Skip to content

Commit

Permalink
Merge pull request #4 from dbojdo/fix/issue-2
Browse files Browse the repository at this point in the history
[fix] issue #2 (CustomerReference deserialisation)
  • Loading branch information
Daniel Bojdo authored Dec 5, 2016
2 parents db2e802 + b001af1 commit d7f2fdd
Show file tree
Hide file tree
Showing 14 changed files with 739 additions and 6 deletions.
126 changes: 126 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# GLS Tracking SDK

## Installation
### via Composer

Add the **webit/gls-tracking** into **composer.json**

```json
{
"require": {
"php": ">=5.3.2",
"webit/gls-tracking": "^1.0"
}
}
```

## Configuration / Usage

### API Factory preparation

```php
use Doctrine\Common\Annotations\AnnotationRegistry;
use JMS\Serializer\EventDispatcher\EventDispatcherInterface;
use JMS\Serializer\SerializerBuilder;
use Webit\GlsTracking\Model\Serialiser\TuDetailsResponseDeserialisationListener;
use Webit\SoapApi\SoapClient\SoapClientFactory;
use Webit\GlsTracking\Api\Factory\TrackingApiFactory;
use Webit\SoapApi\Input\InputNormalizerSerializerBased;
use Webit\SoapApi\Hydrator\HydratorSerializerBased;
use Webit\GlsTracking\Api\Exception\ExceptionFactory;
use Webit\SoapApi\Util\BinaryStringHelper;
use Webit\SoapApi\SoapApiExecutorFactory;
use Webit\GlsTracking\Model\UserCredentials;

AnnotationRegistry::registerAutoloadNamespace(
'JMS\Serializer\Annotation',
__DIR__.'/../vendor/jms/serializer/src'
);

$builder = SerializerBuilder::create();
$builder->addDefaultListeners();
$builder->configureListeners(function (EventDispatcherInterface $dispatcher) {
$dispatcher->addSubscriber(new TuDetailsResponseDeserialisationListener());
});
$serializer = $builder->build();

$clientFactory = new SoapClientFactory();
$executorFactory = new SoapApiExecutorFactory();
$normalizer = new InputNormalizerSerializerBased($serializer);
$hydrator = new HydratorSerializerBased($serializer, new BinaryStringHelper());
$exceptionFactory = new ExceptionFactory();

$apiFactory = new TrackingApiFactory($clientFactory, $executorFactory, $normalizer, $hydrator, $exceptionFactory);

```

### Tracking API

```php

$credentials = new UserCredentials('user', 'pass');

$api = $apiFactory->createTrackingApi($credentials);
$details = $api->getParcelDetails($parcelNo);

/** @var \Webit\GlsTracking\Model\Event $event */
printf("Details of parcel \"%s\"\n", $parcelNo);
foreach ($details->getHistory() as $event) {
printf(
"%s - Status: %s (%s), Location: %s, %s (%s)\n",
$event->getDate(),
$event->getCode(),
$event->getDescription(),
$event->getLocationName(),
$event->getCountryName(),
$event->getLocationCode()
);
}
printf("Received by: %s\n", $details->getSignature());

$pod = $api->getProofOfDelivery($parcelNo);
printf("Proof of delivery filename: %s\n", $pod->getFileName());
```

### Tracking Url Provider

```php
use Webit\GlsTracking\UrlProvider\TrackingUrlProviderFactory;
$factory = new TrackingUrlProviderFactory();

/** @var array $config */

$username = 'username';

$urlProvider = $factory->createTrackingUrlProvider();

$reference = 'parcel-no';

$url = $urlProvider->getStandardTrackingUrl($reference, 'EN', 'EN');

printf("Url for tracking \"%s\" (encrypted): %s\n", $reference, $url);

$url = $urlProvider->getEncryptedTrackingUrl($credentials, $reference, $config['language']);

printf("Url for tracking \"%s\" (encrypted): %s\n", $reference, $url);

$customerReference = 'customer-ref';
$customerNo = 'customer-no';
$url = $urlProvider->getEncryptedCustomerReferenceTrackingUrl($credentials, $customerReference, $customerNo, $config['language']);

printf("Url for tracking \"%s\" with customer \"%s\": %s\n", $customerReference, $customerNo, $url);
```

### Examples

To configure the examples:
* Copy ***examples/config.php.dist*** to ***examples/config.php***
* Change the values accordingly


Run:
```bash
php examples/details.php
php examples/url-provider.php
```

