yam 0.0.6 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/.travis.yml +5 -0
- data/.yardopts +10 -0
- data/AUTHORS +1 -0
- data/CHANGELOG.md +7 -0
- data/CONTRIBUTING.md +0 -7
- data/Gemfile +27 -1
- data/README.md +190 -67
- data/Rakefile +9 -3
- data/certs/public.pem +20 -0
- data/lib/yammer.rb +47 -0
- data/lib/yammer/api.rb +29 -0
- data/lib/yammer/api/autocomplete.rb +39 -0
- data/lib/yammer/api/group.rb +92 -0
- data/lib/yammer/api/group_membership.rb +46 -0
- data/lib/yammer/api/invitation.rb +39 -0
- data/lib/yammer/api/like.rb +57 -0
- data/lib/yammer/api/message.rb +227 -0
- data/lib/yammer/api/network.rb +35 -0
- data/lib/yammer/api/notification.rb +32 -0
- data/lib/yammer/api/open_graph_object.rb +92 -0
- data/lib/yammer/api/pending_attachment.rb +64 -0
- data/lib/yammer/api/search.rb +42 -0
- data/lib/yammer/api/subscription.rb +32 -0
- data/lib/yammer/api/thread.rb +37 -0
- data/lib/yammer/api/topic.rb +37 -0
- data/lib/yammer/api/user.rb +168 -0
- data/lib/yammer/api_handler.rb +27 -0
- data/lib/yammer/api_response.rb +57 -0
- data/lib/yammer/base.rb +208 -0
- data/lib/yammer/client.rb +100 -0
- data/lib/yammer/configurable.rb +81 -0
- data/lib/yammer/error.rb +75 -0
- data/lib/yammer/group.rb +27 -0
- data/lib/yammer/group_membership.rb +25 -0
- data/lib/yammer/http_adapter.rb +100 -0
- data/lib/yammer/identity_map.rb +56 -0
- data/lib/yammer/message.rb +32 -0
- data/lib/yammer/message_body.rb +27 -0
- data/lib/yammer/pending_attachment.rb +19 -0
- data/lib/yammer/thread.rb +58 -0
- data/lib/yammer/user.rb +66 -0
- data/lib/yammer/version.rb +32 -0
- data/{lib/yam/configuration.rb → spec/api/autocomplete_spec.rb} +18 -23
- data/spec/api/group_membership_spec.rb +48 -0
- data/spec/api/group_spec.rb +76 -0
- data/spec/api/invitation_spec.rb +60 -0
- data/spec/api/like_spec.rb +46 -0
- data/spec/api/message_spec.rb +136 -0
- data/spec/api/network_spec.rb +41 -0
- data/{lib/yam/client.rb → spec/api/notification_spec.rb} +22 -4
- data/spec/api/open_graph_object_spec.rb +67 -0
- data/spec/api/pending_attachment_spec.rb +56 -0
- data/{lib/yam/constants.rb → spec/api/search_spec.rb} +21 -8
- data/spec/api/subscription_spec.rb +41 -0
- data/{lib/yam.rb → spec/api/thread_spec.rb} +19 -12
- data/{lib/yam/request.rb → spec/api/topic_spec.rb} +19 -15
- data/spec/api/user_spec.rb +108 -0
- data/spec/api_response.rb +86 -0
- data/spec/client_spec.rb +364 -0
- data/spec/error_spec.rb +88 -0
- data/spec/fixtures/group.json +1 -0
- data/spec/fixtures/message.json +1 -0
- data/spec/fixtures/messages_in_thread.json +1 -0
- data/spec/fixtures/portal_thread.json +1 -0
- data/spec/fixtures/private_thread.json +1 -0
- data/spec/fixtures/public_thread.json +1 -0
- data/spec/fixtures/user.json +1 -0
- data/spec/fixtures/users_followed.json +1 -0
- data/spec/fixtures/users_following.json +1 -0
- data/spec/http_adapter_spec.rb +109 -0
- data/spec/identity_map_spec.rb +127 -0
- data/spec/mocks/attachment.txt +1 -0
- data/spec/model/base_spec.rb +196 -0
- data/spec/model/group_membership_spec.rb +57 -0
- data/spec/model/group_spec.rb +73 -0
- data/spec/model/message_spec.rb +74 -0
- data/spec/model/thread_spec.rb +91 -0
- data/spec/model/user_spec.rb +222 -0
- data/spec/spec_helper.rb +39 -14
- data/yam.gemspec +50 -28
- metadata +270 -187
- metadata.gz.sig +0 -0
- data/lib/yam/api.rb +0 -53
- data/lib/yam/connection.rb +0 -57
- data/lib/yam/version.rb +0 -20
- data/spec/yam/client_spec.rb +0 -50
- data/spec/yam_spec.rb +0 -87
@@ -0,0 +1,86 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
# Copyright (c) Microsoft Corporation
|
4
|
+
# All rights reserved.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
13
|
+
# ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
|
14
|
+
# IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR
|
15
|
+
# PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
|
16
|
+
#
|
17
|
+
# See the Apache Version 2.0 License for specific language governing
|
18
|
+
# permissions and limitations under the License.
|
19
|
+
|
20
|
+
require File.expand_path('../spec_helper', __FILE__)
|
21
|
+
require 'yammer/response'
|
22
|
+
|
23
|
+
describe Yammer::ApiResponse do
|
24
|
+
|
25
|
+
context 'successful response' do
|
26
|
+
subject do
|
27
|
+
headers = { 'Location' => 'https://www.yammer.com/api/v1/messages/2' }
|
28
|
+
body = '{ "system_message":false, "direct_message":true, "id":10928508, "privacy":"private", "network_id":1 }'
|
29
|
+
code = '200'
|
30
|
+
Yammer::ApiResponse.new(headers, body, code)
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#raw_body' do
|
34
|
+
it 'returns a string' do
|
35
|
+
expect(subject.raw_body).to eq('{ "system_message":false, "direct_message":true, "id":10928508, "privacy":"private", "network_id":1 }')
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#body' do
|
40
|
+
it 'return a hash' do
|
41
|
+
expect(subject.body).to eq({ :system_message => false, :direct_message => true, :id => 10928508, :privacy => 'private', :network_id => 1 })
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#success' do
|
46
|
+
it 'returns true' do
|
47
|
+
expect(subject.success?).to eq true
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#created?' do
|
52
|
+
it 'returns true' do
|
53
|
+
expect(subject.created?).to eq false
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'failed response' do
|
59
|
+
|
60
|
+
subject { Yammer::ApiResponse.new(double( :headers => {}, :body => '', :code => '500')) }
|
61
|
+
|
62
|
+
describe '#raw_body' do
|
63
|
+
it 'returns a string' do
|
64
|
+
expect(subject.raw_body).to eq('')
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '#body' do
|
69
|
+
it 'return a hash' do
|
70
|
+
expect(subject.body).to eq('')
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#success' do
|
75
|
+
it 'returns true' do
|
76
|
+
expect(subject.success?).to eq false
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe '#created?' do
|
81
|
+
it 'returns true' do
|
82
|
+
expect(subject.created?).to eq false
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
data/spec/client_spec.rb
ADDED
@@ -0,0 +1,364 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
# Copyright (c) Microsoft Corporation
|
4
|
+
# All rights reserved.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
13
|
+
# ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
|
14
|
+
# IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR
|
15
|
+
# PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
|
16
|
+
#
|
17
|
+
# See the Apache Version 2.0 License for specific language governing
|
18
|
+
# permissions and limitations under the License.
|
19
|
+
|
20
|
+
require File.expand_path('../spec_helper', __FILE__)
|
21
|
+
|
22
|
+
describe Yammer::Client do
|
23
|
+
|
24
|
+
before :each do
|
25
|
+
@configuration = {
|
26
|
+
:site_url => 'https://www.yammer.com',
|
27
|
+
:client_id => 'PRbTcg9qjgKsp4jjpm1pw',
|
28
|
+
:client_secret => 'Xn7kp7Ly0TCY4GtZWkmSsqGEPg10DmMADyjWkf2U',
|
29
|
+
:access_token => 'TolNOFka9Uls2DxahNi78A',
|
30
|
+
:connection_options => { :max_redirects => 5, :use_ssl => true },
|
31
|
+
:default_headers => {"Accept"=>"application/json", "User-Agent"=>"Yammer Ruby Gem #{Yammer::Version}"}
|
32
|
+
}
|
33
|
+
|
34
|
+
Yammer.configure do |config|
|
35
|
+
@configuration.each do |key, val|
|
36
|
+
config.send("#{key}=", val)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
after :each do
|
42
|
+
Yammer.reset!
|
43
|
+
end
|
44
|
+
|
45
|
+
subject { Yammer::Client.new(@configuration) }
|
46
|
+
|
47
|
+
context "with module configuration" do
|
48
|
+
|
49
|
+
before :each do
|
50
|
+
@default_conf = {
|
51
|
+
:site_url => nil,
|
52
|
+
:client_id => nil,
|
53
|
+
:client_secret => nil,
|
54
|
+
:access_token => nil,
|
55
|
+
:default_headers => {"Accept"=>"application/json", "User-Agent"=>"Yammer Ruby Gem #{Yammer::Version}"},
|
56
|
+
:connection_options => {}
|
57
|
+
}
|
58
|
+
Yammer.configure do |config|
|
59
|
+
Yammer::Configurable.keys.each do |key|
|
60
|
+
config.send("#{key}=", @default_conf[key])
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
after do
|
66
|
+
Yammer.reset!
|
67
|
+
end
|
68
|
+
|
69
|
+
it "inherits the module configuration" do
|
70
|
+
client = Yammer::Client.new
|
71
|
+
@default_conf.each do |key, value|
|
72
|
+
expect(client.instance_variable_get(:"@#{key}")).to eq value
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context "with initialization options" do
|
77
|
+
before(:all) do
|
78
|
+
@conf = {
|
79
|
+
:site_url => 'https://www.yammer.com',
|
80
|
+
:client_id => 'PRbTcg9qjgKsp4jjpm1pw',
|
81
|
+
:client_secret => 'Xn7kp7Ly0TCY4GtZWkmSsqGEPg10DmMADyjWkf2U',
|
82
|
+
:access_token => 'TolNOFka9Uls2DxahNi78A',
|
83
|
+
:default_headers => {"Accept"=>"application/json", "User-Agent"=>"Yammer Ruby Gem 0.1.1"},
|
84
|
+
:connection_options => { :max_redirects => 5, :use_ssl => true }
|
85
|
+
}
|
86
|
+
end
|
87
|
+
|
88
|
+
context "during initialization" do
|
89
|
+
it "overrides the module configuration" do
|
90
|
+
client = Yammer::Client.new(@conf)
|
91
|
+
Yammer::Configurable.keys.each do |key|
|
92
|
+
expect(client.instance_variable_get(:"@#{key}")).to eq @conf[key]
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context "after initialization" do
|
98
|
+
it "overrides the module configuration" do
|
99
|
+
Yammer.configure {|c| c.connection_options = {}}
|
100
|
+
client = Yammer::Client.new
|
101
|
+
client.configure do |config|
|
102
|
+
@conf.each do |key, value|
|
103
|
+
config.send("#{key}=", value)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
Yammer::Configurable.keys.each do |key|
|
107
|
+
expect(client.instance_variable_get(:"@#{key}")).to eq @conf[key]
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
describe "#connection_options" do
|
117
|
+
context "with default connection options" do
|
118
|
+
it "returns empty hash" do
|
119
|
+
expect(subject.connection_options).to eq({ :max_redirects => 5, :use_ssl => true })
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
context "with custom connection options" do
|
124
|
+
it "returns default options" do
|
125
|
+
subject.connection_options = { :max_redirects => 5, :use_ssl => true }
|
126
|
+
expect(subject.connection_options).to eq({:max_redirects => 5, :use_ssl => true})
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe "#request" do
|
132
|
+
context "when method is not supported" do
|
133
|
+
it "raises an error" do
|
134
|
+
expect {subject.send(:request, :patch, '/')}.to raise_error
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
context "when method is get" do
|
139
|
+
it "returns an http response" do
|
140
|
+
path = '/oauth/authorize'
|
141
|
+
params = {:client_id => '001337', :client_secret => 'abcxyz'}
|
142
|
+
method = :get
|
143
|
+
|
144
|
+
normalized_path = '/oauth/authorize?client_id=001337&client_secret=abcxyz'
|
145
|
+
|
146
|
+
stub_request(:get, "https://www.yammer.com/oauth/authorize?client_id=001337&client_secret=abcxyz").with(
|
147
|
+
:headers => {
|
148
|
+
'Accept'=>'application/json',
|
149
|
+
'User-Agent'=>"Yammer Ruby Gem #{Yammer::Version}"
|
150
|
+
})
|
151
|
+
response = subject.send(:request, method, path, params)
|
152
|
+
|
153
|
+
expect(response.code).to eq 200
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
context "when method is delete" do
|
158
|
+
it "returns an http response" do
|
159
|
+
path = '/users/1'
|
160
|
+
|
161
|
+
stub_request(:delete, "https://www.yammer.com/users/1").with(
|
162
|
+
:headers => {
|
163
|
+
'Accept'=>'application/json',
|
164
|
+
'User-Agent'=>"Yammer Ruby Gem #{Yammer::Version}"
|
165
|
+
}).to_return(:status => 200, :body => "", :headers => {})
|
166
|
+
|
167
|
+
response = subject.send(:request, :delete, path)
|
168
|
+
expect(response.code).to eq 200
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
context "when method is post" do
|
173
|
+
it "returns an http response" do
|
174
|
+
path = '/users'
|
175
|
+
params = {:first_name => 'john', :last_name => 'smith'}
|
176
|
+
query = Addressable::URI.form_encode(params)
|
177
|
+
headers = {'Content-Type' => 'application/x-www-form-urlencoded' }.merge(subject.default_headers)
|
178
|
+
|
179
|
+
stub_request(:post, "https://www.yammer.com/users").with(
|
180
|
+
:body => {
|
181
|
+
"first_name"=>"john",
|
182
|
+
"last_name"=>"smith"
|
183
|
+
},
|
184
|
+
:headers => {
|
185
|
+
'Accept'=>'application/json',
|
186
|
+
'Content-Type'=>'application/x-www-form-urlencoded',
|
187
|
+
'User-Agent'=>"Yammer Ruby Gem #{Yammer::Version}"
|
188
|
+
}).to_return(:status => 200, :body => "", :headers => {})
|
189
|
+
|
190
|
+
response =subject.send(:request, :post, path, params)
|
191
|
+
expect(response.code).to eq 200
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
context "when method is put" do
|
196
|
+
it "returns an http response" do
|
197
|
+
path = '/users/1'
|
198
|
+
params = {:first_name => 'jane', :last_name => 'doe'}
|
199
|
+
query = Addressable::URI.form_encode(params)
|
200
|
+
headers = {'Content-Type' => 'application/x-www-form-urlencoded' }.merge(subject.default_headers)
|
201
|
+
|
202
|
+
stub_request(:put, "https://www.yammer.com/users/1").with(
|
203
|
+
:body => {
|
204
|
+
"first_name" => "jane",
|
205
|
+
"last_name" => "doe"
|
206
|
+
},
|
207
|
+
:headers => {
|
208
|
+
'Accept'=>'application/json',
|
209
|
+
'Content-Type'=>'application/x-www-form-urlencoded',
|
210
|
+
'Authorization'=>'Bearer TolNOFka9Uls2DxahNi78A',
|
211
|
+
'User-Agent'=>"Yammer Ruby Gem #{Yammer::Version}"
|
212
|
+
}).
|
213
|
+
to_return(:status => 200, :body => "", :headers => {})
|
214
|
+
|
215
|
+
response = subject.send(:request, :put, path, params)
|
216
|
+
expect(response.code).to eq 200
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
it "follows redirect" do
|
221
|
+
params = {:first_name => 'jane', :last_name => 'doe'}
|
222
|
+
stub_request(:post, "https://www.yammer.com/users").with(
|
223
|
+
:body => params,
|
224
|
+
:headers => {
|
225
|
+
'Accept' =>'application/json',
|
226
|
+
'Accept-Encoding' => 'gzip, deflate',
|
227
|
+
'Content-Type' => 'application/x-www-form-urlencoded',
|
228
|
+
'User-Agent' => "Yammer Ruby Gem #{Yammer::Version}"
|
229
|
+
}
|
230
|
+
).to_return(:status => 303, :body => "", :headers => { 'Location' => 'https://www.yammer.com/members'})
|
231
|
+
|
232
|
+
stub_request(:get, "https://www.yammer.com/members").
|
233
|
+
with(:headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip, deflate', 'User-Agent'=>"Yammer Ruby Gem #{Yammer::Version}"}).
|
234
|
+
to_return(:status => 200, :body => "", :headers => {})
|
235
|
+
response = subject.send(:request, :post, '/users', params)
|
236
|
+
|
237
|
+
expect(response.code).to eq 200
|
238
|
+
end
|
239
|
+
|
240
|
+
it "respects the redirect limit " do
|
241
|
+
subject.connection_options = { :max_redirects => 1 }
|
242
|
+
|
243
|
+
stub_request(:get, "https://www.yammer.com/users").
|
244
|
+
with(
|
245
|
+
:headers => {
|
246
|
+
'Accept' => 'application/json',
|
247
|
+
'Accept-Encoding'=> 'gzip, deflate',
|
248
|
+
'User-Agent' => "Yammer Ruby Gem #{Yammer::Version}"
|
249
|
+
}
|
250
|
+
).to_return(:status => 301, :body => "", :headers => { 'Location' => 'https://www.yammer.com/members'})
|
251
|
+
|
252
|
+
|
253
|
+
stub_request(:get, "https://www.yammer.com/members").
|
254
|
+
with(
|
255
|
+
:headers => {
|
256
|
+
'Accept' => 'application/json',
|
257
|
+
'Accept-Encoding'=> 'gzip, deflate',
|
258
|
+
'User-Agent' => "Yammer Ruby Gem #{Yammer::Version}"
|
259
|
+
}
|
260
|
+
).to_return(:status => 301, :body => "", :headers => { 'Location' => 'https://www.yammer.com/people'})
|
261
|
+
|
262
|
+
expect { subject.send(:request, :get, '/users') }.to raise_error(RestClient::MaxRedirectsReached)
|
263
|
+
end
|
264
|
+
|
265
|
+
it "modifies http 303 redirect from POST to GET " do
|
266
|
+
params = { :first_name => 'jane', :last_name => 'doe' }
|
267
|
+
stub_request(:post, "https://www.yammer.com/users").with(
|
268
|
+
:body => params,
|
269
|
+
:headers => {
|
270
|
+
'Accept'=>'application/json',
|
271
|
+
'Accept-Encoding'=>'gzip, deflate',
|
272
|
+
'Content-Length'=>'29',
|
273
|
+
'Content-Type'=>'application/x-www-form-urlencoded',
|
274
|
+
'User-Agent'=>"Yammer Ruby Gem #{Yammer::Version}"
|
275
|
+
}
|
276
|
+
).to_return(
|
277
|
+
:status => 303,
|
278
|
+
:body => "you are being redirected",
|
279
|
+
:headers => {'Location' => "http://yammer.com/members"}
|
280
|
+
)
|
281
|
+
|
282
|
+
stub_request(:get, "http://yammer.com/members").
|
283
|
+
with(
|
284
|
+
:headers => {
|
285
|
+
'Accept'=>'application/json',
|
286
|
+
'Accept-Encoding'=>'gzip, deflate',
|
287
|
+
'User-Agent'=> "Yammer Ruby Gem #{Yammer::Version}"
|
288
|
+
}
|
289
|
+
).to_return(:status => 200, :body => "", :headers => {})
|
290
|
+
|
291
|
+
response = subject.send(:request, :post, '/users', params )
|
292
|
+
|
293
|
+
expect(response.code).to eq 200
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
context 'http request' do
|
298
|
+
describe "#post" do
|
299
|
+
it "makes an http POST request" do
|
300
|
+
stub_post('/users').with(
|
301
|
+
:headers => {
|
302
|
+
'Accept'=>'application/json',
|
303
|
+
'Authorization'=>'Bearer TolNOFka9Uls2DxahNi78A',
|
304
|
+
'Content-Type'=>'application/x-www-form-urlencoded',
|
305
|
+
'User-Agent'=>"Yammer Ruby Gem #{Yammer::Version}"
|
306
|
+
},
|
307
|
+
:body => { :name => 'alice' }).to_return({
|
308
|
+
:status => 200, :body => "", :headers => {}
|
309
|
+
})
|
310
|
+
subject.post('/users', { :name => 'alice'})
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
describe "#put" do
|
315
|
+
it "makes an http PUT request" do
|
316
|
+
stub_put('/users/1').with(
|
317
|
+
:headers => {
|
318
|
+
'Accept'=>'application/json',
|
319
|
+
'Authorization'=>'Bearer TolNOFka9Uls2DxahNi78A',
|
320
|
+
'Content-Type'=>'application/x-www-form-urlencoded',
|
321
|
+
'User-Agent'=> "Yammer Ruby Gem #{Yammer::Version}"
|
322
|
+
},
|
323
|
+
:body => { :name => 'bob' }).to_return(
|
324
|
+
:status => 200, :body => "", :headers => {})
|
325
|
+
|
326
|
+
subject.put('/users/1', { :name => 'bob'})
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
330
|
+
describe "#get" do
|
331
|
+
it "makes an http GET request" do
|
332
|
+
stub_get('/users/1').with(:headers => { 'Authorization' => 'Bearer TolNOFka9Uls2DxahNi78A' })
|
333
|
+
subject.get('/users/1')
|
334
|
+
end
|
335
|
+
end
|
336
|
+
|
337
|
+
describe "#delete" do
|
338
|
+
it "makes an http DELETE request" do
|
339
|
+
stub_delete('/users/1').with(:headers => { 'Authorization' => 'Bearer TolNOFka9Uls2DxahNi78A' })
|
340
|
+
subject.delete('/users/1')
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
344
|
+
describe 'with invalid token' do
|
345
|
+
it 'raises exception' do
|
346
|
+
stub_get('/users/1').with(:headers => { 'Authorization' => 'Bearer TolNOFka9Uls2DxahNi78A' }).to_return(
|
347
|
+
:body => '{ "response": { "message": "Token not found.", "code": 16, "stat": "fail" } }',
|
348
|
+
:status => 401)
|
349
|
+
|
350
|
+
expect(subject.get('/users/1')).to eq('{ "response": { "message": "Token not found.", "code": 16, "stat": "fail" } }')
|
351
|
+
end
|
352
|
+
end
|
353
|
+
|
354
|
+
describe 'with too many requests' do
|
355
|
+
it 'raises exception' do
|
356
|
+
stub_get('/users/1').with(:headers => { 'Authorization' => 'Bearer TolNOFka9Uls2DxahNi78A' }).to_return(
|
357
|
+
:body => '{ "response": { "message": "Rate limited due to excessive requests.", "code": 33, "stat": "fail" } }',
|
358
|
+
:status => 429
|
359
|
+
)
|
360
|
+
expect(subject.get('/users/1')).to eq('{ "response": { "message": "Rate limited due to excessive requests.", "code": 33, "stat": "fail" } }')
|
361
|
+
end
|
362
|
+
end
|
363
|
+
end
|
364
|
+
end
|