diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/bootstrap.php | 2 | ||||
-rw-r--r-- | examples/transmission/get_all_transmissions.php | 14 | ||||
-rw-r--r-- | examples/transmission/get_transmission.php | 14 | ||||
-rw-r--r-- | examples/transmission/rfc822.php | 32 | ||||
-rw-r--r-- | examples/transmission/send_transmission_all_fields.php | 69 | ||||
-rw-r--r-- | examples/transmission/simple_send.php | 38 | ||||
-rw-r--r-- | examples/transmission/stored_recipients_inline_content.php | 28 | ||||
-rw-r--r-- | examples/transmission/stored_template_send.php | 34 | ||||
-rw-r--r-- | examples/unwrapped/create_template.php | 33 |
9 files changed, 142 insertions, 122 deletions
diff --git a/examples/bootstrap.php b/examples/bootstrap.php index 8a5f839..774b159 100644 --- a/examples/bootstrap.php +++ b/examples/bootstrap.php @@ -1,3 +1,3 @@ <?php - require_once dirname(__FILE__).'/../vendor/autoload.php'; + require_once dirname(__FILE__).'/../vendor/autoload.php'; ?>
\ No newline at end of file diff --git a/examples/transmission/get_all_transmissions.php b/examples/transmission/get_all_transmissions.php index fb62ec7..afbe5aa 100644 --- a/examples/transmission/get_all_transmissions.php +++ b/examples/transmission/get_all_transmissions.php @@ -3,18 +3,20 @@ namespace Examples\Transmisson; require_once (dirname(__FILE__).'/../bootstrap.php'); //pull in API key config -$configFile = file_get_contents(dirname(__FILE__) . "/../example-config.json"); +$configFile = file_get_contents(dirname(__FILE__) . '/../example-config.json'); $config = json_decode($configFile, true); use SparkPost\SparkPost; -use SparkPost\Transmission; +use GuzzleHttp\Client; +use Ivory\HttpAdapter\Guzzle6HttpAdapter; -SparkPost::setConfig(array('key'=>$config['api-key'])); +$httpAdapter = new Guzzle6HttpAdapter(new Client()); +$sparky = new SparkPost($httpAdapter, ['key'=>$config['api-key']]); try { - $results = Transmission::all(); - echo 'Congrats you can use your SDK!'; + $results = $sparky->transmission->all(); + echo 'Congrats you can use your SDK!'; } catch (\Exception $exception) { - echo $exception->getMessage(); + echo $exception->getMessage(); } ?> diff --git a/examples/transmission/get_transmission.php b/examples/transmission/get_transmission.php index b4781d7..0bda953 100644 --- a/examples/transmission/get_transmission.php +++ b/examples/transmission/get_transmission.php @@ -3,18 +3,20 @@ namespace Examples\Transmisson; require_once (dirname(__FILE__).'/../bootstrap.php'); //pull in API key config -$configFile = file_get_contents(dirname(__FILE__) . "/../example-config.json"); +$configFile = file_get_contents(dirname(__FILE__) . '/../example-config.json'); $config = json_decode($configFile, true); use SparkPost\SparkPost; -use SparkPost\Transmission; +use GuzzleHttp\Client; +use Ivory\HttpAdapter\Guzzle6HttpAdapter; -SparkPost::setConfig(array('key'=>$config['api-key'])); +$httpAdapter = new Guzzle6HttpAdapter(new Client()); +$sparky = new SparkPost($httpAdapter, ['key'=>$config['api-key']]); try { - $results = Transmission::find('Your Transmission Id'); - echo 'Congrats you can use your SDK!'; + $results = $sparky->transmission->find('Your Transmission ID'); + echo 'Congrats you can use your SDK!'; } catch (\Exception $exception) { - echo $exception->getMessage(); + echo $exception->getMessage(); } ?> diff --git a/examples/transmission/rfc822.php b/examples/transmission/rfc822.php index 8163693..1054c57 100644 --- a/examples/transmission/rfc822.php +++ b/examples/transmission/rfc822.php @@ -3,27 +3,29 @@ namespace Examples\Transmisson; require_once (dirname(__FILE__).'/../bootstrap.php'); //pull in API key config -$configFile = file_get_contents(dirname(__FILE__) . "/../example-config.json"); +$configFile = file_get_contents(dirname(__FILE__) . '/../example-config.json'); $config = json_decode($configFile, true); use SparkPost\SparkPost; -use SparkPost\Transmission; +use GuzzleHttp\Client; +use Ivory\HttpAdapter\Guzzle6HttpAdapter; -SparkPost::setConfig(array('key'=>$config['api-key'])); +$httpAdapter = new Guzzle6HttpAdapter(new Client()); +$sparky = new SparkPost($httpAdapter, ['key'=>$config['api-key']]); try { - $results = Transmission::send(array( - 'recipients'=>array( - array( - 'address'=>array( - 'email'=>'john.doe@sample.com' - ) - ) - ), - 'rfc822'=>"Content-Type: text/plain\nFrom: From Envelope <from@example.com>\nSubject: Example Email\n\nHello World" - )); - echo 'Congrats you can use your SDK!'; + $results = $sparky->transmission->send([ + 'recipients'=>[ + [ + 'address'=>[ + 'email'=>'john.doe@example.com' + ] + ] + ], + 'rfc822'=>'Content-Type: text/plain\nFrom: From Envelope <from@sparkpostbox.com>\nSubject: Example Email\n\nHello World' + ]); + echo 'Congrats you can use your SDK!'; } catch (\Exception $exception) { - echo $exception->getMessage(); + echo $exception->getMessage(); } ?> diff --git a/examples/transmission/send_transmission_all_fields.php b/examples/transmission/send_transmission_all_fields.php index 28edbcc..749f0cb 100644 --- a/examples/transmission/send_transmission_all_fields.php +++ b/examples/transmission/send_transmission_all_fields.php @@ -3,45 +3,48 @@ namespace Examples\Transmisson; require_once (dirname(__FILE__).'/../bootstrap.php'); //pull in API key config -$configFile = file_get_contents(dirname(__FILE__) . "/../example-config.json"); +$configFile = file_get_contents(dirname(__FILE__) . '/../example-config.json'); $config = json_decode($configFile, true); use SparkPost\SparkPost; -use SparkPost\Transmission; +use GuzzleHttp\Client; +use Ivory\HttpAdapter\Guzzle6HttpAdapter; -SparkPost::setConfig(array('key'=>$config['api-key'])); +$httpAdapter = new Guzzle6HttpAdapter(new Client()); +$sparky = new SparkPost($httpAdapter, ['key'=>$config['api-key']]); try{ - $results = Transmission::send(array( - "campaign"=>"my-campaign", - "metadata"=>array( - "sample_campaign"=>true, - "type"=>"these are custom fields" - ), - "substitutionData"=>array( - "name"=>"Test Name" - ), - "description"=>"my description", - "replyTo"=>"reply@test.com", - "customHeaders"=>array( - "X-Custom-Header"=>"Sample Custom Header" - ), - "trackOpens"=>false, - "trackClicks"=>false, - "from"=>"From Envelope <from@example.com>", - "html"=>"<p>Hello World! Your name is: {{name}}</p>", - "text"=>"Hello World!", - "subject"=>"Example Email: {{name}}", - "recipients"=>array( - array( - "address"=>array( - "email"=>"john.doe@sample.com" - ) - ) - ) - )); - echo 'Congrats you can use your SDK!'; + $results = $sparky->transmission->send([ + 'campaign'=>'my-campaign', + 'metadata'=>[ + 'sample_campaign'=>true, + 'type'=>'these are custom fields' + ], + 'substitutionData'=>[ + 'name'=>'Test Name' + ], + 'description'=>'my description', + 'replyTo'=>'reply@test.com', + 'customHeaders'=>[ + 'X-Custom-Header'=>'Sample Custom Header' + ], + 'trackOpens'=>false, + 'trackClicks'=>false, + 'from'=>'From Envelope <from@sparkpostbox.com>', + 'html'=>'<p>Hello World! Your name is: {{name}}</p>', + 'text'=>'Hello World!', + 'subject'=>'Example Email: {{name}}', + 'recipients'=>[ + [ + 'address'=>[ + 'email'=>'john.doe@example.com' + ] + ] + ] + ]); + + echo 'Congrats you can use your SDK!'; } catch (\Exception $exception) { - echo $exception->getMessage(); + echo $exception->getMessage(); } ?> diff --git a/examples/transmission/simple_send.php b/examples/transmission/simple_send.php index eafc176..5844ecc 100644 --- a/examples/transmission/simple_send.php +++ b/examples/transmission/simple_send.php @@ -3,30 +3,32 @@ namespace Examples\Transmisson; require_once (dirname(__FILE__).'/../bootstrap.php'); //pull in API key config -$configFile = file_get_contents(dirname(__FILE__) . "/../example-config.json"); +$configFile = file_get_contents(dirname(__FILE__) . '/../example-config.json'); $config = json_decode($configFile, true); use SparkPost\SparkPost; -use SparkPost\Transmission; +use GuzzleHttp\Client; +use Ivory\HttpAdapter\Guzzle6HttpAdapter; -SparkPost::setConfig(array('key'=>$config['api-key'])); +$httpAdapter = new Guzzle6HttpAdapter(new Client()); +$sparky = new SparkPost($httpAdapter, ['key'=>$config['api-key']]); try { - $results = Transmission::send(array( - "from"=>"From Envelope <from@example.com>", - "html"=>"<p>Hello World!</p>", - "text"=>"Hello World!", - "subject"=>"Example Email", - "recipients"=>array( - array( - "address"=>array( - "email"=>"john.doe@example.com" - ) - ) - ) - )); - echo 'Congrats you can use your SDK!'; + $results = $sparky->transmission->send([ + 'from'=>'From Envelope <from@sparkpostbox.com>', + 'html'=>'<p>Hello World!</p>', + 'text'=>'Hello World!', + 'subject'=>'Example Email', + 'recipients'=>[ + [ + 'address'=>[ + 'email'=>'john.doe@example.com' + ] + ] + ] + ]); + echo 'Congrats you can use your SDK!'; } catch (\Exception $exception) { - echo $exception->getMessage(); + echo $exception->getMessage(); } ?> diff --git a/examples/transmission/stored_recipients_inline_content.php b/examples/transmission/stored_recipients_inline_content.php index a2dd8aa..9348f9b 100644 --- a/examples/transmission/stored_recipients_inline_content.php +++ b/examples/transmission/stored_recipients_inline_content.php @@ -3,27 +3,29 @@ namespace Examples\Transmisson; require_once (dirname(__FILE__).'/../bootstrap.php'); //pull in API key config -$configFile = file_get_contents(dirname(__FILE__) . "/../example-config.json"); +$configFile = file_get_contents(dirname(__FILE__) . '/../example-config.json'); $config = json_decode($configFile, true); use SparkPost\SparkPost; -use SparkPost\Transmission; +use GuzzleHttp\Client; +use Ivory\HttpAdapter\Guzzle6HttpAdapter; -SparkPost::setConfig(array('key'=>$config['api-key'])); +$httpAdapter = new Guzzle6HttpAdapter(new Client()); +$sparky = new SparkPost($httpAdapter, ['key'=>$config['api-key']]); try { - $results = Transmission::send(array( - "campaign"=>"my-campaign", - "from"=>"From Envelope <from@example.com>", - "html"=>"<p>Hello World! Your name is: {{name}}</p>", - "text"=>"Hello World!", - "subject"=>"Example Email: {{name}}", - "recipientList"=>'Example List' - )); + $results = $sparky->transmission->send([ + 'campaign'=>'my-campaign', + 'from'=>'From Envelope <from@sparkpostbox.com>', + 'html'=>'<p>Hello World! Your name is: {{name}}</p>', + 'text'=>'Hello World!', + 'subject'=>'Example Email: {{name}}', + 'recipientList'=>'Example List' + ]); - echo 'Congrats you can use your SDK!'; + echo 'Congrats you can use your SDK!'; } catch (\Exception $exception) { - echo $exception->getMessage(); + echo $exception->getMessage(); } ?> diff --git a/examples/transmission/stored_template_send.php b/examples/transmission/stored_template_send.php index 52dbb27..2e22609 100644 --- a/examples/transmission/stored_template_send.php +++ b/examples/transmission/stored_template_send.php @@ -3,28 +3,30 @@ namespace Examples\Transmisson; require_once (dirname(__FILE__).'/../bootstrap.php'); //pull in API key config -$configFile = file_get_contents(dirname(__FILE__) . "/../example-config.json"); +$configFile = file_get_contents(dirname(__FILE__) . '/../example-config.json'); $config = json_decode($configFile, true); use SparkPost\SparkPost; -use SparkPost\Transmission; +use GuzzleHttp\Client; +use Ivory\HttpAdapter\Guzzle6HttpAdapter; -SparkPost::setConfig(array('key'=>$config['api-key'])); +$httpAdapter = new Guzzle6HttpAdapter(new Client()); +$sparky = new SparkPost($httpAdapter, ['key'=>$config['api-key']]); try { - $results = Transmission::send(array( - "from"=>"From Envelope <from@example.com>", - "recipients"=>array( - array( - "address"=>array( - "email"=>"john.doe@sample.com" - ) - ) - ), - "template"=>"my-template" - )); - echo 'Congrats you can use your SDK!'; + $results = $sparky->transmission->send([ + 'from'=>'From Envelope <from@sparkpostbox.com>', + 'recipients'=>[ + [ + 'address'=>[ + 'email'=>'john.doe@example.com' + ] + ] + ], + 'template'=>'my-first-email' + ]); + echo 'Congrats you can use your SDK!'; } catch (\Exception $exception) { - echo $exception->getMessage(); + echo $exception->getMessage(); } ?> diff --git a/examples/unwrapped/create_template.php b/examples/unwrapped/create_template.php index 0e24fd6..a3431d4 100644 --- a/examples/unwrapped/create_template.php +++ b/examples/unwrapped/create_template.php @@ -3,27 +3,32 @@ namespace Examples\Unwrapped; require_once (dirname(__FILE__).'/../bootstrap.php'); //pull in API key config -$configFile = file_get_contents(dirname(__FILE__) . "/../example-config.json"); +$configFile = file_get_contents(dirname(__FILE__) . '/../example-config.json'); $config = json_decode($configFile, true); use SparkPost\SparkPost; -use SparkPost\APIResource; +use GuzzleHttp\Client; +use Ivory\HttpAdapter\Guzzle6HttpAdapter; -SparkPost::setConfig(array('key'=>$config['api-key'])); +$httpAdapter = new Guzzle6HttpAdapter(new Client()); +$sparky = new SparkPost($httpAdapter, ['key'=>$config['api-key']]); try { - // define the endpoint - APIResource::$endpoint = 'templates'; + // define the endpoint + $sparky->setupUnwrapped('templates'); - $templateConfig = array( - 'name' => 'Summer Sale!', - 'content.from' => 'marketing@bounces.company.example', - 'content.subject' => 'Summer deals', - 'content.html' => '<b>Check out these deals!</b>', - ); - $results = APIResource::sendRequest($templateConfig); - echo 'Congrats you can use your SDK!'; + $templateConfig = [ + 'name' => 'Summer Sale!', + 'id'=>'jordan-test-summer-sale', + 'content'=> [ + 'from' => 'from@sparkpostbox.com', + 'subject' => 'Summer deals', + 'html' => '<b>Check out these deals!</b>' + ] + ]; + $results = $sparky->templates->create($templateConfig); + echo 'Congrats you can use your SDK!'; } catch (\Exception $exception) { - echo $exception->getMessage(); + echo $exception->getMessage(); } ?> |