-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathBase.php
More file actions
207 lines (185 loc) · 4.34 KB
/
Copy pathBase.php
File metadata and controls
207 lines (185 loc) · 4.34 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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<?php
/**
* contains Base class
*/
namespace OST;
use InvalidArgumentException;
use BadMethodCallException;
use Lib\Request;
use Lib\Validate;
use RuntimeException;
/**
* Base Class
*/
abstract class Base
{
const PREFIX = '';
const SUFFIX = '';
/** @var Request request object which would fire API calls */
protected $requestObj;
/**
* Constructor
*
* @param Request $requestObj request object which would fire API calls
*/
public function __construct(Request $requestObj)
{
$this->requestObj = $requestObj;
}
/**
* @return string
* @throws RuntimeException
*/
protected function getPrefix()
{
if (empty(static::PREFIX)) {
throw new RuntimeException('Prefix must be defined in class: ' . get_class($this));
}
return static::PREFIX;
}
/**
* @return string
* @throws RuntimeException
*/
protected function getSuffix()
{
if (empty(static::SUFFIX)) {
throw new RuntimeException('Suffix must be defined in class: ' . get_class($this));
}
return static::SUFFIX;
}
/**
* getId from params array
*
* @param array $params request object which would fire API calls
*
* @return string
*/
protected function getId(array $params)
{
return $this->getValueForKey($params, "id");
}
/**
* getUserId from params array
*
* @param array $params request object which would fire API calls
*
* @return string
*/
protected function getUserId(array $params)
{
return $this->getValueForKey($params, "user_id");
}
/**
* getChainId from params array
*
* @param array $params request object which would fire API calls
*
* @return string
*/
protected function getChainId(array $params)
{
return $this->getValueForKey($params, "chain_id");
}
/**
* getDeviceAddress from params array
*
* @param array $params request object which would fire API calls
*
* @return string
*/
protected function getDeviceAddress(array $params)
{
return $this->getValueForKey($params, "device_address");
}
/**
* getSessionAddress from params array
*
* @param array $params request object which would fire API calls
*
* @return string
*/
protected function getSessionAddress(array $params)
{
return $this->getValueForKey($params, "session_address");
}
/**
* getTransactionId from params array
*
* @param array $params request object which would fire API calls
*
* @return string
*/
protected function getTransactionId(array $params)
{
return $this->getValueForKey($params, "transaction_id");
}
/**
* getRedemptionId from params array
*
* @param array $params request object which would fire API calls
*
* @return string
*/
protected function getRedemptionId(array $params)
{
return $this->getValueForKey($params, "redemption_id");
}
/**
* getRedeemableSkuId from params array
*
* @param array $params request object which would fire API calls
*
* @return string
*/
protected function getRedeemableSkuId(array $params)
{
return $this->getValueForKey($params, "redeemable_sku_id");
}
/**
* getRecoveryOwnerAddress from params array
*
* @param array $params request object which would fire API calls
*
* @return string
*/
protected function getRecoveryOwnerAddress(array $params)
{
return $this->getValueForKey($params, "recovery_owner_address");
}
/**
* getWebhookId from params array
*
* @param array $params request object which would fire API calls
*
* @return string
*/
protected function getWebhookId(array $params)
{
return $this->getValueForKey($params, "webhook_id");
}
/**
* Get Value for Given Key
*
* @param array $params request object which would fire API calls
*
* @throws InvalidArgumentException, BadMethodCallException
*
* @return string
*/
private function getValueForKey(&$params, $key)
{
$value = '';
if (array_key_exists($key, $params)) {
$value = $params[$key];
unset($params[$key]);
}
if (($value === null) || ($value === '')) {
throw new BadMethodCallException("$key is missing in request params");
}
if (!(Validate::isValidParams($value))) {
throw new InvalidArgumentException("$key is invalid in request params");
}
return urlencode($value);
}
}