Skip to content

Latest commit

 

History

History

ruby

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

README.md

User Agent Parser API - Ruby Gem

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.

Installation

Add this line to your application's Gemfile:

gem 'apiverve_useragentparser'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install apiverve_useragentparser

Getting Started

Get your API key at APIVerve

Basic Usage

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 response

Error Handling

begin
  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

Debug Mode

# Enable debug logging
client = APIVerve::Useragentparser::Client.new(
  api_key: "YOUR_API_KEY",
  debug: true
)

Example Response

{
  "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"
  }
}

Documentation

For more information, visit the API Documentation.

Support

License

This gem is available under the MIT License.