koala 1.2.1 → 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 +28 -0
- data/Gemfile +14 -0
- data/Guardfile +6 -0
- data/koala.gemspec +3 -3
- 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} +34 -13
- 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 +69 -20
- data/lib/koala/oauth.rb +170 -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 -96
- data/readme.md +9 -9
- data/spec/cases/api_spec.rb +19 -12
- 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 +5 -26
- data/spec/cases/koala_spec.rb +22 -4
- data/spec/cases/legacy_spec.rb +115 -0
- data/spec/cases/multipart_request_spec.rb +7 -7
- data/spec/cases/oauth_spec.rb +134 -48
- data/spec/cases/realtime_updates_spec.rb +154 -47
- data/spec/cases/test_users_spec.rb +276 -219
- data/spec/cases/uploadable_io_spec.rb +1 -1
- data/spec/cases/utils_spec.rb +29 -5
- data/spec/fixtures/mock_facebook_responses.yml +41 -30
- data/spec/spec_helper.rb +3 -0
- data/spec/support/custom_matchers.rb +28 -0
- data/spec/support/graph_api_shared_examples.rb +192 -14
- data/spec/support/koala_test.rb +10 -1
- data/spec/support/mock_http_service.rb +2 -2
- data/spec/support/rest_api_shared_examples.rb +5 -165
- metadata +75 -99
- 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/multipart_request.rb +0 -35
- 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 -22
data/spec/cases/api_spec.rb
CHANGED
|
@@ -11,7 +11,7 @@ describe "Koala::Facebook::API" do
|
|
|
11
11
|
hash_not_including('access_token' => 1),
|
|
12
12
|
anything,
|
|
13
13
|
anything
|
|
14
|
-
).and_return(Koala::Response.new(200, "", ""))
|
|
14
|
+
).and_return(Koala::HTTPService::Response.new(200, "", ""))
|
|
15
15
|
|
|
16
16
|
@service.api('anything')
|
|
17
17
|
end
|
|
@@ -25,7 +25,7 @@ describe "Koala::Facebook::API" do
|
|
|
25
25
|
hash_including('access_token' => token),
|
|
26
26
|
anything,
|
|
27
27
|
anything
|
|
28
|
-
).and_return(Koala::Response.new(200, "", ""))
|
|
28
|
+
).and_return(Koala::HTTPService::Response.new(200, "", ""))
|
|
29
29
|
|
|
30
30
|
service.api('anything')
|
|
31
31
|
end
|
|
@@ -36,15 +36,22 @@ describe "Koala::Facebook::API" do
|
|
|
36
36
|
service.access_token.should == token
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
-
it "gets the attribute of a Koala::Response given by the http_component parameter" do
|
|
39
|
+
it "gets the attribute of a Koala::HTTPService::Response given by the http_component parameter" do
|
|
40
40
|
http_component = :method_name
|
|
41
41
|
|
|
42
42
|
response = mock('Mock KoalaResponse', :body => '', :status => 200)
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
result = stub("result")
|
|
44
|
+
response.stub(http_component).and_return(result)
|
|
45
45
|
Koala.stub(:make_request).and_return(response)
|
|
46
46
|
|
|
47
|
-
@service.api('anything', {}, 'get', :http_component => http_component)
|
|
47
|
+
@service.api('anything', {}, 'get', :http_component => http_component).should == result
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "returns the entire response if http_component => :response" do
|
|
51
|
+
http_component = :response
|
|
52
|
+
response = mock('Mock KoalaResponse', :body => '', :status => 200)
|
|
53
|
+
Koala.stub(:make_request).and_return(response)
|
|
54
|
+
@service.api('anything', {}, 'get', :http_component => http_component).should == response
|
|
48
55
|
end
|
|
49
56
|
|
|
50
57
|
it "returns the body of the request as JSON if no http_component is given" do
|
|
@@ -59,7 +66,7 @@ describe "Koala::Facebook::API" do
|
|
|
59
66
|
|
|
60
67
|
it "executes an error checking block if provided" do
|
|
61
68
|
body = '{}'
|
|
62
|
-
Koala.stub(:make_request).and_return(Koala::Response.new(200, body, {}))
|
|
69
|
+
Koala.stub(:make_request).and_return(Koala::HTTPService::Response.new(200, body, {}))
|
|
63
70
|
|
|
64
71
|
yield_test = mock('Yield Tester')
|
|
65
72
|
yield_test.should_receive(:pass)
|
|
@@ -71,29 +78,29 @@ describe "Koala::Facebook::API" do
|
|
|
71
78
|
end
|
|
72
79
|
|
|
73
80
|
it "raises an API error if the HTTP response code is greater than or equal to 500" do
|
|
74
|
-
Koala.stub(:make_request).and_return(Koala::Response.new(500, 'response body', {}))
|
|
81
|
+
Koala.stub(:make_request).and_return(Koala::HTTPService::Response.new(500, 'response body', {}))
|
|
75
82
|
|
|
76
83
|
lambda { @service.api('anything') }.should raise_exception(Koala::Facebook::APIError)
|
|
77
84
|
end
|
|
78
85
|
|
|
79
86
|
it "handles rogue true/false as responses" do
|
|
80
|
-
Koala.should_receive(:make_request).and_return(Koala::Response.new(200, 'true', {}))
|
|
87
|
+
Koala.should_receive(:make_request).and_return(Koala::HTTPService::Response.new(200, 'true', {}))
|
|
81
88
|
@service.api('anything').should be_true
|
|
82
89
|
|
|
83
|
-
Koala.should_receive(:make_request).and_return(Koala::Response.new(200, 'false', {}))
|
|
90
|
+
Koala.should_receive(:make_request).and_return(Koala::HTTPService::Response.new(200, 'false', {}))
|
|
84
91
|
@service.api('anything').should be_false
|
|
85
92
|
end
|
|
86
93
|
|
|
87
94
|
describe "with regard to leading slashes" do
|
|
88
95
|
it "adds a leading / to the path if not present" do
|
|
89
96
|
path = "anything"
|
|
90
|
-
Koala.should_receive(:make_request).with("/#{path}", anything, anything, anything).and_return(Koala::Response.new(200, 'true', {}))
|
|
97
|
+
Koala.should_receive(:make_request).with("/#{path}", anything, anything, anything).and_return(Koala::HTTPService::Response.new(200, 'true', {}))
|
|
91
98
|
@service.api(path)
|
|
92
99
|
end
|
|
93
100
|
|
|
94
101
|
it "doesn't change the path if a leading / is present" do
|
|
95
102
|
path = "/anything"
|
|
96
|
-
Koala.should_receive(:make_request).with(path, anything, anything, anything).and_return(Koala::Response.new(200, 'true', {}))
|
|
103
|
+
Koala.should_receive(:make_request).with(path, anything, anything, anything).and_return(Koala::HTTPService::Response.new(200, 'true', {}))
|
|
97
104
|
@service.api(path)
|
|
98
105
|
end
|
|
99
106
|
end
|
data/spec/cases/error_spec.rb
CHANGED
|
@@ -10,6 +10,16 @@ describe Koala::Facebook::APIError do
|
|
|
10
10
|
Koala::Facebook::APIError.instance_methods.map(&:to_sym).should include(:fb_error_type=)
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
+
it "has an accessor for raw_response" do
|
|
14
|
+
Koala::Facebook::APIError.instance_methods.map(&:to_sym).should include(:raw_response)
|
|
15
|
+
Koala::Facebook::APIError.instance_methods.map(&:to_sym).should include(:raw_response=)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "sets raw_response to the provided error details" do
|
|
19
|
+
error_response = {"type" => "foo", "other_details" => "bar"}
|
|
20
|
+
Koala::Facebook::APIError.new(error_response).raw_response.should == error_response
|
|
21
|
+
end
|
|
22
|
+
|
|
13
23
|
it "sets fb_error_type to details['type']" do
|
|
14
24
|
type = "foo"
|
|
15
25
|
Koala::Facebook::APIError.new("type" => type).fb_error_type.should == type
|
|
@@ -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
|
|
13
|
+
describe Koala::Facebook::GraphBatchAPI::BatchOperation do
|
|
14
14
|
before :each do
|
|
15
15
|
@args = {
|
|
16
16
|
:url => "my url",
|
|
@@ -22,32 +22,32 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
|
22
22
|
}
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
describe "
|
|
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,13 +102,13 @@ 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
|
|
|
109
109
|
end
|
|
110
110
|
|
|
111
|
-
describe "
|
|
111
|
+
describe "#to_batch_params" do
|
|
112
112
|
describe "handling arguments and URLs" do
|
|
113
113
|
shared_examples_for "request with no body" do
|
|
114
114
|
it "adds the args to the URL string, with ? if no args previously present" do
|
|
@@ -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(",")
|
|
@@ -263,9 +263,8 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
|
263
263
|
end
|
|
264
264
|
|
|
265
265
|
describe "GraphAPI batch interface" do
|
|
266
|
-
|
|
267
266
|
it "returns nothing for a batch operation" do
|
|
268
|
-
Koala.stub(:make_request).and_return(Koala::Response.new(200, "[]", {}))
|
|
267
|
+
Koala.stub(:make_request).and_return(Koala::HTTPService::Response.new(200, "[]", {}))
|
|
269
268
|
@api.batch do |batch_api|
|
|
270
269
|
batch_api.get_object('me').should be_nil
|
|
271
270
|
end
|
|
@@ -273,7 +272,7 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
|
273
272
|
|
|
274
273
|
describe "#batch" do
|
|
275
274
|
before :each do
|
|
276
|
-
@fake_response = Koala::Response.new(200, "[]", {})
|
|
275
|
+
@fake_response = Koala::HTTPService::Response.new(200, "[]", {})
|
|
277
276
|
Koala.stub(:make_request).and_return(@fake_response)
|
|
278
277
|
end
|
|
279
278
|
|
|
@@ -300,9 +299,9 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
|
300
299
|
|
|
301
300
|
it "sets args['batch'] to a json'd map of all the batch params" do
|
|
302
301
|
access_token = "bar"
|
|
303
|
-
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 => "/")
|
|
304
303
|
op.stub(:to_batch_params).and_return({:a => 2})
|
|
305
|
-
Koala::Facebook::BatchOperation.stub(:new).and_return(op)
|
|
304
|
+
Koala::Facebook::GraphBatchAPI::BatchOperation.stub(:new).and_return(op)
|
|
306
305
|
|
|
307
306
|
# two requests should generate two batch operations
|
|
308
307
|
expected = MultiJson.encode([op.to_batch_params(access_token), op.to_batch_params(access_token)])
|
|
@@ -320,7 +319,7 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
|
320
319
|
@key = "file0_0"
|
|
321
320
|
@uploadable_io = stub("UploadableIO")
|
|
322
321
|
batch_op = stub("Koala Batch Operation", :files => {@key => @uploadable_io}, :to_batch_params => {}, :access_token => "foo")
|
|
323
|
-
Koala::Facebook::BatchOperation.stub(:new).and_return(batch_op)
|
|
322
|
+
Koala::Facebook::GraphBatchAPI::BatchOperation.stub(:new).and_return(batch_op)
|
|
324
323
|
|
|
325
324
|
Koala.should_receive(:make_request).with(anything, hash_including(@key => @uploadable_io), anything, anything).and_return(@fake_response)
|
|
326
325
|
Koala::Facebook::API.new("bar").batch do |batch_api|
|
|
@@ -366,35 +365,78 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
|
366
365
|
end
|
|
367
366
|
|
|
368
367
|
describe "processing the request" do
|
|
369
|
-
it "
|
|
370
|
-
Koala.stub(:make_request).and_return(Koala::Response.new(
|
|
371
|
-
|
|
372
|
-
batch_api.get_object(
|
|
373
|
-
end
|
|
368
|
+
it "returns the result headers as a hash if http_component is headers" do
|
|
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
|
+
result = @api.batch do |batch_api|
|
|
371
|
+
batch_api.get_object(KoalaTest.user1, {}, :http_component => :headers)
|
|
372
|
+
end
|
|
373
|
+
result[0].should == {"Content-Type" => "text/javascript; charset=UTF-8"}
|
|
374
374
|
end
|
|
375
|
+
|
|
376
|
+
describe "if it errors" do
|
|
377
|
+
it "raises an APIError if the response is not 200" do
|
|
378
|
+
Koala.stub(:make_request).and_return(Koala::HTTPService::Response.new(500, "[]", {}))
|
|
379
|
+
expect {
|
|
380
|
+
Koala::Facebook::API.new("foo").batch {|batch_api| batch_api.get_object('me') }
|
|
381
|
+
}.to raise_exception(Koala::Facebook::APIError)
|
|
382
|
+
end
|
|
375
383
|
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
384
|
+
context "with the old style" do
|
|
385
|
+
before :each do
|
|
386
|
+
Koala.stub(:make_request).and_return(Koala::HTTPService::Response.new(200, '{"error":190,"error_description":"Error validating access token."}', {}))
|
|
387
|
+
end
|
|
388
|
+
|
|
389
|
+
it "throws an error if the response is an old Batch API-style error" do
|
|
390
|
+
expect {
|
|
391
|
+
Koala::Facebook::API.new("foo").batch {|batch_api| batch_api.get_object('me') }
|
|
392
|
+
}.to raise_exception(Koala::Facebook::APIError)
|
|
393
|
+
end
|
|
394
|
+
|
|
395
|
+
it "provides a type for the error if the response is an old Batch API-style error" do
|
|
396
|
+
begin
|
|
397
|
+
Koala::Facebook::API.new("foo").batch {|batch_api| batch_api.get_object('me') }
|
|
398
|
+
rescue Koala::Facebook::APIError => err
|
|
399
|
+
end
|
|
400
|
+
err.fb_error_type.should
|
|
401
|
+
end
|
|
402
|
+
|
|
403
|
+
it "passes all the error details if an old Batch API-style error is raised" do
|
|
404
|
+
begin
|
|
405
|
+
Koala::Facebook::API.new("foo").batch {|batch_api| batch_api.get_object('me') }
|
|
406
|
+
rescue Koala::Facebook::APIError => err
|
|
407
|
+
end
|
|
408
|
+
err.raw_response["error"].should == 190
|
|
409
|
+
end
|
|
410
|
+
end
|
|
411
|
+
|
|
412
|
+
context "with the new style" do
|
|
413
|
+
before :each do
|
|
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
|
+
end
|
|
416
|
+
|
|
417
|
+
it "throws an error if the response is a new Graph API-style error" do
|
|
418
|
+
expect {
|
|
419
|
+
Koala::Facebook::API.new("foo").batch {|batch_api| batch_api.get_object('me') }
|
|
420
|
+
}.to raise_exception(Koala::Facebook::APIError)
|
|
421
|
+
end
|
|
422
|
+
|
|
423
|
+
it "passes all the error details if an old Batch API-style error is raised" do
|
|
424
|
+
begin
|
|
425
|
+
Koala::Facebook::API.new("foo").batch {|batch_api| batch_api.get_object('me') }
|
|
426
|
+
rescue Koala::Facebook::APIError => err
|
|
427
|
+
end
|
|
428
|
+
err.raw_response["message"].should
|
|
429
|
+
end
|
|
430
|
+
end
|
|
381
431
|
end
|
|
382
432
|
|
|
383
433
|
it "returns the result status if http_component is status" do
|
|
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\"}"}]', {}))
|
|
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\"}"}]', {}))
|
|
385
435
|
result = @api.batch do |batch_api|
|
|
386
436
|
batch_api.get_object(KoalaTest.user1, {}, :http_component => :status)
|
|
387
437
|
end
|
|
388
438
|
result[0].should == 203
|
|
389
439
|
end
|
|
390
|
-
|
|
391
|
-
it "returns the result headers as a hash if http_component is headers" do
|
|
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\"}"}]', {}))
|
|
393
|
-
result = @api.batch do |batch_api|
|
|
394
|
-
batch_api.get_object(KoalaTest.user1, {}, :http_component => :headers)
|
|
395
|
-
end
|
|
396
|
-
result[0].should == {"Content-Type" => "text/javascript; charset=UTF-8"}
|
|
397
|
-
end
|
|
398
440
|
end
|
|
399
441
|
|
|
400
442
|
it "is thread safe" do
|
|
@@ -505,7 +547,7 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
|
505
547
|
it "posts binary files" do
|
|
506
548
|
file = File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "beach.jpg"))
|
|
507
549
|
|
|
508
|
-
Koala::Facebook::BatchOperation.instance_variable_set(:@identifier, 0)
|
|
550
|
+
Koala::Facebook::GraphBatchAPI::BatchOperation.instance_variable_set(:@identifier, 0)
|
|
509
551
|
result = @api.batch do |batch_api|
|
|
510
552
|
batch_api.put_picture(file)
|
|
511
553
|
end
|
|
@@ -518,7 +560,7 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
|
|
|
518
560
|
file = File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "beach.jpg"))
|
|
519
561
|
file2 = File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "beach.jpg"))
|
|
520
562
|
|
|
521
|
-
Koala::Facebook::BatchOperation.instance_variable_set(:@identifier, 0)
|
|
563
|
+
Koala::Facebook::GraphBatchAPI::BatchOperation.instance_variable_set(:@identifier, 0)
|
|
522
564
|
results = @api.batch do |batch_api|
|
|
523
565
|
batch_api.put_picture(file)
|
|
524
566
|
batch_api.put_picture(file2, {}, KoalaTest.user1)
|
|
@@ -74,18 +74,34 @@ describe Koala::Facebook::GraphCollection do
|
|
|
74
74
|
end
|
|
75
75
|
|
|
76
76
|
describe "when parsing page paramters" do
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
describe "#parse_page_url" do
|
|
78
|
+
it "should pass the url to the class method" do
|
|
79
|
+
url = stub("url")
|
|
80
|
+
Koala::Facebook::GraphCollection.should_receive(:parse_page_url).with(url)
|
|
81
|
+
@collection.parse_page_url(url)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it "should return the result of the class method" do
|
|
85
|
+
parsed_content = stub("parsed_content")
|
|
86
|
+
Koala::Facebook::GraphCollection.stub(:parse_page_url).and_return(parsed_content)
|
|
87
|
+
@collection.parse_page_url(stub("url")).should == parsed_content
|
|
88
|
+
end
|
|
80
89
|
end
|
|
90
|
+
|
|
91
|
+
describe ".parse_page_url" do
|
|
92
|
+
it "should return the base as the first array entry" do
|
|
93
|
+
base = "url_path"
|
|
94
|
+
Koala::Facebook::GraphCollection.parse_page_url("anything.com/#{base}?anything").first.should == base
|
|
95
|
+
end
|
|
81
96
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
97
|
+
it "should return the arguments as a hash as the last array entry" do
|
|
98
|
+
args_hash = {"one" => "val_one", "two" => "val_two"}
|
|
99
|
+
Koala::Facebook::GraphCollection.parse_page_url("anything.com/anything?#{args_hash.map {|k,v| "#{k}=#{v}" }.join("&")}").last.should == args_hash
|
|
100
|
+
end
|
|
85
101
|
end
|
|
86
102
|
end
|
|
87
103
|
|
|
88
|
-
describe "
|
|
104
|
+
describe ".evaluate" do
|
|
89
105
|
it "returns the original result if it's provided a non-hash result" do
|
|
90
106
|
result = []
|
|
91
107
|
Koala::Facebook::GraphCollection.evaluate(result, @api).should == result
|
|
@@ -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
|
|
|
@@ -90,7 +90,7 @@ describe "Koala::HTTPService" do
|
|
|
90
90
|
end
|
|
91
91
|
end
|
|
92
92
|
|
|
93
|
-
describe "
|
|
93
|
+
describe ".encode_params" do
|
|
94
94
|
it "returns an empty string if param_hash evaluates to false" do
|
|
95
95
|
Koala::HTTPService.encode_params(nil).should == ''
|
|
96
96
|
end
|
|
@@ -135,7 +135,7 @@ describe "Koala::HTTPService" do
|
|
|
135
135
|
end
|
|
136
136
|
end
|
|
137
137
|
|
|
138
|
-
describe "
|
|
138
|
+
describe ".make_request" do
|
|
139
139
|
before :each do
|
|
140
140
|
# Setup stubs for make_request to execute without exceptions
|
|
141
141
|
@mock_body = stub('Typhoeus response body')
|
|
@@ -273,7 +273,7 @@ describe "Koala::HTTPService" do
|
|
|
273
273
|
:always_use_ssl => :use_ssl,
|
|
274
274
|
:proxy => :proxy
|
|
275
275
|
}.each_pair do |deprecated_method, parameter|
|
|
276
|
-
describe "
|
|
276
|
+
describe ".#{deprecated_method}" do
|
|
277
277
|
context "read" do
|
|
278
278
|
it "reads http_options[:#{parameter}]" do
|
|
279
279
|
value = "foo"
|
|
@@ -305,7 +305,7 @@ describe "Koala::HTTPService" do
|
|
|
305
305
|
|
|
306
306
|
# ssl options
|
|
307
307
|
[:ca_path, :ca_file, :verify_mode].each do |deprecated_method|
|
|
308
|
-
describe "
|
|
308
|
+
describe ".#{deprecated_method}" do
|
|
309
309
|
context "read" do
|
|
310
310
|
it "reads http_options[:ssl][:#{deprecated_method}] if http_options[:ssl]" do
|
|
311
311
|
value = "foo"
|
|
@@ -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
|
data/spec/cases/koala_spec.rb
CHANGED
|
@@ -1,15 +1,33 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
describe
|
|
4
|
-
|
|
5
|
-
Koala.const_defined?("VERSION").should be_true
|
|
6
|
-
end
|
|
3
|
+
describe Koala do
|
|
4
|
+
|
|
7
5
|
|
|
8
6
|
it "has an http_service accessor" do
|
|
9
7
|
Koala.should respond_to(:http_service)
|
|
10
8
|
Koala.should respond_to(:http_service=)
|
|
11
9
|
end
|
|
12
10
|
|
|
11
|
+
describe "constants" do
|
|
12
|
+
it "has a version" do
|
|
13
|
+
Koala.const_defined?("VERSION").should be_true
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
describe Koala::Facebook do
|
|
17
|
+
it "defines GRAPH_SERVER" do
|
|
18
|
+
Koala::Facebook::GRAPH_SERVER.should == "graph.facebook.com"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "defines REST_SERVER" do
|
|
22
|
+
Koala::Facebook::REST_SERVER.should == "api.facebook.com"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "defines DIALOG_HOST" do
|
|
26
|
+
Koala::Facebook::DIALOG_HOST.should == "www.facebook.com"
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
13
31
|
context "for deprecated services" do
|
|
14
32
|
before :each do
|
|
15
33
|
@service = Koala.http_service
|