forked from SurveyGizmoOfficial/PHP_SurveyGizmo_Api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApiResponse.php
executable file
·95 lines (82 loc) · 1.65 KB
/
ApiResponse.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
85
86
87
88
89
90
91
92
93
94
95
<?php
namespace SurveyGizmo;
/**
* ApiResponse class stores the response of an API request.
*/
class ApiResponse
{
/**
* Status.
* @var bool
*/
public $result_ok;
/**
* Response code.
* @var int
*/
public $code;
/**
* Id of the object that has been created.
* @var int
*/
public $id;
/**
* Error message.
* @var string
*/
public $message;
/**
* Total # of records.
* @var int
*/
public $total_count;
/**
* Page # of response.
* @var int
*/
public $page;
/**
* Total # of pages available.
* @var int
*/
public $total_pages;
/**
* Number of items per page.
* @var int
*/
public $results_per_page;
/**
* Response data.
* @var stdClass
*/
public $data;
/**
* Response HTTP code.
* @var int
*/
public $http_code;
/**
* Takes the JSON decoded response from the ApiRequest class and sets the data
* on this instance.
* @access public
* @param $json_obj stdClass
* @return void
*/
public function parseBuffer($json_obj)
{
if (is_object($json_obj)) {
$this->result_ok = $json_obj->result_ok;
$this->code = isset($json_obj->code) ? $json_obj->code : 0;
$this->message = isset($json_obj->message) ? $json_obj->message : null;
// Add meta data
if (isset($json_obj->total_count)) {
$this->total_count = $json_obj->total_count;
$this->page = isset($json_obj->page) ? $json_obj->page : 0;
$this->total_pages = isset($json_obj->total_pages) ? $json_obj->total_pages : 0;
$this->results_per_page = $json_obj->results_per_page;
}
$this->data = isset($json_obj->data) ? $json_obj->data : null;
$this->id = isset($json_obj->id) ? $json_obj->id : null;
}
}
}