@@ -77,17 +77,26 @@ private function getRemainingRequests(ResponseInterface $response): int
7777
7878 private function check (ResponseInterface $ response )
7979 {
80+ $ response ->getBody ()->rewind ();
81+ $ json = json_decode ($ response ->getBody ()->getContents (), true );
82+
8083 if ($ response ->getStatusCode () === 401 ) {
81- $ response ->getBody ()->rewind ();
82- $ json = json_decode ($ response ->getBody ()->getContents (), true );
84+ return new CallResult (
85+ false ,
86+ false ,
87+ $ this ->getRemainingRequests ($ response ),
88+ $ this ->getMaxRequests ($ response ),
89+ [$ json ["message " ]]
90+ );
91+ }
8392
93+ if ($ response ->getStatusCode () === 403 ) {
8494 return new CallResult (
8595 false ,
8696 false ,
8797 $ this ->getRemainingRequests ($ response ),
8898 $ this ->getMaxRequests ($ response ),
89- [$ json ["message " ]],
90- null
99+ [$ json ["message " ]]
91100 );
92101 }
93102
@@ -107,8 +116,7 @@ private function check(ResponseInterface $response)
107116 true ,
108117 $ this ->getRemainingRequests ($ response ),
109118 $ this ->getMaxRequests ($ response ),
110- ["rate limited " ],
111- null
119+ [$ json ["message " ]]
112120 );
113121 }
114122 }
@@ -329,7 +337,7 @@ public function link(array $arguments): CallResult
329337 "deviceId " => $ arguments ["deviceId " ],
330338 "identification " => $ this ->userIdentifiersToArray (
331339 new UserIdentified (
332- isset ($ arguments ["userId " ]) ? (string ) $ arguments ["userId " ] : null ,
340+ isset ($ arguments ["userId " ]) ? (string ) $ arguments ["userId " ] : null ,
333341 isset ($ arguments ["email " ]) ? (string ) $ arguments ["email " ] : null
334342 )
335343 ),
@@ -405,7 +413,14 @@ private function formatProperties(array $properties): array
405413 $ formatted = array ();
406414
407415 foreach ($ properties as $ name => $ value ) {
408- if (is_int ($ value ) || is_float ($ value ) || is_string ($ value ) || is_bool ($ value )) {
416+ if (
417+ is_int ($ value ) ||
418+ is_float ($ value ) ||
419+ is_string ($ value ) ||
420+ is_bool ($ value ) ||
421+ is_array ($ value ) ||
422+ is_null ($ value )
423+ ) {
409424 $ formatted [$ name ] = $ value ;
410425 continue ;
411426 }
@@ -426,7 +441,7 @@ public function upsertUser(array $user): CallResult
426441 $ payload = [
427442 "identification " => $ this ->userIdentifiersToArray (
428443 new UserIdentified (
429- isset ($ user ["userId " ]) ? (string ) $ user ["userId " ] : null ,
444+ isset ($ user ["userId " ]) ? (string ) $ user ["userId " ] : null ,
430445 isset ($ user ["email " ]) ? (string ) $ user ["email " ] : null
431446 )
432447 ),
@@ -485,7 +500,7 @@ public function upsertAccount(array $account): CallResult
485500 $ payload = [
486501 "identification " => $ this ->accountIdentifiersToArray (
487502 new AccountIdentified (
488- isset ($ account ["accountId " ]) ? (string ) $ account ["accountId " ] : null ,
503+ isset ($ account ["accountId " ]) ? (string ) $ account ["accountId " ] : null ,
489504 isset ($ account ["domain " ]) ? (string ) $ account ["domain " ] : null
490505 )
491506 ),
@@ -501,7 +516,7 @@ function (array $user) {
501516 return [
502517 "identification " => $ this ->userIdentifiersToArray (
503518 new UserIdentified (
504- isset ($ user ["userId " ]) ? (string ) $ user ["userId " ] : null ,
519+ isset ($ user ["userId " ]) ? (string ) $ user ["userId " ] : null ,
505520 isset ($ user ["email " ]) ? (string ) $ user ["email " ] : null
506521 )
507522 ),
0 commit comments