From 6ebae6201cddce0155848c71fabb2d4dc1ca7d00 Mon Sep 17 00:00:00 2001 From: Maxime Renou Date: Wed, 5 Feb 2025 19:42:54 +0100 Subject: [PATCH] global test mode + fixes --- src/PushApi.php | 32 ++++++++++++++++---------------- src/PushTemplate.php | 4 ++++ 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/PushApi.php b/src/PushApi.php index a614988..1de2fa1 100644 --- a/src/PushApi.php +++ b/src/PushApi.php @@ -4,6 +4,7 @@ namespace Bluesquare\Push; use Bluesquare\Push\PushTemplate; use GuzzleHttp\Client; +use Illuminate\Support\Arr; use Psr\Http\Message\StreamInterface; use Symfony\Component\HttpFoundation\File\UploadedFile; @@ -73,25 +74,24 @@ class PushApi continue; } - foreach ($value as $subkey => $subvalue) { + $values = Arr::dot($value); + + foreach ($values as $subkey => $subvalue) { + $subkey = str_replace('.', '][', $subkey); + $multipart_form[] = [ - 'name' => "{$key}[$subkey]" . (is_array($subvalue) ? '[' . key($subvalue) . ']' : '' ), - 'contents' => (is_array($subvalue) ? reset($subvalue) : $subvalue) + 'name' => "{$key}[$subkey]", + 'contents' => is_array($subvalue) ? json_encode($subvalue) : $subvalue ]; } } - - try { - return $client->request('post', $url, [ - 'multipart' => $multipart_form, - 'headers' => [ - 'Authorization' => 'Bearer ' . $this->api_key, - 'Accept' => 'application/json' - ] - ])->getBody(); - - } catch(\Exception $e) { - throw new PushException($e->getMessage()); - } + + return $client->request('post', $url, [ + 'multipart' => $multipart_form, + 'headers' => [ + 'Authorization' => 'Bearer ' . $this->api_key, + 'Accept' => 'application/json' + ] + ])->getBody(); } } diff --git a/src/PushTemplate.php b/src/PushTemplate.php index ed98279..f80eb2c 100644 --- a/src/PushTemplate.php +++ b/src/PushTemplate.php @@ -78,6 +78,10 @@ class PushTemplate implements \JsonSerializable public function __construct(string $template_id) { $this->template_id = $template_id; + + if (env('PUSH_TEST_MODE', false)) { + $this->testMode(); + } } /**