Skip to content

Commit e6d3ed1

Browse files
committed
Merge pull request #28 from SparkPost/issue-27
Issue 27
2 parents 31ab390 + 47d8405 commit e6d3ed1

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

lib/SparkPost/SparkPost.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ class SparkPost {
3535
* Sets up instances of sub libraries.
3636
*
3737
* @param Ivory\HttpAdapter $httpAdapter - An adapter for making http requests
38-
* @param Array $settingsConfig - Hashmap that contains config values for the SDK to connect to SparkPost
38+
* @param String | Array $settingsConfig - Hashmap that contains config values
39+
* for the SDK to connect to SparkPost. If its a string we assume that
40+
* its just they API Key.
3941
*/
4042
public function __construct($httpAdapter, $settingsConfig) {
4143
//config needs to be setup before adapter because of default adapter settings
@@ -107,10 +109,17 @@ public function setHttpAdapter($httpAdapter) {
107109

108110
/**
109111
* Allows the user to pass in values to override the defaults and set their API key
110-
* @param Array $settingsConfig - Hashmap that contains config values for the SDK to connect to SparkPost
112+
* @param String | Array $settingsConfig - Hashmap that contains config values
113+
* for the SDK to connect to SparkPost. If its a string we assume that
114+
* its just they API Key.
111115
* @throws \Exception
112116
*/
113-
public function setConfig(Array $settingsConfig) {
117+
public function setConfig($settingsConfig) {
118+
// if the config map is a string we should assume that its an api key
119+
if (is_string($settingsConfig)) {
120+
$settingsConfig = ['key'=>$settingsConfig];
121+
}
122+
114123
// Validate API key because its required
115124
if (!isset($settingsConfig['key']) || empty(trim($settingsConfig['key']))){
116125
throw new \Exception('You must provide an API key');

test/unit/SparkPostTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ public function testSetBadHTTPAdapter() {
5151
$this->resource->setHttpAdapter(new \stdClass());
5252
}
5353

54+
public function testSetConfigStringKey() {
55+
$this->resource->setConfig('a key');
56+
$config = self::$utils->getProperty($this->resource, 'config');
57+
$this->assertEquals('a key', $config['key']);
58+
}
59+
5460
/**
5561
* @expectedException Exception
5662
* @expectedExceptionMessageRegExp /API key/

0 commit comments

Comments
 (0)