The Elixir implementation of Project Woothee, which is multi-language user-agent strings parsers.
There are simply NIF bindings to Rust implementation of the project.
To successfully compile wootheex
, Rust toolchain must be installed on your system with either rustup
or any other installation method.
Once you have that installed (paths may differ):
~ $ which cargo rustc
/home/user/.cargo/bin/cargo
/home/user/.cargo/bin/rustc
You can jump to the next step.
To install Wootheex
you just add it to deps in mix.exs
:
def deps do
[
{:wootheex, "~> 0.1.0"}
]
end
And then download deps with mix deps.get
.
All existing UA parsers are not fast enough for soft real-time systems. Examples are:
The most advanced one, identifies most bots (~95%), but also the slowest one (around 10ms per UA)
UAParser and uap-elixir
These has less functonality, do not identify bots at all, although have better performance (around 1ms)
Because of high performance of original Rust implementation of Project Woothee, binding it's functionality with NIFs gives its full power to Elixir with around 8 microsecond, which is more than 1000 times faster than UAInspector, and about 100 times faster than other implementations
With defined user agent:
iex(1)> user_agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.155 Safari/537.36"
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.155 Safari/537.36"
For basic information in a simple tuple, call Wootheex.parse/1
:
iex(1)> Wootheex.parse(user_agent)
{:pc, "Chrome", :browser, "44.0.2403.155", "Mac OSX", "10.10.4", "Google"}
For more fancy result call Wootheex.UserAgent.parse/1
:
iex(3)> Wootheex.UserAgent.parse(user_agent)
%Wootheex.UserAgent{
browser_name: "Chrome",
browser_type: :browser,
browser_version: "44.0.2403.155",
category: :pc,
os: "Mac OSX",
os_version: "10.10.4",
vendor: "Google"
}