Class: AceClient::Query3

Inherits:
Base3 show all
Defined in:
lib/ace-client/query3.rb

Instance Attribute Summary collapse

Attributes inherited from Base3

#sampler, #signature_method

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

Methods inherited from Base3

#create_signature, #date, #initialize, #string_to_sign

Methods inherited from Base

#endpoint_url, #initialize, #record_response, #set_http_proxy

Constructor Details

This class inherits a constructor from AceClient::Base3

Instance Attribute Details

#http_methodObject

Returns the value of attribute http_method.



8
9
10
# File 'lib/ace-client/query3.rb', line 8

def http_method
  @http_method
end

Instance Method Details

#action(action, params = {}) ⇒ Object



12
13
14
15
# File 'lib/ace-client/query3.rb', line 12

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

#dryrun(action, params = {}) ⇒ Object



17
18
19
20
# File 'lib/ace-client/query3.rb', line 17

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

#execute(params = {}, dryrun = false) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ace-client/query3.rb', line 22

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