Class: AceClient::Base4
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.
-
#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) ⇒ Base4
constructor
A new instance of Base4.
- #querystring ⇒ Object
Methods inherited from Base
#endpoint_url, #record_response, #set_http_proxy
Constructor Details
#initialize(options) ⇒ Base4
Returns a new instance of Base4.
9 10 11 12 13 |
# File 'lib/ace-client/base4.rb', line 9 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/base4.rb', line 5 def body @body end |
#datetime ⇒ Object
Returns the value of attribute datetime.
7 8 9 |
# File 'lib/ace-client/base4.rb', line 7 def datetime @datetime end |
#headers ⇒ Object
Returns the value of attribute headers.
3 4 5 |
# File 'lib/ace-client/base4.rb', line 3 def headers @headers end |
#region ⇒ Object
Returns the value of attribute region.
4 5 6 |
# File 'lib/ace-client/base4.rb', line 4 def region @region end |
#service ⇒ Object
Returns the value of attribute service.
6 7 8 |
# File 'lib/ace-client/base4.rb', line 6 def service @service end |
Instance Method Details
#action(action, params = {}) ⇒ Object
15 16 17 18 |
# File 'lib/ace-client/base4.rb', line 15 def action(action, params={}) params.update('Action' => action) execute(params) end |
#add_authorization! ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'lib/ace-client/base4.rb', line 80 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
20 21 22 23 24 25 26 27 |
# File 'lib/ace-client/base4.rb', line 20 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
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ace-client/base4.rb', line 29 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
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/ace-client/base4.rb', line 54 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
70 71 72 73 74 75 76 77 78 |
# File 'lib/ace-client/base4.rb', line 70 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 |