awesome_bot 1.2.1 → 1.3.0
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 +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +43 -27
- data/lib/awesome_bot/check.rb +11 -2
- data/lib/awesome_bot/cli.rb +21 -7
- data/lib/awesome_bot/result.rb +9 -6
- data/lib/awesome_bot/statuses.rb +5 -2
- data/lib/awesome_bot/version.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 3b80a642954635c67e93c87aafb2524e0a89316d
         | 
| 4 | 
            +
              data.tar.gz: 6afbd8b1d0e1b219aea4345f0be7aec0df309a6a
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 074d3347f394c15e8c4d21e533bf66a2da153f97187e2ca1b10ca0fc63cb96d634444c3ddc3938ab4a2669415f1b0be55b67620f35ccfd26151f4c7214961675
         | 
| 7 | 
            +
              data.tar.gz: be54ae943b07eb0be805e8530b9b969bc244bf0a375338f1e8da29f22318ddaca6ef354d9d3b130428988740e8725f30fea89688e130096d770803a2c15a12f8
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -31,6 +31,12 @@ | |
| 31 31 |  | 
| 32 32 | 
             
            - correct logic for displaying white list status
         | 
| 33 33 |  | 
| 34 | 
            +
            # 1.3.0
         | 
| 35 | 
            +
             | 
| 36 | 
            +
            - add `--allow-redirect` option
         | 
| 37 | 
            +
            - output `→` as redirect status indicator
         | 
| 38 | 
            +
            - update error logic in statuses
         | 
| 39 | 
            +
             | 
| 34 40 | 
             
            ## Contact
         | 
