Permalink
Browse files

Added Postmark support.

  • Loading branch information...
1 parent f1a936a commit 746dd6f01754f9c0dd302f857cdaaf48bf081005 @m4tthumphrey committed Apr 22, 2012
Showing with 119 additions and 4 deletions.
  1. +35 −2 README.md
  2. +3 −2 bootstrap.php
  3. +75 −0 classes/provider/postmark.php
  4. +6 −0 config/postmark.php
View
@@ -18,10 +18,11 @@ The following list of providers are currently supported, feel free to fork and a
* Last.fm
* LinkedIn
* MailChimp
+* Postmark
* Tumblr
* Twitter
-* Vimeo
* [Twtmore](http://dev.twtmore.com/)
+* Vimeo
Usage
-----
@@ -225,8 +226,40 @@ Asana (HTTP Auth Basic)
return $user;
}
+Postmark
+--------
+
+ <?php
+
+ function send_email()
+ {
+ $provider = 'postmark';
+ if (($options = Config::load($provider)) === false) {
+ $options = Config::get($provider);
+ }
+
+ $postmark = Api::forge($provider, $options);
+
+ try
+ {
+ $message = $postmark->post('send', array(
+ 'To' => 'user@example.com',
+ 'From' => 'send@example.com',
+ 'Subject' => 'Hi there!',
+ 'TextBody' => 'Hi!'
+ ));
+ }
+ catch (Api\ApiException $e)
+ {
+ $message = null;
+ logger(\Fuel::L_ERROR, $e->getMessage(), __METHOD__);
+ }
+
+ return $message;
+ }
+
Twtmore
------------------------
+-------
<?php
View
@@ -23,9 +23,10 @@
'Api\\Api_HTTP_Auth' => __DIR__.'/classes/provider/httpauth.php',
'Api\\Api_HTTP_Auth_Basic' => __DIR__.'/classes/provider/httpauth/basic.php',
'Api\\Api_Asana' => __DIR__.'/classes/provider/httpauth/basic/asana.php',
-
+
'Api\\Api_Mailchimp' => __DIR__.'/classes/provider/mailchimp.php',
'Api\\Api_Lastfm' => __DIR__.'/classes/provider/lastfm.php',
- 'Api\\Api_Twtmore' => __DIR__.'/classes/provider/twtmore.php',
+ 'Api\\Api_Postmark' => __DIR__.'/classes/provider/postmark.php',
+ 'Api\\Api_Twtmore' => __DIR__.'/classes/provider/twtmore.php',
));
@@ -0,0 +1,75 @@
+<?php
+
+namespace Api;
+
+class Api_Postmark extends Api
+{
+ protected $api_key = null;
+
+ public function __construct($options = array())
+ {
+ $this->api_key = $options['api_key'];
+ }
+
+ public function api_url()
+ {
+ return 'http://api.postmarkapp.com/email';
+ }
+
+ public function build_request($path, $params = array(), $type = 'POST')
+ {
+ $params = \Format::forge($params)->to_json();
+ $request = \Request::forge($this->api_url(), array('driver' => 'curl'), $type)
+
+ ->set_header('X-Postmark-Server-Token', $this->api_key)
+ ->set_header('Accept', 'application/json')
+ ->set_header('Content-Type', 'application/json')
+ ->set_options(array(
+ 'SSL_VERIFYPEER' => false,
+ 'SSL_VERIFYHOST' => false,
+ 'CUSTOMREQUEST' => $type,
+ 'POSTFIELDS' => $params
+ ));
+
+ return $request;
+ }
+
+ public function callback($request)
+ {
+ $message = 'An error occurred connecting to the Postmark servers';
+ $code = 0;
+
+ try
+ {
+ $data = $request->execute();
+ $data = json_decode(json_encode($data->response()->body));
+
+ if (isset($data->ErrorCode))
+ {
+ throw new ApiException($data->Message, $data->ErrorCode);
+ }
+
+ return $data;
+ }
+ catch (\RequestStatusException $e)
+ {
+ $data = json_decode($e->getMessage());
+
+ if (isset($data->ErrorCode))
+ {
+ $code = $data->ErrorCode;
+ $message = $data->Message;
+ }
+ }
+ catch (ApiException $e)
+ {
+ throw $e;
+ }
+ catch (\Exception $e)
+ {
+ throw new ApiException($e->getMessage());
+ }
+
+ throw new ApiException($message, $code);
+ }
+}
View
@@ -0,0 +1,6 @@
+<?php
+
+return array(
+ 'api_key' => 'POSTMARK_API_TEST',
+
+);

0 comments on commit 746dd6f

Please sign in to comment.