awesome_bot 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/CHANGELOG.md +7 -0
- data/README.md +3 -4
- data/lib/awesome_bot/check.rb +28 -55
- data/lib/awesome_bot/cli.rb +38 -2
- data/lib/awesome_bot/log.rb +17 -0
- data/lib/awesome_bot/result.rb +44 -0
- data/lib/awesome_bot/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c6768985f4950e9e02cd32463e1f160b9dc0900
|
4
|
+
data.tar.gz: b32f892d1dcbb164b14a91a860000c39dd23cd44
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 758801b59a894c8f59f6b11238b7b73e302202a32991b924d9c20bc884a0355197c5a969454e731e8c5559df2b109837cb66f5dcd319e6e1706add98ee1c6355
|
7
|
+
data.tar.gz: 1d5ba3c19898eae9e252bdcc2344798f5af89400d0f7c79f528b86eed88f16e9fe4b573830dbe5ad95b296d3dbc819a41f79635a1b453c7019f36416fbbce779
|
data/.travis.yml
CHANGED
@@ -8,4 +8,4 @@ script:
|
|
8
8
|
- awesome_bot bin/assets/test-no-issues
|
9
9
|
- awesome_bot bin/assets/test-no-links
|
10
10
|
- awesome_bot bin/assets/test-dupe --allow-dupe
|
11
|
-
- awesome_bot README.md --allow-dupe --white-list gph.is,bot.svg,codeload,badge
|
11
|
+
- awesome_bot README.md --allow-dupe --white-list gph.is,bot.svg,codeload,badge,rubydoc
|
data/CHANGELOG.md
CHANGED
@@ -20,6 +20,13 @@
|
|
20
20
|
- add head option when getting statuses
|
21
21
|
- [cli] improve output for `--allow-dupe`
|
22
22
|
|
23
|
+
# 1.2.0
|
24
|
+
|
25
|
+
- move some logic from check to cli
|
26
|
+
- output status for white listed links
|
27
|
+
- use `result`
|
28
|
+
- use `logger`
|
29
|
+
|
23
30
|
## Contact
|
24
31
|
|
25
32
|
- [github.com/dkhamsing](https://github.com/dkhamsing)
|
data/README.md
CHANGED
@@ -33,12 +33,11 @@ irb(main):001:0> require 'awesome_bot'
|
|
33
33
|
irb(main):002:0> c = File.read 'README.md'
|
34
34
|
=> "..."
|
35
35
|
irb(main):003:0> AwesomeBot.check c
|
36
|
-
=>
|
37
|
-
#
|
38
|
-
# otherwise returning true
|
36
|
+
=> #<AwesomeBot::Result:0x007fdde39f4408 @links=...>
|
37
|
+
# AwesomeBot Result with success, statuses_issues, dupes and more
|
39
38
|
```
|
40
39
|
|
41
|
-
More information at [rubydoc](http://www.rubydoc.info/gems/awesome_bot
|
40
|
+
More information at [rubydoc](http://www.rubydoc.info/gems/awesome_bot).
|
42
41
|
|
43
42
|
### Command Line
|
44
43
|
|
data/lib/awesome_bot/check.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'awesome_bot/links'
|
2
|
+
require 'awesome_bot/log'
|
3
|
+
require 'awesome_bot/result'
|
2
4
|
require 'awesome_bot/statuses'
|
3
|
-
require 'awesome_bot/white_list'
|
4
5
|
|
5
6
|
# Check links
|
6
7
|
module AwesomeBot
|
@@ -10,71 +11,43 @@ module AwesomeBot
|
|
10
11
|
STATUS_OTHER = 'x'
|
11
12
|
|
12
13
|
class << self
|
13
|
-
def check(content, white_listed = nil, skip_dupe = false,
|
14
|
-
|
14
|
+
def check(content, white_listed = nil, skip_dupe = false, log = Log.new)
|
15
|
+
log.add '> Will allow duplicate links' if skip_dupe
|
15
16
|
|
16
|
-
|
17
|
+
temp = links_filter(links_find(content))
|
17
18
|
|
18
|
-
|
19
|
-
|
19
|
+
r = Result.new(temp, white_listed)
|
20
|
+
r.skip_dupe = skip_dupe
|
20
21
|
|
21
|
-
|
22
|
+
log.add "> White list: #{white_listed.join ', '}" if r.white_listing
|
22
23
|
|
23
|
-
|
24
|
-
rejected, links = links.partition { |u| white_list white_listed, u }
|
25
|
-
end
|
26
|
-
|
27
|
-
if verbose
|
28
|
-
print "Links found: #{links.count}"
|
29
|
-
print ", #{rejected.count} white listed" if white_listing
|
30
|
-
print ", #{links.uniq.count} unique" if links.count != links.uniq.count
|
31
|
-
puts ''
|
32
|
-
links.uniq.each_with_index { |u, j| puts " #{j + 1}. #{u}" }
|
33
|
-
end
|
34
|
-
|
35
|
-
print 'Checking URLs: ' if verbose && (links.count > 0)
|
36
|
-
statuses =
|
37
|
-
statuses(links.uniq, NUMBER_OF_THREADS) do |s|
|
38
|
-
print(s == 200 ? STATUS_OK : STATUS_OTHER) if verbose
|
39
|
-
end
|
40
|
-
puts '' if verbose
|
41
|
-
|
42
|
-
statuses_issues = statuses.select { |x| x['status'] != 200 }
|
43
|
-
links_success = statuses_issues.count == 0
|
24
|
+
r.dupes = r.links.select { |e| r.links.count(e) > 1 } unless skip_dupe
|
44
25
|
|
26
|
+
log.addp "Links found: #{r.links.count}"
|
27
|
+
log.addp ", #{r.rejected.count} white listed" if r.white_listing
|
45
28
|
unless skip_dupe
|
46
|
-
|
47
|
-
dupes = links.select { |e| links.count(e) > 1 }
|
48
|
-
end
|
49
|
-
|
50
|
-
if links_success && dupe_success
|
51
|
-
puts 'No issues :-)' if verbose
|
52
|
-
return true
|
29
|
+
log.addp ", #{r.links.uniq.count} unique" if r.dupes.count > 0
|
53
30
|
end
|
31
|
+
log.add ''
|
32
|
+
r.links.uniq.each_with_index { |u, j| log.add " #{j + 1}. #{u}" }
|
54
33
|
|
55
|
-
if
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
if links_success
|
60
|
-
puts " All OK #{STATUS_OK}"
|
61
|
-
else
|
62
|
-
statuses_issues.each_with_index do |x, k|
|
63
|
-
puts " #{k + 1}. #{x['status']}: #{x['url']} "
|
64
|
-
end
|
34
|
+
log.addp 'Checking URLs: ' if r.links.count > 0
|
35
|
+
r.status =
|
36
|
+
statuses(r.links.uniq, NUMBER_OF_THREADS) do |s|
|
37
|
+
log.addp(s == 200 ? STATUS_OK : STATUS_OTHER)
|
65
38
|
end
|
39
|
+
log.add ''
|
40
|
+
|
41
|
+
return r if !r.white_listing || (r.rejected.count > 0)
|
66
42
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
else
|
72
|
-
dupes.uniq.each_with_index { |d, m| puts " #{m + 1}. #{d}" }
|
73
|
-
end
|
43
|
+
log.addp 'Checking white listed URLs: '
|
44
|
+
r.white_listed =
|
45
|
+
statuses(r.rejected.uniq, NUMBER_OF_THREADS, true) do |s|
|
46
|
+
log.addp(s == 200 ? STATUS_OK : STATUS_OTHER)
|
74
47
|
end
|
75
|
-
|
48
|
+
log.add ''
|
76
49
|
|
77
|
-
|
78
|
-
end #
|
50
|
+
r
|
51
|
+
end # check
|
79
52
|
end # class
|
80
53
|
end
|
data/lib/awesome_bot/cli.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'awesome_bot/check'
|
2
|
+
require 'awesome_bot/log'
|
3
|
+
require 'awesome_bot/result'
|
1
4
|
require 'awesome_bot/version'
|
2
5
|
|
3
6
|
# Command line interface
|
@@ -43,9 +46,42 @@ module AwesomeBot
|
|
43
46
|
exit 1
|
44
47
|
end
|
45
48
|
|
46
|
-
|
49
|
+
log = Log.new(true)
|
50
|
+
r = check(content, white_listed, skip_dupe, log)
|
47
51
|
|
48
|
-
|
52
|
+
unless r.white_listed.nil?
|
53
|
+
puts "\n> White listed:"
|
54
|
+
r.white_listed.each_with_index do |x, k|
|
55
|
+
puts " #{k + 1}. #{x['status']}: #{x['url']} "
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
if r.success == true
|
60
|
+
puts 'No issues :-)'
|
61
|
+
# exit ?
|
62
|
+
else
|
63
|
+
puts "\nIssues :-("
|
64
|
+
|
65
|
+
print "> Links \n"
|
66
|
+
if r.success_links
|
67
|
+
puts " All OK #{STATUS_OK}"
|
68
|
+
else
|
69
|
+
r.statuses_issues.each_with_index do |x, k|
|
70
|
+
puts " #{k + 1}. #{x['status']}: #{x['url']} "
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
unless skip_dupe
|
75
|
+
print "> Dupes \n"
|
76
|
+
if r.success_dupe
|
77
|
+
puts " None #{STATUS_OK}"
|
78
|
+
else
|
79
|
+
r.dupes.uniq.each_with_index { |d, m| puts " #{m + 1}. #{d}" }
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
exit 1
|
84
|
+
end
|
49
85
|
end
|
50
86
|
end # class
|
51
87
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'awesome_bot/white_list'
|
2
|
+
|
3
|
+
# Result
|
4
|
+
module AwesomeBot
|
5
|
+
# Result
|
6
|
+
class Result
|
7
|
+
attr_accessor :dupes
|
8
|
+
attr_accessor :skip_dupe
|
9
|
+
attr_accessor :status
|
10
|
+
attr_accessor :white_listed
|
11
|
+
|
12
|
+
attr_reader :rejected
|
13
|
+
attr_reader :links
|
14
|
+
|
15
|
+
def initialize(links, white_list_from_cli)
|
16
|
+
@links = links
|
17
|
+
@w = white_list_from_cli
|
18
|
+
|
19
|
+
return if @w.nil?
|
20
|
+
@rejected, @links = links.partition { |u| AwesomeBot.white_list @w, u }
|
21
|
+
end
|
22
|
+
|
23
|
+
def statuses_issues
|
24
|
+
status.select { |x| x['status'] != 200 }
|
25
|
+
end
|
26
|
+
|
27
|
+
def success
|
28
|
+
success_dupe && success_links
|
29
|
+
end
|
30
|
+
|
31
|
+
def success_dupe
|
32
|
+
return true if skip_dupe
|
33
|
+
links.uniq.count == links.count
|
34
|
+
end
|
35
|
+
|
36
|
+
def success_links
|
37
|
+
statuses_issues.count == 0
|
38
|
+
end
|
39
|
+
|
40
|
+
def white_listing
|
41
|
+
!@w.nil?
|
42
|
+
end
|
43
|
+
end # class
|
44
|
+
end
|
data/lib/awesome_bot/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: awesome_bot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Khamsing
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -95,6 +95,8 @@ files:
|
|
95
95
|
- lib/awesome_bot/check.rb
|
96
96
|
- lib/awesome_bot/cli.rb
|
97
97
|
- lib/awesome_bot/links.rb
|
98
|
+
- lib/awesome_bot/log.rb
|
99
|
+
- lib/awesome_bot/result.rb
|
98
100
|
- lib/awesome_bot/statuses.rb
|
99
101
|
- lib/awesome_bot/version.rb
|
100
102
|
- lib/awesome_bot/white_list.rb
|