package updates
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* Nexmo Client Library for PHP
|
||||
*
|
||||
* @copyright Copyright (c) 2016 Nexmo, Inc. (http://nexmo.com)
|
||||
* @license https://github.com/Nexmo/nexmo-php/blob/master/LICENSE.txt MIT License
|
||||
*/
|
||||
|
||||
namespace Nexmo\Client\Response;
|
||||
|
||||
|
||||
abstract class AbstractResponse implements ResponseInterface
|
||||
{
|
||||
protected $data;
|
||||
|
||||
public function getData()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function isSuccess()
|
||||
{
|
||||
return isset($this->data['status']) AND $this->data['status'] == 0;
|
||||
}
|
||||
|
||||
public function isError()
|
||||
{
|
||||
return !$this->isSuccess();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
/**
|
||||
* Nexmo Client Library for PHP
|
||||
*
|
||||
* @copyright Copyright (c) 2016 Nexmo, Inc. (http://nexmo.com)
|
||||
* @license https://github.com/Nexmo/nexmo-php/blob/master/LICENSE.txt MIT License
|
||||
*/
|
||||
|
||||
namespace Nexmo\Client\Response;
|
||||
|
||||
|
||||
class Error extends Response
|
||||
{
|
||||
public function __construct($data)
|
||||
{
|
||||
//normalize the data
|
||||
if(isset($data['error_text'])){
|
||||
$data['error-text'] = $data['error_text'];
|
||||
}
|
||||
|
||||
$this->expected = ['status', 'error-text'];
|
||||
|
||||
return parent::__construct($data);
|
||||
}
|
||||
|
||||
public function isError()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function isSuccess()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getCode()
|
||||
{
|
||||
return $this->data['status'];
|
||||
}
|
||||
|
||||
public function getMessage()
|
||||
{
|
||||
return $this->data['error-text'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* Nexmo Client Library for PHP
|
||||
*
|
||||
* @copyright Copyright (c) 2016 Nexmo, Inc. (http://nexmo.com)
|
||||
* @license https://github.com/Nexmo/nexmo-php/blob/master/LICENSE.txt MIT License
|
||||
*/
|
||||
|
||||
namespace Nexmo\Client\Response;
|
||||
|
||||
class Response extends AbstractResponse implements ResponseInterface
|
||||
{
|
||||
/**
|
||||
* Allow specific responses to easily define required parameters.
|
||||
* @var array
|
||||
*/
|
||||
protected $expected = array();
|
||||
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$keys = array_keys($data);
|
||||
$missing = array_diff($this->expected, $keys);
|
||||
|
||||
if($missing){
|
||||
throw new \RuntimeException('missing expected response keys: ' . implode(', ', $missing));
|
||||
}
|
||||
|
||||
$this->data = $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* Nexmo Client Library for PHP
|
||||
*
|
||||
* @copyright Copyright (c) 2016 Nexmo, Inc. (http://nexmo.com)
|
||||
* @license https://github.com/Nexmo/nexmo-php/blob/master/LICENSE.txt MIT License
|
||||
*/
|
||||
|
||||
namespace Nexmo\Client\Response;
|
||||
|
||||
|
||||
interface ResponseInterface
|
||||
{
|
||||
public function getData();
|
||||
public function isError();
|
||||
public function isSuccess();
|
||||
}
|
||||
Reference in New Issue
Block a user