koala 0.7.4 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ v0.8.0
2
+ -- Breaking interface changes
3
+ -- Removed string overloading for the methods, per 0.7.3, which caused Marshaling issues
4
+ -- Removed ability to provide a string as the second argument to url_for_access_token, per 0.5.0
5
+
1
6
  v0.7.4
2
7
  -- Fixed bug with get_user_from_cookies
3
8
 
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require 'rake'
4
4
  require 'echoe'
5
5
 
6
6
  # gem management
7
- Echoe.new('koala', '0.7.4') do |p|
7
+ Echoe.new('koala', '0.8.0') do |p|
8
8
  p.summary = "A lightweight, flexible library for Facebook with support for the Graph API, the old REST API, realtime updates, and OAuth validation."
9
9
  p.description = "Koala is a lightweight, flexible Ruby SDK for Facebook. It allows read/write access to the social graph via the Graph API and the older REST API, 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."
10
10
  p.url = "http://github.com/arsduo/koala"
data/koala.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{koala}
5
- s.version = "0.7.4"
5
+ s.version = "0.8.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Alex Koppel, Chris Baclig, Rafi Jacoby, Context Optional"]
9
- s.date = %q{2010-06-23}
9
+ s.date = %q{2010-06-27}
10
10
  s.description = %q{Koala is a lightweight, flexible Ruby SDK for Facebook. It allows read/write access to the social graph via the Graph API and the older REST API, 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.}
11
11
  s.email = %q{alex@alexkoppel.com}
12
12
  s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "lib/koala.rb", "lib/koala/graph_api.rb", "lib/koala/http_services.rb", "lib/koala/realtime_updates.rb", "lib/koala/rest_api.rb"]
data/lib/koala.rb CHANGED
@@ -107,7 +107,7 @@ module Koala
107
107
  @app_secret = app_secret
108
108
  @oauth_callback_url = oauth_callback_url
109
109
  end
110
-
110
+
111
111
  def get_user_info_from_cookie(cookie_hash)
112
112
  # Parses the cookie set by the official Facebook JavaScript SDK.
113
113
  #
@@ -141,7 +141,6 @@ module Koala
141
141
  def get_user_from_cookie(cookies)
142
142
  if info = get_user_info_from_cookies(cookies)
143
143
  string = info["uid"]
144
- overload_as_hash(string, info)
145
144
  end
146
145
  end
147
146
  alias_method :get_user_from_cookies, :get_user_from_cookie
@@ -162,10 +161,6 @@ module Koala
162
161
 
163
162
  def url_for_access_token(code, options = {})
164
163
  # Creates the URL for the token corresponding to a given code generated by Facebook
165
- if options.is_a?(String) # changing the arguments
166
- puts "Deprecation warning: url_for_access_token now takes an options hash as the second argument; pass the callback as :callback."
167
- options = {:callback => options}
168
- end
169
164
  callback = options[:callback] || @oauth_callback_url
170
165
  raise ArgumentError, "url_for_access_token must get a callback either from the OAuth object or in the parameters!" unless callback
171
166
  "https://#{GRAPH_SERVER}/oauth/access_token?client_id=#{@app_id}&redirect_uri=#{callback}&client_secret=#{@app_secret}&code=#{code}"
@@ -178,11 +173,10 @@ module Koala
178
173
  end
179
174
 
180
175
  def get_access_token(code)
181
- info = get_access_token_info(code)
182
176
  # upstream methods will throw errors if needed
183
- string = info["access_token"]
184
-
185
- overload_as_hash(string, info)
177
+ if info = get_access_token_info(code)
178
+ string = info["access_token"]
179
+ end
186
180
  end
187
181
 
188
182
  def get_app_access_token_info
@@ -191,12 +185,11 @@ module Koala
191
185
  end
192
186
 
193
187
  def get_app_access_token
194
- info = get_app_access_token_info
195
- string = info["access_token"]
196
-
197
- overload_as_hash(string, info)
188
+ if info = get_app_access_token_info
189
+ string = info["access_token"]
190
+ end
198
191
  end
