Permalink
Browse files

Removed the MailchimpSts provider as the service has been shut down

  • Loading branch information...
1 parent 7be1fc0 commit 386140ce8fbbacbd47d0261e24b47848e1a30c94 @stof stof committed Jan 10, 2013
Showing with 1 addition and 221 deletions.
  1. +1 −2 README.md
  2. +0 −82 lib/Stampie/Mailer/MailChimpSts.php
  3. +0 −137 tests/Stampie/Tests/Mailer/MailChimpStsTest.php
View
@@ -10,8 +10,7 @@ It is very easy to use and to integrate into your application as demonstrated be
* [Postmark](http://postmarkapp.com)
* [SendGrid](http://sendgrid.com)
-* [MailChimp](http://mailchimp.com) Their STS Api
-* [MailGun](http://mailgun.org)
+* [MailGun](http://www.mailgun.com)
* [Mandrill](http://mandrill.com/)
``` php
@@ -1,82 +0,0 @@
-<?php
-
-namespace Stampie\Mailer;
-
-use Stampie\Mailer;
-use Stampie\MessageInterface;
-use Stampie\Message\TaggableInterface;
-use Stampie\Adapter\ResponseInterface;
-use Stampie\Exception\HttpException;
-use Stampie\Exception\ApiException;
-
-/**
- * A Mailer for MailChimp STS http://mailchimp.com/features/simple-transactional-service/
- *
- * @author Henrik Bjornskov <henrik@bjrnskov.dk>
- */
-class MailChimpSts extends Mailer
-{
- /**
- * {@inheritdoc}
- *
- * Splits the ServerToken up and uses the last part as the <dc>. More information
- * is at http://apidocs.mailchimp.com/sts/rtfm/
- */
- protected function getEndpoint()
- {
- return strtr('http://<dc>.sts.mailchimp.com/1.0/SendEmail.json', array(
- '<dc>' => current(array_reverse(explode('-', $this->getServerToken())))
- ));
- }
-
- /**
- * {@inheritdoc}
- */
- protected function format(MessageInterface $message)
- {
- $from = $this->normalizeIdentity($message->getFrom());
-
- $toEmails = array();
- $toNames = array();
-
- foreach ($this->normalizeIdentities($message->getTo()) as $recipient) {
- $toEmails[] = $recipient->getEmail();
- $toNames[] = $recipient->getName();
- }
-
- $tags = array();
- if ($message instanceof TaggableInterface) {
- $tags = (array) $message->getTag();
- }
-
- $parameters = array(
- 'apikey' => $this->getServerToken(),
- 'message' => array_filter(array(
- 'html' => $message->getHtml(),
- 'text' => $message->getText(),
- 'subject' => $message->getSubject(),
- 'to_email' => $toEmails,
- 'to_name' => $toNames,
- 'from_email' => $from->getEmail(),
- 'from_name' => $from->getName(),
- 'reply_to' => $message->getReplyTo(),
- )),
- 'tags' => $tags,
- );
-
- return http_build_query($parameters);
- }
-
- /**
- * {@inheritdoc}
- *
- * "You can consider any non-200 HTTP response code an error - the returned data will contain more detailed information"
- */
- protected function handle(ResponseInterface $response)
- {
- $httpException = new HttpException($response->getStatusCode(), $response->getStatusText());
- $error = json_decode($response->getContent());
-
- throw new ApiException($error->message, $httpException);
- }
-}
@@ -1,137 +0,0 @@
-<?php
-
-namespace Stampie\Tests\Mailer;
-
-use Stampie\Tests\BaseMailerTest;
-use Stampie\Mailer\MailChimpSts;
-use Stampie\Adapter\Response;
-use Stampie\Adapter\ResponseInterface;
-use Stampie\MessageInterface;
-
-class MailChimpStsTest extends BaseMailerTest
-{
- const SERVER_TOKEN = '21381c475f2bccabdc860aa6dbe1c362d48688d7-us4';
-
- public function setUp()
- {
- parent::setUp();
-
- $this->mailer = new TestMailChimpSts(
- $this->adapter,
- self::SERVER_TOKEN
- );
- }
-
- /**
- * @dataProvider endpointDataProvider
- */
- public function testEndpoint($serverToken)
- {
- list(, $dc) = explode('-', $serverToken);
- $this->mailer->setServerToken($serverToken);
- $this->assertEquals('http://' . $dc . '.sts.mailchimp.com/1.0/SendEmail.json', $this->mailer->getEndpoint());
- }
-
- public function testFormat()
- {
- $message = $this->getMessageMock(
- $from = 'henrik@bjrnskov.dk',
- $to = 'hb@peytz.dk',
- $subject = 'Stampie is awesome',
- $html = 'asdad',
- $text = ''
- );
-
- $this->assertEquals(http_build_query(array(
- 'apikey' => self::SERVER_TOKEN,
- 'message' => array(
- 'html' => $html,
- 'subject' => $subject,
- 'to_email' => array($to),
- 'to_name' => array(null),
- 'from_email' => $from,
- ),
- )), $this->mailer->format($message));
- }
-
- public function testFormatTaggable()
- {
- $message = $this->getTaggableMessageMock(
- $from = 'hb@peytz.dk',
- $to = 'henrik@bjrnskov.dk',
- $subject = 'Stampie is awesome',
- $html = 'So what do you thing',
- $text = 'text',
- $headers = array('X-Stampie-To' => 'henrik+to@bjrnskov.dk'),
- $tag = 'tag'
- );
-
- $this->assertEquals(http_build_query(array(
- 'apikey' => self::SERVER_TOKEN,
- 'message' => array(
- 'html' => $html,
- 'text' => $text,
- 'subject' => $subject,
- 'to_email' => array($to),
- 'to_name' => array(null),
- 'from_email' => $from,
- ),
- 'tags' => array($tag)
- )), $this->mailer->format($message));
- }
-
- /**
- * @dataProvider handleDataProvider
- */
- public function testHandle($statusCode, $content)
- {
- $response = new Response($statusCode, json_encode(array('message' => $content)));
-
- try {
- $this->mailer->handle($response);
- } catch (\Stampie\Exception\ApiException $e) {
- $this->assertInstanceOf('Stampie\Exception\HttpException', $e->getPrevious());
- $this->assertEquals($e->getPrevious()->getMessage(), $content);
- $this->assertEquals($e->getMessage(), $content);
- return;
- }
-
- $this->fail('Expected Stampie\Exception\ApiException to be trown');
- }
-
- public function endpointDataProvider()
- {
- return array(
- array('82ce197df3e18234bc1535ccf5780f9f3cc79f92-uk1'),
- array('4cbd1e10f62a197d8397df258b04842ba10fced7-us3'),
- array('e02c993a61d86419f0e5ce8ee01a6e1373bb5623-us6'),
- );
- }
-
- public function handleDataProvider()
- {
- return array(
- array(400, 'Bad Request'),
- array(401, 'Unauthorized'),
- array(504, 'Gateway Timeout'),
- );
- }
-}
-
-class TestMailChimpSts extends MailChimpSts
-{
- public function getEndpoint()
- {
- return parent::getEndpoint();
- }
-
- public function format(MessageInterface $message)
- {
- return parent::format($message);
- }
-
- public function handle(ResponseInterface $response)
- {
- parent::handle($response);
- }
-}

0 comments on commit 386140c

Please sign in to comment.