1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dekalee\MailjetBundle\Creator; |
4
|
|
|
|
5
|
|
|
use Dekalee\MailjetBundle\Convertor\ContactListConvertor; |
6
|
|
|
use Doctrine\Common\Inflector\Inflector; |
7
|
|
|
use Mailjet\Client; |
8
|
|
|
use Mailjet\Resources; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class ContactListCreator |
12
|
|
|
*/ |
13
|
|
|
class ContactListCreator |
14
|
|
|
{ |
15
|
|
|
protected $client; |
16
|
|
|
protected $contactListConvertor; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @param ContactListConvertor $contactListConvertor |
20
|
|
|
* @param Client $client |
21
|
|
|
*/ |
22
|
|
|
public function __construct(ContactListConvertor $contactListConvertor, Client $client) |
23
|
|
|
{ |
24
|
|
|
$this->client = $client; |
25
|
|
|
$this->contactListConvertor = $contactListConvertor; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param string $name |
30
|
|
|
* @param string $contact |
31
|
|
|
* @param array $parameters |
32
|
|
|
* |
33
|
|
|
* @throws \Dekalee\MailjetBundle\Exception\ContactListNotCreated |
34
|
|
|
*/ |
35
|
|
|
public function addContactToList($name, $contact, array $parameters = []) |
36
|
|
|
{ |
37
|
|
|
$contactListId = $this->contactListConvertor->convert($name); |
38
|
|
|
|
39
|
|
|
$body = [ |
40
|
|
|
'Email' => $contact |
41
|
|
|
]; |
42
|
|
|
|
43
|
|
|
$response = $this->client->post(Resources::$Contact, ['body' => $body]); |
44
|
|
|
var_dump($response->success()); |
|
|
|
|
45
|
|
|
print_r($response->getData()); |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
$body = [ |
49
|
|
|
'Datatype' => "str", |
50
|
|
|
'Name' => "content_" . $name, |
51
|
|
|
'NameSpace' => "static" |
52
|
|
|
]; |
53
|
|
|
$response = $this->client->post(Resources::$Contactmetadata, ['body' => $body]); |
54
|
|
|
var_dump($response->success()); |
55
|
|
|
print_r($response->getData()); |
56
|
|
|
|
57
|
|
|
$body = [ |
58
|
|
|
'Data' => [ |
59
|
|
|
[ |
60
|
|
|
'Name' => "content_" . $name, |
61
|
|
|
'value' => $parameters['content'] |
62
|
|
|
], |
63
|
|
|
] |
64
|
|
|
]; |
65
|
|
|
$response = $this->client->put(Resources::$Contactdata, ['id' => $contact, 'body' => $body]); |
66
|
|
|
var_dump($response->success()); |
67
|
|
|
print_r($response->getData()); |
68
|
|
|
|
69
|
|
|
$body = [ |
70
|
|
|
'ContactsLists' => [ |
71
|
|
|
[ |
72
|
|
|
'ListID' => $contactListId, |
73
|
|
|
'Action' => "addforce" |
74
|
|
|
] |
75
|
|
|
] |
76
|
|
|
]; |
77
|
|
|
$response = $this->client->post(Resources::$ContactManagecontactslists, ['id' => $contact, 'body' => $body]); |
78
|
|
|
var_dump($response->success()); |
79
|
|
|
print_r($response->getData()); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|