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.
Files changed (45) hide show
  1. data/.gitignore +3 -1
  2. data/.travis.yml +4 -0
  3. data/.yardopts +3 -0
  4. data/CHANGELOG +7 -0
  5. data/Gemfile +14 -0
  6. data/Guardfile +6 -0
  7. data/lib/koala.rb +16 -97
  8. data/lib/koala/api.rb +93 -0
  9. data/lib/koala/api/batch_operation.rb +83 -0
  10. data/lib/koala/api/graph_api.rb +476 -0
  11. data/lib/koala/{graph_batch_api.rb → api/graph_batch_api.rb} +20 -16
  12. data/lib/koala/api/graph_collection.rb +107 -0
  13. data/lib/koala/api/legacy.rb +26 -0
  14. data/lib/koala/{rest_api.rb → api/rest_api.rb} +33 -3
  15. data/lib/koala/http_service.rb +69 -19
  16. data/lib/koala/http_service/multipart_request.rb +41 -0
  17. data/lib/koala/http_service/response.rb +18 -0
  18. data/lib/koala/http_service/uploadable_io.rb +187 -0
  19. data/lib/koala/oauth.rb +117 -14
  20. data/lib/koala/realtime_updates.rb +89 -51
  21. data/lib/koala/test_users.rb +109 -33
  22. data/lib/koala/utils.rb +4 -0
  23. data/lib/koala/version.rb +1 -1
  24. data/spec/cases/api_spec.rb +19 -12
  25. data/spec/cases/graph_api_batch_spec.rb +41 -41
  26. data/spec/cases/http_service_spec.rb +1 -22
  27. data/spec/cases/legacy_spec.rb +107 -0
  28. data/spec/cases/multipart_request_spec.rb +5 -5
  29. data/spec/cases/oauth_spec.rb +9 -9
  30. data/spec/cases/realtime_updates_spec.rb +154 -47
  31. data/spec/cases/test_users_spec.rb +268 -219
  32. data/spec/fixtures/mock_facebook_responses.yml +10 -6
  33. data/spec/support/graph_api_shared_examples.rb +17 -12
  34. data/spec/support/koala_test.rb +1 -1
  35. data/spec/support/mock_http_service.rb +2 -2
  36. data/spec/support/rest_api_shared_examples.rb +1 -1
  37. metadata +82 -104
  38. data/lib/koala/batch_operation.rb +0 -74
  39. data/lib/koala/graph_api.rb +0 -289
  40. data/lib/koala/graph_collection.rb +0 -63
  41. data/lib/koala/multipart_request.rb +0 -35
  42. data/lib/koala/uploadable_io.rb +0 -181
  43. data/spec/cases/graph_and_rest_api_spec.rb +0 -22
  44. data/spec/cases/graph_api_spec.rb +0 -22
  45. data/spec/cases/rest_api_spec.rb +0 -22
@@ -10,7 +10,7 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
10
10
  @app_api = Koala::Facebook::API.new(@app_access_token)
11
11
  end
12
12
 
13
- describe "BatchOperations" do
13
+ describe Koala::Facebook::GraphBatchAPI::BatchOperation do
14
14
  before :each do
15
15
  @args = {
16
16
  :url => "my url",
@@ -24,30 +24,30 @@ 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::BatchOperation.new(@args).http_options.should == @args[:http_options]
27
+ Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).http_options.should == @args[:http_options]
28
28
  end
29
29
 
30
30
  it "makes post_processing accessible" do
31
- Koala::Facebook::BatchOperation.new(@args).post_processing.should == @args[:post_processing]
31
+ Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).post_processing.should == @args[:post_processing]
32
32
  end
33
33
 
34
34
  it "makes access_token accessible" do
35
- Koala::Facebook::BatchOperation.new(@args).access_token.should == @args[:access_token]
35
+ Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).access_token.should == @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
- Koala::Facebook::BatchOperation.new(@args).to_batch_params(nil)
41
+ Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).to_batch_params(nil)
42
42
  @args[:http_options].should == expected
43
43
  end
44
44
 
45
45
  it "leaves the file array nil by default" do
