Packages

Meuralex is an API Wrapper for the Meural Canvas.

Current section

Files

Jump to
meuralex lib meuralex.ex
Raw

lib/meuralex.ex

defmodule Meuralex do
@moduledoc """
Documentation for Meuralex, an API Wrapper for the Meural Canvas.
See API documentation here https://documenter.getpostman.com/view/1657302/RVnWjKUL?version=latest
"""
######################## User routes ########################
def create_user(body) when is_map(body) do
case Meuralex.Schemas.validate_params(:create_user, body) do
{:ok, _} -> Meuralex.Meural.post("/user", body)
error -> error
end
end
def create_token(body) when is_map(body) do
case Meuralex.Schemas.validate_params(:create_token, body) do
{:ok, _} -> Meuralex.Meural.post("/authenticate", body)
error -> error
end
end
def get_user() do
Meuralex.Meural.get("/user")
end
def get_user_items(page, count) when is_integer(page) and is_integer(count) do
Meuralex.Meural.get("/user/items?page=#{page}&count=#{count}")
end
def get_user_galleries(page, count) when is_integer(page) and is_integer(count) do
Meuralex.Meural.get("/user/galleries?page=#{page}&count=#{count}")
end
def get_user_devices() do
Meuralex.Meural.get("/user/devices")
end
######################## Favorite routes ########################
def create_favorite(body) when is_map(body) do
case Meuralex.Schemas.validate_params(:create_favorite, body) do
{:ok, _} -> Meuralex.Meural.post("/favorites", body)
error -> error
end
end
def delete_favorite(body) when is_map(body) do
# delete uses the same schema as create
case Meuralex.Schemas.validate_params(:create_favorite, body) do
{:ok, _} -> Meuralex.Meural.delete("/favorites", body)
error -> error
end
end
def get_favorite_items(page, count) when is_integer(page) and is_integer(count) do
Meuralex.Meural.get("/favorites/items?page=#{page}&count=#{count}")
end
def get_favorite_items(page, count) when is_integer(page) and is_integer(count) do
Meuralex.Meural.get("/favorites/galleries?page=#{page}&count=#{count}")
end
def get_favorite_items(page, count) when is_integer(page) and is_integer(count) do
Meuralex.Meural.get("/favorites/artists?page=#{page}&count=#{count}")
end
def get_favorite_items(page, count) when is_integer(page) and is_integer(count) do
Meuralex.Meural.get("/favorites/channels?page=#{page}&count=#{count}")
end
######################## Device routes ########################
def register_device(body) when is_map(body) do
case Meuralex.Schemas.validate_params(:register_device, body) do
{:ok, _} -> Meuralex.Meural.post("/devices", body)
error -> error
end
end
def get_device(device_id) when is_integer(device_id) do
Meuralex.Meural.get("/devices/#{device_id}")
end
def update_device_config(device_id, body) when is_integer(device_id) and is_map(body) do
case Meuralex.Schemas.validate_params(:update_device_config, body) do
{:ok, _} -> Meuralex.Meural.put("/devices/#{device_id}", body)
error -> error
end
end
def deregister_device(device_id) when is_integer(device_id) do
Meuralex.Meural.delete("/devices/#{device_id}")
end
def get_device_galleries(device_id, page, count)
when is_integer(device_id) and is_integer(page) and is_integer(count) do
Meuralex.Meural.get("/devices/#{device_id}/galleries?page=#{page}&count=#{count}")
end
def add_gallery_to_device(device_id, gallery_id)
when is_integer(device_id) and is_integer(gallery_id) do
Meuralex.Meural.post("/devices/#{device_id}/galleries/#{gallery_id}", "")
end
def delete_gallery_from_device(device_id, gallery_id)
when is_integer(device_id) and is_integer(gallery_id) do
Meuralex.Meural.delete("/devices/#{device_id}/galleries/#{gallery_id}")
end
def get_device_schedule(device_id) when is_integer(device_id) do
Meuralex.Meural.get("/devices/#{device_id}/schedule")
end
def update_device_schedule(device_id, body) when is_integer(device_id) and is_map(body) do
case Meuralex.Schemas.validate_params(:update_device_schedule, body) do
{:ok, _} -> Meuralex.Meural.put("/devices/#{device_id}/schedule", body)
error -> error
end
end
def preview_item_on_device(device_id, item_id)
when is_integer(device_id) and is_integer(item_id) do
Meuralex.Meural.post("/devices/#{device_id}/preview/#{item_id}", "")
end
######################## Items routes ########################
def upload_item(file_path, "image") when is_binary(file_path) do
Meuralex.Meural.post(
"/items",
{:multipart,
[
{:file, file_path,
{"form-data", [{"name", "image"}, {"filename", Path.basename(file_path)}]}, []}
]}
)
end
def upload_item(file_path, "video") when is_binary(file_path) do
Meuralex.Meural.post(
"/items",
{:multipart,
[
{:file, file_path,
{"form-data", [{"name", "video"}, {"filename", Path.basename(file_path)}]}, []}
]}
)
end
def get_item(item_id) when is_integer(item_id) do
Meuralex.Meural.get("/items/#{item_id}")
end
def update_item_metadata(item_id, body) when is_integer(item_id) and is_map(body) do
case Meuralex.Schemas.validate_params(:update_item_metadata, body) do
{:ok, _} -> Meuralex.Meural.put("/items/#{item_id}", body)
error -> error
end
end
def crop_item(item_id, body) when is_integer(item_id) and is_map(body) do
case Meuralex.Schemas.validate_params(:crop_item, body) do
{:ok, _} -> Meuralex.Meural.put("/items/#{item_id}/crop", body)
error -> error
end
end
def delete_item(item_id) when is_integer(item_id) do
Meuralex.Meural.delete("/items/#{item_id}")
end
def get_item_articles(item_id) when is_integer(item_id) do
Meuralex.Meural.get("/items/#{item_id}/articles")
end
######################## Galleries routes ########################
def create_gallery(body) when is_map(body) do
case Meuralex.Schemas.validate_params(:create_gallery, body) do
{:ok, _} -> Meuralex.Meural.post("/galleries", body)
error -> error
end
end
def get_gallery(gallery_id) when is_integer(gallery_id) do
Meuralex.Meural.get("/galleries/#{gallery_id}")
end
def update_gallery(gallery_id, body) when is_integer(gallery_id) and is_map(body) do
# update uses the same schema as create
case Meuralex.Schemas.validate_params(:create_gallery, body) do
{:ok, _} -> Meuralex.Meural.put("/galleries/#{gallery_id}", body)
error -> error
end
end
def delete_gallery(gallery_id) when is_integer(gallery_id) do
Meuralex.Meural.delete("/galleries/#{gallery_id}")
end
def get_items_from_gallery(gallery_id) when is_integer(gallery_id) do
Meuralex.Meural.get("/galleries/#{gallery_id}/items")
end
def get_articles_from_gallery(gallery_id) when is_integer(gallery_id) do
Meuralex.Meural.get("/galleries/#{gallery_id}/articles")
end
def update_gallery_order(gallery_id, body) when is_integer(gallery_id) and is_map(body) do
case Meuralex.Schemas.validate_params(:update_gallery_order, body) do
{:ok, _} -> Meuralex.Meural.put("/galleries/#{gallery_id}/sort", body)
error -> error
end
end
def add_item_to_gallery(gallery_id, item_id) when is_integer(gallery_id) and is_map(item_id) do
Meuralex.Meural.post("/galleries/#{gallery_id}/items/#{item_id}", "")
end
def delete_item_to_gallery(gallery_id, item_id)
when is_integer(gallery_id) and is_map(item_id) do
Meuralex.Meural.delete("/galleries/#{gallery_id}/items/#{item_id}")
end
######################## Artist routes ########################
# sort_parameter is not documented. Known accepted values: date_added__dsc, date_added__asc
def get_artists(page, count, sort_parameter \\ "date_added__dsc")
when is_integer(page) and is_integer(count) and is_binary(sort_parameter) do
Meuralex.Meural.get("/artists?page=#{page}&count=#{count}&sort=#{sort_parameter}")
end
def get_artist(artist_id) when is_integer(artist_id) do
Meuralex.Meural.get("/artists/#{artist_id}")
end
def get_galleries_from_artist(artist_id, page, count)
when is_integer(artist_id) and is_integer(page) and is_integer(count) do
Meuralex.Meural.get("/artists/#{artist_id}/galleries?page=#{page}&count=#{count}")
end
def get_articles_from_artist(artist_id, page, count)
when is_integer(artist_id) and is_integer(page) and is_integer(count) do
Meuralex.Meural.get("/artists/#{artist_id}/articles?page=#{page}&count=#{count}")
end
def get_items_from_artist(artist_id, page, count)
when is_integer(artist_id) and is_integer(page) and is_integer(count) do
Meuralex.Meural.get("/artists/#{artist_id}/items?page=#{page}&count=#{count}")
end
######################## Categories routes ########################
def get_categories(page, count) when is_integer(page) and is_integer(count) do
Meuralex.Meural.get("/categories?page=#{page}&count=#{count}")
end
def get_category(category_id) when is_integer(category_id) do
Meuralex.Meural.get("/categories/#{category_id}")
end
def get_galleries_from_category(category_id, page, count)
when is_integer(category_id) and is_integer(page) and is_integer(count) do
Meuralex.Meural.get("/categories/#{category_id}/galleries?page=#{page}&count=#{count}")
end
def get_articles_from_category(category_id, page, count)
when is_integer(category_id) and is_integer(page) and is_integer(count) do
Meuralex.Meural.get("/categories/#{category_id}/articles?page=#{page}&count=#{count}")
end
def get_items_from_category(category_id, page, count)
when is_integer(category_id) and is_integer(page) and is_integer(count) do
Meuralex.Meural.get(
"/categories/#{category_id}/items?page=#{page}&count=#{count}&sort=date_added__dsc"
)
end
######################## Channels routes ########################
def get_channels(page, count) when is_integer(page) and is_integer(count) do
Meuralex.Meural.get("/channels?page=#{page}&count=#{count}")
end
def get_channel(channel_id) when is_integer(channel_id) do
Meuralex.Meural.get("/channels/#{channel_id}")
end
def get_galleries_from_channel(channel_id, page, count)
when is_integer(channel_id) and is_integer(page) and is_integer(count) do
Meuralex.Meural.get("/channels/#{channel_id}/galleries?page=#{page}&count=#{count}")
end
def get_artists_from_channel(artist_id, page, count)
when is_integer(artist_id) and is_integer(page) and is_integer(count) do
Meuralex.Meural.get("/channels/#{artist_id}/artists?page=#{page}&count=#{count}")
end
def get_items_from_channel(artist_id, page, count, sort_parameter \\ "date_added__dsc")
when is_integer(artist_id) and is_integer(page) and is_integer(count) and
is_binary(sort_parameter) do
Meuralex.Meural.get(
"/channels/#{artist_id}/items?page=#{page}&count=#{count}&sort=#{sort_parameter}"
)
end
def get_articles_from_channel(channel_id, page, count, sort_parameter \\ "date_added__dsc")
when is_integer(channel_id) and is_integer(page) and is_integer(count) and
is_binary(sort_parameter) do
Meuralex.Meural.get(
"/channels/#{channel_id}/articles?page=#{page}&count=#{count}&sort=#{sort_parameter}"
)
end
######################## Groups routes ########################
def get_groups() do
Meuralex.Meural.get("/groups")
end
def get_group(group_id) when is_integer(group_id) do
Meuralex.Meural.get("/groups/#{group_id}")
end
def get_categories_from_group(group_id) when is_integer(group_id) do
Meuralex.Meural.get("/groups/#{group_id}/categories")
end
######################## Feed routes ########################
def get_feed(page, count) when is_integer(page) and is_integer(count) do
Meuralex.Meural.get("/feed?page=#{page}&count=#{count}")
end
######################## Articles routes ########################
def get_article(article_id) when is_integer(article_id) do
Meuralex.Meural.get("/articles/#{article_id}")
end
end