diff options
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 |