diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/message-events/get_message_events.php | 29 | ||||
-rw-r--r-- | examples/templates/create_template.php | 34 | ||||
-rw-r--r-- | examples/templates/delete_template.php | 27 | ||||
-rw-r--r-- | examples/templates/get_all_templates.php | 27 | ||||
-rw-r--r-- | examples/templates/get_template.php | 27 | ||||
-rw-r--r-- | examples/templates/preview_template.php | 31 | ||||
-rw-r--r-- | examples/templates/update_template.php | 31 | ||||
-rw-r--r-- | examples/transmissions/create_transmission.php | 2 | ||||
-rw-r--r-- | examples/transmissions/create_transmission_with_cc_and_bcc.php | 6 | ||||
-rw-r--r-- | examples/transmissions/create_transmission_with_recipient_list.php | 39 | ||||
-rw-r--r-- | examples/transmissions/create_transmission_with_template.php | 38 | ||||
-rw-r--r-- | examples/transmissions/get_transmission.php | 27 |
12 files changed, 314 insertions, 4 deletions
diff --git a/examples/message-events/get_message_events.php b/examples/message-events/get_message_events.php new file mode 100644 index 0000000..bff4300 --- /dev/null +++ b/examples/message-events/get_message_events.php @@ -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"; +} diff --git a/examples/templates/create_template.php b/examples/templates/create_template.php new file mode 100644 index 0000000..c25b900 --- /dev/null +++ b/examples/templates/create_template.php @@ -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"; +} diff --git a/examples/templates/delete_template.php b/examples/templates/delete_template.php new file mode 100644 index 0000000..0985c5f --- /dev/null +++ b/examples/templates/delete_template.php @@ -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"; +} diff --git a/examples/templates/get_all_templates.php b/examples/templates/get_all_templates.php new file mode 100644 index 0000000..25e222c --- /dev/null +++ b/examples/templates/get_all_templates.php @@ -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"; +} diff --git a/examples/templates/get_template.php b/examples/templates/get_template.php new file mode 100644 index 0000000..9ae977e --- /dev/null +++ b/examples/templates/get_template.php @@ -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"; +} diff --git a/examples/templates/preview_template.php b/examples/templates/preview_template.php new file mode 100644 index 0000000..cdfa055 --- /dev/null +++ b/examples/templates/preview_template.php @@ -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"; +} diff --git a/examples/templates/update_template.php b/examples/templates/update_template.php new file mode 100644 index 0000000..1f467ce --- /dev/null +++ b/examples/templates/update_template.php @@ -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"; +} diff --git a/examples/transmissions/create_transmission.php b/examples/transmissions/create_transmission.php index 61478a8..a7a1914 100644 --- a/examples/transmissions/create_transmission.php +++ b/examples/transmissions/create_transmission.php @@ -23,7 +23,7 @@ $promise = $sparky->transmissions->post([ ], '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!', + 'text' => 'Congratulations, {{name}}! You just sent your very first mailing!', ], 'substitution_data' => ['name' => 'YOUR_FIRST_NAME'], 'recipients' => [ diff --git a/examples/transmissions/create_transmission_with_cc_and_bcc.php b/examples/transmissions/create_transmission_with_cc_and_bcc.php index eab64b8..5e1bf23 100644 --- a/examples/transmissions/create_transmission_with_cc_and_bcc.php +++ b/examples/transmissions/create_transmission_with_cc_and_bcc.php @@ -21,9 +21,9 @@ $promise = $sparky->transmissions->post([ 'name' => 'SparkPost Team', 'email' => 'from@sparkpostbox.com', ], - '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' => [ diff --git a/examples/transmissions/create_transmission_with_recipient_list.php b/examples/transmissions/create_transmission_with_recipient_list.php new file mode 100644 index 0000000..e658b0d --- /dev/null +++ b/examples/transmissions/create_transmission_with_recipient_list.php @@ -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' => 'from@sparkpostbox.com', + ], + '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"; +} diff --git a/examples/transmissions/create_transmission_with_template.php b/examples/transmissions/create_transmission_with_template.php new file mode 100644 index 0000000..e8f3fb6 --- /dev/null +++ b/examples/transmissions/create_transmission_with_template.php @@ -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"; +} diff --git a/examples/transmissions/get_transmission.php b/examples/transmissions/get_transmission.php new file mode 100644 index 0000000..b149107 --- /dev/null +++ b/examples/transmissions/get_transmission.php @@ -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"; +} |