Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/debuss/lapostesuivi
This API allows you to track your shipments in real time. "Suivi v2" allows you to harmonize the delivery status of tracked mail, Colissimo parcels and Chronopost shipments.
https://github.com/debuss/lapostesuivi
Last synced: about 1 month ago
JSON representation
This API allows you to track your shipments in real time. "Suivi v2" allows you to harmonize the delivery status of tracked mail, Colissimo parcels and Chronopost shipments.
- Host: GitHub
- URL: https://github.com/debuss/lapostesuivi
- Owner: debuss
- License: mit
- Created: 2020-02-20T09:56:41.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-11-23T09:56:46.000Z (about 1 month ago)
- Last Synced: 2024-11-23T10:30:25.256Z (about 1 month ago)
- Language: PHP
- Size: 44.9 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
La Poste Suivi API
The best way to track your La Poste, Colissimo and Chronopost packages.
## What does it do ?
This framework-agnostic package is an implementation of the tracking API version 2 from La Poste.
This API allows you to track your shipments in real time. "Suivi v2" allows you to harmonize the delivery status of tracked parcels, Colissimo parcels and Chronopost shipments.More information on the [developer page](https://developer.laposte.fr/products/suivi/2).
## Installation
It is recommended to use [composer](https://getcomposer.org/) to install the package :
```
$ composer require debuss-a/lapostesuivi:^2
```PHP 5.6 or newer is required.
## Usage
First of all you need an X-Okapi-Key to use the API.
Subscribe to a new Tracking API to get one **(it is free)**, [here](https://developer.laposte.fr/products/suivi/2), then you can instantiate the app :```php
require_once __DIR__.'/vendor/autoload.php';$app = new LaPoste\Suivi\App('YOUR_X-OKAPI-KEY_HERE');
```You need to create an object `Request` for every tracking number :
```php
$request = new \LaPoste\Suivi\Request('6M17554710224');
```You can pass 2 more parameters to define the `lang` and `ip_address` you wish to set up.
By default, `lang` is set to `fr_FR` and `ip_address` to `$_SERVER['REMOTE_ADDR']` (or `123.123.123.123` if `REMOTE_ADDR` is not defined).To track only 1 parcel, you can use the `LaPoste\Suivi\App::call` method :
```php
require_once __DIR__.'/vendor/autoload.php';$app = new LaPoste\Suivi\App('YOUR_X-OKAPI-KEY_HERE');
$request = new \LaPoste\Suivi\Request('6M17554710224');
$response = $app->call($request);
```To track more than 1 parcel, use the `LaPoste\Suivi\App::callMultiple` method :
```php
require_once __DIR__.'/vendor/autoload.php';$app = new LaPoste\Suivi\App('YOUR_X-OKAPI-KEY_HERE');
$requests = [
new \LaPoste\Suivi\Request('6M17554710224'),
new \LaPoste\Suivi\Request('EY604176344FR', LaPoste\Suivi\App::LANG_EN),
new \LaPoste\Suivi\Request('6M17554710224'),
];
$responses = $app->callMultiple($requests);
````LaPoste\Suivi\App::call` and `LaPoste\Suivi\App::callMultiple` return instances of [`LaPoste\Suivi\Response`](https://github.com/debuss/lapostesuivi/blob/master/src/Suivi/Response.php).
Note: in the case of `LaPoste\Suivi\App::callMultiple`, this package uses `curl_multi*` functions therefore all tracking numbers are tracked asynchronously.
This means the tracking of multiple packages is done at the same time instead of one by one, and it is much **MUCH!** faster.## Decorator
The package is included with an `AppV1Decorator` decorator class that you can use to format the output of
the v2 API to the v1 API.```php
$app = new \LaPoste\Suivi\AppV1Decorator(
new LaPoste\Suivi\App('YOUR_X-OKAPI-KEY_HERE')
);$single_response = $app->call(new \LaPoste\Suivi\Request('6A18987970674'));
$multiple_response = $app->callMultiple([
new \LaPoste\Suivi\Request('6A18987970674'),
new \LaPoste\Suivi\Request('6A18987970674'),
new \LaPoste\Suivi\Request('6A18987970674')
]);
```Result of `call` :
```
array (
'code' => '6A18987970674',
'date' => '06/07/2020',
'status' => 'LIVRE',
'message' => 'Votre colis est livré à votre gardien.',
'link' => 'https://www.laposte.fr/particulier/outils/suivre-vos-envois?code=6A18987970674',
'type' => 'Colissimo',
)
```Result of `callMultiple` :
```
array (
0 => array (
'data' => array (
'code' => '6A18987970674',
'date' => '06/07/2020',
'status' => 'LIVRE',
'message' => 'Votre colis est livré à votre gardien.',
'link' => 'https://www.laposte.fr/particulier/outils/suivre-vos-envois?code=6A18987970674',
'type' => 'Colissimo',
),
),
1 => array (
'data' => array (
'code' => '6A18987970674',
'date' => '06/07/2020',
'status' => 'LIVRE',
'message' => 'Votre colis est livré à votre gardien.',
'link' => 'https://www.laposte.fr/particulier/outils/suivre-vos-envois?code=6A18987970674',
'type' => 'Colissimo',
),
),
2 => array (
'data' => array (
'code' => '6A18987970674',
'date' => '06/07/2020',
'status' => 'LIVRE',
'message' => 'Votre colis est livré à votre gardien.',
'link' => 'https://www.laposte.fr/particulier/outils/suivre-vos-envois?code=6A18987970674',
'type' => 'Colissimo',
),
),
)
```Useful if you do not want to refactor all your code to the different v2 API !
## License
The package is licensed under the MIT license. See [License File](https://github.com/debuss/lapostesuivi/blob/master/LICENSE.md) for more information.