<?php 

namespace App\Bundle\Notisend;
 
class Request
{
	private $client = null;
	private $token = '1ea37dfb1838675d5d3985220c7ad895';

	function __construct()
	{
		$this->client = new \GuzzleHttp\Client(
			['base_uri' => 'https://api.notisend.ru']
		);;
	}

    public function send($method = 'POST', $path = '/v1/email/messages', $params = NULL)
    {
    	$options = [
    		'debug' => false,
    		'verify' => false,
    		'http_errors' => false,
	        'allow_redirects' => [
	            'max' => 10,
	            'strict' => true,
	            'referer' => true,
	            'track_redirects' => true,
	        ],
			'headers' => [
              	'Authorization' => 'Bearer ' . $this->token,
                'Content-Encoding' =>  'UTF-8',
                'Content-Type' => 'application/json',
			]
		];

		if ($params) {
			$options['body'] = json_encode($params);
		}

    	$response = $this->client->request($method, $path, $options);    	

    	return $response->getBody()->getContents();
    }

    public function getTemplates()
    {
    	return $this->send('GET', '/v1/email/templates');
    }
}
