Skip to content

Commit f79318a

Browse files
committed
fixed examples, and small details
1 parent fda0a91 commit f79318a

File tree

9 files changed

+73
-57
lines changed

9 files changed

+73
-57
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
],
1010
"minimum-stability": "stable",
1111
"scripts": {
12-
"post-install-cmd": "if [ ! -f 'examples/example-options.json' ]; then echo '{\n\t\"api-key\":\"Your API Key\"\n}' >> examples/example-options.json; fi",
13-
"post-update-cmd": "if [ ! -f 'examples/example-options.json' ]; then echo '{\n\t\"api-key\":\"Your API Key\"\n}' >> examples/example-options.json; fi",
12+
"post-install-cmd": "if [ ! -f 'examples/example-options.json' ]; then echo '{\n\t\"key\":\"YOUR_API_KEY\"\n}' >> examples/example-options.json; fi",
13+
"post-update-cmd": "if [ ! -f 'examples/example-options.json' ]; then echo '{\n\t\"key\":\"YOUR_API_KEY\"\n}' >> examples/example-options.json; fi",
1414
"test": "phpunit ./test/unit/",
1515
"fix-style": "php-cs-fixer fix ."
1616
},

examples/bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
require_once dirname(__FILE__).'/../vendor/autoload.php';
44

5-
//pull in API key config
5+
//pull in library options
66
$optionsFile = file_get_contents(dirname(__FILE__).'/example-options.json');
77
$options = json_decode($optionsFile, true);

examples/transmissions/create_transmission.php

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,37 @@
1010

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

13-
/**
13+
/*
1414
* configure options in example-options.json
1515
*/
1616
$sparky = new SparkPost($httpClient, $options);
1717

