1 | <?php |
||
14 | class Api |
||
15 | { |
||
16 | /** |
||
17 | * Holds the provided email address for API authentication |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | public $email; |
||
22 | |||
23 | /** |
||
24 | * Holds the provided auth_key for API authentication |
||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | public $auth_key; |
||
29 | |||
30 | /** |
||
31 | * Holds the request object to perform API requests |
||
32 | * |
||
33 | * @var RequestInterface |
||
34 | */ |
||
35 | public $request; |
||
36 | |||
37 | /** |
||
38 | * Holds the curl options |
||
39 | * |
||
40 | * @var array |
||
41 | */ |
||
42 | public $curl_options; |
||
43 | |||
44 | /** |
||
45 | * Make a new instance of the API client |
||
46 | * This can be done via providing the email address and api key as seperate parameters |
||
47 | * or by passing in an already instantiated object from which the details will be extracted |
||
48 | */ |
||
49 | public function __construct() |
||
69 | |||
70 | /** |
||
71 | * Setter to allow the setting of the email address |
||
72 | * |
||
73 | * @param string $email The email address associated with the Cloudflare account |
||
74 | */ |
||
75 | public function setEmail($email) |
||
79 | |||
80 | /** |
||
81 | * Setter to allow the setting of the Authentication Key |
||
82 | * |
||
83 | * @param string $token Authentication key, this can be retrieve from the 'My Account' section of the Cloudflare account |
||
84 | */ |
||
85 | public function setAuthKey($token) |
||
89 | |||
90 | /** |
||
91 | * Setter to change request object |
||
92 | * |
||
93 | * @param RequestInterface $request The request object to perform API requests |
||
94 | */ |
||
95 | public function setRequest($request) |
||
99 | |||
100 | /** |
||
101 | * Setter to allow the adding / changing of the Curl options that will be used within the HTTP requests |
||
102 | * |
||
103 | * @param int $key The CURLOPT_XXX option to set e.g. CURLOPT_TIMEOUT |
||
104 | * @param mixed $value The value to be set on option e.g. 10 |
||
105 | */ |
||
106 | public function setCurlOption($key, $value) |
||
110 | |||
111 | /** |
||
112 | * API call method for sending requests using GET |
||
113 | * |
||
114 | * @param string $path Path of the endpoint |
||
115 | * @param array|null $data Data to be sent along with the request |
||
116 | * |
||
117 | * @return mixed |
||
118 | */ |
||
119 | public function get($path, array $data = null) |
||
123 | |||
124 | /** |
||
125 | * API call method for sending requests using POST |
||
126 | * |
||
127 | * @param string $path Path of the endpoint |
||
128 | * @param array|null $data Data to be sent along with the request |
||
129 | * |
||
130 | * @return mixed |
||
131 | */ |
||
132 | public function post($path, array $data = null) |
||
136 | |||
137 | /** |
||
138 | * API call method for sending requests using PUT |
||
139 | * |
||
140 | * @param string $path Path of the endpoint |
||
141 | * @param array|null $data Data to be sent along with the request |
||
142 | * |
||
143 | * @return mixed |
||
144 | */ |
||
145 | public function put($path, array $data = null) |
||
149 | |||
150 | /** |
||
151 | * API call method for sending requests using DELETE |
||
152 | * |
||
153 | * @param string $path Path of the endpoint |
||
154 | * @param array|null $data Data to be sent along with the request |
||
155 | * |
||
156 | * @return mixed |
||
157 | */ |
||
158 | public function delete($path, array $data = null) |
||
162 | |||
163 | /** |
||
164 | * API call method for sending requests using PATCH |
||
165 | * |
||
166 | * @param string $path Path of the endpoint |
||
167 | * @param array|null $data Data to be sent along with the request |
||
168 | * |
||
169 | * @return mixed |
||
170 | */ |
||
171 | public function patch($path, array $data = null) |
||
175 | |||
176 | /** |
||
177 | * @codeCoverageIgnore |
||
178 | * |
||
179 | * API call method for sending requests using GET, POST, PUT, DELETE OR PATCH |
||
180 | * |
||
181 | * @param string $path Path of the endpoint |
||
182 | * @param array|null $data Data to be sent along with the request |
||
183 | * @param string|null $method Type of method that should be used ('GET', 'POST', 'PUT', 'DELETE', 'PATCH') |
||
184 | * |
||
185 | * @throws \Cloudflare\Exception\UnauthorizedException |
||
186 | * @throws \Cloudflare\Exception\AuthenticationException |
||
187 | * |
||
188 | * @return mixed |
||
189 | */ |
||
190 | protected function request($path, array $data = null, $method = null) |
||
194 | } |
||
195 |