Skip to content

Commit 6171690

Browse files
author
tuck1s
committed
Updated and tested all examples. README updated.
Update transmissions GET & DELETE deprecations
1 parent eeb6ba9 commit 6171690

20 files changed

+164
-95
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,9 @@ test/output/
77
/composer.phar
88
composer.lock
99
test.php
10+
.php-version
11+
.gitignore
12+
.phpunit.result.cache
13+
.DS_Store
14+
.gitignore
15+
.vscode/launch.json

CHANGELOG.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ This project adheres to [Semantic Versioning](http://semver.org/).
44

55
## [Unreleased][unreleased]
66

7-
## [2.2.1] - 2021-03-08
7+
- [#200](https://github.com/SparkPost/php-sparkpost/pull/200) PHP 8 support
88

9-
- [#198](https://github.com/SparkPost/php-sparkpost/pull/198)
10-
- [#191](https://github.com/SparkPost/php-sparkpost/pull/191)
9+
## [2.2.1] - 2021-03-08
10+
- [#198](https://github.com/SparkPost/php-sparkpost/pull/198) Address #197: No longer need formfeed replacement. README work.
11+
- [#191](https://github.com/SparkPost/php-sparkpost/pull/191) Updating License
1112

1213
## [2.2.0] - 2019-06-04
13-
- [#187](https://github.com/SparkPost/php-sparkpost/pull/169) Updated composer.json
14+
- [#187](https://github.com/SparkPost/php-sparkpost/pull/187) Updated composer.json
1415
- [#169](https://github.com/SparkPost/php-sparkpost/pull/169) Optional automatic retry on 5xx
1516
- [#166](https://github.com/SparkPost/php-sparkpost/pull/166/files) Quick fix for using the API without composer
1617
- [#149](https://github.com/SparkPost/php-sparkpost/pull/149) Setters should return current object

README.md

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,9 @@ Sends an asynchronous request to the SparkPost API and returns a `SparkPostPromi
170170
* Type: `Array`
171171
* See constructor
172172

173-
173+
---
174174
## Endpoints
175175
### transmissions
176-
* **get([transmissionID] [, payload])**
177-
* `transmissionID` - see `uri` request options
178-
* `payload` - see request options
179176
* **post(payload)**
180177
* `payload` - see request options
181178
* `payload.cc`
@@ -186,8 +183,8 @@ Sends an asynchronous request to the SparkPost API and returns a `SparkPostPromi
186183
* Required: No
187184
* Type: `Array`
188185
* Recipients to descreetly recieve a carbon copy of the transmission
189-
* **delete(transmissionID)**
190-
* `transmissionID` - see `uri` request options
186+
187+
For complete list of endpoints, refer to [API documentation](https://developers.sparkpost.com/api/).
191188

192189
## Examples
193190

@@ -252,6 +249,26 @@ var_dump($results);
252249
?>
253250
```
254251

252+
More examples [here](./examples/):
253+
### Transmission
254+
- Create with attachment
255+
- Create with recipient list
256+
- Create with cc and bcc
257+
- Create with template
258+
- Create
259+
- Delete (scheduled transmission by campaign_id *only*)
260+
261+
### Template
262+
- Create
263+
- Get
264+
- Get (list) all
265+
- Update
266+
- Delete
267+
268+
### Message Events
269+
- get
270+
- get (with retry logic)
271+
255272
### Send An API Call Using The Base Request Function
256273
We provide a base request function to access any of our API resources.
257274
```php
@@ -274,7 +291,6 @@ $promise = $sparky->request('GET', 'metrics/ip-pools', [
274291
?>
275292
```
276293

277-
278294
## Handling Responses
279295
The API calls either return a `SparkPostPromise` or `SparkPostResponse` depending on if `async` is `true` or `false`
280296

examples/debug/index.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
* configure options in example-options.json
1515
*/
1616
$sparky = new SparkPost($httpClient, [
17-
"key" => "YOUR_API_KEY",
18-
// This will expose your API KEY - do not use this in production.
17+
"key" => getenv('SPARKPOST_API_KEY'),
18+
// fetch API KEY from environment variable
1919
"debug" => true
2020
]);
2121

examples/message-events/get_message_events.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010

1111
$httpClient = new GuzzleAdapter(new Client());
1212

13-
$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY",]);
13+
// In these examples, fetch API key from environment variable
14+
$sparky = new SparkPost($httpClient, ["key" => getenv('SPARKPOST_API_KEY')]);
1415

15-
$promise = $sparky->request('GET', 'message-events', [
16+
// New endpoint - https://developers.sparkpost.com/api/events/
17+
$promise = $sparky->request('GET', 'events/message', [
1618
'campaign_ids' => 'CAMPAIGN_ID',
1719
]);
1820

examples/message-events/get_message_events_with_retry_logic.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010

1111
$httpClient = new GuzzleAdapter(new Client());
1212

13-
$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY", "retries" => 3]);
13+
// In these examples, fetch API key from environment variable
14+
$sparky = new SparkPost($httpClient, ["key" => getenv('SPARKPOST_API_KEY'), "retries" => 3]);
1415

15-
$promise = $sparky->request('GET', 'message-events', [
16+
// New endpoint - https://developers.sparkpost.com/api/events/
17+
$promise = $sparky->request('GET', 'events/message', [
1618
'campaign_ids' => 'CAMPAIGN_ID',
1719
]);
1820

examples/templates/create_template.php

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,50 @@
1010

1111
$httpClient = new GuzzleAdapter(new Client());
1212

13-
$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
13+
// In these examples, fetch API key from environment variable
14+
$sparky = new SparkPost($httpClient, ["key" => getenv('SPARKPOST_API_KEY')]);
15+
16+
$template_name = "PHP example template";
17+
$template_id = "PHP-example-template";
18+
19+
// put your own sending domain here
20+
$sending_domain = "steve2-test.trymsys.net";
21+
22+
// Valid short template content examples
23+
$plain_text = 'Write your text message part here.';
24+
25+
$html = <<<HTML
26+
<!DOCTYPE html>
27+
<html lang="en">
28+
<body>
29+
<p><strong>Write your HTML message part here</strong></p>
30+
</body>
31+
</html>
32+
HTML;
33+
34+
$amp_html = <<<HTML
35+
<!doctype html>
36+
<html ⚡4email>
37+
<head>
38+
<meta charset="utf-8">
39+
<style amp4email-boilerplate>body{visibility:hidden}</style>
40+
<script async src="https://cdn.ampproject.org/v0.js"></script>
41+
</head>
42+
<body>
43+
Hello World! Let's get started using AMP HTML together!
44+
</body>
45+
</html>
46+
HTML;
1447

1548
$promise = $sparky->request('POST', 'templates', [
16-
'name' => 'PHP example template',
49+
'name' => $template_name,
50+
'id' => $template_id,
1751
'content' => [
18-
'from' => 'from@YOUR_DOMAIN',
52+
'from' => "from@$sending_domain",
1953
'subject' => 'Your Subject',
20-
'html' => '<b>Write your message here.</b>',
54+
'text' => $plain_text,
55+
'html' => $html,
56+
'amp_html' => $amp_html,
2157
],
2258
]);
2359

examples/templates/delete_template.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010

1111
$httpClient = new GuzzleAdapter(new Client());
1212

13-
$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
13+
// In these examples, fetch API key from environment variable
14+
$sparky = new SparkPost($httpClient, ["key" => getenv('SPARKPOST_API_KEY')]);
1415

15-
$promise = $sparky->request('DELETE', 'templates/TEMPLATE_ID');
16+
$template_id = "PHP-example-template";
17+
18+
$promise = $sparky->request('DELETE', "templates/$template_id");
1619

1720
try {
1821
$response = $promise->wait();

examples/templates/get_all_templates.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
$httpClient = new GuzzleAdapter(new Client());
1212

13-
$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
13+
// In these examples, fetch API key from environment variable
14+
$sparky = new SparkPost($httpClient, ["key" => getenv('SPARKPOST_API_KEY')]);
1415

1516
$promise = $sparky->request('GET', 'templates');
1617

examples/templates/get_template.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010

1111
$httpClient = new GuzzleAdapter(new Client());
1212

13-
$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
13+
// In these examples, fetch API key from environment variable
14+
$sparky = new SparkPost($httpClient, ["key" => getenv('SPARKPOST_API_KEY')]);
1415

15-
$promise = $sparky->request('GET', 'templates/TEMPLATE_ID?draft=true');
16+
$template_id = "PHP-example-template";
17+
18+
$promise = $sparky->request('GET', "templates/$template_id?draft=true");
1619

1720
try {
1821
$response = $promise->wait();

0 commit comments

Comments
 (0)