User Agent Parser parses user agent strings to extract browser, operating system, and hardware details. It identifies device types, CPU architecture, and bot traffic, so you can run user agent detection on every incoming HTTP request.
Add this line to your application's Gemfile:
gem 'apiverve_useragentparser'And then execute:
$ bundle installOr install it yourself as:
$ gem install apiverve_useragentparserGet your API key at APIVerve
require 'apiverve_useragentparser'
# Initialize the client
client = APIVerve::Useragentparser::Client.new(api_key: "YOUR_API_KEY")
# Make a request
response = client.execute({ ua: "Mozilla/5.0 (Windows NT 6.4) AppleWebKit/537.36.0 (KHTML, like Gecko) Chrome/60.0.0.0 Safari/537.36.0" })
# Print the response
puts responsebegin
response = client.execute({ ua: "Mozilla/5.0 (Windows NT 6.4) AppleWebKit/537.36.0 (KHTML, like Gecko) Chrome/60.0.0.0 Safari/537.36.0" })
puts response["data"]
rescue APIVerve::Useragentparser::ValidationError => e
puts "Validation error: #{e.errors.join(', ')}"
rescue APIVerve::Useragentparser::APIError => e
puts "API error: #{e.message}"
puts "Status code: #{e.status_code}"
end# Enable debug logging
client = APIVerve::Useragentparser::Client.new(
api_key: "YOUR_API_KEY",
debug: true
){
"status": "ok",
"error": null,
"data": {
"ua": "Mozilla/5.0 (Windows NT 6.4) AppleWebKit/537.36.0 (KHTML, like Gecko) Chrome/60.0.0.0 Safari/537.36.0",
"browser": {
"name": "Chrome",
"version": "60.0.0.0",
"major": "60"
},
"engine": {
"name": "Blink",
"version": "60.0.0.0"
},
"os": {
"name": "Windows",
"version": "10"
},
"device": {},
"cpu": {},
"isMobile": false,
"isBot": false,
"deviceType": "desktop",
"clientType": "browser",
"library": null,
"isSuspicious": false,
"suspiciousReasons": [],
"osVersionFrozen": true,
"versionCheck": {
"browserFamily": "Chrome",
"latestVersion": "156",
"majorsBehind": 95,
"isOutdated": true,
"osEndOfLife": null
},
"summary": "Chrome 60 on Windows 10"
}
}For more information, visit the API Documentation.
- Website: https://apiverve.com/marketplace/useragentparser?utm_source=ruby&utm_medium=referral&utm_content=readme
- Email: hello@apiverve.com
This gem is available under the MIT License.