response.php
1.66 KB
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
<?php
class Flora_Api_Response
{
protected $data;
public function __construct($response, $api, $apiparams, $throwOnUpdateVersion = true, $debug = false, $url)
{
$this->data = json_decode($response);
$this->url = $url;
if (!$this->data) {
throw new Flora_Api_Exception("Invalid JSON data:" . $response, json_last_error());
}
if ($throwOnUpdateVersion && $this->isClientAdapterRequired()) {
$system = $this->getSystem();
throw new Flora_Api_Exception("Please update your flora client adapter. Please check url " .
$system->getApiVersionUrl(), Flora_Api_Exception::API_NEED_UPDATE_CLIENT);
}
if ($this->data->error->message) {
if ($debug) {
throw new Flora_Api_Exception($this->data->error->message . ' at ' . $api .
' with params: ' . http_build_query($apiparams), (int)$this->data->error->code);
} else {
throw new Flora_Api_Exception($this->data->error->message, (int)$this->data->error->code);
}
}
}
public function isClientAdapterRequired()
{
$system = $this->getSystem();
return $system->getApiVersion() != Flora_Api::API_VERSION;
}
public function getSystem()
{
return new Flora_Api_Response_System($this);
}
public function __toString()
{
return "<pre>" . print_r($this->data, 1) . "</pre>";
}
public function getResponseObject()
{
return $this->data;
}
/**
* @return mixed
*/
public function getResult()
{
return $this->data->result;
}
}