koala 2.5.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +5 -3
- data/Gemfile +1 -1
- data/ISSUE_TEMPLATE +25 -0
- data/PULL_REQUEST_TEMPLATE +11 -0
- data/changelog.md +66 -4
- data/code_of_conduct.md +64 -12
- data/koala.gemspec +3 -0
- data/lib/koala/api/batch_operation.rb +3 -6
- data/lib/koala/api/{graph_api.rb → graph_api_methods.rb} +13 -102
- data/lib/koala/api/graph_batch_api.rb +112 -65
- data/lib/koala/api/graph_collection.rb +19 -12
- data/lib/koala/api/graph_error_checker.rb +1 -1
- data/lib/koala/api.rb +49 -25
- data/lib/koala/configuration.rb +49 -0
- data/lib/koala/errors.rb +1 -1
- data/lib/koala/http_service/multipart_request.rb +6 -10
- data/lib/koala/http_service/request.rb +135 -0
- data/lib/koala/http_service/response.rb +6 -4
- data/lib/koala/http_service/uploadable_io.rb +0 -4
- data/lib/koala/http_service.rb +18 -76
- data/lib/koala/oauth.rb +7 -7
- data/lib/koala/realtime_updates.rb +26 -21
- data/lib/koala/test_users.rb +9 -8
- data/lib/koala/version.rb +1 -1
- data/lib/koala.rb +6 -8
- data/readme.md +50 -109
- data/spec/cases/api_spec.rb +99 -69
- data/spec/cases/configuration_spec.rb +11 -0
- data/spec/cases/graph_api_batch_spec.rb +73 -42
- data/spec/cases/graph_api_spec.rb +15 -29
- data/spec/cases/graph_collection_spec.rb +47 -34
- data/spec/cases/graph_error_checker_spec.rb +6 -1
- data/spec/cases/http_service/request_spec.rb +242 -0
- data/spec/cases/http_service/response_spec.rb +24 -0
- data/spec/cases/http_service_spec.rb +102 -296
- data/spec/cases/koala_spec.rb +7 -5
- data/spec/cases/oauth_spec.rb +40 -1
- data/spec/cases/realtime_updates_spec.rb +51 -13
- data/spec/cases/test_users_spec.rb +56 -2
- data/spec/cases/uploadable_io_spec.rb +31 -31
- data/spec/fixtures/cat.m4v +0 -0
- data/spec/fixtures/facebook_data.yml +4 -6
- data/spec/fixtures/mock_facebook_responses.yml +29 -69
- data/spec/fixtures/vcr_cassettes/app_test_accounts.yml +97 -0
- data/spec/integration/graph_collection_spec.rb +8 -5
- data/spec/spec_helper.rb +2 -2
- data/spec/support/graph_api_shared_examples.rb +143 -336
- data/spec/support/koala_test.rb +8 -10
- data/spec/support/mock_http_service.rb +9 -9
- data/spec/support/uploadable_io_shared_examples.rb +4 -4
- metadata +31 -11
- data/.autotest +0 -12
- data/Guardfile +0 -6
- data/autotest/discover.rb +0 -1
- data/lib/koala/api/rest_api.rb +0 -135
- data/spec/support/rest_api_shared_examples.rb +0 -168
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
shared_examples_for "Koala GraphAPI" do
|
|
2
2
|
# all Graph API instances should pass these tests, regardless of configuration
|
|
3
|
+
let(:dummy_response) { double("fake response", data: {}, status: 200, body: "", headers: {}) }
|
|
3
4
|
|
|
4
5
|
# API
|
|
5
6
|
it "never uses the rest api server" do
|
|
@@ -13,80 +14,7 @@ shared_examples_for "Koala GraphAPI" do
|
|
|
13
14
|
@api.api("anything")
|
|
14
15
|
end
|
|
15
16
|
|
|
16
|
-
# GRAPH CALL
|
|
17
|
-
describe "graph_call" do
|
|
18
|
-
it "passes all arguments to the api method" do
|
|
19
|
-
user = KoalaTest.user1
|
|
20
|
-
args = {}
|
|
21
|
-
verb = 'get'
|
|
22
|
-
opts = {:a => :b}
|
|
23
|
-
expect(@api).to receive(:api).with(user, args, verb, opts)
|
|
24
|
-
@api.graph_call(user, args, verb, opts)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
it "throws an APIError if the result hash has an error key" do
|
|
28
|
-
allow(Koala).to receive(:make_request).and_return(Koala::HTTPService::Response.new(500, '{"error": "An error occurred!"}', {}))
|
|
29
|
-
expect { @api.graph_call(KoalaTest.user1, {}) }.to raise_exception(Koala::Facebook::APIError)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
it "passes the results through GraphCollection.evaluate" do
|
|
33
|
-
result = {}
|
|
34
|
-
allow(@api).to receive(:api).and_return(result)
|
|
35
|
-
expect(Koala::Facebook::GraphCollection).to receive(:evaluate).with(result, @api)
|
|
36
|
-
@api.graph_call("/me")
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
it "returns the results of GraphCollection.evaluate" do
|
|
40
|
-
expected = {}
|
|
41
|
-
allow(@api).to receive(:api).and_return([])
|
|
42
|
-
expect(Koala::Facebook::GraphCollection).to receive(:evaluate).and_return(expected)
|
|
43
|
-
expect(@api.graph_call("/me")).to eq(expected)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
it "returns the post_processing block's results if one is supplied" do
|
|
47
|
-
other_result = [:a, 2, :three]
|
|
48
|
-
block = Proc.new {|r| other_result}
|
|
49
|
-
allow(@api).to receive(:api).and_return({})
|
|
50
|
-
expect(@api.graph_call("/me", {}, "get", {}, &block)).to eq(other_result)
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
# SEARCH
|
|
55
|
-
it "can search" do
|
|
56
|
-
result = @api.search("facebook")
|
|
57
|
-
expect(result.length).to be_an(Integer)
|
|
58
|
-
end
|
|
59
|
-
|
|
60
17
|
# DATA
|
|
61
|
-
# access public info
|
|
62
|
-
|
|
63
|
-
# get_object
|
|
64
|
-
it "gets public data about a user" do
|
|
65
|
-
result = @api.get_object(KoalaTest.user1)
|
|
66
|
-
# the results should have an ID and a name, among other things
|
|
67
|
-
expect(result["id"] && result["name"]).not_to be_nil
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
it "gets public data about a Page" do
|
|
71
|
-
result = @api.get_object(KoalaTest.page)
|
|
72
|
-
# the results should have an ID and a name, among other things
|
|
73
|
-
expect(result["id"] && result["name"]).to be_truthy
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
it "returns [] from get_objects if passed an empty array" do
|
|
77
|
-
results = @api.get_objects([])
|
|
78
|
-
expect(results).to eq([])
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
it "gets multiple objects" do
|
|
82
|
-
results = @api.get_objects([KoalaTest.page, KoalaTest.user1])
|
|
83
|
-
expect(results.size).to eq(2)
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
it "gets multiple objects if they're a string" do
|
|
87
|
-
results = @api.get_objects("facebook,#{KoalaTest.user1}")
|
|
88
|
-
expect(results.size).to eq(2)
|
|
89
|
-
end
|
|
90
18
|
|
|
91
19
|
describe "#get_picture" do
|
|
92
20
|
it "can access a user's picture" do
|
|
@@ -123,27 +51,6 @@ shared_examples_for "Koala GraphAPI" do
|
|
|
123
51
|
end
|
|
124
52
|
end
|
|
125
53
|
|
|
126
|
-
it "can access connections from public Pages" do
|
|
127
|
-
result = @api.get_connections(KoalaTest.page, "photos")
|
|
128
|
-
expect(result).to be_a(Array)
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
it "can access comments for a URL" do
|
|
132
|
-
result = @api.get_comments_for_urls(["http://developers.facebook.com/blog/post/472"])
|
|
133
|
-
expect(result["http://developers.facebook.com/blog/post/472"]).to be_truthy
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
it "can access comments for 2 URLs" do
|
|
137
|
-
result = @api.get_comments_for_urls(["http://developers.facebook.com/blog/post/490", "http://developers.facebook.com/blog/post/472"])
|
|
138
|
-
expect(result["http://developers.facebook.com/blog/post/490"] && result["http://developers.facebook.com/blog/post/472"]).to be_truthy
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
# SEARCH
|
|
142
|
-
it "can search" do
|
|
143
|
-
result = @api.search("facebook")
|
|
144
|
-
expect(result.length).to be_an(Integer)
|
|
145
|
-
end
|
|
146
|
-
|
|
147
54
|
# PAGING THROUGH COLLECTIONS
|
|
148
55
|
# see also graph_collection_tests
|
|
149
56
|
it "makes a request for a page when provided a specific set of page params" do
|
|
@@ -151,74 +58,44 @@ shared_examples_for "Koala GraphAPI" do
|
|
|
151
58
|
expect(@api).to receive(:graph_call).with(*query)
|
|
152
59
|
@api.get_page(query)
|
|
153
60
|
end
|
|
61
|
+
end
|
|
154
62
|
|
|
155
|
-
# Beta tier
|
|
156
|
-
it "can use the beta tier" do
|
|
157
|
-
result = @api.get_object(KoalaTest.user1, {}, :beta => true)
|
|
158
|
-
# the results should have an ID and a name, among other things
|
|
159
|
-
expect(result["id"] && result["name"]).to be_truthy
|
|
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
63
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
expect(@api).to receive(:get_object).with(anything, hash_including(:q => query), anything)
|
|
172
|
-
@api.fql_query(query)
|
|
173
|
-
end
|
|
64
|
+
shared_examples_for "Koala GraphAPI with an access token" do
|
|
65
|
+
let(:dummy_response) { double("fake response", data: {}, status: 200, body: "", headers: {}) }
|
|
174
66
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
end
|
|
67
|
+
it "gets public data about a user" do
|
|
68
|
+
result = @api.get_object(KoalaTest.user1)
|
|
69
|
+
# the results should have an ID and a name, among other things
|
|
70
|
+
expect(result["id"] && result["name"]).not_to be_nil
|
|
180
71
|
end
|
|
181
72
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
@api.
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
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)
|
|
73
|
+
it "gets public data about a Page" do
|
|
74
|
+
begin
|
|
75
|
+
Koala::Utils.level = 0
|
|
76
|
+
result = @api.get_object(KoalaTest.page)
|
|
77
|
+
# the results should have an ID and a name, among other things
|
|
78
|
+
expect(result["id"] && result["name"]).to be_truthy
|
|
79
|
+
ensure
|
|
80
|
+
Koala::Utils.level = Logger::ERROR
|
|
195
81
|
end
|
|
82
|
+
end
|
|
196
83
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
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
|
|
84
|
+
it "returns [] from get_objects if passed an empty array" do
|
|
85
|
+
results = @api.get_objects([])
|
|
86
|
+
expect(results).to eq([])
|
|
87
|
+
end
|
|
211
88
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
@api.fql_multiquery("a query", args)
|
|
216
|
-
end
|
|
89
|
+
it "gets multiple objects" do
|
|
90
|
+
results = @api.get_objects([KoalaTest.page, KoalaTest.user1])
|
|
91
|
+
expect(results.size).to eq(2)
|
|
217
92
|
end
|
|
218
|
-
end
|
|
219
93
|
|
|
94
|
+
it "gets multiple objects if they're a string" do
|
|
95
|
+
results = @api.get_objects("facebook,#{KoalaTest.user1}")
|
|
96
|
+
expect(results.size).to eq(2)
|
|
97
|
+
end
|
|
220
98
|
|
|
221
|
-
shared_examples_for "Koala GraphAPI with an access token" do
|
|
222
99
|
it "gets private data about a user" do
|
|
223
100
|
result = @api.get_object(KoalaTest.user1)
|
|
224
101
|
# updated_time should be a pretty fixed test case
|
|
@@ -231,8 +108,18 @@ shared_examples_for "Koala GraphAPI with an access token" do
|
|
|
231
108
|
end
|
|
232
109
|
|
|
233
110
|
it "gets multiple objects" do
|
|
234
|
-
|
|
235
|
-
|
|
111
|
+
begin
|
|
112
|
+
Koala::Utils.level = 0
|
|
113
|
+
result = @api.get_objects([KoalaTest.page, KoalaTest.user1])
|
|
114
|
+
expect(result.length).to eq(2)
|
|
115
|
+
ensure
|
|
116
|
+
Koala::Utils.level = Logger::ERROR
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
it "can access connections from public Pages" do
|
|
121
|
+
result = @api.get_connections(KoalaTest.page, "events")
|
|
122
|
+
expect(result).to be_a(Array)
|
|
236
123
|
end
|
|
237
124
|
|
|
238
125
|
describe "#get_object_metadata" do
|
|
@@ -243,10 +130,16 @@ shared_examples_for "Koala GraphAPI with an access token" do
|
|
|
243
130
|
end
|
|
244
131
|
|
|
245
132
|
it "can access connections from users" do
|
|
246
|
-
result = @api.get_connections(KoalaTest.user2, "
|
|
133
|
+
result = @api.get_connections(KoalaTest.user2, "likes")
|
|
247
134
|
expect(result.length).to be > 0
|
|
248
135
|
end
|
|
249
136
|
|
|
137
|
+
# SEARCH
|
|
138
|
+
it "can search" do
|
|
139
|
+
result = @api.search("facebook", type: "page")
|
|
140
|
+
expect(result.length).to be_an(Integer)
|
|
141
|
+
end
|
|
142
|
+
|
|
250
143
|
# PUT
|
|
251
144
|
it "can write an object to the graph" do
|
|
252
145
|
result = @api.put_wall_post("Hello, world, from the test suite!")
|
|
@@ -259,7 +152,7 @@ shared_examples_for "Koala GraphAPI with an access token" do
|
|
|
259
152
|
result = @api.put_wall_post("Hello, world, from the test suite delete method!")
|
|
260
153
|
object_id_to_delete = result["id"]
|
|
261
154
|
delete_result = @api.delete_object(object_id_to_delete)
|
|
262
|
-
expect(delete_result).to eq(true)
|
|
155
|
+
expect(delete_result).to eq("success" => true)
|
|
263
156
|
end
|
|
264
157
|
|
|
265
158
|
it "can delete likes" do
|
|
@@ -267,7 +160,7 @@ shared_examples_for "Koala GraphAPI with an access token" do
|
|
|
267
160
|
@temporary_object_id = result["id"]
|
|
268
161
|
@api.put_like(@temporary_object_id)
|
|
269
162
|
delete_like_result = @api.delete_like(@temporary_object_id)
|
|
270
|
-
expect(delete_like_result).to eq(true)
|
|
163
|
+
expect(delete_like_result).to eq("success" => true)
|
|
271
164
|
end
|
|
272
165
|
|
|
273
166
|
# additional put tests
|
|
@@ -282,7 +175,7 @@ shared_examples_for "Koala GraphAPI with an access token" do
|
|
|
282
175
|
end
|
|
283
176
|
|
|
284
177
|
it "can post a message with an attachment to a feed" do
|
|
285
|
-
result = @api.put_wall_post("Hello, world, from the test suite again!", {:name => "OAuth Playground", :link => "http://
|
|
178
|
+
result = @api.put_wall_post("Hello, world, from the test suite again!", {:name => "OAuth Playground", :link => "http://testdomain.koalatest.test/"})
|
|
286
179
|
@temporary_object_id = result["id"]
|
|
287
180
|
expect(@temporary_object_id).not_to be_nil
|
|
288
181
|
end
|
|
@@ -310,52 +203,53 @@ shared_examples_for "Koala GraphAPI with an access token" do
|
|
|
310
203
|
end
|
|
311
204
|
|
|
312
205
|
describe "#put_picture" do
|
|
313
|
-
|
|
314
|
-
content_type
|
|
315
|
-
file
|
|
206
|
+
context "with a file object" do
|
|
207
|
+
let(:content_type) { "image/jpg" }
|
|
208
|
+
let(:file) { File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "beach.jpg")) }
|
|
209
|
+
let(:file_path) { File.join(File.dirname(__FILE__), "..", "fixtures", "beach.jpg") }
|
|
316
210
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
it "can post photos to the user's wall without an open file object" do
|
|
323
|
-
content_type = "image/jpg",
|
|
324
|
-
file_path = File.join(File.dirname(__FILE__), "..", "fixtures", "beach.jpg")
|
|
211
|
+
it "can post photos to the user's wall with an open file object" do
|
|
212
|
+
result = @api.put_picture(file, content_type)
|
|
213
|
+
@temporary_object_id = result["id"]
|
|
214
|
+
expect(@temporary_object_id).not_to be_nil
|
|
215
|
+
end
|
|
325
216
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
217
|
+
it "can post photos to the user's wall without an open file object" do
|
|
218
|
+
result = @api.put_picture(file_path, content_type)
|
|
219
|
+
@temporary_object_id = result["id"]
|
|
220
|
+
expect(@temporary_object_id).not_to be_nil
|
|
221
|
+
end
|
|
330
222
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
file_path = File.join(File.dirname(__FILE__), "..", "fixtures", "beach.jpg")
|
|
223
|
+
it "can verify a photo posted to a user's wall" do
|
|
224
|
+
expected_message = "This is the test message"
|
|
334
225
|
|
|
335
|
-
|
|
226
|
+
result = @api.put_picture(file_path, content_type, :message => expected_message)
|
|
227
|
+
@temporary_object_id = result["id"]
|
|
228
|
+
expect(@temporary_object_id).not_to be_nil
|
|
336
229
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
230
|
+
get_result = @api.get_object(@temporary_object_id)
|
|
231
|
+
expect(get_result["name"]).to eq(expected_message)
|
|
232
|
+
end
|
|
340
233
|
|
|
341
|
-
|
|
342
|
-
|
|
234
|
+
it "passes options and block through" do
|
|
235
|
+
opts = {a: 2}
|
|
236
|
+
block = Proc.new {}
|
|
237
|
+
expect(@api).to receive(:graph_call).with(anything, anything, anything, hash_including(opts), &block)
|
|
238
|
+
@api.put_picture(file_path, content_type, {:message => "my message"}, "target", opts, &block)
|
|
239
|
+
end
|
|
343
240
|
end
|
|
344
241
|
|
|
345
|
-
|
|
346
242
|
describe "using a URL instead of a file" do
|
|
347
|
-
|
|
348
|
-
@url = "http://img.slate.com/images/redesign2008/slate_logo.gif"
|
|
349
|
-
end
|
|
243
|
+
let(:url) { "http://img.slate.com/images/redesign2008/slate_logo.gif" }
|
|
350
244
|
|
|
351
245
|
it "can post photo to the user's wall using a URL" do
|
|
352
|
-
result = @api.put_picture(
|
|
246
|
+
result = @api.put_picture(url)
|
|
353
247
|
@temporary_object_id = result["id"]
|
|
354
248
|
expect(@temporary_object_id).not_to be_nil
|
|
355
249
|
end
|
|
356
250
|
|
|
357
|
-
it "can post photo to the user's wall using
|
|
358
|
-
result = @api.put_picture(
|
|
251
|
+
it "can post photo to the user's wall using aurl and an additional param" do
|
|
252
|
+
result = @api.put_picture(url, :message => "my message")
|
|
359
253
|
@temporary_object_id = result["id"]
|
|
360
254
|
expect(@temporary_object_id).not_to be_nil
|
|
361
255
|
end
|
|
@@ -363,29 +257,35 @@ shared_examples_for "Koala GraphAPI with an access token" do
|
|
|
363
257
|
end
|
|
364
258
|
|
|
365
259
|
describe "#put_video" do
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
@content_type = "video/mpeg4"
|
|
369
|
-
end
|
|
260
|
+
let(:cat_movie) { File.join(File.dirname(__FILE__), "..", "fixtures", "cat.m4v") }
|
|
261
|
+
let(:content_type) { "video/mpeg4" }
|
|
370
262
|
|
|
371
263
|
it "sets options[:video] to true" do
|
|
372
264
|
source = double("UploadIO")
|
|
373
|
-
allow(Koala::UploadableIO).to receive(:new).and_return(source)
|
|
265
|
+
allow(Koala::HTTPService::UploadableIO).to receive(:new).and_return(source)
|
|
374
266
|
allow(source).to receive(:requires_base_http_service).and_return(false)
|
|
375
267
|
expect(Koala).to receive(:make_request).with(anything, anything, anything, hash_including(:video => true)).and_return(Koala::HTTPService::Response.new(200, "[]", {}))
|
|
376
268
|
@api.put_video("foo")
|
|
377
269
|
end
|
|
378
270
|
|
|
271
|
+
it "passes options and block through" do
|
|
272
|
+
opts = {a: 2}
|
|
273
|
+
block = Proc.new {}
|
|
274
|
+
expect(@api).to receive(:graph_call).with(anything, anything, anything, hash_including(opts), &block)
|
|
275
|
+
file = File.open(cat_movie)
|
|
276
|
+
@api.put_video(file, content_type, {}, "target", opts, &block)
|
|
277
|
+
end
|
|
278
|
+
|
|
379
279
|
it "can post videos to the user's wall with an open file object" do
|
|
380
|
-
file = File.open(
|
|
280
|
+
file = File.open(cat_movie)
|
|
381
281
|
|
|
382
|
-
result = @api.put_video(file,
|
|
282
|
+
result = @api.put_video(file, content_type)
|
|
383
283
|
@temporary_object_id = result["id"]
|
|
384
284
|
expect(@temporary_object_id).not_to be_nil
|
|
385
285
|
end
|
|
386
286
|
|
|
387
287
|
it "can post videos to the user's wall without an open file object" do
|
|
388
|
-
result = @api.put_video(
|
|
288
|
+
result = @api.put_video(cat_movie, content_type)
|
|
389
289
|
@temporary_object_id = result["id"]
|
|
390
290
|
expect(@temporary_object_id).not_to be_nil
|
|
391
291
|
end
|
|
@@ -393,21 +293,17 @@ shared_examples_for "Koala GraphAPI with an access token" do
|
|
|
393
293
|
# note: Facebook doesn't post videos immediately to the wall, due to processing time
|
|
394
294
|
# during which get_object(video_id) will return false
|
|
395
295
|
# hence we can't do the same verify test we do for photos
|
|
296
|
+
describe "using aurl instead of a file" do
|
|
297
|
+
let(:url) { "http://techslides.com/demos/sample-videos/small.mp4" }
|
|
396
298
|
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
before :each do
|
|
400
|
-
@url = "http://techslides.com/demos/sample-videos/small.mp4"
|
|
401
|
-
end
|
|
402
|
-
|
|
403
|
-
it "can post photo to the user's wall using a URL" do
|
|
404
|
-
result = @api.put_video(@url)
|
|
299
|
+
it "can post photo to the user's wall using aurl" do
|
|
300
|
+
result = @api.put_video(url)
|
|
405
301
|
@temporary_object_id = result["id"]
|
|
406
302
|
expect(@temporary_object_id).not_to be_nil
|
|
407
303
|
end
|
|
408
304
|
|
|
409
|
-
it "can post photo to the user's wall using
|
|
410
|
-
result = @api.put_video(
|
|
305
|
+
it "can post photo to the user's wall using aurl and an additional param" do
|
|
306
|
+
result = @api.put_video(url, :description => "my message")
|
|
411
307
|
@temporary_object_id = result["id"]
|
|
412
308
|
expect(@temporary_object_id).not_to be_nil
|
|
413
309
|
end
|
|
@@ -415,14 +311,14 @@ shared_examples_for "Koala GraphAPI with an access token" do
|
|
|
415
311
|
end
|
|
416
312
|
|
|
417
313
|
it "can verify a message with an attachment posted to a feed" do
|
|
418
|
-
attachment = {"name" => "OAuth Playground", "link" => "http://
|
|
314
|
+
attachment = {"name" => "OAuth Playground", "link" => "http://testdomain.koalatest.test/"}
|
|
419
315
|
result = @api.put_wall_post("Hello, world, from the test suite again!", attachment)
|
|
420
316
|
@temporary_object_id = result["id"]
|
|
421
317
|
get_result = @api.get_object(@temporary_object_id)
|
|
422
318
|
|
|
423
319
|
# make sure the result we fetch includes all the parameters we sent
|
|
424
320
|
it_matches = attachment.inject(true) {|valid, param| valid && (get_result[param[0]] == attachment[param[0]])}
|
|
425
|
-
expect(it_matches).to
|
|
321
|
+
expect(it_matches).to be true
|
|
426
322
|
end
|
|
427
323
|
|
|
428
324
|
it "can comment on an object" do
|
|
@@ -451,7 +347,8 @@ shared_examples_for "Koala GraphAPI with an access token" do
|
|
|
451
347
|
it "can like an object" do
|
|
452
348
|
result = @api.put_wall_post("Hello, world, from the test suite, testing liking!")
|
|
453
349
|
@temporary_object_id = result["id"]
|
|
454
|
-
|
|
350
|
+
app_api = Koala::Facebook::API.new(@app_access_token)
|
|
351
|
+
like_result = app_api.put_like(@temporary_object_id)
|
|
455
352
|
expect(like_result).to be_truthy
|
|
456
353
|
end
|
|
457
354
|
|
|
@@ -459,14 +356,14 @@ shared_examples_for "Koala GraphAPI with an access token" do
|
|
|
459
356
|
describe "#get_page_access_token" do
|
|
460
357
|
it "gets the page object with the access_token field" do
|
|
461
358
|
# we can't test this live since test users (or random real users) can't be guaranteed to have pages to manage
|
|
462
|
-
expect(@api).to receive(:api).with("my_page", hash_including({:fields => "access_token"}), "get", anything)
|
|
359
|
+
expect(@api).to receive(:api).with("my_page", hash_including({:fields => "access_token"}), "get", anything).and_return(dummy_response)
|
|
463
360
|
@api.get_page_access_token("my_page")
|
|
464
361
|
end
|
|
465
362
|
|
|
466
363
|
it "merges in any other arguments" do
|
|
467
364
|
# we can't test this live since test users (or random real users) can't be guaranteed to have pages to manage
|
|
468
365
|
args = {:a => 3}
|
|
469
|
-
expect(@api).to receive(:api).with("my_page", hash_including(args), "get", anything)
|
|
366
|
+
expect(@api).to receive(:api).with("my_page", hash_including(args), "get", anything).and_return(dummy_response)
|
|
470
367
|
@api.get_page_access_token("my_page", args)
|
|
471
368
|
end
|
|
472
369
|
end
|
|
@@ -508,87 +405,26 @@ shared_examples_for "Koala GraphAPI with an access token" do
|
|
|
508
405
|
end
|
|
509
406
|
end
|
|
510
407
|
|
|
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
408
|
# test all methods to make sure they pass data through to the API
|
|
557
409
|
# we run the tests here (rather than in the common shared example group)
|
|
558
410
|
# since some require access tokens
|
|
559
411
|
describe "HTTP options" do
|
|
560
|
-
# Each of the below methods should take an options hash as their last argument
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
:
|
|
568
|
-
:
|
|
569
|
-
:
|
|
570
|
-
:
|
|
571
|
-
|
|
572
|
-
:search => 3,
|
|
573
|
-
:set_app_restrictions => 4,
|
|
574
|
-
:get_page_access_token => 3,
|
|
575
|
-
:fql_query => 3, :fql_multiquery => 3,
|
|
576
|
-
# methods that have special arguments
|
|
577
|
-
:get_comments_for_urls => [["url1", "url2"], {}],
|
|
578
|
-
:put_picture => ["x.jpg", "image/jpg", {}, "me"],
|
|
579
|
-
:put_video => ["x.mp4", "video/mpeg4", {}, "me"],
|
|
580
|
-
:get_objects => [["x"], {}]
|
|
581
|
-
}.each_pair do |method_name, params|
|
|
412
|
+
# Each of the below methods should take an options hash as their last argument.
|
|
413
|
+
[
|
|
414
|
+
:get_object,
|
|
415
|
+
:get_connections,
|
|
416
|
+
:put_wall_post,
|
|
417
|
+
:put_comment,
|
|
418
|
+
:put_like,
|
|
419
|
+
:search,
|
|
420
|
+
:set_app_restrictions,
|
|
421
|
+
:get_page_access_token,
|
|
422
|
+
:get_objects
|
|
423
|
+
].each do |method_name|
|
|
582
424
|
it "passes http options through for #{method_name}" do
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
expect(
|
|
586
|
-
|
|
587
|
-
# if we supply args, use them (since some methods process params)
|
|
588
|
-
# the method should receive as args n-1 anythings and then options
|
|
589
|
-
args = (params.is_a?(Integer) ? ([{}] * (params - 1)) : params) + [options]
|
|
590
|
-
|
|
591
|
-
@api.send(method_name, *args)
|
|
425
|
+
params = @api.method(method_name).parameters
|
|
426
|
+
expect(params.last).to eq([:block, :block])
|
|
427
|
+
expect(params[-2]).to eq([:opt, :options])
|
|
592
428
|
end
|
|
593
429
|
end
|
|
594
430
|
|
|
@@ -600,16 +436,26 @@ shared_examples_for "Koala GraphAPI with an access token" do
|
|
|
600
436
|
@api.send(:get_picture, "x", {}, options)
|
|
601
437
|
end
|
|
602
438
|
end
|
|
439
|
+
|
|
440
|
+
# Beta tier
|
|
441
|
+
# In theory this is usable by both but so few operations now allow access without a token
|
|
442
|
+
it "can use the beta tier" do
|
|
443
|
+
result = @api.get_object(KoalaTest.user1, {}, :beta => true)
|
|
444
|
+
# the results should have an ID and a name, among other things
|
|
445
|
+
expect(result["id"] && result["name"]).to be_truthy
|
|
446
|
+
end
|
|
603
447
|
end
|
|
604
448
|
|
|
605
449
|
|
|
606
450
|
# GraphCollection
|
|
607
451
|
shared_examples_for "Koala GraphAPI with GraphCollection" do
|
|
452
|
+
let(:dummy_response) { double("fake response", data: {}, status: 200, body: "", headers: {}) }
|
|
453
|
+
|
|
608
454
|
describe "when getting a collection" do
|
|
609
455
|
# GraphCollection methods
|
|
610
456
|
it "gets a GraphCollection when getting connections" do
|
|
611
|
-
@result = @api.get_connections(KoalaTest.page, "
|
|
612
|
-
expect(@result).to be_a(Koala::Facebook::GraphCollection)
|
|
457
|
+
@result = @api.get_connections(KoalaTest.page, "events")
|
|
458
|
+
expect(@result).to be_a(Koala::Facebook::API::GraphCollection)
|
|
613
459
|
end
|
|
614
460
|
|
|
615
461
|
it "returns nil if the get_collections call fails with nil" do
|
|
@@ -619,43 +465,37 @@ shared_examples_for "Koala GraphAPI with GraphCollection" do
|
|
|
619
465
|
end
|
|
620
466
|
|
|
621
467
|
it "gets a GraphCollection when searching" do
|
|
622
|
-
result = @api.search("facebook")
|
|
623
|
-
expect(result).to be_a(Koala::Facebook::GraphCollection)
|
|
468
|
+
result = @api.search("facebook", type: "page")
|
|
469
|
+
expect(result).to be_a(Koala::Facebook::API::GraphCollection)
|
|
624
470
|
end
|
|
625
471
|
|
|
626
472
|
it "returns nil if the search call fails with nil" do
|
|
627
473
|
# this happens sometimes
|
|
628
474
|
expect(@api).to receive(:graph_call).and_return(nil)
|
|
629
|
-
expect(@api.search("facebook")).to be_nil
|
|
475
|
+
expect(@api.search("facebook", type: "page")).to be_nil
|
|
630
476
|
end
|
|
631
477
|
|
|
632
478
|
it "gets a GraphCollection when paging through results" do
|
|
633
|
-
@results = @api.get_page(["search", {"q"=>"facebook", "limit"=>"25", "until"=> KoalaTest.search_time}])
|
|
634
|
-
expect(@results).to be_a(Koala::Facebook::GraphCollection)
|
|
479
|
+
@results = @api.get_page(["search", {"q"=>"facebook", "type" => "page", "limit"=>"25", "until"=> KoalaTest.search_time}])
|
|
480
|
+
expect(@results).to be_a(Koala::Facebook::API::GraphCollection)
|
|
635
481
|
end
|
|
636
482
|
|
|
637
483
|
it "returns nil if the page call fails with nil" do
|
|
638
484
|
# this happens sometimes
|
|
639
485
|
expect(@api).to receive(:graph_call).and_return(nil)
|
|
640
|
-
expect(@api.get_page(["search", {"q"=>"facebook", "limit"=>"25", "until"=> KoalaTest.search_time}])).to be_nil
|
|
486
|
+
expect(@api.get_page(["search", {"q"=>"facebook", "type" => "page", "limit"=>"25", "until"=> KoalaTest.search_time}])).to be_nil
|
|
641
487
|
end
|
|
642
488
|
end
|
|
643
489
|
end
|
|
644
490
|
|
|
645
491
|
|
|
646
492
|
shared_examples_for "Koala GraphAPI without an access token" do
|
|
647
|
-
it "can't get private data about a user" do
|
|
648
|
-
result = @api.get_object(KoalaTest.user1)
|
|
649
|
-
# updated_time should be a pretty fixed test case
|
|
650
|
-
expect(result["updated_time"]).to be_nil
|
|
651
|
-
end
|
|
652
|
-
|
|
653
493
|
it "can't get data about 'me'" do
|
|
654
494
|
expect { @api.get_object("me") }.to raise_error(Koala::Facebook::ClientError)
|
|
655
495
|
end
|
|
656
496
|
|
|
657
497
|
it "can't access connections from users" do
|
|
658
|
-
expect { @api.get_connections(KoalaTest.user2, "
|
|
498
|
+
expect { @api.get_connections(KoalaTest.user2, "likes") }.to raise_error(Koala::Facebook::ClientError)
|
|
659
499
|
end
|
|
660
500
|
|
|
661
501
|
it "can't put an object" do
|
|
@@ -668,7 +508,7 @@ shared_examples_for "Koala GraphAPI without an access token" do
|
|
|
668
508
|
# but are here for completeness
|
|
669
509
|
it "can't post to a feed" do
|
|
670
510
|
expect(lambda do
|
|
671
|
-
attachment = {:name => "OAuth Playground", :link => "http://
|
|
511
|
+
attachment = {:name => "OAuth Playground", :link => "http://testdomain.koalatest.test/"}
|
|
672
512
|
@result = @api.put_wall_post("Hello, world", attachment, "facebook")
|
|
673
513
|
end).to raise_error(Koala::Facebook::AuthenticationError)
|
|
674
514
|
end
|
|
@@ -691,37 +531,4 @@ shared_examples_for "Koala GraphAPI without an access token" do
|
|
|
691
531
|
it "can't delete a like" do
|
|
692
532
|
expect { @api.delete_like("7204941866_119776748033392") }.to raise_error(Koala::Facebook::AuthenticationError)
|
|
693
533
|
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
534
|
end
|