Skip to content

Commit 689daf3

Browse files
committed
First commit
0 parents  commit 689daf3

File tree

1,724 files changed

+95252
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,724 files changed

+95252
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/.test
2+
/.idea
3+
/vendor

.idea/.gitignore

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/api-sdk-php.iml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/php.xml

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License
2+
3+
Copyright (c) 2024 Shoptet, a.s. (https://www.shoptet.cz/)
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
13+
all 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
21+
THE SOFTWARE.

README.md

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
# Shoptet API SDK PHP
2+
3+
The official PHP library for the Shoptet REST API.
4+
5+
## Documentation
6+
7+
See the [Shoptet API doc](https://shoptet.docs.apiary.io/#).
8+
9+
## Requirements
10+
11+
- PHP 8.3 and later
12+
13+
## Dependencies
14+
15+
SDK require the following extensions and libraries in order to work properly:
16+
17+
- [`curl`](https://secure.php.net/manual/en/book.curl.php) - _You can use your own non-cURL client if you prefer._
18+
- [`json`](https://secure.php.net/manual/en/book.json.php)
19+
- [`psr/log`](https://www.php-fig.org/psr/psr-3/)
20+
21+
> If you use Composer, these dependencies should be handled automatically.
22+
>
23+
> If you install the library manually, please ensure that these extensions are available.
24+
25+
## Installation
26+
27+
### Composer
28+
29+
You can install the sdk via [Composer](http://getcomposer.org/). Run the following command:
30+
31+
**@todo** Currently not working as it's not public
32+
33+
```bash
34+
composer require shoptet/api-sdk-php
35+
```
36+
37+
To use the sdk, use Composer's [autoload](https://getcomposer.org/doc/01-basic-usage.md#autoloading):
38+
39+
```php
40+
require_once 'vendor/autoload.php';
41+
```
42+
43+
### Manual
44+
45+
```php
46+
require_once '/path/to/api-sdk-php/init.php';
47+
```
48+
49+
## Getting Started
50+
51+
### Simple usage
52+
53+
#### Call endpoint with request body
54+
```php
55+
\Shoptet\Api\Sdk\Php\Sdk::setAccessToken('ENTER_SHOPTET_ACCESS_TOKEN');
56+
57+
$createdBrandResponse = \Shoptet\Api\Sdk\Php\Sdk::createBrand([
58+
'data' => [
59+
'name' => 'Brand name',
60+
'description' => 'Brand description',
61+
'indexName' => 'brand-name',
62+
]
63+
]);
64+
65+
$createdBrandResponse->getBody();
66+
//...
67+
```
68+
69+
> [Read more](docs/request_body_processing_methods.md) about possible methods, how to call endpoints with request body.
70+
71+
#### Paginator
72+
```php
73+
\Shoptet\Api\Sdk\Php\Sdk::setAccessToken('ENTER_SHOPTET_ACCESS_TOKEN');
74+
75+
$listOfProductResponse = \Shoptet\Api\Sdk\Php\Sdk::getListOfProducts();
76+
//... Process response
77+
try {
78+
$listOfProductResponseNextPage = $listOfProductResponse->getNextPage();
79+
} catch (\Shoptet\Api\Sdk\Php\Exception\OutOfRangeException $e) {
80+
//Next page is out of range - Last page already reached
81+
}
82+
```
83+
84+
### Custom header
85+
86+
```php
87+
// Add/remove custom header
88+
\Shoptet\Api\Sdk\Php\Sdk::setHeader('X-MY-AWESOME-HEADER', 'my-awesome-header-value');
89+
\Shoptet\Api\Sdk\Php\Sdk::unsetHeader('X-MY-AWESOME-HEADER');
90+
```
91+
92+
### Custom request timeouts
93+
94+
```php
95+
$httpClient = \Shoptet\Api\Sdk\Php\Sdk::getHttpClient();
96+
97+
/**
98+
* Set connection timeout on 60sec
99+
* Default is 30sec
100+
* @see \Shoptet\Api\Sdk\Php\HttpClient\CurlClient::DEFAULT_TIMEOUT
101+
*/
102+
$httpClient->setTimeout(60);
103+
104+
/**
105+
* Set timeout on 90sec
106+
* Default is 80sec
107+
* @see \Shoptet\Api\Sdk\Php\HttpClient\CurlClient::DEFAULT_CONNECT_TIMEOUT
108+
*/
109+
$httpClient->setConnectTimeout(90);
110+
111+
echo $httpClient->getTimeout(); // 60
112+
echo $httpClient->getConnectTimeout(); // 90
113+
```
114+
115+
### Custom cURL options
116+
117+
You can customize the default CurlClient with extra options.
118+
The keys should be valid `CURLOPT_*` constants or their integer equivalents.
119+
The options will be used in `curl_setopt_array()`.
120+
121+
```php
122+
// Add/remove custom option in HttpClient
123+
\Shoptet\Api\Sdk\Php\Sdk::getHttpClient()
124+
->addOption(CURLOPT_PROXY, 'my-proxy.local:80');
125+
->removeOption(CURLOPT_PROXY);
126+
```
127+
128+
### Response body type
129+
130+
The SDK provides multiple options how to handle response body automatically.
131+
132+
- Return response body as the corresponding `Entity` object
133+
- Factory class: `\Shoptet\Api\Sdk\Php\Factory\Response\EntityResponseFactory`
134+
- Default option
135+
- Return response body as array
136+
- Factory class: `\Shoptet\Api\Sdk\Php\Factory\Response\ArrayResponseFactory`
137+
- Return response body as raw string
138+
- Factory class: `\Shoptet\Api\Sdk\Php\Factory\Response\RawResponseFactory`
139+
140+
```php
141+
echo get_class(\Shoptet\Api\Sdk\Php\Sdk::getEshopInfo()->getBody()); // Shoptet\Api\Sdk\Php\Endpoint\Eshop\GetEshopInfoResponse\GetEshopInfoResponse
142+
143+
// Set response factory to ArrayResponseFactory so the response body will return as array (not the Entity)
144+
\Shoptet\Api\Sdk\Php\Sdk::getHttpClient()->setResponseFactory(new \Shoptet\Api\Sdk\Php\Factory\Response\ArrayResponseFactory());
145+
146+
echo gettype(\Shoptet\Api\Sdk\Php\Sdk::getEshopInfo()->getBody()); // array
147+
```
148+
149+
### Custom HttpClient
150+
151+
If current HttpClient is not sufficient you can implement your own Client.
152+
The client must implement `\Shoptet\Api\Sdk\Php\HttpClient\ClientInterface`.
153+
154+
```php
155+
\Shoptet\Api\Sdk\Php\Sdk::setHttpClient($httpClient);
156+
```
157+
158+
### Logger
159+
160+
The library does minimal logging.
161+
Logging can be configured with a [`PSR-3` compatible logger](https://www.php-fig.org/psr/psr-3/).
162+
Default Logger is the `Psr\Log\NullLogger` - So the logs end up in the void.
163+
164+
```php
165+
\Shoptet\Api\Sdk\Php\Sdk::setLogger($logger);
166+
```
167+
168+
### Exceptions
169+
170+
All exceptions should implement `Shoptet\Api\Sdk\Php\Exception\Exception`.
171+
172+
There are 3 base types of Exceptions:
173+
174+
- `Shoptet\Api\Sdk\Php\Exception\LogicException`
175+
- `Shoptet\Api\Sdk\Php\Exception\RuntimeException`
176+
- `Shoptet\Api\Sdk\Php\Exception\ReflectionException`

build/phpstan.bootstrap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?php

composer.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"name": "shoptet/api-sdk-php",
3+
"description": "Shoptet API SDK PHP",
4+
"keywords": [
5+
"shoptet",
6+
"api",
7+
"sdk",
8+
"php"
9+
],
10+
"homepage": "https://www.shoptet.cz/",
11+
"license": "MIT",
12+
"authors": [
13+
{
14+
"name": "Shoptet and contributors",
15+
"homepage": "https://github.com/shoptet/api-sdk-php/contributors"
16+
}
17+
],
18+
"require": {
19+
"php": "^8.3",
20+
"ext-json": "*",
21+
"ext-curl": "*",
22+
"psr/log": ">=1.0.0"
23+
},
24+
"require-dev": {
25+
"phpstan/phpstan": "1.12.1"
26+
},
27+
"autoload": {
28+
"psr-4": {
29+
"Shoptet\\Api\\Sdk\\Php\\": "src/"
30+
}
31+
},
32+
"scripts": {
33+
"phpstan": "php vendor/phpstan/phpstan/phpstan analyze -v -c phpstan.neon.dist --memory-limit=-1",
34+
"phpstan:clear-cache": "php vendor/phpstan/phpstan/phpstan clear-result-cache -c phpstan.neon.dist"
35+
},
36+
"scripts-descriptions": {
37+
"phpstan": "Run PHPStan",
38+
"phpstan:clear-cache": "Clear PHPStan result cache"
39+
}
40+
}

0 commit comments

Comments
 (0)