-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added example of getting transmission by ID * updated example messages and added example with recipient list and template * fixed lib to work with recipient lists * fixed lib to work with recipient lists * added test covering recipient list * added message event example * added template examples
- Loading branch information
1 parent
e325c04
commit 1bbefef
Showing
14 changed files
with
352 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?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, $options); | ||
|
||
$promise = $sparky->request('GET', 'message-events', [ | ||
'campaign_ids' => 'CAMPAIGN_ID' | ||
]); | ||
|
||
try { | ||
$response = $promise->wait(); | ||
echo $response->getStatusCode()."\n"; | ||
print_r($response->getBody())."\n"; | ||
} catch (\Exception $e) { | ||
echo $e->getCode()."\n"; | ||
echo $e->getMessage()."\n"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?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, $options); | ||
|
||
$promise = $sparky->request('POST', 'templates', [ | ||
"name" => "PHP example template", | ||
"content" => [ | ||
"from" => "from@YOUR_DOMAIN", | ||
"subject" => "Your Subject", | ||
"html" => "<b>Write your message here.</b>" | ||
] | ||
]); | ||
|
||
try { | ||
$response = $promise->wait(); | ||
echo $response->getStatusCode()."\n"; | ||
print_r($response->getBody())."\n"; | ||
} catch (\Exception $e) { | ||
echo $e->getCode()."\n"; | ||
echo $e->getMessage()."\n"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?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, $options); | ||
|
||
$promise = $sparky->request('DELETE', 'templates/TEMPLATE_ID'); | ||
|
||
try { | ||
$response = $promise->wait(); | ||
echo $response->getStatusCode()."\n"; | ||
print_r($response->getBody())."\n"; | ||
} catch (\Exception $e) { | ||
echo $e->getCode()."\n"; | ||
echo $e->getMessage()."\n"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?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, $options); | ||
|
||
$promise = $sparky->request('GET', 'templates'); | ||
|
||
try { | ||
$response = $promise->wait(); | ||
echo $response->getStatusCode()."\n"; | ||
print_r($response->getBody())."\n"; | ||
} catch (\Exception $e) { | ||
echo $e->getCode()."\n"; | ||
echo $e->getMessage()."\n"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?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, $options); | ||
|
||
$promise = $sparky->request('GET', 'templates/TEMPLATE_ID?draft=true'); | ||
|
||
try { | ||
$response = $promise->wait(); | ||
echo $response->getStatusCode()."\n"; | ||
print_r($response->getBody())."\n"; | ||
} catch (\Exception $e) { | ||
echo $e->getCode()."\n"; | ||
echo $e->getMessage()."\n"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?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, $options); | ||
|
||
$promise = $sparky->request('POST', 'templates/TEMPLATE_ID/preview?draft=true', [ | ||
'substitution_data' => [ | ||
'some_key' => 'some_value' | ||
] | ||
]); | ||
|
||
try { | ||
$response = $promise->wait(); | ||
echo $response->getStatusCode()."\n"; | ||
print_r($response->getBody())."\n"; | ||
} catch (\Exception $e) { | ||
echo $e->getCode()."\n"; | ||
echo $e->getMessage()."\n"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?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, $options); | ||
|
||
$promise = $sparky->request('PUT', 'templates/TEMPLATE_ID', [ | ||
'options' => [ | ||
'open_tracking' => true | ||
] | ||
]); | ||
|
||
try { | ||
$response = $promise->wait(); | ||
echo $response->getStatusCode()."\n"; | ||
print_r($response->getBody())."\n"; | ||
} catch (\Exception $e) { | ||
echo $e->getCode()."\n"; | ||
echo $e->getMessage()."\n"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,9 +21,9 @@ | |
'name' => 'SparkPost Team', | ||
'email' => '[email protected]', | ||
], | ||
'subject' => 'First Mailing From PHP', | ||
'html' => '<html><body><h1>Congratulations, {{name}}!</h1><p>You just sent your very first mailing!</p></body></html>', | ||
'text' => 'Congratulations, {{name}}!! You just sent your very first mailing!', | ||
'subject' => 'Mailing With CC and BCC From PHP', | ||
'html' => '<html><body><h1>Congratulations, {{name}}!</h1><p>You just sent your very first mailing with CC and BCC recipients!</p></body></html>', | ||
'text' => 'Congratulations, {{name}}! You just sent your very first mailing with CC and BCC recipients!', | ||
], | ||
'substitution_data' => ['name' => 'YOUR_FIRST_NAME'], | ||
'recipients' => [ | ||
|
39 changes: 39 additions & 0 deletions
39
examples/transmissions/create_transmission_with_recipient_list.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?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()); | ||
|
||
/* | ||
* configure options in example-options.json | ||
*/ | ||
$sparky = new SparkPost($httpClient, $options); | ||
|
||
$promise = $sparky->transmissions->post([ | ||
'content' => [ | ||
'from' => [ | ||
'name' => 'SparkPost Team', | ||
'email' => '[email protected]', | ||
], | ||
'subject' => 'Mailing With Recipient List From PHP', | ||
'html' => '<html><body><h1>Congratulations, {{name}}!</h1><p>You just sent an email to everyone on your recipient list!</p></body></html>', | ||
'text' => 'Congratulations, {{name}}! You just sent an email to everyone on your recipient list!', | ||
], | ||
'substitution_data' => ['name' => 'YOUR_FIRST_NAME'], | ||
'recipients' => ['list_id' => 'RECIPIENT_LIST_ID'], | ||
]); | ||
|
||
try { | ||
$response = $promise->wait(); | ||
echo $response->getStatusCode()."\n"; | ||
print_r($response->getBody())."\n"; | ||
} catch (\Exception $e) { | ||
echo $e->getCode()."\n"; | ||
echo $e->getMessage()."\n"; | ||
} |
38 changes: 38 additions & 0 deletions
38
examples/transmissions/create_transmission_with_template.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?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()); | ||
|
||
/* | ||
* configure options in example-options.json | ||
*/ | ||
$sparky = new SparkPost($httpClient, $options); | ||
|
||
$promise = $sparky->transmissions->post([ | ||
'content' => ['template_id' => 'TEMPLATE_ID'], | ||
'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"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?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()); | ||
|
||
/* | ||
* configure options in example-options.json | ||
*/ | ||
$sparky = new SparkPost($httpClient, $options); | ||
|
||
$promise = $sparky->transmissions->get('TRANSMISSION_ID'); | ||
|
||
try { | ||
$response = $promise->wait(); | ||
echo $response->getStatusCode()."\n"; | ||
print_r($response->getBody())."\n"; | ||
} catch (\Exception $e) { | ||
echo $e->getCode()."\n"; | ||
echo $e->getMessage()."\n"; | ||
} |
Oops, something went wrong.