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

Events   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 14
dl 0
loc 40
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A list() 0 12 3
A store() 0 9 1
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