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\Email\Subscription; |
10
|
|
|
|
11
|
|
|
use Flipbox\Relay\HubSpot\AuthorizationInterface; |
12
|
|
|
use Flipbox\Relay\HubSpot\Builder\HttpRelayBuilder; |
13
|
|
|
use Flipbox\Relay\HubSpot\Middleware\ResourceV1; |
14
|
|
|
use Flipbox\Relay\Middleware\SimpleCache as CacheMiddleware; |
15
|
|
|
use Psr\Log\LoggerInterface; |
16
|
|
|
use Psr\SimpleCache\CacheInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @author Flipbox Factory <[email protected]> |
20
|
|
|
* @since 1.2.0 |
21
|
|
|
*/ |
22
|
|
|
class Read extends HttpRelayBuilder |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* The node |
26
|
|
|
*/ |
27
|
|
|
const NODE = 'email/public'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* The resource |
31
|
|
|
*/ |
32
|
|
|
const RESOURCE = 'subscriptions'; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param string $email |
36
|
|
|
* @param AuthorizationInterface $authorization |
37
|
|
|
* @param CacheInterface $cache |
38
|
|
|
* @param LoggerInterface|null $logger |
39
|
|
|
* @param array $config |
40
|
|
|
*/ |
41
|
|
|
public function __construct( |
42
|
|
|
string $email, |
43
|
|
|
AuthorizationInterface $authorization, |
44
|
|
|
CacheInterface $cache, |
45
|
|
|
LoggerInterface $logger = null, |
46
|
|
|
$config = [] |
47
|
|
|
) { |
48
|
|
|
parent::__construct($authorization, $logger, $config); |
49
|
|
|
|
50
|
|
|
$cacheKey = self::NODE . '/' . self::RESOURCE . ':' . $email; |
51
|
|
|
|
52
|
|
|
$this->addUri($email, $logger) |
53
|
|
|
->addCache($cache, $cacheKey, $logger); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param string|null $email |
58
|
|
|
* @param LoggerInterface|null $logger |
59
|
|
|
* @return $this |
60
|
|
|
*/ |
61
|
|
|
protected function addUri(string $email, LoggerInterface $logger = null) |
62
|
|
|
{ |
63
|
|
|
return $this->addBefore('uri', [ |
64
|
|
|
'class' => ResourceV1::class, |
65
|
|
|
'node' => self::NODE, |
66
|
|
|
'resource' => self::RESOURCE . '/' . $email, |
67
|
|
|
'logger' => $logger ?: $this->getLogger() |
68
|
|
|
]); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param CacheInterface $cache |
73
|
|
|
* @param string $key |
74
|
|
|
* @param LoggerInterface|null $logger |
75
|
|
|
* @return $this |
76
|
|
|
*/ |
77
|
|
|
protected function addCache(CacheInterface $cache, string $key, LoggerInterface $logger = null) |
78
|
|
|
{ |
79
|
|
|
return $this->addBefore('cache', [ |
80
|
|
|
'class' => CacheMiddleware::class, |
81
|
|
|
'logger' => $logger ?: $this->getLogger(), |
82
|
|
|
'cache' => $cache, |
83
|
|
|
'key' => $key |
84
|
|
|
], 'token'); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|