koala 1.3.0rc1 → 1.3.0rc2
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/.gitignore +3 -1
- data/.travis.yml +4 -0
- data/.yardopts +3 -0
- data/CHANGELOG +7 -0
- data/Gemfile +14 -0
- data/Guardfile +6 -0
- data/lib/koala.rb +16 -97
- data/lib/koala/api.rb +93 -0
- data/lib/koala/api/batch_operation.rb +83 -0
- data/lib/koala/api/graph_api.rb +476 -0
- data/lib/koala/{graph_batch_api.rb → api/graph_batch_api.rb} +20 -16
- data/lib/koala/api/graph_collection.rb +107 -0
- data/lib/koala/api/legacy.rb +26 -0
- data/lib/koala/{rest_api.rb → api/rest_api.rb} +33 -3
- data/lib/koala/http_service.rb +69 -19
- data/lib/koala/http_service/multipart_request.rb +41 -0
- data/lib/koala/http_service/response.rb +18 -0
- data/lib/koala/http_service/uploadable_io.rb +187 -0
- data/lib/koala/oauth.rb +117 -14
- data/lib/koala/realtime_updates.rb +89 -51
- data/lib/koala/test_users.rb +109 -33
- data/lib/koala/utils.rb +4 -0
- data/lib/koala/version.rb +1 -1
- data/spec/cases/api_spec.rb +19 -12
- data/spec/cases/graph_api_batch_spec.rb +41 -41
- data/spec/cases/http_service_spec.rb +1 -22
- data/spec/cases/legacy_spec.rb +107 -0
- data/spec/cases/multipart_request_spec.rb +5 -5
- data/spec/cases/oauth_spec.rb +9 -9
- data/spec/cases/realtime_updates_spec.rb +154 -47
- data/spec/cases/test_users_spec.rb +268 -219
- data/spec/fixtures/mock_facebook_responses.yml +10 -6
- data/spec/support/graph_api_shared_examples.rb +17 -12
- data/spec/support/koala_test.rb +1 -1
- data/spec/support/mock_http_service.rb +2 -2
- data/spec/support/rest_api_shared_examples.rb +1 -1
- metadata +82 -104
- data/lib/koala/batch_operation.rb +0 -74
- data/lib/koala/graph_api.rb +0 -289
- data/lib/koala/graph_collection.rb +0 -63
- data/lib/koala/multipart_request.rb +0 -35
- data/lib/koala/uploadable_io.rb +0 -181
- data/spec/cases/graph_and_rest_api_spec.rb +0 -22
- data/spec/cases/graph_api_spec.rb +0 -22
- data/spec/cases/rest_api_spec.rb +0 -22
@@ -262,10 +262,10 @@ graph_api:
|
|
262
262
|
no_token: '{"data": [{"id": "507731521_100412693339488"}], "paging": {"previous": "https:\/\/graph.facebook.com\/7204941866\/photos?limit=25&until=2008-09-15T18%3A30%3A25%2B0000", "next": "https:\/\/graph.facebook.com\/7204941866\/photos?limit=25&until=2008-09-15T18%3A30%3A25%2B0000"}}'
|
263
263
|
|
264
264
|
/fql:
|
265
|
-
q=select first_name from user where uid = 2901279:
|
265
|
+
q=select uid, first_name from user where uid = 2901279:
|
266
266
|
get:
|
267
|
-
no_token: '[{"first_name":"Luke"}]'
|
268
|
-
with_token: '[{"first_name":"Luke"}]'
|
267
|
+
no_token: '[{"uid":2901279,"first_name":"Luke"}]'
|
268
|
+
with_token: '[{"uid":2901279,"first_name":"Luke"}]'
|
269
269
|
q=select read_stream from permissions where uid = 2901279:
|
270
270
|
get:
|
271
271
|
<<: *token_required
|
@@ -274,10 +274,10 @@ graph_api:
|
|
274
274
|
get:
|
275
275
|
<<: *token_required
|
276
276
|
with_token: '[{"name":"query1", "fql_result_set":[]},{"name":"query2", "fql_result_set":[]},{"name":"query3", "fql_result_set":[]}]'
|
277
|
-
'q=<%= MultiJson.encode({"query1" => "select first_name from user where uid = 2901279", "query2" => "select first_name from user where uid = 2905623"}) %>':
|
277
|
+
'q=<%= MultiJson.encode({"query1" => "select uid, first_name from user where uid = 2901279", "query2" => "select uid, first_name from user where uid = 2905623"}) %>':
|
278
278
|
get:
|
279
|
-
with_token: '[{"name":"query1", "fql_result_set":[{"first_name":"Luke"}]},{"name":"query2", "fql_result_set":[{"first_name":"Alex"}]}]'
|
280
|
-
no_token: '[{"name":"query1", "fql_result_set":[{"first_name":"Luke"}]},{"name":"query2", "fql_result_set":[{"first_name":"Alex"}]}]'
|
279
|
+
with_token: '[{"name":"query1", "fql_result_set":[{"uid":2901279,"first_name":"Luke"}]},{"name":"query2", "fql_result_set":[{"uid":"2905623","first_name":"Alex"}]}]'
|
280
|
+
no_token: '[{"name":"query1", "fql_result_set":[{"uid":2901279,"first_name":"Luke"}]},{"name":"query2", "fql_result_set":[{"uid":"2905623","first_name":"Alex"}]}]'
|
281
281
|
|
282
282
|
|
283
283
|
'/115349521819193_113815981982767':
|
@@ -333,6 +333,10 @@ graph_api:
|
|
333
333
|
post:
|
334
334
|
with_token:
|
335
335
|
code: 200
|
336
|
+
callback_url=<%= SUBSCRIPTION_DATA["subscription_path"] %>&fields=name&object=user:
|
337
|
+
post:
|
338
|
+
with_token:
|
339
|
+
code: 200
|
336
340
|
callback_url=<%= SUBSCRIPTION_DATA["subscription_path"] %>foo&fields=name&object=user&verify_token=<%= SUBSCRIPTION_DATA["verify_token"] %>:
|
337
341
|
post:
|
338
342
|
with_token: '{"error":{"type":"Exception","message":"(#2200) subscription validation failed"}}'
|
@@ -8,7 +8,7 @@ shared_examples_for "Koala GraphAPI" do
|
|
8
8
|
anything,
|
9
9
|
anything,
|
10
10
|
hash_not_including(:rest_api => true)
|
11
|
-
).and_return(Koala::Response.new(200, "", {}))
|
11
|
+
).and_return(Koala::HTTPService::Response.new(200, "", {}))
|
12
12
|
|
13
13
|
@api.api("anything")
|
14
14
|
end
|
@@ -22,7 +22,7 @@ shared_examples_for "Koala GraphAPI" do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
it "throws an APIError if the result hash has an error key" do
|
25
|
-
Koala.stub(:make_request).and_return(Koala::Response.new(500, {"error" => "An error occurred!"}, {}))
|
25
|
+
Koala.stub(:make_request).and_return(Koala::HTTPService::Response.new(500, {"error" => "An error occurred!"}, {}))
|
26
26
|
lambda { @api.graph_call(KoalaTest.user1, {}) }.should raise_exception(Koala::Facebook::APIError)
|
27
27
|
end
|
28
28
|
|
@@ -331,7 +331,7 @@ shared_examples_for "Koala GraphAPI with an access token" do
|
|
331
331
|
source = stub("UploadIO")
|
332
332
|
Koala::UploadableIO.stub(:new).and_return(source)
|
333
333
|
source.stub(:requires_base_http_service).and_return(false)
|
334
|
-
Koala.should_receive(:make_request).with(anything, anything, anything, hash_including(:video => true)).and_return(Koala::Response.new(200, "[]", {}))
|
334
|
+
Koala.should_receive(:make_request).with(anything, anything, anything, hash_including(:video => true)).and_return(Koala::HTTPService::Response.new(200, "[]", {}))
|
335
335
|
@api.put_video("foo")
|
336
336
|
end
|
337
337
|
|
@@ -441,19 +441,24 @@ shared_examples_for "Koala GraphAPI with an access token" do
|
|
441
441
|
end
|
442
442
|
end
|
443
443
|
|
444
|
+
it "changes tests to first_name when FB repairs its bug"
|
445
|
+
|
444
446
|
it "can access public information via FQL" do
|
445
|
-
result = @api.fql_query("select first_name from user where uid = #{KoalaTest.user2_id}")
|
447
|
+
result = @api.fql_query("select uid, first_name from user where uid = #{KoalaTest.user2_id}")
|
446
448
|
result.size.should == 1
|
447
|
-
result.first['first_name'].should == KoalaTest.user2_name
|
449
|
+
# result.first['first_name'].should == KoalaTest.user2_name
|
450
|
+
result.first['uid'].should == KoalaTest.user2_id.to_i
|
448
451
|
end
|
449
|
-
|
452
|
+
|
450
453
|
it "can access public information via FQL.multiquery" do
|
451
454
|
result = @api.fql_multiquery(
|
452
|
-
:query1 => "select first_name from user where uid = #{KoalaTest.user2_id}",
|
453
|
-
:query2 => "select first_name from user where uid = #{KoalaTest.user1_id}"
|
455
|
+
:query1 => "select uid, first_name from user where uid = #{KoalaTest.user2_id}",
|
456
|
+
:query2 => "select uid, first_name from user where uid = #{KoalaTest.user1_id}"
|
454
457
|
)
|
455
458
|
result.size.should == 2
|
456
|
-
|
459
|
+
# this should check for first_name, but there's an FB bug currently
|
460
|
+
result["query1"].first['uid'].should == KoalaTest.user2_id.to_i
|
461
|
+
# result["query1"].first['first_name'].should == KoalaTest.user2_name
|
457
462
|
result["query2"].first['first_name'].should == KoalaTest.user1_name
|
458
463
|
end
|
459
464
|
|
@@ -622,15 +627,15 @@ shared_examples_for "Koala GraphAPI without an access token" do
|
|
622
627
|
# FQL_QUERY
|
623
628
|
describe "when making a FQL request" do
|
624
629
|
it "can access public information via FQL" do
|
625
|
-
result = @api.fql_query("select first_name from user where uid = #{KoalaTest.user2_id}")
|
630
|
+
result = @api.fql_query("select uid, first_name from user where uid = #{KoalaTest.user2_id}")
|
626
631
|
result.size.should == 1
|
627
632
|
result.first['first_name'].should == KoalaTest.user2_name
|
628
633
|
end
|
629
634
|
|
630
635
|
it "can access public information via FQL.multiquery" do
|
631
636
|
result = @api.fql_multiquery(
|
632
|
-
:query1 => "select first_name from user where uid = #{KoalaTest.user2_id}",
|
633
|
-
:query2 => "select first_name from user where uid = #{KoalaTest.user1_id}"
|
637
|
+
:query1 => "select uid, first_name from user where uid = #{KoalaTest.user2_id}",
|
638
|
+
:query2 => "select uid, first_name from user where uid = #{KoalaTest.user1_id}"
|
634
639
|
)
|
635
640
|
result.size.should == 2
|
636
641
|
result["query1"].first['first_name'].should == KoalaTest.user2_name
|
data/spec/support/koala_test.rb
CHANGED
@@ -29,7 +29,7 @@ module KoalaTest
|
|
29
29
|
KoalaTest.setup_test_data(live_data)
|
30
30
|
|
31
31
|
# allow live tests with different adapters
|
32
|
-
adapter = ENV['ADAPTER'] || "typhoeus"# use Typhoeus by default if available
|
32
|
+
adapter = ENV['ADAPTER'] || "typhoeus" # use Typhoeus by default if available
|
33
33
|
begin
|
34
34
|
require adapter
|
35
35
|
Faraday.default_adapter = adapter.to_sym
|
@@ -56,9 +56,9 @@ module Koala
|
|
56
56
|
|
57
57
|
# create response class object
|
58
58
|
response_object = if response.is_a? String
|
59
|
-
Koala::Response.new(200, response, {})
|
59
|
+
Koala::HTTPService::Response.new(200, response, {})
|
60
60
|
else
|
61
|
-
Koala::Response.new(response["code"] || 200, response["body"] || "", response["headers"] || {})
|
61
|
+
Koala::HTTPService::Response.new(response["code"] || 200, response["body"] || "", response["headers"] || {})
|
62
62
|
end
|
63
63
|
|
64
64
|
rescue NoMethodError
|
@@ -112,7 +112,7 @@ shared_examples_for "Koala RestAPI" do
|
|
112
112
|
end
|
113
113
|
|
114
114
|
it "throws an APIError if the result hash has an error key" do
|
115
|
-
Koala.stub(:make_request).and_return(Koala::Response.new(500, {"error_code" => "An error occurred!"}, {}))
|
115
|
+
Koala.stub(:make_request).and_return(Koala::HTTPService::Response.new(500, {"error_code" => "An error occurred!"}, {}))
|
116
116
|
lambda { @api.rest_call(KoalaTest.user1, {}) }.should raise_exception(Koala::Facebook::APIError)
|
117
117
|
end
|
118
118
|
end
|
metadata
CHANGED
@@ -1,130 +1,113 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: koala
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 1
|
7
|
-
- 3
|
8
|
-
- 0rc1
|
9
|
-
segments_generated: true
|
10
|
-
version: 1.3.0rc1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.3.0rc2
|
5
|
+
prerelease: 5
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Alex Koppel, Chris Baclig, Rafi Jacoby, Context Optional
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
22
|
-
version_requirements: &id001 !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ~>
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
segments:
|
27
|
-
- 1
|
28
|
-
- 0
|
29
|
-
segments_generated: true
|
30
|
-
version: "1.0"
|
31
|
-
requirement: *id001
|
12
|
+
date: 2011-10-04 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
32
15
|
name: multi_json
|
33
|
-
|
16
|
+
requirement: &70189471321260 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.0'
|
34
22
|
type: :runtime
|
35
|
-
|
36
|
-
version_requirements:
|
37
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70189471321260
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: faraday
|
27
|
+
requirement: &70189471320500 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
38
30
|
- - ~>
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
segments:
|
41
|
-
- 0
|
42
|
-
- 7
|
43
|
-
- 0
|
44
|
-
segments_generated: true
|
31
|
+
- !ruby/object:Gem::Version
|
45
32
|
version: 0.7.0
|
46
|
-
requirement: *id002
|
47
|
-
name: faraday
|
48
|
-
prerelease: false
|
49
33
|
type: :runtime
|
50
|
-
|
51
|
-
version_requirements:
|
52
|
-
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70189471320500
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec
|
38
|
+
requirement: &70189471319840 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
53
41
|
- - ~>
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
segments:
|
56
|
-
- 2
|
57
|
-
- 8
|
58
|
-
- 0rc1
|
59
|
-
segments_generated: true
|
42
|
+
- !ruby/object:Gem::Version
|
60
43
|
version: 2.8.0rc1
|
61
|
-
requirement: *id003
|
62
|
-
name: rspec
|
63
|
-
prerelease: false
|
64
44
|
type: :development
|
65
|
-
|
66
|
-
version_requirements:
|
67
|
-
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70189471319840
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: &70189471318960 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
68
52
|
- - ~>
|
69
|
-
- !ruby/object:Gem::Version
|
70
|
-
segments:
|
71
|
-
- 0
|
72
|
-
- 8
|
73
|
-
- 7
|
74
|
-
segments_generated: true
|
53
|
+
- !ruby/object:Gem::Version
|
75
54
|
version: 0.8.7
|
76
|
-
requirement: *id004
|
77
|
-
name: rake
|
78
|
-
prerelease: false
|
79
55
|
type: :development
|
80
|
-
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70189471318960
|
58
|
+
description: Koala is a lightweight, flexible Ruby SDK for Facebook. It allows read/write
|
59
|
+
access to the social graph via the Graph and REST APIs, as well as support for realtime
|
60
|
+
updates and OAuth and Facebook Connect authentication. Koala is fully tested and
|
61
|
+
supports Net::HTTP and Typhoeus connections out of the box and can accept custom
|
62
|
+
modules for other services.
|
81
63
|
email: alex@alexkoppel.com
|
82
64
|
executables: []
|
83
|
-
|
84
65
|
extensions: []
|
85
|
-
|
86
|
-
extra_rdoc_files:
|
66
|
+
extra_rdoc_files:
|
87
67
|
- readme.md
|
88
68
|
- CHANGELOG
|
89
|
-
files:
|
69
|
+
files:
|
90
70
|
- .autotest
|
91
71
|
- .gitignore
|
92
72
|
- .rspec
|
93
73
|
- .travis.yml
|
74
|
+
- .yardopts
|
94
75
|
- CHANGELOG
|
95
76
|
- Gemfile
|
77
|
+
- Guardfile
|
96
78
|
- LICENSE
|
97
79
|
- Manifest
|
98
80
|
- Rakefile
|
99
81
|
- autotest/discover.rb
|
100
82
|
- koala.gemspec
|
101
83
|
- lib/koala.rb
|
102
|
-
- lib/koala/
|
103
|
-
- lib/koala/
|
104
|
-
- lib/koala/
|
105
|
-
- lib/koala/
|
84
|
+
- lib/koala/api.rb
|
85
|
+
- lib/koala/api/batch_operation.rb
|
86
|
+
- lib/koala/api/graph_api.rb
|
87
|
+
- lib/koala/api/graph_batch_api.rb
|
88
|
+
- lib/koala/api/graph_collection.rb
|
89
|
+
- lib/koala/api/legacy.rb
|
90
|
+
- lib/koala/api/rest_api.rb
|
106
91
|
- lib/koala/http_service.rb
|
107
|
-
- lib/koala/multipart_request.rb
|
92
|
+
- lib/koala/http_service/multipart_request.rb
|
93
|
+
- lib/koala/http_service/response.rb
|
94
|
+
- lib/koala/http_service/uploadable_io.rb
|
108
95
|
- lib/koala/oauth.rb
|
109
96
|
- lib/koala/realtime_updates.rb
|
110
|
-
- lib/koala/rest_api.rb
|
111
97
|
- lib/koala/test_users.rb
|
112
|
-
- lib/koala/uploadable_io.rb
|
113
98
|
- lib/koala/utils.rb
|
114
99
|
- lib/koala/version.rb
|
115
100
|
- readme.md
|
116
101
|
- spec/cases/api_spec.rb
|
117
102
|
- spec/cases/error_spec.rb
|
118
|
-
- spec/cases/graph_and_rest_api_spec.rb
|
119
103
|
- spec/cases/graph_api_batch_spec.rb
|
120
|
-
- spec/cases/graph_api_spec.rb
|
121
104
|
- spec/cases/graph_collection_spec.rb
|
122
105
|
- spec/cases/http_service_spec.rb
|
123
106
|
- spec/cases/koala_spec.rb
|
107
|
+
- spec/cases/legacy_spec.rb
|
124
108
|
- spec/cases/multipart_request_spec.rb
|
125
109
|
- spec/cases/oauth_spec.rb
|
126
110
|
- spec/cases/realtime_updates_spec.rb
|
127
|
-
- spec/cases/rest_api_spec.rb
|
128
111
|
- spec/cases/test_users_spec.rb
|
129
112
|
- spec/cases/uploadable_io_spec.rb
|
130
113
|
- spec/cases/utils_spec.rb
|
@@ -141,55 +124,49 @@ files:
|
|
141
124
|
- spec/support/ordered_hash.rb
|
142
125
|
- spec/support/rest_api_shared_examples.rb
|
143
126
|
- spec/support/uploadable_io_shared_examples.rb
|
144
|
-
has_rdoc: true
|
145
127
|
homepage: http://github.com/arsduo/koala
|
146
128
|
licenses: []
|
147
|
-
|
148
129
|
post_install_message:
|
149
|
-
rdoc_options:
|
130
|
+
rdoc_options:
|
150
131
|
- --line-numbers
|
151
132
|
- --inline-source
|
152
133
|
- --title
|
153
134
|
- Koala
|
154
|
-
require_paths:
|
135
|
+
require_paths:
|
155
136
|
- lib
|
156
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
+
none: false
|
139
|
+
requirements:
|
140
|
+
- - ! '>='
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
segments:
|
161
144
|
- 0
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
requirements:
|
166
|
-
- -
|
167
|
-
- !ruby/object:Gem::Version
|
168
|
-
|
169
|
-
- 1
|
170
|
-
- 2
|
171
|
-
segments_generated: true
|
172
|
-
version: "1.2"
|
145
|
+
hash: 1629034737345566413
|
146
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
+
none: false
|
148
|
+
requirements:
|
149
|
+
- - ! '>='
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '1.2'
|
173
152
|
requirements: []
|
174
|
-
|
175
153
|
rubyforge_project:
|
176
|
-
rubygems_version: 1.
|
154
|
+
rubygems_version: 1.8.10
|
177
155
|
signing_key:
|
178
156
|
specification_version: 3
|
179
|
-
summary: A lightweight, flexible library for Facebook with support for the Graph API,
|
180
|
-
|
157
|
+
summary: A lightweight, flexible library for Facebook with support for the Graph API,
|
158
|
+
the REST API, realtime updates, and OAuth authentication.
|
159
|
+
test_files:
|
181
160
|
- spec/cases/api_spec.rb
|
182
161
|
- spec/cases/error_spec.rb
|
183
|
-
- spec/cases/graph_and_rest_api_spec.rb
|
184
162
|
- spec/cases/graph_api_batch_spec.rb
|
185
|
-
- spec/cases/graph_api_spec.rb
|
186
163
|
- spec/cases/graph_collection_spec.rb
|
187
164
|
- spec/cases/http_service_spec.rb
|
188
165
|
- spec/cases/koala_spec.rb
|
166
|
+
- spec/cases/legacy_spec.rb
|
189
167
|
- spec/cases/multipart_request_spec.rb
|
190
168
|
- spec/cases/oauth_spec.rb
|
191
169
|
- spec/cases/realtime_updates_spec.rb
|
192
|
-
- spec/cases/rest_api_spec.rb
|
193
170
|
- spec/cases/test_users_spec.rb
|
194
171
|
- spec/cases/uploadable_io_spec.rb
|
195
172
|
- spec/cases/utils_spec.rb
|
@@ -206,3 +183,4 @@ test_files:
|
|
206
183
|
- spec/support/ordered_hash.rb
|
207
184
|
- spec/support/rest_api_shared_examples.rb
|
208
185
|
- spec/support/uploadable_io_shared_examples.rb
|
186
|
+
has_rdoc:
|
@@ -1,74 +0,0 @@
|
|
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
|