Skip to content

Commit

Permalink
Merge branch 'main' into feature/mail_master
Browse files Browse the repository at this point in the history
  • Loading branch information
itsalongstory authored Mar 11, 2024
2 parents 984b0af + fa4f685 commit 7ce5d70
Show file tree
Hide file tree
Showing 106 changed files with 871 additions and 303 deletions.
4 changes: 4 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# These are supported funding model platforms
---
github: [fnando]
custom: ["https://paypal.me/nandovieira/🍕"]
58 changes: 58 additions & 0 deletions .github/workflows/ruby-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
name: ruby-tests

on:
pull_request_target:
push:
branches:
- main
workflow_dispatch:
inputs: {}

jobs:
build:
name: Tests with Ruby ${{ matrix.ruby }} and ${{ matrix.gemfile }}
runs-on: "ubuntu-latest"
if: |
github.actor == 'dependabot[bot]' && github.event_name == 'pull_request_target' ||
github.actor != 'dependabot[bot]'
strategy:
fail-fast: false
matrix:
ruby: ["2.7", "3.0", "3.1"]
gemfile:
- Gemfile
- gemfiles/7_0.gemfile
- gemfiles/6_1.gemfile
- gemfiles/6_0.gemfile

steps:
- uses: actions/[email protected]

- uses: actions/cache@v2
with:
path: vendor/bundle
key: >
${{ runner.os }}-${{ matrix.ruby }}-gems-${{
hashFiles(matrix.gemfile) }}
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}

- name: Install gem dependencies
env:
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
run: |
gem install bundler
bundle config path vendor/bundle
bundle update --jobs 4 --retry 3
- name: Run Tests
env:
PGHOST: localhost
PGUSER: postgres
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
run: |
bundle exec rake
24 changes: 2 additions & 22 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ inherit_gem:

AllCops:
TargetRubyVersion: 2.5
NewCops: enable
Exclude:
- bin/**/*
- gemfiles/**/*
Expand All @@ -13,26 +14,5 @@ AllCops:
- "*.gemspec"
- config.ru

Metrics/ClassLength:
Enabled: false

Layout/LineLength:
Max: 80

Metrics/MethodLength:
Enabled: false

Style/Alias:
EnforcedStyle: prefer_alias_method

Lint/RedundantCopDisableDirective:
Enabled: false

Metrics/AbcSize:
Enabled: false

Metrics/CyclomaticComplexity:
Enabled: false

Metrics/PerceivedComplexity:
Naming/VariableNumber:
Enabled: false
23 changes: 0 additions & 23 deletions .travis.yml

This file was deleted.

57 changes: 47 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,56 @@

## Unreleased

- Rename `Browser::Platform#other?` to `Browser::Platform#unknown?`
- Unknown platforms now return `:unknown_platform` as the id
- Unknown devices now return `:unknown_device` as the id
- Unknown browsers now return `:unknown_browser` as the id
- All the changes above affect how `browser.meta` is composed
- Add method `Browser::Base#unknown?`
- Fix issue with `Browser::Base#safari?` matching full version
- Add Maxthon detection
- Add Google Search App detection
- Add Huawei Browser detection
- Add `Browser::Base#chromium_based?`.
- Change how browser detection works to avoid re-instantiating classes.

## 5.3.1

- Remove Stripe webhooks from bot list.

## 5.3.0

- Bump up minimum required ruby version to 2.5.0. We're now relying on
`String#match?`, which was introduced by ruby-2.4, but given that ruby's
stable version is >= 2.5, seems reasonable.

## 5.2.0

- Add KaiOS detection.
- Replace `String#=~` with `String#match?` and other optimizations.

## 5.1.0

- Add Samsung device detection.
- Delay parsing `Accept-Language` until `Browser::Base#accept_language` is
called for the first time.
- Bump up default size limit for `Accept-Language` and `User-Agent` to 2048
bytes.

## 5.0.0

- Rename `Browser::Platform#other?` to `Browser::Platform#unknown?`.
- Unknown platforms now return `:unknown_platform` as the id.
- Unknown devices now return `:unknown_device` as the id.
- Unknown browsers now return `:unknown_browser` as the id.
- All the changes above affect how `browser.meta` is composed.
- Add method `Browser::Base#unknown?`.
- Fix issue with `Browser::Base#safari?` matching full version.
- Add Maxthon detection.
- Add Google Search App detection.
- Add Huawei Browser detection.
- Fix Duck Duck Go browser that was being recognized as a bot.
- Add Miui Browser detection
- Add Mail Master mail app for iOS & Android detection
- Add Miui Browser detection.
- Add `Browser::Base#qq?`.
- Fix QQ detection.
- Fix Alipay detection.
- Add Sougou Browser detection.
- User agent has a size limit of 512 bytes. This can be customized through
`Browser.user_agent_size_limit`.
- Accept-Language has a size limit of 256 bytes. This can be customized through
`Browser.accept_language_size_limit`.

## 4.2.0

Expand Down
20 changes: 20 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# The MIT License (MIT)

Copyright (c) 2010 Nando Vieira

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 changes: 21 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Browser