46
- Koala::Facebook::BatchOperation.new(@args).files.should be_nil
46
+ Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).files.should be_nil
47
47
  end
48
48
 
49
49
  it "raises a KoalaError if no access token supplied" do
50
- expect { Koala::Facebook::BatchOperation.new(@args.merge(:access_token => nil)) }.to raise_exception(Koala::KoalaError)
50
+ expect { Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args.merge(:access_token => nil)) }.to raise_exception(Koala::KoalaError)
51
51
  end
52
52
 
53
53
  describe "when supplied binary files" do
@@ -69,7 +69,7 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
69
69
 
70
70
  it "adds binary files to the files attribute as UploadableIOs" do
71
71
  @args[:args].merge!("source" => @binary)
72
- batch_op = Koala::Facebook::BatchOperation.new(@args)
72
+ batch_op = Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args)
73
73
  batch_op.files.should_not be_nil
74
74
  batch_op.files.find {|k, v| v == @uploadable_io}.should_not be_nil
75
75
  end
@@ -77,24 +77,24 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
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
- batch_op = Koala::Facebook::BatchOperation.new(@args)
80
+ batch_op = Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args)
81
81
  batch_op.files.should_not be_nil
82
82
  batch_op.files.find {|k, v| v == @uploadable_io}.should_not 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
- batch_op = Koala::Facebook::BatchOperation.new(@args)
87
+ batch_op = Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args)
88
88
  # if the name wasn't unique, there'd just be one item
89
89
  batch_op.files.should have(2).items
90
90
  end
91
91
 
92
92
  it "assigns each binary parameter unique name across batch requests" do
93
93
  @args[:args].merge!("source" => @binary, "source2" => @binary)
94
- batch_op = Koala::Facebook::BatchOperation.new(@args)
94
+ batch_op = Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args)
95
95
  # simulate the batch operation, since it's used in determination
96
96
  @batch_queue << batch_op
97
- batch_op2 = Koala::Facebook::BatchOperation.new(@args)
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
100
  batch_op.files.merge(batch_op2.files).should have(4).items
@@ -102,7 +102,7 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
102
102
 
103
103
  it "removes the value from the arguments" do
104
104
  @args[:args].merge!("source" => @binary)
105
- Koala::Facebook::BatchOperation.new(@args).to_batch_params(nil)[:body].should_not =~ /source=/
105
+ Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).to_batch_params(nil)[:body].should_not =~ /source=/
106
106
  end
107
107
  end
108
108
 
@@ -116,7 +116,7 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
116
116
  @args[:url] = url = "/"
117
117
  Koala.http_service.stub(:encode_params).and_return(test_args)
118
118
 
119
- Koala::Facebook::BatchOperation.new(@args).to_batch_params(nil)[:relative_url].should == "#{url}?#{test_args}"
119
+ Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).to_batch_params(nil)[:relative_url].should == "#{url}?#{test_args}"
120
120
  end
121
121
 
122
122
  it "adds the args to the URL string, with & if args previously present" do
@@ -124,16 +124,16 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
124
124
  @args[:url] = url = "/?a=2"
125
125
  Koala.http_service.stub(:encode_params).and_return(test_args)
126
126
 
127
- Koala::Facebook::BatchOperation.new(@args).to_batch_params(nil)[:relative_url].should == "#{url}&#{test_args}"
127
+ Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).to_batch_params(nil)[:relative_url].should == "#{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::BatchOperation.new(@args).to_batch_params(@args[:access_token])[:relative_url].should == @args[:url]
132
+ Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).to_batch_params(@args[:access_token])[:relative_url].should == @args[:url]
133
133
  end
134
134
 
135
135
  it "adds nothing to the body" do
136
- Koala::Facebook::BatchOperation.new(@args).to_batch_params(nil)[:body].should be_nil
136
+ Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).to_batch_params(nil)[:body].should be_nil
137
137
  end
138
138
  end
139
139
 
@@ -142,13 +142,13 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
142
142
  test_args = "foo"
143
143
  Koala.http_service.stub(:encode_params).and_return(test_args)
144
144
 
