class Tweakphoeus::UserAgent

User agent data generator

Constants

OS_DATA

Public Class Methods

random(systems: OS_DATA[:types]) click to toggle source
# File lib/tweakphoeus/user_agent.rb, line 14
def random(systems: OS_DATA[:types])
  user_agent = "Mozilla/5.0 (#{os[systems.sample]}) #{browser}"
  firefox_version = user_agent.match(%r{Firefox/([0-9.]+)})
  user_agent.gsub!(')', "; rv:#{firefox_version[1]})") if firefox_version.is_a?(MatchData)
  user_agent
end

Private Class Methods

browser() click to toggle source
# File lib/tweakphoeus/user_agent.rb, line 31
def browser
  chrome_version = "Chrome/#{Random.rand(90..92)}.0.#{Random.rand(1000..4000)}.#{Random.rand(100..900)}"
  webkit603 = "603.#{Random.rand(0..9)}.#{Random.rand(0..9)}"
  ["Gecko/20100101 Firefox/#{Random.rand(82..90)}.0",
   "AppleWebKit/537.36 (KHTML, like Gecko) #{chrome_version} Safari/537.36",
   "AppleWebKit/#{webkit603} (KHTML, like Gecko) Version/10.1 #{chrome_version} Safari/#{webkit603}"].sample
end
os() click to toggle source
# File lib/tweakphoeus/user_agent.rb, line 23
def os
  {
    win: "Windows NT #{"#{%w[5 6 7 8 10].sample}.#{%w[0 1].sample}"}",
    linux: "X11; #{['', "#{OS_DATA[:linux_distro].sample}; "].sample}Linux #{OS_DATA[:arch].sample}",
    mac: "Macintosh; Intel Mac OS X 10_#{Random.rand(11..13)}_#{Random.rand(0..3)}"
  }
end