Sha256: bd03c3615fdcb774baa11db33540a5f8145c0f1b2b64d9a4af59d43a887dbfd4

Contents?: true

Size: 1.53 KB

Versions: 6

Compression:

Stored size: 1.53 KB

Contents

require 'openssl'
require 'cgi'
require 'nokogiri'
require 'time'

module AceClient
  class Query3 < Base3
    attr_accessor :http_method

    format :xml

    def action(action, params={})
      params.update('Action' => action)
      execute(params)
    end

    def dryrun(action, params={})
      params.update('Action' => action)
      execute(params, true)
    end

    def execute(params={}, dryrun=false)
      @params = params
      @params['Version'] = @version if @version

      @before_signature.call(@params) if @before_signature

      signature = create_signature

      options = self.class.default_options.dup
      options[:headers] = {}
      options[:headers]['Date'] = date
      options[:headers][@authorization_key] = "#{@authorization_prefix} #{@access_key_id_key}=#{access_key_id},Algorithm=#{signature_method},Signature=#{signature}"
      options[:headers]['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8'
      options[:headers]['User-Agent'] = @user_agent if @user_agent
      options[:headers][@nonce_key] = @nonce if @nonce

      if http_method == :get
        options[:query] = @params
        http_method_class = Net::HTTP::Get
      elsif http_method == :post
        options[: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, options)
      if dryrun
        request
      else
        record_response { request.perform }
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ace-client-0.0.23 lib/ace-client/query3.rb
ace-client-0.0.22 lib/ace-client/query3.rb
ace-client-0.0.21 lib/ace-client/query3.rb
ace-client-0.0.20 lib/ace-client/query3.rb
ace-client-0.0.19 lib/ace-client/query3.rb
ace-client-0.0.18 lib/ace-client/query3.rb