awesome_bot 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1aa43c6f8d790d1333e7777dbd1794552c1f5b51
4
- data.tar.gz: ab95e39072c0bc07dce439e09baaba53feac1776
3
+ metadata.gz: 8feb264201072a97f70c9146f636d95bcd5fca77
4
+ data.tar.gz: 5762b4ef3b0584cd155b87dd3ba81cb5347f6a1d
5
5
  SHA512:
6
- metadata.gz: bd052b6b4b58b4cfd60c148aa8f79158aa523e71c8403a5dfa6ff0fea57bc2503a10bd4a4e9e772daf8eebe8ae3a2944ad159d746587840b6cc3a06ce8aa7d19
7
- data.tar.gz: 2a95a657d668d72ea67fba69f19a400323d9669938230a9cdee1468f3c01e15de8f0504b7bfcceb00c8f3472eb3850cd900a5588efe38829e62aa7607e390dcb
6
+ metadata.gz: 00f748d97bc39f0ad148288611ed8252dc0d1f242da3b948146a0cae7e3c373063fc9df67f14990dff622e9ae01b81934018a00b28931d2a425ac643d3df8dd1
7
+ data.tar.gz: 023bad1bc68ee5b59915ac10cd2ccad6fe3d77626318b886fe8a1ad5c3da1bd51d1707020d2396165589e3efe54d725816b7d35706c66d734c94c3a790555840
@@ -13,6 +13,13 @@
13
13
  - [gemspec] update
14
14
  - [travis] simplify
15
15
 
16
+ ## 1.1.0
17
+
18
+ - handle bad links
19
+ - statuses yields `status`, `url`
20
+ - add head option when getting statuses
21
+ - [cli] improve output for `--allow-dupe`
22
+
16
23
  ## Contact
17
24
 
18
25
  - [github.com/dkhamsing](https://github.com/dkhamsing)
data/README.md CHANGED
@@ -11,15 +11,15 @@
11
11
 
12
12
  ## Installation
13
13
 
14
- Add this line to your application's Gemfile:
14
+ Add this line to your application's Gemfile
15
15
 
16
- gem 'awesome_bot', '~> 0.1'
16
+ gem 'awesome_bot'
17
17
 
18
- And then execute:
18
+ And then execute
19
19
 
20
20
  $ bundle
21
21
 
22
- Or install it yourself as:
22
+ Or install it yourself as
23
23
 
24
24
  $ gem install awesome_bot
25
25
 
@@ -38,7 +38,7 @@ irb(main):003:0> AwesomeBot.check c
38
38
  # otherwise returning true
39
39
  ```
40
40
 
41
- More information at [rubydoc](http://www.rubydoc.info/gems/awesome_bot/0.1.0).
41
+ More information at [rubydoc](http://www.rubydoc.info/gems/awesome_bot/1.1.0).
42
42
 
43
43
  ### Command Line
44
44
 
@@ -110,13 +110,9 @@ language: ruby
110
110
  rvm:
111
111
  - 2.2
112
112
  before_script:
113
- - wget https://codeload.github.com/dkhamsing/awesome_bot/tar.gz/master -O /tmp/temp.tar.gz
114
- - tar -xvf /tmp/temp.tar.gz
115
- - export PATH=$PATH:$PWD/awesome_bot-master/bin/
116
- - cd awesome_bot-master
117
- - bundle install
118
- script:
119
- - awesome_bot ../README.md
113
+ - gem install awesome_bot
114
+ script:
115
+ - awesome_bot README.md
120
116
  ```
121
117
 
122
118
  ## Credits
@@ -0,0 +1,3 @@
1
+ https://github.com ok
2
+ http://google.com redirect
3
+ http://localhost:11029 bad
@@ -13,7 +13,7 @@ module AwesomeBot
13
13
  def check(content, white_listed = nil, skip_dupe = false, verbose = false)
14
14
  dupe_success = skip_dupe
15
15
 
16
- puts '> Will not check for duplicate links' if skip_dupe && verbose
16
+ puts '> Will allow duplicate links' if skip_dupe && verbose
17
17
 
18
18
  white_listing = !white_listed.nil?
19
19
  puts "> White list: #{white_listed.join ', '}" if white_listing && verbose
@@ -34,7 +34,9 @@ module AwesomeBot
34
34
 
35
35
  print 'Checking URLs: ' if verbose && (links.count > 0)
36
36
  statuses =
37
- statuses links.uniq, NUMBER_OF_THREADS, verbose, STATUS_OK, STATUS_OTHER
37
+ statuses(links.uniq, NUMBER_OF_THREADS) do |s|
38
+ print(s == 200 ? STATUS_OK : STATUS_OTHER) if verbose
39
+ end
38
40
  puts '' if verbose
39
41
 
40
42
  statuses_issues = statuses.select { |x| x['status'] != 200 }
@@ -58,7 +60,7 @@ module AwesomeBot
58
60
  puts " All OK #{STATUS_OK}"
59
61
  else
60
62
  statuses_issues.each_with_index do |x, k|
61
- puts " #{k + 1}. #{x['status']} #{x['url']} "
63
+ puts " #{k + 1}. #{x['status']}: #{x['url']} "
62
64
  end
63
65
  end
64
66
 
@@ -4,17 +4,28 @@ module AwesomeBot
4
4
  require 'parallel'
5
5
 
6
6
  class << self
7
- def net_status(url)
7
+ def net_head_status(url)
8
+ Faraday.head(url).status
9
+ end
10
+
11
+ def net_get_status(url)
8
12
  Faraday.get(url).status
9
13
  end
10
14
 
11
- def statuses(links, threads, verbose, status_ok, status_other)
15
+ def net_status(url, head)
16
+ head ? net_head_status(url) : net_get_status(url)
17
+ end
18
+
19
+ def statuses(links, threads, head = false)
12
20
  statuses = []
13
21
  Parallel.each(links, in_threads: threads) do |u|
14
- status = net_status u
15
-
16
- print(status == 200 ? status_ok : status_other) if verbose
22
+ begin
23
+ status = net_status u, head
24
+ rescue => e
25
+ status = e
26
+ end
17
27
 
28
+ yield status, u
18
29
  statuses.push('url' => u, 'status' => status)
19
30
  end # Parallel
20
31
 
@@ -5,5 +5,5 @@ module AwesomeBot
5
5
  'Great for "awesome" projects.'
6
6
  PROJECT_URL = 'https://github.com/dkhamsing/awesome_bot'
7
7
 
8
- VERSION = '1.0.0'
8
+ VERSION = '1.1.0'
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awesome_bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Khamsing
@@ -82,6 +82,7 @@ files:
82
82
  - README.md
83
83
  - Rakefile
84
84
  - awesome_bot.gemspec
85
+ - bin/assets/test-bad-link
85
86
  - bin/assets/test-dupe
86
87
  - bin/assets/test-link-issue
87
88
  - bin/assets/test-no-dupes