Skip to content

Commit 543585a

Browse files
committed
changed error functions, fixed mistake in example, cleaned up transmission delete function, added header option in request function
1 parent 78a33d5 commit 543585a

File tree

1 file changed

+34
-23
lines changed

1 file changed

+34
-23
lines changed

README.md

+34-23
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,20 @@ use SparkPost\SparkPost;
4747
use GuzzleHttp\Client;
4848
use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
4949

50-
$httpAdapter = new GuzzleAdapter(new Client());
51-
$sparky = new SparkPost($httpAdapter, ['key'=>'YOUR_API_KEY']);
50+
$httpClient = new GuzzleAdapter(new Client());
51+
$sparky = new SparkPost($httpClient, ['key'=>'YOUR_API_KEY']);
5252
?>
5353
```
5454

5555
## Initialization
56-
#### new Sparkpost(httpAdapter, options)
57-
* `httpAdapter`
56+
#### new Sparkpost(httpClient, options)
57+
* `httpClient`
5858
* Required: Yes
5959
* HTTP client or adapter supported by HTTPlug
60+
* `options`
61+
* Required: Yes
62+
* Type: `String` or `Array`
63+
* A valid Sparkpost API key or an array of options
6064
* `options.key`
6165
* Required: Yes
6266
* Type: `String`
@@ -73,10 +77,6 @@ $sparky = new SparkPost($httpAdapter, ['key'=>'YOUR_API_KEY']);
7377
* Required: No
7478
* Type: `Number`
7579
* Default: 443
76-
* `options.strictSSL`
77-
* Required: No
78-
* Type: `Boolean`
79-
* Default: `true`
8080
* `options.version`
8181
* Required: No
8282
* Type: `String`
@@ -86,8 +86,9 @@ $sparky = new SparkPost($httpAdapter, ['key'=>'YOUR_API_KEY']);
8686
* Type: `Number`
8787
* Default: `10`
8888

89+
8990
## Methods
90-
### request(method, uri [, payload])
91+
### request(method, uri [, payload [, headers]])
9192
* `method`
9293
* Required: Yes
9394
* Type: `String`
@@ -100,12 +101,23 @@ $sparky = new SparkPost($httpAdapter, ['key'=>'YOUR_API_KEY']);
100101
* Required: No
101102
* Type: `Array`
102103
* If the method is `GET` the values are encoded into the URL. Otherwise, if the method is `POST`, `PUT`, or `DELETE` the payload is used for the request body.
104+
* `headers`
105+
* Required: No
106+
* Type: `Array`
107+
* If the method is `GET` the values are encoded into the URL. Otherwise, if the method is `POST`, `PUT`, or `DELETE` the payload is used for the request body.
103108

104-
### setHttpAdapter(httpAdapter)
105-
* `httpAdapter`
109+
### setHttpClient(httpClient)
110+
* `httpClient`
106111
* Required: Yes
107112
* HTTP client or adapter supported by HTTPlug
108113

114+
### setOptions(options)
115+
* `options`
116+
* Required: Yes
117+
* Type: `Array`
118+
* See initialization
119+
120+
109121
## Endpoints
110122
### transmissions
111123
* **get([transmissionID] [, payload])**
@@ -123,7 +135,6 @@ $sparky = new SparkPost($httpAdapter, ['key'=>'YOUR_API_KEY']);
123135
* Recipients to descreetly recieve a carbon copy of the transmission
124136
* **delete(transmissionID)**
125137
* `transmissionID` - see `uri` request options
126-
* `payload` - see request options
127138

128139
## Examples
129140

@@ -134,8 +145,8 @@ use SparkPost\SparkPost;
134145
use GuzzleHttp\Client;
135146
use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
136147

137-
$httpAdapter = new GuzzleAdapter(new Client());
138-
$sparky = new SparkPost($httpAdapter, ['key'=>'YOUR_API_KEY']);
148+
$httpClient = new GuzzleAdapter(new Client());
149+
$sparky = new SparkPost($httpClient, ['key'=>'YOUR_API_KEY']);
139150

140151
$promise = $sparky->transmissions->post([
141152
'content' => [
@@ -148,7 +159,7 @@ $promise = $sparky->transmissions->post([
148159
'text'=>'Congratulations, {{name}}!! You just sent your very first mailing!'
149160
],
150161
'substitution_data'=> ['name'=>'YOUR_FIRST_NAME'],
151-
'recipients'= [
162+
'recipients'=> [
152163
[ 'address' => '<YOUR_EMAIL_ADDRESS>' ]
153164
],
154165
'bcc' => [
@@ -166,8 +177,8 @@ use SparkPost\SparkPost;
166177
use GuzzleHttp\Client;
167178
use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
168179

169-
$httpAdapter = new GuzzleAdapter(new Client());
170-
$sparky = new SparkPost($httpAdapter, ['key'=>'YOUR_API_KEY']);
180+
$httpClient = new GuzzleAdapter(new Client());
181+
$sparky = new SparkPost($httpClient, ['key'=>'YOUR_API_KEY']);
171182

172183
$promise = $sparky->request('GET', 'metrics/ip-pools', [
173184
'from' => '2015-12-01T08:00',
@@ -190,8 +201,8 @@ try {
190201
echo $response->getStatusCode();
191202
echo $response->getBody();
192203
} catch (Exception $e) {
193-
echo $e->getStatusCode();
194-
echo $e->getBody();
204+
echo $e->getCode();
205+
echo $e->getMessage();
195206
}
196207
?>
197208
```
@@ -207,8 +218,8 @@ $promise->then(
207218
},
208219
// Failure callback
209220
function (Exception $e) {
210-
echo $e->getStatusCode();
211-
echo $e->getBody();
221+
echo $e->getCode();
222+
echo $e->getMessage();
212223
}
213224
);
214225
?>
@@ -218,9 +229,9 @@ $promise->then(
218229
The promise will throw an exception if the server returns a status code of `400` or higher.
219230

220231
### Exception
221-
* **getStatusCode()**
232+
* **getCode()**
222233
* Returns the response status code of `400` or higher
223-
* **getBody()**
234+
* **getMessage()**
224235
* Returns the body of response as an `Array`
225236

226237

0 commit comments

Comments
 (0)