onebox 1.8.25 → 1.8.26

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
- SHA256:
3
- metadata.gz: 442e01fb4f1bcf4b312f8dbdcd3b71e7c4bde332d4f0ca381d01eaf3f37fff84
4
- data.tar.gz: 5cd1e9cc178e664a27d8d93244bb7162b0f8d483008d6505dc2a9c29e41c6220
2
+ SHA1:
3
+ metadata.gz: 46a7ed36caa2a4739734bac88039bf5112e82237
4
+ data.tar.gz: 5567b27220d7ab70aa94b72f4769f6803043b802
5
5
  SHA512:
6
- metadata.gz: 0e71fef9fb69b35c1d7413a85dba0b233ba21e52bb12b9fa46a58b63fb7829c74a3af587bf78addb9a09e11b2e64c24a0817d2d86741f5b189f8ae960e972b84
7
- data.tar.gz: c00d0124b8cf9c214f8af312d530772347a25f78dfa2c96b82bcca3c8d39d52fc623ae87fa3f62902da8750059ffdbd39803ec243ab194f1bf8bb8c9d81fe339
6
+ metadata.gz: 18bab86adf0e4dde4e4db0990ce59898489afc3061d4b1b3b3040ae566b0a10d7d6de1651b8cf920ea408d2fdc59b0dbedc2209086a039ab33b2f67a3450b1cb
7
+ data.tar.gz: 8453cb98229163cfa8cafb92a5d5d62b605cdf64db20fac6b80f2b06ee15fdf9d7d1432e90ad3733fda573b01037a1b79a6a4db63af74cb1d3f105e8d9f69e8b
@@ -9,7 +9,7 @@ module Onebox
9
9
  end
10
10
 
11
11
  def raw
12
- @raw ||= Nokogiri::HTML(open(url, { read_timeout: timeout }.merge(http_params)).read)
12
+ @raw ||= Onebox::Helpers.fetch_html_doc(url, http_params)
13
13
  end
14
14
 
15
15
  def html?
@@ -55,21 +55,7 @@ module Onebox
55
55
  headers = nil
56
56
  headers = { 'Cookie' => options[:cookie] } if options[:cookie]
57
57
 
58
- response = (Onebox::Helpers.fetch_response(url, nil, nil, headers) rescue nil)
59
- doc = Nokogiri::HTML(response)
60
-
61
- ignore_canonical = doc.at('meta[property="og:ignore_canonical"]')
62
- unless ignore_canonical && ignore_canonical['content'].to_s == 'true'
63
- # prefer canonical link
64
- canonical_link = doc.at('//link[@rel="canonical"]/@href')
65
- if canonical_link && "#{URI(canonical_link).host}#{URI(canonical_link).path}" != "#{URI(url).host}#{URI(url).path}"
66
- response = (Onebox::Helpers.fetch_response(canonical_link, nil, nil, headers) rescue nil)
67
- doc = Nokogiri::HTML(response) if response
68
- end
69
- end
70
-
71
- @html_doc = doc
72
- @html_doc
58
+ @html_doc = Onebox::Helpers.fetch_html_doc(url, headers)
73
59
  end
74
60
 
75
61
  def get_oembed
@@ -223,22 +223,22 @@ module Onebox
223
223
  d[:video] = d[:video_secure_url] || d[:video_url] || d[:video]
224
224
 
225
225
  if !Onebox::Helpers.blank?(d[:published_time])
226
- d[:article_published_time] = Time.parse(d[:published_time]).strftime("%d %b %y")
226
+ d[:article_published_time] = Time.parse(d[:published_time]).strftime("%-d %b %y")
227
227
  d[:article_published_time_title] = Time.parse(d[:published_time]).strftime("%I:%M%p - %d %B %Y")
