/**
  * @desc Tests overridable values are set while invalid values are ignored
  */
 public function testSetConfigMultipleValuesAndGetConfig()
 {
     SparkPost::setConfig(array('key' => 'lala', 'version' => 'v8', 'port' => 1024, 'someOtherValue' => 'fakeValue'));
     $testConfig = SparkPost::getConfig();
     $this->assertEquals('lala', $testConfig['key']);
     $this->assertEquals('v8', $testConfig['version']);
     $this->assertEquals(1024, $testConfig['port']);
     $this->assertNotContains('someOtherValue', array_keys($testConfig));
     $this->assertEquals('https', $testConfig['protocol']);
     $this->assertEquals('api.sparkpost.com', $testConfig['host']);
     $this->assertEquals(true, $testConfig['strictSSL']);
 }
Exemplo n.º 2
0
 public function testSetMessageFactory()
 {
     $messageFactory = Mockery::mock(MessageFactory::class);
     $this->resource->setMessageFactory($messageFactory);
     $this->assertEquals($messageFactory, NSA::invokeMethod($this->resource, 'getMessageFactory'));
 }
Exemplo n.º 3
0
 /**
  * @desc Private Method for issuing GET request to Transmissions API
  *
  *  This method is responsible for getting the collection _and_
  *  a specific entity from the Transmissions API
  *
  *  If TransmissionID parameter is omitted, then we fetch the collection
  *
  * @param string $transmissionID (optional) string Transmission ID of specific Transmission to retrieve
  * @return array Result set of transmissions found
  */
 private static function fetch($transmissionID = null)
 {
     //figure out the url
     $hostConfig = SparkPost::getConfig();
     $url = self::getBaseUrl($hostConfig);
     if (!is_null($transmissionID)) {
         $url .= '/' . $transmissionID;
     }
     $request = self::getHttpClient();
     //make request
     try {
         $response = $request->get($url, array('authorization' => $hostConfig['key']), array("verify" => $hostConfig['strictSSL']))->send();
         return $response->json();
     } catch (ClientErrorResponseException $exception) {
         $response = $exception->getResponse();
         $statusCode = $response->getStatusCode();
         if ($statusCode === 404) {
             throw new \Exception("The specified Transmission ID does not exist", 404);
         }
         throw new \Exception("Received bad response from Transmission API: " . $statusCode);
     } catch (\Exception $exception) {
         throw new \Exception('Unable to contact Transmissions API: ' . $exception->getMessage());
     }
 }
Exemplo n.º 4
0
<?php

/*Cron will automaticly run this program every minute, seeing which polls are old. Old polls have their data sent to the specified email and are removed.*/
namespace Examples\Transmisson;

require_once "config.php";
require 'vendor/autoload.php';
use SparkPost\SparkPost;
use SparkPost\Transmission;
SparkPost::setConfig(["key" => SPARK_KEY]);
$result = $db->query("SELECT * FROM poll WHERE end_time < NOW()");
while ($row = $result->fetch_array()) {
    try {
        $results = Transmission::send(array("from" => "From Envelope <*****@*****.**>", "recipients" => array(array("address" => array("email" => $row['email']))), "template" => "suggest-app-poll-dat", 'substitutionData' => $row));
    } catch (\Exception $exception) {
        echo $exception->getMessage();
    }
}
$db->query("DELETE FROM poll WHERE end_time < NOW()");
<?php

namespace Examples\Transmisson;

require_once dirname(__FILE__) . '/../bootstrap.php';
use SparkPost\SparkPost;
use SparkPost\Transmission;
$key = 'YOURAPIKEY';
SparkPost::setConfig(array('key' => $key));
try {
    $results = Transmission::send(array("campaign" => "my-campaign", "metadata" => array("sample_campaign" => true, "type" => "these are custom fields"), "substitutionData" => array("name" => "Test Name"), "description" => "my description", "replyTo" => "*****@*****.**", "customHeaders" => array("X-Custom-Header" => "Sample Custom Header"), "trackOpens" => false, "trackClicks" => false, "from" => "From Envelope <*****@*****.**>", "html" => "<p>Hello World! Your name is: {{name}}</p>", "text" => "Hello World!", "subject" => "Example Email: {{name}}", "recipients" => array(array("address" => array("email" => "*****@*****.**")))));
    echo 'Congrats you can use your SDK!';
} catch (\Exception $exception) {
    echo $exception->getMessage();
}
Exemplo n.º 6
0
<?php

namespace Examples\Templates;

require dirname(__FILE__) . '/../bootstrap.php';
use SparkPost\SparkPost;
use GuzzleHttp\Client;
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->request('PUT', 'templates/TEMPLATE_ID', ['options' => ['open_tracking' => true]]);
try {
    $response = $promise->wait();
    echo $response->getStatusCode() . "\n";
    print_r($response->getBody()) . "\n";
} catch (\Exception $e) {
    echo $e->getCode() . "\n";
    echo $e->getMessage() . "\n";
}
Exemplo n.º 7
0
<?php

