hipchat 0.4.0 → 0.4.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.
- data/README.textile +9 -4
- data/VERSION +1 -1
- data/hipchat.gemspec +2 -2
- data/lib/hipchat.rb +45 -12
- data/lib/hipchat/capistrano.rb +11 -3
- data/spec/hipchat_spec.rb +41 -10
- metadata +8 -8
data/README.textile
CHANGED
@@ -5,8 +5,13 @@ A very basic wrapper for the HipChat HTTP API.
|
|
5
5
|
h2. Usage
|
6
6
|
|
7
7
|
bc.. client = HipChat::Client.new(api_token)
|
8
|
-
|
9
|
-
|
8
|
+
client['my room'].send('username', 'I talk')
|
9
|
+
|
10
|
+
# Send notifications to users (default false)
|
11
|
+
client['my room'].send('username', 'I quit!', :notify => true)
|
12
|
+
|
13
|
+
# Color it red. or "yellow", "green", "purple", "random" (default "yellow")
|
14
|
+
client['my room'].send('username', 'Build failed!', :color => 'red')
|
10
15
|
|
11
16
|
h2. Capistrano
|
12
17
|
|
@@ -47,13 +52,13 @@ Use a "deploy hook":http://bit.ly/qnbIkP to send messages from Engine Yard's Clo
|
|
47
52
|
RAILS_ROOT/deploy/after_restart.rb:
|
48
53
|
|
49
54
|
bc.. on_app_master do
|
50
|
-
message = "Deploying revision #{@configuration[:revision]}"
|
55
|
+
message = "Deploying revision #{@configuration[:revision][0...6]}"
|
51
56
|
message += " to #{@configuration[:environment]}"
|
52
57
|
message += " (with migrations)" if migrate?
|
53
58
|
message += "."
|
54
59
|
|
55
60
|
# Send a message via rake task assuming a hipchat.yml in your config like above
|
56
|
-
run "cd #{release_path} && rake hipchat:send MESSAGE
|
61
|
+
run "cd #{release_path} && rake hipchat:send MESSAGE='#{message}'"
|
57
62
|
end
|
58
63
|
|
59
64
|
h2. Copyright
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.1
|
data/hipchat.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "hipchat"
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["MojoTech"]
|
12
|
-
s.date = "2011-10-
|
12
|
+
s.date = "2011-10-19"
|
13
13
|
s.description = "Ruby library to interact with HipChat"
|
14
14
|
s.email = "gems@mojotech.com"
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/hipchat.rb
CHANGED
@@ -39,21 +39,54 @@ module HipChat
|
|
39
39
|
super(params)
|
40
40
|
end
|
41
41
|
|
42
|
-
|
42
|
+
# Send a message to this room.
|
43
|
+
#
|
44
|
+
# Usage:
|
45
|
+
#
|
46
|
+
# # Default
|
47
|
+
# send 'nickname', 'some message'
|
48
|
+
#
|
49
|
+
# # Notify users and color the message red
|
50
|
+
# send 'nickname', 'some message', :notify => true, :color => 'red'
|
51
|
+
#
|
52
|
+
# # Notify users (deprecated)
|
53
|
+
# send 'nickname', 'some message', true
|
54
|
+
#
|
55
|
+
# Options:
|
56
|
+
#
|
57
|
+
# +color+:: "yellow", "red", "green", "purple", or "random"
|
58
|
+
# (default "yellow")
|
59
|
+
# +notify+:: true or false
|
60
|
+
# (default false)
|
61
|
+
def send(from, message, options_or_notify = false)
|
62
|
+
options = if options_or_notify == true or options_or_notify == false
|
63
|
+
warn "DEPRECATED: Specify notify flag as an option (e.g., :notify => true)"
|
64
|
+
{ :notify => options_or_notify }
|
65
|
+
else
|
66
|
+
options_or_notify || {}
|
67
|
+
end
|
68
|
+
|
69
|
+
options = { :color => 'yellow', :notify => false }.merge options
|
70
|
+
|
43
71
|
response = self.class.post('/message',
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
72
|
+
:query => { :auth_token => @token },
|
73
|
+
:body => {
|
74
|
+
:room_id => room_id,
|
75
|
+
:from => from,
|
76
|
+
:message => message,
|
77
|
+
:color => options[:color],
|
78
|
+
:notify => options[:notify] ? 1 : 0
|
79
|
+
}
|
80
|
+
)
|
49
81
|
|
50
82
|
case response.code
|
51
|
-
when 200;
|
52
|
-
when 404
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
83
|
+
when 200; true
|
84
|
+
when 404
|
85
|
+
raise UnknownRoom, "Unknown room: `#{room_id}'"
|
86
|
+
when 401
|
87
|
+
raise Unauthorized, "Access denied to room `#{room_id}'"
|
88
|
+
else
|
89
|
+
raise UnknownResponseCode, "Unexpected #{response.code} for room `#{room_id}'"
|
57
90
|
end
|
58
91
|
end
|
59
92
|
end
|
data/lib/hipchat/capistrano.rb
CHANGED
@@ -21,10 +21,10 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
21
21
|
if hipchat_send_notification
|
22
22
|
on_rollback do
|
23
23
|
hipchat_client[hipchat_room_name].
|
24
|
-
send(deploy_user, "#{human} cancelled deployment of #{
|
24
|
+
send(deploy_user, "#{human} cancelled deployment of #{deployment_name} to #{env}.", hipchat_announce)
|
25
25
|
end
|
26
26
|
|
27
|
-
message = "#{human} is deploying #{
|
27
|
+
message = "#{human} is deploying #{deployment_name} to #{env}"
|
28
28
|
message << " (with migrations)" if hipchat_with_migrations
|
29
29
|
message << "."
|
30
30
|
|
@@ -35,9 +35,17 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
35
35
|
|
36
36
|
task :notify_deploy_finished do
|
37
37
|
hipchat_client[hipchat_room_name].
|
38
|
-
send(deploy_user, "#{human} finished deploying #{
|
38
|
+
send(deploy_user, "#{human} finished deploying #{deployment_name} to #{env}.", hipchat_announce)
|
39
39
|
end
|
40
40
|
|
41
|
+
def deployment_name
|
42
|
+
if branch
|
43
|
+
"#{application}/#{branch}"
|
44
|
+
else
|
45
|
+
application
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
41
49
|
def deploy_user
|
42
50
|
fetch(:hipchat_deploy_user, "Deploy")
|
43
51
|
end
|
data/spec/hipchat_spec.rb
CHANGED
@@ -4,21 +4,52 @@ describe HipChat do
|
|
4
4
|
subject { HipChat::Client.new("blah") }
|
5
5
|
|
6
6
|
let(:room) { subject["Hipchat"] }
|
7
|
+
|
8
|
+
# Helper for mocking room message post requests
|
9
|
+
def mock_successful_send(from, message, options={})
|
10
|
+
options = {:color => 'yellow', :notify => 0}.merge(options)
|
11
|
+
mock(HipChat::Room).post("/message",
|
12
|
+
:query => {:auth_token => "blah"},
|
13
|
+
:body => {:room_id => "Hipchat",
|
14
|
+
:from => "Dude",
|
15
|
+
:message => "Hello world",
|
16
|
+
:color => options[:color],
|
17
|
+
:notify => options[:notify]}) {
|
18
|
+
OpenStruct.new(:code => 200)
|
19
|
+
}
|
20
|
+
end
|
7
21
|
|
8
22
|
describe "sends a message to a room" do
|
9
|
-
it "successfully" do
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
23
|
+
it "successfully without custom options" do
|
24
|
+
mock_successful_send 'Dude', 'Hello world'
|
25
|
+
|
26
|
+
room.send("Dude", "Hello world").should be_true
|
27
|
+
end
|
28
|
+
|
29
|
+
it "successfully with notifications on as boolean" do
|
30
|
+
mock_successful_send 'Dude', 'Hello world', :notify => 1
|
31
|
+
|
32
|
+
room.send("Dude", "Hello world", true).should be_true
|
33
|
+
end
|
34
|
+
|
35
|
+
it "successfully with notifications off as boolean" do
|
36
|
+
mock_successful_send 'Dude', 'Hello world', :notify => 0
|
37
|
+
|
38
|
+
room.send("Dude", "Hello world", false).should be_true
|
39
|
+
end
|
40
|
+
|
41
|
+
it "successfully with notifications on as option" do
|
42
|
+
mock_successful_send 'Dude', 'Hello world', :notify => 1
|
18
43
|
|
19
|
-
room.send
|
44
|
+
room.send("Dude", "Hello world", :notify => true).should be_true
|
20
45
|
end
|
46
|
+
|
47
|
+
it "successfully with custom color" do
|
48
|
+
mock_successful_send 'Dude', 'Hello world', :color => 'red'
|
21
49
|
|
50
|
+
room.send("Dude", "Hello world", :color => 'red').should be_true
|
51
|
+
end
|
52
|
+
|
22
53
|
it "but fails when the room doesn't exist" do
|
23
54
|
mock(HipChat::Room).post(anything, anything) {
|
24
55
|
OpenStruct.new(:code => 404)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hipchat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-10-
|
12
|
+
date: 2011-10-19 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
16
|
-
requirement: &
|
16
|
+
requirement: &70228089062780 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70228089062780
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &70228089062160 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '2.0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70228089062160
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rr
|
38
|
-
requirement: &
|
38
|
+
requirement: &70228089061480 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '1.0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70228089061480
|
47
47
|
description: Ruby library to interact with HipChat
|
48
48
|
email: gems@mojotech.com
|
49
49
|
executables: []
|