[![Travis-CI](https://travis-ci.org/fnando/browser.svg)](https://travis-ci.org/fnando/browser)
[![Code Climate](https://codeclimate.com/github/fnando/browser/badges/gpa.svg)](https://codeclimate.com/github/fnando/browser)
[![Test Coverage](https://codeclimate.com/github/fnando/browser/badges/coverage.svg)](https://codeclimate.com/github/fnando/browser/coverage)
[![Tests](https://github.com/fnando/browser/workflows/ruby-tests/badge.svg)](https://github.com/fnando/browser)
[![Gem](https://img.shields.io/gem/v/browser.svg)](https://rubygems.org/gems/browser)
[![Gem](https://img.shields.io/gem/dt/browser.svg)](https://rubygems.org/gems/browser)

Expand All @@ -24,6 +22,7 @@ browser = Browser.new("Some User Agent", accept_language: "en-us")
# General info
browser.bot?
browser.chrome?
browser.chromium_based?
browser.core_media?
browser.duck_duck_go?
browser.edge? # Newest MS browser
Expand Down Expand Up @@ -52,9 +51,10 @@ browser.webkit?
browser.webkit_full_version
browser.yandex?
browser.wechat?
browser.qq?
browser.weibo?
browser.yandex?
browser.sputnik?
browser.sougou_browser?

# Get bot info
browser.bot.name
Expand Down Expand Up @@ -88,6 +88,7 @@ browser.device.tv?
browser.device.vita?
browser.device.wii?
browser.device.wiiu?
browser.device.samsung?
browser.device.switch?
browser.device.xbox?
browser.device.xbox_360?
Expand Down Expand Up @@ -128,6 +129,7 @@ browser.platform.windows_wow64?
browser.platform.windows_x64?
browser.platform.windows_x64_inclusive?
browser.platform.windows_xp?
browser.platform.kai_os?
```

### Aliases
Expand Down Expand Up @@ -302,7 +304,7 @@ To add custom matchers, you can add a callable object to
`externalhit` substring on it. The bot name will always be `General Bot`.

```ruby
Browser::Bot.matchers << ->(ua, _browser) { ua =~ /externalhit/i }
Browser::Bot.matchers << ->(ua, _browser) { ua.match?(/externalhit/i) }
```

To clear all matchers, including the ones that are bundled, use
Expand Down Expand Up @@ -348,6 +350,20 @@ Rails.configuration.middleware.use Browser::Middleware do
end
```

### Restrictions

- User agent has a size limit of 2048 bytes. This can be customized through
`Browser.user_agent_size_limit=(size)`.
- Accept-Language has a size limit of 2048 bytes. This can be customized through
`Browser.accept_language_size_limit=(size)`.

If size is not respected, then `Browser::Error` is raised.

```ruby
Browser.user_agent_size_limit = 4096
Browser.accept_language_size_limit = 4096
```

## Development

### Versioning
Expand Down
1 change: 0 additions & 1 deletion bots.yml
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ spinn3r: Spinn3r aggregator
sputnikbot: SputnikBot
squider: Squider
statuscake: StatusCake
stripe: Stripe
swiftbot: Swiftype Bot
tangibleebot: TangibleeBot
teeraid: TeeRaidBot
Expand Down
7 changes: 4 additions & 3 deletions browser.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ Gem::Specification.new do |s|
s.summary = "Do some browser detection with Ruby."
s.description = s.summary
s.license = "MIT"
s.required_ruby_version = ">= 2.5.0"

s.metadata["changelog_uri"] = "https://github.com/fnando/browser/blob/main/CHANGELOG.md"

s.metadata["changelog_uri"] = "https://github.com/fnando/browser/blob/master/CHANGELOG.md"

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- exe/*`
Expand All @@ -31,6 +32,6 @@ Gem::Specification.new do |s|
s.add_development_dependency "rails"
s.add_development_dependency "rake"
s.add_development_dependency "rubocop"
s.add_development_dependency "rubocop-fnando", "~> 0.0.3"
s.add_development_dependency "rubocop-fnando"
s.add_development_dependency "simplecov"
end
2 changes: 1 addition & 1 deletion gemfiles/rails5.gemfile → gemfiles/6_0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
source "https://rubygems.org"
gemspec path: ".."

gem "rails", "~> 5.0"
gem "rails", "~> 6.0.0"
2 changes: 1 addition & 1 deletion gemfiles/rails6.gemfile → gemfiles/6_1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
source "https://rubygems.org"
gemspec path: ".."

gem "rails", "~> 6.0"
gem "rails", "~> 6.1.0"
6 changes: 6 additions & 0 deletions gemfiles/7_0.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

source "https://rubygems.org"
gemspec path: ".."

gem "rails", "~> 7.0.0"
8 changes: 4 additions & 4 deletions lib/browser/accept_language.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ def region
def quality
@quality ||= begin
Float(quality_value || 1.0)
rescue ArgumentError
0.1
rescue ArgumentError
0.1
end
end

private def quality_value
qvalue = part[/;q=([\d.]+)/, 1]
qvalue = qvalue =~ /\A0\.0?\z/ ? "0.0" : qvalue
qvalue = qvalue.gsub(/\.+/, ".") if qvalue
qvalue = "0.0" if /\A0\.0?\z/.match?(qvalue)
qvalue = qvalue.squeeze(".") if qvalue
qvalue
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/browser/alipay.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def full_version
end

def match?
ua =~ /AlipayClient/i
ua.match?(/AlipayClient/i)
end
end
end
Loading

0 comments on commit 7ce5d70

Please sign in to comment.