Skip to content
arsduo edited this page May 12, 2011 · 20 revisions

Out of the box Koala supports two services to handle the HTTP requests going to and from Facebook’s servers: Net::HTTP and Typhoeus. Both of these services are defined in lib/http_services.rb. By default, Koala will try use Typhoeus. If it is not installed or just not available, Koala will use the Net::HTTP-based service instead.

To force Koala to use one service or another, you can run the following line before using Koala anywhere in your code:

Koala.http_service = NetHTTPService (or TyphoeusService)

If you’d like to implement another HTTP service to be used with Koala, see Extensions.

Always Using HTTPS

Only requests to the Facebook servers that pass an access token must use HTTPS. If you would like to use HTTPS even for calls that do not use access tokens (like getting a person’s public profile information,) you can set the always_use_ssl class attribute to true in both the NetHTTPService and TyphoeusService classes.

Koala.http_service.always_use_ssl = true

HTTP Options

All Graph and REST API methods take an optional hash of parameters that get directly forwarded to the HTTP service to be used when issuing the appropriate HTTP request. The following is a description of all options that can be supplied. Note that the option is supported by both the NetHTTPService and TyphoeusService unless noted otherwise.

:beta

If set to true, the request is sent to the beta version of whichever API (Graph or REST) that you are using. Useful for ensuring your application won’t break as changes are released.

# Sends a request to http://beta.graph.facebook.com 
@graph.get_object('me', {}, {:beta => true})

:use_ssl

If set to true, uses SSL for this particular request, regardless of the type of request. (By default, requests without access tokens are done over http, and those with tokens are done over https.)

# Sends a request to https://graph.facebook.com 
@graph.get_object('me', {}, {:use_ssl => true})

:proxy

NetHTTPService only
Set this to the URL of a proxy server you wish the Net::HTTP request to go through.

# Uses http://my.proxy.com as a proxy
@graph.get_object('me', {}, {:proxy => "http://my.proxy.com"})

:timeout

NetHTTPService only
Sets the Net::HTTP open_timeout and read_timeout attributes to the given value (see http://www.ensta-paristech.fr/~diam/ruby/online/ruby-doc-stdlib/libdoc/net/http/rdoc/classes/Net/HTTP.html for more details).

# Sets the Net::HTTP read_timeout and open_timeout to 10 seconds
@graph.get_object('me', {}, {:timeout => 10})

:typhoeus_options

TyphoeusService only
Use this to pass any options directly to Typhoeus#send.

# Sends the options in typh_options to Typhoeus#send
@graph.get_object('me', {}, {:typhoeus_options => typh_options})

A Note On Typhoeus

When trying to upload photos while using the Typhoeus HTTP service, there were problems when using older versions of Typhoeus. If you are having problems with uploading photos in particular, try upgrading to the latest version of Typhoeus.

Clone this wiki locally