Skip to content

Commit d7f2fdd

Browse files
author
Daniel Bojdo
authored
Merge pull request #4 from dbojdo/fix/issue-2
[fix] issue #2 (CustomerReference deserialisation)
2 parents db2e802 + b001af1 commit d7f2fdd

14 files changed

+739
-6
lines changed

README.md

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# GLS Tracking SDK
2+
3+
## Installation
4+
### via Composer
5+
6+
Add the **webit/gls-tracking** into **composer.json**
7+
8+
```json
9+
{
10+
"require": {
11+
"php": ">=5.3.2",
12+
"webit/gls-tracking": "^1.0"
13+
}
14+
}
15+
```
16+
17+
## Configuration / Usage
18+
19+
### API Factory preparation
20+
21+
```php
22+
use Doctrine\Common\Annotations\AnnotationRegistry;
23+
use JMS\Serializer\EventDispatcher\EventDispatcherInterface;
24+
use JMS\Serializer\SerializerBuilder;
25+
use Webit\GlsTracking\Model\Serialiser\TuDetailsResponseDeserialisationListener;
26+
use Webit\SoapApi\SoapClient\SoapClientFactory;
27+
use Webit\GlsTracking\Api\Factory\TrackingApiFactory;
28+
use Webit\SoapApi\Input\InputNormalizerSerializerBased;
29+
use Webit\SoapApi\Hydrator\HydratorSerializerBased;
30+
use Webit\GlsTracking\Api\Exception\ExceptionFactory;
31+
use Webit\SoapApi\Util\BinaryStringHelper;
32+
use Webit\SoapApi\SoapApiExecutorFactory;
33+
use Webit\GlsTracking\Model\UserCredentials;
34+
35+
AnnotationRegistry::registerAutoloadNamespace(
36+
'JMS\Serializer\Annotation',
37+
__DIR__.'/../vendor/jms/serializer/src'
38+
);
39+
40+
$builder = SerializerBuilder::create();
41+
$builder->addDefaultListeners();
42+
$builder->configureListeners(function (EventDispatcherInterface $dispatcher) {
43+
$dispatcher->addSubscriber(new TuDetailsResponseDeserialisationListener());
44+
});
45+
$serializer = $builder->build();
46+
47+
$clientFactory = new SoapClientFactory();
48+
$executorFactory = new SoapApiExecutorFactory();
49+
$normalizer = new InputNormalizerSerializerBased($serializer);
50+
$hydrator = new HydratorSerializerBased($serializer, new BinaryStringHelper());
51+
$exceptionFactory = new ExceptionFactory();
52+
53+
$apiFactory = new TrackingApiFactory($clientFactory, $executorFactory, $normalizer, $hydrator, $exceptionFactory);
54+
55+
```
56+
57+
### Tracking API
58+
59+
```php
60+
61+
$credentials = new UserCredentials('user', 'pass');
62+
63+
$api = $apiFactory->createTrackingApi($credentials);
64+
$details = $api->getParcelDetails($parcelNo);
65+
66+
/** @var \Webit\GlsTracking\Model\Event $event */
67+
printf("Details of parcel \"%s\"\n", $parcelNo);
68+
foreach ($details->getHistory() as $event) {
69+
printf(
70+
"%s - Status: %s (%s), Location: %s, %s (%s)\n",
71+
$event->getDate(),
72+
$event->getCode(),
73+
$event->getDescription(),
74+
$event->getLocationName(),
75+
$event->getCountryName(),
76+
$event->getLocationCode()
77+
);
78+
}
79+
printf("Received by: %s\n", $details->getSignature());
80+
81+
$pod = $api->getProofOfDelivery($parcelNo);
82+
printf("Proof of delivery filename: %s\n", $pod->getFileName());
83+
```
84+
85+
### Tracking Url Provider
86+
87+
```php
88+
use Webit\GlsTracking\UrlProvider\TrackingUrlProviderFactory;
89+
$factory = new TrackingUrlProviderFactory();
90+
91+
/** @var array $config */
92+
93+
$username = 'username';
94+
95+
$urlProvider = $factory->createTrackingUrlProvider();
96+
97+
$reference = 'parcel-no';
98+
99+
$url = $urlProvider->getStandardTrackingUrl($reference, 'EN', 'EN');
100+
101+
printf("Url for tracking \"%s\" (encrypted): %s\n", $reference, $url);
102+
103+
$url = $urlProvider->getEncryptedTrackingUrl($credentials, $reference, $config['language']);
104+
105+
printf("Url for tracking \"%s\" (encrypted): %s\n", $reference, $url);
106+
107+
$customerReference = 'customer-ref';
108+
$customerNo = 'customer-no';
109+
$url = $urlProvider->getEncryptedCustomerReferenceTrackingUrl($credentials, $customerReference, $customerNo, $config['language']);
110+
111+
printf("Url for tracking \"%s\" with customer \"%s\": %s\n", $customerReference, $customerNo, $url);
112+
```
113+
114+
### Examples
115+
116+
To configure the examples:
117+
* Copy ***examples/config.php.dist*** to ***examples/config.php***
118+
* Change the values accordingly
119+
120+
121+
Run:
122+
```bash
123+
php examples/details.php
124+
php examples/url-provider.php
125+
```
126+

composer.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,24 @@
1313
"php": ">=5.3.3",
1414
"webit/soap-api": "~1.0"
1515
},
16+
"require-dev": {
17+
"phpunit/phpunit": "^4.6.0"
18+
},
1619
"autoload": {
1720
"psr-4": {
1821
"Webit\\GlsTracking\\": "src/"
1922
}
2023
},
21-
"minimum-stability": "dev"
24+
"autoload-dev": {
25+
"psr-4": {
26+
"Webit\\GlsTracking\\Tests\\": "tests/"
27+
}
28+
},
29+
"extra": {
30+
"branch-alias": {
31+
"dev-master": "1.x-dev"
32+
}
33+
},
34+
"minimum-stability": "dev",
35+
"prefer-stable": true
2236
}

