Skip to content

Commit b1cc656

Browse files
committed
Add support for fetching a list of conversations for a specific user
1 parent 906240c commit b1cc656

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/Conversations/Collection.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ public function hydrateEntity($data, $idOrConversation)
4949
return $idOrConversation;
5050
}
5151

52+
public function hydrateAll($conversations)
53+
{
54+
$hydrated = [];
55+
foreach ($conversations as $conversation) {
56+
$hydrated[] = $this->hydrateEntity($conversation, $conversation['id']);
57+
}
58+
59+
return $hydrated;
60+
}
61+
5262
/**
5363
* @param null $conversation
5464
* @return $this|Conversation

src/User/User.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
use Nexmo\Client\ClientAwareInterface;
1313
use Nexmo\Client\ClientAwareTrait;
14-
use Nexmo\Conversations\Conversation;
1514
use Nexmo\Entity\EntityInterface;
1615
use Nexmo\Entity\JsonResponseTrait;
1716
use Nexmo\Entity\JsonSerializableTrait;
@@ -71,6 +70,20 @@ public function get()
7170
return $this;
7271
}
7372

73+
public function getConversations() {
74+
$response = $this->getClient()->get(
75+
\Nexmo\Client::BASE_API . Collection::getCollectionPath().'/'.$this->getId().'/conversations'
76+
);
77+
78+
if($response->getStatusCode() != '200'){
79+
throw $this->getException($response);
80+
}
81+
82+
$data = json_decode($response->getBody()->getContents(), true);
83+
$conversationCollection = $this->getClient()->conversation();
84+
85+
return $conversationCollection->hydrateAll($data);
86+
}
7487

7588
public function jsonSerialize()
7689
{

0 commit comments

Comments
 (0)