1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Date: 21/08/15 |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace Mailxpert\Request; |
7
|
|
|
|
8
|
|
|
use Mailxpert\Exceptions\MailxpertSDKException; |
9
|
|
|
use Mailxpert\Exceptions\MailxpertSDKResponseException; |
10
|
|
|
use Mailxpert\Mailxpert; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class CustomFieldsRequest |
14
|
|
|
* @package Mailxpert\Request |
15
|
|
|
*/ |
16
|
|
View Code Duplication |
class CustomFieldsRequest |
|
|
|
|
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @param Mailxpert $mailxpert |
20
|
|
|
* @param array $params |
21
|
|
|
* |
22
|
|
|
* @return \Mailxpert\MailxpertResponse |
23
|
|
|
* @throws MailxpertSDKResponseException |
24
|
|
|
*/ |
25
|
|
|
public static function get(Mailxpert $mailxpert, array $params = []) |
26
|
|
|
{ |
27
|
|
|
$response = $mailxpert->sendRequest('GET', 'custom_fields', $params); |
28
|
|
|
|
29
|
|
|
if (!$response->isHttpResponseCodeOK()) { |
30
|
|
|
throw new MailxpertSDKResponseException($response, 'An error occured during the Custom field fetching.'); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
return $response; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param Mailxpert $mailxpert |
38
|
|
|
* @param array $params |
39
|
|
|
* |
40
|
|
|
* @return \Mailxpert\MailxpertResponse |
41
|
|
|
* @throws MailxpertSDKResponseException |
42
|
|
|
*/ |
43
|
|
|
public static function post(Mailxpert $mailxpert, array $params) |
44
|
|
|
{ |
45
|
|
|
$response = $mailxpert->sendRequest('POST', 'custom_fields', [], null, json_encode($params)); |
46
|
|
|
|
47
|
|
|
if (!$response->getHeader('Location')) { |
|
|
|
|
48
|
|
|
throw new MailxpertSDKResponseException($response, 'An error occured during the Custom field creation.'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return $response; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param Mailxpert $mailxpert |
56
|
|
|
* @param string $id |
57
|
|
|
* @param array $params |
58
|
|
|
* |
59
|
|
|
* @return \Mailxpert\MailxpertResponse |
60
|
|
|
* @throws MailxpertSDKResponseException |
61
|
|
|
*/ |
62
|
|
|
public static function patch(Mailxpert $mailxpert, $id, array $params) |
63
|
|
|
{ |
64
|
|
|
$response = $mailxpert->sendRequest('PATCH', sprintf('custom_fields/%s', $id), [], null, json_encode($params)); |
65
|
|
|
|
66
|
|
|
if (!$response->isHttpResponseCodeOK()) { |
67
|
|
|
throw new MailxpertSDKResponseException($response, 'An error occured during updating the CustomField.'); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
return $response; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param Mailxpert $mailxpert |
75
|
|
|
* @param string $id |
76
|
|
|
* |
77
|
|
|
* @return \Mailxpert\MailxpertResponse |
78
|
|
|
* @throws MailxpertSDKResponseException |
79
|
|
|
*/ |
80
|
|
|
public static function delete(Mailxpert $mailxpert, $id) |
81
|
|
|
{ |
82
|
|
|
$response = $mailxpert->sendRequest('DELETE', sprintf('custom_fields/%s', $id)); |
83
|
|
|
|
84
|
|
|
if (!$response->isHttpResponseCodeOK()) { |
85
|
|
|
throw new MailxpertSDKResponseException($response, 'An error occured during the CustomField deletion.'); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return $response; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
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.