-
Notifications
You must be signed in to change notification settings - Fork 162
/
Copy pathClient.php
120 lines (107 loc) · 2.48 KB
/
Client.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
<?php
/**
* WooCommerce REST API Client
*
* @category Client
* @package Automattic/WooCommerce
*/
namespace Automattic\WooCommerce;
use Automattic\WooCommerce\HttpClient\HttpClient;
/**
* REST API Client class.
*
* @package Automattic/WooCommerce
*/
class Client
{
/**
* WooCommerce REST API Client version.
*/
public const VERSION = '3.1.0';
/**
* HttpClient instance.
*
* @var HttpClient
*/
public $http;
/**
* @var string $id
*/
private $id;
/**
* Initialize client.
*
* @param string $url Store URL.
* @param string $consumerKey Consumer key.
* @param string $consumerSecret Consumer secret.
* @param array $options Options (version, timeout, verify_ssl, oauth_only).
*/
public function __construct($url, $consumerKey, $consumerSecret, $options = [])
{
$this->http = new HttpClient($url, $consumerKey, $consumerSecret, $options);
$this->id = md5($url);
}
/**
* POST method.
*
* @param string $endpoint API endpoint.
* @param array $data Request data.
*
* @return \stdClass
*/
public function post($endpoint, $data)
{
return $this->http->request($endpoint, 'POST', $data);
}
/**
* PUT method.
*
* @param string $endpoint API endpoint.
* @param array $data Request data.
*
* @return \stdClass
*/
public function put($endpoint, $data)
{
return $this->http->request($endpoint, 'PUT', $data);
}
/**
* GET method.
*
* @param string $endpoint API endpoint.
* @param array $parameters Request parameters.
*
* @return \stdClass
*/
public function get($endpoint, $parameters = [])
{
return $this->http->request($endpoint, 'GET', [], $parameters);
}
/**
* DELETE method.
*
* @param string $endpoint API endpoint.
* @param array $parameters Request parameters.
*
* @return \stdClass
*/
public function delete($endpoint, $parameters = [])
{
return $this->http->request($endpoint, 'DELETE', [], $parameters);
}
/**
* OPTIONS method.
*
* @param string $endpoint API endpoint.
*
* @return \stdClass
*/
public function options($endpoint)
{
return $this->http->request($endpoint, 'OPTIONS', [], []);
}
public function getId()
{
return $this->id;
}
}