link_thumbnailer 3.2.0 → 3.2.1

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: 9799bede3f23e3369ddafa4ddeb36c9436d7ee5d
4
- data.tar.gz: 484c6c008967be9cd3d813bac81dffde02c18bd7
3
+ metadata.gz: f99697da11cef790d10eddde8f79ad1dd4a2e1e6
4
+ data.tar.gz: c113e7b8c50dda3e4ead33dde327b0beec15435d
5
5
  SHA512:
6
- metadata.gz: 3c6a25faef22554a54a84a2ffbf0ee85babb1b088b5ed79d08e6550504f9e9853fa177cd730856cd1c3cb3d285dc1bf6a727cd89a85d410f00cf89023668d1de
7
- data.tar.gz: 10216dc920ce54195179337fc4034ba14413c833369a2e566e2b7aa5d118a5c7599df4673564ff7a57bc3558be3fa8d826e0c8f35058aba64e9544a13bc1d09d
6
+ metadata.gz: f4f15babf9656fa90eae2cd10c9634011e766f02319e8d80ed03bb47149e30770420c6e17b3d4b91488022b7df4c1ed1cbc2f41b7d5b850f55d514708aed74fa
7
+ data.tar.gz: 1572e848bf83ae6eba3bef808474b2ca466b13d8b6ce467c73f0768cd0f57247083400a9a05823cd247a45fe5765438ae242bb2731804c2a6b2e64391896c554
data/.travis.yml CHANGED
@@ -1,6 +1,4 @@
1
1
  bundler_args: --without development
2
2
  language: ruby
3
3
  rvm:
4
- - 1.9.3
5
- - 2.0.0
6
- - 2.1.0
4
+ - 2.2.0
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # 3.2.1
2
+
3
+ - Fixes #88
4
+ - Override User-Agent header properly
5
+ - Match xpath nodes if attribute content is present
6
+ - Avoid nil urls in image parser
7
+
1
8
  # 3.2.0
2
9
 
3
10
  Makes scrapers configurable by allowing to set the scraping strategy:
@@ -6,7 +6,7 @@ module LinkThumbnailer
6
6
  attr_reader :images
7
7
 
8
8
  def initialize(urls)
9
- @images = perform? ? ::ImageInfo.from(urls, max_concurrency: max_concurrency) : Array(urls).map(&method(:build_default_image))
9
+ @images = perform? ? ::ImageInfo.from(urls, max_concurrency: max_concurrency) : Array(urls).compact.map(&method(:build_default_image))
10
10
  end
11
11
 
12
12
  def size
@@ -39,7 +39,7 @@ module LinkThumbnailer
39
39
 
40
40
  def set_http_headers(headers = {})
41
41
  headers.each { |k, v| http.headers[k] = v }
42
- http.headers['User-Agent'] = user_agent
42
+ http.override_headers['User-Agent'] = user_agent
43
43
  http.override_headers['Accept-Encoding'] = 'none'
44
44
  end
45
45
 
@@ -47,7 +47,7 @@ module LinkThumbnailer
47
47
  value = options.fetch(:value, :content)
48
48
  attribute = options.fetch(:attribute, attribute_name)
49
49
 
50
- document.xpath("//meta[translate(@#{key},'#{abc.upcase}','#{abc}') = '#{attribute}' and @#{value}]")
50
+ document.xpath("//meta[translate(@#{key},'#{abc.upcase}','#{abc}') = '#{attribute}' and string-length(@#{value}) > 0]")
51
51
  end
52
52
 
53
53
  def abc
@@ -1,4 +1,5 @@
1
1
  require 'link_thumbnailer/scrapers/opengraph/base'
2
+ require 'link_thumbnailer/uri'
2
3
 
3
4
  module LinkThumbnailer
4
5
  module Scrapers
@@ -20,7 +21,10 @@ module LinkThumbnailer
20
21
  end
21
22
 
22
23
  def model
23
- nodes.map { |n| modelize(n, n.attributes['content'].to_s) }
24
+ nodes.map do |n|
25
+ uri = LinkThumbnailer::URI.new(n.attributes['content'])
26
+ modelize(n, uri.to_s) if uri.valid?
27
+ end.compact
24
28
  end
25
29
 
26
30
  def modelize(node, text = nil)
@@ -0,0 +1,18 @@
1
+ module LinkThumbnailer
2
+ class URI
3
+
4
+ attr_reader :attribute
5
+
6
+ def initialize(uri)
7
+ @attribute = uri.to_s
8
+ end
9
+
10
+ def valid?
11
+ !!(attribute =~ ::URI::regexp)
12
+ end
13
+
14
+ def to_s
15
+ attribute
16
+ end
17
+ end
18
+ end
@@ -1,3 +1,3 @@
1
1
  module LinkThumbnailer
2
- VERSION = '3.2.0'
2
+ VERSION = '3.2.1'
3
3
  end
@@ -106,7 +106,7 @@ describe LinkThumbnailer::Processor do
106
106
  describe '#set_http_headers' do
107
107
 
108
108
  let(:user_agent) { 'foo' }
109
- let(:headers) { instance.send(:http).headers }
109
+ let(:headers) { instance.send(:http).override_headers }
110
110
  let(:action) { instance.send(:set_http_headers) }
111
111
 
112
112
  before do
data/spec/uri_spec.rb ADDED
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe LinkThumbnailer::URI do
4
+
5
+ let(:uri) { 'http://foo.com' }
6
+ let(:instance) { described_class.new(uri) }
7
+
8
+ describe '#valid?' do
9
+
10
+ let(:action) { instance.send(:valid?) }
11
+
12
+ context 'when bad format' do
13
+
14
+ before do
15
+ instance.stub(:attribute).and_return("/invalid/path")
16
+ end
17
+
18
+ it { expect(action).to be_falsey }
19
+
20
+ end
21
+
22
+ context 'when valid format' do
23
+
24
+ before do
25
+ instance.stub(:attribute).and_return("http://foo.com")
26
+ end
27
+
28
+ it { expect(action).to be_truthy }
29
+
30
+ end
31
+
32
+ end
33
+
34
+ describe '#to_s' do
35
+
36
+ let(:action) { instance.to_s }
37
+
38
+ it { expect(action).to eq(uri) }
39
+
40
+ end
41
+
42
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: link_thumbnailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0
4
+ version: 3.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pierre-Louis Gottfrois
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-15 00:00:00.000000000 Z
11
+ date: 2016-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -172,6 +172,7 @@ files:
172
172
  - lib/link_thumbnailer/scrapers/opengraph/title.rb
173
173
  - lib/link_thumbnailer/scrapers/opengraph/video.rb
174
174
  - lib/link_thumbnailer/scrapers/opengraph/videos.rb
175
+ - lib/link_thumbnailer/uri.rb
175
176
  - lib/link_thumbnailer/version.rb
176
177
  - lib/link_thumbnailer/video_parser.rb
177
178
  - link_thumbnailer.gemspec
@@ -206,6 +207,7 @@ files:
206
207
  - spec/scrapers/base_spec.rb
207
208
  - spec/scrapers/opengraph/base_spec.rb
208
209
  - spec/spec_helper.rb
210
+ - spec/uri_spec.rb
209
211
  - spec/video_parser_spec.rb
210
212
  homepage: https://github.com/gottfrois/link_thumbnailer
211
213
  licenses: []
@@ -263,4 +265,5 @@ test_files:
263
265
  - spec/scrapers/base_spec.rb
264
266
  - spec/scrapers/opengraph/base_spec.rb
265
267
  - spec/spec_helper.rb
268
+ - spec/uri_spec.rb
266
269
  - spec/video_parser_spec.rb