145
- Koala::Facebook::BatchOperation.new(@args).to_batch_params(nil)[:body].should == test_args
145
+ Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).to_batch_params(nil)[:body].should == 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
150
  Koala.http_service.stub(:encode_params).and_return(test_args)
151
- Koala::Facebook::BatchOperation.new(@args).to_batch_params(nil)[:body].should be_nil
151
+ Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).to_batch_params(nil)[:body].should be_nil
152
152
  end
153
153
 
154
154
 
@@ -156,7 +156,7 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
156
156
  test_args = "foo"
157
157
  Koala.http_service.stub(:encode_params).and_return(test_args)
158
158
 
159
- Koala::Facebook::BatchOperation.new(@args).to_batch_params(nil)[:relative_url].should == @args[:url]
159
+ Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).to_batch_params(nil)[:relative_url].should == @args[:url]
160
160
  end
161
161
  end
162
162
 
@@ -194,45 +194,45 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
194
194
  end
195
195
 
196
196
  it "includes the access token if the token is not the main one for the request" do
197
- params = Koala::Facebook::BatchOperation.new(@args).to_batch_params(nil)
197
+ params = Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).to_batch_params(nil)
198
198
  params[:relative_url].should =~ /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
- params = Koala::Facebook::BatchOperation.new(@args).to_batch_params(nil)
203
+ params = Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).to_batch_params(nil)
204
204
  params[:relative_url].should =~ /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
- params = Koala::Facebook::BatchOperation.new(@args).to_batch_params(@args[:access_token])
208
+ params = Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).to_batch_params(@args[:access_token])
209
209
  params[:relative_url].should_not =~ /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
- params = Koala::Facebook::BatchOperation.new(@args).to_batch_params(@args[:access_token])
214
+ params = Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).to_batch_params(@args[:access_token])
215
215
  params[:relative_url].should =~ /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
- params = Koala::Facebook::BatchOperation.new(@args).to_batch_params(nil)
221
+ params = Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).to_batch_params(nil)
222
222
  params.should include(batch_args)
223
223
  end
224
224
 
225
225
  it "includes the method" do
226
- params = Koala::Facebook::BatchOperation.new(@args).to_batch_params(@args[:access_token])
226
+ params = Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args).to_batch_params(@args[:access_token])
227
227
  params[:method].should == @args[:method].to_s
228
228
  end
229
229
 
230
230
  it "works with nil http_options" do
231
- expect { Koala::Facebook::BatchOperation.new(@args.merge(:http_options => nil)).to_batch_params(nil) }.not_to raise_exception
231
+ expect { Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args.merge(:http_options => nil)).to_batch_params(nil) }.not_to raise_exception
232
232
  end
233
233
 
234
234
  it "works with nil args" do
235
- expect { Koala::Facebook::BatchOperation.new(@args.merge(:args => nil)).to_batch_params(nil) }.not_to raise_exception
235
+ expect { Koala::Facebook::GraphBatchAPI::BatchOperation.new(@args.merge(:args => nil)).to_batch_params(nil) }.not_to raise_exception
236
236
  end
237
237
 
238
238
  describe "with binary files" do
@@ -252,7 +252,7 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
252
252
 
253
253
  it "adds file identifiers as attached_files in a comma-separated list" do
254
254
  @args[:args].merge!("source" => @binary, "source2" => @binary)
255
- batch_op = Koala::Facebook::BatchOperation.new(@args)
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
258
  params[:attached_files].should == file_ids.join(",")
@@ -264,7 +264,7 @@ 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.stub(:make_request).and_return(Koala::Response.new(200, "[]", {}))
267
+ Koala.stub(:make_request).and_return(Koala::HTTPService::Response.new(200, "[]", {}))
268
268
  @api.batch do |batch_api|
269
269
  batch_api.get_object('me').should be_nil
270
270
  end
@@ -272,7 +272,7 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
272
272
 
273
273
  describe "#batch" do
274
274
  before :each do
275
- @fake_response = Koala::Response.new(200, "[]", {})
275
+ @fake_response = Koala::HTTPService::Response.new(200, "[]", {})
276
276
  Koala.stub(:make_request).and_return(@fake_response)
