link_thumbnailer 1.1.2 → 2.0.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.
Files changed (104) hide show
  1. checksums.yaml +5 -13
  2. data/.travis.yml +1 -1
  3. data/CHANGELOG.md +117 -104
  4. data/Gemfile +1 -1
  5. data/{LICENSE → LICENSE.txt} +21 -21
  6. data/README.md +153 -184
  7. data/lib/generators/link_thumbnailer/install_generator.rb +0 -4
  8. data/lib/generators/templates/initializer.rb +63 -41
  9. data/lib/link_thumbnailer/configuration.rb +52 -10
  10. data/lib/link_thumbnailer/exceptions.rb +6 -0
  11. data/lib/link_thumbnailer/grader.rb +37 -0
  12. data/lib/link_thumbnailer/graders/base.rb +32 -0
  13. data/lib/link_thumbnailer/graders/html_attribute.rb +49 -0
  14. data/lib/link_thumbnailer/graders/length.rb +19 -0
  15. data/lib/link_thumbnailer/graders/link_density.rb +21 -0
  16. data/lib/link_thumbnailer/graders/position.rb +11 -0
  17. data/lib/link_thumbnailer/image_comparator.rb +24 -0
  18. data/lib/link_thumbnailer/image_comparators/base.rb +17 -0
  19. data/lib/link_thumbnailer/image_comparators/size.rb +11 -0
  20. data/lib/link_thumbnailer/image_parser.rb +18 -0
  21. data/lib/link_thumbnailer/image_parsers/size.rb +15 -0
  22. data/lib/link_thumbnailer/image_parsers/type.rb +15 -0
  23. data/lib/link_thumbnailer/image_validator.rb +30 -0
  24. data/lib/link_thumbnailer/model.rb +16 -0
  25. data/lib/link_thumbnailer/models/description.rb +34 -0
  26. data/lib/link_thumbnailer/models/image.rb +54 -0
  27. data/lib/link_thumbnailer/models/title.rb +20 -0
  28. data/lib/link_thumbnailer/models/website.rb +39 -0
  29. data/lib/link_thumbnailer/page.rb +40 -0
  30. data/lib/link_thumbnailer/parser.rb +13 -0
  31. data/lib/link_thumbnailer/processor.rb +94 -0
  32. data/lib/link_thumbnailer/railtie.rb +9 -9
  33. data/lib/link_thumbnailer/scraper.rb +64 -0
  34. data/lib/link_thumbnailer/scrapers/base.rb +63 -0
  35. data/lib/link_thumbnailer/scrapers/default/base.rb +10 -0
  36. data/lib/link_thumbnailer/scrapers/default/description.rb +47 -0
  37. data/lib/link_thumbnailer/scrapers/default/images.rb +64 -0
  38. data/lib/link_thumbnailer/scrapers/default/title.rb +25 -0
  39. data/lib/link_thumbnailer/scrapers/opengraph/base.rb +43 -0
  40. data/lib/link_thumbnailer/scrapers/opengraph/description.rb +10 -0
  41. data/lib/link_thumbnailer/scrapers/opengraph/image.rb +30 -0
  42. data/lib/link_thumbnailer/scrapers/opengraph/images.rb +16 -0
  43. data/lib/link_thumbnailer/scrapers/opengraph/title.rb +10 -0
  44. data/lib/link_thumbnailer/version.rb +3 -3
  45. data/lib/link_thumbnailer.rb +36 -119
  46. data/link_thumbnailer.gemspec +26 -28
  47. data/spec/configuration_spec.rb +51 -0
  48. data/spec/examples/empty_og_image_example.html +9 -0
  49. data/spec/fixture_spec.rb +88 -0
  50. data/spec/fixtures/bar.png +2907 -0
  51. data/spec/fixtures/default_from_body.html +12 -0
  52. data/spec/fixtures/default_from_meta.html +11 -0
  53. data/spec/{examples → fixtures}/example.html +53 -53
  54. data/spec/fixtures/foo.png +0 -0
  55. data/spec/fixtures/og_not_valid_example.html +12 -0
  56. data/spec/fixtures/og_valid_example.html +12 -0
  57. data/spec/fixtures/og_valid_multi_image_example.html +13 -0
  58. data/spec/grader_spec.rb +24 -0
  59. data/spec/graders/base_spec.rb +12 -0
  60. data/spec/graders/html_attribute_spec.rb +48 -0
  61. data/spec/graders/length_spec.rb +81 -0
  62. data/spec/graders/link_density_spec.rb +22 -0
  63. data/spec/image_comparators/size_spec.rb +39 -0
  64. data/spec/image_parsers/size_spec.rb +34 -0
  65. data/spec/image_parsers/type_spec.rb +34 -0
  66. data/spec/image_validator_spec.rb +35 -0
  67. data/spec/model_spec.rb +17 -0
  68. data/spec/models/description_spec.rb +64 -0
  69. data/spec/models/image_spec.rb +71 -0
  70. data/spec/models/title_spec.rb +24 -0
  71. data/spec/models/website_spec.rb +49 -0
  72. data/spec/page_spec.rb +26 -0
  73. data/spec/processor_spec.rb +349 -0
  74. data/spec/scraper_spec.rb +95 -0
  75. data/spec/scrapers/base_spec.rb +67 -0
  76. data/spec/scrapers/opengraph/base_spec.rb +94 -0
  77. data/spec/spec_helper.rb +15 -13
  78. metadata +126 -120
  79. data/app/controllers/link_thumbnailer/application_controller.rb +0 -4
  80. data/app/controllers/link_thumbnailer/previews_controller.rb +0 -11
  81. data/lib/link_thumbnailer/doc.rb +0 -65
  82. data/lib/link_thumbnailer/doc_parser.rb +0 -15
  83. data/lib/link_thumbnailer/engine.rb +0 -4
  84. data/lib/link_thumbnailer/fetcher.rb +0 -34
  85. data/lib/link_thumbnailer/img_comparator.rb +0 -17
  86. data/lib/link_thumbnailer/img_parser.rb +0 -41
  87. data/lib/link_thumbnailer/img_url_filter.rb +0 -13
  88. data/lib/link_thumbnailer/object.rb +0 -41
  89. data/lib/link_thumbnailer/opengraph.rb +0 -20
  90. data/lib/link_thumbnailer/rails/routes/mapper.rb +0 -30
  91. data/lib/link_thumbnailer/rails/routes/mapping.rb +0 -33
  92. data/lib/link_thumbnailer/rails/routes.rb +0 -47
  93. data/lib/link_thumbnailer/web_image.rb +0 -19
  94. data/spec/doc_parser_spec.rb +0 -25
  95. data/spec/doc_spec.rb +0 -23
  96. data/spec/examples/empty_example.html +0 -11
  97. data/spec/examples/og_example.html +0 -12
  98. data/spec/fetcher_spec.rb +0 -97
  99. data/spec/img_comparator_spec.rb +0 -16
  100. data/spec/img_url_filter_spec.rb +0 -31
  101. data/spec/link_thumbnailer_spec.rb +0 -205
  102. data/spec/object_spec.rb +0 -130
  103. data/spec/opengraph_spec.rb +0 -7
  104. data/spec/web_image_spec.rb +0 -57
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MTI4ZDFkMDdhMWJiM2Y2M2ZlODEwMTg1NjU4MDg3NWIxNDg1NmVkMw==
5
- data.tar.gz: !binary |-
6
- ZGY2MzVlMTM1OGQxNWEwODNjMDM2ZGIyNDIwZjAzNWZiNjI5ZmEzNA==
2
+ SHA1:
3
+ metadata.gz: c1f15206d5f7ec2528178fd2fc49a2c226cbd1d7
4
+ data.tar.gz: b10ea72d36315c40263688402b268075264131f6
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- YTRlNGI4Yjk2Njk2MDgwNTI2YTgyMGJlNDdmMTk2Y2Q4YjEyY2UyODAyOGU5
10
- YTk0ZTJjOTg5YWJjZDBjN2U5NWM2ODg3YzRiNGY3ZGYzZGU3NTE0YzE2YjM3
11
- MDIyM2UwNTQ3MmJkZWY4YzcwZjkzNWU0ZjRiNzNmMmViNzA2MTM=
12
- data.tar.gz: !binary |-
13
- MGI4ZjIwNWEzODIwN2E4YjA0MGVjYWY1NzUzZGE0Njk3MzcxOTA0Zjk3OGY5
14
- YmFkZmM3MTE3ODc5Mzk2OTYxZTY0NTQwYjY0NjQwNzFjODY5NmY2MDE2MDFj
15
- ODY0NWYxMzNmMTAzY2FkYjU5YzY3YTg2ODhmNjhhODFlYzc5ZjA=
6
+ metadata.gz: fd9cb26e28184c783f82f866173b49988ceba7b62f04a26930be127e3382fdcfb7f891f9f21d73cbbfc176b61a29ed6581f7cbd9b52fe56bc474c7ba10cdacd9
7
+ data.tar.gz: 426fb6ec3bf6f2118807d7eb281b36fa1abb1bccce060b85e734704bb5489806483e4a048df2d81e54d9db5b9be0edb2359909ea4d267dd3f9800aac850e107a
data/.travis.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  bundler_args: --without development
2
2
  language: ruby
