summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/bootstrap.php4
-rw-r--r--examples/message-events/get_message_events.php5
-rw-r--r--examples/templates/create_template.php5
-rw-r--r--examples/templates/delete_template.php5
-rw-r--r--examples/templates/get_all_templates.php5
-rw-r--r--examples/templates/get_template.php5
-rw-r--r--examples/templates/preview_template.php5
-rw-r--r--examples/templates/update_template.php5
-rw-r--r--examples/transmissions/create_transmission.php5
-rw-r--r--examples/transmissions/create_transmission_with_attachment.php55
-rw-r--r--examples/transmissions/create_transmission_with_cc_and_bcc.php5
-rw-r--r--examples/transmissions/create_transmission_with_recipient_list.php5
-rw-r--r--examples/transmissions/create_transmission_with_template.php5
-rw-r--r--examples/transmissions/delete_transmission.php5
-rw-r--r--examples/transmissions/get_all_transmissions.php5
-rw-r--r--examples/transmissions/get_transmission.php5
-rw-r--r--examples/transmissions/sparkpost.pngbin0 -> 6953 bytes
17 files changed, 69 insertions, 60 deletions
diff --git a/examples/bootstrap.php b/examples/bootstrap.php
index 1110ed3..688d53e 100644
--- a/examples/bootstrap.php
+++ b/examples/bootstrap.php
@@ -1,7 +1,3 @@
<?php
require_once dirname(__FILE__).'/../vendor/autoload.php';
-
-//pull in library options
-$optionsFile = file_get_contents(dirname(__FILE__).'/example-options.json');
-$options = json_decode($optionsFile, true);
diff --git a/examples/message-events/get_message_events.php b/examples/message-events/get_message_events.php
index e027df1..0a3c4ac 100644
--- a/examples/message-events/get_message_events.php
+++ b/examples/message-events/get_message_events.php
@@ -10,10 +10,7 @@ use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
$httpClient = new GuzzleAdapter(new Client());
-/*
- * configure options in example-options.json
- */
-$sparky = new SparkPost($httpClient, $options);
+$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY",]);
$promise = $sparky->request('GET', 'message-events', [
'campaign_ids' => 'CAMPAIGN_ID',
diff --git a/examples/templates/create_template.php b/examples/templates/create_template.php
index 826b076..ada8ff1 100644
--- a/examples/templates/create_template.php
+++ b/examples/templates/create_template.php
@@ -10,10 +10,7 @@ use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
$httpClient = new GuzzleAdapter(new Client());
-/*
- * configure options in example-options.json
- */
-$sparky = new SparkPost($httpClient, $options);
+$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
$promise = $sparky->request('POST', 'templates', [
'name' => 'PHP example template',
diff --git a/examples/templates/delete_template.php b/examples/templates/delete_template.php
index 0985c5f..906a308 100644
--- a/examples/templates/delete_template.php
+++ b/examples/templates/delete_template.php
@@ -10,10 +10,7 @@ use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
$httpClient = new GuzzleAdapter(new Client());
-/*
- * configure options in example-options.json
- */
-$sparky = new SparkPost($httpClient, $options);
+$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
$promise = $sparky->request('DELETE', 'templates/TEMPLATE_ID');
diff --git a/examples/templates/get_all_templates.php b/examples/templates/get_all_templates.php
index 25e222c..289ccb8 100644
--- a/examples/templates/get_all_templates.php
+++ b/examples/templates/get_all_templates.php
@@ -10,10 +10,7 @@ use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
$httpClient = new GuzzleAdapter(new Client());
-/*
- * configure options in example-options.json
- */
-$sparky = new SparkPost($httpClient, $options);
+$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
$promise = $sparky->request('GET', 'templates');
diff --git a/examples/templates/get_template.php b/examples/templates/get_template.php
index 9ae977e..1cd4d42 100644
--- a/examples/templates/get_template.php
+++ b/examples/templates/get_template.php
@@ -10,10 +10,7 @@ use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
$httpClient = new GuzzleAdapter(new Client());
-/*
- * configure options in example-options.json
- */
-$sparky = new SparkPost($httpClient, $options);
+$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
$promise = $sparky->request('GET', 'templates/TEMPLATE_ID?draft=true');
diff --git a/examples/templates/preview_template.php b/examples/templates/preview_template.php
index 0f0a1db..60f38c1 100644
--- a/examples/templates/preview_template.php
+++ b/examples/templates/preview_template.php
@@ -10,10 +10,7 @@ use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
$httpClient = new GuzzleAdapter(new Client());
-/*
- * configure options in example-options.json
- */
-$sparky = new SparkPost($httpClient, $options);
+$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
$promise = $sparky->request('POST', 'templates/TEMPLATE_ID/preview?draft=true', [
'substitution_data' => [
diff --git a/examples/templates/update_template.php b/examples/templates/update_template.php
index 4da186c..bc6ed53 100644
--- a/examples/templates/update_template.php
+++ b/examples/templates/update_template.php
@@ -10,10 +10,7 @@ use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
$httpClient = new GuzzleAdapter(new Client());
-/*
- * configure options in example-options.json
- */
-$sparky = new SparkPost($httpClient, $options);
+$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
$promise = $sparky->request('PUT', 'templates/TEMPLATE_ID', [
'options' => [
diff --git a/examples/transmissions/create_transmission.php b/examples/transmissions/create_transmission.php
index a7a1914..a46edd2 100644
--- a/examples/transmissions/create_transmission.php
+++ b/examples/transmissions/create_transmission.php
@@ -10,10 +10,7 @@ use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
$httpClient = new GuzzleAdapter(new Client());
-/*
- * configure options in example-options.json
- */
-$sparky = new SparkPost($httpClient, $options);
+$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
$promise = $sparky->transmissions->post([
'content' => [
diff --git a/examples/transmissions/create_transmission_with_attachment.php b/examples/transmissions/create_transmission_with_attachment.php
new file mode 100644
index 0000000..74c1822
--- /dev/null
+++ b/examples/transmissions/create_transmission_with_attachment.php
@@ -0,0 +1,55 @@
+<?php
+
+namespace Examples\Transmissions;
+
+require dirname(__FILE__).'/../bootstrap.php';
+
+use SparkPost\SparkPost;
+use GuzzleHttp\Client;
+use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
+
+$httpClient = new GuzzleAdapter(new Client());
+
+$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
+
+$filePath = dirname(__FILE__).'/';
+$fileName = 'sparkpost.png';
+$fileType = mime_content_type($filePath.$fileName);
+$fileData = base64_encode(file_get_contents($filePath.$fileName));
+
+$promise = $sparky->transmissions->post([
+ 'content' => [
+ 'from' => [
+ 'name' => 'SparkPost Team',
+ 'email' => 'from@sparkpostbox.com',
+ ],
+ 'subject' => 'Mailing With Attachment From PHP',
+ 'html' => '<html><body><h1>Congratulations, {{name}}!</h1><p>You just sent an email with an attachment!</p></body></html>',
+ 'text' => 'Congratulations, {{name}}! You just sent an email with an attachment',
+ 'attachments' => [
+ [
+ 'name' => $fileName,
+ 'type' => $fileType,
+ 'data' => $fileData,
+ ],
+ ],
+ ],
+ 'substitution_data' => ['name' => 'YOUR_FIRST_NAME'],
+ 'recipients' => [
+ [
+ 'address' => [
+ 'name' => 'YOUR_NAME',
+ 'email' => 'YOUR_EMAIL',
+ ],
+ ],
+ ],
+]);
+
+try {
+ $response = $promise->wait();
+ echo $response->getStatusCode()."\n";
+ print_r($response->getBody())."\n";
+} catch (\Exception $e) {
+ echo $e->getCode()."\n";
+ echo $e->getMessage()."\n";
+}
diff --git a/examples/transmissions/create_transmission_with_cc_and_bcc.php b/examples/transmissions/create_transmission_with_cc_and_bcc.php
index 5e1bf23..de65b29 100644
--- a/examples/transmissions/create_transmission_with_cc_and_bcc.php
+++ b/examples/transmissions/create_transmission_with_cc_and_bcc.php
@@ -10,10 +10,7 @@ use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
$httpClient = new GuzzleAdapter(new Client());
-/*
- * configure options in example-options.json
- */
-$sparky = new SparkPost($httpClient, $options);
+$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
$promise = $sparky->transmissions->post([
'content' => [
diff --git a/examples/transmissions/create_transmission_with_recipient_list.php b/examples/transmissions/create_transmission_with_recipient_list.php
index e658b0d..b8fa75f 100644
--- a/examples/transmissions/create_transmission_with_recipient_list.php
+++ b/examples/transmissions/create_transmission_with_recipient_list.php
@@ -10,10 +10,7 @@ use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
$httpClient = new GuzzleAdapter(new Client());
-/*
- * configure options in example-options.json
- */
-$sparky = new SparkPost($httpClient, $options);
+$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
$promise = $sparky->transmissions->post([
'content' => [
diff --git a/examples/transmissions/create_transmission_with_template.php b/examples/transmissions/create_transmission_with_template.php
index e8f3fb6..7bb9020 100644
--- a/examples/transmissions/create_transmission_with_template.php
+++ b/examples/transmissions/create_transmission_with_template.php
@@ -10,10 +10,7 @@ use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
$httpClient = new GuzzleAdapter(new Client());
-/*
- * configure options in example-options.json
- */
-$sparky = new SparkPost($httpClient, $options);
+$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
$promise = $sparky->transmissions->post([
'content' => ['template_id' => 'TEMPLATE_ID'],
diff --git a/examples/transmissions/delete_transmission.php b/examples/transmissions/delete_transmission.php
index ad0cc64..f62766c 100644
--- a/examples/transmissions/delete_transmission.php
+++ b/examples/transmissions/delete_transmission.php
@@ -10,10 +10,7 @@ use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
$httpClient = new GuzzleAdapter(new Client());
-/*
- * configure options in example-options.json
- */
-$sparky = new SparkPost($httpClient, $options);
+$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
$promise = $sparky->transmissions->delete('TRANSMISSION_ID');
diff --git a/examples/transmissions/get_all_transmissions.php b/examples/transmissions/get_all_transmissions.php
index 0b4eb7f..37646ba 100644
--- a/examples/transmissions/get_all_transmissions.php
+++ b/examples/transmissions/get_all_transmissions.php
@@ -10,10 +10,7 @@ use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
$httpClient = new GuzzleAdapter(new Client());
-/*
- * configure options in example-options.json
- */
-$sparky = new SparkPost($httpClient, $options);
+$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
$promise = $sparky->transmissions->get();
diff --git a/examples/transmissions/get_transmission.php b/examples/transmissions/get_transmission.php
index b149107..f62078f 100644
--- a/examples/transmissions/get_transmission.php
+++ b/examples/transmissions/get_transmission.php
@@ -10,10 +10,7 @@ use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
$httpClient = new GuzzleAdapter(new Client());
-/*
- * configure options in example-options.json
- */
-$sparky = new SparkPost($httpClient, $options);
+$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
$promise = $sparky->transmissions->get('TRANSMISSION_ID');
diff --git a/examples/transmissions/sparkpost.png b/examples/transmissions/sparkpost.png
new file mode 100644
index 0000000..140a146
--- /dev/null
+++ b/examples/transmissions/sparkpost.png
Binary files differ