yammer-client 0.1.2 → 0.1.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.
- data.tar.gz.sig +0 -0
- data/.travis.yml +1 -0
- data/CHANGELOG.md +22 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +3 -4
- data/README.md +11 -10
- data/file.txt +1 -0
- data/lib/yammer.rb +7 -11
- data/lib/yammer/api.rb +2 -1
- data/lib/yammer/api/autocomplete.rb +1 -1
- data/lib/yammer/api/group.rb +5 -5
- data/lib/yammer/api/group_membership.rb +2 -2
- data/lib/yammer/api/message.rb +13 -13
- data/lib/yammer/api/network.rb +1 -1
- data/lib/yammer/api/notification.rb +1 -1
- data/lib/yammer/api/pending_attachment.rb +48 -0
- data/lib/yammer/api/search.rb +1 -1
- data/lib/yammer/api/topic.rb +1 -1
- data/lib/yammer/api/user.rb +17 -17
- data/lib/yammer/api_handler.rb +15 -0
- data/lib/yammer/{response.rb → api_response.rb} +6 -6
- data/lib/yammer/base.rb +19 -11
- data/lib/yammer/client.rb +27 -42
- data/lib/yammer/configurable.rb +14 -8
- data/lib/yammer/group.rb +1 -1
- data/lib/yammer/group_membership.rb +1 -1
- data/lib/yammer/http_adapter.rb +74 -0
- data/lib/yammer/message.rb +1 -1
- data/lib/yammer/thread.rb +1 -1
- data/lib/yammer/user.rb +6 -6
- data/lib/yammer/version.rb +1 -1
- data/spec/api/autocomplete_spec.rb +1 -2
- data/spec/api/group_membership_spec.rb +1 -2
- data/spec/api/group_spec.rb +1 -2
- data/spec/api/message_spec.rb +1 -2
- data/spec/api/network_spec.rb +1 -2
- data/spec/api/notification_spec.rb +3 -4
- data/spec/api/pending_attachment_spec.rb +37 -0
- data/spec/api/search_spec.rb +1 -2
- data/spec/api/thread_spec.rb +1 -2
- data/spec/api/topic_spec.rb +1 -2
- data/spec/api/user_spec.rb +15 -2
- data/spec/{response_spec.rb → api_response.rb} +9 -8
- data/spec/client_spec.rb +203 -66
- data/spec/fixtures/users_followed.json +1 -0
- data/spec/fixtures/users_following.json +1 -0
- data/spec/http_adapter_spec.rb +90 -0
- data/spec/mocks/attachment.txt +1 -0
- data/spec/model/base_spec.rb +26 -5
- data/spec/model/group_membership_spec.rb +11 -0
- data/spec/model/group_spec.rb +10 -0
- data/spec/model/message_spec.rb +10 -0
- data/spec/model/thread_spec.rb +6 -0
- data/spec/model/user_spec.rb +53 -0
- data/spec/spec_helper.rb +8 -0
- data/yammer.gemspec +3 -1
- metadata +35 -10
- metadata.gz.sig +0 -0
- data/lib/yammer/http_connection.rb +0 -184
- data/lib/yammer/model.rb +0 -6
- data/spec/connection_spec.rb +0 -306
metadata.gz.sig
CHANGED
Binary file
|
@@ -1,184 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require 'net/https'
|
3
|
-
rescue LoadError
|
4
|
-
warn "Warning: no such file to load -- net/https. Make sure openssl is installed if you want ssl support"
|
5
|
-
require 'net/http'
|
6
|
-
end
|
7
|
-
require 'zlib'
|
8
|
-
require 'addressable/uri'
|
9
|
-
|
10
|
-
module Yammer
|
11
|
-
class HttpConnection
|
12
|
-
|
13
|
-
class UnhandledHTTPMethodError < StandardError; end
|
14
|
-
class UnsupportedSchemeError < StandardError; end
|
15
|
-
|
16
|
-
NET_HTTP_EXCEPTIONS = [
|
17
|
-
EOFError,
|
18
|
-
Errno::ECONNABORTED,
|
19
|
-
Errno::ECONNREFUSED,
|
20
|
-
Errno::ECONNRESET,
|
21
|
-
Errno::EINVAL,
|
22
|
-
Net::HTTPBadResponse,
|
23
|
-
Net::HTTPHeaderSyntaxError,
|
24
|
-
Net::ProtocolError,
|
25
|
-
SocketError,
|
26
|
-
Zlib::GzipFile::Error,
|
27
|
-
] unless defined? NET_HTTP_EXCEPTIONS
|
28
|
-
|
29
|
-
attr_accessor :config, :scheme, :host, :port, :max_redirects, :ssl,
|
30
|
-
:user_agent, :accept, :max_redirects, :headers, :uri
|
31
|
-
|
32
|
-
def self.default_options
|
33
|
-
{
|
34
|
-
:headers => {
|
35
|
-
'Accept' => 'application/json',
|
36
|
-
'User-Agent' => "Yammer Ruby Gem #{Yammer::Version}"
|
37
|
-
},
|
38
|
-
:ssl => {:verify => true},
|
39
|
-
:max_redirects => 5
|
40
|
-
}
|
41
|
-
end
|
42
|
-
|
43
|
-
def initialize(url, options={})
|
44
|
-
@uri = Addressable::URI.parse(url)
|
45
|
-
self.class.default_options.keys.each do |key|
|
46
|
-
instance_variable_set(:"@#{key}", options.fetch(key, self.class.default_options[key]))
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def default_headers
|
51
|
-
self.class.default_options[:headers]
|
52
|
-
end
|
53
|
-
|
54
|
-
def scheme=(scheme)
|
55
|
-
unless ['http', 'https'].include? scheme
|
56
|
-
raise UnsupportedSchemeError.new "#{scheme} is not supported, only http and https"
|
57
|
-
end
|
58
|
-
@scheme = scheme
|
59
|
-
end
|
60
|
-
|
61
|
-
def scheme
|
62
|
-
@scheme ||= @uri.scheme
|
63
|
-
end
|
64
|
-
|
65
|
-
def host
|
66
|
-
@host ||= @uri.host
|
67
|
-
end
|
68
|
-
|
69
|
-
def port
|
70
|
-
_port = ssl? ? 443 : 80
|
71
|
-
@port = @uri.port || _port
|
72
|
-
end
|
73
|
-
|
74
|
-
def absolute_url(path='')
|
75
|
-
"#{scheme}://#{host}#{path}"
|
76
|
-
end
|
77
|
-
|
78
|
-
def ssl?
|
79
|
-
scheme == "https" ? true : false
|
80
|
-
end
|
81
|
-
|
82
|
-
def ssl=(opts)
|
83
|
-
raise "Expected Hash but got #{opts.class.name}" unless opts.is_a?(Hash)
|
84
|
-
@ssl.merge!(opts)
|
85
|
-
end
|
86
|
-
|
87
|
-
def http_connection(opts={})
|
88
|
-
_host = opts[:host] || host
|
89
|
-
_port = opts[:port] || port
|
90
|
-
_scheme = opts[:scheme] || scheme
|
91
|
-
|
92
|
-
@http_client = Net::HTTP.new(_host, _port)
|
93
|
-
|
94
|
-
configure_ssl(@http_client) if _scheme == 'https'
|
95
|
-
|
96
|
-
@http_client
|
97
|
-
end
|
98
|
-
|
99
|
-
def send_request(method, path, opts={})
|
100
|
-
headers = @headers.merge(opts.fetch(:headers, {}))
|
101
|
-
params = opts[:params] || {}
|
102
|
-
query = Addressable::URI.form_encode(params)
|
103
|
-
method = method.to_sym
|
104
|
-
normalized_path = query.empty? ? path : [path, query].join("?")
|
105
|
-
client = http_connection(opts.fetch(:connection_options, {}))
|
106
|
-
|
107
|
-
if (method == :post || method == :put)
|
108
|
-
headers['Content-Type'] ||= 'application/x-www-form-urlencoded'
|
109
|
-
end
|
110
|
-
|
111
|
-
case method
|
112
|
-
when :get, :delete
|
113
|
-
response = client.send(method, normalized_path, headers)
|
114
|
-
when :post, :put
|
115
|
-
response = client.send(method, path, query, headers)
|
116
|
-
else
|
117
|
-
raise UnhandledHTTPMethodError.new("Unsupported HTTP method, #{method}")
|
118
|
-
end
|
119
|
-
|
120
|
-
status = response.code.to_i
|
121
|
-
|
122
|
-
case status
|
123
|
-
when 301, 302, 303, 307
|
124
|
-
unless redirect_limit_reached?
|
125
|
-
if status == 303
|
126
|
-
method = :get
|
127
|
-
params = nil
|
128
|
-
headers.delete('Content-Type')
|
129
|
-
end
|
130
|
-
redirect_uri = Addressable::URI.parse(response.header['Location'])
|
131
|
-
conn = {
|
132
|
-
:scheme => redirect_uri.scheme,
|
133
|
-
:host => redirect_uri.host,
|
134
|
-
:port => redirect_uri.port
|
135
|
-
}
|
136
|
-
return send_request(method, redirect_uri.path, :params => params, :headers => headers, :connection_options => conn)
|
137
|
-
end
|
138
|
-
when 100..599
|
139
|
-
@redirect_count = 0
|
140
|
-
else
|
141
|
-
raise "Unhandled status code value of #{response.code}"
|
142
|
-
end
|
143
|
-
response
|
144
|
-
rescue *NET_HTTP_EXCEPTIONS
|
145
|
-
raise "Error::ConnectionFailed, #{$!.backtrace}"
|
146
|
-
end
|
147
|
-
|
148
|
-
private
|
149
|
-
|
150
|
-
def configure_ssl(http)
|
151
|
-
http.use_ssl = true
|
152
|
-
http.verify_mode = ssl_verify_mode
|
153
|
-
http.cert_store = ssl_cert_store
|
154
|
-
|
155
|
-
http.cert = ssl[:client_cert] if ssl[:client_cert]
|
156
|
-
http.key = ssl[:client_key] if ssl[:client_key]
|
157
|
-
http.ca_file = ssl[:ca_file] if ssl[:ca_file]
|
158
|
-
http.ca_path = ssl[:ca_path] if ssl[:ca_path]
|
159
|
-
http.verify_depth = ssl[:verify_depth] if ssl[:verify_depth]
|
160
|
-
http.ssl_version = ssl[:version] if ssl[:version]
|
161
|
-
end
|
162
|
-
|
163
|
-
def ssl_verify_mode
|
164
|
-
if ssl.fetch(:verify, true)
|
165
|
-
OpenSSL::SSL::VERIFY_PEER
|
166
|
-
else
|
167
|
-
OpenSSL::SSL::VERIFY_NONE
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
def ssl_cert_store
|
172
|
-
return ssl[:cert_store] if ssl[:cert_store]
|
173
|
-
cert_store = OpenSSL::X509::Store.new
|
174
|
-
cert_store.set_default_paths
|
175
|
-
cert_store
|
176
|
-
end
|
177
|
-
|
178
|
-
def redirect_limit_reached?
|
179
|
-
@redirect_count ||= 0
|
180
|
-
@redirect_count += 1
|
181
|
-
@redirect_count > @max_redirects
|
182
|
-
end
|
183
|
-
end
|
184
|
-
end
|
data/lib/yammer/model.rb
DELETED
data/spec/connection_spec.rb
DELETED
@@ -1,306 +0,0 @@
|
|
1
|
-
require File.expand_path('../spec_helper', __FILE__)
|
2
|
-
require 'yammer/http_connection'
|
3
|
-
|
4
|
-
describe Yammer::HttpConnection do
|
5
|
-
|
6
|
-
before :all do
|
7
|
-
Yammer.configure do |conf|
|
8
|
-
conf.access_token = 'TolNOFka9Uls2DxahNi78A'
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
subject do
|
13
|
-
@conn = Yammer::HttpConnection.new('https://yammer.com')
|
14
|
-
end
|
15
|
-
|
16
|
-
context "with user options" do
|
17
|
-
before do
|
18
|
-
@options = {
|
19
|
-
:headers => {
|
20
|
-
'Accept' => 'application/json',
|
21
|
-
'User-Agent' => "Yammer Ruby Gem #{Yammer::Version}"
|
22
|
-
},
|
23
|
-
:ssl => {:verify => false},
|
24
|
-
:max_redirects => 2
|
25
|
-
}
|
26
|
-
@conn = Yammer::HttpConnection.new('https://microsoft.com', @options)
|
27
|
-
end
|
28
|
-
|
29
|
-
it "overrides default options" do
|
30
|
-
opts = Yammer::HttpConnection.default_options
|
31
|
-
opts.keys.each do |key|
|
32
|
-
expect(@conn.instance_variable_get(:"@#{key}")).to eq @options[key]
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe "#default_headers" do
|
38
|
-
it "returns user_agent and response format" do
|
39
|
-
expect(subject.default_headers).to eq ({
|
40
|
-
"Accept" => "application/json",
|
41
|
-
"User-Agent" => "Yammer Ruby Gem #{Yammer::Version}"
|
42
|
-
})
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe "#scheme" do
|
47
|
-
it "returns the http scheme" do
|
48
|
-
expect(subject.scheme).to eq 'https'
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
describe "#scheme" do
|
53
|
-
context "scheme is unsupported" do
|
54
|
-
it "raises an error" do
|
55
|
-
expect { subject.scheme = 'ftp'}.to raise_error(Yammer::HttpConnection::UnsupportedSchemeError)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
context "scheme is http" do
|
60
|
-
it "sets the scheme" do
|
61
|
-
subject.scheme = 'http'
|
62
|
-
expect(subject.scheme).to eq 'http'
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
context "scheme is https" do
|
67
|
-
it "sets the scheme" do
|
68
|
-
subject.scheme = 'https'
|
69
|
-
expect(subject.scheme).to eq 'https'
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
describe "#host" do
|
75
|
-
it "returns the host server" do
|
76
|
-
expect(subject.host).to eq 'yammer.com'
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
describe "#port" do
|
81
|
-
it "returns the port" do
|
82
|
-
expect(subject.port).to eq 443
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
describe "#ssl?" do
|
87
|
-
context "scheme is https" do
|
88
|
-
it "returns true" do
|
89
|
-
subject.scheme = 'https'
|
90
|
-
expect(subject.ssl?).to eq true
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
context "scheme is http" do
|
95
|
-
it "returns false" do
|
96
|
-
subject.scheme = 'http'
|
97
|
-
expect(subject.ssl?).to eq false
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
describe "#http_connection" do
|
103
|
-
it "behaves like HTTP client" do
|
104
|
-
expect(subject.http_connection).to respond_to(:get)
|
105
|
-
expect(subject.http_connection).to respond_to(:post)
|
106
|
-
expect(subject.http_connection).to respond_to(:put)
|
107
|
-
expect(subject.http_connection).to respond_to(:delete)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
describe "#absolute_url" do
|
112
|
-
context "with no parameters" do
|
113
|
-
it "returns a uri without path" do
|
114
|
-
expect(subject.absolute_url).to eq "https://yammer.com"
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
context "with parameters" do
|
119
|
-
it "returns a uri with path" do
|
120
|
-
expect(subject.absolute_url('/oauth/v2/authorize')).to eq "https://yammer.com/oauth/v2/authorize"
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
describe "#configure_ssl" do
|
126
|
-
end
|
127
|
-
|
128
|
-
describe "#redirect_limit_reached?" do
|
129
|
-
end
|
130
|
-
|
131
|
-
describe "#ssl_verify_mode" do
|
132
|
-
context "ssl verify set to true" do
|
133
|
-
it "returns OpenSSL::SSL::VERIFY_PEER" do
|
134
|
-
subject.ssl = { :verify => true }
|
135
|
-
expect(subject.send(:ssl_verify_mode)).to eq OpenSSL::SSL::VERIFY_PEER
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
context "ssl verify set to false" do
|
140
|
-
it "returns OpenSSL::SSL::VERIFY_NONE" do
|
141
|
-
subject.ssl = { :verify => false }
|
142
|
-
expect(subject.send(:ssl_verify_mode)).to eq OpenSSL::SSL::VERIFY_NONE
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
describe "ssl_cert_store" do
|
148
|
-
end
|
149
|
-
|
150
|
-
describe "#send_request" do
|
151
|
-
before do
|
152
|
-
@http_ok = OpenStruct.new(
|
153
|
-
:code => '200',
|
154
|
-
:body => 'success',
|
155
|
-
:header => {'Content-Type' => "application/json"}
|
156
|
-
)
|
157
|
-
@http_redirect = OpenStruct.new(
|
158
|
-
:code => '301',
|
159
|
-
:body => 'redirect',
|
160
|
-
:header => {'Location' => "http://yammer.com/members"}
|
161
|
-
)
|
162
|
-
end
|
163
|
-
|
164
|
-
context "when method is not supported" do
|
165
|
-
it "raises an error" do
|
166
|
-
expect {subject.send_request(:patch, '/')}.to raise_error(Yammer::HttpConnection::UnhandledHTTPMethodError)
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
context "when method is get" do
|
171
|
-
it "returns an http response" do
|
172
|
-
path = '/oauth/authorize'
|
173
|
-
params = {:client_id => '001337', :client_secret => 'abcxyz'}
|
174
|
-
method = :get
|
175
|
-
|
176
|
-
normalized_path = '/oauth/authorize?client_id=001337&client_secret=abcxyz'
|
177
|
-
|
178
|
-
stub_request(:get, "https://yammer.com/oauth/authorize?client_id=001337&client_secret=abcxyz").with(
|
179
|
-
:headers => {
|
180
|
-
'Accept'=>'application/json',
|
181
|
-
'User-Agent'=>"Yammer Ruby Gem #{Yammer::Version}"
|
182
|
-
})
|
183
|
-
response = subject.send_request(method, path, :params => params)
|
184
|
-
|
185
|
-
expect(response.code).to eq '200'
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
context "when method is delete" do
|
190
|
-
it "returns an http response" do
|
191
|
-
path = '/users/1'
|
192
|
-
method = 'delete'
|
193
|
-
|
194
|
-
stub_request(:delete, "https://yammer.com/users/1").with(
|
195
|
-
:headers => {
|
196
|
-
'Accept'=>'application/json',
|
197
|
-
'User-Agent'=>"Yammer Ruby Gem #{Yammer::Version}"
|
198
|
-
}).to_return(:status => 200, :body => "", :headers => {})
|
199
|
-
|
200
|
-
response = subject.send_request(method, path)
|
201
|
-
expect(response.code).to eq '200'
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
205
|
-
context "when method is post" do
|
206
|
-
it "returns an http response" do
|
207
|
-
path = '/users'
|
208
|
-
params = {:first_name => 'john', :last_name => 'smith'}
|
209
|
-
query = Addressable::URI.form_encode(params)
|
210
|
-
headers = {'Content-Type' => 'application/x-www-form-urlencoded' }.merge(subject.default_headers)
|
211
|
-
|
212
|
-
stub_request(:post, "https://yammer.com/users").with(
|
213
|
-
:body => {
|
214
|
-
"first_name"=>"john",
|
215
|
-
"last_name"=>"smith"
|
216
|
-
},
|
217
|
-
:headers => {
|
218
|
-
'Accept'=>'application/json',
|
219
|
-
'Content-Type'=>'application/x-www-form-urlencoded',
|
220
|
-
'User-Agent'=>"Yammer Ruby Gem #{Yammer::Version}"
|
221
|
-
}).to_return(:status => 200, :body => "", :headers => {})
|
222
|
-
|
223
|
-
response =subject.send_request(:post, path, :params => params)
|
224
|
-
expect(response.code).to eq '200'
|
225
|
-
end
|
226
|
-
end
|
227
|
-
|
228
|
-
context "when method is put" do
|
229
|
-
it "returns an http response" do
|
230
|
-
path = '/users/1'
|
231
|
-
params = {:first_name => 'jane', :last_name => 'doe'}
|
232
|
-
query = Addressable::URI.form_encode(params)
|
233
|
-
headers = {'Content-Type' => 'application/x-www-form-urlencoded' }.merge(subject.default_headers)
|
234
|
-
|
235
|
-
stub_request(:put, "https://yammer.com/users/1").with(
|
236
|
-
:body => {
|
237
|
-
"first_name" => "jane",
|
238
|
-
"last_name" => "doe"
|
239
|
-
},
|
240
|
-
:headers => {
|
241
|
-
'Accept'=>'application/json',
|
242
|
-
'Content-Type'=>'application/x-www-form-urlencoded',
|
243
|
-
'User-Agent'=>"Yammer Ruby Gem #{Yammer::Version}"
|
244
|
-
}).
|
245
|
-
to_return(:status => 200, :body => "", :headers => {})
|
246
|
-
|
247
|
-
response = subject.send_request(:put, path, :params => params)
|
248
|
-
expect(response.code).to eq '200'
|
249
|
-
end
|
250
|
-
end
|
251
|
-
|
252
|
-
it "follows redirect" do
|
253
|
-
path = '/users'
|
254
|
-
params = {:first_name => 'jane', :last_name => 'doe'}
|
255
|
-
query = Addressable::URI.form_encode(params)
|
256
|
-
headers = {'Content-Type' => 'application/x-www-form-urlencoded' }.merge(subject.default_headers)
|
257
|
-
client = double("client")
|
258
|
-
|
259
|
-
subject.should_receive(:http_connection).twice.and_return(client, client)
|
260
|
-
client.should_receive(:post).ordered.with(path, query, headers).and_return(@http_redirect)
|
261
|
-
client.should_receive(:post).ordered.with('/members', query, headers).and_return(@http_ok)
|
262
|
-
|
263
|
-
response = subject.send_request(:post, path, :params => params)
|
264
|
-
|
265
|
-
expect(response.code).to eq '200'
|
266
|
-
end
|
267
|
-
|
268
|
-
it "respects the redirect limit " do
|
269
|
-
subject.max_redirects = 1
|
270
|
-
path = '/users'
|
271
|
-
params = {:first_name => 'jane', :last_name => 'doe'}
|
272
|
-
query = Addressable::URI.form_encode(params)
|
273
|
-
headers = {'Content-Type' => 'application/x-www-form-urlencoded' }.merge(subject.default_headers)
|
274
|
-
client = double("client")
|
275
|
-
|
276
|
-
subject.should_receive(:http_connection).twice.and_return(client, client)
|
277
|
-
client.should_receive(:post).ordered.with(path, query, headers).and_return(@http_redirect)
|
278
|
-
client.should_receive(:post).ordered.with('/members', query, headers).and_return(@http_redirect)
|
279
|
-
|
280
|
-
response = subject.send_request(:post, path, :params => params)
|
281
|
-
|
282
|
-
expect(response.code).to eq '301'
|
283
|
-
end
|
284
|
-
|
285
|
-
it "modifies http 303 redirect from POST to GET " do
|
286
|
-
http_303 = OpenStruct.new(
|
287
|
-
:code => '303',
|
288
|
-
:body => 'redirect',
|
289
|
-
:header => {'Location' => "http://yammer.com/members"}
|
290
|
-
)
|
291
|
-
path = '/users'
|
292
|
-
params = {:first_name => 'jane', :last_name => 'doe'}
|
293
|
-
query = Addressable::URI.form_encode(params)
|
294
|
-
headers = {'Content-Type' => 'application/x-www-form-urlencoded' }.merge(subject.default_headers)
|
295
|
-
client = double("client")
|
296
|
-
|
297
|
-
subject.should_receive(:http_connection).twice.and_return(client, client)
|
298
|
-
client.should_receive(:post).ordered.with(path, query, headers).and_return(http_303)
|
299
|
-
client.should_receive(:get).ordered.with('/members', subject.default_headers).and_return(@http_ok)
|
300
|
-
|
301
|
-
response = subject.send_request(:post, path, :params => params)
|
302
|
-
|
303
|
-
expect(response.code).to eq '200'
|
304
|
-
end
|
305
|
-
end
|
306
|
-
end
|