Options
All
  • Public
  • Public/Protected
  • All
Menu

Class PreferredPicturesClient

Hierarchy

  • PreferredPicturesClient

Index

Constructors

Methods

Constructors

constructor

  • new PreferredPicturesClient(params: { endpoint?: undefined | string; identity: string; maxChoices?: undefined | number; secretKey: string }): PreferredPicturesClient
  • Create a new PreferredPicturesClient instance using an identity and the secret API key associated with that identity.

    Example:

    import PreferredPicturesClient from '@preferred-pictures/client';
    const pp = new PreferredPicturesClient({
        // Obtain your account's values by
        // signing into PreferredPictures.
        identity: "test-identity",
        secretKey: "secret123456",
    });

    Parameters

    • params: { endpoint?: undefined | string; identity: string; maxChoices?: undefined | number; secretKey: string }
      • Optional endpoint?: undefined | string

        The endpoint of the API to use, default is https://api.PreferredPictures/

      • identity: string

        The identity that should be used for API calls generated

      • Optional maxChoices?: undefined | number

        The maximum number of choices to allow, default 35

      • secretKey: string

        The secret key of the identity that should be used to generated signatures

    Returns PreferredPicturesClient

Methods

createChooseUrl

  • createChooseUrl(params: { choices: string[]; choices_prefix?: undefined | string; choices_suffix?: undefined | string; destinations?: string[]; destinations_prefix?: undefined | string; destinations_suffix?: undefined | string; expirationTtl?: undefined | number; go?: undefined | false | true; json?: undefined | false | true; limited_signature?: undefined | false | true; tournament: string; ttl?: undefined | number; uid?: undefined | string }): string
  • Build a URL for a call to /choose of the PreferredPictures API, using the passed parameters.

    Parameters

    • params: { choices: string[]; choices_prefix?: undefined | string; choices_suffix?: undefined | string; destinations?: string[]; destinations_prefix?: undefined | string; destinations_suffix?: undefined | string; expirationTtl?: undefined | number; go?: undefined | false | true; json?: undefined | false | true; limited_signature?: undefined | false | true; tournament: string; ttl?: undefined | number; uid?: undefined | string }
      • choices: string[]

        A list of choices from which a selection should be made. Typically these are URLs.

      • Optional choices_prefix?: undefined | string

        An optional prefix to prepend to all of the choices

      • Optional choices_suffix?: undefined | string

        An optional suffix to append to all of the choices

      • Optional destinations?: string[]

        An optional list of destination URLs which are paired with each choice

      • Optional destinations_prefix?: undefined | string

        An optional prefix to prepend to all of the destination URLs

      • Optional destinations_suffix?: undefined | string

        An optional suffix to append to all of the destination URLs

      • Optional expirationTtl?: undefined | number

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

      • Optional go?: undefined | false | true

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

      • Optional json?: undefined | false | true

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

      • Optional limited_signature?: undefined | false | true

        Produce a limited signature over all fields except uid, expiration, json, go.

      • tournament: string

        The tournament of which this API call is a member

      • Optional ttl?: undefined | number

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

      • Optional uid?: undefined | string

        An optional unique identifier that is used to correlate choices and actions.

        If it is not specified a UUID v4 will be generated.

    Returns string

    A URL that when requested will return the result of the API call.

    Example:

    // A simple example of choosing between three different
    // URLs.
    const simpleChoiceUrl = pp.createChooseUrl({
        choices: [
            "https://example.com/image-red.jpg",
            "https://example.com/image-green.jpg",
            "https://example.com/image-blue.jpg",
        ],
        // Change the tournament as necessary to represent
        // different needs.
        tournament: "testing",
    });

Generated using TypeDoc