Skip to content

Commit 2adae97

Browse files
committed
Merge pull request #12 from messagebird/verify-implementation
Verify implementation
2 parents 7c4d9d2 + d847b45 commit 2adae97

File tree

13 files changed

+297
-201
lines changed

13 files changed

+297
-201
lines changed

examples/verify-create.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
require_once(__DIR__ . '/../autoload.php');
4+
5+
$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here.
6+
7+
$Verify = new \MessageBird\Objects\Verify();
8+
$Verify->recipient = 31612345678;
9+
10+
$extraOptions = array(
11+
'originator' => 'MessageBird',
12+
'timeout' => 60,
13+
);
14+
15+
try {
16+
$VerifyResult = $MessageBird->verify->create($Verify, $extraOptions);
17+
var_dump($VerifyResult);
18+
19+
} catch (\MessageBird\Exceptions\AuthenticateException $e) {
20+
// That means that your accessKey is unknown
21+
echo 'wrong login';
22+
23+
} catch (\MessageBird\Exceptions\BalanceException $e) {
24+
// That means that you are out of credits, so do something about it.
25+
echo 'no balance';
26+
27+
} catch (\Exception $e) {
28+
echo $e->getMessage();
29+
}

examples/verify-verification.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
require_once(__DIR__ . '/../autoload.php');
4+
5+
$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here.
6+
7+
try {
8+
$VerifyResult = $MessageBird->verify->verify('05a90ee1155d2f4cdd12440v10006813', '585438'); // Set a message id and the token here.
9+
var_dump($VerifyResult);
10+
11+
// Check if $VerifyResult->getStatus() === MessageBird\Objects\Verify::STATUS_VERIFIED
12+
13+
} catch (\MessageBird\Exceptions\AuthenticateException $e) {
14+
// That means that your accessKey is unknown
15+
echo 'wrong login';
16+
17+
} catch (\Exception $e) {
18+
echo $e->getMessage();
19+
}

examples/verify-view.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
require_once(__DIR__ . '/../autoload.php');
4+
5+
$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here.
6+
7+
try {
8+
$VerifyResult = $MessageBird->verify->read('05a90ee1155d2f4cdd12440v10006813'); // Set a message id here
9+
var_dump($VerifyResult);
10+
11+
} catch (\MessageBird\Exceptions\AuthenticateException $e) {
12+
// That means that your accessKey is unknown
13+
echo 'wrong login';
14+
15+
} catch (\Exception $e) {
16+
echo $e->getMessage();
17+
}

examples/voicemessages-view.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
22

3-
date_default_timezone_set('Europe/Amsterdam');
4-
53
require_once(__DIR__ . '/../autoload.php');
64

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

src/MessageBird/Client.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ class Client
3535
public $hlr;
3636

3737
/**
38-
* @var Resources\Otp
38+
* @var Resources\Verify
3939
*/
40-
public $otp;
40+
public $verify;
4141

