|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* File: CampaignCreateHandler.php |
|
4
|
|
|
* |
|
5
|
|
|
* @author Maciej Sławik <[email protected]> |
|
6
|
|
|
* Github: https://github.com/maciejslawik |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace MSlwk\FreshMail\Handler\Campaign; |
|
10
|
|
|
|
|
11
|
|
|
use MSlwk\FreshMail\Handler\AbstractHandler; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Class CampaignCreateHandler |
|
15
|
|
|
* |
|
16
|
|
|
* @package MSlwk\FreshMail\Handler\Campaign |
|
17
|
|
|
*/ |
|
18
|
|
|
class CampaignCreateHandler extends AbstractHandler |
|
19
|
|
|
{ |
|
20
|
|
|
const API_ENDPOINT = '/rest/campaigns/create'; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @param string $name |
|
24
|
|
|
* @param string $urlToDownloadContent |
|
25
|
|
|
* @param string $content |
|
26
|
|
|
* @param string $subject |
|
27
|
|
|
* @param string $fromAddress |
|
28
|
|
|
* @param string $fromName |
|
29
|
|
|
* @param string $replyTo |
|
30
|
|
|
* @param string $listHash |
|
31
|
|
|
* @param string $groupHash |
|
32
|
|
|
* @param string $resignLink |
|
33
|
|
|
* @return string |
|
34
|
|
|
*/ |
|
35
|
98 |
|
public function createCampaign( |
|
36
|
|
|
string $name, |
|
37
|
|
|
string $urlToDownloadContent = '', |
|
38
|
|
|
string $content = '', |
|
39
|
|
|
string $subject = '', |
|
40
|
|
|
string $fromAddress = '', |
|
41
|
|
|
string $fromName = '', |
|
42
|
|
|
string $replyTo = '', |
|
43
|
|
|
string $listHash = '', |
|
44
|
|
|
string $groupHash = '', |
|
45
|
|
|
string $resignLink = '' |
|
46
|
|
|
) { |
|
47
|
98 |
|
$getParameters = []; |
|
48
|
28 |
|
$postParameters = [ |
|
49
|
98 |
|
'name' => $name, |
|
50
|
|
|
'url' => $urlToDownloadContent ?: null, |
|
51
|
|
|
'html' => $content ?: null, |
|
52
|
|
|
'subject' => $subject ?: null, |
|
53
|
|
|
'from_address' => $fromAddress ?: null, |
|
54
|
|
|
'from_name' => $fromName ?: null, |
|
55
|
|
|
'reply_to' => $replyTo ?: null, |
|
56
|
|
|
'list' => $listHash ?: null, |
|
57
|
|
|
'group' => $groupHash ?: null, |
|
58
|
|
|
'resignlink' => $resignLink ?: null |
|
59
|
|
|
]; |
|
60
|
|
|
|
|
61
|
70 |
|
$postParameters = array_filter($postParameters, function ($value) { |
|
62
|
98 |
|
return $value !== null; |
|
63
|
98 |
|
}); |
|
64
|
98 |
|
$response = $this->processRequest($getParameters, $postParameters); |
|
65
|
7 |
|
return $response->data->hash; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @return string |
|
70
|
|
|
*/ |
|
71
|
7 |
|
protected function getApiEndpoint(): string |
|
72
|
|
|
{ |
|
73
|
7 |
|
return self::API_ENDPOINT; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|