PluginProbe
MailerLite – WooCommerce integration / 2.0.2
MailerLite – WooCommerce integration v2.0.2
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 / shared / api / class.woo-mailerlite-api-client.php

class.woo-mailerlite-api-client.php in MailerLite – WooCommerce integration 2.0.2, at includes/shared/api/class.woo-mailerlite-api-client.php

106 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace MailerLite\Includes\Shared\Api;
4
5 class MailerLiteClient
6 {
7
8 private $url;
9 private $headers;
10 private $timeout = 90;
11
12 /**
13 * Client constructor
14 *
15 * @access public
16 * @return void
17 * @since 1.6.0
18 */
19 public function __construct($url, $headers)
20 {
21
22 $this->url = $url;
23 $this->headers = $headers;
24 }
25
26 /**
27 * Client for GET requests
28 *
29 * @access public
30 * @since 1.6.0
31 */
32 public function remote_get($endpoint, $args = [])
33 {
34
35 $args['body'] = $args;
36 $args['headers'] = $this->headers;
37 $args['timeout'] = $this->timeout;
38 $args['user-agent'] = $this->userAgent();
39
40 return wp_remote_get($this->url . $endpoint, $args);
41 }
42
43 /**
44 * Client for POST requests
45 *
46 * @access public
47 * @since 1.6.0
48 */
49 public function remote_post($endpoint, $args = [])
50 {
51
52 $params = [];
53 $params['headers'] = $this->headers;
54 $params['body'] = json_encode($args);
55 $params['timeout'] = $this->timeout;
56 $params['user-agent'] = $this->userAgent();
57
58 return wp_remote_post($this->url . $endpoint, $params);
59 }
60
61 /**
62 * Client for PUT requests
63 *
64 * @access public
65 * @since 1.6.0
66 */
67 public function remote_put($endpoint, $args = [])
68 {
69
70 $params = [];
71 $params['method'] = 'PUT';
72 $params['headers'] = $this->headers;
73 $params['body'] = json_encode($args);
74 $params['timeout'] = $this->timeout;
75 $params['user-agent'] = $this->userAgent();
76
77 return wp_remote_post($this->url . $endpoint, $params);
78 }
79
80 /**
81 * Client for DELETE requests
82 *
83 * @access public
84 * @since 1.6.0
85 */
86 public function remote_delete($endpoint, $args = [])
87 {
88
89 $params = [];
90 $params['method'] = 'DELETE';
91 $params['headers'] = $this->headers;
92 $params['body'] = json_encode($args);
93 $params['timeout'] = $this->timeout;
94 $params['user-agent'] = $this->userAgent();
95
96 return wp_remote_post($this->url . $endpoint, $params);
97 }
98
99 private function userAgent()
100 {
101 global $wp_version;
102
103 return 'MailerLite WooCommerce/' . WOO_MAILERLITE_VER . ' (WP/' . $wp_version . ' WOO/' . get_option('woocommerce_version',
104 -1) . ')';
105 }
106 }