Class: ActiveMerchant::Shipping::NewZealandPost::RateRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/active_shipping/shipping/carriers/new_zealand_post.rb

Direct Known Subclasses

Domestic, International

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(origin, destination, packages, options) ⇒ RateRequest

Returns a new instance of RateRequest


54
55
56
57
58
59
60
61
62
# File 'lib/active_shipping/shipping/carriers/new_zealand_post.rb', line 54

def initialize(origin, destination, packages, options)
  @origin = Location.from(origin)
  @destination = Location.from(destination)
  @packages = Array(packages).map { |package| NewZealandPostPackage.new(package, api) }
  @params = { :format => "json", :api_key => options[:key] }
  @test = options[:test]
  @rates = @responses = @raw_responses = []
  @urls = @packages.map { |package| url(package) }
end

Instance Attribute Details

#raw_responses=(value) ⇒ Object (writeonly)

Sets the attribute raw_responses

Parameters:

  • value

    the value to set the attribute raw_responses to.


47
48
49
# File 'lib/active_shipping/shipping/carriers/new_zealand_post.rb', line 47

def raw_responses=(value)
  @raw_responses = value
end

#urlsObject (readonly)

Returns the value of attribute urls


46
47
48
# File 'lib/active_shipping/shipping/carriers/new_zealand_post.rb', line 46

def urls
  @urls
end

Class Method Details

.from(*args) ⇒ Object


49
50
51
52
# File 'lib/active_shipping/shipping/carriers/new_zealand_post.rb', line 49

def self.from(*args)
  return International.new(*args) unless domestic?(args[0..1])
  Domestic.new(*args)
end

Instance Method Details

#new_zealand_origin?Boolean

Returns:

  • (Boolean)

71
72
73
# File 'lib/active_shipping/shipping/carriers/new_zealand_post.rb', line 71

def new_zealand_origin?
  self.class.new_zealand?(@origin)
end

#rate_responseObject


64
65
66
67
68
69
# File 'lib/active_shipping/shipping/carriers/new_zealand_post.rb', line 64

def rate_response
  @rates = rates
  NewZealandPostRateResponse.new(true, "success", response_params, response_options)
rescue => error
  NewZealandPostRateResponse.new(false, error.message, response_params, response_options)
end