Skip to content

Commit

Permalink
Detect alipay client (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
fnando authored Aug 31, 2016
2 parents 8d5e4be + e7453b1 commit d36174e
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Add Stripe and Netcraft to bots.
- Add Microsoft Bing bots (adldxbot, bingpreview, and msnbot-media).
- Match Alipay.

## v2.2.0

Expand Down
2 changes: 2 additions & 0 deletions lib/browser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
require "browser/micro_messenger"
require "browser/weibo"
require "browser/qq"
require "browser/alipay"

require "browser/bot"
require "browser/middleware"
Expand Down Expand Up @@ -51,6 +52,7 @@ def self.matchers
Firefox,
Weibo, # must be placed before Chrome and Safari
QQ, # must be placed before Chrome and Safari
Alipay, # must be placed before Chrome and Safari
Chrome,
Safari,
MicroMessenger,
Expand Down
19 changes: 19 additions & 0 deletions lib/browser/alipay.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module Browser
class Alipay < Base
def id
:alipay
end

def name
"Alipay"
end

def full_version
ua[%r[(?:AlipayClient)/([\d.]+)]i, 1] || "0.0"
end

def match?
ua =~ /AlipayClient/i
end
end
end
4 changes: 4 additions & 0 deletions lib/browser/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ def weibo?
Weibo.new(ua).match?
end

def alipay?
Alipay.new(ua).match?
end

# Detect if browser is Opera Mini.
def opera_mini?
ua =~ /Opera Mini/
Expand Down
2 changes: 2 additions & 0 deletions test/ua.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,5 @@ WEIBO_IOS: 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_4 like Mac OS X) AppleWebKit/60
WEIBO_ANDROID: 'Mozilla/5.0 (Linux; Android 5.0.2; vivo X5M Build/LRX22G) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/37.0.0.0 Mobile Safari/537.36 Weibo (vivo-vivo X5M__weibo__5.7.1__android__android5.0.2)'
QQ_BROWSER_IOS: 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_3_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Mobile/13E238 QQ/6.3.3.432 V1_IPH_SQ_6.3.3_1_APP_A Pixel/640 Core/UIWebView NetType/WIFI Mem/47'
QQ_BROWSER_ANDROID: 'Mozilla/5.0 (Linux; Android 5.1.1; SM-N9108V Build/LMY47X) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/37.0.0.0 Mobile MQQBrowser/6.2 TBS/036222 Safari/537.36 V1_AND_SQ_6.2.0_320_YYB_D QQ/6.2.0.2655 NetType/WIFI WebP/0.3.0 Pixel/1440'
ALIPAY_IOS: "Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53 AliApp(AP/2.3.4) AlipayClient/2.3.4"
ALIPAY_ANDROID: "Mozilla/5.0 (Linux; U; Android 4.2.1; zh-cn; HUAWEI G610-T00 Build/HuaweiG610-T00) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 AlipayDefined(nt:WIFI,ws:360|640|1.5) AliApp(AP/9.0.1.073001) AlipayClient/9.0.1.073001 GCanvas/1.4.2.15"
24 changes: 24 additions & 0 deletions test/unit/alipay_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true
require "test_helper"

class AlipayTest < Minitest::Test
test "detects alipay iOS" do
browser = Browser.new(Browser["ALIPAY_IOS"])
puts browser.id
puts browser.name

assert_equal :alipay, browser.id
assert browser.alipay?
assert_equal "Alipay", browser.name
assert_equal "2.3.4", browser.full_version
end

test "detects alipay Android" do
browser = Browser.new(Browser["ALIPAY_ANDROID"])

assert_equal :alipay, browser.id
assert browser.alipay?
assert_equal "Alipay", browser.name
assert_equal "9.0.1.073001", browser.full_version
end
end

0 comments on commit d36174e

Please sign in to comment.