cakemail / cakemail
A simple client to get started with Cakemail Next-gen API
Installs: 8 041
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 7
Forks: 2
Open Issues: 0
Requires
- php: >=7.2.5
- guzzlehttp/guzzle: ^7.6
- twig/twig: ^2.14.0 | ^3.1
README
Install the cakemail
package using composer
$ composer require cakemail/cakemail
Usage
Create an object from the Cakemail\Api
class with your Cakemail username and password. The object will take care of
all authorization mechanisms automatically.
$username = 'your@email.com'; $password = 'somepassword'; $api = new Api($username, $password);
Call one of the API operations (refer to the online documentation here)
$myAcount = $api->account->getSelf();
API operations
API operations accepts all the parameters in an array. You can use any parameter, in any order, but you must provide the required ones.
$filteredCampaigns = $api->campaign->list([ 'with_count' => true, 'filter' => 'type==recurring;name==Newsletter' ]);
Operation Examples
Create a Sender
use Cakemail\Lib\Model; $sender = $api->sender->create([ 'create_sender' => new Model\CreateSender([ 'name' => 'My Sender', 'email' => 'someone@gmail.com' ]) ]); # look for the confirmation ID in your email inbox $api->sender->confirm([ 'sender_id' => $sender['id'], 'confirm_sender' => new Model\ConfirmSender([ 'confirmation_id' => '[Confirmation ID]' ]) ]);
Create a Contact List
use Cakemail\Lib\Model; $myList = $api->list->create([ 'model_list' => new Model\ModelList([ 'name' => 'My new List', 'default_sender' => new Model\Sender([ 'id' => $senderId ]) ]) ]);
Send a transactional email
use Cakemail\Lib\Model; $myList = $api->transactional_email->send([ 'email' => new Model\Email([ 'email' => 'destination@gmail.com', 'sender' => $sender, 'content' => new Model\EmailContent([ 'subject' => 'Subject line', 'html' => 'Email body', 'encoding' => 'utf-8' ]) ]) ]);
Accessing data
The CakemailAPI always return its data under the 'data' key. For simplicity, the resource data is accessible from the returned response directly:
$myUser = $api->user->getSelf(); print_r($myUser['email']);
Iterate through lists
Some methods return a list of resources on which you can iterate directly:
$campaigns = $api->campaign->list(); foreach ($campaigns as $campaign) { $html = $api->campaign->render([ 'campaign_id' => $campaign['id'] ])['html']; print_r("id: {$campaign['id']}, name: {$campaign['name']}, html: {$html}"); }
Pagination
Pagination is stored in the 'pagination' key of all methods returning a list of resources:
$campaigns = $api->campaign->list(['with_count' => 'true']); print_r(" page: " . $campaigns['pagination']['page'] . ", per_page: " . $campaigns['pagination']['per_page'] . ", count: " . $campaigns['pagination']['count'] . " ");