View Source Bonfire.Common.URIs (Bonfire v0.9.10-classic-beta.169)
URI/URL/path helpers
Summary
Functions
Returns the base domain from the given URI or endpoint.
Returns the homepage URI (as struct) of the local instance.
Return the homepage URL (as string) of the local instance
Returns the canonical URL (i.e., the one used for ActivityPub federation) of an object.
Removes the scheme from a URL to get the display URL.
Returns true if the given string is a valid URI.
Returns the path (URL on the local instance) for the given object/struct (eg. a User), view or schema module, or path name (atom defined in routes), along with optional arguments.
Generates a static path based on the given path and endpoint module.
Returns the full URL (including domain and path) for a given object, module, or path name.
Validates a URI string.
Functions
Returns the base domain from the given URI or endpoint.
iex> base_domain(%URI{host: "example.com", port: 443})
"example.com"
Returns the homepage URI (as struct) of the local instance.
> %URI{scheme: "http", host: "localhost"} = base_uri(:my_endpoint)
Return the homepage URL (as string) of the local instance
TODOC
Returns the canonical URL (i.e., the one used for ActivityPub federation) of an object.
Examples
iex> canonical_url(%{canonical_uri: "http://example.com"})
"http://example.com"
iex> canonical_url(%{canonical_url: "http://example.com"})
"http://example.com"
iex> canonical_url(%{"canonicalUrl" => "http://example.com"})
"http://example.com"
iex> canonical_url(%{peered: %{canonical_uri: "http://example.com"}})
"http://example.com"
iex> canonical_url(%{character: %{canonical_uri: "http://example.com"}})
"http://example.com"
iex> canonical_url(%{character: %{peered: %{canonical_uri: "http://example.com"}}})
"http://example.com"
iex> canonical_url(%{peered: %Ecto.Association.NotLoaded{}})
nil
iex> canonical_url(%{created: %Ecto.Association.NotLoaded{}})
nil
iex> canonical_url(%{character: %Ecto.Association.NotLoaded{}})
nil
iex> canonical_url(%{character: %{peered: %{}}})
nil
iex> canonical_url(%{path: "http://example.com"})
"http://example.com"
iex> canonical_url(%{other: "data"})
nil
Removes the scheme from a URL to get the display URL.
iex> display_url("https://example.com/path")
"example.com/path"
iex> display_url("http://example.com/path")
"example.com/path"
iex> display_url("/path")
"/path"
Returns true if the given string is a valid URI.
iex> is_uri?("http://example.com")
true
iex> is_uri?("invalid_uri")
false
Returns the path (URL on the local instance) for the given object/struct (eg. a User), view or schema module, or path name (atom defined in routes), along with optional arguments.
Returns the path (URL on the local instance) for the given object/struct (e.g., a User), view or schema module, or path name (atom defined in routes), along with optional arguments.
Examples
> path(:user, [1], [])
"/users/1"
> path(User, [1], [])
"/users/1"
> path(%{id: "1"}, :show, [])
"/users/1/show"
> path(%{id: "1"}, [some: :args], [])
"/users/1/some_args"
iex> path("12345", [some: :args], [])
nil
static_path(path, endpoint_module \\ Bonfire.Common.Config.endpoint_module())
View SourceGenerates a static path based on the given path and endpoint module.
> static_path("/assets/image.png")
"/assets/image.png"
Returns the full URL (including domain and path) for a given object, module, or path name.
> url_path(:user, [1])
"http://localhost:4000/discussion/user/1"
Validates a URI string.
Examples
iex> {:ok, %URI{scheme: "http", host: "example.com"}} = validate_uri("http://example.com")
iex> {:error, %URI{scheme: nil, host: nil}} = validate_uri("invalid_uri")