33namespace LaravelFCM \Sender ;
44
55use 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