koala 2.5.0 → 3.0.0.beta1
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.
- checksums.yaml +4 -4
- data/.travis.yml +4 -2
- data/Gemfile +1 -1
- data/changelog.md +26 -0
- data/lib/koala/api/batch_operation.rb +3 -6
- data/lib/koala/api/graph_api.rb +6 -45
- data/lib/koala/api/graph_batch_api.rb +1 -2
- data/lib/koala/api/graph_collection.rb +1 -5
- data/lib/koala/api/graph_error_checker.rb +1 -1
- data/lib/koala/api.rb +3 -7
- data/lib/koala/errors.rb +1 -1
- data/lib/koala/http_service/multipart_request.rb +6 -10
- data/lib/koala/http_service/request.rb +139 -0
- data/lib/koala/http_service/response.rb +0 -4
- data/lib/koala/http_service/uploadable_io.rb +0 -4
- data/lib/koala/http_service.rb +16 -68
- data/lib/koala/oauth.rb +3 -3
- data/lib/koala/version.rb +1 -1
- data/lib/koala.rb +2 -1
- data/readme.md +5 -26
- data/spec/cases/api_spec.rb +1 -7
- data/spec/cases/graph_api_batch_spec.rb +12 -22
- data/spec/cases/graph_api_spec.rb +0 -19
- data/spec/cases/graph_collection_spec.rb +18 -18
- data/spec/cases/graph_error_checker_spec.rb +6 -1
- data/spec/cases/http_service/request_spec.rb +240 -0
- data/spec/cases/http_service_spec.rb +102 -296
- data/spec/cases/koala_spec.rb +6 -1
- data/spec/cases/oauth_spec.rb +1 -1
- data/spec/cases/test_users_spec.rb +4 -1
- data/spec/cases/uploadable_io_spec.rb +31 -31
- data/spec/fixtures/mock_facebook_responses.yml +0 -37
- data/spec/spec_helper.rb +2 -2
- data/spec/support/graph_api_shared_examples.rb +6 -142
- data/spec/support/koala_test.rb +6 -6
- data/spec/support/mock_http_service.rb +6 -6
- data/spec/support/uploadable_io_shared_examples.rb +4 -4
- metadata +7 -7
- data/lib/koala/api/rest_api.rb +0 -135
- data/spec/support/rest_api_shared_examples.rb +0 -168
@@ -8,7 +8,7 @@ module Koala::MIME
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
describe "Koala::UploadableIO" do
|
11
|
+
describe "Koala::HTTPService::UploadableIO" do
|
12
12
|
def rails_3_mocks
|
13
13
|
tempfile = double('Tempfile', :path => "foo")
|
14
14
|
uploaded_file = double('ActionDispatch::Http::UploadedFile',
|
@@ -39,15 +39,15 @@ describe "Koala::UploadableIO" do
|
|
39
39
|
end
|
40
40
|
|
41
41
|
it "returns an UploadIO with the same file path" do
|
42
|
-
expect(Koala::UploadableIO.new(*@koala_io_params).io_or_path).to eq(@path)
|
42
|
+
expect(Koala::HTTPService::UploadableIO.new(*@koala_io_params).io_or_path).to eq(@path)
|
43
43
|
end
|
44
44
|
|
45
45
|
it "returns an UploadIO with the same content type" do
|
46
|
-
expect(Koala::UploadableIO.new(*@koala_io_params).content_type).to eq(@stub_type)
|
46
|
+
expect(Koala::HTTPService::UploadableIO.new(*@koala_io_params).content_type).to eq(@stub_type)
|
47
47
|
end
|
48
48
|
|
49
49
|
it "returns an UploadIO with the file's name" do
|
50
|
-
expect(Koala::UploadableIO.new(*@koala_io_params).filename).to eq(File.basename(@path))
|
50
|
+
expect(Koala::HTTPService::UploadableIO.new(*@koala_io_params).filename).to eq(File.basename(@path))
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
@@ -68,16 +68,16 @@ describe "Koala::UploadableIO" do
|
|
68
68
|
end
|
69
69
|
|
70
70
|
it "returns an UploadIO with the same io" do
|
71
|
-
expect(Koala::UploadableIO.new(*@koala_io_params).io_or_path).to eq(@koala_io_params[0])
|
71
|
+
expect(Koala::HTTPService::UploadableIO.new(*@koala_io_params).io_or_path).to eq(@koala_io_params[0])
|
72
72
|
end
|
73
73
|
|
74
74
|
it "returns an UploadableIO with the same content_type" do
|
75
75
|
content_stub = @koala_io_params[1] = double('Content Type')
|
76
|
-
expect(Koala::UploadableIO.new(*@koala_io_params).content_type).to eq(content_stub)
|
76
|
+
expect(Koala::HTTPService::UploadableIO.new(*@koala_io_params).content_type).to eq(content_stub)
|
77
77
|
end
|
78
78
|
|
79
79
|
it "returns an UploadableIO with the right filename" do
|
80
|
-
expect(Koala::UploadableIO.new(*@koala_io_params).filename).to eq(File.basename(@file.path))
|
80
|
+
expect(Koala::HTTPService::UploadableIO.new(*@koala_io_params).filename).to eq(File.basename(@file.path))
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
@@ -100,16 +100,16 @@ describe "Koala::UploadableIO" do
|
|
100
100
|
|
101
101
|
it "returns an UploadIO with the same io" do
|
102
102
|
#Problem comparing Tempfile in Ruby 1.8, REE and Rubinius mode 1.8
|
103
|
-
expect(Koala::UploadableIO.new(*@koala_io_params).io_or_path.path).to eq(@koala_io_params[0].path)
|
103
|
+
expect(Koala::HTTPService::UploadableIO.new(*@koala_io_params).io_or_path.path).to eq(@koala_io_params[0].path)
|
104
104
|
end
|
105
105
|
|
106
106
|
it "returns an UploadableIO with the same content_type" do
|
107
107
|
content_stub = @koala_io_params[1] = double('Content Type')
|
108
|
-
expect(Koala::UploadableIO.new(*@koala_io_params).content_type).to eq(content_stub)
|
108
|
+
expect(Koala::HTTPService::UploadableIO.new(*@koala_io_params).content_type).to eq(content_stub)
|
109
109
|
end
|
110
110
|
|
111
111
|
it "returns an UploadableIO with the right filename" do
|
112
|
-
expect(Koala::UploadableIO.new(*@koala_io_params).filename).to eq(File.basename(@file.path))
|
112
|
+
expect(Koala::HTTPService::UploadableIO.new(*@koala_io_params).filename).to eq(File.basename(@file.path))
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
@@ -130,18 +130,18 @@ describe "Koala::UploadableIO" do
|
|
130
130
|
end
|
131
131
|
|
132
132
|
it "returns an UploadableIO with the same io" do
|
133
|
-
expect(Koala::UploadableIO.new(*@koala_io_params).io_or_path).to eq(@koala_io_params[0])
|
133
|
+
expect(Koala::HTTPService::UploadableIO.new(*@koala_io_params).io_or_path).to eq(@koala_io_params[0])
|
134
134
|
end
|
135
135
|
|
136
136
|
it "returns an UploadableIO with the same content_type" do
|
137
137
|
content_stub = @koala_io_params[1] = double('Content Type')
|
138
|
-
expect(Koala::UploadableIO.new(*@koala_io_params).content_type).to eq(content_stub)
|
138
|
+
expect(Koala::HTTPService::UploadableIO.new(*@koala_io_params).content_type).to eq(content_stub)
|
139
139
|
end
|
140
140
|
end
|
141
141
|
|
142
142
|
describe "and no content type" do
|
143
143
|
it "raises an exception" do
|
144
|
-
expect { Koala::UploadableIO.new(*@koala_io_params) }.to raise_exception(Koala::KoalaError)
|
144
|
+
expect { Koala::HTTPService::UploadableIO.new(*@koala_io_params) }.to raise_exception(Koala::KoalaError)
|
145
145
|
end
|
146
146
|
end
|
147
147
|
end
|
@@ -154,17 +154,17 @@ describe "Koala::UploadableIO" do
|
|
154
154
|
it "gets the path from the tempfile associated with the UploadedFile" do
|
155
155
|
expected_path = double('Tempfile')
|
156
156
|
expect(@tempfile).to receive(:path).and_return(expected_path)
|
157
|
-
expect(Koala::UploadableIO.new(@uploaded_file).io_or_path).to eq(expected_path)
|
157
|
+
expect(Koala::HTTPService::UploadableIO.new(@uploaded_file).io_or_path).to eq(expected_path)
|
158
158
|
end
|
159
159
|
|
160
160
|
it "gets the content type via the content_type method" do
|
161
161
|
expected_content_type = double('Content Type')
|
162
162
|
expect(@uploaded_file).to receive(:content_type).and_return(expected_content_type)
|
163
|
-
expect(Koala::UploadableIO.new(@uploaded_file).content_type).to eq(expected_content_type)
|
163
|
+
expect(Koala::HTTPService::UploadableIO.new(@uploaded_file).content_type).to eq(expected_content_type)
|
164
164
|
end
|
165
165
|
|
166
166
|
it "gets the filename from the UploadedFile" do
|
167
|
-
expect(Koala::UploadableIO.new(@uploaded_file).filename).to eq(@uploaded_file.original_filename)
|
167
|
+
expect(Koala::HTTPService::UploadableIO.new(@uploaded_file).filename).to eq(@uploaded_file.original_filename)
|
168
168
|
end
|
169
169
|
end
|
170
170
|
|
@@ -177,7 +177,7 @@ describe "Koala::UploadableIO" do
|
|
177
177
|
expected_file = double('File')
|
178
178
|
@file_hash[:tempfile] = expected_file
|
179
179
|
|
180
|
-
uploadable = Koala::UploadableIO.new(@file_hash)
|
180
|
+
uploadable = Koala::HTTPService::UploadableIO.new(@file_hash)
|
181
181
|
expect(uploadable.io_or_path).to eq(expected_file)
|
182
182
|
end
|
183
183
|
|
@@ -185,12 +185,12 @@ describe "Koala::UploadableIO" do
|
|
185
185
|
expected_content_type = double('Content Type')
|
186
186
|
@file_hash[:type] = expected_content_type
|
187
187
|
|
188
|
-
uploadable = Koala::UploadableIO.new(@file_hash)
|
188
|
+
uploadable = Koala::HTTPService::UploadableIO.new(@file_hash)
|
189
189
|
expect(uploadable.content_type).to eq(expected_content_type)
|
190
190
|
end
|
191
191
|
|
192
192
|
it "gets the content type from the :type key" do
|
193
|
-
uploadable = Koala::UploadableIO.new(@file_hash)
|
193
|
+
uploadable = Koala::HTTPService::UploadableIO.new(@file_hash)
|
194
194
|
expect(uploadable.filename).to eq(@file_hash[:filename])
|
195
195
|
end
|
196
196
|
end
|
@@ -199,12 +199,12 @@ describe "Koala::UploadableIO" do
|
|
199
199
|
# what that means is tested below
|
200
200
|
it "should accept a file object alone" do
|
201
201
|
params = [BEACH_BALL_PATH]
|
202
|
-
expect { Koala::UploadableIO.new(*params) }.not_to raise_exception
|
202
|
+
expect { Koala::HTTPService::UploadableIO.new(*params) }.not_to raise_exception
|
203
203
|
end
|
204
204
|
|
205
205
|
it "should accept a file path alone" do
|
206
206
|
params = [BEACH_BALL_PATH]
|
207
|
-
expect { Koala::UploadableIO.new(*params) }.not_to raise_exception
|
207
|
+
expect { Koala::HTTPService::UploadableIO.new(*params) }.not_to raise_exception
|
208
208
|
end
|
209
209
|
end
|
210
210
|
end
|
@@ -218,7 +218,7 @@ describe "Koala::UploadableIO" do
|
|
218
218
|
context "if no filename was provided" do
|
219
219
|
it "should call the constructor with the content type, file name, and a dummy file name" do
|
220
220
|
expect(UploadIO).to receive(:new).with(BEACH_BALL_PATH, "content/type", anything).and_return(@upload_io)
|
221
|
-
expect(Koala::UploadableIO.new(BEACH_BALL_PATH, "content/type").to_upload_io).to eq(@upload_io)
|
221
|
+
expect(Koala::HTTPService::UploadableIO.new(BEACH_BALL_PATH, "content/type").to_upload_io).to eq(@upload_io)
|
222
222
|
end
|
223
223
|
end
|
224
224
|
|
@@ -226,7 +226,7 @@ describe "Koala::UploadableIO" do
|
|
226
226
|
it "should call the constructor with the content type, file name, and the filename" do
|
227
227
|
filename = "file"
|
228
228
|
expect(UploadIO).to receive(:new).with(BEACH_BALL_PATH, "content/type", filename).and_return(@upload_io)
|
229
|
-
Koala::UploadableIO.new(BEACH_BALL_PATH, "content/type", filename).to_upload_io
|
229
|
+
Koala::HTTPService::UploadableIO.new(BEACH_BALL_PATH, "content/type", filename).to_upload_io
|
230
230
|
end
|
231
231
|
end
|
232
232
|
end
|
@@ -234,33 +234,33 @@ describe "Koala::UploadableIO" do
|
|
234
234
|
describe "getting a file" do
|
235
235
|
it "returns the File if initialized with a file" do
|
236
236
|
f = File.new(BEACH_BALL_PATH)
|
237
|
-
expect(Koala::UploadableIO.new(f).to_file).to eq(f)
|
237
|
+
expect(Koala::HTTPService::UploadableIO.new(f).to_file).to eq(f)
|
238
238
|
end
|
239
239
|
|
240
240
|
it "should open up and return a file corresponding to the path if io_or_path is a path" do
|
241
241
|
result = double("File")
|
242
242
|
expect(File).to receive(:open).with(BEACH_BALL_PATH).and_return(result)
|
243
|
-
expect(Koala::UploadableIO.new(BEACH_BALL_PATH).to_file).to eq(result)
|
243
|
+
expect(Koala::HTTPService::UploadableIO.new(BEACH_BALL_PATH).to_file).to eq(result)
|
244
244
|
end
|
245
245
|
end
|
246
246
|
|
247
247
|
describe ".binary_content?" do
|
248
248
|
it "returns true for Rails 3 file uploads" do
|
249
|
-
expect(Koala::UploadableIO.binary_content?(rails_3_mocks.last)).to be_truthy
|
249
|
+
expect(Koala::HTTPService::UploadableIO.binary_content?(rails_3_mocks.last)).to be_truthy
|
250
250
|
end
|
251
251
|
|
252
252
|
it "returns true for Sinatra file uploads" do
|
253
|
-
expect(Koala::UploadableIO.binary_content?(rails_3_mocks.last)).to be_truthy
|
253
|
+
expect(Koala::HTTPService::UploadableIO.binary_content?(rails_3_mocks.last)).to be_truthy
|
254
254
|
end
|
255
255
|
|
256
256
|
it "returns true for File objects" do
|
257
|
-
expect(Koala::UploadableIO.binary_content?(File.open(BEACH_BALL_PATH))).to be_truthy
|
257
|
+
expect(Koala::HTTPService::UploadableIO.binary_content?(File.open(BEACH_BALL_PATH))).to be_truthy
|
258
258
|
end
|
259
259
|
|
260
260
|
it "returns false for everything else" do
|
261
|
-
expect(Koala::UploadableIO.binary_content?(StringIO.new)).to be_falsey
|
262
|
-
expect(Koala::UploadableIO.binary_content?(BEACH_BALL_PATH)).to be_falsey
|
263
|
-
expect(Koala::UploadableIO.binary_content?(nil)).to be_falsey
|
261
|
+
expect(Koala::HTTPService::UploadableIO.binary_content?(StringIO.new)).to be_falsey
|
262
|
+
expect(Koala::HTTPService::UploadableIO.binary_content?(BEACH_BALL_PATH)).to be_falsey
|
263
|
+
expect(Koala::HTTPService::UploadableIO.binary_content?(nil)).to be_falsey
|
264
264
|
end
|
265
265
|
end
|
266
266
|
end # describe UploadableIO
|
@@ -10,22 +10,6 @@
|
|
10
10
|
# with_token:
|
11
11
|
# no_token:
|
12
12
|
|
13
|
-
# ====== REST API =====
|
14
|
-
rest_api:
|
15
|
-
|
16
|
-
# -- Stubbed Responses --
|
17
|
-
/method/admin.setAppProperties:
|
18
|
-
'properties={"desktop":0}':
|
19
|
-
post:
|
20
|
-
with_token: 'true'
|
21
|
-
/method/fql.query: # for testing the beta tier
|
22
|
-
query=select first_name from user where uid = 2901279:
|
23
|
-
get:
|
24
|
-
no_token: '[{"first_name":"Luke"}]'
|
25
|
-
with_token: '[{"first_name":"Luke"}]'
|
26
|
-
|
27
|
-
|
28
|
-
|
29
13
|
# ====== GRAPH API =====
|
30
14
|
graph_api:
|
31
15
|
|
@@ -95,9 +79,6 @@ graph_api:
|
|
95
79
|
batch=<%= JSON.dump([{"method"=>"post", "relative_url"=>"FEED_ITEM_BATCH/likes"}, {"method"=>"delete", "relative_url"=> "FEED_ITEM_BATCH"}]) %>:
|
96
80
|
post:
|
97
81
|
with_token: '[{"code": 200, "body": "{\"id\": \"MOCK_LIKE\"}"},{"code": 200, "body":true}]'
|
98
|
-
batch=<%= JSON.dump([{"method" => "post", "relative_url" => "method/fql.query", "body" => "query=select+first_name+from+user+where+uid%3D2905623"}]) %>:
|
99
|
-
post:
|
100
|
-
with_token: '[{"code": 200, "body":"[{\"first_name\":\"Alex\"}]"}]'
|
101
82
|
|
102
83
|
# dependencies
|
103
84
|
batch=<%= JSON.dump([{"method"=>"get", "relative_url"=>"me", "name" => "getme"}, {"method"=>"get", "relative_url"=>"koppel", "depends_on" => "getme"}]) %>:
|
@@ -296,24 +277,6 @@ graph_api:
|
|
296
277
|
with_token: '{"data": [{"id": "507731521_100412693339488"}], "paging": {"previous": "https:\/\/graph.facebook.com\/7204941866\/photos?limit=25&until=2008-09-15T18%3A30%3A25%2B0000", "next": "https:\/\/graph.facebook.com\/7204941866\/photos?limit=25&until=2008-09-15T18%3A30%3A25%2B0000"}}'
|
297
278
|
no_token: '{"data": [{"id": "507731521_100412693339488"}], "paging": {"previous": "https:\/\/graph.facebook.com\/7204941866\/photos?limit=25&until=2008-09-15T18%3A30%3A25%2B0000", "next": "https:\/\/graph.facebook.com\/7204941866\/photos?limit=25&until=2008-09-15T18%3A30%3A25%2B0000"}}'
|
298
279
|
|
299
|
-
/fql:
|
300
|
-
q=select uid, first_name from user where uid = 2901279:
|
301
|
-
get:
|
302
|
-
no_token: '[{"uid":2901279,"first_name":"Luke"}]'
|
303
|
-
with_token: '[{"uid":2901279,"first_name":"Luke"}]'
|
304
|
-
q=select read_stream from permissions where uid = 2901279:
|
305
|
-
get:
|
306
|
-
<<: *token_required
|
307
|
-
with_token: '[{"read_stream":1}]'
|
308
|
-
'q=<%= JSON.dump({"query1" => "select post_id from stream where source_id = me()", "query2" => "select fromid from comment where post_id in (select post_id from #query1)", "query3" => "select uid, name from user where uid in (select fromid from #query2)"}) %>':
|
309
|
-
get:
|
310
|
-
<<: *token_required
|
311
|
-
with_token: '[{"name":"query1", "fql_result_set":[]},{"name":"query2", "fql_result_set":[]},{"name":"query3", "fql_result_set":[]}]'
|
312
|
-
'q=<%= JSON.dump({"query1" => "select uid, first_name from user where uid = 2901279", "query2" => "select uid, first_name from user where uid = 2905623"}) %>':
|
313
|
-
get:
|
314
|
-
with_token: '[{"name":"query1", "fql_result_set":[{"uid":2901279,"first_name":"Luke"}]},{"name":"query2", "fql_result_set":[{"uid":"2905623","first_name":"Alex"}]}]'
|
315
|
-
no_token: '[{"name":"query1", "fql_result_set":[{"uid":2901279,"first_name":"Luke"}]},{"name":"query2", "fql_result_set":[{"uid":"2905623","first_name":"Alex"}]}]'
|
316
|
-
|
317
280
|
|
318
281
|
'/115349521819193_113815981982767':
|
319
282
|
no_args:
|
data/spec/spec_helper.rb
CHANGED
@@ -32,14 +32,14 @@ shared_examples_for "Koala GraphAPI" do
|
|
32
32
|
it "passes the results through GraphCollection.evaluate" do
|
33
33
|
result = {}
|
34
34
|
allow(@api).to receive(:api).and_return(result)
|
35
|
-
expect(Koala::Facebook::GraphCollection).to receive(:evaluate).with(result, @api)
|
35
|
+
expect(Koala::Facebook::API::GraphCollection).to receive(:evaluate).with(result, @api)
|
36
36
|
@api.graph_call("/me")
|
37
37
|
end
|
38
38
|
|
39
39
|
it "returns the results of GraphCollection.evaluate" do
|
40
40
|
expected = {}
|
41
41
|
allow(@api).to receive(:api).and_return([])
|
42
|
-
expect(Koala::Facebook::GraphCollection).to receive(:evaluate).and_return(expected)
|
42
|
+
expect(Koala::Facebook::API::GraphCollection).to receive(:evaluate).and_return(expected)
|
43
43
|
expect(@api.graph_call("/me")).to eq(expected)
|
44
44
|
end
|
45
45
|
|
@@ -158,63 +158,6 @@ shared_examples_for "Koala GraphAPI" do
|
|
158
158
|
# the results should have an ID and a name, among other things
|
159
159
|
expect(result["id"] && result["name"]).to be_truthy
|
160
160
|
end
|
161
|
-
|
162
|
-
# FQL
|
163
|
-
describe "#fql_query" do
|
164
|
-
it "makes a request to /fql" do
|
165
|
-
expect(@api).to receive(:get_object).with("fql", anything, anything)
|
166
|
-
@api.fql_query double('query string')
|
167
|
-
end
|
168
|
-
|
169
|
-
it "passes a query argument" do
|
170
|
-
query = double('query string')
|
171
|
-
expect(@api).to receive(:get_object).with(anything, hash_including(:q => query), anything)
|
172
|
-
@api.fql_query(query)
|
173
|
-
end
|
174
|
-
|
175
|
-
it "passes on any other arguments provided" do
|
176
|
-
args = {:a => 2}
|
177
|
-
expect(@api).to receive(:get_object).with(anything, hash_including(args), anything)
|
178
|
-
@api.fql_query("a query", args)
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
describe "#fql_multiquery" do
|
183
|
-
it "makes a request to /fql" do
|
184
|
-
expect(@api).to receive(:get_object).with("fql", anything, anything)
|
185
|
-
@api.fql_multiquery 'query string'
|
186
|
-
end
|
187
|
-
|
188
|
-
it "passes a queries argument" do
|
189
|
-
queries = double('query string')
|
190
|
-
queries_json = "some JSON"
|
191
|
-
allow(JSON).to receive(:dump).with(queries).and_return(queries_json)
|
192
|
-
|
193
|
-
expect(@api).to receive(:get_object).with(anything, hash_including(:q => queries_json), anything)
|
194
|
-
@api.fql_multiquery(queries)
|
195
|
-
end
|
196
|
-
|
197
|
-
it "simplifies the response format" do
|
198
|
-
raw_results = [
|
199
|
-
{"name" => "query1", "fql_result_set" => [1, 2, 3]},
|
200
|
-
{"name" => "query2", "fql_result_set" => [:a, :b, :c]}
|
201
|
-
]
|
202
|
-
expected_results = {
|
203
|
-
"query1" => [1, 2, 3],
|
204
|
-
"query2" => [:a, :b, :c]
|
205
|
-
}
|
206
|
-
|
207
|
-
allow(@api).to receive(:get_object).and_return(raw_results)
|
208
|
-
results = @api.fql_multiquery({:query => true})
|
209
|
-
expect(results).to eq(expected_results)
|
210
|
-
end
|
211
|
-
|
212
|
-
it "passes on any other arguments provided" do
|
213
|
-
args = {:a => 2}
|
214
|
-
expect(@api).to receive(:get_object).with(anything, hash_including(args), anything)
|
215
|
-
@api.fql_multiquery("a query", args)
|
216
|
-
end
|
217
|
-
end
|
218
161
|
end
|
219
162
|
|
220
163
|
|
@@ -370,7 +313,7 @@ shared_examples_for "Koala GraphAPI with an access token" do
|
|
370
313
|
|
371
314
|
it "sets options[:video] to true" do
|
372
315
|
source = double("UploadIO")
|
373
|
-
allow(Koala::UploadableIO).to receive(:new).and_return(source)
|
316
|
+
allow(Koala::HTTPService::UploadableIO).to receive(:new).and_return(source)
|
374
317
|
allow(source).to receive(:requires_base_http_service).and_return(false)
|
375
318
|
expect(Koala).to receive(:make_request).with(anything, anything, anything, hash_including(:video => true)).and_return(Koala::HTTPService::Response.new(200, "[]", {}))
|
376
319
|
@api.put_video("foo")
|
@@ -508,51 +451,6 @@ shared_examples_for "Koala GraphAPI with an access token" do
|
|
508
451
|
end
|
509
452
|
end
|
510
453
|
|
511
|
-
it "can access public information via FQL" do
|
512
|
-
result = @api.fql_query("select uid, first_name from user where uid = #{KoalaTest.user2_id}")
|
513
|
-
expect(result.size).to eq(1)
|
514
|
-
expect(result.first['first_name']).to eq(KoalaTest.user2_name)
|
515
|
-
expect(result.first['uid']).to eq(KoalaTest.user2_id.to_i)
|
516
|
-
end
|
517
|
-
|
518
|
-
it "can access public information via FQL.multiquery" do
|
519
|
-
result = @api.fql_multiquery(
|
520
|
-
:query1 => "select uid, first_name from user where uid = #{KoalaTest.user2_id}",
|
521
|
-
:query2 => "select uid, first_name from user where uid = #{KoalaTest.user1_id}"
|
522
|
-
)
|
523
|
-
expect(result.size).to eq(2)
|
524
|
-
# this should check for first_name, but there's an FB bug currently
|
525
|
-
expect(result["query1"].first['uid']).to eq(KoalaTest.user2_id.to_i)
|
526
|
-
# result["query1"].first['first_name'].should == KoalaTest.user2_name
|
527
|
-
expect(result["query2"].first['first_name']).to eq(KoalaTest.user1_name)
|
528
|
-
end
|
529
|
-
|
530
|
-
it "can access protected information via FQL" do
|
531
|
-
# Tests agains the permissions fql table
|
532
|
-
|
533
|
-
# get the current user's ID
|
534
|
-
# we're sneakily using the Graph API, which should be okay since it has its own tests
|
535
|
-
g = Koala::Facebook::API.new(@token)
|
536
|
-
id = g.get_object("me", :fields => "id")["id"]
|
537
|
-
|
538
|
-
# now send a query about your permissions
|
539
|
-
result = @api.fql_query("select read_stream from permissions where uid = #{id}")
|
540
|
-
|
541
|
-
expect(result.size).to eq(1)
|
542
|
-
# we've verified that you have read_stream permissions, so we can test against that
|
543
|
-
expect(result.first["read_stream"]).to eq(1)
|
544
|
-
end
|
545
|
-
|
546
|
-
it "can access protected information via FQL.multiquery" do
|
547
|
-
result = @api.fql_multiquery(
|
548
|
-
:query1 => "select post_id from stream where source_id = me()",
|
549
|
-
:query2 => "select fromid from comment where post_id in (select post_id from #query1)",
|
550
|
-
:query3 => "select uid, name from user where uid in (select fromid from #query2)"
|
551
|
-
)
|
552
|
-
expect(result.size).to eq(3)
|
553
|
-
expect(result.keys).to include("query1", "query2", "query3")
|
554
|
-
end
|
555
|
-
|
556
454
|
# test all methods to make sure they pass data through to the API
|
557
455
|
# we run the tests here (rather than in the common shared example group)
|
558
456
|
# since some require access tokens
|
@@ -572,7 +470,6 @@ shared_examples_for "Koala GraphAPI with an access token" do
|
|
572
470
|
:search => 3,
|
573
471
|
:set_app_restrictions => 4,
|
574
472
|
:get_page_access_token => 3,
|
575
|
-
:fql_query => 3, :fql_multiquery => 3,
|
576
473
|
# methods that have special arguments
|
577
474
|
:get_comments_for_urls => [["url1", "url2"], {}],
|
578
475
|
:put_picture => ["x.jpg", "image/jpg", {}, "me"],
|
@@ -609,7 +506,7 @@ shared_examples_for "Koala GraphAPI with GraphCollection" do
|
|
609
506
|
# GraphCollection methods
|
610
507
|
it "gets a GraphCollection when getting connections" do
|
611
508
|
@result = @api.get_connections(KoalaTest.page, "photos")
|
612
|
-
expect(@result).to be_a(Koala::Facebook::GraphCollection)
|
509
|
+
expect(@result).to be_a(Koala::Facebook::API::GraphCollection)
|
613
510
|
end
|
614
511
|
|
615
512
|
it "returns nil if the get_collections call fails with nil" do
|
@@ -620,7 +517,7 @@ shared_examples_for "Koala GraphAPI with GraphCollection" do
|
|
620
517
|
|
621
518
|
it "gets a GraphCollection when searching" do
|
622
519
|
result = @api.search("facebook")
|
623
|
-
expect(result).to be_a(Koala::Facebook::GraphCollection)
|
520
|
+
expect(result).to be_a(Koala::Facebook::API::GraphCollection)
|
624
521
|
end
|
625
522
|
|
626
523
|
it "returns nil if the search call fails with nil" do
|
@@ -631,7 +528,7 @@ shared_examples_for "Koala GraphAPI with GraphCollection" do
|
|
631
528
|
|
632
529
|
it "gets a GraphCollection when paging through results" do
|
633
530
|
@results = @api.get_page(["search", {"q"=>"facebook", "limit"=>"25", "until"=> KoalaTest.search_time}])
|
634
|
-
expect(@results).to be_a(Koala::Facebook::GraphCollection)
|
531
|
+
expect(@results).to be_a(Koala::Facebook::API::GraphCollection)
|
635
532
|
end
|
636
533
|
|
637
534
|
it "returns nil if the page call fails with nil" do
|
@@ -691,37 +588,4 @@ shared_examples_for "Koala GraphAPI without an access token" do
|
|
691
588
|
it "can't delete a like" do
|
692
589
|
expect { @api.delete_like("7204941866_119776748033392") }.to raise_error(Koala::Facebook::AuthenticationError)
|
693
590
|
end
|
694
|
-
|
695
|
-
# FQL_QUERY
|
696
|
-
describe "when making a FQL request" do
|
697
|
-
it "can access public information via FQL" do
|
698
|
-
result = @api.fql_query("select uid, first_name from user where uid = #{KoalaTest.user2_id}")
|
699
|
-
expect(result.size).to eq(1)
|
700
|
-
expect(result.first['first_name']).to eq(KoalaTest.user2_name)
|
701
|
-
end
|
702
|
-
|
703
|
-
it "can access public information via FQL.multiquery" do
|
704
|
-
result = @api.fql_multiquery(
|
705
|
-
:query1 => "select uid, first_name from user where uid = #{KoalaTest.user2_id}",
|
706
|
-
:query2 => "select uid, first_name from user where uid = #{KoalaTest.user1_id}"
|
707
|
-
)
|
708
|
-
expect(result.size).to eq(2)
|
709
|
-
expect(result["query1"].first['first_name']).to eq(KoalaTest.user2_name)
|
710
|
-
expect(result["query2"].first['first_name']).to eq(KoalaTest.user1_name)
|
711
|
-
end
|
712
|
-
|
713
|
-
it "can't access protected information via FQL" do
|
714
|
-
expect { @api.fql_query("select read_stream from permissions where uid = #{KoalaTest.user2_id}") }.to raise_error(Koala::Facebook::APIError)
|
715
|
-
end
|
716
|
-
|
717
|
-
it "can't access protected information via FQL.multiquery" do
|
718
|
-
expect {
|
719
|
-
@api.fql_multiquery(
|
720
|
-
:query1 => "select post_id from stream where source_id = me()",
|
721
|
-
:query2 => "select fromid from comment where post_id in (select post_id from #query1)",
|
722
|
-
:query3 => "select uid, name from user where uid in (select fromid from #query2)"
|
723
|
-
)
|
724
|
-
}.to raise_error(Koala::Facebook::APIError)
|
725
|
-
end
|
726
|
-
end
|
727
591
|
end
|
data/spec/support/koala_test.rb
CHANGED
@@ -157,12 +157,12 @@ module KoalaTest
|
|
157
157
|
print "Validating permissions for live testing..."
|
158
158
|
# make sure we have the necessary permissions
|
159
159
|
api = Koala::Facebook::API.new(token)
|
160
|
-
perms = api.
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
160
|
+
perms = api.get_connect("me", "permissions")["data"]
|
161
|
+
|
162
|
+
# live testing depends on insights calls failing
|
163
|
+
if perms.keys.include?("read_insights") || (perms.keys & testing_permissions) != testing_permissions
|
164
|
+
puts "failed!\n" # put a new line after the print above
|
165
|
+
raise ArgumentError, "Your access token must have #{testing_permissions.join(", ")}, and lack read_insights. You have: #{perms.inspect}"
|
166
166
|
end
|
167
167
|
puts "done!"
|
168
168
|
end
|
@@ -32,8 +32,8 @@ module Koala
|
|
32
32
|
mock_response_file_path = File.join(File.dirname(__FILE__), '..', 'fixtures', 'mock_facebook_responses.yml')
|
33
33
|
RESPONSES = YAML.load(ERB.new(IO.read(mock_response_file_path)).result(binding))
|
34
34
|
|
35
|
-
def self.make_request(
|
36
|
-
if response = match_response(
|
35
|
+
def self.make_request(request)
|
36
|
+
if response = match_response(request.raw_path, request.raw_args, request.raw_verb, request.raw_options)
|
37
37
|
# create response class object
|
38
38
|
response_object = if response.is_a? String
|
39
39
|
Koala::HTTPService::Response.new(200, response, {})
|
@@ -65,7 +65,7 @@ module Koala
|
|
65
65
|
|
66
66
|
# For a given query, see if our mock responses YAML has a resopnse for it.
|
67
67
|
def self.match_response(path, args, verb, options = {})
|
68
|
-
server =
|
68
|
+
server = 'graph_api'
|
69
69
|
path = 'root' if path == '' || path == '/'
|
70
70
|
verb = (verb || 'get').to_s
|
71
71
|
token = args.delete('access_token')
|
@@ -88,8 +88,8 @@ module Koala
|
|
88
88
|
args = arguments.inject({}) do |hash, (k, v)|
|
89
89
|
# ensure our args are all stringified
|
90
90
|
value = if v.is_a?(String)
|
91
|
-
should_json_decode?(v) ? JSON.
|
92
|
-
elsif v.is_a?(Koala::UploadableIO)
|
91
|
+
should_json_decode?(v) ? JSON.parse(v) : v
|
92
|
+
elsif v.is_a?(Koala::HTTPService::UploadableIO)
|
93
93
|
# obviously there are no files in the yaml
|
94
94
|
"[FILE]"
|
95
95
|
else
|
@@ -119,7 +119,7 @@ module Koala
|
|
119
119
|
# will remove +'s in restriction strings
|
120
120
|
string.split("&").reduce({}) do |hash, component|
|
121
121
|
k, v = component.split("=", 2) # we only care about the first =
|
122
|
-
value = should_json_decode?(v) ? JSON.
|
122
|
+
value = should_json_decode?(v) ? JSON.parse(v) : v.to_s rescue v.to_s
|
123
123
|
# some special-casing, unfortunate but acceptable in this testing
|
124
124
|
# environment
|
125
125
|
value = nil if value.empty?
|
@@ -12,7 +12,7 @@ shared_examples_for "MIME::Types can't return results" do
|
|
12
12
|
else
|
13
13
|
@koala_io_params[0] = path
|
14
14
|
end
|
15
|
-
expect(Koala::UploadableIO.new(*@koala_io_params).content_type).to eq(mime_type)
|
15
|
+
expect(Koala::HTTPService::UploadableIO.new(*@koala_io_params).content_type).to eq(mime_type)
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should get content types for #{extension} using basic analysis with file names with more than one dot" do
|
@@ -22,7 +22,7 @@ shared_examples_for "MIME::Types can't return results" do
|
|
22
22
|
else
|
23
23
|
@koala_io_params[0] = path
|
24
24
|
end
|
25
|
-
expect(Koala::UploadableIO.new(*@koala_io_params).content_type).to eq(mime_type)
|
25
|
+
expect(Koala::HTTPService::UploadableIO.new(*@koala_io_params).content_type).to eq(mime_type)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
@@ -37,7 +37,7 @@ shared_examples_for "MIME::Types can't return results" do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should throw an exception" do
|
40
|
-
expect { Koala::UploadableIO.new(*@koala_io_params) }.to raise_exception(Koala::KoalaError)
|
40
|
+
expect { Koala::HTTPService::UploadableIO.new(*@koala_io_params) }.to raise_exception(Koala::KoalaError)
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
@@ -47,7 +47,7 @@ shared_examples_for "determining a mime type" do
|
|
47
47
|
it "should return an UploadIO with MIME::Types-determined type if the type exists" do
|
48
48
|
type_result = ["type"]
|
49
49
|
allow(Koala::MIME::Types).to receive(:type_for).and_return(type_result)
|
50
|
-
expect(Koala::UploadableIO.new(*@koala_io_params).content_type).to eq(type_result.first)
|
50
|
+
expect(Koala::HTTPService::UploadableIO.new(*@koala_io_params).content_type).to eq(type_result.first)
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: koala
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0.beta1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Koppel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02-
|
11
|
+
date: 2017-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -71,10 +71,10 @@ files:
|
|
71
71
|
- lib/koala/api/graph_batch_api.rb
|
72
72
|
- lib/koala/api/graph_collection.rb
|
73
73
|
- lib/koala/api/graph_error_checker.rb
|
74
|
-
- lib/koala/api/rest_api.rb
|
75
74
|
- lib/koala/errors.rb
|
76
75
|
- lib/koala/http_service.rb
|
77
76
|
- lib/koala/http_service/multipart_request.rb
|
77
|
+
- lib/koala/http_service/request.rb
|
78
78
|
- lib/koala/http_service/response.rb
|
79
79
|
- lib/koala/http_service/uploadable_io.rb
|
80
80
|
- lib/koala/oauth.rb
|
@@ -89,6 +89,7 @@ files:
|
|
89
89
|
- spec/cases/graph_api_spec.rb
|
90
90
|
- spec/cases/graph_collection_spec.rb
|
91
91
|
- spec/cases/graph_error_checker_spec.rb
|
92
|
+
- spec/cases/http_service/request_spec.rb
|
92
93
|
- spec/cases/http_service_spec.rb
|
93
94
|
- spec/cases/koala_spec.rb
|
94
95
|
- spec/cases/koala_test_spec.rb
|
@@ -109,7 +110,6 @@ files:
|
|
109
110
|
- spec/support/graph_api_shared_examples.rb
|
110
111
|
- spec/support/koala_test.rb
|
111
112
|
- spec/support/mock_http_service.rb
|
112
|
-
- spec/support/rest_api_shared_examples.rb
|
113
113
|
- spec/support/uploadable_io_shared_examples.rb
|
114
114
|
homepage: http://github.com/arsduo/koala
|
115
115
|
licenses:
|
@@ -130,9 +130,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
130
130
|
version: '0'
|
131
131
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
132
|
requirements:
|
133
|
-
- - "
|
133
|
+
- - ">"
|
134
134
|
- !ruby/object:Gem::Version
|
135
|
-
version:
|
135
|
+
version: 1.3.1
|
136
136
|
requirements: []
|
137
137
|
rubyforge_project:
|
138
138
|
rubygems_version: 2.4.3
|
@@ -147,6 +147,7 @@ test_files:
|
|
147
147
|
- spec/cases/graph_api_spec.rb
|
148
148
|
- spec/cases/graph_collection_spec.rb
|
149
149
|
- spec/cases/graph_error_checker_spec.rb
|
150
|
+
- spec/cases/http_service/request_spec.rb
|
150
151
|
- spec/cases/http_service_spec.rb
|
151
152
|
- spec/cases/koala_spec.rb
|
152
153
|
- spec/cases/koala_test_spec.rb
|
@@ -167,6 +168,5 @@ test_files:
|
|
167
168
|
- spec/support/graph_api_shared_examples.rb
|
168
169
|
- spec/support/koala_test.rb
|
169
170
|
- spec/support/mock_http_service.rb
|
170
|
-
- spec/support/rest_api_shared_examples.rb
|
171
171
|
- spec/support/uploadable_io_shared_examples.rb
|
172
172
|
has_rdoc:
|