Skip to content

Commit dd4964a

Browse files
author
SteveT
authored
Merge pull request #198 from SparkPost/formfeed
Address #197: No longer need formfeed replacement. README work.
2 parents fe98775 + 7b84442 commit dd4964a

File tree

3 files changed

+78
-44
lines changed

3 files changed

+78
-44
lines changed

Diff for: CHANGELOG.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ This project adheres to [Semantic Versioning](http://semver.org/).
44

55
## [Unreleased][unreleased]
66

7+
## [2.2.1] - 2021-03-08
8+
9+
- [#198](https://github.com/SparkPost/php-sparkpost/pull/198)
10+
- [#191](https://github.com/SparkPost/php-sparkpost/pull/191)
11+
712
## [2.2.0] - 2019-06-04
813
- [#187](https://github.com/SparkPost/php-sparkpost/pull/169) Updated composer.json
914
- [#169](https://github.com/SparkPost/php-sparkpost/pull/169) Optional automatic retry on 5xx
@@ -103,7 +108,8 @@ This major release included a complete refactor of the library to be a thin HTTP
103108
### Fixed
104109
- README now has proper code blocks denoting PHP language
105110

106-
[unreleased]: https://github.com/sparkpost/php-sparkpost/compare/2.2.0...HEAD
111+
[unreleased]: https://github.com/sparkpost/php-sparkpost/compare/2.2.1...HEAD
112+
[2.2.1]: https://github.com/sparkpost/php-sparkpost/compare/2.2.0...2.2.1
107113
[2.2.0]: https://github.com/sparkpost/php-sparkpost/compare/2.1.0...2.2.0
108114
[2.1.0]: https://github.com/sparkpost/php-sparkpost/compare/2.0.3...2.1.0
109115
[2.0.3]: https://github.com/sparkpost/php-sparkpost/compare/2.0.2...2.0.3

Diff for: README.md

+69-37
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ curl -sS https://getcomposer.org/installer | php
2626
Sparkpost requires php-http client (see [Setting up a Request Adapter](#setting-up-a-request-adapter)). There are several [providers](https://packagist.org/providers/php-http/client-implementation) available. If you were using guzzle6 your install might look like this.
2727

2828
```
29-
composer require guzzlehttp/guzzle
30-
composer require php-http/guzzle6-adapter
29+
composer require php-http/guzzle6-adapter "^1.1"
30+
composer require guzzlehttp/guzzle "^6.0"
3131
```
3232

3333
Next, run the Composer command to install the SparkPost PHP Library:
@@ -43,7 +43,29 @@ require 'vendor/autoload.php';
4343
use SparkPost\SparkPost;
4444
```
4545

46-
**Note:** Without composer the costs outweight the benefits of using the PHP client library. A simple function like the one in [issue #164](https://github.com/SparkPost/php-sparkpost/issues/164#issuecomment-289888237) wraps the SparkPost API and makes it easy to use the API without resolving the composer dependencies.
46+
**Note:** Without composer the costs outweigh the benefits of using the PHP client library. A simple function like the one in [issue #164](https://github.com/SparkPost/php-sparkpost/issues/164#issuecomment-289888237) wraps the SparkPost API and makes it easy to use the API without resolving the composer dependencies.
47+
48+
## Running with IDEs
49+
50+
When running with `xdebug` under an IDE such as VS Code, you may see an exception is thrown in file `vendor/php-http/discovery/src/Strategy/PuliBetaStrategy.php`:
51+
52+
```
53+
Exception has occurred.
54+
Http\Discovery\Exception\PuliUnavailableException: Puli Factory is not available
55+
```
56+
57+
[This is usual](http://docs.php-http.org/en/latest/discovery.html#puli-factory-is-not-available). Puli is not required to use the library. You can resume running after the exception.
58+
59+
You can prevent the exception, by setting the discovery strategies, prior to creating the adapter object:
60+
```php
61+
// Prevent annoying "Puli exception" during work with xdebug / IDE
62+
// See https://github.com/getsentry/sentry-php/issues/801
63+
\Http\Discovery\ClassDiscovery::setStrategies([
64+
// \Http\Discovery\Strategy\PuliBetaStrategy::class, // Deliberately disabled
65+
\Http\Discovery\Strategy\CommonClassesStrategy::class,
66+
\Http\Discovery\Strategy\CommonPsr17ClassesStrategy::class,
67+
]);
68+
```
4769

4870
## Setting up a Request Adapter
4971

@@ -179,44 +201,54 @@ use GuzzleHttp\Client;
179201
use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
180202

181203
$httpClient = new GuzzleAdapter(new Client());
182-
$sparky = new SparkPost($httpClient, ['key'=>'YOUR_API_KEY']);
204+
// Good practice to not have API key literals in code - set an environment variable instead
205+
$sparky = new SparkPost($httpClient, ['key' => getenv('SPARKPOST_API_KEY')]);
206+
// For simple example, use synchronous model
207+
$sparky->setOptions(['async' => false]);
183208

184-
$promise = $sparky->transmissions->post([
185-
'content' => [
186-
'from' => [
187-
'name' => 'SparkPost Team',
188-
'email' => '[email protected]',
209+
try {
210+
$response = $sparky->transmissions->post([
211+
'content' => [
212+
'from' => [
213+
'name' => 'SparkPost Team',
214+
'email' => '[email protected]',
215+
],
216+
'subject' => 'First Mailing From PHP',
217+
'html' => '<html><body><h1>Congratulations, {{name}}!</h1><p>You just sent your very first mailing!</p></body></html>',
218+
'text' => 'Congratulations, {{name}}!! You just sent your very first mailing!',
189219
],
190-
'subject' => 'First Mailing From PHP',
191-
'html' => '<html><body><h1>Congratulations, {{name}}!</h1><p>You just sent your very first mailing!</p></body></html>',
192-
'text' => 'Congratulations, {{name}}!! You just sent your very first mailing!',
193-
],
194-
'substitution_data' => ['name' => 'YOUR_FIRST_NAME'],
195-
'recipients' => [
196-
[
197-
'address' => [
198-
'name' => 'YOUR_NAME',
199-
'email' => 'YOUR_EMAIL',
220+
'substitution_data' => ['name' => 'YOUR_FIRST_NAME'],
221+
'recipients' => [
222+
[
223+
'address' => [
224+
'name' => 'YOUR_NAME',
225+
'email' => 'YOUR_EMAIL',
226+
],
200227
],
201228
],
202-
],
203-
'cc' => [
204-
[
205-
'address' => [
206-
'name' => 'ANOTHER_NAME',
207-
'email' => 'ANOTHER_EMAIL',
229+
'cc' => [
230+
[
231+
'address' => [
232+
'name' => 'ANOTHER_NAME',
233+
'email' => 'ANOTHER_EMAIL',
234+
],
208235
],
209236
],
210-
],
211-
'bcc' => [
212-
[
213-
'address' => [
214-
'name' => 'AND_ANOTHER_NAME',
215-
'email' => 'AND_ANOTHER_EMAIL',
237+
'bcc' => [
238+
[
239+
'address' => [
240+
'name' => 'AND_ANOTHER_NAME',
241+
'email' => 'AND_ANOTHER_EMAIL',
242+
],
216243
],
217244
],
218-
],
219-
]);
245+
]);
246+
} catch (\Exception $error) {
247+
var_dump($error);
248+
}
249+
print($response->getStatusCode());
250+
$results = $response->getBody()['results'];
251+
var_dump($results);
220252
?>
221253
```
222254

@@ -250,8 +282,8 @@ The API calls either return a `SparkPostPromise` or `SparkPostResponse` dependin
250282
```php
251283
$sparky->setOptions(['async' => false]);
252284
try {
253-
$response = $sparky->transmissions->get();
254-
285+
$response = $sparky->transmissions->get(); //TODO: Change this. Transmissions no longer supports GET call
286+
255287
echo $response->getStatusCode()."\n";
256288
print_r($response->getBody())."\n";
257289
}
@@ -265,7 +297,7 @@ catch (\Exception $e) {
265297
Asynchronous an be handled in two ways: by passing callbacks or waiting for the promise to be fulfilled. Waiting acts like synchronous request.
266298
##### Wait (Synchronous)
267299
```php
268-
$promise = $sparky->transmissions->get();
300+
$promise = $sparky->transmissions->get(); //TODO: Change this. Transmissions no longer supports GET call
269301

270302
try {
271303
$response = $promise->wait();
@@ -281,7 +313,7 @@ echo "I will print out after the promise is fulfilled";
281313

282314
##### Then (Asynchronous)
283315
```php
284-
$promise = $sparky->transmissions->get();
316+
$promise = $sparky->transmissions->get(); //TODO: Change this. Transmissions no longer supports GET call
285317

286318
$promise->then(
287319
// Success callback

Diff for: lib/SparkPost/SparkPost.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,8 @@ public function buildRequestValues($method, $uri, $payload, $headers)
184184
$url = $this->getUrl($uri, $params);
185185
$headers = $this->getHttpHeaders($headers);
186186

187-
// Sparkpost API will not tolerate form feed in JSON.
188-
$jsonReplace = [
189-
'\f' => '',
190-
];
191-
$body = strtr(json_encode($body), $jsonReplace);
192-
187+
// old form-feed workaround now removed
188+
$body = json_encode($body);
193189
return [
194190
'method' => $method,
195191
'url' => $url,

0 commit comments

Comments
 (0)