Skip to content

Commit 23448f0

Browse files
committed
added debug example
1 parent f9d5c0c commit 23448f0

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

examples/debug/index.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace Examples\Templates;
4+
5+
require dirname(__FILE__).'/../bootstrap.php';
6+
7+
use SparkPost\SparkPost;
8+
use GuzzleHttp\Client;
9+
use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
10+
11+
$httpClient = new GuzzleAdapter(new Client());
12+
13+
/*
14+
* configure options in example-options.json
15+
*/
16+
$sparky = new SparkPost($httpClient, [
17+
"key" => "YOUR_API_KEY",
18+
// This will expose your API KEY - do not use this in production.
19+
"debug" => true
20+
]);
21+
22+
$promise = $sparky->request('GET', 'templates');
23+
24+
try {
25+
$response = $promise->wait();
26+
27+
var_dump($response);
28+
29+
echo "Request:\n";
30+
print_r($response->getRequest());
31+
32+
echo "Response:\n";
33+
echo $response->getStatusCode()."\n";
34+
print_r($response->getBody())."\n";
35+
} catch (\Exception $e) {
36+
echo "Request:\n";
37+
print_r($e->getRequest());
38+
39+
echo "Exception:\n";
40+
echo $e->getCode()."\n";
41+
echo $e->getMessage()."\n";
42+
}

0 commit comments

Comments
 (0)