Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15408312
D19008.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D19008.diff
View Options
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -349,6 +349,7 @@
'PhutilPirateEnglishLocale' => 'internationalization/locales/PhutilPirateEnglishLocale.php',
'PhutilPortugueseBrazilLocale' => 'internationalization/locales/PhutilPortugueseBrazilLocale.php',
'PhutilPortuguesePortugalLocale' => 'internationalization/locales/PhutilPortuguesePortugalLocale.php',
+ 'PhutilPostmarkFuture' => 'future/postmark/PhutilPostmarkFuture.php',
'PhutilPregsprintfTestCase' => 'xsprintf/__tests__/PhutilPregsprintfTestCase.php',
'PhutilProcessGroupDaemon' => 'daemon/torture/PhutilProcessGroupDaemon.php',
'PhutilProseDiff' => 'utils/PhutilProseDiff.php',
@@ -986,6 +987,7 @@
'PhutilPirateEnglishLocale' => 'PhutilLocale',
'PhutilPortugueseBrazilLocale' => 'PhutilLocale',
'PhutilPortuguesePortugalLocale' => 'PhutilLocale',
+ 'PhutilPostmarkFuture' => 'FutureProxy',
'PhutilPregsprintfTestCase' => 'PhutilTestCase',
'PhutilProcessGroupDaemon' => 'PhutilTortureTestDaemon',
'PhutilProseDiff' => 'Phobject',
diff --git a/src/future/postmark/PhutilPostmarkFuture.php b/src/future/postmark/PhutilPostmarkFuture.php
new file mode 100644
--- /dev/null
+++ b/src/future/postmark/PhutilPostmarkFuture.php
@@ -0,0 +1,85 @@
+<?php
+
+final class PhutilPostmarkFuture extends FutureProxy {
+
+ private $future;
+ private $accessToken;
+ private $method;
+ private $parameters;
+
+ public function __construct() {
+ parent::__construct(null);
+ }
+
+ public function setAccessToken($token) {
+ $this->accessToken = $token;
+ return $this;
+ }
+
+ public function setClientID($client_id) {
+ $this->clientID = $client_id;
+ return $this;
+ }
+
+ public function setMethod($method, array $parameters) {
+ $this->method = $method;
+ $this->parameters = $parameters;
+ return $this;
+ }
+
+ protected function getProxiedFuture() {
+ if (!$this->future) {
+ if ($this->accessToken === null) {
+ throw new PhutilInvalidStateException('setAccessToken');
+ }
+
+ if ($this->method === null || $this->parameters === null) {
+ throw new PhutilInvalidStateException('setMethod');
+ }
+
+ $uri = id(new PhutilURI('https://api.postmarkapp.com/'))
+ ->setPath('/'.$this->method);
+
+ $request_body = phutil_json_encode($this->parameters);
+
+ $future = id(new HTTPSFuture($uri))
+ ->setData($request_body)
+ ->setMethod('POST')
+ ->addHeader('X-Postmark-Server-Token', $this->accessToken)
+ ->addHeader('Accept', 'application/json')
+ ->addHeader('Content-Type', 'application/json');
+
+ $this->future = $future;
+ }
+
+ return $this->future;
+ }
+
+ protected function didReceiveResult($result) {
+ list($status, $body, $headers) = $result;
+
+ if ($status->isError()) {
+ throw $status;
+ }
+
+ try {
+ $data = phutil_json_decode($body);
+ } catch (PhutilJSONParserException $ex) {
+ throw new PhutilProxyException(
+ pht('Expected JSON response from Postmark.'),
+ $ex);
+ }
+
+ if (idx($data, 'ErrorCode')) {
+ $error = $data['ErrorCode'];
+ throw new Exception(
+ pht(
+ 'Received error from Postmark: (%s) %s',
+ $error,
+ idx($data, 'Message')));
+ }
+
+ return $data;
+ }
+
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Mar 19, 10:25 PM (1 w, 6 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7712110
Default Alt Text
D19008.diff (3 KB)
Attached To
Mode
D19008: Add a Postmark API client
Attached
Detach File
Event Timeline
Log In to Comment