Completed
Push — develop ( eb315e...09dc45 )
by Chris
03:29
created

Request::makeRequest()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 24
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 24
rs 8.9713
cc 2
eloc 13
nc 2
nop 3
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", $data = null)
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
            'json' => $data
41
        ]);
42
43
        $response = (string) $this->request->getBody();
44
        $this->response = @json_decode($response);
45
46
        return $this;
47
    }
48
49
    public function getResponse()
50
    {
51
        return $this->response;
52
    }
53
}
54