ParseClient

REST API client for Parse in Elixir

Example usage

To get information about an object (and print out the whole response):

ParseClient.get("classes/Lumberjacks")

To just see the body, use the query function:

ParseClient.query("classes/Lumberjacks")

To create a new object, use the post function, to update an object, use the put function, and to delete an object, use the delete function.

The get and query methods can also be used with users and roles.

Use of filters when making queries

Queries can be filtered by using filters and options.

Use filters when you would use where= clauses in a request to the Parse API. Options include “order”, “limit”, “count” and “include”.

Both filters and options need to be Elixir maps.

Comparisons in filters

The following filters (keys) from Parse.com are supported:

KeyOperation
$ltLess than
$lteLess than or equal to
$gtGreater than
$gteGreater than or equal to
$neNot equal to
$inContained in
$ninNot contained in
$existsA value is set for the key
$selectThis matches a value for a key in the result of a different query
$dontSelectRequires that a key’s value not match a value for a key in the result of a different query
$allContains all of the given values

Examples

To make a query just about animals that are aged less then 3 years old:

ParseClient.query("classes/Animals", %{"age" => %{"$lt" => 3}})

To make a query just about animals who have a name and are still alive:

ParseClient.query("classes/Animals", %{"name" => %{"$exists" => true}, "status" => 1})
Source

Summary

delete(url)

Request to delete an object

delete_user(objectid, token_val)

Deletes the user. Takes the user’s objectid and session token as arguments

get(url)

Get request for making queries

get(url, filters, options \\ %{})

Get request with filters

login(username, password)

Request from a user to login. Username and password are required. As in the signup function, username and password needs to be strings

post(url, body)

Request to create an object

put(url, body)

Request to update an object

query(url)

Get request for making queries. Just returns the body of the response

query(url, filters, options \\ %{})

Get request for making queries with filters and options. Just returns the body of the response

request_passwd_reset(email)

Request to reset a user’s password

signup(username, password, options \\ %{})

Request from a user to signup. The user must provide a username and a password. The options argument refers to additional information, such as email address or phone number, and it needs to be in the form of an Elixir map

upload_file(url, contents, content_type)

Post request to upload a file

validate_user(token_val)

Validates the user. Takes the user’s session token as the only argument

Functions

delete(url)

Request to delete an object.

Example

ParseClient.delete("classes/Animals/12345678")
Source
delete_user(objectid, token_val)

Deletes the user. Takes the user’s objectid and session token as arguments.

Example

ParseClient.delete_user("g7y9tkhB7O", "12345678")
Source
get(url)

Get request for making queries.

Source
get(url, filters, options \\ %{})

Get request with filters.

Examples

To make a query just about animals that have a name and are still alive:

ParseClient.get("classes/Animals", %{"name" => %{"$exists" => true}, "status" => 1})

To make a request with options, but no filters, use %{} as the second argument:

ParseClient.get("classes/Animals", %{}, %{"order" => "createdAt"})
Source
login(username, password)

Request from a user to login. Username and password are required. As in the signup function, username and password needs to be strings.

Source
post(url, body)

Request to create an object.

Example

body = %{"animal" => "parrot, "name" => "NorwegianBlue", "status" => 0}
ParseClient.post("classes/Animals", body)
Source
put(url, body)

Request to update an object.

Example

ParseClient.put("classes/Animals/12345678", %{"status" => 1})
Source
query(url)

Get request for making queries. Just returns the body of the response.

Source
query(url, filters, options \\ %{})

Get request for making queries with filters and options. Just returns the body of the response.

Source
request_passwd_reset(email)

Request to reset a user’s password.

Example

ParseClient.request_passwd_reset("example@example.com")
Source
signup(username, password, options \\ %{})

Request from a user to signup. The user must provide a username and a password. The options argument refers to additional information, such as email address or phone number, and it needs to be in the form of an Elixir map.

Examples

ParseClient.signup("Duchamp", "L_H;OO#Q")
ParseClient.signup("Duchamp", "L_H;OO#Q", %{"email" => "eros@selavy.com"})
Source
upload_file(url, contents, content_type)

Post request to upload a file.

Source
validate_user(token_val)

Validates the user. Takes the user’s session token as the only argument.

Example

ParseClient.validate_user("12345678")
Source