isbot 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 379d67b37eaedcd41284a4f047a4982c4c914e30
4
- data.tar.gz: fc33bf369f402c899bf1ed5c1dbea4dd8667fde4
3
+ metadata.gz: d9d1d1bd8a2da54f66ee96a4e016eda9ea71c8d5
4
+ data.tar.gz: 7a8578933be095b5180d7db76b70011dad614788
5
5
  SHA512:
6
- metadata.gz: 9806ad2d0580d92842701eff286137ad5ca3e16d1dacef4ead90b2ca095b92dd7dc5d6db7c87bdd646365be306a96206181d7c2833c7824e41d977788bcda4fa
7
- data.tar.gz: 743aecd910ee3a6b66d8454cff8854d59f5ea287c579c852295c81ceee71b2fdb8716f3403aaf18281cc532a02fc336499617c6065a9a663f201215a16b530b9
6
+ metadata.gz: 54eef6e02d138091ea81eade42ee6502402377a93514f7662d90cc7fdc9d9a935cc4196252c6cd593b0adc147e7b02b97db7302b0f5d72bb700ec4baea3c3758
7
+ data.tar.gz: 36d32f718d1b09384f955bc4aa55877044ecdf76092c5891a77d601ca361289ea3a4e51fb71d7d94d87debb211f4829b9de1cd21734a315f72b859a4e0d08236
data/README.md CHANGED
@@ -14,16 +14,25 @@ user_agent = 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot
14
14
  # Three forms of use:
15
15
 
16
16
  # 1. Use the is_bot function
17
- puts is_bot user_agent # true
17
+ is_bot user_agent # true
18
18
 
19
19
  # 2. Use the monkey patch method of the String object
20
- puts user_agent.is_bot? # true
20
+ user_agent.is_bot? # true
21
21
 
22
22
  # 3. Use the is_bot function with code_blocks
23
23
  is_bot user_agent do |match_bot|
24
24
  puts match_bot # Googlebot/
25
25
  end
26
26
  ````
27
+
28
+ Add a Spider User-Agent field:
29
+
30
+ ```` ruby
31
+ user_agent = 'Mozilla/5.0 (compatible; MyBot/1.0; +http://my.me/bot.html'
32
+ IsBot::add_ua_field 'MyBot'
33
+
34
+ user_agent.is_bot? # true
35
+ ````
27
36
  #### Attached:
28
37
 
29
38
  The crawler user-agent data from https://github.com/monperrus/crawler-user-agents, thanks! 😀
@@ -1,14 +1,14 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'isbot'
3
- s.version = '0.1.1'
3
+ s.version = '0.1.2'
4
4
  s.executables << 'isbot'
5
- s.date = '2017-05-16'
5
+ s.date = '2017-05-21'
6
6
  s.summary = 'detects bots/crawlers/spiders via the user agent.'
7
7
  s.description = 'A simple library for detecting bots/crawlers/spiders through User-Agent strings.'
8
8
  s.authors = ['Hentioe']
9
- s.email = 'meow.i5.br@gmai.com'
9
+ s.email = 'meow.i5.br@gmail.com'
10
10
  s.files = Dir['**/*']
11
11
  s.homepage =
12
12
  'https://github.com/Hentioe/isbot'
13
13
  s.license = 'MIT'
14
- end
14
+ end
@@ -18,6 +18,11 @@ module IsBot
18
18
  $regex
19
19
  end
20
20
 
21
+ def IsBot.add_ua_field(user_agent_field)
22
+ IsBotParser::PATTERN_LIST.push user_agent_field
23
+ $init = false
24
+ end
25
+
21
26
  end
22
27
 
23
28
  def is_bot(user_agent, &block)
@@ -15,7 +15,7 @@ module IsBotParser
15
15
  list = JSON.parse(json_str)
16
16
  list.each do |item|
17
17
  pattern = item['pattern'].to_s
18
- PATTERN_LIST.push(pattern)
18
+ PATTERN_LIST.push(pattern) unless PATTERN_LIST.include? pattern
19
19
  end
20
20
  PATTERN_LIST
21
21
  end
@@ -5,7 +5,7 @@ class IsBotTest < Test::Unit::TestCase
5
5
  $list = [
6
6
  'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)',
7
7
  'Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)',
8
- 'Mozilla/5.0 (compatible; Baiduspid1er/2.0; +http://www.baidu.com/search/spider.html)'
8
+ 'Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)'
9
9
  ]
10
10
 
11
11
  def test_is_bot
@@ -15,8 +15,15 @@ class IsBotTest < Test::Unit::TestCase
15
15
  def test_is_bot_with_block
16
16
  $list.each do |ua|
17
17
  is_bot ua do |match_bot|
18
- puts match_bot.to_s
18
+ assert_not_nil match_bot
19
19
  end
20
20
  end
21
21
  end
22
+
23
+ def test_add_ua_field
24
+ user_agent = 'Mozilla/5.0 (compatible; MyBot/1.0; +http://my.me/bot.html'
25
+ IsBot::add_ua_field 'MyBot'
26
+
27
+ assert_true user_agent.is_bot?
28
+ end
22
29
  end
metadata CHANGED
@@ -1,18 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isbot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hentioe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-16 00:00:00.000000000 Z
11
+ date: 2017-05-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A simple library for detecting bots/crawlers/spiders through User-Agent
14
14
  strings.
15
- email: meow.i5.br@gmai.com
15
+ email: meow.i5.br@gmail.com
16
16
  executables:
17
17
  - isbot
18
18
  extensions: []