277
277
  end
278
278
 
@@ -299,9 +299,9 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
299
299
 
300
300
  it "sets args['batch'] to a json'd map of all the batch params" do
301
301
  access_token = "bar"
302
- op = Koala::Facebook::BatchOperation.new(:access_token => access_token, :method => :get, :url => "/")
302
+ op = Koala::Facebook::GraphBatchAPI::BatchOperation.new(:access_token => access_token, :method => :get, :url => "/")
303
303
  op.stub(:to_batch_params).and_return({:a => 2})
304
- Koala::Facebook::BatchOperation.stub(:new).and_return(op)
304
+ Koala::Facebook::GraphBatchAPI::BatchOperation.stub(:new).and_return(op)
305
305
 
306
306
  # two requests should generate two batch operations
307
307
  expected = MultiJson.encode([op.to_batch_params(access_token), op.to_batch_params(access_token)])
@@ -319,7 +319,7 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
319
319
  @key = "file0_0"
320
320
  @uploadable_io = stub("UploadableIO")
321
321
  batch_op = stub("Koala Batch Operation", :files => {@key => @uploadable_io}, :to_batch_params => {}, :access_token => "foo")
322
- Koala::Facebook::BatchOperation.stub(:new).and_return(batch_op)
322
+ Koala::Facebook::GraphBatchAPI::BatchOperation.stub(:new).and_return(batch_op)
323
323
 
324
324
  Koala.should_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|
@@ -366,7 +366,7 @@ 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.stub(:make_request).and_return(Koala::Response.new(200, '[{"code":203,"headers":[{"name":"Content-Type","value":"text/javascript; charset=UTF-8"}],"body":"{\"id\":\"1234\"}"}]', {}))
369
+ Koala.stub(: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
@@ -375,7 +375,7 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
375
375
 
376
376
  describe "if it errors" do
377
377
  it "raises an APIError if the response is not 200" do
378
- Koala.stub(:make_request).and_return(Koala::Response.new(500, "[]", {}))
378
+ Koala.stub(: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)
@@ -383,7 +383,7 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
383
383
 
384
384
  context "with the old style" do
385
385
  before :each do
386
- Koala.stub(:make_request).and_return(Koala::Response.new(200, '{"error":190,"error_description":"Error validating access token."}', {}))
386
+ Koala.stub(:make_request).and_return(Koala::HTTPService::Response.new(200, '{"error":190,"error_description":"Error validating access token."}', {}))
387
387
  end
388
388
 
389
389
  it "throws an error if the response is an old Batch API-style error" do
@@ -411,7 +411,7 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
411
411
 
412
412
  context "with the new style" do
413
413
  before :each do
414
- Koala.stub(:make_request).and_return(Koala::Response.new(200, '{"error":{"message":"Request 0 cannot depend on an unresolved request with name f. Requests can only depend on preceding requests","type":"GraphBatchException"}}', {}))
414
+ Koala.stub(:make_request).and_return(Koala::HTTPService::Response.new(200, '{"error":{"message":"Request 0 cannot depend on an unresolved request with name f. Requests can only depend on preceding requests","type":"GraphBatchException"}}', {}))
415
415
  end
416
416
 
417
417
  it "throws an error if the response is a new Graph API-style error" do
@@ -431,7 +431,7 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
431
431
  end
432
432
 
433
433
  it "returns the result status if http_component is status" do
434
- 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\"}"}]', {}))
434
+ Koala.stub(:make_request).and_return(Koala::HTTPService::Response.new(200, '[{"code":203,"headers":[{"name":"Content-Type","value":"text/javascript; charset=UTF-8"}],"body":"{\"id\":\"1234\"}"}]', {}))
435
435
  result = @api.batch do |batch_api|
436
436
  batch_api.get_object(KoalaTest.user1, {}, :http_component => :status)
437
437
  end
@@ -547,7 +547,7 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
547
547
  it "posts binary files" do
548
548
  file = File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "beach.jpg"))
549
549
 
