Erlang User-Agent Parser Library for the uap-core project.
Get a copy of regexes.yaml
with:
make priv/regexes.yaml
From a make all shell
you should be able to just run:
application:ensure_all_started(yamerl),
rr(uap),
f(),
{ok, UAP} = uap:state(file, "priv/regexes.yaml"),
UA = "Mozilla/5.0 (X11; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0",
uap:parse(UA, UAP).
{ok, [
#uap_ua{family = "Firefox",major = "55",minor = "0",
patch = undefined},
#uap_os{family = "Linux",major = undefined,minor = undefined,
patch = undefined,patch_minor = undefined},
#uap_device{family = "Other",brand = undefined,
model = undefined}
]}
application:ensure_all_started(uap),
rr(uap).
uap_server:parse(UA, [os]).
Add to your rel/sys.config
so that when the application (re)starts it knows how to build its internal state:
{uap, [{priv,APP}]}
Now just add to the applications
section of your APP.app.src
file uap
.
Add to your Makefile
:
DEPS += uap
dep_uap = git https://gitlab.com/jimdigriz/uap-erlang.git master
Loads in YAML in the expected format from either a provided filepath or in-memory string.
Throws on error.
Same as parse(iodata(), [ua, os, device], uap())
.
Parses the User-Agent in passed in as the string UA
.
N.B. from the unit tests, it seems that parsing binaries is faster than lists
Same as start_link([])
.
Supported configuration properties are:
priv
(default:uap
): application name for thepriv
directory whereregexes.yaml
is locatedfile
(default:regexes.yaml
): name of the regexes file to loadcache
(default: 10000): number of entries for the lookup cache (can also be0
for disabled andunlimited
)
parse(iodata(), list(ua | os | device))
-> {ok, [uap_ua() | uap_os() | uap_device()]} | {error,atom()}`
Same as parse(iodata(), list(ua | os | device), [])
.
parse(iodata(), list(ua | os | device), list(proplists:property()))
-> {ok, [uap_ua() | uap_os() | uap_device()]} | {error,atom()}`
Supported properties are:
normalize
(default: false):- improves the effectiveness of the cache
- recommended only when the cardinality of User-Agents is high
- suitable for use only when you require
#uap_{ua,os}.{family,major}
as it is inaccurate for all other fields!
An an error is returned if you duplicate any of the atoms ua
os
or device
in the list of results to return.
Fetch a copy of the test data:
make testdata
Now run the tests (takes about five minutes and needs 4GB of RAM) with:
make tests
If you just want to test the uap-core
test data (takes about 30 seconds and needs 4GB of RAM) use:
make tests CT_SUITES=uap