koala 1.8.0 → 1.9.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/.travis.yml +2 -2
- data/Gemfile +5 -9
- data/changelog.md +22 -3
- data/koala.gemspec +0 -2
- data/lib/koala.rb +5 -0
- data/lib/koala/api.rb +12 -2
- data/lib/koala/api/graph_api.rb +4 -1
- data/lib/koala/version.rb +1 -1
- data/readme.md +17 -4
- data/spec/cases/api_spec.rb +81 -24
- data/spec/cases/error_spec.rb +16 -16
- data/spec/cases/graph_api_batch_spec.rb +103 -103
- data/spec/cases/graph_api_spec.rb +33 -10
- data/spec/cases/graph_collection_spec.rb +35 -35
- data/spec/cases/http_service_spec.rb +92 -92
- data/spec/cases/koala_spec.rb +9 -9
- data/spec/cases/legacy_spec.rb +22 -22
- data/spec/cases/multipart_request_spec.rb +20 -21
- data/spec/cases/oauth_spec.rb +125 -125
- data/spec/cases/realtime_updates_spec.rb +44 -44
- data/spec/cases/test_users_spec.rb +58 -58
- data/spec/cases/uploadable_io_spec.rb +36 -36
- data/spec/cases/utils_spec.rb +11 -11
- data/spec/spec_helper.rb +0 -19
- data/spec/support/custom_matchers.rb +3 -3
- data/spec/support/graph_api_shared_examples.rb +117 -114
- data/spec/support/koala_test.rb +3 -8
- data/spec/support/rest_api_shared_examples.rb +18 -19
- data/spec/support/uploadable_io_shared_examples.rb +10 -10
- metadata +20 -50
- data/spec/support/ordered_hash.rb +0 -201
@@ -24,26 +24,26 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
24
24
|
|
25
25
|
describe ".new" do
|
26
26
|
it "makes http_options accessible" do
|
27
|
-
Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).http_options.
|
27
|
+
expect(Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).http_options).to eq(@args[:http_options])
|
28
28
|
end
|
29
29
|
|
30
30
|
it "makes post_processing accessible" do
|
31
|
-
Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).post_processing.
|
31
|
+
expect(Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).post_processing).to eq(@args[:post_processing])
|
32
32
|
end
|
33
33
|
|
34
34
|
it "makes access_token accessible" do
|
35
|
-
Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).access_token.
|
35
|
+
expect(Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).access_token).to eq(@args[:access_token])
|
36
36
|
end
|
37
37
|
|
38
38
|
it "doesn't change the original http_options" do
|
39
39
|
@args[:http_options][:name] = "baz2"
|
40
40
|
expected = @args[:http_options].dup
|
41
41
|
Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).to_batch_params(nil)
|
42
|
-
@args[:http_options].
|
42
|
+
expect(@args[:http_options]).to eq(expected)
|
43
43
|
end
|
44
44
|
|
45
45
|
it "leaves the file array nil by default" do
|
46
|
-
Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).files.
|
46
|
+
expect(Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).files).to be_nil
|
47
47
|
end
|
48
48
|
|
49
49
|
it "raises a KoalaError if no access token supplied" do
|
@@ -56,13 +56,13 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
56
56
|
@uploadable_io = double("UploadableIO 1")
|
57
57
|
|
58
58
|
@batch_queue = []
|
59
|
-
Koala::Facebook::GraphAPI.
|
59
|
+
allow(Koala::Facebook::GraphAPI).to receive(:batch_calls).and_return(@batch_queue)
|
60
60
|
|
61
|
-
Koala::UploadableIO.
|
62
|
-
Koala::UploadableIO.
|
63
|
-
Koala::UploadableIO.
|
64
|
-
Koala::UploadableIO.
|
65
|
-
@uploadable_io.
|
61
|
+
allow(Koala::UploadableIO).to receive(:new).with(@binary).and_return(@uploadable_io)
|
62
|
+
allow(Koala::UploadableIO).to receive(:binary_content?).and_return(false)
|
63
|
+
allow(Koala::UploadableIO).to receive(:binary_content?).with(@binary).and_return(true)
|
64
|
+
allow(Koala::UploadableIO).to receive(:binary_content?).with(@uploadable_io).and_return(true)
|
65
|
+
allow(@uploadable_io).to receive(:is_a?).with(Koala::UploadableIO).and_return(true)
|
66
66
|
|
67
67
|
@args[:method] = "post" # files are always post
|
68
68
|
end
|
@@ -70,23 +70,23 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
70
70
|
it "adds binary files to the files attribute as UploadableIOs" do
|
71
71
|
@args[:args].merge!("source" => @binary)
|
72
72
|
batch_op = Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args)
|
73
|
-
batch_op.files.
|
74
|
-
batch_op.files.find {|k, v| v == @uploadable_io}.
|
73
|
+
expect(batch_op.files).not_to be_nil
|
74
|
+
expect(batch_op.files.find {|k, v| v == @uploadable_io}).not_to be_nil
|
75
75
|
end
|
76
76
|
|
77
77
|
it "works if supplied an UploadableIO as an argument" do
|
78
78
|
# as happens with put_picture at the moment
|
79
79
|
@args[:args].merge!("source" => @uploadable_io)
|
80
80
|
batch_op = Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args)
|
81
|
-
batch_op.files.
|
82
|
-
batch_op.files.find {|k, v| v == @uploadable_io}.
|
81
|
+
expect(batch_op.files).not_to be_nil
|
82
|
+
expect(batch_op.files.find {|k, v| v == @uploadable_io}).not_to be_nil
|
83
83
|
end
|
84
84
|
|
85
85
|
it "assigns each binary parameter unique name" do
|
86
86
|
@args[:args].merge!("source" => @binary, "source2" => @binary)
|
87
87
|
batch_op = Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args)
|
88
88
|
# if the name wasn't unique, there'd just be one item
|
89
|
-
batch_op.files.
|
89
|
+
expect(batch_op.files.size).to eq(2)
|
90
90
|
end
|
91
91
|
|
92
92
|
it "assigns each binary parameter unique name across batch requests" do
|
@@ -97,12 +97,12 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
97
97
|
batch_op2 = Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args)
|
98
98
|
@batch_queue << batch_op2
|
99
99
|
# if the name wasn't unique, we should have < 4 items since keys would be the same
|
100
|
-
batch_op.files.merge(batch_op2.files).
|
100
|
+
expect(batch_op.files.merge(batch_op2.files).size).to eq(4)
|
101
101
|
end
|
102
102
|
|
103
103
|
it "removes the value from the arguments" do
|
104
104
|
@args[:args].merge!("source" => @binary)
|
105
|
-
Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).to_batch_params(nil)[:body].
|
105
|
+
expect(Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).to_batch_params(nil)[:body]).not_to match(/source=/)
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
@@ -114,49 +114,49 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
114
114
|
it "adds the args to the URL string, with ? if no args previously present" do
|
115
115
|
test_args = "foo"
|
116
116
|
@args[:url] = url = "/"
|
117
|
-
Koala.http_service.
|
117
|
+
allow(Koala.http_service).to receive(:encode_params).and_return(test_args)
|
118
118
|
|
119
|
-
Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).to_batch_params(nil)[:relative_url].
|
119
|
+
expect(Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).to_batch_params(nil)[:relative_url]).to eq("#{url}?#{test_args}")
|
120
120
|
end
|
121
121
|
|
122
122
|
it "adds the args to the URL string, with & if args previously present" do
|
123
123
|
test_args = "foo"
|
124
124
|
@args[:url] = url = "/?a=2"
|
125
|
-
Koala.http_service.
|
125
|
+
allow(Koala.http_service).to receive(:encode_params).and_return(test_args)
|
126
126
|
|
127
|
-
Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).to_batch_params(nil)[:relative_url].
|
127
|
+
expect(Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).to_batch_params(nil)[:relative_url]).to eq("#{url}&#{test_args}")
|
128
128
|
end
|
129
129
|
|
130
130
|
it "adds nothing to the URL string if there are no args to be added" do
|
131
131
|
@args[:args] = {}
|
132
|
-
Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).to_batch_params(@args[:access_token])[:relative_url].
|
132
|
+
expect(Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).to_batch_params(@args[:access_token])[:relative_url]).to eq(@args[:url])
|
133
133
|
end
|
134
134
|
|
135
135
|
it "adds nothing to the body" do
|
136
|
-
Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).to_batch_params(nil)[:body].
|
136
|
+
expect(Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).to_batch_params(nil)[:body]).to be_nil
|
137
137
|
end
|
138
138
|
end
|
139
139
|
|
140
140
|
shared_examples_for "requests with a body param" do
|
141
141
|
it "sets the body to the encoded args string, if there are args" do
|
142
142
|
test_args = "foo"
|
143
|
-
Koala.http_service.
|
143
|
+
allow(Koala.http_service).to receive(:encode_params).and_return(test_args)
|
144
144
|
|
145
|
-
Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).to_batch_params(nil)[:body].
|
145
|
+
expect(Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).to_batch_params(nil)[:body]).to eq(test_args)
|
146
146
|
end
|
147
147
|
|
148
148
|
it "does not set the body if there are no args" do
|
149
149
|
test_args = ""
|
150
|
-
Koala.http_service.
|
151
|
-
Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).to_batch_params(nil)[:body].
|
150
|
+
allow(Koala.http_service).to receive(:encode_params).and_return(test_args)
|
151
|
+
expect(Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).to_batch_params(nil)[:body]).to be_nil
|
152
152
|
end
|
153
153
|
|
154
154
|
|
155
155
|
it "doesn't change the url" do
|
156
156
|
test_args = "foo"
|
157
|
-
Koala.http_service.
|
157
|
+
allow(Koala.http_service).to receive(:encode_params).and_return(test_args)
|
158
158
|
|
159
|
-
Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).to_batch_params(nil)[:relative_url].
|
159
|
+
expect(Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).to_batch_params(nil)[:relative_url]).to eq(@args[:url])
|
160
160
|
end
|
161
161
|
end
|
162
162
|
|
@@ -195,36 +195,36 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
195
195
|
|
196
196
|
it "includes the access token if the token is not the main one for the request" do
|
197
197
|
params = Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).to_batch_params(nil)
|
198
|
-
params[:relative_url].
|
198
|
+
expect(params[:relative_url]).to match(/access_token=#{@args[:access_token]}/)
|
199
199
|
end
|
200
200
|
|
201
201
|
it "includes the other arguments if the token is not the main one for the request" do
|
202
202
|
@args[:args] = {:a => 2}
|
203
203
|
params = Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).to_batch_params(nil)
|
204
|
-
params[:relative_url].
|
204
|
+
expect(params[:relative_url]).to match(/a=2/)
|
205
205
|
end
|
206
206
|
|
207
207
|
it "does not include the access token if the token is the main one for the request" do
|
208
208
|
params = Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).to_batch_params(@args[:access_token])
|
209
|
-
params[:relative_url].
|
209
|
+
expect(params[:relative_url]).not_to match(/access_token=#{@args[:access_token]}/)
|
210
210
|
end
|
211
211
|
|
212
212
|
it "includes the other arguments if the token is the main one for the request" do
|
213
213
|
@args[:args] = {:a => 2}
|
214
214
|
params = Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).to_batch_params(@args[:access_token])
|
215
|
-
params[:relative_url].
|
215
|
+
expect(params[:relative_url]).to match(/a=2/)
|
216
216
|
end
|
217
217
|
|
218
218
|
it "includes any arguments passed as http_options[:batch_args]" do
|
219
219
|
batch_args = {:name => "baz", :headers => {:some_param => true}}
|
220
220
|
@args[:http_options][:batch_args] = batch_args
|
221
221
|
params = Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).to_batch_params(nil)
|
222
|
-
params.
|
222
|
+
expect(params).to include(batch_args)
|
223
223
|
end
|
224
224
|
|
225
225
|
it "includes the method" do
|
226
226
|
params = Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).to_batch_params(@args[:access_token])
|
227
|
-
params[:method].
|
227
|
+
expect(params[:method]).to eq(@args[:method].to_s)
|
228
228
|
end
|
229
229
|
|
230
230
|
it "works with nil http_options" do
|
@@ -238,14 +238,14 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
238
238
|
describe "with binary files" do
|
239
239
|
before :each do
|
240
240
|
@binary = double("Binary file")
|
241
|
-
Koala::UploadableIO.
|
242
|
-
Koala::UploadableIO.
|
241
|
+
allow(Koala::UploadableIO).to receive(:binary_content?).and_return(false)
|
242
|
+
allow(Koala::UploadableIO).to receive(:binary_content?).with(@binary).and_return(true)
|
243
243
|
@uploadable_io = double("UploadableIO")
|
244
|
-
Koala::UploadableIO.
|
245
|
-
@uploadable_io.
|
244
|
+
allow(Koala::UploadableIO).to receive(:new).with(@binary).and_return(@uploadable_io)
|
245
|
+
allow(@uploadable_io).to receive(:is_a?).with(Koala::UploadableIO).and_return(true)
|
246
246
|
|
247
247
|
@batch_queue = []
|
248
|
-
Koala::Facebook::GraphAPI.
|
248
|
+
allow(Koala::Facebook::GraphAPI).to receive(:batch_calls).and_return(@batch_queue)
|
249
249
|
|
250
250
|
@args[:method] = "post" # files are always post
|
251
251
|
end
|
@@ -255,7 +255,7 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
255
255
|
batch_op = Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args)
|
256
256
|
file_ids = batch_op.files.find_all {|k, v| v == @uploadable_io}.map {|k, v| k}
|
257
257
|
params = batch_op.to_batch_params(nil)
|
258
|
-
params[:attached_files].
|
258
|
+
expect(params[:attached_files]).to eq(file_ids.join(","))
|
259
259
|
end
|
260
260
|
end
|
261
261
|
end
|
@@ -264,33 +264,33 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
264
264
|
|
265
265
|
describe "GraphAPI batch interface" do
|
266
266
|
it "returns nothing for a batch operation" do
|
267
|
-
Koala.
|
267
|
+
allow(Koala).to receive(:make_request).and_return(Koala::HTTPService::Response.new(200, "[]", {}))
|
268
268
|
@api.batch do |batch_api|
|
269
|
-
batch_api.get_object('me').
|
269
|
+
expect(batch_api.get_object('me')).to be_nil
|
270
270
|
end
|
271
271
|
end
|
272
272
|
|
273
273
|
describe "#batch" do
|
274
274
|
before :each do
|
275
275
|
@fake_response = Koala::HTTPService::Response.new(200, "[]", {})
|
276
|
-
Koala.
|
276
|
+
allow(Koala).to receive(:make_request).and_return(@fake_response)
|
277
277
|
end
|
278
278
|
|
279
279
|
describe "making the request" do
|
280
280
|
context "with no calls" do
|
281
281
|
it "does not make any requests if batch_calls is empty" do
|
282
|
-
Koala.
|
282
|
+
expect(Koala).not_to receive(:make_request)
|
283
283
|
@api.batch {|batch_api|}
|
284
284
|
end
|
285
285
|
|
286
286
|
it "returns []" do
|
287
|
-
@api.batch {|batch_api|}.
|
287
|
+
expect(@api.batch {|batch_api|}).to eq([])
|
288
288
|
end
|
289
289
|
end
|
290
290
|
|
291
291
|
it "includes the first operation's access token as the main one in the args" do
|
292
292
|
access_token = "foo"
|
293
|
-
Koala.
|
293
|
+
expect(Koala).to receive(:make_request).with(anything, hash_including("access_token" => access_token), anything, anything).and_return(@fake_response)
|
294
294
|
Koala::Facebook::API.new(access_token).batch do |batch_api|
|
295
295
|
batch_api.get_object('me')
|
296
296
|
batch_api.get_object('me', {}, {'access_token' => 'bar'})
|
@@ -300,12 +300,12 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
300
300
|
it "sets args['batch'] to a json'd map of all the batch params" do
|
301
301
|
access_token = "bar"
|
302
302
|
op = Koala::Facebook::GraphBatchAPI::BatchOperation.new(:access_token => access_token, :method => :get, :url => "/")
|
303
|
-
op.
|
304
|
-
Koala::Facebook::GraphBatchAPI::BatchOperation.
|
303
|
+
allow(op).to receive(:to_batch_params).and_return({:a => 2})
|
304
|
+
allow(Koala::Facebook::GraphBatchAPI::BatchOperation).to receive(:new).and_return(op)
|
305
305
|
|
306
306
|
# two requests should generate two batch operations
|
307
307
|
expected = MultiJson.dump([op.to_batch_params(access_token), op.to_batch_params(access_token)])
|
308
|
-
Koala.
|
308
|
+
expect(Koala).to receive(:make_request).with(anything, hash_including("batch" => expected), anything, anything).and_return(@fake_response)
|
309
309
|
Koala::Facebook::API.new(access_token).batch do |batch_api|
|
310
310
|
batch_api.get_object('me')
|
311
311
|
batch_api.get_object('me')
|
@@ -319,9 +319,9 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
319
319
|
@key = "file0_0"
|
320
320
|
@uploadable_io = double("UploadableIO")
|
321
321
|
batch_op = double("Koala Batch Operation", :files => {@key => @uploadable_io}, :to_batch_params => {}, :access_token => "foo")
|
322
|
-
Koala::Facebook::GraphBatchAPI::BatchOperation.
|
322
|
+
allow(Koala::Facebook::GraphBatchAPI::BatchOperation).to receive(:new).and_return(batch_op)
|
323
323
|
|
324
|
-
Koala.
|
324
|
+
expect(Koala).to receive(:make_request).with(anything, hash_including(@key => @uploadable_io), anything, anything).and_return(@fake_response)
|
325
325
|
Koala::Facebook::API.new("bar").batch do |batch_api|
|
326
326
|
batch_api.put_picture("path/to/file", "image/jpeg")
|
327
327
|
end
|
@@ -330,9 +330,9 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
330
330
|
it "preserves operation order" do
|
331
331
|
access_token = "bar"
|
332
332
|
# two requests should generate two batch operations
|
333
|
-
Koala.
|
333
|
+
expect(Koala).to receive(:make_request) do |url, args, method, options|
|
334
334
|
# test the batch operations to make sure they appear in the right order
|
335
|
-
(args ||= {})["batch"].
|
335
|
+
expect((args ||= {})["batch"]).to match(/.*me\/farglebarg.*otheruser\/bababa/)
|
336
336
|
@fake_response
|
337
337
|
end
|
338
338
|
Koala::Facebook::API.new(access_token).batch do |batch_api|
|
@@ -342,14 +342,14 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
342
342
|
end
|
343
343
|
|
344
344
|
it "makes a POST request" do
|
345
|
-
Koala.
|
345
|
+
expect(Koala).to receive(:make_request).with(anything, anything, "post", anything).and_return(@fake_response)
|
346
346
|
Koala::Facebook::API.new("foo").batch do |batch_api|
|
347
347
|
batch_api.get_object('me')
|
348
348
|
end
|
349
349
|
end
|
350
350
|
|
351
351
|
it "makes a request to /" do
|
352
|
-
Koala.
|
352
|
+
expect(Koala).to receive(:make_request).with("/", anything, anything, anything).and_return(@fake_response)
|
353
353
|
Koala::Facebook::API.new("foo").batch do |batch_api|
|
354
354
|
batch_api.get_object('me')
|
355
355
|
end
|
@@ -357,7 +357,7 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
357
357
|
|
358
358
|
it "includes any http options specified at the top level" do
|
359
359
|
http_options = {"a" => "baz"}
|
360
|
-
Koala.
|
360
|
+
expect(Koala).to receive(:make_request).with(anything, anything, anything, hash_including(http_options)).and_return(@fake_response)
|
361
361
|
Koala::Facebook::API.new("foo").batch(http_options) do |batch_api|
|
362
362
|
batch_api.get_object('me')
|
363
363
|
end
|
@@ -366,23 +366,23 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
366
366
|
|
367
367
|
describe "processing the request" do
|
368
368
|
it "returns the result headers as a hash if http_component is headers" do
|
369
|
-
Koala.
|
369
|
+
allow(Koala).to receive(:make_request).and_return(Koala::HTTPService::Response.new(200, '[{"code":203,"headers":[{"name":"Content-Type","value":"text/javascript; charset=UTF-8"}],"body":"{\"id\":\"1234\"}"}]', {}))
|
370
370
|
result = @api.batch do |batch_api|
|
371
371
|
batch_api.get_object(KoalaTest.user1, {}, :http_component => :headers)
|
372
372
|
end
|
373
|
-
result[0].
|
373
|
+
expect(result[0]).to eq({"Content-Type" => "text/javascript; charset=UTF-8"})
|
374
374
|
end
|
375
375
|
|
376
376
|
describe "if it errors" do
|
377
377
|
it "raises an APIError if the response is not 200" do
|
378
|
-
Koala.
|
378
|
+
allow(Koala).to receive(:make_request).and_return(Koala::HTTPService::Response.new(500, "[]", {}))
|
379
379
|
expect {
|
380
380
|
Koala::Facebook::API.new("foo").batch {|batch_api| batch_api.get_object('me') }
|
381
381
|
}.to raise_exception(Koala::Facebook::APIError)
|
382
382
|
end
|
383
383
|
|
384
384
|
it "raises a BadFacebookResponse if the body is empty" do
|
385
|
-
Koala.
|
385
|
+
allow(Koala).to receive(:make_request).and_return(Koala::HTTPService::Response.new(200, "", {}))
|
386
386
|
expect {
|
387
387
|
Koala::Facebook::API.new("foo").batch {|batch_api| batch_api.get_object('me') }
|
388
388
|
}.to raise_exception(Koala::Facebook::BadFacebookResponse)
|
@@ -390,7 +390,7 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
390
390
|
|
391
391
|
context "with the old style" do
|
392
392
|
before :each do
|
393
|
-
Koala.
|
393
|
+
allow(Koala).to receive(:make_request).and_return(Koala::HTTPService::Response.new(400, '{"error_code":190,"error_description":"Error validating access token."}', {}))
|
394
394
|
end
|
395
395
|
|
396
396
|
it "throws an error" do
|
@@ -403,8 +403,8 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
403
403
|
begin
|
404
404
|
Koala::Facebook::API.new("foo").batch {|batch_api| batch_api.get_object('me') }
|
405
405
|
rescue Koala::Facebook::APIError => err
|
406
|
-
err.fb_error_code.
|
407
|
-
err.fb_error_message.
|
406
|
+
expect(err.fb_error_code).to eq(190)
|
407
|
+
expect(err.fb_error_message).to eq("Error validating access token.")
|
408
408
|
err.http_status == 400
|
409
409
|
err.response_body == '{"error_code":190,"error_description":"Error validating access token."}'
|
410
410
|
end
|
@@ -413,7 +413,7 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
413
413
|
|
414
414
|
context "with the new style" do
|
415
415
|
before :each do
|
416
|
-
Koala.
|
416
|
+
allow(Koala).to receive(:make_request).and_return(Koala::HTTPService::Response.new(400, '{"error":{"message":"Request 0 cannot depend on an unresolved request with name f. Requests can only depend on preceding requests","type":"GraphBatchException"}}', {}))
|
417
417
|
end
|
418
418
|
|
419
419
|
it "throws an error" do
|
@@ -426,8 +426,8 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
426
426
|
begin
|
427
427
|
Koala::Facebook::API.new("foo").batch {|batch_api| batch_api.get_object('me') }
|
428
428
|
rescue Koala::Facebook::APIError => err
|
429
|
-
err.fb_error_type.
|
430
|
-
err.fb_error_message.
|
429
|
+
expect(err.fb_error_type).to eq("GraphBatchException")
|
430
|
+
expect(err.fb_error_message).to eq("Request 0 cannot depend on an unresolved request with name f. Requests can only depend on preceding requests")
|
431
431
|
err.http_status == 400
|
432
432
|
err.response_body == '{"error":{"message":"Request 0 cannot depend on an unresolved request with name f. Requests can only depend on preceding requests","type":"GraphBatchException"}}'
|
433
433
|
end
|
@@ -436,11 +436,11 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
436
436
|
end
|
437
437
|
|
438
438
|
it "returns the result status if http_component is status" do
|
439
|
-
Koala.
|
439
|
+
allow(Koala).to receive(:make_request).and_return(Koala::HTTPService::Response.new(200, '[{"code":203,"headers":[{"name":"Content-Type","value":"text/javascript; charset=UTF-8"}],"body":"{\"id\":\"1234\"}"}]', {}))
|
440
440
|
result = @api.batch do |batch_api|
|
441
441
|
batch_api.get_object(KoalaTest.user1, {}, :http_component => :status)
|
442
442
|
end
|
443
|
-
result[0].
|
443
|
+
expect(result[0]).to eq(203)
|
444
444
|
end
|
445
445
|
end
|
446
446
|
|
@@ -451,7 +451,7 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
451
451
|
first_count = 20
|
452
452
|
second_count = 10
|
453
453
|
|
454
|
-
Koala.
|
454
|
+
allow(Koala).to receive(:make_request).and_return(@fake_response)
|
455
455
|
|
456
456
|
thread1 = Thread.new do
|
457
457
|
@api.batch do |batch_api|
|
@@ -470,8 +470,8 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
470
470
|
thread1.join
|
471
471
|
thread2.join
|
472
472
|
|
473
|
-
thread_one_count.
|
474
|
-
thread_two_count.
|
473
|
+
expect(thread_one_count).to eq(first_count)
|
474
|
+
expect(thread_two_count).to eq(second_count)
|
475
475
|
end
|
476
476
|
end
|
477
477
|
end
|
@@ -482,8 +482,8 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
482
482
|
batch_api.get_object('me')
|
483
483
|
batch_api.get_object(KoalaTest.user1)
|
484
484
|
end
|
485
|
-
me['id'].
|
486
|
-
koppel['id'].
|
485
|
+
expect(me['id']).not_to be_nil
|
486
|
+
expect(koppel['id']).not_to be_nil
|
487
487
|
end
|
488
488
|
|
489
489
|
it 'makes mixed calls inside of a batch' do
|
@@ -491,7 +491,7 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
491
491
|
batch_api.get_object('me')
|
492
492
|
batch_api.get_connections('me', 'friends')
|
493
493
|
end
|
494
|
-
friends.
|
494
|
+
expect(friends).to be_a(Koala::Facebook::GraphCollection)
|
495
495
|
end
|
496
496
|
|
497
497
|
it 'turns pageable results into GraphCollections' do
|
@@ -499,15 +499,15 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
499
499
|
batch_api.get_object('me')
|
500
500
|
batch_api.get_connections('me', 'friends')
|
501
501
|
end
|
502
|
-
me['id'].
|
503
|
-
friends.
|
502
|
+
expect(me['id']).not_to be_nil
|
503
|
+
expect(friends).to be_an(Array)
|
504
504
|
end
|
505
505
|
|
506
506
|
it 'makes a get_picture call inside of a batch' do
|
507
507
|
pictures = @api.batch do |batch_api|
|
508
508
|
batch_api.get_picture('me')
|
509
509
|
end
|
510
|
-
pictures.first.
|
510
|
+
expect(pictures.first).to match(/http\:\/\//) # works both live & stubbed
|
511
511
|
end
|
512
512
|
|
513
513
|
it "handles requests for two different tokens" do
|
@@ -515,8 +515,8 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
515
515
|
batch_api.get_object('me')
|
516
516
|
batch_api.get_connections(@app_id, 'insights', {}, {"access_token" => @app_api.access_token})
|
517
517
|
end
|
518
|
-
me['id'].
|
519
|
-
insights.
|
518
|
+
expect(me['id']).not_to be_nil
|
519
|
+
expect(insights).to be_an(Koala::Facebook::GraphCollection)
|
520
520
|
end
|
521
521
|
|
522
522
|
it "preserves batch-op specific access tokens in GraphCollection returned from batch" do
|
@@ -531,11 +531,11 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
531
531
|
|
532
532
|
# The alternate token is returned with the next page parameters
|
533
533
|
# The GraphCollection should receive a request for the next_page_params during paging
|
534
|
-
insights.
|
534
|
+
expect(insights).to receive(:next_page_params).and_return([double("base"), @other_access_token_args.dup])
|
535
535
|
|
536
536
|
# The alternate access token should pass through to making the request
|
537
537
|
# Koala should receive a request during paging using the alternate token
|
538
|
-
Koala.
|
538
|
+
expect(Koala).to receive(:make_request).with(
|
539
539
|
anything,
|
540
540
|
hash_including(@other_access_token_args.dup),
|
541
541
|
anything,
|
@@ -551,8 +551,8 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
551
551
|
batch_api.get_connection("2", "invalidconnection")
|
552
552
|
batch_api.get_object(KoalaTest.user1, {}, {"access_token" => @app_api.access_token})
|
553
553
|
end
|
554
|
-
failed_call.
|
555
|
-
koppel["id"].
|
554
|
+
expect(failed_call).to be_a(Koala::Facebook::ClientError)
|
555
|
+
expect(koppel["id"]).not_to be_nil
|
556
556
|
end
|
557
557
|
|
558
558
|
it "handles different request methods" do
|
@@ -571,8 +571,8 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
571
571
|
end
|
572
572
|
|
573
573
|
fql_result = result[0]
|
574
|
-
fql_result[0].
|
575
|
-
fql_result[0]["first_name"].
|
574
|
+
expect(fql_result[0]).to be_a(Hash)
|
575
|
+
expect(fql_result[0]["first_name"]).to eq("Alex")
|
576
576
|
end
|
577
577
|
|
578
578
|
describe 'with post-processing callback' do
|
@@ -587,8 +587,8 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
587
587
|
batch_api.get_object('me', &me_callback)
|
588
588
|
batch_api.get_connections('me', 'friends', &friends_callback)
|
589
589
|
end
|
590
|
-
me["args"].
|
591
|
-
friends["args"].first.
|
590
|
+
expect(me["args"]).to include("id" => KoalaTest.user1)
|
591
|
+
expect(friends["args"].first).to include("id" => KoalaTest.user2)
|
592
592
|
end
|
593
593
|
|
594
594
|
it 'passes GraphCollections, not raw data' do
|
@@ -596,14 +596,14 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
596
596
|
batch_api.get_object('me')
|
597
597
|
batch_api.get_connections('me', 'friends', &friends_callback)
|
598
598
|
end
|
599
|
-
friends["args"].
|
599
|
+
expect(friends["args"]).to be_a(Koala::Facebook::API::GraphCollection)
|
600
600
|
end
|
601
601
|
|
602
602
|
it "returns the result of the callback" do
|
603
|
-
@api.batch do |batch_api|
|
603
|
+
expect(@api.batch do |batch_api|
|
604
604
|
batch_api.get_object('me', &me_callback)
|
605
605
|
batch_api.get_connections('me', 'friends', &friends_callback)
|
606
|
-
end.map {|r| r["result"]}.
|
606
|
+
end.map {|r| r["result"]}).to eq([me_result, friends_result])
|
607
607
|
end
|
608
608
|
end
|
609
609
|
|
@@ -617,7 +617,7 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
617
617
|
end
|
618
618
|
|
619
619
|
@temporary_object_id = result[0]["id"]
|
620
|
-
@temporary_object_id.
|
620
|
+
expect(@temporary_object_id).not_to be_nil
|
621
621
|
end
|
622
622
|
|
623
623
|
it "posts binary files with multiple requests" do
|
@@ -629,8 +629,8 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
629
629
|
batch_api.put_picture(file)
|
630
630
|
batch_api.put_picture(file2, {}, KoalaTest.user1)
|
631
631
|
end
|
632
|
-
results[0]["id"].
|
633
|
-
results[1]["id"].
|
632
|
+
expect(results[0]["id"]).not_to be_nil
|
633
|
+
expect(results[1]["id"]).not_to be_nil
|
634
634
|
end
|
635
635
|
end
|
636
636
|
|
@@ -641,8 +641,8 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
641
641
|
batch_api.get_objects("{result=get-friends:$.data.*.id}")
|
642
642
|
end
|
643
643
|
|
644
|
-
results[0].
|
645
|
-
results[1].
|
644
|
+
expect(results[0]).to be_nil
|
645
|
+
expect(results[1]).to be_an(Hash)
|
646
646
|
end
|
647
647
|
|
648
648
|
it "allows you create relationships between requests with omit_response_on_success" do
|
@@ -651,8 +651,8 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
651
651
|
batch_api.get_objects("{result=get-friends:$.data.*.id}")
|
652
652
|
end
|
653
653
|
|
654
|
-
results[0].
|
655
|
-
results[1].
|
654
|
+
expect(results[0]).to be_an(Array)
|
655
|
+
expect(results[1]).to be_an(Hash)
|
656
656
|
end
|
657
657
|
|
658
658
|
it "allows you to create dependencies" do
|
@@ -661,8 +661,8 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
661
661
|
batch_api.get_object(KoalaTest.user1, {}, :batch_args => {:depends_on => "getme"})
|
662
662
|
end
|
663
663
|
|
664
|
-
me.
|
665
|
-
koppel["id"].
|
664
|
+
expect(me).to be_nil # gotcha! it's omitted because it's a successfully-executed dependency
|
665
|
+
expect(koppel["id"]).not_to be_nil
|
666
666
|
end
|
667
667
|
|
668
668
|
it "properly handles dependencies that fail" do
|
@@ -671,8 +671,8 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
671
671
|
batch_api.get_object(KoalaTest.user1, {}, :batch_args => {:depends_on => "getdata"})
|
672
672
|
end
|
673
673
|
|
674
|
-
failed_call.
|
675
|
-
koppel.
|
674
|
+
expect(failed_call).to be_a(Koala::Facebook::ClientError)
|
675
|
+
expect(koppel).to be_nil
|
676
676
|
end
|
677
677
|
|
678
678
|
it "throws an error for badly-constructed request relationships" do
|