Skip to content
This repository was archived by the owner on Jun 28, 2024. It is now read-only.

Commit b05f60a

Browse files
author
Nicolas Brosy
committed
Merge branch 'arubacao-master'
2 parents ffb37d8 + d64aa52 commit b05f60a

17 files changed

+105
-56
lines changed

config/fcm.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
return [
44
'driver' => env('FCM_PROTOCOL', 'http'),
5-
'log_enabled' => true,
5+
'log_enabled' => false,
66

77
'http' => [
88
'server_key' => env('FCM_SERVER_KEY', 'Your FCM server key'),

src/Request/BaseRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ abstract class BaseRequest
1010
/**
1111
* @internal
1212
*
13-
* @var \GuzzleHttp\Client
13+
* @var \GuzzleHttp\ClientInterface
1414
*/
1515
protected $client;
1616

src/Response/BaseResponse.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace LaravelFCM\Response;
44

5-
use GuzzleHttp\Psr7\Response as GuzzleResponse;
5+
use Psr\Http\Message\ResponseInterface;
66
use LaravelFCM\Response\Exceptions\ServerResponseException;
77
use LaravelFCM\Response\Exceptions\InvalidRequestException;
88
use LaravelFCM\Response\Exceptions\UnauthorizedRequestException;
@@ -25,9 +25,9 @@ abstract class BaseResponse
2525
/**
2626
* BaseResponse constructor.
2727
*
28-
* @param GuzzleResponse $response
28+
* @param \Psr\Http\Message\ResponseInterface $response
2929
*/
30-
public function __construct(GuzzleResponse $response)
30+
public function __construct(ResponseInterface $response)
3131
{
3232
$this->isJsonResponse($response);
3333
$this->logEnabled = app('config')->get('fcm.log_enabled', false);
@@ -38,13 +38,13 @@ public function __construct(GuzzleResponse $response)
3838
/**
3939
* Check if the response given by fcm is parsable.
4040
*
41-
* @param GuzzleResponse $response
41+
* @param \Psr\Http\Message\ResponseInterface $response
4242
*
4343
* @throws InvalidRequestException
4444
* @throws ServerResponseException
4545
* @throws UnauthorizedRequestException
4646
*/
47-
private function isJsonResponse(GuzzleResponse $response)
47+
private function isJsonResponse(ResponseInterface $response)
4848
{
4949
if ($response->getStatusCode() == 200) {
5050
return;

src/Response/DownstreamResponse.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use Monolog\Logger;
66
use Monolog\Handler\StreamHandler;
7-
use GuzzleHttp\Psr7\Response as GuzzleResponse;
7+
use Psr\Http\Message\ResponseInterface;
88

99
/**
1010
* Class DownstreamResponse.
@@ -96,10 +96,10 @@ class DownstreamResponse extends BaseResponse implements DownstreamResponseContr
9696
/**
9797
* DownstreamResponse constructor.
9898
*
99-
* @param GuzzleResponse $response
99+
* @param \Psr\Http\Message\ResponseInterface $response
100100
* @param $tokens
101101
*/
102-
public function __construct(GuzzleResponse $response, $tokens)
102+
public function __construct(ResponseInterface $response, $tokens)
103103
{
104104
$this->tokens = is_string($tokens) ? [$tokens] : $tokens;
105105

src/Response/Exceptions/InvalidRequestException.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace LaravelFCM\Response\Exceptions;
44

55
use Exception;
6-
use GuzzleHttp\Psr7\Response as GuzzleResponse;
6+
use Psr\Http\Message\ResponseInterface;
77

88
/**
99
* Class InvalidRequestException.
@@ -13,9 +13,9 @@ class InvalidRequestException extends Exception
1313
/**
1414
* InvalidRequestException constructor.
1515
*
16-
* @param GuzzleResponse $response
16+
* @param \Psr\Http\Message\ResponseInterface $response
1717
*/
18-
public function __construct(GuzzleResponse $response)
18+
public function __construct(ResponseInterface $response)
1919
{
2020
$code = $response->getStatusCode();
2121
$responseBody = $response->getBody()->getContents();

src/Response/Exceptions/ServerResponseException.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace LaravelFCM\Response\Exceptions;
44

55
use Exception;
6-
use GuzzleHttp\Psr7\Response as GuzzleResponse;
6+
use Psr\Http\Message\ResponseInterface;
77

88
/**
99
* Class ServerResponseException.
@@ -20,9 +20,9 @@ class ServerResponseException extends Exception
2020
/**
2121
* ServerResponseException constructor.
2222
*
23-
* @param GuzzleResponse $response
23+
* @param \Psr\Http\Message\ResponseInterface $response
2424
*/
25-
public function __construct(GuzzleResponse $response)
25+
public function __construct(ResponseInterface $response)
2626
{
2727
$code = $response->getStatusCode();
2828
$responseHeader = $response->getHeaders();

src/Response/Exceptions/UnauthorizedRequestException.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace LaravelFCM\Response\Exceptions;
44

55
use Exception;
6-
use GuzzleHttp\Psr7\Response as GuzzleResponse;
6+
use Psr\Http\Message\ResponseInterface;
77

88
/**
99
* Class UnauthorizedRequestException.
@@ -13,9 +13,9 @@ class UnauthorizedRequestException extends Exception
1313
/**
1414
* UnauthorizedRequestException constructor.
1515
*
16-
* @param GuzzleResponse $response
16+
* @param \Psr\Http\Message\ResponseInterface $response
1717
*/
18-
public function __construct(GuzzleResponse $response)
18+
public function __construct(ResponseInterface $response)
1919
{
2020
$code = $response->getStatusCode();
2121

src/Response/GroupResponse.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use Monolog\Logger;
66
use Monolog\Handler\StreamHandler;
7-
use GuzzleHttp\Psr7\Response as GuzzleResponse;
7+
use Psr\Http\Message\ResponseInterface;
88

99
/**
1010
* Class GroupResponse.
@@ -44,10 +44,10 @@ class GroupResponse extends BaseResponse implements GroupResponseContract
4444
/**
4545
* GroupResponse constructor.
4646
*
47-
* @param GuzzleResponse $response
47+
* @param \Psr\Http\Message\ResponseInterface $response
4848
* @param $to
4949
*/
50-
public function __construct(GuzzleResponse $response, $to)
50+
public function __construct(ResponseInterface $response, $to)
5151
{
5252
$this->to = $to;
5353
parent::__construct($response);

src/Response/TopicResponse.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Monolog\Logger;
66
use LaravelFCM\Message\Topics;
77
use Monolog\Handler\StreamHandler;
8-
use GuzzleHttp\Psr7\Response as GuzzleResponse;
8+
use Psr\Http\Message\ResponseInterface;
99

1010
/**
1111
* Class TopicResponse.
@@ -45,10 +45,10 @@ class TopicResponse extends BaseResponse implements TopicResponseContract
4545
/**
4646
* TopicResponse constructor.
4747
*
48-
* @param GuzzleResponse $response
48+
* @param \Psr\Http\Message\ResponseInterface $response
4949
* @param Topics $topic
5050
*/
51-
public function __construct(GuzzleResponse $response, Topics $topic)
51+
public function __construct(ResponseInterface $response, Topics $topic)
5252
{
5353
$this->topic = $topic;
5454
parent::__construct($response);

src/Sender/FCMGroup.php

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace LaravelFCM\Sender;
44

55
use LaravelFCM\Request\GroupRequest;
6-
use GuzzleHttp\Psr7\Response as GuzzleResponse;
6+
use Psr\Http\Message\ResponseInterface;
77

88
/**
99
* Class FCMGroup.
@@ -19,12 +19,14 @@ class FCMGroup extends HTTPSender
1919
*
2020
* @param $notificationKeyName
2121
* @param array $registrationIds
22+
*
23+
* @return null|string notification_key
2224
*/
2325
public function createGroup($notificationKeyName, array $registrationIds)
2426
{
2527
$request = new GroupRequest(self::CREATE, $notificationKeyName, null, $registrationIds);
2628

27-
$response = $this->client->post($this->url, $request->build());
29+
$response = $this->client->request('post', $this->url, $request->build());
2830

2931
return $this->getNotificationToken($response);
3032
}
@@ -35,11 +37,12 @@ public function createGroup($notificationKeyName, array $registrationIds)
3537
* @param $notificationKeyName
3638
* @param $notificationKey
3739
* @param array $registrationIds registrationIds to add
40+
* @return null|string notification_key
3841
*/
3942
public function addToGroup($notificationKeyName, $notificationKey, array $registrationIds)
4043
{
4144
$request = new GroupRequest(self::ADD, $notificationKeyName, $notificationKey, $registrationIds);
42-
$response = $this->client->post($this->url, $request->build());
45+
$response = $this->client->request('post', $this->url, $request->build());
4346

4447
return $this->getNotificationToken($response);
4548
}
@@ -52,40 +55,40 @@ public function addToGroup($notificationKeyName, $notificationKey, array $regist
5255
* @param $notificationKeyName
5356
* @param $notificationKey
5457
* @param array $registeredIds registrationIds to remove
58+
* @return null|string notification_key
5559
*/
5660
public function removeFromGroup($notificationKeyName, $notificationKey, array $registeredIds)
5761
{
5862
$request = new GroupRequest(self::REMOVE, $notificationKeyName, $notificationKey, $registeredIds);
59-
$response = $this->client->post($this->url, $request->build());
63+
$response = $this->client->request('post', $this->url, $request->build());
6064

6165
return $this->getNotificationToken($response);
6266
}
6367

6468
/**
6569
* @internal
6670
*
67-
* @param GuzzleResponse $response
71+
* @param \Psr\Http\Message\ResponseInterface $response
72+
* @return null|string notification_key
6873
*/
69-
private function getNotificationToken(GuzzleResponse $response)
74+
private function getNotificationToken(ResponseInterface $response)
7075
{
71-
if ($this->isValidResponse($response)) {
76+
if (! $this->isValidResponse($response)) {
7277
return null;
7378
}
7479

75-
$json = json_decode($response->getBody(), true);
80+
$json = json_decode($response->getBody()->getContents(), true);
7681

7782
return $json['notification_key'];
7883
}
7984

8085
/**
81-
* @internal
82-
*
83-
* @param $response
86+
* @param \Psr\Http\Message\ResponseInterface $response
8487
*
8588
* @return bool
8689
*/
87-
public function isValidResponse(GuzzleResponse $response)
90+
public function isValidResponse(ResponseInterface $response)
8891
{
89-
return $response->getReasonPhrase() != 'OK' || $response->getStatusCode() != 200;
92+
return $response->getStatusCode() === 200;
9093
}
9194
}

0 commit comments

Comments
 (0)