199
-
192
+
200
193
  # from session keys
201
194
  def get_token_info_from_session_keys(sessions)
202
195
  # fetch the OAuth tokens from Facebook
@@ -217,13 +210,8 @@ module Koala
217
210
  def get_tokens_from_session_keys(sessions)
218
211
  # get the original hash results
219
212
  results = get_token_info_from_session_keys(sessions)
220
- # now recollect them as backward-compatible strings
221
- # for easier use
222
- results.collect do |r|
223
- string = r["access_token"]
224
-
225
- overload_as_hash string, r
226
- end
213
+ # now recollect them as just the access tokens
214
+ results.collect { |r| string = r["access_token"] }
227
215
  end
228
216
 
229
217
  def get_token_from_session_key(session)
@@ -259,23 +247,6 @@ module Koala
259
247
  :client_secret => @app_secret
260
248
  }.merge!(args), post ? "post" : "get").body
261
249
  end
262
-
263
- # overload the object to be accessible as a hash
264
- # used to make get_*_token methods backward compatible
265
- # icky ruby magic, but it's _really_ cool we can do this
266
- def overload_as_hash(obj, hash)
267
- command = <<-EOS
268
- def [](index)
269
- puts "WARNING: get_app_access_token now provides the access token as a string; use get_app_access_token_info if you want the hash with expirations. Otherwise you no longer need to call [] to get the token itself."
270
- hash = #{hash.inspect}
271
- hash[index]
272
- end
273
- EOS
274
-
275
- (class << obj; self; end).class_eval command
276
-
277
- obj
278
- end
279
250
  end
280
251
  end
281
252
 
@@ -44,7 +44,7 @@ module Koala
44
44
  # fetch the access token if we're provided a secret
45
45
  if @secret && !@app_access_token
46
46
  oauth = Koala::Facebook::OAuth.new(@app_id, @secret)
47
- @app_access_token = oauth.get_app_access_token["access_token"]
47
+ @app_access_token = oauth.get_app_access_token
48
48
  end
49
49
  end
50
50
 
@@ -77,35 +77,4 @@ class ApiBaseTests < Test::Unit::TestCase
77
77
  @service.api('anything').should be_false
78
78
  end
79
79
  end
80
- end
81
-
82
- shared_examples_for "methods that return overloaded strings" do
83
- before :each do
84
- @key ||= "access_token"
85
- end
86
-
87
- it "should be overloaded to be backward compatible" do
88
- @result.respond_to?(:[]).should be_true
89
- end
90
-
91
- it "should allow hash access to the access token info" do
92
- @result[@key].should == @result
93
- end
94
-
95
- it "should output a deprecation warning when the result is used as a hash" do
96
- out = nil
97
-
98
- begin
99
- # we want to capture the deprecation warning as well as the output
100
- # credit to http://thinkingdigitally.com/archive/capturing-output-from-puts-in-ruby/ for the technique
101
- out = StringIO.new
102
- $stdout = out
103
- @result[@key]
104
- ensure
105
- $stdout = STDOUT
106
- end
107
-
108
- # ensure we got a warning
109
- out.should_not be_nil
110
- end
111
80
  end
@@ -107,16 +107,7 @@ class FacebookOAuthTests < Test::Unit::TestCase
107
107
  bad_cookie_hash = @oauth_data["valid_cookies"].inject({}) { |hash, value| hash[value[0]] = value[1].gsub(/[0-9]/, "3") }
108
108
  result = @oauth.get_user_from_cookies(bad_cookie_hash)
109
109
  result.should be_nil
110
- end
111
-
112
- describe "backward compatibility" do
113
- before :each do
114
- @result = @oauth.get_user_from_cookies(@oauth_data["valid_cookies"])
115
- @key = "uid"
116
- end
117
-
118
- it_should_behave_like "methods that return overloaded strings"
119
- end
110
+ end
120
111
  end
121
112
  end
122
113
 
