3 Commits
0.1 ... 0.4

Author SHA1 Message Date
6ebae6201c global test mode + fixes 2025-02-05 19:42:54 +01:00
9df8151682 add custom locale per recipient 2025-01-23 15:40:48 +01:00
3178fc309c fix composer.json 2025-01-20 14:28:12 +01:00
3 changed files with 30 additions and 18 deletions

View File

@@ -29,7 +29,7 @@
"extra": {
"laravel": {
"providers": [
"PushServiceProvider"
"Bluesquare\\Push\\PushServiceProvider"
]
}
},

View File

@@ -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();
}
}

View File

@@ -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();
}
}
/**
@@ -138,6 +142,10 @@ class PushTemplate implements \JsonSerializable
$data['unsubscribe_url'] = $recipient['unsubscribe_url'];
}
if (! empty($recipient['locale'])) {
$data['locale'] = $recipient['locale'];
}
$this->recipients[] = $data;
}
}
@@ -152,7 +160,7 @@ class PushTemplate implements \JsonSerializable
* @param string|null $unsubscribe_url
* @return $this
*/
public function addRecipient(string $email, string $name = null, array $parameters = [], string $unsubscribe_url = null): PushTemplate
public function addRecipient(string $email, string $name = null, array $parameters = [], string $unsubscribe_url = null, string $locale = null): PushTemplate
{
$data = [
'email' => $email
@@ -170,6 +178,10 @@ class PushTemplate implements \JsonSerializable
$data['unsubscribe_url'] = $unsubscribe_url;
}
if (! is_null($locale)) {
$data['locale'] = $locale;
}
$this->recipients[] = $data;
return $this;