diff options
Diffstat (limited to 'lib/SparkPost/SparkPost.php')
-rw-r--r-- | lib/SparkPost/SparkPost.php | 61 |
1 files changed, 24 insertions, 37 deletions
diff --git a/lib/SparkPost/SparkPost.php b/lib/SparkPost/SparkPost.php index 13d947c..46623c9 100644 --- a/lib/SparkPost/SparkPost.php +++ b/lib/SparkPost/SparkPost.php @@ -1,16 +1,14 @@ <?php namespace SparkPost; - use Ivory\HttpAdapter\Configuration; use Ivory\HttpAdapter\HttpAdapterInterface; -class SparkPost -{ +class SparkPost { + public $transmission; /** - * Connection config for making requests - * @var array + * Connection config for making requests. */ private $config; @@ -23,12 +21,12 @@ class SparkPost * 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' ]; /** @@ -37,12 +35,11 @@ class SparkPost * Sets up instances of sub libraries. * * @param \Ivory\HttpAdapter\HttpAdapterInterface $httpAdapter - An adapter for making http requests - * @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. */ - 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); @@ -53,12 +50,10 @@ class SparkPost /** * Creates an unwrapped api interface for endpoints that aren't yet supported. * The new resource is attached to this object as well as returned - * * @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; @@ -68,11 +63,10 @@ class SparkPost /** * 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', + 'Authorization' => $this->config['key'], + 'Content-Type' => 'application/json', ]; return $defaultOptions; @@ -80,55 +74,48 @@ class SparkPost /** * Helper function for getting the configuration for http requests - * * @param array $config * @return Configuration */ - private function getHttpConfig(array $config) - { + private function getHttpConfig($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; } + /** * Validates and sets up the httpAdapter - * * @param $httpAdapter \Ivory\HttpAdapter\HttpAdapterInterface to make requests through. * @throws \Exception */ - public function setHttpAdapter(HttpAdapterInterface $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'); } @@ -136,7 +123,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; } } |