Class: Hoodoo::Services::Request
- Inherits:
-
Object
- Object
- Hoodoo::Services::Request
- Defined in:
- lib/hoodoo/services/services/request.rb
Overview
Instances of the Hoodoo::Services::Request class are passed to service interface implementations when requests come in via Rack, after basic checks have been passed and a particular interface implementation has been identified by endpoint.
Descriptions of default values expected out of accessors herein refer to the use case when driven through Hoodoo::Services::Middleware. If the class is instantiated “bare” it gains no default values at all (all read accessors would report nil
).
Defined Under Namespace
Classes: ListParameters
Instance Attribute Summary collapse
-
#body ⇒ Object
Parsed payload hash, for create and update actions only; else
nil
. -
#embeds ⇒ Object
Array of strings giving requested embedded items; [] if there are none requested.
-
#headers ⇒ Object
Hash of HTTP headers in Rack format - e.g.
-
#ident ⇒ Object
readonly
The first entry in the #uri_path_components array, or
nil
if the array is empty. -
#list ⇒ Object
The Hoodoo::Services::Request::ListParameters instance associated with this request.
-
#locale ⇒ Object
Requested locale for internationalised operations; “en-nz” by default.
-
#references ⇒ Object
Array of strings giving requested referenced items; [] if there are none requested.
-
#uri_path_components ⇒ Object
An array of zero or more path components making up the URI after the service endpoint has been accounted for.
-
#uri_path_extension ⇒ Object
A filename extension on the URI path component, if any, else an empty string.
Instance Method Summary collapse
-
#initialize ⇒ Request
constructor
Set up defaults in this instance.
Constructor Details
#initialize ⇒ Request
Set up defaults in this instance.
178 179 180 181 182 183 184 185 186 |
# File 'lib/hoodoo/services/services/request.rb', line 178 def initialize self.locale = 'en-nz' self.uri_path_components = [] self.uri_path_extension = '' self.list = Hoodoo::Services::Request::ListParameters.new self. = [] self.references = [] self.headers = {}.freeze end |
Instance Attribute Details
#body ⇒ Object
Parsed payload hash, for create and update actions only; else nil
.
90 91 92 |
# File 'lib/hoodoo/services/services/request.rb', line 90 def body @body end |
#embeds ⇒ Object
Array of strings giving requested embedded items; [] if there are none requested.
169 170 171 |
# File 'lib/hoodoo/services/services/request.rb', line 169 def @embeds end |
#headers ⇒ Object
Hash of HTTP headers in Rack format - e.g. HTTP_X_INTERACTION_ID
for the “X-Interaction-ID” header, for read-only use. All keys are in upper case, are Strings, have “HTTP_” at the start and use underscores where the original request might’ve used an underscore or hyphen. The usual curious Rack exceptions of CONTENT_TYPE
and CONTENT_LENGTH
do apply, though. This is a superset of header values including those sent by the client in its request and anything Rack itself might have added.
86 87 88 |
# File 'lib/hoodoo/services/services/request.rb', line 86 def headers @headers end |
#ident ⇒ Object (readonly)
The first entry in the #uri_path_components array, or nil
if the array is empty. This supports a common case for inter-resource calls where a UUID or other unique identifier is provided through the first path element (“.../v1/resource/uuid
”).
128 129 130 |
# File 'lib/hoodoo/services/services/request.rb', line 128 def ident @ident end |
#list ⇒ Object
The Hoodoo::Services::Request::ListParameters instance associated with this request.
145 146 147 |
# File 'lib/hoodoo/services/services/request.rb', line 145 def list @list end |
#locale ⇒ Object
Requested locale for internationalised operations; “en-nz” by default.
71 72 73 |
# File 'lib/hoodoo/services/services/request.rb', line 71 def locale @locale end |
#references ⇒ Object
Array of strings giving requested referenced items; [] if there are none requested.
174 175 176 |
# File 'lib/hoodoo/services/services/request.rb', line 174 def references @references end |
#uri_path_components ⇒ Object
An array of zero or more path components making up the URI after the service endpoint has been accounted for. For example, with a service endpoint of “products”, this URI:
http://test.com/v1/products/1234/foo.json
…would lead to this path component array:
[ '1234', 'foo' ]
The first element of the path components array is exposed in the read-only #ident accessor.
105 106 107 |
# File 'lib/hoodoo/services/services/request.rb', line 105 def uri_path_components @uri_path_components end |
#uri_path_extension ⇒ Object
A filename extension on the URI path component, if any, else an empty string. The first dot in the last path component is looked for (see also #uri_path_components), so for example this URI:
http://test.com/v1/products/1.2.3.4/foo.my.tar.gz
…would lead to this URI path extension string:
'my.tar.gz'
140 141 142 |
# File 'lib/hoodoo/services/services/request.rb', line 140 def uri_path_extension @uri_path_extension end |