koala 1.0.0.rc → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,31 +1,29 @@
1
1
  v1.0
2
2
  New methods:
3
3
  -- Photo and file upload now supported through #put_picture
4
- -- RC: now supported natively through Typhoeus
5
- -- Beta 2: support for Rails 3, Sinatra, File objects, and paths (see documentation)
6
- -- Beta 2: Added UploadableIO class to manage file uploads
7
- -- Added a delete_like method (thanks to wassem)
8
- -- Beta 2: Added put_connection and delete_connection convenience methods
4
+ -- Added UploadableIO class to manage file uploads
5
+ -- Added a delete_like method (thanks to waseem)
6
+ -- Added put_connection and delete_connection convenience methods
9
7
  Updated methods:
10
- -- RC: url_for_oauth_code can now take a :display option (thanks, netbe!)
11
- -- RC: Net::HTTP can now accept :timeout and :proxy options (thanks, gilles!)
12
- -- RC: search can now search places, checkins, etc. (thanks, rickyc!)
13
- -- Beta 2: TestUser#befriend now requires user info hashes (id and access token) due to Facebook API changes (thanks to pulsd/kbighorse)
14
- -- Beta 2: all methods now accept an http_options hash as their optional last parameter
15
- -- Beta 2: You can now pass :beta => true in the http options to use Facebook's beta tier.
8
+ -- Search can now search places, checkins, etc. (thanks, rickyc!)
9
+ -- You can now pass :beta => true in the http options to use Facebook's beta tier.
10
+ -- TestUser#befriend now requires user info hashes (id and access token) due to Facebook API changes (thanks, pulsd and kbighorse!)
11
+ -- All methods now accept an http_options hash as their optional last parameter (thanks, spiegela!)
12
+ -- url_for_oauth_code can now take a :display option (thanks, netbe!)
13
+ -- Net::HTTP can now accept :timeout and :proxy options (thanks, gilles!)
14
+ -- Test users now supports using test accounts across multiple apps
16
15
  Internal improvements:
17
16
  -- For public requests, Koala now uses http by default (instead of https) to improve speed
18
17
  -- This can be overridden through Koala.always_use_ssl= or by passing :use_ssl => true in the options hash for an api call
19
18
  -- Read-only REST API requests now go through the faster api-read server
20
19
  -- Replaced parse_signed_request with a version from Facebook that also supports the new signed params proposal
21
20
  -- Note: invalid requests will now raise exceptions rather than return nil, in keeping with other SDKs
22
- -- delete_object will now raise an error if there's no access token (like put_object and delete_like)
23
- -- Beta 2.1: Updated parse_signed_request to match Facebook's current implementation (thanks, imajes!)
24
- -- Beta 2: photo and file uploads now accept symbols as well as strings overall
25
- -- Beta 2: APIError is now < StandardError, not Exception
26
- -- Beta 2: Added KoalaError for non-API errors
21
+ -- Delete methods will now raise an error if there's no access token (like put_object and delete_like)
22
+ -- Updated parse_signed_request to match Facebook's current implementation (thanks, imajes!)
23
+ -- APIError is now < StandardError, not Exception
24
+ -- Added KoalaError for non-API errors
27
25
  Test improvements:
28
- -- RC: Incorporated joshk's awesome rewrite of the entire Koala test suite (thanks, joshk!)
26
+ -- Incorporated joshk's awesome rewrite of the entire Koala test suite (thanks, joshk!)
29
27
  -- Expanded HTTP service tests (added Typhoeus test suite and additional Net::HTTP test cases)
30
28
  -- Live tests now verify that the access token has the necessary permissions before starting
31
29
  -- Replaced the 50-person network test, which often took 15+ minutes to run live, with a 5-person test
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License
2
2
 
3
- Copyright (c) 2010 Alex Koppel
3
+ Copyright (c) 2010-2011 Alex Koppel
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
data/koala.gemspec CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{koala}
5
- s.version = "1.0.0.rc"
6
- s.date = %q{2011-04-18}
5
+ s.version = "1.0.0"
6
+ s.date = %q{2011-05-01}
7
7
 
