Class: ActiveShipping::AustraliaPost::AustraliaPostRequest
- Inherits:
-
Object
- Object
- ActiveShipping::AustraliaPost::AustraliaPostRequest
show all
- Defined in:
- lib/active_shipping/carriers/australia_post.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(origin, destination, package, options) ⇒ AustraliaPostRequest
Returns a new instance of AustraliaPostRequest.
126
127
128
129
130
131
132
|
# File 'lib/active_shipping/carriers/australia_post.rb', line 126
def initialize(origin, destination, package, options)
@origin = Location.from(origin)
@destination = Location.from(destination)
@package = package
@rates = []
@options = options
end
|
Instance Attribute Details
#rates ⇒ Object
Returns the value of attribute rates.
124
125
126
|
# File 'lib/active_shipping/carriers/australia_post.rb', line 124
def rates
@rates
end
|
#raw_response ⇒ Object
Returns the value of attribute raw_response.
122
123
124
|
# File 'lib/active_shipping/carriers/australia_post.rb', line 122
def raw_response
@raw_response
end
|
#response ⇒ Object
Returns the value of attribute response.
123
124
125
|
# File 'lib/active_shipping/carriers/australia_post.rb', line 123
def response
@response
end
|
Instance Method Details
#domestic_destination? ⇒ Boolean
148
149
150
|
# File 'lib/active_shipping/carriers/australia_post.rb', line 148
def domestic_destination?
@destination.country_code == 'AU'
end
|
#domestic_params ⇒ Object
152
153
154
155
156
157
158
159
160
161
|
# File 'lib/active_shipping/carriers/australia_post.rb', line 152
def domestic_params
{
length: @package.cm(:length),
width: @package.cm(:width),
height: @package.cm(:height),
weight: @package.weight.in_kg.to_f.round(2),
from_postcode: @origin.postal_code,
to_postcode: @destination.postal_code
}
end
|
#international_params ⇒ Object
163
164
165
166
167
168
|
# File 'lib/active_shipping/carriers/australia_post.rb', line 163
def international_params
{
weight: @package.weight.in_kg.to_f.round(2),
country_code: @destination.country_code
}
end
|
#parse(data) ⇒ Object
141
142
143
144
|
# File 'lib/active_shipping/carriers/australia_post.rb', line 141
def parse(data)
@raw_response = data
@response = JSON.parse(data)
end
|
#url ⇒ Object
134
135
136
137
138
139
|
# File 'lib/active_shipping/carriers/australia_post.rb', line 134
def url
endpoint = domestic_destination? ? @endpoints[:domestic] : @endpoints[:international]
params = domestic_destination? ? domestic_params : international_params
URI::HTTPS.build(host: HOST, path: endpoint, query: params.to_query).to_s
end
|