hound v1.0.2 Hound.Metadata

Metadata allows to pass and extract custom data through. This can be useful if you need to identify sessions.

The keys and values must be serializable using :erlang.term_to_binary/1.

Examples

You can start a session using metadata by doing the following:

Hound.start_session(metadata: %{pid: self()})

If you need to retrieve the metadata, you simply need to use Hound.Metadata.extract/1 on the user agent string, so supposing you are using plug,

user_agent =  conn |> get_req_header("user-agent") |> List.first
metadata   = Hound.Metadata.extract(user_agent)
assert %{pid: pid} = metadata
# you can use your pid here

Summary

Functions

Appends the metdata to the user_agent string

Extracts and parses the metadata contained in a user agent string. If the user agent does not contain any metadata, an empty map is returned

Formats a string to a valid UserAgent string to be passed to be appended to the browser user agent

Functions

append(user_agent, metadata)

Specs

append(String.t, nil | map | String.t) :: String.t

Appends the metdata to the user_agent string.

extract(str)

Extracts and parses the metadata contained in a user agent string. If the user agent does not contain any metadata, an empty map is returned.

format(metadata)

Specs

format(map | Keyword.t) :: String.t

Formats a string to a valid UserAgent string to be passed to be appended to the browser user agent.