Class: Linzer::Message::Adapter::Generic::Response Abstract

Inherits:
Abstract
  • Object
show all
Defined in:
lib/linzer/message/adapter/generic/response.rb

Overview

This class is abstract.

Subclass must implement #derived method.

Generic HTTP response adapter.

Provides a base implementation for response message access. Assumes the operation responds to [] for header access.

Direct Known Subclasses

HTTPGem::Response, NetHTTP::Response

Instance Method Summary collapse

Methods inherited from Abstract

#[], #attached_request?, #field?, #request?, #response?

Constructor Details

#initialize(operation, **options) ⇒ Response

Creates a new response adapter.

Parameters:

  • operation (Object)

    The HTTP response object

  • options (Hash)

    Additional options

Options Hash (**options):

  • :attached_request (Object)

    An associated request for ‘;req` parameter support



19
20
21
22
23
24
25
# File 'lib/linzer/message/adapter/generic/response.rb', line 19

def initialize(operation, **options)
  @operation = operation
  attached_request = options[:attached_request]
  @attached_request = attached_request ? Message.new(attached_request) : nil
  validate_attached_request @attached_request if @attached_request
  freeze
end

Instance Method Details

#attach!(signature) ⇒ Object

Attaches a signature to the response.

Parameters:

  • signature (Signature)

    The signature to attach

Returns:

  • (Object)

    The underlying response object



37
38
39
40
# File 'lib/linzer/message/adapter/generic/response.rb', line 37

def attach!(signature)
  signature.to_h.each { |h, v| @operation[h] = v }
  @operation
end

#header(name) ⇒ String?

Retrieves a header value by name.

Parameters:

  • name (String)

    The header name

Returns:

  • (String, nil)

    The header value



30
31
32
# File 'lib/linzer/message/adapter/generic/response.rb', line 30

def header(name)
  @operation[name]
end