You've already forked laravel-push
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6ebae6201c | |||
| 9df8151682 |
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user