Skip to content

Commit 5779b3e

Browse files
committed
Initial commit
0 parents  commit 5779b3e

35 files changed

+2395
-0
lines changed

.github/workflows/code_quality.yml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: Code quality
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
install_dependencies:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v3
18+
19+
- name: Cache composer directory
20+
id: cache-composer
21+
uses: actions/cache@v3
22+
env:
23+
cache-name: cache-vendor-directory
24+
with:
25+
path: vendor
26+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/composer.json') }}
27+
restore-keys: |
28+
${{ runner.os }}-build-${{ env.cache-name }}-
29+
${{ runner.os }}-build-
30+
${{ runner.os }}-
31+
32+
- name: Validate composer.json and composer.lock
33+
run: composer validate --strict
34+
35+
- name: Install dependencies
36+
run: composer install --prefer-dist --no-progress
37+
38+
lint:
39+
needs: [ install_dependencies ]
40+
41+
runs-on: ubuntu-latest
42+
43+
steps:
44+
- uses: actions/checkout@v3
45+
46+
- name: Cache composer directory
47+
id: cache-composer
48+
uses: actions/cache@v3
49+
env:
50+
cache-name: cache-vendor-directory
51+
with:
52+
path: vendor
53+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/composer.json') }}
54+
restore-keys: |
55+
${{ runner.os }}-build-${{ env.cache-name }}-
56+
${{ runner.os }}-build-
57+
${{ runner.os }}-
58+
59+
- if: ${{ steps.cache-composer.outputs.cache-hit != 'true' }}
60+
name: Install composer dependencies
61+
run: composer install --prefer-dist --no-progress
62+
63+
- name: Analyze the code formatting
64+
run: composer run-script lint
65+
66+
analyze:
67+
runs-on: ubuntu-latest
68+
69+
needs: [ install_dependencies ]
70+
71+
steps:
72+
- uses: actions/checkout@v3
73+
74+
- name: Cache composer directory
75+
id: cache-composer
76+
uses: actions/cache@v3
77+
env:
78+
cache-name: cache-vendor-directory
79+
with:
80+
path: vendor
81+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/composer.json') }}
82+
restore-keys: |
83+
${{ runner.os }}-build-${{ env.cache-name }}-
84+
${{ runner.os }}-build-
85+
${{ runner.os }}-
86+
87+
- if: ${{ steps.cache-composer.outputs.cache-hit != 'true' }}
88+
name: Install composer dependencies
89+
run: composer install --prefer-dist --no-progress
90+
91+
- name: Run static analysis
92+
run: composer run-script analyze

.github/workflows/tests.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
install_dependencies:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v3
18+
19+
- name: Cache composer directory
20+
id: cache-composer
21+
uses: actions/cache@v3
22+
env:
23+
cache-name: cache-vendor-directory
24+
with:
25+
path: vendor
26+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/composer.json') }}
27+
restore-keys: |
28+
${{ runner.os }}-build-${{ env.cache-name }}-
29+
${{ runner.os }}-build-
30+
${{ runner.os }}-
31+
32+
- name: Validate composer.json and composer.lock
33+
run: composer validate --strict
34+
35+
- name: Install dependencies
36+
run: composer install --prefer-dist --no-progress
37+
38+
tests:
39+
needs: [ install_dependencies ]
40+
strategy:
41+
matrix:
42+
php-versions: [ "7.4", "8.0", "8.1", "8.2" ]
43+
44+
runs-on: ubuntu-latest
45+
46+
steps:
47+
- name: Setup PHP
48+
uses: shivammathur/setup-php@v2
49+
with:
50+
php-version: ${{ matrix.php-versions}}
51+
52+
- uses: actions/checkout@v3
53+
54+
- name: Cache composer directory
55+
id: cache-composer
56+
uses: actions/cache@v3
57+
env:
58+
cache-name: cache-vendor-directory
59+
with:
60+
path: vendor
61+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/composer.json') }}
62+
restore-keys: |
63+
${{ runner.os }}-build-${{ env.cache-name }}-
64+
${{ runner.os }}-build-
65+
${{ runner.os }}-
66+
67+
- if: ${{ steps.cache-composer.outputs.cache-hit != 'true' }}
68+
name: Install composer dependencies
69+
run: composer install --prefer-dist --no-progress
70+
71+
- name: Run test suite
72+
run: composer run-script test

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
composer.phar
2+
vendor
3+
.env
4+
.idea
5+
composer.lock
6+
.phpunit.result.cache
7+
.phpunit.cache

