Skip to content

Commit 558ade0

Browse files
bbredewoldLidbetter
authored andcommitted
Added ability to provide default options to SparkPost API (#8)
1 parent 89dbf8c commit 558ade0

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/SparkpostServiceProvider.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,16 @@ public function register()
4141
$manager->extend('sparkpost', function() {
4242

4343
$config = $this->app['config']->get('services.sparkpost', []);
44-
$options = isset($config['guzzle']) ? $config['guzzle'] : [];
45-
$client = new Client($options);
44+
$sparkpostOptions = isset($config['options']) ? $config['options'] : [];
45+
$guzzleOptions = isset($config['guzzle']) ? $config['guzzle'] : [];
46+
$client = new Client($guzzleOptions);
4647

4748
if(class_exists(AbstractTransport::class)) {
48-
return new SparkPostTransport($client, $config['secret']);
49+
return new SparkPostTransport($client, $config['secret'], $sparkpostOptions);
4950
}
5051

5152
// Fallback to implementation which only depends on Swift_Transport
52-
return new SparkPostTransportFiveZero($client, $config['secret']);
53+
return new SparkPostTransportFiveZero($client, $config['secret'], $sparkpostOptions);
5354
});
5455

5556
return $manager;

src/Transport/SparkPostTransportTrait.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Swift_Mime_Message;
66
use GuzzleHttp\ClientInterface;
77

8-
trait SparkPostTransportTrait
8+
trait SparkPostTransportTrait
99
{
1010
/**
1111
* Guzzle client instance.
@@ -26,11 +26,13 @@ trait SparkPostTransportTrait
2626
*
2727
* @param ClientInterface $client
2828
* @param string $key
29+
* @param array $options
2930
*/
30-
public function __construct(ClientInterface $client, $key)
31+
public function __construct(ClientInterface $client, $key, $options = [])
3132
{
3233
$this->client = $client;
3334
$this->key = $key;
35+
$this->options = $options;
3436
}
3537

3638
/**
@@ -56,6 +58,10 @@ public function send(Swift_Mime_Message $message, &$failedRecipients = null)
5658
],
5759
];
5860

61+
if ($this->options) {
62+
$options['json']['options'] = $this->options;
63+
}
64+
5965
return $this->client->post('https://api.sparkpost.com/api/v1/transmissions', $options);
6066
}
6167

@@ -70,7 +76,6 @@ public function send(Swift_Mime_Message $message, &$failedRecipients = null)
7076
protected function getRecipients(Swift_Mime_Message $message)
7177
{
7278
$to = [];
73-
7479
if ($getTo = $message->getTo()) {
7580
$to = array_merge($to, array_keys($getTo));
7681
}
@@ -110,4 +115,4 @@ public function setKey($key)
110115
{
111116
return $this->key = $key;
112117
}
113-
}
118+
}

0 commit comments

Comments
 (0)