Completed
Push — develop ( 15f6f1...6d4cdf )
by Chris
52:46
created

Zone::getDetails()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
/*
3
 * @author Chris Hilsdon <[email protected]>
4
 *
5
 * @link https://api.cloudflare.com/#zone
6
 */
7
namespace Cloudflare;
8
9
class Zone extends Base
10
{
11
    protected $URL = "zones";
12
13
    /**
14
     *
15
     * @link https://api.cloudflare.com/#zone-list-zones
16
     */
17
    public function getAll()
18
    {
19
        $this->makeRequest($this->URL);
20
        return $this->getResponse();
21
    }
22
23
    /**
24
     *
25
     * @link https://api.cloudflare.com/#zone-list-zones
26
     */
27
    public function get($name = '', $options = [])
28
    {
29
        $defaultOptions = [
30
            'status' => 'active',
31
            'page' => 1,
32
            'per_page' => 20,
33
            'order' => 'status',
34
            'direction' => 'asc',
35
            'match' => 'all',
36
        ];
37
38
        $newOptions = [
39
            'name' => $name
40
        ];
41
42
        $newOptions = array_merge($newOptions, $defaultOptions, $options);
43
44
        $string = "?";
45
        foreach ($newOptions as $k => $v) {
46
            $string .= $k . '=' . $v . '&';
47
        }
48
49
        //Remove the last '&'
50
        $string = substr($string, 0, -1);
51
52
        $this->makeRequest($this->URL . $string);
53
54
        return $this->getResponse();
55
    }
56
57
    public function getDetails($zoneID)
58
    {
59
        $this->makeRequest($this->URL . '/' . $zoneID);
60
61
        return $this->getResponse();
62
    }
63
64
    public function clearCache($zoneId)
65
    {
66
        $this->makeRequest(
67
            $this->URL . '/' . $zoneId . '/purge_cache',
68
            'DELETE',
69
            ['purge_everything' => true]
70
        );
71
72
        return $this->getResponse();
73
    }
74
}
75