forked from objectivehtml/UPS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BaseResponse.php
145 lines (109 loc) · 1.73 KB
/
BaseResponse.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
/**
* UPS Base Response
*
* @package UPS API
* @author Justin Kimbrell
* @copyright Copyright (c) 2012, Objective HTML
* @link http://www.objectivehtml.com/
* @version 0.2.0
* @build 20120823
*/
abstract class Ups_BaseResponse {
/**
* UPS Success Constant
*
* @var string
*/
const UPS_SUCCESS = TRUE;
/**
* UPS Failed Constant
*
* @var string
*/
const UPS_FAILED = FALSE;
/**
* Errors
*
* @var array
*/
public $errors = array();
/**
* Warning
*
* @var array
*/
public $warnings = array();
/**
* Timestamp
*
* @var array
*/
public $timestamp;
/**
* Response Code
*
* @var string
*/
public $code;
/**
* Response Status
*
* @var string
*/
public $status;
/**
* Construct
*
* @access public
* @return obj
*/
public function __construct($data = array())
{
$this->timestamp = time();
foreach($data as $key => $value)
{
if(property_exists($this, $key))
{
$this->$key = $value;
}
}
}
/**
* Set the response as success
*
* @access public
* @param mixed Response code
* @return NULL
*/
public function success($code = NULL)
{
$this->set_response(self::UPS_SUCCESS, $code);
}
/**
* Set the response as failed
*
* @access public
* @param mixed Response code
* @return NULL
*/
public function failed($code = NULL)
{
$this->set_response(self::UPS_FAILED, $code);
}
/**
* Set the response
*
* @access public
* @param mixed Response code
* @return NULL
*/
public function set_response($response, $code = NULL)
{
if(!is_null($code))
{
$this->code = $code;
}
$this->status = $response;
}
}