link_thumbnailer 0.0.3 → 0.0.4
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/CHANGELOG.md +11 -1
- data/lib/link_thumbnailer/object.rb +1 -0
- data/lib/link_thumbnailer/version.rb +1 -1
- data/lib/link_thumbnailer/web_image.rb +11 -0
- data/lib/link_thumbnailer.rb +2 -1
- data/link_thumbnailer.gemspec +1 -0
- data/spec/doc_parser_spec.rb +7 -0
- data/spec/doc_spec.rb +23 -0
- data/spec/examples/example.html +363 -0
- data/spec/fetcher_spec.rb +45 -0
- data/spec/img_comparator_spec.rb +16 -0
- data/spec/img_url_filter_spec.rb +31 -0
- data/spec/link_thumbnailer_spec.rb +5 -4
- data/spec/object_spec.rb +95 -0
- data/spec/opengraph_spec.rb +7 -0
- data/spec/web_image_spec.rb +49 -0
- metadata +36 -2
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
# 0.0.4
|
2
|
+
|
3
|
+
- Add specs for almost all classes
|
4
|
+
- Add a method `to_json` for WebImage class to be able to get a usable array of images' attributes
|
5
|
+
|
6
|
+
# 0.0.3
|
7
|
+
|
8
|
+
- Add specs for LinkThumbnailer class
|
9
|
+
- Refactor config system, now using dedicated configuration class
|
10
|
+
|
1
11
|
# 0.0.2
|
2
12
|
|
3
13
|
- Added Rspec
|
@@ -16,4 +26,4 @@
|
|
16
26
|
- LinkThumbnailer::Opengraph
|
17
27
|
- LinkThumbnailer::WebImage
|
18
28
|
- LinkThumbnailer.configure
|
19
|
-
- LinkThumbnailer.generate
|
29
|
+
- LinkThumbnailer.generate
|
@@ -14,6 +14,7 @@ module LinkThumbnailer
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
# TODO remove blank call. Rails dependent.
|
17
18
|
def valid?
|
18
19
|
return false if self.keys.empty?
|
19
20
|
LinkThumbnailer.configuration.mandatory_attributes.each {|a| return false if self[a].blank? } if LinkThumbnailer.configuration.strict
|
@@ -1,8 +1,19 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
1
3
|
module LinkThumbnailer
|
2
4
|
module WebImage
|
3
5
|
|
4
6
|
attr_accessor :source_url
|
5
7
|
attr_accessor :doc
|
6
8
|
|
9
|
+
def to_json
|
10
|
+
result = []
|
11
|
+
%w(source_url mime_type density colums rows filesize number_colors).each {|m|
|
12
|
+
result << { m.to_sym => self.send(m) } if self.respond_to?(m)
|
13
|
+
}
|
14
|
+
|
15
|
+
JSON(result)
|
16
|
+
end
|
17
|
+
|
7
18
|
end
|
8
19
|
end
|
data/lib/link_thumbnailer.rb
CHANGED
@@ -16,7 +16,8 @@ module LinkThumbnailer
|
|
16
16
|
|
17
17
|
class << self
|
18
18
|
|
19
|
-
attr_accessor :configuration, :object, :fetcher, :doc_parser,
|
19
|
+
attr_accessor :configuration, :object, :fetcher, :doc_parser,
|
20
|
+
:img_url_filters, :img_parser
|
20
21
|
|
21
22
|
def config
|
22
23
|
self.configuration ||= Configuration.new(
|
data/link_thumbnailer.gemspec
CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |gem|
|
|
19
19
|
gem.add_dependency(%q{hashie}, ['~> 1.2.0'])
|
20
20
|
gem.add_dependency(%q{net-http-persistent}, ['~> 2.7'])
|
21
21
|
gem.add_dependency(%q{rmagick}, ['~> 2.13.1'])
|
22
|
+
gem.add_dependency(%q{json}, ['~> 1.7.5'])
|
22
23
|
|
23
24
|
gem.add_development_dependency(%q{rspec}, ['~> 2.11.0'])
|
24
25
|
gem.add_development_dependency(%q{webmock}, ['~> 1.8.10'])
|
data/spec/doc_spec.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe LinkThumbnailer::Doc do
|
4
|
+
|
5
|
+
class Foo
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:foo) { Foo.new }
|
9
|
+
|
10
|
+
before do
|
11
|
+
foo.extend LinkThumbnailer::Doc
|
12
|
+
end
|
13
|
+
|
14
|
+
subject { foo }
|
15
|
+
|
16
|
+
it { should respond_to :doc_base_href }
|
17
|
+
it { should respond_to :img_srcs }
|
18
|
+
it { should respond_to :img_abs_urls }
|
19
|
+
it { should respond_to :title }
|
20
|
+
it { should respond_to :description }
|
21
|
+
it { should respond_to :source_url }
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,363 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<!-- saved from url=(0019)http://www.foo.com/ -->
|
3
|
+
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
4
|
+
<meta charset="UTF-8">
|
5
|
+
<title>Foo.com</title>
|
6
|
+
<link href="./example_files/style-3706572431311a3a4cf5c6f3266c9bce.css" media="all" rel="stylesheet" type="text/css">
|
7
|
+
<link href="./example_files/belt_layout1_google-1c8ee8bd905a6121e7a7ac73b7ffb888.css" media="all" rel="stylesheet" type="text/css">
|
8
|
+
<script src="./example_files/application-e8b3208729190cb9cc8a800ff3283fd8.js" type="text/javascript"></script>
|
9
|
+
<link href="./example_files/load_style.css" media="all" rel="stylesheet" type="text/css">
|
10
|
+
<meta content="authenticity_token" name="csrf-param">
|
11
|
+
<meta content="Mh9Ervhd7HlDNhhJdZ+nKec9RE0sn2FO8nyJXUrKUng=" name="csrf-token">
|
12
|
+
</head>
|
13
|
+
<body>
|
14
|
+
|
15
|
+
|
16
|
+
<style>
|
17
|
+
.listing .sitelinks{
|
18
|
+
padding:5px 15px;
|
19
|
+
}
|
20
|
+
|
21
|
+
.listing .sitelinks td{
|
22
|
+
padding-right:16px;
|
23
|
+
|
24
|
+
}
|
25
|
+
.listing .sitelinks a, .listing .ratings a{
|
26
|
+
color:#0000DE;
|
27
|
+
}
|
28
|
+
.listing .url a:hover{
|
29
|
+
color:#a02934;
|
30
|
+
}
|
31
|
+
.ratings{
|
32
|
+
color: #666666;
|
33
|
+
}
|
34
|
+
.listing{
|
35
|
+
margin-bottom:15px;
|
36
|
+
}
|
37
|
+
.listing .url {
|
38
|
+
font-size:16px;
|
39
|
+
}
|
40
|
+
.listing .host {
|
41
|
+
color:#a02934;
|
42
|
+
display:block;
|
43
|
+
font-size:16px;
|
44
|
+
text-decoration:none;
|
45
|
+
}
|
46
|
+
|
47
|
+
.listing .url a{
|
48
|
+
color:#0000DE;
|
49
|
+
line-height:auto;
|
50
|
+
}
|
51
|
+
.listing .description a{
|
52
|
+
text-decoration:none;
|
53
|
+
color:black;
|
54
|
+
font-size:16px;
|
55
|
+
line-height:12pt;
|
56
|
+
}
|
57
|
+
.listing .host a{
|
58
|
+
text-decoration:none;
|
59
|
+
color:#008000;
|
60
|
+
font-size:16px;
|
61
|
+
line-height:12pt;
|
62
|
+
}
|
63
|
+
</style>
|
64
|
+
<script src="./example_files/jquery-1.5.js"></script>
|
65
|
+
<script>
|
66
|
+
var google_about_url = '';
|
67
|
+
var ads_array = new Array();
|
68
|
+
var bottom_ads_array = new Array();
|
69
|
+
var webSearch = "";
|
70
|
+
var google_tag = "";
|
71
|
+
|
72
|
+
var genCatSearches_array=new Array();
|
73
|
+
var relatedSearches_array=new Array();
|
74
|
+
var popularCategories_array = new Array();
|
75
|
+
var digi_keyword_links_array = new Array();
|
76
|
+
var global_afd_response = "";
|
77
|
+
|
78
|
+
var call_num = 1;
|
79
|
+
function redirect(){
|
80
|
+
document.getElementById('results').innerHTML = "No results found";
|
81
|
+
}
|
82
|
+
|
83
|
+
function jscript_log(name, severity, message, page){
|
84
|
+
$.ajax({
|
85
|
+
type: "POST",
|
86
|
+
url: "/log_error",
|
87
|
+
data: {
|
88
|
+
name: name,
|
89
|
+
severity: severity,
|
90
|
+
domain: window.location.hostname,
|
91
|
+
message: message,
|
92
|
+
tag: google_tag,
|
93
|
+
page: page
|
94
|
+
},
|
95
|
+
context: document.body
|
96
|
+
})
|
97
|
+
}
|
98
|
+
|
99
|
+
function token_link(keyword){
|
100
|
+
window.location = '/results' + '?q=' + encodeURIComponent(keyword) + '&token=' + global_afd_response.token;
|
101
|
+
return false;
|
102
|
+
}
|
103
|
+
|
104
|
+
function link_to_google(){
|
105
|
+
if(google_about_url!=''){
|
106
|
+
window.open(google_about_url,'_blank');
|
107
|
+
}
|
108
|
+
}
|
109
|
+
|
110
|
+
function gadlink(ga, inner_text, visible_url){
|
111
|
+
visible_url = visible_url.replace(/<b>/gi,'')
|
112
|
+
visible_url = visible_url.replace(/<\/b>/gi,'')
|
113
|
+
return '<a ' +
|
114
|
+
'href="http://' + visible_url + '"' +
|
115
|
+
' onclick="window.open(\'' + ga.url + '\');return false;"' +
|
116
|
+
' target="_blank" ' +
|
117
|
+
'>' +
|
118
|
+
inner_text + '</a>';
|
119
|
+
|
120
|
+
}
|
121
|
+
|
122
|
+
function google_afd_ad_request_done(google_afd_response) {
|
123
|
+
if(google_afd_response.faillisted==true){
|
124
|
+
jscript_log('faillisted', 10, JSON.stringify(google_afd_response), "/")
|
125
|
+
}
|
126
|
+
if(google_afd_response.token || google_afd_response.ads){
|
127
|
+
|
128
|
+
global_afd_response = google_afd_response;
|
129
|
+
if(google_afd_response.feedback_url){
|
130
|
+
google_about_url = google_afd_response.feedback_url;
|
131
|
+
}
|
132
|
+
|
133
|
+
if (google_afd_response.ads && google_afd_response.ads.length > 0) {
|
134
|
+
var google_ads = google_afd_response.ads;
|
135
|
+
for (var i = 0; i < google_ads.length; i++) {
|
136
|
+
seller_ratings = google_ads[i].seller_ratings;
|
137
|
+
site_links = google_ads[i].sitelinks;
|
138
|
+
ads="";
|
139
|
+
ads +=
|
140
|
+
'<div class="listing"><div class="url">' +
|
141
|
+
gadlink(google_ads[i], google_ads[i].line1, google_ads[i].visible_url) +
|
142
|
+
'</div>';
|
143
|
+
if (seller_ratings) {
|
144
|
+
ads += '<div class="ratings">'+seller_ratings.advertiser_info+' <img src="/assets/'+seller_ratings.rating+'star.gif" border="0"> <a href="'+seller_ratings.source_url+'" target="_blank">('+seller_ratings.review_count+')</a></div>';
|
145
|
+
}
|
146
|
+
ads +=
|
147
|
+
'<div class="description">' + google_ads[i].line2 + ' ' +
|
148
|
+
(google_ads[i].line3 != undefined ? google_ads[i].line3 + '' : '') +
|
149
|
+
'</div>' +
|
150
|
+
'<div class="host">' +
|
151
|
+
gadlink(google_ads[i], google_ads[i].visible_url, google_ads[i].visible_url) +
|
152
|
+
'</div>';
|
153
|
+
if (site_links && site_links.length > 0) {
|
154
|
+
ads += '<table class="sitelinks" cellpadding=0 cellspacing=0 border=0>';
|
155
|
+
for (var x = 0; x < site_links.length; x++) {
|
156
|
+
if(x % 2 == 0){
|
157
|
+
ads += '<tr>';
|
158
|
+
}
|
159
|
+
ads +=
|
160
|
+
'<td class="sitelink">' +
|
161
|
+
gadlink(site_links[x], site_links[x].link_text, google_ads[i].visible_url) +
|
162
|
+
'</td>';
|
163
|
+
if(x % 2 == 1){
|
164
|
+
ads += '</tr>';
|
165
|
+
}
|
166
|
+
}
|
167
|
+
if(x % 2 == 0){
|
168
|
+
ads += '</tr>';
|
169
|
+
}
|
170
|
+
ads += '</table>';
|
171
|
+
}
|
172
|
+
|
173
|
+
ads += '</div>';
|
174
|
+
if(google_ads[i].position=="Top"){
|
175
|
+
ads_array.push(ads);
|
176
|
+
}else{
|
177
|
+
bottom_ads_array.push(ads);
|
178
|
+
}
|
179
|
+
}
|
180
|
+
}
|
181
|
+
|
182
|
+
if (google_afd_response.categories && google_afd_response.categories.length > 0) {
|
183
|
+
var google_categories = google_afd_response.categories;
|
184
|
+
for (var i = 0; i < google_categories.length; i++) {
|
185
|
+
subcats = google_categories[i].subcategories;
|
186
|
+
popularCategories =
|
187
|
+
'<div class="termgroup">' +
|
188
|
+
'<h3><a class="popular_category" ' +
|
189
|
+
'href="/#' + google_categories[i].term + '"' +
|
190
|
+
' onclick="window.location=\'/results' +
|
191
|
+
'?q=' + encodeURIComponent(google_categories[i].term) +
|
192
|
+
'&token=' + google_categories[i].token + '\';return false;"' +
|
193
|
+
'>' +
|
194
|
+
google_categories[i].term +
|
195
|
+
'</a></h3>';
|
196
|
+
for(var gci =0; gci < subcats.length; gci++){
|
197
|
+
popularCategories = popularCategories +
|
198
|
+
'<div class="term">' +
|
199
|
+
'<a class="popular_category" ' +
|
200
|
+
'href="/#' + subcats[gci].term + '"' +
|
201
|
+
' onclick="window.location=\'/results' +
|
202
|
+
'?q=' + encodeURIComponent(subcats[gci].term) +
|
203
|
+
'&token=' + subcats[gci].token + '\';return false;"' +
|
204
|
+
'>' +
|
205
|
+
subcats[gci].term +
|
206
|
+
'</a></div>';
|
207
|
+
}
|
208
|
+
popularCategories = popularCategories + '</div>';
|
209
|
+
popularCategories_array.push(popularCategories);
|
210
|
+
}
|
211
|
+
}
|
212
|
+
|
213
|
+
if (google_afd_response.link_units && google_afd_response.link_units.length > 0) {
|
214
|
+
var google_link_units = google_afd_response.link_units;
|
215
|
+
for (var i = 0; i < google_link_units.length; i++) {
|
216
|
+
relatedSearches =
|
217
|
+
'<div class="term">' +
|
218
|
+
'<a class="related_searches" ' +
|
219
|
+
'href="/#' + google_link_units[i].term + '"' +
|
220
|
+
' onclick="window.location=\'/results' +
|
221
|
+
'?q=' + encodeURIComponent(google_link_units[i].term) +
|
222
|
+
'&token=' + google_link_units[i].token + '\';return false;"' +
|
223
|
+
'>' +
|
224
|
+
google_link_units[i].term +
|
225
|
+
'</a>' +
|
226
|
+
'</div>';
|
227
|
+
relatedSearches_array.push(relatedSearches);
|
228
|
+
}
|
229
|
+
|
230
|
+
}
|
231
|
+
if (google_afd_response.link_units && google_afd_response.link_units.length > 0) {
|
232
|
+
var google_link_units = google_afd_response.link_units;
|
233
|
+
for (var i = 0; i < google_link_units.length; i++) {
|
234
|
+
relatedSearches = "";
|
235
|
+
if(i % 5 == 0){
|
236
|
+
relatedSearches += "<div class='termgroup'>";
|
237
|
+
}
|
238
|
+
relatedSearches +=
|
239
|
+
'<div class="term">' +
|
240
|
+
'<a class="related_searches" ' +
|
241
|
+
'href="/#' + google_link_units[i].term + '"' +
|
242
|
+
' onclick="window.location=\'/results' +
|
243
|
+
'?q=' + encodeURIComponent(google_link_units[i].term) +
|
244
|
+
'&token=' + google_link_units[i].token + '\';return false;"' +
|
245
|
+
'>' +
|
246
|
+
google_link_units[i].term +
|
247
|
+
'</a>' +
|
248
|
+
'</div>';
|
249
|
+
if(((i % 5) == 4) || ((i-1)==google_link_units.length)){
|
250
|
+
relatedSearches += "</div>";
|
251
|
+
}
|
252
|
+
if(((i+1) % 10 == 0)){
|
253
|
+
relatedSearches += "<div class='clear'> </div>";
|
254
|
+
}
|
255
|
+
genCatSearches_array.push(relatedSearches);
|
256
|
+
}
|
257
|
+
|
258
|
+
}
|
259
|
+
try{document.getElementById('results').innerHTML = ads_array.join("\n");}catch(error){}
|
260
|
+
try{document.getElementById('bottomresults').innerHTML = bottom_ads_array.join("\n");}catch(error){}
|
261
|
+
|
262
|
+
if(ads_array.length>1){
|
263
|
+
document.getElementById('sponsoredresults').style.display='block';
|
264
|
+
}
|
265
|
+
if(bottom_ads_array.length>1){
|
266
|
+
document.getElementById('bottomsponsoredresults').style.display='block';
|
267
|
+
}
|
268
|
+
|
269
|
+
try{document.getElementById('keywords').innerHTML = relatedSearches_array.join("\n");}catch(error){}
|
270
|
+
try{document.getElementById('gencats').innerHTML = genCatSearches_array.join("\n");}catch(error){}
|
271
|
+
// if(genCatSearches_array.length==0){
|
272
|
+
// try{
|
273
|
+
// document.getElementById('gencats').innerHTML = popularCategories_array.join("\n");
|
274
|
+
// }catch(error){}
|
275
|
+
// }
|
276
|
+
try{document.getElementById('popcats').innerHTML = popularCategories_array.join("\n");}catch(error){}
|
277
|
+
try{document.getElementById('token').value = google_afd_response.search_token;}catch(error){}
|
278
|
+
console.log(google_afd_response);
|
279
|
+
try{document.getElementById('token2').value = google_afd_response.search_token;}catch(error){}
|
280
|
+
}
|
281
|
+
}
|
282
|
+
|
283
|
+
function getParam(name) {
|
284
|
+
var match = new RegExp('[\?&]' + name + "=([^&]+)","i").exec(location.search);
|
285
|
+
if (match==null) return null;
|
286
|
+
else return decodeURIComponent(match[1]).replace(/\+/g,' ');
|
287
|
+
}
|
288
|
+
</script>
|
289
|
+
|
290
|
+
|
291
|
+
|
292
|
+
<center>
|
293
|
+
<div id="container">
|
294
|
+
<div id="header">
|
295
|
+
<div class="logo">
|
296
|
+
<a href="./example_files/example.html">Foo.com</a>
|
297
|
+
</div>
|
298
|
+
</div>
|
299
|
+
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
|
306
|
+
<div id="main">
|
307
|
+
<div class="image">
|
308
|
+
<img alt="Cordovabeach" border="0" src="./example_files/cordovabeach.jpg">
|
309
|
+
</div>
|
310
|
+
<div class="search">
|
311
|
+
<div class="catch_phrase">
|
312
|
+
<div id="wysiwyg_id_322" class="mercury-region" data-type="editable">Search FOO.com
|
313
|
+
</div>
|
314
|
+
</div>
|
315
|
+
<div id="search">
|
316
|
+
<form action="http://www.foo.com/results" method="/get">
|
317
|
+
<input class="search_field" name="q" type="text">
|
318
|
+
<input id="token" name="token" type="hidden" value="AG06ipADDhq1IogUPtnbN7KiSVdr6HlXngoTCITm8PO41bICFSENtAodnwEA0RgDIAA4AUCwAlCUjqIBUIO6sAhQ4a65DlDN_pgPUOK53A9Qqo3jD1C1q_YPUM3B_g9QivCIEVCU-qcTUIfrhBtQx4yNHVCsxv8eUPD02SBQ1PXZIFDd2ZEhUIOcrSlQu5ytKVDSsa0pUPKxrSlQ3KCvKVCTnKYtULKU5y1QsKX8U1CTtJSVAVDL74OWAVDqp6KyAVCslfPAAVC6lfPAAVCOl_PAAVCYrMGbA1DlhNOdA2iUjqIBcQL5qk1K1hZJggETCOW09_O41bICFfILtAodzTkAq5EBp8Lq2utL_VI">
|
319
|
+
<input class="search_button" type="submit" value="Search">
|
320
|
+
</form>
|
321
|
+
</div>
|
322
|
+
|
323
|
+
</div>
|
324
|
+
</div>
|
325
|
+
|
326
|
+
<div id="footer">
|
327
|
+
<a href="http://www.foo.com/digimedia_privacy_policy.html" target="_blank">Privacy Policy</a>
|
328
|
+
-
|
329
|
+
© 2012 Digimedia.com, L.P.
|
330
|
+
</div>
|
331
|
+
|
332
|
+
</div>
|
333
|
+
</center>
|
334
|
+
<script type="text/javascript">
|
335
|
+
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
|
336
|
+
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
|
337
|
+
</script><script src="./example_files/ga.js" type="text/javascript"></script>
|
338
|
+
<script type="text/javascript">
|
339
|
+
var pageTracker = _gat._getTracker('UA-1726084-83');
|
340
|
+
pageTracker._initData();
|
341
|
+
pageTracker._setDomainName('foo.com');
|
342
|
+
pageTracker._trackPageview('/');
|
343
|
+
</script>
|
344
|
+
|
345
|
+
<script>
|
346
|
+
google_tag = 'dp-digimedia_js';
|
347
|
+
var google_afd_request = {
|
348
|
+
client: 'ca-dp-digimedia-rs_js',
|
349
|
+
domain_name: 'www.foo.com',
|
350
|
+
num_ads: 0,
|
351
|
+
num_radlinks: 10,
|
352
|
+
token: getParam('token'),
|
353
|
+
q: getParam('q'),
|
354
|
+
kw: 'foo',
|
355
|
+
channel: 'afsonly'
|
356
|
+
}
|
357
|
+
</script>
|
358
|
+
<script language="JavaScript" src="./example_files/show_afd_ads.js" type="text/javascript"></script><script src="./example_files/domainpark.cgi"></script>
|
359
|
+
|
360
|
+
|
361
|
+
|
362
|
+
|
363
|
+
</body></html>
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe LinkThumbnailer::Fetcher do
|
4
|
+
|
5
|
+
it { should respond_to :fetch }
|
6
|
+
|
7
|
+
let(:fetcher) { LinkThumbnailer::Fetcher.new }
|
8
|
+
|
9
|
+
describe ".fetch" do
|
10
|
+
|
11
|
+
before do
|
12
|
+
LinkThumbnailer.configure {|config| config.redirect_count = 3}
|
13
|
+
end
|
14
|
+
|
15
|
+
context "when redirect_count is more than config" do
|
16
|
+
|
17
|
+
it { lambda { fetcher.fetch('http://foo.com', 10) }.should raise_exception(ArgumentError) }
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
context "when no http error" do
|
22
|
+
|
23
|
+
before do
|
24
|
+
stub_request(:get, 'http://foo.com/').to_return(:status => 200, :body => 'foo', :headers => {})
|
25
|
+
end
|
26
|
+
|
27
|
+
subject { fetcher.fetch('http://foo.com') }
|
28
|
+
|
29
|
+
it { should eq('foo') }
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
context "when http error" do
|
34
|
+
|
35
|
+
before do
|
36
|
+
stub_request(:get, 'http://foo.com/').to_return(:status => 500, :body => 'foo', :headers => {})
|
37
|
+
end
|
38
|
+
|
39
|
+
it { lambda { fetcher.fetch('http://foo.com') }.should raise_exception(Net::HTTPFatalError) }
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe LinkThumbnailer::ImgUrlFilter do
|
4
|
+
|
5
|
+
it { should respond_to :reject? }
|
6
|
+
|
7
|
+
describe ".reject?" do
|
8
|
+
|
9
|
+
let(:img_url_filter) { LinkThumbnailer::ImgUrlFilter.new }
|
10
|
+
|
11
|
+
before do
|
12
|
+
LinkThumbnailer.configure {|config| config.blacklist_urls = [
|
13
|
+
%r{^http://not_valid\.net/}
|
14
|
+
]}
|
15
|
+
end
|
16
|
+
|
17
|
+
context "when img_url does not contain any blacklisted urls" do
|
18
|
+
|
19
|
+
it { img_url_filter.reject?('http://valid.com/foo/bar.png').should be_false }
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
context "when img_url does contain any blacklisted urls" do
|
24
|
+
|
25
|
+
it { img_url_filter.reject?('http://not_valid.net/foo/bar.png').should be_true }
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -2,7 +2,8 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe LinkThumbnailer do
|
4
4
|
|
5
|
-
let(:og_example)
|
5
|
+
let(:og_example) { File.open(File.dirname(__FILE__) + '/examples/og_example.html').read() }
|
6
|
+
let(:example) { File.open(File.dirname(__FILE__) + '/examples/example.html').read() }
|
6
7
|
|
7
8
|
it { should respond_to :configuration }
|
8
9
|
it { should respond_to :configure }
|
@@ -99,7 +100,7 @@ describe LinkThumbnailer do
|
|
99
100
|
subject { LinkThumbnailer.generate('http://zerply.com') }
|
100
101
|
|
101
102
|
it { should_not be_nil }
|
102
|
-
it {
|
103
|
+
it { should be_valid }
|
103
104
|
|
104
105
|
end
|
105
106
|
|
@@ -116,7 +117,7 @@ describe LinkThumbnailer do
|
|
116
117
|
subject { LinkThumbnailer.generate('foo') }
|
117
118
|
|
118
119
|
it { should_not be_nil }
|
119
|
-
it {
|
120
|
+
it { should be_valid }
|
120
121
|
|
121
122
|
end
|
122
123
|
|
@@ -129,7 +130,7 @@ describe LinkThumbnailer do
|
|
129
130
|
subject { LinkThumbnailer.generate('http://zerply.com') }
|
130
131
|
|
131
132
|
it { should_not be_nil }
|
132
|
-
it {
|
133
|
+
it { should be_valid }
|
133
134
|
|
134
135
|
end
|
135
136
|
|
data/spec/object_spec.rb
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe LinkThumbnailer::Object do
|
4
|
+
|
5
|
+
it { should respond_to :valid? }
|
6
|
+
|
7
|
+
let(:object) { LinkThumbnailer::Object.new }
|
8
|
+
|
9
|
+
describe ".method_missing" do
|
10
|
+
|
11
|
+
before do
|
12
|
+
object[:foo] = 'foo'
|
13
|
+
end
|
14
|
+
|
15
|
+
subject { object }
|
16
|
+
|
17
|
+
it { subject.foo.should eq('foo') }
|
18
|
+
it { subject.foo?.should be_true }
|
19
|
+
it { subject.bar.should be_nil }
|
20
|
+
it { subject.bar?.should be_false }
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
describe ".valid" do
|
25
|
+
|
26
|
+
before do
|
27
|
+
LinkThumbnailer.configure {|config|}
|
28
|
+
end
|
29
|
+
|
30
|
+
context "when strict" do
|
31
|
+
|
32
|
+
before do
|
33
|
+
LinkThumbnailer.configure { |config| config.strict = true }
|
34
|
+
end
|
35
|
+
|
36
|
+
context "and valid" do
|
37
|
+
|
38
|
+
before do
|
39
|
+
LinkThumbnailer.configuration.mandatory_attributes.each { |a| object[a] = 'foo' }
|
40
|
+
end
|
41
|
+
|
42
|
+
subject { object }
|
43
|
+
|
44
|
+
it { should be_valid }
|
45
|
+
it { subject.keys.should eq(LinkThumbnailer.configuration.mandatory_attributes) }
|
46
|
+
it { subject.values.should include 'foo' }
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
context "and not valid" do
|
51
|
+
|
52
|
+
subject { object }
|
53
|
+
|
54
|
+
it { should_not be_valid }
|
55
|
+
it { subject.keys.should be_empty }
|
56
|
+
it { subject.values.should be_empty }
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
context "when not strict" do
|
63
|
+
|
64
|
+
before do
|
65
|
+
LinkThumbnailer.configure { |config| config.strict = false }
|
66
|
+
end
|
67
|
+
|
68
|
+
context "and empty" do
|
69
|
+
|
70
|
+
subject { object }
|
71
|
+
|
72
|
+
it { should_not be_valid }
|
73
|
+
it { subject.keys.should be_empty }
|
74
|
+
it { subject.values.should be_empty }
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
context "and not empty" do
|
79
|
+
|
80
|
+
before do
|
81
|
+
object[:foo] = 'foo'
|
82
|
+
end
|
83
|
+
|
84
|
+
subject { object }
|
85
|
+
|
86
|
+
it { should be_valid }
|
87
|
+
it { subject.foo.should eq('foo') }
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe LinkThumbnailer::WebImage do
|
4
|
+
|
5
|
+
class Foo
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:foo) { Foo.new }
|
9
|
+
|
10
|
+
before do
|
11
|
+
foo.extend LinkThumbnailer::WebImage
|
12
|
+
end
|
13
|
+
|
14
|
+
subject { foo }
|
15
|
+
|
16
|
+
it { should respond_to :to_json }
|
17
|
+
it { should respond_to :source_url }
|
18
|
+
it { should respond_to :doc }
|
19
|
+
|
20
|
+
describe ".to_json" do
|
21
|
+
|
22
|
+
context "with default attributes" do
|
23
|
+
|
24
|
+
let(:attributes) { %w(source_url) }
|
25
|
+
|
26
|
+
subject { foo.to_json }
|
27
|
+
|
28
|
+
it { JSON.parse(subject).first.keys.should eq(attributes) }
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
context "with all attributes" do
|
33
|
+
|
34
|
+
let(:attributes) { %w(source_url mime_type density colums rows filesize number_colors) }
|
35
|
+
|
36
|
+
before do
|
37
|
+
attributes.each {|a| foo.class.send(:define_method, a.to_sym) { 'foo' } }
|
38
|
+
end
|
39
|
+
|
40
|
+
subject { foo.to_json }
|
41
|
+
|
42
|
+
it { puts JSON.parse(subject).map {|e| e.keys.first }.should eq(attributes) }
|
43
|
+
it { puts JSON.parse(subject).map {|e| e.values.first }.should include('foo') }
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: link_thumbnailer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
@@ -75,6 +75,22 @@ dependencies:
|
|
75
75
|
- - ~>
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: 2.13.1
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: json
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 1.7.5
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 1.7.5
|
78
94
|
- !ruby/object:Gem::Dependency
|
79
95
|
name: rspec
|
80
96
|
requirement: !ruby/object:Gem::Requirement
|
@@ -136,9 +152,18 @@ files:
|
|
136
152
|
- lib/link_thumbnailer/version.rb
|
137
153
|
- lib/link_thumbnailer/web_image.rb
|
138
154
|
- link_thumbnailer.gemspec
|
155
|
+
- spec/doc_parser_spec.rb
|
156
|
+
- spec/doc_spec.rb
|
157
|
+
- spec/examples/example.html
|
139
158
|
- spec/examples/og_example.html
|
159
|
+
- spec/fetcher_spec.rb
|
160
|
+
- spec/img_comparator_spec.rb
|
161
|
+
- spec/img_url_filter_spec.rb
|
140
162
|
- spec/link_thumbnailer_spec.rb
|
163
|
+
- spec/object_spec.rb
|
164
|
+
- spec/opengraph_spec.rb
|
141
165
|
- spec/spec_helper.rb
|
166
|
+
- spec/web_image_spec.rb
|
142
167
|
homepage: https://github.com/gottfrois/link_thumbnailer
|
143
168
|
licenses: []
|
144
169
|
post_install_message:
|
@@ -165,6 +190,15 @@ specification_version: 3
|
|
165
190
|
summary: Ruby gem ranking images from a given URL returning an object containing images
|
166
191
|
and website informations.
|
167
192
|
test_files:
|
193
|
+
- spec/doc_parser_spec.rb
|
194
|
+
- spec/doc_spec.rb
|
195
|
+
- spec/examples/example.html
|
168
196
|
- spec/examples/og_example.html
|
197
|
+
- spec/fetcher_spec.rb
|
198
|
+
- spec/img_comparator_spec.rb
|
199
|
+
- spec/img_url_filter_spec.rb
|
169
200
|
- spec/link_thumbnailer_spec.rb
|
201
|
+
- spec/object_spec.rb
|
202
|
+
- spec/opengraph_spec.rb
|
170
203
|
- spec/spec_helper.rb
|
204
|
+
- spec/web_image_spec.rb
|