mirror of
https://github.com/bitinflow/expose.git
synced 2026-03-13 13:35:54 +00:00
Added the ability to retrieve welcome messags from APIs
This commit is contained in:
38
app/Server/Support/RetrieveWelcomeMessageFromApi.php
Normal file
38
app/Server/Support/RetrieveWelcomeMessageFromApi.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Server\Support;
|
||||
|
||||
use Exception;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Clue\React\Buzz\Browser;
|
||||
|
||||
class RetrieveWelcomeMessageFromApi
|
||||
{
|
||||
/** @var Browser */
|
||||
protected $browser;
|
||||
|
||||
/** @var string */
|
||||
protected $url;
|
||||
|
||||
public function __construct(Browser $browser)
|
||||
{
|
||||
$this->browser = $browser;
|
||||
|
||||
$this->url = config('expose.admin.welcome_message_api_url');
|
||||
}
|
||||
|
||||
public function forUser($user)
|
||||
{
|
||||
return $this->browser
|
||||
->get($this->url . '?' . http_build_query($user), [
|
||||
'Accept' => 'application/json',
|
||||
])
|
||||
->then(function (ResponseInterface $response) {
|
||||
$result = json_decode($response->getBody());
|
||||
|
||||
return $result->message ?? '';
|
||||
}, function (Exception $e) {
|
||||
return '';
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user