forked from SparkPost/php-sparkpost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
42 lines (31 loc) · 892 Bytes
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
namespace Examples\Templates;
require dirname(__FILE__).'/../bootstrap.php';
use SparkPost\SparkPost;
use GuzzleHttp\Client;
use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
$httpClient = new GuzzleAdapter(new Client());
/*
* configure options in example-options.json
*/
$sparky = new SparkPost($httpClient, [
"key" => getenv('SPARKPOST_API_KEY'),
// fetch API KEY from environment variable
"debug" => true
]);
$promise = $sparky->request('GET', 'templates');
try {
$response = $promise->wait();
var_dump($response);
echo "Request:\n";
print_r($response->getRequest());
echo "Response:\n";
echo $response->getStatusCode()."\n";
print_r($response->getBody())."\n";
} catch (\Exception $e) {
echo "Request:\n";
print_r($e->getRequest());
echo "Exception:\n";
echo $e->getCode()."\n";
echo $e->getMessage()."\n";
}