summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAvi Goldman <avrahamymgoldman@gmail.com>2016-06-10 15:16:26 -0400
committerAvi Goldman <avrahamymgoldman@gmail.com>2016-06-10 15:16:26 -0400
commit0cebe422480e3df4b633a5e74452b6b00351cfe6 (patch)
tree77de137eeb5511cce2431197670f0562a503d412
parenta145c9149a77b2dfe9af2d2aaa857f119040863c (diff)
downloadphp-sparkpost-0cebe422480e3df4b633a5e74452b6b00351cfe6.zip
php-sparkpost-0cebe422480e3df4b633a5e74452b6b00351cfe6.tar.gz
php-sparkpost-0cebe422480e3df4b633a5e74452b6b00351cfe6.tar.bz2
added support for async/sync option
-rw-r--r--lib/SparkPost/SparkPost.php14
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/SparkPost/SparkPost.php b/lib/SparkPost/SparkPost.php
index 9b586bc..05a73b1 100644
--- a/lib/SparkPost/SparkPost.php
+++ b/lib/SparkPost/SparkPost.php
@@ -18,7 +18,8 @@ class SparkPost
'port' => 443,
'key' => '',
'version' => 'v1',
- 'timeout' => 10
+ 'timeout' => 10,
+ 'async' => true
];
public $transmissions;
@@ -30,7 +31,16 @@ class SparkPost
$this->setupEndpoints();
}
- public function request($method = 'GET', $uri = '', $payload = [], $headers = [])
+ public function request($method = 'GET', $uri = '', $payload = [], $headers = []) {
+ if ($this->options['async'] === true && $this->httpClient instanceof HttpAsyncClient) {
+ $this->syncRequest($method = 'GET', $uri = '', $payload = [], $headers = []);
+ }
+ else {
+ $this->asyncRequest($method = 'GET', $uri = '', $payload = [], $headers = []);
+ }
+ }
+
+ public function syncRequest($method = 'GET', $uri = '', $payload = [], $headers = [])
{
$request = $this->buildRequest($method, $uri, $payload, $headers);
try