2014-09-17 15:54:24 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Standard Response object for the AlternC API
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class Alternc_Api_Response {
|
|
|
|
|
2014-09-18 10:01:34 +00:00
|
|
|
/**
|
|
|
|
* Error codes
|
|
|
|
*/
|
|
|
|
const ERR_DISABLED_ACCOUNT = 221801;
|
|
|
|
const ERR_INVALID_AUTH = 221802;
|
|
|
|
|
|
|
|
|
2014-09-17 15:54:24 +00:00
|
|
|
/**
|
|
|
|
* Result code. 0 means success
|
|
|
|
*
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
public $code;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Result message. May be empty
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $message;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Result data
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $content;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Result metadata
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $metadata;
|
|
|
|
|
2014-09-18 10:01:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* initialize a response object
|
|
|
|
* @param options any of the public above
|
|
|
|
*/
|
2014-09-21 14:44:06 +00:00
|
|
|
public function __construct($options=array()) {
|
2014-09-18 10:01:34 +00:00
|
|
|
$os=array("code","message","content","metadata");
|
|
|
|
foreach ($os as $o) {
|
|
|
|
if (isset($options[$o])) $this->$o=$options[$o];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-17 15:54:24 +00:00
|
|
|
/**
|
|
|
|
* Formats response to json
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2014-09-18 10:01:34 +00:00
|
|
|
public function toJson (){
|
2014-09-17 15:54:24 +00:00
|
|
|
return json_encode(get_object_vars($this));
|
|
|
|
}
|
|
|
|
|
2014-09-18 10:01:34 +00:00
|
|
|
|
|
|
|
|
2014-09-17 15:54:24 +00:00
|
|
|
|
2014-09-18 10:01:34 +00:00
|
|
|
} // class Alternc_Api_Response
|
|
|
|
|