View Source UAInspector (UAInspector v3.0.0)
User agent parser library.
preparation
Preparation
- Verify your supervision setup according to
UAInspector.Supervisor
- Revise the default configuration values of
UAInspector.Config
and adjust to your project/environment where necessary - Download a copy of the database files as outlined in
UAInspector.Downloader
usage
Usage
iex(1)> UAInspector.parse("Mozilla/5.0 (iPad; CPU OS 7_0_4 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11B554a Safari/9537.53")
%UAInspector.Result{
browser_family: "Safari",
client: %UAInspector.Result.Client{
engine: "WebKit",
engine_version: "537.51.11",
name: "Mobile Safari",
type: "browser",
version: "7.0"
},
device: %UAInspector.Result.Device{
brand: "Apple",
model: "iPad",
type: "tablet"
},
os: %UAInspector.Result.OS{
name: "iOS",
platform: :unknown,
version: "7.0.4"
},
os_family: "iOS",
user_agent: "Mozilla/5.0 (iPad; CPU OS 7_0_4 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11B554a Safari/9537.53"
}
iex(2)> UAInspector.parse("Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Googlebot/2.1; +http://www.google.com/bot.html) Safari/537.36")
%UAInspector.Result.Bot{
category: "Search bot",
name: "Googlebot",
producer: %UAInspector.Result.BotProducer{
name: "Google Inc.",
url: "http://www.google.com"
},
url: "http://www.google.com/bot.html",
user_agent: "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Googlebot/2.1; +http://www.google.com/bot.html) Safari/537.36"
}
iex(3)> UAInspector.parse("generic crawler agent")
%UAInspector.Result.Bot{
category: :unknown,
name: "Generic Bot",
producer: %UAInspector.Result.BotProducer{
name: :unknown,
url: :unknown
},
url: :unknown,
user_agent: "generic crawler agent"
}
iex(4)> UAInspector.parse("--- undetectable ---")
%UAInspector.Result{
browser_family: :unknown,
client: :unknown,
device: :unknown,
os: :unknown,
os_family: :unknown,
user_agent: "--- undetectable ---"
}
The map key :user_agent
will hold the unmodified passed user agent.
If the device type cannot be determined a "desktop" device type will be
assumed (and returned). Both :brand
and :model
are set to :unknown
.
When a bot agent is detected the result with be a UAInspector.Result.Bot
struct instead of UAInspector.Result
.
Link to this section Summary
Functions
Checks if a user agent is a known bot.
Checks if a user agent is a HbbTV and returns its version if so.
Parses a user agent.
Parses a user agent without checking for bots.
Checks if UAInspector is ready to perform lookups.
Reloads all databases.
Checks if a user agent is a ShellTV.
Link to this section Functions
Specs
Checks if a user agent is a known bot.
Specs
Checks if a user agent is a HbbTV and returns its version if so.
Specs
parse(String.t() | nil) :: UAInspector.Result.t() | UAInspector.Result.Bot.t()
Parses a user agent.
Specs
parse_client(String.t() | nil) :: UAInspector.Result.t()
Parses a user agent without checking for bots.
Specs
ready?() :: boolean()
Checks if UAInspector is ready to perform lookups.
The true == ready?
definition is made on the assumption that if there is
at least one entry in all databases then lookups can be performed.
Checking the state is done using the currently active databases. Any potentially concurrent reload requests are not considered.
Specs
reload(Keyword.t()) :: :ok
Reloads all databases.
You can pass [async: true|false]
to define if the reload should happen
in the background (default!) or block your calling process until completed.
Specs
Checks if a user agent is a ShellTV.