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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8feb264201072a97f70c9146f636d95bcd5fca77
4
- data.tar.gz: 5762b4ef3b0584cd155b87dd3ba81cb5347f6a1d
3
+ metadata.gz: 4c6768985f4950e9e02cd32463e1f160b9dc0900
4
+ data.tar.gz: b32f892d1dcbb164b14a91a860000c39dd23cd44
5
5
  SHA512:
6
- metadata.gz: 00f748d97bc39f0ad148288611ed8252dc0d1f242da3b948146a0cae7e3c373063fc9df67f14990dff622e9ae01b81934018a00b28931d2a425ac643d3df8dd1
7
- data.tar.gz: 023bad1bc68ee5b59915ac10cd2ccad6fe3d77626318b886fe8a1ad5c3da1bd51d1707020d2396165589e3efe54d725816b7d35706c66d734c94c3a790555840
6
+ metadata.gz: 758801b59a894c8f59f6b11238b7b73e302202a32991b924d9c20bc884a0355197c5a969454e731e8c5559df2b109837cb66f5dcd319e6e1706add98ee1c6355
7
+ data.tar.gz: 1d5ba3c19898eae9e252bdcc2344798f5af89400d0f7c79f528b86eed88f16e9fe4b573830dbe5ad95b296d3dbc819a41f79635a1b453c7019f36416fbbce779
@@ -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
@@ -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
- => [false, [{"url"=>"http://gph.is/1gU5itl", "status"=>301},..]
37
- # returning false, statuses and dupes if there are errors
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/1.1.0).
40
+ More information at [rubydoc](http://www.rubydoc.info/gems/awesome_bot).
42
41
 
43
42
  ### Command Line
44
43
 
@@ -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, verbose = false)
14
- dupe_success = skip_dupe
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
- puts '> Will allow duplicate links' if skip_dupe && verbose
17
+ temp = links_filter(links_find(content))
17
18
 
18
- white_listing = !white_listed.nil?
19
- puts "> White list: #{white_listed.join ', '}" if white_listing && verbose
19
+ r = Result.new(temp, white_listed)
20
+ r.skip_dupe = skip_dupe
20
21
 
21
- links = links_filter(links_find(content))
22
+ log.add "> White list: #{white_listed.join ', '}" if r.white_listing
22
23
 
23
- if white_listing
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
- dupe_success = links.uniq.count == links.count
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 verbose
56
- puts "\nIssues :-("
57
-
58
- print "> Links \n"
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
- unless skip_dupe
68
- print "> Dupes \n"
69
- if dupe_success
70
- puts " None #{STATUS_OK}"
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
- end # if verbose
48
+ log.add ''
76
49
 
77
- [false, statuses, dupes]
78
- end # run
50
+ r
51
+ end # check
79
52
  end # class
80
53
  end
@@ -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
- exit 1 unless check(content, white_listed, skip_dupe, true) == true
49
+ log = Log.new(true)
50
+ r = check(content, white_listed, skip_dupe, log)
47
51
 
48
- exit
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,17 @@
1
+ # Log
2
+ module AwesomeBot
3
+ # Log
4
+ class Log
5
+ def initialize(verbose = false)
6
+ @v = verbose
7
+ end
8
+
9
+ def add(message)
10
+ puts message if @v
11
+ end
12
+
13
+ def addp(message)
14
+ print message if @v
15
+ end
16
+ end # class
17
+ 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
@@ -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.1.0'
8
+ VERSION = '1.2.0'
9
9
  end
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.1.0
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-10 00:00:00.000000000 Z
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