Completed
Push — master ( 461c20...02a675 )
by Chris
01:56
created

Request::setRequestURL()   A

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