Class: Hoodoo::Services::Middleware::Interaction
- Inherits:
-
Object
- Object
- Hoodoo::Services::Middleware::Interaction
- Defined in:
- lib/hoodoo/services/middleware/interaction.rb
Overview
Encapsulate all data related to an interaction (API call) within one object.
Instance Attribute Summary collapse
-
#context ⇒ Object
A Hoodoo::Services::Context instance representing this API call.
-
#interaction_id ⇒ Object
readonly
Every interaction has a UUID passed back in API responses via the X-Interaction-ID HTTP header.
-
#owning_middleware_instance ⇒ Object
readonly
API calls are handled by the middleware, so Interactions are created by Hoodoo::Services::Middleware instances.
-
#rack_request ⇒ Object
readonly
The inbound Rack request; a
Rack::Request
instance. -
#requested_action ⇒ Object
The requested action, as a symbol; see Hoodoo::Services::Middleware::ALLOWED_ACTIONS.
-
#requested_content_encoding ⇒ Object
The requested content encoding as a String - e.g.
-
#requested_content_type ⇒ Object
The requested content type as a String - e.g.
-
#target_implementation ⇒ Object
The target Hoodoo::Services::Implementation instance for the API call.
-
#target_interface ⇒ Object
The Hoodoo::Services::Interface subclass describing the resource interface that is the target of the API call.
Instance Method Summary collapse
-
#initialize(env, owning_middleware_instance, session = nil) ⇒ Interaction
constructor
Create a new Interaction instance, acquiring a new interaction ID automatically or picking up one from an X-Interaction-ID header if available.
-
#using_test_session ⇒ Object
Hoodoo middleware calls here to say “I’m using the test session” (or not), so that this can be enquired about via #using_test_session? if need be.
-
#using_test_session? ⇒ Boolean
Returns
true
if Hoodoo has previously called #using_test_session.
Constructor Details
#initialize(env, owning_middleware_instance, session = nil) ⇒ Interaction
Create a new Interaction instance, acquiring a new interaction ID automatically or picking up one from an X-Interaction-ID header if available.
A new context instance (see #context) is generated with a new empty request and response object attached, along with nil
session data or the given session information in the input parameters:
env
-
The raw Rack request Hash. May be “{}” in some test scenarios. Converted to a Rack::Request instance. If this describes an X-Interaction-ID header then this Interaction will use - without validation - whatever value the header holds, else a new UUID is generated.
owning_middleware_instance
-
See #owning_middleware_instance.
session
-
The session data attached to the #context value; optional; if omitted,
nil
is used.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/hoodoo/services/middleware/interaction.rb', line 98 def initialize( env, owning_middleware_instance, session = nil ) @rack_request = ::Rack::Request.new( env ) @interaction_id = find_or_generate_interaction_id() @context = Hoodoo::Services::Context.new( session, Hoodoo::Services::Request.new, Hoodoo::Services::Response.new( @interaction_id ), self ) @owning_middleware_instance = owning_middleware_instance @context.request.headers = env.select() do | k,v | k.to_s.start_with?( 'HTTP_' ) || k == 'CONTENT_TYPE' || k == 'CONTENT_LENGTH' end.freeze() end |
Instance Attribute Details
#context ⇒ Object
A Hoodoo::Services::Context instance representing this API call. May be updated/replaced during processing.
39 40 41 |
# File 'lib/hoodoo/services/middleware/interaction.rb', line 39 def context @context end |
#interaction_id ⇒ Object (readonly)
Every interaction has a UUID passed back in API responses via the X-Interaction-ID HTTP header. This is that UUID.
34 35 36 |
# File 'lib/hoodoo/services/middleware/interaction.rb', line 34 def interaction_id @interaction_id end |
#owning_middleware_instance ⇒ Object (readonly)
API calls are handled by the middleware, so Interactions are created by Hoodoo::Services::Middleware instances. This is that creating instance, or the instance that should be treated as if it were the creator.
25 26 27 |
# File 'lib/hoodoo/services/middleware/interaction.rb', line 25 def owning_middleware_instance @owning_middleware_instance end |
#rack_request ⇒ Object (readonly)
The inbound Rack request; a Rack::Request
instance.
29 30 31 |
# File 'lib/hoodoo/services/middleware/interaction.rb', line 29 def rack_request @rack_request end |
#requested_action ⇒ Object
The requested action, as a symbol; see Hoodoo::Services::Middleware::ALLOWED_ACTIONS.
54 55 56 |
# File 'lib/hoodoo/services/middleware/interaction.rb', line 54 def requested_action @requested_action end |
#requested_content_encoding ⇒ Object
The requested content encoding as a String - e.g. “utf-8”.
62 63 64 |
# File 'lib/hoodoo/services/middleware/interaction.rb', line 62 def requested_content_encoding @requested_content_encoding end |
#requested_content_type ⇒ Object
The requested content type as a String - e.g. “application/json”.
58 59 60 |
# File 'lib/hoodoo/services/middleware/interaction.rb', line 58 def requested_content_type @requested_content_type end |
#target_implementation ⇒ Object
The target Hoodoo::Services::Implementation instance for the API call. See #target_interface.
49 50 51 |
# File 'lib/hoodoo/services/middleware/interaction.rb', line 49 def target_implementation @target_implementation end |
#target_interface ⇒ Object
The Hoodoo::Services::Interface subclass describing the resource interface that is the target of the API call.
44 45 46 |
# File 'lib/hoodoo/services/middleware/interaction.rb', line 44 def target_interface @target_interface end |
Instance Method Details
#using_test_session ⇒ Object
Hoodoo middleware calls here to say “I’m using the test session” (or not), so that this can be enquired about via #using_test_session? if need be.
68 69 70 |
# File 'lib/hoodoo/services/middleware/interaction.rb', line 68 def using_test_session @using_test_session = true end |
#using_test_session? ⇒ Boolean
Returns true
if Hoodoo has previously called #using_test_session.
74 75 76 |
# File 'lib/hoodoo/services/middleware/interaction.rb', line 74 def using_test_session? @using_test_session == true end |