1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Integracao\ControlPay\API; |
4
|
|
|
|
5
|
|
|
use GuzzleHttp\Exception\RequestException; |
6
|
|
|
use Integracao\ControlPay\AbstractAPI; |
7
|
|
|
use Integracao\ControlPay\Client; |
8
|
|
|
use Integracao\ControlPay\Helpers\SerializerHelper; |
9
|
|
|
use Integracao\ControlPay\Contracts; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class TerminalApi |
13
|
|
|
* @package Integracao\ControlPay\API |
14
|
|
|
*/ |
15
|
|
|
class TerminalApi extends AbstractAPI |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* TerminalApi constructor. |
20
|
|
|
*/ |
21
|
|
|
public function __construct(Client $client = null) |
22
|
|
|
{ |
23
|
|
|
parent::__construct('terminal', $client); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param integer $pessoaId |
28
|
|
|
* @return Contracts\Terminal\GetByPessoaIdResponse |
29
|
|
|
* @throws \Exception |
30
|
|
|
*/ |
31
|
|
View Code Duplication |
public function getByPessoaId($pessoaId) |
|
|
|
|
32
|
|
|
{ |
33
|
|
|
try{ |
34
|
|
|
$this->response = $this->_httpClient->post(__FUNCTION__,[ |
35
|
|
|
'query' => $this->addQueryAdditionalParameters([ |
36
|
|
|
'pessoaId' => $pessoaId |
37
|
|
|
]) |
38
|
|
|
]); |
39
|
|
|
|
40
|
|
|
return SerializerHelper::denormalize( |
41
|
|
|
$this->response->json(), |
42
|
|
|
Contracts\Terminal\GetByPessoaIdResponse::class |
43
|
|
|
); |
44
|
|
|
}catch (RequestException $ex) { |
45
|
|
|
$this->requestException($ex); |
46
|
|
|
}catch (\Exception $ex){ |
47
|
|
|
throw new \Exception($ex->getMessage(), $ex->getCode(), $ex); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param integer $terminalId |
53
|
|
|
* @return Contracts\Terminal\GetByIdResponse |
54
|
|
|
* @throws \Exception |
55
|
|
|
*/ |
56
|
|
View Code Duplication |
public function getById($terminalId) |
|
|
|
|
57
|
|
|
{ |
58
|
|
|
try{ |
59
|
|
|
$this->response = $this->_httpClient->post(__FUNCTION__,[ |
60
|
|
|
'query' => $this->addQueryAdditionalParameters([ |
61
|
|
|
'terminalId' => $terminalId |
62
|
|
|
]) |
63
|
|
|
]); |
64
|
|
|
|
65
|
|
|
return SerializerHelper::denormalize( |
66
|
|
|
$this->response->json(), |
67
|
|
|
Contracts\Terminal\GetByIdResponse::class |
68
|
|
|
); |
69
|
|
|
}catch (RequestException $ex) { |
70
|
|
|
$this->requestException($ex); |
71
|
|
|
}catch (\Exception $ex){ |
72
|
|
|
throw new \Exception($ex->getMessage(), $ex->getCode(), $ex); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @param Contracts\Terminal\InsertRequest $insertRequest |
78
|
|
|
* @return Contracts\Terminal\GetByIdResponse |
79
|
|
|
* @throws \Exception |
80
|
|
|
*/ |
81
|
|
View Code Duplication |
public function insert(Contracts\Terminal\InsertRequest $insertRequest) |
|
|
|
|
82
|
|
|
{ |
83
|
|
|
try{ |
84
|
|
|
$this->response = $this->_httpClient->post(__FUNCTION__,[ |
85
|
|
|
'body' => json_encode($insertRequest) |
86
|
|
|
]); |
87
|
|
|
|
88
|
|
|
return SerializerHelper::denormalize( |
89
|
|
|
$this->response->json(), |
90
|
|
|
Contracts\Terminal\InsertResponse::class |
91
|
|
|
); |
92
|
|
|
}catch (RequestException $ex) { |
93
|
|
|
$this->requestException($ex); |
94
|
|
|
}catch (\Exception $ex){ |
95
|
|
|
throw new \Exception($ex->getMessage(), $ex->getCode(), $ex); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.