hipchat 1.5.2 → 1.5.3
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 +4 -4
- data/.travis.yml +5 -0
- data/README.textile +14 -5
- data/hipchat.gemspec +2 -2
- data/lib/hipchat/api_version.rb +83 -1
- data/lib/hipchat/capistrano/tasks/hipchat.rake +10 -3
- data/lib/hipchat/client.rb +27 -23
- data/lib/hipchat/errors.rb +47 -8
- data/lib/hipchat/room.rb +198 -83
- data/lib/hipchat/user.rb +32 -32
- data/lib/hipchat/version.rb +1 -1
- data/spec/hipchat_api_v1_spec.rb +49 -5
- data/spec/hipchat_api_v2_spec.rb +291 -7
- data/spec/hipchat_spec.rb +5 -0
- data/spec/support/shared_contexts_for_hipchat.rb +156 -1
- metadata +8 -8
data/spec/hipchat_spec.rb
CHANGED
@@ -54,6 +54,11 @@ describe HipChat do
|
|
54
54
|
client = HipChat::Client.new("blah", :api_version => 'v2')
|
55
55
|
expect(client[:example].api_version).to eql('v2')
|
56
56
|
end
|
57
|
+
|
58
|
+
it "when given '2' it raises an exception" do
|
59
|
+
expect { HipChat::Client.new("blah", :api_version => '2') }.
|
60
|
+
to raise_error(HipChat::InvalidApiVersion)
|
61
|
+
end
|
57
62
|
end
|
58
63
|
|
59
64
|
context "server_url" do
|
@@ -49,6 +49,7 @@ shared_context "HipChatV1" do
|
|
49
49
|
:timezone => options[:timezone],
|
50
50
|
:'max-results' => options[:'max-results'],
|
51
51
|
:'start-index' => options[:'start-index'],
|
52
|
+
:'end-date' => options[:'end-date'],
|
52
53
|
:format => options[:format]}).to_return(canned_response)
|
53
54
|
end
|
54
55
|
|
@@ -63,10 +64,50 @@ shared_context "HipChatV1" do
|
|
63
64
|
:body => '{"room": {"room_id": "1234", "name" : "A Room"}}',
|
64
65
|
:headers => {})
|
65
66
|
end
|
67
|
+
|
68
|
+
def mock_successful_user_creation(name, email, options={})
|
69
|
+
stub_request(:post, "https://api.hipchat.com/v1/users/create").with(
|
70
|
+
:query => {:auth_token => "blah"},
|
71
|
+
:body => { :name => "A User", :email => "email@example.com" }.merge(options),
|
72
|
+
:headers => {'Accept' => 'application/json',
|
73
|
+
'Content-Type' => 'application/x-www-form-urlencoded'}).to_return(
|
74
|
+
:status => 200,
|
75
|
+
:body => '{"user": {"user_id": "1234", "A User" : "A User", "email" : "email@example.com"}}',
|
76
|
+
:headers => {})
|
77
|
+
end
|
78
|
+
|
79
|
+
def mock_successful_delete_room(room_id="1234")
|
80
|
+
stub_request(:post, "https://api.hipchat.com/v1/rooms/delete").with(
|
81
|
+
:query => {:auth_token => "blah", :room_id => room_id},
|
82
|
+
:headers => {"Accept" => "application/json",
|
83
|
+
"Content-Type" => "application/x-www-form-urlencoded"}).to_return(
|
84
|
+
:status => 204,
|
85
|
+
:body => "",
|
86
|
+
:headers => {})
|
87
|
+
end
|
88
|
+
|
89
|
+
def mock_delete_missing_room(room_id="1234")
|
90
|
+
stub_request(:post, "https://api.hipchat.com/v1/rooms/delete").with(
|
91
|
+
:query => {:auth_token => "blah", :room_id => room_id},
|
92
|
+
:headers => {"Accept" => "application/json",
|
93
|
+
"Content-Type" => "application/x-www-form-urlencoded"}).to_return(
|
94
|
+
:status => 404,
|
95
|
+
:body => "",
|
96
|
+
:headers => {})
|
97
|
+
|
98
|
+
end
|
66
99
|
end
|
67
100
|
|
68
101
|
shared_context "HipChatV2" do
|
69
102
|
before { @api_version = 'v2'}
|
103
|
+
def mock_successful_send_message(message)
|
104
|
+
stub_request(:post, "https://api.hipchat.com/v2/room/Hipchat/message").with(
|
105
|
+
:query => {:auth_token => "blah"},
|
106
|
+
:body => {:room_id => "Hipchat",
|
107
|
+
:message => "Hello world"}.to_json,
|
108
|
+
:headers => {'Accept' => 'application/json',
|
109
|
+
'Content-Type' => 'application/json'}).to_return(:status => 200, :body => "", :headers => {})
|
110
|
+
end
|
70
111
|
# Helper for mocking room message post requests
|
71
112
|
def mock_successful_send(from, message, options={})
|
72
113
|
options = {:color => 'yellow', :notify => false, :message_format => 'html'}.merge(options)
|
@@ -82,6 +123,17 @@ shared_context "HipChatV2" do
|
|
82
123
|
'Content-Type' => 'application/json'}).to_return(:status => 200, :body => "", :headers => {})
|
83
124
|
end
|
84
125
|
|
126
|
+
def mock_successful_link_share(from, message, link)
|
127
|
+
stub_request(:post, "https://api.hipchat.com/v2/room/Hipchat/share/link").with(
|
128
|
+
:query => {:auth_token => "blah"},
|
129
|
+
:body => {:room_id => "Hipchat",
|
130
|
+
:from => "Dude",
|
131
|
+
:message => message,
|
132
|
+
:link => link}.to_json,
|
133
|
+
:headers => {'Accept' => 'application/json',
|
134
|
+
'Content-Type' => 'application/json'}).to_return(:status => 200, :body => "", :headers => {})
|
135
|
+
end
|
136
|
+
|
85
137
|
def mock_successful_file_send(from, message, file)
|
86
138
|
stub_request(:post, "https://api.hipchat.com/v2/room/Hipchat/share/file").with(
|
87
139
|
:query => {:auth_token => "blah"},
|
@@ -90,6 +142,21 @@ shared_context "HipChatV2" do
|
|
90
142
|
'Content-Type' => 'multipart/related; boundary=sendfileboundary'}).to_return(:status => 200, :body => "", :headers => {})
|
91
143
|
end
|
92
144
|
|
145
|
+
def mock_successful_send_card(from, message, card)
|
146
|
+
options = {:color => 'yellow', :notify => false, :message_format => 'html'}
|
147
|
+
stub_request(:post, "https://api.hipchat.com/v2/room/Hipchat/notification").with(
|
148
|
+
:query => {:auth_token => "blah"},
|
149
|
+
:body => {:room_id => "Hipchat",
|
150
|
+
:from => "Dude",
|
151
|
+
:message => "Hello world",
|
152
|
+
:message_format => options[:message_format],
|
153
|
+
:color => options[:color],
|
154
|
+
:card => card,
|
155
|
+
:notify => options[:notify]}.to_json,
|
156
|
+
:headers => {'Accept' => 'application/json',
|
157
|
+
'Content-Type' => 'application/json'}).to_return(:status => 200, :body => "", :headers => {})
|
158
|
+
end
|
159
|
+
|
93
160
|
def mock_successful_topic_change(topic, options={})
|
94
161
|
options = {:from => 'API'}.merge(options)
|
95
162
|
stub_request(:put, "https://api.hipchat.com/v2/room/Hipchat/topic").with(
|
@@ -121,6 +188,7 @@ shared_context "HipChatV2" do
|
|
121
188
|
:timezone => options[:timezone],
|
122
189
|
:'max-results' => options[:'max-results'],
|
123
190
|
:'start-index' => options[:'start-index'],
|
191
|
+
:'end-date' => options[:'end-date'],
|
124
192
|
:format => options[:format]}).to_return(canned_response)
|
125
193
|
end
|
126
194
|
|
@@ -146,6 +214,18 @@ shared_context "HipChatV2" do
|
|
146
214
|
:headers => {})
|
147
215
|
end
|
148
216
|
|
217
|
+
def mock_successful_user_creation(name, email, options={})
|
218
|
+
stub_request(:post, "https://api.hipchat.com/v2/user").with(
|
219
|
+
:query => {:auth_token => "blah"},
|
220
|
+
:body => { :name => name, :email => email }.merge(options).to_json,
|
221
|
+
:headers => {'Accept' => 'application/json',
|
222
|
+
'Content-Type' => 'application/json'}).to_return(
|
223
|
+
:status => 201,
|
224
|
+
:body => '{"id": "12345", "links": {"self": "https://api.hipchat.com/v2/user/12345"}}',
|
225
|
+
:headers => {})
|
226
|
+
end
|
227
|
+
|
228
|
+
|
149
229
|
def mock_successful_get_room(room_id="1234")
|
150
230
|
stub_request(:get, "https://api.hipchat.com/v2/room/#{room_id}").with(
|
151
231
|
:query => {:auth_token => "blah"},
|
@@ -172,6 +252,26 @@ shared_context "HipChatV2" do
|
|
172
252
|
:headers => {})
|
173
253
|
end
|
174
254
|
|
255
|
+
def mock_successful_delete_room(room_id="1234")
|
256
|
+
stub_request(:delete, "https://api.hipchat.com/v2/room/#{room_id}").with(
|
257
|
+
:query => {:auth_token => "blah"},
|
258
|
+
:headers => {"Accept" => "application/json",
|
259
|
+
"Content-Type" => "application/json"}).to_return(
|
260
|
+
:status => 204,
|
261
|
+
:body => "",
|
262
|
+
:headers => {})
|
263
|
+
end
|
264
|
+
|
265
|
+
def mock_delete_missing_room(room_id="1234")
|
266
|
+
stub_request(:delete, "https://api.hipchat.com/v2/room/#{room_id}").with(
|
267
|
+
:query => {:auth_token => "blah"},
|
268
|
+
:headers => {"Accept" => "application/json",
|
269
|
+
"Content-Type" => "application/json"}).to_return(
|
270
|
+
:status => 404,
|
271
|
+
:body => "",
|
272
|
+
:headers => {})
|
273
|
+
end
|
274
|
+
|
175
275
|
def mock_successful_invite(options={})
|
176
276
|
options = {:user_id => "1234"}.merge(options)
|
177
277
|
stub_request(:post, "https://api.hipchat.com/v2/room/Hipchat/invite/#{options[:user_id]}").with(
|
@@ -186,11 +286,26 @@ shared_context "HipChatV2" do
|
|
186
286
|
:headers => {})
|
187
287
|
end
|
188
288
|
|
289
|
+
def mock_successful_add_member(options={})
|
290
|
+
options = {:user_id => "1234"}.merge(options)
|
291
|
+
stub_request(:put, "https://api.hipchat.com/v2/room/Hipchat/member/#{options[:user_id]}").with(
|
292
|
+
:query => {:auth_token => "blah"},
|
293
|
+
:body => {
|
294
|
+
:room_roles => options[:room_roles] || ["room_member"]
|
295
|
+
}.to_json,
|
296
|
+
:headers => {'Accept' => 'application/json',
|
297
|
+
'Content-Type' => 'application/json'}).to_return(
|
298
|
+
:status => 204,
|
299
|
+
:body => "",
|
300
|
+
:headers => {})
|
301
|
+
end
|
302
|
+
|
189
303
|
def mock_successful_user_send(message)
|
190
304
|
stub_request(:post, "https://api.hipchat.com/v2/user/12345678/message").with(
|
191
305
|
:query => {:auth_token => "blah"},
|
192
306
|
:body => {:message => "Equal bytes for everyone",
|
193
|
-
:message_format => "text"
|
307
|
+
:message_format => "text",
|
308
|
+
:notify => false},
|
194
309
|
:headers => {'Accept' => 'application/json',
|
195
310
|
'Content-Type' => 'application/json'}).to_return(:status => 200, :body => "", :headers => {})
|
196
311
|
end
|
@@ -210,4 +325,44 @@ shared_context "HipChatV2" do
|
|
210
325
|
:headers => {'Accept' => 'application/json',
|
211
326
|
'Content-Type' => 'multipart/related; boundary=sendfileboundary'}).to_return(:status => 200, :body => "", :headers => {})
|
212
327
|
end
|
328
|
+
|
329
|
+
def mock_successful_create_webhook(room_id, url, event, options = {})
|
330
|
+
options = {:pattern => '', :name => ''}.merge(options)
|
331
|
+
stub_request(:post, "https://api.hipchat.com/v2/room/#{room_id}/webhook").with(
|
332
|
+
:query => {:auth_token => "blah"},
|
333
|
+
:body => {:url => url,
|
334
|
+
:pattern => options[:pattern],
|
335
|
+
:event => event,
|
336
|
+
:name => options[:name]}.to_json,
|
337
|
+
:headers => {'Accept' => 'application/json',
|
338
|
+
'Content-Type' => 'application/json'}).to_return(:status => 201,
|
339
|
+
:body => {:id => '1234', :links => {:self => "https://api.hipchat.com/v2/room/#{room_id}/webhook/1234"}}.to_json,
|
340
|
+
:headers => {})
|
341
|
+
end
|
342
|
+
|
343
|
+
def mock_successful_delete_webhook(room_id, webhook_id)
|
344
|
+
stub_request(:delete, "https://api.hipchat.com/v2/room/#{room_id}/webhook/#{webhook_id}").with(
|
345
|
+
:query => {:auth_token => "blah"},
|
346
|
+
:headers => {'Accept' => 'application/json',
|
347
|
+
'Content-Type' => 'application/json'}).to_return(:status => 204, :headers => {})
|
348
|
+
end
|
349
|
+
|
350
|
+
def mock_successful_get_all_webhooks(room_id, options = {})
|
351
|
+
options = {:'start-index' => 0, :'max-results' => 100}.merge(options)
|
352
|
+
stub_request(:get, "https://api.hipchat.com/v2/room/#{room_id}/webhook").with(
|
353
|
+
:query => {:auth_token => "blah", :'start-index' => options[:'start-index'], :'max-results' => options[:'max-results']},
|
354
|
+
:headers => {'Accept' => 'application/json',
|
355
|
+
'Content-Type' => 'application/json'}).to_return(:status => 200,
|
356
|
+
:body => {:items => [], :startIndex => 0, :maxResults => 100, :links => {:self => "https://api.hipchat.com/v2/room/#{room_id}/webhook"}}.to_json,
|
357
|
+
:headers => {})
|
358
|
+
end
|
359
|
+
|
360
|
+
def mock_successful_get_webhook(room_id, webhook_id)
|
361
|
+
stub_request(:get, "https://api.hipchat.com/v2/room/#{room_id}/webhook/#{webhook_id}").with(
|
362
|
+
:query => {:auth_token => "blah"},
|
363
|
+
:headers => {'Accept' => 'application/json',
|
364
|
+
'Content-Type' => 'application/json'}).to_return(:status => 200,
|
365
|
+
:body => {:room => nil, :links => {:self => "https://api.hipchat.com/v2/room/#{room_id}/webhook/#{webhook_id}"}, :creator => nil, :url => 'http://example.org/webhook', :created => '2014-09-02T21:33:54+00:00', :event => 'room_deleted'}.to_json,
|
366
|
+
:headers => {})
|
367
|
+
end
|
213
368
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hipchat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- HipChat/Atlassian
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 1.11.1
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 1.11.1
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rake
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -98,16 +98,16 @@ dependencies:
|
|
98
98
|
name: webmock
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - '='
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
103
|
+
version: 1.22.1
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - '='
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
110
|
+
version: 1.22.1
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: rdoc
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|