-
Notifications
You must be signed in to change notification settings - Fork 192
Expand file tree
/
Copy pathEmailSubscription.php
More file actions
172 lines (153 loc) · 4.8 KB
/
EmailSubscription.php
File metadata and controls
172 lines (153 loc) · 4.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<?php
namespace SevenShores\Hubspot\Endpoints;
/**
* @see https://developers.hubspot.com/docs/api-reference/legacy/communication-preferences/v3/guide
*/
class EmailSubscription extends Endpoint
{
/**
* Get all subscription definitions for the portal.
*
* @see https://developers.hubspot.com/docs/api-reference/legacy/communication-preferences/v3/get-subscription-definitions
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function subscriptionDefinitions()
{
$endpoint = 'https://api.hubapi.com/communication-preferences/v3/definitions';
return $this->client->request('get', $endpoint);
}
/**
* Get subscription statuses for a contact email address.
*
* @see https://developers.hubspot.com/docs/api-reference/legacy/communication-preferences/v3/get-subscription-statuses-for-a-contact
*
* @param string $emailAddress
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function subscriptionStatuses($emailAddress)
{
$emailAddress = url_encode($emailAddress);
$endpoint = "https://api.hubapi.com/communication-preferences/v3/status/email/{$emailAddress}";
return $this->client->request('get', $endpoint);
}
/**
* Subscribe a contact to a given subscription type.
*
* @see https://developers.hubspot.com/docs/api-reference/legacy/communication-preferences/v3/subscribe-contact
*
* @param array $data
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function subscribe(array $data = [])
{
$endpoint = 'https://api.hubapi.com/communication-preferences/v3/subscribe';
return $this->client->request('post', $endpoint, ['json' => $data]);
}
/**
* Unsubscribe a contact from a given subscription type.
*
* @see https://developers.hubspot.com/docs/api-reference/legacy/communication-preferences/v3/unsubscribe-contact
*
* @param array $data
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function unsubscribe(array $data = [])
{
$endpoint = 'https://api.hubapi.com/communication-preferences/v3/unsubscribe';
return $this->client->request('post', $endpoint, ['json' => $data]);
}
/**
* Get email subscription types for a portal.
*
* @see https://developers.hubspot.com/docs/methods/email/get_subscriptions
*
* @param int $portalId
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function subscriptions($portalId = null)
{
$endpoint = 'https://api.hubapi.com/email/public/v1/subscriptions';
return $this->client->request(
'get',
$endpoint,
[],
$this->getQueryString($portalId)
);
}
/**
* View subscriptions timeline for a portal.
*
* @see https://developers.hubspot.com/docs/methods/email/get_subscriptions_timeline
*
* @param array $params Optional parameters
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function subscriptionsTimeline(array $params = [])
{
$endpoint = 'https://api.hubapi.com/email/public/v1/subscriptions/timeline';
return $this->client->request(
'get',
$endpoint,
[],
build_query_string($params)
);
}
/**
* Get email subscription status for an email address.
*
* @see https://developers.hubspot.com/docs/methods/email/get_status
*
* @param string $email
* @param int $portalId
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function subscriptionStatus($email, $portalId = null)
{
$endpoint = "https://api.hubapi.com/email/public/v1/subscriptions/{$email}";
return $this->client->request(
'get',
$endpoint,
[],
$this->getQueryString($portalId)
);
}
/**
* Update email subscription status for an email address.
*
* @see https://developers.hubspot.com/docs/methods/email/update_status
*
* @param string $email
* @param int $portalId
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function updateSubscription($email, array $data = [], $portalId = null)
{
$endpoint = "https://api.hubapi.com/email/public/v1/subscriptions/{$email}";
return $this->client->request(
'put',
$endpoint,
['json' => $data],
$this->getQueryString($portalId)
);
}
/**
* @param int $portalId
*
* @return string
*/
protected function getQueryString($portalId)
{
if (!empty($portalId)) {
return build_query_string(['portalId' => $portalId]);
}
return null;
}
}