1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dekalee\MailjetBundle\Client; |
4
|
|
|
|
5
|
|
|
use Mailjet\Client; |
6
|
|
|
use Mailjet\Response; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class DekaleeClient |
10
|
|
|
*/ |
11
|
|
|
class DekaleeClient extends Client |
12
|
|
|
{ |
13
|
|
|
protected $calls = []; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Trigger a POST request |
17
|
|
|
* |
18
|
|
|
* @param array $resource Mailjet Resource/Action pair |
19
|
|
|
* @param array $args Request arguments |
20
|
|
|
* |
21
|
|
|
* @return Response |
22
|
|
|
*/ |
23
|
|
View Code Duplication |
public function post($resource, $args = []) |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
$response = parent::post($resource, $args); |
26
|
|
|
|
27
|
|
|
$this->calls[] = [ |
28
|
|
|
'method' => 'POST', |
29
|
|
|
'resource' => $resource, |
30
|
|
|
'args' => $args, |
31
|
|
|
'success' => $response->success(), |
32
|
|
|
'response' => $response->getBody(), |
33
|
|
|
]; |
34
|
|
|
|
35
|
|
|
return $response; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Trigger a GET request |
40
|
|
|
* |
41
|
|
|
* @param array $resource Mailjet Resource/Action pair |
42
|
|
|
* @param array $args Request arguments |
43
|
|
|
* |
44
|
|
|
* @return Response |
45
|
|
|
*/ |
46
|
|
View Code Duplication |
public function get($resource, $args = []) |
|
|
|
|
47
|
|
|
{ |
48
|
|
|
$response = parent::get($resource, $args); |
49
|
|
|
|
50
|
|
|
$this->calls[] = [ |
51
|
|
|
'method' => 'GET', |
52
|
|
|
'resource' => $resource, |
53
|
|
|
'args' => $args, |
54
|
|
|
'success' => $response->success(), |
55
|
|
|
'response' => $response->getBody(), |
56
|
|
|
]; |
57
|
|
|
|
58
|
|
|
return $response; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Trigger a POST request |
63
|
|
|
* |
64
|
|
|
* @param array $resource Mailjet Resource/Action pair |
65
|
|
|
* @param array $args Request arguments |
66
|
|
|
* |
67
|
|
|
* @return Response |
68
|
|
|
*/ |
69
|
|
View Code Duplication |
public function put($resource, $args = []) |
|
|
|
|
70
|
|
|
{ |
71
|
|
|
$response = parent::put($resource, $args); |
72
|
|
|
|
73
|
|
|
$this->calls[] = [ |
74
|
|
|
'method' => 'PUT', |
75
|
|
|
'resource' => $resource, |
76
|
|
|
'args' => $args, |
77
|
|
|
'success' => $response->success(), |
78
|
|
|
'response' => $response->getBody(), |
79
|
|
|
]; |
80
|
|
|
|
81
|
|
|
return $resource; |
|
|
|
|
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Trigger a GET request |
86
|
|
|
* |
87
|
|
|
* @param array $resource Mailjet Resource/Action pair |
88
|
|
|
* @param array $args Request arguments |
89
|
|
|
* |
90
|
|
|
* @return Response |
91
|
|
|
*/ |
92
|
|
View Code Duplication |
public function delete($resource, $args = []) |
|
|
|
|
93
|
|
|
{ |
94
|
|
|
$response = parent::delete($resource, $args); |
95
|
|
|
|
96
|
|
|
$this->calls[] = [ |
97
|
|
|
'method' => 'DELETE', |
98
|
|
|
'resource' => $resource, |
99
|
|
|
'args' => $args, |
100
|
|
|
'success' => $response->success(), |
101
|
|
|
'response' => $response->getBody(), |
102
|
|
|
]; |
103
|
|
|
|
104
|
|
|
return $response; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @return array |
109
|
|
|
*/ |
110
|
|
|
public function getCalls() |
111
|
|
|
{ |
112
|
|
|
return $this->calls; |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|
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.