summaryrefslogtreecommitdiff
path: root/app/Core
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-06-07 22:17:50 -0400
committerFrederic Guillot <fred@kanboard.net>2015-06-07 22:17:50 -0400
commite22da9d32addefa8d739171febcf6f6d0c06ba7b (patch)
treeaffb9f8729ac9d4f07dd7f24dff39bfaa9cda0ff /app/Core
parent4f32352fe62e47ad5ea760eb00493bdc061b2407 (diff)
Add Mailgun API as mail transport
Diffstat (limited to 'app/Core')
-rw-r--r--app/Core/Base.php2
-rw-r--r--app/Core/EmailClient.php3
-rw-r--r--app/Core/HttpClient.php50
3 files changed, 45 insertions, 10 deletions
diff --git a/app/Core/Base.php b/app/Core/Base.php
index 5e179b13..6cb87cbc 100644
--- a/app/Core/Base.php
+++ b/app/Core/Base.php
@@ -22,7 +22,7 @@ use Pimple\Container;
* @property \Integration\GitlabWebhook $gitlabWebhook
* @property \Integration\HipchatWebhook $hipchatWebhook
* @property \Integration\Jabber $jabber
- * @property \Integration\MailgunWebhook $mailgunWebhook
+ * @property \Integration\Mailgun $mailgun
* @property \Integration\Postmark $postmark
* @property \Integration\SendgridWebhook $sendgridWebhook
* @property \Integration\SlackWebhook $slackWebhook
diff --git a/app/Core/EmailClient.php b/app/Core/EmailClient.php
index 980f5acc..07687c42 100644
--- a/app/Core/EmailClient.php
+++ b/app/Core/EmailClient.php
@@ -31,6 +31,9 @@ class EmailClient extends Base
}
switch (MAIL_TRANSPORT) {
+ case 'mailgun':
+ $this->mailgun->sendEmail($email, $name, $subject, $html, $author);
+ break;
case 'postmark':
$this->postmark->sendEmail($email, $name, $subject, $html, $author);
break;
diff --git a/app/Core/HttpClient.php b/app/Core/HttpClient.php
index fcfb1a47..2f280a1e 100644
--- a/app/Core/HttpClient.php
+++ b/app/Core/HttpClient.php
@@ -32,7 +32,7 @@ class HttpClient extends Base
const HTTP_USER_AGENT = 'Kanboard';
/**
- * Send a POST HTTP request
+ * Send a POST HTTP request encoded in JSON
*
* @access public
* @param string $url
@@ -40,17 +40,49 @@ class HttpClient extends Base
* @param array $headers
* @return string
*/
- public function post($url, array $data, array $headers = array())
+ public function postJson($url, array $data, array $headers = array())
+ {
+ return $this->doRequest(
+ $url,
+ json_encode($data),
+ array_merge(array('Content-type: application/json'), $headers)
+ );
+ }
+
+ /**
+ * Send a POST HTTP request encoded in www-form-urlencoded
+ *
+ * @access public
+ * @param string $url
+ * @param array $data
+ * @param array $headers
+ * @return string
+ */
+ public function postForm($url, array $data, array $headers = array())
+ {
+ return $this->doRequest(
+ $url,
+ http_build_query($data),
+ array_merge(array('Content-type: application/x-www-form-urlencoded'), $headers)
+ );
+ }
+
+ /**
+ * Make the HTTP request
+ *
+ * @access private
+ * @param string $url
+ * @param array $content
+ * @param array $headers
+ * @return string
+ */
+ private function doRequest($url, $content, array $headers)
{
if (empty($url)) {
return '';
}
- $headers = array_merge(array(
- 'User-Agent: '.self::HTTP_USER_AGENT,
- 'Content-Type: application/json',
- 'Connection: close',
- ), $headers);
+ $headers = array_merge(array('User-Agent: '.self::HTTP_USER_AGENT, 'Connection: close'), $headers);
$context = stream_context_create(array(
'http' => array(
@@ -59,7 +91,7 @@ class HttpClient extends Base
'timeout' => self::HTTP_TIMEOUT,
'max_redirects' => self::HTTP_MAX_REDIRECTS,
'header' => implode("\r\n", $headers),
- 'content' => json_encode($data)
+ 'content' => $content
)
));
@@ -75,7 +107,7 @@ class HttpClient extends Base
if (DEBUG) {
$this->container['logger']->debug('HttpClient: url='.$url);
- $this->container['logger']->debug('HttpClient: payload='.var_export($data, true));
+ $this->container['logger']->debug('HttpClient: payload='.$content);
$this->container['logger']->debug('HttpClient: metadata='.var_export(@stream_get_meta_data($stream), true));
$this->container['logger']->debug('HttpClient: response='.$response);
}