koala 1.11.1 → 2.0.0rc1
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/changelog.md +21 -2
- data/lib/koala.rb +3 -11
- data/lib/koala/api.rb +1 -3
- data/lib/koala/api/graph_api.rb +1 -15
- data/lib/koala/api/graph_batch_api.rb +2 -2
- data/lib/koala/http_service.rb +1 -118
- data/lib/koala/oauth.rb +0 -56
- data/lib/koala/realtime_updates.rb +0 -6
- data/lib/koala/test_users.rb +0 -7
- data/lib/koala/version.rb +1 -1
- data/readme.md +1 -1
- data/spec/cases/graph_api_batch_spec.rb +15 -2
- data/spec/cases/http_service_spec.rb +0 -166
- data/spec/cases/koala_spec.rb +0 -29
- data/spec/cases/oauth_spec.rb +315 -482
- data/spec/cases/realtime_updates_spec.rb +0 -12
- data/spec/cases/test_users_spec.rb +8 -20
- data/spec/fixtures/mock_facebook_responses.yml +0 -10
- data/spec/support/graph_api_shared_examples.rb +1 -30
- data/spec/support/koala_test.rb +1 -4
- data/spec/support/rest_api_shared_examples.rb +1 -1
- metadata +3 -6
- data/lib/koala/api/legacy.rb +0 -26
- data/spec/cases/legacy_spec.rb +0 -115
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01598f2db0d23da8cbd84470160a9cba1084716f
|
4
|
+
data.tar.gz: a6f806ca786838e52ed397491302183e9d9baf49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b37d3eeff4c01d7258cbbe100d2a782c21b2e67a9f0e15d8d42beb896a5b20480757b8a8aab7527255180a635099ac84f7a96057f687d989c0f1103c1bfcb7f3
|
7
|
+
data.tar.gz: 57a67e64453cfb7b5778e5b87d1dfeebbcdb4f9dcad369e0c1a5d6e83915531feaa26e72a6eb3671becca3dbdd516cc94b0eec29d4b30455134098073d9e0e0a
|
data/changelog.md
CHANGED
@@ -1,5 +1,24 @@
|
|
1
|
+
v2.0.0
|
2
|
+
======
|
3
|
+
|
4
|
+
Koala 2.0 is not a major refactor, but rather a set of small, mostly internal
|
5
|
+
refactors:
|
6
|
+
|
7
|
+
* BatchAPI now reads both access token and app secret from the original API
|
8
|
+
instance (thanks, lukeasrodgers!)
|
9
|
+
* Remove legacy interfaces (deprecated since 1.2)
|
10
|
+
* API#search (which Facebook doesn't support anymore)
|
11
|
+
* TestUser#graph\_api and RealtimeUpdates#graph\_api (use #api instead)
|
12
|
+
* Various HTTP options (see diff for deprecation warnings/upgrade
|
13
|
+
instructions for each method)
|
14
|
+
* NetHTTPService and TyphoeusHTTPService (see diff for deprecation
|
15
|
+
warnings/upgrade instructions)
|
16
|
+
* OAuth methods for dealing with session tokens (which Facebook stopped
|
17
|
+
providing)
|
18
|
+
* OAuth#get\_user\_from\_cookies (use get\_user\_info\_from\_cookies instead)
|
19
|
+
|
1
20
|
v.1.11.1
|
2
|
-
|
21
|
+
========
|
3
22
|
|
4
23
|
Bug fixes:
|
5
24
|
* Properly import Facebook error attributes (thanks, isra17!)
|
@@ -14,7 +33,7 @@ Updated features:
|
|
14
33
|
|
15
34
|
Bug fixes:
|
16
35
|
* Fixed bug in GraphCollection URL versioning (thanks, deviousdodo and jankowy!)
|
17
|
-
* TestUsers#
|
36
|
+
* TestUsers#create\_network now properly handles options (thanks, crx!)
|
18
37
|
|
19
38
|
Documentation improvements:
|
20
39
|
* Updated gem version (thanks, thomasklemm!)
|
data/lib/koala.rb
CHANGED
@@ -53,18 +53,10 @@ module Koala
|
|
53
53
|
end
|
54
54
|
|
55
55
|
# @private
|
56
|
-
#
|
57
|
-
# For deprecated services (Typhoeus and Net::HTTP), print a warning and set the default Faraday adapter appropriately.
|
56
|
+
# Switch the HTTP service -- mostly used for testing.
|
58
57
|
def self.http_service=(service)
|
59
|
-
if
|
60
|
-
|
61
|
-
# by changing the default adapter so the right library is used
|
62
|
-
# we continue to use the single HTTPService module for everything
|
63
|
-
service.deprecated_interface
|
64
|
-
else
|
65
|
-
# if it's a real http_service, use it
|
66
|
-
@http_service = service
|
67
|
-
end
|
58
|
+
# if it's a real http_service, use it
|
59
|
+
@http_service = service
|
68
60
|
end
|
69
61
|
|
70
62
|
# An convenenient alias to Koala.http_service.make_request.
|
data/lib/koala/api.rb
CHANGED
data/lib/koala/api/graph_api.rb
CHANGED
@@ -300,20 +300,6 @@ module Koala
|
|
300
300
|
graph_call("#{id}/likes", {}, "delete", options, &block)
|
301
301
|
end
|
302
302
|
|
303
|
-
# Search for a given query among visible Facebook objects.
|
304
|
-
# See {http://developers.facebook.com/docs/reference/api/#searching Facebook documentation} for more information.
|
305
|
-
#
|
306
|
-
# @param search_terms the query to search for
|
307
|
-
# @param args additional arguments, such as type, fields, etc.
|
308
|
-
# @param options (see #get_object)
|
309
|
-
# @param block (see Koala::Facebook::API#api)
|
310
|
-
#
|
311
|
-
# @return [Koala::Facebook::API::GraphCollection] an array of search results
|
312
|
-
def search(search_terms, args = {}, options = {}, &block)
|
313
|
-
args.merge!({:q => search_terms}) unless search_terms.nil?
|
314
|
-
graph_call("search", args, "get", options, &block)
|
315
|
-
end
|
316
|
-
|
317
303
|
# Convenience Methods
|
318
304
|
# In general, we're trying to avoid adding convenience methods to Koala
|
319
305
|
# except to support cases where the Facebook API requires non-standard input
|
@@ -469,7 +455,7 @@ module Koala
|
|
469
455
|
# @return an array of results from your batch calls (as if you'd made them individually),
|
470
456
|
# arranged in the same order they're made.
|
471
457
|
def batch(http_options = {}, &block)
|
472
|
-
batch_client = GraphBatchAPI.new(
|
458
|
+
batch_client = GraphBatchAPI.new(self)
|
473
459
|
if block
|
474
460
|
yield batch_client
|
475
461
|
batch_client.execute(http_options)
|
data/lib/koala/http_service.rb
CHANGED
@@ -81,7 +81,7 @@ module Koala
|
|
81
81
|
params = args.inject({}) {|hash, kv| hash[kv.first.to_s] = kv.last.is_a?(UploadableIO) ? kv.last.to_upload_io : kv.last; hash}
|
82
82
|
|
83
83
|
# figure out our options for this request
|
84
|
-
request_options = {:params => (verb == "get" ? params : {})}.merge(http_options || {}).merge(
|
84
|
+
request_options = {:params => (verb == "get" ? params : {})}.merge(http_options || {}).merge(options)
|
85
85
|
request_options[:use_ssl] = true if args["access_token"] # require https if there's a token
|
86
86
|
if request_options[:use_ssl]
|
87
87
|
ssl = (request_options[:ssl] ||= {})
|
@@ -135,128 +135,11 @@ module Koala
|
|
135
135
|
!!(match && match[1])
|
136
136
|
end
|
137
137
|
|
138
|
-
# deprecations
|
139
|
-
# not elegant or compact code, but temporary
|
140
|
-
|
141
|
-
# @private
|
142
|
-
def self.always_use_ssl
|
143
|
-
Koala::Utils.deprecate("HTTPService.always_use_ssl is now HTTPService.http_options[:use_ssl]; always_use_ssl will be removed in a future version.")
|
144
|
-
http_options[:use_ssl]
|
145
|
-
end
|
146
|
-
|
147
|
-
# @private
|
148
|
-
def self.always_use_ssl=(value)
|
149
|
-
Koala::Utils.deprecate("HTTPService.always_use_ssl is now HTTPService.http_options[:use_ssl]; always_use_ssl will be removed in a future version.")
|
150
|
-
http_options[:use_ssl] = value
|
151
|
-
end
|
152
|
-
|
153
|
-
# @private
|
154
|
-
def self.timeout
|
155
|
-
Koala::Utils.deprecate("HTTPService.timeout is now HTTPService.http_options[:timeout]; .timeout will be removed in a future version.")
|
156
|
-
http_options[:timeout]
|
157
|
-
end
|
158
|
-
|
159
|
-
# @private
|
160
|
-
def self.timeout=(value)
|
161
|
-
Koala::Utils.deprecate("HTTPService.timeout is now HTTPService.http_options[:timeout]; .timeout will be removed in a future version.")
|
162
|
-
http_options[:timeout] = value
|
163
|
-
end
|
164
|
-
|
165
|
-
# @private
|
166
|
-
def self.proxy
|
167
|
-
Koala::Utils.deprecate("HTTPService.proxy is now HTTPService.http_options[:proxy]; .proxy will be removed in a future version.")
|
168
|
-
http_options[:proxy]
|
169
|
-
end
|
170
|
-
|
171
|
-
# @private
|
172
|
-
def self.proxy=(value)
|
173
|
-
Koala::Utils.deprecate("HTTPService.proxy is now HTTPService.http_options[:proxy]; .proxy will be removed in a future version.")
|
174
|
-
http_options[:proxy] = value
|
175
|
-
end
|
176
|
-
|
177
|
-
# @private
|
178
|
-
def self.ca_path
|
179
|
-
Koala::Utils.deprecate("HTTPService.ca_path is now (HTTPService.http_options[:ssl] ||= {})[:ca_path]; .ca_path will be removed in a future version.")
|
180
|
-
(http_options[:ssl] || {})[:ca_path]
|
181
|
-
end
|
182
|
-
|
183
|
-
# @private
|
184
|
-
def self.ca_path=(value)
|
185
|
-
Koala::Utils.deprecate("HTTPService.ca_path is now (HTTPService.http_options[:ssl] ||= {})[:ca_path]; .ca_path will be removed in a future version.")
|
186
|
-
(http_options[:ssl] ||= {})[:ca_path] = value
|
187
|
-
end
|
188
|
-
|
189
|
-
# @private
|
190
|
-
def self.ca_file
|
191
|
-
Koala::Utils.deprecate("HTTPService.ca_file is now (HTTPService.http_options[:ssl] ||= {})[:ca_file]; .ca_file will be removed in a future version.")
|
192
|
-
(http_options[:ssl] || {})[:ca_file]
|
193
|
-
end
|
194
|
-
|
195
|
-
# @private
|
196
|
-
def self.ca_file=(value)
|
197
|
-
Koala::Utils.deprecate("HTTPService.ca_file is now (HTTPService.http_options[:ssl] ||= {})[:ca_file]; .ca_file will be removed in a future version.")
|
198
|
-
(http_options[:ssl] ||= {})[:ca_file] = value
|
199
|
-
end
|
200
|
-
|
201
|
-
# @private
|
202
|
-
def self.verify_mode
|
203
|
-
Koala::Utils.deprecate("HTTPService.verify_mode is now (HTTPService.http_options[:ssl] ||= {})[:verify_mode]; .verify_mode will be removed in a future version.")
|
204
|
-
(http_options[:ssl] || {})[:verify_mode]
|
205
|
-
end
|
206
|
-
|
207
|
-
# @private
|
208
|
-
def self.verify_mode=(value)
|
209
|
-
Koala::Utils.deprecate("HTTPService.verify_mode is now (HTTPService.http_options[:ssl] ||= {})[:verify_mode]; .verify_mode will be removed in a future version.")
|
210
|
-
(http_options[:ssl] ||= {})[:verify_mode] = value
|
211
|
-
end
|
212
|
-
|
213
138
|
private
|
214
139
|
|
215
|
-
def self.process_options(options)
|
216
|
-
if typhoeus_options = options.delete(:typhoeus_options)
|
217
|
-
Koala::Utils.deprecate("typhoeus_options should now be included directly in the http_options hash. Support for this key will be removed in a future version.")
|
218
|
-
options = options.merge(typhoeus_options)
|
219
|
-
end
|
220
|
-
|
221
|
-
if ca_file = options.delete(:ca_file)
|
222
|
-
Koala::Utils.deprecate("http_options[:ca_file] should now be passed inside (http_options[:ssl] = {}) -- that is, http_options[:ssl][:ca_file]. Support for this key will be removed in a future version.")
|
223
|
-
(options[:ssl] ||= {})[:ca_file] = ca_file
|
224
|
-
end
|
225
|
-
|
226
|
-
if ca_path = options.delete(:ca_path)
|
227
|
-
Koala::Utils.deprecate("http_options[:ca_path] should now be passed inside (http_options[:ssl] = {}) -- that is, http_options[:ssl][:ca_path]. Support for this key will be removed in a future version.")
|
228
|
-
(options[:ssl] ||= {})[:ca_path] = ca_path
|
229
|
-
end
|
230
|
-
|
231
|
-
if verify_mode = options.delete(:verify_mode)
|
232
|
-
Koala::Utils.deprecate("http_options[:verify_mode] should now be passed inside (http_options[:ssl] = {}) -- that is, http_options[:ssl][:verify_mode]. Support for this key will be removed in a future version.")
|
233
|
-
(options[:ssl] ||= {})[:verify_mode] = verify_mode
|
234
|
-
end
|
235
|
-
|
236
|
-
options
|
237
|
-
end
|
238
|
-
|
239
140
|
def self.faraday_options(options)
|
240
141
|
valid_options = [:request, :proxy, :ssl, :builder, :url, :parallel_manager, :params, :headers, :builder_class]
|
241
142
|
Hash[ options.select { |key,value| valid_options.include?(key) } ]
|
242
143
|
end
|
243
144
|
end
|
244
|
-
|
245
|
-
# @private
|
246
|
-
module TyphoeusService
|
247
|
-
def self.deprecated_interface
|
248
|
-
# support old-style interface with a warning
|
249
|
-
Koala::Utils.deprecate("the TyphoeusService module is deprecated; to use Typhoeus, set Faraday.default_adapter = :typhoeus. Enabling Typhoeus for all Faraday connections.")
|
250
|
-
Faraday.default_adapter = :typhoeus
|
251
|
-
end
|
252
|
-
end
|
253
|
-
|
254
|
-
# @private
|
255
|
-
module NetHTTPService
|
256
|
-
def self.deprecated_interface
|
257
|
-
# support old-style interface with a warning
|
258
|
-
Koala::Utils.deprecate("the NetHTTPService module is deprecated; to use Net::HTTP, set Faraday.default_adapter = :net_http. Enabling Net::HTTP for all Faraday connections.")
|
259
|
-
Faraday.default_adapter = :net_http
|
260
|
-
end
|
261
|
-
end
|
262
145
|
end
|
data/lib/koala/oauth.rb
CHANGED
@@ -40,26 +40,6 @@ module Koala
|
|
40
40
|
end
|
41
41
|
alias_method :get_user_info_from_cookie, :get_user_info_from_cookies
|
42
42
|
|
43
|
-
# Parses the cookie set Facebook's JavaScript SDK and returns only the user ID.
|
44
|
-
#
|
45
|
-
# @note (see #get_user_info_from_cookie)
|
46
|
-
#
|
47
|
-
# @param (see #get_user_info_from_cookie)
|
48
|
-
#
|
49
|
-
# @return the authenticated user's Facebook ID, or nil.
|
50
|
-
def get_user_from_cookies(cookies)
|
51
|
-
Koala::Utils.deprecate("Due to Facebook changes, you can only redeem an OAuth code once; it is therefore recommended not to use this method, as it will consume the code without providing you the access token. See https://developers.facebook.com/roadmap/completed-changes/#december-2012.")
|
52
|
-
if signed_cookie = cookies["fbsr_#{@app_id}"]
|
53
|
-
if components = parse_signed_request(signed_cookie)
|
54
|
-
components["user_id"]
|
55
|
-
end
|
56
|
-
elsif info = get_user_info_from_cookies(cookies)
|
57
|
-
# Parsing unsigned cookie
|
58
|
-
info["uid"]
|
59
|
-
end
|
60
|
-
end
|
61
|
-
alias_method :get_user_from_cookie, :get_user_from_cookies
|
62
|
-
|
63
43
|
# URLs
|
64
44
|
|
65
45
|
# Builds an OAuth URL, where users will be prompted to log in and for any desired permissions.
|
@@ -180,7 +160,6 @@ module Koala
|
|
180
160
|
get_token_from_server({:code => code, :redirect_uri => options[:redirect_uri] || @oauth_callback_url}, false, options)
|
181
161
|
end
|
182
162
|
|
183
|
-
|
184
163
|
# Fetches the access token (ignoring expiration and other info) from Facebook.
|
185
164
|
# Useful when you've received an OAuth code using the server-side authentication process.
|
186
165
|
# @see get_access_token_info
|
@@ -272,41 +251,6 @@ module Koala
|
|
272
251
|
envelope
|
273
252
|
end
|
274
253
|
|
275
|
-
# Old session key code
|
276
|
-
|
277
|
-
# @deprecated Facebook no longer provides session keys.
|
278
|
-
def get_token_info_from_session_keys(sessions, options = {})
|
279
|
-
Koala::Utils.deprecate("Facebook no longer provides session keys. The relevant OAuth methods will be removed in the next release.")
|
280
|
-
|
281
|
-
# fetch the OAuth tokens from Facebook
|
282
|
-
response = fetch_token_string({
|
283
|
-
:type => 'client_cred',
|
284
|
-
:sessions => sessions.join(",")
|
285
|
-
}, true, "exchange_sessions", options)
|
286
|
-
|
287
|
-
# Facebook returns an empty body in certain error conditions
|
288
|
-
if response == ""
|
289
|
-
raise BadFacebookResponse.new(200, '', "get_token_from_session_key received an error (empty response body) for sessions #{sessions.inspect}!")
|
290
|
-
end
|
291
|
-
|
292
|
-
MultiJson.load(response)
|
293
|
-
end
|
294
|
-
|
295
|
-
# @deprecated (see #get_token_info_from_session_keys)
|
296
|
-
def get_tokens_from_session_keys(sessions, options = {})
|
297
|
-
# get the original hash results
|
298
|
-
results = get_token_info_from_session_keys(sessions, options)
|
299
|
-
# now recollect them as just the access tokens
|
300
|
-
results.collect { |r| r ? r["access_token"] : nil }
|
301
|
-
end
|
302
|
-
|
303
|
-
# @deprecated (see #get_token_info_from_session_keys)
|
304
|
-
def get_token_from_session_key(session, options = {})
|
305
|
-
# convenience method for a single key
|
306
|
-
# gets the overlaoded strings automatically
|
307
|
-
get_tokens_from_session_keys([session], options)[0]
|
308
|
-
end
|
309
|
-
|
310
254
|
protected
|
311
255
|
|
312
256
|
def get_token_from_server(args, post = false, options = {})
|
@@ -141,12 +141,6 @@ module Koala
|
|
141
141
|
def subscription_path
|
142
142
|
@subscription_path ||= "#{@app_id}/subscriptions"
|
143
143
|
end
|
144
|
-
|
145
|
-
# @private
|
146
|
-
def graph_api
|
147
|
-
Koala::Utils.deprecate("the TestUsers.graph_api accessor is deprecated and will be removed in a future version; please use .api instead.")
|
148
|
-
@api
|
149
|
-
end
|
150
144
|
end
|
151
145
|
end
|
152
146
|
end
|
data/lib/koala/test_users.rb
CHANGED
@@ -183,13 +183,6 @@ module Koala
|
|
183
183
|
def test_user_accounts_path
|
184
184
|
@test_user_accounts_path ||= "/#{@app_id}/accounts/test-users"
|
185
185
|
end
|
186
|
-
|
187
|
-
# @private
|
188
|
-
# Legacy accessor for before GraphAPI was unified into API
|
189
|
-
def graph_api
|
190
|
-
Koala::Utils.deprecate("the TestUsers.graph_api accessor is deprecated and will be removed in a future version; please use .api instead.")
|
191
|
-
@api
|
192
|
-
end
|
193
186
|
end # TestUserMethods
|
194
187
|
end # Facebook
|
195
188
|
end # Koala
|
data/lib/koala/version.rb
CHANGED
data/readme.md
CHANGED
@@ -65,7 +65,7 @@ Koala.config.api_version = "v2.0"
|
|
65
65
|
|
66
66
|
The response of most requests is the JSON data returned from the Facebook servers as a Hash.
|
67
67
|
|
68
|
-
When retrieving data that returns an array of results (for example, when calling `API#get_connections`
|
68
|
+
When retrieving data that returns an array of results (for example, when calling `API#get_connections`)
|
69
69
|
a GraphCollection object will be returned, which makes it easy to page through the results:
|
70
70
|
|
71
71
|
```ruby
|
@@ -56,7 +56,7 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
56
56
|
@uploadable_io = double("UploadableIO 1")
|
57
57
|
|
58
58
|
@batch_queue = []
|
59
|
-
allow(Koala::Facebook::
|
59
|
+
allow(Koala::Facebook::API).to receive(:batch_calls).and_return(@batch_queue)
|
60
60
|
|
61
61
|
allow(Koala::UploadableIO).to receive(:new).with(@binary).and_return(@uploadable_io)
|
62
62
|
allow(Koala::UploadableIO).to receive(:binary_content?).and_return(false)
|
@@ -245,7 +245,7 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
245
245
|
allow(@uploadable_io).to receive(:is_a?).with(Koala::UploadableIO).and_return(true)
|
246
246
|
|
247
247
|
@batch_queue = []
|
248
|
-
allow(Koala::Facebook::
|
248
|
+
allow(Koala::Facebook::API).to receive(:batch_calls).and_return(@batch_queue)
|
249
249
|
|
250
250
|
@args[:method] = "post" # files are always post
|
251
251
|
end
|
@@ -297,6 +297,19 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
297
297
|
end
|
298
298
|
end
|
299
299
|
|
300
|
+
context 'with appsecret_proof and app_secret' do
|
301
|
+
it "includes the app_secret in the API call" do
|
302
|
+
access_token = "foo"
|
303
|
+
app_secret = "baz"
|
304
|
+
app_secret_digest = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new("sha256"), app_secret, access_token)
|
305
|
+
expect(Koala).to receive(:make_request).with(anything, hash_including("access_token" => access_token, "appsecret_proof" => app_secret_digest), anything, anything).and_return(@fake_response)
|
306
|
+
Koala::Facebook::API.new(access_token, app_secret).batch do |batch_api|
|
307
|
+
batch_api.get_object('me')
|
308
|
+
batch_api.get_object('me', {}, {'access_token' => 'bar'})
|
309
|
+
end
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
300
313
|
it "sets args['batch'] to a json'd map of all the batch params" do
|
301
314
|
access_token = "bar"
|
302
315
|
op = Koala::Facebook::GraphBatchAPI::BatchOperation.new(:access_token => access_token, :method => :get, :url => "/")
|
@@ -401,170 +401,4 @@ describe Koala::HTTPService do
|
|
401
401
|
expect(Koala::HTTPService.path_contains_api_version?('/anything')).to be false
|
402
402
|
end
|
403
403
|
end
|
404
|
-
|
405
|
-
describe "deprecated options" do
|
406
|
-
before :each do
|
407
|
-
allow(Koala::HTTPService).to receive(:http_options).and_return({})
|
408
|
-
@service = Koala.http_service
|
409
|
-
end
|
410
|
-
|
411
|
-
after :each do
|
412
|
-
Koala.http_service = @service
|
413
|
-
end
|
414
|
-
|
415
|
-
{
|
416
|
-
:timeout => :timeout,
|
417
|
-
:always_use_ssl => :use_ssl,
|
418
|
-
:proxy => :proxy
|
419
|
-
}.each_pair do |deprecated_method, parameter|
|
420
|
-
describe ".#{deprecated_method}" do
|
421
|
-
context "read" do
|
422
|
-
it "reads http_options[:#{parameter}]" do
|
423
|
-
value = "foo"
|
424
|
-
Koala::HTTPService.http_options[parameter] = value
|
425
|
-
expect(Koala::HTTPService.send(deprecated_method)).to eq(value)
|
426
|
-
end
|
427
|
-
|
428
|
-
it "generates a deprecation warning" do
|
429
|
-
expect(Koala::Utils).to receive(:deprecate)
|
430
|
-
Koala::HTTPService.send(deprecated_method)
|
431
|
-
end
|
432
|
-
end
|
433
|
-
|
434
|
-
context "write" do
|
435
|
-
it "writes to http_options[:#{parameter}]" do
|
436
|
-
Koala::HTTPService.http_options[parameter] = nil
|
437
|
-
value = "foo"
|
438
|
-
Koala::HTTPService.send(:"#{deprecated_method}=", value)
|
439
|
-
expect(Koala::HTTPService.http_options[parameter]).to eq(value)
|
440
|
-
end
|
441
|
-
|
442
|
-
it "generates a deprecation warning" do
|
443
|
-
expect(Koala::Utils).to receive(:deprecate)
|
444
|
-
Koala::HTTPService.send(:"#{deprecated_method}=", 2)
|
445
|
-
end
|
446
|
-
end
|
447
|
-
end
|
448
|
-
end
|
449
|
-
|
450
|
-
# ssl options
|
451
|
-
[:ca_path, :ca_file, :verify_mode].each do |deprecated_method|
|
452
|
-
describe ".#{deprecated_method}" do
|
453
|
-
context "read" do
|
454
|
-
it "reads http_options[:ssl][:#{deprecated_method}] if http_options[:ssl]" do
|
455
|
-
value = "foo"
|
456
|
-
Koala::HTTPService.http_options[:ssl] = {deprecated_method => value}
|
457
|
-
expect(Koala::HTTPService.send(deprecated_method)).to eq(value)
|
458
|
-
end
|
459
|
-
|
460
|
-
it "returns nil if http_options[:ssl] is not defined" do
|
461
|
-
expect(Koala::HTTPService.send(deprecated_method)).to be_nil
|
462
|
-
end
|
463
|
-
|
464
|
-
it "generates a deprecation warning" do
|
465
|
-
expect(Koala::Utils).to receive(:deprecate)
|
466
|
-
Koala::HTTPService.send(deprecated_method)
|
467
|
-
end
|
468
|
-
end
|
469
|
-
|
470
|
-
context "write" do
|
471
|
-
it "defines http_options[:ssl] if not defined" do
|
472
|
-
Koala::HTTPService.http_options[:ssl] = nil
|
473
|
-
value = "foo"
|
474
|
-
Koala::HTTPService.send(:"#{deprecated_method}=", value)
|
475
|
-
expect(Koala::HTTPService.http_options[:ssl]).to be_a(Hash)
|
476
|
-
end
|
477
|
-
|
478
|
-
it "writes to http_options[:ssl][:#{deprecated_method}]" do
|
479
|
-
value = "foo"
|
480
|
-
Koala::HTTPService.send(:"#{deprecated_method}=", value)
|
481
|
-
expect(Koala::HTTPService.http_options[:ssl]).to be_a(Hash)
|
482
|
-
expect(Koala::HTTPService.http_options[:ssl][deprecated_method]).to eq(value)
|
483
|
-
end
|
484
|
-
|
485
|
-
it "does not redefine http_options[:ssl] if already defined" do
|
486
|
-
hash = {:a => 2}
|
487
|
-
Koala::HTTPService.http_options[:ssl] = hash
|
488
|
-
Koala::HTTPService.send(:"#{deprecated_method}=", 3)
|
489
|
-
expect(Koala::HTTPService.http_options[:ssl]).to include(hash)
|
490
|
-
end
|
491
|
-
|
492
|
-
it "generates a deprecation warning" do
|
493
|
-
expect(Koala::Utils).to receive(:deprecate)
|
494
|
-
Koala::HTTPService.send(:"#{deprecated_method}=", 2)
|
495
|
-
end
|
496
|
-
end
|
497
|
-
end
|
498
|
-
end
|
499
|
-
|
500
|
-
describe "per-request options" do
|
501
|
-
before :each do
|
502
|
-
# Setup stubs for make_request to execute without exceptions
|
503
|
-
@mock_body = double('Typhoeus response body')
|
504
|
-
@mock_headers_hash = double({:value => "headers hash"})
|
505
|
-
@mock_http_response = double("Faraday Response", :status => 200, :headers => @mock_headers_hash, :body => @mock_body)
|
506
|
-
|
507
|
-
@mock_connection = double("Faraday connection")
|
508
|
-
allow(@mock_connection).to receive(:get).and_return(@mock_http_response)
|
509
|
-
allow(@mock_connection).to receive(:post).and_return(@mock_http_response)
|
510
|
-
allow(Faraday).to receive(:new).and_return(@mock_connection)
|
511
|
-
end
|
512
|
-
|
513
|
-
describe ":typhoeus_options" do
|
514
|
-
it "merges any typhoeus_options into options" do
|
515
|
-
typhoeus_options = {:proxy => "http://user:password@example.org/" }
|
516
|
-
expect(Faraday).to receive(:new).with(anything, hash_including(typhoeus_options)).and_return(@mock_connection)
|
517
|
-
Koala::HTTPService.make_request("anything", {}, "get", :typhoeus_options => typhoeus_options)
|
518
|
-
end
|
519
|
-
|
520
|
-
it "deletes the typhoeus_options key" do
|
521
|
-
typhoeus_options = {:proxy => "http://user:password@example.org/" }
|
522
|
-
expect(Faraday).to receive(:new).with(anything, hash_not_including(:typhoeus_options => typhoeus_options)).and_return(@mock_connection)
|
523
|
-
Koala::HTTPService.make_request("anything", {}, "get", :typhoeus_options => typhoeus_options)
|
524
|
-
end
|
525
|
-
end
|
526
|
-
|
527
|
-
describe ":ca_path" do
|
528
|
-
it "sets any ca_path into options[:ssl]" do
|
529
|
-
ca_path = :foo
|
530
|
-
expect(Faraday).to receive(:new).with(anything, hash_including(:ssl => hash_including(:ca_path => ca_path))).and_return(@mock_connection)
|
531
|
-
Koala::HTTPService.make_request("anything", {}, "get", :ca_path => ca_path)
|
532
|
-
end
|
533
|
-
|
534
|
-
it "deletes the ca_path key" do
|
535
|
-
ca_path = :foo
|
536
|
-
expect(Faraday).to receive(:new).with(anything, hash_not_including(:ca_path => ca_path)).and_return(@mock_connection)
|
537
|
-
Koala::HTTPService.make_request("anything", {}, "get", :ca_path => ca_path)
|
538
|
-
end
|
539
|
-
end
|
540
|
-
|
541
|
-
describe ":ca_file" do
|
542
|
-
it "sets any ca_file into options[:ssl]" do
|
543
|
-
ca_file = :foo
|
544
|
-
expect(Faraday).to receive(:new).with(anything, hash_including(:ssl => hash_including(:ca_file => ca_file))).and_return(@mock_connection)
|
545
|
-
Koala::HTTPService.make_request("anything", {}, "get", :ca_file => ca_file)
|
546
|
-
end
|
547
|
-
|
548
|
-
it "deletes the ca_file key" do
|
549
|
-
ca_file = :foo
|
550
|
-
expect(Faraday).to receive(:new).with(anything, hash_not_including(:ca_file => ca_file)).and_return(@mock_connection)
|
551
|
-
Koala::HTTPService.make_request("anything", {}, "get", :ca_file => ca_file)
|
552
|
-
end
|
553
|
-
end
|
554
|
-
|
555
|
-
describe ":verify_mode" do
|
556
|
-
it "sets any verify_mode into options[:ssl]" do
|
557
|
-
verify_mode = :foo
|
558
|
-
expect(Faraday).to receive(:new).with(anything, hash_including(:ssl => hash_including(:verify_mode => verify_mode))).and_return(@mock_connection)
|
559
|
-
Koala::HTTPService.make_request("anything", {}, "get", :verify_mode => verify_mode)
|
560
|
-
end
|
561
|
-
|
562
|
-
it "deletes the verify_mode key" do
|
563
|
-
verify_mode = :foo
|
564
|
-
expect(Faraday).to receive(:new).with(anything, hash_not_including(:verify_mode => verify_mode)).and_return(@mock_connection)
|
565
|
-
Koala::HTTPService.make_request("anything", {}, "get", :verify_mode => verify_mode)
|
566
|
-
end
|
567
|
-
end
|
568
|
-
end
|
569
|
-
end
|
570
404
|
end
|