Class: ActiveShipping::RateResponse

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

Overview

Note:

Some carriers provide more information than others, so not all attributes will be set, depending on what carrier you are using.

The RateResponse object is returned by the Carrier#find_rates call. The most important method is #rates, which will return a list of possible shipping options with an estimated price.

Instance Attribute Summary collapse

Attributes inherited from Response

#message, #params, #request, #test, #xml

Instance Method Summary collapse

Methods inherited from Response

#success?, #test?

Constructor Details

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

Initializes a new RateResponse instance.

Parameters:

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

    a customizable set of options

  • 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 (options):

  • :rates (Array<ActiveShipping::RateEstimate>)

    The rate estimates to populate the #rates method with.

  • :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.



25
26
27
28
# File 'lib/active_shipping/rate_response.rb', line 25

def initialize(success, message, params = {}, options = {})
  @rates = Array(options[:estimates] || options[:rates] || options[:rate_estimates])
  super
end

Instance Attribute Details

#ratesArray<ActiveShipping::RateEstimate> Also known as: estimates, rate_estimates

The available rate options for the shipment, with an estimated price.

Returns:



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/active_shipping/rate_response.rb', line 13

class RateResponse < Response

  attr_reader :rates

  # Initializes a new RateResponse instance.
  #
  # @param success (see ActiveShipping::Response#initialize)
  # @param message (see ActiveShipping::Response#initialize)
  # @param params (see ActiveShipping::Response#initialize)
  # @option options (see ActiveShipping::Response#initialize)
  # @option options [Array<ActiveShipping::RateEstimate>] :rates The rate estimates to
  #   populate the {#rates} method with.
  def initialize(success, message, params = {}, options = {})
    @rates = Array(options[:estimates] || options[:rates] || options[:rate_estimates])
    super
  end

  alias_method :estimates, :rates
  alias_method :rate_estimates, :rates
end