Skip to content

Commit

Permalink
Merge pull request #28 from SparkPost/issue-27
Browse files Browse the repository at this point in the history
Issue 27
  • Loading branch information
beardyman committed Oct 14, 2015
2 parents 31ab390 + 47d8405 commit e6d3ed1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/SparkPost/SparkPost.php
Expand Up @@ -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
Expand Down Expand Up @@ -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');
Expand Down
6 changes: 6 additions & 0 deletions test/unit/SparkPostTest.php
Expand Up @@ -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/
Expand Down

0 comments on commit e6d3ed1

Please sign in to comment.