koala 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. data/.gitignore +3 -1
  2. data/.rspec +1 -0
  3. data/.travis.yml +4 -0
  4. data/.yardopts +3 -0
  5. data/CHANGELOG +43 -0
  6. data/Gemfile +14 -0
  7. data/Guardfile +6 -0
  8. data/koala.gemspec +4 -4
  9. data/lib/koala/api/batch_operation.rb +83 -0
  10. data/lib/koala/api/graph_api.rb +476 -0
  11. data/lib/koala/{graph_batch_api.rb → api/graph_batch_api.rb} +22 -17
  12. data/lib/koala/api/graph_collection.rb +107 -0
  13. data/lib/koala/api/legacy.rb +26 -0
  14. data/lib/koala/{rest_api.rb → api/rest_api.rb} +36 -10
  15. data/lib/koala/api.rb +93 -0
  16. data/lib/koala/http_service/multipart_request.rb +41 -0
  17. data/lib/koala/http_service/response.rb +18 -0
  18. data/lib/koala/http_service/uploadable_io.rb +187 -0
  19. data/lib/koala/http_service.rb +73 -23
  20. data/lib/koala/oauth.rb +173 -36
  21. data/lib/koala/realtime_updates.rb +89 -51
  22. data/lib/koala/test_users.rb +122 -32
  23. data/lib/koala/utils.rb +11 -4
  24. data/lib/koala/version.rb +1 -1
  25. data/lib/koala.rb +16 -95
  26. data/readme.md +30 -13
  27. data/spec/cases/api_spec.rb +28 -21
  28. data/spec/cases/error_spec.rb +10 -0
  29. data/spec/cases/graph_api_batch_spec.rb +100 -58
  30. data/spec/cases/graph_collection_spec.rb +23 -7
  31. data/spec/cases/http_service_spec.rb +14 -34
  32. data/spec/cases/koala_spec.rb +22 -4
  33. data/spec/cases/legacy_spec.rb +115 -0
  34. data/spec/cases/multipart_request_spec.rb +66 -0
  35. data/spec/cases/oauth_spec.rb +232 -108
  36. data/spec/cases/realtime_updates_spec.rb +154 -47
  37. data/spec/cases/test_users_spec.rb +276 -217
  38. data/spec/cases/uploadable_io_spec.rb +1 -1
  39. data/spec/cases/utils_spec.rb +29 -5
  40. data/spec/fixtures/mock_facebook_responses.yml +50 -26
  41. data/spec/spec_helper.rb +3 -0
  42. data/spec/support/custom_matchers.rb +28 -0
  43. data/spec/support/graph_api_shared_examples.rb +274 -70
  44. data/spec/support/koala_test.rb +27 -16
  45. data/spec/support/mock_http_service.rb +2 -2
  46. data/spec/support/rest_api_shared_examples.rb +46 -162
  47. metadata +33 -25
  48. data/lib/koala/batch_operation.rb +0 -74
  49. data/lib/koala/graph_api.rb +0 -270
  50. data/lib/koala/graph_collection.rb +0 -59
  51. data/lib/koala/uploadable_io.rb +0 -181
  52. data/spec/cases/graph_and_rest_api_spec.rb +0 -22
  53. data/spec/cases/graph_api_spec.rb +0 -22
  54. data/spec/cases/rest_api_spec.rb +0 -41
@@ -4,6 +4,7 @@ module KoalaTest
4
4
  class << self
5
5
  attr_accessor :oauth_token, :app_id, :secret, :app_access_token, :code, :session_key
6
6
  attr_accessor :oauth_test_data, :subscription_test_data, :search_time
7
+ attr_accessor :test_user_api
7
8
  end
8
9
 
9
10
  # Test setup
@@ -28,7 +29,7 @@ module KoalaTest
28
29
  KoalaTest.setup_test_data(live_data)
29
30
 
30
31
  # allow live tests with different adapters
