summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJordan Nornhold <nornholdj@gmail.com>2015-10-14 11:06:45 -0400
committerJordan Nornhold <nornholdj@gmail.com>2015-10-14 11:06:45 -0400
commite6d3ed189383fb34e290ebaf15b040400ff409f6 (patch)
tree59646ecfa19b628fde12e5a983261faf27c8843f
parent31ab3908d8835b2ee7ccd1b33e16ad5d5417e1ac (diff)
parent47d840576d7e4c29fc4ae359f5f1adff6ffbc751 (diff)
downloadphp-sparkpost-e6d3ed189383fb34e290ebaf15b040400ff409f6.zip
php-sparkpost-e6d3ed189383fb34e290ebaf15b040400ff409f6.tar.gz
php-sparkpost-e6d3ed189383fb34e290ebaf15b040400ff409f6.tar.bz2
Merge pull request #28 from SparkPost/issue-27
Issue 27
-rw-r--r--lib/SparkPost/SparkPost.php15
-rw-r--r--test/unit/SparkPostTest.php6
2 files changed, 18 insertions, 3 deletions
diff --git a/lib/SparkPost/SparkPost.php b/lib/SparkPost/SparkPost.php
index f88d847..3c75803 100644
--- a/lib/SparkPost/SparkPost.php
+++ b/lib/SparkPost/SparkPost.php
@@ -35,7 +35,9 @@ class SparkPost {
* Sets up instances of sub libraries.
*
* @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
+ * @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) {
//config needs to be setup before adapter because of default adapter settings
@@ -107,10 +109,17 @@ class SparkPost {
/**
* Allows the user to pass in values to override the defaults and set their API key
- * @param Array $settingsConfig - Hashmap that contains config values for the SDK to connect to SparkPost
+ * @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(Array $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];
+ }
+
// Validate API key because its required
if (!isset($settingsConfig['key']) || empty(trim($settingsConfig['key']))){
throw new \Exception('You must provide an API key');
diff --git a/test/unit/SparkPostTest.php b/test/unit/SparkPostTest.php
index 101784a..b1b38fe 100644
--- a/test/unit/SparkPostTest.php
+++ b/test/unit/SparkPostTest.php
@@ -51,6 +51,12 @@ class SparkPostTest extends \PHPUnit_Framework_TestCase {
$this->resource->setHttpAdapter(new \stdClass());
}
+ public function testSetConfigStringKey() {
+ $this->resource->setConfig('a key');
+ $config = self::$utils->getProperty($this->resource, 'config');
+ $this->assertEquals('a key', $config['key']);
+ }
+
/**
* @expectedException Exception
* @expectedExceptionMessageRegExp /API key/