8
8
  s.summary = %q{A lightweight, flexible library for Facebook with support for the Graph API, the REST API, realtime updates, and OAuth authentication.}
9
9
  s.description = %q{Koala is a lightweight, flexible Ruby SDK for Facebook. It allows read/write access to the social graph via the Graph and REST APIs, as well as support for realtime updates and OAuth and Facebook Connect authentication. Koala is fully tested and supports Net::HTTP and Typhoeus connections out of the box and can accept custom modules for other services.}
data/lib/koala.rb CHANGED
@@ -21,25 +21,9 @@ module Koala
21
21
 
22
22
  module Facebook
23
23
  # Ruby client library for the Facebook Platform.
24
- # Copyright 2010 Facebook
25
- # Adapted from the Python library by Alex Koppel, Rafi Jacoby, and the team at Context Optional
26
- #
27
- # Licensed under the Apache License, Version 2.0 (the "License"); you may
28
- # not use this file except in compliance with the License. You may obtain
29
- # a copy of the License at
30
- # http://www.apache.org/licenses/LICENSE-2.0
31
- #
32
- # Unless required by applicable law or agreed to in writing, software
33
- # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
34
- # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
35
- # License for the specific language governing permissions and limitations
36
- # under the License.
37
- #
38
- # This client library is designed to support the Graph API and the official
39
- # Facebook JavaScript SDK, which is the canonical way to implement
40
- # Facebook authentication. Read more about the Graph API at
41
- # http://developers.facebook.com/docs/api. You can download the Facebook
42
- # JavaScript SDK at http://github.com/facebook/connect-js/.
24
+ # Copyright 2010-2011 Alex Koppel
25
+ # Contributors: Alex Koppel, Chris Baclig, Rafi Jacoby, and the team at Context Optional
26
+ # http://github.com/arsduo/koala
43
27
 
44
28
  class API
45
29
  # initialize with an access token
@@ -179,26 +163,26 @@ module Koala
179
163
  "https://#{GRAPH_SERVER}/oauth/access_token?client_id=#{@app_id}&redirect_uri=#{callback}&client_secret=#{@app_secret}&code=#{code}"
180
164
  end
181
165
 
182
- def get_access_token_info(code)
166
+ def get_access_token_info(code, options = {})
183
167
  # convenience method to get a parsed token from Facebook for a given code
184
168
  # should this require an OAuth callback URL?
185
- get_token_from_server(:code => code, :redirect_uri => @oauth_callback_url)
169
+ get_token_from_server({:code => code, :redirect_uri => @oauth_callback_url}, false, options)
186
170
  end
187
171
 
188
- def get_access_token(code)
172
+ def get_access_token(code, options = {})
189
173
  # upstream methods will throw errors if needed
190
- if info = get_access_token_info(code)
174
+ if info = get_access_token_info(code, options)
191
175
  string = info["access_token"]
192
176
  end
193
177
  end
194
178
 
195
- def get_app_access_token_info
179
+ def get_app_access_token_info(options = {})
196
180
  # convenience method to get a the application's sessionless access token
197
- get_token_from_server({:type => 'client_cred'}, true)
181
+ get_token_from_server({:type => 'client_cred'}, true, options)
198
182
  end
199
183
 
200
- def get_app_access_token
201
- if info = get_app_access_token_info
184
+ def get_app_access_token(options = {})
185
+ if info = get_app_access_token_info(options)
202
186
  string = info["access_token"]
203
187
  end
204
188
  end
@@ -223,12 +207,12 @@ module Koala
223
207
  end
224
208
 
225
209
  # from session keys
226
- def get_token_info_from_session_keys(sessions)
210
+ def get_token_info_from_session_keys(sessions, options = {})
227
211
  # fetch the OAuth tokens from Facebook
