User Agent Parser API - Ruby Gem

User Agent Parser is a simple tool for parsing user agent strings. It returns the browser, operating system, and more from the user agent string.

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,
    "summary": "Chrome 60 on Windows 10"
  }
}

Documentation

For more information, visit the API Documentation.

Support

License

This gem is available under the MIT License.