PHP Class SparkPost\SparkPost

Datei anzeigen Open project: sparkpost/php-sparkpost Class Usage Examples

Public Properties

Property Type Description
$transmissions Instance of Transmission class.

Public Methods

Method Description
__construct ( Http\Client\HttpClient $httpClient, array $options ) Sets up the SparkPost instance.
asyncRequest ( string $method = 'GET', string $uri = '', array $payload = [], array $headers = [] ) : SparkPostPromise Sends async request to SparkPost API.
buildRequest ( string $method, string $uri, array $payload, array $headers ) : Psr\Http\Message\RequestInterface Builds request from given params.
getHttpHeaders ( array $headers = [] ) : array Returns an array for the request headers.
getUrl ( string $path, array $params = [] ) : string Builds the request url from the options and given params.
request ( string $method = 'GET', string $uri = '', array $payload = [], array $headers = [] ) : SparkPostPromise | SparkPostResponse Sends either sync or async request based on async option.
setHttpClient ( Http\Client\HttpClient | Http\Client\HttpAsyncClient $httpClient ) Sets $httpClient to be used for request.
setMessageFactory ( Http\Message\RequestFactory $messageFactory ) : SparkPost
setOptions ( array $options ) Sets the options from the param and defaults for the SparkPost object.
syncRequest ( string $method = 'GET', string $uri = '', array $payload = [], array $headers = [] ) : SparkPostResponse Sends sync request to SparkPost API.

Private Methods

Method Description
getMessageFactory ( ) : Http\Message\RequestFactory
setupEndpoints ( ) Sets up any endpoints to custom classes e.g. $this->transmissions.

Method Details

__construct() public method

Sets up the SparkPost instance.
public __construct ( Http\Client\HttpClient $httpClient, array $options )
$httpClient Http\Client\HttpClient - An httplug client or adapter
$options array - An array to overide default options or a string to be used as an API key

asyncRequest() public method

Sends async request to SparkPost API.
public asyncRequest ( string $method = 'GET', string $uri = '', array $payload = [], array $headers = [] ) : SparkPostPromise
$method string
$uri string
$payload array
$headers array
return SparkPostPromise

buildRequest() public method

Builds request from given params.
public buildRequest ( string $method, string $uri, array $payload, array $headers ) : Psr\Http\Message\RequestInterface
$method string
$uri string
$payload array
$headers array
return Psr\Http\Message\RequestInterface

getHttpHeaders() public method

Returns an array for the request headers.
public getHttpHeaders ( array $headers = [] ) : array
$headers array - any custom headers for the request
return array $headers - headers for the request

getUrl() public method

Builds the request url from the options and given params.
public getUrl ( string $path, array $params = [] ) : string
$path string - the path in the url to hit
$params array - query parameters to be encoded into the url
return string $url - the url to send the desired request to

request() public method

Sends either sync or async request based on async option.
public request ( string $method = 'GET', string $uri = '', array $payload = [], array $headers = [] ) : SparkPostPromise | SparkPostResponse
$method string
$uri string
$payload array - either used as the request body or url query params
$headers array
return SparkPostPromise | SparkPostResponse Promise or Response depending on sync or async request

setHttpClient() public method

Sets $httpClient to be used for request.
public setHttpClient ( Http\Client\HttpClient | Http\Client\HttpAsyncClient $httpClient )
$httpClient Http\Client\HttpClient | Http\Client\HttpAsyncClient - the client to be used for request

setMessageFactory() public method

public setMessageFactory ( Http\Message\RequestFactory $messageFactory ) : SparkPost
$messageFactory Http\Message\RequestFactory
return SparkPost

setOptions() public method

Sets the options from the param and defaults for the SparkPost object.
public setOptions ( array $options )
$options array - either an string API key or an array of options

syncRequest() public method

Sends sync request to SparkPost API.
public syncRequest ( string $method = 'GET', string $uri = '', array $payload = [], array $headers = [] ) : SparkPostResponse
$method string
$uri string
$payload array
$headers array
return SparkPostResponse

Property Details

$transmissions public_oe property

Instance of Transmission class.
public $transmissions