4242
/**
4343
* @var Resources\Balance
@@ -66,11 +66,12 @@ public function __construct($accessKey = null, Common\HttpClient $httpClient = n
6666
if ($accessKey !== null) {
6767
$this->setAccessKey($accessKey);
6868
}
69-
$this->messages = new Resources\Messages($this->HttpClient);
70-
$this->hlr = new Resources\Hlr($this->HttpClient);
71-
$this->otp = new Resources\Otp($this->HttpClient);
72-
$this->balance = new Resources\Balance($this->HttpClient);
73-
$this->voicemessages = new Resources\VoiceMessage($this->HttpClient);
69+
70+
$this->messages = new Resources\Messages($this->HttpClient);
71+
$this->hlr = new Resources\Hlr($this->HttpClient);
72+
$this->verify = new Resources\Verify($this->HttpClient);
73+
$this->balance = new Resources\Balance($this->HttpClient);
74+
$this->voicemessages = new Resources\VoiceMessage($this->HttpClient);
7475
}
7576

7677
/**

src/MessageBird/Objects/Otp.php

Lines changed: 0 additions & 92 deletions
This file was deleted.

src/MessageBird/Objects/Verify.php

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
<?php
2+
3+
namespace MessageBird\Objects;
4+
5+
/**
6+
* Class Verify
7+
*
8+
* @package MessageBird\Objects
9+
*/
10+
class Verify extends Base
11+
{
12+
const STATUS_SENT = 'sent';
13+
const STATUS_VERIFIED = 'verified';
14+
const STATUS_FAILED = 'failed';
15+
const STATUS_EXPIRED = 'expired';
16+
const STATUS_DELETED = 'deleted';
17+
18+
/**
19+
* An unique random ID which is created on the MessageBird platform and is returned upon
20+
* creation of the object.
21+
*
22+
* @var string
23+
*/
24+
protected $id;
25+
26+
/**
27+
* The URL of the created object.
28+
*
29+
* @var string
30+
*/
31+
protected $href;
32+
33+
/**
34+
* The msisdn of the recipient
35+
*
36+
* @var int
37+
*/
38+
public $recipient;
39+
40+
/**
41+
* A client reference. Here you can put your own reference,
42+
* like your internal reference.
43+
*
44+
* @var string
45+
*/
46+
public $reference;
47+
48+
/**
49+
* A hash containing one href entry referring to the URL of the created object.
50+
* The entry can either refer to either the messages or the voicemessages endpoint
51+
*
52+
* @var object
53+
*/
54+
protected $messages;
55+
56+
/**
57+
* The status of the Verify. Possible values: sent, expired, failed, verified, and deleted
58+
*
59+
* @var string
60+
*/
61+
protected $status;
62+
63+
/**
64+
* The date and time of the creation of the hlr in RFC3339 format (Y-m-d\TH:i:sP)
65+
*
66+
* @var string
67+
*/
68+
protected $createdDatetime;
69+
70+
/**
71+
* The date and time indicating the expiration time of the verify object in RFC3339 format (Y-m-d\TH:i:sP)
72+
*
73+
* @var string
74+
*/
75+
protected $validUntilDatetime;
76+
77+
78+
/**
79+
* Get the created id
80+
*
81+
* @return mixed
82+
*/
83+
public function getId()
84+
{
85+
return $this->id;
86+
}
87+
88+
/**
89+
* Get the created href
90+
*
91+
* @return string
92+
*/
93+
public function getHref()
94+
{
95+
return $this->href;
96+
}
97+
98+
/**
99+
* Get the created href
100+
*
101+
* @return string
102+
*/
103+
public function getMessage()
104+
{
105+
return $this->messages->href;
106+
}
107+
108+
/**
109+
* Get the status
110+
*
111+
* @return string
112+
*/
113+
public function getStatus()
114+
{
115+
return $this->status;
116+
}
117+
118+
/**
119+
* Get the $createdDatetime value
120+
*
121+
* @return string
122+
*/
123+
public function getCreatedDatetime()
124+
{
125+
return $this->createdDatetime;
126+
}
127+
128+
/**
129+
* Get the $validUntilDatetime value
130+
*
131+
* @return string
132+
*/
133+
public function getValidUntilDatetime()
134+
{
135+
return $this->validUntilDatetime;
136+
}
137+
}

src/MessageBird/Resources/Base.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Base
2525
protected $resourceName;
2626

2727
/**
28-
* @var Objects\Hlr|Objects\Message|Objects\Balance
28+
* @var Objects\Hlr|Objects\Message|Objects\Balance|Objects\Verify
2929
*/
3030
protected $Object;
3131

@@ -70,17 +70,18 @@ public function getObject()
7070
}
7171

7272
/**
73-
* @param $object
73+
* @param $object
74+
* @param array|null $query
7475
*
7576
* @return $this->Object
76-
*
77+
* @throws Exceptions\HttpException
7778
* @throws Exceptions\RequestException
7879
* @throws Exceptions\ServerException
7980
*/
80-
public function create($object)
81+
public function create($object, $query = null)
8182
{
8283
$body = json_encode($object);
83-
list(, , $body) = $this->HttpClient->performHttpRequest(Common\HttpClient::REQUEST_POST, $this->resourceName, $query = null, $body);
84+
list(, , $body) = $this->HttpClient->performHttpRequest(Common\HttpClient::REQUEST_POST, $this->resourceName, $query, $body);
8485
return $this->processRequest($body);
8586
}
8687

0 commit comments

Comments
 (0)