blinkr 0.2.9 → 0.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.
data/lib/blinkr/report.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'slim'
2
2
  require 'ostruct'
3
+ require 'blinkr/error'
3
4
 
4
5
  module Blinkr
5
6
  class Report
@@ -17,31 +18,33 @@ module Blinkr
17
18
  end
18
19
 
19
20
  def render
20
- @context.severities = {}
21
- @context.categories = {}
22
- @context.types = {}
23
- @context.pages.each do |url, page|
24
- page.max_severity = 'success'
21
+ @context.pages.delete_if { |_, page| page.errors.empty? }
22
+ @context.total = 0
23
+ @context.severity = {}
24
+ @context.category = {}
25
+ @context.type = {}
26
+ @context.pages.each do |_, page|
27
+ page.max_severity = ::Blinkr::SEVERITY.first # :success
25
28
  page.errors.each do |error|
26
- raise "#{error.severity} not a valid severity. Must be one of #{SEVERITY.join(',')}" unless SEVERITY.include? error.severity
29
+ raise "#{error.severity} not a valid severity. Must be one of #{::Blinkr::SEVERITY.join(',')}" unless ::Blinkr::SEVERITY.include? error.severity
27
30
  raise "#{error.category} must be specified." if error.category.nil?
28
- @context.severities[error.severity] ||= OpenStruct.new({ :id => error.severity, :count => 0 })
29
- @context.severities[error.severity].count += 1
30
- page.max_severity = error.severity if SEVERITY.index(error.severity) > SEVERITY.index(page.max_severity)
31
- @context.categories[error.category] ||= OpenStruct.new({ :id => @context.categories.length, :count => 0, :severities => Hash.new(0), :types => {} })
32
- @context.categories[error.category].severities[error.severity] += 1
33
- @context.categories[error.category].types[error.type] ||= OpenStruct.new({ :id => @context.categories[error.category].types.length, :count => 0, :severities => Hash.new(0) })
34
- @context.categories[error.category].types[error.type].severities[error.severity] += 1
31
+ @context.total += 1
32
+ @context.severity[error.severity] ||= OpenStruct.new({:count => 0})
33
+ @context.severity[error.severity].count += 1
34
+ page.max_severity = error.severity if ::Blinkr::SEVERITY.index(error.severity) > ::Blinkr::SEVERITY.index(page.max_severity)
35
+ @context.category[error.category] ||= OpenStruct.new({:count => 0})
36
+ @context.category[error.category].count += 1
37
+ @context.type[error.type] ||= OpenStruct.new({:count => 0})
38
+ @context.type[error.type].count += 1
35
39
  end
36
40
  end
37
- @context.error_count = @context.severities.reduce(0){ |sum, (severity, metadata)| sum += metadata.count }
38
- File.open(@config.report, 'w') { |file| file.write(Slim::Template.new(TMPL).render(OpenStruct.new({ :blinkr => @context, :engine => @engine }))) }
41
+ File.open(@config.report, 'w') do |file|
42
+ file.write(Slim::Template.new(TMPL).render(OpenStruct.new({:blinkr => @context, :engine => @engine,
43
+ :errors => @context.to_json})))
44
+ end
45
+
39
46
  puts "Wrote report to #{@config.report}" if @config.verbose
40
47
  end
41
48
 
42
- private
43
-
44
- SEVERITY = ['success', 'info', 'warning', 'danger']
45
-
46
49
  end
47
50
  end
@@ -1,16 +1,17 @@
1
+ require 'open-uri'
1
2
  module Blinkr
2
3
  module Sitemap
3
4
 
4
5
  def sitemap_locations
5
- open.css('loc').collect { |loc| loc.content }
6
+ open_sitemap.css('loc').collect { |loc| loc.content }
6
7
  end
7
8
 
8
9
  private
9
-
10
- def open
10
+
11
+ def open_sitemap
11
12
  puts "Loading sitemap from #{@config.sitemap}"
12
13
  if @config.sitemap =~ URI::regexp
13
- Nokogiri::XML(Typhoeus.get(@config.sitemap, followlocation: true).body)
14
+ Nokogiri::XML(open(@config.sitemap).read)
14
15
  else
15
16
  Nokogiri::XML(File.open(@config.sitemap))
16
17
  end
@@ -1,6 +1,3 @@
1
- require 'typhoeus/request'
2
- require 'typhoeus/response'
3
- require 'typhoeus/hydra'
4
1
  require 'typhoeus'
5
2
  require 'blinkr/cache'
6
3
  require 'blinkr/http_utils'
@@ -11,24 +8,30 @@ module Blinkr
11
8
 
12
9
  attr_reader :count, :hydra
13
10
 
14
- def initialize config, context
11
+ def initialize(config, context)
15
12
  @config = config.validate
