Skip to content

Commit

Permalink
Remove the Stampie Response (#100)
Browse files Browse the repository at this point in the history
* Remove the Stampie Response

* removed type casting
  • Loading branch information
Nyholm authored Feb 4, 2018
1 parent 19b4629 commit 55bc297
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 206 deletions.
114 changes: 0 additions & 114 deletions lib/Adapter/Response.php

This file was deleted.

31 changes: 0 additions & 31 deletions lib/Adapter/ResponseInterface.php

This file was deleted.

13 changes: 5 additions & 8 deletions lib/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
use Http\Discovery\MessageFactoryDiscovery;
use Http\Message\MessageFactory;
use Http\Message\MultipartStream\MultipartStreamBuilder;
use Stampie\Adapter\Response;
use Stampie\Adapter\ResponseInterface;
use Psr\Http\Message\ResponseInterface;
use Stampie\Util\IdentityUtils;

/**
Expand Down Expand Up @@ -108,7 +107,7 @@ public function send(MessageInterface $message)
$response = $this->doSend($message);

// We are all clear if status is HTTP 2xx OK
if ($response->isSuccessful()) {
if (in_array($response->getStatusCode(), range(200, 206), true)) {
return;
}

Expand Down Expand Up @@ -203,11 +202,11 @@ protected function buildIdentityString($identities)
}

/**
* Take a Message and return a Stampie Response.
* Take a Message and return a PSR ResponseInterface.
*
* @param MessageInterface $message
*
* @return Response
* @return ResponseInterface
*/
private function doSend(MessageInterface $message)
{
Expand Down Expand Up @@ -248,8 +247,6 @@ private function doSend(MessageInterface $message)
}

$request = $this->getMessageFactory()->createRequest('POST', $this->getEndpoint(), $headers, $content);
$psr7Response = $this->getHttpClient()->sendRequest($request);

return new Response($psr7Response->getStatusCode(), $psr7Response->getBody()->__toString());
return $this->getHttpClient()->sendRequest($request);
}
}
4 changes: 2 additions & 2 deletions lib/Mailer/MailGun.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Stampie\Mailer;

use Stampie\Adapter\ResponseInterface;
use Psr\Http\Message\ResponseInterface;
use Stampie\Attachment;
use Stampie\Exception\HttpException;
use Stampie\Mailer;
Expand Down Expand Up @@ -122,7 +122,7 @@ protected function format(MessageInterface $message)
*/
protected function handle(ResponseInterface $response)
{
throw new HttpException($response->getStatusCode(), $response->getStatusText());
throw new HttpException($response->getStatusCode(), $response->getReasonPhrase());
}

/**
Expand Down
6 changes: 3 additions & 3 deletions lib/Mailer/Mandrill.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Stampie\Mailer;

use Stampie\Adapter\ResponseInterface;
use Psr\Http\Message\ResponseInterface;
use Stampie\Attachment;
use Stampie\Exception\ApiException;
use Stampie\Exception\HttpException;
Expand Down Expand Up @@ -106,8 +106,8 @@ protected function format(MessageInterface $message)
*/
protected function handle(ResponseInterface $response)
{
$httpException = new HttpException($response->getStatusCode(), $response->getStatusText());
$error = json_decode($response->getContent());
$httpException = new HttpException($response->getStatusCode(), $response->getReasonPhrase());
$error = json_decode((string) $response->getBody());

throw new ApiException($error->message, $httpException, $error->code);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Mailer/Postmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Stampie\Mailer;

use Stampie\Adapter\ResponseInterface;
use Psr\Http\Message\ResponseInterface;
use Stampie\Attachment;
use Stampie\Exception\ApiException;
use Stampie\Exception\HttpException;
Expand Down Expand Up @@ -32,11 +32,11 @@ protected function getEndpoint()
*/
protected function handle(ResponseInterface $response)
{
$httpException = new HttpException($response->getStatusCode(), $response->getStatusText());
$httpException = new HttpException($response->getStatusCode(), $response->getReasonPhrase());

// Not 422 contains information about API Error
if ($response->getStatusCode() == 422) {
$error = json_decode($response->getContent());
$error = json_decode((string) $response->getBody());
throw new ApiException(isset($error->Message) ? $error->Message : 'Unprocessable Entity', $httpException);
}

Expand Down
6 changes: 3 additions & 3 deletions lib/Mailer/SendGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Stampie\Mailer;

use Stampie\Adapter\ResponseInterface;
use Psr\Http\Message\ResponseInterface;
use Stampie\Attachment;
use Stampie\Exception\ApiException;
use Stampie\Exception\HttpException;
Expand Down Expand Up @@ -35,14 +35,14 @@ protected function getEndpoint()
*/
protected function handle(ResponseInterface $response)
{
$httpException = new HttpException($response->getStatusCode(), $response->getStatusText());
$httpException = new HttpException($response->getStatusCode(), $response->getReasonPhrase());

// 4xx will content error information in the body encoded as JSON
if (!in_array($response->getStatusCode(), range(400, 417))) {
throw $httpException;
}

$error = json_decode($response->getContent());
$error = json_decode((string) $response->getBody());
$message = '';
foreach ($error->errors as $i => $e) {
$message .= sprintf(
Expand Down
42 changes: 0 additions & 42 deletions tests/Stampie/Tests/Adapter/ResponseTest.php

This file was deleted.

0 comments on commit 55bc297

Please sign in to comment.