1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (c) Flipbox Digital Limited |
5
|
|
|
* @license https://github.com/flipbox/relay-hubspot/blob/master/LICENSE |
6
|
|
|
* @link https://github.com/flipbox/relay-hubspot |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Flipbox\Relay\HubSpot\Builder\Resources\ContactList\Contacts; |
10
|
|
|
|
11
|
|
|
use Flipbox\Relay\HubSpot\AuthorizationInterface; |
12
|
|
|
use Flipbox\Relay\HubSpot\Builder\HttpRelayBuilder; |
13
|
|
|
use Flipbox\Relay\HubSpot\Middleware\JsonRequest as JsonMiddleware; |
14
|
|
|
use Flipbox\Relay\HubSpot\Middleware\ResourceV1; |
15
|
|
|
use Psr\Log\LoggerInterface; |
16
|
|
|
use Psr\SimpleCache\CacheInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @author Flipbox Factory <[email protected]> |
20
|
|
|
* @since 1.0.0 |
21
|
|
|
*/ |
22
|
|
|
class Add extends HttpRelayBuilder |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* The node |
26
|
|
|
*/ |
27
|
|
|
const NODE = 'contacts'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* The resource |
31
|
|
|
*/ |
32
|
|
|
const RESOURCE = 'lists'; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param string $id |
36
|
|
|
* @param array $payload |
37
|
|
|
* @param AuthorizationInterface $authorization |
38
|
|
|
* @param CacheInterface $cache |
39
|
|
|
* @param LoggerInterface|null $logger |
40
|
|
|
* @param array $config |
41
|
|
|
*/ |
42
|
|
|
public function __construct( |
43
|
|
|
string $id, |
44
|
|
|
array $payload, |
45
|
|
|
AuthorizationInterface $authorization, |
46
|
|
|
CacheInterface $cache, |
|
|
|
|
47
|
|
|
LoggerInterface $logger = null, |
48
|
|
|
$config = [] |
49
|
|
|
) { |
50
|
|
|
parent::__construct($authorization, $logger, $config); |
51
|
|
|
|
52
|
|
|
$this->addUri($id, $logger) |
53
|
|
|
->addPayload($payload, $logger); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param array $payload |
58
|
|
|
* @param LoggerInterface|null $logger |
59
|
|
|
* @return $this |
60
|
|
|
*/ |
61
|
|
|
protected function addPayload(array $payload, LoggerInterface $logger = null) |
62
|
|
|
{ |
63
|
|
|
return $this->addAfter('body', [ |
64
|
|
|
'class' => JsonMiddleware::class, |
65
|
|
|
'payload' => $payload, |
66
|
|
|
'logger' => $logger ?: $this->getLogger() |
67
|
|
|
], 'uri'); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param string $id |
72
|
|
|
* @param LoggerInterface|null $logger |
73
|
|
|
* @return $this |
74
|
|
|
*/ |
75
|
|
|
protected function addUri(string $id, LoggerInterface $logger = null) |
76
|
|
|
{ |
77
|
|
|
return $this->addBefore('uri', [ |
78
|
|
|
'class' => ResourceV1::class, |
79
|
|
|
'method' => 'POST', |
80
|
|
|
'node' => self::NODE, |
81
|
|
|
'resource' => self::RESOURCE . '/' . $id . '/add', |
82
|
|
|
'logger' => $logger ?: $this->getLogger() |
83
|
|
|
]); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.