koala 2.5.0 → 3.0.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.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +5 -3
  3. data/Gemfile +1 -1
  4. data/ISSUE_TEMPLATE +25 -0
  5. data/PULL_REQUEST_TEMPLATE +11 -0
  6. data/changelog.md +66 -4
  7. data/code_of_conduct.md +64 -12
  8. data/koala.gemspec +3 -0
  9. data/lib/koala/api/batch_operation.rb +3 -6
  10. data/lib/koala/api/{graph_api.rb → graph_api_methods.rb} +13 -102
  11. data/lib/koala/api/graph_batch_api.rb +112 -65
  12. data/lib/koala/api/graph_collection.rb +19 -12
  13. data/lib/koala/api/graph_error_checker.rb +1 -1
  14. data/lib/koala/api.rb +49 -25
  15. data/lib/koala/configuration.rb +49 -0
  16. data/lib/koala/errors.rb +1 -1
  17. data/lib/koala/http_service/multipart_request.rb +6 -10
  18. data/lib/koala/http_service/request.rb +135 -0
  19. data/lib/koala/http_service/response.rb +6 -4
  20. data/lib/koala/http_service/uploadable_io.rb +0 -4
  21. data/lib/koala/http_service.rb +18 -76
  22. data/lib/koala/oauth.rb +7 -7
  23. data/lib/koala/realtime_updates.rb +26 -21
  24. data/lib/koala/test_users.rb +9 -8
  25. data/lib/koala/version.rb +1 -1
  26. data/lib/koala.rb +6 -8
  27. data/readme.md +50 -109
  28. data/spec/cases/api_spec.rb +99 -69
  29. data/spec/cases/configuration_spec.rb +11 -0
  30. data/spec/cases/graph_api_batch_spec.rb +73 -42
  31. data/spec/cases/graph_api_spec.rb +15 -29
  32. data/spec/cases/graph_collection_spec.rb +47 -34
  33. data/spec/cases/graph_error_checker_spec.rb +6 -1
  34. data/spec/cases/http_service/request_spec.rb +242 -0
  35. data/spec/cases/http_service/response_spec.rb +24 -0
  36. data/spec/cases/http_service_spec.rb +102 -296
  37. data/spec/cases/koala_spec.rb +7 -5
  38. data/spec/cases/oauth_spec.rb +40 -1
  39. data/spec/cases/realtime_updates_spec.rb +51 -13
  40. data/spec/cases/test_users_spec.rb +56 -2
  41. data/spec/cases/uploadable_io_spec.rb +31 -31
  42. data/spec/fixtures/cat.m4v +0 -0
  43. data/spec/fixtures/facebook_data.yml +4 -6
  44. data/spec/fixtures/mock_facebook_responses.yml +29 -69
  45. data/spec/fixtures/vcr_cassettes/app_test_accounts.yml +97 -0
  46. data/spec/integration/graph_collection_spec.rb +8 -5
  47. data/spec/spec_helper.rb +2 -2
  48. data/spec/support/graph_api_shared_examples.rb +143 -336
  49. data/spec/support/koala_test.rb +8 -10
  50. data/spec/support/mock_http_service.rb +9 -9
  51. data/spec/support/uploadable_io_shared_examples.rb +4 -4
  52. metadata +31 -11
  53. data/.autotest +0 -12
  54. data/Guardfile +0 -6
  55. data/autotest/discover.rb +0 -1
  56. data/lib/koala/api/rest_api.rb +0 -135
  57. data/spec/support/rest_api_shared_examples.rb +0 -168
@@ -1,9 +1,30 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "Koala::Facebook::API" do
4
- before(:each) do
4
+ before :each do
5
5
  @service = Koala::Facebook::API.new
6
6
  end
7
+ let(:dummy_response) { double("fake response", data: {}, status: 200, body: "", headers: {}) }
8
+
9
+ it "defaults to the globally configured token if one's provided" do
10
+ token = "Foo"
11
+
12
+ Koala.configure do |config|
13
+ config.access_token = token
14
+ end
15
+
16
+ expect(Koala::Facebook::API.new.access_token).to eq(token)
17
+ end
18
+
19
+ it "defaults to the globally configured app_secret if one's provided" do
20
+ app_secret = "Foo"
21
+
22
+ Koala.configure do |config|
23
+ config.app_secret = app_secret
24
+ end
25
+
26
+ expect(Koala::Facebook::API.new.app_secret).to eq(app_secret)
27
+ end
7
28
 