228
212
  response = fetch_token_string({
229
213
  :type => 'client_cred',
230
214
  :sessions => sessions.join(",")
231
- }, true, "exchange_sessions")
215
+ }, true, "exchange_sessions", options)
232
216
 
233
217
  # Facebook returns an empty body in certain error conditions
234
218
  if response == ""
@@ -241,24 +225,24 @@ module Koala
241
225
  JSON.parse(response)
242
226
  end
243
227
 
244
- def get_tokens_from_session_keys(sessions)
228
+ def get_tokens_from_session_keys(sessions, options = {})
245
229
  # get the original hash results
246
- results = get_token_info_from_session_keys(sessions)
230
+ results = get_token_info_from_session_keys(sessions, options)
247
231
  # now recollect them as just the access tokens
248
232
  results.collect { |r| r ? r["access_token"] : nil }
249
233
  end
250
234
 
251
- def get_token_from_session_key(session)
235
+ def get_token_from_session_key(session, options = {})
252
236
  # convenience method for a single key
253
237
  # gets the overlaoded strings automatically
254
- get_tokens_from_session_keys([session])[0]
238
+ get_tokens_from_session_keys([session], options)[0]
255
239
  end
256
240
 
257
241
  protected
258
242
 
259
- def get_token_from_server(args, post = false)
243
+ def get_token_from_server(args, post = false, options = {})
260
244
  # fetch the result from Facebook's servers
261
- result = fetch_token_string(args, post)
245
+ result = fetch_token_string(args, post, "access_token", options)
262
246
 
263
247
  # if we have an error, parse the error JSON and raise an error
264
248
  raise APIError.new((JSON.parse(result)["error"] rescue nil) || {}) if result =~ /error/
@@ -275,11 +259,11 @@ module Koala
275
259
  components
276
260
  end
277
261
 
278
- def fetch_token_string(args, post = false, endpoint = "access_token")
262
+ def fetch_token_string(args, post = false, endpoint = "access_token", options = {})
279
263
  Koala.make_request("/oauth/#{endpoint}", {
280
264
  :client_id => @app_id,
281
265
  :client_secret => @app_secret
282
- }.merge!(args), post ? "post" : "get", :use_ssl => true).body
266
+ }.merge!(args), post ? "post" : "get", {:use_ssl => true}.merge!(options)).body
283
267
  end
284
268
 
285
269
  # base 64
