Events   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
eloc 25
dl 0
loc 71
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A store() 0 8 1
A batchStore() 0 25 4
A list() 0 11 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
     * @return \Glorand\Drip\Api\Response\ApiResponse
16
     * @throws \Glorand\Drip\Exceptions\DripException
17
     */
18 2
    public function list(int $page = 1, int $perPage = 100): ApiResponse
19
    {
20 2
        if (1 > $perPage || 1000 < $perPage) {
21 2
            throw new DripException('Invalid per page; maximum 1000');
22
        }
23
24 1
        return $this->sendGet(
25 1
            ':account_id:/event_actions',
26
            [
27 1
                'page'     => $page,
28 1
                'per_page' => $perPage,
29
            ]
30
        );
31
    }
32
33
    /**
34
     * Record an event
35
     * @see https://developer.drip.com/?shell#events
36
     * @param \Glorand\Drip\Models\Event $event
37
     *
38
     * @return bool
39
     */
40 1
    public function store(Event $event): bool
41
    {
42 1
        $response = $this->sendPost(
43 1
            ':account_id:/events',
44 1
            $event->toDrip()
45
        );
46
47 1
        return $response->isSuccess();
48
    }
49
50
    /**
51
     * @param array $events
52
     *
53
     * @return bool
54
     */
55 1
    public function batchStore(array $events)
56
    {
57 1
        $data = [];
58 1
        foreach ($events as $event) {
59 1
            if (is_array($event)) {
60 1
                $data[] = $event;
61 1
            } elseif ($event instanceof Event) {
62 1
                $data[] = $event->jsonSerialize();
63
            }
64
        }
65
66
        $postData = [
67
            'batches' => [
68
                [
69 1
                    'events' => $data,
70
                ],
71
            ],
72
        ];
73
74 1
        $response = $this->sendPost(
75 1
            ':account_id:/events/batches',
76 1
            $postData
77
        );
78
79 1
        return $response->isSuccess();
80
    }
81
}
82