Module: AuthHMAC::Rails::ActiveResourceExtension::BaseHmac::ClassMethods

Defined in:
lib/auth-hmac.rb

Instance Method Summary collapse

Instance Method Details

#connection_with_hmac(refresh = false) ⇒ Object

:nodoc:



355
356
357
358
359
360
361
362
# File 'lib/auth-hmac.rb', line 355

def connection_with_hmac(refresh = false) # :nodoc: 
  c = connection_without_hmac(refresh)
  c.hmac_access_id = self.hmac_access_id
  c.hmac_secret = self.hmac_secret
  c.use_hmac = self.use_hmac
  c.hmac_options = self.hmac_options
  c
end

#with_auth_hmac(access_id, secret = nil, options = nil) ⇒ Object

Call with an Active Resource class definition to sign all HTTP requests sent by that class with the provided credentials.

Can be called with either a hash or two separate parameters like so:

class MyResource < ActiveResource::Base
  with_auth_hmac("my_access_id", "my_secret")
end

or

class MyOtherResource < ActiveResource::Base
  with_auth_hmac("my_access_id" => "my_secret")
end

This has only been tested with Rails 2.1 and since it is virtually a monkey patch of the internals of ActiveResource it might not work with past or future versions.



339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
# File 'lib/auth-hmac.rb', line 339

def with_auth_hmac(access_id, secret = nil, options = nil)
  if access_id.is_a?(Hash)
    self.hmac_access_id = access_id.keys.first
    self.hmac_secret = access_id[self.hmac_access_id]
  else
    self.hmac_access_id = access_id
    self.hmac_secret = secret
  end
  self.use_hmac = true
  self.hmac_options = options
  
  class << self
    alias_method_chain :connection, :hmac
  end
end