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
-
#body ⇒ Object
Raw string data to be put in the body of the request.
-
#headers ⇒ Object
readonly
Hash of headers to send with the request.
-
#host ⇒ Object
readonly
Host and Path of the URI this Request will be using.
-
#method ⇒ Object
readonly
HTTP method this Request will use (:get, :post, :put, :delete).
-
#params ⇒ Object
readonly
Hash of parameters to pass in this Request.
-
#path ⇒ Object
Host and Path of the URI this Request will be using.
Instance Method Summary collapse
-
#initialize(method, host, path) ⇒ Request
constructor
Set up a new Request for the given +host+ and +path+ using the given http +method+ (:get, :post, :put, :delete).
-
#uri ⇒ Object
Build up the full URI.
Constructor Details
#initialize(method, host, path) ⇒ Request
Set up a new Request for the given +host+ and +path+ using the given http +method+ (:get, :post, :put, :delete).
132 133 134 135 136 137 138 |
# File 'lib/simple_aws/core/request.rb', line 132 def initialize(method, host, path) @method = method @host = host self.path = path @params = Params.new @headers = {} end |
Instance Attribute Details
#body ⇒ Object
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.
126 127 128 |
# File 'lib/simple_aws/core/request.rb', line 126 def body @body end |
#headers ⇒ Object (readonly)
Hash of headers to send with the request
119 120 121 |
# File 'lib/simple_aws/core/request.rb', line 119 def headers @headers end |
#host ⇒ Object (readonly)
Host and Path of the URI this Request will be using
108 109 110 |
# File 'lib/simple_aws/core/request.rb', line 108 def host @host end |
#method ⇒ Object (readonly)
HTTP method this Request will use (:get, :post, :put, :delete)
103 104 105 |
# File 'lib/simple_aws/core/request.rb', line 103 def method @method end |
#params ⇒ Object (readonly)
Hash of parameters to pass in this Request. See top-level documentation for any special handling of types
114 115 116 |
# File 'lib/simple_aws/core/request.rb', line 114 def params @params end |
#path ⇒ Object
Host and Path of the URI this Request will be using
108 109 110 |
# File 'lib/simple_aws/core/request.rb', line 108 def path @path end |
Instance Method Details
#uri ⇒ Object
Build up the full URI
143 144 145 |
# File 'lib/simple_aws/core/request.rb', line 143 def uri "#{host}#{path}" end |