data/readme.md CHANGED
@@ -7,12 +7,16 @@ Koala (<a href="http://github.com/arsduo/koala" target="_blank">http://github.co
7
7
  * Flexible: Koala should be useful to everyone, regardless of their current configuration. (We have no dependencies beyond the JSON gem. Koala also has a built-in mechanism for using whichever HTTP library you prefer to make requests against the graph.)
8
8
  * Tested: Koala should have complete test coverage, so you can rely on it. (Our complete test coverage can be run against either mocked responses or the live Facebook servers.)
9
9
 
10
- 1.0 beta
10
+ 1.0
11
11
  ---
12
- Version 1.0 is currently in beta, chock-full of great new features. To download the beta, just add --pre when installing the gem:
12
+ Version 1.0 is due out on May 1st, 2011 with a ton of great features.
13
13
 
14
- sudo gem install koala --pre
14
+ sudo gem install koala
15
15
 
16
+ Until then, you can install the release candidate like so:
17
+
18
+ sudo gem install koala --pre
19
+
16
20
  Graph API
17
21
  ----
18
22
  The Graph API is the simple, slick new interface to Facebook's data. Using it with Koala is quite straightforward:
@@ -126,11 +130,14 @@ Testing
126
130
  -----
127
131
 
128
132
  Unit tests are provided for all of Koala's methods. By default, these tests run against mock responses and hence are ready out of the box:
129
- # From the spec directory
130
- spec koala_spec.rb
133
+
134
+ # From anywhere in the project directory:
135
+ rake spec
136
+
131
137
 
132
138
  You can also run live tests against Facebook's servers:
133
- # Again from the spec directory
134
- spec koala_spec_without_mocks.rb
139
+
140
+ # Again from anywhere in the project directory:
141
+ LIVE=true rake spec
135
142
 
136
- Important Note: to run the live tests, you have to provide some of your own data: a valid OAuth access token with publish\_stream, read\_stream, and user\_photos permissions and an OAuth code that can be used to generate an access token. You can get these data at the OAuth Playground; if you want to use your own app, remember to swap out the app ID, secret, and other values. (The file also provides valid values for other tests, which you're welcome to swap out for data specific to your own application.)
143
+ Important Note: to run the live tests, you have to provide some of your own data in spec/fixtures/facebook_data.yml: a valid OAuth access token with publish\_stream, read\_stream, and user\_photos permissions and an OAuth code that can be used to generate an access token. You can get thisdata at the OAuth Playground; if you want to use your own app, remember to swap out the app ID, secret, and other values. (The file also provides valid values for other tests, which you're welcome to swap out for data specific to your own application.)
@@ -157,7 +157,6 @@ describe "Koala::Facebook::OAuth" do
157
157
  end
158
158
 
159
159
  describe "for access token URLs" do
160
-
161
160
  # url_for_access_token
162
161
  it "should generate a properly formatted OAuth token URL when provided a code" do
163
162
  url = @oauth.url_for_access_token(@code)
@@ -204,6 +203,12 @@ describe "Koala::Facebook::OAuth" do
204
203
  it "should raise an error when get_access_token is called with a bad code" do
205
204
  lambda { @oauth.get_access_token("foo") }.should raise_error(Koala::Facebook::APIError)
206
205
  end
206
+
207
+ it "should pass on any options provided to make_request" do
208
+ options = {:a => 2}
209
+ Koala.should_receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::Response.new(200, "", {}))
210
+ @oauth.get_access_token(@code, options)
211
+ end
207
212
  end
208
213
 
209
214
  describe "get_app_access_token_info" do
@@ -211,11 +216,17 @@ describe "Koala::Facebook::OAuth" do
211
216
  result = @oauth.get_app_access_token_info
212
217
  result.should be_a(Hash)
213
218
  end
214
-
219
+
215
220
  it "should include the access token" do
216
221
  result = @oauth.get_app_access_token_info
217
222
  result["access_token"].should
218
223
  end
224
+
225
+ it "should pass on any options provided to make_request" do
226
+ options = {:a => 2}
227
+ Koala.should_receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::Response.new(200, "", {}))
228
+ @oauth.get_app_access_token_info(options)
229
+ end
219
230
  end
220
231
 
221
232
  describe "get_app_acess_token" do
@@ -229,6 +240,12 @@ describe "Koala::Facebook::OAuth" do
229
240
  original = @oauth.get_app_access_token_info
230
241
  result.should == original["access_token"]
231
242
  end
243
+
244
+ it "should pass on any options provided to make_request" do
245
+ options = {:a => 2}
246
+ Koala.should_receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::Response.new(200, "", {}))
247
+ @oauth.get_app_access_token(options)
248
+ end
232
249
  end
233
250
 
234
251
  describe "protected methods" do
@@ -299,12 +316,18 @@ describe "Koala::Facebook::OAuth" do
299
316
  @oauth.should_receive(:fetch_token_string).and_return("")
300
317
  lambda { @oauth.get_token_info_from_session_keys(@oauth_data["multiple_session_keys"]) }.should raise_error(Koala::Facebook::APIError)
301
318
  end
319
+
320
+ it "should pass on any options provided to make_request" do
321
+ options = {:a => 2}
322
+ Koala.should_receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::Response.new(200, "[{}]", {}))
323
+ @oauth.get_token_info_from_session_keys([], options)
324
+ end
302
325
  end
303
326
 
304
327
  describe "with get_tokens_from_session_keys" do
305
328
  it "should call get_token_info_from_session_keys" do
306
329
  args = @oauth_data["multiple_session_keys"]
