\PreferredPicturesClient

Summary

Methods
Properties
Constants
__construct()
createChooseUrl()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
$identity
$secret_key
$endpoint
$max_choices
N/A

Properties

$identity

$identity : string

The identity that is used for all URLs created by this client

Type

normal

$secret_key

$secret_key : string

The secret key that is used to create the crypographic signature for all requests created by this client.

Type

normal

$endpoint

$endpoint : string

The API endpoint for the PreferredPictures API defaults to https://api.preferred-pictures.com

Type

normal

$max_choices

$max_choices : int

The maximum number of choices to allow in a request.

Type

normal

Methods

__construct()

__construct(string  $identity, string  $secret_key, int  $max_choices = 35, string  $endpoint = 'https://api.preferred-pictures.com/') : \PreferredPictures\Client

Create a new client object

Parameters

string $identity

The identity that should be used for the API calls.

string $secret_key

The secret key of the identity that will be used to create request signatures

int $max_choices

The maximum number of choices to allow in an API call

string $endpoint

The endpoint of the API to use, default is https://api.preferred-pictures.com/

Returns

\PreferredPictures\Client —

A new PreferredPictures client object.

Example:

<?php
use PreferredPictures\Client as Client;

$client = new Client("testidentity", "secret123456"); ?>

createChooseUrl()

createChooseUrl(array  $choices, string  $tournament, int  $ttl = 600, int  $expiration_ttl = 3600, string  $choices_prefix = "", string  $choices_suffix = "", array  $destinations = [], string  $destinations_prefix = "", string  $destinations_suffix = "", bool  $json = false, bool  $go = false, string  $uid = "") : string

Build a URL for a call to /choose of the PreferredPictures API

Parameters

array $choices

A list of choices of which a selection should be made

string $tournament

The tournament of which this API call is a part.

int $ttl

The amount of time in seconds after a choice is made that an action can be recorded.

int $expiration_ttl

The amount of time in seconds that the request's signature is valid.

string $choices_prefix

An optional prefix to prepend to all of the choices

string $choices_suffix

An optional suffix to append to all of the choices

array $destinations

A list of destination URLs which are paired with choices for redirection

string $destinations_prefix

An optional prefix to prepend to all of the destination URLs

string $destinations_suffix

An options suffix to append to all of the destination URLs

bool $json

Indicate that the result should be returned as JSON, rather than a HTTP redirect

bool $go

Indicate that the user should be redirected to the destination URL from a previously chosen option associated with the same tournament and unique id.

string $uid

An optional unique identifier that is used to correlate choices and actions. If it is not specified a random string will be generated.

Returns

string —

A URL that calls the PreferredPictures /choose API.

Example:

<?php
use PreferredPictures\Client as Client;

$client = new Client("testidentity", "secret123456");

// Explicitly listing all choices $url = client->createChooseUrl( ["https://example.com/image-red.jpg", "https://example.com/image-green.jpg", "https://example.com/image-blue.jpg"], "test-tournament");

// Using a prefix and suffix to make choices easier $url = client->createChooseUrl( ["red", "green", "blue"], "test-tournament", 300, 6000, "https://example.com/image-", ".jpg"); ?>