2017 © Pedro Peláez
 

library bringapi

BringApi is a fully functional library to help contact Bring API

image

crakter/bringapi

BringApi is a fully functional library to help contact Bring API

  • Friday, July 7, 2017
  • by crakter
  • Repository
  • 1 Watchers
  • 1 Stars
  • 27 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 93 % Grown

The README.md

Bring API PHP

Build Status, (*1)

Bring API PHP is a library to contact Bring API for prices, booking, reports and so on. I did not find anything that i could use for my project with PHP and Bring API. So i needed a good library that was reusable. This is used in production of a large Norwegian wholesaler., (*2)

Install

Can be installed directly with Composer., (*3)

Run the following command in correct directory., (*4)

$ composer require crakter/bringapi

Requirements

  • PHP version 7.2.0 or higher
  • PHP extension php_simplexml enabled (enabled by default in 5.1.2 and above)

Supported Apis

  • [x] Shipping Guide API
    • [x] Get estimated prices
    • [x] Get Estimated delivery time
    • [x] Get Estimated shipment prices, delivery time and more
  • [x] Booking API
    • [x] List customer names
    • [x] Book Shipments
    • [x] Order pickups
  • [x] Tracking API
    • [x] Track shipments (also logged in)
    • [x] Download Signature
  • [x] Reports API
    • [x] List available customers
    • [x] List available reports for a customer
    • [x] Generate a report
    • [x] Check the status of a report
    • [x] List invoice numbers
  • [x] Postal Code API
    • [x] Lookup postal code

Basic usage

Tracking as logged in

If you remove the authorizationModule you can track like normal user., (*5)

use Crakter\BringApi\Entity\TrackingEntity;
use Crakter\BringApi\Clients\Authorization;
use Crakter\BringApi\Clients\Tracking\TrackingEndpoint;

$trackingEntity = (new TrackingEntity)->set(['q' => 'TESTPACKAGE-AT-PICKUPPOINT']); // Can be used like this
//$trackingEntity = (new TrackingEntity)->setQ('TESTPACKAGE-AT-PICKUPPOINT'); // Can also be used like this
/* And like this
$trackingEntity = (new TrackingEntity);
$trackingEntity->q = 'TESTPACKAGE-AT-PICKUPPOINT';
*/
$authorizationModule = (new Authorization)
    ->setApiKey('1234abc-abcd-1234-5678-abcd1234abcd')
    ->setClientId('example@example.no')
    ->setClientUrl('http://example.com');

$tracking = (new TrackingEndpoint)
    ->setAuthorizationModule($authorizationModule)
    ->setApiEntity($trackingEntity)
    ->send();
print_r($tracking->toArray());

Advanced Usage

Look in the examples folder or you can generate the documents using Sami (composer dev-dependency)., (*6)

For people running Linux, (*7)

vendor/bin/sami.php -n render SamiConfig.php

For people running Windows, (*8)

"vendor/bin/sami.php.bat" -n render SamiConfig.php

You will now find the documents in the docs/build folder., (*9)

Running examples

For the tests to be able to run the Bring UID, Bring API Key and Customer number has to be set in the environment, (*10)

For people running Linux, (*11)

export BRING_UID="john.doe@example.com" && export BRING_API_KEY="1234abc-abcd-1234-5678-abcd1234abcd" && export BRING_CUSTOMER_NUMBER=" PARCELS_NORWAY-10001123123"

For people running Windows, (*12)

setx BRING_UID john.doe@example.com
setx BRING_API_KEY 1234abc-abcd-1234-5678-abcd1234abcd
setx BRING_CUSTOMER_NUMBER PARCELS_NORWAY-10001123123

Go into a new command prompt and run the examples. Some examples can be passed with arguments like postalcodes., (*13)

cd examples/
php BookAndPickupShipment.php
php PostalCode.php <numberOfPostalCode>
php ShippingGuideAll.php <fromPostalCode> <toPostalCode>
php Tracking.php <query>
php Reports.php <reportId>

Contribute

Contributions are very welcomed., (*14)

Please follow PSR-2 coding standard. You can run php-cs-fixer to fix the problems in the code., (*15)

License

MIT, (*16)

The Versions

07/07 2017

dev-master

9999999-dev

BringApi is a fully functional library to help contact Bring API

  Sources   Download

MIT

The Requires

 

The Development Requires

21/06 2017

1.0.0

1.0.0.0

BringApi is a fully functional library to help contact Bring API

  Sources   Download

MIT

The Requires

 

The Development Requires