Class: FriendlyShipping::Response

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status:, body:, headers:) ⇒ Response

Returns a new instance of Response.

Parameters:

  • status (Integer)

    The HTTP response status code

  • body (String)

    The HTTP response body

  • headers (Hash)

    The HTTP response headers



10
11
12
13
14
# File 'lib/friendly_shipping/response.rb', line 10

def initialize(status:, body:, headers:)
  @status = status
  @body = body
  @headers = headers || {}
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



5
6
7
# File 'lib/friendly_shipping/response.rb', line 5

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



5
6
7
# File 'lib/friendly_shipping/response.rb', line 5

def headers
  @headers
end

#statusObject (readonly) Also known as: code

Returns the value of attribute status.



5
6
7
# File 'lib/friendly_shipping/response.rb', line 5

def status
  @status
end

Class Method Details

.new_from_rest_client_response(response) ⇒ FriendlyShipping::Response

Parameters:

  • response (RestClient::Response)

Returns:



20
21
22
# File 'lib/friendly_shipping/response.rb', line 20

def self.new_from_rest_client_response(response)
  new(status: response&.code, body: response&.body, headers: response&.headers)
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?

Parameters:

  • other (Object)


25
26
27
28
# File 'lib/friendly_shipping/response.rb', line 25

def ==(other)
  other.class == self.class &&
    other.attributes == attributes
end

#hashObject



32
33
34
# File 'lib/friendly_shipping/response.rb', line 32

def hash
  attributes.hash
end