class ReactiveShipping::Response

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

Attributes

message[R]
params[R]
request[R]
test[R]
xml[R]

Public Class Methods

new(success, message, params = {}, options = {}) click to toggle source

@param success [Boolean] Whether the request was considered successful, i.e. this

response object will have the expected data set.

@param message [String] A status message. Usuaully set when `success` is `false`,

but can also be set for successful responses.

@param params [Hash] Response parameters @param options [Hash] @option options [Boolean] :test (default: false) Whether this reponse was a result

of a request executed against the sandbox or test environment of the carrier's API.

@option options [String] :xml The raw XML of the response. @option options [String] :request The payload of the request. @option options [Boolean] :allow_failure Allows a failed response without raising.

# File lib/reactive_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

Public Instance Methods

success?() click to toggle source

Whether the request was executed successfully or not. @return [Boolean] Should only return `true` if the attributes of teh response

instance are set with useful values.
# File lib/reactive_shipping/response.rb, line 33
def success?
  @success ? true : false
end
test?() click to toggle source

Whether this request was executed against the sandbox or test environment instead of the production environment of the carrier. @return [Boolean]

# File lib/reactive_shipping/response.rb, line 40
def test?
  @test ? true : false
end