koala 1.2.0 → 1.3.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/.gitignore +3 -1
- data/.rspec +1 -0
- data/.travis.yml +4 -0
- data/.yardopts +3 -0
- data/CHANGELOG +43 -0
- data/Gemfile +14 -0
- data/Guardfile +6 -0
- data/koala.gemspec +4 -4
- data/lib/koala/api/batch_operation.rb +83 -0
- data/lib/koala/api/graph_api.rb +476 -0
- data/lib/koala/{graph_batch_api.rb → api/graph_batch_api.rb} +22 -17
- data/lib/koala/api/graph_collection.rb +107 -0
- data/lib/koala/api/legacy.rb +26 -0
- data/lib/koala/{rest_api.rb → api/rest_api.rb} +36 -10
- data/lib/koala/api.rb +93 -0
- data/lib/koala/http_service/multipart_request.rb +41 -0
- data/lib/koala/http_service/response.rb +18 -0
- data/lib/koala/http_service/uploadable_io.rb +187 -0
- data/lib/koala/http_service.rb +73 -23
- data/lib/koala/oauth.rb +173 -36
- data/lib/koala/realtime_updates.rb +89 -51
- data/lib/koala/test_users.rb +122 -32
- data/lib/koala/utils.rb +11 -4
- data/lib/koala/version.rb +1 -1
- data/lib/koala.rb +16 -95
- data/readme.md +30 -13
- data/spec/cases/api_spec.rb +28 -21
- data/spec/cases/error_spec.rb +10 -0
- data/spec/cases/graph_api_batch_spec.rb +100 -58
- data/spec/cases/graph_collection_spec.rb +23 -7
- data/spec/cases/http_service_spec.rb +14 -34
- data/spec/cases/koala_spec.rb +22 -4
- data/spec/cases/legacy_spec.rb +115 -0
- data/spec/cases/multipart_request_spec.rb +66 -0
- data/spec/cases/oauth_spec.rb +232 -108
- data/spec/cases/realtime_updates_spec.rb +154 -47
- data/spec/cases/test_users_spec.rb +276 -217
- data/spec/cases/uploadable_io_spec.rb +1 -1
- data/spec/cases/utils_spec.rb +29 -5
- data/spec/fixtures/mock_facebook_responses.yml +50 -26
- data/spec/spec_helper.rb +3 -0
- data/spec/support/custom_matchers.rb +28 -0
- data/spec/support/graph_api_shared_examples.rb +274 -70
- data/spec/support/koala_test.rb +27 -16
- data/spec/support/mock_http_service.rb +2 -2
- data/spec/support/rest_api_shared_examples.rb +46 -162
- metadata +33 -25
- data/lib/koala/batch_operation.rb +0 -74
- data/lib/koala/graph_api.rb +0 -270
- data/lib/koala/graph_collection.rb +0 -59
- data/lib/koala/uploadable_io.rb +0 -181
- data/spec/cases/graph_and_rest_api_spec.rb +0 -22
- data/spec/cases/graph_api_spec.rb +0 -22
- data/spec/cases/rest_api_spec.rb +0 -41
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
# Support for legacy / deprecated interfaces
|
|
4
|
+
describe "legacy APIs" do
|
|
5
|
+
|
|
6
|
+
it "deprecates the REST API" do
|
|
7
|
+
api = Koala::Facebook::API.new
|
|
8
|
+
api.stub(:api)
|
|
9
|
+
Koala::Utils.should_receive(:deprecate)
|
|
10
|
+
api.rest_call("stuff")
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
describe Koala::Facebook::GraphAPI do
|
|
14
|
+
describe "class consolidation" do
|
|
15
|
+
before :each do
|
|
16
|
+
Koala::Utils.stub(:deprecate) # avoid actual messages to stderr
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "still allows you to instantiate a GraphAndRestAPI object" do
|
|
20
|
+
api = Koala::Facebook::GraphAPI.new("token").should be_a(Koala::Facebook::GraphAPI)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "ultimately creates an API object" do
|
|
24
|
+
api = Koala::Facebook::GraphAPI.new("token").should be_a(Koala::Facebook::API)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "fires a depreciation warning" do
|
|
28
|
+
Koala::Utils.should_receive(:deprecate)
|
|
29
|
+
api = Koala::Facebook::GraphAPI.new("token")
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
describe Koala::Facebook::RestAPI do
|
|
35
|
+
describe "class consolidation" do
|
|
36
|
+
before :each do
|
|
37
|
+
Koala::Utils.stub(:deprecate) # avoid actual messages to stderr
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "still allows you to instantiate a GraphAndRestAPI object" do
|
|
41
|
+
api = Koala::Facebook::RestAPI.new("token").should be_a(Koala::Facebook::RestAPI)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it "ultimately creates an API object" do
|
|
45
|
+
api = Koala::Facebook::RestAPI.new("token").should be_a(Koala::Facebook::API)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it "fires a depreciation warning" do
|
|
49
|
+
Koala::Utils.should_receive(:deprecate)
|
|
50
|
+
api = Koala::Facebook::RestAPI.new("token")
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
describe Koala::Facebook::GraphAndRestAPI do
|
|
56
|
+
describe "class consolidation" do
|
|
57
|
+
before :each do
|
|
58
|
+
Koala::Utils.stub(:deprecate) # avoid actual messages to stderr
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it "still allows you to instantiate a GraphAndRestAPI object" do
|
|
62
|
+
api = Koala::Facebook::GraphAndRestAPI.new("token").should be_a(Koala::Facebook::GraphAndRestAPI)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "ultimately creates an API object" do
|
|
66
|
+
api = Koala::Facebook::GraphAndRestAPI.new("token").should be_a(Koala::Facebook::API)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it "fires a depreciation warning" do
|
|
70
|
+
Koala::Utils.should_receive(:deprecate)
|
|
71
|
+
api = Koala::Facebook::GraphAndRestAPI.new("token")
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
{:typhoeus => Koala::TyphoeusService, :net_http => Koala::NetHTTPService}.each_pair do |adapter, module_class|
|
|
77
|
+
describe module_class.to_s do
|
|
78
|
+
it "responds to deprecated_interface" do
|
|
79
|
+
module_class.should respond_to(:deprecated_interface)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it "issues a deprecation warning" do
|
|
83
|
+
Koala::Utils.should_receive(:deprecate)
|
|
84
|
+
module_class.deprecated_interface
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it "sets the default adapter to #{adapter}" do
|
|
88
|
+
module_class.deprecated_interface
|
|
89
|
+
Faraday.default_adapter.should == adapter
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
describe "moved classes" do
|
|
95
|
+
it "allows you to access Koala::HTTPService::MultipartRequest through the Koala module" do
|
|
96
|
+
Koala::MultipartRequest.should == Koala::HTTPService::MultipartRequest
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it "allows you to access Koala::Response through the Koala module" do
|
|
100
|
+
Koala::Response.should == Koala::HTTPService::Response
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
it "allows you to access Koala::Response through the Koala module" do
|
|
104
|
+
Koala::UploadableIO.should == Koala::HTTPService::UploadableIO
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
it "allows you to access Koala::Facebook::GraphBatchAPI::BatchOperation through the Koala::Facebook module" do
|
|
108
|
+
Koala::Facebook::BatchOperation.should == Koala::Facebook::GraphBatchAPI::BatchOperation
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
it "allows you to access Koala::Facebook::API::GraphCollection through the Koala::Facebook module" do
|
|
112
|
+
Koala::Facebook::GraphCollection.should == Koala::Facebook::API::GraphCollection
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Koala::HTTPService::MultipartRequest do
|
|
4
|
+
it "is a subclass of Faraday::Request::Multipart" do
|
|
5
|
+
Koala::HTTPService::MultipartRequest.superclass.should == Faraday::Request::Multipart
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it "defines mime_type as multipart/form-data" do
|
|
9
|
+
Koala::HTTPService::MultipartRequest.mime_type.should == 'multipart/form-data'
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
describe "#process_request?" do
|
|
13
|
+
before :each do
|
|
14
|
+
@env = {}
|
|
15
|
+
@multipart = Koala::HTTPService::MultipartRequest.new
|
|
16
|
+
@multipart.stub(:request_type).and_return("")
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# no way to test the call to super, unfortunately
|
|
20
|
+
it "returns true if env[:body] is a hash with at least one hash in its values" do
|
|
21
|
+
@env[:body] = {:a => {:c => 2}}
|
|
22
|
+
@multipart.process_request?(@env).should be_true
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "returns true if env[:body] is a hash with at least one array in its values" do
|
|
26
|
+
@env[:body] = {:a => [:c, 2]}
|
|
27
|
+
@multipart.process_request?(@env).should be_true
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "returns true if env[:body] is a hash with mixed objects in its values" do
|
|
31
|
+
@env[:body] = {:a => [:c, 2], :b => {:e => :f}}
|
|
32
|
+
@multipart.process_request?(@env).should be_true
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "returns false if env[:body] is a string" do
|
|
36
|
+
@env[:body] = "my body"
|
|
37
|
+
@multipart.process_request?(@env).should be_false
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "returns false if env[:body] is a hash without an array or hash value" do
|
|
41
|
+
@env[:body] = {:a => 3}
|
|
42
|
+
@multipart.process_request?(@env).should be_false
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
describe "#process_params" do
|
|
47
|
+
before :each do
|
|
48
|
+
@parent = Faraday::Request::Multipart.new
|
|
49
|
+
@multipart = Koala::HTTPService::MultipartRequest.new
|
|
50
|
+
@block = lambda {|k, v| "#{k}=#{v}"}
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it "is identical to the parent for requests without a prefix" do
|
|
54
|
+
hash = {:a => 2, :c => "3"}
|
|
55
|
+
@multipart.process_params(hash, &@block).should == @parent.process_params(hash, &@block)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "replaces encodes [ and ] if the request has a prefix" do
|
|
59
|
+
hash = {:a => 2, :c => "3"}
|
|
60
|
+
prefix = "foo"
|
|
61
|
+
# process_params returns an array
|
|
62
|
+
@multipart.process_params(hash, prefix, &@block).join("&").should == @parent.process_params(hash, prefix, &@block).join("&").gsub(/\[/, "%5B").gsub(/\]/, "%5D")
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
end
|