koala 0.9.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.autotest +12 -0
- data/.gitignore +5 -0
- data/.travis.yml +8 -0
- data/CHANGELOG +71 -7
- data/Gemfile +7 -0
- data/LICENSE +1 -1
- data/Manifest +10 -15
- data/Rakefile +13 -13
- data/autotest/discover.rb +1 -0
- data/koala.gemspec +36 -16
- data/lib/koala/batch_operation.rb +74 -0
- data/lib/koala/graph_api.rb +200 -134
- data/lib/koala/graph_batch_api.rb +87 -0
- data/lib/koala/graph_collection.rb +54 -0
- data/lib/koala/http_services/net_http_service.rb +92 -0
- data/lib/koala/http_services/typhoeus_service.rb +37 -0
- data/lib/koala/http_services.rb +22 -47
- data/lib/koala/oauth.rb +181 -0
- data/lib/koala/realtime_updates.rb +5 -14
- data/lib/koala/rest_api.rb +82 -10
- data/lib/koala/test_users.rb +85 -0
- data/lib/koala/uploadable_io.rb +175 -0
- data/lib/koala.rb +67 -229
- data/readme.md +71 -38
- data/spec/cases/api_base_spec.rb +101 -0
- data/spec/cases/graph_and_rest_api_spec.rb +31 -0
- data/spec/cases/graph_api_batch_spec.rb +609 -0
- data/spec/cases/graph_api_spec.rb +25 -0
- data/spec/cases/http_services/http_service_spec.rb +129 -0
- data/spec/cases/http_services/net_http_service_spec.rb +532 -0
- data/spec/cases/http_services/typhoeus_service_spec.rb +152 -0
- data/spec/cases/koala_spec.rb +55 -0
- data/spec/cases/oauth_spec.rb +409 -0
- data/spec/cases/realtime_updates_spec.rb +184 -0
- data/spec/cases/rest_api_spec.rb +25 -0
- data/spec/cases/test_users_spec.rb +221 -0
- data/spec/cases/uploadable_io_spec.rb +193 -0
- data/spec/fixtures/beach.jpg +0 -0
- data/spec/fixtures/cat.m4v +0 -0
- data/spec/{facebook_data.yml → fixtures/facebook_data.yml} +18 -14
- data/spec/fixtures/mock_facebook_responses.yml +409 -0
- data/spec/spec_helper.rb +19 -0
- data/spec/support/graph_api_shared_examples.rb +495 -0
- data/spec/support/json_testing_fix.rb +18 -0
- data/spec/support/live_testing_data_helper.rb +40 -0
- data/spec/support/mock_http_service.rb +96 -0
- data/spec/support/rest_api_shared_examples.rb +285 -0
- data/spec/support/setup_mocks_or_live.rb +51 -0
- data/spec/support/uploadable_io_shared_examples.rb +76 -0
- metadata +131 -59
- data/examples/oauth_playground/Capfile +0 -2
- data/examples/oauth_playground/LICENSE +0 -22
- data/examples/oauth_playground/Rakefile +0 -4
- data/examples/oauth_playground/config/deploy.rb +0 -39
- data/examples/oauth_playground/config/facebook.yml +0 -13
- data/examples/oauth_playground/config.ru +0 -27
- data/examples/oauth_playground/lib/load_facebook.rb +0 -3
- data/examples/oauth_playground/lib/oauth_playground.rb +0 -187
- data/examples/oauth_playground/readme.md +0 -8
- data/examples/oauth_playground/spec/oauth_playground_spec.rb +0 -35
- data/examples/oauth_playground/spec/spec_helper.rb +0 -36
- data/examples/oauth_playground/tmp/restart.txt +0 -0
- data/examples/oauth_playground/views/index.erb +0 -206
- data/examples/oauth_playground/views/layout.erb +0 -39
- data/init.rb +0 -2
- data/spec/koala/api_base_tests.rb +0 -95
- data/spec/koala/graph_and_rest_api/graph_and_rest_api_no_token_tests.rb +0 -10
- data/spec/koala/graph_and_rest_api/graph_and_rest_api_with_token_tests.rb +0 -11
- data/spec/koala/graph_api/graph_api_no_access_token_tests.rb +0 -114
- data/spec/koala/graph_api/graph_api_with_access_token_tests.rb +0 -150
- data/spec/koala/graph_api/graph_collection_tests.rb +0 -104
- data/spec/koala/live_testing_data_helper.rb +0 -15
- data/spec/koala/net_http_service_tests.rb +0 -181
- data/spec/koala/oauth/oauth_tests.rb +0 -440
- data/spec/koala/realtime_updates/realtime_updates_tests.rb +0 -187
- data/spec/koala/rest_api/rest_api_no_access_token_tests.rb +0 -94
- data/spec/koala/rest_api/rest_api_with_access_token_tests.rb +0 -36
- data/spec/koala_spec.rb +0 -18
- data/spec/koala_spec_helper.rb +0 -31
- data/spec/koala_spec_without_mocks.rb +0 -19
- data/spec/mock_facebook_responses.yml +0 -241
- data/spec/mock_http_service.rb +0 -81
data/.autotest
ADDED
data/.travis.yml
ADDED
data/CHANGELOG
CHANGED
|
@@ -1,10 +1,74 @@
|
|
|
1
|
+
v1.1
|
|
2
|
+
New methods:
|
|
3
|
+
-- Added Batch API support (thanks, seejohnrun and spiegela!)
|
|
4
|
+
-- includes file uploads, error handling, and FQL
|
|
5
|
+
-- Added GraphAPI#put_video
|
|
6
|
+
-- Added GraphAPI#get_comments_for_urls (thanks, amrnt!)
|
|
7
|
+
-- Added RestAPI#fql_multiquery, which simplifies the results (thanks, amrnt!)
|
|
8
|
+
-- HTTP services support global proxy and timeout settings (thanks, itchy!)
|
|
9
|
+
-- Net::HTTP supports global ca_path, ca_file, and verify_mode settings (thanks, spiegela!)
|
|
10
|
+
Updated methods:
|
|
11
|
+
-- RealtimeUpdates now uses a GraphAPI object instead of its own API
|
|
12
|
+
-- RestAPI#rest_call now has an optional last argument for method, for calls requiring POST, DELETE, etc. (thanks, sshilo!)
|
|
13
|
+
-- Filename can now be specified when uploading (e.g. for Ads API) (thanks, sshilo!)
|
|
14
|
+
-- get_objects([]) returns [] instead of a Facebook error in non-batch mode (thanks, aselder!)
|
|
15
|
+
Internal improvements:
|
|
16
|
+
-- Koala is now more compatible with other Rubies (JRuby, Rubinius, etc.)
|
|
17
|
+
-- HTTP services are more modular and can be changed on the fly (thanks, chadk!)
|
|
18
|
+
-- Includes support for uploading StringIOs and other non-files via Net::HTTP even when using TyphoeusService
|
|
19
|
+
-- Koala now uses multi_json to improve compatibility with Rubinius and other Ruby versions
|
|
20
|
+
-- Koala now uses the modern Typhoeus API (thanks, aselder!)
|
|
21
|
+
-- Koala now uses the current modern Net::HTTP interface (thanks, romanbsd!)
|
|
22
|
+
-- Fixed bugs and typos (thanks, waynn, mokevnin, and tikh!)
|
|
23
|
+
|
|
24
|
+
v1.0
|
|
25
|
+
New methods:
|
|
26
|
+
-- Photo and file upload now supported through #put_picture
|
|
27
|
+
-- Added UploadableIO class to manage file uploads
|
|
28
|
+
-- Added a delete_like method (thanks to waseem)
|
|
29
|
+
-- Added put_connection and delete_connection convenience methods
|
|
30
|
+
Updated methods:
|
|
31
|
+
-- Search can now search places, checkins, etc. (thanks, rickyc!)
|
|
32
|
+
-- You can now pass :beta => true in the http options to use Facebook's beta tier
|
|
33
|
+
-- TestUser#befriend now requires user info hashes (id and access token) due to Facebook API changes (thanks, pulsd and kbighorse!)
|
|
34
|
+
-- All methods now accept an http_options hash as their optional last parameter (thanks, spiegela!)
|
|
35
|
+
-- url_for_oauth_code can now take a :display option (thanks, netbe!)
|
|
36
|
+
-- Net::HTTP can now accept :timeout and :proxy options (thanks, gilles!)
|
|
37
|
+
-- Test users now supports using test accounts across multiple apps
|
|
38
|
+
Internal improvements:
|
|
39
|
+
-- For public requests, Koala now uses http by default (instead of https) to improve speed
|
|
40
|
+
-- This can be overridden through Koala.always_use_ssl= or by passing :use_ssl => true in the options hash for an api call
|
|
41
|
+
-- Read-only REST API requests now go through the faster api-read server
|
|
42
|
+
-- Replaced parse_signed_request with a version from Facebook that also supports the new signed params proposal
|
|
43
|
+
-- Note: invalid requests will now raise exceptions rather than return nil, in keeping with other SDKs
|
|
44
|
+
-- Delete methods will now raise an error if there's no access token (like put_object and delete_like)
|
|
45
|
+
-- Updated parse_signed_request to match Facebook's current implementation (thanks, imajes!)
|
|
46
|
+
-- APIError is now < StandardError, not Exception
|
|
47
|
+
-- Added KoalaError for non-API errors
|
|
48
|
+
-- Net::HTTP's SSL verification is no longer disabled by default
|
|
49
|
+
Test improvements:
|
|
50
|
+
-- Incorporated joshk's awesome rewrite of the entire Koala test suite (thanks, joshk!)
|
|
51
|
+
-- Expanded HTTP service tests (added Typhoeus test suite and additional Net::HTTP test cases)
|
|
52
|
+
-- Live tests now verify that the access token has the necessary permissions before starting
|
|
53
|
+
-- Replaced the 50-person network test, which often took 15+ minutes to run live, with a 5-person test
|
|
54
|
+
|
|
55
|
+
v0.10.0
|
|
56
|
+
-- Added test user module
|
|
57
|
+
-- Fixed bug when raising APIError after Facebook fails to exchange session keys
|
|
58
|
+
-- Made access_token accessible via the readonly access_token property on all our API classes
|
|
59
|
+
|
|
60
|
+
v0.9.1
|
|
61
|
+
-- Tests are now compatible with Ruby 1.9.2
|
|
62
|
+
-- Added JSON to runtime dependencies
|
|
63
|
+
-- Removed examples directory (referenced from github instead)
|
|
64
|
+
|
|
1
65
|
v0.9.0
|
|
2
66
|
-- Added parse_signed_request to handle Facebook's new authentication scheme
|
|
3
67
|
-- note: creates dependency on OpenSSL (OpenSSL::HMAC) for decryption
|
|
4
|
-
-- Added GraphCollection class to provide paging support for GraphAPI get_connections and search methods (thanks to jagthedrummer)
|
|
68
|
+
-- Added GraphCollection class to provide paging support for GraphAPI get_connections and search methods (thanks to jagthedrummer)
|
|
5
69
|
-- Added get_page method to easily fetch pages of results from GraphCollections
|
|
6
70
|
-- Exchanging sessions for tokens now works properly when provided invalid/expired session keys
|
|
7
|
-
-- You can now include a :typhoeus_options key in TyphoeusService#make_request's options hash to control the Typhoeus call (for example, to set :disable_ssl_peer_verification => true)
|
|
71
|
+
-- You can now include a :typhoeus_options key in TyphoeusService#make_request's options hash to control the Typhoeus call (for example, to set :disable_ssl_peer_verification => true)
|
|
8
72
|
-- All paths provided to HTTP services start with leading / to improve compatibility with stubbing libraries
|
|
9
73
|
-- If Facebook returns nil for search or get_connections requests, Koala now returns nil rather than throwing an exception
|
|
10
74
|
|
|
@@ -13,7 +77,7 @@ v0.8.0
|
|
|
13
77
|
-- Removed string overloading for the methods, per 0.7.3, which caused Marshaling issues
|
|
14
78
|
-- Removed ability to provide a string as the second argument to url_for_access_token, per 0.5.0
|
|
15
79
|
|
|
16
|
-
v0.7.4
|
|
80
|
+
v0.7.4
|
|
17
81
|
-- Fixed bug with get_user_from_cookies
|
|
18
82
|
|
|
19
83
|
v0.7.3
|
|
@@ -24,18 +88,18 @@ v0.7.3
|
|
|
24
88
|
-- Using those methods triggers a deprecation warning
|
|
25
89
|
-- This will be removed by 1.0
|
|
26
90
|
-- There are new info methods (get_access_token_info, get_app_access_token_info, get_token_info_from_session_keys, and get_user_info_from_cookies) that natively return hashes, for when you want the expiration date
|
|
27
|
-
-- Responses with HTTP status 500+ now properly throw errors under Net::HTTP
|
|
91
|
+
-- Responses with HTTP status 500+ now properly throw errors under Net::HTTP
|
|
28
92
|
-- Updated changelog
|
|
29
93
|
-- Added license
|
|
30
94
|
|
|
31
95
|
v0.7.2
|
|
32
96
|
-- Added support for exchanging session keys for OAuth access tokens (get_token_from_session_key for single keys, get_tokens_from_session_keys for multiple)
|
|
33
97
|
-- Moved Koala files into a koala/ subdirectory to minimize risk of name collisions
|
|
34
|
-
-- Added OAuth Playground git submodule as an example
|
|
98
|
+
-- Added OAuth Playground git submodule as an example
|
|
35
99
|
-- Updated tests, readme, and changelog
|
|
36
100
|
|
|
37
101
|
v0.7.1
|
|
38
|
-
-- Updated RealtimeUpdates#list_subscriptions and GraphAPI#get_connections to now return an
|
|
102
|
+
-- Updated RealtimeUpdates#list_subscriptions and GraphAPI#get_connections to now return an
|
|
39
103
|
array of results directly (rather than a hash with one key)
|
|
40
104
|
-- Fixed a bug with Net::HTTP-based HTTP service in which the headers hash was improperly formatted
|
|
41
105
|
-- Updated readme
|
|
@@ -82,7 +146,7 @@ v0.3.1
|
|
|
82
146
|
v0.3
|
|
83
147
|
-- Renamed Graph API class from Facebook::GraphAPI to FacebookGraph::API
|
|
84
148
|
-- Created FacebookGraph::OAuth class for tokens and OAuth URLs
|
|
85
|
-
-- Updated method for including HTTP service (think we've got it this time)
|
|
149
|
+
-- Updated method for including HTTP service (think we've got it this time)
|
|
86
150
|
-- Updated tests
|
|
87
151
|
-- Added CHANGELOG and gemspec
|
|
88
152
|
|
data/Gemfile
ADDED
data/LICENSE
CHANGED
data/Manifest
CHANGED
|
@@ -2,20 +2,6 @@ CHANGELOG
|
|
|
2
2
|
LICENSE
|
|
3
3
|
Manifest
|
|
4
4
|
Rakefile
|
|
5
|
-
examples/oauth_playground/Capfile
|
|
6
|
-
examples/oauth_playground/LICENSE
|
|
7
|
-
examples/oauth_playground/Rakefile
|
|
8
|
-
examples/oauth_playground/config.ru
|
|
9
|
-
examples/oauth_playground/config/deploy.rb
|
|
10
|
-
examples/oauth_playground/config/facebook.yml
|
|
11
|
-
examples/oauth_playground/lib/load_facebook.rb
|
|
12
|
-
examples/oauth_playground/lib/oauth_playground.rb
|
|
13
|
-
examples/oauth_playground/readme.md
|
|
14
|
-
examples/oauth_playground/spec/oauth_playground_spec.rb
|
|
15
|
-
examples/oauth_playground/spec/spec_helper.rb
|
|
16
|
-
examples/oauth_playground/tmp/restart.txt
|
|
17
|
-
examples/oauth_playground/views/index.erb
|
|
18
|
-
examples/oauth_playground/views/layout.erb
|
|
19
5
|
init.rb
|
|
20
6
|
koala.gemspec
|
|
21
7
|
lib/koala.rb
|
|
@@ -23,20 +9,29 @@ lib/koala/graph_api.rb
|
|
|
23
9
|
lib/koala/http_services.rb
|
|
24
10
|
lib/koala/realtime_updates.rb
|
|
25
11
|
lib/koala/rest_api.rb
|
|
12
|
+
lib/koala/test_users.rb
|
|
13
|
+
lib/koala/uploadable_io.rb
|
|
26
14
|
readme.md
|
|
27
15
|
spec/facebook_data.yml
|
|
28
16
|
spec/koala/api_base_tests.rb
|
|
17
|
+
spec/koala/assets/beach.jpg
|
|
29
18
|
spec/koala/graph_and_rest_api/graph_and_rest_api_no_token_tests.rb
|
|
30
19
|
spec/koala/graph_and_rest_api/graph_and_rest_api_with_token_tests.rb
|
|
31
20
|
spec/koala/graph_api/graph_api_no_access_token_tests.rb
|
|
21
|
+
spec/koala/graph_api/graph_api_tests.rb
|
|
32
22
|
spec/koala/graph_api/graph_api_with_access_token_tests.rb
|
|
33
23
|
spec/koala/graph_api/graph_collection_tests.rb
|
|
24
|
+
spec/koala/http_services/http_service_tests.rb
|
|
25
|
+
spec/koala/http_services/net_http_service_tests.rb
|
|
26
|
+
spec/koala/http_services/typhoeus_service_tests.rb
|
|
34
27
|
spec/koala/live_testing_data_helper.rb
|
|
35
|
-
spec/koala/net_http_service_tests.rb
|
|
36
28
|
spec/koala/oauth/oauth_tests.rb
|
|
37
29
|
spec/koala/realtime_updates/realtime_updates_tests.rb
|
|
38
30
|
spec/koala/rest_api/rest_api_no_access_token_tests.rb
|
|
31
|
+
spec/koala/rest_api/rest_api_tests.rb
|
|
39
32
|
spec/koala/rest_api/rest_api_with_access_token_tests.rb
|
|
33
|
+
spec/koala/test_users/test_users_tests.rb
|
|
34
|
+
spec/koala/uploadable_io/uploadable_io_tests.rb
|
|
40
35
|
spec/koala_spec.rb
|
|
41
36
|
spec/koala_spec_helper.rb
|
|
42
37
|
spec/koala_spec_without_mocks.rb
|
data/Rakefile
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
# Rakefile
|
|
2
|
-
require 'rubygems'
|
|
3
1
|
require 'rake'
|
|
4
|
-
require 'echoe'
|
|
5
2
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
3
|
+
begin
|
|
4
|
+
require 'bundler/setup'
|
|
5
|
+
Bundler::GemHelper.install_tasks
|
|
6
|
+
rescue LoadError
|
|
7
|
+
puts 'although not required, bundler is recommened for running the tests'
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
task :default => :spec
|
|
12
|
+
|
|
13
|
+
require 'rspec/core/rake_task'
|
|
14
|
+
RSpec::Core::RakeTask.new do |t|
|
|
15
|
+
t.rspec_opts = ["--color", '--format doc']
|
|
16
16
|
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Autotest.add_discovery { "rspec2" }
|
data/koala.gemspec
CHANGED
|
@@ -1,30 +1,50 @@
|
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
|
2
2
|
|
|
3
3
|
Gem::Specification.new do |s|
|
|
4
|
-
s.name
|
|
5
|
-
s.version = "
|
|
4
|
+
s.name = %q{koala}
|
|
5
|
+
s.version = "1.1.0"
|
|
6
|
+
s.date = %q{2011-07-18}
|
|
7
|
+
|
|
8
|
+
s.summary = %q{A lightweight, flexible library for Facebook with support for the Graph API, the REST API, realtime updates, and OAuth authentication.}
|
|
9
|
+
s.description = %q{Koala is a lightweight, flexible Ruby SDK for Facebook. It allows read/write access to the social graph via the Graph and REST APIs, as well as support for realtime updates and OAuth and Facebook Connect authentication. Koala is fully tested and supports Net::HTTP and Typhoeus connections out of the box and can accept custom modules for other services.}
|
|
10
|
+
s.homepage = %q{http://github.com/arsduo/koala}
|
|
6
11
|
|
|
7
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
|
8
12
|
s.authors = ["Alex Koppel, Chris Baclig, Rafi Jacoby, Context Optional"]
|
|
9
|
-
s.
|
|
10
|
-
|
|
11
|
-
s.
|
|
12
|
-
s.
|
|
13
|
-
|
|
14
|
-
s.
|
|
15
|
-
s.rdoc_options
|
|
16
|
-
|
|
17
|
-
s.
|
|
18
|
-
|
|
19
|
-
s.
|
|
13
|
+
s.email = %q{alex@alexkoppel.com}
|
|
14
|
+
|
|
15
|
+
s.files = `git ls-files`.split("\n")
|
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
17
|
+
|
|
18
|
+
s.extra_rdoc_files = ["readme.md", "CHANGELOG"]
|
|
19
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Koala"]
|
|
20
|
+
|
|
21
|
+
s.require_paths = ["lib"]
|
|
22
|
+
|
|
23
|
+
s.rubygems_version = %q{1.4.2}
|
|
24
|
+
|
|
25
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
|
20
26
|
|
|
21
27
|
if s.respond_to? :specification_version then
|
|
22
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
23
28
|
s.specification_version = 3
|
|
24
29
|
|
|
25
|
-
if Gem::Version.new(Gem::
|
|
30
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
|
31
|
+
s.add_runtime_dependency(%q<multi_json>, ["~> 1.0"])
|
|
32
|
+
s.add_runtime_dependency(%q<multipart-post>, ["~> 1.0"])
|
|
33
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.5"])
|
|
34
|
+
s.add_development_dependency(%q<rake>, ["~> 0.8.7"])
|
|
35
|
+
s.add_development_dependency(%q<typhoeus>, ["~> 0.2.4"])
|
|
26
36
|
else
|
|
37
|
+
s.add_dependency(%q<multi_json>, ["~> 1.0"])
|
|
38
|
+
s.add_dependency(%q<multipart-post>, ["~> 1.0"])
|
|
39
|
+
s.add_dependency(%q<rspec>, ["~> 2.5"])
|
|
40
|
+
s.add_dependency(%q<rake>, ["~> 0.8.7"])
|
|
41
|
+
s.add_dependency(%q<typhoeus>, ["~> 0.2.4"])
|
|
27
42
|
end
|
|
28
43
|
else
|
|
44
|
+
s.add_dependency(%q<multi_json>, ["~> 1.0"])
|
|
45
|
+
s.add_dependency(%q<multipart-post>, ["~> 1.0"])
|
|
46
|
+
s.add_dependency(%q<rspec>, ["~> 2.5"])
|
|
47
|
+
s.add_dependency(%q<rake>, ["~> 0.8.7"])
|
|
48
|
+
s.add_dependency(%q<typhoeus>, ["~> 0.2.4"])
|
|
29
49
|
end
|
|
30
50
|
end
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
module Koala
|
|
2
|
+
module Facebook
|
|
3
|
+
class BatchOperation
|
|
4
|
+
attr_reader :access_token, :http_options, :post_processing, :files, :batch_api, :identifier
|
|
5
|
+
|
|
6
|
+
@identifier = 0
|
|
7
|
+
|
|
8
|
+
def self.next_identifier
|
|
9
|
+
@identifier += 1
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def initialize(options = {})
|
|
13
|
+
@identifier = self.class.next_identifier
|
|
14
|
+
@args = (options[:args] || {}).dup # because we modify it below
|
|
15
|
+
@access_token = options[:access_token]
|
|
16
|
+
@http_options = (options[:http_options] || {}).dup # dup because we modify it below
|
|
17
|
+
@batch_args = @http_options.delete(:batch_args) || {}
|
|
18
|
+
@url = options[:url]
|
|
19
|
+
@method = options[:method].to_sym
|
|
20
|
+
@post_processing = options[:post_processing]
|
|
21
|
+
|
|
22
|
+
process_binary_args
|
|
23
|
+
|
|
24
|
+
raise Koala::KoalaError, "Batch operations require an access token, none provided." unless @access_token
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def to_batch_params(main_access_token)
|
|
28
|
+
# set up the arguments
|
|
29
|
+
args_string = Koala.http_service.encode_params(@access_token == main_access_token ? @args : @args.merge(:access_token => @access_token))
|
|
30
|
+
|
|
31
|
+
response = {
|
|
32
|
+
:method => @method.to_s,
|
|
33
|
+
:relative_url => @url,
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
# handle batch-level arguments, such as name, depends_on, and attached_files
|
|
37
|
+
@batch_args[:attached_files] = @files.keys.join(",") if @files
|
|
38
|
+
response.merge!(@batch_args) if @batch_args
|
|
39
|
+
|
|
40
|
+
# for get and delete, we append args to the URL string
|
|
41
|
+
# otherwise, they go in the body
|
|
42
|
+
if args_string.length > 0
|
|
43
|
+
if args_in_url?
|
|
44
|
+
response[:relative_url] += (@url =~ /\?/ ? "&" : "?") + args_string if args_string.length > 0
|
|
45
|
+
else
|
|
46
|
+
response[:body] = args_string if args_string.length > 0
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
response
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
protected
|
|
54
|
+
|
|
55
|
+
def process_binary_args
|
|
56
|
+
# collect binary files
|
|
57
|
+
@args.each_pair do |key, value|
|
|
58
|
+
if UploadableIO.binary_content?(value)
|
|
59
|
+
@files ||= {}
|
|
60
|
+
# we use a class-level counter to ensure unique file identifiers across multiple batch operations
|
|
61
|
+
# (this is thread safe, since we just care about uniqueness)
|
|
62
|
+
# so remove the file from the original hash and add it to the file store
|
|
63
|
+
id = "op#{identifier}_file#{@files.keys.length}"
|
|
64
|
+
@files[id] = @args.delete(key).is_a?(UploadableIO) ? value : UploadableIO.new(value)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def args_in_url?
|
|
70
|
+
@method == :get || @method == :delete
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|