Skip to content

Commit 28fc522

Browse files
author
Laurynas Griciunas
committed
PR changes
1 parent 8a6f3bb commit 28fc522

File tree

15 files changed

+142
-170
lines changed

15 files changed

+142
-170
lines changed

src/Paysera/Bundle/CodeGeneratorBundle/Service/BodyResolver.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,11 @@ public function isIterableResponse(Method $method, ApiDefinition $api)
106106

107107
private function getSuccessfulResponse(Method $method): ?Response
108108
{
109-
if ($method->getResponse(StatusCodeInterface::STATUS_OK) !== null) {
110-
return ($method->getResponse(StatusCodeInterface::STATUS_OK));
111-
}
112-
113-
if ($method->getResponse(StatusCodeInterface::STATUS_ACCEPTED) !== null) {
114-
return ($method->getResponse(StatusCodeInterface::STATUS_ACCEPTED));
109+
foreach ($method->getResponses() as $response) {
110+
$statusCode = $response->getStatusCode();
111+
if (in_array($statusCode, [200, 202], true)) {
112+
return $method->getResponse($statusCode);
113+
}
115114
}
116115

117116
return null;

tests/PhpGeneratorBundle/RestClient/Fixtures/expected/transfer-surveillance-assistant/README.md renamed to tests/PhpGeneratorBundle/RestClient/Fixtures/expected/sky-net/README.md

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11

2-
## vendor-transfer-surveillance-assistant-client
2+
## vendor-sky-net-client
33

4-
Provides methods to manipulate `TransferSurveillanceAssistantClient` API.
4+
Provides methods to manipulate `SkyNetClient` API.
55
It automatically authenticates all requests and maps required data structure for you.
66

77
#### Usage
88

99
This library provides `ClientFactory` class, which you should use to get the API client itself:
1010

1111
```php
12-
use Paysera\Test\TransferSurveillanceAssistantClient\ClientFactory;
12+
use Paysera\Test\SkyNetClient\ClientFactory;
1313

1414
$clientFactory = new ClientFactory([
15-
'base_url' => 'http://example.com/transfer-surveillance-assistant/rest/v1/', // optional, in case you need a custom one.
15+
'base_url' => 'http://example.com/sky-net/rest/v1/', // optional, in case you need a custom one.
1616
'mac' => [ // use this, if API requires Mac authentication.
1717
'mac_id' => 'my-mac-id',
1818
'mac_secret' => 'my-mac-secret',
@@ -30,36 +30,40 @@ $clientFactory = new ClientFactory([
3030
// other configuration options, if needed
3131
]);
3232

33-
$transferSurveillanceAssistantClient = $clientFactory->getTransferSurveillanceAssistantClient();
33+
$skyNetClient = $clientFactory->getSkyNetClient();
3434
```
3535

3636
Please use only one authentication mechanism, provided by `Vendor`.
3737

38-
Now, that you have instance of `TransferSurveillanceAssistantClient`, you can use following methods
38+
Now, that you have instance of `SkyNetClient`, you can use following methods
3939
### Methods
4040

4141

42-
Submit a new analysis task for processing
42+
Set the target of termination
4343

4444

4545
```php
46-
use Paysera\Test\TransferSurveillanceAssistantClient\Entity as Entities;
46+
use Paysera\Test\SkyNetClient\Entity as Entities;
4747

48-
$analysisTaskInput = new Entities\AnalysisTaskInput();
48+
$terminationInput = new Entities\TerminationInput();
4949

50-
$analysisTaskInput->setReferenceId($referenceId);
51-
$analysisTaskInput->setReferenceType($referenceType);
50+
$terminationInput->setTargetName($targetName);
5251

53-
$result = $transferSurveillanceAssistantClient->createAnalysisTask($analysisTaskInput);
52+
$result = $skyNetClient->createTermination($terminationInput);
5453
```
5554
---
5655

57-
I am not a real endpoint
56+
Change the target of termination
5857

5958

6059
```php
60+
use Paysera\Test\SkyNetClient\Entity as Entities;
6161

62-
$transferSurveillanceAssistantClient->updateAnalysisTask();
62+
$terminationInput = new Entities\TerminationInput();
63+
64+
$terminationInput->setTargetName($targetName);
65+
66+
$skyNetClient->updateTermination($terminationInput);
6367
```
6468
---
6569

tests/PhpGeneratorBundle/RestClient/Fixtures/expected/transfer-surveillance-assistant/composer.json renamed to tests/PhpGeneratorBundle/RestClient/Fixtures/expected/sky-net/composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"name": "vendor/lib-transfer-surveillance-assistant-client",
3-
"description": "TransferSurveillanceAssistantClient",
2+
"name": "vendor/lib-sky-net-client",
3+
"description": "SkyNetClient",
44
"version": "1.0",
55
"autoload": {
66
"psr-4": {
7-
"Paysera\\Test\\TransferSurveillanceAssistantClient\\": "src"
7+
"Paysera\\Test\\SkyNetClient\\": "src"
88
}
99
},
1010
"require": {

tests/PhpGeneratorBundle/RestClient/Fixtures/expected/transfer-surveillance-assistant/src/ClientFactory.php renamed to tests/PhpGeneratorBundle/RestClient/Fixtures/expected/sky-net/src/ClientFactory.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?php
22

3-
namespace Paysera\Test\TransferSurveillanceAssistantClient;
3+
namespace Paysera\Test\SkyNetClient;
44

55
use Paysera\Component\RestClientCommon\Util\ClientFactoryAbstract;
66
use Paysera\Component\RestClientCommon\Client\ApiClient;
77

88
class ClientFactory extends ClientFactoryAbstract
99
{
10-
const DEFAULT_BASE_URL = 'http://example.com/transfer-surveillance-assistant/rest/v1/';
10+
const DEFAULT_BASE_URL = 'http://example.com/sky-net/rest/v1/';
1111

1212
protected $apiClient;
1313

@@ -24,9 +24,9 @@ public function __construct($options)
2424
$this->apiClient = $this->createApiClient($options);
2525
}
2626

27-
public function getTransferSurveillanceAssistantClient()
27+
public function getSkyNetClient()
2828
{
29-
return new TransferSurveillanceAssistantClient($this->apiClient);
29+
return new SkyNetClient($this->apiClient);
3030
}
3131

3232
private function resolveDefaultUrlParameters(array $defaults, array $options)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Paysera\Test\SkyNetClient\Entity;
4+
5+
use Paysera\Component\RestClientCommon\Entity\Entity;
6+
7+
class TerminationInput extends Entity
8+
{
9+
public function __construct(array $data = [])
10+
{
11+
parent::__construct($data);
12+
}
13+
14+
/**
15+
* @return string
16+
*/
17+
public function getTargetName()
18+
{
19+
return $this->get('target_name');
20+
}
21+
/**
22+
* @param string $targetName
23+
* @return $this
24+
*/
25+
public function setTargetName($targetName)
26+
{
27+
$this->set('target_name', $targetName);
28+
return $this;
29+
}
30+
}

tests/PhpGeneratorBundle/RestClient/Fixtures/expected/transfer-surveillance-assistant/src/Entity/AnalysisTaskOutput.php renamed to tests/PhpGeneratorBundle/RestClient/Fixtures/expected/sky-net/src/Entity/TerminationOutput.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
22

3-
namespace Paysera\Test\TransferSurveillanceAssistantClient\Entity;
3+
namespace Paysera\Test\SkyNetClient\Entity;
44

55
use Paysera\Component\RestClientCommon\Entity\Entity;
66

7-
class AnalysisTaskOutput extends Entity
7+
class TerminationOutput extends Entity
88
{
99
const REFERENCE_TYPE_INFORMATION_REQUEST = 'information_request';
1010
const STATUS_ACCEPTED = 'accepted';

tests/PhpGeneratorBundle/RestClient/Fixtures/expected/transfer-surveillance-assistant/src/TransferSurveillanceAssistantClient.php renamed to tests/PhpGeneratorBundle/RestClient/Fixtures/expected/sky-net/src/SkyNetClient.php

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?php
22

3-
namespace Paysera\Test\TransferSurveillanceAssistantClient;
3+
namespace Paysera\Test\SkyNetClient;
44

5-
use Paysera\Test\TransferSurveillanceAssistantClient\Entity as Entities;
5+
use Paysera\Test\SkyNetClient\Entity as Entities;
66
use Fig\Http\Message\RequestMethodInterface;
77
use Paysera\Component\RestClientCommon\Entity\Entity;
88
use Paysera\Component\RestClientCommon\Client\ApiClient;
99

10-
class TransferSurveillanceAssistantClient
10+
class SkyNetClient
1111
{
1212
private $apiClient;
1313

@@ -18,40 +18,41 @@ public function __construct(ApiClient $apiClient)
1818

1919
public function withOptions(array $options)
2020
{
21-
return new TransferSurveillanceAssistantClient($this->apiClient->withOptions($options));
21+
return new SkyNetClient($this->apiClient->withOptions($options));
2222
}
2323

2424
/**
25-
* Submit a new analysis task for processing
26-
* POST /analysis-tasks
25+
* Set the target of termination
26+
* POST /termination
2727
*
28-
* @param Entities\AnalysisTaskInput $analysisTaskInput
29-
* @return Entities\AnalysisTaskOutput
28+
* @param Entities\TerminationInput $terminationInput
29+
* @return Entities\TerminationOutput
3030
*/
31-
public function createAnalysisTask(Entities\AnalysisTaskInput $analysisTaskInput)
31+
public function createTermination(Entities\TerminationInput $terminationInput)
3232
{
3333
$request = $this->apiClient->createRequest(
3434
RequestMethodInterface::METHOD_POST,
35-
'analysis-tasks',
36-
$analysisTaskInput
35+
'termination',
36+
$terminationInput
3737
);
3838
$data = $this->apiClient->makeRequest($request);
3939

40-
return new Entities\AnalysisTaskOutput($data);
40+
return new Entities\TerminationOutput($data);
4141
}
4242

4343
/**
44-
* I am not a real endpoint
45-
* PUT /analysis-tasks
44+
* Change the target of termination
45+
* PUT /termination
4646
*
47+
* @param Entities\TerminationInput $terminationInput
4748
* @return null
4849
*/
49-
public function updateAnalysisTask()
50+
public function updateTermination(Entities\TerminationInput $terminationInput)
5051
{
5152
$request = $this->apiClient->createRequest(
5253
RequestMethodInterface::METHOD_PUT,
53-
'analysis-tasks',
54-
null
54+
'termination',
55+
$terminationInput
5556
);
5657
$data = $this->apiClient->makeRequest($request);
5758

tests/PhpGeneratorBundle/RestClient/Fixtures/expected/transfer-surveillance-assistant/src/Entity/AnalysisTaskInput.php

Lines changed: 0 additions & 48 deletions
This file was deleted.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#%RAML 1.0
2+
title: Sky-Net
3+
version: "1.0"
4+
baseUri: http://example.com/sky-net/rest/v1/
5+
protocols: [HTTP]
6+
7+
uses:
8+
Paysera: ../__library/rest.raml
9+
10+
types:
11+
TerminationInput: !include types/termination-input.raml
12+
TerminationOutput: !include types/termination-output.raml
13+
14+
/termination:
15+
post:
16+
description: Set the target of termination
17+
body:
18+
application/json:
19+
type: TerminationInput
20+
responses:
21+
202:
22+
body:
23+
application/json:
24+
type: TerminationOutput
25+
put:
26+
description: Change the target of termination
27+
body:
28+
application/json:
29+
type: TerminationInput
30+
responses:
31+
202:
32+
body: null
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#%RAML 1.0 DataType
2+
displayName: Termination Input
3+
type: object
4+
properties:
5+
target_name:
6+
type: string
7+
required: true

0 commit comments

Comments
 (0)