550
- Koala::Facebook::BatchOperation.instance_variable_set(:@identifier, 0)
550
+ Koala::Facebook::GraphBatchAPI::BatchOperation.instance_variable_set(:@identifier, 0)
551
551
  result = @api.batch do |batch_api|
552
552
  batch_api.put_picture(file)
553
553
  end
@@ -560,7 +560,7 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
560
560
  file = File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "beach.jpg"))
561
561
  file2 = File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "beach.jpg"))
562
562
 
563
- Koala::Facebook::BatchOperation.instance_variable_set(:@identifier, 0)
563
+ Koala::Facebook::GraphBatchAPI::BatchOperation.instance_variable_set(:@identifier, 0)
564
564
  results = @api.batch do |batch_api|
565
565
  batch_api.put_picture(file)
566
566
  batch_api.put_picture(file2, {}, KoalaTest.user1)
@@ -28,7 +28,7 @@ describe "Koala::HTTPService" do
28
28
  end
29
29
 
30
30
  it "adds multipart" do
31
- @builder.should_receive(:use).with(Koala::MultipartRequest)
31
+ @builder.should_receive(:use).with(Koala::HTTPService::MultipartRequest)
32
32
  Koala::HTTPService::DEFAULT_MIDDLEWARE.call(@builder)
33
33
  end
34
34
 
@@ -422,26 +422,5 @@ describe "Koala::HTTPService" do
422
422
  end
423
423
  end
424
424
  end
425
-
426
- {
427
- :typhoeus => Koala::TyphoeusService,
428
- :net_http => Koala::NetHTTPService
429
- }.each_pair do |adapter, module_class|
430
- describe module_class.to_s do
431
- it "responds to deprecated_interface" do
432
- module_class.should respond_to(:deprecated_interface)
433
- end
434
-
435
- it "issues a deprecation warning" do
436
- Koala::Utils.should_receive(:deprecate)
437
- module_class.deprecated_interface
438
- end
439
-
440
- it "sets the default adapter to #{adapter}" do
441
- module_class.deprecated_interface
442
- Faraday.default_adapter.should == adapter
443
- end
444
- end
445
- end
446
425
  end
447
426
  end
