Class: Rubizon::Request
- Inherits:
-
Object
- Object
- Rubizon::Request
- Defined in:
- lib/rubizon/request.rb
Overview
Represents a request to be made to AWS.
Starts with access credentials and specifications for the product, such as its ARN, elements of its URL and query elements.
To this is added specifications for the specific action to be performed.
Request builds a URL for the action and signs the request. It then makes the entire URL and various components of it available for whatever transport mechanism is to be used.
A new instance of Request is to be created for each request sent to AWS
Instance Attribute Summary collapse
-
#canonical_querystring ⇒ Object
readonly
An artifact of the signature version 2 signing process: The query string portion of the string to sign.
-
#host ⇒ Object
readonly
Returns the host (domain and subdomains) of the product served by this object.
-
#path ⇒ Object
Returns the path part of the URL of the product served by this object, typically ‘/’.
-
#scheme ⇒ Object
readonly
Returns the URL scheme, such as http or https.
-
#string_to_sign ⇒ Object
readonly
An artifact of the signature version 2 signing process: The string that is used to calculate the signature.
Instance Method Summary collapse
-
#add_query_elements(query_elements) ⇒ Object
Add key/value pairs to the query_elements.
-
#append_to_path(path) ⇒ Object
Append additional elements to the currently defined path.
-
#endpoint ⇒ Object
Returns the product’s endpoint.
-
#initialize(credentials, scheme, host, path, query_elements = {}) ⇒ Request
constructor
Initialize the request.
-
#query_string ⇒ Object
Create a query string from a hash and sign it.
-
#url ⇒ Object
Returns the full URL .
Constructor Details
#initialize(credentials, scheme, host, path, query_elements = {}) ⇒ Request
Initialize the request.
credentials - A Rubizon::SecurityCredentials object that
encapsulates an AWS key pair.
It will be used to sign the request.
scheme - The scheme to be used: ‘http’ or ‘https’ host - The name of the HTTP host to serve this request path - The URL path, typically ‘/’. query_elements - A hash of key/value pairs to be included in the
query string.
_omit - If an element with a key of '_omit' is included,
the value must be an array containing names of keys
to be omitted from the query_elements array before
the request is signed and the query string formed.
This allows allowing SignatureMethod or
SignatureVersion to be specified, even if they are
not to be included in the query string.
SignatureVersion - The signature version to be used, such
as 1 or 2. This should be a numeric value. If not
present, signature version 1 is implied.
SignatureMethod - The signature methods defined for version
two are HmacSHA256 and HmacSHA1.
37 38 39 40 41 42 43 |
# File 'lib/rubizon/request.rb', line 37 def initialize(credentials,scheme,host,path,query_elements={}) @credentials= credentials @scheme= scheme @host= host @path= path @query_elements= query_elements.dup end |
Instance Attribute Details
#canonical_querystring ⇒ Object (readonly)
An artifact of the signature version 2 signing process: The query string portion of the string to sign.
This is of possible debugging value.
111 112 113 |
# File 'lib/rubizon/request.rb', line 111 def canonical_querystring @canonical_querystring end |
#host ⇒ Object (readonly)
Returns the host (domain and subdomains) of the product served by this object.
73 74 75 |
# File 'lib/rubizon/request.rb', line 73 def host @host end |
#path ⇒ Object
Returns the path part of the URL of the product served by this object, typically ‘/’.
77 78 79 |
# File 'lib/rubizon/request.rb', line 77 def path @path end |
#scheme ⇒ Object (readonly)
Returns the URL scheme, such as http or https
69 70 71 |
# File 'lib/rubizon/request.rb', line 69 def scheme @scheme end |
#string_to_sign ⇒ Object (readonly)
An artifact of the signature version 2 signing process: The string that is used to calculate the signature.
This is of possible debugging value.
116 117 118 |
# File 'lib/rubizon/request.rb', line 116 def string_to_sign @string_to_sign end |
Instance Method Details
#add_query_elements(query_elements) ⇒ Object
Add key/value pairs to the query_elements. Typically, these additional elements will be added to specify the action to be taken or subject of that action and parameters of that action or subject.
query_elements - A Hash containing key/value pairs to be added to the
query string.
returns self
63 64 65 66 |
# File 'lib/rubizon/request.rb', line 63 def add_query_elements(query_elements) @query_elements.merge! query_elements self end |
#append_to_path(path) ⇒ Object
Append additional elements to the currently defined path.
46 47 48 |
# File 'lib/rubizon/request.rb', line 46 def append_to_path(path) @path+= path end |
#endpoint ⇒ Object
Returns the product’s endpoint. The endpoint is that part of a URL that includes the scheme, host, and path, but not the query string. An action may extend the product’s path, but otherwise would retain the rest of the endpoint.
83 84 85 |
# File 'lib/rubizon/request.rb', line 83 def endpoint @endpoint||= "#{@scheme}://#{@host}#{@path}" end |
#query_string ⇒ Object
Create a query string from a hash and sign it. The signature algorithm will be determined from the query elements, such as SignatureVersion
The query string, once created, is immutable.
92 93 94 95 96 97 98 99 |
# File 'lib/rubizon/request.rb', line 92 def query_string return @query_string ||= if @query_elements['SignatureVersion'].to_i == 2 query_string_sig2 else raise UnsupportedSignatureVersionError, 'Only signature version 2 requests are supported at this time' end end |
#url ⇒ Object
Returns the full URL
The query string portion of the URL, once created, is immutable.
104 105 106 |
# File 'lib/rubizon/request.rb', line 104 def url endpoint+'?'+query_string end |