koala 1.1.0 → 1.2.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/.travis.yml +2 -1
- data/CHANGELOG +36 -0
- data/Gemfile +6 -2
- data/Rakefile +0 -1
- data/koala.gemspec +7 -8
- data/lib/koala/batch_operation.rb +15 -15
- data/lib/koala/graph_api.rb +85 -73
- data/lib/koala/graph_batch_api.rb +21 -11
- data/lib/koala/graph_collection.rb +13 -8
- data/lib/koala/http_service.rb +176 -0
- data/lib/koala/oauth.rb +34 -24
- data/lib/koala/realtime_updates.rb +21 -18
- data/lib/koala/rest_api.rb +1 -1
- data/lib/koala/test_users.rb +33 -17
- data/lib/koala/uploadable_io.rb +49 -43
- data/lib/koala/utils.rb +11 -0
- data/lib/koala/version.rb +3 -0
- data/lib/koala.rb +47 -45
- data/readme.md +58 -38
- data/spec/cases/{api_base_spec.rb → api_spec.rb} +27 -2
- data/spec/cases/error_spec.rb +32 -0
- data/spec/cases/graph_and_rest_api_spec.rb +12 -21
- data/spec/cases/graph_api_batch_spec.rb +92 -119
- data/spec/cases/graph_api_spec.rb +11 -14
- data/spec/cases/graph_collection_spec.rb +116 -0
- data/spec/cases/http_service_spec.rb +446 -0
- data/spec/cases/koala_spec.rb +36 -37
- data/spec/cases/oauth_spec.rb +318 -212
- data/spec/cases/realtime_updates_spec.rb +45 -31
- data/spec/cases/rest_api_spec.rb +23 -7
- data/spec/cases/test_users_spec.rb +123 -75
- data/spec/cases/uploadable_io_spec.rb +77 -36
- data/spec/cases/utils_spec.rb +10 -0
- data/spec/fixtures/facebook_data.yml +26 -24
- data/spec/fixtures/mock_facebook_responses.yml +131 -101
- data/spec/spec_helper.rb +29 -5
- data/spec/support/graph_api_shared_examples.rb +80 -120
- data/spec/support/json_testing_fix.rb +35 -11
- data/spec/support/koala_test.rb +187 -0
- data/spec/support/mock_http_service.rb +8 -5
- data/spec/support/ordered_hash.rb +205 -0
- data/spec/support/rest_api_shared_examples.rb +37 -37
- data/spec/support/uploadable_io_shared_examples.rb +2 -8
- metadata +72 -83
- data/lib/koala/http_services/net_http_service.rb +0 -92
- data/lib/koala/http_services/typhoeus_service.rb +0 -37
- data/lib/koala/http_services.rb +0 -46
- data/spec/cases/http_services/http_service_spec.rb +0 -129
- data/spec/cases/http_services/net_http_service_spec.rb +0 -532
- data/spec/cases/http_services/typhoeus_service_spec.rb +0 -152
- data/spec/support/live_testing_data_helper.rb +0 -40
- data/spec/support/setup_mocks_or_live.rb +0 -51
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
4
|
-
|
|
4
|
+
|
|
5
5
|
before :each do
|
|
6
|
-
@api = Koala::Facebook::
|
|
6
|
+
@api = Koala::Facebook::API.new(@token)
|
|
7
7
|
# app API
|
|
8
|
-
@
|
|
9
|
-
@
|
|
10
|
-
@
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
@app_id = KoalaTest.app_id
|
|
9
|
+
@app_access_token = KoalaTest.app_access_token
|
|
10
|
+
@app_api = Koala::Facebook::API.new(@app_access_token)
|
|
11
|
+
end
|
|
12
|
+
|
|
14
13
|
describe "BatchOperations" do
|
|
15
14
|
before :each do
|
|
16
15
|
@args = {
|
|
@@ -22,43 +21,43 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
|
22
21
|
:post_processing => lambda { }
|
|
23
22
|
}
|
|
24
23
|
end
|
|
25
|
-
|
|
24
|
+
|
|
26
25
|
describe "#new" do
|
|
27
26
|
it "makes http_options accessible" do
|
|
28
27
|
Koala::Facebook::BatchOperation.new(@args).http_options.should == @args[:http_options]
|
|
29
28
|
end
|
|
30
|
-
|
|
29
|
+
|
|
31
30
|
it "makes post_processing accessible" do
|
|
32
31
|
Koala::Facebook::BatchOperation.new(@args).post_processing.should == @args[:post_processing]
|
|
33
32
|
end
|
|
34
|
-
|
|
33
|
+
|
|
35
34
|
it "makes access_token accessible" do
|
|
36
35
|
Koala::Facebook::BatchOperation.new(@args).access_token.should == @args[:access_token]
|
|
37
36
|
end
|
|
38
|
-
|
|
37
|
+
|
|
39
38
|
it "doesn't change the original http_options" do
|
|
40
39
|
@args[:http_options][:name] = "baz2"
|
|
41
40
|
expected = @args[:http_options].dup
|
|
42
41
|
Koala::Facebook::BatchOperation.new(@args).to_batch_params(nil)
|
|
43
42
|
@args[:http_options].should == expected
|
|
44
43
|
end
|
|
45
|
-
|
|
44
|
+
|
|
46
45
|
it "leaves the file array nil by default" do
|
|
47
|
-
Koala::Facebook::BatchOperation.new(@args).files.should be_nil
|
|
46
|
+
Koala::Facebook::BatchOperation.new(@args).files.should be_nil
|
|
48
47
|
end
|
|
49
|
-
|
|
48
|
+
|
|
50
49
|
it "raises a KoalaError if no access token supplied" do
|
|
51
50
|
expect { Koala::Facebook::BatchOperation.new(@args.merge(:access_token => nil)) }.to raise_exception(Koala::KoalaError)
|
|
52
51
|
end
|
|
53
|
-
|
|
52
|
+
|
|
54
53
|
describe "when supplied binary files" do
|
|
55
54
|
before :each do
|
|
56
55
|
@binary = stub("Binary file")
|
|
57
56
|
@uploadable_io = stub("UploadableIO 1")
|
|
58
|
-
|
|
57
|
+
|
|
59
58
|
@batch_queue = []
|
|
60
59
|
Koala::Facebook::GraphAPI.stub(:batch_calls).and_return(@batch_queue)
|
|
61
|
-
|
|
60
|
+
|
|
62
61
|
Koala::UploadableIO.stub(:new).with(@binary).and_return(@uploadable_io)
|
|
63
62
|
Koala::UploadableIO.stub(:binary_content?).and_return(false)
|
|
64
63
|
Koala::UploadableIO.stub(:binary_content?).with(@binary).and_return(true)
|
|
@@ -67,14 +66,14 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
|
67
66
|
|
|
68
67
|
@args[:method] = "post" # files are always post
|
|
69
68
|
end
|
|
70
|
-
|
|
69
|
+
|
|
71
70
|
it "adds binary files to the files attribute as UploadableIOs" do
|
|
72
71
|
@args[:args].merge!("source" => @binary)
|
|
73
72
|
batch_op = Koala::Facebook::BatchOperation.new(@args)
|
|
74
73
|
batch_op.files.should_not be_nil
|
|
75
74
|
batch_op.files.find {|k, v| v == @uploadable_io}.should_not be_nil
|
|
76
75
|
end
|
|
77
|
-
|
|
76
|
+
|
|
78
77
|
it "works if supplied an UploadableIO as an argument" do
|
|
79
78
|
# as happens with put_picture at the moment
|
|
80
79
|
@args[:args].merge!("source" => @uploadable_io)
|
|
@@ -82,14 +81,14 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
|
82
81
|
batch_op.files.should_not be_nil
|
|
83
82
|
batch_op.files.find {|k, v| v == @uploadable_io}.should_not be_nil
|
|
84
83
|
end
|
|
85
|
-
|
|
84
|
+
|
|
86
85
|
it "assigns each binary parameter unique name" do
|
|
87
86
|
@args[:args].merge!("source" => @binary, "source2" => @binary)
|
|
88
87
|
batch_op = Koala::Facebook::BatchOperation.new(@args)
|
|
89
88
|
# if the name wasn't unique, there'd just be one item
|
|
90
89
|
batch_op.files.should have(2).items
|
|
91
90
|
end
|
|
92
|
-
|
|
91
|
+
|
|
93
92
|
it "assigns each binary parameter unique name across batch requests" do
|
|
94
93
|
@args[:args].merge!("source" => @binary, "source2" => @binary)
|
|
95
94
|
batch_op = Koala::Facebook::BatchOperation.new(@args)
|
|
@@ -100,59 +99,59 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
|
100
99
|
# if the name wasn't unique, we should have < 4 items since keys would be the same
|
|
101
100
|
batch_op.files.merge(batch_op2.files).should have(4).items
|
|
102
101
|
end
|
|
103
|
-
|
|
102
|
+
|
|
104
103
|
it "removes the value from the arguments" do
|
|
105
104
|
@args[:args].merge!("source" => @binary)
|
|
106
105
|
Koala::Facebook::BatchOperation.new(@args).to_batch_params(nil)[:body].should_not =~ /source=/
|
|
107
106
|
end
|
|
108
|
-
end
|
|
109
|
-
|
|
107
|
+
end
|
|
108
|
+
|
|
110
109
|
end
|
|
111
|
-
|
|
112
|
-
describe ".to_batch_params" do
|
|
110
|
+
|
|
111
|
+
describe ".to_batch_params" do
|
|
113
112
|
describe "handling arguments and URLs" do
|
|
114
113
|
shared_examples_for "request with no body" do
|
|
115
114
|
it "adds the args to the URL string, with ? if no args previously present" do
|
|
116
115
|
test_args = "foo"
|
|
117
116
|
@args[:url] = url = "/"
|
|
118
117
|
Koala.http_service.stub(:encode_params).and_return(test_args)
|
|
119
|
-
|
|
118
|
+
|
|
120
119
|
Koala::Facebook::BatchOperation.new(@args).to_batch_params(nil)[:relative_url].should == "#{url}?#{test_args}"
|
|
121
120
|
end
|
|
122
|
-
|
|
121
|
+
|
|
123
122
|
it "adds the args to the URL string, with & if args previously present" do
|
|
124
123
|
test_args = "foo"
|
|
125
124
|
@args[:url] = url = "/?a=2"
|
|
126
125
|
Koala.http_service.stub(:encode_params).and_return(test_args)
|
|
127
|
-
|
|
126
|
+
|
|
128
127
|
Koala::Facebook::BatchOperation.new(@args).to_batch_params(nil)[:relative_url].should == "#{url}&#{test_args}"
|
|
129
128
|
end
|
|
130
|
-
|
|
129
|
+
|
|
131
130
|
it "adds nothing to the URL string if there are no args to be added" do
|
|
132
131
|
@args[:args] = {}
|
|
133
|
-
Koala::Facebook::BatchOperation.new(@args).to_batch_params(@args[:access_token])[:relative_url].should == @args[:url]
|
|
132
|
+
Koala::Facebook::BatchOperation.new(@args).to_batch_params(@args[:access_token])[:relative_url].should == @args[:url]
|
|
134
133
|
end
|
|
135
|
-
|
|
134
|
+
|
|
136
135
|
it "adds nothing to the body" do
|
|
137
136
|
Koala::Facebook::BatchOperation.new(@args).to_batch_params(nil)[:body].should be_nil
|
|
138
137
|
end
|
|
139
138
|
end
|
|
140
|
-
|
|
139
|
+
|
|
141
140
|
shared_examples_for "requests with a body param" do
|
|
142
141
|
it "sets the body to the encoded args string, if there are args" do
|
|
143
142
|
test_args = "foo"
|
|
144
143
|
Koala.http_service.stub(:encode_params).and_return(test_args)
|
|
145
|
-
|
|
144
|
+
|
|
146
145
|
Koala::Facebook::BatchOperation.new(@args).to_batch_params(nil)[:body].should == test_args
|
|
147
146
|
end
|
|
148
|
-
|
|
147
|
+
|
|
149
148
|
it "does not set the body if there are no args" do
|
|
150
149
|
test_args = ""
|
|
151
150
|
Koala.http_service.stub(:encode_params).and_return(test_args)
|
|
152
151
|
Koala::Facebook::BatchOperation.new(@args).to_batch_params(nil)[:body].should be_nil
|
|
153
152
|
end
|
|
154
|
-
|
|
155
|
-
|
|
153
|
+
|
|
154
|
+
|
|
156
155
|
it "doesn't change the url" do
|
|
157
156
|
test_args = "foo"
|
|
158
157
|
Koala.http_service.stub(:encode_params).and_return(test_args)
|
|
@@ -160,40 +159,40 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
|
160
159
|
Koala::Facebook::BatchOperation.new(@args).to_batch_params(nil)[:relative_url].should == @args[:url]
|
|
161
160
|
end
|
|
162
161
|
end
|
|
163
|
-
|
|
162
|
+
|
|
164
163
|
context "for get operations" do
|
|
165
164
|
before :each do
|
|
166
165
|
@args[:method] = :get
|
|
167
166
|
end
|
|
168
|
-
|
|
169
|
-
it_should_behave_like "request with no body"
|
|
167
|
+
|
|
168
|
+
it_should_behave_like "request with no body"
|
|
170
169
|
end
|
|
171
|
-
|
|
170
|
+
|
|
172
171
|
context "for delete operations" do
|
|
173
172
|
before :each do
|
|
174
173
|
@args[:method] = :delete
|
|
175
174
|
end
|
|
176
|
-
|
|
177
|
-
it_should_behave_like "request with no body"
|
|
175
|
+
|
|
176
|
+
it_should_behave_like "request with no body"
|
|
178
177
|
end
|
|
179
|
-
|
|
178
|
+
|
|
180
179
|
context "for get operations" do
|
|
181
180
|
before :each do
|
|
182
181
|
@args[:method] = :put
|
|
183
182
|
end
|
|
184
|
-
|
|
185
|
-
it_should_behave_like "requests with a body param"
|
|
183
|
+
|
|
184
|
+
it_should_behave_like "requests with a body param"
|
|
186
185
|
end
|
|
187
|
-
|
|
186
|
+
|
|
188
187
|
context "for delete operations" do
|
|
189
188
|
before :each do
|
|
190
189
|
@args[:method] = :post
|
|
191
190
|
end
|
|
192
|
-
|
|
193
|
-
it_should_behave_like "requests with a body param"
|
|
191
|
+
|
|
192
|
+
it_should_behave_like "requests with a body param"
|
|
194
193
|
end
|
|
195
194
|
end
|
|
196
|
-
|
|
195
|
+
|
|
197
196
|
it "includes the access token if the token is not the main one for the request" do
|
|
198
197
|
params = Koala::Facebook::BatchOperation.new(@args).to_batch_params(nil)
|
|
199
198
|
params[:relative_url].should =~ /access_token=#{@args[:access_token]}/
|
|
@@ -209,13 +208,13 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
|
209
208
|
params = Koala::Facebook::BatchOperation.new(@args).to_batch_params(@args[:access_token])
|
|
210
209
|
params[:relative_url].should_not =~ /access_token=#{@args[:access_token]}/
|
|
211
210
|
end
|
|
212
|
-
|
|
211
|
+
|
|
213
212
|
it "includes the other arguments if the token is the main one for the request" do
|
|
214
213
|
@args[:args] = {:a => 2}
|
|
215
214
|
params = Koala::Facebook::BatchOperation.new(@args).to_batch_params(@args[:access_token])
|
|
216
215
|
params[:relative_url].should =~ /a=2/
|
|
217
216
|
end
|
|
218
|
-
|
|
217
|
+
|
|
219
218
|
it "includes any arguments passed as http_options[:batch_args]" do
|
|
220
219
|
batch_args = {:name => "baz", :headers => {:some_param => true}}
|
|
221
220
|
@args[:http_options][:batch_args] = batch_args
|
|
@@ -227,22 +226,22 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
|
227
226
|
params = Koala::Facebook::BatchOperation.new(@args).to_batch_params(@args[:access_token])
|
|
228
227
|
params[:method].should == @args[:method].to_s
|
|
229
228
|
end
|
|
230
|
-
|
|
229
|
+
|
|
231
230
|
it "works with nil http_options" do
|
|
232
231
|
expect { Koala::Facebook::BatchOperation.new(@args.merge(:http_options => nil)).to_batch_params(nil) }.not_to raise_exception
|
|
233
232
|
end
|
|
234
|
-
|
|
233
|
+
|
|
235
234
|
it "works with nil args" do
|
|
236
235
|
expect { Koala::Facebook::BatchOperation.new(@args.merge(:args => nil)).to_batch_params(nil) }.not_to raise_exception
|
|
237
|
-
end
|
|
238
|
-
|
|
236
|
+
end
|
|
237
|
+
|
|
239
238
|
describe "with binary files" do
|
|
240
239
|
before :each do
|
|
241
240
|
@binary = stub("Binary file")
|
|
242
241
|
Koala::UploadableIO.stub(:binary_content?).and_return(false)
|
|
243
242
|
Koala::UploadableIO.stub(:binary_content?).with(@binary).and_return(true)
|
|
244
243
|
@uploadable_io = stub("UploadableIO")
|
|
245
|
-
Koala::UploadableIO.stub(:new).with(@binary).and_return(@uploadable_io)
|
|
244
|
+
Koala::UploadableIO.stub(:new).with(@binary).and_return(@uploadable_io)
|
|
246
245
|
@uploadable_io.stub(:is_a?).with(Koala::UploadableIO).and_return(true)
|
|
247
246
|
|
|
248
247
|
@batch_queue = []
|
|
@@ -250,7 +249,7 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
|
250
249
|
|
|
251
250
|
@args[:method] = "post" # files are always post
|
|
252
251
|
end
|
|
253
|
-
|
|
252
|
+
|
|
254
253
|
it "adds file identifiers as attached_files in a comma-separated list" do
|
|
255
254
|
@args[:args].merge!("source" => @binary, "source2" => @binary)
|
|
256
255
|
batch_op = Koala::Facebook::BatchOperation.new(@args)
|
|
@@ -293,7 +292,7 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
|
293
292
|
it "includes the first operation's access token as the main one in the args" do
|
|
294
293
|
access_token = "foo"
|
|
295
294
|
Koala.should_receive(:make_request).with(anything, hash_including("access_token" => access_token), anything, anything).and_return(@fake_response)
|
|
296
|
-
Koala::Facebook::
|
|
295
|
+
Koala::Facebook::API.new(access_token).batch do |batch_api|
|
|
297
296
|
batch_api.get_object('me')
|
|
298
297
|
batch_api.get_object('me', {}, {'access_token' => 'bar'})
|
|
299
298
|
end
|
|
@@ -308,7 +307,7 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
|
308
307
|
# two requests should generate two batch operations
|
|
309
308
|
expected = MultiJson.encode([op.to_batch_params(access_token), op.to_batch_params(access_token)])
|
|
310
309
|
Koala.should_receive(:make_request).with(anything, hash_including("batch" => expected), anything, anything).and_return(@fake_response)
|
|
311
|
-
Koala::Facebook::
|
|
310
|
+
Koala::Facebook::API.new(access_token).batch do |batch_api|
|
|
312
311
|
batch_api.get_object('me')
|
|
313
312
|
batch_api.get_object('me')
|
|
314
313
|
end
|
|
@@ -324,7 +323,7 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
|
324
323
|
Koala::Facebook::BatchOperation.stub(:new).and_return(batch_op)
|
|
325
324
|
|
|
326
325
|
Koala.should_receive(:make_request).with(anything, hash_including(@key => @uploadable_io), anything, anything).and_return(@fake_response)
|
|
327
|
-
Koala::Facebook::
|
|
326
|
+
Koala::Facebook::API.new("bar").batch do |batch_api|
|
|
328
327
|
batch_api.put_picture("path/to/file", "image/jpeg")
|
|
329
328
|
end
|
|
330
329
|
end
|
|
@@ -337,7 +336,7 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
|
337
336
|
(args ||= {})["batch"].should =~ /.*me\/farglebarg.*otheruser\/bababa/
|
|
338
337
|
@fake_response
|
|
339
338
|
end
|
|
340
|
-
Koala::Facebook::
|
|
339
|
+
Koala::Facebook::API.new(access_token).batch do |batch_api|
|
|
341
340
|
batch_api.get_connections('me', "farglebarg")
|
|
342
341
|
batch_api.get_connections('otheruser', "bababa")
|
|
343
342
|
end
|
|
@@ -345,14 +344,14 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
|
345
344
|
|
|
346
345
|
it "makes a POST request" do
|
|
347
346
|
Koala.should_receive(:make_request).with(anything, anything, "post", anything).and_return(@fake_response)
|
|
348
|
-
Koala::Facebook::
|
|
347
|
+
Koala::Facebook::API.new("foo").batch do |batch_api|
|
|
349
348
|
batch_api.get_object('me')
|
|
350
349
|
end
|
|
351
350
|
end
|
|
352
351
|
|
|
353
352
|
it "makes a request to /" do
|
|
354
353
|
Koala.should_receive(:make_request).with("/", anything, anything, anything).and_return(@fake_response)
|
|
355
|
-
Koala::Facebook::
|
|
354
|
+
Koala::Facebook::API.new("foo").batch do |batch_api|
|
|
356
355
|
batch_api.get_object('me')
|
|
357
356
|
end
|
|
358
357
|
end
|
|
@@ -360,7 +359,7 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
|
360
359
|
it "includes any http options specified at the top level" do
|
|
361
360
|
http_options = {"a" => "baz"}
|
|
362
361
|
Koala.should_receive(:make_request).with(anything, anything, anything, hash_including(http_options)).and_return(@fake_response)
|
|
363
|
-
Koala::Facebook::
|
|
362
|
+
Koala::Facebook::API.new("foo").batch(http_options) do |batch_api|
|
|
364
363
|
batch_api.get_object('me')
|
|
365
364
|
end
|
|
366
365
|
end
|
|
@@ -369,14 +368,14 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
|
369
368
|
describe "processing the request" do
|
|
370
369
|
it "throws an error if the response is not 200" do
|
|
371
370
|
Koala.stub(:make_request).and_return(Koala::Response.new(500, "[]", {}))
|
|
372
|
-
expect { Koala::Facebook::
|
|
371
|
+
expect { Koala::Facebook::API.new("foo").batch do |batch_api|
|
|
373
372
|
batch_api.get_object('me')
|
|
374
373
|
end }.to raise_exception(Koala::Facebook::APIError)
|
|
375
374
|
end
|
|
376
375
|
|
|
377
376
|
it "throws an error if the response is a Batch API-style error" do
|
|
378
377
|
Koala.stub(:make_request).and_return(Koala::Response.new(200, '{"error":190,"error_description":"Error validating access token."}', {}))
|
|
379
|
-
expect { Koala::Facebook::
|
|
378
|
+
expect { Koala::Facebook::API.new("foo").batch do |batch_api|
|
|
380
379
|
batch_api.get_object('me')
|
|
381
380
|
end }.to raise_exception(Koala::Facebook::APIError)
|
|
382
381
|
end
|
|
@@ -384,7 +383,7 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
|
384
383
|
it "returns the result status if http_component is status" do
|
|
385
384
|
Koala.stub(:make_request).and_return(Koala::Response.new(200, '[{"code":203,"headers":[{"name":"Content-Type","value":"text/javascript; charset=UTF-8"}],"body":"{\"id\":\"1234\"}"}]', {}))
|
|
386
385
|
result = @api.batch do |batch_api|
|
|
387
|
-
batch_api.get_object(
|
|
386
|
+
batch_api.get_object(KoalaTest.user1, {}, :http_component => :status)
|
|
388
387
|
end
|
|
389
388
|
result[0].should == 203
|
|
390
389
|
end
|
|
@@ -392,7 +391,7 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
|
392
391
|
it "returns the result headers as a hash if http_component is headers" do
|
|
393
392
|
Koala.stub(:make_request).and_return(Koala::Response.new(200, '[{"code":203,"headers":[{"name":"Content-Type","value":"text/javascript; charset=UTF-8"}],"body":"{\"id\":\"1234\"}"}]', {}))
|
|
394
393
|
result = @api.batch do |batch_api|
|
|
395
|
-
batch_api.get_object(
|
|
394
|
+
batch_api.get_object(KoalaTest.user1, {}, :http_component => :headers)
|
|
396
395
|
end
|
|
397
396
|
result[0].should == {"Content-Type" => "text/javascript; charset=UTF-8"}
|
|
398
397
|
end
|
|
@@ -404,26 +403,26 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
|
404
403
|
thread_two_count = 0
|
|
405
404
|
first_count = 20
|
|
406
405
|
second_count = 10
|
|
407
|
-
|
|
406
|
+
|
|
408
407
|
Koala.stub(:make_request).and_return(@fake_response)
|
|
409
408
|
|
|
410
409
|
thread1 = Thread.new do
|
|
411
|
-
@api.batch do |batch_api|
|
|
410
|
+
@api.batch do |batch_api|
|
|
412
411
|
first_count.times {|i| batch_api.get_object("me"); sleep(0.01) }
|
|
413
412
|
thread_one_count = batch_api.batch_calls.count
|
|
414
413
|
end
|
|
415
414
|
end
|
|
416
|
-
|
|
415
|
+
|
|
417
416
|
thread2 = Thread.new do
|
|
418
|
-
@api.batch do |batch_api|
|
|
417
|
+
@api.batch do |batch_api|
|
|
419
418
|
second_count.times {|i| batch_api.get_object("me"); sleep(0.01) }
|
|
420
419
|
thread_two_count = batch_api.batch_calls.count
|
|
421
420
|
end
|
|
422
421
|
end
|
|
423
|
-
|
|
422
|
+
|
|
424
423
|
thread1.join
|
|
425
424
|
thread2.join
|
|
426
|
-
|
|
425
|
+
|
|
427
426
|
thread_one_count.should == first_count
|
|
428
427
|
thread_two_count.should == second_count
|
|
429
428
|
end
|
|
@@ -431,25 +430,24 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
|
431
430
|
end
|
|
432
431
|
|
|
433
432
|
describe "usage tests" do
|
|
434
|
-
it "
|
|
433
|
+
it "gets two results at once" do
|
|
435
434
|
me, koppel = @api.batch do |batch_api|
|
|
436
435
|
batch_api.get_object('me')
|
|
437
|
-
batch_api.get_object(
|
|
436
|
+
batch_api.get_object(KoalaTest.user1)
|
|
438
437
|
end
|
|
439
438
|
me['id'].should_not be_nil
|
|
440
439
|
koppel['id'].should_not be_nil
|
|
441
440
|
end
|
|
442
441
|
|
|
443
|
-
it
|
|
444
|
-
me,
|
|
442
|
+
it 'makes mixed calls inside of a batch' do
|
|
443
|
+
me, friends = @api.batch do |batch_api|
|
|
445
444
|
batch_api.get_object('me')
|
|
446
|
-
batch_api.
|
|
445
|
+
batch_api.get_connections('me', 'friends')
|
|
447
446
|
end
|
|
448
|
-
|
|
449
|
-
koppel['id'].should_not be_nil
|
|
447
|
+
friends.should be_a(Koala::Facebook::GraphCollection)
|
|
450
448
|
end
|
|
451
|
-
|
|
452
|
-
it '
|
|
449
|
+
|
|
450
|
+
it 'turns pageable results into GraphCollections' do
|
|
453
451
|
me, friends = @api.batch do |batch_api|
|
|
454
452
|
batch_api.get_object('me')
|
|
455
453
|
batch_api.get_connections('me', 'friends')
|
|
@@ -458,14 +456,14 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
|
458
456
|
friends.should be_an(Array)
|
|
459
457
|
end
|
|
460
458
|
|
|
461
|
-
it '
|
|
459
|
+
it 'makes a get_picture call inside of a batch' do
|
|
462
460
|
pictures = @api.batch do |batch_api|
|
|
463
461
|
batch_api.get_picture('me')
|
|
464
462
|
end
|
|
465
463
|
pictures.first.should_not be_empty
|
|
466
464
|
end
|
|
467
465
|
|
|
468
|
-
it "
|
|
466
|
+
it "handles requests for two different tokens" do
|
|
469
467
|
me, insights = @api.batch do |batch_api|
|
|
470
468
|
batch_api.get_object('me')
|
|
471
469
|
batch_api.get_connections(@app_id, 'insights', {}, {"access_token" => @app_api.access_token})
|
|
@@ -477,7 +475,7 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
|
477
475
|
it "inserts errors in the appropriate place, without breaking other results" do
|
|
478
476
|
failed_insights, koppel = @api.batch do |batch_api|
|
|
479
477
|
batch_api.get_connections(@app_id, 'insights')
|
|
480
|
-
batch_api.get_object(
|
|
478
|
+
batch_api.get_object(KoalaTest.user1, {}, {"access_token" => @app_api.access_token})
|
|
481
479
|
end
|
|
482
480
|
failed_insights.should be_a(Koala::Facebook::APIError)
|
|
483
481
|
koppel["id"].should_not be_nil
|
|
@@ -495,12 +493,12 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
|
495
493
|
|
|
496
494
|
it "allows FQL" do
|
|
497
495
|
result = @api.batch do |batch_api|
|
|
498
|
-
batch_api.graph_call("method/fql.query", {:query=>"select
|
|
496
|
+
batch_api.graph_call("method/fql.query", {:query=>"select first_name from user where uid=#{KoalaTest.user1_id}"}, "post")
|
|
499
497
|
end
|
|
500
498
|
|
|
501
499
|
fql_result = result[0]
|
|
502
500
|
fql_result[0].should be_a(Hash)
|
|
503
|
-
fql_result[0]["
|
|
501
|
+
fql_result[0]["first_name"].should == "Alex"
|
|
504
502
|
end
|
|
505
503
|
|
|
506
504
|
describe "binary files" do
|
|
@@ -518,11 +516,12 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
|
518
516
|
|
|
519
517
|
it "posts binary files with multiple requests" do
|
|
520
518
|
file = File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "beach.jpg"))
|
|
519
|
+
file2 = File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "beach.jpg"))
|
|
521
520
|
|
|
522
521
|
Koala::Facebook::BatchOperation.instance_variable_set(:@identifier, 0)
|
|
523
522
|
results = @api.batch do |batch_api|
|
|
524
523
|
batch_api.put_picture(file)
|
|
525
|
-
batch_api.put_picture(
|
|
524
|
+
batch_api.put_picture(file2, {}, KoalaTest.user1)
|
|
526
525
|
end
|
|
527
526
|
results[0]["id"].should_not be_nil
|
|
528
527
|
results[1]["id"].should_not be_nil
|
|
@@ -553,7 +552,7 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
|
553
552
|
it "allows you to create dependencies" do
|
|
554
553
|
me, koppel = @api.batch do |batch_api|
|
|
555
554
|
batch_api.get_object("me", {}, :batch_args => {:name => "getme"})
|
|
556
|
-
batch_api.get_object(
|
|
555
|
+
batch_api.get_object(KoalaTest.user1, {}, :batch_args => {:depends_on => "getme"})
|
|
557
556
|
end
|
|
558
557
|
|
|
559
558
|
me.should be_nil # gotcha! it's omitted because it's a successfully-executed dependency
|
|
@@ -563,7 +562,7 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
|
563
562
|
it "properly handles dependencies that fail" do
|
|
564
563
|
data, koppel = @api.batch do |batch_api|
|
|
565
564
|
batch_api.get_connections(@app_id, 'insights', {}, :batch_args => {:name => "getdata"})
|
|
566
|
-
batch_api.get_object(
|
|
565
|
+
batch_api.get_object(KoalaTest.user1, {}, :batch_args => {:depends_on => "getdata"})
|
|
567
566
|
end
|
|
568
567
|
|
|
569
568
|
data.should be_a(Koala::Facebook::APIError)
|
|
@@ -580,30 +579,4 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
|
580
579
|
end
|
|
581
580
|
end
|
|
582
581
|
end
|
|
583
|
-
|
|
584
|
-
describe "new interface" do
|
|
585
|
-
it "includes a deprecation warning on GraphAPI" do
|
|
586
|
-
begin
|
|
587
|
-
Koala::Facebook::GraphAPI.batch do
|
|
588
|
-
end
|
|
589
|
-
rescue NoMethodError => @err
|
|
590
|
-
end
|
|
591
|
-
|
|
592
|
-
# verify the message points people to the wiki page
|
|
593
|
-
@err.should
|
|
594
|
-
@err.message.should =~ /https\:\/\/github.com\/arsduo\/koala\/wiki\/Batch-requests/
|
|
595
|
-
end
|
|
596
|
-
|
|
597
|
-
it "includes a deprecation warning on GraphAndRESTAPI" do
|
|
598
|
-
begin
|
|
599
|
-
Koala::Facebook::GraphAndRestAPI.batch do
|
|
600
|
-
end
|
|
601
|
-
rescue NoMethodError => @err
|
|
602
|
-
end
|
|
603
|
-
|
|
604
|
-
# verify the message points people to the wiki page
|
|
605
|
-
@err.should
|
|
606
|
-
@err.message.should =~ /https\:\/\/github.com\/arsduo\/koala\/wiki\/Batch-requests/
|
|
607
|
-
end
|
|
608
|
-
end
|
|
609
582
|
end
|
|
@@ -1,25 +1,22 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe "Koala::Facebook::GraphAPI" do
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
context "with an access token" do
|
|
4
|
+
describe "class consolidation" do
|
|
7
5
|
before :each do
|
|
8
|
-
|
|
6
|
+
Koala::Utils.stub(:deprecate) # avoid actual messages to stderr
|
|
9
7
|
end
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
end
|
|
9
|
+
it "still allows you to instantiate a GraphAndRestAPI object" do
|
|
10
|
+
api = Koala::Facebook::GraphAPI.new("token").should be_a(Koala::Facebook::GraphAPI)
|
|
11
|
+
end
|
|
15
12
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
@api = Koala::Facebook::GraphAPI.new
|
|
13
|
+
it "ultimately creates an API object" do
|
|
14
|
+
api = Koala::Facebook::GraphAPI.new("token").should be_a(Koala::Facebook::API)
|
|
19
15
|
end
|
|
20
16
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
it "fires a depreciation warning" do
|
|
18
|
+
Koala::Utils.should_receive(:deprecate)
|
|
19
|
+
api = Koala::Facebook::GraphAPI.new("token")
|
|
20
|
+
end
|
|
24
21
|
end
|
|
25
22
|
end
|