Passed
Pull Request — master (#3)
by Gombos
02:02
created

Events::list()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 2
nop 2
dl 0
loc 11
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->sendGet(
26
            ':account_id:/event_actions',
27
            [
28
                'page'     => $page,
29
                'per_page' => $perPage,
30
            ]
31
        );
32
    }
33
34
    /**
35
     * Record an event
36
     * @see https://developer.drip.com/?shell#events
37
     *
38
     * @param Event $event
39
     *
40
     * @return bool
41
     */
42
    public function store(Event $event): bool
43
    {
44
        $response = $this->sendPost(
45
            ':account_id:/events',
46
            $event->toDrip()
47
        );
48
49
        return $response->isSuccess();
50
    }
51
}
52