Skip to content

Commit

Permalink
Improve HTTP Client structure
Browse files Browse the repository at this point in the history
  • Loading branch information
mathleite committed Mar 27, 2020
1 parent 590fb49 commit f57be43
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 22 deletions.
4 changes: 2 additions & 2 deletions app/Notification/AppNotificationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@


use App\Notification\Client\HTTPClientAdapterInterface;
use App\Notification\Client\ResponseAdapterInterface;
use App\Notification\Client\HTTPResponseInterface;

interface AppNotificationInterface
{
public function __construct(HTTPClientAdapterInterface $client, string $message, string $messageType);

public function notify(): ResponseAdapterInterface;
public function notify(): HTTPResponseInterface;
}
9 changes: 4 additions & 5 deletions app/Notification/Client/Guzzle/GuzzleHTTPClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@


use App\Notification\Client\HTTPClientAdapterInterface;
use App\Notification\Client\ResponseAdapterInterface;
use App\Notification\Client\HTTPResponseInterface;
use GuzzleHttp\Client;
use Psr\Http\Message\ResponseInterface;

class GuzzleHTTPClient implements HTTPClientAdapterInterface
{
Expand All @@ -18,15 +17,15 @@ public function __construct()
$this->client = new Client();
}

public function post(string $url, array $params): ResponseAdapterInterface
public function post(string $url, array $params): HTTPResponseInterface
{
$clientResponse = $this->client->post(
$guzzleResponse = $this->client->post(
$url,
[
'json' => $params
]
);

return new GuzzleResponse($clientResponse);
return new HTTPResponse($guzzleResponse);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
namespace App\Notification\Client\Guzzle;


use App\Notification\Client\ResponseAdapterInterface;
use App\Notification\Client\HTTPResponseInterface;
use Psr\Http\Message\ResponseInterface;

class GuzzleResponse implements ResponseAdapterInterface
class HTTPResponse implements HTTPResponseInterface
{
private ResponseInterface $clientResponse;

Expand Down
2 changes: 1 addition & 1 deletion app/Notification/Client/HTTPClientAdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@

interface HTTPClientAdapterInterface
{
public function post(string $url, array $params): ResponseAdapterInterface;
public function post(string $url, array $params): HTTPResponseInterface;
}
14 changes: 14 additions & 0 deletions app/Notification/Client/HTTPResponseInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php


namespace App\Notification\Client;


use Psr\Http\Message\ResponseInterface;

interface HTTPResponseInterface
{
public function __construct(ResponseInterface $clientResponse);

public function getResponse(): array;
}
10 changes: 0 additions & 10 deletions app/Notification/Client/ResponseAdapterInterface.php

This file was deleted.

4 changes: 2 additions & 2 deletions app/Notification/Slack/SlackNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use App\Notification\AppNotificationInterface;
use App\Notification\Client\HTTPClientAdapterInterface;
use App\Notification\Client\ResponseAdapterInterface;
use App\Notification\Client\HTTPResponseInterface;

final class SlackNotification implements AppNotificationInterface
{
Expand All @@ -19,7 +19,7 @@ public function __construct(HTTPClientAdapterInterface $client, string $message,
$this->client = $client;
}

public function notify(): ResponseAdapterInterface
public function notify(): HTTPResponseInterface
{
return $this->client->post(
getenv('SLACK_API_WEBHOOK'),
Expand Down

0 comments on commit f57be43

Please sign in to comment.