Skip to content

Commit

Permalink
added attachment example
Browse files Browse the repository at this point in the history
added attachment example
  • Loading branch information
avigoldman committed Jan 10, 2017
2 parents f4cb526 + 6bcfbd1 commit 36afb9f
Show file tree
Hide file tree
Showing 20 changed files with 69 additions and 66 deletions.
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -3,7 +3,6 @@
.settings
.buildpath
test/output/
examples/example-options.json
.idea
/composer.phar
test.php
2 changes: 0 additions & 2 deletions composer.json
Expand Up @@ -9,8 +9,6 @@
],
"minimum-stability": "stable",
"scripts": {
"post-install-cmd": "./post-install.sh",
"post-update-cmd": "./post-install.sh",
"test": "./vendor/bin/phpunit",
"fix-style": "php-cs-fixer fix ."
},
Expand Down
4 changes: 0 additions & 4 deletions 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);
5 changes: 1 addition & 4 deletions examples/message-events/get_message_events.php
Expand Up @@ -10,10 +10,7 @@

$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',
Expand Down
5 changes: 1 addition & 4 deletions examples/templates/create_template.php
Expand Up @@ -10,10 +10,7 @@

$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',
Expand Down
5 changes: 1 addition & 4 deletions examples/templates/delete_template.php
Expand Up @@ -10,10 +10,7 @@

$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');

Expand Down
5 changes: 1 addition & 4 deletions examples/templates/get_all_templates.php
Expand Up @@ -10,10 +10,7 @@

$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');

Expand Down
5 changes: 1 addition & 4 deletions examples/templates/get_template.php
Expand Up @@ -10,10 +10,7 @@

$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');

Expand Down
5 changes: 1 addition & 4 deletions examples/templates/preview_template.php
Expand Up @@ -10,10 +10,7 @@

$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' => [
Expand Down
5 changes: 1 addition & 4 deletions examples/templates/update_template.php
Expand Up @@ -10,10 +10,7 @@

$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' => [
Expand Down
5 changes: 1 addition & 4 deletions examples/transmissions/create_transmission.php
Expand Up @@ -10,10 +10,7 @@

$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' => [
Expand Down
55 changes: 55 additions & 0 deletions 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";
}
Expand Up @@ -10,10 +10,7 @@

$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' => [
Expand Down
Expand Up @@ -10,10 +10,7 @@

$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' => [
Expand Down
5 changes: 1 addition & 4 deletions examples/transmissions/create_transmission_with_template.php
Expand Up @@ -10,10 +10,7 @@

$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'],
Expand Down
5 changes: 1 addition & 4 deletions examples/transmissions/delete_transmission.php
Expand Up @@ -10,10 +10,7 @@

$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');

Expand Down
5 changes: 1 addition & 4 deletions examples/transmissions/get_all_transmissions.php
Expand Up @@ -10,10 +10,7 @@

$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();

Expand Down
5 changes: 1 addition & 4 deletions examples/transmissions/get_transmission.php
Expand Up @@ -10,10 +10,7 @@

$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');

Expand Down
Binary file added examples/transmissions/sparkpost.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 0 additions & 3 deletions post-install.sh

This file was deleted.

0 comments on commit 36afb9f

Please sign in to comment.