|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Mailxpert\Request; |
|
4
|
|
|
|
|
5
|
|
|
use Mailxpert\Exceptions\MailxpertSDKResponseException; |
|
6
|
|
|
use Mailxpert\Mailxpert; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class ContactsRequest |
|
10
|
|
|
* @package Mailxpert\Request |
|
11
|
|
|
*/ |
|
12
|
|
|
class ContactsRequest |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @param Mailxpert $mailxpert |
|
16
|
|
|
* @param array $params |
|
17
|
|
|
* |
|
18
|
|
|
* @return \Mailxpert\MailxpertResponse |
|
19
|
|
|
* @throws MailxpertSDKResponseException |
|
20
|
|
|
*/ |
|
21
|
|
|
public static function get(Mailxpert $mailxpert, array $params = []) |
|
22
|
|
|
{ |
|
23
|
|
|
$response = $mailxpert->sendRequest('GET', 'contacts', $params); |
|
24
|
|
|
|
|
25
|
|
|
if (!$response->isHttpResponseCodeOK()) { |
|
26
|
|
|
throw new MailxpertSDKResponseException($response, 'An error occured during receiving Contacts.'); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
return $response; |
|
30
|
|
|
} |
|
31
|
|
|
/** |
|
32
|
|
|
* @param Mailxpert $mailxpert |
|
33
|
|
|
* @param int $id |
|
34
|
|
|
* @param array $params |
|
35
|
|
|
* |
|
36
|
|
|
* @return \Mailxpert\MailxpertResponse |
|
37
|
|
|
* @throws MailxpertSDKResponseException |
|
38
|
|
|
*/ |
|
39
|
|
|
public static function getOne(Mailxpert $mailxpert, $id, array $params = []) |
|
40
|
|
|
{ |
|
41
|
|
|
$response = $mailxpert->sendRequest('GET', sprintf('contacts/%d', $id), $params); |
|
42
|
|
|
|
|
43
|
|
|
if (!$response->isHttpResponseCodeOK()) { |
|
44
|
|
|
throw new MailxpertSDKResponseException($response, 'An error occured during receiving Contacts.'); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
return $response; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @param Mailxpert $mailxpert |
|
52
|
|
|
* @param array $params |
|
53
|
|
|
* |
|
54
|
|
|
* @return \Mailxpert\MailxpertResponse |
|
55
|
|
|
* @throws MailxpertSDKResponseException |
|
56
|
|
|
*/ |
|
57
|
|
|
public static function post(Mailxpert $mailxpert, array $params) |
|
58
|
|
|
{ |
|
59
|
|
|
$response = $mailxpert->sendRequest('POST', 'contacts', [], null, json_encode($params)); |
|
60
|
|
|
|
|
61
|
|
|
if (!$response->isHttpResponseCodeOK()) { |
|
62
|
|
|
throw new MailxpertSDKResponseException($response, 'An error occured during the Contact creation.'); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
return $response; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @param Mailxpert $mailxpert |
|
70
|
|
|
* @param int $id |
|
71
|
|
|
* |
|
72
|
|
|
* @return \Mailxpert\MailxpertResponse |
|
73
|
|
|
* @throws MailxpertSDKResponseException |
|
74
|
|
|
*/ |
|
75
|
|
|
public static function subscribe(Mailxpert $mailxpert, $id) |
|
76
|
|
|
{ |
|
77
|
|
|
$response = $mailxpert->sendRequest('PATCH', sprintf('contacts/%d/subscribe', $id)); |
|
78
|
|
|
|
|
79
|
|
|
if (!$response->isHttpResponseCodeOK()) { |
|
80
|
|
|
throw new MailxpertSDKResponseException($response, 'An error occured during the Contact creation.'); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
return $response; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @param Mailxpert $mailxpert |
|
88
|
|
|
* @param string $id |
|
89
|
|
|
* @param array $params |
|
90
|
|
|
* |
|
91
|
|
|
* @return \Mailxpert\MailxpertResponse |
|
92
|
|
|
* @throws MailxpertSDKResponseException |
|
93
|
|
|
*/ |
|
94
|
|
|
public static function patch(Mailxpert $mailxpert, $id, array $params) |
|
95
|
|
|
{ |
|
96
|
|
|
$response = $mailxpert->sendRequest('PATCH', sprintf('contacts/%s', $id), [], null, json_encode($params)); |
|
97
|
|
|
|
|
98
|
|
|
if (!$response->isHttpResponseCodeOK()) { |
|
99
|
|
|
throw new MailxpertSDKResponseException($response, 'An error occured during updating the Contact.'); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
return $response; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @param Mailxpert $mailxpert |
|
107
|
|
|
* @param string $id |
|
108
|
|
|
* |
|
109
|
|
|
* @return \Mailxpert\MailxpertResponse |
|
110
|
|
|
* @throws MailxpertSDKResponseException |
|
111
|
|
|
*/ |
|
112
|
|
|
public static function delete(Mailxpert $mailxpert, $id) |
|
113
|
|
|
{ |
|
114
|
|
|
$response = $mailxpert->sendRequest('DELETE', sprintf('contacts/%s', $id)); |
|
115
|
|
|
|
|
116
|
|
|
if (!$response->isHttpResponseCodeOK()) { |
|
117
|
|
|
throw new MailxpertSDKResponseException($response, 'An error occured during the Contact deletion.'); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
return $response; |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|