No commit activity in last 3 years
No release in over 3 years
In few cases random HTTP User-Agent strings are required that are generated by this gem.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.6
~> 0.7
~> 1.6
~> 10.3
~> 3.0
~> 0.8
 Project Readme

UserAgentRandomizer

Gem Version Build Status Dependency Status Code Climate Coverage Status

There exist few use cases where random HTTP User-Agent strings are required. This was the motivation for me to write this user-agent-randomizer Ruby gem. Currently it provides ca. 10.700 different HTTP User-Agent strings. You can choose a random HTTP User-Agent string from the entire pool as well as fetch a HTTP User-Agent string by category.

Every HTTP User-Agent string is assigned exactly to one of the following categories:

  • crawler
  • desktop_browser
  • mobile_browser
  • console
  • offline_browser
  • email_client
  • link_checker
  • email_collector
  • validator
  • feed_reader
  • library
  • cloud_platform
  • other

Installation

Add this line to your application's Gemfile:

gem 'user-agent-randomizer'

And then execute:

$ bundle

Or install it manually:

$ gem install user-agent-randomizer

Usage

The usage is pretty simple. You can fetch a random HTTP User-Agent string from the entire pool as well as one from a specified category (see the list above):

Open an IRB and require the gem first of all:

irb> require 'user_agent_randomizer'
# => true

Fetch a random HTTP User-Agent string from the entire pool:

irb> ua_all = UserAgentRandomizer::UserAgent.fetch
# => #<UserAgentRandomizer::UserAgent:0x007fe1f30a6658 @type="crawler", @string="CatchBot/1.0;  http://www.catchbot.com">

Fetch a random HTTP User-Agent for a desktop browser:

irb> ua_desktop = UserAgentRandomizer::UserAgent.fetch(type: "desktop_browser")
# => #<UserAgentRandomizer::UserAgent:0x007fe1f2282b58 @type="desktop_browser", @string="Mozilla/4.6 [en] (WinNT; I)">

Retrieve the type and the string from the objects above:

irb> puts "UA general -> type: '#{ua_all.type}', string: '#{ua_all.string}'"
# => "UA general -> type: 'crawler', string: 'CatchBot/1.0;  http://www.catchbot.com'"

irb> puts "UA desktop browser -> type: '#{ua_desktop.type}', string: '#{ua_desktop.string}'"
# => "UA desktop browser -> type: 'desktop_browser', string: 'Mozilla/4.6 [en] (WinNT; I)'"

Contributing

  1. Fork it ( https://github.com/asconix/user-agent-randomizer/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Copyright © 2014 Asconix Systems AS (Christoph Pilka), released under the MIT license