examples/bootstrap.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
require __DIR__.'/../vendor/autoload.php';
33

44
use Doctrine\Common\Annotations\AnnotationRegistry;
5+
use JMS\Serializer\EventDispatcher\EventDispatcherInterface;
56
use JMS\Serializer\SerializerBuilder;
7+
use Webit\GlsTracking\Model\Serialiser\TuDetailsResponseDeserialisationListener;
68
use Webit\SoapApi\SoapClient\SoapClientFactory;
79
use Webit\GlsTracking\Api\Factory\TrackingApiFactory;
810
use Webit\SoapApi\Input\InputNormalizerSerializerBased;
@@ -25,7 +27,12 @@
2527

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

28-
$serializer = SerializerBuilder::create()->build();
30+
$builder = SerializerBuilder::create();
31+
$builder->addDefaultListeners();
32+
$builder->configureListeners(function (EventDispatcherInterface $dispatcher) {
33+
$dispatcher->addSubscriber(new TuDetailsResponseDeserialisationListener());
34+
});
35+
$serializer = $builder->build();
2936

3037
$clientFactory = new SoapClientFactory();
3138
$executorFactory = new SoapApiExecutorFactory();

phpunit.xml.dist

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
bootstrap="tests/bootstrap.php"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false"
11+
syntaxCheck="false">
12+
13+
<testsuites>
14+
<testsuite name="GLS Tracking API test">
15+
<directory>./tests</directory>
16+
</testsuite>
17+
</testsuites>
18+
</phpunit>

src/Model/Address.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,50 @@ class Address
112112
*/
113113
private $country;
114114

115+
/**
116+
* Address constructor.
117+
* @param string $name1
118+
* @param string $name2
119+
* @param string $name3
120+
* @param string $contactName
121+
* @param string $street1
122+
* @param string $blockNo1
123+
* @param string $street2
124+
* @param string $blockNo2
125+
* @param string $zipCode
126+
* @param string $city
127+
* @param string $province
128+
* @param string $country
129+
*/
130+
public function __construct(
131+
$name1 = null,
132+
$name2 = null,
133+
$name3 = null,
134+
$contactName = null,
135+
$street1 = null,
136+
$blockNo1 = null,
137+
$street2 = null,
138+
$blockNo2 = null,
139+
$zipCode = null,
140+
$city = null,
141+
$province = null,
142+
$country = null
143+
) {
144+
$this->name1 = $name1;
145+
$this->name2 = $name2;
146+
$this->name3 = $name3;
147+
$this->contactName = $contactName;
148+
$this->street1 = $street1;
149+
$this->blockNo1 = $blockNo1;
150+
$this->street2 = $street2;
151+
$this->blockNo2 = $blockNo2;
152+
$this->zipCode = $zipCode;
153+
$this->city = $city;
154+
$this->province = $province;
155+
$this->country = $country;
156+
}
157+
158+
115159
/**
116160
* @return string
117161
*/

src/Model/CustomerReference.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ class CustomerReference
3232
*/
3333
private $value;
3434

35+
/**
36+
* CustomerReference constructor.
37+
* @param string $type
38+
* @param string $value
39+
*/
40+
public function __construct($type = null, $value = null)
41+
{
42+
$this->type = $type;
43+
$this->value = $value;
44+
}
45+
3546
/**
3647
* @return string
3748
*/

src/Model/Event.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,35 @@ class Event
7272
*/
7373
private $reasonName;
7474

75+
/**
76+
* Event constructor.
77+
* @param DateTime $date
78+
* @param string $locationCode
79+
* @param string $locationName
80+
* @param string $countryName
81+
* @param string $code
82+
* @param string $description
83+
* @param string $reasonName
84+
*/
85+
public function __construct(
86+
DateTime $date = null,
87+
$locationCode = null,
88+
$locationName = null,
89+
$countryName = null,
90+
$code = null,
91+
$description = null,
92+
$reasonName = null
93+
) {
94+
$this->date = $date;
95+
$this->locationCode = $locationCode;
96+
$this->locationName = $locationName;
97+
$this->countryName = $countryName;
98+
$this->code = $code;
99+
$this->description = $description;
100+
$this->reasonName = $reasonName;
101+
}
102+
103+
75104
/**
76105
* @return string
77106
*/

src/Model/ExitCode.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ class ExitCode
3636
*/
3737
private $description;
3838

39+
/**
40+
* ExitCode constructor.
41+
* @param int $code
42+
* @param string $description
43+
*/
44+
public function __construct($code, $description)
45+
{
46+
$this->code = $code;
47+
$this->description = $description;
48+
}
49+
3950
/**
4051
* @return int
4152
*/

src/Model/Message/AbstractResponse.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
namespace Webit\GlsTracking\Model\Message;
1010

1111
use JMS\Serializer\Annotation as JMS;
12+
use Webit\GlsTracking\Model\ExitCode;
1213

1314
/**
1415
* Class AbstractResponse
@@ -24,6 +25,11 @@ abstract class AbstractResponse
2425
*/
2526
private $exitCode;
2627

28+
public function __construct(ExitCode $exitCode = null)
29+
{
30+
$this->exitCode = $exitCode;
31+
}
32+
2733
public function getExitCode()
2834
{
2935
return $this->exitCode;

0 commit comments

Comments
 (0)