lib/koala.rb in koala-0.7.4 vs lib/koala.rb in koala-0.8.0

- old
+ new

@@ -105,11 +105,11 @@ def initialize(app_id, app_secret, oauth_callback_url = nil) @app_id = app_id @app_secret = app_secret @oauth_callback_url = oauth_callback_url end - + def get_user_info_from_cookie(cookie_hash) # Parses the cookie set by the official Facebook JavaScript SDK. # # cookies should be a Hash, like the one Rails provides # @@ -139,11 +139,10 @@ alias_method :get_user_info_from_cookies, :get_user_info_from_cookie def get_user_from_cookie(cookies) if info = get_user_info_from_cookies(cookies) string = info["uid"] - overload_as_hash(string, info) end end alias_method :get_user_from_cookies, :get_user_from_cookie # URLs @@ -160,14 +159,10 @@ "https://#{GRAPH_SERVER}/oauth/authorize?client_id=#{@app_id}&redirect_uri=#{callback}#{scope}" end def url_for_access_token(code, options = {}) # Creates the URL for the token corresponding to a given code generated by Facebook - if options.is_a?(String) # changing the arguments - puts "Deprecation warning: url_for_access_token now takes an options hash as the second argument; pass the callback as :callback." - options = {:callback => options} - end callback = options[:callback] || @oauth_callback_url raise ArgumentError, "url_for_access_token must get a callback either from the OAuth object or in the parameters!" unless callback "https://#{GRAPH_SERVER}/oauth/access_token?client_id=#{@app_id}&redirect_uri=#{callback}&client_secret=#{@app_secret}&code=#{code}" end @@ -176,29 +171,27 @@ # should this require an OAuth callback URL? get_token_from_server(:code => code, :redirect_uri => @oauth_callback_url) end def get_access_token(code) - info = get_access_token_info(code) # upstream methods will throw errors if needed - string = info["access_token"] - - overload_as_hash(string, info) + if info = get_access_token_info(code) + string = info["access_token"] + end end def get_app_access_token_info # convenience method to get a the application's sessionless access token get_token_from_server({:type => 'client_cred'}, true) end def get_app_access_token - info = get_app_access_token_info - string = info["access_token"] - - overload_as_hash(string, info) + if info = get_app_access_token_info + string = info["access_token"] + end end - + # from session keys def get_token_info_from_session_keys(sessions) # fetch the OAuth tokens from Facebook response = fetch_token_string({ :type => 'client_cred', @@ -215,17 +208,12 @@ end def get_tokens_from_session_keys(sessions) # get the original hash results results = get_token_info_from_session_keys(sessions) - # now recollect them as backward-compatible strings - # for easier use - results.collect do |r| - string = r["access_token"] - - overload_as_hash string, r - end + # now recollect them as just the access tokens + results.collect { |r| string = r["access_token"] } end def get_token_from_session_key(session) # convenience method for a single key # gets the overlaoded strings automatically @@ -256,26 +244,9 @@ def fetch_token_string(args, post = false, endpoint = "access_token") Koala.make_request("oauth/#{endpoint}", { :client_id => @app_id, :client_secret => @app_secret }.merge!(args), post ? "post" : "get").body - end - - # overload the object to be accessible as a hash - # used to make get_*_token methods backward compatible - # icky ruby magic, but it's _really_ cool we can do this - def overload_as_hash(obj, hash) - command = <<-EOS - def [](index) - 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." - hash = #{hash.inspect} - hash[index] - end - EOS - - (class << obj; self; end).class_eval command - - obj end end end # finally, set up the http service Koala methods used to make requests