3
3
  rvm:
4
- - 1.9.2
5
4
  - 1.9.3
6
5
  - 2.0.0
6
+ - 2.1.0
data/CHANGELOG.md CHANGED
@@ -1,104 +1,117 @@
1
- # 1.1.2
2
-
3
- - Fix issue with FastImage URLs [https://github.com/gottfrois/link_thumbnailer/pull/31](https://github.com/gottfrois/link_thumbnailer/pull/31)
4
-
5
- # 1.1.1
6
-
7
- - Fix route helper not working under rails 4.
8
-
9
- # 1.1.0
10
-
11
- - Replace RMagick by [FastImage](https://github.com/sdsykes/fastimage)
12
- - Rename `rmagick_attributes` config into `image_attributes`
13
-
14
- # 1.0.9
15
-
16
- - Fix issue when Location header used a relative path instead of an absolute path
17
- - Update gemfile to be more flexible when using Hashie gem
18
-
19
- # 1.0.8
20
-
21
- - Thanks to [juriglx](https://github.com/juriglx), support for canonical urls
22
- - Bug fixes
23
-
24
- # 1.0.7
25
-
26
- - Fix: Issue with preview controller
27
-
28
- # 1.0.6
29
-
30
- - Fix: Issue when setting `strict` option. Always returning OG representation.
31
-
32
- # 1.0.5
33
-
34
- - Thanks to [phlegx](https://github.com/phlegx), support for timeout http connection through configurations.
35
-
36
- # 1.0.4
37
-
38
- - Fix issue #7: nil img was returned when exception is raised. Now skiping nil images in results.
39
- - Thanks to [phlegx](https://github.com/phlegx), support for SSL and User Agent customization through configurations.
40
-
41
- # 1.0.3
42
-
43
- - Fix issue #5: Url was incorect in case of HTTP Redirections.
44
-
45
- # 1.0.2
46
-
47
- - Feature: User can now set options at runtime by passing valid options to ```generate``` method
48
- - Bug fix when doing ```rails g link_thumbnailer:install``` by explicitly specifying the scope of Rails
49
-
50
- # 1.0.1
51
-
52
- - Refactor LinkThumbnailer#generate method to have a cleaner code
53
-
54
- # 1.0.0
55
-
56
- - Update readme
57
- - Add PreviewController for easy integration with user's app
58
- - Add link_thumbnailer routes for easy integration with user's app
59
- - Refactor some code
60
- - Change 'to_a' method to 'to_hash' in object model
61
-
62
- # 0.0.6
63
-
64
- - Update readme
65
- - Add `to_a` to WebImage class
66
- - Refactor `to_json` for WebImage class
67
- - Add specs corresponding
68
-
69
- # 0.0.5
70
-
71
- - Bug fix
72
- - Remove `require 'rails'` from spec_helper.rb
73
- - Remove rails dependences (blank? method) in code
74
- - Spec fix
75
-
76
- # 0.0.4
77
-
78
- - Add specs for almost all classes
79
- - Add a method `to_json` for WebImage class to be able to get a usable array of images' attributes
80
-
81
- # 0.0.3
82
-
83
- - Add specs for LinkThumbnailer class
84
- - Refactor config system, now using dedicated configuration class
85
-
86
- # 0.0.2
87
-
88
- - Added Rspec
89
- - Bug fixes:
90
- - Now checking if attribute is blank for LinkThumbnailer::Object.valid? method
91
-
92
- # 0.0.1
93
-
94
- - LinkThumbnailer::Object
95
- - LinkThumbnailer::Doc
96
- - LinkThumbnailer::DocParser
97
- - LinkThumbnailer::Fetcher
98
- - LinkThumbnailer::ImgComparator
99
- - LinkThumbnailer::ImgParser
100
- - LinkThumbnailer::ImgUrlFilter
101
- - LinkThumbnailer::Opengraph
102
- - LinkThumbnailer::WebImage
103
- - LinkThumbnailer.configure
104
- - LinkThumbnailer.generate
1
+ # 2.0.0
2
+
3
+ - Fully refactored LinkThumbnailer
4
+ - Introduced [Graders](https://github.com/gottfrois/link_thumbnailer/wiki/How-to-build-your-own-Grader%3F)
5
+ - Introduced [Scrapers](https://github.com/gottfrois/link_thumbnailer/wiki/Attributes-option-explained)
6
+ - Ability to score descriptions
7
+ - Ability to fetch multiple `og:image`
8
+ - Fixed memoized run-time options
9
+ - Fixed some website urls not working
10
+ - Refactor ugly code
11
+ - More specs
12
+ - Removed `PreviewsController` since it does not add much value. Simply create your own and use the `to_json` method.
13
+
14
+ # 1.1.2
15
+
16
+ - Fix issue with FastImage URLs [https://github.com/gottfrois/link_thumbnailer/pull/31](https://github.com/gottfrois/link_thumbnailer/pull/31)
17
+
18
+ # 1.1.1
19
+
20
+ - Fix route helper not working under rails 4.
21
+
22
+ # 1.1.0
23
+
24
+ - Replace RMagick by [FastImage](https://github.com/sdsykes/fastimage)
25
+ - Rename `rmagick_attributes` config into `image_attributes`
26
+
27
+ # 1.0.9
28
+
29
+ - Fix issue when Location header used a relative path instead of an absolute path
30
+ - Update gemfile to be more flexible when using Hashie gem
31
+
32
+ # 1.0.8
33
+
34
+ - Thanks to [juriglx](https://github.com/juriglx), support for canonical urls
35
+ - Bug fixes
36
+
37
+ # 1.0.7
38
+
39
+ - Fix: Issue with preview controller
40
+
41
+ # 1.0.6
42
+
43
+ - Fix: Issue when setting `strict` option. Always returning OG representation.
44
+
45
+ # 1.0.5
46
+
47
+ - Thanks to [phlegx](https://github.com/phlegx), support for timeout http connection through configurations.
48
+
49
+ # 1.0.4
50
+
51
+ - Fix issue #7: nil img was returned when exception is raised. Now skiping nil images in results.
52
+ - Thanks to [phlegx](https://github.com/phlegx), support for SSL and User Agent customization through configurations.
53
+
54
+ # 1.0.3
55
+
56
+ - Fix issue #5: Url was incorect in case of HTTP Redirections.
57
+
58
+ # 1.0.2
59
+
60
+ - Feature: User can now set options at runtime by passing valid options to ```generate``` method
61
+ - Bug fix when doing ```rails g link_thumbnailer:install``` by explicitly specifying the scope of Rails
62
+
63
+ # 1.0.1
64
+
65
+ - Refactor LinkThumbnailer#generate method to have a cleaner code
66
+
67
+ # 1.0.0
68
+
69
+ - Update readme
70
+ - Add PreviewController for easy integration with user's app
71
+ - Add link_thumbnailer routes for easy integration with user's app
72
+ - Refactor some code
73
+ - Change 'to_a' method to 'to_hash' in object model
74
+
75
+ # 0.0.6
76
+
77
+ - Update readme
78
+ - Add `to_a` to WebImage class
79
+ - Refactor `to_json` for WebImage class
80
+ - Add specs corresponding
81
+
82
+ # 0.0.5
83
+
84
+ - Bug fix
85
+ - Remove `require 'rails'` from spec_helper.rb
86
+ - Remove rails dependences (blank? method) in code
87
+ - Spec fix
88
+
89
+ # 0.0.4
90
+
91
+ - Add specs for almost all classes
92
+ - Add a method `to_json` for WebImage class to be able to get a usable array of images' attributes
93
+
94
+ # 0.0.3
95
+
96
+ - Add specs for LinkThumbnailer class
97
+ - Refactor config system, now using dedicated configuration class
98
+
99
+ # 0.0.2
100
+
101
+ - Added Rspec
102
+ - Bug fixes:
103
+ - Now checking if attribute is blank for LinkThumbnailer::Object.valid? method
104
+
105
+ # 0.0.1
106
+
107
+ - LinkThumbnailer::Object
108
+ - LinkThumbnailer::Doc
109
+ - LinkThumbnailer::DocParser
110
+ - LinkThumbnailer::Fetcher
111
+ - LinkThumbnailer::ImgComparator
112
+ - LinkThumbnailer::ImgParser
113
+ - LinkThumbnailer::ImgUrlFilter
114
+ - LinkThumbnailer::Opengraph
115
+ - LinkThumbnailer::WebImage
116
+ - LinkThumbnailer.configure
117
+ - LinkThumbnailer.generate
data/Gemfile CHANGED
@@ -3,7 +3,7 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in link_thumbnailer.gemspec
4
4
  gemspec
5
5
 
6
- group :test do
6
+ group :development, :test do
7
7
  gem 'coveralls', require: false
8
8
  gem 'simplecov', require: false
9
9
  gem 'rspec', '~> 2.14'
@@ -1,22 +1,22 @@
1
- Copyright (c) 2012 Pierre-Louis Gottfrois
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
1
+ Copyright (c) 2012 Pierre-Louis Gottfrois
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
22
  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,184 +1,153 @@
1
- # LinkThumbnailer
2
-
3
- [![Code Climate](https://codeclimate.com/github/gottfrois/link_thumbnailer.png)](https://codeclimate.com/github/gottfrois/link_thumbnailer)
4
- [![Coverage Status](https://coveralls.io/repos/gottfrois/link_thumbnailer/badge.png?branch=master)](https://coveralls.io/r/gottfrois/link_thumbnailer?branch=master)
5
- [![Build Status](https://travis-ci.org/gottfrois/link_thumbnailer.png?branch=master)](https://travis-ci.org/gottfrois/link_thumbnailer)
6
-
7
- Ruby gem generating image thumbnails from a given URL. Rank them and give you back an object containing images and website informations. Works like Facebook link previewer.
8
-
9
- Demo Application is [here](http://link-thumbnailer-demo.herokuapp.com/) !
10
-
11
- ## Installation
12
-
13
- Add this line to your application's Gemfile:
14
-
15
- gem 'link_thumbnailer'
16
-
17
- And then execute:
18
-
19
- $ bundle
20
-
21
- Or install it yourself as:
22
-
23
- $ gem install link_thumbnailer
24
-
25
- Run:
26
-
27
- $ rails g link_thumbnailer:install
28
-
29
- This will add `link_thumbnailer.rb` to `config/initializers/`. See [#Configuration](https://github.com/gottfrois/link_thumbnailer#configuration) for more details.
30
-
31
- ## Usage
32
-
33
- Run `irb` and require the gem:
34
-
35
- require 'rails'
36
- => true
37
-
38
- require 'link_thumbnailer'
39
- => true
40
-
41
- This gem can handle [Opengraph](http://ogp.me/) protocol. Here is an example with such a website:
42
-
43
- object = LinkThumbnailer.generate('http://zerply.com')
44
- => #<LinkThumbnailer::Object description="Go beyond the résumé - showcase your work and your talent" image="http://zerply.com/img/front/facebook_icon_green.png" images=["http://zerply.com/img/front/facebook_icon_green.png"] site_name="zerply.com" title="Join Me on Zerply" url="http://zerply.com">
45
-
46
- object.title?
47
- => true
48
- object.title
49
- => "Join Me on Zerply"
50
-
51
- object.url?
52
- => true
53
- object.url
54
- => "http://zerply.com"
55
-
56
- object.foo?
57
- => false
58
- object.foo
59
- => nil
60
-
61
- Now with a regular website with no particular protocol:
62
-
63
- object = LinkThumbnailer.generate('http://foo.com')
64
- => #<LinkThumbnailer::Object description=nil images=[[ JPEG 750x200 750x200+0+0 DirectClass 8-bit 45kb] scene=0] title="Foo.com" url="http://foo.com">
65
-
66
- object.title
67
- => "Foo.com"
68
-
69
- object.images
70
- => [[ JPEG 750x200 750x200+0+0 DirectClass 8-bit 45kb]
71
- scene=0]
72
-
73
- object.images.first.source_url
74
- => #<URI::HTTP:0x007ff7a923ef58 URL:http://foo.com/media/BAhbB1sHOgZmSSItMjAxMi8wNC8yNi8yMC8xMS80OS80MjYvY29yZG92YWJlYWNoLmpwZwY6BkVUWwg6BnA6CnRodW1iSSINNzUweDIwMCMGOwZU/cordovabeach.jpg>
75
-
76
- object.to_hash
77
- => {"url"=>"http://foo.com", "images"=>[{:source_url=>"http://foo.com/media/BAhbB1sHOgZmSSItMjAxMi8wNC8yNi8yMC8xMS80OS80MjYvY29yZG92YWJlYWNoLmpwZwY6BkVUWwg6BnA6CnRodW1iSSINNzUweDIwMCMGOwZU/cordovabeach.jpg", :mime_type=>"image/jpeg", :rows=>200, :filesize=>46501, :number_colors=>9490}], "title"=>"Foo.com", "description"=>nil}
78
-
79
- object.to_json
80
- => "{\"url\":\"http://foo.com\",\"images\":[{\"source_url\":\"http://foo.com/media/BAhbB1sHOgZmSSItMjAxMi8wNC8yNi8yMC8xMS80OS80MjYvY29yZG92YWJlYWNoLmpwZwY6BkVUWwg6BnA6CnRodW1iSSINNzUweDIwMCMGOwZU/cordovabeach.jpg\",\"mime_type\":\"image/jpeg\",\"rows\":200,\"filesize\":46501,\"number_colors\":9490}],\"title\":\"Foo.com\",\"description\":null}"
81
-
82
- You can check whether this object is valid or not (set mandatory attributes in the initializer, defaults are `[url, title, images]`)
83
-
84
- object.valid?
85
- => true
86
-
87
- You also can set options at runtime:
88
-
89
- object = LinkThumbnailer.generate('http://foo.com', top: 10, limit: 20, redirect_limit: 5)
90
-
91
- ## Preview Controller
92
-
93
- For an easy integration into your application, use the builtin `PreviewController`.
94
-
95
- Take a look at the demo application [here](https://github.com/gottfrois/link_thumbnailer_demo).
96
-
97
- Basically, all you have to do in your view is something like this:
98
-
99
- <%= form_tag '/link/preview', method: :post, remote: true do %>
100
- <%= text_field_tag :url %>
101
- <%= submit_tag 'Preview' %>
102
- <% end %>
103
-
104
- Don't forget to add this anywhere in your `routes.rb` file:
105
-
106
- use_link_thumbnailer
107
-
108
- Note: You won't have to bother with this if you did run the installer using:
109
-
110
- $ rails g link_thumbnailer:install
111
-
112
- The `PreviewController` will automatically respond to json calls, returning json version of the preview object. Just like in the IRB console above.
113
-
114
- ## Configuration
115
-
116
- In `config/initializers/link_thumbnailer.rb`
117
-
118
- LinkThumbnailer.configure do |config|
119
- # Set mandatory attributes require for the website to be valid.
120
- # You can set `strict` to false if you want to skip this validation.
121
- # config.mandatory_attributes = %w(url title image)
122
-
123
- # Whether you want to validate given website against mandatory attributes or not.
124
- # config.strict = true
125
-
126
- # Numbers of redirects before raising an exception when trying to parse given url.
127
- # config.redirect_limit = 3
128
-
129
- # List of blacklisted urls you want to skip when searching for images.
130
- # config.blacklist_urls = [
131
- # %r{^http://ad\.doubleclick\.net/},
132
- # %r{^http://b\.scorecardresearch\.com/},
133
- # %r{^http://pixel\.quantserve\.com/},
134
- # %r{^http://s7\.addthis\.com/}
135
- # ]
136
-
137
- # Fetch 10 images maximum.
138
- # config.limit = 10
139
-
140
- # Return top 5 images only.
141
- # config.top = 5
142
-
143
- # Set user agent
144
- # config.user_agent = 'linkthumbnailer'
145
-
146
- # Enable or disable SSL verification
147
- # config.verify_ssl = true
148
-
149
- # HTTP open_timeout: The amount of time in seconds to wait for a connection to be opened.
150
- # config.http_timeout = 5
151
- end
152
-
153
- ## Features
154
-
155
- Implemented:
156
-
157
- - Implements [OpenGraph](http://ogp.me/) protocol.
158
- - Find images and sort them according to how well they represent what the page is about (includes absolute images).
159
- - Sort images based on their size and color.
160
- - Blacklist some well known advertisings image urls.
161
- - Routes and Controllers to handle preview generation
162
-
163
- Coming soon:
164
-
165
- - Use the gem [ruby-readability](https://github.com/iterationlabs/ruby-readability) to parse images and website information
166
- - Cache results on filesystem
167
-
168
- ## Contributing
169
-
170
- 1. Fork it
171
- 2. Create your feature branch (`git checkout -b my-new-feature`)
172
- 3. Run the specs (`bundle exec rspec spec`)
173
- 4. Commit your changes (`git commit -am 'Added some feature'`)
174
- 5. Push to the branch (`git push origin my-new-feature`)
175
- 6. Create new Pull Request
176
-
177
- ## Contributors
178
-
179
- - [phlegx](https://github.com/phlegx)
180
- - [juriglx](https://github.com/juriglx)
181
-
182
-
183
- [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/gottfrois/link_thumbnailer/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
184
-
1
+ # LinkThumbnailer
2
+
3
+ [![Code Climate](https://codeclimate.com/github/gottfrois/link_thumbnailer.png)](https://codeclimate.com/github/gottfrois/link_thumbnailer)
4
+ [![Coverage Status](https://coveralls.io/repos/gottfrois/link_thumbnailer/badge.png?branch=master)](https://coveralls.io/r/gottfrois/link_thumbnailer?branch=master)
5
+ [![Build Status](https://travis-ci.org/gottfrois/link_thumbnailer.png?branch=master)](https://travis-ci.org/gottfrois/link_thumbnailer)
6
+
7
+ Ruby gem generating image thumbnails from a given URL. Rank them and give you back an object containing images and website informations. Works like Facebook link previewer.
8
+
9
+ Demo Application is [here](http://link-thumbnailer-demo.herokuapp.com/) !
10
+
11
+ ## Features
12
+
13
+ - Dead simple.
14
+ - Support [OpenGraph](http://ogp.me/) protocol.
15
+ - Find and sort images that best represent what the page is about.
16
+ - Find and rate description that best represent what the page is about.
17
+ - Allow for custom class to sort the website descriptions yourself.
18
+ - Support image urls blacklisting (advertisements).
19
+ - Works with and without Rails.
20
+ - Fully customizable.
21
+ - Fully tested.
22
+
23
+ ## Installation
24
+
25
+ Add this line to your application's Gemfile:
26
+
27
+ gem 'link_thumbnailer'
28
+
29
+ And then execute:
30
+
31
+ $ bundle
32
+
33
+ Or install it yourself as:
34
+
35
+ $ gem install link_thumbnailer
36
+
37
+ Run:
38
+
39
+ $ rails g link_thumbnailer:install
40
+
41
+ This will add `link_thumbnailer.rb` to `config/initializers/`.
42
+
43
+ ## Usage
44
+
45
+ Run `irb` and require the gem:
46
+
47
+ require 'link_thumbnailer'
48
+
49
+ The gem handle regular website but also website that use the [Opengraph](http://ogp.me/) protocol.
50
+
51
+ object = LinkThumbnailer.generate('http://stackoverflow.com')
52
+ => #<LinkThumbnailer::Models::Website:...>
53
+
54
+ object.title
55
+ => "Stack Overflow"
56
+
57
+ object.description
58
+ => "Q&A for professional and enthusiast programmers"
59
+
60
+ object.images.first.src.to_s
61
+ => "http://cdn.sstatic.net/stackoverflow/img/apple-touch-icon@2.png?v=fde65a5a78c6"
62
+
63
+ LinkThumbnailer `generate` method return an instance of `LinkThumbnailer::Models::Website` that respond to `to_json` and `as_json` as you would expect:
64
+
65
+ object.to_json
66
+ => "{\"url\":\"http://stackoverflow.com\",\"title\":\"Stack Overflow\",\"description\":\"Q&A for professional and enthusiast programmers\",\"images\":[{\"src\":\"http://cdn.sstatic.net/stackoverflow/img/apple-touch-icon@2.png?v=fde65a5a78c6\",\"size\":[316,316],\"type\":\"png\"}]}"
67
+
68
+
69
+ ## Configuration
70
+
71
+ LinkThumnailer comes with default configuration values. You can change default value by overriding them in a rails initializer:
72
+
73
+ In `config/initializers/link_thumbnailer.rb`
74
+
75
+ LinkThumbnailer.configure do |config|
76
+ # Numbers of redirects before raising an exception when trying to parse given url.
77
+ #
78
+ # config.redirect_limit = 3
79
+
80
+ # Set user agent
81
+ #
82
+ # config.user_agent = 'link_thumbnailer'
83
+
84
+ # Enable or disable SSL verification
85
+ #
86
+ # config.verify_ssl = true
87
+
88
+ # The amount of time in seconds to wait for a connection to be opened.
89
+ # If the HTTP object cannot open a connection in this many seconds,
90
+ # it raises a Net::OpenTimeout exception.
91
+ #
92
+ # See http://www.ruby-doc.org/stdlib-2.1.1/libdoc/net/http/rdoc/Net/HTTP.html#open_timeout
93
+ #
94
+ # config.http_timeout = 5
95
+
96
+ # List of blacklisted urls you want to skip when searching for images.
97
+ #
98
+ # config.blacklist_urls = [
99
+ # %r{^http://ad\.doubleclick\.net/},
100
+ # %r{^http://b\.scorecardresearch\.com/},
101
+ # %r{^http://pixel\.quantserve\.com/},
102
+ # %r{^http://s7\.addthis\.com/}
103
+ # ]
104
+
105
+ # List of attributes you want LinkThumbnailer to fetch on a website.
106
+ #
107
+ # config.attributes = [:title, :images, :description]
108
+
109
+ # List of procedures used to rate the website description. Add you custom class
110
+ # here. Note that the order matter to compute the score. See wiki for more details
111
+ # on how to build your own graders.
112
+ #
113
+ # config.graders = [
114
+ # ->(description) { ::LinkThumbnailer::Graders::Length.new(description) },
115
+ # ->(description) { ::LinkThumbnailer::Graders::HtmlAttribute.new(description, :class) },
116
+ # ->(description) { ::LinkThumbnailer::Graders::HtmlAttribute.new(description, :id) },
117
+ # ->(description) { ::LinkThumbnailer::Graders::Position.new(description) },
118
+ # ->(description) { ::LinkThumbnailer::Graders::LinkDensity.new(description) }
119
+ # ]
120
+
121
+ # Minimum description length for a website.
122
+ #
123
+ # config.description_min_length = 25
124
+
125
+ # Regex of words considered positive to rate website description.
126
+ #
127
+ # config.positive_regex = /article|body|content|entry|hentry|main|page|pagination|post|text|blog|story/i
128
+
129
+ # Regex of words considered negative to rate website description.
130
+ #
131
+ # config.negative_regex = /combx|comment|com-|contact|foot|footer|footnote|masthead|media|meta|outbrain|promo|related|scroll|shoutbox|sidebar|sponsor|shopping|tags|tool|widget|modal/i
132
+
133
+ # Numbers of images to fetch. Fetching too many images will be slow.
134
+ #
135
+ # config.image_limit = 5
136
+ end
137
+
138
+ Or at runtime:
139
+
140
+ object = LinkThumbnailer.generate('http://stackoverflow.com', redirect_limit: 5, user_agent: 'foo')
141
+
142
+ Note that runtime options will override default global configuration.
143
+
144
+ See [Configuration Options Explained](https://github.com/gottfrois/link_thumbnailer/wiki/Configuration-options-explained) for more details on each configuration options.
145
+
146
+ ## Contributing
147
+
148
+ 1. Fork it
149
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
150
+ 3. Run the specs (`bundle exec rspec spec`)
151
+ 4. Commit your changes (`git commit -am 'Added some feature'`)
152
+ 5. Push to the branch (`git push origin my-new-feature`)
153
+ 6. Create new Pull Request