global test mode + fixes
This commit is contained in:
parent
9df8151682
commit
6ebae6201c
|
@ -4,6 +4,7 @@ namespace Bluesquare\Push;
|
||||||
|
|
||||||
use Bluesquare\Push\PushTemplate;
|
use Bluesquare\Push\PushTemplate;
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
use Psr\Http\Message\StreamInterface;
|
use Psr\Http\Message\StreamInterface;
|
||||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||||
|
|
||||||
|
@ -73,25 +74,24 @@ class PushApi
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($value as $subkey => $subvalue) {
|
$values = Arr::dot($value);
|
||||||
|
|
||||||
|
foreach ($values as $subkey => $subvalue) {
|
||||||
|
$subkey = str_replace('.', '][', $subkey);
|
||||||
|
|
||||||
$multipart_form[] = [
|
$multipart_form[] = [
|
||||||
'name' => "{$key}[$subkey]" . (is_array($subvalue) ? '[' . key($subvalue) . ']' : '' ),
|
'name' => "{$key}[$subkey]",
|
||||||
'contents' => (is_array($subvalue) ? reset($subvalue) : $subvalue)
|
'contents' => is_array($subvalue) ? json_encode($subvalue) : $subvalue
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
return $client->request('post', $url, [
|
||||||
return $client->request('post', $url, [
|
'multipart' => $multipart_form,
|
||||||
'multipart' => $multipart_form,
|
'headers' => [
|
||||||
'headers' => [
|
'Authorization' => 'Bearer ' . $this->api_key,
|
||||||
'Authorization' => 'Bearer ' . $this->api_key,
|
'Accept' => 'application/json'
|
||||||
'Accept' => 'application/json'
|
]
|
||||||
]
|
])->getBody();
|
||||||
])->getBody();
|
|
||||||
|
|
||||||
} catch(\Exception $e) {
|
|
||||||
throw new PushException($e->getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,6 +78,10 @@ class PushTemplate implements \JsonSerializable
|
||||||
public function __construct(string $template_id)
|
public function __construct(string $template_id)
|
||||||
{
|
{
|
||||||
$this->template_id = $template_id;
|
$this->template_id = $template_id;
|
||||||
|
|
||||||
|
if (env('PUSH_TEST_MODE', false)) {
|
||||||
|
$this->testMode();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue