hipchat 1.4.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/hipchat.gemspec +2 -1
- data/lib/hipchat.rb +3 -1
- data/lib/hipchat/api_version.rb +77 -14
- data/lib/hipchat/capistrano/tasks/hipchat.rake +2 -0
- data/lib/hipchat/capistrano2.rb +5 -1
- data/lib/hipchat/chef.rb +10 -9
- data/lib/hipchat/client.rb +7 -9
- data/lib/hipchat/file_helper.rb +42 -0
- data/lib/hipchat/rails3_tasks.rb +2 -2
- data/lib/hipchat/room.rb +49 -10
- data/lib/hipchat/user.rb +53 -12
- data/lib/hipchat/version.rb +1 -1
- data/spec/hipchat_api_v1_spec.rb +26 -30
- data/spec/hipchat_api_v2_spec.rb +133 -43
- data/spec/spec_helper.rb +6 -2
- data/spec/support/shared_contexts_for_hipchat.rb +36 -9
- metadata +44 -29
data/lib/hipchat/user.rb
CHANGED
@@ -5,13 +5,13 @@ module HipChat
|
|
5
5
|
|
6
6
|
class User < OpenStruct
|
7
7
|
include HTTParty
|
8
|
+
include FileHelper
|
8
9
|
|
9
|
-
format
|
10
|
+
format :json
|
10
11
|
|
11
12
|
def initialize(token, params)
|
12
13
|
@token = token
|
13
|
-
@api = HipChat::ApiVersion::User.new(params
|
14
|
-
params)
|
14
|
+
@api = HipChat::ApiVersion::User.new(params)
|
15
15
|
self.class.base_uri(@api.base_uri)
|
16
16
|
super(params)
|
17
17
|
end
|
@@ -19,13 +19,36 @@ module HipChat
|
|
19
19
|
#
|
20
20
|
# Send a private message to user.
|
21
21
|
#
|
22
|
-
def send(message)
|
22
|
+
def send(message, message_format='text')
|
23
23
|
response = self.class.post(@api.send_config[:url],
|
24
|
+
:query => { :auth_token => @token },
|
25
|
+
:body => {
|
26
|
+
:message => message,
|
27
|
+
:message_format => message_format
|
28
|
+
}.send(@api.send_config[:body_format]),
|
29
|
+
:headers => @api.headers
|
30
|
+
)
|
31
|
+
|
32
|
+
case response.code
|
33
|
+
when 200, 204;
|
34
|
+
true
|
35
|
+
when 404
|
36
|
+
raise UnknownUser, "Unknown user: `#{user_id}'"
|
37
|
+
when 401
|
38
|
+
raise Unauthorized, "Access denied to user `#{user_id}'"
|
39
|
+
else
|
40
|
+
raise UnknownResponseCode, "Unexpected #{response.code} for private message to `#{user_id}'"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
#
|
45
|
+
# Send a private file to user.
|
46
|
+
#
|
47
|
+
def send_file(message, file)
|
48
|
+
response = self.class.post(@api.send_file_config[:url],
|
24
49
|
:query => { :auth_token => @token },
|
25
|
-
:body
|
26
|
-
|
27
|
-
}.send(@api.send_config[:body_format]),
|
28
|
-
:headers => @api.headers
|
50
|
+
:body => file_body({ :message => message }.send(@api.send_config[:body_format]), file),
|
51
|
+
:headers => file_body_headers(@api.headers)
|
29
52
|
)
|
30
53
|
|
31
54
|
case response.code
|
@@ -43,18 +66,36 @@ module HipChat
|
|
43
66
|
# Get a user's details.
|
44
67
|
#
|
45
68
|
def view
|
46
|
-
puts "#{@api.base_uri}#{@api.view_config[:url]}"
|
47
69
|
response = self.class.get(@api.view_config[:url],
|
48
|
-
|
49
|
-
|
70
|
+
:query => { :auth_token => @token }.merge(@api.view_config[:query_params]),
|
71
|
+
:headers => @api.headers
|
50
72
|
)
|
51
73
|
|
52
74
|
case response.code
|
53
75
|
when 200
|
54
|
-
User.new(@token, response.merge(:api_version =>
|
76
|
+
User.new(@token, response.merge(:api_version => @api.version))
|
55
77
|
else
|
56
78
|
raise UnknownResponseCode, "Unexpected #{response.code} for view message to `#{user_id}'"
|
57
79
|
end
|
58
80
|
end
|
81
|
+
|
82
|
+
#
|
83
|
+
# Get private message history
|
84
|
+
#
|
85
|
+
def history(params = {})
|
86
|
+
params.select! { |key, _value| @api.history_config[:allowed_params].include? key }
|
87
|
+
|
88
|
+
response = self.class.get(@api.history_config[:url],
|
89
|
+
:query => { :auth_token => @token }.merge(params),
|
90
|
+
:headers => @api.headers
|
91
|
+
)
|
92
|
+
|
93
|
+
case response.code
|
94
|
+
when 200
|
95
|
+
response.body
|
96
|
+
else
|
97
|
+
raise UnknownResponseCode, "Unexpected #{response.code} for view private message history for `#{user_id}'"
|
98
|
+
end
|
99
|
+
end
|
59
100
|
end
|
60
101
|
end
|
data/lib/hipchat/version.rb
CHANGED
data/spec/hipchat_api_v1_spec.rb
CHANGED
@@ -11,20 +11,20 @@ describe "HipChat (API V1)" do
|
|
11
11
|
it "is successful without custom options" do
|
12
12
|
mock_successful_history()
|
13
13
|
|
14
|
-
room.history().
|
14
|
+
expect(room.history()).to be_truthy
|
15
15
|
end
|
16
16
|
|
17
17
|
it "is successful with custom options" do
|
18
|
-
mock_successful_history(:timezone => 'America/Los_Angeles', :date => '2010-11-19')
|
19
|
-
room.history(:timezone => 'America/Los_Angeles', :date => '2010-11-19').
|
18
|
+
mock_successful_history(:timezone => 'America/Los_Angeles', :date => '2010-11-19', :'max-results' => 10)
|
19
|
+
expect(room.history(:timezone => 'America/Los_Angeles', :date => '2010-11-19', :'max-results' => 10)).to be_truthy
|
20
20
|
end
|
21
21
|
|
22
22
|
it "is successful from fetched room" do
|
23
23
|
mock_successful_rooms
|
24
24
|
mock_successful_history
|
25
25
|
|
26
|
-
subject.rooms.
|
27
|
-
subject.rooms.first.history.
|
26
|
+
expect(subject.rooms).to be_truthy
|
27
|
+
expect(subject.rooms.first.history).to be_truthy
|
28
28
|
end
|
29
29
|
|
30
30
|
it "fails when the room doen't exist" do
|
@@ -32,7 +32,7 @@ describe "HipChat (API V1)" do
|
|
32
32
|
OpenStruct.new(:code => 404)
|
33
33
|
}
|
34
34
|
|
35
|
-
|
35
|
+
expect { room.history }.to raise_error(HipChat::UnknownRoom)
|
36
36
|
end
|
37
37
|
|
38
38
|
it "fails when we're not allowed to do so" do
|
@@ -40,7 +40,7 @@ describe "HipChat (API V1)" do
|
|
40
40
|
OpenStruct.new(:code => 401)
|
41
41
|
}
|
42
42
|
|
43
|
-
|
43
|
+
expect { room.history }.to raise_error(HipChat::Unauthorized)
|
44
44
|
end
|
45
45
|
|
46
46
|
it "fails if we get an unknown response code" do
|
@@ -48,8 +48,7 @@ describe "HipChat (API V1)" do
|
|
48
48
|
OpenStruct.new(:code => 403)
|
49
49
|
}
|
50
50
|
|
51
|
-
|
52
|
-
should raise_error(HipChat::UnknownResponseCode)
|
51
|
+
expect { room.history }.to raise_error(HipChat::UnknownResponseCode)
|
53
52
|
end
|
54
53
|
end
|
55
54
|
|
@@ -58,13 +57,13 @@ describe "HipChat (API V1)" do
|
|
58
57
|
it "is successful without custom options" do
|
59
58
|
mock_successful_topic_change("Nice topic")
|
60
59
|
|
61
|
-
room.topic("Nice topic").
|
60
|
+
expect(room.topic("Nice topic")).to be_truthy
|
62
61
|
end
|
63
62
|
|
64
63
|
it "is successful with a custom from" do
|
65
64
|
mock_successful_topic_change("Nice topic", :from => "Me")
|
66
65
|
|
67
|
-
room.topic("Nice topic", :from => "Me").
|
66
|
+
expect(room.topic("Nice topic", :from => "Me")).to be_truthy
|
68
67
|
end
|
69
68
|
|
70
69
|
it "fails when the room doesn't exist" do
|
@@ -72,7 +71,7 @@ describe "HipChat (API V1)" do
|
|
72
71
|
OpenStruct.new(:code => 404)
|
73
72
|
}
|
74
73
|
|
75
|
-
|
74
|
+
expect { room.topic "" }.to raise_error(HipChat::UnknownRoom)
|
76
75
|
end
|
77
76
|
|
78
77
|
it "fails when we're not allowed to do so" do
|
@@ -80,7 +79,7 @@ describe "HipChat (API V1)" do
|
|
80
79
|
OpenStruct.new(:code => 401)
|
81
80
|
}
|
82
81
|
|
83
|
-
|
82
|
+
expect { room.topic "" }.to raise_error(HipChat::Unauthorized)
|
84
83
|
end
|
85
84
|
|
86
85
|
it "fails if we get an unknown response code" do
|
@@ -88,8 +87,7 @@ describe "HipChat (API V1)" do
|
|
88
87
|
OpenStruct.new(:code => 403)
|
89
88
|
}
|
90
89
|
|
91
|
-
|
92
|
-
should raise_error(HipChat::UnknownResponseCode)
|
90
|
+
expect { room.topic "" }.to raise_error(HipChat::UnknownResponseCode)
|
93
91
|
end
|
94
92
|
end
|
95
93
|
|
@@ -98,25 +96,25 @@ describe "HipChat (API V1)" do
|
|
98
96
|
it "successfully without custom options" do
|
99
97
|
mock_successful_send 'Dude', 'Hello world'
|
100
98
|
|
101
|
-
room.send("Dude", "Hello world").
|
99
|
+
expect(room.send("Dude", "Hello world")).to be_truthy
|
102
100
|
end
|
103
101
|
|
104
102
|
it "successfully with notifications on as option" do
|
105
103
|
mock_successful_send 'Dude', 'Hello world', :notify => 1
|
106
104
|
|
107
|
-
room.send("Dude", "Hello world", :notify => 1).
|
105
|
+
expect(room.send("Dude", "Hello world", :notify => 1)).to be_truthy
|
108
106
|
end
|
109
107
|
|
110
108
|
it "successfully with custom color" do
|
111
109
|
mock_successful_send 'Dude', 'Hello world', :color => 'red'
|
112
110
|
|
113
|
-
room.send("Dude", "Hello world", :color => 'red').
|
111
|
+
expect(room.send("Dude", "Hello world", :color => 'red')).to be_truthy
|
114
112
|
end
|
115
113
|
|
116
114
|
it "successfully with text message_format" do
|
117
115
|
mock_successful_send 'Dude', 'Hello world', :message_format => 'text'
|
118
116
|
|
119
|
-
room.send("Dude", "Hello world", :message_format => 'text').
|
117
|
+
expect(room.send("Dude", "Hello world", :message_format => 'text')).to be_truthy
|
120
118
|
end
|
121
119
|
|
122
120
|
it "but fails when the room doesn't exist" do
|
@@ -124,7 +122,7 @@ describe "HipChat (API V1)" do
|
|
124
122
|
OpenStruct.new(:code => 404)
|
125
123
|
}
|
126
124
|
|
127
|
-
|
125
|
+
expect { room.send "", "" }.to raise_error(HipChat::UnknownRoom)
|
128
126
|
end
|
129
127
|
|
130
128
|
it "but fails when we're not allowed to do so" do
|
@@ -132,11 +130,11 @@ describe "HipChat (API V1)" do
|
|
132
130
|
OpenStruct.new(:code => 401)
|
133
131
|
}
|
134
132
|
|
135
|
-
|
133
|
+
expect { room.send "", "" }.to raise_error(HipChat::Unauthorized)
|
136
134
|
end
|
137
135
|
|
138
136
|
it "but fails if the username is more than 15 chars" do
|
139
|
-
|
137
|
+
expect { room.send "a very long username here", "a message" }.to raise_error(HipChat::UsernameTooLong)
|
140
138
|
end
|
141
139
|
|
142
140
|
it "but fails if we get an unknown response code" do
|
@@ -144,8 +142,7 @@ describe "HipChat (API V1)" do
|
|
144
142
|
OpenStruct.new(:code => 403)
|
145
143
|
}
|
146
144
|
|
147
|
-
|
148
|
-
should raise_error(HipChat::UnknownResponseCode)
|
145
|
+
expect { room.send "", "" }.to raise_error(HipChat::UnknownResponseCode)
|
149
146
|
end
|
150
147
|
end
|
151
148
|
|
@@ -155,26 +152,25 @@ describe "HipChat (API V1)" do
|
|
155
152
|
it "successfully with room name" do
|
156
153
|
mock_successful_room_creation("A Room", :owner_user_id => "123456")
|
157
154
|
|
158
|
-
subject.create_room("A Room", {:owner_user_id => "123456"}).
|
155
|
+
expect(subject.create_room("A Room", {:owner_user_id => "123456"})).to be_truthy
|
159
156
|
end
|
160
157
|
|
161
158
|
it "successfully with custom parameters" do
|
162
159
|
mock_successful_room_creation("A Room", {:owner_user_id => "123456", :privacy => "private", :guest_access => "1"})
|
163
160
|
|
164
|
-
subject.create_room("A Room", {:owner_user_id => "123456", :privacy => "private", :guest_access =>true}).
|
161
|
+
expect(subject.create_room("A Room", {:owner_user_id => "123456", :privacy => "private", :guest_access =>true})).to be_truthy
|
165
162
|
end
|
166
163
|
|
167
164
|
it "but fails if we dont pass owner_user_id" do
|
168
|
-
|
169
|
-
should raise_error(HipChat::RoomMissingOwnerUserId)
|
165
|
+
expect { subject.create_room("A Room", {:privacy => "private", :guest_access =>true}) }.to raise_error(HipChat::RoomMissingOwnerUserId)
|
170
166
|
end
|
171
167
|
end
|
172
168
|
|
173
169
|
describe "#send user message" do
|
174
170
|
it "fails because API V1 doesn't support user operations" do
|
175
171
|
|
176
|
-
|
177
|
-
|
172
|
+
expect { HipChat::Client.new("blah", :api_version => @api_version).user('12345678').send('nope') }.
|
173
|
+
to raise_error(HipChat::InvalidApiVersion)
|
178
174
|
end
|
179
175
|
end
|
180
176
|
end
|
data/spec/hipchat_api_v2_spec.rb
CHANGED
@@ -12,20 +12,20 @@ describe "HipChat (API V2)" do
|
|
12
12
|
it "is successful without custom options" do
|
13
13
|
mock_successful_history()
|
14
14
|
|
15
|
-
room.history().
|
15
|
+
expect(room.history()).to be_truthy
|
16
16
|
end
|
17
17
|
|
18
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').
|
19
|
+
mock_successful_history(:timezone => 'America/Los_Angeles', :date => '2010-11-19', :'max-results' => 10)
|
20
|
+
expect(room.history(:timezone => 'America/Los_Angeles', :date => '2010-11-19', :'max-results' => 10)).to be_truthy
|
21
21
|
end
|
22
22
|
|
23
23
|
it "is successful from fetched room" do
|
24
24
|
mock_successful_rooms
|
25
25
|
mock_successful_history
|
26
26
|
|
27
|
-
subject.rooms.
|
28
|
-
subject.rooms.first.history.
|
27
|
+
expect(subject.rooms).to be_truthy
|
28
|
+
expect(subject.rooms.first.history).to be_truthy
|
29
29
|
end
|
30
30
|
|
31
31
|
it "fails when the room doen't exist" do
|
@@ -33,7 +33,7 @@ describe "HipChat (API V2)" do
|
|
33
33
|
OpenStruct.new(:code => 404)
|
34
34
|
}
|
35
35
|
|
36
|
-
|
36
|
+
expect { room.history }.to raise_error(HipChat::UnknownRoom)
|
37
37
|
end
|
38
38
|
|
39
39
|
it "fails when we're not allowed to do so" do
|
@@ -41,7 +41,7 @@ describe "HipChat (API V2)" do
|
|
41
41
|
OpenStruct.new(:code => 401)
|
42
42
|
}
|
43
43
|
|
44
|
-
|
44
|
+
expect { room.history }.to raise_error(HipChat::Unauthorized)
|
45
45
|
end
|
46
46
|
|
47
47
|
it "fails if we get an unknown response code" do
|
@@ -49,8 +49,7 @@ describe "HipChat (API V2)" do
|
|
49
49
|
OpenStruct.new(:code => 403)
|
50
50
|
}
|
51
51
|
|
52
|
-
|
53
|
-
should raise_error(HipChat::UnknownResponseCode)
|
52
|
+
expect { room.history }.to raise_error(HipChat::UnknownResponseCode)
|
54
53
|
end
|
55
54
|
end
|
56
55
|
|
@@ -59,15 +58,15 @@ describe "HipChat (API V2)" do
|
|
59
58
|
it "is successful without custom options" do
|
60
59
|
mock_successful_statistics
|
61
60
|
|
62
|
-
room.statistics().
|
61
|
+
expect(room.statistics()).to be_truthy
|
63
62
|
end
|
64
63
|
|
65
64
|
it "is successful from fetched room" do
|
66
65
|
mock_successful_rooms
|
67
66
|
mock_successful_statistics
|
68
67
|
|
69
|
-
subject.rooms.
|
70
|
-
subject.rooms.first.statistics.
|
68
|
+
expect(subject.rooms).to be_truthy
|
69
|
+
expect(subject.rooms.first.statistics).to be_truthy
|
71
70
|
end
|
72
71
|
|
73
72
|
it "fails when the room doen't exist" do
|
@@ -75,7 +74,7 @@ describe "HipChat (API V2)" do
|
|
75
74
|
OpenStruct.new(:code => 404)
|
76
75
|
}
|
77
76
|
|
78
|
-
|
77
|
+
expect { room.statistics }.to raise_error(HipChat::UnknownRoom)
|
79
78
|
end
|
80
79
|
|
81
80
|
it "fails when we're not allowed to do so" do
|
@@ -83,7 +82,7 @@ describe "HipChat (API V2)" do
|
|
83
82
|
OpenStruct.new(:code => 401)
|
84
83
|
}
|
85
84
|
|
86
|
-
|
85
|
+
expect { room.statistics }.to raise_error(HipChat::Unauthorized)
|
87
86
|
end
|
88
87
|
|
89
88
|
it "fails if we get an unknown response code" do
|
@@ -91,9 +90,8 @@ describe "HipChat (API V2)" do
|
|
91
90
|
OpenStruct.new(:code => 403)
|
92
91
|
}
|
93
92
|
|
94
|
-
|
95
|
-
|
96
|
-
end
|
93
|
+
expect { room.statistics }.to raise_error(HipChat::UnknownResponseCode)
|
94
|
+
end
|
97
95
|
end
|
98
96
|
|
99
97
|
describe "#topic" do
|
@@ -101,13 +99,13 @@ describe "HipChat (API V2)" do
|
|
101
99
|
it "is successful without custom options" do
|
102
100
|
mock_successful_topic_change("Nice topic")
|
103
101
|
|
104
|
-
room.topic("Nice topic").
|
102
|
+
expect(room.topic("Nice topic")).to be_truthy
|
105
103
|
end
|
106
104
|
|
107
105
|
it "is successful with a custom from" do
|
108
106
|
mock_successful_topic_change("Nice topic", :from => "Me")
|
109
107
|
|
110
|
-
room.topic("Nice topic", :from => "Me").
|
108
|
+
expect(room.topic("Nice topic", :from => "Me")).to be_truthy
|
111
109
|
end
|
112
110
|
|
113
111
|
it "fails when the room doesn't exist" do
|
@@ -115,7 +113,7 @@ describe "HipChat (API V2)" do
|
|
115
113
|
OpenStruct.new(:code => 404)
|
116
114
|
}
|
117
115
|
|
118
|
-
|
116
|
+
expect { room.topic "" }.to raise_error(HipChat::UnknownRoom)
|
119
117
|
end
|
120
118
|
|
121
119
|
it "fails when we're not allowed to do so" do
|
@@ -123,7 +121,7 @@ describe "HipChat (API V2)" do
|
|
123
121
|
OpenStruct.new(:code => 401)
|
124
122
|
}
|
125
123
|
|
126
|
-
|
124
|
+
expect { room.topic "" }.to raise_error(HipChat::Unauthorized)
|
127
125
|
end
|
128
126
|
|
129
127
|
it "fails if we get an unknown response code" do
|
@@ -131,8 +129,7 @@ describe "HipChat (API V2)" do
|
|
131
129
|
OpenStruct.new(:code => 403)
|
132
130
|
}
|
133
131
|
|
134
|
-
|
135
|
-
should raise_error(HipChat::UnknownResponseCode)
|
132
|
+
expect { room.topic "" }.to raise_error(HipChat::UnknownResponseCode)
|
136
133
|
end
|
137
134
|
end
|
138
135
|
|
@@ -141,25 +138,25 @@ describe "HipChat (API V2)" do
|
|
141
138
|
it "successfully without custom options" do
|
142
139
|
mock_successful_send 'Dude', 'Hello world'
|
143
140
|
|
144
|
-
room.send("Dude", "Hello world").
|
141
|
+
expect(room.send("Dude", "Hello world")).to be_truthy
|
145
142
|
end
|
146
143
|
|
147
144
|
it "successfully with notifications on as option" do
|
148
145
|
mock_successful_send 'Dude', 'Hello world', :notify => true
|
149
146
|
|
150
|
-
room.send("Dude", "Hello world", :notify => true).
|
147
|
+
expect(room.send("Dude", "Hello world", :notify => true)).to be_truthy
|
151
148
|
end
|
152
149
|
|
153
150
|
it "successfully with custom color" do
|
154
151
|
mock_successful_send 'Dude', 'Hello world', :color => 'red'
|
155
152
|
|
156
|
-
room.send("Dude", "Hello world", :color => 'red').
|
153
|
+
expect(room.send("Dude", "Hello world", :color => 'red')).to be_truthy
|
157
154
|
end
|
158
155
|
|
159
156
|
it "successfully with text message_format" do
|
160
157
|
mock_successful_send 'Dude', 'Hello world', :message_format => 'text'
|
161
158
|
|
162
|
-
room.send("Dude", "Hello world", :message_format => 'text').
|
159
|
+
expect(room.send("Dude", "Hello world", :message_format => 'text')).to be_truthy
|
163
160
|
end
|
164
161
|
|
165
162
|
it "but fails when the room doesn't exist" do
|
@@ -167,7 +164,7 @@ describe "HipChat (API V2)" do
|
|
167
164
|
OpenStruct.new(:code => 404)
|
168
165
|
}
|
169
166
|
|
170
|
-
|
167
|
+
expect { room.send "", "" }.to raise_error(HipChat::UnknownRoom)
|
171
168
|
end
|
172
169
|
|
173
170
|
it "but fails when we're not allowed to do so" do
|
@@ -175,11 +172,11 @@ describe "HipChat (API V2)" do
|
|
175
172
|
OpenStruct.new(:code => 401)
|
176
173
|
}
|
177
174
|
|
178
|
-
|
175
|
+
expect { room.send "", "" }.to raise_error(HipChat::Unauthorized)
|
179
176
|
end
|
180
177
|
|
181
178
|
it "but fails if the username is more than 15 chars" do
|
182
|
-
|
179
|
+
expect { room.send "a very long username here", "a message" }.to raise_error(HipChat::UsernameTooLong)
|
183
180
|
end
|
184
181
|
|
185
182
|
it "but fails if we get an unknown response code" do
|
@@ -187,7 +184,54 @@ describe "HipChat (API V2)" do
|
|
187
184
|
OpenStruct.new(:code => 403)
|
188
185
|
}
|
189
186
|
|
190
|
-
|
187
|
+
expect { room.send "", "" }.to raise_error(HipChat::UnknownResponseCode)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
describe "#send_file" do
|
192
|
+
let(:file) do
|
193
|
+
Tempfile.new('foo').tap do |f|
|
194
|
+
f.write("the content")
|
195
|
+
f.rewind
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
after { file.unlink }
|
200
|
+
|
201
|
+
include_context "HipChatV2"
|
202
|
+
|
203
|
+
it "successfully" do
|
204
|
+
mock_successful_file_send 'Dude', 'Hello world', file
|
205
|
+
|
206
|
+
room.send_file("Dude", "Hello world", file).should be_truthy
|
207
|
+
end
|
208
|
+
|
209
|
+
it "but fails when the room doesn't exist" do
|
210
|
+
mock(HipChat::Room).post(anything, anything) {
|
211
|
+
OpenStruct.new(:code => 404)
|
212
|
+
}
|
213
|
+
|
214
|
+
lambda { room.send_file "", "", file }.should raise_error(HipChat::UnknownRoom)
|
215
|
+
end
|
216
|
+
|
217
|
+
it "but fails when we're not allowed to do so" do
|
218
|
+
mock(HipChat::Room).post(anything, anything) {
|
219
|
+
OpenStruct.new(:code => 401)
|
220
|
+
}
|
221
|
+
|
222
|
+
lambda { room.send_file "", "", file }.should raise_error(HipChat::Unauthorized)
|
223
|
+
end
|
224
|
+
|
225
|
+
it "but fails if the username is more than 15 chars" do
|
226
|
+
lambda { room.send_file "a very long username here", "a message", file }.should raise_error(HipChat::UsernameTooLong)
|
227
|
+
end
|
228
|
+
|
229
|
+
it "but fails if we get an unknown response code" do
|
230
|
+
mock(HipChat::Room).post(anything, anything) {
|
231
|
+
OpenStruct.new(:code => 403)
|
232
|
+
}
|
233
|
+
|
234
|
+
lambda { room.send_file "", "", file }.
|
191
235
|
should raise_error(HipChat::UnknownResponseCode)
|
192
236
|
end
|
193
237
|
end
|
@@ -198,18 +242,18 @@ describe "HipChat (API V2)" do
|
|
198
242
|
it "successfully with room name" do
|
199
243
|
mock_successful_room_creation("A Room")
|
200
244
|
|
201
|
-
subject.create_room("A Room").
|
245
|
+
expect(subject.create_room("A Room")).to be_truthy
|
202
246
|
end
|
203
247
|
|
204
248
|
it "successfully with custom parameters" do
|
205
249
|
mock_successful_room_creation("A Room", {:owner_user_id => "123456", :privacy => "private", :guest_access => true})
|
206
250
|
|
207
|
-
subject.create_room("A Room", {:owner_user_id => "123456", :privacy => "private", :guest_access =>true}).
|
251
|
+
expect(subject.create_room("A Room", {:owner_user_id => "123456", :privacy => "private", :guest_access =>true})).to be_truthy
|
208
252
|
end
|
209
253
|
|
210
254
|
it "but fail is name is longer then 50 char" do
|
211
|
-
|
212
|
-
|
255
|
+
expect { subject.create_room("A Room that is too long that I should fail right now") }.
|
256
|
+
to raise_error(HipChat::RoomNameTooLong)
|
213
257
|
end
|
214
258
|
end
|
215
259
|
|
@@ -219,7 +263,7 @@ describe "HipChat (API V2)" do
|
|
219
263
|
it "successfully" do
|
220
264
|
mock_successful_get_room("Hipchat")
|
221
265
|
|
222
|
-
room.get_room.
|
266
|
+
expect(room.get_room).to be_truthy
|
223
267
|
end
|
224
268
|
|
225
269
|
end
|
@@ -236,9 +280,9 @@ describe "HipChat (API V2)" do
|
|
236
280
|
"owner" => { "id" => "12345" }
|
237
281
|
}
|
238
282
|
}
|
239
|
-
it "successfully" do
|
283
|
+
it "successfully" do
|
240
284
|
mock_successful_update_room("Hipchat", room_info)
|
241
|
-
room.update_room(room_info).
|
285
|
+
expect(room.update_room(room_info)).to be_truthy
|
242
286
|
end
|
243
287
|
end
|
244
288
|
|
@@ -248,13 +292,13 @@ describe "HipChat (API V2)" do
|
|
248
292
|
it "successfully with user_id" do
|
249
293
|
mock_successful_invite()
|
250
294
|
|
251
|
-
room.invite("1234").
|
295
|
+
expect(room.invite("1234")).to be_truthy
|
252
296
|
end
|
253
297
|
|
254
298
|
it "successfully with custom parameters" do
|
255
299
|
mock_successful_invite({:user_id => "321", :reason => "A great reason"})
|
256
300
|
|
257
|
-
room.invite("321", "A great reason").
|
301
|
+
expect(room.invite("321", "A great reason")).to be_truthy
|
258
302
|
end
|
259
303
|
end
|
260
304
|
|
@@ -263,7 +307,53 @@ describe "HipChat (API V2)" do
|
|
263
307
|
it "successfully with a standard message" do
|
264
308
|
mock_successful_user_send 'Equal bytes for everyone'
|
265
309
|
|
266
|
-
user.send('Equal bytes for everyone').
|
310
|
+
expect(user.send('Equal bytes for everyone')).to be_truthy
|
311
|
+
end
|
312
|
+
|
313
|
+
it "but fails when the user doesn't exist" do
|
314
|
+
mock(HipChat::User).post(anything, anything) {
|
315
|
+
OpenStruct.new(:code => 404)
|
316
|
+
}
|
317
|
+
|
318
|
+
expect { user.send "" }.to raise_error(HipChat::UnknownUser)
|
319
|
+
end
|
320
|
+
|
321
|
+
it "but fails when we're not allowed to do so" do
|
322
|
+
mock(HipChat::User).post(anything, anything) {
|
323
|
+
OpenStruct.new(:code => 401)
|
324
|
+
}
|
325
|
+
|
326
|
+
expect { user.send "" }.to raise_error(HipChat::Unauthorized)
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
330
|
+
describe '#get_user_history' do
|
331
|
+
include_context 'HipChatV2'
|
332
|
+
|
333
|
+
it 'successfully returns history' do
|
334
|
+
mock_successful_user_history
|
335
|
+
user.history.should be_truthy
|
336
|
+
end
|
337
|
+
|
338
|
+
it 'has allowed params' do
|
339
|
+
expect(user.instance_variable_get(:@api).history_config[:allowed_params]).to eq([:'max-results', :timezone, :'not-before'])
|
340
|
+
end
|
341
|
+
end
|
342
|
+
|
343
|
+
describe "#send_file user" do
|
344
|
+
include_context "HipChatV2"
|
345
|
+
|
346
|
+
let(:file) do
|
347
|
+
Tempfile.new('foo').tap do |f|
|
348
|
+
f.write("the content")
|
349
|
+
f.rewind
|
350
|
+
end
|
351
|
+
end
|
352
|
+
|
353
|
+
it "successfully with a standard file" do
|
354
|
+
mock_successful_user_send_file 'Equal bytes for everyone', file
|
355
|
+
|
356
|
+
user.send_file('Equal bytes for everyone', file).should be_truthy
|
267
357
|
end
|
268
358
|
|
269
359
|
it "but fails when the user doesn't exist" do
|
@@ -271,7 +361,7 @@ describe "HipChat (API V2)" do
|
|
271
361
|
OpenStruct.new(:code => 404)
|
272
362
|
}
|
273
363
|
|
274
|
-
lambda { user.
|
364
|
+
lambda { user.send_file "", file }.should raise_error(HipChat::UnknownUser)
|
275
365
|
end
|
276
366
|
|
277
367
|
it "but fails when we're not allowed to do so" do
|
@@ -279,7 +369,7 @@ describe "HipChat (API V2)" do
|
|
279
369
|
OpenStruct.new(:code => 401)
|
280
370
|
}
|
281
371
|
|
282
|
-
lambda { user.
|
372
|
+
lambda { user.send_file "", file }.should raise_error(HipChat::Unauthorized)
|
283
373
|
end
|
284
374
|
end
|
285
375
|
end
|