forked from opportus/sls-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2b3a253
Showing
27 changed files
with
1,409 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Contributor Covenant Code of Conduct | ||
|
||
## Our Pledge | ||
|
||
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. | ||
|
||
## Our Standards | ||
|
||
Examples of behavior that contributes to creating a positive environment include: | ||
|
||
- Using welcoming and inclusive language | ||
- Being respectful of differing viewpoints and experiences | ||
- Gracefully accepting constructive criticism | ||
- Focusing on what is best for the community | ||
- Showing empathy towards other community members | ||
|
||
Examples of unacceptable behavior by participants include: | ||
|
||
- The use of sexualized language or imagery and unwelcome sexual attention or advances | ||
- Trolling, insulting/derogatory comments, and personal or political attacks | ||
- Public or private harassment | ||
- Publishing others' private information, such as a physical or electronic address, without explicit permission | ||
- Other conduct which could reasonably be considered inappropriate in a professional setting | ||
|
||
## Our Responsibilities | ||
|
||
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. | ||
|
||
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. | ||
|
||
## Scope | ||
|
||
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. | ||
|
||
## Enforcement | ||
|
||
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [email protected]. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. | ||
|
||
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. | ||
|
||
## Attribution | ||
|
||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] | ||
|
||
[homepage]: http://contributor-covenant.org | ||
[version]: http://contributor-covenant.org/version/1/4/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Contributing | ||
|
||
First off, thank you for considering contributing to that project. | ||
|
||
This is an open source project and we love to receive contributions from our community — you! There are many ways to contribute, from writing tutorials or blog posts, improving the documentation, submitting bug reports and feature requests or writing code which can be incorporated into the project itself. | ||
|
||
Following these guidelines helps to communicate that you respect the time of the developers managing and developing this open source project. In return, they should reciprocate that respect in addressing your issue, assessing changes, and helping you finalize your pull requests. | ||
|
||
--- | ||
|
||
## Bug Reports & Feature Requests | ||
|
||
Before submitting a bug report or feature request, make sure you're not going to duplicate any existing one by checking the current list of open and closed [issues](https://github.com/opportus/sls-client/issues). | ||
|
||
While submitting a [bug report](https://github.com/opportus/sls-client/issues/new?template=bug_report.md) or [feature request](https://github.com/opportus/sls-client/issues/new?template=feature_request.md), make sure you comply with the instructions in the template. This will help other contributors to address efficiently the issue. | ||
|
||
## Pull Requests | ||
|
||
Pull requests must address an open bug report or feature request. | ||
|
||
Before implementing your feature or fix, make sure you're not going to duplicate anyone's work by checking the current list of open and closed [pull requests](https://github.com/opportus/sls-client/pulls). | ||
|
||
Make your code comply with the [PSR-12 Coding Standards](https://www.php-fig.org/psr/psr-12/). | ||
|
||
Leave detailed commit messages. | ||
|
||
While submitting a pull request, make sure you comply with the instructions in the template. This will help other contributors to address efficiently the pull request. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
|
||
name: Bug report | ||
about: Create a report to help us improve | ||
|
||
--- | ||
|
||
<!-- A clear and concise description of the bug. --> | ||
|
||
## Bug Reproduction Steps | ||
|
||
<!-- A clear and concise list of steps to reproduce the bug. --> | ||
|
||
## Expected Result | ||
|
||
<!-- A clear and concise description of the expected result. --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
|
||
name: Feature request | ||
about: Suggest an idea for this project | ||
|
||
--- | ||
|
||
## Problem | ||
|
||
<!-- A clear and concise description of the problem. --> | ||
|
||
## Solutions | ||
|
||
<!-- A clear and concise description of the solutions. --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Closes #<!-- Issue number -->. | ||
|
||
<!-- Describe the changes introduced by the Pull Request here. --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/composer.lock | ||
/vendor/ | ||
.phpunit.result.cache | ||
phpunit*.phar | ||
.php_cs.cache | ||
tags | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2019-2020 Clément Cazaud | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is furnished | ||
to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
A Colissimo Simple Label Solution (SLS) client. | ||
|
||
## To do | ||
|
||
- Implement cache system | ||
- Implement unit and functional tests | ||
- Implement benchmarks | ||
- Implement all SLS methods | ||
- Implement request validation based on SLS WSDL so that we economize client-server roundtrips | ||
|
||
## Installation | ||
|
||
### Requirements | ||
|
||
- PHP >= 5.4 | ||
- libxml PHP extension installed and enabled | ||
- soap PHP extension installed and enabled | ||
- composer | ||
|
||
### Step 1 - Download and install the package | ||
|
||
Open a command console, enter your project directory and execute: | ||
|
||
```sh | ||
$ composer require opportus/sls-client | ||
``` | ||
|
||
## Guide | ||
|
||
A basic code example: | ||
|
||
```php | ||
use Opportus\SlsClient\Client; | ||
|
||
$client = Client::create(); | ||
|
||
$requestParameters = [ | ||
'contractNumber' => '111111', | ||
'password' => '1111111', | ||
'outputFormat' => [ | ||
'x' => '0', | ||
'y' => '0', | ||
'outputPrintingType' => 'PDF_A4_300dpi', | ||
], | ||
'letter' => [ | ||
'service' => [ | ||
'productCode' => 'DOM', | ||
'depositDate' => '2019-01-01', | ||
], | ||
'parcel' => [ | ||
'weight' => '1', | ||
], | ||
'sender' => [ | ||
'address' => [ | ||
'companyName' => 'FOO', | ||
'line2' => '1 RUE FOO', | ||
'countryCode' => 'FR', | ||
'city' => 'FOO', | ||
'zipCode' => '00000', | ||
], | ||
], | ||
'addressee' => [ | ||
'address' => [ | ||
'companyName' => 'BAR', | ||
'line2' => '1 RUE BAR', | ||
'countryCode' => 'FR', | ||
'city' => 'BAR', | ||
'zipCode' => '00000', | ||
], | ||
], | ||
], | ||
]; | ||
|
||
$response = $client->generateLabel($requestParameters); | ||
|
||
$response->getMessageId(); // '0' | ||
$response->getLabel(); // 'https://example.com/label.pdf' | ||
$response->getParcelNumber(); // '6A11111111111' | ||
``` | ||
|
||
This library is currently a *passthrough* client of the SLS service. Therefore, the [SLS documentation](https://github.com/opportus/sls-client/blob/master/specs/sls-doc-2019-03.pdf) covers pretty much everything else you need to know in order to use this library. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{ | ||
"name": "opportus/sls-client", | ||
"type": "library", | ||
"description": "Colissimo Simple Label Solution (SLS) client", | ||
"keywords": [ | ||
"colissimo", | ||
"colissimo api", | ||
"colissimo client", | ||
"colissimo api client", | ||
"simple label solution", | ||
"simple label solution api", | ||
"simple label solution client", | ||
"simple label solution api client", | ||
"colissimo simple label solution", | ||
"colissimo simple label solution api", | ||
"colissimo simple label solution client", | ||
"colissimo simple label solution api client", | ||
"sls", | ||
"sls api", | ||
"sls api client", | ||
"colissimo sls", | ||
"colissimo sls api", | ||
"colissimo sls api client" | ||
], | ||
"homepage": "https://github.com/opportus/sls-client", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Clément Cazaud", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.4" | ||
}, | ||
"require-dev": { | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Opportus\\SlsClient\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Opportus\\SlsClient\\Tests\\": "tests/", | ||
"Opportus\\SlsClient\\Benchmarks\\": "benchmarks/" | ||
} | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the opportus/sls-client package. | ||
* | ||
* Copyright (c) 2019-2020 Clément Cazaud <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace Opportus\SlsClient; | ||
|
||
use Opportus\SlsClient\Exception\InvalidArgumentException; | ||
use Opportus\SlsClient\Response\CheckGenerateLabelResponseInterface; | ||
use Opportus\SlsClient\Response\GenerateLabelResponseInterface; | ||
use Opportus\SlsClient\Response\ResponseInterface; | ||
use Opportus\SlsClient\Response\FaultResponse; | ||
use SoapClient; | ||
|
||
/** | ||
* The client. | ||
* | ||
* @package Opportus\SlsClient | ||
* @author Clément Cazaud <[email protected]> | ||
* @license https://github.com/opportus/sls-client/blob/master/LICENSE MIT | ||
*/ | ||
class Client implements ClientInterface | ||
{ | ||
const SERVICE_VERSION = '2.0'; | ||
const SERVICE_URI = 'https://ws.colissimo.fr/sls-ws/SlsServiceWS/'.self::SERVICE_VERSION; | ||
const SERVICE_WSDL = self::SERVICE_URI.'?wsdl'; | ||
|
||
/** | ||
* @var SoapClient $soapClient | ||
*/ | ||
private $soapClient; | ||
|
||
/** | ||
* Constructs the client. | ||
* | ||
* @param SoapClient $soapClient | ||
*/ | ||
public function __construct(SoapClient $soapClient) | ||
{ | ||
$this->soapClient = $soapClient; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function create(): ClientInterface | ||
{ | ||
$soapClient = new SoapClient(self::SERVICE_WSDL, [ | ||
'exceptions' => false, | ||
'trace' => true, | ||
]); | ||
|
||
return new self($soapClient); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function generateLabel($parameters): GenerateLabelResponseInterface | ||
{ | ||
return $this->request(__FUNCTION__, $parameters); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function checkGenerateLabel($parameters): CheckGenerateLabelResponseInterface | ||
{ | ||
return $this->request(__FUNCTION__, $parameters); | ||
} | ||
|
||
/** | ||
* Requests the WSL service. | ||
* | ||
* @param string $function | ||
* @param array $parameters | ||
* @return ResponseInterface | ||
* @throws InvalidOperationException | ||
*/ | ||
private function request($function, $parameters): ResponseInterface | ||
{ | ||
$requestType = \sprintf('Opportus\SlsClient\Request\%sRequest', \ucfirst($function)); | ||
$responseType = \sprintf('Opportus\SlsClient\Response\%sResponse', \ucfirst($function)); | ||
|
||
$request = new $requestType($parameters); | ||
|
||
$rawResponse = $this->soapClient->__doRequest( | ||
$request, | ||
self::SERVICE_URI, | ||
$function, | ||
self::SERVICE_VERSION | ||
); | ||
|
||
try { | ||
$response = new $responseType($rawResponse); | ||
} catch (InvalidArgumentException $exception) { | ||
try { | ||
$response = new FaultResponse($rawResponse); | ||
} catch (InvalidArgumentException $exception) { | ||
throw new Exception(\sprintf( | ||
'No supported response type matches the following raw response: %s', | ||
$rawResponse | ||
)); | ||
} | ||
|
||
throw new InvalidArgumentException(\sprintf( | ||
'%s: %s', | ||
$response->getCode(), | ||
$response->getString() | ||
)); | ||
} | ||
|
||
return $response; | ||
} | ||
} | ||
|
Oops, something went wrong.