View Source JikanEx.Url (JikanEx v0.1.6)

Interface to build Jikan URLs. These are then passed onto JikanEx.Request.request/3.

In here, generally, URLs shouldn't start with a slash, and should typically have a slash at the end. The final / is removed when adding query parameters or in JikanEx.Request.request/3.

Summary

Functions

Add a page number to the URL, calls JikanEx.Url.path/2

Formats a map of GET params into a URL

Formats a GET key and value into a URL

Add the endpoint (a string, atom, or integer) to the URL

Adds multiple URL parts (joined by '/') to a URL

Removes a trailing forward slash from a URL

Types

parameter_key()

@type parameter_key() :: String.t() | atom()

parameter_val()

@type parameter_val() :: String.t() | integer()

parameters()

@type parameters() :: %{optional(parameter_key()) => parameter_val()} | %{}

path()

@type path() :: String.t() | atom() | integer()

url()

@type url() :: String.t()

Functions

page(prev_url, endpoint)

@spec page(url(), integer()) :: url()

Add a page number to the URL, calls JikanEx.Url.path/2

Example

iex> JikanEx.Url.page("animelist/all/", 2)
"animelist/all/2/"

params(prev_url, parameter_map)

@spec params(url(), parameters()) :: url()

Formats a map of GET params into a URL

Example

iex> JikanEx.Url.params("animelist/all/2", %{year: 2019, airing_status: "complete"})
"animelist/all/2?airing_status=complete&year=2019&"

params(prev_url, key, val)

@spec params(url(), parameter_key(), parameter_val()) :: url()

Formats a GET key and value into a URL

Example

iex> JikanEx.Url.params("animelist/all/2/", "year", 2019)
"animelist/all/2?year=2019&"

path(prev_url, endpoint)

@spec path(url(), path()) :: url()

Add the endpoint (a string, atom, or integer) to the URL

Example

iex> JikanEx.Url.path("anime/5/", "videos")
"anime/5/videos/"

paths(prev_url, paths)

@spec paths(url(), [path()]) :: url()

Adds multiple URL parts (joined by '/') to a URL

Example

iex> JikanEx.Url.paths("anime/", [1, :character_staff])
"anime/1/character_staff/"

trim_url(prev_url)

@spec trim_url(url()) :: url()

Removes a trailing forward slash from a URL

iex> JikanEx.Url.trim_url("username/animelist/2/")
"username/animelist/2"
iex> JikanEx.Url.trim_url("username/animelist/2")
"username/animelist/2"