Class: Bisques::AwsRequest
- Inherits:
-
Object
- Object
- Bisques::AwsRequest
- Defined in:
- lib/bisques/aws_request.rb
Overview
A request to an AWS API call. This class must be initiated with a client instance of HTTPClient. A number of mandatory attributes must be set before calling #make_request to return the response. #make_request returns an AwsResponse object.
Instance Attribute Summary collapse
-
#body ⇒ Hash, String
A hash or string describing the form params or HTTP body.
-
#credentials ⇒ AwsCredentials
The AWS credentials.
-
#headers ⇒ Hash
A hash of additional HTTP headers to send with the request.
-
#method ⇒ String
The HTTP method to use.
-
#path ⇒ String
The path to the API call.
-
#query ⇒ Hash
A hash describing the query params to send.
-
#region ⇒ String
The AWS region.
-
#response ⇒ AwsResponse
readonly
An AwsResponse object describing the response.
-
#service ⇒ String
The AWS service.
Class Method Summary collapse
-
.aws_encode(value) ⇒ String
AWS has some particular rules about how it likes it’s form params encoded.
Instance Method Summary collapse
-
#initialize(httpclient) ⇒ AwsRequest
constructor
Create a new AwsRequest using the given HTTPClient object.
-
#make_request ⇒ Object
Send the HTTP request and get a response.
-
#url ⇒ String
The full URL to the API endpoint the request will call.
Constructor Details
#initialize(httpclient) ⇒ AwsRequest
Create a new Bisques::AwsRequest using the given HTTPClient object.
63 64 65 |
# File 'lib/bisques/aws_request.rb', line 63 def initialize(httpclient) @httpclient = httpclient end |
Instance Attribute Details
#body ⇒ Hash, String
Returns A hash or string describing the form params or HTTP body. Only used when the method is POST or PUT.
30 31 32 |
# File 'lib/bisques/aws_request.rb', line 30 def body @body end |
#credentials ⇒ AwsCredentials
Returns The AWS credentials. Should respond to aws_key and aws_secret.
41 42 43 |
# File 'lib/bisques/aws_request.rb', line 41 def credentials @credentials end |
#headers ⇒ Hash
Returns A hash of additional HTTP headers to send with the request.
32 33 34 |
# File 'lib/bisques/aws_request.rb', line 32 def headers @headers end |
#method ⇒ String
Returns The HTTP method to use. Should be GET or POST.
25 26 27 |
# File 'lib/bisques/aws_request.rb', line 25 def method @method end |
#path ⇒ String
Returns The path to the API call. This shouldn’t be the full URL as the host part is built from the region and service.
35 36 37 |
# File 'lib/bisques/aws_request.rb', line 35 def path @path end |
#query ⇒ Hash
Returns A hash describing the query params to send.
27 28 29 |
# File 'lib/bisques/aws_request.rb', line 27 def query @query end |
#region ⇒ String
Returns The AWS region. Ex: us-east-1.
37 38 39 |
# File 'lib/bisques/aws_request.rb', line 37 def region @region end |
#response ⇒ AwsResponse (readonly)
Returns An AwsResponse object describing the response. Returns nil until #make_request has been called.
45 46 47 |
# File 'lib/bisques/aws_request.rb', line 45 def response @response end |
#service ⇒ String
Returns The AWS service. Ex: sqs.
39 40 41 |
# File 'lib/bisques/aws_request.rb', line 39 def service @service end |
Class Method Details
.aws_encode(value) ⇒ String
AWS has some particular rules about how it likes it’s form params encoded.
54 55 56 57 58 |
# File 'lib/bisques/aws_request.rb', line 54 def self.aws_encode(value) value.to_s.gsub(/([^a-zA-Z0-9._~-]+)/n) do '%' + $1.unpack('H2' * $1.size).join('%').upcase end end |
Instance Method Details
#make_request ⇒ Object
Send the HTTP request and get a response. Returns an AwsResponse object. The instance is frozen once this method is called and cannot be used again.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/bisques/aws_request.rb', line 77 def make_request = {} [:header] = .headers.merge( 'Authorization' => . ) [:query] = query if query.any? [:body] = form_body if body http_response = @httpclient.request(method, url, ) @response = AwsResponse.new(self, http_response) freeze @response end |
#url ⇒ String
The full URL to the API endpoint the request will call.
70 71 72 |
# File 'lib/bisques/aws_request.rb', line 70 def url File.join("https://#{service}.#{region}.amazonaws.com", path) end |