diff options
author | danil zakablukovskii <danil.kabluk@gmail.com> | 2016-02-27 17:13:12 +0100 |
---|---|---|
committer | danil zakablukovskii <danil.kabluk@gmail.com> | 2016-02-27 17:13:12 +0100 |
commit | f4ed2228821f3aa3357bd522489c7d1ce3c7e960 (patch) | |
tree | 4c34f003a5636d61af197918c98b125f1e9be5f4 | |
parent | 4330e3231c54fb4b3c30aa3ac5e64e51dc3edb9d (diff) | |
download | php-sparkpost-f4ed2228821f3aa3357bd522489c7d1ce3c7e960.zip php-sparkpost-f4ed2228821f3aa3357bd522489c7d1ce3c7e960.tar.gz php-sparkpost-f4ed2228821f3aa3357bd522489c7d1ce3c7e960.tar.bz2 |
clean lib code
removed @desc tag, since it doesn't exist in phpdoc
fixed comments
fixed namespaces
added strong-typing for some methods
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | lib/SendGridCompatibility/Email.php | 149 | ||||
-rw-r--r-- | lib/SendGridCompatibility/SendGrid.php | 15 | ||||
-rw-r--r-- | lib/SparkPost/APIResource.php | 150 | ||||
-rw-r--r-- | lib/SparkPost/APIResponseException.php | 3 | ||||
-rw-r--r-- | lib/SparkPost/SparkPost.php | 87 | ||||
-rw-r--r-- | lib/SparkPost/Transmission.php | 96 |
7 files changed, 288 insertions, 213 deletions
@@ -4,3 +4,4 @@ .buildpath test/output/ examples/example-config.json +.idea diff --git a/lib/SendGridCompatibility/Email.php b/lib/SendGridCompatibility/Email.php index 251b7f2..b375839 100644 --- a/lib/SendGridCompatibility/Email.php +++ b/lib/SendGridCompatibility/Email.php @@ -1,146 +1,181 @@ <?php namespace SparkPost\SendGridCompatibility; -class Email { +class Email +{ public $model; - /** - * @desc Sets up the model for saving the configuration + * Sets up the model for saving the configuration */ - public function __construct() { + public function __construct() + { $this->model = array(); } /** - * @desc adds addresses as recipients + * Adds addresses as recipients + * * @param string $address * @param string $name optional * @return \SparkPost\SendGridCompatibility\Email */ - public function addTo($address, $name = null) { + public function addTo($address, $name = null) + { if (!isset($this->model['recipients'])) { $this->model['recipients'] = array(); } - if(isset($name)) { - $address = array('address'=>array('email'=>$address, 'name'=>$name)); + if (isset($name)) { + $address = array('address' => array('email' => $address, 'name' => $name)); } else { - $address = array('address'=>array('email'=>$address)); + $address = array('address' => array('email' => $address)); } array_push($this->model['recipients'], $address); + return $this; } /** - * @desc explicitly sets a list of addresses - * @param array $addresses - * @return \SparkPost\SendGridCompatibility\Email - */ - public function setTos(array $addresses) { + * Explicitly sets a list of addresses + * + * @param array $addresses + * @return \SparkPost\SendGridCompatibility\Email + */ + public function setTos(array $addresses) + { $this->model['recipients'] = $addresses; + return $this; } /** - * @desc sets the from address + * Sets the from address + * * @param string $address - * @return \MessageSystems\SendGridCompatibility\Email + * @return $this */ - public function setFrom($address) { + public function setFrom($address) + { $this->model['from'] = array('email' => $address); + return $this; } /** - * @desc sets the name for the from address + * Sets the name for the from address + * * @param string $name + * @return $this + * @throws \Exception */ - public function setFromName($name) { - if(!isset($this->model['from'])){ + public function setFromName($name) + { + if (!isset($this->model['from'])) { throw new \Exception('Must set \'From\' prior to setting \'From Name\'.'); } $this->model['from']['name'] = $name; + return $this; } /** - * @desc sets the reply to field + * Sets the reply to field + * * @param string $address - * @return \MessageSystems\SendGridCompatibility\Email + * @return $this */ - public function setReplyTo ($address) { + public function setReplyTo($address) + { $this->model['replyTo'] = $address; + return $this; } /** - * @desc throws an error because bcc fields are not yet implemented. + * Throws an error because bcc fields are not yet implemented + * * @throws \Exception * @param string $address - * @return \MessageSystems\SendGridCompatibility\Email + * @return $this */ - public function addBcc($address) { + public function addBcc($address) + { throw new \Exception('Adding bcc recipients is not yet supported, try adding them as a \'to\' address'); } /** - * @desc sets the subject header + * Sets the subject header + * * @param string $subject * @return \SparkPost\SendGridCompatibility\Email */ - public function setSubject($subject) { + public function setSubject($subject) + { $this->model['subject'] = $subject; + return $this; } /** - * @desc sets the text body + * Sets the text body + * * @param string $text * @return \SparkPost\SendGridCompatibility\Email */ - public function setText($text) { + public function setText($text) + { $this->model['text'] = $text; + return $this; } /** - * @desc sets the html body + * Sets the html body + * * @param string $html * @return \SparkPost\SendGridCompatibility\Email */ - public function setHtml($html) { + public function setHtml($html) + { $this->model['html'] = $html; + return $this; } /** - * @desc Throws an exception since adding categories is not yet supported + * Throws an exception since adding categories is not yet supported + * * @throws \Exception * @param string $category * @throws \Exception */ - public function addCategory($category) { + public function addCategory($category) + { throw new \Exception('Adding categories is not yet supported'); } /** - * @desc Throws an exception since adding attachments is not yet supported - * @throws Exception + * Throws an exception since adding attachments is not yet supported + * * @param mixed $attachment + * @throws \Exception */ - public function addAttachment($attachment) { + public function addAttachment($attachment) + { throw new \Exception('Adding attachments is not yet supported'); } /** - * @desc Adds transmission level substitution data + * Adds transmission level substitution data + * * @param string $name * @param mixed $values * @return \SparkPost\SendGridCompatibility\Email */ - public function addSubstitution($name, $values) { + public function addSubstitution($name, $values) + { if (!isset($this->model['substitutionData'])) { $this->model['substitutionData'] = array(); } @@ -150,38 +185,47 @@ class Email { } /** - * @desc Adds transmission level substitution data + * Adds transmission level substitution data + * * @param string $name * @param mixed $values */ - public function addSection($name, $values) { + public function addSection($name, $values) + { $this->addSubstitution($name, $values); } /** - * @desc Throws an exception because arguments for third party systems is not supported - * @throws Exception + * Throws an exception because arguments for third party systems is not supported + * + * @param $key * @param mixed $value + * @throws \Exception */ - public function addUniqueArg($key, $value) { + public function addUniqueArg($key, $value) + { throw new \Exception('Adding Unique Arguments is not yet supported'); } /** - * @desc Throws an exception because arguments for third party systems is not supported - * @throws Exception + * Throws an exception because arguments for third party systems is not supported + * * @param mixed $values + * @throws \Exception */ - public function setUniqueArgs(array $values) { + public function setUniqueArgs(array $values) + { throw new \Exception('Setting Unique Arguments is not yet supported'); } /** - * @desc Adds custom headers to the email header + * Adds custom headers to the email header + * * @param string $name * @param string $value */ - public function addHeader($name, $value) { + public function addHeader($name, $value) + { if (!isset($this->model['customHeaders'])) { $this->model['customHeaders'] = array(); } @@ -189,11 +233,14 @@ class Email { } /** - * @desc converts this object to a configuration for a SparkPost transmission + * Converts this object to a configuration for a SparkPost transmission + * * @return array */ - public function toSparkPostTransmission() { + public function toSparkPostTransmission() + { return $this->model; } } + ?> diff --git a/lib/SendGridCompatibility/SendGrid.php b/lib/SendGridCompatibility/SendGrid.php index 7f8697a..e5b21e6 100644 --- a/lib/SendGridCompatibility/SendGrid.php +++ b/lib/SendGridCompatibility/SendGrid.php @@ -2,14 +2,15 @@ namespace SparkPost\SendGridCompatibility; use SparkPost\SparkPost; -use SparkPost\SendGridCompatibility\Email; -class SendGrid{ +class SendGrid +{ private $sparky; - public function __construct($username, $password, $options = null, $httpAdapter) { - //username isn't used in our system - $opts = array('key'=>$password); + public function __construct($username, $password, $options = null, $httpAdapter) + { + // username isn't used in our system + $opts = array('key' => $password); if (!is_null($options)) { $opts = array_merge($opts, $options); } @@ -17,8 +18,10 @@ class SendGrid{ $this->sparky = new SparkPost($httpAdapter, $opts); } - public function send(Email $email) { + public function send(Email $email) + { $this->sparky->transmission->send($email->toSparkPostTransmission()); } } + ?> diff --git a/lib/SparkPost/APIResource.php b/lib/SparkPost/APIResource.php index 563a56e..0677b38 100644 --- a/lib/SparkPost/APIResource.php +++ b/lib/SparkPost/APIResource.php @@ -1,62 +1,61 @@ <?php namespace SparkPost; -use Ivory\HttpAdapter\HttpAdapterException; -use SparkPost\SparkPost; - - /** - * @desc SDK interface for managing SparkPost API endpoints + * SDK interface for managing SparkPost API endpoints */ -class APIResource { +class APIResource +{ /** - * @desc name of the API endpoint, mainly used for URL construction. + * Name of the API endpoint, mainly used for URL construction. * This is public to provide an interface - * * @var string */ public $endpoint; /** - * @desc Mapping for values passed into the send method to the values needed for the respective API + * Mapping for values passed into the send method to the values needed for the respective API * @var array */ protected static $parameterMappings = []; /** - * @desc Sets up default structure and default values for the model that is acceptable by the API + * Sets up default structure and default values for the model that is acceptable by the API * @var array */ protected static $structure = []; /** - * @desc SparkPost reference for httpAdapters and configs + * SparkPost reference for httpAdapters and configs */ protected $sparkpost; /** - * @desc Initializes config and httpAdapter for use later. - * @param $sparkpost SparkPost\SparkPost provides api configuration information + * Initializes config and httpAdapter for use later. + * + * @param $sparkpost \SparkPost\SparkPost provides api configuration information */ - public function __construct(SparkPost $sparkpost) { + public function __construct(SparkPost $sparkpost) + { $this->sparkpost = $sparkpost; } /** - * @desc Private Method helper to reference parameter mappings and set the right value for the right parameter + * Private Method helper to reference parameter mappings and set the right value for the right parameter * * @param array $model (pass by reference) the set of values to map * @param string $mapKey a dot syntax path determining which value to set * @param mixed $value value for the given path */ - protected function setMappedValue(&$model, $mapKey, $value) { - //get mapping - if( empty(static::$parameterMappings) ) { + protected function setMappedValue(&$model, $mapKey, $value) + { + // get mapping + if (empty(static::$parameterMappings)) { // if parameterMappings is empty we can assume that no wrapper is defined // for the current endpoint and we will use the mapKey to define the mappings directly $mapPath = $mapKey; - }elseif(array_key_exists($mapKey, static::$parameterMappings)) { + } elseif (array_key_exists($mapKey, static::$parameterMappings)) { // use only defined parameter mappings to construct $model $mapPath = static::$parameterMappings[$mapKey]; } else { @@ -65,109 +64,120 @@ class APIResource { $path = explode('.', $mapPath); $temp = &$model; - foreach( $path as $key ) { - if( !isset($temp[$key]) ){ + foreach ($path as $key) { + if (!isset($temp[$key])) { $temp[$key] = null; } $temp = &$temp[$key]; } $temp = $value; - } /** - * @desc maps values from the passed in model to those needed for the request - * @param $requestConfig the passed in model - * @param $model the set of defaults + * Maps values from the passed in model to those needed for the request + * + * @param array $requestConfig the passed in model + * @param array $model the set of defaults * @return array A model ready for the body of a request */ - protected function buildRequestModel(Array $requestConfig, Array $model=[] ) { - foreach($requestConfig as $key => $value) { + protected function buildRequestModel(array $requestConfig, array $model = []) + { + foreach ($requestConfig as $key => $value) { $this->setMappedValue($model, $key, $value); } + return $model; } /** - * @desc posts to the api with a supplied body - * @param body post body for the request + * Posts to the api with a supplied body + * + * @param array $body post body for the request * @return array Result of the request */ - public function create(Array $body=[]) { - return $this->callResource( 'post', null, ['body'=>$body]); + public function create(array $body = []) + { + return $this->callResource('post', null, ['body' => $body]); } /** - * @desc Makes a put request to the api with a supplied body - * @param body Put body for the request + * Makes a put request to the api with a supplied body + * + * @param string $resourcePath string resource path of specific resource + * @param array $body Put body for the request * @return array Result of the request */ - public function update( $resourcePath, Array $body=[]) { - return $this->callResource( 'put', $resourcePath, ['body'=>$body]); + public function update($resourcePath, array $body = []) + { + return $this->callResource('put', $resourcePath, ['body' => $body]); } /** - * @desc Wrapper method for issuing GET request to current API endpoint + * Wrapper method for issuing GET request to current API endpoint * * @param string $resourcePath (optional) string resource path of specific resource - * @param array $options (optional) query string parameters + * @param array $query (optional) query string parameters * @return array Result of the request */ - public function get( $resourcePath=null, Array $query=[] ) { - return $this->callResource( 'get', $resourcePath, ['query'=>$query] ); + public function get($resourcePath = null, array $query = []) + { + return $this->callResource('get', $resourcePath, ['query' => $query]); } /** - * @desc Wrapper method for issuing DELETE request to current API endpoint + * Wrapper method for issuing DELETE request to current API endpoint * * @param string $resourcePath (optional) string resource path of specific resource - * @param array $options (optional) query string parameters + * @param array $query (optional) query string parameters * @return array Result of the request */ - public function delete( $resourcePath=null, Array $query=[] ) { - return $this->callResource( 'delete', $resourcePath, ['query'=>$query] ); + public function delete($resourcePath = null, array $query = []) + { + return $this->callResource('delete', $resourcePath, ['query' => $query]); } - /** - * @desc assembles a URL for a request + * Assembles a URL for a request + * * @param string $resourcePath path after the initial endpoint - * @param array options array with an optional value of query with values to build a querystring from. + * @param array $options array with an optional value of query with values to build a querystring from. * @return string the assembled URL */ - private function buildUrl($resourcePath, $options) { - $url = join(['/', $this->endpoint, '/']); - if (!is_null($resourcePath)){ + private function buildUrl($resourcePath, $options) + { + $url = "/{$this->endpoint}/"; + if (!is_null($resourcePath)) { $url .= $resourcePath; } - if( !empty($options['query'])) { + if (!empty($options['query'])) { $queryString = http_build_query($options['query']); - $url .= '?'.$queryString; + $url .= '?' . $queryString; } return $url; } - /** - * @desc Prepares a body for put and post requests - * @param array options array with an optional value of body with values to build a request body from. + * Prepares a body for put and post requests + * + * @param array $options array with an optional value of body with values to build a request body from. * @return string|null A json encoded string or null if no body was provided */ - private function buildBody($options) { + private function buildBody($options) + { $body = null; - if( !empty($options['body']) ) { + if (!empty($options['body'])) { $model = static::$structure; - $requestModel = $this->buildRequestModel( $options['body'], $model ); + $requestModel = $this->buildRequestModel($options['body'], $model); $body = json_encode($requestModel); } + return $body; } - /** - * @desc Private Method for issuing GET and DELETE request to current API endpoint + * Private Method for issuing GET and DELETE request to current API endpoint * * This method is responsible for getting the collection _and_ * a specific entity from the API endpoint @@ -178,14 +188,16 @@ class APIResource { * @param string $resourcePath (optional) string resource path of specific resource * @param array $options (optional) query string parameters * @return array Result set of action performed on resource + * @throws APIResponseException */ - private function callResource( $action, $resourcePath=null, $options=[] ) { + private function callResource($action, $resourcePath = null, $options = []) + { $action = strtoupper($action); // normalize $url = $this->buildUrl($resourcePath, $options); $body = $this->buildBody($options); - //make request + // make request try { $response = $this->sparkpost->httpAdapter->send($url, $action, $this->sparkpost->getHttpHeaders(), $body); @@ -198,20 +210,16 @@ class APIResource { if ($statusCode === 404) { throw new APIResponseException('The specified resource does not exist', 404); } - throw new APIResponseException('Received bad response from ' . ucfirst($this->endpoint) . ' API: '. $statusCode ); + throw new APIResponseException('Received bad response from ' . ucfirst($this->endpoint) . ' API: ' . + $statusCode); } - } - - /* - * Configuration Errors, and a catch all for other errors - */ - catch (\Exception $exception) { - if($exception instanceof APIResponseException) { + } catch (\Exception $exception) { // Configuration Errors, and a catch all for other errors + if ($exception instanceof APIResponseException) { throw $exception; } - throw new APIResponseException('Unable to contact ' . ucfirst($this->endpoint) . ' API: '. $exception->getMessage()); + throw new APIResponseException('Unable to contact ' . ucfirst($this->endpoint) . ' API: ' . + $exception->getMessage()); } } - } diff --git a/lib/SparkPost/APIResponseException.php b/lib/SparkPost/APIResponseException.php index cc0842c..e279e4d 100644 --- a/lib/SparkPost/APIResponseException.php +++ b/lib/SparkPost/APIResponseException.php @@ -2,7 +2,8 @@ namespace SparkPost; -class APIResponseException extends \Exception { +class APIResponseException extends \Exception +{ } diff --git a/lib/SparkPost/SparkPost.php b/lib/SparkPost/SparkPost.php index 3c75803..13d947c 100644 --- a/lib/SparkPost/SparkPost.php +++ b/lib/SparkPost/SparkPost.php @@ -1,45 +1,48 @@ <?php namespace SparkPost; + use Ivory\HttpAdapter\Configuration; use Ivory\HttpAdapter\HttpAdapterInterface; -class SparkPost { - +class SparkPost +{ public $transmission; /** - * @dec connection config for making requests. + * Connection config for making requests + * @var array */ private $config; /** - * @desc Ivory\HttpAdapter\HttpAdapterInterface to make requests through. + * @var \Ivory\HttpAdapter\HttpAdapterInterface to make requests through. */ public $httpAdapter; /** - * @desc Default config values. Passed in values will override these. + * Default config values. Passed in values will override these. */ private static $apiDefaults = [ - 'host'=>'api.sparkpost.com', - 'protocol'=>'https', - 'port'=>443, - 'strictSSL'=>true, - 'key'=>'', - 'version'=>'v1' + 'host' => 'api.sparkpost.com', + 'protocol' => 'https', + 'port' => 443, + 'strictSSL' => true, + 'key' => '', + 'version' => 'v1' ]; /** - * @desc sets up httpAdapter and config + * Sets up httpAdapter and config * * Sets up instances of sub libraries. * - * @param Ivory\HttpAdapter $httpAdapter - An adapter for making http requests - * @param String | Array $settingsConfig - Hashmap that contains config values + * @param \Ivory\HttpAdapter\HttpAdapterInterface $httpAdapter - An adapter for making http requests + * @param string | array $settingsConfig - Hashmap that contains config values * for the SDK to connect to SparkPost. If its a string we assume that * its just they API Key. */ - public function __construct($httpAdapter, $settingsConfig) { + public function __construct($httpAdapter, $settingsConfig) + { //config needs to be setup before adapter because of default adapter settings $this->setConfig($settingsConfig); $this->setHttpAdapter($httpAdapter); @@ -47,14 +50,15 @@ class SparkPost { $this->transmission = new Transmission($this); } - - /** * Creates an unwrapped api interface for endpoints that aren't yet supported. * The new resource is attached to this object as well as returned - * @return SparkPost\APIResource - the unwrapped resource + * + * @param string $endpoint + * @return APIResource - the unwrapped resource */ - public function setupUnwrapped ($endpoint) { + public function setupUnwrapped($endpoint) + { $this->{$endpoint} = new APIResource($this); $this->{$endpoint}->endpoint = $endpoint; @@ -62,9 +66,10 @@ class SparkPost { } /** - * @desc Merges passed in headers with default headers for http requests + * Merges passed in headers with default headers for http requests */ - public function getHttpHeaders() { + public function getHttpHeaders() + { $defaultOptions = [ 'Authorization' => $this->config['key'], 'Content-Type' => 'application/json', @@ -73,55 +78,57 @@ class SparkPost { return $defaultOptions; } - /** - * @desc Helper function for getting the configuration for http requests - * @return \Ivory\HttpAdapter\Configuration + * Helper function for getting the configuration for http requests + * + * @param array $config + * @return Configuration */ - private function getHttpConfig($config) { + private function getHttpConfig(array $config) + { // get composer.json to extract version number $composerFile = file_get_contents(dirname(__FILE__) . '/../../composer.json'); $composer = json_decode($composerFile, true); // create Configuration for http adapter $httpConfig = new Configuration(); - $baseUrl = $config['protocol'] . '://' . $config['host'] . ($config['port'] ? ':' . $config['port'] : '') . '/api/' . $config['version']; + $baseUrl = $config['protocol'] . '://' . $config['host'] . ($config['port'] ? ':' . $config['port'] : '') . + '/api/' . $config['version']; $httpConfig->setBaseUri($baseUrl); $httpConfig->setUserAgent('php-sparkpost/' . $composer['version']); + return $httpConfig; } - /** - * @desc Validates and sets up the httpAdapter - * @param $httpAdapter Ivory\HttpAdapter\HttpAdapterInterface to make requests through. + * Validates and sets up the httpAdapter + * + * @param $httpAdapter \Ivory\HttpAdapter\HttpAdapterInterface to make requests through. * @throws \Exception */ - public function setHttpAdapter($httpAdapter) { - if (!$httpAdapter instanceOf HttpAdapterInterface) { - throw new \Exception('$httpAdapter paramter must be a valid Ivory\HttpAdapter'); - } - + public function setHttpAdapter(HttpAdapterInterface $httpAdapter) + { $this->httpAdapter = $httpAdapter; $this->httpAdapter->setConfiguration($this->getHttpConfig($this->config)); } - /** * Allows the user to pass in values to override the defaults and set their API key - * @param String | Array $settingsConfig - Hashmap that contains config values + * + * @param string | array $settingsConfig - Hashmap that contains config values * for the SDK to connect to SparkPost. If its a string we assume that * its just they API Key. * @throws \Exception */ - public function setConfig($settingsConfig) { + public function setConfig($settingsConfig) + { // if the config map is a string we should assume that its an api key if (is_string($settingsConfig)) { - $settingsConfig = ['key'=>$settingsConfig]; + $settingsConfig = ['key' => $settingsConfig]; } // Validate API key because its required - if (!isset($settingsConfig['key']) || empty(trim($settingsConfig['key']))){ + if (!isset($settingsConfig['key']) || empty(trim($settingsConfig['key']))) { throw new \Exception('You must provide an API key'); } @@ -129,7 +136,7 @@ class SparkPost { // set config, overriding defaults foreach ($settingsConfig as $configOption => $configValue) { - if(key_exists($configOption, $this->config)) { + if (key_exists($configOption, $this->config)) { $this->config[$configOption] = $configValue; } } diff --git a/lib/SparkPost/Transmission.php b/lib/SparkPost/Transmission.php index 613ec12..bbd1ca9 100644 --- a/lib/SparkPost/Transmission.php +++ b/lib/SparkPost/Transmission.php @@ -1,56 +1,54 @@ <?php namespace SparkPost; -use Guzzle\Http\Client; -use Guzzle\Http\Exception\ClientErrorResponseException; /** - * @desc SDK interface for managing transmissions + * SDK interface for managing transmissions */ -class Transmission extends APIResource { - +class Transmission extends APIResource +{ public $endpoint = 'transmissions'; /** - * @desc Mapping for values passed into the send method to the values needed for the Transmission API + * Mapping for values passed into the send method to the values needed for the Transmission API * @var array */ protected static $parameterMappings = [ - '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' + '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 + * Sets up default structure and default values for the model that is acceptable by the API * @var array */ protected static $structure = [ - 'return_path'=>'default@sparkpostmail.com', - 'content'=>[ - 'html'=>null, - 'text'=>null, - 'email_rfc822'=>null + 'return_path' => 'default@sparkpostmail.com', + 'content' => [ + 'html' => null, + 'text' => null, + 'email_rfc822' => null ], - 'use_draft_template'=>false + 'use_draft_template' => false ]; /** - * @desc Method for issuing POST request to the Transmissions API + * 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 @@ -73,34 +71,44 @@ class Transmission extends APIResource { * 'trackClicks': boolean, * 'useDraftTemplate': boolean * - * @return array API repsonse represented as key-value pairs + * @param array $transmissionConfig + * @return array API response represented as key-value pairs */ - public function send( $transmissionConfig ) { - return $this->create( $transmissionConfig ); + public function send(array $transmissionConfig) + { + return $this->create($transmissionConfig); } /** - * @desc Method for retrieving information about all transmissions + * Method for retrieving information about all transmissions * Wrapper method for a cleaner interface * + * @param null|string $campaignID + * @param null|string $templateID * @return array result Set of transmissions */ - public function all( $campaignID=null, $templateID=null ) { + public function all($campaignID = null, $templateID = null) + { $options = []; - if( $campaignID !== NULL ) $options['campaign_id'] = $campaignID; - if( $templateID !== NULL ) $options['template_id'] = $templateID; + if ($campaignID !== null) { + $options['campaign_id'] = $campaignID; + } + if ($templateID !== null) { + $options['template_id'] = $templateID; + } - return $this->get( null, $options ); + return $this->get(null, $options); } /** - * @desc Method for retrieving information about a single transmission - * Wrapper method for a cleaner interface - * + * 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 function find($transmissionID) { + public function find($transmissionID) + { return $this->get($transmissionID); } } |