-
Notifications
You must be signed in to change notification settings - Fork 45
/
Campaigns.php
81 lines (62 loc) · 1.92 KB
/
Campaigns.php
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
<?php
namespace MailerLiteApi\Api;
use MailerLiteApi\Common\ApiAbstract;
class Campaigns extends ApiAbstract {
protected $endpoint = 'campaigns';
/**
* Add custom html to campaign
*
* @param int $campaignId
* @param array $contentData
* @param array $params
* @return [type]
*/
public function addContent($campaignId, $contentData = [], $params = [])
{
$endpoint = $this->endpoint . '/' . $campaignId . '/content';
$response = $this->restClient->put($endpoint, $contentData);
return $response['body'];
}
/**
* Trigger action: send
*
* @param int $campaignId
* @param array $settingsData
* @return [type]
*/
public function send($campaignId, $settingsData = [])
{
$endpoint = $this->endpoint . '/' . $campaignId . '/actions/send';
$response = $this->restClient->post($endpoint, $settingsData);
return $response['body'];
}
/**
* Trigger action: cancel
*
* @param int $campaignId
* @return [type]
*/
public function cancel($campaignId)
{
$endpoint = $this->endpoint . '/' . $campaignId . '/actions/cancel';
$response = $this->restClient->post($endpoint);
return $response['body'];
}
/**
* Get collection of items
* @param array $fields
* @return [type]
*/
public function get($type = 'sent', $fields = ['*'])
{
// filter anything that is not an available type
$type = in_array($type, ['sent', 'draft', 'outbox']) ? $type : 'sent';
$params = $this->prepareParams();
if ( ! empty($fields) && is_array($fields) && $fields != ['*']) {
$params['fields'] = $fields;
}
$response = $this->restClient->get($this->endpoint . '/' . $type, $params);
$entities = $this->generateCollection($response['body']);
return $entities;
}
}