16
- @hydra = Typhoeus::Hydra.new(max_concurrency: 200)
13
+ # Configure Typhoeus a bit
14
+ Typhoeus::Config.verbose = true if config.vverbose
15
+ Typhoeus::Config.cache = Blinkr::Cache.new
16
+ @hydra = Typhoeus::Hydra.new(:maxconnects => (@config.maxconnects || 30),
17
+ :max_total_connections => (@config.maxconnects || 30),
18
+ :max_concurrency => (@config.maxconnects || 30))
17
19
  @count = 0
18
20
  @context = context
19
21
  end
20
22
 
21
- def process_all urls, limit, &block
23
+ def process_all(urls, limit, opts = {}, &block)
22
24
  urls.each do |url|
23
- process url, limit, &block
25
+ process url, limit, opts, &block
24
26
  end
27
+ @hydra.run
25
28
  end
26
29
 
27
- def process url, limit, &block
28
- _process url, limit, limit, &block
30
+ def process(url, limit, opts = {}, &block)
31
+ _process url, limit, limit, opts, &block
29
32
  end
30
33
 
31
- def debug url
34
+ def debug(url)
32
35
  process(url, @config.max_retrys) do |resp|
33
36
  puts "\n++++++++++"
34
37
  puts "+ Blinkr +"
@@ -65,21 +68,21 @@ module Blinkr
65
68
 
66
69
  private
67
70
 
68
- def _process url, limit, max, &block
71
+ def _process(url, limit, max, opts = {}, &block)
69
72
  unless @config.skipped? url
70
73
  req = Typhoeus::Request.new(
71
- url,
72
- followlocation: true,
73
- verbose: @config.vverbose
74
+ url,
75
+ opts.merge(:followlocation => true)
74
76
  )
75
77
  req.on_complete do |resp|
76
78
  if retry? resp
77
- if limit > 1
79
+ if limit > 1
78
80
  puts "Loading #{url} via typhoeus (attempt #{max - limit + 2} of #{max})" if @config.verbose
79
81
  _process(url, limit - 1, max, &Proc.new)
80
82
  else
81
83
  puts "Loading #{url} via typhoeus failed" if @config.verbose
82
- response = Typhoeus::Response.new(code: 0, status_message: "Server timed out after #{max} retries", mock: true)
84
+ response = Typhoeus::Response.new(:code => 0, :status_message => "Server timed out after #{max} retries",
85
+ :mock => true)
83
86
  response.request = Typhoeus::Request.new(url)
84
87
  Typhoeus.stub(url).and_return(response)
85
88
  block.call response, nil, nil
@@ -1,4 +1,4 @@
1
1
  module Blinkr
2
- VERSION='0.2.9'
2
+ VERSION='0.3.0'
3
3
  end
4
4
 
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blinkr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pete Muir
8
+ - Jason Porter
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2015-02-12 00:00:00.000000000 Z
12
+ date: 2015-07-06 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: bundler
@@ -99,14 +100,12 @@ description: A broken page and link checker for websites. Optionally uses phanto
99
100
  page load errors.
100
101
  email:
101
102
  - pmuir@bleepbleep.org.uk
103
+ - lightguard.jp@gmail.com
102
104
  executables:
103
105
  - blinkr
104
106
  extensions: []
105
107
  extra_rdoc_files: []
106
108
  files:
107
- - ".gitignore"
108
- - ".ruby-gemset"
109
- - ".ruby-version"
110
109
  - Gemfile
111
110
  - LICENSE.txt
112
111
  - README.md
@@ -117,6 +116,7 @@ files:
117
116
  - lib/blinkr/cache.rb
118
117
  - lib/blinkr/config.rb
119
118
  - lib/blinkr/engine.rb
119
+ - lib/blinkr/error.rb
120
120
  - lib/blinkr/extensions/a_title.rb
121
121
  - lib/blinkr/extensions/empty_a_href.rb
122
122
  - lib/blinkr/extensions/img_alt.rb
@@ -127,7 +127,9 @@ files:
127
127
  - lib/blinkr/extensions/meta.rb
128
128
  - lib/blinkr/extensions/pipeline.rb
129
129
  - lib/blinkr/extensions/resources.rb
130
+ - lib/blinkr/hacks.rb
130
131
  - lib/blinkr/http_utils.rb
132
+ - lib/blinkr/manticore_wrapper.rb
131
133
  - lib/blinkr/phantomjs_wrapper.rb
132
134
  - lib/blinkr/report.html.slim
133
135
  - lib/blinkr/report.rb
@@ -147,7 +149,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
147
149
  requirements:
148
150
  - - "~>"
149
151
  - !ruby/object:Gem::Version
150
- version: '2.0'
152
+ version: '1.9'
151
153
  required_rubygems_version: !ruby/object:Gem::Requirement
152
154
  requirements:
153
155
  - - ">="
data/.gitignore DELETED
@@ -1,18 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
18
- *.swp
data/.ruby-gemset DELETED
@@ -1 +0,0 @@
1
- blink
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- ruby-2.1.2