|
17 | 17 | /**
|
18 | 18 | * Class NewsletterRecipient
|
19 | 19 | *
|
| 20 | + * @method NewsletterRecipient setId($id) |
20 | 21 | * @method NewsletterRecipient setListId($listId)
|
21 | 22 | * @method NewsletterRecipient setEmail($email)
|
22 | 23 | * @method NewsletterRecipient setPhone($phone)
|
@@ -63,7 +64,7 @@ class NewsletterRecipient extends AbstractModel implements ModelDeletableInterfa
|
63 | 64 | * @param GetParameters $getParams
|
64 | 65 | * @param ApiCredentials $credentials
|
65 | 66 | *
|
66 |
| - * @return \Psr\Http\Message\ResponseInterface |
| 67 | + * @return Collection|null |
67 | 68 | */
|
68 | 69 | public static function findByListAndGroup(
|
69 | 70 | $lid,
|
@@ -110,19 +111,58 @@ public static function findByList($lid, GetParameters $getParams = null, ApiCred
|
110 | 111 | }
|
111 | 112 |
|
112 | 113 |
|
| 114 | + /** |
| 115 | + * Add this recipient to a particular group |
| 116 | + * |
| 117 | + * @param string $gid The group id |
| 118 | + */ |
| 119 | + public function addToGroup($gid) |
| 120 | + { |
| 121 | + $endpoint = $this->api->fillEndpointWithParams( |
| 122 | + '/lists/%s/groups/%s/recipients/%s', |
| 123 | + [$this->getListId(), $gid, $this->getId()] |
| 124 | + ); |
| 125 | + |
| 126 | + $this->api |
| 127 | + ->getHttpClient() |
| 128 | + ->post($endpoint); |
| 129 | + } |
| 130 | + |
| 131 | + |
| 132 | + /** |
| 133 | + * Remove this recipient from a particular group |
| 134 | + * |
| 135 | + * @param string $gid The group id |
| 136 | + */ |
| 137 | + public function removeFromGroup($gid) |
| 138 | + { |
| 139 | + $endpoint = $this->api->fillEndpointWithParams( |
| 140 | + '/lists/%s/groups/%s/recipients/%s', |
| 141 | + [$this->getListId(), $gid, $this->getId()] |
| 142 | + ); |
| 143 | + |
| 144 | + $this->api |
| 145 | + ->getHttpClient() |
| 146 | + ->delete($endpoint); |
| 147 | + } |
| 148 | + |
| 149 | + |
113 | 150 | /**
|
114 | 151 | * {@inheritdoc}
|
115 | 152 | */
|
116 | 153 | public function save()
|
117 | 154 | {
|
118 |
| - $this->api->getHttpClient() |
| 155 | + $response = $this->api->getHttpClient() |
119 | 156 | ->post(
|
120 | 157 | '/recipients',
|
121 | 158 | [
|
122 | 159 | 'json' => $this,
|
123 | 160 | ]
|
124 | 161 | );
|
125 | 162 |
|
| 163 | + $json = \GuzzleHttp\json_decode($response->getBody()->getContents()); |
| 164 | + $this->setId($json->value->id); |
| 165 | + |
126 | 166 | return $this;
|
127 | 167 | }
|
128 | 168 |
|
|
0 commit comments