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

Events   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A store() 0 9 1
A list() 0 12 3
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
     * @return bool
38
     */
39
    public function store(Event $event): bool
40
    {
41
        $response = $this->makeRequest(
42
            self::POST,
43
            $this->prepareUrl('/:account_id:/event_actions'),
44
            $event->jsonSerialize()
45
        );
46
47
        return $response->isSuccess();
48
    }
49
}
50