31
- adapter = ENV['ADAPTER'] || "typhoeus"# use Typhoeus by default if available
32
+ adapter = ENV['ADAPTER'] || "typhoeus" # use Typhoeus by default if available
32
33
  begin
33
34
  require adapter
34
35
  Faraday.default_adapter = adapter.to_sym
@@ -57,16 +58,16 @@ module KoalaTest
57
58
  end
58
59
 
59
60
  config.after :each do
60
- # clean up any objects posted to Facebook
61
- if @temporary_object_id && !KoalaTest.mock_interface?
62
- api = @api || (@test_users ? @test_users.graph_api : nil)
63
- raise "Unable to locate API when passed temporary object to delete!" unless api
61
+ # if we're working with a real user, clean up any objects posted to Facebook
62
+ # no need to do so for test users, since they get deleted at the end
63
+ if @temporary_object_id && KoalaTest.real_user?
64
+ raise "Unable to locate API when passed temporary object to delete!" unless @api
64
65
 
65
66
  # wait 10ms to allow Facebook to propagate data so we can delete it
66
67
  sleep(0.01)
67
68
 
68
69
  # clean up any objects we've posted
69
- result = (api.delete_object(@temporary_object_id) rescue false)
70
+ result = (@api.delete_object(@temporary_object_id) rescue false)
70
71
  # if we errored out or Facebook returned false, track that
71
72
  puts "Unable to delete #{@temporary_object_id}: #{result} (probably a photo or video, which can't be deleted through the API)" unless result
72
73
  end
@@ -94,19 +95,16 @@ module KoalaTest
94
95
  end
95
96
 
96
97
  def self.setup_test_users
97
- # note: we don't have to delete the two test users explicitly, since the test user specs do that for us
98
- # technically, this is a point of brittleness and would break if the tests were run out of order
99
- # however, for now we can live with it since it would slow tests way too much to constantly recreate our test users
100
98
  print "Setting up test users..."
101
99
  @test_user_api = Koala::Facebook::TestUsers.new(:app_id => self.app_id, :secret => self.secret)
102
100
 
103
101
  RSpec.configure do |config|
104
- config.before :all do
102
+ config.before :suite do
105
103
  # before each test module, create two test users with specific names and befriend them
106
104
  KoalaTest.create_test_users
107
105
  end
108
106
 
109
- config.after :all do
107
+ config.after :suite do
110
108
  # after each test module, delete the test users to avoid cluttering up the application
111
109
  KoalaTest.destroy_test_users
112
110
  end
@@ -116,10 +114,15 @@ module KoalaTest
116
114
  end
117
115
 
118
116
  def self.create_test_users
119
- @live_testing_user = @test_user_api.create(true, KoalaTest.testing_permissions, :name => KoalaTest.user1_name)
120
- @live_testing_friend = @test_user_api.create(true, KoalaTest.testing_permissions, :name => KoalaTest.user2_name)
121
- @test_user_api.befriend(@live_testing_user, @live_testing_friend)
122
- self.oauth_token = @live_testing_user["access_token"]
117
+ begin
118
+ @live_testing_user = @test_user_api.create(true, KoalaTest.testing_permissions, :name => KoalaTest.user1_name)
119
+ @live_testing_friend = @test_user_api.create(true, KoalaTest.testing_permissions, :name => KoalaTest.user2_name)
120
+ @test_user_api.befriend(@live_testing_user, @live_testing_friend)
121
+ self.oauth_token = @live_testing_user["access_token"]
122
+ rescue Exception => e
123
+ Kernel.warn("Problem creating test users! #{e.message}")
124
+ raise
125
+ end
123
126
  end
124
127
 
125
128
  def self.destroy_test_users
@@ -144,7 +147,7 @@ module KoalaTest
144
147
 
145
148
  # Info about the testing environment
146
149
  def self.real_user?
