Module: Bisques::AwsConnection
- Included in:
- Client
- Defined in:
- lib/bisques/aws_connection.rb
Overview
This module is for making API classes more convenient. The including class must pass the correct params via super from it’s #initialize call. Two useful methods are added to the including class, #request and #action.
Instance Method Summary collapse
-
#action(action_name, path = "/", options = {}) ⇒ AwsResponse
Call an AWS API with the given name at the given path.
-
#initialize(region, service, credentials = AwsCredentials.default) ⇒ Object
Give the region, service and optionally the AwsCredentials.
- #marshal_dump ⇒ Object
- #marshal_load(array) ⇒ Object
-
#request(method, path, query = {}, body = nil, headers = {}) ⇒ AwsRequest
Perform an HTTP query to the given path using the given method (GET, POST, PUT, DELETE).
Instance Method Details
#action(action_name, path = "/", options = {}) ⇒ AwsResponse
The API call will be automatically retried once if the returned status code is in the 500 range.
Call an AWS API with the given name at the given path. An optional hash of options can be passed as arguments for the API call.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/bisques/aws_connection.rb', line 96 def action(action_name, path = "/", = {}) retries = 0 begin # If options given in place of path assume / , path = path, "/" if path.is_a?(Hash) && .empty? request(:post, path, {}, .merge("Action" => action_name)).response.tap do |response| unless response.success? element = response.doc.xpath("//Error") raise AwsActionError.new(element.xpath("Type").text, element.xpath("Code").text, element.xpath("Message").text, response.http_response.status) end end rescue AwsActionError => e if retries < 2 && (500..599).include?(e.status.to_i) retries += 1 retry else raise e end end end |
#initialize(region, service, credentials = AwsCredentials.default) ⇒ Object
Give the region, service and optionally the AwsCredentials.
55 56 57 |
# File 'lib/bisques/aws_connection.rb', line 55 def initialize(region, service, credentials = AwsCredentials.default) @region, @service, @credentials = region, service, credentials end |
#marshal_dump ⇒ Object
118 119 120 |
# File 'lib/bisques/aws_connection.rb', line 118 def marshal_dump [@region, @service, @credentials] end |
#marshal_load(array) ⇒ Object
122 123 124 |
# File 'lib/bisques/aws_connection.rb', line 122 def marshal_load array @region, @service, @credentials = array end |
#request(method, path, query = {}, body = nil, headers = {}) ⇒ AwsRequest
Perform an HTTP query to the given path using the given method (GET, POST, PUT, DELETE). A hash of query params can be specified. A POST or PUT body cna be specified as either a string or a hash of form params. A hash of HTTP headers can be specified.
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/bisques/aws_connection.rb', line 70 def request(method, path, query = {}, body = nil, headers = {}) AwsRequest.new(aws_http_connection).tap do |aws_request| aws_request.credentials = credentials aws_request.path = path aws_request.region = region aws_request.service = service aws_request.method = method aws_request.query = query aws_request.body = body aws_request.headers = headers aws_request.make_request end end |