Class: SimpleAWS::Request
- Inherits:
-
Object
- Object
- SimpleAWS::Request
- Defined in:
- lib/simple_aws/core/request.rb
Overview
Defines a request to an Amazon API.
Requests need to know a number of attributes to work, including the host, path, the HTTP method, and any params or POST bodies. Most of this is straight forward through the constructor and setter methods defined below.
One of the more interesting aspects of the AWS API are the indexed parameters. These are the parameters in the document defined thusly:
Filter.n.Name
Filter.n.Value.m
This class has special handling to facilitate building these parameters from regular Ruby Hashes and Arrays, but does not prevent you from specifying these parameters exactly as defined. For the example above, here are the ways you can set these parameters:
By yourself, filling in the n and m as you need:
request.params.merge({
"Filter.1.Name" => "domain",
"Filter.1.Value" => "vpc",
"Filter.2.Name" => "ids",
"Filter.2.Value.1" => "i-1234",
"Filter.2.Value.2" => "i-8902"
})
Or let Request handle the indexing and numbering for you:
request.params["Filter"] = [
{"Name" => "domain", "Value" => "vpc"},
{"Name" => "ids", "Value" => ["i-1234", "i-8902"]}
]
Straight arrays are handled as well:
request.params["InstanceId"] = ["i-1234", "i-8970"]
In an effort to make this library as transparent as possible when working directly with the AWS API, the keys of the hashes must be the values specified in the API, and the values must be Hashes and/or Arrays who contain easily String-serializable keys and values.
A more detailed example can be found in test/simple_aws/request_test.rb where you can
see how to use many levels of nesting to build your AWS request.
Defined Under Namespace
Classes: Params
Instance Attribute Summary (collapse)
-
- (Object) body
Raw string data to be put in the body of the request.
-
- (Object) headers
readonly
Hash of headers to send with the request.
-
- (Object) host
readonly
Host and Path of the URI this Request will be using.
-
- (Object) method
readonly
HTTP method this Request will use (:get, :post, :put, :delete).
-
- (Object) params
readonly
Hash of parameters to pass in this Request.
-
- (Object) path
Host and Path of the URI this Request will be using.
Instance Method Summary (collapse)
-
- (Request) initialize(method, host, path)
constructor
Set up a new Request for the given +host+ and +path+ using the given http +method+ (:get, :post, :put, :delete).
-
- (Object) uri
Build up the full URI.
Constructor Details
- (Request) initialize(method, host, path)
Set up a new Request for the given +host+ and +path+ using the given http +method+ (:get, :post, :put, :delete).
125 126 127 128 129 130 131 |
# File 'lib/simple_aws/core/request.rb', line 125 def initialize(method, host, path) @method = method @host = host self.path = path @params = Params.new @headers = {} end |
Instance Attribute Details
- (Object) body
Raw string data to be put in the body of the request. Body can also be an IO object (something that response to #read) and if so the request will stream the file to the server.
119 120 121 |
# File 'lib/simple_aws/core/request.rb', line 119 def body @body end |
- (Object) headers (readonly)
Hash of headers to send with the request
112 113 114 |
# File 'lib/simple_aws/core/request.rb', line 112 def headers @headers end |
- (Object) host (readonly)
Host and Path of the URI this Request will be using
101 102 103 |
# File 'lib/simple_aws/core/request.rb', line 101 def host @host end |
- (Object) method (readonly)
HTTP method this Request will use (:get, :post, :put, :delete)
96 97 98 |
# File 'lib/simple_aws/core/request.rb', line 96 def method @method end |
- (Object) params (readonly)
Hash of parameters to pass in this Request. See top-level documentation for any special handling of types
107 108 109 |
# File 'lib/simple_aws/core/request.rb', line 107 def params @params end |
- (Object) path
Host and Path of the URI this Request will be using
101 102 103 |
# File 'lib/simple_aws/core/request.rb', line 101 def path @path end |
Instance Method Details
- (Object) uri
Build up the full URI
136 137 138 |
# File 'lib/simple_aws/core/request.rb', line 136 def uri "#{host}#{path}" end |