namespace Examples\Templates;

require dirname(__FILE__) . '/../bootstrap.php';
use SparkPost\SparkPost;
use GuzzleHttp\Client;
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->request('POST', 'templates', ["name" => "PHP example template", "content" => ["from" => "from@YOUR_DOMAIN", "subject" => "Your Subject", "html" => "<b>Write your message here.</b>"]]);
try {
    $response = $promise->wait();
    echo $response->getStatusCode() . "\n";
    print_r($response->getBody()) . "\n";
} catch (\Exception $e) {
    echo $e->getCode() . "\n";
    echo $e->getMessage() . "\n";
}
<?php

namespace Examples\Templates;

require dirname(__FILE__) . '/../bootstrap.php';
use SparkPost\SparkPost;
use GuzzleHttp\Client;
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->request('GET', 'message-events', ['campaign_ids' => 'CAMPAIGN_ID']);
try {
    $response = $promise->wait();
    echo $response->getStatusCode() . "\n";
    print_r($response->getBody()) . "\n";
} catch (\Exception $e) {
    echo $e->getCode() . "\n";
    echo $e->getMessage() . "\n";
}
Exemplo n.º 9
0
<?php

namespace Examples\Templates;

require dirname(__FILE__) . '/../bootstrap.php';
use SparkPost\SparkPost;
use GuzzleHttp\Client;
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->request('GET', 'templates');
try {
    $response = $promise->wait();
    echo $response->getStatusCode() . "\n";
    print_r($response->getBody()) . "\n";
} catch (\Exception $e) {
    echo $e->getCode() . "\n";
    echo $e->getMessage() . "\n";
}
Exemplo n.º 10
0
<?php

namespace Examples\Templates;

require dirname(__FILE__) . '/../bootstrap.php';
use SparkPost\SparkPost;
use GuzzleHttp\Client;
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->request('DELETE', 'templates/TEMPLATE_ID');
try {
    $response = $promise->wait();
    echo $response->getStatusCode() . "\n";
    print_r($response->getBody()) . "\n";
} catch (\Exception $e) {
    echo $e->getCode() . "\n";
    echo $e->getMessage() . "\n";
}
Exemplo n.º 11
0
<?php

namespace Examples\Templates;

require dirname(__FILE__) . '/../bootstrap.php';
use SparkPost\SparkPost;
use GuzzleHttp\Client;
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->request('GET', 'templates/TEMPLATE_ID?draft=true');
try {
    $response = $promise->wait();
    echo $response->getStatusCode() . "\n";
    print_r($response->getBody()) . "\n";
} catch (\Exception $e) {
    echo $e->getCode() . "\n";
    echo $e->getMessage() . "\n";
}
Exemplo n.º 12
0
<?php

namespace Examples\Unwrapped;

require_once dirname(__FILE__) . '/../bootstrap.php';
//pull in API key config
$configFile = file_get_contents(dirname(__FILE__) . '/../example-config.json');
$config = json_decode($configFile, true);
use SparkPost\SparkPost;
use GuzzleHttp\Client;
use Ivory\HttpAdapter\Guzzle6HttpAdapter;
$httpAdapter = new Guzzle6HttpAdapter(new Client());
$sparky = new SparkPost($httpAdapter, ['key' => $config['api-key']]);
try {
    // define the endpoint
    $sparky->setupUnwrapped('templates');
    $templateConfig = ['name' => 'Summer Sale!', 'id' => 'summer-sale', 'content' => ['from' => '*****@*****.**', 'subject' => 'Summer deals', 'html' => '<b>Check out these deals!</b>']];
    $results = $sparky->templates->create($templateConfig);
    echo 'Congrats you can use your SDK!';
} catch (\Exception $exception) {
    echo $exception->getMessage();
}
Exemplo n.º 13
0
<?php

namespace Examples\Templates;

require dirname(__FILE__) . '/../bootstrap.php';
use SparkPost\SparkPost;
use GuzzleHttp\Client;
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->request('POST', 'templates/TEMPLATE_ID/preview?draft=true', ['substitution_data' => ['some_key' => 'some_value']]);
try {
    $response = $promise->wait();
    echo $response->getStatusCode() . "\n";
    print_r($response->getBody()) . "\n";
} catch (\Exception $e) {
    echo $e->getCode() . "\n";
    echo $e->getMessage() . "\n";
}
 /**
  * (non-PHPdoc)
  * @before
  * @see PHPUnit_Framework_TestCase::setUp()
  */
 public function setUp()
 {
     SparkPost::setConfig(array('key' => 'blah'));
     $this->client = self::getMethod('getHttpClient')->invoke(null);
     //so we can bootstrap api responses
 }