Created
October 9, 2008 19:17
-
-
Save croaky/15849 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module TimedOutConnection | |
# overrides the Net::HTTP object | |
# used by ActiveResource::Connection | |
def http | |
http_obj = super | |
http_obj.open_timeout = 2 # seconds | |
http_obj.read_timeout = 5 # seconds | |
http_obj | |
end | |
end | |
SITE_ENVS = Hash.new('http://test.example.com') | |
SITE_ENVS['staging'] = 'http://test.example.com' | |
SITE_ENVS['production'] = 'http://example.com' | |
class ExampleResource < ActiveResource::Base | |
self.site = SITE_ENVS[RAILS_ENV] | |
self.basic_auth 'user', 'password' | |
def connection(*args) | |
connection = super | |
connection.extend TimedOutConnection | |
connection | |
end | |
class << self | |
@@api_key = "key" | |
def find(*arguments) | |
arguments.last[:params].update({ :key => @@api_key }) | |
super(*arguments) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment