hipchat 1.0.1 → 1.1.0
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/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +1 -0
- data/README.textile +25 -1
- data/lib/hipchat.rb +4 -206
- data/lib/hipchat/api_version.rb +80 -14
- data/lib/hipchat/capistrano2.rb +41 -1
- data/lib/hipchat/client.rb +111 -0
- data/lib/hipchat/errors.rb +10 -0
- data/lib/hipchat/rails3_tasks.rb +2 -1
- data/lib/hipchat/room.rb +193 -0
- data/lib/hipchat/user.rb +62 -0
- data/lib/hipchat/version.rb +1 -1
- data/spec/hipchat_api_v1_spec.rb +172 -0
- data/spec/hipchat_api_v2_spec.rb +217 -0
- data/spec/hipchat_spec.rb +0 -271
- data/spec/spec_helper.rb +3 -0
- data/spec/{shared_hipchat.rb → support/shared_contexts_for_hipchat.rb} +58 -7
- metadata +15 -6
@@ -0,0 +1,217 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "HipChat (API V2)" do
|
4
|
+
|
5
|
+
subject { HipChat::Client.new("blah", :api_version => @api_version) }
|
6
|
+
|
7
|
+
let(:room) { subject["Hipchat"] }
|
8
|
+
let(:user) { subject.user "12345678" }
|
9
|
+
|
10
|
+
describe "#history" do
|
11
|
+
include_context "HipChatV2"
|
12
|
+
it "is successful without custom options" do
|
13
|
+
mock_successful_history()
|
14
|
+
|
15
|
+
room.history().should be_true
|
16
|
+
end
|
17
|
+
|
18
|
+
it "is successful with custom options" do
|
19
|
+
mock_successful_history(:timezone => 'America/Los_Angeles', :date => '2010-11-19')
|
20
|
+
room.history(:timezone => 'America/Los_Angeles', :date => '2010-11-19').should be_true
|
21
|
+
end
|
22
|
+
|
23
|
+
it "fails when the room doen't exist" do
|
24
|
+
mock(HipChat::Room).get(anything, anything) {
|
25
|
+
OpenStruct.new(:code => 404)
|
26
|
+
}
|
27
|
+
|
28
|
+
lambda { room.history }.should raise_error(HipChat::UnknownRoom)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "fails when we're not allowed to do so" do
|
32
|
+
mock(HipChat::Room).get(anything, anything) {
|
33
|
+
OpenStruct.new(:code => 401)
|
34
|
+
}
|
35
|
+
|
36
|
+
lambda { room.history }.should raise_error(HipChat::Unauthorized)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "fails if we get an unknown response code" do
|
40
|
+
mock(HipChat::Room).get(anything, anything) {
|
41
|
+
OpenStruct.new(:code => 403)
|
42
|
+
}
|
43
|
+
|
44
|
+
lambda { room.history }.
|
45
|
+
should raise_error(HipChat::UnknownResponseCode)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#topic" do
|
50
|
+
include_context "HipChatV2"
|
51
|
+
it "is successful without custom options" do
|
52
|
+
mock_successful_topic_change("Nice topic")
|
53
|
+
|
54
|
+
room.topic("Nice topic").should be_true
|
55
|
+
end
|
56
|
+
|
57
|
+
it "is successful with a custom from" do
|
58
|
+
mock_successful_topic_change("Nice topic", :from => "Me")
|
59
|
+
|
60
|
+
room.topic("Nice topic", :from => "Me").should be_true
|
61
|
+
end
|
62
|
+
|
63
|
+
it "fails when the room doesn't exist" do
|
64
|
+
mock(HipChat::Room).put(anything, anything) {
|
65
|
+
OpenStruct.new(:code => 404)
|
66
|
+
}
|
67
|
+
|
68
|
+
lambda { room.topic "" }.should raise_error(HipChat::UnknownRoom)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "fails when we're not allowed to do so" do
|
72
|
+
mock(HipChat::Room).put(anything, anything) {
|
73
|
+
OpenStruct.new(:code => 401)
|
74
|
+
}
|
75
|
+
|
76
|
+
lambda { room.topic "" }.should raise_error(HipChat::Unauthorized)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "fails if we get an unknown response code" do
|
80
|
+
mock(HipChat::Room).put(anything, anything) {
|
81
|
+
OpenStruct.new(:code => 403)
|
82
|
+
}
|
83
|
+
|
84
|
+
lambda { room.topic "" }.
|
85
|
+
should raise_error(HipChat::UnknownResponseCode)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "#send" do
|
90
|
+
include_context "HipChatV2"
|
91
|
+
it "successfully without custom options" do
|
92
|
+
mock_successful_send 'Dude', 'Hello world'
|
93
|
+
|
94
|
+
room.send("Dude", "Hello world").should be_true
|
95
|
+
end
|
96
|
+
|
97
|
+
it "successfully with notifications on as option" do
|
98
|
+
mock_successful_send 'Dude', 'Hello world', :notify => true
|
99
|
+
|
100
|
+
room.send("Dude", "Hello world", :notify => true).should be_true
|
101
|
+
end
|
102
|
+
|
103
|
+
it "successfully with custom color" do
|
104
|
+
mock_successful_send 'Dude', 'Hello world', :color => 'red'
|
105
|
+
|
106
|
+
room.send("Dude", "Hello world", :color => 'red').should be_true
|
107
|
+
end
|
108
|
+
|
109
|
+
it "successfully with text message_format" do
|
110
|
+
mock_successful_send 'Dude', 'Hello world', :message_format => 'text'
|
111
|
+
|
112
|
+
room.send("Dude", "Hello world", :message_format => 'text').should be_true
|
113
|
+
end
|
114
|
+
|
115
|
+
it "but fails when the room doesn't exist" do
|
116
|
+
mock(HipChat::Room).post(anything, anything) {
|
117
|
+
OpenStruct.new(:code => 404)
|
118
|
+
}
|
119
|
+
|
120
|
+
lambda { room.send "", "" }.should raise_error(HipChat::UnknownRoom)
|
121
|
+
end
|
122
|
+
|
123
|
+
it "but fails when we're not allowed to do so" do
|
124
|
+
mock(HipChat::Room).post(anything, anything) {
|
125
|
+
OpenStruct.new(:code => 401)
|
126
|
+
}
|
127
|
+
|
128
|
+
lambda { room.send "", "" }.should raise_error(HipChat::Unauthorized)
|
129
|
+
end
|
130
|
+
|
131
|
+
it "but fails if the username is more than 15 chars" do
|
132
|
+
lambda { room.send "a very long username here", "a message" }.should raise_error(HipChat::UsernameTooLong)
|
133
|
+
end
|
134
|
+
|
135
|
+
it "but fails if we get an unknown response code" do
|
136
|
+
mock(HipChat::Room).post(anything, anything) {
|
137
|
+
OpenStruct.new(:code => 403)
|
138
|
+
}
|
139
|
+
|
140
|
+
lambda { room.send "", "" }.
|
141
|
+
should raise_error(HipChat::UnknownResponseCode)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
describe "#create" do
|
146
|
+
include_context "HipChatV2"
|
147
|
+
|
148
|
+
it "successfully with room name" do
|
149
|
+
mock_successful_room_creation("A Room")
|
150
|
+
|
151
|
+
subject.create_room("A Room").should be_true
|
152
|
+
end
|
153
|
+
|
154
|
+
it "successfully with custom parameters" do
|
155
|
+
mock_successful_room_creation("A Room", {:owner_user_id => "123456", :privacy => "private", :guest_access => true})
|
156
|
+
|
157
|
+
subject.create_room("A Room", {:owner_user_id => "123456", :privacy => "private", :guest_access =>true}).should be_true
|
158
|
+
end
|
159
|
+
|
160
|
+
it "but fail is name is longer then 50 char" do
|
161
|
+
lambda { subject.create_room("A Room that is too long that I should fail right now") }.
|
162
|
+
should raise_error(HipChat::RoomNameTooLong)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
describe "#get_room" do
|
167
|
+
include_context "HipChatV2"
|
168
|
+
|
169
|
+
it "successfully" do
|
170
|
+
mock_successful_get_room("Hipchat")
|
171
|
+
|
172
|
+
room.get_room.should be_true
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|
176
|
+
|
177
|
+
describe "#invite" do
|
178
|
+
include_context "HipChatV2"
|
179
|
+
|
180
|
+
it "successfully with user_id" do
|
181
|
+
mock_successful_invite()
|
182
|
+
|
183
|
+
room.invite("1234").should be_true
|
184
|
+
end
|
185
|
+
|
186
|
+
it "successfully with custom parameters" do
|
187
|
+
mock_successful_invite({:user_id => "321", :reason => "A great reason"})
|
188
|
+
|
189
|
+
room.invite("321", "A great reason").should be_true
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
describe "#send user message" do
|
194
|
+
include_context "HipChatV2"
|
195
|
+
it "successfully with a standard message" do
|
196
|
+
mock_successful_user_send 'Equal bytes for everyone'
|
197
|
+
|
198
|
+
user.send('Equal bytes for everyone').should be_true
|
199
|
+
end
|
200
|
+
|
201
|
+
it "but fails when the user doesn't exist" do
|
202
|
+
mock(HipChat::User).post(anything, anything) {
|
203
|
+
OpenStruct.new(:code => 404)
|
204
|
+
}
|
205
|
+
|
206
|
+
lambda { user.send "" }.should raise_error(HipChat::UnknownUser)
|
207
|
+
end
|
208
|
+
|
209
|
+
it "but fails when we're not allowed to do so" do
|
210
|
+
mock(HipChat::User).post(anything, anything) {
|
211
|
+
OpenStruct.new(:code => 401)
|
212
|
+
}
|
213
|
+
|
214
|
+
lambda { user.send "" }.should raise_error(HipChat::Unauthorized)
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
data/spec/hipchat_spec.rb
CHANGED
@@ -1,278 +1,7 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
require File.expand_path(File.dirname(__FILE__) + '/shared_hipchat')
|
3
2
|
|
4
3
|
describe HipChat do
|
5
4
|
|
6
|
-
describe "#history (API V1)" do
|
7
|
-
include_context "HipChatV1"
|
8
|
-
it "is successful without custom options" do
|
9
|
-
mock_successful_history()
|
10
|
-
|
11
|
-
room.history().should be_true
|
12
|
-
end
|
13
|
-
|
14
|
-
it "is successful with custom options" do
|
15
|
-
mock_successful_history(:timezone => 'America/Los_Angeles', :date => '2010-11-19')
|
16
|
-
room.history(:timezone => 'America/Los_Angeles', :date => '2010-11-19').should be_true
|
17
|
-
end
|
18
|
-
|
19
|
-
it "fails when the room doen't exist" do
|
20
|
-
mock(HipChat::Room).get(anything, anything) {
|
21
|
-
OpenStruct.new(:code => 404)
|
22
|
-
}
|
23
|
-
|
24
|
-
lambda { room.history }.should raise_error(HipChat::UnknownRoom)
|
25
|
-
end
|
26
|
-
|
27
|
-
it "fails when we're not allowed to do so" do
|
28
|
-
mock(HipChat::Room).get(anything, anything) {
|
29
|
-
OpenStruct.new(:code => 401)
|
30
|
-
}
|
31
|
-
|
32
|
-
lambda { room.history }.should raise_error(HipChat::Unauthorized)
|
33
|
-
end
|
34
|
-
|
35
|
-
it "fails if we get an unknown response code" do
|
36
|
-
mock(HipChat::Room).get(anything, anything) {
|
37
|
-
OpenStruct.new(:code => 403)
|
38
|
-
}
|
39
|
-
|
40
|
-
lambda { room.history }.
|
41
|
-
should raise_error(HipChat::UnknownResponseCode)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe "#topic (API V1)" do
|
46
|
-
include_context "HipChatV1"
|
47
|
-
it "is successful without custom options" do
|
48
|
-
mock_successful_topic_change("Nice topic")
|
49
|
-
|
50
|
-
room.topic("Nice topic").should be_true
|
51
|
-
end
|
52
|
-
|
53
|
-
it "is successful with a custom from" do
|
54
|
-
mock_successful_topic_change("Nice topic", :from => "Me")
|
55
|
-
|
56
|
-
room.topic("Nice topic", :from => "Me").should be_true
|
57
|
-
end
|
58
|
-
|
59
|
-
it "fails when the room doesn't exist" do
|
60
|
-
mock(HipChat::Room).post(anything, anything) {
|
61
|
-
OpenStruct.new(:code => 404)
|
62
|
-
}
|
63
|
-
|
64
|
-
lambda { room.topic "" }.should raise_error(HipChat::UnknownRoom)
|
65
|
-
end
|
66
|
-
|
67
|
-
it "fails when we're not allowed to do so" do
|
68
|
-
mock(HipChat::Room).post(anything, anything) {
|
69
|
-
OpenStruct.new(:code => 401)
|
70
|
-
}
|
71
|
-
|
72
|
-
lambda { room.topic "" }.should raise_error(HipChat::Unauthorized)
|
73
|
-
end
|
74
|
-
|
75
|
-
it "fails if we get an unknown response code" do
|
76
|
-
mock(HipChat::Room).post(anything, anything) {
|
77
|
-
OpenStruct.new(:code => 403)
|
78
|
-
}
|
79
|
-
|
80
|
-
lambda { room.topic "" }.
|
81
|
-
should raise_error(HipChat::UnknownResponseCode)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
describe "sends a message to a room (API V1)" do
|
86
|
-
include_context "HipChatV1"
|
87
|
-
it "successfully without custom options" do
|
88
|
-
mock_successful_send 'Dude', 'Hello world'
|
89
|
-
|
90
|
-
room.send("Dude", "Hello world").should be_true
|
91
|
-
end
|
92
|
-
|
93
|
-
it "successfully with notifications on as option" do
|
94
|
-
mock_successful_send 'Dude', 'Hello world', :notify => 1
|
95
|
-
|
96
|
-
room.send("Dude", "Hello world", :notify => 1).should be_true
|
97
|
-
end
|
98
|
-
|
99
|
-
it "successfully with custom color" do
|
100
|
-
mock_successful_send 'Dude', 'Hello world', :color => 'red'
|
101
|
-
|
102
|
-
room.send("Dude", "Hello world", :color => 'red').should be_true
|
103
|
-
end
|
104
|
-
|
105
|
-
it "successfully with text message_format" do
|
106
|
-
mock_successful_send 'Dude', 'Hello world', :message_format => 'text'
|
107
|
-
|
108
|
-
room.send("Dude", "Hello world", :message_format => 'text').should be_true
|
109
|
-
end
|
110
|
-
|
111
|
-
it "but fails when the room doesn't exist" do
|
112
|
-
mock(HipChat::Room).post(anything, anything) {
|
113
|
-
OpenStruct.new(:code => 404)
|
114
|
-
}
|
115
|
-
|
116
|
-
lambda { room.send "", "" }.should raise_error(HipChat::UnknownRoom)
|
117
|
-
end
|
118
|
-
|
119
|
-
it "but fails when we're not allowed to do so" do
|
120
|
-
mock(HipChat::Room).post(anything, anything) {
|
121
|
-
OpenStruct.new(:code => 401)
|
122
|
-
}
|
123
|
-
|
124
|
-
lambda { room.send "", "" }.should raise_error(HipChat::Unauthorized)
|
125
|
-
end
|
126
|
-
|
127
|
-
it "but fails if the username is more than 15 chars" do
|
128
|
-
lambda { room.send "a very long username here", "a message" }.should raise_error(HipChat::UsernameTooLong)
|
129
|
-
end
|
130
|
-
|
131
|
-
it "but fails if we get an unknown response code" do
|
132
|
-
mock(HipChat::Room).post(anything, anything) {
|
133
|
-
OpenStruct.new(:code => 403)
|
134
|
-
}
|
135
|
-
|
136
|
-
lambda { room.send "", "" }.
|
137
|
-
should raise_error(HipChat::UnknownResponseCode)
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
describe "#history (API v2)" do
|
142
|
-
include_context "HipChatV2"
|
143
|
-
it "is successful without custom options" do
|
144
|
-
mock_successful_history()
|
145
|
-
|
146
|
-
room.history().should be_true
|
147
|
-
end
|
148
|
-
|
149
|
-
it "is successful with custom options" do
|
150
|
-
mock_successful_history(:timezone => 'America/Los_Angeles', :date => '2010-11-19')
|
151
|
-
room.history(:timezone => 'America/Los_Angeles', :date => '2010-11-19').should be_true
|
152
|
-
end
|
153
|
-
|
154
|
-
it "fails when the room doen't exist" do
|
155
|
-
mock(HipChat::Room).get(anything, anything) {
|
156
|
-
OpenStruct.new(:code => 404)
|
157
|
-
}
|
158
|
-
|
159
|
-
lambda { room.history }.should raise_error(HipChat::UnknownRoom)
|
160
|
-
end
|
161
|
-
|
162
|
-
it "fails when we're not allowed to do so" do
|
163
|
-
mock(HipChat::Room).get(anything, anything) {
|
164
|
-
OpenStruct.new(:code => 401)
|
165
|
-
}
|
166
|
-
|
167
|
-
lambda { room.history }.should raise_error(HipChat::Unauthorized)
|
168
|
-
end
|
169
|
-
|
170
|
-
it "fails if we get an unknown response code" do
|
171
|
-
mock(HipChat::Room).get(anything, anything) {
|
172
|
-
OpenStruct.new(:code => 403)
|
173
|
-
}
|
174
|
-
|
175
|
-
lambda { room.history }.
|
176
|
-
should raise_error(HipChat::UnknownResponseCode)
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
describe "#topic (API v2)" do
|
181
|
-
include_context "HipChatV2"
|
182
|
-
it "is successful without custom options" do
|
183
|
-
mock_successful_topic_change("Nice topic")
|
184
|
-
|
185
|
-
room.topic("Nice topic").should be_true
|
186
|
-
end
|
187
|
-
|
188
|
-
it "is successful with a custom from" do
|
189
|
-
mock_successful_topic_change("Nice topic", :from => "Me")
|
190
|
-
|
191
|
-
room.topic("Nice topic", :from => "Me").should be_true
|
192
|
-
end
|
193
|
-
|
194
|
-
it "fails when the room doesn't exist" do
|
195
|
-
mock(HipChat::Room).put(anything, anything) {
|
196
|
-
OpenStruct.new(:code => 404)
|
197
|
-
}
|
198
|
-
|
199
|
-
lambda { room.topic "" }.should raise_error(HipChat::UnknownRoom)
|
200
|
-
end
|
201
|
-
|
202
|
-
it "fails when we're not allowed to do so" do
|
203
|
-
mock(HipChat::Room).put(anything, anything) {
|
204
|
-
OpenStruct.new(:code => 401)
|
205
|
-
}
|
206
|
-
|
207
|
-
lambda { room.topic "" }.should raise_error(HipChat::Unauthorized)
|
208
|
-
end
|
209
|
-
|
210
|
-
it "fails if we get an unknown response code" do
|
211
|
-
mock(HipChat::Room).put(anything, anything) {
|
212
|
-
OpenStruct.new(:code => 403)
|
213
|
-
}
|
214
|
-
|
215
|
-
lambda { room.topic "" }.
|
216
|
-
should raise_error(HipChat::UnknownResponseCode)
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
describe "sends a message to a room (API V2)" do
|
221
|
-
include_context "HipChatV2"
|
222
|
-
it "successfully without custom options" do
|
223
|
-
mock_successful_send 'Dude', 'Hello world'
|
224
|
-
|
225
|
-
room.send("Dude", "Hello world").should be_true
|
226
|
-
end
|
227
|
-
|
228
|
-
it "successfully with notifications on as option" do
|
229
|
-
mock_successful_send 'Dude', 'Hello world', :notify => true
|
230
|
-
|
231
|
-
room.send("Dude", "Hello world", :notify => true).should be_true
|
232
|
-
end
|
233
|
-
|
234
|
-
it "successfully with custom color" do
|
235
|
-
mock_successful_send 'Dude', 'Hello world', :color => 'red'
|
236
|
-
|
237
|
-
room.send("Dude", "Hello world", :color => 'red').should be_true
|
238
|
-
end
|
239
|
-
|
240
|
-
it "successfully with text message_format" do
|
241
|
-
mock_successful_send 'Dude', 'Hello world', :message_format => 'text'
|
242
|
-
|
243
|
-
room.send("Dude", "Hello world", :message_format => 'text').should be_true
|
244
|
-
end
|
245
|
-
|
246
|
-
it "but fails when the room doesn't exist" do
|
247
|
-
mock(HipChat::Room).post(anything, anything) {
|
248
|
-
OpenStruct.new(:code => 404)
|
249
|
-
}
|
250
|
-
|
251
|
-
lambda { room.send "", "" }.should raise_error(HipChat::UnknownRoom)
|
252
|
-
end
|
253
|
-
|
254
|
-
it "but fails when we're not allowed to do so" do
|
255
|
-
mock(HipChat::Room).post(anything, anything) {
|
256
|
-
OpenStruct.new(:code => 401)
|
257
|
-
}
|
258
|
-
|
259
|
-
lambda { room.send "", "" }.should raise_error(HipChat::Unauthorized)
|
260
|
-
end
|
261
|
-
|
262
|
-
it "but fails if the username is more than 15 chars" do
|
263
|
-
lambda { room.send "a very long username here", "a message" }.should raise_error(HipChat::UsernameTooLong)
|
264
|
-
end
|
265
|
-
|
266
|
-
it "but fails if we get an unknown response code" do
|
267
|
-
mock(HipChat::Room).post(anything, anything) {
|
268
|
-
OpenStruct.new(:code => 403)
|
269
|
-
}
|
270
|
-
|
271
|
-
lambda { room.send "", "" }.
|
272
|
-
should raise_error(HipChat::UnknownResponseCode)
|
273
|
-
end
|
274
|
-
end
|
275
|
-
|
276
5
|
describe 'http_proxy' do
|
277
6
|
let(:proxy_user) { 'proxy_user' }
|
278
7
|
let(:proxy_pass) { 'proxy_pass' }
|