RoomAPI   A
last analyzed

Complexity

Total Complexity 18

Size/Duplication

Total Lines 150
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 150
ccs 55
cts 55
cp 1
rs 10
c 0
b 0
f 0
wmc 18

15 Methods

Rating   Name   Duplication   Size   Complexity  
A deleteRoom() 0 3 1
A createRoom() 0 5 1
A addMember() 0 3 1
A deleteWebhook() 0 3 1
A setTopic() 0 3 1
A getRoom() 0 5 1
A updateRoom() 0 3 1
A createWebhook() 0 5 1
A removeMember() 0 3 1
A sendRoomNotification() 0 4 1
A __construct() 0 3 1
A inviteUser() 0 3 1
A getRooms() 0 9 2
A getAllWebhooks() 0 9 2
A getRecentHistory() 0 9 2
1
<?php
2
3
namespace SolutionDrive\HipchatAPIv2Client\API;
4
5
use SolutionDrive\HipchatAPIv2Client\ClientInterface;
6
use SolutionDrive\HipchatAPIv2Client\Model\Message;
7
use SolutionDrive\HipchatAPIv2Client\Model\MessageInterface;
8
use SolutionDrive\HipchatAPIv2Client\Model\Room;
9
use SolutionDrive\HipchatAPIv2Client\Model\RoomInterface;
10
use SolutionDrive\HipchatAPIv2Client\Model\Webhook;
11
use SolutionDrive\HipchatAPIv2Client\Model\WebhookInterface;
12
13
14
class RoomAPI implements RoomAPIInterface
15
{
16
    /** @var ClientInterface */
17
    protected $client;
18
19
    /**
20
     * Room api constructor
21
     *
22
     * @param ClientInterface $client that will be used to connect the server
23
     */
24 15
    public function __construct(ClientInterface $client)
25
    {
26 15
        $this->client = $client;
27 15
    }
28
29
    /**
30
     * @inheritdoc
31
     */
32 1
    public function getRooms($params = array())
33
    {
34 1
        $response = $this->client->get("/v2/room", $params);
35
36 1
        $rooms = array();
37 1
        foreach ($response['items'] as $response) {
38 1
            $rooms[] = new Room($response);
39
        }
40 1
        return $rooms;
41
    }
42
43
    /**
44
     * @inheritdoc
45
     */
46 1
    public function getRoom($id)
47
    {
48 1
        $response = $this->client->get("/v2/room/$id");
49
50 1
        return new Room($response);
51
    }
52
53
    /**
54
     * @inheritdoc
55
     */
56 1
    public function getRecentHistory($id, $params = array())
57
    {
58 1
        $response = $this->client->get(sprintf('/v2/room/%s/history/latest', $id), $params);
59
60 1
        $messages = array();
61 1
        foreach ($response['items'] as $response) {
62 1
            $messages[] = new Message($response);
63
        }
64 1
        return $messages;
65
    }
66
67
    /**
68
     * @inheritdoc
69
     */
70 1
    public function createRoom(RoomInterface $room)
71
    {
72 1
        $response = $this->client->post("/v2/room", $room->toJson());
73
74 1
        return $response['id'];
75
    }
76
77
    /**
78
     * @inheritdoc
79
     */
80 1
    public function updateRoom(RoomInterface $room)
81
    {
82 1
        $this->client->put(sprintf("/v2/room/%s", $room->getId()), $room->toJson());
83 1
    }
84
85
    /**
86
     * @inheritdoc
87
     */
88 1
    public function deleteRoom($id)
89
    {
90 1
        $this->client->delete(sprintf('/v2/room/%s', $id));
91 1
    }
92
93
    /**
94
     * @inheritdoc
95
     */
96 1
    public function sendRoomNotification($id, MessageInterface $message)
97
    {
98 1
        $id = rawurlencode($id);
99 1
        $this->client->post("/v2/room/$id/notification", $message->toJson());
100 1
    }
101
102
    /**
103
     * @inheritdoc
104
     */
105 1
    public function addMember($roomId, $memberId)
106
    {
107 1
        $this->client->put(sprintf('/v2/room/%s/member/%s', $roomId, $memberId));
108 1
    }
109
110
    /**
111
     * @inheritdoc
112
     */
113 1
    public function removeMember($roomId, $memberId)
114
    {
115 1
        $this->client->delete(sprintf('/v2/room/%s/member/%s', $roomId, $memberId));
116 1
    }
117
118
    /**
119
     * @inheritdoc
120
     */
121 1
    public function inviteUser($roomId, $memberId, $reason)
122
    {
123 1
        $this->client->post(sprintf('/v2/room/%s/invite/%s', $roomId, $memberId), array('reason' => $reason));
124 1
    }
125
126
    /**
127
     * @inheritdoc
128
     */
129 1
    public function setTopic($roomId, $topic)
130
    {
131 1
        $this->client->put(sprintf('/v2/room/%s/topic', $roomId), array('topic' => $topic));
132 1
    }
133
134
    /**
135
     * @inheritdoc
136
     */
137 1
    public function createWebhook($roomId, WebhookInterface $webhook)
138
    {
139 1
        $response = $this->client->post(sprintf('/v2/room/%s/webhook', $roomId), $webhook->toJson());
140
141 1
        return $response['id'];
142
    }
143
144
    /**
145
     * @inheritdoc
146
     */
147 1
    public function deleteWebhook($roomId, $webhookId)
148
    {
149 1
        $this->client->delete(sprintf('/v2/room/%s/webhook/%s', $roomId, $webhookId));
150 1
    }
151
152
    /**
153
     * @inheritdoc
154
     */
155 1
    public function getAllWebhooks($roomId)
156
    {
157 1
        $webhooks = array();
158 1
        $response = $this->client->get(sprintf('/v2/room/%s/webhook', $roomId));
159 1
        foreach ($response['items'] as $item) {
160 1
            $webhooks[] = new Webhook($item);
161
        }
162
163 1
        return $webhooks;
164
    }
165
}
166