summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/unwrapped/create_transmission.php47
-rw-r--r--examples/unwrapped/get_webhooks.php4
2 files changed, 50 insertions, 1 deletions
diff --git a/examples/unwrapped/create_transmission.php b/examples/unwrapped/create_transmission.php
new file mode 100644
index 0000000..f19ee6e
--- /dev/null
+++ b/examples/unwrapped/create_transmission.php
@@ -0,0 +1,47 @@
+<?php
+
+namespace Examples\Unwrapped;
+
+require_once dirname(__FILE__).'/../bootstrap.php';
+
+//pull in API key config
+$configFile = file_get_contents(dirname(__FILE__).'/../example-config.json');
+$config = json_decode($configFile, true);
+
+use SparkPost\SparkPost;
+use GuzzleHttp\Client;
+use Ivory\HttpAdapter\Guzzle6HttpAdapter;
+
+$httpAdapter = new Guzzle6HttpAdapter(new Client());
+$sparky = new SparkPost($httpAdapter, ['key' => $config['api-key']]);
+
+try {
+ // define the endpoint
+ $sparky->setupUnwrapped('transmissions');
+
+ $message = [
+ 'recipients' => [
+ [
+ 'address' => [
+ 'email' => 'john.doe@example.com',
+ ]
+ ]
+ ],
+ 'content' => [
+ 'from' => [
+ 'name' => 'From Envelope',
+ 'email' => 'from@sparkpostbox.com',
+ ],
+ 'html' => '<p>Hello World!</p>',
+ 'text' => 'Hello World!',
+ 'subject' => 'Example Email'
+ ]
+ ];
+ $results = $sparky->transmissions->create($message);
+ echo 'Congrats! You sent a message using SparkPost!';
+} catch (\Exception $exception) {
+ echo $exception->getAPIMessage()."\n";
+ echo $exception->getAPICode()."\n";
+ echo $exception->getAPIDescription()."\n";
+}
+
diff --git a/examples/unwrapped/get_webhooks.php b/examples/unwrapped/get_webhooks.php
index e149b21..90f7a9c 100644
--- a/examples/unwrapped/get_webhooks.php
+++ b/examples/unwrapped/get_webhooks.php
@@ -22,5 +22,7 @@ try {
echo 'Congrats! You got a list of all your webhooks from SparkPost!';
} catch (\Exception $exception) {
- echo $exception->getMessage();
+ echo $exception->getAPIMessage()."\n";
+ echo $exception->getAPICode()."\n";
+ echo $exception->getAPIDescription()."\n";
}