PluginProbe ʕ •ᴥ•ʔ
JetBackup – Backup, Restore & Migrate / 1.3.3
JetBackup – Backup, Restore & Migrate v1.3.3
3.1.22.3 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.8.1 1.4.9 1.5.0 1.5.1 1.5.1.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.10 1.6.11 1.6.12 1.6.13 1.6.15 1.6.5.1 1.6.8.8 1.6.9 1.6.9.1 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7.5 2.0.8.7 2.0.9.11 2.0.9.14 2.0.9.15 2.0.9.6 2.0.9.7 2.0.9.9 3.1.10.7 3.1.11.1 3.1.12.3 3.1.13.4 3.1.14.17 3.1.15.4 3.1.16.1 3.1.17.5 3.1.18.10 3.1.18.8 3.1.18.9 3.1.19.8 3.1.20.3 3.1.21.3 3.1.7.9 3.1.9.2 trunk 1.1.90 1.1.91 1.2.0 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2
backup / com / lib / BackupGuard / Client.php
backup / com / lib / BackupGuard Last commit date
Exception 6 years ago Client.php 6 years ago Config.php 6 years ago Curl.php 6 years ago Helper.php 6 years ago RequestHandler.php 6 years ago Response.php 6 years ago Stream.php 6 years ago
Client.php
298 lines
1 <?php
2
3 namespace BackupGuard;
4
5 require_once(dirname(__FILE__).'/Helper.php');
6
7 class Client
8 {
9 private $accessToken = null;
10
11 public function __construct($accessToken = null)
12 {
13 $this->setAccessToken($accessToken);
14 }
15
16 public function getAccessToken()
17 {
18 return $this->accessToken;
19 }
20
21 public function setAccessToken($accessToken)
22 {
23 $this->accessToken = $accessToken;
24 }
25
26 public function createAccessToken($clientId, $clientSecret, $email, $password)
27 {
28 $response = Helper::sendPostRequest(
29 '/token',
30 array(
31 'grant_type' => 'password',
32 'client_id' => $clientId,
33 'client_secret' => $clientSecret,
34 'email' => $email,
35 'password' => $password
36 )
37 );
38
39 Helper::validateResponse($response);
40
41 $accessToken = $response->getBodyParam('access_token');
42 $refreshToken = $response->getBodyParam('refresh_token');
43
44 return array(
45 'access_token' => $accessToken,
46 'refresh_token' => $refreshToken
47 );
48 }
49
50 public function refreshAccessToken($clientId, $clientSecret, $refreshToken)
51 {
52 $response = Helper::sendPostRequest(
53 '/token',
54 array(
55 'grant_type' => 'refresh_token',
56 'client_id' => $clientId,
57 'client_secret' => $clientSecret,
58 'refresh_token' => $refreshToken
59 )
60 );
61
62 Helper::validateResponse($response);
63
64 $accessToken = $response->getBodyParam('access_token');
65 $refreshToken = $response->getBodyParam('refresh_token');
66
67 return array(
68 'access_token' => $accessToken,
69 'refresh_token' => $refreshToken
70 );
71 }
72
73 public function getCurrentUser()
74 {
75 Helper::requiredParam('access_token', $this->getAccessToken());
76
77 $response = Helper::sendGetRequest(
78 '/users',
79 array(),
80 array(
81 'access_token' => $this->getAccessToken()
82 )
83 );
84
85 Helper::validateResponse($response);
86
87 return $response->getBody();
88 }
89
90 public function createUser($userInfo)
91 {
92 Helper::requiredParam('access_token', $this->getAccessToken());
93 Helper::requiredParamInArray($userInfo, 'email');
94 Helper::requiredParamInArray($userInfo, 'password');
95 Helper::requiredParamInArray($userInfo, 'firstname');
96 Helper::requiredParamInArray($userInfo, 'lastname');
97
98 $params = array(
99 'email' => $userInfo['email'],
100 'password' => $userInfo['password'],
101 'firstname' => $userInfo['firstname'],
102 'lastname' => $userInfo['lastname']
103 );
104
105 if (!empty($userInfo['package'])) {
106 $params['package'] = $userInfo['package'];
107 }
108
109 $response = Helper::sendPostRequest(
110 '/users',
111 $params,
112 array(
113 'access_token' => $this->getAccessToken()
114 )
115 );
116
117 Helper::validateResponse($response);
118
119 return $response->getBodyParam('user_id');
120 }
121
122 public function getBanner($env, $type, $userType = null)
123 {
124 Helper::requiredParam('environment', $env);
125
126 $params = array(
127 'environment' => $env,
128 'type' => $type
129 );
130
131 if ($userType) {
132 $params['user_type'] = $userType;
133 }
134
135 $response = Helper::sendGetRequest(
136 '/banners',
137 $params
138 );
139
140 try {
141 Helper::validateResponse($response);
142 }
143 catch (Exception $e) {
144 return '';
145 }
146
147 return $response->getBodyParam('html');
148 }
149
150 public function validateUrl($url, $productName)
151 {
152 Helper::requiredParam('access_token', $this->getAccessToken());
153 Helper::requiredParam('url', $url);
154 Helper::requiredParam('product', $productName);
155
156 $params = array(
157 'url' => $url,
158 'product' => $productName
159 );
160
161 $response = Helper::sendPostRequest(
162 '/products/validateUrl',
163 $params,
164 array(
165 'access_token' => $this->getAccessToken()
166 )
167 );
168
169 Helper::validateResponse($response);
170
171 return $response->getBodyParam('license');
172 }
173
174 public function getAllUserProducts($productName = '')
175 {
176 Helper::requiredParam('access_token', $this->getAccessToken());
177
178 $params = array();
179
180 if ($productName) {
181 $params['product'] = $productName;
182 }
183
184 $response = Helper::sendGetRequest(
185 '/products',
186 $params,
187 array(
188 'access_token' => $this->getAccessToken()
189 )
190 );
191
192 Helper::validateResponse($response);
193
194 return $response->getBodyParam('products');
195 }
196
197 public function linkUrlToProduct($url, $userProductId)
198 {
199 Helper::requiredParam('access_token', $this->getAccessToken());
200 Helper::requiredParam('url', $url);
201 Helper::requiredParam('product_id', $userProductId);
202
203 $params = array(
204 'url' => $url,
205 'id' => $userProductId
206 );
207
208 $response = Helper::sendPostRequest(
209 '/products/link',
210 $params,
211 array(
212 'access_token' => $this->getAccessToken()
213 )
214 );
215
216 Helper::validateResponse($response);
217
218 return $response->getBodyParam('link_id');
219 }
220
221 //Added by Nerses
222 public function getMerchantOrderId($productName)
223 {
224 Helper::requiredParam('access_token', $this->getAccessToken());
225 Helper::requiredParam('product', $productName);
226
227 $params = array(
228 'product' => $productName
229 );
230
231 $response = Helper::sendGetRequest(
232 '/products/merchant',
233 $params,
234 array(
235 'access_token' => $this->getAccessToken()
236 )
237 );
238
239 Helper::validateResponse($response);
240
241 return $response->getBodyParam('id');
242 }
243
244 public function storeSubscriberInfo($url, $fname, $lname, $email, $priority)
245 {
246 Helper::requiredParam('url', $url);
247 Helper::requiredParam('fname', $fname);
248 Helper::requiredParam('lname', $lname);
249 Helper::requiredParam('email', $email);
250 Helper::requiredParam('priority', $priority);
251
252 $params = array(
253 'url' => $url,
254 'fname' => $fname,
255 'lname' => $lname,
256 'email' => $email,
257 'priority' => $priority,
258 'referrer' => 'wordpress-backup-free'
259 );
260
261 $response = Helper::sendPostRequest(
262 '/products/subscriber',
263 $params
264 );
265
266 Helper::validateResponse($response);
267
268 return $response->getBodyParam('subscriber');
269 }
270
271 public function storeSurveyResult($url, $firstname, $lastname, $email, $response)
272 {
273 Helper::requiredParam('url', $url);
274 Helper::requiredParam('firstname', $firstname);
275 Helper::requiredParam('lastname', $lastname);
276 Helper::requiredParam('email', $email);
277 Helper::requiredParam('response', $response);
278
279 $params = array(
280 'url' => $url,
281 'firstname' => $firstname,
282 'lastname' => $lastname,
283 'email' => $email,
284 'response' => $response,
285 'name' => SG_PRODUCT_IDENTIFIER.'-deactivation'
286 );
287
288 $response = Helper::sendPostRequest(
289 '/products/survey',
290 $params
291 );
292
293 Helper::validateResponse($response);
294
295 return $response->getBodyParam('survey');
296 }
297 }
298