Skip to content

Instantly share code, notes, and snippets.

@croaky
Created October 9, 2008 19:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save croaky/15849 to your computer and use it in GitHub Desktop.
Save croaky/15849 to your computer and use it in GitHub Desktop.
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