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.



57
58
59
60
61
62
63
64
65
# File 'lib/active_shipping/shipping/carriers/new_zealand_post.rb', line 57

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.



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

def raw_responses=(value)
  @raw_responses = value
end

#urlsObject (readonly)

Returns the value of attribute urls.



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

def urls
  @urls
end

Class Method Details

.from(*args) ⇒ Object



52
53
54
55
# File 'lib/active_shipping/shipping/carriers/new_zealand_post.rb', line 52

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)


74
75
76
# File 'lib/active_shipping/shipping/carriers/new_zealand_post.rb', line 74

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

#rate_responseObject



67
68
69
70
71
72
# File 'lib/active_shipping/shipping/carriers/new_zealand_post.rb', line 67

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