summaryrefslogtreecommitdiffstats
path: root/lib/SparkPost/SparkPost.php
diff options
context:
space:
mode:
authornornholdj <nornholdj@gmail.com>2014-11-14 16:25:36 -0500
committernornholdj <nornholdj@gmail.com>2014-11-14 16:25:36 -0500
commit2ca3b8764d9e7ad8c7436e53b6676e9eb6591f28 (patch)
tree6934c8cf3d9c91852a76e57314246e17c81b4f80 /lib/SparkPost/SparkPost.php
parent39f2699a7e7850397882a6d2ee3a8438a105b72d (diff)
parent3095de0dca14565911a2bdcc1ee5960e63b9b1f4 (diff)
downloadphp-sparkpost-2ca3b8764d9e7ad8c7436e53b6676e9eb6591f28.zip
php-sparkpost-2ca3b8764d9e7ad8c7436e53b6676e9eb6591f28.tar.gz
php-sparkpost-2ca3b8764d9e7ad8c7436e53b6676e9eb6591f28.tar.bz2
Merge branch 'feature/MA-1084' into develop
Diffstat (limited to 'lib/SparkPost/SparkPost.php')
-rw-r--r--lib/SparkPost/SparkPost.php56
1 files changed, 56 insertions, 0 deletions
diff --git a/lib/SparkPost/SparkPost.php b/lib/SparkPost/SparkPost.php
new file mode 100644
index 0000000..5c2a554
--- /dev/null
+++ b/lib/SparkPost/SparkPost.php
@@ -0,0 +1,56 @@
+<?php
+namespace SparkPost;
+
+class SparkPost {
+
+ private static $config;
+ private static $defaults = array(
+ 'host'=>'api.sparkpost.com',
+ 'protocol'=>'https',
+ 'port'=>443,
+ 'strictSSL'=>true,
+ 'key'=>'',
+ 'version'=>'v1'
+ );
+
+ /**
+ * Enforce that this object can't be instansiated
+ */
+ private function __construct(){}
+
+ /**
+ * Allows the user to pass in values to override the defaults and set their API key
+ * @param Array $configMap - Hashmap that contains config values for the SDK to connect to SparkPost
+ * @throws \Exception
+ */
+ public static function setConfig(array $configMap) {
+ //check for API key because its required
+ if (isset($configMap['key'])){
+ $key = trim($configMap['key']);
+ if(empty($key)){
+ throw new \Exception('You must provide an API key');
+ }
+ } else {
+ throw new \Exception('You must provide an API key');
+ }
+ self::$config = self::$defaults;
+ foreach ($configMap as $configOption => $configValue) {
+ if(key_exists($configOption, self::$config)) {
+ self::$config[$configOption] = $configValue;
+ }
+ }
+ }
+
+ /**
+ * Retrieves the configuration that was previously setup by the user
+ * @throws \Exception
+ */
+ public static function getConfig() {
+ if (self::$config === null) {
+ throw new \Exception('No configuration has been provided');
+ }
+ return self::$config;
+ }
+}
+
+?> \ No newline at end of file