| 35 41 |  | 
| 36 42 | 
             
            - [github.com/dkhamsing](https://github.com/dkhamsing)
         | 
    
        data/README.md
    CHANGED
    
    | @@ -32,39 +32,47 @@ irb(main):001:0> require 'awesome_bot' | |
| 32 32 | 
             
            => true
         | 
| 33 33 | 
             
            irb(main):002:0> c = File.read 'README.md'
         | 
| 34 34 | 
             
            => "..."
         | 
| 35 | 
            -
            irb(main):003:0> AwesomeBot.check c
         | 
| 35 | 
            +
            irb(main):003:0> r = AwesomeBot.check c
         | 
| 36 36 | 
             
            => #<AwesomeBot::Result:0x007fdde39f4408 @links=...>
         | 
| 37 37 | 
             
            # AwesomeBot Result with success, statuses_issues, dupes and more
         | 
| 38 | 
            +
            irb(main):004:0> puts r.success ? 'No errors' : ':-('
         | 
| 39 | 
            +
            :-(
         | 
| 38 40 | 
             
            ```
         | 
| 39 41 |  | 
| 40 42 | 
             
            More information at [rubydoc](http://www.rubydoc.info/gems/awesome_bot).
         | 
| 41 43 |  | 
| 42 44 | 
             
            ### Command Line
         | 
| 43 45 |  | 
| 44 | 
            -
                awesome_bot <file> [--allow-dupe] [--white-list item1,item2,..]
         | 
| 45 | 
            -
             | 
| 46 | 
            +
                awesome_bot <file> [--allow-dupe] [--allow-redirect] [--white-list item1,item2,..]
         | 
| 46 47 |  | 
| 47 48 | 
             
            ```shell
         | 
| 48 49 | 
             
            $ awesome_bot README.md
         | 
| 49 | 
            -
            Checking links in  | 
| 50 | 
            -
            Links found:  | 
| 50 | 
            +
            > Checking links in README.md
         | 
| 51 | 
            +
            Links found: 46, 14 unique
         | 
| 51 52 | 
             
              1. https://github.com/sindresorhus/awesome
         | 
| 52 53 | 
             
              2. http://i.giphy.com/12qq4Em3MVuwJW.gif
         | 
| 53 54 | 
             
              3. https://travis-ci.org/dkhamsing/awesome_bot.svg
         | 
| 54 55 | 
             
              4. https://travis-ci.org/dkhamsing/awesome_bot
         | 
| 55 | 
            -
              5. https:// | 
| 56 | 
            -
              6.  | 
| 57 | 
            -
              7.  | 
| 58 | 
            -
              8. https:// | 
| 59 | 
            -
              9.  | 
| 60 | 
            -
              10. https://github.com/dkhamsing | 
| 61 | 
            -
              11. https:// | 
| 62 | 
            -
             | 
| 56 | 
            +
              5. https://badge.fury.io/rb/awesome_bot.svg
         | 
| 57 | 
            +
              6. https://badge.fury.io/rb/awesome_bot
         | 
| 58 | 
            +
              7. http://www.rubydoc.info/gems/awesome_bot
         | 
| 59 | 
            +
              8. https://travis-ci.org/
         | 
| 60 | 
            +
              9. http://gph.is/1gU5itl
         | 
| 61 | 
            +
              10. https://github.com/dkhamsing
         | 
| 62 | 
            +
              11. https://twitter.com/dkhamsing
         | 
| 63 | 
            +
              12. https://github.com/dkhamsing/open-source-ios-apps/pull/159
         | 
| 64 | 
            +
              13. https://github.com/dkhamsing/open-source-ios-apps/blob/master/.travis.yml
         | 
| 65 | 
            +
              14. https://codeload.github.com/dkhamsing/awesome_bot/tar.gz/wip
         | 
| 66 | 
            +
            Checking URLs: ✓→→x→→✓✓✓✓x✓✓✓
         | 
| 63 67 |  | 
| 64 68 | 
             
            Issues :-(
         | 
| 65 69 | 
             
            > Links
         | 
| 66 | 
            -
             | 
| 67 | 
            -
             | 
| 70 | 
            +
            1. 302 https://badge.fury.io/rb/awesome_bot.svg
         | 
| 71 | 
            +
            2. 302 https://badge.fury.io/rb/awesome_bot
         | 
| 72 | 
            +
            3. 202 http://www.rubydoc.info/gems/awesome_bot
         | 
| 73 | 
            +
            4. 301 http://gph.is/1gU5itl
         | 
| 74 | 
            +
            5. 301 https://travis-ci.org/dkhamsing/awesome_bot.svg
         | 
| 75 | 
            +
            6. 404 https://codeload.github.com/dkhamsing/awesome_bot/tar.gz/wip
         | 
| 68 76 | 
             
            > Dupes
         | 
| 69 77 | 
             
              1. https://github.com/sindresorhus/awesome
         | 
| 70 78 | 
             
              2. http://i.giphy.com/12qq4Em3MVuwJW.gif
         | 
| @@ -80,21 +88,29 @@ Issues :-( | |
| 80 88 | 
             
            ```
         | 
| 81 89 |  | 
| 82 90 | 
             
            ```shell
         | 
| 83 | 
            -
            $ awesome_bot README.md --allow-dupe --white-list gph.is, | 
| 91 | 
            +
            $ awesome_bot README.md --allow-dupe --white-list fury,gph.is,rubydoc,travis,codeload
         | 
| 84 92 | 
             
            > Checking links in README.md
         | 
| 85 | 
            -
            > Will  | 
| 86 | 
            -
            > White list: gph.is,  | 
| 87 | 
            -
            Links found:  | 
| 93 | 
            +
            > Will allow duplicate links
         | 
| 94 | 
            +
            > White list: fury, gph.is, rubydoc, travis, codeload
         | 
| 95 | 
            +
            Links found: 20, 33 white listed
         | 
| 88 96 | 
             
              1. https://github.com/sindresorhus/awesome
         | 
| 89 97 | 
             
              2. http://i.giphy.com/12qq4Em3MVuwJW.gif
         | 
| 90 | 
            -
              3. https:// | 
| 91 | 
            -
              4. https:// | 
| 92 | 
            -
              5. https://github.com/dkhamsing
         | 
| 93 | 
            -
             | 
| 94 | 
            -
             | 
| 95 | 
            -
             | 
| 96 | 
            -
             | 
| 97 | 
            -
             | 
| 98 | 
            +
              3. https://github.com/dkhamsing
         | 
| 99 | 
            +
              4. https://twitter.com/dkhamsing
         | 
| 100 | 
            +
              5. https://github.com/dkhamsing/open-source-ios-apps/pull/159
         | 
| 101 | 
            +
            Checking URLs: ✓✓✓✓✓
         | 
| 102 | 
            +
            Checking white listed URLs: →x→→✓→✓x✓
         | 
| 103 | 
            +
             | 
| 104 | 
            +
            > White listed:
         | 
| 105 | 
            +
              1. 301: http://gph.is/1gU5itl
         | 
| 106 | 
            +
              2. 202: http://www.rubydoc.info/gems/awesome_bot
         | 
| 107 | 
            +
              3. 302: https://badge.fury.io/rb/awesome_bot
         | 
| 108 | 
            +
              4. 302: https://badge.fury.io/rb/awesome_bot.svg
         | 
| 109 | 
            +
              5. 200: https://travis-ci.org/dkhamsing/awesome_bot
         | 
| 110 | 
            +
              6. 301: https://travis-ci.org/dkhamsing/awesome_bot.svg
         | 
| 111 | 
            +
              7. 200: https://travis-ci.org/
         | 
| 112 | 
            +
              8. 404: https://codeload.github.com/dkhamsing/awesome_bot/tar.gz/wip
         | 
| 113 | 
            +
              9. 200: https://github.com/dkhamsing/open-source-ios-apps/blob/master/.travis.yml
         | 
| 98 114 | 
             
            No issues :-)
         | 
| 99 115 | 
             
            ```
         | 
| 100 116 |  | 
    
        data/lib/awesome_bot/check.rb
    CHANGED
    
    | @@ -9,6 +9,7 @@ module AwesomeBot | |
| 9 9 |  | 
| 10 10 | 
             
              STATUS_OK = '✓'
         | 
| 11 11 | 
             
              STATUS_OTHER = 'x'
         | 
| 12 | 
            +
              STATUS_REDIRECT = '→'  
         | 
| 12 13 |  | 
| 13 14 | 
             
              class << self
         | 
| 14 15 | 
             
                def check(content, white_listed = nil, skip_dupe = false, log = Log.new)
         | 
| @@ -34,7 +35,11 @@ module AwesomeBot | |
| 34 35 | 
             
                  log.addp 'Checking URLs: ' if r.links.count > 0
         | 
| 35 36 | 
             
                  r.status =
         | 
| 36 37 | 
             
                    statuses(r.links.uniq, NUMBER_OF_THREADS) do |s|
         | 
| 37 | 
            -
                       | 
| 38 | 
            +
                      if (s > 299) && (s < 400)
         | 
| 39 | 
            +
                        log.addp STATUS_REDIRECT
         | 
| 40 | 
            +
                      else
         | 
| 41 | 
            +
                        log.addp(s == 200 ? STATUS_OK : STATUS_OTHER)
         | 
| 42 | 
            +
                      end
         | 
| 38 43 | 
             
                    end
         | 
| 39 44 | 
             
                  log.add ''
         | 
| 40 45 |  | 
| @@ -43,7 +48,11 @@ module AwesomeBot | |
| 43 48 | 
             
                  log.addp 'Checking white listed URLs: '
         | 
| 44 49 | 
             
                  r.white_listed =
         | 
| 45 50 | 
             
                    statuses(r.rejected.uniq, NUMBER_OF_THREADS, true) do |s|
         | 
| 46 | 
            -
                       | 
| 51 | 
            +
                      if (s > 299) && (s < 400)
         | 
| 52 | 
            +
                        log.addp STATUS_REDIRECT
         | 
| 53 | 
            +
                      else
         | 
| 54 | 
            +
                        log.addp(s == 200 ? STATUS_OK : STATUS_OTHER)
         | 
| 55 | 
            +
                      end
         | 
| 47 56 | 
             
                    end
         | 
| 48 57 | 
             
                  log.add ''
         | 
| 49 58 |  | 
    
        data/lib/awesome_bot/cli.rb
    CHANGED
    
    | @@ -6,6 +6,7 @@ require 'awesome_bot/version' | |
| 6 6 | 
             
            # Command line interface
         | 
| 7 7 | 
             
            module AwesomeBot
         | 
| 8 8 | 
             
              OPTION_DUPE = 'allow-dupe'
         | 
| 9 | 
            +
              OPTION_REDIRECT = 'allow-redirect'
         | 
| 9 10 | 
             
              OPTION_WHITE_LIST = 'white-list'
         | 
| 10 11 |  | 
| 11 12 | 
             
              USAGE = "\t"
         | 
| @@ -13,14 +14,16 @@ module AwesomeBot | |
| 13 14 | 
             
              class << self
         | 
| 14 15 | 
             
                def cli
         | 
| 15 16 | 
             
                  option_d = "--#{OPTION_DUPE}"
         | 
| 17 | 
            +
                  option_r = "--#{OPTION_REDIRECT}"
         | 
| 16 18 | 
             
                  option_w = "--#{OPTION_WHITE_LIST}"
         | 
| 17 19 |  | 
| 18 20 | 
             
                  if ARGV.count == 0
         | 
| 19 | 
            -
                    puts "Usage: #{PROJECT} <file> [#{option_d}] "\
         | 
| 21 | 
            +
                    puts "Usage: #{PROJECT} <file> [#{option_d}] [#{option_r}] "\
         | 
| 20 22 | 
             
                         "[#{option_w} item1,item2,..]\n"\
         | 
| 21 23 | 
             
                         "#{USAGE} file \t\t Path to file \n"\
         | 
| 22 | 
            -
                         "#{USAGE} #{option_d} \t  | 
| 23 | 
            -
                         "#{USAGE} #{ | 
| 24 | 
            +
                         "#{USAGE} #{option_d} \t  Duplicates URLs are allowed URLs \n"\
         | 
| 25 | 
            +
                         "#{USAGE} #{option_r} Redirected URLs are allowed \n"\
         | 
| 26 | 
            +
                         "#{USAGE} #{option_w} \t  Comma separated URLs to white list \n"\
         | 
| 24 27 | 
             
                         "\nVersion #{VERSION}, see #{PROJECT_URL} for more information"
         | 
| 25 28 | 
             
                    exit
         | 
| 26 29 | 
             
                  end
         | 
| @@ -33,10 +36,15 @@ module AwesomeBot | |
| 33 36 |  | 
| 34 37 | 
             
                    skip_dupe = options.include? option_d
         | 
| 35 38 |  | 
| 39 | 
            +
                    allow_redirects = options.include? option_r
         | 
| 40 | 
            +
                    puts '> Will allow redirects' if allow_redirects == true
         | 
| 41 | 
            +
             | 
| 36 42 | 
             
                    if options.include? option_w
         | 
| 37 43 | 
             
                      i = options.find_index(option_w) + 1
         | 
| 38 44 | 
             
                      white_listed = options[i].split ','
         | 
| 39 45 | 
             
                    end
         | 
| 46 | 
            +
                  else
         | 
| 47 | 
            +
                    allow_redirects = false
         | 
| 40 48 | 
             
                  end
         | 
| 41 49 |  | 
| 42 50 | 
             
                  begin
         | 
| @@ -46,6 +54,7 @@ module AwesomeBot | |
| 46 54 | 
             
                    exit 1
         | 
| 47 55 | 
             
                  end
         | 
| 48 56 |  | 
| 57 | 
            +
             | 
| 49 58 | 
             
                  log = Log.new(true)
         | 
| 50 59 | 
             
                  r = check(content, white_listed, skip_dupe, log)
         | 
| 51 60 |  | 
| @@ -56,18 +65,23 @@ module AwesomeBot | |
| 56 65 | 
             
                    end
         | 
| 57 66 | 
             
                  end
         | 
| 58 67 |  | 
| 59 | 
            -
                  if r.success == true
         | 
| 68 | 
            +
                  if r.success(allow_redirects) == true
         | 
| 60 69 | 
             
                    puts 'No issues :-)'
         | 
| 61 70 | 
             
                    # exit ?
         | 
| 62 71 | 
             
                  else
         | 
| 63 72 | 
             
                    puts "\nIssues :-("
         | 
| 64 73 |  | 
| 65 74 | 
             
                    print "> Links \n"
         | 
| 66 | 
            -
                    if r.success_links
         | 
| 75 | 
            +
                    if r.success_links(allow_redirects)
         | 
| 67 76 | 
             
                      puts "  All OK #{STATUS_OK}"
         | 
| 68 77 | 
             
                    else
         | 
| 69 | 
            -
                      r.statuses_issues.each_with_index do |x, k|
         | 
| 70 | 
            -
                         | 
| 78 | 
            +
                      r.statuses_issues(allow_redirects).each_with_index do |x, k|
         | 
| 79 | 
            +
                        s = x['status']
         | 
| 80 | 
            +
                        print "#{k + 1}. "
         | 
| 81 | 
            +
                        print "#{s} " unless s == STATUS_ERROR
         | 
| 82 | 
            +
                        print "#{x['url']}"
         | 
| 83 | 
            +
                        print x['error'] if s == STATUS_ERROR
         | 
| 84 | 
            +
                        puts ''
         | 
| 71 85 | 
             
                      end
         | 
| 72 86 | 
             
                    end
         | 
| 73 87 |  | 
    
        data/lib/awesome_bot/result.rb
    CHANGED
    
    | @@ -20,12 +20,15 @@ module AwesomeBot | |
| 20 20 | 
             
                  @rejected, @links = links.partition { |u| AwesomeBot.white_list @w, u }
         | 
| 21 21 | 
             
                end
         | 
| 22 22 |  | 
| 23 | 
            -
                def statuses_issues
         | 
| 24 | 
            -
                  status.select { |x| x['status'] != 200 }
         | 
| 23 | 
            +
                def statuses_issues(allow_redirects = false)
         | 
| 24 | 
            +
                  s = status.select { |x| x['status'] != 200 }
         | 
| 25 | 
            +
                  return s if allow_redirects == false
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                  s.reject { |x| (x['status'] > 299) && (x['status'] < 400) }
         | 
| 25 28 | 
             
                end
         | 
| 26 29 |  | 
| 27 | 
            -
                def success
         | 
| 28 | 
            -
                  success_dupe && success_links
         | 
| 30 | 
            +
                def success(allow_redirects = false)
         | 
| 31 | 
            +
                  success_dupe && success_links(allow_redirects)
         | 
| 29 32 | 
             
                end
         | 
| 30 33 |  | 
| 31 34 | 
             
                def success_dupe
         | 
| @@ -33,8 +36,8 @@ module AwesomeBot | |
| 33 36 | 
             
                  links.uniq.count == links.count
         | 
| 34 37 | 
             
                end
         | 
| 35 38 |  | 
| 36 | 
            -
                def success_links
         | 
| 37 | 
            -
                  statuses_issues.count == 0
         | 
| 39 | 
            +
                def success_links(allow_redirects = false)
         | 
| 40 | 
            +
                  statuses_issues(allow_redirects).count == 0
         | 
| 38 41 | 
             
                end
         | 
| 39 42 |  | 
| 40 43 | 
             
                def white_listing
         | 
    
        data/lib/awesome_bot/statuses.rb
    CHANGED
    
    | @@ -3,6 +3,8 @@ module AwesomeBot | |
| 3 3 | 
             
              require 'faraday'
         | 
| 4 4 | 
             
              require 'parallel'
         | 
| 5 5 |  | 
| 6 | 
            +
              STATUS_ERROR = -1
         | 
| 7 | 
            +
             | 
| 6 8 | 
             
              class << self
         | 
| 7 9 | 
             
                def net_head_status(url)
         | 
| 8 10 | 
             
                  Faraday.head(url).status
         | 
| @@ -22,11 +24,12 @@ module AwesomeBot | |
| 22 24 | 
             
                    begin
         | 
| 23 25 | 
             
                      status = net_status u, head
         | 
| 24 26 | 
             
                    rescue => e
         | 
| 25 | 
            -
                      status =  | 
| 27 | 
            +
                      status = STATUS_ERROR
         | 
| 28 | 
            +
                      error = e
         | 
| 26 29 | 
             
                    end
         | 
| 27 30 |  | 
| 28 31 | 
             
                    yield status, u
         | 
| 29 | 
            -
                    statuses.push('url' => u, 'status' => status)
         | 
| 32 | 
            +
                    statuses.push('url' => u, 'status' => status, 'error' => error)
         | 
| 30 33 | 
             
                  end # Parallel
         | 
| 31 34 |  | 
| 32 35 | 
             
                  statuses
         | 
    
        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.3.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-14 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: faraday
         |