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
@type parameters() :: %{optional(parameter_key()) => parameter_val()} | %{}
@type url() :: String.t()
Functions
Add a page number to the URL, calls JikanEx.Url.path/2
Example
iex> JikanEx.Url.page("animelist/all/", 2)
"animelist/all/2/"
@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&"
@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&"
Add the endpoint (a string, atom, or integer) to the URL
Example
iex> JikanEx.Url.path("anime/5/", "videos")
"anime/5/videos/"
Adds multiple URL parts (joined by '/') to a URL
Example
iex> JikanEx.Url.paths("anime/", [1, :character_staff])
"anime/1/character_staff/"
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"