hipchat-1.5.2/ 0000755 0000041 0000041 00000000000 12554164714 013200 5 ustar www-data www-data hipchat-1.5.2/Rakefile 0000644 0000041 0000041 00000000624 12554164714 014647 0 ustar www-data www-data require "bundler/gem_tasks"
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new do |t|
t.pattern = 'spec/**/*_spec.rb'
t.rspec_opts = '-c -fd'
end
task :default => :spec
require 'rdoc/task'
Rake::RDocTask.new do |rdoc|
version = HipChat::VERSION
rdoc.rdoc_dir = 'rdoc'
rdoc.title = "hipchat #{version}"
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end
hipchat-1.5.2/Gemfile 0000644 0000041 0000041 00000000134 12554164714 014471 0 ustar www-data www-data source 'https://rubygems.org'
# Specify your gem's dependencies in hipchat.gemspec
gemspec
hipchat-1.5.2/.coveralls.yml 0000644 0000041 0000041 00000000027 12554164714 015772 0 ustar www-data www-data service_name: travis-ci hipchat-1.5.2/.ruby-version 0000644 0000041 0000041 00000000005 12554164714 015640 0 ustar www-data www-data 2.1.0 hipchat-1.5.2/spec/ 0000755 0000041 0000041 00000000000 12554164714 014132 5 ustar www-data www-data hipchat-1.5.2/spec/hipchat_spec.rb 0000644 0000041 0000041 00000004475 12554164714 017123 0 ustar www-data www-data require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe HipChat do
describe 'http_proxy' do
let(:proxy_user) { 'proxy_user' }
let(:proxy_pass) { 'proxy_pass' }
let(:proxy_host) { 'proxy.example.com' }
let(:proxy_port) { 2649 }
let(:proxy_url) { "http://#{proxy_user}:#{proxy_pass}@#{proxy_host}:#{proxy_port}" }
context 'specified by option of constructor' do
before do
HipChat::Client.new("blah", :http_proxy => proxy_url)
end
subject { HipChat::Client.default_options }
specify "Client's proxy settings should be changed" do
expect(subject[:http_proxyaddr]).to eql(proxy_host)
expect(subject[:http_proxyport]).to eql(proxy_port)
expect(subject[:http_proxyuser]).to eql(proxy_user)
expect(subject[:http_proxypass]).to eql(proxy_pass)
end
describe "Room class's proxy" do
subject { HipChat::Room.default_options }
specify "proxy settings should be changed" do
expect(subject[:http_proxyaddr]).to eql(proxy_host)
expect(subject[:http_proxyport]).to eql(proxy_port)
expect(subject[:http_proxyuser]).to eql(proxy_user)
expect(subject[:http_proxypass]).to eql(proxy_pass)
end
end
end
end
describe 'options' do
context "api_version" do
it "defaults to a v1 client" do
client = HipChat::Client.new("blah")
expect(client[:example].api_version).to eql('v1')
end
it "when given 'v1' it registers a v1 client" do
client = HipChat::Client.new("blah", :api_version => 'v1')
expect(client[:example].api_version).to eql('v1')
end
it "when given 'v2' it registers a v2 client" do
client = HipChat::Client.new("blah", :api_version => 'v2')
expect(client[:example].api_version).to eql('v2')
end
end
context "server_url" do
it "defaults to 'https://api.hipchat.com'" do
client = HipChat::Client.new("derr")
expect(client[:example].server_url).to eql('https://api.hipchat.com')
end
it "can be overridden to 'http://hipchat.example.com'" do
client = HipChat::Client.new("derr", :server_url => 'http://hipchat.example.com')
expect(client[:example].server_url).to eql('http://hipchat.example.com')
end
end
end
end
hipchat-1.5.2/spec/spec.opts 0000644 0000041 0000041 00000000010 12554164714 015762 0 ustar www-data www-data --color
hipchat-1.5.2/spec/spec_helper.rb 0000644 0000041 0000041 00000000674 12554164714 016757 0 ustar www-data www-data $LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'hipchat'
require 'rspec'
require 'rspec/autorun'
require 'json'
require 'webmock/rspec'
begin
require 'coveralls'
Coveralls.wear!
rescue LoadError
warn 'warning: coveralls gem not found; skipping coverage'
end
Dir["./spec/support/**/*.rb"].each {|f| require f}
RSpec.configure do |config|
config.mock_with :rr
end
hipchat-1.5.2/spec/hipchat_api_v1_spec.rb 0000644 0000041 0000041 00000012613 12554164714 020353 0 ustar www-data www-data require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe "HipChat (API V1)" do
subject { HipChat::Client.new("blah", :api_version => @api_version) }
let(:room) { subject["Hipchat"] }
describe "#history" do
include_context "HipChatV1"
it "is successful without custom options" do
mock_successful_history()
expect(room.history()).to be_truthy
end
it "is successful with custom options" do
mock_successful_history(:timezone => 'America/Los_Angeles', :date => '2010-11-19', :'max-results' => 10, :'start-index' => 10)
expect(room.history(:timezone => 'America/Los_Angeles', :date => '2010-11-19', :'max-results' => 10, :'start-index' => 10)).to be_truthy
end
it "is successful from fetched room" do
mock_successful_rooms
mock_successful_history
expect(subject.rooms).to be_truthy
expect(subject.rooms.first.history).to be_truthy
end
it "fails when the room doen't exist" do
mock(HipChat::Room).get(anything, anything) {
OpenStruct.new(:code => 404)
}
expect { room.history }.to raise_error(HipChat::UnknownRoom)
end
it "fails when we're not allowed to do so" do
mock(HipChat::Room).get(anything, anything) {
OpenStruct.new(:code => 401)
}
expect { room.history }.to raise_error(HipChat::Unauthorized)
end
it "fails if we get an unknown response code" do
mock(HipChat::Room).get(anything, anything) {
OpenStruct.new(:code => 403)
}
expect { room.history }.to raise_error(HipChat::UnknownResponseCode)
end
end
describe "#topic" do
include_context "HipChatV1"
it "is successful without custom options" do
mock_successful_topic_change("Nice topic")
expect(room.topic("Nice topic")).to be_truthy
end
it "is successful with a custom from" do
mock_successful_topic_change("Nice topic", :from => "Me")
expect(room.topic("Nice topic", :from => "Me")).to be_truthy
end
it "fails when the room doesn't exist" do
mock(HipChat::Room).post(anything, anything) {
OpenStruct.new(:code => 404)
}
expect { room.topic "" }.to raise_error(HipChat::UnknownRoom)
end
it "fails when we're not allowed to do so" do
mock(HipChat::Room).post(anything, anything) {
OpenStruct.new(:code => 401)
}
expect { room.topic "" }.to raise_error(HipChat::Unauthorized)
end
it "fails if we get an unknown response code" do
mock(HipChat::Room).post(anything, anything) {
OpenStruct.new(:code => 403)
}
expect { room.topic "" }.to raise_error(HipChat::UnknownResponseCode)
end
end
describe "#send" do
include_context "HipChatV1"
it "successfully without custom options" do
mock_successful_send 'Dude', 'Hello world'
expect(room.send("Dude", "Hello world")).to be_truthy
end
it "successfully with notifications on as option" do
mock_successful_send 'Dude', 'Hello world', :notify => 1
expect(room.send("Dude", "Hello world", :notify => 1)).to be_truthy
end
it "successfully with custom color" do
mock_successful_send 'Dude', 'Hello world', :color => 'red'
expect(room.send("Dude", "Hello world", :color => 'red')).to be_truthy
end
it "successfully with text message_format" do
mock_successful_send 'Dude', 'Hello world', :message_format => 'text'
expect(room.send("Dude", "Hello world", :message_format => 'text')).to be_truthy
end
it "but fails when the room doesn't exist" do
mock(HipChat::Room).post(anything, anything) {
OpenStruct.new(:code => 404)
}
expect { room.send "", "" }.to raise_error(HipChat::UnknownRoom)
end
it "but fails when we're not allowed to do so" do
mock(HipChat::Room).post(anything, anything) {
OpenStruct.new(:code => 401)
}
expect { room.send "", "" }.to raise_error(HipChat::Unauthorized)
end
it "but fails if the username is more than 15 chars" do
expect { room.send "a very long username here", "a message" }.to raise_error(HipChat::UsernameTooLong)
end
it "but fails if we get an unknown response code" do
mock(HipChat::Room).post(anything, anything) {
OpenStruct.new(:code => 403)
}
expect { room.send "", "" }.to raise_error(HipChat::UnknownResponseCode)
end
end
describe "#create" do
include_context "HipChatV1"
it "successfully with room name" do
mock_successful_room_creation("A Room", :owner_user_id => "123456")
expect(subject.create_room("A Room", {:owner_user_id => "123456"})).to be_truthy
end
it "successfully with custom parameters" do
mock_successful_room_creation("A Room", {:owner_user_id => "123456", :privacy => "private", :guest_access => "1"})
expect(subject.create_room("A Room", {:owner_user_id => "123456", :privacy => "private", :guest_access =>true})).to be_truthy
end
it "but fails if we dont pass owner_user_id" do
expect { subject.create_room("A Room", {:privacy => "private", :guest_access =>true}) }.to raise_error(HipChat::RoomMissingOwnerUserId)
end
end
describe "#send user message" do
it "fails because API V1 doesn't support user operations" do
expect { HipChat::Client.new("blah", :api_version => @api_version).user('12345678').send('nope') }.
to raise_error(HipChat::InvalidApiVersion)
end
end
end
hipchat-1.5.2/spec/hipchat_api_v2_spec.rb 0000644 0000041 0000041 00000024652 12554164714 020362 0 ustar www-data www-data require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe "HipChat (API V2)" do
subject { HipChat::Client.new("blah", :api_version => @api_version) }
let(:room) { subject["Hipchat"] }
let(:user) { subject.user "12345678" }
describe "#history" do
include_context "HipChatV2"
it "is successful without custom options" do
mock_successful_history()
expect(room.history()).to be_truthy
end
it "is successful with custom options" do
mock_successful_history(:timezone => 'America/Los_Angeles', :date => '2010-11-19', :'max-results' => 10, :'start-index' => 10)
expect(room.history(:timezone => 'America/Los_Angeles', :date => '2010-11-19', :'max-results' => 10, :'start-index' => 10)).to be_truthy
end
it "is successful from fetched room" do
mock_successful_rooms
mock_successful_history
expect(subject.rooms).to be_truthy
expect(subject.rooms.first.history).to be_truthy
end
it "fails when the room doen't exist" do
mock(HipChat::Room).get(anything, anything) {
OpenStruct.new(:code => 404)
}
expect { room.history }.to raise_error(HipChat::UnknownRoom)
end
it "fails when we're not allowed to do so" do
mock(HipChat::Room).get(anything, anything) {
OpenStruct.new(:code => 401)
}
expect { room.history }.to raise_error(HipChat::Unauthorized)
end
it "fails if we get an unknown response code" do
mock(HipChat::Room).get(anything, anything) {
OpenStruct.new(:code => 403)
}
expect { room.history }.to raise_error(HipChat::UnknownResponseCode)
end
end
describe "#statistics" do
include_context "HipChatV2"
it "is successful without custom options" do
mock_successful_statistics
expect(room.statistics()).to be_truthy
end
it "is successful from fetched room" do
mock_successful_rooms
mock_successful_statistics
expect(subject.rooms).to be_truthy
expect(subject.rooms.first.statistics).to be_truthy
end
it "fails when the room doen't exist" do
mock(HipChat::Room).get(anything, anything) {
OpenStruct.new(:code => 404)
}
expect { room.statistics }.to raise_error(HipChat::UnknownRoom)
end
it "fails when we're not allowed to do so" do
mock(HipChat::Room).get(anything, anything) {
OpenStruct.new(:code => 401)
}
expect { room.statistics }.to raise_error(HipChat::Unauthorized)
end
it "fails if we get an unknown response code" do
mock(HipChat::Room).get(anything, anything) {
OpenStruct.new(:code => 403)
}
expect { room.statistics }.to raise_error(HipChat::UnknownResponseCode)
end
end
describe "#topic" do
include_context "HipChatV2"
it "is successful without custom options" do
mock_successful_topic_change("Nice topic")
expect(room.topic("Nice topic")).to be_truthy
end
it "is successful with a custom from" do
mock_successful_topic_change("Nice topic", :from => "Me")
expect(room.topic("Nice topic", :from => "Me")).to be_truthy
end
it "fails when the room doesn't exist" do
mock(HipChat::Room).put(anything, anything) {
OpenStruct.new(:code => 404)
}
expect { room.topic "" }.to raise_error(HipChat::UnknownRoom)
end
it "fails when we're not allowed to do so" do
mock(HipChat::Room).put(anything, anything) {
OpenStruct.new(:code => 401)
}
expect { room.topic "" }.to raise_error(HipChat::Unauthorized)
end
it "fails if we get an unknown response code" do
mock(HipChat::Room).put(anything, anything) {
OpenStruct.new(:code => 403)
}
expect { room.topic "" }.to raise_error(HipChat::UnknownResponseCode)
end
end
describe "#send" do
include_context "HipChatV2"
it "successfully without custom options" do
mock_successful_send 'Dude', 'Hello world'
expect(room.send("Dude", "Hello world")).to be_truthy
end
it "successfully with notifications on as option" do
mock_successful_send 'Dude', 'Hello world', :notify => true
expect(room.send("Dude", "Hello world", :notify => true)).to be_truthy
end
it "successfully with custom color" do
mock_successful_send 'Dude', 'Hello world', :color => 'red'
expect(room.send("Dude", "Hello world", :color => 'red')).to be_truthy
end
it "successfully with text message_format" do
mock_successful_send 'Dude', 'Hello world', :message_format => 'text'
expect(room.send("Dude", "Hello world", :message_format => 'text')).to be_truthy
end
it "but fails when the room doesn't exist" do
mock(HipChat::Room).post(anything, anything) {
OpenStruct.new(:code => 404)
}
expect { room.send "", "" }.to raise_error(HipChat::UnknownRoom)
end
it "but fails when we're not allowed to do so" do
mock(HipChat::Room).post(anything, anything) {
OpenStruct.new(:code => 401)
}
expect { room.send "", "" }.to raise_error(HipChat::Unauthorized)
end
it "but fails if the username is more than 15 chars" do
expect { room.send "a very long username here", "a message" }.to raise_error(HipChat::UsernameTooLong)
end
it "but fails if we get an unknown response code" do
mock(HipChat::Room).post(anything, anything) {
OpenStruct.new(:code => 403)
}
expect { room.send "", "" }.to raise_error(HipChat::UnknownResponseCode)
end
end
describe "#send_file" do
let(:file) do
Tempfile.new('foo').tap do |f|
f.write("the content")
f.rewind
end
end
after { file.unlink }
include_context "HipChatV2"
it "successfully" do
mock_successful_file_send 'Dude', 'Hello world', file
room.send_file("Dude", "Hello world", file).should be_truthy
end
it "but fails when the room doesn't exist" do
mock(HipChat::Room).post(anything, anything) {
OpenStruct.new(:code => 404)
}
lambda { room.send_file "", "", file }.should raise_error(HipChat::UnknownRoom)
end
it "but fails when we're not allowed to do so" do
mock(HipChat::Room).post(anything, anything) {
OpenStruct.new(:code => 401)
}
lambda { room.send_file "", "", file }.should raise_error(HipChat::Unauthorized)
end
it "but fails if the username is more than 15 chars" do
lambda { room.send_file "a very long username here", "a message", file }.should raise_error(HipChat::UsernameTooLong)
end
it "but fails if we get an unknown response code" do
mock(HipChat::Room).post(anything, anything) {
OpenStruct.new(:code => 403)
}
lambda { room.send_file "", "", file }.
should raise_error(HipChat::UnknownResponseCode)
end
end
describe "#create" do
include_context "HipChatV2"
it "successfully with room name" do
mock_successful_room_creation("A Room")
expect(subject.create_room("A Room")).to be_truthy
end
it "successfully with custom parameters" do
mock_successful_room_creation("A Room", {:owner_user_id => "123456", :privacy => "private", :guest_access => true})
expect(subject.create_room("A Room", {:owner_user_id => "123456", :privacy => "private", :guest_access =>true})).to be_truthy
end
it "but fail is name is longer then 50 char" do
expect { subject.create_room("A Room that is too long that I should fail right now") }.
to raise_error(HipChat::RoomNameTooLong)
end
end
describe "#get_room" do
include_context "HipChatV2"
it "successfully" do
mock_successful_get_room("Hipchat")
expect(room.get_room).to be_truthy
end
end
describe "#update_room" do
include_context "HipChatV2"
let(:room_info) {
{
"name" => "hipchat",
"topic" => "hipchat topic",
"privacy" => "public",
"is_archived" => false,
"is_guest_accessible" => false,
"owner" => { "id" => "12345" }
}
}
it "successfully" do
mock_successful_update_room("Hipchat", room_info)
expect(room.update_room(room_info)).to be_truthy
end
end
describe "#invite" do
include_context "HipChatV2"
it "successfully with user_id" do
mock_successful_invite()
expect(room.invite("1234")).to be_truthy
end
it "successfully with custom parameters" do
mock_successful_invite({:user_id => "321", :reason => "A great reason"})
expect(room.invite("321", "A great reason")).to be_truthy
end
end
describe "#send user message" do
include_context "HipChatV2"
it "successfully with a standard message" do
mock_successful_user_send 'Equal bytes for everyone'
expect(user.send('Equal bytes for everyone')).to be_truthy
end
it "but fails when the user doesn't exist" do
mock(HipChat::User).post(anything, anything) {
OpenStruct.new(:code => 404)
}
expect { user.send "" }.to raise_error(HipChat::UnknownUser)
end
it "but fails when we're not allowed to do so" do
mock(HipChat::User).post(anything, anything) {
OpenStruct.new(:code => 401)
}
expect { user.send "" }.to raise_error(HipChat::Unauthorized)
end
end
describe '#get_user_history' do
include_context 'HipChatV2'
it 'successfully returns history' do
mock_successful_user_history
user.history.should be_truthy
end
it 'has allowed params' do
expect(user.instance_variable_get(:@api).history_config[:allowed_params]).to eq([:'max-results', :timezone, :'not-before'])
end
end
describe "#send_file user" do
include_context "HipChatV2"
let(:file) do
Tempfile.new('foo').tap do |f|
f.write("the content")
f.rewind
end
end
it "successfully with a standard file" do
mock_successful_user_send_file 'Equal bytes for everyone', file
user.send_file('Equal bytes for everyone', file).should be_truthy
end
it "but fails when the user doesn't exist" do
mock(HipChat::User).post(anything, anything) {
OpenStruct.new(:code => 404)
}
lambda { user.send_file "", file }.should raise_error(HipChat::UnknownUser)
end
it "but fails when we're not allowed to do so" do
mock(HipChat::User).post(anything, anything) {
OpenStruct.new(:code => 401)
}
lambda { user.send_file "", file }.should raise_error(HipChat::Unauthorized)
end
end
end
hipchat-1.5.2/spec/example/ 0000755 0000041 0000041 00000000000 12554164714 015565 5 ustar www-data www-data hipchat-1.5.2/spec/example/history.json 0000644 0000041 0000041 00000001443 12554164714 020163 0 ustar www-data www-data HTTP/1.1 200 OK
Content-Type: application/json
{
"messages": [
{
"date": "2010-11-19T15:48:19-0800",
"from": {
"name": "Garret Heaton",
"user_id": 10
},
"message": "Good morning! This is a regular message."
},
{
"date": "2010-11-19T15:49:44-0800",
"from": {
"name": "Garret Heaton",
"user_id": 10
},
"file": {
"name": "Screenshot.png",
"size": 141909,
"url": "http:\/\/uploads.hipchat.com\/xxx\/Screenshot.png"
},
"message": "This is a file upload"
},
{
"date": "2010-11-19T16:13:40-0800",
"from": {
"name": "Deploy Bot",
"user_id": "api"
},
"message": "This message is sent via the API so the user_id is 'api'."
}
]
} hipchat-1.5.2/spec/support/ 0000755 0000041 0000041 00000000000 12554164714 015646 5 ustar www-data www-data hipchat-1.5.2/spec/support/shared_contexts_for_hipchat.rb 0000644 0000041 0000041 00000031307 12554164714 023742 0 ustar www-data www-data HISTORY_JSON_PATH = File.expand_path(File.dirname(__FILE__) + '/../example/history.json')
shared_context "HipChatV1" do
before { @api_version = 'v1'}
# Helper for mocking room message post requests
def mock_successful_send(from, message, options={})
options = {:color => 'yellow', :notify => 0, :message_format => 'html'}.merge(options)
stub_request(:post, "https://api.hipchat.com/v1/rooms/message").with(
:query => {:auth_token => "blah"},
:body => {:room_id => "Hipchat",
:from => "Dude",
:message => "Hello world",
:message_format => options[:message_format],
:color => options[:color],
:notify => "#{options[:notify]}"},
:headers => {'Accept' => 'application/json',
'Content-Type' => 'application/x-www-form-urlencoded'}).to_return(:status => 200, :body => "", :headers => {})
end
def mock_successful_topic_change(topic, options={})
options = {:from => 'API'}.merge(options)
stub_request(:post, "https://api.hipchat.com/v1/rooms/topic").with(
:query => {:auth_token => "blah"},
:body => {:room_id => "Hipchat",
:from => options[:from],
:topic => "Nice topic" },
:headers => {'Accept' => 'application/json',
'Content-Type' => 'application/x-www-form-urlencoded'}).to_return(:status => 200, :body => "", :headers => {})
end
def mock_successful_rooms
stub_request(:get, "https://api.hipchat.com/v1/rooms/list").with(
:query => {:auth_token => "blah"},
:body => "",
:headers => {'Accept' => 'application/json',
'Content-Type' => 'application/x-www-form-urlencoded'}).to_return(
:status => 200,
:body => '{"rooms":[{"room_id": "Hipchat", "links": {"self": "https://api.hipchat.com/v2/room/12345"}}]}',
:headers => {})
end
def mock_successful_history(options={})
options = { :date => 'recent', :timezone => 'UTC', :format => 'JSON', :'max-results' => 100, :'start-index' => 0 }.merge(options)
canned_response = File.new(HISTORY_JSON_PATH)
stub_request(:get, "https://api.hipchat.com/v1/rooms/history").with(:query => {:auth_token => "blah",
:room_id => "Hipchat",
:date => options[:date],
:timezone => options[:timezone],
:'max-results' => options[:'max-results'],
:'start-index' => options[:'start-index'],
:format => options[:format]}).to_return(canned_response)
end
def mock_successful_room_creation(name, options={})
options = {:name => "A Room"}.merge(options)
stub_request(:post, "https://api.hipchat.com/v1/rooms/create").with(
:query => {:auth_token => "blah"},
:body => { :name => name }.merge(options),
:headers => {'Accept' => 'application/json',
'Content-Type' => 'application/x-www-form-urlencoded'}).to_return(
:status => 200,
:body => '{"room": {"room_id": "1234", "name" : "A Room"}}',
:headers => {})
end
end
shared_context "HipChatV2" do
before { @api_version = 'v2'}
# Helper for mocking room message post requests
def mock_successful_send(from, message, options={})
options = {:color => 'yellow', :notify => false, :message_format => 'html'}.merge(options)
stub_request(:post, "https://api.hipchat.com/v2/room/Hipchat/notification").with(
:query => {:auth_token => "blah"},
:body => {:room_id => "Hipchat",
:from => "Dude",
:message => "Hello world",
:message_format => options[:message_format],
:color => options[:color],
:notify => options[:notify]}.to_json,
:headers => {'Accept' => 'application/json',
'Content-Type' => 'application/json'}).to_return(:status => 200, :body => "", :headers => {})
end
def mock_successful_file_send(from, message, file)
stub_request(:post, "https://api.hipchat.com/v2/room/Hipchat/share/file").with(
:query => {:auth_token => "blah"},
:body => "--sendfileboundary\nContent-Type: application/json; charset=UTF-8\nContent-Disposition: attachment; name=\"metadata\"\n\n{\"room_id\":\"Hipchat\",\"from\":\"Dude\",\"message\":\"Hello world\"}\n--sendfileboundary\nContent-Type: ; charset=UTF-8\nContent-Transfer-Encoding: base64\nContent-Disposition: attachment; name=\"file\"; filename=\"#{File.basename(file.path)}\"\n\ndGhlIGNvbnRlbnQ=\n\n--sendfileboundary--",
:headers => {'Accept' => 'application/json',
'Content-Type' => 'multipart/related; boundary=sendfileboundary'}).to_return(:status => 200, :body => "", :headers => {})
end
def mock_successful_topic_change(topic, options={})
options = {:from => 'API'}.merge(options)
stub_request(:put, "https://api.hipchat.com/v2/room/Hipchat/topic").with(
:query => {:auth_token => "blah"},
:body => {:room_id => "Hipchat",
:from => options[:from],
:topic => "Nice topic" }.to_json,
:headers => {'Accept' => 'application/json',
'Content-Type' => 'application/json'}).to_return(:status => 200, :body => "", :headers => {})
end
def mock_successful_rooms
stub_request(:get, "https://api.hipchat.com/v2/room").with(
:query => {:auth_token => "blah"},
:body => "",
:headers => {'Accept' => 'application/json',
'Content-Type' => 'application/json'}).to_return(
:status => 200,
:body => '{"items":[{"id": "Hipchat", "links": {"self": "https://api.hipchat.com/v2/room/12345"}}]}',
:headers => {})
end
def mock_successful_history(options={})
options = { :date => 'recent', :timezone => 'UTC', :format => 'JSON', :'max-results' => 100, :'start-index' => 0 }.merge(options)
canned_response = File.new(HISTORY_JSON_PATH)
stub_request(:get, "https://api.hipchat.com/v2/room/Hipchat/history").with(:query => {:auth_token => "blah",
:room_id => "Hipchat",
:date => options[:date],
:timezone => options[:timezone],
:'max-results' => options[:'max-results'],
:'start-index' => options[:'start-index'],
:format => options[:format]}).to_return(canned_response)
end
def mock_successful_statistics(options={})
stub_request(:get, "https://api.hipchat.com/v2/room/Hipchat/statistics").with(:query => {:auth_token => "blah",
:room_id => "Hipchat",
:date => options[:date],
:timezone => options[:timezone],
:format => options[:format]}).to_return(
:status => 200,
:body => '{"last_active": "2014-09-02T21:33:54+00:00", "links": {"self": "https://api.hipchat.com/v2/room/12345/statistics"}, "messages_sent": 10}',
:headers => {})
end
def mock_successful_room_creation(name, options={})
stub_request(:post, "https://api.hipchat.com/v2/room").with(
:query => {:auth_token => "blah"},
:body => { :name => name }.merge(options).to_json,
:headers => {'Accept' => 'application/json',
'Content-Type' => 'application/json'}).to_return(
:status => 201,
:body => '{"id": "12345", "links": {"self": "https://api.hipchat.com/v2/room/12345"}}',
:headers => {})
end
def mock_successful_get_room(room_id="1234")
stub_request(:get, "https://api.hipchat.com/v2/room/#{room_id}").with(
:query => {:auth_token => "blah"},
:body => "",
:headers => {'Accept' => 'application/json',
'Content-Type' => 'application/json'}).to_return(:status => 200, :body => "{\"id\":\"#{room_id}\"}", :headers => {})
end
def mock_successful_update_room(room_id="1234", options={})
stub_request(:put, "https://api.hipchat.com/v2/room/#{room_id}").with(
:query => {:auth_token => "blah"},
:body => {
:name => "hipchat",
:topic => "hipchat topic",
:privacy => "public",
:is_archived => false,
:is_guest_accessible => false,
:owner => { :id => "12345" }
}.to_json,
:headers => {"Accept" => "application/json",
"Content-Type" => "application/json"}).to_return(
:status => 204,
:body => "",
:headers => {})
end
def mock_successful_invite(options={})
options = {:user_id => "1234"}.merge(options)
stub_request(:post, "https://api.hipchat.com/v2/room/Hipchat/invite/#{options[:user_id]}").with(
:query => {:auth_token => "blah"},
:body => {
:reason => options[:reason]||""
}.to_json,
:headers => {'Accept' => 'application/json',
'Content-Type' => 'application/json'}).to_return(
:status => 204,
:body => "",
:headers => {})
end
def mock_successful_user_send(message)
stub_request(:post, "https://api.hipchat.com/v2/user/12345678/message").with(
:query => {:auth_token => "blah"},
:body => {:message => "Equal bytes for everyone",
:message_format => "text"},
:headers => {'Accept' => 'application/json',
'Content-Type' => 'application/json'}).to_return(:status => 200, :body => "", :headers => {})
end
def mock_successful_user_history()
canned_response = File.new(HISTORY_JSON_PATH)
url = 'https://api.hipchat.com/v2/user/12345678/history/latest'
stub_request(:get, url).with(:query => { :auth_token => "blah" },
:headers => { 'Accept' => 'application/json',
'Content-Type' => 'application/json' }).to_return(canned_response)
end
def mock_successful_user_send_file(message, file)
stub_request(:post, "https://api.hipchat.com/v2/user/12345678/share/file").with(
:query => {:auth_token => "blah"},
:body => "--sendfileboundary\nContent-Type: application/json; charset=UTF-8\nContent-Disposition: attachment; name=\"metadata\"\n\n{\"message\":\"Equal bytes for everyone\"}\n--sendfileboundary\nContent-Type: ; charset=UTF-8\nContent-Transfer-Encoding: base64\nContent-Disposition: attachment; name=\"file\"; filename=\"#{File.basename(file)}\"\n\ndGhlIGNvbnRlbnQ=\n\n--sendfileboundary--",
:headers => {'Accept' => 'application/json',
'Content-Type' => 'multipart/related; boundary=sendfileboundary'}).to_return(:status => 200, :body => "", :headers => {})
end
end
hipchat-1.5.2/.travis.yml 0000644 0000041 0000041 00000000061 12554164714 015306 0 ustar www-data www-data language: ruby
rvm:
- 1.9.3
- 2.0.0
- 2.1
hipchat-1.5.2/lib/ 0000755 0000041 0000041 00000000000 12554164714 013746 5 ustar www-data www-data hipchat-1.5.2/lib/hipchat/ 0000755 0000041 0000041 00000000000 12554164714 015366 5 ustar www-data www-data hipchat-1.5.2/lib/hipchat/capistrano2.rb 0000644 0000041 0000041 00000013102 12554164714 020135 0 ustar www-data www-data require 'hipchat'
Capistrano::Configuration.instance(:must_exist).load do
set :hipchat_send_notification, false
set :hipchat_with_migrations, ''
namespace :hipchat do
task :trigger_notification do
set :hipchat_send_notification, true if !dry_run
end
task :configure_for_migrations do
set :hipchat_with_migrations, ' (with migrations)'
end
task :notify_deploy_started do
if hipchat_send_notification
environment_string = env
if self.respond_to?(:stage)
environment_string = "#{stage} (#{env})"
end
on_rollback do
send_options.merge!(:color => failed_message_color)
send("#{human} cancelled deployment of #{deployment_name} to #{environment_string}.", send_options)
end
send("#{human} is deploying #{deployment_name} to #{environment_string}#{fetch(:hipchat_with_migrations, '')}.", send_options)
end
end
task :notify_deploy_finished do
if hipchat_send_notification
send_options.merge!(:color => success_message_color)
environment_string = env
if self.respond_to?(:stage)
environment_string = "#{stage} (#{env})"
end
if fetch(:hipchat_commit_log, false)
logs = commit_logs
unless logs.empty?
send(logs.join(commit_log_line_separator), send_options)
end
end
send("#{human} finished deploying #{deployment_name} to #{environment_string}#{fetch(:hipchat_with_migrations, '')}.", send_options)
end
end
def send_options
return @send_options if defined?(@send_options)
@send_options = message_format ? {:message_format => message_format } : {}
@send_options.merge!(:notify => message_notification)
@send_options.merge!(:color => message_color)
@send_options
end
def send(message, options)
return unless enabled?
hipchat_options = fetch(:hipchat_options, {})
set :hipchat_client, HipChat::Client.new(hipchat_token, hipchat_options) if fetch(:hipchat_client, nil).nil?
if hipchat_room_name.is_a?(String)
rooms = [hipchat_room_name]
elsif hipchat_room_name.is_a?(Symbol)
rooms = [hipchat_room_name.to_s]
else
rooms = hipchat_room_name
end
rooms.each { |room|
begin
hipchat_client[room].send(deploy_user, message, options)
rescue => e
puts e.message
puts e.backtrace
end
}
end
def enabled?
fetch(:hipchat_enabled, true)
end
def deployment_name
if fetch(:branch, nil)
name = "#{application}/#{branch}"
name += " (revision #{real_revision[0..7]})" if real_revision
name
else
application
end
end
def message_color
fetch(:hipchat_color, nil)
end
def success_message_color
fetch(:hipchat_success_color, "green")
end
def failed_message_color
fetch(:hipchat_failed_color, "red")
end
def message_notification
fetch(:hipchat_announce, false)
end
def message_format
fetch(:hipchat_message_format, "html")
end
def deploy_user
fetch(:hipchat_deploy_user, "Deploy")
end
def human
ENV['HIPCHAT_USER'] ||
fetch(:hipchat_human,
if (u = %x{git config user.name}.strip) != ""
u
elsif (u = ENV['USER']) != ""
u
else
"Someone"
end)
end
def env
fetch(:hipchat_env, fetch(:rack_env, fetch(:rails_env, "production")))
end
def commit_log_line_separator
message_format == "html" ? "
" : "\n"
end
end
def commit_logs
from = (previous_revision rescue nil)
to = (latest_revision rescue nil)
log_hashes = []
case scm.to_s
when 'git'
logs = run_locally(source.local.scm(:log, "--no-merges --pretty=format:'%H$$%at$$%an$$%s' #{from}..#{to}"))
logs.split(/\n/).each do |log|
ll = log.split(/\$\$/)
log_hashes << {revision: ll[0], time: Time.at(ll[1].to_i), user: ll[2], message: ll[3]}
end
when 'svn'
logs = run_locally(source.local.scm(:log, "--non-interactive -r #{from}:#{to}"))
logs.scan(/^[-]+$\n\s*(?[^\|]+)\s+\|\s+(?[^\|]+)\s+\|\s+(?