Client::put()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
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 = '3.0.0';
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 \stdClass
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 \stdClass
66
     */
67
    public function put($endpoint, $data)
68
    {
69
        return $this->http->request($endpoint, 'PUT', $data);
70
    }
71
72
    /**
73
     * GET method.
74
     *
75
     * @param string $endpoint   API endpoint.
76
     * @param array  $parameters Request parameters.
77
     *
78
     * @return \stdClass
79
     */
80
    public function get($endpoint, $parameters = [])
81
    {
82
        return $this->http->request($endpoint, 'GET', [], $parameters);
83
    }
84
85
    /**
86
     * DELETE method.
87
     *
88
     * @param string $endpoint   API endpoint.
89
     * @param array  $parameters Request parameters.
90
     *
91
     * @return \stdClass
92
     */
93
    public function delete($endpoint, $parameters = [])
94
    {
95
        return $this->http->request($endpoint, 'DELETE', [], $parameters);
96
    }
97
98
    /**
99
     * OPTIONS method.
100
     *
101
     * @param string $endpoint API endpoint.
102
     *
103
     * @return \stdClass
104
     */
105
    public function options($endpoint)
106
    {
107
        return $this->http->request($endpoint, 'OPTIONS', [], []);
108
    }
109
}
110