Skip to content

Commit 6ea9b9d

Browse files
committed
Added client changes endpoint
1 parent 11b68fd commit 6ea9b9d

5 files changed

Lines changed: 158 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Fapi\FapiClient\EndPoints;
4+
5+
use Fapi\FapiClient\Rest\FapiRestClient;
6+
7+
final class ClientChanges
8+
{
9+
10+
/** @var FapiRestClient */
11+
private $client;
12+
13+
/** @var string */
14+
private $path;
15+
16+
/** @var string */
17+
private $resources;
18+
19+
public function __construct(FapiRestClient $client)
20+
{
21+
$this->client = $client;
22+
$this->path = '/client-changes';
23+
$this->resources = 'client_changes';
24+
}
25+
26+
/**
27+
* @param array<mixed> $parameters
28+
* @return array<mixed>|null
29+
*/
30+
public function findAll(int $clientId, array $parameters = []): ?array
31+
{
32+
return $this->client->getResources(
33+
$this->path . '/search',
34+
$this->resources,
35+
['client' => $clientId] + $parameters
36+
);
37+
}
38+
39+
}

src/Fapi/FapiClient/FapiClient.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Fapi\FapiClient;
44

55
use Fapi\FapiClient\EndPoints\ApiTokens;
6+
use Fapi\FapiClient\EndPoints\ClientChanges;
67
use Fapi\FapiClient\EndPoints\Clients;
78
use Fapi\FapiClient\EndPoints\Countries;
89
use Fapi\FapiClient\EndPoints\DiscountCodes;
@@ -127,6 +128,9 @@ class FapiClient implements IFapiClient
127128
/** @var Vouchers */
128129
private $vouchers;
129130

131+
/** @var ClientChanges */
132+
private $clientChanges;
133+
130134
public function __construct(string $username, string $password, string $apiUrl, IHttpClient $httpClient)
131135
{
132136
$this->restClient = new FapiRestClient($username, $password, $apiUrl, $httpClient);
@@ -147,6 +151,7 @@ public function __construct(string $username, string $password, string $apiUrl,
147151
$this->exchangeRates = new ExchangeRates($this->restClient);
148152
$this->userSetting = new UserSettings($this->restClient);
149153
$this->vouchers = new Vouchers($this->restClient);
154+
$this->clientChanges = new ClientChanges($this->restClient);
150155
}
151156

152157
public function checkConnection(): void
@@ -174,6 +179,11 @@ public function getClients(): Clients
174179
return $this->clients;
175180
}
176181

182+
public function getClientChanges(): ClientChanges
183+
{
184+
return $this->clientChanges;
185+
}
186+
177187
public function getCountries(): Countries
178188
{
179189
return $this->countries;

src/Fapi/FapiClient/Rest/FapiRestClientOptions.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class FapiRestClientOptions
66
{
77

88
public const STRING_KEY = 1;
9+
910
public const STRING_RESOURCE = 2;
1011

1112
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Fapi\FapiClientTests;
4+
5+
use Fapi\FapiClient\FapiClient;
6+
use Fapi\HttpClient\CapturingHttpClient;
7+
use Fapi\HttpClient\GuzzleHttpClient;
8+
use Tester\Assert;
9+
use Tester\Environment;
10+
use Tester\TestCase;
11+
use const LOCKS_DIR;
12+
13+
require __DIR__ . '/../../bootstrap.php';
14+
15+
class FapiClientClientChangesTest extends TestCase
16+
{
17+
18+
/** @var CapturingHttpClient */
19+
private $httpClient;
20+
21+
/** @var FapiClient */
22+
private $fapiClient;
23+
24+
protected function setUp(): void
25+
{
26+
Environment::lock('FapiClient', LOCKS_DIR);
27+
28+
$this->httpClient = new CapturingHttpClient(
29+
new GuzzleHttpClient(),
30+
__DIR__ . '/MockHttpClients/FapiClientClientChangesMockHttpClient.php',
31+
'Fapi\FapiClientTests\MockHttpClients\FapiClientClientChangesMockHttpClient'
32+
);
33+
34+
$this->fapiClient = new FapiClient(
35+
'slischka@test-fapi.cz',
36+
'jIBAWlKzzB6rQVk5Y3T0VxTgn',
37+
'https://api.fapi.cz/',
38+
$this->httpClient
39+
);
40+
}
41+
42+
protected function tearDown(): void
43+
{
44+
$this->httpClient->close();
45+
}
46+
47+
public function testFindAll(): void
48+
{
49+
$clientChanges = $this->fapiClient->getClientChanges()->findAll(1810411, ['_action' => 'created']);
50+
51+
Assert::type('array', $clientChanges);
52+
}
53+
54+
}
55+
56+
(new FapiClientClientChangesTest())->run();
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Fapi\FapiClientTests\MockHttpClients;
4+
5+
use Fapi\HttpClient\HttpRequest;
6+
use Fapi\HttpClient\HttpResponse;
7+
use Fapi\HttpClient\MockHttpClient;
8+
9+
final class FapiClientClientChangesMockHttpClient extends MockHttpClient
10+
{
11+
12+
public function __construct()
13+
{
14+
$this->add(
15+
new HttpRequest(
16+
'GET',
17+
'https://api.fapi.cz/client-changes/search?client=1810411&_action=created',
18+
[
19+
'Host' => ['api.fapi.cz'],
20+
'verify' => ['1'],
21+
'Content-Type' => ['application/json'],
22+
'Accept' => ['application/json'],
23+
'Authorization' => ['Basic c2xpc2Noa2FAdGVzdC1mYXBpLmN6OmpJQkFXbEt6ekI2clFWazVZM1QwVnhUZ24='],
24+
],
25+
'',
26+
'1.1'
27+
),
28+
new HttpResponse(
29+
200,
30+
[
31+
'Date' => ['Thu, 18 Nov 2021 15:39:32 GMT'],
32+
'Content-Type' => ['application/json'],
33+
'Transfer-Encoding' => ['chunked'],
34+
'Connection' => ['keep-alive'],
35+
'Server' => ['nginx'],
36+
'Vary' => ['Accept-Encoding'],
37+
'X-Powered-By' => ['Nette Framework 3'],
38+
'X-Frame-Options' => ['SAMEORIGIN', 'sameorigin'],
39+
'Set-Cookie' => ['_nss=1; path=/; HttpOnly; SameSite=Strict'],
40+
'Strict-Transport-Security' => ['max-age=63072000; includeSubDomains; preload'],
41+
'X-Content-Type-Options' => ['nosniff'],
42+
'X-Origin-Instance' => ['web1.prod.fapi.cloud'],
43+
'Access-Control-Allow-Origin' => ['*'],
44+
'Access-Control-Allow-Headers' => ['Origin, X-Requested-With, Content-Type, Accept'],
45+
'x-encoded-content-encoding' => ['gzip'],
46+
],
47+
'{"client_changes":[{"id":14404731,"client":1810411,"action":"created","date":"2020-09-10 10:14:58","changes":null,"user":{"id":5,"username":"admin@fapi.cz"}}]}'
48+
)
49+
);
50+
}
51+
52+
}

0 commit comments

Comments
 (0)