tp TouchPointWP api - TenthPres/TouchPoint-WP GitHub Wiki

tp\TouchPointWP\Api

This class handles communication with the TouchPoint API.

  • Class name: Api
  • Namespace: \tp\TouchPointWP

Constants

MAX_API_CALLS

const MAX_API_CALLS = 20

Properties

parent

public mixed parent = null

The main plugin object.

  • Visibility: public

Methods

__construct

mixed tp\TouchPointWP\Api::__construct(\tp\TouchPointWP\TouchPointWP parent)

Constructor function.

  • Visibility: public

Arguments

Returns

  • mixed

instance

\tp\TouchPointWP\Api tp\TouchPointWP\Api::instance(?\tp\TouchPointWP\TouchPointWP parent)

Main Api Instance

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

  • Visibility: public
  • This method is static.

Arguments

  • parent ?\tp\TouchPointWP\TouchPointWP - Object instance.

Returns

  • \tp\TouchPointWP\Api - instance

pyGet

\stdClass|array tp\TouchPointWP\Api::pyGet(string command, ?array parameters, int timeout, mixed verbose)

Gets data from the API via the python script.

  • Visibility: public

Arguments

  • 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

Returns

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

pyPost

\stdClass|array tp\TouchPointWP\Api::pyPost(string command, ?mixed data, int timeout, float timeTaken)

Do a POST to the Python-Defined API.

  • Visibility: public

Arguments

  • 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.

Returns

  • \stdClass|array - An object that corresponds to the Data python object in TouchPoint.

get

array|\WP_Error tp\TouchPointWP\Api::get(string command, array headers, ?int onBehalfPid, int timeout, float timeTaken)

Do a GET to the standard API using a PAB.

  • Visibility: public

Arguments

  • command string - The API endpoint to call
  • 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.

Returns

  • array|\WP_Error - The response from the Http request call.

post

array|\WP_Error tp\TouchPointWP\Api::post(string command, ?mixed data, array headers, ?int onBehalfPid, int timeout, float timeTaken)

Do a POST to the standard API using a PAB.

  • Visibility: public

Arguments

  • command string - The API endpoint to call
  • 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.

Returns

  • array|\WP_Error - The response from the Http request call.

invalidatePAT

void tp\TouchPointWP\Api::invalidatePAT()

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

  • Visibility: public