Class: AceClient::Query4
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#datetime ⇒ Object
Returns the value of attribute datetime.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#query ⇒ Object
Returns the value of attribute query.
-
#region ⇒ Object
Returns the value of attribute region.
-
#service ⇒ Object
Returns the value of attribute service.
Attributes inherited from Base
#access_key_id, #endpoint, #http_method, #http_proxy, #last_response, #last_response_time, #secret_access_key, #use_ssl, #user_agent
Instance Method Summary collapse
- #action(action, params = {}) ⇒ Object
- #add_authorization! ⇒ Object
- #execute(params) ⇒ Object
- #execute_get(params) ⇒ Object
- #execute_post(params) ⇒ Object
-
#initialize(options) ⇒ Query4
constructor
A new instance of Query4.
- #querystring ⇒ Object
Methods inherited from Base
#endpoint_url, #record_response, #set_http_proxy
Constructor Details
#initialize(options) ⇒ Query4
Returns a new instance of Query4.
12 13 14 15 16 |
# File 'lib/ace-client/query4.rb', line 12 def initialize() super() @service = [:service] @region = [:region] end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
5 6 7 |
# File 'lib/ace-client/query4.rb', line 5 def body @body end |
#datetime ⇒ Object
Returns the value of attribute datetime.
7 8 9 |
# File 'lib/ace-client/query4.rb', line 7 def datetime @datetime end |
#headers ⇒ Object
Returns the value of attribute headers.
3 4 5 |
# File 'lib/ace-client/query4.rb', line 3 def headers @headers end |
#query ⇒ Object
Returns the value of attribute query.
8 9 10 |
# File 'lib/ace-client/query4.rb', line 8 def query @query end |
#region ⇒ Object
Returns the value of attribute region.
4 5 6 |
# File 'lib/ace-client/query4.rb', line 4 def region @region end |
#service ⇒ Object
Returns the value of attribute service.
6 7 8 |
# File 'lib/ace-client/query4.rb', line 6 def service @service end |
Instance Method Details
#action(action, params = {}) ⇒ Object
18 19 20 21 |
# File 'lib/ace-client/query4.rb', line 18 def action(action, params={}) params.update('Action' => action) execute(params) end |
#add_authorization! ⇒ Object
83 84 85 86 87 88 89 90 |
# File 'lib/ace-client/query4.rb', line 83 def headers['content-type'] ||= 'application/x-www-form-urlencoded' headers['host'] = endpoint headers['x-amz-date'] = datetime #headers['x-amz-security-token'] = credentials.session_token if credentials.session_token headers['x-amz-content-sha256'] ||= hexdigest(body || '') headers['authorization'] = (datetime) end |
#execute(params) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/ace-client/query4.rb', line 23 def execute(params) @datetime = Time.now.utc.strftime("%Y%m%dT%H%M%SZ") if http_method == :get execute_get(params) else http_method == :post execute_post(params) end end |
#execute_get(params) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/ace-client/query4.rb', line 32 def execute_get(params) @headers = {} @headers['host'] = @endpoint @params = params @params['Version'] = @version if @version @params.update( 'X-Amz-Algorithm' => 'AWS4-HMAC-SHA256', 'X-Amz-Credential' => access_key_id + '/' + credential_string(datetime), 'X-Amz-Date' => datetime, 'X-Amz-SignedHeaders' => signed_headers ) = self.class..dup [:query] = @params request = HTTParty::Request.new(Net::HTTP::Get, endpoint_url + @path, ) @query = request.send(:normalize_query, [:query]) @params.update('X-Amz-Signature' => signature(datetime)) @body = '' request = HTTParty::Request.new(Net::HTTP::Get, endpoint_url + @path, ) request.perform end |
#execute_post(params) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/ace-client/query4.rb', line 57 def execute_post(params) @params = params = {} = self.class..dup [:body] = @params request = HTTParty::Request.new(Net::HTTP::Post, endpoint_url + @path, ) @body = request.send(:normalize_query, [:body]) @headers = {} [:headers] = headers request = HTTParty::Request.new(Net::HTTP::Post, endpoint_url + @path, ) request.perform end |
#querystring ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'lib/ace-client/query4.rb', line 73 def querystring if http_method == :post '' elsif http_method == :get @params.sort.collect { |param| "#{CGI::escape(param[0])}=#{CGI::escape(param[1])}" }.join("&").gsub('+', '%20').gsub('%7E', '~') end end |