Resources objects¶
The resources classes¶
GenericResource¶
All resources extends the GenericResource class, and therefore have access to all its public methods.
GET request¶
| Method: | get($uri) |
|---|---|
| Summary: | Send a GET request to the API using the current resource uri, or
the uri given in parameter. |
| Parameters: | String $uri : forced url |
| Return: | Collection of entities or entity of the matching type |
$collection = $client->messages->get();
$message = $client->messages->get($message_uri);
PATCH request¶
| Method: |
|
|---|---|
| Summary: | Send a |
| Parameters: |
|
| Return: | Entity of the same type |
$entity = $client->resource_name->patch($values);
POST request¶
| Method: |
|
|---|---|
| Summary: | Send a |
| Parameters: |
|
| Return: | Entity of the same type |
$message = $client->messages->post($values);
PUT request¶
| Method: |
|
|---|---|
| Summary: | Send a |
| Parameters: |
|
| Return: | Entity of the same type |
DELETE Request¶
| Method: | delete() |
|---|---|
| Summary: | Send a DELETE request to the API to delete the current resource uri. |
Warning
Be very careful as you can delete several API resources using this method!
Filtering the resource¶
| Method: |
|
|---|---|
| Summary: | Register a filter. The filters are passed to the API in the query string parameters. |
| Parameters: |
|
| Return: | Current resource with registered filters |
$resource = $client->messages->filter(['sender_name' => 'tintin@crunchmail.net']);
$collection = $resource->get();
Direct acces to a page¶
| Method: |
|
|---|---|
| Summary: | Access directly to the requested page. This is a shortcut to
|
| Parameters: |
|
| Return: | Collection of the matching type |
$collection = $client->messages->page(3);
DomainsResource¶
Searching for a domain¶
| Method: |
|
|---|---|
| Summary: | Search for the domain |
| Parameters: |
|
| Returns: | GenericCollection |
// search for domain
$collection = $client->domains->search('crunchmail.net');
if ($collection->count() > 0)
{
$current = $collection->current();
// the is one result
$domain = $current[0];
}
Verifying a domain¶
| Method: |
|
|---|---|
| Summary: | Verify the domain |
| Parameters: |
|
| Returns: | GenericCollection |
// search for domain
if ($client->domains->verify('crunchmail.net'))
{
echo "Domain verified";
}
if ($client->domains->verify('contact@crunchmail.net'))
{
echo "Domain verified";
}
PreviewSendResource¶
| Method: |
|
|---|---|
| Summary: | Send the preview to the recipient(s) |
| Parameters: |
|
| Returns: | GenericEntity |
$messageEntity->preview_send->send('ilove@crunchmail.net');
Sub-resources¶
You can also access sub-resources directly using the recursive syntax. This is useful when using, for example, the contact lists features.
// accessing /contacts/lists/ end-point
$contactListsCollection = $client->contacts->lists->get();
// accessing /contacts/queues/ end-point
$contactQueuesCollection = $client->contacts->queues->get();