summaryrefslogtreecommitdiffstats
path: root/lib/SparkPost
diff options
context:
space:
mode:
authorbeardyman <nornholdj@gmail.com>2015-10-03 11:05:25 -0400
committerbeardyman <nornholdj@gmail.com>2015-10-03 11:05:25 -0400
commitada533a743125008474de854a3f6bcec5c104fbe (patch)
treec640e50d2a4d9cacae7c7964260f18c3af5258a8 /lib/SparkPost
parent55d428cb95c10c7b94225760a663f28d50190091 (diff)
downloadphp-sparkpost-ada533a743125008474de854a3f6bcec5c104fbe.zip
php-sparkpost-ada533a743125008474de854a3f6bcec5c104fbe.tar.gz
php-sparkpost-ada533a743125008474de854a3f6bcec5c104fbe.tar.bz2
replaced tabs with two spaces. normalized quotes
Diffstat (limited to 'lib/SparkPost')
-rw-r--r--lib/SparkPost/APIResource.php268
-rw-r--r--lib/SparkPost/SparkPost.php18
-rw-r--r--lib/SparkPost/Transmission.php176
3 files changed, 231 insertions, 231 deletions
diff --git a/lib/SparkPost/APIResource.php b/lib/SparkPost/APIResource.php
index d500963..3747f6d 100644
--- a/lib/SparkPost/APIResource.php
+++ b/lib/SparkPost/APIResource.php
@@ -9,69 +9,69 @@ use SparkPost\SparkPost;
class APIResource {
/**
- * @desc name of the API endpoint, mainly used for URL construction.
+ * @desc 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
- * @var array
- */
- protected static $parameterMappings = [];
-
- /**
- * @desc Sets up default structure and default values for the model that is acceptable by the API
- * @var array
- */
- protected static $structure = [];
+ * @var string
+ */
+ public $endpoint;
+
+ /**
+ * @desc 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
+ * @var array
+ */
+ protected static $structure = [];
/**
* @desc SparkPost reference for httpAdapters and configs
*/
protected $sparkpost;
- /**
- * @desc Initializes config and httpAdapter for use later.
+ /**
+ * @desc 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
+ /**
+ * @desc 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) ) {
- // 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)) {
- // use only defined parameter mappings to construct $model
- $mapPath = static::$parameterMappings[$mapKey];
- } else {
- return;
- }
-
- $path = explode('.', $mapPath);
- $temp = &$model;
- foreach( $path as $key ) {
- if( !isset($temp[$key]) ){
- $temp[$key] = null;
- }
- $temp = &$temp[$key];
- }
- $temp = $value;
-
- }
+ */
+ 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)) {
+ // use only defined parameter mappings to construct $model
+ $mapPath = static::$parameterMappings[$mapKey];
+ } else {
+ return;
+ }
+
+ $path = explode('.', $mapPath);
+ $temp = &$model;
+ 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
@@ -79,52 +79,52 @@ class APIResource {
* @param $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) {
- $this->setMappedValue($model, $key, $value);
- }
- return $model;
- }
-
- /**
- * @desc posts to the api with a supplied body
+ 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
* @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
* @return array Result of the request
- */
- public function update( $resourcePath, Array $body=[]) {
- return $this->callResource( 'put', $resourcePath, ['body'=>$body]);
- }
-
- /**
- * @desc 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
- * @return array Result of the request
- */
- 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
- *
- * @param string $resourcePath (optional) string resource path of specific resource
- * @param array $options (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 update( $resourcePath, Array $body=[]) {
+ return $this->callResource( 'put', $resourcePath, ['body'=>$body]);
+ }
+
+ /**
+ * @desc 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
+ * @return array Result of the request
+ */
+ 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
+ *
+ * @param string $resourcePath (optional) string resource path of specific resource
+ * @param array $options (optional) query string parameters
+ * @return array Result of the request
+ */
+ public function delete( $resourcePath=null, Array $query=[] ) {
+ return $this->callResource( 'delete', $resourcePath, ['query'=>$query] );
+ }
/**
@@ -156,59 +156,59 @@ class APIResource {
private function buildBody($options) {
$body = null;
if( !empty($options['body']) ) {
- $model = static::$structure;
- $requestModel = $this->buildRequestModel( $options['body'], $model );
- $body = json_encode($requestModel);
- }
+ $model = static::$structure;
+ $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
- *
- * This method is responsible for getting the collection _and_
- * a specific entity from the API endpoint
- *
- * If resourcePath parameter is omitted, then we fetch the collection
- *
- * @param string $action HTTP method type
- * @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
- */
- private function callResource( $action, $resourcePath=null, $options=[] ) {
- $action = strtoupper($action); // normalize
-
- if( !in_array($action, ['POST', 'PUT', 'GET', 'DELETE'])) {
- throw new \Exception('Invalid resource action');
- }
-
- $url = $this->buildUrl($resourcePath, $options);
- $body = $this->buildBody($options);
-
- //make request
- try {
- $response = $this->sparkpost->httpAdapter->send($url, $action, $this->sparkpost->getHttpHeaders(), $body);
- return json_decode($response->getBody()->getContents(), true);
- }
- /*
- * Handles 4XX responses
+ /**
+ * @desc 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
+ *
+ * If resourcePath parameter is omitted, then we fetch the collection
+ *
+ * @param string $action HTTP method type
+ * @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
+ */
+ private function callResource( $action, $resourcePath=null, $options=[] ) {
+ $action = strtoupper($action); // normalize
+
+ if( !in_array($action, ['POST', 'PUT', 'GET', 'DELETE'])) {
+ throw new \Exception('Invalid resource action');
+ }
+
+ $url = $this->buildUrl($resourcePath, $options);
+ $body = $this->buildBody($options);
+
+ //make request
+ try {
+ $response = $this->sparkpost->httpAdapter->send($url, $action, $this->sparkpost->getHttpHeaders(), $body);
+ return json_decode($response->getBody()->getContents(), true);
+ }
+ /*
+ * Handles 4XX responses
*/
catch (HttpAdapterException $exception) {
- $response = $exception->getResponse();
- $statusCode = $response->getStatusCode();
- if($statusCode === 404) {
- throw new \Exception("The specified resource does not exist", 404);
- }
- throw new \Exception("Received bad response from ".ucfirst($this->endpoint)." API: ". $statusCode );
- }
- /*
- * Handles 5XX Errors, Configuration Errors, and a catch all for other errors
- */
- catch (\Exception $exception) {
- throw new \Exception("Unable to contact ".ucfirst($this->endpoint)." API: ". $exception->getMessage());
- }
- }
+ $response = $exception->getResponse();
+ $statusCode = $response->getStatusCode();
+ if($statusCode === 404) {
+ throw new \Exception('The specified resource does not exist', 404);
+ }
+ throw new \Exception('Received bad response from '.ucfirst($this->endpoint).' API: '. $statusCode );
+ }
+ /*
+ * Handles 5XX Errors, Configuration Errors, and a catch all for other errors
+ */
+ catch (\Exception $exception) {
+ throw new \Exception('Unable to contact '.ucfirst($this->endpoint).' API: '. $exception->getMessage());
+ }
+ }
}
diff --git a/lib/SparkPost/SparkPost.php b/lib/SparkPost/SparkPost.php
index d9dc3c8..b3cef5e 100644
--- a/lib/SparkPost/SparkPost.php
+++ b/lib/SparkPost/SparkPost.php
@@ -21,13 +21,13 @@ class SparkPost {
* @desc 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
@@ -37,7 +37,7 @@ class SparkPost {
* @param Ivory\HttpAdapter $httpAdapter - An adapter for making http requests
* @param Array $settingsConfig - Hashmap that contains config values for the SDK to connect to SparkPost
*/
- 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);
@@ -85,7 +85,7 @@ class SparkPost {
*/
private function getHttpConfig($config) {
// get composer.json to extract version number
- $composerFile = file_get_contents(dirname(__FILE__) . "/../../composer.json");
+ $composerFile = file_get_contents(dirname(__FILE__) . '/../../composer.json');
$composer = json_decode($composerFile, true);
// create Configuration for http adapter
diff --git a/lib/SparkPost/Transmission.php b/lib/SparkPost/Transmission.php
index f811cdf..613ec12 100644
--- a/lib/SparkPost/Transmission.php
+++ b/lib/SparkPost/Transmission.php
@@ -10,99 +10,99 @@ class Transmission extends APIResource {
public $endpoint = 'transmissions';
- /**
- * @desc 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'
- ];
+ /**
+ * @desc 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'
+ ];
- /**
- * @desc 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
- ],
- 'use_draft_template'=>false
- ];
+ /**
+ * @desc 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
+ ],
+ '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 function send( $transmissionConfig ) {
- return $this->create( $transmissionConfig );
- }
+ /**
+ * @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 function send( $transmissionConfig ) {
+ return $this->create( $transmissionConfig );
+ }
- /**
- * @desc Method for retrieving information about all transmissions
- * Wrapper method for a cleaner interface
- *
- * @return array result Set of transmissions
- */
- public function all( $campaignID=null, $templateID=null ) {
- $options = [];
- if( $campaignID !== NULL ) $options['campaign_id'] = $campaignID;
- if( $templateID !== NULL ) $options['template_id'] = $templateID;
+ /**
+ * @desc Method for retrieving information about all transmissions
+ * Wrapper method for a cleaner interface
+ *
+ * @return array result Set of transmissions
+ */
+ public function all( $campaignID=null, $templateID=null ) {
+ $options = [];
+ 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
- *
- * @param string $transmissionID Identifier of the transmission to be found
- * @return array result Single transmission represented in key-value pairs
- */
- public function find($transmissionID) {
- return $this->get($transmissionID);
- }
+ /**
+ * @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 function find($transmissionID) {
+ return $this->get($transmissionID);
+ }
}
?>