147
- !(mock_interface? || @test_user)
150
+ !(mock_interface? || @test_user_api)
148
151
  end
149
152
 
150
153
  def self.test_user?
@@ -157,10 +160,13 @@ module KoalaTest
157
160
 
158
161
  # Data for testing
159
162
  def self.user1
163
+ # user ID, either numeric or username
160
164
  test_user? ? @live_testing_user["id"] : "koppel"
161
165
  end
162
166
 
163
167
  def self.user1_id
168
+ # numerical ID, used for FQL
169
+ # (otherwise the two IDs are interchangeable)
164
170
  test_user? ? @live_testing_user["id"] : 2905623
165
171
  end
166
172
 
@@ -169,10 +175,12 @@ module KoalaTest
169
175
  end
170
176
 
171
177
  def self.user2
178
+ # see notes for user1
172
179
  test_user? ? @live_testing_friend["id"] : "lukeshepard"
173
180
  end
174
181
 
175
182
  def self.user2_id
183
+ # see notes for user1
176
184
  test_user? ? @live_testing_friend["id"] : 2901279
177
185
  end
178
186
 
@@ -184,4 +192,7 @@ module KoalaTest
184
192
  "contextoptional"
185
193
  end
186
194
 
195
+ def self.app_properties
196
+ mock_interface? ? {"desktop" => 0} : {"description" => "A test framework for Koala and its users. (#{rand(10000).to_i})"}
197
+ end
187
198
  end
@@ -56,9 +56,9 @@ module Koala
56
56
 
57
57
  # create response class object
58
58
  response_object = if response.is_a? String
59
- Koala::Response.new(200, response, {})
59
+ Koala::HTTPService::Response.new(200, response, {})
60
60
  else
61
- Koala::Response.new(response["code"] || 200, response["body"] || "", response["headers"] || {})
61
+ Koala::HTTPService::Response.new(response["code"] || 200, response["body"] || "", response["headers"] || {})
62
62
  end
63
63
 
64
64
  rescue NoMethodError
@@ -1,7 +1,7 @@
1
1
  shared_examples_for "Koala RestAPI" do
2
2
  # REST_CALL
3
3
  describe "when making a rest request" do
4
- it "should use the proper path" do
4
+ it "uses the proper path" do
5
5
  method = stub('methodName')
