tp TouchPointWP Api - TenthPres/TouchPoint-WP GitHub Wiki

tp\TouchPointWP\Api

This class handles communication with the TouchPoint API.


  • Full name: \tp\TouchPointWP\Api

Constants

Constant Visibility Type Value
MAX_API_CALLS public 20

Properties

parent

The main plugin object.

public ?\tp\TouchPointWP\TouchPointWP $parent

Methods

__construct

Constructor function.

public __construct(\tp\TouchPointWP\TouchPointWP $parent): mixed

Parameters:

Parameter Type Description
$parent \tp\TouchPointWP\TouchPointWP Parent object.

instance

Main Api Instance

public static instance(?\tp\TouchPointWP\TouchPointWP $parent = null): \tp\TouchPointWP\Api

Ensures only one instance of Api is loaded or can be loaded.

  • This method is static. Parameters:
Parameter Type Description
$parent ?\tp\TouchPointWP\TouchPointWP Object instance.

Return Value:

instance

See Also:

  • \tp\TouchPointWP\TouchPointWP()

uGet

Gets data from the API with Basic User Auth.

public uGet(string $command, array $parameters = [], array $headers = [], ?int $onBehalfPid = null, int $timeout = 5, float& $timeTaken = 0): array|\WP_Error

This method is provided until TouchPoint has been updated to allow PAT authentication on more endpoints. The signature is identical to the PAT version so replacement later should be easy, however, onbehalf

  • Warning: this method is deprecated. This means that this method will likely be removed in a future version. Parameters:
Parameter Type Description
$command string The API endpoint to call
$parameters array
$headers array Headers to send with the request.
$onBehalfPid ?int The PID of the user to act on behalf of.
$timeout int Amount of time in sec to wait before timing out.
$timeTaken float The time taken to complete the request.

Return Value:

An array with headers, body, and other keys

Throws:

Thrown if the API credentials are incomplete.


pyGet

Gets data from the API via the python script.

public pyGet(string $command, ?array $parameters = null, int $timeout = 5, mixed $verbose = false): \stdClass|array

Parameters:

Parameter Type Description
$command string The thing to get
$parameters ?array URL parameters to be added.
$timeout int Amount of time in sec to wait before timing out.
$verbose mixed

Return Value:

An array with headers, body, and other keys Data is generally in json_decode($response['body'])->data

Throws:

Thrown if the API credentials are incomplete.


pyPost

Do a POST to the Python-Defined API.

public pyPost(string $command, ?mixed $data = null, int $timeout = 5, float& $timeTaken = 0): \stdClass|array

Parameters:

Parameter Type Description
$command string The thing to post
$data ?mixed Data to post
$timeout int Amount of time in sec to wait before timing out.
$timeTaken float The time taken to complete the request.

Return Value:

An object that corresponds to the Data python object in TouchPoint.

Throws:

If anything went wrong.


get

Do a GET to the standard API using a PAT.

public get(string $command, array $parameters = [], array $headers = [], ?int $onBehalfPid = null, int $timeout = 5, float& $timeTaken = 0): array

Parameters:

Parameter Type Description
$command string The API endpoint to call (after /api/)
$parameters array URL parameters to be added.
$headers array Headers to send with the request.
$onBehalfPid ?int The PID of the user to act on behalf of.
$timeout int Amount of time in sec to wait before timing out.
$timeTaken float The time taken to complete the request.

Return Value:

The response from the Http request call.

Throws:

If anything went wrong.


post

Do a POST to the standard API using a PAT.

public post(string $command, ?mixed $data = null, array $headers = [], ?int $onBehalfPid = null, int $timeout = 5, float& $timeTaken = 0): array|\WP_Error

Parameters:

Parameter Type Description
$command string The API endpoint to call (after /api/)
$data ?mixed Data to post
$headers array Headers to send with the request.
$onBehalfPid ?int The PID of the user to act on behalf of.
$timeout int Amount of time in sec to wait before timing out.
$timeTaken float The time taken to complete the request.

Return Value:

The response from the Http request call.

Throws:

If anything went wrong.


invalidatePAT

Invalidate the existing PAT, both here and on the server.

final public invalidatePAT(): void
  • This method is final.