diff options
author | Avi Goldman <avrahamymgoldman@gmail.com> | 2016-06-10 14:21:18 -0400 |
---|---|---|
committer | Avi Goldman <avrahamymgoldman@gmail.com> | 2016-06-10 14:21:18 -0400 |
commit | 9a295b1ab3c911b10ba9f25235ad557563b2ffd0 (patch) | |
tree | 7ce263d5054e9ea1be6219947547d881aed278e7 /lib/SparkPost/SparkPostPromise.php | |
parent | 425bc01d8b2915f114032777e03046cdd5884453 (diff) | |
download | php-sparkpost-9a295b1ab3c911b10ba9f25235ad557563b2ffd0.zip php-sparkpost-9a295b1ab3c911b10ba9f25235ad557563b2ffd0.tar.gz php-sparkpost-9a295b1ab3c911b10ba9f25235ad557563b2ffd0.tar.bz2 |
added sync and aysnc, cleaned up code
Diffstat (limited to 'lib/SparkPost/SparkPostPromise.php')
-rw-r--r-- | lib/SparkPost/SparkPostPromise.php | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/SparkPost/SparkPostPromise.php b/lib/SparkPost/SparkPostPromise.php new file mode 100644 index 0000000..462599a --- /dev/null +++ b/lib/SparkPost/SparkPostPromise.php @@ -0,0 +1,43 @@ +<?php + +namespace SparkPost; + +use Http\Promise\Promise as HttpPromise; + +class SparkPostPromise implements HttpPromise +{ + private $promise; + + public function __construct(HttpPromise $promise) { + $this->promise = $promise; + } + + public function then(callable $onFulfilled = null, callable $onRejected = null) { + $this->promise->then( + function($response) { + $onFulfilled(new SparkPostResponse($response)); + }, + function(\Exception $exception) { + $onRejected(new SparkPostException($exception)); + }); + } + + public function getState() { + return $this->promise->getState(); + } + + + public function wait($unwrap = true) { + try + { + $response = $this->promise->wait($unwrap); + return new SparkPostResponse($response); + } + catch (\Exception $exception) + { + throw new SparkPostException($exception); + } + } +} + +?>
\ No newline at end of file |