Request::getRequestURL()   A
last analyzed

Complexity

Conditions 1
Paths 1

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 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * @author Chris Hilsdon <[email protected]>
4
 */
5
namespace Cloudflare\Traits;
6
7
trait Request
8
{
9
    protected $request;
10
    protected $response;
11
    protected $RequestURL;
12
    public $CF;
13
14
    public function getRequestURL()
15
    {
16
        return $this->RequestURL;
17
    }
18
19
    public function setRequestURL($url)
20
    {
21
        $this->RequestURL = $url;
22
    }
23
24
    public function makeRequest($request = "", $type = "GET")
25
    {
26
        $this->setRequestURL($this->CF->getEndpoint() . $request);
27
28
        //Use in testing to not actualy make the request
29
        if ($this->CF->getMakeRequests() === false) {
30
            return true;
31
        }
32
33
        $client = $this->CF->getGuzzle();
34
35
        $this->request = $client->request($type, $this->getRequestURL(), [
36
            'headers' => [
37
                'X-Auth-Key' => $this->CF->getAPIKey(),
38
                'X-Auth-Email' => $this->CF->getEmail()
39
            ]
40
        ]);
41
42
        $response = (string) $this->request->getBody();
43
        $this->response = @json_decode($response);
44
45
        return $this;
46
    }
47
48
    public function getResponse()
49
    {
50
        return $this->response;
51
    }
52
}
53