8
29
  it "doesn't include an access token if none was given" do
9
30
  expect(Koala).to receive(:make_request).with(
@@ -45,36 +66,6 @@ describe "Koala::Facebook::API" do
45
66
  service.api('anything', args)
46
67
  end
47
68
 
48
- it "has an attr_reader for access token" do
49
- token = 'adfadf'
50
- service = Koala::Facebook::API.new token
51
- expect(service.access_token).to eq(token)
52
- end
53
-
54
- it "has an attr_reader for app_secret" do
55
- secret = double
56
- service = Koala::Facebook::API.new(@token, secret)
57
- expect(service.app_secret).to eq(secret)
58
- end
59
-
60
- it "gets the attribute of a Koala::HTTPService::Response given by the http_component parameter" do
61
- http_component = :method_name
62
-
63
- response = double('Mock KoalaResponse', :body => '', :status => 200)
64
- result = double("result")
65
- allow(response).to receive(http_component).and_return(result)
66
- allow(Koala).to receive(:make_request).and_return(response)
67
-
68
- expect(@service.api('anything', {}, 'get', :http_component => http_component)).to eq(result)
69
- end
70
-
71
- it "returns the entire response if http_component => :response" do
72
- http_component = :response
73
- response = double('Mock KoalaResponse', :body => '', :status => 200)
74
- allow(Koala).to receive(:make_request).and_return(response)
75
- expect(@service.api('anything', {}, 'get', :http_component => http_component)).to eq(response)
76
- end
77
-
78
69
  it "turns arrays of non-enumerables into comma-separated arguments by default" do
79
70
  args = [12345, {:foo => [1, 2, "3", :four]}]
80
71
  expected = ["/12345", {:foo => "1,2,3,four"}, "get", {}]
@@ -123,43 +114,12 @@ describe "Koala::Facebook::API" do
123
114
  @service.api(*args)
124
115
  end
125
116
 
126
- it "returns the body of the request as JSON if no http_component is given" do
127
- response = double('response', :body => 'body', :status => 200)
128
- allow(Koala).to receive(:make_request).and_return(response)
129
-
130
- json_body = double('JSON body')
131
- allow(JSON).to receive(:load).and_return([json_body])
132
-
133
- expect(@service.api('anything')).to eq(json_body)
134
- end
135
-
136
- it "executes an error checking block if provided" do
137
- response = Koala::HTTPService::Response.new(200, '{}', {})
138
- allow(Koala).to receive(:make_request).and_return(response)
139
-
140
- yield_test = double('Yield Tester')
141
- expect(yield_test).to receive(:pass)
142
-
143
- @service.api('anything', {}, "get") do |arg|
144
- yield_test.pass
145
- expect(arg).to eq(response)
146
- end
147
- end
148
-
149
117
  it "raises an API error if the HTTP response code is greater than or equal to 500" do
150
118
  allow(Koala).to receive(:make_request).and_return(Koala::HTTPService::Response.new(500, 'response body', {}))
151
119
 
152
120
  expect { @service.api('anything') }.to raise_exception(Koala::Facebook::APIError)
153
121
  end
154
122
 
155
- it "handles rogue true/false as responses" do
156
- expect(Koala).to receive(:make_request).and_return(Koala::HTTPService::Response.new(200, 'true', {}))
157
- expect(@service.api('anything')).to be_truthy
158
-
159
- expect(Koala).to receive(:make_request).and_return(Koala::HTTPService::Response.new(200, 'false', {}))
160
- expect(@service.api('anything')).to be_falsey
161
- end
162
-
163
123
  describe "path manipulation" do
164
124
  context "leading /" do
165
125
  it "adds a leading / to the path if not present" do
@@ -179,11 +139,9 @@ describe "Koala::Facebook::API" do
179
139
  describe "with an access token" do
180
140
  before(:each) do
181
141
  @api = Koala::Facebook::API.new(@token)
142
+ @app_access_token = KoalaTest.app_access_token
182
143
  end
183
144
 
184
- it_should_behave_like "Koala RestAPI"
185
- it_should_behave_like "Koala RestAPI with an access token"
186
-
187
145
  it_should_behave_like "Koala GraphAPI"
188
146
  it_should_behave_like "Koala GraphAPI with an access token"
189
147
  it_should_behave_like "Koala GraphAPI with GraphCollection"
@@ -194,12 +152,10 @@ describe "Koala::Facebook::API" do
194
152
  @api = Koala::Facebook::API.new
195
153
  end
196
154
 
197
- it_should_behave_like "Koala RestAPI"
198
- it_should_behave_like "Koala RestAPI without an access token"
199
-
155
+ # In theory this should behave the same with a GraphCollection, but those tests currently hit
156
+ # an endpoint that now requires a token.
200
157
  it_should_behave_like "Koala GraphAPI"
201
158
  it_should_behave_like "Koala GraphAPI without an access token"
202
- it_should_behave_like "Koala GraphAPI with GraphCollection"
203
159
  end
204
160
 
205
161
  context '#api' do
@@ -252,4 +208,78 @@ describe "Koala::Facebook::API" do
252
208
  end
253
209
  end
254
210
  end
211
+
212
+ describe "#graph_call" do
213
+ it "passes all arguments to the api method" do
214
+ user = KoalaTest.user1
215
+ args = {}
216
+ verb = 'get'
217
+ opts = {:a => :b}
218
+ expect(@service).to receive(:api).with(user, args, verb, opts).and_return(dummy_response)
219
+ @service.graph_call(user, args, verb, opts)
220
+ end
221
+
222
+ it "throws an APIError if the result hash has an error key" do
223
+ allow(Koala).to receive(:make_request).and_return(Koala::HTTPService::Response.new(500, '{"error": "An error occurred!"}', {}))
224
+ expect { @service.graph_call(KoalaTest.user1, {}) }.to raise_exception(Koala::Facebook::APIError)
225
+ end
226
+
227
+ it "passes the results through GraphCollection.evaluate" do
228
+ allow(@service).to receive(:api).and_return(dummy_response)
229
+ expect(Koala::Facebook::API::GraphCollection).to receive(:evaluate).with(dummy_response, @service)
230
+ @service.graph_call("/me")
231
+ end
232
+
233
+ it "returns the results of GraphCollection.evaluate" do
234
+ expected = {}
235
+ allow(@service).to receive(:api).and_return(dummy_response)
236
+ expect(Koala::Facebook::API::GraphCollection).to receive(:evaluate).and_return(expected)
237
+ expect(@service.graph_call("/me")).to eq(expected)
238
+ end
239
+
240
+ it "returns the post_processing block's results if one is supplied" do
241
+ other_result = [:a, 2, :three]
242
+ block = Proc.new {|r| other_result}
243
+ allow(@service).to receive(:api).and_return(dummy_response)
244
+ expect(@service.graph_call("/me", {}, "get", {}, &block)).to eq(other_result)
245
+ end
246
+
247
+ it "gets the status of a Koala::HTTPService::Response if requested" do
248
+ response = Koala::HTTPService::Response.new(200, '', {})
249
+ allow(Koala).to receive(:make_request).and_return(response)
250
+
251
+ expect(@service.graph_call('anything', {}, 'get', http_component: :status)).to eq(200)
252
+ end
253
+
254
+ it "gets the headers of a Koala::HTTPService::Response if requested" do
255
+ headers = {"a" => 2}
256
+ response = Koala::HTTPService::Response.new(200, '', headers)
257
+ allow(Koala).to receive(:make_request).and_return(response)
258
+
259
+ expect(@service.graph_call('anything', {}, 'get', :http_component => :headers)).to eq(headers)
260
+ end
261
+
262
+ it "returns the entire response if http_component => :response" do
263
+ http_component = :response
264
+ response = Koala::HTTPService::Response.new(200, '', {})
265
+ allow(Koala).to receive(:make_request).and_return(response)
266
+ expect(@service.graph_call('anything', {}, 'get', :http_component => http_component)).to eq(response)
267
+ end
268
+
269
+ it "returns the body of the request as JSON if no http_component is given" do
270
+ result = {"a" => 2}
271
+ response = Koala::HTTPService::Response.new(200, result.to_json, {})
272
+ allow(Koala).to receive(:make_request).and_return(response)
273
+
274
+ expect(@service.graph_call('anything')).to eq(result)
275
+ end
276
+
277
+ it "handles rogue true/false as responses" do
278
+ expect(Koala).to receive(:make_request).and_return(Koala::HTTPService::Response.new(200, 'true', {}))
279
+ expect(@service.graph_call('anything')).to be_truthy
280
+
281
+ expect(Koala).to receive(:make_request).and_return(Koala::HTTPService::Response.new(200, 'false', {}))
282
+ expect(@service.graph_call('anything')).to be_falsey
283
+ end
284
+ end
255
285
  end
@@ -0,0 +1,11 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Koala::Configuration do
4
+ let(:config) { Koala::Configuration.new }
5
+
6
+ it "defaults the HTTPService's DEFAULT_SERVERS" do
7
+ Koala::HTTPService::DEFAULT_SERVERS.each_pair do |key, value|
8
+ expect(config.public_send(key)).to eq(value)
9
+ end
10
+ end
11
+ end
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'json' unless Hash.respond_to?(:to_json)
2
3
 
3
4
  describe "Koala::Facebook::GraphAPI in batch mode" do
4
5
 
@@ -58,11 +59,11 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
58
59
  @batch_queue = []
59
60
  allow(Koala::Facebook::API).to receive(:batch_calls).and_return(@batch_queue)
60
61
 
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)
62
+ allow(Koala::HTTPService::UploadableIO).to receive(:new).with(@binary).and_return(@uploadable_io)
63
+ allow(Koala::HTTPService::UploadableIO).to receive(:binary_content?).and_return(false)
64
+ allow(Koala::HTTPService::UploadableIO).to receive(:binary_content?).with(@binary).and_return(true)
65
+ allow(Koala::HTTPService::UploadableIO).to receive(:binary_content?).with(@uploadable_io).and_return(true)
66
+ allow(@uploadable_io).to receive(:is_a?).with(Koala::HTTPService::UploadableIO).and_return(true)
66
67
 
