|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @copyright Copyright (c) Flipbox Digital Limited |
|
5
|
|
|
* @license https://flipboxfactory.com/software/hubspot/license |
|
6
|
|
|
* @link https://www.flipboxfactory.com/software/hubspot/ |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace flipbox\hubspot\services\resources; |
|
10
|
|
|
|
|
11
|
|
|
use flipbox\hubspot\connections\IntegrationConnectionInterface; |
|
12
|
|
|
use flipbox\hubspot\criteria\TimelineEventCriteria; |
|
13
|
|
|
use flipbox\hubspot\helpers\TransformerHelper; |
|
14
|
|
|
use flipbox\hubspot\HubSpot; |
|
15
|
|
|
use flipbox\hubspot\pipeline\Resource; |
|
16
|
|
|
use flipbox\hubspot\transformers\collections\TransformerCollectionInterface; |
|
17
|
|
|
use Flipbox\Relay\HubSpot\Builder\Resources\Timeline\UpsertEvent; |
|
18
|
|
|
use League\Pipeline\PipelineBuilderInterface; |
|
19
|
|
|
use yii\base\Component; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @author Flipbox Factory <[email protected]> |
|
23
|
|
|
* @since 1.0.0 |
|
24
|
|
|
*/ |
|
25
|
|
|
class TimelineEvents extends Component |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* The HubSpot Resource name |
|
29
|
|
|
*/ |
|
30
|
|
|
const HUBSPOT_RESOURCE = 'timelineEvents'; |
|
31
|
|
|
|
|
32
|
|
|
/******************************************* |
|
33
|
|
|
* UPSERT |
|
34
|
|
|
*******************************************/ |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param string $id |
|
38
|
|
|
* @param string $typeId |
|
39
|
|
|
* @param array $payload |
|
40
|
|
|
* @param IntegrationConnectionInterface $connection |
|
41
|
|
|
* @param TransformerCollectionInterface|null $transformer |
|
42
|
|
|
* @param mixed|null $source |
|
43
|
|
|
* @return mixed |
|
44
|
|
|
*/ |
|
45
|
|
|
public function upsert( |
|
46
|
|
|
string $id, |
|
47
|
|
|
string $typeId, |
|
48
|
|
|
array $payload, |
|
49
|
|
|
IntegrationConnectionInterface $connection, |
|
50
|
|
|
TransformerCollectionInterface $transformer = null, |
|
51
|
|
|
$source = null |
|
52
|
|
|
) { |
|
53
|
|
|
return $this->upsertPipeline( |
|
54
|
|
|
$id, |
|
55
|
|
|
$typeId, |
|
56
|
|
|
$payload, |
|
57
|
|
|
$connection, |
|
58
|
|
|
$transformer |
|
59
|
|
|
)($source); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @param string $id |
|
64
|
|
|
* @param string $typeId |
|
65
|
|
|
* @param array $payload |
|
66
|
|
|
* @param IntegrationConnectionInterface $connection |
|
67
|
|
|
* @param TransformerCollectionInterface|null $transformer |
|
68
|
|
|
* @return Resource |
|
69
|
|
|
*/ |
|
70
|
|
|
public function upsertPipeline( |
|
71
|
|
|
string $id, |
|
72
|
|
|
string $typeId, |
|
73
|
|
|
array $payload, |
|
74
|
|
|
IntegrationConnectionInterface $connection, |
|
75
|
|
|
TransformerCollectionInterface $transformer = null |
|
76
|
|
|
): PipelineBuilderInterface { |
|
77
|
|
|
$transformer = TransformerHelper::populateTransformerCollection($transformer, [ |
|
78
|
|
|
'resource' => [UpsertEvent::class] |
|
79
|
|
|
]); |
|
80
|
|
|
|
|
81
|
|
|
$payload['id'] = $id; |
|
82
|
|
|
$payload['eventTypeId'] = $typeId; |
|
83
|
|
|
|
|
84
|
|
|
$logger = HubSpot::getInstance()->getPsrLogger(); |
|
85
|
|
|
|
|
86
|
|
|
return (new Resource( |
|
87
|
|
|
(new UpsertEvent( |
|
88
|
|
|
$connection->getAppId(), |
|
89
|
|
|
$payload, |
|
90
|
|
|
$connection, |
|
91
|
|
|
$logger |
|
92
|
|
|
))->build(), |
|
93
|
|
|
$transformer, |
|
94
|
|
|
$logger |
|
95
|
|
|
)); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @param TimelineEventCriteria $criteria |
|
100
|
|
|
* @param null $source |
|
101
|
|
|
* @throws \yii\base\InvalidConfigException |
|
102
|
|
|
* @return mixed |
|
103
|
|
|
*/ |
|
104
|
|
|
public function upsertByCriteria( |
|
105
|
|
|
TimelineEventCriteria $criteria, |
|
106
|
|
|
$source = null |
|
107
|
|
|
) { |
|
108
|
|
|
return $this->readPipelineByCriteria( |
|
109
|
|
|
$criteria |
|
110
|
|
|
)($source); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @param TimelineEventCriteria $criteria |
|
115
|
|
|
* @return PipelineBuilderInterface |
|
116
|
|
|
* @throws \yii\base\InvalidConfigException |
|
117
|
|
|
*/ |
|
118
|
|
|
public function readPipelineByCriteria( |
|
119
|
|
|
TimelineEventCriteria $criteria |
|
120
|
|
|
): PipelineBuilderInterface { |
|
121
|
|
|
return $this->upsertPipeline( |
|
122
|
|
|
$criteria->getId(), |
|
123
|
|
|
$criteria->getTypeId(), |
|
124
|
|
|
$criteria->getPayload(), |
|
125
|
|
|
$criteria->getConnection(), |
|
126
|
|
|
$criteria->getTransformer() |
|
|
|
|
|
|
127
|
|
|
); |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.