Class: ActiveShipping::Response

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

Overview

Basic Response class for requests against a carrier's API.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(success, message, params = {}, options = {}) ⇒ Response

Returns a new instance of Response.

Parameters:

  • success (Boolean)

    Whether the request was considered successful, i.e. this response object will have the expected data set.

  • message (String)

    A status message. Usuaully set when success is false, but can also be set for successful responses.

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

    Response parameters

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

Options Hash (options):

  • :test (Boolean) — default: default: false

    Whether this reponse was a result of a request executed against the sandbox or test environment of the carrier's API.

  • :xml (String)

    The raw XML of the response.

  • :request (String)

    The payload of the request.

  • :allow_failure (Boolean)

    Allows a failed response without raising.

Raises:



22
23
24
25
26
27
28
# File 'lib/active_shipping/response.rb', line 22

def initialize(success, message, params = {}, options = {})
  @success, @message, @params = success, message, params.stringify_keys
  @test = options[:test] || false
  @xml = options[:xml]
  @request = options[:request]
  raise ResponseError.new(self) unless success || options[:allow_failure]
end

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



6
7
8
# File 'lib/active_shipping/response.rb', line 6

def message
  @message
end

#paramsObject (readonly)

Returns the value of attribute params.



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

def params
  @params
end

#requestObject (readonly)

Returns the value of attribute request.



9
10
11
# File 'lib/active_shipping/response.rb', line 9

def request
  @request
end

#testObject (readonly)

Returns the value of attribute test.



7
8
9
# File 'lib/active_shipping/response.rb', line 7

def test
  @test
end

#xmlObject (readonly)

Returns the value of attribute xml.



8
9
10
# File 'lib/active_shipping/response.rb', line 8

def xml
  @xml
end

Instance Method Details

#success?Boolean

Whether the request was executed successfully or not.

Returns:

  • (Boolean)

    Should only return true if the attributes of teh response instance are set with useful values.



33
34
35
# File 'lib/active_shipping/response.rb', line 33

def success?
  @success ? true : false
end

#test?Boolean

Whether this request was executed against the sandbox or test environment instead of the production environment of the carrier.

Returns:

  • (Boolean)


40
41
42
# File 'lib/active_shipping/response.rb', line 40

def test?
  @test ? true : false
end