67
68
  @args[:method] = "post" # files are always post
68
69
  end
@@ -243,11 +244,11 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
243
244
  describe "with binary files" do
244
245
  before :each do
245
246
  @binary = double("Binary file")
246
- allow(Koala::UploadableIO).to receive(:binary_content?).and_return(false)
247
- allow(Koala::UploadableIO).to receive(:binary_content?).with(@binary).and_return(true)
247
+ allow(Koala::HTTPService::UploadableIO).to receive(:binary_content?).and_return(false)
248
+ allow(Koala::HTTPService::UploadableIO).to receive(:binary_content?).with(@binary).and_return(true)
248
249
  @uploadable_io = double("UploadableIO")
249
- allow(Koala::UploadableIO).to receive(:new).with(@binary).and_return(@uploadable_io)
250
- allow(@uploadable_io).to receive(:is_a?).with(Koala::UploadableIO).and_return(true)
250
+ allow(Koala::HTTPService::UploadableIO).to receive(:new).with(@binary).and_return(@uploadable_io)
251
+ allow(@uploadable_io).to receive(:is_a?).with(Koala::HTTPService::UploadableIO).and_return(true)
251
252
 
252
253
  @batch_queue = []
253
254
  allow(Koala::Facebook::API).to receive(:batch_calls).and_return(@batch_queue)
