-
Notifications
You must be signed in to change notification settings - Fork 5
/
logicboxes_response.php
84 lines (77 loc) · 1.96 KB
/
logicboxes_response.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/**
* LogicBoxes API response handler
*
* @copyright Copyright (c) 2013, Phillips Data, Inc.
* @license http://opensource.org/licenses/mit-license.php MIT License
* @package logicboxes
*/
class LogicboxesResponse {
/**
* @var stdClass A stdClass object representing the response
*/
private $response;
/**
* @var string The raw response from the API (JSON)
*/
private $raw;
/**
* Initializes the LogicBoxes Response
*
* @param string $response The raw XML response data from an API request
*/
public function __construct($response) {
$this->raw = $response;
$this->response = $this->formatResponse($this->raw);
}
/**
* Returns the CommandResponse
*
* @return stdClass A stdClass object representing the CommandResponses, null if invalid response
*/
public function response() {
return $this->response;
}
/**
* Returns the status of the API Responses
*
* @return string The status (OK = success, ERROR = error, null = invalid responses)
*/
public function status() {
if ($this->errors())
return "ERROR";
elseif ($this->raw)
return "OK";
return null;
}
/**
* Returns all errors contained in the response
*
* @return stdClass A stdClass object representing the errors in the response, false if invalid response
*/
public function errors() {
if (isset($this->response->status) && strtolower($this->response->status) == "error")
return $this->response;
elseif (isset($this->response->status) && strtolower($this->response->status) == "failed")
return (object)array('message' => $this->response->actionstatusdesc);
return false;
}
/**
* Returns the raw response
*
* @return string The raw response
*/
public function raw() {
return $this->raw;
}
/**
* Decodes the response
*
* @param mixed $data The JSON data to convert to a stdClass object
* @return stdClass $data in a stdClass object form
*/
private function formatResponse($data) {
return json_decode($data);
}
}
?>