Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions src/Sockudo.php
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,33 @@ public function appendMessage(string $channel, string $messageSerial, array $par
return $this->post('/channels/' . $channel . '/messages/' . $messageSerial . '/append', $params);
}

/**
* Publish an annotation for a versioned message.
*/
public function publishAnnotation(string $channel, string $messageSerial, array $params): object
{
$this->validate_channel($channel);
return $this->post('/channels/' . $channel . '/messages/' . $messageSerial . '/annotations', json_encode($params, JSON_THROW_ON_ERROR));
}

/**
* Delete an annotation from a versioned message.
*/
public function deleteAnnotation(string $channel, string $messageSerial, string $annotationSerial, array $params = []): object
{
$this->validate_channel($channel);
return $this->delete('/channels/' . $channel . '/messages/' . $messageSerial . '/annotations/' . $annotationSerial, $params);
}

/**
* List raw annotation events for a versioned message.
*/
public function listAnnotations(string $channel, string $messageSerial, array $params = []): object
{
$this->validate_channel($channel);
return $this->get('/channels/' . $channel . '/messages/' . $messageSerial . '/annotations', $params);
}

/**
* @deprecated in favour of getPresenceUsers
*/
Expand Down Expand Up @@ -897,6 +924,45 @@ public function get(string $path, array $params = [], $associative = false)
return $body;
}

/**
* DELETE arbitrary REST API resource using a synchronous http client.
* All request signing is handled automatically.
*/
public function delete(string $path, array $params = [], $associative = false)
{
$path = $this->settings['base_path'] . $path;

$signature = $this->sign($path, 'DELETE', $params);

$headers = [
'Content-Type' => 'application/json',
'X-Pusher-Library' => 'sockudo-http-php ' . self::$VERSION,
];

$response = $this->client->delete(ltrim($path, '/'), [
'query' => $signature,
'http_errors' => false,
'headers' => $headers,
'base_uri' => $this->channels_url_prefix(),
'timeout' => $this->settings['timeout'],
]);

$status = $response->getStatusCode();

if ($status !== 200) {
$body = (string) $response->getBody();
throw new ApiErrorException($body, $status);
}

try {
$body = json_decode($response->getBody(), $associative, 512, JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
throw new SockudoException('Data decoding error.');
}

return $body;
}

/**
* POST arbitrary REST API resource using a synchronous http client.
* All request signing is handled automatically.
Expand Down
15 changes: 15 additions & 0 deletions src/SockudoInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,21 @@ public function deleteMessage(string $channel, string $messageSerial, array $par
*/
public function appendMessage(string $channel, string $messageSerial, array $params = []): object;

/**
* Publish an annotation for a versioned message.
*/
public function publishAnnotation(string $channel, string $messageSerial, array $params): object;

/**
* Delete an annotation from a versioned message.
*/
public function deleteAnnotation(string $channel, string $messageSerial, string $annotationSerial, array $params = []): object;

/**
* List raw annotation events for a versioned message.
*/
public function listAnnotations(string $channel, string $messageSerial, array $params = []): object;

/**
* GET arbitrary REST API resource using a synchronous http client.
* All request signing is handled automatically.
Expand Down
Loading