307
- @oauth.should_receive(:get_token_info_from_session_keys).with(args).and_return([])
330
+ @oauth.should_receive(:get_token_info_from_session_keys).with(args, anything).and_return([])
308
331
  @oauth.get_tokens_from_session_keys(args)
309
332
  end
310
333
 
@@ -325,12 +348,18 @@ describe "Koala::Facebook::OAuth" do
325
348
  # it should return nil for each of the invalid ones
326
349
  result.each_with_index {|r, index| index > 0 ? r.should(be_a(String)) : r.should(be_nil)}
327
350
  end
351
+
352
+ it "should pass on any options provided to make_request" do
353
+ options = {:a => 2}
354
+ Koala.should_receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::Response.new(200, "[{}]", {}))
355
+ @oauth.get_tokens_from_session_keys([], options)
356
+ end
328
357
  end
329
358
 
330
359
  describe "get_token_from_session_key" do
331
360
  it "should call get_tokens_from_session_keys when the get_token_from_session_key is called" do
332
361
  key = @oauth_data["session_key"]
333
- @oauth.should_receive(:get_tokens_from_session_keys).with([key]).and_return([])
362
+ @oauth.should_receive(:get_tokens_from_session_keys).with([key], anything).and_return([])
334
363
  @oauth.get_token_from_session_key(key)
335
364
  end
336
365
 
@@ -349,6 +378,12 @@ describe "Koala::Facebook::OAuth" do
349
378
  result = @oauth.get_token_from_session_key("foo")
350
379
  result.should be_nil
351
380
  end
381
+
382
+ it "should pass on any options provided to make_request" do
383
+ options = {:a => 2}
384
+ Koala.should_receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::Response.new(200, "[{}]", {}))
385
+ @oauth.get_token_from_session_key("", options)
386
+ end
352
387
  end
353
388
  end
354
389
 
@@ -118,29 +118,31 @@ graph_api:
118
118
  get:
119
119
  <<: *token_required
120
120
  with_token: '{"data": [{}]}'
121
-
122
- /chris.baclig/picture:
123
- no_args:
121
+
122
+ /lukeshepard/picture:
123
+ type=large:
124
124
  get:
125
125
  no_token:
126
126
  code: 302
127
127
  headers:
128
- Location: http://facebook.com/
128
+ Location: https://facebook.com/large
129
129
  with_token:
130
130
  code: 302
131
131
  headers:
132
- Location: http://facebook.com/
133
- type=large:
132
+ Location: https://facebook.com/large
133
+
134
+
135
+ /chris.baclig/picture:
136
+ no_args:
134
137
  get:
135
138
  no_token:
136
139
  code: 302
137
140
  headers:
138
- Location: http://facebook.com/large
141
+ Location: http://facebook.com/
139
142
  with_token:
140
143
  code: 302
141
144
  headers:
142
- Location: http://facebook.com/large
143
-
145
+ Location: http://facebook.com/
144
146
 
145
147
  /search:
146
148
  q=facebook:
@@ -57,11 +57,11 @@ shared_examples_for "Koala GraphAPI" do
57
57
  end
58
58
 
59
59
  it "should be able to access a user's picture" do
60
- @api.get_picture("chris.baclig").should =~ /http\:\/\//
60
+ @api.get_picture("chris.baclig").should =~ /http[s]*\:\/\//
61
61
  end
62
62
 
63
63
  it "should be able to access a user's picture, given a picture type" do
64
- @api.get_picture("chris.baclig", {:type => 'large'}).should =~ /^http\:\/\//
64
+ @api.get_picture("lukeshepard", {:type => 'large'}).should =~ /^http[s]*\:\/\//
65
65
  end
66
66
 
67
67
  it "should be able to access connections from public Pages" do
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: koala
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7712010
5
- prerelease: 6
4
+ hash: 23
5
+ prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
9
  - 0
10
- - rc
11
- version: 1.0.0.rc
10
+ version: 1.0.0
12
11
  platform: ruby
13
12
  authors:
