lib/koala.rb in koala-1.0.0.beta2.1 vs lib/koala.rb in koala-1.0.0.rc

- old
+ new

@@ -1,29 +1,19 @@ require 'cgi' require 'digest/md5' -# rubygems is required to support json, how facebook returns data -require 'rubygems' require 'json' # OpenSSL and Base64 are required to support signed_request require 'openssl' require 'base64' -# include default http services +# include koala modules require 'koala/http_services' - -# add Graph API methods require 'koala/graph_api' - -# add REST API methods require 'koala/rest_api' - -# add realtime update methods require 'koala/realtime_updates' - -# add test user methods require 'koala/test_users' # add KoalaIO class require 'koala/uploadable_io' @@ -50,20 +40,20 @@ # Facebook authentication. Read more about the Graph API at # http://developers.facebook.com/docs/api. You can download the Facebook # JavaScript SDK at http://github.com/facebook/connect-js/. class API - # initialize with an access token + # initialize with an access token def initialize(access_token = nil) @access_token = access_token end attr_reader :access_token def api(path, args = {}, verb = "get", options = {}, &error_checking_block) # Fetches the given path in the Graph API. args["access_token"] = @access_token || @app_access_token if @access_token || @app_access_token - + # add a leading / path = "/#{path}" unless path =~ /^\// # make the request via the provided service result = Koala.make_request(path, args, verb, options) @@ -171,16 +161,17 @@ def url_for_oauth_code(options = {}) # for permissions, see http://developers.facebook.com/docs/authentication/permissions permissions = options[:permissions] scope = permissions ? "&scope=#{permissions.is_a?(Array) ? permissions.join(",") : permissions}" : "" - + display = options.has_key?(:display) ? "&display=#{options[:display]}" : "" + callback = options[:callback] || @oauth_callback_url raise ArgumentError, "url_for_oauth_code must get a callback either from the OAuth object or in the options!" unless callback # Creates the URL for oauth authorization for a given callback and optional set of permissions - "https://#{GRAPH_SERVER}/oauth/authorize?client_id=#{@app_id}&redirect_uri=#{callback}#{scope}" + "https://#{GRAPH_SERVER}/oauth/authorize?client_id=#{@app_id}&redirect_uri=#{callback}#{scope}#{display}" end def url_for_access_token(code, options = {}) # Creates the URL for the token corresponding to a given code generated by Facebook callback = options[:callback] || @oauth_callback_url @@ -223,11 +214,11 @@ envelope = JSON.parse(base64_url_decode(encoded_envelope)) raise "SignedRequest: Unsupported algorithm #{envelope['algorithm']}" if envelope['algorithm'] != 'HMAC-SHA256' # now see if the signature is valid (digest, key, data) - hmac = OpenSSL::HMAC.hexdigest('sha256', @app_secret, encoded_envelope.tr("-_", "+/")) + hmac = OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA256.new, @app_secret, encoded_envelope.tr("-_", "+/")) raise 'SignedRequest: Invalid signature' if (signature != hmac) return envelope end @@ -297,10 +288,10 @@ str += '=' * (4 - str.length.modulo(4)) Base64.decode64(str.tr('-_', '+/')) end end end - + class KoalaError< StandardError; end # finally, set up the http service Koala methods used to make requests # you can use your own (for HTTParty, etc.) by calling Koala.http_service = YourModule def self.http_service=(service)