laravel-mail/BMailApi.php

43 lines
799 B
PHP
Raw Normal View History

2020-04-09 10:50:49 +02:00
<?php
namespace BMail;
use GuzzleHttp\Client;
class BMailApi
{
/**
* The API key
*
* @var string
*/
private $api_key;
public function __construct(string $api_key)
{
$this->api_key = $api_key;
}
public function send($template)
{
$url = "http://127.0.0.1:9000/api/project/template/send";
// TODO
// $url = "http://127.0.0.1:9000/api/project/template/send";
$client = new Client();
try {
return $client->request('post', $url, [
'form_params' => $template,
'headers' => ['Authorization' => 'Bearer ' . $this->api_key]
])->getBody();
} catch(\Exception $e) {
throw new BMailException($e->getMessage());
}
}
}