Class: ActiveShipping::AustraliaPost

Inherits:
Carrier
  • Object
show all
Defined in:
lib/active_shipping/carriers/australia_post.rb

Defined Under Namespace

Classes: AustraliaPostRateEstimate, AustraliaPostRequest, CalculateRequest, CombinedResponse, ServiceRequest

Constant Summary collapse

HOST =
'digitalapi.auspost.com.au'
PARCEL_ENDPOINTS =
{
  service: {
    domestic:      '/postage/parcel/domestic/service.json',
    international: '/postage/parcel/international/service.json'
  },
  calculate: {
    domestic:      '/postage/parcel/domestic/calculate.json',
    international: '/postage/parcel/international/calculate.json'
  }
}.freeze
@@name =
'Australia Post'

Instance Attribute Summary

Attributes inherited from Carrier

#last_request, #test_mode

Instance Method Summary collapse

Methods inherited from Carrier

#available_services, #cancel_shipment, #create_shipment, default_location, #find_tracking_info, #initialize, #maximum_address_field_length, #maximum_weight, #save_request, #timestamp_from_business_day, #valid_credentials?

Constructor Details

This class inherits a constructor from ActiveShipping::Carrier

Instance Method Details

#calculate_rates(origin, destination, packages, service_code, options = {}) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/active_shipping/carriers/australia_post.rb', line 38

def calculate_rates(origin, destination, packages, service_code, options = {})
  packages = Array(packages)

  calculate_requests = packages.map do |package|
    calculate_request = CalculateRequest.new(origin, destination, package, service_code, options)

    calculate_request.parse(commit(calculate_request.url))
    calculate_request
  end

  combined_response = CombinedResponse.new(origin, destination, packages, calculate_requests)

  RateResponse.new(true, 'success', combined_response.params, combined_response.options)
end

#find_rates(origin, destination, packages, options = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/active_shipping/carriers/australia_post.rb', line 23

def find_rates(origin, destination, packages, options = {})
  packages = Array(packages)

  service_requests = packages.map do |package|
    service_request = ServiceRequest.new(origin, destination, package, options)

    service_request.parse(commit(service_request.url))
    service_request
  end

  combined_response = CombinedResponse.new(origin, destination, packages, service_requests)

  RateResponse.new(true, 'success', combined_response.params, combined_response.options)
end

#requirementsObject



19
20
21
# File 'lib/active_shipping/carriers/australia_post.rb', line 19

def requirements
  [:api_key]
end