Skip to content
This repository has been archived by the owner on Dec 11, 2022. It is now read-only.

Commit

Permalink
Update URL and functions according to new API docs
Browse files Browse the repository at this point in the history
In addition to the changes for international postage, Auspost have
also changed the API URL, as described in this document:

http://auspost.com.au/pdfs/pac-api-update-2016.pdf

The testing URL has been removed at the same time.
  • Loading branch information
chnorton committed Jun 20, 2016
1 parent aa21d85 commit d0c1f7a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 28 deletions.
16 changes: 5 additions & 11 deletions src/Auspost/Postage/PostageClient.php
Expand Up @@ -34,6 +34,9 @@
*/ */
class PostageClient extends Client class PostageClient extends Client
{ {

const API_URL = 'https://digitalapi.auspost.com.au';

public static function factory($config = array()) public static function factory($config = array())
{ {
if (isset($config['developer_mode']) && is_bool($config['developer_mode'])) { if (isset($config['developer_mode']) && is_bool($config['developer_mode'])) {
Expand All @@ -42,20 +45,11 @@ public static function factory($config = array())
$developerMode = false; $developerMode = false;
} }


$baseUrl = array(
'https://auspost.com.au',
'https://test.npe.auspost.com.au'
);

// Ignore unnecessary user-specified configuration values
if ($developerMode) {
unset($config['auth_key']);
}
unset($config['base_url']); unset($config['base_url']);


$default = array( $default = array(
'developer_mode' => $developerMode, 'developer_mode' => $developerMode,
'base_url' => $baseUrl[$developerMode], 'base_url' => self::API_URL,
'auth_key' => '28744ed5982391881611cca6cf5c2409' 'auth_key' => '28744ed5982391881611cca6cf5c2409'
); );


Expand All @@ -67,7 +61,7 @@ public static function factory($config = array())


$config = Collection::fromConfig($config, $default, $required); $config = Collection::fromConfig($config, $default, $required);


$client = new self($config->get('base_url'), $config); $client = new self(self::API_URL, $config);


$client->getConfig()->setPath('request.options/headers/Accept', 'application/json'); $client->getConfig()->setPath('request.options/headers/Accept', 'application/json');
$client->getConfig()->setPath('request.options/headers/Auth-Key', $config->get('auth_key')); $client->getConfig()->setPath('request.options/headers/Auth-Key', $config->get('auth_key'));
Expand Down
34 changes: 17 additions & 17 deletions src/Auspost/Postage/service.json
Expand Up @@ -2,39 +2,39 @@
"operations": { "operations": {
"ListCountries": { "ListCountries": {
"httpMethod": "GET", "httpMethod": "GET",
"uri": "api/postage/country" "uri": "postage/country"
}, },
"ListDomesticLetterSizes": { "ListDomesticLetterSizes": {
"httpMethod": "GET", "httpMethod": "GET",
"uri": "api/postage/letter/domestic/size" "uri": "postage/letter/domestic/size"
}, },
"ListDomesticLetterThicknesses": { "ListDomesticLetterThicknesses": {
"httpMethod": "GET", "httpMethod": "GET",
"uri": "api/postage/letter/domestic/thickness" "uri": "postage/letter/domestic/thickness"
}, },
"ListDomesticLetterWeights": { "ListDomesticLetterWeights": {
"httpMethod": "GET", "httpMethod": "GET",
"uri": "api/postage/letter/domestic/weight" "uri": "postage/letter/domestic/weight"
}, },
"ListDomesticParcelSizes": { "ListDomesticParcelSizes": {
"httpMethod": "GET", "httpMethod": "GET",
"uri": "api/postage/parcel/domestic/size" "uri": "postage/parcel/domestic/size"
}, },
"ListDomesticParcelWeights": { "ListDomesticParcelWeights": {
"httpMethod": "GET", "httpMethod": "GET",
"uri": "api/postage/parcel/domestic/weight" "uri": "postage/parcel/domestic/weight"
}, },
"ListInternationalLetterWeights": { "ListInternationalLetterWeights": {
"httpMethod": "GET", "httpMethod": "GET",
"uri": "api/postage/letter/international/weight" "uri": "postage/letter/international/weight"
}, },
"ListInternationalParcelWeights": { "ListInternationalParcelWeights": {
"httpMethod": "GET", "httpMethod": "GET",
"uri": "api/postage/parcel/international/weight" "uri": "postage/parcel/international/weight"
}, },
"ListDomesticLetterServices": { "ListDomesticLetterServices": {
"httpMethod": "GET", "httpMethod": "GET",
"uri": "api/postage/letter/domestic/service", "uri": "postage/letter/domestic/service",
"parameters": { "parameters": {
"length": { "length": {
"required": true, "required": true,
Expand All @@ -60,7 +60,7 @@
}, },
"ListDomesticParcelServices": { "ListDomesticParcelServices": {
"httpMethod": "GET", "httpMethod": "GET",
"uri": "api/postage/parcel/domestic/service", "uri": "postage/parcel/domestic/service",
"parameters": { "parameters": {
"from_postcode": { "from_postcode": {
"required": true, "required": true,
Expand Down Expand Up @@ -96,7 +96,7 @@
}, },
"ListInternationalLetterServices": { "ListInternationalLetterServices": {
"httpMethod": "GET", "httpMethod": "GET",
"uri": "api/postage/letter/international/service", "uri": "postage/letter/international/service",
"parameters": { "parameters": {
"country_code": { "country_code": {
"required": true, "required": true,
Expand All @@ -112,7 +112,7 @@
}, },
"ListInternationalParcelServices": { "ListInternationalParcelServices": {
"httpMethod": "GET", "httpMethod": "GET",
"uri": "api/postage/parcel/international/service", "uri": "postage/parcel/international/service",
"parameters": { "parameters": {
"country_code": { "country_code": {
"required": true, "required": true,
Expand All @@ -128,7 +128,7 @@
}, },
"SearchPostcode": { "SearchPostcode": {
"httpMethod": "GET", "httpMethod": "GET",
"uri": "api/postcode/search", "uri": "postcode/search",
"parameters": { "parameters": {
"q": { "q": {
"required": true, "required": true,
Expand All @@ -150,7 +150,7 @@
}, },
"CalculateDomesticLetterPostage": { "CalculateDomesticLetterPostage": {
"httpMethod": "GET", "httpMethod": "GET",
"uri": "api/postage/letter/domestic/calculate", "uri": "postage/letter/domestic/calculate",
"parameters": { "parameters": {
"service_code": { "service_code": {
"required": true, "required": true,
Expand Down Expand Up @@ -181,7 +181,7 @@
}, },
"CalculateDomesticParcelPostage": { "CalculateDomesticParcelPostage": {
"httpMethod": "GET", "httpMethod": "GET",
"uri": "api/postage/parcel/domestic/calculate", "uri": "postage/parcel/domestic/calculate",
"parameters": { "parameters": {
"from_postcode": { "from_postcode": {
"required": true, "required": true,
Expand Down Expand Up @@ -237,7 +237,7 @@
}, },
"CalculateInternationalLetterPostage": { "CalculateInternationalLetterPostage": {
"httpMethod": "GET", "httpMethod": "GET",
"uri": "api/postage/letter/international/calculate", "uri": "postage/letter/international/calculate",
"parameters": { "parameters": {
"country_code": { "country_code": {
"required": true, "required": true,
Expand All @@ -258,7 +258,7 @@
}, },
"CalculateInternationalParcelPostage": { "CalculateInternationalParcelPostage": {
"httpMethod": "GET", "httpMethod": "GET",
"uri": "api/postage/parcel/international/calculate", "uri": "postage/parcel/international/calculate",
"parameters": { "parameters": {
"country_code": { "country_code": {
"required": true, "required": true,
Expand Down

0 comments on commit d0c1f7a

Please sign in to comment.