NotificationApi::post()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 2
nop 1
1
<?php
2
/**
3
 * This file is part of the fnayou/instapush-php project.
4
 *
5
 * Copyright (c) 2017. Aymen FNAYOU <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Fnayou\InstapushPHP\Api;
12
13
use Fnayou\InstapushPHP\Exception\ApiException;
14
use Fnayou\InstapushPHP\Model\Notification;
15
16
/**
17
 * Class NotificationApi.
18
 */
19
class NotificationApi extends AbstractApi
20
{
21
    /**
22
     * @param \Fnayou\InstapushPHP\Model\Notification $notification
23
     *
24
     * @throws \Fnayou\InstapushPHP\Exception\ApiException
25
     *
26
     * @return bool
27
     */
28
    public function post(Notification $notification)
29
    {
30
        $notificationApi = $this->doPost('/post', $notification->toArray());
31
32
        if (200 !== $notificationApi->getResponse()->getStatusCode()
33
            && 201 !== $notificationApi->getResponse()->getStatusCode()) {
34
            throw new ApiException('cannot send notification', $this->getRequest(), $this->getResponse());
35
        }
36
37
        return true;
38
    }
39
}
40