class Hoodoo::Services::Middleware::Interaction
Encapsulate all data related to an interaction (API call) within one object.
Attributes
A Hoodoo::Services::Context
instance representing this API call. May be updated/replaced during processing.
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.
The inbound Rack
request; a Rack::Request
instance.
The requested action, as a symbol; see Hoodoo::Services::Middleware::ALLOWED_ACTIONS.
The requested content encoding as a String - e.g. “utf-8”.
The requested content type as a String - e.g. “application/json”.
The target Hoodoo::Services::Implementation
instance for the API call. See target_interface
.
The Hoodoo::Services::Interface
subclass describing the resource interface that is the target of the API call.
Public Class Methods
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 thisInteraction
will use - without validation - whatever value the header holds, else a newUUID
is generated. owning_middleware_instance
session
-
The session data attached to the
context
value; optional; if omitted,nil
is used.
# 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
Public Instance Methods
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.
# File lib/hoodoo/services/middleware/interaction.rb, line 68 def using_test_session @using_test_session = true end
Returns true
if Hoodoo
has previously called using_test_session
.
# File lib/hoodoo/services/middleware/interaction.rb, line 74 def using_test_session? @using_test_session == true end