Completed
Push — master ( 326e17...6e0c68 )
by Claudio
11s
created

Options::apiPrefix()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 2
eloc 2
nc 2
nop 0
1
<?php
2
/**
3
 * WooCommerce REST API HTTP Client Options
4
 *
5
 * @category HttpClient
6
 * @package  Automattic/WooCommerce
7
 */
8
9
namespace Automattic\WooCommerce\HttpClient;
10
11
/**
12
 * REST API HTTP Client Options class.
13
 *
14
 * @package Automattic/WooCommerce
15
 */
16
class Options
17
{
18
19
    /**
20
     * Default WooCommerce REST API version.
21
     */
22
    const VERSION = 'v3';
23
24
    /**
25
     * Default request timeout.
26
     */
27
    const TIMEOUT = 15;
28
29
    /**
30
     * Default WP API prefix.
31
     * Including leading and trailing slashes.
32
     */
33
    const WP_API_PREFIX = '/wp-json/';
34
35
    /**
36
     * Options.
37
     *
38
     * @var array
39
     */
40
    private $options;
41
42
    /**
43
     * Initialize HTTP client options.
44
     *
45
     * @param array $options Client options.
46
     */
47
    public function __construct($options)
48
    {
49
        $this->options = $options;
50
    }
51
52
    /**
53
     * Get API version.
54
     *
55
     * @return string
56
     */
57
    public function getVersion()
58
    {
59
        return isset($this->options['version']) ? $this->options['version'] : self::VERSION;
60
    }
61
62
    /**
63
     * Check if need to verify SSL.
64
     *
65
     * @return bool
66
     */
67
    public function verifySsl()
68
    {
69
        return isset($this->options['verify_ssl']) ? (bool) $this->options['verify_ssl'] : true;
70
    }
71
72
    /**
73
     * Get timeout.
74
     *
75
     * @return int
76
     */
77
    public function getTimeout()
78
    {
79
        return isset($this->options['timeout']) ? (int) $this->options['timeout'] : self::TIMEOUT;
80
    }
81
82
    /**
83
     * Basic Authentication as query string.
84
     * Some old servers are not able to use CURLOPT_USERPWD.
85
     *
86
     * @return bool
87
     */
88
    public function isQueryStringAuth()
89
    {
90
        return isset($this->options['query_string_auth']) ? (bool) $this->options['query_string_auth'] : false;
91
    }
92
93
    /**
94
     * Check if is WP REST API.
95
     *
96
     * @return bool
97
     */
98
    public function isWPAPI()
99
    {
100
        return isset($this->options['wp_api']) ? (bool) $this->options['wp_api'] : false;
101
    }
102
103
    /**
104
     * Custom API Prefix for WP API.
105
     * 
106
     * @return string
107
     */
108
    public function apiPrefix()
109
    {
110
        return isset($this->options['api_prefix']) ? $this->options['api_prefix'] : self::WP_API_PREFIX;
111
    }
112
}
113