Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to fetch email messages created by Verify email verification #171

Merged
merged 4 commits into from
May 28, 2021
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
17 changes: 17 additions & 0 deletions examples/emailmessages-view.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

use MessageBird\Client;

require_once(__DIR__ . '/../autoload.php');

$messageBird = new Client('YOUR_ACCESS_KEY'); // Set your own API access key here.

try {
$emailMessageResult = $messageBird->emailmessages->read('ca0a8220453bc36ddeb3115a37400870'); // Set a message id here
var_dump($emailMessageResult);
} catch (\MessageBird\Exceptions\AuthenticateException $e) {
// That means that your accessKey is unknown
echo 'wrong login';
} catch (\Exception $e) {
var_dump($e->getMessage());
}
33 changes: 33 additions & 0 deletions examples/verify-create-email.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use MessageBird\Client;
use MessageBird\Exceptions\AuthenticateException;
use MessageBird\Exceptions\BalanceException;
use MessageBird\Objects\Verify;

require_once(__DIR__ . '/../autoload.php');

$messageBird = new Client('YOUR_ACCESS_KEY'); // Set your own API access key here.

$verify = new Verify();
$verify->recipient = 'Client Name <client-email@example.com>';

$extraOptions = [
'type' => 'email',
// This email domain needs to be set up as an email channel in your account at https://dashboard.messagebird.com/en/channels/
'originator' => 'Email Verification <verify@company.com>',
'timeout' => 60,
];

try {
$verifyResult = $messageBird->verify->create($verify, $extraOptions);
var_dump($verifyResult);
} catch (AuthenticateException $e) {
// That means that your accessKey is unknown
echo 'wrong login';
} catch (BalanceException $e) {
// That means that you are out of credits, so do something about it.
echo 'no balance';
} catch (\Exception $e) {
echo $e->getMessage();
}
6 changes: 6 additions & 0 deletions src/MessageBird/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ class Client
*/
public $groups;

/**
* @var Resources\EmailMessage
*/
public $emailmessages;

/**
* @var Resources\VoiceMessage
*/
Expand Down Expand Up @@ -241,6 +246,7 @@ public function __construct($accessKey = null, Common\HttpClient $httpClient = n
$this->hlr = new Resources\Hlr($this->httpClient);
$this->verify = new Resources\Verify($this->httpClient);
$this->balance = new Resources\Balance($this->httpClient);
$this->emailmessages = new Resources\EmailMessage($this->httpClient);
$this->voicemessages = new Resources\VoiceMessage($this->httpClient);
$this->lookup = new Resources\Lookup($this->httpClient);
$this->lookupHlr = new Resources\LookupHlr($this->httpClient);
Expand Down
46 changes: 46 additions & 0 deletions src/MessageBird/Objects/EmailMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace MessageBird\Objects;

/**
* Class EmailMessage
*
* @package MessageBird\Objects
*/
class EmailMessage extends Base
{
/**
* An unique random ID which is created on the MessageBird
* platform and is returned upon creation of the object.
*
* @var string
*/
protected $id;

/**
* The status of the Email Message.
*
* @var string
*/
protected $status;

/**
* Get the created id
*
* @return mixed
*/
public function getId()
{
return $this->id;
}

/**
* Get the status
*
* @return string
*/
public function getStatus()
{
return $this->status;
}
}
4 changes: 2 additions & 2 deletions src/MessageBird/Objects/Verify.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ class Verify extends Base
protected $href;

/**
* The msisdn of the recipient
* The msisdn or email of the recipient
*
* @var int
* @var int|string
*/
public $recipient;

Expand Down
25 changes: 25 additions & 0 deletions src/MessageBird/Resources/EmailMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace MessageBird\Resources;

use MessageBird\Common;
use MessageBird\Objects;

/**
* Class EmailMessage
*
* @package MessageBird\Resources
*/
class EmailMessage extends Base
{
/**
* @param Common\HttpClient $httpClient
*/
public function __construct(Common\HttpClient $httpClient)
{
$this->setObject(new Objects\EmailMessage);
$this->setResourceName('verify/messages/email');

parent::__construct($httpClient);
}
}