Class: ReactiveShipping::AustraliaPost::AustraliaPostRequest
- Inherits:
-
Object
- Object
- ReactiveShipping::AustraliaPost::AustraliaPostRequest
show all
- Defined in:
- lib/reactive_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.
124
125
126
127
128
129
130
|
# File 'lib/reactive_shipping/carriers/australia_post.rb', line 124
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.
122
123
124
|
# File 'lib/reactive_shipping/carriers/australia_post.rb', line 122
def rates
@rates
end
|
#raw_response ⇒ Object
Returns the value of attribute raw_response.
120
121
122
|
# File 'lib/reactive_shipping/carriers/australia_post.rb', line 120
def raw_response
@raw_response
end
|
#response ⇒ Object
Returns the value of attribute response.
121
122
123
|
# File 'lib/reactive_shipping/carriers/australia_post.rb', line 121
def response
@response
end
|
Instance Method Details
#domestic_destination? ⇒ Boolean
146
147
148
|
# File 'lib/reactive_shipping/carriers/australia_post.rb', line 146
def domestic_destination?
@destination.country_code == 'AU'
end
|
#domestic_params ⇒ Object
150
151
152
153
154
155
156
157
158
159
|
# File 'lib/reactive_shipping/carriers/australia_post.rb', line 150
def domestic_params
{
length: @package.cm(:length),
width: @package.cm(:width),
height: @package.cm(:height),
weight: @package.kilograms.to_f.round(2),
from_postcode: @origin.postal_code,
to_postcode: @destination.postal_code
}
end
|
#international_params ⇒ Object
161
162
163
164
165
166
|
# File 'lib/reactive_shipping/carriers/australia_post.rb', line 161
def international_params
{
weight: @package.kilograms.to_f.round(2),
country_code: @destination.country_code
}
end
|
#parse(data) ⇒ Object
139
140
141
142
|
# File 'lib/reactive_shipping/carriers/australia_post.rb', line 139
def parse(data)
@raw_response = data
@response = JSON.parse(data)
end
|
#url ⇒ Object
132
133
134
135
136
137
|
# File 'lib/reactive_shipping/carriers/australia_post.rb', line 132
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
|