2017 © Pedro Peláez
 

library bring-api

Bring Tracking API library

image

animail/bring-api

Bring Tracking API library

  • Wednesday, December 16, 2015
  • by Sleavely
  • Repository
  • 4 Watchers
  • 0 Stars
  • 297 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Bring PHP API

This PHP wrapper is not supported by Bring, but as of Dec 2015 they do not offer a PHP alternative. Based on the developer documentation., (*1)

Installing

With Composer:, (*2)

composer require animail/bring-api

Voila!, (*3)

How to use it

Initialize

use \Animail\BringApi;

// ...

$api_uid = 'john.doe@example.com';
$api_key = '1234abc-abcd-1234-5678-abcd1234abcd';
$my_website_url = 'https://example.com/';
$bring = new BringApi($api_uid, $api_key, $my_website_url);

// Don't want to authenticate?
$bring = new BringApi();

Find shipment by reference, package number or shipment number

The track() method wraps the Tracking API and always returns an array, including when the shipment(s) could not be found. Unless there was an API error, in which case we'll throw all kinds of fun \Animail\BringApiExceptions., (*4)


// Shipment number $consignmentSet = $bring->track('73325389952521130'); // array('consignmentSet' => array()) // Package number $consignmentSet = $bring->track('CT797294851NO'); // array('consignmentSet' => array()) // Reference (this is usually your internal ordernumber or shipmentID) $consignmentSet = $bring->track('1234'); // array('consignmentSet' => array())

Catching exceptions

Catch everything in the same place, (*5)

try {
  $bring = new BringApi('', '', '');
} catch (BringApiException $e) {
  // All our exception types extend the BringApiException class
}

Only catch errors from the API, (*6)

try {
  $bring = new BringApi('', '', '');
  $results = $bring->track('boobar');
} catch (BringApiErrorException $e) {

}

Separate handlers for different types, (*7)

try {
  $bring = new BringApi('', '', '');
  $results = $bring->track('boobar');
} catch (BringApiClientException $e) {
  // Issues with the client. Guzzle for some reason threw an error.
} catch (BringApiErrorException $e) {

} catch (BringApiException $e) {
  // This one will never be called unless we add more exception types in the future
}

Contributing

We love open source software and would love to see pull requests. We're trying to be PSR-4 compliant but don't have many other requirements., (*8)

The Versions

16/12 2015

dev-master

9999999-dev

Bring Tracking API library

  Sources   Download

The Requires