Skip to content
Browse files

added skeleton files for nzpost

  • Loading branch information...
1 parent 5b5ea0d commit 1e8ac50290aaf99118739f874ae6e7fe397484a5 @camfowler camfowler committed
View
38 lib/active_shipping/shipping/carriers/new_zealand_post.rb
@@ -0,0 +1,38 @@
+module ActiveMerchant
+ module Shipping
+ class NewZealandPost < Carrier
+
+ URL = "http://workshop.nzpost.co.nz/api/v1/rate.xml"
+
+ # Override to return required keys in options hash for initialize method.
+ def requirements
+ [:api_key]
+ end
+
+ # Override with whatever you need to get the rates
+ def find_rates(origin, destination, packages, options = {})
+
+ end
+
+ def maximum_weight
+ Mass.new(20, :kilograms)
+ end
+
+ protected
+
+ def node_text_or_nil(xml_node)
+ xml_node ? xml_node.text : nil
+ end
+
+ # Override in subclasses for non-U.S.-based carriers.
+ def self.default_location
+ Location.new( :country => 'NZ',
+ :city => 'Wellington',
+ :address1 => '455 Rexford Dr',
+ :zip => '6012',
+ :phone => '')
+ end
+
+ end
+ end
+end
View
6 test/fixtures.yml
@@ -1,6 +1,6 @@
-usps:
+usps:
login: APIKey
-ups:
+ups:
key: XmlAccessKey
login: UPSDotComLogin
password: UPSDotComPassword
@@ -13,3 +13,5 @@ shipwire:
password: Password
canada_post:
login: CPC_DEMO_XML
+new_zealand_post:
+ api_key: 123
View
422 test/fixtures/xml/newzealandpost/example_response.xml
@@ -0,0 +1,422 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<hash>
+ <status>success</status>
+ <defaulting-to-nationwide type="boolean">false</defaulting-to-nationwide>
+ <products-by-service>
+ <parcel-post-tracking type="array">
+ <parcel-post-tracking>
+ <cost>4.20</cost>
+ <speed-description>1-3 Working days Moday to Friday</speed-description>
+ <weight type="float">0.4</weight>
+ <product-url nil="true"></product-url>
+ <product-max-dimensions>165*235*70 3000gms</product-max-dimensions>
+ <length type="integer">25</length>
+ <code>PCB3C5</code>
+ <height type="integer">15</height>
+ <packaging>postage_only</packaging>
+ <description>C5 70mm Thick</description>
+ <label-url>https://www.nzpost.co.nz/cart/checkout</label-url>
+ <service>parcel_post_tracking</service>
+ <thickness type="integer">2</thickness>
+ </parcel-post-tracking>
+ <parcel-post-tracking>
+ <cost>4.50</cost>
+ <speed-description>1-3 Working days Moday to Friday</speed-description>
+ <weight type="float">0.4</weight>
+ <product-url>http://www.nzpost.co.nz/products-services/postage-packaging/bags/parcelpost-fast/10-x-c5-flat-parcelpost-fast-postage-includ</product-url>
+ <product-max-dimensions>125*230*70 3000gms</product-max-dimensions>
+ <length type="integer">25</length>
+ <code>PICFDLE</code>
+ <height type="integer">15</height>
+ <packaging>flat</packaging>
+ <description>DLE Flat Bag</description>
+ <label-url nil="true"></label-url>
+ <service>parcel_post_tracking</service>
+ <thickness type="integer">2</thickness>
+ </parcel-post-tracking>
+ <parcel-post-tracking>
+ <cost>5.50</cost>
+ <speed-description>1-3 Working days Moday to Friday</speed-description>
+ <weight type="float">0.4</weight>
+ <product-url>http://www.nzpost.co.nz/products-services/postage-packaging/bags/parcelpost-fast/10-x-c5-flat-parcelpost-fast-postage-includ</product-url>
+ <product-max-dimensions>185*270*70 3000gms</product-max-dimensions>
+ <length type="integer">25</length>
+ <code>PICBC5</code>
+ <height type="integer">15</height>
+ <packaging>bubble</packaging>
+ <description>C5 Bubble Bag</description>
+ <label-url nil="true"></label-url>
+ <service>parcel_post_tracking</service>
+ <thickness type="integer">2</thickness>
+ </parcel-post-tracking>
+ </parcel-post-tracking>
+ <parcel-post-po-box-priority type="array">
+ <parcel-post-po-box-priority>
+ <cost>4.00</cost>
+ <speed-description>Next working day</speed-description>
+ <weight type="float">0.4</weight>
+ <product-url>http://www.nzpost.co.nz/products-services/postage-packaging/bags/parcelpost-fast/10-x-c5-flat-parcelpost-fast-postage-includ</product-url>
+ <product-max-dimensions>185*270*70 3000gms</product-max-dimensions>
+ <length type="integer">25</length>
+ <code>PIXFC5</code>
+ <height type="integer">15</height>
+ <packaging>flat</packaging>
+ <description>C5 Flat Bag</description>
+ <label-url nil="true"></label-url>
+ <service>parcel_post_po_box_priority</service>
+ <thickness type="integer">2</thickness>
+ </parcel-post-po-box-priority>
+ </parcel-post-po-box-priority>
+ <parcel-post type="array">
+ <parcel-post>
+ <cost>2.40</cost>
+ <speed-description>1-3 Working days Moday to Saturday</speed-description>
+ <weight type="float">0.4</weight>
+ <product-url>http://www.nzpost.co.nz/products-services/postage-packaging/bags/parcelpost-fast/10-x-c5-flat-parcelpost-fast-postage-includ</product-url>
+ <product-max-dimensions>130*235*70 1500gms</product-max-dimensions>
+ <length type="integer">25</length>
+ <code>PKTDLE</code>
+ <height type="integer">15</height>
+ <packaging>postage_included_envelopes</packaging>
+ <description>DLE Postage Included Envelopes</description>
+ <label-url nil="true"></label-url>
+ <service>parcel_post</service>
+ <thickness type="integer">2</thickness>
+ </parcel-post>
+ <parcel-post>
+ <cost>2.40</cost>
+ <speed-description>1-3 Working days Moday to Saturday</speed-description>
+ <weight type="float">0.4</weight>
+ <product-url>http://www.nzpost.co.nz/products-services/postage-packaging/bags/parcelpost-fast/10-x-c5-flat-parcelpost-fast-postage-includ</product-url>
+ <product-max-dimensions>130*235*70 1500gms</product-max-dimensions>
+ <length type="integer">25</length>
+ <code>PKPDLE</code>
+ <height type="integer">15</height>
+ <packaging>permitpost</packaging>
+ <description>DLE </description>
+ <label-url nil="true"></label-url>
+ <service>parcel_post</service>
+ <thickness type="integer">2</thickness>
+ </parcel-post>
+ <parcel-post>
+ <cost>4.00</cost>
+ <speed-description>1-3 Working days Moday to Saturday</speed-description>
+ <weight type="float">0.4</weight>
+ <product-url>http://www.nzpost.co.nz/products-services/postage-packaging/bags/parcelpost-fast/10-x-c5-flat-parcelpost-fast-postage-includ</product-url>
+ <product-max-dimensions>185*270*70 1500gms</product-max-dimensions>
+ <length type="integer">25</length>
+ <code>PIKFC5</code>
+ <height type="integer">15</height>
+ <packaging>flat</packaging>
+ <description>C5 Flat Bag</description>
+ <label-url nil="true"></label-url>
+ <service>parcel_post</service>
+ <thickness type="integer">2</thickness>
+ </parcel-post>
+ <parcel-post>
+ <cost>4.50</cost>
+ <speed-description>1-3 Working days Moday to Saturday</speed-description>
+ <weight type="float">0.4</weight>
+ <product-url>http://www.nzpost.co.nz/products-services/postage-packaging/bags/parcelpost-fast/10-x-c5-flat-parcelpost-fast-postage-includ</product-url>
+ <product-max-dimensions>185*270*70 1500gms</product-max-dimensions>
+ <length type="integer">25</length>
+ <code>PIKBC5</code>
+ <height type="integer">15</height>
+ <packaging>bubble</packaging>
+ <description>C5 Bubble Bag</description>
+ <label-url nil="true"></label-url>
+ <service>parcel_post</service>
+ <thickness type="integer">2</thickness>
+ </parcel-post>
+ </parcel-post>
+ <parcel-post-fast type="array">
+ <parcel-post-fast>
+ <cost>3.00</cost>
+ <speed-description>Next working day Moday to Saturday</speed-description>
+ <weight type="float">0.4</weight>
+ <product-url>http://www.nzpost.co.nz/products-services/postage-packaging/bags/parcelpost-fast/10-x-c5-flat-parcelpost-fast-postage-includ</product-url>
+ <product-max-dimensions>130*235*70 1500gms</product-max-dimensions>
+ <length type="integer">25</length>
+ <code>PKTDLE, PKTEF</code>
+ <height type="integer">15</height>
+ <packaging>postage_included_envelopes</packaging>
+ <description>DLE Postage Included Envelopes</description>
+ <label-url nil="true"></label-url>
+ <service>parcel_post_fast</service>
+ <thickness type="integer">2</thickness>
+ </parcel-post-fast>
+ <parcel-post-fast>
+ <cost>3.00</cost>
+ <speed-description>Next working day Moday to Saturday</speed-description>
+ <weight type="float">0.4</weight>
+ <product-url>http://www.nzpost.co.nz/products-services/postage-packaging/bags/parcelpost-fast/10-x-c5-flat-parcelpost-fast-postage-includ</product-url>
+ <product-max-dimensions>130*235*70 1500gms</product-max-dimensions>
+ <length type="integer">25</length>
+ <code>PKFDLE</code>
+ <height type="integer">15</height>
+ <packaging>permitpost</packaging>
+ <description>DLE </description>
+ <label-url nil="true"></label-url>
+ <service>parcel_post_fast</service>
+ <thickness type="integer">2</thickness>
+ </parcel-post-fast>
+ <parcel-post-fast>
+ <cost>4.60</cost>
+ <speed-description>Next working day Moday to Saturday</speed-description>
+ <weight type="float">0.4</weight>
+ <product-url>http://www.nzpost.co.nz/products-services/postage-packaging/bags/parcelpost-fast/10-x-c5-flat-parcelpost-fast-postage-includ</product-url>
+ <product-max-dimensions>185*270*70 1500gms</product-max-dimensions>
+ <length type="integer">25</length>
+ <code>PIFFC5</code>
+ <height type="integer">15</height>
+ <packaging>flat</packaging>
+ <description>C5 Flat Bag</description>
+ <label-url nil="true"></label-url>
+ <service>parcel_post_fast</service>
+ <thickness type="integer">2</thickness>
+ </parcel-post-fast>
+ <parcel-post-fast>
+ <cost>5.10</cost>
+ <speed-description>Next working day Moday to Saturday</speed-description>
+ <weight type="float">0.4</weight>
+ <product-url>http://www.nzpost.co.nz/products-services/postage-packaging/bags/parcelpost-fast/10-x-c5-flat-parcelpost-fast-postage-includ</product-url>
+ <product-max-dimensions>185*270*70 1500gms</product-max-dimensions>
+ <length type="integer">25</length>
+ <code>PIFBC5</code>
+ <height type="integer">15</height>
+ <packaging>bubble</packaging>
+ <description>C5 Bubble Bag</description>
+ <label-url nil="true"></label-url>
+ <service>parcel_post_fast</service>
+ <thickness type="integer">2</thickness>
+ </parcel-post-fast>
+ </parcel-post-fast>
+ <parcel-post-tracked-zonal type="array">
+ <parcel-post-tracked-zonal>
+ <cost>5.50</cost>
+ <speed-description>Next working day</speed-description>
+ <weight type="float">0.4</weight>
+ <product-url nil="true"></product-url>
+ <product-max-dimensions>15000*15000*15000 25000gms</product-max-dimensions>
+ <length type="integer">25</length>
+ <code>PCBXT</code>
+ <height type="integer">15</height>
+ <packaging>postage_only</packaging>
+ <description>Across town</description>
+ <label-url>https://www.nzpost.co.nz/cart/checkout</label-url>
+ <service>parcel_post_tracked_zonal</service>
+ <thickness type="integer">2</thickness>
+ </parcel-post-tracked-zonal>
+ </parcel-post-tracked-zonal>
+ </products-by-service>
+ <products type="array">
+ <product>
+ <cost>2.40</cost>
+ <speed-description>1-3 Working days Moday to Saturday</speed-description>
+ <weight type="float">0.4</weight>
+ <product-url>http://www.nzpost.co.nz/products-services/postage-packaging/bags/parcelpost-fast/10-x-c5-flat-parcelpost-fast-postage-includ</product-url>
+ <product-max-dimensions>130*235*70 1500gms</product-max-dimensions>
+ <length type="integer">25</length>
+ <code>PKTDLE</code>
+ <height type="integer">15</height>
+ <packaging>postage_included_envelopes</packaging>
+ <description>DLE Postage Included Envelopes</description>
+ <label-url nil="true"></label-url>
+ <service>parcel_post</service>
+ <thickness type="integer">2</thickness>
+ </product>
+ <product>
+ <cost>3.00</cost>
+ <speed-description>Next working day Moday to Saturday</speed-description>
+ <weight type="float">0.4</weight>
+ <product-url>http://www.nzpost.co.nz/products-services/postage-packaging/bags/parcelpost-fast/10-x-c5-flat-parcelpost-fast-postage-includ</product-url>
+ <product-max-dimensions>130*235*70 1500gms</product-max-dimensions>
+ <length type="integer">25</length>
+ <code>PKTDLE, PKTEF</code>
+ <height type="integer">15</height>
+ <packaging>postage_included_envelopes</packaging>
+ <description>DLE Postage Included Envelopes</description>
+ <label-url nil="true"></label-url>
+ <service>parcel_post_fast</service>
+ <thickness type="integer">2</thickness>
+ </product>
+ <product>
+ <cost>2.40</cost>
+ <speed-description>1-3 Working days Moday to Saturday</speed-description>
+ <weight type="float">0.4</weight>
+ <product-url>http://www.nzpost.co.nz/products-services/postage-packaging/bags/parcelpost-fast/10-x-c5-flat-parcelpost-fast-postage-includ</product-url>
+ <product-max-dimensions>130*235*70 1500gms</product-max-dimensions>
+ <length type="integer">25</length>
+ <code>PKPDLE</code>
+ <height type="integer">15</height>
+ <packaging>permitpost</packaging>
+ <description>DLE </description>
+ <label-url nil="true"></label-url>
+ <service>parcel_post</service>
+ <thickness type="integer">2</thickness>
+ </product>
+ <product>
+ <cost>3.00</cost>
+ <speed-description>Next working day Moday to Saturday</speed-description>
+ <weight type="float">0.4</weight>
+ <product-url>http://www.nzpost.co.nz/products-services/postage-packaging/bags/parcelpost-fast/10-x-c5-flat-parcelpost-fast-postage-includ</product-url>
+ <product-max-dimensions>130*235*70 1500gms</product-max-dimensions>
+ <length type="integer">25</length>
+ <code>PKFDLE</code>
+ <height type="integer">15</height>
+ <packaging>permitpost</packaging>
+ <description>DLE </description>
+ <label-url nil="true"></label-url>
+ <service>parcel_post_fast</service>
+ <thickness type="integer">2</thickness>
+ </product>
+ <product>
+ <cost>4.00</cost>
+ <speed-description>1-3 Working days Moday to Saturday</speed-description>
+ <weight type="float">0.4</weight>
+ <product-url>http://www.nzpost.co.nz/products-services/postage-packaging/bags/parcelpost-fast/10-x-c5-flat-parcelpost-fast-postage-includ</product-url>
+ <product-max-dimensions>185*270*70 1500gms</product-max-dimensions>
+ <length type="integer">25</length>
+ <code>PIKFC5</code>
+ <height type="integer">15</height>
+ <packaging>flat</packaging>
+ <description>C5 Flat Bag</description>
+ <label-url nil="true"></label-url>
+ <service>parcel_post</service>
+ <thickness type="integer">2</thickness>
+ </product>
+ <product>
+ <cost>4.50</cost>
+ <speed-description>1-3 Working days Moday to Saturday</speed-description>
+ <weight type="float">0.4</weight>
+ <product-url>http://www.nzpost.co.nz/products-services/postage-packaging/bags/parcelpost-fast/10-x-c5-flat-parcelpost-fast-postage-includ</product-url>
+ <product-max-dimensions>185*270*70 1500gms</product-max-dimensions>
+ <length type="integer">25</length>
+ <code>PIKBC5</code>
+ <height type="integer">15</height>
+ <packaging>bubble</packaging>
+ <description>C5 Bubble Bag</description>
+ <label-url nil="true"></label-url>
+ <service>parcel_post</service>
+ <thickness type="integer">2</thickness>
+ </product>
+ <product>
+ <cost>4.60</cost>
+ <speed-description>Next working day Moday to Saturday</speed-description>
+ <weight type="float">0.4</weight>
+ <product-url>http://www.nzpost.co.nz/products-services/postage-packaging/bags/parcelpost-fast/10-x-c5-flat-parcelpost-fast-postage-includ</product-url>
+ <product-max-dimensions>185*270*70 1500gms</product-max-dimensions>
+ <length type="integer">25</length>
+ <code>PIFFC5</code>
+ <height type="integer">15</height>
+ <packaging>flat</packaging>
+ <description>C5 Flat Bag</description>
+ <label-url nil="true"></label-url>
+ <service>parcel_post_fast</service>
+ <thickness type="integer">2</thickness>
+ </product>
+ <product>
+ <cost>5.10</cost>
+ <speed-description>Next working day Moday to Saturday</speed-description>
+ <weight type="float">0.4</weight>
+ <product-url>http://www.nzpost.co.nz/products-services/postage-packaging/bags/parcelpost-fast/10-x-c5-flat-parcelpost-fast-postage-includ</product-url>
+ <product-max-dimensions>185*270*70 1500gms</product-max-dimensions>
+ <length type="integer">25</length>
+ <code>PIFBC5</code>
+ <height type="integer">15</height>
+ <packaging>bubble</packaging>
+ <description>C5 Bubble Bag</description>
+ <label-url nil="true"></label-url>
+ <service>parcel_post_fast</service>
+ <thickness type="integer">2</thickness>
+ </product>
+ <product>
+ <cost>4.20</cost>
+ <speed-description>1-3 Working days Moday to Friday</speed-description>
+ <weight type="float">0.4</weight>
+ <product-url nil="true"></product-url>
+ <product-max-dimensions>165*235*70 3000gms</product-max-dimensions>
+ <length type="integer">25</length>
+ <code>PCB3C5</code>
+ <height type="integer">15</height>
+ <packaging>postage_only</packaging>
+ <description>C5 70mm Thick</description>
+ <label-url>https://www.nzpost.co.nz/cart/checkout</label-url>
+ <service>parcel_post_tracking</service>
+ <thickness type="integer">2</thickness>
+ </product>
+ <product>
+ <cost>4.50</cost>
+ <speed-description>1-3 Working days Moday to Friday</speed-description>
+ <weight type="float">0.4</weight>
+ <product-url>http://www.nzpost.co.nz/products-services/postage-packaging/bags/parcelpost-fast/10-x-c5-flat-parcelpost-fast-postage-includ</product-url>
+ <product-max-dimensions>125*230*70 3000gms</product-max-dimensions>
+ <length type="integer">25</length>
+ <code>PICFDLE</code>
+ <height type="integer">15</height>
+ <packaging>flat</packaging>
+ <description>DLE Flat Bag</description>
+ <label-url nil="true"></label-url>
+ <service>parcel_post_tracking</service>
+ <thickness type="integer">2</thickness>
+ </product>
+ <product>
+ <cost>5.50</cost>
+ <speed-description>1-3 Working days Moday to Friday</speed-description>
+ <weight type="float">0.4</weight>
+ <product-url>http://www.nzpost.co.nz/products-services/postage-packaging/bags/parcelpost-fast/10-x-c5-flat-parcelpost-fast-postage-includ</product-url>
+ <product-max-dimensions>185*270*70 3000gms</product-max-dimensions>
+ <length type="integer">25</length>
+ <code>PICBC5</code>
+ <height type="integer">15</height>
+ <packaging>bubble</packaging>
+ <description>C5 Bubble Bag</description>
+ <label-url nil="true"></label-url>
+ <service>parcel_post_tracking</service>
+ <thickness type="integer">2</thickness>
+ </product>
+ <product>
+ <cost>5.50</cost>
+ <speed-description>Next working day</speed-description>
+ <weight type="float">0.4</weight>
+ <product-url nil="true"></product-url>
+ <product-max-dimensions>15000*15000*15000 25000gms</product-max-dimensions>
+ <length type="integer">25</length>
+ <code>PCBXT</code>
+ <height type="integer">15</height>
+ <packaging>postage_only</packaging>
+ <description>Across town</description>
+ <label-url>https://www.nzpost.co.nz/cart/checkout</label-url>
+ <service>parcel_post_tracked_zonal</service>
+ <thickness type="integer">2</thickness>
+ </product>
+ <product>
+ <cost>4.00</cost>
+ <speed-description>Next working day</speed-description>
+ <weight type="float">0.4</weight>
+ <product-url>http://www.nzpost.co.nz/products-services/postage-packaging/bags/parcelpost-fast/10-x-c5-flat-parcelpost-fast-postage-includ</product-url>
+ <product-max-dimensions>185*270*70 3000gms</product-max-dimensions>
+ <length type="integer">25</length>
+ <code>PIXFC5</code>
+ <height type="integer">15</height>
+ <packaging>flat</packaging>
+ <description>C5 Flat Bag</description>
+ <label-url nil="true"></label-url>
+ <service>parcel_post_po_box_priority</service>
+ <thickness type="integer">2</thickness>
+ </product>
+ </products>
+ <large-delivery-type type="symbol">across_town</large-delivery-type>
+ <params>
+ <format>xml</format>
+ <thickness>2</thickness>
+ <postcode-dest>6012</postcode-dest>
+ <weight>0.4</weight>
+ <api-key>123</api-key>
+ <action>rate</action>
+ <height>25</height>
+ <length>15</length>
+ <controller>api</controller>
+ <postcode-src>6011</postcode-src>
+ </params>
+</hash>
View
35 test/unit/carriers/new_zealand_post_test.rb
@@ -0,0 +1,35 @@
+require 'test_helper'
+
+class NewZealandPostTest < Test::Unit::TestCase
+
+ def setup
+ login = fixtures(:new_zealand_post)
+
+ @carrier = NewZealandPost.new(login)
+
+ @response = xml_fixture('newzealandpost/example_response')
+ # @bad_response = xml_fixture('newzealandpost/example_response_error')
+
+ @origin = {:postal_code => "6011"}
+ @destination = {:postal_code => "6012"}
+ @line_items = [Package.new(400, [25, 15, 2],
+ :description => "Edmonds Cookbook",
+ :units => :metric)]
+ end
+
+ def test_parse_response
+ end
+
+ def test_build_rectangular_request_params
+ params = @carrier.send(:build_rectangular_request_params, @origin, @destination, @line_items)
+
+ assert_equal 123, params[:api_key]
+ assert_equal 25, params[:height]
+ assert_equal 15, params[:length]
+ assert_equal 2, params[:thickness]
+ assert_equal 0.4, params[:weight]
+ assert_equal 6011, params[:postcode_src]
+ assert_equal 6012, params[:postcode_dest]
+ end
+
+end

0 comments on commit 1e8ac50

Please sign in to comment.
Something went wrong with that request. Please try again.