Skip to content

Commit dc14add

Browse files
committed
Basic support for Verify
1 parent e5c4160 commit dc14add

File tree

14 files changed

+505
-0
lines changed

14 files changed

+505
-0
lines changed

src/Nexmo/Verify/Check/Request.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: tjlytle
5+
* Date: 10/28/14
6+
* Time: 10:56 PM
7+
*/
8+
9+
namespace Nexmo\Verify\Check;
10+
use Nexmo\Client\Request\AbstractRequest;
11+
use Nexmo\Client\Request\RequestInterface;
12+
use Nexmo\Client\Request\WrapResponseInterface;
13+
use Nexmo\Client\Response\Error;
14+
use Nexmo\Client\Response\ResponseInterface;
15+
16+
class Request extends AbstractRequest implements RequestInterface, WrapResponseInterface
17+
{
18+
protected $params = array();
19+
20+
public function __construct($id, $code, $ip = null)
21+
{
22+
$this->params['request_id'] = $id;
23+
$this->params['code'] = $code;
24+
$this->params['ip_address'] = $ip;
25+
}
26+
27+
/**
28+
* @return string
29+
*/
30+
public function getURI()
31+
{
32+
return '/verify/check/json';
33+
}
34+
35+
/**
36+
* @param ResponseInterface $response
37+
* @return ResponseInterface
38+
*/
39+
public function wrapResponse(ResponseInterface $response)
40+
{
41+
if($response->isError()){
42+
return new Error($response->getData());
43+
}
44+
45+
return new Response($response->getData());
46+
}
47+
48+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: tjlytle
5+
* Date: 10/28/14
6+
* Time: 10:56 PM
7+
*/
8+
9+
namespace Nexmo\Verify\Check;
10+
11+
use Nexmo\Client\Response\Response as BaseResponse;
12+
use Nexmo\Client\Response\ResponseInterface;
13+
14+
class Response extends BaseResponse implements ResponseInterface
15+
{
16+
protected $expected = array('event_id', 'status', 'price', 'currency');
17+
18+
public function getEventId()
19+
{
20+
return $this->data['event_id'];
21+
}
22+
23+
public function getStatus()
24+
{
25+
return $this->data['status'];
26+
}
27+
28+
public function getPrice()
29+
{
30+
return $this->data['price'];
31+
}
32+
33+
public function getCurrency()
34+
{
35+
return $this->data['currency'];
36+
}
37+
38+
}

src/Nexmo/Verify/Request.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: tjlytle
5+
* Date: 10/28/14
6+
* Time: 10:56 PM
7+
*/
8+
9+
namespace Nexmo\Verify;
10+
use Nexmo\Client\Request\AbstractRequest;
11+
use Nexmo\Client\Request\RequestInterface;
12+
use Nexmo\Client\Request\WrapResponseInterface;
13+
use Nexmo\Client\Response\Error;
14+
use Nexmo\Client\Response\ResponseInterface;
15+
16+
class Request extends AbstractRequest implements RequestInterface, WrapResponseInterface
17+
{
18+
protected $params = array();
19+
20+
public function __construct($number, $brand, $from = null, $length = null, $lang = null)
21+
{
22+
$this->params['number'] = $number;
23+
$this->params['brand'] = $brand;
24+
$this->params['sender_id'] = $from;
25+
$this->params['code_length'] = $length;
26+
$this->params['lg'] = $lang;
27+
28+
if(!is_null($length) AND !(4 == $length OR 6 == $length)){
29+
throw new \InvalidArgumentException('length must be 4 or 6');
30+
}
31+
}
32+
33+
/**
34+
* @return string
35+
*/
36+
public function getURI()
37+
{
38+
return 'verify/json';
39+
}
40+
41+
/**
42+
* @param ResponseInterface $response
43+
* @return ResponseInterface
44+
*/
45+
public function wrapResponse(ResponseInterface $response)
46+
{
47+
if($response->isError()){
48+
return new Error($response->getData());
49+
}
50+
51+
return new Response($response->getData());
52+
}
53+
54+
}

src/Nexmo/Verify/Response.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: tjlytle
5+
* Date: 10/28/14
6+
* Time: 10:56 PM
7+
*/
8+
9+
namespace Nexmo\Verify;
10+
11+
use Nexmo\Client\Response\Response as BaseResponse;
12+
use Nexmo\Client\Response\ResponseInterface;
13+
14+
class Response extends BaseResponse implements ResponseInterface
15+
{
16+
protected $expected = array('request_id', 'status');
17+
18+
public function getId()
19+
{
20+
return $this->data['request_id'];
21+
}
22+
23+
public function getStatus()
24+
{
25+
return $this->data['status'];
26+
}
27+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: tjlytle
5+
* Date: 10/28/14
6+
* Time: 10:57 PM
7+
*/
8+
9+
namespace Nexmo\Verify\Search;
10+
use Nexmo\Client\Request\AbstractRequest;
11+
use Nexmo\Client\Request\RequestInterface;
12+
use Nexmo\Client\Request\WrapResponseInterface;
13+
use Nexmo\Client\Response\Error;
14+
use Nexmo\Client\Response\ResponseInterface;
15+
16+
class Request extends AbstractRequest implements RequestInterface, WrapResponseInterface
17+
{
18+
protected $params = array();
19+
20+
public function __construct($id)
21+
{
22+
$this->params['request_id'] = $id;
23+
}
24+
25+
/**
26+
* @return string
27+
*/
28+
public function getURI()
29+
{
30+
return '/verify/search/json';
31+
}
32+
33+
/**
34+
* @param ResponseInterface $response
35+
* @return ResponseInterface
36+
*/
37+
public function wrapResponse(ResponseInterface $response)
38+
{
39+
if($response->isError()){
40+
return new Error($response->getData());
41+
}
42+
43+
return new Response($response->getData());
44+
}
45+
46+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: tjlytle
5+
* Date: 10/28/14
6+
* Time: 10:57 PM
7+
*/
8+
9+
namespace Nexmo\Verify\Search;
10+
11+
use Nexmo\Client\Response\Response as BaseResponse;
12+
use Nexmo\Client\Response\ResponseInterface;
13+
14+
class Response extends BaseResponse implements ResponseInterface
15+
{
16+
protected $expected = array('request_id', 'status');
17+
18+
public function getId()
19+
{
20+
return $this->data['request_id'];
21+
}
22+
23+
public function getStatus()
24+
{
25+
return $this->data['status'];
26+
}
27+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: tjlytle
5+
* Date: 10/28/14
6+
* Time: 10:58 PM
7+
*/
8+
9+
namespace Nexmo\Verify\Check;
10+
11+
12+
class RequestTest extends \PHPUnit_Framework_TestCase
13+
{
14+
protected $request_id = '1234abcd';
15+
protected $code = '123456';
16+
17+
public function testOptionalValues()
18+
{
19+
$request = new Request($this->request_id, $this->code);
20+
$this->assertArrayNotHasKey('ip_address', $request->getParams());
21+
}
22+
23+
public function testRequiredValues()
24+
{
25+
$request = new Request($this->request_id, $this->code);
26+
$params = $request->getParams();
27+
28+
$this->assertArrayHasKey('request_id', $params);
29+
$this->assertArrayHasKey('code', $params);
30+
31+
$this->assertEquals($this->request_id, $params['request_id']);
32+
$this->assertEquals($this->code, $params['code']);
33+
}
34+
35+
public function testIpAddress()
36+
{
37+
$request = new Request($this->request_id, $this->code, '127.0.0.1');
38+
$params = $request->getParams();
39+
40+
$this->assertArrayHasKey('ip_address', $params);
41+
$this->assertEquals('127.0.0.1', $params['ip_address']);
42+
}
43+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: tjlytle
5+
* Date: 10/28/14
6+
* Time: 10:58 PM
7+
*/
8+
9+
namespace Nexmo\Verify\Check;
10+
11+
12+
class ResponseTest extends \PHPUnit_Framework_TestCase
13+
{
14+
protected $data = array(
15+
'event_id' => '1234abcd',
16+
'status' => '0',
17+
'price' => '.03',
18+
'currency' => 'EUR'
19+
);
20+
21+
protected $response;
22+
23+
public function setUp()
24+
{
25+
$this->response = new Response($this->data);
26+
}
27+
28+
public function testResponseMap()
29+
{
30+
$this->assertEquals($this->data['event_id'], $this->response->getEventId());
31+
$this->assertEquals($this->data['status'], $this->response->getStatus());
32+
$this->assertEquals($this->data['price'], $this->response->getPrice());
33+
$this->assertEquals($this->data['currency'], $this->response->getCurrency());
34+
}
35+
}

0 commit comments

Comments
 (0)