link_thumbnailer 3.1.2 → 3.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: 11cf021d0592289c3cba03e2e9168397b17bf952
4
- data.tar.gz: 873d56f6a10e21bba990f1be63ea750b811766ae
3
+ metadata.gz: 9799bede3f23e3369ddafa4ddeb36c9436d7ee5d
4
+ data.tar.gz: 484c6c008967be9cd3d813bac81dffde02c18bd7
5
5
  SHA512:
6
- metadata.gz: 283a2b8210c2ba9f71aee43eacc7e66e2896aebb1c1d9d68ebf1284c85d78bd083ddb83c3b6643411b4e575667aae463d1b5061d1a2f1e880ce3f0c4d6d0b3ea
7
- data.tar.gz: cb3cc71b303e6845352d9e934c4dda1f9aee8451c8a24c9df30b0ab808c5cc65188e1c1851fe58a5d477791f48cbfa82eca98e16afc52937baecc634359df327
6
+ metadata.gz: 3c6a25faef22554a54a84a2ffbf0ee85babb1b088b5ed79d08e6550504f9e9853fa177cd730856cd1c3cb3d285dc1bf6a727cd89a85d410f00cf89023668d1de
7
+ data.tar.gz: 10216dc920ce54195179337fc4034ba14413c833369a2e566e2b7aa5d118a5c7599df4673564ff7a57bc3558be3fa8d826e0c8f35058aba64e9544a13bc1d09d
data/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ # 3.2.0
2
+
3
+ Makes scrapers configurable by allowing to set the scraping strategy:
4
+
5
+ ```ruby
6
+ LinkThumbnailer.configure do |config|
7
+ config.scrapers = [:opengraph, :default]
8
+ end
9
+ ```
10
+
11
+ `opengraph` use the [Open Graph Protocol](http://ogp.me/).
12
+ `default` use a homemade algorithm
13
+
1
14
  # 3.1.2
2
15
 
3
16
  Allows to customize ideal description length
@@ -67,13 +67,17 @@ LinkThumbnailer.configure do |config|
67
67
  # does not have to fetch its size and type.
68
68
  #
69
69
  # config.image_stats = true
70
- #
70
+
71
71
  # Whether you want LinkThumbnailer to raise an exception if the Content-Type of the HTTP request
72
72
  # is not an html or xml.
73
73
  #
74
74
  # config.raise_on_invalid_format = false
75
- #
75
+
76
76
  # Sets number of concurrent http connections that can be opened to fetch images informations such as size and type.
77
77
  #
78
78
  # config.max_concurrency = 20
79
+
80
+ # Defines the strategies to use to scrap the website. See the [Open Graph Protocol](http://ogp.me/) for more information.
81
+ #
82
+ # config.scrapers = [:opengraph, :default]
79
83
  end
@@ -25,7 +25,8 @@ module LinkThumbnailer
25
25
  attr_accessor :redirect_limit, :blacklist_urls, :user_agent,
26
26
  :verify_ssl, :http_open_timeout, :http_read_timeout, :attributes,
27
27
  :graders, :description_min_length, :positive_regex, :negative_regex,
28
- :image_limit, :image_stats, :raise_on_invalid_format, :max_concurrency
28
+ :image_limit, :image_stats, :raise_on_invalid_format, :max_concurrency,
29
+ :scrapers
29
30
 
30
31
  alias_method :http_timeout, :http_open_timeout
31
32
  alias_method :http_timeout=, :http_open_timeout=
@@ -60,6 +61,7 @@ module LinkThumbnailer
60
61
  @image_stats = true
61
62
  @raise_on_invalid_format = false
62
63
  @max_concurrency = 20
64
+ @scrapers = [:opengraph, :default]
63
65
  end
64
66
 
65
67
  end
@@ -33,7 +33,7 @@ module LinkThumbnailer
33
33
 
34
34
  def call
35
35
  config.attributes.each do |name|
36
- scrapers.each do |scraper_prefix|
36
+ config.scrapers.each do |scraper_prefix|
37
37
  scraper_class(scraper_prefix, name).new(document, website).call(name.to_s)
38
38
  break unless website.send(name).blank?
39
39
  end
@@ -44,14 +44,8 @@ module LinkThumbnailer
44
44
 
45
45
  private
46
46
 
47
- def scrapers
48
- [
49
- '::LinkThumbnailer::Scrapers::Opengraph',
50
- '::LinkThumbnailer::Scrapers::Default'
51
- ]
52
- end
53
-
54
47
  def scraper_class(prefix, name)
48
+ prefix = "::LinkThumbnailer::Scrapers::#{prefix.to_s.camelize}"
55
49
  name = name.to_s.camelize
56
50
  "#{prefix}::#{name}".constantize
57
51
  rescue NameError
@@ -1,3 +1,3 @@
1
1
  module LinkThumbnailer
2
- VERSION = '3.1.2'
2
+ VERSION = '3.2.0'
3
3
  end
data/spec/scraper_spec.rb CHANGED
@@ -25,7 +25,7 @@ describe LinkThumbnailer::Scraper do
25
25
 
26
26
  before do
27
27
  instance.stub_chain(:config, :attributes).and_return(attributes)
28
- instance.stub(:scrapers).and_return(scrapers)
28
+ instance.stub_chain(:config, :scrapers).and_return(scrapers)
29
29
  end
30
30
 
31
31
  context 'when first one return a result' do
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.1.2
4
+ version: 3.2.0
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-04-18 00:00:00.000000000 Z
11
+ date: 2016-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport