|
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\Contact; |
|
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
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @author Flipbox Factory <[email protected]> |
|
19
|
|
|
* @since 1.0.3 |
|
20
|
|
|
*/ |
|
21
|
|
|
class Batch extends HttpRelayBuilder |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* The node |
|
25
|
|
|
*/ |
|
26
|
|
|
const NODE = 'contacts'; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* The resource |
|
30
|
|
|
*/ |
|
31
|
|
|
const RESOURCE = 'contact/batch'; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Upsert constructor. |
|
35
|
|
|
* @param array $payload |
|
36
|
|
|
* @param AuthorizationInterface $authorization |
|
37
|
|
|
* @param LoggerInterface|null $logger |
|
38
|
|
|
* @param array $config |
|
39
|
|
|
*/ |
|
40
|
|
|
public function __construct( |
|
41
|
|
|
array $payload, |
|
42
|
|
|
AuthorizationInterface $authorization, |
|
43
|
|
|
LoggerInterface $logger = null, |
|
44
|
|
|
$config = [] |
|
45
|
|
|
) { |
|
46
|
|
|
parent::__construct($authorization, $logger, $config); |
|
47
|
|
|
|
|
48
|
|
|
$this->addUri($logger) |
|
49
|
|
|
->addPayload($payload, $logger); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param array $payload |
|
54
|
|
|
* @param LoggerInterface|null $logger |
|
55
|
|
|
* @return $this |
|
56
|
|
|
*/ |
|
57
|
|
|
protected function addPayload(array $payload, LoggerInterface $logger = null) |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->addAfter('body', [ |
|
60
|
|
|
'class' => JsonMiddleware::class, |
|
61
|
|
|
'payload' => $payload, |
|
62
|
|
|
'logger' => $logger ?: $this->getLogger() |
|
63
|
|
|
], 'uri'); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @param LoggerInterface|null $logger |
|
68
|
|
|
* @return $this |
|
69
|
|
|
*/ |
|
70
|
|
|
protected function addUri(LoggerInterface $logger = null) |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->addBefore('uri', [ |
|
73
|
|
|
'class' => ResourceV1::class, |
|
74
|
|
|
'method' => 'POST', |
|
75
|
|
|
'node' => self::NODE, |
|
76
|
|
|
'resource' => self::RESOURCE, |
|
77
|
|
|
'logger' => $logger ?: $this->getLogger() |
|
78
|
|
|
]); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|