Completed
Pull Request — master (#79)
by
unknown
04:16
created

Client::patch()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
/**
3
 * WooCommerce REST API Client
4
 *
5
 * @category Client
6
 * @package  Automattic/WooCommerce
7
 */
8
9
namespace Automattic\WooCommerce;
10
11
use Automattic\WooCommerce\HttpClient\HttpClient;
12
13
/**
14
 * REST API Client class.
15
 *
16
 * @package Automattic/WooCommerce
17
 */
18
class Client
19
{
20
21
    /**
22
     * WooCommerce REST API Client version.
23
     */
24
    const VERSION = '1.1.4';
25
26
    /**
27
     * HttpClient instance.
28
     *
29
     * @var HttpClient
30
     */
31
    public $http;
32
33
    /**
34
     * Initialize client.
35
     *
36
     * @param string $url            Store URL.
37
     * @param string $consumerKey    Consumer key.
38
     * @param string $consumerSecret Consumer secret.
39
     * @param array  $options        Options (version, timeout, verify_ssl).
40
     */
41
    public function __construct($url, $consumerKey, $consumerSecret, $options = [])
42
    {
43
        $this->http = new HttpClient($url, $consumerKey, $consumerSecret, $options);
44
    }
45
46
    /**
47
     * POST method.
48
     *
49
     * @param string $endpoint API endpoint.
50
     * @param array  $data     Request data.
51
     *
52
     * @return array
53
     */
54
    public function post($endpoint, $data)
55
    {
56
        return $this->http->request($endpoint, 'POST', $data);
57
    }
58
59
    /**
60
     * PUT method.
61
     *
62
     * @param string $endpoint API endpoint.
63
     * @param array  $data     Request data.
64
     *
65
     * @return array
66
     */
67
    public function put($endpoint, $data)
68
    {
69
        return $this->http->request($endpoint, 'PUT', $data);
70
    }
71
72
    /**
73
     * PATCH method.
74
     *
75
     * @param string $endpoint API endpoint.
76
     * @param array  $data     Request data.
77
     *
78
     * @return array
79
     */
80
    public function patch($endpoint, $data)
81
    {
82
        return $this->http->request($endpoint, 'PATCH', $data);
83
    }
84
85
    /**
86
     * GET method.
87
     *
88
     * @param string $endpoint   API endpoint.
89
     * @param array  $parameters Request parameters.
90
     *
91
     * @return array
92
     */
93
    public function get($endpoint, $parameters = [])
94
    {
95
        return $this->http->request($endpoint, 'GET', [], $parameters);
96
    }
97
98
    /**
99
     * DELETE method.
100
     *
101
     * @param string $endpoint   API endpoint.
102
     * @param array  $parameters Request parameters.
103
     *
104
     * @return array
105
     */
106
    public function delete($endpoint, $parameters = [])
107
    {
108
        return $this->http->request($endpoint, 'DELETE', [], $parameters);
109
    }
110
111
    /**
112
     * OPTIONS method.
113
     *
114
     * @param string $endpoint API endpoint.
115
     *
116
     * @return array
117
     */
118
    public function options($endpoint)
119
    {
120
        return $this->http->request($endpoint, 'OPTIONS', [], []);
121
    }
122
}
123