@@ -0,0 +1,107 @@
1
+ require 'spec_helper'
2
+
3
+ # Support for legacy / deprecated interfaces
4
+ describe "legacy APIs" do
5
+ describe Koala::Facebook::GraphAPI do
6
+ describe "class consolidation" do
7
+ before :each do
8
+ Koala::Utils.stub(:deprecate) # avoid actual messages to stderr
9
+ end
10
+
11
+ it "still allows you to instantiate a GraphAndRestAPI object" do
12
+ api = Koala::Facebook::GraphAPI.new("token").should be_a(Koala::Facebook::GraphAPI)
13
+ end
14
+
15
+ it "ultimately creates an API object" do
16
+ api = Koala::Facebook::GraphAPI.new("token").should be_a(Koala::Facebook::API)
17
+ end
18
+
19
+ it "fires a depreciation warning" do
20
+ Koala::Utils.should_receive(:deprecate)
21
+ api = Koala::Facebook::GraphAPI.new("token")
22
+ end
23
+ end
24
+ end
25
+
26
+ describe Koala::Facebook::RestAPI do
27
+ describe "class consolidation" do
28
+ before :each do
29
+ Koala::Utils.stub(:deprecate) # avoid actual messages to stderr
30
+ end
31
+
32
+ it "still allows you to instantiate a GraphAndRestAPI object" do
33
+ api = Koala::Facebook::RestAPI.new("token").should be_a(Koala::Facebook::RestAPI)
34
+ end
35
+
36
+ it "ultimately creates an API object" do
37
+ api = Koala::Facebook::RestAPI.new("token").should be_a(Koala::Facebook::API)
38
+ end
39
+
40
+ it "fires a depreciation warning" do
41
+ Koala::Utils.should_receive(:deprecate)
42
+ api = Koala::Facebook::RestAPI.new("token")
43
+ end
44
+ end
45
+ end
46
+
47
+ describe Koala::Facebook::GraphAndRestAPI do
48
+ describe "class consolidation" do
49
+ before :each do
50
+ Koala::Utils.stub(:deprecate) # avoid actual messages to stderr
51
+ end
52
+
53
+ it "still allows you to instantiate a GraphAndRestAPI object" do
54
+ api = Koala::Facebook::GraphAndRestAPI.new("token").should be_a(Koala::Facebook::GraphAndRestAPI)
55
+ end
56
+
57
+ it "ultimately creates an API object" do
58
+ api = Koala::Facebook::GraphAndRestAPI.new("token").should be_a(Koala::Facebook::API)
59
+ end
60
+
61
+ it "fires a depreciation warning" do
62
+ Koala::Utils.should_receive(:deprecate)
63
+ api = Koala::Facebook::GraphAndRestAPI.new("token")
64
+ end
65
+ end
66
+ end
67
+
68
+ {:typhoeus => Koala::TyphoeusService, :net_http => Koala::NetHTTPService}.each_pair do |adapter, module_class|
69
+ describe module_class.to_s do
70
+ it "responds to deprecated_interface" do
71
+ module_class.should respond_to(:deprecated_interface)
72
+ end
73
+
74
+ it "issues a deprecation warning" do
75
+ Koala::Utils.should_receive(:deprecate)
76
+ module_class.deprecated_interface
77
+ end
78
+
79
+ it "sets the default adapter to #{adapter}" do
80
+ module_class.deprecated_interface
81
+ Faraday.default_adapter.should == adapter
82
+ end
83
+ end
84
+ end
85
+
86
+ describe "moved classes" do
87
+ it "allows you to access Koala::HTTPService::MultipartRequest through the Koala module" do
88
+ Koala::MultipartRequest.should == Koala::HTTPService::MultipartRequest
89
+ end
90
+
91
+ it "allows you to access Koala::Response through the Koala module" do
92
+ Koala::Response.should == Koala::HTTPService::Response
93
+ end
94
+
95
+ it "allows you to access Koala::Response through the Koala module" do
96
+ Koala::UploadableIO.should == Koala::HTTPService::UploadableIO
97
+ end
98
+
99
+ it "allows you to access Koala::Facebook::GraphBatchAPI::BatchOperation through the Koala::Facebook module" do
100
+ Koala::Facebook::BatchOperation.should == Koala::Facebook::GraphBatchAPI::BatchOperation
101
+ end
102
+
103
+ it "allows you to access Koala::Facebook::API::GraphCollection through the Koala::Facebook module" do
104
+ Koala::Facebook::GraphCollection.should == Koala::Facebook::API::GraphCollection
105
+ end
106
+ end
107
+ end
@@ -1,18 +1,18 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Koala::MultipartRequest do
3
+ describe Koala::HTTPService::MultipartRequest do
4
4
  it "is a subclass of Faraday::Request::Multipart" do
5
- Koala::MultipartRequest.superclass.should == Faraday::Request::Multipart
5
+ Koala::HTTPService::MultipartRequest.superclass.should == Faraday::Request::Multipart
6
6
  end
7
7
 
8
8
  it "defines mime_type as multipart/form-data" do
9
- Koala::MultipartRequest.mime_type.should == 'multipart/form-data'
9
+ Koala::HTTPService::MultipartRequest.mime_type.should == 'multipart/form-data'
10
10
  end
11
11
 
12
12
  describe "#process_request?" do
13
13
  before :each do
14
14
  @env = {}
15
- @multipart = Koala::MultipartRequest.new
15
+ @multipart = Koala::HTTPService::MultipartRequest.new
16
16
  @multipart.stub(:request_type).and_return("")
17
17
  end
18
18
 
@@ -46,7 +46,7 @@ describe Koala::MultipartRequest do
46
46
  describe "#process_params" do
47
47
  before :each do
48
48
  @parent = Faraday::Request::Multipart.new
49
- @multipart = Koala::MultipartRequest.new
49
+ @multipart = Koala::HTTPService::MultipartRequest.new
50
50
  @block = lambda {|k, v| "#{k}=#{v}"}
51
51
  end
52
52