Module: Fontist::Utils::UserAgent

Defined in:
lib/fontist/utils/user_agent.rb

Constant Summary collapse

PROFILES =
[
  {
    user_agent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) " \
                "AppleWebKit/537.36 (KHTML, like Gecko) " \
                "Chrome/131.0.0.0 Safari/537.36",
    platform: '"macOS"',
    chrome_version: "131",
  },
  {
    user_agent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " \
                "AppleWebKit/537.36 (KHTML, like Gecko) " \
                "Chrome/130.0.0.0 Safari/537.36",
    platform: '"Windows"',
    chrome_version: "130",
  },
  {
    user_agent: "Mozilla/5.0 (X11; Linux x86_64) " \
                "AppleWebKit/537.36 (KHTML, like Gecko) " \
                "Chrome/132.0.0.0 Safari/537.36",
    platform: '"Linux"',
    chrome_version: "132",
  },
  {
    user_agent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) " \
                "AppleWebKit/537.36 (KHTML, like Gecko) " \
                "Chrome/130.0.0.0 Safari/537.36",
    platform: '"macOS"',
    chrome_version: "130",
  },
  {
    user_agent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " \
                "AppleWebKit/537.36 (KHTML, like Gecko) " \
                "Chrome/132.0.0.0 Safari/537.36",
    platform: '"Windows"',
    chrome_version: "132",
  },
].freeze
ACCEPT =
"text/html,application/xhtml+xml,application/xml;q=0.9," \
"image/avif,image/webp,image/apng,*/*;q=0.8," \
"application/signed-exchange;v=b3;q=0.7"
ACCEPT_LANGUAGE =
"en-US,en;q=0.9"
STATIC_HEADERS =
{
  "Accept" => ACCEPT,
  "Accept-Language" => ACCEPT_LANGUAGE,
  "Cache-Control" => "no-cache",
  "Pragma" => "no-cache",
  "Sec-Ch-Ua-Mobile" => "?0",
  "Sec-Fetch-Dest" => "document",
  "Sec-Fetch-Mode" => "navigate",
  "Sec-Fetch-Site" => "cross-site",
  "Sec-Fetch-User" => "?1",
  "Upgrade-Insecure-Requests" => "1",
}.freeze

Class Method Summary collapse

Class Method Details

.browser_headersObject



68
69
70
71
# File 'lib/fontist/utils/user_agent.rb', line 68

def browser_headers
  profile = random_profile
  build_headers(profile)
end

.random_profileObject



64
65
66
# File 'lib/fontist/utils/user_agent.rb', line 64

def random_profile
  PROFILES.sample
end

.random_user_agentObject



73
74
75
# File 'lib/fontist/utils/user_agent.rb', line 73

def random_user_agent
  random_profile[:user_agent]
end