summaryrefslogtreecommitdiffstats
path: root/lib/SparkPost/Transmission.php
blob: 82cc11d572285f4e41c550908b08d964ddafd07e (plain)
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
<?php
namespace SparkPost;
use Guzzle\Http\Client;
use Guzzle\Http\Exception\ClientErrorResponseException;

/**
 * @desc SDK interface for managing transmissions
 */
class Transmission extends APIResource {

	public static $endpoint = 'transmissions';

	/**
	 * @desc Mapping for values passed into the send method to the values needed for the Transmission API
	 * @var array
	 */
	protected static $parameterMappings = array(
		'campaign'=>'campaign_id',
		'metadata'=>'metadata',
		'substitutionData'=>'substitution_data',
		'description'=>'description',
		'returnPath'=>'return_path',
		'replyTo'=>'content.reply_to',
		'subject'=>'content.subject',
		'from'=>'content.from',
		'html'=>'content.html',
		'text'=>'content.text',
		'rfc822'=>'content.email_rfc822',
		'customHeaders'=>'content.headers',
		'recipients'=>'recipients',
		'recipientList'=>'recipients.list_id',
		'template'=>'content.template_id',
		'trackOpens'=>'options.open_tracking',
		'trackClicks'=>'options.click_tracking',
		'useDraftTemplate'=>'use_draft_template'
	);

	/**
	 * @desc Sets up default structure and default values for the model that is acceptable by the API
	 * @var array
	 */
	protected static $structure = array(
		'return_path'=>"default@sparkpostmail.com",
		'content'=>array(
			'html'=>null,
			'text'=>null,
			'email_rfc822'=>null
		),
		'use_draft_template'=>false
	);

	/**
	 * @desc Method for issuing POST request to the Transmissions API
	 *
	 *  This method assumes that all the appropriate fields have
	 *  been populated by the user through configuration.  Acceptable
	 *  configuration values are:
	 *  'campaign': string,
	 *	'metadata': array,
	 *	'substitutionData': array,
	 *	'description': string,
	 *	'replyTo': string,
	 *	'subject': string,
	 *	'from': string,
	 *	'html': string,
	 *	'text': string,
	 *	'rfc822': string,
	 *	'customHeaders': array,
	 *	'recipients': array,
	 *	'recipientList': string,
	 *	'template': string,
	 *	'trackOpens': boolean,
	 *	'trackClicks': boolean,
	 *	'useDraftTemplate': boolean
	 *
	 * @return array API repsonse represented as key-value pairs
	 */
	public static function send( $transmissionConfig ) {
		return self::create( $transmissionConfig );
	}

	/**
	 * @desc Method for retrieving information about all transmissions
	 *  Wrapper method for a cleaner interface
	 *
	 * @return array result Set of transmissions
	 */
	public static function all( $campaignID=null, $templateID=null ) {
		$options = array();
		if( $campaignID !== NULL ) $options['campaign_id'] = $campaignID;
		if( $templateID !== NULL ) $options['template_id'] = $templateID;

		return self::get( null, $options );
	}

	/**
	 * @desc Method for retrieving information about a single transmission
 	 *  Wrapper method for a cleaner interface
 	 *
	 * @param string $transmissionID Identifier of the transmission to be found
	 * @return array result Single transmission represented in key-value pairs
	 */
	public static function find($transmissionID) {
		return self::get($transmissionID);
	}
}

?>