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 @@ public function setHttpAdapter($httpAdapter) { /** * 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 @@ public function testSetBadHTTPAdapter() { $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/