forked from campaignmonitor/createsend-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
csrest_transactional_classicemail.php
133 lines (125 loc) · 5.81 KB
/
csrest_transactional_classicemail.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
<?php
require_once dirname(__FILE__).'/class/base_classes.php';
/**
* Class to access transactional from the create send API.
* @author philoye
*
*/
if (!class_exists('CS_REST_Transactional_ClassicEmail')) {
class CS_REST_Transactional_ClassicEmail extends CS_REST_Wrapper_Base {
/**
* The client id to use for the timeline. Optional if using a client api key
* @var array
* @access private
*/
var $_client_id_param;
/**
* Constructor.
* @param $client_id string The client id to send email on behalf of
* Optional if using a client api key
* @param $auth_details array Authentication details to use for API calls.
* This array must take one of the following forms:
* If using OAuth to authenticate:
* array(
* 'access_token' => 'your access token',
* 'refresh_token' => 'your refresh token')
*
* Or if using an API key:
* array('api_key' => 'your api key')
* @param $protocol string The protocol to use for requests (http|https)
* @param $debug_level int The level of debugging required CS_REST_LOG_NONE | CS_REST_LOG_ERROR | CS_REST_LOG_WARNING | CS_REST_LOG_VERBOSE
* @param $host string The host to send API requests to. There is no need to change this
* @param $log CS_REST_Log The logger to use. Used for dependency injection
* @param $serialiser The serialiser to use. Used for dependency injection
* @param $transport The transport to use. Used for dependency injection
* @access public
*/
function __construct (
$auth_details,
$client_id = NULL,
$protocol = 'https',
$debug_level = CS_REST_LOG_NONE,
$host = 'api.createsend.com',
$log = NULL,
$serialiser = NULL,
$transport = NULL) {
parent::__construct($auth_details, $protocol, $debug_level, $host, $log, $serialiser, $transport);
$this->set_client($client_id);
}
/**
* Change the client id used for calls after construction
* Only required if using OAuth or an Account level API Key
* @param $client_id
* @access public
*/
function set_client($client_id) {
$this->_client_id_param = array("clientID" => $client_id);
}
/**
* Sends a new classic transactional email
* @param array $message The details of the template
* This should be an array of the form
* array(
* 'From' => string required The From name/email in the form "first last <[email protected]>"
* 'ReplyTo' => string optional The Reply-To address
* 'To' => array(
* "First Last <[email protected]>", "[email protected]"
* ) optional To recipients
* 'CC' => array(
* "First Last <[email protected]>", "[email protected]"
* ) optional CC recipients
* 'BCC' => array(
* "First Last <[email protected]>", "[email protected]"
* ) optional BCC recipients
* 'Subject' => string required The subject of the email
* 'Html' => string The HTML content of the message
* 'Text' => string optional The text content of the message
* 'Attachments' => array
* "Name" => string required
* "Type" => string required
* "Content" => string required
* ) optional
* )
* @param string $group Optional. Name to group emails by for reporting
* For example "Password reset", "Order confirmation"
* @param array $options optional. Advanced options for sending this email (optional)
* This should be an array, each property is optionals
* array(
* TrackOpens => whether to track opens, defaults to true
* TrackClicks => whether to track clicks, defaults to true
* InlineCSS => whether inline CSS, defaults to true
* AddRecipientsToListID => ID of a list to add all recipeints to
* )
* @access public
* @return CS_REST_Wrapper_Result A successful response will be the include the details of the action, including a Message ID.
* array(
* array(
* "MessageID" => string
* "Recipient" => string
* "Status" => string
* )
* )
*/
function send($message, $group = NULL, $add_to_list_ID = NULL, $options = array()) {
$group_param = array( "Group" => $group);
$add_to_list_param = array( "AddRecipientsToListID" => $add_to_list_ID);
$data = array_merge($this->_client_id_param, $message, $group_param, $add_to_list_param, $options);
return $this->post_request($this->_base_route.'transactional/classicemail/send', $data);
}
/**
* Gets the list of Classic Groups
* @access public
* @return CS_REST_Wrapper_Result A successful response will be an array of the form
* array(
* array(
* "Group" => string
* "CreatedAt" => string
* )
* )
*/
function groups() {
$data = array_merge($this->_client_id_param);
return $this->get_request($this->_base_route . 'transactional/classicemail/groups', $data);
}
}
}