Completed
Push — master ( 6835a6...4d776f )
by Nate
12:26
created

ContactLists::getContacts()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 0
cts 18
cp 0
rs 9.2
c 0
b 0
f 0
cc 1
eloc 12
nc 1
nop 3
crap 2
1
<?php
2
3
namespace flipbox\hubspot\modules\http\services;
4
5
use craft\helpers\Json;
6
use flipbox\hubspot\authentication\AuthenticationStrategyInterface;
7
use flipbox\hubspot\cache\CacheStrategyInterface;
8
use flipbox\hubspot\HubSpot;
9
use Flipbox\Relay\HubSpot\Segment\ContactLists\Add;
10
use Flipbox\Relay\HubSpot\Segment\ContactLists\Remove;
11
use Flipbox\Relay\HubSpot\Segment\ContactLists\GetById;
12
use Flipbox\Relay\HubSpot\Segment\ContactLists\GetContacts;
13
use Psr\Http\Message\ResponseInterface;
14
15
class ContactLists extends AbstractResource
16
{
17
18
    /**
19
     * @param int                                  $id
20
     * @param AuthenticationStrategyInterface|null $authenticationStrategy
21
     * @param CacheStrategyInterface|null          $cacheStrategy
22
     * @return ResponseInterface
23
     */
24
    public function getContacts(
25
        int $id,
26
        AuthenticationStrategyInterface $authenticationStrategy = null,
27
        CacheStrategyInterface $cacheStrategy = null
28
    ) {
29
        // Create runner segments
30
        $segments = new GetContacts(
31
            [
32
                'id' => $id,
33
                'logger' => $this->getLogger(),
34
                'cache' => $this->resolveCacheStrategy($cacheStrategy)->getPool()
35
            ]
36
        );
37
38
        // Prepend authorization
39
        $this->prependAuthenticationMiddleware(
40
            $segments,
41
            $authenticationStrategy
42
        );
43
44
        return $segments->run();
45
    }
46
47
    /**
48
     * @param int                                  $id
49
     * @param AuthenticationStrategyInterface|null $authenticationStrategy
50
     * @param CacheStrategyInterface|null          $cacheStrategy
51
     * @return ResponseInterface
52
     */
53
    public function getById(
54
        int $id,
55
        AuthenticationStrategyInterface $authenticationStrategy = null,
56
        CacheStrategyInterface $cacheStrategy = null
57
    ) {
58
        // Create runner segments
59
        $segments = new GetById(
60
            [
61
                'id' => $id,
62
                'logger' => $this->getLogger(),
63
                'cache' => $this->resolveCacheStrategy($cacheStrategy)->getPool()
64
            ]
65
        );
66
67
        // Prepend authorization
68
        $this->prependAuthenticationMiddleware(
69
            $segments,
70
            $authenticationStrategy
71
        );
72
73
        return $segments->run();
74
    }
75
76
    /**
77
     * @param int                                  $id
78
     * @param array                                $vids
79
     * @param array                                $emails
80
     * @param AuthenticationStrategyInterface|null $authenticationStrategy
81
     * @return ResponseInterface
82
     */
83
    public function add(
84
        int $id,
85
        array $vids = [],
86
        array $emails = [],
87
        AuthenticationStrategyInterface $authenticationStrategy = null
88
    ) {
89
        // Create runner segments
90
        $segments = new Add(
91
            [
92
                'id' => $id,
93
                'vids' => $vids,
94
                'emails' => $emails,
95
                'logger' => $this->getLogger()
96
            ]
97
        );
98
99
        // Prepend authorization
100
        $this->prependAuthenticationMiddleware(
101
            $segments,
102
            $authenticationStrategy
103
        );
104
105
        return $segments->run();
106
    }
107
108
    /**
109
     * @param int                                  $id
110
     * @param array                                $vids
111
     * @param array                                $emails
112
     * @param AuthenticationStrategyInterface|null $authenticationStrategy
113
     * @return ResponseInterface
114
     */
115
    public function remove(
116
        int $id,
117
        array $vids = [],
118
        array $emails = [],
119
        AuthenticationStrategyInterface $authenticationStrategy = null
120
    ) {
121
        // Create runner segments
122
        $segments = new Remove(
123
            [
124
                'id' => $id,
125
                'vids' => $vids,
126
                'emails' => $emails,
127
                'logger' => $this->getLogger()]
128
        );
129
130
        // Prepend authorization
131
        $this->prependAuthenticationMiddleware(
132
            $segments,
133
            $authenticationStrategy
134
        );
135
136
        return $segments->run();
137
    }
138
}
139