@@ -468,17 +469,57 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
468
469
  expect(thread_one_count).to eq(first_count)
469
470
  expect(thread_two_count).to eq(second_count)
470
471
  end
472
+
473
+ end
474
+ end
475
+
476
+ describe '#big_batches' do
477
+ before :each do
478
+ payload = [{code: 200, headers: [{name: "Content-Type", value: "text/javascript; charset=UTF-8"}], body: "{\"id\":\"1234\"}"}]
479
+ allow(Koala).to receive(:make_request) do |_request, args, _verb, _options|
480
+ request_count = JSON.parse(args['batch']).length
481
+ expect(request_count).to be <= 50 # check FB's limit
482
+ Koala::HTTPService::Response.new(200, (payload * request_count).to_json, {})
483
+ end
484
+ end
485
+
486
+ it 'stays within fb limits' do
487
+ count_calls = 0
488
+ expected_calls = 100
489
+ @api.batch do |batch_api|
490
+ expected_calls.times { |_i| batch_api.get_object('me') { |_ret| count_calls += 1 } }
491
+ end
492
+
493
+ expect(count_calls).to eq(expected_calls)
494
+ end
495
+
496
+ it 'is recursive safe' do
497
+ # ensure batch operations whose callbacks call batch operations don't resubmit
498
+ call_count = 0
499
+ iterations = 60
500
+ @api.batch do |batch_api|
501
+ # must do enough calls to provoke a batch submission
502
+ iterations.times { |_i|
503
+ batch_api.get_object('me') { |_ret|
504
+ call_count += 1
505
+ batch_api.get_object('me') { |_ret|
506
+ call_count += 1
507
+ }
508
+ }
509
+ }
510
+ end
511
+ expect(call_count).to eq(2 * iterations)
471
512
  end
