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:
Key | Operation |
---|---|
$lt | Less than |
$lte | Less than or equal to |
$gt | Greater than |
$gte | Greater than or equal to |
$ne | Not equal to |
$in | Contained in |
$nin | Not contained in |
$exists | A value is set for the key |
$select | This matches a value for a key in the result of a different query |
$dontSelect | Requires that a key’s value not match a value for a key in the result of a different query |
$all | Contains 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})
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
Request to delete an object.
Example
ParseClient.delete("classes/Animals/12345678")
Deletes the user. Takes the user’s objectid and session token as arguments.
Example
ParseClient.delete_user("g7y9tkhB7O", "12345678")
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"})
Request from a user to login. Username and password are required. As in the signup function, username and password needs to be strings.
Request to create an object.
Example
body = %{"animal" => "parrot, "name" => "NorwegianBlue", "status" => 0}
ParseClient.post("classes/Animals", body)
Request to update an object.
Example
ParseClient.put("classes/Animals/12345678", %{"status" => 1})
Get request for making queries. Just returns the body of the response.
Get request for making queries with filters and options. Just returns the body of the response.
Request to reset a user’s password.
Example
ParseClient.request_passwd_reset("example@example.com")
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"})