Class: Linzer::Message::Adapter::Generic::Request

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

Overview

Generic HTTP request adapter.

Provides a base implementation for request message access. Assumes the operation responds to [] for header access and has a uri attribute.

Examples:

Creating a custom adapter

class MyRequestAdapter < Linzer::Message::Adapter::Generic::Request
  private
  def derived(name)
    return @operation.http_method if name.value == "@method"
    super
  end
end

Direct Known Subclasses

HTTPGem::Request, NetHTTP::Request

Instance Method Summary collapse

Methods inherited from Abstract

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

Constructor Details

#initialize(operation, **options) ⇒ Request

Creates a new request adapter.

Parameters:

  • operation (Object)

    The HTTP request object

  • options (Hash)

    Additional options (unused in base class)



31
32
33
34
# File 'lib/linzer/message/adapter/generic/request.rb', line 31

def initialize(operation, **options)
  @operation = operation
  freeze
end

Instance Method Details

#attach!(signature) ⇒ Object

Attaches a signature to the request.

Parameters:

  • signature (Signature)

    The signature to attach

Returns:

  • (Object)

    The underlying request object



46
47
48
49
# File 'lib/linzer/message/adapter/generic/request.rb', line 46

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



39
40
41
# File 'lib/linzer/message/adapter/generic/request.rb', line 39

def header(name)
  @operation[name]
end