@@ -170,25 +161,6 @@ class FacebookOAuthTests < Test::Unit::TestCase
170
161
  url.should == "https://#{Koala::Facebook::GRAPH_SERVER}/oauth/access_token?client_id=#{@app_id}&redirect_uri=#{callback}&client_secret=#{@secret}&code=#{@code}"
171
162
  end
172
163
 
173
- it "should output a deprecation warning but generate a properly formatted OAuth token URL when provided a callback in the deprecated fashion" do
174
- callback = "foo.com"
175
- url = out = nil
176
-
177
- begin
178
- # we want to capture the deprecation warning as well as the output
179
- # credit to http://thinkingdigitally.com/archive/capturing-output-from-puts-in-ruby/ for the technique
180
- out = StringIO.new
181
- $stdout = out
182
- url = @oauth.url_for_access_token(@code, callback)
183
- ensure
184
- $stdout = STDOUT
185
- end
186
-
187
- # two assertions may be bad test writing, but this is for a deprecated method
188
- url.should == "https://#{Koala::Facebook::GRAPH_SERVER}/oauth/access_token?client_id=#{@app_id}&redirect_uri=#{callback}&client_secret=#{@secret}&code=#{@code}"
189
- out.should_not be_nil
190
- end
191
-
192
164
  describe "get_access_token_info" do
193
165
  it "should properly get and parse an access token token results into a hash" do
194
166
  result = @oauth.get_access_token_info(@code)
@@ -216,18 +188,10 @@ class FacebookOAuthTests < Test::Unit::TestCase
216
188
  original = @oauth.get_access_token_info(@code)
217
189
  result.should == original["access_token"]
218
190
  end
219
-
191
+
220
192
  it "should raise an error when get_access_token is called with a bad code" do
221
193
  lambda { @oauth.get_access_token("foo") }.should raise_error(Koala::Facebook::APIError)
222
194
  end
223
-
224
- describe "backwards compatibility" do
225
- before :each do
226
- @result = @oauth.get_access_token(@code)
227
- end
228
-
229
- it_should_behave_like "methods that return overloaded strings"
230
- end
231
195
  end
232
196
 
233
197
  describe "get_app_access_token_info" do
@@ -253,14 +217,6 @@ class FacebookOAuthTests < Test::Unit::TestCase
253
217
  original = @oauth.get_app_access_token_info
254
218
  result.should == original["access_token"]
255
219
  end
256
-
257
- describe "backwards compatibility" do
258
- before :each do
259
- @result = @oauth.get_app_access_token
260
- end
261
-
262
- it_should_behave_like "methods that return overloaded strings"
263
- end
264
220
  end
265
221
 
266
222
  describe "exchanging session keys" do
@@ -295,15 +251,6 @@ class FacebookOAuthTests < Test::Unit::TestCase
295
251
  result = @oauth.get_tokens_from_session_keys(args)
296
252
  result.each {|r| r.should be_a(String) }
297
253
  end
298
-
299
- describe "backwards compatibility" do
300
- before :each do
301
- args = @oauth_data["multiple_session_keys"]
302
- @result = @oauth.get_tokens_from_session_keys(args)[0]
303
- end
304
-
305
- it_should_behave_like "methods that return overloaded strings"
306
- end
307
254
  end
308
255
 
309
256
  describe "get_token_from_session_key" do
@@ -323,14 +270,6 @@ class FacebookOAuthTests < Test::Unit::TestCase
323
270
  array = @oauth.get_tokens_from_session_keys([@oauth_data["session_key"]])
324
271
  result.should == array[0]
325
272
  end
326
-
327
- describe "backwards compatibility" do
328
- before :each do
329
- @result = @oauth.get_token_from_session_key(@oauth_data["session_key"])
330
- end
331
-
332
- it_should_behave_like "methods that return overloaded strings"
333
- end
334
273
  end
335
274
  end
336
275
 
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 7
8
- - 4
9
- version: 0.7.4
7
+ - 8
8
+ - 0
9
+ version: 0.8.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Alex Koppel, Chris Baclig, Rafi Jacoby, Context Optional
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-06-23 00:00:00 -07:00
17
+ date: 2010-06-27 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies: []
20
20