seo_report 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0a0fa771b74ecf5037cc397b72df2e54bc651566
4
- data.tar.gz: 3819ea29b3f5d13986927d1a33e57fcb95967b28
3
+ metadata.gz: c93527848fb421a0afa93d0a2776433d5fac964d
4
+ data.tar.gz: 1eb31dc4447df2f7502f57208999ec0bc408c759
5
5
  SHA512:
6
- metadata.gz: d8b6a81345d083b7aaacc45986b0568644ae7f0f079ae4a4f6d73c68b576bf6fd5dd5fe1beafae2a8d006dc7b5f9b00fc330011aec169abec90cc45ffef4a393
7
- data.tar.gz: cd899d9827fc44b60836846406bebf1a93e7e9431fad5d2e31b275a5315a2efe491d6012246ba0cf93e799e21b8dbbc138bd4d6ced69f933c65092d76b52b2e1
6
+ metadata.gz: 0813918a25958b5d67c16cd0ffef4b3274bfcf9f6ad61e97ac520a96aedb6b322be2fdcfcc51b4c2cc0e277867c43f1ea7f4a51a5865d3ac89a5b4cd88d4edec
7
+ data.tar.gz: e7240e062955eeb06985cf93bca25c9c87e30805eae910ba358ff3c403ed457f3303e17d01e0bd865d4f9b392fc0602cba59fe6620a5dbb94bab071f00c94709
data/CHANGELOG.md ADDED
@@ -0,0 +1,46 @@
1
+ # Change Log
2
+
3
+ This change log contains information about the changes introduced as part of
4
+ specific releases. It adheres to the guidelines outlined by
5
+ [keepachangelog](http://keepachangelog.com/en/0.3.0/).
6
+
7
+ ## [unreleased]
8
+
9
+ ## [0.1.3] — 2016-08-14
10
+ ### Added
11
+ - Provide error message, without internal stacktrace information when the
12
+ command fails for unrecoverable reasons. Also introduces the
13
+ `SEO_REPORT_DEBUG` environment variable in order to show the stacktrace if
14
+ failure occurs, for... well debugging.
15
+ - Add error-integration to json/internal-struct for microdata. This allows the
16
+ recognition and handling of errors regarding microdata in the document.
17
+ - Specify minimum required ruby-version of **2.0.0**. It wouldn't really have
18
+ worked with anything less than /1.9.3/ before, but specifying it exactly makes
19
+ it easier to test for and to adhere to.
20
+ - The starts of a real test-suite. Currrently there are only specs for the main
21
+ extractions, meaning SEO (canonical and robots meta) and HEAD (title and meta
22
+ description). But the start has been made and the test suite will grow over
23
+ the next releases up to 0.2.0, at which point there should be at least an 85%
24
+ coverage.
25
+ ### Fixed
26
+ - Don't fail as easily when parsing microdata information. Seeing as this a
27
+ reporting-tool, that should also display information whether something is
28
+ valid (or *ok*) or not, we need to handle most errors in the html-document
29
+ gracefully in order to live to report about it.
30
+
31
+ ## [0.1.2] — 2016-08-10
32
+ ### Added
33
+ - Always send an appropriate User-Agent: `seo-report/0.1.2 Net::HTTP`.
34
+ `Net::HTTP` is used as the underlying library to perform http-requests, which
35
+ is why it is listed. However the actual user-agent is seo-report itself. The
36
+ number specifies the version of seo-report that was used to perform the
37
+ request.
38
+
39
+ ### Changed
40
+ - Handle path-only redirects and mark them as warnings.
41
+ While they are supported they don't represent a full URL, which
42
+ is what is supposed to be present in the `LOCATION` header.
43
+
44
+ ## [0.1.1] — 2016-08-07
45
+ This marks the first release of the seo_report gem, which provides the
46
+ `seo-report` binary. This software is licensed under LGPL-3.0.
data/README.md CHANGED
@@ -44,6 +44,13 @@ Or install it yourself as:
44
44
  example [jq](https://stedolan.github.io/jq/)). Be aware that the json
45
45
  format is currently not set in stone. It is most likely to change until
46
46
  at least version *0.2.0* is reached.
47
+
48
+ ### environment variables
49
+
50
+ Usually `seo-report` will in the case of an unrecoverable error, just provide
51
+ a message and bug out. If you are a developer, or want to file an issue, you
52
+ can run the command with `SEO_REPORT_DEBUG=1` set, which will provide
53
+ backtrace information instead.
47
54
 
48
55
  ## development
49
56
 
@@ -5,6 +5,7 @@ module SeoReport
5
5
  title = doc.xpath('//head/title').text
6
6
  description = doc.xpath('//head/meta[@name="description"]').
7
7
  map { |node| node.attr("content") }
8
+ title = nil if title.empty?
8
9
  {
9
10
  title: title,
10
11
  description: unarray(description),
@@ -12,10 +12,22 @@ module SeoReport::Extractions
12
12
  end
13
13
 
14
14
  def extract!
15
- document.at_xpath('/html/body').children.each do |child|
16
- process(child)
15
+ elements.each { |child| process(child) }
16
+ {
17
+ microdata: {
18
+ elements: result_set,
19
+ errors: errors,
20
+ }
21
+ }
22
+ end
23
+
24
+ def elements
25
+ body = document.at_xpath('/html/body')
26
+ if body
27
+ body.children
28
+ else
29
+ []
17
30
  end
18
- {microdata: result_set}
19
31
  end
20
32
 
21
33
  protected
@@ -50,21 +62,18 @@ module SeoReport::Extractions
50
62
  end
51
63
 
52
64
  def provide_data_for_itemprop(element)
53
- data =
54
- if element.name == "meta"
55
- element["content"]
56
- elsif %w(audio embed iframe img source track video).include?(element.name)
57
- element["src"]
58
- elsif %w(a area link).include?(element.name)
59
- element["href"]
60
- elsif element.name == "object"
61
- element["data"]
62
- elsif %w(data meter).include?(element.name)
63
- element["value"]
64
- else
65
- element.text
66
- end
67
- current_scope[element["itemprop"]] = data
65
+ data = microdata_itemprop_value(element)
66
+ if current_scope
67
+ current_scope[element["itemprop"]] = data
68
+ else
69
+ error = {
70
+ tag: element.name,
71
+ itemprop: element["itemprop"],
72
+ value: data,
73
+ }
74
+ error.merge!(id: element["id"]) if element["id"]
75
+ (errors[:scopeless_elements] ||= []) << error
76
+ end
68
77
  end
69
78
 
70
79
  def push_scope(element)
@@ -93,6 +102,10 @@ module SeoReport::Extractions
93
102
  @result_set ||= []
94
103
  end
95
104
 
105
+ def errors
106
+ @errors ||= {}
107
+ end
108
+
96
109
  def microdata_element?(element)
97
110
  %w(itemscope itemtype itemprop).
98
111
  any? { |attr| element.has_attribute?(attr) }
@@ -105,6 +118,22 @@ module SeoReport::Extractions
105
118
  def microdata_prop?(element)
106
119
  element.has_attribute?("itemprop")
107
120
  end
121
+
122
+ def microdata_itemprop_value(element)
123
+ if element.name == "meta"
124
+ element["content"]
125
+ elsif %w(audio embed iframe img source track video).include?(element.name)
126
+ element["src"]
127
+ elsif %w(a area link).include?(element.name)
128
+ element["href"]
129
+ elsif element.name == "object"
130
+ element["data"]
131
+ elsif %w(data meter).include?(element.name)
132
+ element["value"]
133
+ else
134
+ element.text
135
+ end
136
+ end
108
137
  end
109
138
 
110
139
  SeoReport::Report.register_extraction(:html, Microdata, :extract_microdata)
@@ -11,7 +11,7 @@ module SeoReport
11
11
  end
12
12
 
13
13
  def self.extractions
14
- @extractions ||= Hash.new([])
14
+ @extractions ||= {}
15
15
  end
16
16
 
17
17
  def initialize(start_url)
@@ -24,10 +24,8 @@ module SeoReport
24
24
 
25
25
  protected
26
26
  def generate_report
27
- chain = RequestChain.new(start_url)
28
- chain.perform
29
27
  {
30
- requests: chain.request_chain.map do |request|
28
+ requests: request_chain.request_chain.map do |request|
31
29
  {
32
30
  request_url: request.url.to_s,
33
31
  response_code: request.response.code.to_i
@@ -36,6 +34,14 @@ module SeoReport
36
34
  }
37
35
  end
38
36
 
37
+ def request_chain
38
+ @request_chain ||= build_request_chain
39
+ end
40
+
41
+ def build_request_chain
42
+ RequestChain.new(start_url).tap(&:perform)
43
+ end
44
+
39
45
  def generate_html_report(request)
40
46
  if request.response.is_a?(Net::HTTPOK)
41
47
  doc = Nokogiri::HTML(request.response.body)
@@ -50,7 +56,7 @@ module SeoReport
50
56
  end
51
57
 
52
58
  def content_through_extractions(base, document, type: :html)
53
- self.class.extractions[type].reduce(base) do |current, method_name|
59
+ self.class.extractions.fetch(type, []).reduce(base) do |current, method_name|
54
60
  current.merge(send(method_name, document))
55
61
  end
56
62
  end
@@ -11,6 +11,13 @@ module SeoReport::Representation
11
11
  report = SeoReport::Report.new(url)
12
12
  report.produce
13
13
  new(report).represent
14
+ rescue StandardError => _error
15
+ debug = ENV["SEO_REPORT_DEBUG"]
16
+ if debug.to_i > 0
17
+ raise
18
+ else
19
+ abort("-- Sorry, something went wrong when creating the report.")
20
+ end
14
21
  end
15
22
 
16
23
  def initialize(report)
@@ -1,3 +1,3 @@
1
1
  module SeoReport
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
data/seo_report.gemspec CHANGED
@@ -19,11 +19,14 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
+ spec.required_ruby_version = '>= 2.0.0'
23
+
22
24
  spec.add_dependency "nokogiri", "~> 1.6", ">= 1.6.8"
23
25
  spec.add_dependency "json", "~> 2.0", ">= 2.0.1"
24
26
 
25
27
  spec.add_development_dependency "bundler", "~> 1.10"
26
28
  spec.add_development_dependency "rake", "~> 10.0"
27
29
  spec.add_development_dependency "rspec", "~> 3.5"
30
+ spec.add_development_dependency "webmock", "~> 2.1"
28
31
  spec.add_development_dependency "pry", "~> 0.10"
29
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seo_report
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Reddehase
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-10 00:00:00.000000000 Z
11
+ date: 2016-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -92,6 +92,20 @@ dependencies:
92
92
  - - "~>"
93
93
  - !ruby/object:Gem::Version
94
94
  version: '3.5'
95
+ - !ruby/object:Gem::Dependency
96
+ name: webmock
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: '2.1'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - "~>"
107
+ - !ruby/object:Gem::Version
108
+ version: '2.1'
95
109
  - !ruby/object:Gem::Dependency
96
110
  name: pry
97
111
  requirement: !ruby/object:Gem::Requirement
@@ -118,6 +132,7 @@ files:
118
132
  - ".gitignore"
119
133
  - ".rspec"
120
134
  - ".travis.yml"
135
+ - CHANGELOG.md
121
136
  - Gemfile
122
137
  - LICENSE
123
138
  - README.md
@@ -153,7 +168,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
153
168
  requirements:
154
169
  - - ">="
155
170
  - !ruby/object:Gem::Version
156
- version: '0'
171
+ version: 2.0.0
157
172
  required_rubygems_version: !ruby/object:Gem::Requirement
158
173
  requirements:
159
174
  - - ">="