Module: ApiAuth::Rails::ActiveResourceExtension::Connection

Defined in:
lib/api_auth/railtie.rb

Overview

BaseApiAuth

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object


57
58
59
60
61
62
63
64
# File 'lib/api_auth/railtie.rb', line 57

def self.included(base)
  base.send :alias_method, :request_without_auth, :request
  base.send :alias_method, :request,              :request_with_auth

  base.class_eval do
    attr_accessor :hmac_secret_key, :hmac_access_id, :use_hmac, :api_auth_options
  end
end

Instance Method Details

#request_with_auth(method, path, *arguments) ⇒ Object


66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/api_auth/railtie.rb', line 66

def request_with_auth(method, path, *arguments)
  if use_hmac && hmac_access_id && hmac_secret_key
    h = arguments.last
    tmp = "Net::HTTP::#{method.to_s.capitalize}".constantize.new(path, h)
    tmp.body = arguments[0] if arguments.length > 1
    ApiAuth.sign!(tmp, hmac_access_id, hmac_secret_key, api_auth_options)
    arguments.last['Content-MD5'] = tmp['Content-MD5'] if tmp['Content-MD5']
    arguments.last['DATE'] = tmp['DATE']
    arguments.last['Authorization'] = tmp['Authorization']
  end

  request_without_auth(method, path, *arguments)
end