Class: FriendlyShipping::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/friendly_shipping/request.rb

Overview

Represents an HTTP request sent to a carrier API.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url:, http_method: nil, body: nil, readable_body: nil, headers: {}, debug: false) ⇒ Request

Returns a new instance of Request.

Parameters:

  • url (String)

    the HTTP request URL

  • http_method (String) (defaults to: nil)

    the HTTP request method

  • body (String) (defaults to: nil)

    the HTTP request body

  • readable_body (String) (defaults to: nil)

    human-readable HTTP request body

  • headers (Hash) (defaults to: {})

    the HTTP request headers

  • debug (Boolean) (defaults to: false)

    whether to attach debugging information to the response



27
28
29
30
31
32
33
34
# File 'lib/friendly_shipping/request.rb', line 27

def initialize(url:, http_method: nil, body: nil, readable_body: nil, headers: {}, debug: false)
  @url = url
  @http_method = http_method
  @body = body
  @readable_body = readable_body
  @headers = headers
  @debug = debug
end

Instance Attribute Details

#bodyString (readonly)

Returns the HTTP request body.

Returns:

  • (String)

    the HTTP request body



13
14
15
# File 'lib/friendly_shipping/request.rb', line 13

def body
  @body
end

#debugBoolean (readonly)

Returns whether to attach debugging information to the response.

Returns:

  • (Boolean)

    whether to attach debugging information to the response



19
20
21
# File 'lib/friendly_shipping/request.rb', line 19

def debug
  @debug
end

#headersString (readonly)

Returns human-readable HTTP request body.

Returns:

  • (String)

    human-readable HTTP request body



16
17
18
# File 'lib/friendly_shipping/request.rb', line 16

def headers
  @headers
end

#http_methodString (readonly)

Returns the HTTP request method.

Returns:

  • (String)

    the HTTP request method



10
11
12
# File 'lib/friendly_shipping/request.rb', line 10

def http_method
  @http_method
end

#urlString (readonly)

Returns the HTTP request URL.

Returns:

  • (String)

    the HTTP request URL



7
8
9
# File 'lib/friendly_shipping/request.rb', line 7

def url
  @url
end

Instance Method Details

#readable_bodyString

Returns the HTTP request body.

Returns:

  • (String)

    human-readable HTTP request body



38
39
40
# File 'lib/friendly_shipping/request.rb', line 38

def readable_body
  @readable_body.presence || @body
end