lib/koala.rb in koala-1.1.0 vs lib/koala.rb in koala-1.2.0beta1
- old
+ new
@@ -6,21 +6,20 @@
# OpenSSL and Base64 are required to support signed_request
require 'openssl'
require 'base64'
# include koala modules
-require 'koala/http_services'
-require 'koala/http_services/net_http_service'
+require 'koala/http_service'
require 'koala/oauth'
require 'koala/graph_api'
require 'koala/graph_batch_api'
require 'koala/batch_operation'
require 'koala/graph_collection'
require 'koala/rest_api'
require 'koala/realtime_updates'
require 'koala/test_users'
-require 'koala/http_services'
+require 'koala/utils'
# add KoalaIO class
require 'koala/uploadable_io'
module Koala
@@ -29,21 +28,25 @@
# Ruby client library for the Facebook Platform.
# Copyright 2010-2011 Alex Koppel
# Contributors: Alex Koppel, Chris Baclig, Rafi Jacoby, and the team at Context Optional
# http://github.com/arsduo/koala
+ # APIs
class API
# initialize with an access token
def initialize(access_token = nil)
@access_token = access_token
end
attr_reader :access_token
+ include GraphAPIMethods
+ include RestAPIMethods
+
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)
@@ -62,39 +65,34 @@
# if we want a component other than the body (e.g. redirect header for images), return that
options[:http_component] ? result.send(options[:http_component]) : body
end
end
- # APIs
-
- class GraphAPI < API
- include GraphAPIMethods
+ # special enhanced APIs
+ class GraphBatchAPI < API
+ include GraphBatchAPIMethods
end
-
- class GraphBatchAPI < GraphAPI
- include GraphBatchAPIMethods
- end
-
- class RestAPI < API
- include RestAPIMethods
- end
- class GraphAndRestAPI < API
- include GraphAPIMethods
- include RestAPIMethods
- end
-
- class RealtimeUpdates < API
+ class RealtimeUpdates
include RealtimeUpdateMethods
end
- class TestUsers < API
+ class TestUsers
include TestUserMethods
- # make the Graph API accessible in case someone wants to make other calls to interact with their users
- attr_reader :graph_api
end
+ # legacy support for old APIs
+ class OldAPI < API;
+ def initialize(*args)
+ Koala::Utils.deprecate("#{self.class.name} is deprecated and will be removed in a future version; please use the API class instead.")
+ super
+ end
+ end
+ class GraphAPI < OldAPI; end
+ class RestAPI < OldAPI; end
+ class GraphAndRestAPI < OldAPI; end
+
# Errors
class APIError < StandardError
attr_accessor :fb_error_type
def initialize(details = {})
@@ -104,31 +102,30 @@
end
end
class KoalaError < StandardError; end
- # Make an api request using the provided api service or one passed by the caller
- def self.make_request(path, args, verb, options = {})
- http_service = options.delete(:http_service) || Koala.http_service
- options = options.merge(:use_ssl => true) if @always_use_ssl
- http_service.make_request(path, args, verb, options)
- 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
+ # finally, the few things defined on the Koala module itself
class << self
attr_accessor :http_service
- attr_accessor :always_use_ssl
- attr_accessor :base_http_service
end
- Koala.base_http_service = NetHTTPService
- # by default, try requiring Typhoeus -- if that works, use it
- # if you have Typheous and don't want to use it (or want another service),
- # you can run Koala.http_service = NetHTTPService (or MyHTTPService)
- begin
- require 'koala/http_services/typhoeus_service'
- Koala.http_service = TyphoeusService
- rescue LoadError
- Koala.http_service = Koala.base_http_service
+ def self.http_service=(service)
+ if service.respond_to?(:deprecated_interface)
+ # if this is a deprecated module, support the old interface
+ # by changing the default adapter so the right library is used
+ # we continue to use the single HTTPService module for everything
+ service.deprecated_interface
+ else
+ # if it's a real http_service, use it
+ @http_service = service
+ end
end
+
+ def self.make_request(path, args, verb, options = {})
+ http_service.make_request(path, args, verb, options)
+ end
+
+ # we use Faraday as our main service, with mock as the other main one
+ self.http_service = HTTPService
end