Completed
Pull Request — master (#19)
by Yuan
01:59
created

SlotManager::delete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Acquia\LiftClient\Manager;
4
5
use Acquia\LiftClient\Entity\Slot;
6
use GuzzleHttp\Psr7\Request;
7
8
class SlotManager extends ManagerBase
9
{
10
    /**
11
     * {@inheritdoc}
12
     */
13
    protected $queryParameters = [
14
        'visible_on_page' => null,
15
        'status' => null,
16
    ];
17
18
    /**
19
     * Get a list of slots.
20
     *
21
     * Example of how to structure the $options parameter:
22
     * <code>
23
     * $options = [
24
     *     'visible_on_page'  => 'http://localhost/blog/*',
25
     *     'status' => 'enabled',
26
     * ];
27
     * </code>
28
     *
29
     * @see http://docs.decision-api.acquia.com/#slots_get
30
     *
31
     * @param array $options
32
     *
33
     * @throws \GuzzleHttp\Exception\RequestException
34
     *
35
     * @return \Acquia\LiftClient\Entity\Slot[]
36
     */
37 8 View Code Duplication
    public function query($options = [])
38
    {
39 6
        $url = '/slots';
40 6
        $url .= $this->getQueryString($options);
41
42
        // Now make the request.
43 6
        $request = new Request('GET', $url);
44 6
        $data = $this->getResponseJson($request);
45
46
        // Get them as Slot objects
47 3
        $slots = [];
48 3
        foreach ($data as $dataItem) {
49 3
            $slots[] = new Slot($dataItem);
50 2
        }
51
52 7
        return $slots;
53
    }
54
55
    /**
56
     * Get a specific slot.
57
     *
58
     * Example of how to structure the $options parameter:
59
     *
60
     * @see http://docs.decision-api.acquia.com/#slots__slotId__get
61
     *
62
     * @param array $id
63
     *
64
     * @throws \GuzzleHttp\Exception\RequestException
65
     *
66
     * @return \Acquia\LiftClient\Entity\Slot
67
     */
68 6 View Code Duplication
    public function get($id)
69
    {
70 6
        $url = "/slots/{$id}";
71
72
        // Now make the request.
73 6
        $request = new Request('GET', $url);
74 6
        $data = $this->getResponseJson($request);
75
76 3
        return new Slot($data);
77
    }
78
79
    /**
80
     * Add a slot.
81
     *
82
     * @param \Acquia\LiftClient\Entity\Slot $slot
83
     *
84
     * @throws \GuzzleHttp\Exception\RequestException
85
     *
86
     * @return \Acquia\LiftClient\Entity\Slot
87
     */
88 6 View Code Duplication
    public function add(Slot $slot)
89
    {
90 6
        $body = $slot->json();
91 6
        $url = '/slots';
92 6
        $request = new Request('POST', $url, [], $body);
93 6
        $data = $this->getResponseJson($request);
94
95 3
        return new Slot($data);
96
    }
97
98
    /**
99
     * Deletes a slot by ID.
100
     *
101
     * @param string $id
102
     *
103
     * @throws \GuzzleHttp\Exception\RequestException
104
     *
105
     * @return bool
106
     */
107 6
    public function delete($id)
108
    {
109 6
        $url = "/slots/{$id}";
110 6
        $this->client->delete($url);
111
112 3
        return true;
113
    }
114
}
115