472
513
  end
473
514
 
474
515
  describe "usage tests" do
475
516
  it "gets two results at once" do
476
- me, koppel = @api.batch do |batch_api|
517
+ me, barackobama = @api.batch do |batch_api|
477
518
  batch_api.get_object('me')
478
519
  batch_api.get_object(KoalaTest.user1)
479
520
  end
480
521
  expect(me['id']).not_to be_nil
481
- expect(koppel['id']).not_to be_nil
522
+ expect(barackobama['id']).not_to be_nil
482
523
  end
483
524
 
484
525
  it 'makes mixed calls inside of a batch' do
@@ -486,7 +527,7 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
486
527
  batch_api.get_object('me')
487
528
  batch_api.get_connections('me', 'friends')
488
529
  end
489
- expect(friends).to be_a(Koala::Facebook::GraphCollection)
530
+ expect(friends).to be_a(Koala::Facebook::API::GraphCollection)
490
531
  end
491
532
 
492
533
  it 'turns pageable results into GraphCollections' do
@@ -502,7 +543,7 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
502
543
  pictures = @api.batch do |batch_api|
503
544
  batch_api.get_picture('me')
504
545
  end
505
- expect(pictures.first).to match(/http\:\/\//) # works both live & stubbed
546
+ expect(pictures.first).to match(/https\:\/\//) # works both live & stubbed
506
547
  end
507
548
 
508
549
  it 'takes an after processing block for a get_picture call inside of a batch' do
@@ -510,40 +551,40 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
510
551
  @api.batch do |batch_api|
511
552
  batch_api.get_picture('me') { |pic| picture = pic }
512
553
  end
513
- expect(picture).to match(/http\:\/\//) # works both live & stubbed
554
+ expect(picture).to match(/https\:\/\//) # works both live & stubbed
514
555
  end
515
556
 
516
557
  it "handles requests for two different tokens" do
517
- me, insights = @api.batch do |batch_api|
558
+ me, app_event_types = @api.batch do |batch_api|
518
559
  batch_api.get_object('me')
519
- batch_api.get_connections(@app_id, 'insights', {}, {"access_token" => @app_api.access_token})
560
+ batch_api.get_connections(@app_id, 'app_event_types', {}, {"access_token" => @app_api.access_token})
520
561
  end
521
562
  expect(me['id']).not_to be_nil
522
- expect(insights).to be_an(Koala::Facebook::GraphCollection)
563
+ expect(app_event_types).to be_an(Koala::Facebook::API::GraphCollection)
523
564
  end
524
565
 
525
566
  it "handles requests passing the access token option as a symbol instead of a string" do
526
- me, insights = @api.batch do |batch_api|
567
+ me, app_event_types = @api.batch do |batch_api|
527
568
  batch_api.get_object('me')
528
- batch_api.get_connections(@app_id, 'insights', {}, {:access_token => @app_api.access_token})
569
+ batch_api.get_connections(@app_id, 'app_event_types', {}, {:access_token => @app_api.access_token})
529
570
  end
530
571
  expect(me['id']).not_to be_nil
531
- expect(insights).to be_an(Koala::Facebook::GraphCollection)
572
+ expect(app_event_types).to be_an(Koala::Facebook::API::GraphCollection)
532
573
  end
533
574
 
534
575
  it "preserves batch-op specific access tokens in GraphCollection returned from batch" do
535
576
  # Provide an alternate token for a batch operation
536
577
  @other_access_token_args = { 'access_token' => @app_api.access_token }
537
578
 
538
- # make a batch call for insights using another token
539
- me, insights = @api.batch do |batch_api|
579
+ # make a batch call for app_event_types using another token
580
+ me, app_event_types = @api.batch do |batch_api|
540
581
  batch_api.get_object('me')
541
- batch_api.get_connections(@app_id, 'insights', {}, @other_access_token_args)
582
+ batch_api.get_connections(@app_id, 'app_event_types', {}, @other_access_token_args)
542
583
  end
543
584
 
544
585
  # The alternate token is returned with the next page parameters
545
586
  # The GraphCollection should receive a request for the next_page_params during paging
546
- expect(insights).to receive(:next_page_params).and_return([double("base"), @other_access_token_args.dup])
587
+ expect(app_event_types).to receive(:next_page_params).and_return([double("base"), @other_access_token_args.dup])
547
588
 
548
589
  # The alternate access token should pass through to making the request
549
590
  # Koala should receive a request during paging using the alternate token
@@ -555,38 +596,28 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
555
596
  ).and_return(Koala::HTTPService::Response.new(200, "", ""))
556
597
 
557
598
  # Page the collection
558
- insights.next_page
599
+ app_event_types.next_page
559
600
  end
560
601
 
561
602
  it "inserts errors in the appropriate place, without breaking other results" do
562
- failed_call, koppel = @api.batch do |batch_api|
603
+ failed_call, barackobama = @api.batch do |batch_api|
563
604
  batch_api.get_connection("2", "invalidconnection")
564
605
  batch_api.get_object(KoalaTest.user1, {}, {"access_token" => @app_api.access_token})
565
606
  end
566
607
  expect(failed_call).to be_a(Koala::Facebook::ClientError)
567
- expect(koppel["id"]).not_to be_nil
608
+ expect(barackobama["id"]).not_to be_nil
568
609
  end
569
610
 
570
611
  it "handles different request methods" do
571
612
  result = @api.put_wall_post("Hello, world, from the test suite batch API!")
572
613
  wall_post = result["id"]
573
614
 
574
- wall_post, koppel = @api.batch do |batch_api|
615
+ wall_post, barackobama = @api.batch do |batch_api|
575
616
  batch_api.put_like(wall_post)
576
617
  batch_api.delete_object(wall_post)
577
618
  end
578
619
  end
579
620
 
580
- it "allows FQL" do
581
- result = @api.batch do |batch_api|
582
- batch_api.graph_call("method/fql.query", {:query=>"select first_name from user where uid=#{KoalaTest.user1_id}"}, "post")
583
- end
584
-
585
- fql_result = result[0]
586
- expect(fql_result[0]).to be_a(Hash)
587
- expect(fql_result[0]["first_name"]).to eq("Alex")
588
- end
589
-
590
621
  describe 'with post-processing callback' do
591
622
  let(:me_result) { double("me result") }
592
623
  let(:friends_result) { [double("friends result")] }
@@ -668,23 +699,23 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
668
699
  end
669
700
 
670
701
  it "allows you to create dependencies" do
671
- me, koppel = @api.batch do |batch_api|
702
+ me, barackobama = @api.batch do |batch_api|
672
703
  batch_api.get_object("me", {}, :batch_args => {:name => "getme"})
673
704
  batch_api.get_object(KoalaTest.user1, {}, :batch_args => {:depends_on => "getme"})
674
705
  end
675
706
 
676
707
  expect(me).to be_nil # gotcha! it's omitted because it's a successfully-executed dependency
677
- expect(koppel["id"]).not_to be_nil
708
+ expect(barackobama["id"]).not_to be_nil
678
709
  end
679
710
 
680
711
  it "properly handles dependencies that fail" do
681
- failed_call, koppel = @api.batch do |batch_api|
712
+ failed_call, barackobama = @api.batch do |batch_api|
682
713
  batch_api.get_connections("2", "invalidconnection", {}, :batch_args => {:name => "getdata"})
683
714
  batch_api.get_object(KoalaTest.user1, {}, :batch_args => {:depends_on => "getdata"})
684
715
  end
685
716
 
686
717
  expect(failed_call).to be_a(Koala::Facebook::ClientError)
687
- expect(koppel).to be_nil
718
+ expect(barackobama).to be_nil
688
719
  end
689
720
 
690
721
  it "throws an error for badly-constructed request relationships" do
@@ -9,6 +9,8 @@ describe 'Koala::Facebook::GraphAPIMethods' do
9
9
  @app_api = Koala::Facebook::API.new(@app_access_token)
10
10
  end
11
11
 
12
+ let(:dummy_response) { double("fake response", data: {}, status: 200, body: "", headers: {}) }
13
+
12
14
  describe 'post-processing for' do
13
15
  let(:result) { double("result") }
14
16
  let(:post_processing) { lambda {|arg| {"result" => result, "args" => arg} } }
@@ -17,47 +19,31 @@ describe 'Koala::Facebook::GraphAPIMethods' do
17
19
  # and the other methods which do some post-processing locally
18
20
  context '#get_object' do
19
21
  it 'returns result of block' do
20
- allow(@api).to receive(:api).and_return(double("other results"))
21
- expect(@api.get_object('koppel', &post_processing)["result"]).to eq(result)
22
+ allow(@api).to receive(:api).and_return(dummy_response)
23
+ expect(@api.get_object('barackobama', &post_processing)["result"]).to eq(result)
22
24
  end
23
25
 
24
26
  it "doesn't add token to received arguments" do
25
27
  args = {}.freeze
26
- expect(Koala).to receive(:make_request).and_return(Koala::HTTPService::Response.new(200, "", ""))
27
- expect(@api.get_object('koppel', args, &post_processing)["result"]).to eq(result)
28
+ expect(Koala).to receive(:make_request).and_return(dummy_response)
29
+ expect(@api.get_object('barackobama', args, &post_processing)["result"]).to eq(result)
28
30
  end
29
31
  end
30
32
 
31
33
  context '#get_picture' do
32
34
  it 'returns result of block' do
33
- allow(@api).to receive(:api).and_return({"data" => {"is_silhouette" => false, "url" => result}})
34
- expect(@api.get_picture('lukeshepard', &post_processing)["result"]).to eq(result)
35
- end
36
- end
37
-
38
- context '#fql_multiquery' do
39
- before do
40
- expect(@api).to receive(:get_object).and_return([
41
- {"name" => "query1", "fql_result_set" => [{"id" => 123}]},
42
- {"name" => "query2", "fql_result_set" => ["id" => 456]}
43
- ])
44
- end
45
-
46
- it 'is called with resolved response' do
47
- resolved_result = {
48
- 'query1' => [{'id' => 123}],
49
- 'query2' => [{'id' => 456}]
50
- }
51
- response = @api.fql_multiquery({}, &post_processing)
52
- expect(response["args"]).to eq(resolved_result)
53
- expect(response["result"]).to eq(result)
35
+ result_url = "a url"
36
+ allow(@api).to receive(:api).and_return(Koala::HTTPService::Response.new(200, {"data" => {"is_silhouette" => false, "url" => result_url}}.to_json, {}))
37
+ expect(@api.get_picture('koppel', &post_processing)["result"]).to eq(result)
54
38
  end
55
39
  end
56
40
 
57
41
  context '#get_page_access_token' do
58
42
  it 'returns result of block' do
59
43
  token = Koala::MockHTTPService::APP_ACCESS_TOKEN
60
- allow(@api).to receive(:api).and_return("access_token" => token)
44
+ allow(@api).to receive(:api).and_return(
45
+ Koala::HTTPService::Response.new(200, {"access_token" => token}.to_json, {})
46
+ )
61
47
  response = @api.get_page_access_token('facebook', &post_processing)
62
48
  expect(response["args"]).to eq(token)
63
49
  expect(response["result"]).to eq(result)
@@ -71,18 +57,18 @@ describe 'Koala::Facebook::GraphAPIMethods' do
71
57
 
72
58
  it "is enabled by default if an app secret is present" do
73
59
  api = Koala::Facebook::API.new(@token, "mysecret")
74
- expect(api).to receive(:api).with(path, {}, 'get', :appsecret_proof => true)
60
+ expect(api).to receive(:api).with(path, {}, 'get', :appsecret_proof => true).and_return(dummy_response)
75
61
  api.graph_call(path)
76
62
  end
77
63
 
78
64
  it "can be disabled manually" do
79
65
  api = Koala::Facebook::API.new(@token, "mysecret")
80
- expect(api).to receive(:api).with(path, {}, 'get', hash_not_including(appsecret_proof: true))
66
+ expect(api).to receive(:api).with(path, {}, 'get', hash_not_including(appsecret_proof: true)).and_return(dummy_response)
81
67
  api.graph_call(path, {}, "get", appsecret_proof: false)
82
68
  end
83
69
 
84
70
  it "isn't included if no app secret is present" do
85
- expect(@api).to receive(:api).with(path, {}, 'get', {})
71
+ expect(@api).to receive(:api).with(path, {}, 'get', {}).and_return(dummy_response)
86
72
  @api.graph_call(path)
87
73
  end
88
74
  end