Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
name: Tests
on: [ push, pull_request ]
jobs:
test:
name: Test (Ruby ${{ matrix.ruby }})
runs-on: ubuntu-${{ matrix.ubuntu }}
strategy:
fail-fast: false
matrix:
ruby: [ '3.3', '3.2', '3.1', '3.0', '2.7', '2.6', '2.5', '2.4', '2.3', 'jruby-9.4' ]
ubuntu: [ 'latest' ]
include:
- { ruby: '2.2', ubuntu: '20.04' }
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- run: bundle exec rake
14 changes: 0 additions & 14 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# UserAgent

[![Build Status](https://travis-ci.org/gshutler/useragent.svg?branch=master)](https://travis-ci.org/gshutler/useragent)
[![Build Status](https://github.com/gshutler/useragent/actions/workflows/test.yml/badge.svg)](https://github.com/gshutler/useragent/actions/workflows/test.yml)
[![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.
Expand Down
8 changes: 8 additions & 0 deletions lib/user_agent/browsers/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ def browser
application && application.product
end

def web_browser?
false
end

def version
application && application.version
end
Expand Down Expand Up @@ -78,6 +82,10 @@ def bot?
# list will be rejected.
elsif detect_comment_match(/bot/i)
true
# Google PageSpeed Insights adds "Chrome-Lighthouse" to the user agent
# https://stackoverflow.com/questions/16403295/what-is-the-name-of-the-google-pagespeed-user-agent
elsif detect_product("Chrome-Lighthouse")
true
elsif product = application.product
product.include?('bot')
else
Expand Down
4 changes: 4 additions & 0 deletions lib/user_agent/browsers/chrome.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ def build
webkit.version
end

def web_browser?
true
end

# Prior to Safari 3, the user agent did not include a version number
def version
str = if detect_product("CriOs")
Expand Down
4 changes: 4 additions & 0 deletions lib/user_agent/browsers/edge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ def os
OperatingSystems.normalize_os(os_comment)
end

def web_browser?
true
end

private

def os_comment
Expand Down
4 changes: 4 additions & 0 deletions lib/user_agent/browsers/gecko.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ def browser
GeckoBrowsers.detect { |browser| respond_to?(browser) } || super
end

def web_browser?
true
end

def version
v = send(browser).version
v.nil? ? super : v
Expand Down
4 changes: 4 additions & 0 deletions lib/user_agent/browsers/internet_explorer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ def browser
"Internet Explorer"
end

def web_browser?
true
end

def version
str = application.comment.join('; ')[/(MSIE\s|rv:)([\d\.]+)/, 2]
Version.new(str)
Expand Down
4 changes: 4 additions & 0 deletions lib/user_agent/browsers/opera.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ def browser
'Opera'
end

def web_browser?
true
end

def version
if mini?
Version.new(application.comment.detect{|c| c =~ /Opera Mini/}[/Opera Mini\/([\d\.]+)/, 1]) rescue Version.new
Expand Down
31 changes: 31 additions & 0 deletions lib/user_agent/browsers/samsung.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
class UserAgent
module Browsers
class Samsung < Webkit

SAMSUNG_BROWSER = 'SamsungBrowser'

def self.extend?(agent)
agent.detect { |useragent| useragent.product == SAMSUNG_BROWSER }
end

def version
self.detect { |useragent| useragent.product == SAMSUNG_BROWSER }.version
end

##
# @return [Boolean]
# SamsungBrowser is a mobile device
def mobile?
true
end

def browser
'Samsung Internet Browser'
end

def web_browser?
true
end
end
end
end
4 changes: 4 additions & 0 deletions lib/user_agent/browsers/vivaldi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ def platform
end
end

def web_browser?
true
end

def webkit
detect_product("AppleWebKit")
end
Expand Down
4 changes: 4 additions & 0 deletions lib/user_agent/browsers/webkit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ def platform
end
end

def web_browser?
true
end

def webkit
if product_match = detect { |useragent| useragent.product =~ WEBKIT_PRODUCT_REGEXP }
product_match
Expand Down
4 changes: 4 additions & 0 deletions lib/user_agent/browsers/wechat_browser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ def browser
'Wechat Browser'
end

def web_browser?
true
end

def version
micro_messenger = detect_product("MicroMessenger")
Version.new(micro_messenger.version)
Expand Down
51 changes: 51 additions & 0 deletions spec/browsers/acast_user_agent_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# frozen_string_literal: true

require 'user_agent'

shared_examples 'Acast' do |version, platform, os|
it "returns 'Acast' as its browser" do
expect(useragent.browser).to eq('Acast')
end

it "returns '#{version}' as its version" do
expect(useragent.version).to eq(version)
end

it "returns '#{platform}' as its platform" do
expect(useragent.platform).to eq(platform)
end

it "returns '#{os}' as its operating system" do
expect(useragent.os).to eq(os)
end

it { expect(useragent).to be_mobile }
it { expect(useragent).not_to be_desktop }
it { expect(useragent).not_to be_speaker }
it { expect(useragent).not_to be_bot }
it { expect(useragent).not_to be_web_browser }
end

describe "UserAgent: Acast/1.63.0 (Phone; iOS 11.2.6; iPad6,11)" do
let!(:useragent) { UserAgent.parse("Acast/1.63.0 (Phone; iOS 11.2.6; iPad6,11)") }

it_behaves_like 'Acast', '1.63.0', 'iPad', 'iOS 11.2.6'
end

describe "UserAgent: Acast/1.63.0 (Phone; iOS 11.2.5; iPhone9,4)" do
let!(:useragent) { UserAgent.parse("Acast/1.63.0 (Phone; iOS 11.2.5; iPhone9,4)") }

it_behaves_like 'Acast', '1.63.0', 'iPhone', 'iOS 11.2.5'
end

describe "UserAgent: Acast/1.42.1 (phone; android 10; Google Pixel 3 XL)" do
let!(:useragent) { UserAgent.parse("Acast/1.42.1 (phone; android 10; Google Pixel 3 XL)") }

it_behaves_like 'Acast', '1.42.1', 'Android', 'Android 10'
end

describe "UserAgent: Acast/1.26.0 (Linux;Android 9) ExoPlayerLib/2.2.0" do
let!(:useragent) { UserAgent.parse("Acast/1.26.0 (Linux;Android 9) ExoPlayerLib/2.2.0") }

it_behaves_like 'Acast', '1.26.0', 'Android', 'Android 9'
end
Loading
Loading