228
- else
229
- # Twitter labels
230
- if !Onebox::Helpers.blank?(d[:label1]) && !Onebox::Helpers.blank?(d[:data1]) && !!WhitelistedGenericOnebox.twitter_label_whitelist.find { |l| d[:label1] =~ /#{l}/i }
231
- d[:label_1] = Sanitize.fragment(Onebox::Helpers.truncate(d[:label1].strip))
232
- d[:data_1] = Sanitize.fragment(Onebox::Helpers.truncate(d[:data1].strip))
233
- end
234
- if !Onebox::Helpers.blank?(d[:label2]) && !Onebox::Helpers.blank?(d[:data2]) && !!WhitelistedGenericOnebox.twitter_label_whitelist.find { |l| d[:label2] =~ /#{l}/i }
235
- unless Onebox::Helpers.blank?(d[:label_1])
236
- d[:label_2] = Sanitize.fragment(Onebox::Helpers.truncate(d[:label2].strip))
237
- d[:data_2] = Sanitize.fragment(Onebox::Helpers.truncate(d[:data2].strip))
238
- else
239
- d[:label_1] = Sanitize.fragment(Onebox::Helpers.truncate(d[:label2].strip))
240
- d[:data_1] = Sanitize.fragment(Onebox::Helpers.truncate(d[:data2].strip))
241
- end
228
+ end
229
+
230
+ # Twitter labels
231
+ if !Onebox::Helpers.blank?(d[:label1]) && !Onebox::Helpers.blank?(d[:data1]) && !!WhitelistedGenericOnebox.twitter_label_whitelist.find { |l| d[:label1] =~ /#{l}/i }
232
+ d[:label_1] = Sanitize.fragment(Onebox::Helpers.truncate(d[:label1].strip))
233
+ d[:data_1] = Sanitize.fragment(Onebox::Helpers.truncate(d[:data1].strip))
234
+ end
235
+ if !Onebox::Helpers.blank?(d[:label2]) && !Onebox::Helpers.blank?(d[:data2]) && !!WhitelistedGenericOnebox.twitter_label_whitelist.find { |l| d[:label2] =~ /#{l}/i }
236
+ unless Onebox::Helpers.blank?(d[:label_1])
237
+ d[:label_2] = Sanitize.fragment(Onebox::Helpers.truncate(d[:label2].strip))
238
+ d[:data_2] = Sanitize.fragment(Onebox::Helpers.truncate(d[:data2].strip))
239
+ else
240
+ d[:label_1] = Sanitize.fragment(Onebox::Helpers.truncate(d[:label2].strip))
241
+ d[:data_1] = Sanitize.fragment(Onebox::Helpers.truncate(d[:data2].strip))
242
242
  end
243
243
  end
244
244
 
@@ -39,6 +39,23 @@ module Onebox
39
39
  og
40
40
  end
41
41
 
42
+ def self.fetch_html_doc(url, headers=nil)
43
+ response = (fetch_response(url, nil, nil, headers) rescue nil)
44
+ doc = Nokogiri::HTML(response)
45
+
46
+ ignore_canonical = doc.at('meta[property="og:ignore_canonical"]')
47
+ unless ignore_canonical && ignore_canonical['content'].to_s == 'true'
48
+ # prefer canonical link
49
+ canonical_link = doc.at('//link[@rel="canonical"]/@href')
50
+ if canonical_link && "#{URI(canonical_link).host}#{URI(canonical_link).path}" != "#{URI(url).host}#{URI(url).path}"
51
+ response = (fetch_response(canonical_link, nil, nil, headers) rescue nil)
52
+ doc = Nokogiri::HTML(response) if response
53
+ end
54
+ end
55
+
56
+ doc
57
+ end
58
+
42
59
  def self.fetch_response(location, limit = nil, domain = nil, headers = nil)
43
60
 
44
61
  limit ||= 5
data/lib/onebox/layout.rb CHANGED
@@ -49,27 +49,13 @@ module Onebox
49
49
  record[:domain] || URI(link || '').host.to_s.sub(/^www\./, '')
50
50
  end
51
51
 
52
- def metadata_1_label
53
- record[:metadata_1_label]
54
- end
55
-
56
- def metadata_1_value
57
- record[:metadata_1_value]
58
- end
59
-
60
- def metadata_2_label
61
- record[:metadata_2_label]
62
- end
63
-
64
- def metadata_2_value
65
- record[:metadata_2_value]
66
- end
67
-
68
52
  def details
69
53
  {
70
54
  link: record[:link],
71
55
  title: record[:title],
72
56
  domain: domain,
57
+ article_published_time: record[:article_published_time],
58
+ article_published_time_title: record[:article_published_time_title],
73
59
  metadata_1_label: record[:metadata_1_label],
74
60
  metadata_1_value: record[:metadata_1_value],
75
61
  metadata_2_label: record[:metadata_2_label],
@@ -1,3 +1,3 @@
1
1
  module Onebox
2
- VERSION = "1.8.25"
2
+ VERSION = "1.8.26"
3
3
  end
@@ -100,8 +100,7 @@ describe Onebox::Engine::WhitelistedGenericOnebox do
100
100
  onebox = described_class.new(url)
101
101
  expect(onebox.to_html).not_to be_empty
102
102
 
103
- expect(onebox.to_html).to include("Mail Online")
104
- expect(onebox.to_html).to include("08 Aug 14")
103
+ expect(onebox.to_html).to include("Mail Online - 8 Aug 14")
105
104
  end
106
105
  end
107
106
 
@@ -4,12 +4,6 @@ describe Onebox::Preview do
4
4
 
5
5
  before do
6
6
  fake("https://www.amazon.com/product", response("amazon"))
7
- FakeWeb.register_uri(:get, "https://www.amazon.com/404-url", status: 404)
8
- FakeWeb.register_uri(:get, "https://www.amazon.com/500-url", status: 500)
9
- FakeWeb.register_uri(:get, "https://www.amazon.com/error-url", status: 500)
10
- FakeWeb.register_uri(:get, "https://www.amazon.com/timeout-url", exception: Timeout::Error)
11
- FakeWeb.register_uri(:get, "https://www.amazon.com/http-error", exception: Net::HTTPError)
12
- FakeWeb.register_uri(:get, "https://www.amazon.com/error-connecting", exception: Errno::ECONNREFUSED)
13
7
  end
14
8
 
15
9
  let(:preview_url) { "http://www.amazon.com/product" }
@@ -21,26 +15,6 @@ describe Onebox::Preview do
21
15
  expect(preview.to_s).to include(title)
22
16
  end
23
17
 
24
- it "returns an empty string if the resource is missing" do
25
- expect(described_class.new("http://www.amazon.com/404-url").to_s).to eq("")
26
- end
27
-
28
- it "returns an empty string if the resource returns an error" do
29
- expect(described_class.new("http://www.amazon.com/500-url").to_s).to eq("")
30
- end
31
-
32
- it "returns an empty string if the resource times out" do
33
- expect(described_class.new("http://www.amazon.com/timeout-url").to_s).to eq("")
34
- end
35
-
36
- it "returns an empty string if there is an http error" do
37
- expect(described_class.new("http://www.amazon.com/http-error").to_s).to eq("")
38
- end
39
-
40
- it "returns an empty string if there is an error connecting" do
41
- expect(described_class.new("http://www.amazon.com/error-connecting").to_s).to eq("")
42
- end
43
-
44
18
  it "returns an empty string if the url is not valid" do
45
19
  expect(described_class.new('not a url').to_s).to eq("")
46
20
  end
@@ -1,6 +1,11 @@
1
1
  <aside class="onebox {{subname}}">
2
2
  <header class="source">
3
- <a href="{{link}}" target='_blank'>{{domain}}</a>
3
+ {{#article_published_time}}
4
+ <a href="{{link}}" target='_blank' title="{{article_published_time_title}}">{{domain}} - {{article_published_time}}</a>
5
+ {{/article_published_time}}
6
+ {{^article_published_time}}
7
+ <a href="{{link}}" target='_blank'>{{domain}}</a>
8
+ {{/article_published_time}}
4
9
  </header>
5
10
  <article class="onebox-body">
6
11
  {{{view}}}
@@ -4,10 +4,6 @@
4
4
 
5
5
  <p>{{description}}</p>
6
6
 
7
- {{#article_published_time}}
8
- <p><span class="label1" title="{{article_published_time_title}}">{{article_published_time}}</span>
9
- {{/article_published_time}}
10
-
11
7
  {{#data_1}}
12
8
  <p><span class="label1">{{label_1}}: {{data_1}}</span>
13
9
  {{#data_2}}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onebox
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.25
4
+ version: 1.8.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joanna Zeta
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-11-22 00:00:00.000000000 Z
13
+ date: 2017-11-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: multi_json
@@ -524,7 +524,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
524
524
  version: '0'
525
525
  requirements: []
526
526
  rubyforge_project:
527
- rubygems_version: 2.7.2
527
+ rubygems_version: 2.6.13
528
528
  signing_key:
529
529
  specification_version: 4
530
530
  summary: A gem for turning URLs into previews.