2017 © Pedro Peláez
 

library pd-parcelshop-api

Webservice for PostDanmark ParcelShop

image

lsv/pd-parcelshop-api

Webservice for PostDanmark ParcelShop

  • Wednesday, August 23, 2017
  • by lsv
  • Repository
  • 1 Watchers
  • 1 Stars
  • 1,605 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

PostNord parcelshop (tested with Denmark and Sweden)

Build Status, (*1)

Get parcelshops from either, (*2)

  • A parcelshop number
  • A danish zipcode
  • Nearby an address

Connecting

You will need an ApiKey to get access to the API, (*3)

You can get the ApiKey here, (*4)

Get single parcelshop by Id

<?php
require 'vendor/autoload.php';

use Lsv\PdDk\Client;

$p = new Client( API_KEY );
$shop = $p->getParcelshop( ZIPCODE , ID );
// Yes zipcode is unfortunately mandatory

Throws Exceptions\ParcelNotFoundException if not found, (*5)

Returns $shop is a Entity\Parcelshop object, (*6)

Get parcelshops from a zipcode

<?php
require 'vendor/autoload.php';

use Lsv\PdDk\Client;

$p = new Client( API_KEY );
$shops = $p->getParcelshopsFromZipcode( ZIPCODE );

Throws Exceptions\NoParcelsFoundInZipcodeException if none found, (*7)

Returns $shops is a array of Entity\Parcelshop, (*8)

Get parcelshops near address

<?php
require 'vendor/autoload.php';

use Lsv\PdDk\Client;

$p = new Client( API_KEY );
$shops = $p->getParcelshopsNearAddress( STREET , ZIPCODE, 20 );

Third argument is how many you want, (*9)

Throws Exceptions\MalformedAddressException if address is unknown, (*10)

Returns $shops is a array of Entity\Parcelshop, (*11)

Add retry guzzle client

First install it with composer, (*12)

composer require guzzlehttp/retry-subscriber

Now create our client, (*13)

<?php
require 'vendor/autoload.php';

use Lsv\PdDk\Client;
use GuzzleHttp\Subscriber\Retry\RetrySubscriber;

$retry = new RetrySubscriber([
    'filter' => RetrySubscriber::createStatusFilter()
]);

$httpClient = new GuzzleHttp\Client();
$httpClient->getEmitter()->attach($retry);

$p = new Client($httpClient);
$shops = $p->getParcelshopsNearAddress( STREET , ZIPCODE, 20 );

The Versions