summaryrefslogtreecommitdiffstats
path: root/lib/SparkPost/SparkPost.php
diff options
context:
space:
mode:
authordanil zakablukovskii <danil.kabluk@gmail.com>2016-02-27 17:13:12 +0100
committerdanil zakablukovskii <danil.kabluk@gmail.com>2016-02-27 17:13:12 +0100
commitf4ed2228821f3aa3357bd522489c7d1ce3c7e960 (patch)
tree4c34f003a5636d61af197918c98b125f1e9be5f4 /lib/SparkPost/SparkPost.php
parent4330e3231c54fb4b3c30aa3ac5e64e51dc3edb9d (diff)
downloadphp-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
Diffstat (limited to 'lib/SparkPost/SparkPost.php')
-rw-r--r--lib/SparkPost/SparkPost.php87
1 files changed, 47 insertions, 40 deletions
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;
}
}