Skip to content

Commit 62081b7

Browse files
committed
Add removeFromGroup and addToGroup
1 parent fa806a4 commit 62081b7

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

src/Newsletter2Go/Api/Model/NewsletterRecipient.php

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
/**
1818
* Class NewsletterRecipient
1919
*
20+
* @method NewsletterRecipient setId($id)
2021
* @method NewsletterRecipient setListId($listId)
2122
* @method NewsletterRecipient setEmail($email)
2223
* @method NewsletterRecipient setPhone($phone)
@@ -63,7 +64,7 @@ class NewsletterRecipient extends AbstractModel implements ModelDeletableInterfa
6364
* @param GetParameters $getParams
6465
* @param ApiCredentials $credentials
6566
*
66-
* @return \Psr\Http\Message\ResponseInterface
67+
* @return Collection|null
6768
*/
6869
public static function findByListAndGroup(
6970
$lid,
@@ -110,19 +111,58 @@ public static function findByList($lid, GetParameters $getParams = null, ApiCred
110111
}
111112

112113

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+
113150
/**
114151
* {@inheritdoc}
115152
*/
116153
public function save()
117154
{
118-
$this->api->getHttpClient()
155+
$response = $this->api->getHttpClient()
119156
->post(
120157
'/recipients',
121158
[
122159
'json' => $this,
123160
]
124161
);
125162

163+
$json = \GuzzleHttp\json_decode($response->getBody()->getContents());
164+
$this->setId($json->value->id);
165+
126166
return $this;
127167
}
128168

0 commit comments

Comments
 (0)