Passed
Pull Request — master (#3)
by Gombos
03:08 queued 42s
created

Events::all()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 2
nop 2
dl 0
loc 12
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Glorand\Drip\Api;
4
5
use Glorand\Drip\Api\Response\ApiResponse;
6
use Glorand\Drip\Exceptions\DripException;
7
use Glorand\Drip\Models\Event;
8
9
class Events extends Api
10
{
11
    /**
12
     * @param int $page
13
     * @param int $perPage
14
     *
15
     * @throws DripException
16
     *
17
     * @return Response\ApiResponse
18
     */
19
    public function list(int $page = 1, int $perPage = 100): ApiResponse
20
    {
21
        if (1 > $perPage || 1000 < $perPage) {
22
            throw new DripException('Invalid per page; maximum 1000');
23
        }
24
25
        return $this->makeRequest(
26
            self::GET,
27
            $this->prepareUrl('/:account_id:/event_actions'),
28
            [
29
                'page'     => $page,
30
                'per_page' => $perPage,
31
            ]
32
        );
33
    }
34
35
    /**
36
     * @param Event $event
37
     *
38
     * @return bool
39
     */
40
    public function store(Event $event): bool
41
    {
42
        $response = $this->makeRequest(
43
            self::POST,
44
            $this->prepareUrl('/:account_id:/event_actions'),
45
            $event->jsonSerialize()
46
        );
47
48
        return $response->isSuccess();
49
    }
50
}
51