Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gshutler/useragent
HTTP User Agent parser
https://github.com/gshutler/useragent
Last synced: about 2 months ago
JSON representation
HTTP User Agent parser
- Host: GitHub
- URL: https://github.com/gshutler/useragent
- Owner: gshutler
- License: mit
- Created: 2012-12-27T19:35:20.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2024-02-19T09:30:22.000Z (10 months ago)
- Last Synced: 2024-09-09T14:47:41.461Z (3 months ago)
- Language: Ruby
- Homepage:
- Size: 315 KB
- Stars: 178
- Watchers: 6
- Forks: 159
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome - useragent - HTTP User Agent parser (Ruby)
README
# UserAgent
[![Build Status](https://travis-ci.org/gshutler/useragent.svg?branch=master)](https://travis-ci.org/gshutler/useragent)
[![Gem Version](https://badge.fury.io/rb/useragent.svg)](http://badge.fury.io/rb/useragent)UserAgent is a Ruby library that parses and compares HTTP User Agents.
## Installation
gem install useragent
### Examples
#### Reporting
```ruby
string = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5'
user_agent = UserAgent.parse(string)
user_agent.browser
# => 'Chrome'
user_agent.version
# => '19.0.1084.56'
user_agent.platform
# => 'Macintosh'
```#### Comparison
```ruby
Browser = Struct.new(:browser, :version)SupportedBrowsers = [
Browser.new("Safari", "3.1.1"),
Browser.new("Firefox", "2.0.0.14"),
Browser.new("Internet Explorer", "7.0")
]user_agent = UserAgent.parse(request.user_agent)
SupportedBrowsers.detect { |browser| user_agent >= browser }
```Copyright (c) 2015-2019 Garry Shutler, released under the MIT license