Encapsulate all data related to an interaction (API call) within one object.

Methods
N
U
Attributes
[RW] context

A Hoodoo::Services::Context instance representing this API call. May be updated/replaced during processing.

[R] interaction_id

Every interaction has a UUID passed back in API responses via the X-Interaction-ID HTTP header. This is that UUID.

[R] owning_middleware_instance

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.

[R] rack_request

The inbound Rack request; a Rack::Request instance.

[RW] requested_action

The requested action, as a symbol; see Hoodoo::Services::Middleware::ALLOWED_ACTIONS.

[RW] requested_content_encoding

The requested content encoding as a String - e.g. “utf-8”.

[RW] requested_content_type

The requested content type as a String - e.g. “application/json”.

[RW] target_implementation

The target Hoodoo::Services::Implementation instance for the API call. See target_interface.

[RW] target_interface

The Hoodoo::Services::Interface subclass describing the resource interface that is the target of the API call.

Class Public methods
new( env, owning_middleware_instance, session = nil )

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.

# 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 Public methods
using_test_session()

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
using_test_session?()

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