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
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,23 +195,23 @@ $clientJWT = new Client(

### Core Methods

| Category | Method | Description |
| ------------------ | ---------------------------------------------------- | --------------------------------- |
| **Messages** | `SendMessage(Message $message)` | Send SMS message |
| | `GetMessageState(string $id)` | Get message status by ID |
| | `RequestInboxExport(MessagesExportRequest $request)` | Request inbox export via webhooks |
| **Devices** | `ListDevices()` | List registered devices |
| | `RemoveDevice(string $id)` | Remove device by ID |
| **System** | `HealthCheck()` | Check API health status |
| | `GetLogs(?string $from, ?string $to)` | Retrieve system logs |
| **Settings** | `GetSettings()` | Get account settings |
| | `PatchSettings(Settings $settings)` | Partially update account settings |
| | `ReplaceSettings(Settings $settings)` | Replace account settings |
| **Webhooks** | `ListWebhooks()` | List registered webhooks |
| | `RegisterWebhook(Webhook $webhook)` | Register new webhook |
| | `DeleteWebhook(string $id)` | Delete webhook by ID |
| **Authentication** | `GenerateToken(TokenRequest $request)` | Generate a new JWT token |
| | `RevokeToken(string $jti)` | Revoke a JWT token by ID |
| Category | Method | Description |
| ------------------ | -------------------------------------------- | --------------------------------- |
| **Messages** | `SendMessage(Message $message)` | Send SMS message |
| | `GetMessageState(string $id)` | Get message status by ID |
| | `RefreshInbox(InboxRefreshRequest $request)` | Refresh inbox, deliver webhooks |
| **Devices** | `ListDevices()` | List registered devices |
| | `RemoveDevice(string $id)` | Remove device by ID |
| **System** | `HealthCheck()` | Check API health status |
| | `GetLogs(?string $from, ?string $to)` | Retrieve system logs |
| **Settings** | `GetSettings()` | Get account settings |
| | `PatchSettings(Settings $settings)` | Partially update account settings |
| | `ReplaceSettings(Settings $settings)` | Replace account settings |
| **Webhooks** | `ListWebhooks()` | List registered webhooks |
| | `RegisterWebhook(Webhook $webhook)` | Register new webhook |
| | `DeleteWebhook(string $id)` | Delete webhook by ID |
| **Authentication** | `GenerateToken(TokenRequest $request)` | Generate a new JWT token |
| | `RevokeToken(string $jti)` | Revoke a JWT token by ID |

### Builder Methods
```php
Expand Down
18 changes: 18 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace AndroidSmsGateway;

use AndroidSmsGateway\Domain\InboxRefreshRequest;
use AndroidSmsGateway\Domain\Message;
use AndroidSmsGateway\Domain\MessageState;
use AndroidSmsGateway\Domain\Device;
Expand Down Expand Up @@ -290,6 +291,7 @@ public function HealthCheck(): object {
/**
* Request inbox messages export
*
* @deprecated Use RefreshInbox instead
* @param MessagesExportRequest $request
* @return object
*/
Expand All @@ -308,6 +310,22 @@ public function RequestInboxExport(MessagesExportRequest $request): object {
return $response;
}

/**
* Request inbox messages refresh
*
* @param InboxRefreshRequest $request
* @return void
*/
public function RefreshInbox(InboxRefreshRequest $request): void {
$path = '/inbox/refresh';

$this->sendRequest(
'POST',
$path,
$request
);
}

/**
* Get logs within a specified time range
*
Expand Down
88 changes: 88 additions & 0 deletions src/Domain/InboxRefreshRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

namespace AndroidSmsGateway\Domain;

use AndroidSmsGateway\Enums\IncomingMessageType;
use AndroidSmsGateway\Enums\WebhookDelivery;
use AndroidSmsGateway\Interfaces\SerializableInterface;

/**
* Inbox refresh request
*/
class InboxRefreshRequest implements SerializableInterface {
/**
* ID of the device to refresh messages for
*/
private ?string $deviceId;

/**
* Start of the time range to refresh
*/
private string $since;

/**
* End of the time range to refresh
*/
private string $until;

/**
* List of message types to refresh
*
* @var array<int, IncomingMessageType>
*/
private array $messageTypes;

/**
* Delivery mode for webhooks
*/
private ?WebhookDelivery $webhookDelivery;


/**
* @param string|null $deviceId
* @param string $since
* @param string $until
* @param array<int, IncomingMessageType> $messageTypes
* @param WebhookDelivery|null $webhookDelivery
*/
public function __construct(
?string $deviceId,
string $since,
string $until,
array $messageTypes,
?WebhookDelivery $webhookDelivery = null
) {
$this->deviceId = $deviceId;
$this->since = $since;
$this->until = $until;
$this->messageTypes = $messageTypes;
$this->webhookDelivery = $webhookDelivery;
}

/**
* @return object
*/
public function ToObject(): object {
$obj = [
'since' => $this->since,
'until' => $this->until,
];

if ($this->deviceId !== null) {
$obj['deviceId'] = $this->deviceId;
}

if (!empty($this->messageTypes)) {
$obj['messageTypes'] = array_values(array_map(
static fn(IncomingMessageType $type): string => $type->Value(),
$this->messageTypes
));
}

if ($this->webhookDelivery !== null) {
$obj['webhookDelivery'] = $this->webhookDelivery->Value();
}

return (object) $obj;
}
}
41 changes: 41 additions & 0 deletions src/Domain/MmsBatchDownloadedPayload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace AndroidSmsGateway\Domain;

/**
* Payload of an mms:batch:downloaded event (list of downloaded MMS messages).
*/
final class MmsBatchDownloadedPayload {
/** @var MmsDownloadedPayload[] */
private array $messages;

/**
* @param MmsDownloadedPayload[] $messages
*/
public function __construct(array $messages) {
$this->messages = $messages;
}

/**
* @param object $obj
* @return self
*/
public static function FromObject(object $obj): self {
$messages = [];
if (isset($obj->messages) && is_array($obj->messages)) {
$messages = array_map(
static fn($m) => MmsDownloadedPayload::FromObject($m),
$obj->messages
);
}

return new self($messages);
}

/**
* @return MmsDownloadedPayload[]
*/
public function Messages(): array {
return $this->messages;
}
}
41 changes: 41 additions & 0 deletions src/Domain/MmsBatchReceivedPayload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace AndroidSmsGateway\Domain;

/**
* Payload of an mms:batch:received event (list of received MMS messages).
*/
final class MmsBatchReceivedPayload {
/** @var MmsReceivedPayload[] */
private array $messages;

/**
* @param MmsReceivedPayload[] $messages
*/
public function __construct(array $messages) {
$this->messages = $messages;
}

/**
* @param object $obj
* @return self
*/
public static function FromObject(object $obj): self {
$messages = [];
if (isset($obj->messages) && is_array($obj->messages)) {
$messages = array_map(
static fn($m) => MmsReceivedPayload::FromObject($m),
$obj->messages
);
}

return new self($messages);
}

/**
* @return MmsReceivedPayload[]
*/
public function Messages(): array {
return $this->messages;
}
}
41 changes: 41 additions & 0 deletions src/Domain/SmsBatchDataReceivedPayload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace AndroidSmsGateway\Domain;

/**
* Payload of an sms:batch:data-received event (list of received data SMS messages).
*/
final class SmsBatchDataReceivedPayload {
/** @var SmsDataReceivedPayload[] */
private array $messages;

/**
* @param SmsDataReceivedPayload[] $messages
*/
public function __construct(array $messages) {
$this->messages = $messages;
}

/**
* @param object $obj
* @return self
*/
public static function FromObject(object $obj): self {
$messages = [];
if (isset($obj->messages) && is_array($obj->messages)) {
$messages = array_map(
static fn($m) => SmsDataReceivedPayload::FromObject($m),
$obj->messages
);
}

return new self($messages);
}

/**
* @return SmsDataReceivedPayload[]
*/
public function Messages(): array {
return $this->messages;
}
}
41 changes: 41 additions & 0 deletions src/Domain/SmsBatchReceivedPayload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace AndroidSmsGateway\Domain;

/**
* Payload of an sms:batch:received event (list of received SMS messages).
*/
final class SmsBatchReceivedPayload {
/** @var SmsReceivedPayload[] */
private array $messages;

/**
* @param SmsReceivedPayload[] $messages
*/
public function __construct(array $messages) {
$this->messages = $messages;
}

/**
* @param object $obj
* @return self
*/
public static function FromObject(object $obj): self {
$messages = [];
if (isset($obj->messages) && is_array($obj->messages)) {
$messages = array_map(
static fn($m) => SmsReceivedPayload::FromObject($m),
$obj->messages
);
}

return new self($messages);
}

/**
* @return SmsReceivedPayload[]
*/
public function Messages(): array {
return $this->messages;
}
}
Loading
Loading