CONTRIBUTING.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Contributing
2+
3+
Contributions are **welcome**.
4+
5+
Please read and understand the contribution guide before creating an issue or pull request.
6+
7+
## Requirements
8+
9+
If the project maintainer has any additional requirements, you will find them listed here.
10+
11+
- **[PSR-12 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-12-extended-coding-style-guide.md)** - The easiest way to apply the conventions is to run `composer run-script lint`.
12+
13+
- **Add tests!** - Your patch won't be accepted if it doesn't have tests.
14+
15+
- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.
16+
17+
- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
18+
19+
- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.
20+
21+
**Happy coding**!

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2023 Sendy
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# Sendy API PHP Client
2+
3+
PHP Client library to connect with the Sendy API. This client lets you connect with the Sendy API to create shipments
4+
and labels.
5+
6+
[![Code quality](https://github.com/keendelivery/php-sdk/actions/workflows/code_quality.yml/badge.svg)](https://github.com/keendelivery/php-sdk/actions/workflows/code_quality.yml) [![Tests](https://github.com/keendelivery/php-sdk/actions/workflows/tests.yml/badge.svg)](https://github.com/keendelivery/php-sdk/actions/workflows/tests.yml)
7+
8+
## Installation
9+
Installing the client can be done through Composer:
10+
```
11+
composer require sendynl/php-sdk
12+
```
13+
14+
## Usage
15+
16+
### Authentication
17+
18+
Authentication can be done in two different ways: with personal access tokens and the OAuth flow.
19+
20+
#### Personal Access Tokens
21+
22+
You can manage your personal access tokens in [the portal](https://app.sendy.nl/settings/personal-access-tokens). When
23+
you have a personal access token, you can use this library like this:
24+
25+
```php
26+
<?php
27+
28+
$connection = new \Sendy\Api\Connection();
29+
30+
$connection->setAccessToken('your-personal-access-token');
31+
32+
$connection->me->get();
33+
```
34+
35+
#### OAuth
36+
37+
##### Authorize the connection from your app
38+
39+
```php
40+
$connection = new \Sendy\Api\Connection();
41+
42+
$connection->setOauthClient(true);
43+
44+
$connection->setClientId('your-client-id')
45+
->setClientSecret('your-client-secret')
46+
->setRedirectUrl('your-callback-url');
47+
48+
$connection->redirectForAuthorization();
49+
```
50+
51+
This will redirect the user to the portal and authorize your integration with their account.
52+
53+
##### Connect with the API
54+
55+
```php
56+
$connection = new \Sendy\Api\Connection();
57+
58+
$connection->setClientId('your-client-id')
59+
->setClientSecret('your-client-secret')
60+
->setRedirectUrl('your-callback-url');
61+
62+
// Either an authorization code or a refresh token is required to fetch an access token
63+
$connection->setAuthorizationCode('authorization-code');
64+
$connection->setRefreshToken('refresh-token');
65+
66+
// Optional if you have alreay stored the access token in your application
67+
$connection->setAccessToken('access-token');
68+
$connection->setTokenExpires(1123581321);
69+
70+
$connection->me->get();
71+
72+
// Store the access token, refresh token en the expiration timestamp in your application to prevent unnecessary
73+
// requesting new access tokens
74+
$connection->getAccessToken();
75+
$connection->getRefreshToken();
76+
$connection->getTokenExpires();
77+
```
78+
79+
##### Token refresh callback
80+
It is possible to provide the connection a `callable` to execute when the tokens are refresh. This can be useful when
81+
you want to store the new tokens in your application to reuse them when necessary.
82+
83+
```php
84+
$connection = new \Sendy\Api\Connection();
85+
86+
$connection->setOauthClient(true);
87+
88+
$connection->setClientId('your-client-id')
89+
->setClientSecret('your-client-secret')
90+
->setRedirectUrl('your-callback-url');
91+
92+
$tokenUpdateCallback = function (\Sendy\Api\Connection $connection) {
93+
$data = [
94+
'access_token' => $connection->getAccessToken(),
95+
'refresh_token' => $connection->getRefreshToken(),
96+
'token_expires' => $connection->getTokenExpires(),
97+
];
98+
99+
// Use this data to store the tokens in your application
100+
};
101+
```
102+
103+
### Endpoints
104+
105+
The endpoints in the API documentation are mapped to the resource as defined in the Resources directory. Please consult
106+
the [API documentation](https://app.sendy.nl/api/docs) for detailed documentation.
107+
108+
## Contributing
109+
110+
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
111+
112+
### Security
113+
114+
If you've found a bug regarding security please mail [email protected] instead of using the issue tracker.
115+
116+
## License
117+
118+
The MIT License (MIT). Please see the [License file](LICENSE) for more information

composer.json

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"name": "sendynl/php-sdk",
3+
"type": "library",
4+
"description": "A PHP Client for the Sendy API",
5+
"keywords": [
6+
"api",
7+
"php",
8+
"sendy"
9+
],
10+
"homepage": "https://sendy.nl",
11+
"license": "MIT",
12+
"authors": [
13+
{
14+
"name": "Sendy",
15+
"email": "[email protected]"
16+
}
17+
],
18+
"autoload": {
19+
"psr-4": {
20+
"Sendy\\Api\\": "src/"
21+
}
22+
},
23+
"autoload-dev": {
24+
"psr-4": {
25+
"Sendy\\Api\\Tests\\": "tests/"
26+
}
27+
},
28+
"require": {
29+
"php": ">=7.4.0",
30+
"ext-json": "*",
31+
"guzzlehttp/guzzle": "~6.0|~7.0"
32+
},
33+
"config": {
34+
"platform": {
35+
"php": "7.4.0"
36+
}
37+
},
38+
"require-dev": {
39+
"phpunit/phpunit": "^9.0",
40+
"phpstan/phpstan": "^1.10",
41+
"squizlabs/php_codesniffer": "^3.7",
42+
"mockery/mockery": "^1.5"
43+
},
44+
"scripts": {
45+
"lint": "vendor/bin/phpcs",
46+
"analyze": "vendor/bin/phpstan --xdebug",
47+
"test": "vendor/bin/phpunit"
48+
}
49+
}

0 commit comments

Comments
 (0)