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

Link to this function

base_domain(uri_or_endpoint_or_conn \\ nil)

View Source

Returns the base domain from the given URI or endpoint.

iex> base_domain(%URI{host: "example.com", port: 443})
"example.com"
Link to this function

base_uri(conn_or_socket \\ nil)

View Source

Returns the homepage URI (as struct) of the local instance.

> %URI{scheme: "http", host: "localhost"} = base_uri(:my_endpoint)
Link to this function

base_url(conn_or_socket_or_uri \\ nil)

View Source

Return the homepage URL (as string) of the local instance

Link to this function

based_url(url, conn \\ nil)

View Source

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"
Link to this function

fallback(id, type, args)

View Source

Returns true if the given string is a valid URI.

iex> is_uri?("http://example.com")
true

iex> is_uri?("invalid_uri")
false
Link to this function

maybe_generate_canonical_url(thing)

View Source
Link to this function

path(view_module_or_path_name_or_object, args \\ [], opts \\ [])

View Source

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
Link to this function

path_by_id(id, args, object, opts)

View Source
Link to this function

remote_canonical_url(object)

View Source
Link to this function

static_path(path, endpoint_module \\ Bonfire.Common.Config.endpoint_module())

View Source

Generates a static path based on the given path and endpoint module.

> static_path("/assets/image.png")
"/assets/image.png"
Link to this function

url_path(view_module_or_path_name_or_object, args \\ [])

View Source

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")