6
6
  @api.should_receive(:api).with(
7
7
  "method/#{method}",
@@ -13,7 +13,7 @@ shared_examples_for "Koala RestAPI" do
13
13
  @api.rest_call(method)
14
14
  end
15
15
 
16
- it "should always use the rest api" do
16
+ it "always uses the rest api" do
17
17
  @api.should_receive(:api).with(
18
18
  anything,
19
19
  anything,
@@ -24,7 +24,7 @@ shared_examples_for "Koala RestAPI" do
24
24
  @api.rest_call('anything')
25
25
  end
26
26
 
27
- it "should set the read_only option to true if the method is listed in the read-only list" do
27
+ it "sets the read_only option to true if the method is listed in the read-only list" do
28
28
  method = Koala::Facebook::RestAPI::READ_ONLY_METHODS.first
29
29
 
30
30
  @api.should_receive(:api).with(
@@ -37,7 +37,7 @@ shared_examples_for "Koala RestAPI" do
37
37
  @api.rest_call(method)
38
38
  end
39
39
 
40
- it "should set the read_only option to false if the method is not inthe read-only list" do
40
+ it "sets the read_only option to false if the method is not inthe read-only list" do
41
41
  method = "I'm not a read-only method"
42
42
 
43
43
  @api.should_receive(:api).with(
@@ -51,7 +51,7 @@ shared_examples_for "Koala RestAPI" do
51
51
  end
52
52
 
53
53
 
54
- it "should take an optional hash of arguments" do
54
+ it "takes an optional hash of arguments" do
55
55
  args = {:arg1 => 'arg1'}
56
56
 
57
57
  @api.should_receive(:api).with(
@@ -64,7 +64,7 @@ shared_examples_for "Koala RestAPI" do
64
64
  @api.rest_call('anything', args)
65
65
  end
66
66
 
67
- it "should always ask for JSON" do
67
+ it "always asks for JSON" do
68
68
  @api.should_receive(:api).with(
69
69
  anything,
70
70
  hash_including('format' => 'json'),
@@ -75,7 +75,7 @@ shared_examples_for "Koala RestAPI" do
75
75
  @api.rest_call('anything')
76
76
  end
77
77
 
78
- it "should pass any options provided to the API" do
78
+ it "passes any options provided to the API" do
79
79
  options = {:a => 2}
80
80
 
81
81
  @api.should_receive(:api).with(
@@ -111,175 +111,59 @@ shared_examples_for "Koala RestAPI" do
111
111
  @api.rest_call('anything', {}, {}, method)
112
112
  end
113
113
 
114
- it "should throw an APIError if the result hash has an error key" do
115
- Koala.stub(:make_request).and_return(Koala::Response.new(500, {"error_code" => "An error occurred!"}, {}))
116
- lambda { @api.rest_call("koppel", {}) }.should raise_exception(Koala::Facebook::APIError)
114
+ it "throws an APIError if the result hash has an error key" do
115
+ Koala.stub(:make_request).and_return(Koala::HTTPService::Response.new(500, {"error_code" => "An error occurred!"}, {}))
116
+ lambda { @api.rest_call(KoalaTest.user1, {}) }.should raise_exception(Koala::Facebook::APIError)
117
117
  end
118
+ end
118
119
 
119
- describe "when making a FQL request" do
120
- it "should call fql.query method" do
121
- @api.should_receive(:rest_call).with(
122
- "fql.query", anything, anything
123
- ).and_return(Koala::Response.new(200, "2", {}))
124
-
125
- @api.fql_query stub('query string')
126
- end
127
-
128
- it "should pass a query argument" do
129
- query = stub('query string')
130
-
131
- @api.should_receive(:rest_call).with(
132
- anything, hash_including(:query => query), anything
133
- )
134
-
135
- @api.fql_query(query)
136
- end
137
-
138
- it "should pass on any other arguments provided" do
139
- args = {:a => 2}
140
- @api.should_receive(:rest_call).with(anything, hash_including(args), anything)
141
- @api.fql_query("a query", args)
142
- end
143
-
144
- it "should pass on any http options provided" do
145
- opts = {:a => 2}
146
- @api.should_receive(:rest_call).with(anything, anything, hash_including(opts))
147
- @api.fql_query("a query", {}, opts)
148
- end
149
- end
150
-
151
- describe "when making a FQL-multiquery request" do
152
- it "should call fql.multiquery method" do
153
- @api.should_receive(:rest_call).with(
154
- "fql.multiquery", anything, anything
155
- ).and_return({})
156
-
157
- @api.fql_multiquery 'query string'
158
- end
159
-
160
- it "should pass a queries argument" do
161
- queries = stub('query string')
162
- queries_json = "some JSON"
163
- MultiJson.stub(:encode).with(queries).and_return(queries_json)
164
-
165
- @api.should_receive(:rest_call).with(
166
- anything,
167
- hash_including(:queries => queries_json),
168
- anything
169
- )
170
-
171
- @api.fql_multiquery(queries)
172
- end
173
-
174
- it "simplifies the response format" do
175
- raw_results = [
176
- {"name" => "query1", "fql_result_set" => [1, 2, 3]},
177
- {"name" => "query2", "fql_result_set" => [:a, :b, :c]}
178
- ]
179
- expected_results = {
180
- "query1" => [1, 2, 3],
181
- "query2" => [:a, :b, :c]
182
- }
183
-
184
- @api.stub(:rest_call).and_return(raw_results)
185
- results = @api.fql_multiquery({:query => true})
186
- results.should == expected_results
187
- end
188
-
189
- it "should pass on any other arguments provided" do
190
- args = {:a => 2}
191
- @api.should_receive(:rest_call).with(anything, hash_including(args), anything)
192
- @api.fql_multiquery("a query", args)
193
- end
194
-
195
- it "should pass on any http options provided" do
196
- opts = {:a => 2}
197
- @api.should_receive(:rest_call).with(anything, anything, hash_including(opts))
198
- @api.fql_multiquery("a query", {}, opts)
199
- end
200
- end
120
+ it "can use the beta tier" do
121
+ @api.rest_call("fql.query", {:query => "select first_name from user where uid = #{KoalaTest.user2_id}"}, :beta => true)
201
122
  end
202
123
  end
203
124
 
204
125
  shared_examples_for "Koala RestAPI with an access token" do
205
- # FQL
206
- it "should be able to access public information via FQL" do
207
- result = @api.fql_query("select first_name from user where uid = #{KoalaTest.user2_id}")
208
- result.size.should == 1
209
- result.first['first_name'].should == KoalaTest.user2_name
210
- end
211
-
212
- it "should be able to access public information via FQL.multiquery" do
213
- result = @api.fql_multiquery(
214
- :query1 => "select first_name from user where uid = #{KoalaTest.user2_id}",
215
- :query2 => "select first_name from user where uid = #{KoalaTest.user1_id}"
216
- )
217
- result.size.should == 2
218
- result["query1"].first['first_name'].should == KoalaTest.user2_name
219
- result["query2"].first['first_name'].should == KoalaTest.user1_name
220
- end
221
-
222
- it "should be able to access protected information via FQL" do
223
- # Tests agains the permissions fql table
224
-
225
- # get the current user's ID
226
- # we're sneakily using the Graph API, which should be okay since it has its own tests
227
- g = Koala::Facebook::API.new(@token)
228
- id = g.get_object("me", :fields => "id")["id"]
126
+ describe "#set_app_properties" do
127
+ it "sends Facebook the properties JSON-encoded as :properties" do
128
+ props = {:a => 2, :c => [1, 2, "d"]}
129
+ @api.should_receive(:rest_call).with(anything, hash_including(:properties => MultiJson.encode(props)), anything, anything)
130
+ @api.set_app_properties(props)
131
+ end
229
132
 
230
- # now send a query about your permissions
231
- result = @api.fql_query("select read_stream from permissions where uid = #{id}")
133
+ it "calls the admin.setAppProperties method" do
134
+ @api.should_receive(:rest_call).with("admin.setAppProperties", anything, anything, anything)
135
+ @api.set_app_properties({})
136
+ end
232
137
 
233
- result.size.should == 1
234
- # we've verified that you have read_stream permissions, so we can test against that
235
- result.first["read_stream"].should == 1
236
- end
138
+ it "includes any other provided arguments" do
139
+ args = {:c => 3, :d => "a"}
140
+ @api.should_receive(:rest_call).with(anything, hash_including(args), anything, anything)
141
+ @api.set_app_properties({:a => 2}, args)
142
+ end
237
143
 
144
+ it "includes any http_options provided" do
145
+ opts = {:c => 3, :d => "a"}
146
+ @api.should_receive(:rest_call).with(anything, anything, opts, anything)
147
+ @api.set_app_properties({}, {}, opts)
148
+ end
149
+
150
+ it "makes a POST" do
151
+ @api.should_receive(:rest_call).with(anything, anything, anything, "post")
152
+ @api.set_app_properties({})
153
+ end
238
154
 
239
- it "should be able to access protected information via FQL.multiquery" do
240
- result = @api.fql_multiquery(
241
- :query1 => "select post_id from stream where source_id = me()",
242
- :query2 => "select fromid from comment where post_id in (select post_id from #query1)",
243
- :query3 => "select uid, name from user where uid in (select fromid from #query2)"
244
- )
245
- result.size.should == 3
246
- result.keys.should include("query1", "query2", "query3")
155
+ it "can set app properties using the app's access token" do
156
+ oauth = Koala::Facebook::OAuth.new(KoalaTest.app_id, KoalaTest.secret)
157
+ app_token = oauth.get_app_access_token
158
+ @app_api = Koala::Facebook::API.new(app_token)
159
+ @app_api.set_app_properties(KoalaTest.app_properties).should be_true
160
+ end
247
161
  end
248
-
249
162
  end
250
163
 
251
164
 
252
165
  shared_examples_for "Koala RestAPI without an access token" do
253
- # FQL_QUERY
254
- describe "when making a FQL request" do
255
- it "should be able to access public information via FQL" do
256
- result = @api.fql_query("select first_name from user where uid = #{KoalaTest.user2_id}")
257
- result.size.should == 1
258
- result.first['first_name'].should == KoalaTest.user2_name
259
- end
260
-
261
- it "should be able to access public information via FQL.multiquery" do
262
- result = @api.fql_multiquery(
263
- :query1 => "select first_name from user where uid = #{KoalaTest.user2_id}",
264
- :query2 => "select first_name from user where uid = #{KoalaTest.user1_id}"
265
- )
266
- result.size.should == 2
267
- result["query1"].first['first_name'].should == KoalaTest.user2_name
268
- result["query2"].first['first_name'].should == KoalaTest.user1_name
269
- end
270
-
271
- it "should not be able to access protected information via FQL" do
272
- lambda { @api.fql_query("select read_stream from permissions where uid = #{KoalaTest.user2_id}") }.should raise_error(Koala::Facebook::APIError)
273
- end
274
-
275
- it "should not be able to access protected information via FQL.multiquery" do
276
- lambda {
277
- @api.fql_multiquery(
278
- :query1 => "select post_id from stream where source_id = me()",
279
- :query2 => "select fromid from comment where post_id in (select post_id from #query1)",
280
- :query3 => "select uid, name from user where uid in (select fromid from #query2)"
281
- )
282
- }.should raise_error(Koala::Facebook::APIError)
283
- end
166
+ it "can't use set_app_properties" do
167
+ lambda { @api.set_app_properties(:desktop => 0) }.should raise_error(Koala::Facebook::APIError)
284
168
  end
285
169
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: koala
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-27 00:00:00.000000000Z
12
+ date: 2011-10-04 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multi_json
16
- requirement: &70248641333480 !ruby/object:Gem::Requirement
16
+ requirement: &70194747941160 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '1.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70248641333480
24
+ version_requirements: *70194747941160
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: faraday
27
- requirement: &70248641333000 !ruby/object:Gem::Requirement
27
+ requirement: &70194747940100 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,21 +32,21 @@ dependencies:
32
32
  version: 0.7.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70248641333000
35
+ version_requirements: *70194747940100
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &70248641332520 !ruby/object:Gem::Requirement
38
+ requirement: &70194747938880 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
42
42
  - !ruby/object:Gem::Version
43
- version: '2.5'
43
+ version: 2.8.0rc1
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70248641332520
46
+ version_requirements: *70194747938880
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rake
49
- requirement: &70248641332040 !ruby/object:Gem::Requirement
49
+ requirement: &70194747937740 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: 0.8.7
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70248641332040
57
+ version_requirements: *70194747937740
58
58
  description: Koala is a lightweight, flexible Ruby SDK for Facebook. It allows read/write
59
59
  access to the social graph via the Graph and REST APIs, as well as support for realtime
60
60
  updates and OAuth and Facebook Connect authentication. Koala is fully tested and
@@ -69,39 +69,45 @@ extra_rdoc_files:
69
69
  files:
70
70
  - .autotest
71
71
  - .gitignore
72
+ - .rspec
72
73
  - .travis.yml
74
+ - .yardopts
73
75
  - CHANGELOG
74
76
  - Gemfile
77
+ - Guardfile
75
78
  - LICENSE
76
79
  - Manifest
77
80
  - Rakefile
78
81
  - autotest/discover.rb
79
82
  - koala.gemspec
80
83
  - lib/koala.rb
81
- - lib/koala/batch_operation.rb
82
- - lib/koala/graph_api.rb
83
- - lib/koala/graph_batch_api.rb
84
- - lib/koala/graph_collection.rb
84
+ - lib/koala/api.rb
85
+ - lib/koala/api/batch_operation.rb
86
+ - lib/koala/api/graph_api.rb
87
+ - lib/koala/api/graph_batch_api.rb
88
+ - lib/koala/api/graph_collection.rb
89
+ - lib/koala/api/legacy.rb
90
+ - lib/koala/api/rest_api.rb
85
91
  - lib/koala/http_service.rb
92
+ - lib/koala/http_service/multipart_request.rb
93
+ - lib/koala/http_service/response.rb
94
+ - lib/koala/http_service/uploadable_io.rb
86
95
  - lib/koala/oauth.rb
87
96
  - lib/koala/realtime_updates.rb
88
- - lib/koala/rest_api.rb
89
97
  - lib/koala/test_users.rb
90
- - lib/koala/uploadable_io.rb
91
98
  - lib/koala/utils.rb
92
99
  - lib/koala/version.rb
93
100
  - readme.md
94
101
  - spec/cases/api_spec.rb
95
102
  - spec/cases/error_spec.rb
96
- - spec/cases/graph_and_rest_api_spec.rb
97
103
  - spec/cases/graph_api_batch_spec.rb
98
- - spec/cases/graph_api_spec.rb
99
104
  - spec/cases/graph_collection_spec.rb
100
105
  - spec/cases/http_service_spec.rb
101
106
  - spec/cases/koala_spec.rb
107
+ - spec/cases/legacy_spec.rb
108
+ - spec/cases/multipart_request_spec.rb
102
109
  - spec/cases/oauth_spec.rb
103
110
  - spec/cases/realtime_updates_spec.rb
104
- - spec/cases/rest_api_spec.rb
105
111
  - spec/cases/test_users_spec.rb
106
112
  - spec/cases/uploadable_io_spec.rb
107
113
  - spec/cases/utils_spec.rb
@@ -110,6 +116,7 @@ files:
110
116
  - spec/fixtures/facebook_data.yml
111
117
  - spec/fixtures/mock_facebook_responses.yml
112
118
  - spec/spec_helper.rb
119
+ - spec/support/custom_matchers.rb
113
120
  - spec/support/graph_api_shared_examples.rb
114
121
  - spec/support/json_testing_fix.rb
115
122
  - spec/support/koala_test.rb
@@ -135,7 +142,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
135
142
  version: '0'
136
143
  segments:
137
144
  - 0
138
- hash: 2837078681376474267
145
+ hash: 3741350754426721879
139
146
  required_rubygems_version: !ruby/object:Gem::Requirement
140
147
  none: false
141
148
  requirements:
@@ -144,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
151
  version: '1.2'
145
152
  requirements: []
146
153
  rubyforge_project:
147
- rubygems_version: 1.8.8
154
+ rubygems_version: 1.8.10
148
155
  signing_key:
149
156
  specification_version: 3
150
157
  summary: A lightweight, flexible library for Facebook with support for the Graph API,
@@ -152,15 +159,14 @@ summary: A lightweight, flexible library for Facebook with support for the Graph
152
159
  test_files:
153
160
  - spec/cases/api_spec.rb
154
161
  - spec/cases/error_spec.rb
155
- - spec/cases/graph_and_rest_api_spec.rb
156
162
  - spec/cases/graph_api_batch_spec.rb
157
- - spec/cases/graph_api_spec.rb
158
163
  - spec/cases/graph_collection_spec.rb
159
164
  - spec/cases/http_service_spec.rb
160
165
  - spec/cases/koala_spec.rb
166
+ - spec/cases/legacy_spec.rb
167
+ - spec/cases/multipart_request_spec.rb
161
168
  - spec/cases/oauth_spec.rb
162
169
  - spec/cases/realtime_updates_spec.rb
163
- - spec/cases/rest_api_spec.rb
164
170
  - spec/cases/test_users_spec.rb
165
171
  - spec/cases/uploadable_io_spec.rb
166
172
  - spec/cases/utils_spec.rb
@@ -169,6 +175,7 @@ test_files:
169
175
  - spec/fixtures/facebook_data.yml
170
176
  - spec/fixtures/mock_facebook_responses.yml
171
177
  - spec/spec_helper.rb
178
+ - spec/support/custom_matchers.rb
172
179
  - spec/support/graph_api_shared_examples.rb
173
180
  - spec/support/json_testing_fix.rb
174
181
  - spec/support/koala_test.rb
@@ -176,3 +183,4 @@ test_files:
176
183
  - spec/support/ordered_hash.rb
177
184
  - spec/support/rest_api_shared_examples.rb
178
185
  - spec/support/uploadable_io_shared_examples.rb
186
+ has_rdoc:
@@ -1,74 +0,0 @@
1
- module Koala
2
- module Facebook
3
- class BatchOperation
4
- attr_reader :access_token, :http_options, :post_processing, :files, :batch_api, :identifier
5
-
6
- @identifier = 0
7
-
8
- def self.next_identifier
9
- @identifier += 1
10
- end
11
-
12
- def initialize(options = {})
13
- @identifier = self.class.next_identifier
14
- @args = (options[:args] || {}).dup # because we modify it below
15
- @access_token = options[:access_token]
16
- @http_options = (options[:http_options] || {}).dup # dup because we modify it below
17
- @batch_args = @http_options.delete(:batch_args) || {}
18
- @url = options[:url]
19
- @method = options[:method].to_sym
20
- @post_processing = options[:post_processing]
21
-
22
- process_binary_args
23
-
24
- raise Koala::KoalaError, "Batch operations require an access token, none provided." unless @access_token
25
- end
26
-
27
- def to_batch_params(main_access_token)
28
- # set up the arguments
29
- args_string = Koala.http_service.encode_params(@access_token == main_access_token ? @args : @args.merge(:access_token => @access_token))
30
-
31
- response = {
32
- :method => @method.to_s,
33
- :relative_url => @url,
34
- }
35
-
36
- # handle batch-level arguments, such as name, depends_on, and attached_files
37
- @batch_args[:attached_files] = @files.keys.join(",") if @files
38
- response.merge!(@batch_args) if @batch_args
39
-
40
- # for get and delete, we append args to the URL string
41
- # otherwise, they go in the body
42
- if args_string.length > 0
43
- if args_in_url?
44
- response[:relative_url] += (@url =~ /\?/ ? "&" : "?") + args_string if args_string.length > 0
45
- else
46
- response[:body] = args_string if args_string.length > 0
47
- end
48
- end
49
-
50
- response
51
- end
52
-
53
- protected
54
-
55
- def process_binary_args
56
- # collect binary files
57
- @args.each_pair do |key, value|
58
- if UploadableIO.binary_content?(value)
59
- @files ||= {}
60
- # we use a class-level counter to ensure unique file identifiers across multiple batch operations
61
- # (this is thread safe, since we just care about uniqueness)
62
- # so remove the file from the original hash and add it to the file store
63
- id = "op#{identifier}_file#{@files.keys.length}"
64
- @files[id] = @args.delete(key).is_a?(UploadableIO) ? value : UploadableIO.new(value)
65
- end
66
- end
67
- end
68
-
69
- def args_in_url?
70
- @method == :get || @method == :delete
71
- end
72
- end
73
- end
74
- end