16 changes: 15 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,24 @@
"php": ">=5.3.3",
"webit/soap-api": "~1.0"
},
"require-dev": {
"phpunit/phpunit": "^4.6.0"
},
"autoload": {
"psr-4": {
"Webit\\GlsTracking\\": "src/"
}
},
"minimum-stability": "dev"
"autoload-dev": {
"psr-4": {
"Webit\\GlsTracking\\Tests\\": "tests/"
}
},
"extra": {
"branch-alias": {
"dev-master": "1.x-dev"
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
9 changes: 8 additions & 1 deletion examples/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
require __DIR__.'/../vendor/autoload.php';

use Doctrine\Common\Annotations\AnnotationRegistry;
use JMS\Serializer\EventDispatcher\EventDispatcherInterface;
use JMS\Serializer\SerializerBuilder;
use Webit\GlsTracking\Model\Serialiser\TuDetailsResponseDeserialisationListener;
use Webit\SoapApi\SoapClient\SoapClientFactory;
use Webit\GlsTracking\Api\Factory\TrackingApiFactory;
use Webit\SoapApi\Input\InputNormalizerSerializerBased;
Expand All @@ -25,7 +27,12 @@

$config = require __DIR__ .'/config.php';

$serializer = SerializerBuilder::create()->build();
$builder = SerializerBuilder::create();
$builder->addDefaultListeners();
$builder->configureListeners(function (EventDispatcherInterface $dispatcher) {
$dispatcher->addSubscriber(new TuDetailsResponseDeserialisationListener());
});
$serializer = $builder->build();

$clientFactory = new SoapClientFactory();
$executorFactory = new SoapApiExecutorFactory();
Expand Down
18 changes: 18 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="tests/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false">

<testsuites>
<testsuite name="GLS Tracking API test">
<directory>./tests</directory>
</testsuite>
</testsuites>
</phpunit>
44 changes: 44 additions & 0 deletions src/Model/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,50 @@ class Address
*/
private $country;

/**
* Address constructor.
* @param string $name1
* @param string $name2
* @param string $name3
* @param string $contactName
* @param string $street1
* @param string $blockNo1
* @param string $street2
* @param string $blockNo2
* @param string $zipCode
* @param string $city
* @param string $province
* @param string $country
*/
public function __construct(
$name1 = null,
$name2 = null,
$name3 = null,
$contactName = null,
$street1 = null,
$blockNo1 = null,
$street2 = null,
$blockNo2 = null,
$zipCode = null,
$city = null,
$province = null,
$country = null
) {
$this->name1 = $name1;
$this->name2 = $name2;
$this->name3 = $name3;
$this->contactName = $contactName;
$this->street1 = $street1;
$this->blockNo1 = $blockNo1;
$this->street2 = $street2;
$this->blockNo2 = $blockNo2;
$this->zipCode = $zipCode;
$this->city = $city;
$this->province = $province;
$this->country = $country;
}


/**
* @return string
*/
Expand Down
11 changes: 11 additions & 0 deletions src/Model/CustomerReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ class CustomerReference
*/
private $value;

/**
* CustomerReference constructor.
* @param string $type
* @param string $value
*/
public function __construct($type = null, $value = null)
{
$this->type = $type;
$this->value = $value;
}

/**
* @return string
*/
Expand Down
29 changes: 29 additions & 0 deletions src/Model/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,35 @@ class Event
*/
private $reasonName;

/**
* Event constructor.
* @param DateTime $date
* @param string $locationCode
* @param string $locationName
* @param string $countryName
* @param string $code
* @param string $description
* @param string $reasonName
*/
public function __construct(
DateTime $date = null,
$locationCode = null,
$locationName = null,
$countryName = null,
$code = null,
$description = null,
$reasonName = null
) {
$this->date = $date;
$this->locationCode = $locationCode;
$this->locationName = $locationName;
$this->countryName = $countryName;
$this->code = $code;
$this->description = $description;
$this->reasonName = $reasonName;
}


/**
* @return string
*/
Expand Down
11 changes: 11 additions & 0 deletions src/Model/ExitCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ class ExitCode
*/
private $description;

/**
* ExitCode constructor.
* @param int $code
* @param string $description
*/
public function __construct($code, $description)
{
$this->code = $code;
$this->description = $description;
}

/**
* @return int
*/
Expand Down
6 changes: 6 additions & 0 deletions src/Model/Message/AbstractResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace Webit\GlsTracking\Model\Message;

use JMS\Serializer\Annotation as JMS;
use Webit\GlsTracking\Model\ExitCode;

/**
* Class AbstractResponse
Expand All @@ -24,6 +25,11 @@ abstract class AbstractResponse
*/
private $exitCode;

public function __construct(ExitCode $exitCode = null)
{
$this->exitCode = $exitCode;
}

public function getExitCode()
{
return $this->exitCode;
Expand Down
Loading

0 comments on commit d7f2fdd

Please sign in to comment.