MPX v0.1.7 Mpx.Tables

Interact with Ministry Platform’s Tables.

Summary

Types

Specifies the allowed set of options for a delete call

Specifies the allowed set of options when making a call to get records

Functions

Deletes multiple records from the specified table

Returns a single record from the specified table by the records primary key value

Returns the list of records from the specified table satisfying the provided search criteria

Returns the list of tables available to the current users with basic metadata

Types

delete_options :: ["$select": String.t, "$userId": String.t, id: number]

Specifies the allowed set of options for a delete call

get_record_options :: ["$select": String.t, "$filter": String.t, "$orderBy": String.t, "$groupBy": String.t, "$having": String.t, "$top": String.t, "$skip": String.t, "$distint": true | false]

Specifies the allowed set of options when making a call to get records

Functions

delete_records(table, auth_token, ids, opts \\ [])

Specs

delete_records(String.t, String.t, [number], delete_options) ::
  {:ok, list} |
  {:error, any}

Deletes multiple records from the specified table.

Expects the table name, a list of ids of records and an auth_token. Also accepts an optional keyword list of options:

["$select": "Comma_Seperated,List_Of_Columns,To_Return",
 "$userId": "userIdToPreformOnBehalfOf"]
get_record(table, id, auth_token, opts \\ [])

Specs

get_record(String.t, number, String.t, [{:"$select", String.t}]) ::
  {:ok, map} |
  {:error, binary}

Returns a single record from the specified table by the records primary key value.

Optionally pass ["$select": "Columns,To_Select"] option for only a subset of columns.

Examples

  {:ok, token} = Mpx.Authentication.authenticate()
  Mpx.Tables.get_record("Contacts", 2186211, token)
  {:ok, %{"Last_Name" => "Smith"}}

  {:ok, token} = Mpx.Authentication.authenticate()
  Mpx.Tables.get_record("Contacts", 2186211, token, "$select": "Last_Name, First_Name")
  {:ok, %{"Last_Name" => "Smith", "First_Name" => "Mr."}}
get_records(table, auth_token, opts \\ [])

Specs

get_records(String.t, String.t, get_record_options) ::
  {:ok, list} |
  {:error, binary}

Returns the list of records from the specified table satisfying the provided search criteria.

The optional search parameters are:

["$select": "list of columns to be returned",
 "$filter": "filtering expession to select the records to be returned",
 "$orderBy": "list of columns to be sort the result",
 "$groupBy": "list of columns to group and aggregate result by",
 "$having": "expression to filter the aggregated result by",
 "$top": "maximum number of records to be returned. If not specified than 1000 records are returned",
 "$skip": "number of records in the result to be skiped and the rest are returned",
 "$distint": "Flag indicating that only distinct records must be returned"]

Examples

  {:ok, token} = Mpx.Authentication.authenticate()
  Mpx.Tables.get_records("Contacts", token)
  {:ok, [%{"Last_Name" => "Smith", "First_Name" => "Mr."}]}

  {:ok, token} = Mpx.Authentication.authenticate()
  Mpx.Tables.get_records("Contacts", token,
                         "$filter": "First_Name=Mr.",
                         "$select": "Last_Name")
  {:ok, [%{"Last_Name" => "Smith"}]}
list_tables(auth_token, search \\ "")

Specs

list_tables(String.t, String.t) ::
  {:ok, list} |
  {:error, map}

Returns the list of tables available to the current users with basic metadata.

Requires an authentication token and accepts an optional table name pattern to be used for searching tables. Wildcards ‘?’ and ‘*’ can be used at any place. If parameter is Null or empty then all tables are returned.

Examples

  {:ok, token} = Mpx.Authentication.authenticate()
  Mpx.Tables.list_tables(token)
  {:ok, [%{"Name" => "Contacts"}, %{"Name" => "Participants"}]}

  {:ok, token} = Mpx.Authentication.authenticate()
  Mpx.Tables.list_tables(token, "contacts")
  {:ok, [%{"Name" => "Contacts"}]}