Class: AceClient::Query3
Instance Attribute Summary collapse
-
#http_method ⇒ Object
Returns the value of attribute http_method.
-
#sampler ⇒ Object
Returns the value of attribute sampler.
-
#signature_method ⇒ Object
TODO: HMAC-SHA256 or HMAC-SHA1.
Attributes inherited from Base
#access_key_id, #endpoint, #http_proxy, #last_response, #last_response_time, #secret_access_key, #use_ssl, #user_agent
Instance Method Summary collapse
- #action(action, params = {}) ⇒ Object
- #create_signature ⇒ Object
- #date ⇒ Object
- #dryrun(action, params = {}) ⇒ Object
- #execute(params = {}, dryrun = false) ⇒ Object
-
#initialize(options = {}) ⇒ Query3
constructor
A new instance of Query3.
- #string_to_sign ⇒ Object
Methods inherited from Base
#endpoint_url, #record_response, #set_http_proxy
Constructor Details
#initialize(options = {}) ⇒ Query3
Returns a new instance of Query3.
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/ace-client/query3.rb', line 14 def initialize(={}) super() @signature_method = [:signature_method] || 'HmacSHA256' @authorization_key = [:authorization_key] || 'authorization' @date_key = [:date_key] || 'x-date' @nonce_key = [:nonce_key] || 'x-amz-nonce' @authorization_prefix = [:authorization_prefix] || 'AWS3-HTTPS' @nonce = [:nonce] @sampler = [:sampler] @before_signature = [:before_signature] @before_request = [:before_request] end |
Instance Attribute Details
#http_method ⇒ Object
Returns the value of attribute http_method.
8 9 10 |
# File 'lib/ace-client/query3.rb', line 8 def http_method @http_method end |
#sampler ⇒ Object
Returns the value of attribute sampler.
10 11 12 |
# File 'lib/ace-client/query3.rb', line 10 def sampler @sampler end |
#signature_method ⇒ Object
TODO: HMAC-SHA256 or HMAC-SHA1
9 10 11 |
# File 'lib/ace-client/query3.rb', line 9 def signature_method @signature_method end |
Instance Method Details
#action(action, params = {}) ⇒ Object
28 29 30 31 |
# File 'lib/ace-client/query3.rb', line 28 def action(action, params={}) params.update('Action' => action) execute(params) end |
#create_signature ⇒ Object
72 73 74 75 |
# File 'lib/ace-client/query3.rb', line 72 def create_signature digest = OpenSSL::Digest::Digest.new(@signature_method.downcase.gsub(/hmac/, '')) Base64.encode64(OpenSSL::HMAC.digest(digest, secret_access_key, string_to_sign)).strip end |
#date ⇒ Object
81 82 83 |
# File 'lib/ace-client/query3.rb', line 81 def date @date ||= Time.now.utc.rfc822.gsub(/[\-\+]\d{4}$/, 'GMT') end |
#dryrun(action, params = {}) ⇒ Object
33 34 35 36 |
# File 'lib/ace-client/query3.rb', line 33 def dryrun(action, params={}) params.update('Action' => action) execute(params, true) end |
#execute(params = {}, dryrun = false) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ace-client/query3.rb', line 38 def execute(params={}, dryrun=false) @params = params @params['Version'] = @version if @version @before_signature.call(@params) if @before_signature signature = create_signature = self.class..dup [:headers] = {} [:headers]['Date'] = date [:headers][@authorization_key] = "#{@authorization_prefix} #{@access_key_id_key}=#{access_key_id},Algorithm=#{signature_method},Signature=#{signature}" [:headers]['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8' [:headers]['User-Agent'] = @user_agent if @user_agent [:headers][@nonce_key] = @nonce if @nonce if http_method == :get [:query] = @params http_method_class = Net::HTTP::Get elsif http_method == :post [:body] = @params http_method_class = Net::HTTP::Post end @before_request.call(@params) if @before_request request = HTTParty::Request.new(http_method_class, endpoint_url + @path, ) if dryrun request else record_response { request.perform } end end |
#string_to_sign ⇒ Object
77 78 79 |
# File 'lib/ace-client/query3.rb', line 77 def string_to_sign @nonce ? date + @nonce : date end |