hipchat2 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/LICENSE +21 -0
- data/README.md +87 -0
- data/Rakefile +32 -0
- data/VERSION +1 -0
- data/hipchat2.gemspec +58 -0
- data/lib/hipchat2/capistrano.rb +95 -0
- data/lib/hipchat2/chef.rb +31 -0
- data/lib/hipchat2/rails3_tasks.rb +38 -0
- data/lib/hipchat2/railtie.rb +9 -0
- data/lib/hipchat2.rb +84 -0
- data/spec/hipchat2_spec.rb +70 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +9 -0
- metadata +102 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cf3848491ea3b3b22a1c380891e8af9c924ea715
|
4
|
+
data.tar.gz: 6aab7c5a3e0f9311e01560cb8cef89897cef4a1e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dd3a0849a4f7b66a933a392369422672b547579eb158f65e966350ba4ec8f28a2615e3312130f6a5a12b1dc238a5b128456edd5b010d0dbdd064687cf44d3fd6
|
7
|
+
data.tar.gz: ce7fc985b3fa31593c79c57ddb82121447c756b83cdd0e645beee010f7f24266c7023fd3e07968e262052855c48473d05464ee16e0f5db6286e96a94f2ce900b
|
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2009 Mojo Tech
|
2
|
+
Copyright (c) 2013 Dmitry Rybakov
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
HipChat2 Wrapper
|
2
|
+
===============
|
3
|
+
|
4
|
+
A very basic wrapper for the HipChat HTTP API that uses hipchat API v2
|
5
|
+
|
6
|
+
Usage
|
7
|
+
-----
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
client = HipChat2::Client.new(api_token)
|
11
|
+
client['my room'].send('username', 'I talk')
|
12
|
+
|
13
|
+
# Send notifications to users (default false)\
|
14
|
+
client['my room'].send('username', 'I quit!', :notify => true)
|
15
|
+
|
16
|
+
# Color it red. or “yellow”, “green”, “purple”, “random” (default “yellow”)
|
17
|
+
client['my room'].send('username', 'Build failed!', :color => 'red')
|
18
|
+
```
|
19
|
+
|
20
|
+
Capistrano
|
21
|
+
----------
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require 'hipchat/capistrano'
|
25
|
+
|
26
|
+
set :hipchat_token, "<your token>"
|
27
|
+
set :hipchat_room_name, "Your room"
|
28
|
+
set :hipchat_announce, false # notify users
|
29
|
+
set :hipchat_color, 'green' # finished deployment message color
|
30
|
+
set :hipchat_failed_color, 'red' # cancelled deployment message color
|
31
|
+
```
|
32
|
+
|
33
|
+
### Who did it?
|
34
|
+
|
35
|
+
To determine the user that is currently running the deploy, the
|
36
|
+
capistrano tasks will look for the following:
|
37
|
+
|
38
|
+
1. The $HIPCHAT\_USER environment variable
|
39
|
+
2. The hipchat\_human capistrano var.
|
40
|
+
3. The git user.name var.
|
41
|
+
4. The \$USER environment variable.
|
42
|
+
|
43
|
+
Rails 3 Rake Task
|
44
|
+
-----------------
|
45
|
+
|
46
|
+
Send a message using a rake task:
|
47
|
+
|
48
|
+
rake hipchat:send["hello world"]
|
49
|
+
|
50
|
+
Options like the room, API token, user name and notification flag can be
|
51
|
+
set in YAML.
|
52
|
+
|
53
|
+
RAILS\_ROOT/config/hipchat.yml:
|
54
|
+
|
55
|
+
```yaml
|
56
|
+
token: <your token>
|
57
|
+
room: Your room
|
58
|
+
user: Your name” # Default to `whoami`
|
59
|
+
notify: true # Defaults to false
|
60
|
+
```
|
61
|
+
|
62
|
+
Engine Yard
|
63
|
+
-----------
|
64
|
+
|
65
|
+
Use a [deploy hook][] to send messages from Engine Yard’s Cloud
|
66
|
+
platform.
|
67
|
+
|
68
|
+
RAILS\_ROOT/deploy/after\_restart.rb:
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
on_app_master do
|
72
|
+
message = "Deploying revision #{revision[0…6]} to #{node[:environment][:name]}"
|
73
|
+
message += " " if migrate?
|
74
|
+
message += "."
|
75
|
+
|
76
|
+
# Send a message via rake task assuming a hipchat.yml in your config like above
|
77
|
+
run "cd #{release_path} && bundle exec rake hipchat:send MESSAGE='#{message}'"
|
78
|
+
end
|
79
|
+
```
|
80
|
+
|
81
|
+
Copyright
|
82
|
+
---------
|
83
|
+
|
84
|
+
Copyright © 2010 Mojo Tech. See LICENSE for details.
|
85
|
+
Copyright © 2013 Dmitry Rybakov. See LICENSE for details.
|
86
|
+
|
87
|
+
[deploy hook]: http://bit.ly/qnbIkP
|
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "hipchat"
|
8
|
+
gem.summary = %Q{Ruby library to interact with HipChat}
|
9
|
+
gem.description = %Q{Ruby library to interact with HipChat}
|
10
|
+
gem.email = "gems@mojotech.com"
|
11
|
+
gem.homepage = "http://github.com/mojotech/hipchat"
|
12
|
+
gem.authors = ["MojoTech"]
|
13
|
+
gem.add_dependency "httparty"
|
14
|
+
gem.add_development_dependency "rspec", "~> 2.0"
|
15
|
+
gem.add_development_dependency "rr", "~> 1.0"
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
task :default => :spec
|
23
|
+
|
24
|
+
require 'rake/rdoctask'
|
25
|
+
Rake::RDocTask.new do |rdoc|
|
26
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
27
|
+
|
28
|
+
rdoc.rdoc_dir = 'rdoc'
|
29
|
+
rdoc.title = "hipchat #{version}"
|
30
|
+
rdoc.rdoc_files.include('README*')
|
31
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
32
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/hipchat2.gemspec
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "hipchat2"
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["MojoTech", "Dmitry Rybakov"]
|
12
|
+
s.date = "2013-11-29"
|
13
|
+
s.description = "Ruby library to interact with HipChat"
|
14
|
+
s.email = "dmitry.rybakov@gmail.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"LICENSE",
|
22
|
+
"README.md",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"hipchat2.gemspec",
|
26
|
+
"lib/hipchat2.rb",
|
27
|
+
"lib/hipchat2/capistrano.rb",
|
28
|
+
"lib/hipchat2/chef.rb",
|
29
|
+
"lib/hipchat2/rails3_tasks.rb",
|
30
|
+
"lib/hipchat2/railtie.rb",
|
31
|
+
"spec/hipchat2_spec.rb",
|
32
|
+
"spec/spec.opts",
|
33
|
+
"spec/spec_helper.rb"
|
34
|
+
]
|
35
|
+
s.homepage = "http://github.com/comandeo/hipchat"
|
36
|
+
s.require_paths = ["lib"]
|
37
|
+
s.rubygems_version = "1.8.10"
|
38
|
+
s.summary = "Ruby library to interact with HipChat"
|
39
|
+
|
40
|
+
if s.respond_to? :specification_version then
|
41
|
+
s.specification_version = 3
|
42
|
+
|
43
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
44
|
+
s.add_runtime_dependency(%q<httparty>, [">= 0"])
|
45
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.0"])
|
46
|
+
s.add_development_dependency(%q<rr>, ["~> 1.0"])
|
47
|
+
else
|
48
|
+
s.add_dependency(%q<httparty>, [">= 0"])
|
49
|
+
s.add_dependency(%q<rspec>, ["~> 2.0"])
|
50
|
+
s.add_dependency(%q<rr>, ["~> 1.0"])
|
51
|
+
end
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<httparty>, [">= 0"])
|
54
|
+
s.add_dependency(%q<rspec>, ["~> 2.0"])
|
55
|
+
s.add_dependency(%q<rr>, ["~> 1.0"])
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'hipchat2'
|
2
|
+
|
3
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
4
|
+
set :hipchat_send_notification, false
|
5
|
+
set :hipchat_with_migrations, false
|
6
|
+
|
7
|
+
namespace :hipchat do
|
8
|
+
task :set_client do
|
9
|
+
set :hipchat_client, HipChat2::Client.new(hipchat_token)
|
10
|
+
end
|
11
|
+
|
12
|
+
task :trigger_notification do
|
13
|
+
set :hipchat_send_notification, true
|
14
|
+
end
|
15
|
+
|
16
|
+
task :configure_for_migrations do
|
17
|
+
set :hipchat_with_migrations, true
|
18
|
+
end
|
19
|
+
|
20
|
+
task :notify_deploy_started do
|
21
|
+
if hipchat_send_notification
|
22
|
+
on_rollback do
|
23
|
+
send_options.merge!(:color => failed_message_color)
|
24
|
+
hipchat_client[hipchat_room_name].
|
25
|
+
send(deploy_user, "#{human} cancelled deployment of #{deployment_name} to #{env}.", send_options)
|
26
|
+
end
|
27
|
+
|
28
|
+
message = "#{human} is deploying #{deployment_name} to #{env}"
|
29
|
+
message << " (with migrations)" if hipchat_with_migrations
|
30
|
+
message << "."
|
31
|
+
|
32
|
+
hipchat_client[hipchat_room_name].send(deploy_user, message, send_options)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
task :notify_deploy_finished do
|
37
|
+
hipchat_client[hipchat_room_name].
|
38
|
+
send(deploy_user, "#{human} finished deploying #{deployment_name} to #{env}.", send_options)
|
39
|
+
end
|
40
|
+
|
41
|
+
def send_options
|
42
|
+
return @send_options if defined?(@send_options)
|
43
|
+
@send_options = message_color ? {:color => message_color} : {}
|
44
|
+
@send_options.merge!(:notify => message_notification)
|
45
|
+
@send_options
|
46
|
+
end
|
47
|
+
|
48
|
+
def deployment_name
|
49
|
+
if branch
|
50
|
+
"#{application}/#{branch}"
|
51
|
+
else
|
52
|
+
application
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def message_color
|
57
|
+
fetch(:hipchat_color, nil)
|
58
|
+
end
|
59
|
+
|
60
|
+
def failed_message_color
|
61
|
+
fetch(:hipchat_failed_color, "red")
|
62
|
+
end
|
63
|
+
|
64
|
+
def message_notification
|
65
|
+
fetch(:hipchat_announce, false)
|
66
|
+
end
|
67
|
+
|
68
|
+
def deploy_user
|
69
|
+
fetch(:hipchat_deploy_user, "Deploy")
|
70
|
+
end
|
71
|
+
|
72
|
+
def human
|
73
|
+
ENV['HIPCHAT_USER'] ||
|
74
|
+
fetch(:hipchat_human,
|
75
|
+
if (u = %x{git config user.name}.strip) != ""
|
76
|
+
u
|
77
|
+
elsif (u = ENV['USER']) != ""
|
78
|
+
u
|
79
|
+
else
|
80
|
+
"Someone"
|
81
|
+
end)
|
82
|
+
end
|
83
|
+
|
84
|
+
def env
|
85
|
+
fetch(:hipchat_env, fetch(:rack_env, fetch(:rails_env, "production")))
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
before "hipchat:notify_deploy_started", "hipchat:set_client"
|
90
|
+
before "deploy", "hipchat:trigger_notification"
|
91
|
+
before "deploy:migrations", "hipchat:trigger_notification", "hipchat:configure_for_migrations"
|
92
|
+
before "deploy:update_code", "hipchat:notify_deploy_started"
|
93
|
+
after "deploy", "hipchat:notify_deploy_finished"
|
94
|
+
after "deploy:migrations", "hipchat:notify_deploy_finished"
|
95
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'hipchat2'
|
2
|
+
|
3
|
+
#
|
4
|
+
# Provides a Chef exception handler so you can send information about
|
5
|
+
# chef-client failures to a HipChat room.
|
6
|
+
#
|
7
|
+
# Docs: http://wiki.opscode.com/display/chef/Exception+and+Report+Handlers
|
8
|
+
#
|
9
|
+
# Install - add the following to your client.rb:
|
10
|
+
# require 'hipchat/chef'
|
11
|
+
# hipchat_handler = HipChat::NotifyRoom.new("<api token>", "<room name>")
|
12
|
+
# exception_handlers << hipchat_handler
|
13
|
+
#
|
14
|
+
|
15
|
+
module HipChat2
|
16
|
+
class NotifyRoom < Chef::Handler
|
17
|
+
|
18
|
+
def initialize(api_token, room_name, notify_users=false)
|
19
|
+
@api_token = api_token
|
20
|
+
@room_name = room_name
|
21
|
+
@notify_users = notify_users
|
22
|
+
end
|
23
|
+
|
24
|
+
def report
|
25
|
+
msg = "Failure on #{node.name}: #{run_status.formatted_exception}"
|
26
|
+
|
27
|
+
client = HipChat2::Client.new(@api_token)
|
28
|
+
client[@room_name].send('Chef', msg, :notify => @notify_users)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'hipchat2'
|
2
|
+
|
3
|
+
namespace :hipchat do
|
4
|
+
desc "Sends a HipChat message as a particular user"
|
5
|
+
task :send do
|
6
|
+
required_options = [:message, :room, :token, :user]
|
7
|
+
config_file = Rails.root.join 'config', 'hipchat.yml'
|
8
|
+
|
9
|
+
options = {
|
10
|
+
:message => ENV['MESSAGE'],
|
11
|
+
:user => ENV['HIPCHAT_USER'],
|
12
|
+
:notify => ENV['NOTIFY'],
|
13
|
+
:room => ENV['ROOM'],
|
14
|
+
:token => ENV['TOKEN']
|
15
|
+
}.reject { |k, v| v.blank? }
|
16
|
+
|
17
|
+
system_options = {
|
18
|
+
:user => ENV['USER']
|
19
|
+
}.reject { |k, v| v.blank? }
|
20
|
+
|
21
|
+
if File.exists? config_file
|
22
|
+
options.reverse_merge! YAML.load_file(config_file).symbolize_keys
|
23
|
+
end
|
24
|
+
|
25
|
+
options.reverse_merge! system_options
|
26
|
+
|
27
|
+
options[:notify] = options[:notify].to_s != 'false'
|
28
|
+
|
29
|
+
if (missing_options = required_options - options.keys).size > 0
|
30
|
+
puts "HipChat needs #{missing_options.to_sentence} to send!"
|
31
|
+
exit
|
32
|
+
end
|
33
|
+
|
34
|
+
client = HipChat2::Client.new(options[:token])
|
35
|
+
|
36
|
+
client[options[:room]].send(options[:user], options[:message], :notify => options[:notify])
|
37
|
+
end
|
38
|
+
end
|
data/lib/hipchat2.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
require 'hipchat/railtie' if defined?(Rails::Railtie)
|
5
|
+
|
6
|
+
module HipChat2
|
7
|
+
class UnknownRoom < StandardError; end
|
8
|
+
class Unauthorized < StandardError; end
|
9
|
+
class UnknownResponseCode < StandardError; end
|
10
|
+
|
11
|
+
class Client
|
12
|
+
|
13
|
+
def initialize(token)
|
14
|
+
@token = token
|
15
|
+
end
|
16
|
+
|
17
|
+
def [](name)
|
18
|
+
Room.new(@token, :room_id => name)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
class Room < OpenStruct
|
24
|
+
include HTTParty
|
25
|
+
|
26
|
+
base_uri 'https://api.hipchat.com/v2/room'
|
27
|
+
|
28
|
+
def initialize(token, params)
|
29
|
+
@token = token
|
30
|
+
|
31
|
+
super(params)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Send a message to this room.
|
35
|
+
#
|
36
|
+
# Usage:
|
37
|
+
#
|
38
|
+
# # Default
|
39
|
+
# send 'nickname', 'some message'
|
40
|
+
#
|
41
|
+
# # Notify users and color the message red
|
42
|
+
# send 'nickname', 'some message', :notify => true, :color => 'red'
|
43
|
+
#
|
44
|
+
# # Notify users (deprecated)
|
45
|
+
# send 'nickname', 'some message', true
|
46
|
+
#
|
47
|
+
# Options:
|
48
|
+
#
|
49
|
+
# +color+:: "yellow", "red", "green", "purple", or "random"
|
50
|
+
# (default "yellow")
|
51
|
+
# +notify+:: true or false
|
52
|
+
# (default false)
|
53
|
+
def send(from, message, options_or_notify = {})
|
54
|
+
options = if options_or_notify == true or options_or_notify == false
|
55
|
+
warn "DEPRECATED: Specify notify flag as an option (e.g., :notify => true)"
|
56
|
+
{ :notify => options_or_notify }
|
57
|
+
else
|
58
|
+
options_or_notify || {}
|
59
|
+
end
|
60
|
+
|
61
|
+
options = { :color => 'yellow', :notify => false }.merge options
|
62
|
+
|
63
|
+
response = self.class.post("/#{room_id}/notification",
|
64
|
+
:headers => { 'Content-type' => 'application/json' },
|
65
|
+
:query => { :auth_token => @token },
|
66
|
+
:body => {
|
67
|
+
:message => message,
|
68
|
+
:notify => options[:notify],
|
69
|
+
:color => options[:color]
|
70
|
+
}.to_json
|
71
|
+
)
|
72
|
+
|
73
|
+
case response.code
|
74
|
+
when 200, 204 then true
|
75
|
+
when 404
|
76
|
+
raise UnknownRoom, "Unknown room: `#{room_id}'"
|
77
|
+
when 401
|
78
|
+
raise Unauthorized, "Access denied to room `#{room_id}'"
|
79
|
+
else
|
80
|
+
raise UnknownResponseCode, "Unexpected #{response.code} for room `#{room_id}'"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe HipChat2 do
|
4
|
+
subject { HipChat2::Client.new("blah") }
|
5
|
+
|
6
|
+
let(:room_name) { "Hipchat"}
|
7
|
+
let(:room) { subject[room_name] }
|
8
|
+
|
9
|
+
# Helper for mocking room message post requests
|
10
|
+
def mock_successful_send(from, message, options={})
|
11
|
+
options = {:color => 'yellow', :notify => false}.merge(options)
|
12
|
+
mock(HipChat2::Room).post("/#{room_name}/notification",
|
13
|
+
|
14
|
+
:headers => { 'Content-type' => 'application/json' },
|
15
|
+
:query => { :auth_token => 'blah' },
|
16
|
+
:body => {
|
17
|
+
:message => message,
|
18
|
+
:notify => options[:notify],
|
19
|
+
:color => options[:color]
|
20
|
+
}.to_json
|
21
|
+
) {
|
22
|
+
OpenStruct.new(:code => 200)
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "sends a message to a room" do
|
27
|
+
it "successfully without custom options" do
|
28
|
+
mock_successful_send 'Dude', 'Hello world'
|
29
|
+
|
30
|
+
room.send("Dude", "Hello world").should be_true
|
31
|
+
end
|
32
|
+
|
33
|
+
it "successfully with notifications on as option" do
|
34
|
+
mock_successful_send 'Dude', 'Hello world', :notify => true
|
35
|
+
|
36
|
+
room.send("Dude", "Hello world", :notify => true).should be_true
|
37
|
+
end
|
38
|
+
|
39
|
+
it "successfully with custom color" do
|
40
|
+
mock_successful_send 'Dude', 'Hello world', :color => 'red'
|
41
|
+
|
42
|
+
room.send("Dude", "Hello world", :color => 'red').should be_true
|
43
|
+
end
|
44
|
+
|
45
|
+
it "but fails when the room doesn't exist" do
|
46
|
+
mock(HipChat2::Room).post(anything, anything) {
|
47
|
+
OpenStruct.new(:code => 404)
|
48
|
+
}
|
49
|
+
|
50
|
+
lambda { room.send "", "" }.should raise_error(HipChat2::UnknownRoom)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "but fails when we're not allowed to do so" do
|
54
|
+
mock(HipChat2::Room).post(anything, anything) {
|
55
|
+
OpenStruct.new(:code => 401)
|
56
|
+
}
|
57
|
+
|
58
|
+
lambda { room.send "", "" }.should raise_error(HipChat2::Unauthorized)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "but fails if we get an unknown response code" do
|
62
|
+
mock(HipChat2::Room).post(anything, anything) {
|
63
|
+
OpenStruct.new(:code => 403)
|
64
|
+
}
|
65
|
+
|
66
|
+
lambda { room.send "", "" }.
|
67
|
+
should raise_error(HipChat2::UnknownResponseCode)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hipchat2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- MojoTech
|
8
|
+
- Dmitry Rybakov
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-11-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: httparty
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rspec
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '2.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ~>
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '2.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rr
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ~>
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '1.0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '1.0'
|
56
|
+
description: Ruby library to interact with HipChat
|
57
|
+
email: dmitry.rybakov@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files:
|
61
|
+
- LICENSE
|
62
|
+
- README.md
|
63
|
+
files:
|
64
|
+
- .document
|
65
|
+
- LICENSE
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- VERSION
|
69
|
+
- hipchat2.gemspec
|
70
|
+
- lib/hipchat2.rb
|
71
|
+
- lib/hipchat2/capistrano.rb
|
72
|
+
- lib/hipchat2/chef.rb
|
73
|
+
- lib/hipchat2/rails3_tasks.rb
|
74
|
+
- lib/hipchat2/railtie.rb
|
75
|
+
- spec/hipchat2_spec.rb
|
76
|
+
- spec/spec.opts
|
77
|
+
- spec/spec_helper.rb
|
78
|
+
homepage: http://github.com/comandeo/hipchat
|
79
|
+
licenses: []
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.0.6
|
98
|
+
signing_key:
|
99
|
+
specification_version: 3
|
100
|
+
summary: Ruby library to interact with HipChat
|
101
|
+
test_files: []
|
102
|
+
has_rdoc:
|