PluginProbe
MailerLite – WooCommerce integration / 3.1.27
MailerLite – WooCommerce integration v3.1.27
3.1.27 3.1.25 3.1.26 3.1.24 3.1.23 3.1.22 3.1.21 3.1.20 3.1.19 3.1.18 3.1.17 3.1.16 3.1.15 1.8.7 1.8.8 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 All 148 releases
woo-mailerlite / includes / api / WooMailerLiteApiResponse.php

WooMailerLiteApiResponse.php in MailerLite – WooCommerce integration 3.1.27, at includes/api/WooMailerLiteApiResponse.php

50 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class WooMailerLiteApiResponse
4 {
5 public $status = 200;
6 public $success = true;
7 public $data = null;
8 public $message = '';
9 public $links = null;
10 public function __construct($response, $status = null)
11 {
12 $this->generateResponse($response, $status);
13 }
14
15 public function generateResponse($response)
16 {
17 $this->status = wp_remote_retrieve_response_code($response);
18 $this->data = json_decode(wp_remote_retrieve_body($response)) ?? null;
19 if (isset($this->data->links)) {
20 $this->links = $this->data->links;
21 }
22 if (isset($this->data->data)) {
23 $this->data = $this->data->data;
24 }
25 if (isset($this->data->errors)) {
26 $this->success = false;
27 $this->status = 400;
28 $this->message = $this->data->errors;
29 }
30 if (isset($response->errors) || $this->status >= 400) {
31 $this->success = false;
32 $this->data = $response->errors ?? $this->data;
33 }
34 }
35
36 public function setResponse($response, $status = 200)
37 {
38 $this->data = $response;
39 $this->status = $status;
40 return $this;
41 }
42
43 public function addData($key, $value)
44 {
45 if (isset($this->data)) {
46 $this->data->$key = $value;
47 }
48 return $this;
49 }
50 }