diff options
author | Avi Goldman <avrahamymgoldman@gmail.com> | 2016-06-23 09:43:56 -0400 |
---|---|---|
committer | Avi Goldman <avrahamymgoldman@gmail.com> | 2016-06-23 09:43:56 -0400 |
commit | f79318aeea95c0ce7fb8d5ef376a2b0b97f3c140 (patch) | |
tree | 60c4073730c4870404717d2ed3b152bc899371c1 | |
parent | fda0a912a79ef6a7e5ea95123bd305fb712f80db (diff) | |
download | php-sparkpost-f79318aeea95c0ce7fb8d5ef376a2b0b97f3c140.zip php-sparkpost-f79318aeea95c0ce7fb8d5ef376a2b0b97f3c140.tar.gz php-sparkpost-f79318aeea95c0ce7fb8d5ef376a2b0b97f3c140.tar.bz2 |
fixed examples, and small details
-rw-r--r-- | composer.json | 4 | ||||
-rw-r--r-- | examples/bootstrap.php | 2 | ||||
-rw-r--r-- | examples/transmissions/create_transmission.php | 34 | ||||
-rw-r--r-- | examples/transmissions/create_transmission_with_cc_and_bcc.php | 52 | ||||
-rw-r--r-- | examples/transmissions/delete_transmission.php | 9 | ||||
-rw-r--r-- | examples/transmissions/get_all_transmissions.php | 9 | ||||
-rw-r--r-- | lib/SparkPost/Resource.php | 4 | ||||
-rw-r--r-- | lib/SparkPost/SparkPostResponse.php | 2 | ||||
-rw-r--r-- | lib/SparkPost/Transmission.php | 14 |
9 files changed, 73 insertions, 57 deletions
diff --git a/composer.json b/composer.json index e73d007..d8b97fa 100644 --- a/composer.json +++ b/composer.json @@ -9,8 +9,8 @@ ], "minimum-stability": "stable", "scripts": { - "post-install-cmd": "if [ ! -f 'examples/example-options.json' ]; then echo '{\n\t\"api-key\":\"Your API Key\"\n}' >> examples/example-options.json; fi", - "post-update-cmd": "if [ ! -f 'examples/example-options.json' ]; then echo '{\n\t\"api-key\":\"Your API Key\"\n}' >> examples/example-options.json; fi", + "post-install-cmd": "if [ ! -f 'examples/example-options.json' ]; then echo '{\n\t\"key\":\"YOUR_API_KEY\"\n}' >> examples/example-options.json; fi", + "post-update-cmd": "if [ ! -f 'examples/example-options.json' ]; then echo '{\n\t\"key\":\"YOUR_API_KEY\"\n}' >> examples/example-options.json; fi", "test": "phpunit ./test/unit/", "fix-style": "php-cs-fixer fix ." }, diff --git a/examples/bootstrap.php b/examples/bootstrap.php index 2085888..1110ed3 100644 --- a/examples/bootstrap.php +++ b/examples/bootstrap.php @@ -2,6 +2,6 @@ require_once dirname(__FILE__).'/../vendor/autoload.php'; -//pull in API key config +//pull in library options $optionsFile = file_get_contents(dirname(__FILE__).'/example-options.json'); $options = json_decode($optionsFile, true); diff --git a/examples/transmissions/create_transmission.php b/examples/transmissions/create_transmission.php index b21fc1f..4b45509 100644 --- a/examples/transmissions/create_transmission.php +++ b/examples/transmissions/create_transmission.php @@ -10,33 +10,37 @@ use Http\Adapter\Guzzle6\Client as GuzzleAdapter; $httpClient = new GuzzleAdapter(new Client()); -/** +/* * configure options in example-options.json */ $sparky = new SparkPost($httpClient, $options); $promise = $sparky->transmissions->post([ - 'content' => [ - 'from'=> [ + 'content' => [ + 'from' => [ 'name' => 'SparkPost Team', - 'email' => 'from@sparkpostbox.com' + 'email' => 'from@sparkpostbox.com', + ], + 'subject' => 'First Mailing From PHP', + 'html' => '<html><body><h1>Congratulations, {{name}}!</h1><p>You just sent your very first mailing!</p></body></html>', + 'text' => 'Congratulations, {{name}}!! You just sent your very first mailing!', + ], + 'substitution_data' => ['name' => 'YOUR_FIRST_NAME'], + 'recipients' => [ + [ + 'address' => [ + 'name' => 'YOUR_NAME', + 'email' => 'YOUR_EMAIL', + ], ], - 'subject'=>'First Mailing From PHP', - 'html'=>'<html><body><h1>Congratulations, {{name}}!</h1><p>You just sent your very first mailing!</p></body></html>', - 'text'=>'Congratulations, {{name}}!! You just sent your very first mailing!' ], - 'substitution_data'=> ['name'=>'YOUR_FIRST_NAME'], - 'recipients'=> [ - [ 'address' => 'YOUR_NAME <YOUR_EMAIL>' ] - ] ]); try { $response = $promise->wait(); - echo $response->getStatusCode() . "\n"; + echo $response->getStatusCode()."\n"; print_r($response->getBody()); } catch (Exception $e) { - echo $e->getCode() . "\n"; - echo $e->getMessage() . "\n"; + echo $e->getCode()."\n"; + echo $e->getMessage()."\n"; } -?>
\ No newline at end of file diff --git a/examples/transmissions/create_transmission_with_cc_and_bcc.php b/examples/transmissions/create_transmission_with_cc_and_bcc.php index 4c12f81..4c3e12b 100644 --- a/examples/transmissions/create_transmission_with_cc_and_bcc.php +++ b/examples/transmissions/create_transmission_with_cc_and_bcc.php @@ -10,39 +10,53 @@ use Http\Adapter\Guzzle6\Client as GuzzleAdapter; $httpClient = new GuzzleAdapter(new Client()); -/** +/* * configure options in example-options.json */ $sparky = new SparkPost($httpClient, $options); $promise = $sparky->transmissions->post([ - 'content' => [ - 'from'=> [ + 'content' => [ + 'from' => [ 'name' => 'SparkPost Team', - 'email' => 'from@sparkpostbox.com' + 'email' => 'from@sparkpostbox.com', ], - 'subject'=>'First Mailing From PHP', - 'html'=>'<html><body><h1>Congratulations, {{name}}!</h1><p>You just sent your very first mailing!</p></body></html>', - 'text'=>'Congratulations, {{name}}!! You just sent your very first mailing!' + 'subject' => 'First Mailing From PHP', + 'html' => '<html><body><h1>Congratulations, {{name}}!</h1><p>You just sent your very first mailing!</p></body></html>', + 'text' => 'Congratulations, {{name}}!! You just sent your very first mailing!', ], - 'substitution_data'=> ['name'=>'YOUR_FIRST_NAME'], - 'recipients'=> [ - [ 'address' => 'YOUR_NAME <YOUR_EMAIL>' ] + 'substitution_data' => ['name' => 'YOUR_FIRST_NAME'], + 'recipients' => [ + [ + 'address' => [ + 'name' => 'YOUR_NAME', + 'email' => 'YOUR_EMAIL', + ], + ], + ], + 'cc' => [ + [ + 'address' => [ + 'name' => 'ANOTHER_NAME', + 'email' => 'ANOTHER_EMAIL', + ], + ], ], - 'cc'=> [ - [ 'address' => 'ANOTHER_NAME <ANOTHER_EMAIL>' ] + 'bcc' => [ + [ + 'address' => [ + 'name' => 'AND_ANOTHER_NAME', + 'email' => 'AND_ANOTHER_EMAIL', + ], + ], ], - 'bcc'=> [ - [ 'address' => 'AND_ANOTHER_NAME <AND_ANOTHER_EMAIL>' ] - ] ]); try { $response = $promise->wait(); - echo $response->getStatusCode() . "\n"; + echo $response->getStatusCode()."\n"; print_r($response->getBody()); } catch (Exception $e) { - echo $e->getCode() . "\n"; - echo $e->getMessage() . "\n"; + echo $e->getCode()."\n"; + echo $e->getMessage()."\n"; } -?>
\ No newline at end of file diff --git a/examples/transmissions/delete_transmission.php b/examples/transmissions/delete_transmission.php index ca2bd01..13c3150 100644 --- a/examples/transmissions/delete_transmission.php +++ b/examples/transmissions/delete_transmission.php @@ -10,7 +10,7 @@ use Http\Adapter\Guzzle6\Client as GuzzleAdapter; $httpClient = new GuzzleAdapter(new Client()); -/** +/* * configure options in example-options.json */ $sparky = new SparkPost($httpClient, $options); @@ -19,10 +19,9 @@ $promise = $sparky->transmissions->delete('TRANSMISSION_ID'); try { $response = $promise->wait(); - echo $response->getStatusCode() . "\n"; + echo $response->getStatusCode()."\n"; print_r($response->getBody()); } catch (Exception $e) { - echo $e->getCode() . "\n"; - echo $e->getMessage() . "\n"; + echo $e->getCode()."\n"; + echo $e->getMessage()."\n"; } -?>
\ No newline at end of file diff --git a/examples/transmissions/get_all_transmissions.php b/examples/transmissions/get_all_transmissions.php index 5b48971..a8bfca8 100644 --- a/examples/transmissions/get_all_transmissions.php +++ b/examples/transmissions/get_all_transmissions.php @@ -10,7 +10,7 @@ use Http\Adapter\Guzzle6\Client as GuzzleAdapter; $httpClient = new GuzzleAdapter(new Client()); -/** +/* * configure options in example-options.json */ $sparky = new SparkPost($httpClient, $options); @@ -19,10 +19,9 @@ $promise = $sparky->transmissions->get(); try { $response = $promise->wait(); - echo $response->getStatusCode() . "\n"; + echo $response->getStatusCode()."\n"; print_r($response->getBody()); } catch (Exception $e) { - echo $e->getCode() . "\n"; - echo $e->getMessage() . "\n"; + echo $e->getCode()."\n"; + echo $e->getMessage()."\n"; } -?>
\ No newline at end of file diff --git a/lib/SparkPost/Resource.php b/lib/SparkPost/Resource.php index 7fab937..7c88743 100644 --- a/lib/SparkPost/Resource.php +++ b/lib/SparkPost/Resource.php @@ -17,7 +17,7 @@ class Resource /** * Sets up the Resource. * - * @param SparKPost $sparkpost - the sparkpost instance that this resource is attached to + * @param SparkPost $sparkpost - the sparkpost instance that this resource is attached to * @param string $endpoint - the endpoint that this resource wraps */ public function __construct(SparkPost $sparkpost, $endpoint) @@ -82,7 +82,7 @@ class Resource } $uri = $this->endpoint.'/'.$uri; - + return $this->sparkpost->request($method, $uri, $payload, $headers); } } diff --git a/lib/SparkPost/SparkPostResponse.php b/lib/SparkPost/SparkPostResponse.php index 08750f9..e6a8fd1 100644 --- a/lib/SparkPost/SparkPostResponse.php +++ b/lib/SparkPost/SparkPostResponse.php @@ -38,7 +38,7 @@ class SparkPostResponse implements ResponseInterface } /** - * pass these down to the response given in the constructor + * pass these down to the response given in the constructor. */ public function getProtocolVersion() { diff --git a/lib/SparkPost/Transmission.php b/lib/SparkPost/Transmission.php index 1847e1b..6c45c7e 100644 --- a/lib/SparkPost/Transmission.php +++ b/lib/SparkPost/Transmission.php @@ -137,22 +137,22 @@ class Transmission extends Resource */ private function toAddressObject($address) { - $return = $address; - if (is_string($address)) { - $return = []; + $formatted = $address; + if (is_string($formatted)) { + $formatted = []; if ($this->isEmail($address)) { - $return['email'] = $address; + $formatted['email'] = $address; } elseif (preg_match('/"?(.[^"]*)?"?\s*<(.+)>/', $address, $matches)) { $name = trim($matches[1]); - $return['name'] = $matches[1]; - $return['email'] = $matches[2]; + $formatted['name'] = $matches[1]; + $formatted['email'] = $matches[2]; } else { throw new \Exception('Invalid address format: '.$address); } } - return $return; + return $formatted; } /** |