1818
$promise = $sparky->transmissions->post([
19-
'content' => [
20-
'from'=> [
19+
'content' => [
20+
'from' => [
2121
'name' => 'SparkPost Team',
22-
'email' => 'from@sparkpostbox.com'
22+
'email' => 'from@sparkpostbox.com',
23+
],
24+
'subject' => 'First Mailing From PHP',
25+
'html' => '<html><body><h1>Congratulations, {{name}}!</h1><p>You just sent your very first mailing!</p></body></html>',
26+
'text' => 'Congratulations, {{name}}!! You just sent your very first mailing!',
27+
],
28+
'substitution_data' => ['name' => 'YOUR_FIRST_NAME'],
29+
'recipients' => [
30+
[
31+
'address' => [
32+
'name' => 'YOUR_NAME',
33+
'email' => 'YOUR_EMAIL',
34+
],
2335
],
24-
'subject'=>'First Mailing From PHP',
25-
'html'=>'<html><body><h1>Congratulations, {{name}}!</h1><p>You just sent your very first mailing!</p></body></html>',
26-
'text'=>'Congratulations, {{name}}!! You just sent your very first mailing!'
2736
],
28-
'substitution_data'=> ['name'=>'YOUR_FIRST_NAME'],
29-
'recipients'=> [
30-
[ 'address' => 'YOUR_NAME <YOUR_EMAIL>' ]
31-
]
3237
]);
3338

3439
try {
3540
$response = $promise->wait();
36-
echo $response->getStatusCode() . "\n";
41+
echo $response->getStatusCode()."\n";
3742
print_r($response->getBody());
3843
} catch (Exception $e) {
39-
echo $e->getCode() . "\n";
40-
echo $e->getMessage() . "\n";
44+
echo $e->getCode()."\n";
45+
echo $e->getMessage()."\n";
4146
}
42-
?>

examples/transmissions/create_transmission_with_cc_and_bcc.php

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,53 @@
1010

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

13-
/**
13+
/*
1414
* configure options in example-options.json
1515
*/
1616
$sparky = new SparkPost($httpClient, $options);
1717

1818
$promise = $sparky->transmissions->post([
19-
'content' => [
20-
'from'=> [
19+
'content' => [
20+
'from' => [
2121
'name' => 'SparkPost Team',
22-
'email' => 'from@sparkpostbox.com'
22+
'email' => 'from@sparkpostbox.com',
2323
],
24-
'subject'=>'First Mailing From PHP',
25-
'html'=>'<html><body><h1>Congratulations, {{name}}!</h1><p>You just sent your very first mailing!</p></body></html>',
26-
'text'=>'Congratulations, {{name}}!! You just sent your very first mailing!'
24+
'subject' => 'First Mailing From PHP',
25+
'html' => '<html><body><h1>Congratulations, {{name}}!</h1><p>You just sent your very first mailing!</p></body></html>',
26+
'text' => 'Congratulations, {{name}}!! You just sent your very first mailing!',
2727
],
28-
'substitution_data'=> ['name'=>'YOUR_FIRST_NAME'],
29-
'recipients'=> [
30-
[ 'address' => 'YOUR_NAME <YOUR_EMAIL>' ]
28+
'substitution_data' => ['name' => 'YOUR_FIRST_NAME'],
29+
'recipients' => [
30+
[
31+
'address' => [
32+
'name' => 'YOUR_NAME',
33+
'email' => 'YOUR_EMAIL',
34+
],
35+
],
36+
],
37+
'cc' => [
38+
[
39+
'address' => [
40+
'name' => 'ANOTHER_NAME',
41+
'email' => 'ANOTHER_EMAIL',
42+
],
43+
],
3144
],
32-
'cc'=> [
33-
[ 'address' => 'ANOTHER_NAME <ANOTHER_EMAIL>' ]
45+
'bcc' => [
46+
[
47+
'address' => [
48+
'name' => 'AND_ANOTHER_NAME',
49+
'email' => 'AND_ANOTHER_EMAIL',
50+
],
51+
],
3452
],
35-
'bcc'=> [
36-
[ 'address' => 'AND_ANOTHER_NAME <AND_ANOTHER_EMAIL>' ]
37-
]
3853
]);
3954

4055
try {
4156
$response = $promise->wait();
42-
echo $response->getStatusCode() . "\n";
57+
echo $response->getStatusCode()."\n";
4358
print_r($response->getBody());
4459
} catch (Exception $e) {
45-
echo $e->getCode() . "\n";
46-
echo $e->getMessage() . "\n";
60+
echo $e->getCode()."\n";
61+
echo $e->getMessage()."\n";
4762
}
48-
?>

examples/transmissions/delete_transmission.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

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

13-
/**
13+
/*
1414
* configure options in example-options.json
1515
*/
1616
$sparky = new SparkPost($httpClient, $options);
@@ -19,10 +19,9 @@
1919

2020
try {
2121
$response = $promise->wait();
22-
echo $response->getStatusCode() . "\n";
22+
echo $response->getStatusCode()."\n";
2323
print_r($response->getBody());
2424
} catch (Exception $e) {
25-
echo $e->getCode() . "\n";
26-
echo $e->getMessage() . "\n";
25+
echo $e->getCode()."\n";
26+
echo $e->getMessage()."\n";
2727
}
28-
?>

examples/transmissions/get_all_transmissions.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

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

13-
/**
13+
/*
1414
* configure options in example-options.json
1515
*/
1616
$sparky = new SparkPost($httpClient, $options);
@@ -19,10 +19,9 @@
1919

2020
try {
2121
$response = $promise->wait();
22-
echo $response->getStatusCode() . "\n";
22+
echo $response->getStatusCode()."\n";
2323
print_r($response->getBody());
2424
} catch (Exception $e) {
25-
echo $e->getCode() . "\n";
26-
echo $e->getMessage() . "\n";
25+
echo $e->getCode()."\n";
26+
echo $e->getMessage()."\n";
2727
}
28-
?>

lib/SparkPost/Resource.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Resource
1717
/**
1818
* Sets up the Resource.
1919
*
20-
* @param SparKPost $sparkpost - the sparkpost instance that this resource is attached to
20+
* @param SparkPost $sparkpost - the sparkpost instance that this resource is attached to
2121
* @param string $endpoint - the endpoint that this resource wraps
2222
*/
2323
public function __construct(SparkPost $sparkpost, $endpoint)
@@ -82,7 +82,7 @@ public function request($method = 'GET', $uri = '', $payload = [], $headers = []
8282
}
8383

8484
$uri = $this->endpoint.'/'.$uri;
85-
85+
8686
return $this->sparkpost->request($method, $uri, $payload, $headers);
8787
}
8888
}

lib/SparkPost/SparkPostResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function getBody()
3838
}
3939

4040
/**
41-
* pass these down to the response given in the constructor
41+
* pass these down to the response given in the constructor.
4242
*/
4343
public function getProtocolVersion()
4444
{

lib/SparkPost/Transmission.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,22 +137,22 @@ private function addListToRecipients($payload, $listName)
137137
*/
138138
private function toAddressObject($address)
139139
{
140-
$return = $address;
141-
if (is_string($address)) {
142-
$return = [];
140+
$formatted = $address;
141+
if (is_string($formatted)) {
142+
$formatted = [];
143143

144144
if ($this->isEmail($address)) {
145-
$return['email'] = $address;
145+
$formatted['email'] = $address;
146146
} elseif (preg_match('/"?(.[^"]*)?"?\s*<(.+)>/', $address, $matches)) {
147147
$name = trim($matches[1]);
148-
$return['name'] = $matches[1];
149-
$return['email'] = $matches[2];
148+
$formatted['name'] = $matches[1];
149+
$formatted['email'] = $matches[2];
150150
} else {
151151
throw new \Exception('Invalid address format: '.$address);
152152
}
153153
}
154154

155-
return $return;
155+
return $formatted;
156156
}
157157

158158
/**

0 commit comments

Comments
 (0)