14
13
  - Alex Koppel, Chris Baclig, Rafi Jacoby, Context Optional
@@ -16,10 +15,10 @@ autorequire:
16
15
  bindir: bin
17
16
  cert_chain: []
18
17
 
19
- date: 2011-04-18 00:00:00 +02:00
20
- default_executable:
18
+ date: 2011-05-01 00:00:00 Z
21
19
  dependencies:
22
20
  - !ruby/object:Gem::Dependency
21
+ prerelease: false
23
22
  requirement: &id001 !ruby/object:Gem::Requirement
24
23
  none: false
25
24
  requirements:
@@ -30,11 +29,11 @@ dependencies:
30
29
  - 1
31
30
  - 0
32
31
  version: "1.0"
33
- prerelease: false
34
- version_requirements: *id001
35
32
  type: :runtime
36
33
  name: json
34
+ version_requirements: *id001
37
35
  - !ruby/object:Gem::Dependency
36
+ prerelease: false
38
37
  requirement: &id002 !ruby/object:Gem::Requirement
39
38
  none: false
40
39
  requirements:
@@ -45,11 +44,11 @@ dependencies:
45
44
  - 1
46
45
  - 0
47
46
  version: "1.0"
48
- prerelease: false
49
- version_requirements: *id002
50
47
  type: :runtime
51
48
  name: multipart-post
49
+ version_requirements: *id002
52
50
  - !ruby/object:Gem::Dependency
51
+ prerelease: false
53
52
  requirement: &id003 !ruby/object:Gem::Requirement
54
53
  none: false
55
54
  requirements:
@@ -61,11 +60,11 @@ dependencies:
61
60
  - 5
62
61
  - 0
63
62
  version: 2.5.0
64
- prerelease: false
65
- version_requirements: *id003
66
63
  type: :development
67
64
  name: rspec
65
+ version_requirements: *id003
68
66
  - !ruby/object:Gem::Dependency
67
+ prerelease: false
69
68
  requirement: &id004 !ruby/object:Gem::Requirement
70
69
  none: false
71
70
  requirements:
@@ -77,11 +76,11 @@ dependencies:
77
76
  - 8
78
77
  - 7
79
78
  version: 0.8.7
80
- prerelease: false
81
- version_requirements: *id004
82
79
  type: :development
83
80
  name: rake
81
+ version_requirements: *id004
84
82
  - !ruby/object:Gem::Dependency
83
+ prerelease: false
85
84
  requirement: &id005 !ruby/object:Gem::Requirement
86
85
  none: false
87
86
  requirements:
@@ -93,10 +92,9 @@ dependencies:
93
92
  - 2
94
93
  - 4
95
94
  version: 0.2.4
96
- prerelease: false
97
- version_requirements: *id005
98
95
  type: :development
99
96
  name: typhoeus
97
+ version_requirements: *id005
100
98
  description: Koala is a lightweight, flexible Ruby SDK for Facebook. It allows read/write access to the social graph via the Graph and REST APIs, as well as support for realtime updates and OAuth and Facebook Connect authentication. Koala is fully tested and supports Net::HTTP and Typhoeus connections out of the box and can accept custom modules for other services.
101
99
  email: alex@alexkoppel.com
102
100
  executables: []
@@ -143,7 +141,6 @@ files:
143
141
  - spec/support/rest_api_shared_examples.rb
144
142
  - spec/support/setup_mocks_or_live.rb
145
143
  - spec/support/uploadable_io_shared_examples.rb
146
- has_rdoc: true
147
144
  homepage: http://github.com/arsduo/koala
148
145
  licenses: []
149
146
 
@@ -177,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
177
174
  requirements: []
178
175
 
179
176
  rubyforge_project:
180
- rubygems_version: 1.4.2
177
+ rubygems_version: 1.7.2
181
178
  signing_key:
182
179
  specification_version: 3
183
180
  summary: A lightweight, flexible library for Facebook with support for the Graph API, the REST API, realtime updates, and OAuth authentication.