-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpepocampaign.php
170 lines (133 loc) · 5.01 KB
/
pepocampaign.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
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
<?php
class pepocampaign
{
private $pepo_key;
private $pepo_secret;
private $pepo_url;
private $list;
function __construct(){
//date_default_timezone_set('America/Los_Angeles');
$this->pepo_key = 'change-me';
$this->pepo_secret = 'change-me';
$this->pepo_url = 'https://pepocampaigns.com';
}
public function set_list($list_id){
$this->list = $list_id;
}
/*
* Create new list
* $atributes Array
* atributes
* name: List name
* source: Description about how contacts joined the list
*/
public function create_list($atributes){
$current_date = strtotime(date('Y-m-d H:i:s'));
$url = '/api/v1/list/create/';
$request_time = date("c", $current_date);
$delimiter = '::';
$signature = $this->generate_signature($this->pepo_secret, $url.$delimiter.$request_time);
$fields = array(
'request-time' => urlencode($request_time),
'signature' => urlencode($signature),
'api-key' => urlencode($this->pepo_key),
'name' => urlencode($atributes['name']),
'source' => urlencode($atributes['source'])
);
$fields_string = '';
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
$result = $this->execute_curl($fields);
return $result;
}
/*
* Add contact to list
* $atributes Array
* atributes
* email: Email to be added to the list
* first_name: User first name
* last_name: User last name
*/
public function add_contact_to_list($atributes){
$current_date = strtotime(date('Y-m-d H:i:s'));
$url = '/api/v1/list/'.$this->list.'/add-contact/';
$request_time = date("c", $current_date);
$delimiter = '::';
$signature = $this->generate_signature($this->pepo_secret, $url.$delimiter.$request_time);
$fields = array(
'request-time' => urlencode($request_time),
'signature' => urlencode($signature),
'api-key' => urlencode($this->pepo_key),
'email' => urlencode($atributes['email']),
'attributes[First Name]' => urlencode($atributes['first_name']),
'attributes[Last Name]' => urlencode($atributes['last_name'])
);
$fields_string = '';
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
$result = $this->execute_curl($fields);
return $result;
}
/*
* Remove contact from list
* $atributes Array
* atributes
* email: Email to be removed from the list.
*/
public function remove_contact_from_list($atributes){
$current_date = strtotime(date('Y-m-d H:i:s'));
$url = '/api/v1/list/'.$this->list.'/remove-contact/';
$request_time = date("c", $current_date);
$delimiter = '::';
$signature = $this->generate_signature($this->pepo_secret, $url.$delimiter.$request_time);
$fields = array(
'request-time' => urlencode($request_time),
'signature' => urlencode($signature),
'api-key' => urlencode($this->pepo_key),
'email' => urlencode($atributes['email'])
);
$result = $this->execute_curl($fields);
return $result;
}
/*
* Change user status
* $atributes Array
* atributes
* email: Email to be removed from the list.
* type: The status to be updated
*/
public function change_user_status($atributes){
$current_date = strtotime(date('Y-m-d H:i:s'));
$url = '/api/v1/list/'.$this->list.'/remove-contact/';
$request_time = date("c", $current_date);
$delimiter = '::';
$signature = $this->generate_signature($this->pepo_secret, $url.$delimiter.$request_time);
$fields = array(
'request-time' => urlencode($request_time),
'signature' => urlencode($signature),
'api-key' => urlencode($this->pepo_key),
'email' => urlencode($atributes['email']),
'type' => urlencode($atributes['type'])
);
$result = $this->execute_curl($fields);
return $result;
}
private function execute_curl($fields){
$fields_string = '';
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
$ch = curl_init();
$url= $this->pepo_url;
curl_setopt( $ch,CURLOPT_URL, $url );
curl_setopt( $ch,CURLOPT_POST, count($fields) );
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
$result = curl_exec($ch );
curl_close( $ch );
return $result;
}
private function generate_signature($api_secret, $signature){
return hash_hmac('sha256', $signature, $api_secret, false);
}
}