onebox 1.5.43 → 1.5.44
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -2
- data/lib/onebox/engine/amazon_onebox.rb +3 -4
- data/lib/onebox/engine/stack_exchange_onebox.rb +14 -4
- data/lib/onebox/engine/whitelisted_generic_onebox.rb +2 -1
- data/lib/onebox/version.rb +1 -1
- data/spec/fixtures/stackexchange-answer.response +1 -0
- data/spec/fixtures/stackexchange-question.response +1 -0
- data/spec/lib/onebox/engine/amazon_onebox_spec.rb +14 -14
- data/spec/lib/onebox/engine/json_spec.rb +1 -1
- data/spec/lib/onebox/engine/stack_exchange_onebox_spec.rb +90 -10
- data/spec/lib/onebox/preview_spec.rb +7 -7
- data/spec/lib/onebox_spec.rb +10 -3
- data/templates/_layout.mustache +1 -1
- data/templates/amazon.mustache +2 -2
- data/templates/douban.mustache +1 -1
- data/templates/stackexchange.mustache +3 -1
- data/templates/twitterstatus.mustache +1 -1
- data/templates/whitelistedgeneric.mustache +1 -1
- data/templates/wikipedia.mustache +1 -1
- metadata +6 -5
- data/spec/fixtures/stackexchange.response +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 582db3162e74f04ce27959dbef0e385e27621406
|
4
|
+
data.tar.gz: 026c67c405e0e80fb0ceb1c7553eed6c724eb170
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1bce5e96adfaecb9ffd25c014f0e96b501e32738965b12a3fd3458b3a619dc5fe82718bfc7e6c6d4fd3de0745d97db5eda460c6e99dd50e4ec7d70b643e04e33
|
7
|
+
data.tar.gz: 37eaee6c5aab1784e5af0d6ca086de9eb9aa8c18de8bf46e59f36ec845895e406db5c3e12b334c9f5d9a57eb382e1cd21f328533938679ec10e5700fab67a228
|
data/.rubocop.yml
CHANGED
@@ -7,15 +7,14 @@ module Onebox
|
|
7
7
|
include LayoutSupport
|
8
8
|
include HTML
|
9
9
|
|
10
|
-
|
10
|
+
always_https
|
11
11
|
matches_regexp(/^https?:\/\/(?:www)\.amazon\.(?<tld>com|ca|de|it|es|fr|co\.jp|co\.uk|cn|in|com\.br)\//)
|
12
12
|
|
13
13
|
def url
|
14
14
|
if match && match[:id]
|
15
|
-
|
16
|
-
_url.scheme = URI(@url).scheme
|
17
|
-
return _url.to_s
|
15
|
+
return "https://www.amazon.#{tld}/gp/aw/d/#{URI::encode(match[:id])}"
|
18
16
|
end
|
17
|
+
|
19
18
|
@url
|
20
19
|
end
|
21
20
|
|
@@ -6,10 +6,11 @@ module Onebox
|
|
6
6
|
include JSON
|
7
7
|
|
8
8
|
def self.domains
|
9
|
-
%w(stackexchange stackoverflow superuser serverfault askubuntu)
|
9
|
+
%w(stackexchange.com stackoverflow.com superuser.com serverfault.com askubuntu.com stackapps.com mathoverflow.net)
|
10
|
+
.map { |domain| Regexp.escape(domain) }
|
10
11
|
end
|
11
12
|
|
12
|
-
matches_regexp /^https?:\/\/(?:(?:(?<subsubdomain>\w*)\.)?(?<subdomain>\w*)\.)?(?<domain>#{domains.join('|')})
|
13
|
+
matches_regexp /^https?:\/\/(?:(?:(?<subsubdomain>\w*)\.)?(?<subdomain>\w*)\.)?(?<domain>#{domains.join('|')})\/((?:questions|q)\/(?<question_id>\d*)(\/.*\/(?<answer_id1>\d*))?|(a\/(?<answer_id2>\d*)))/
|
13
14
|
|
14
15
|
def always_https?
|
15
16
|
uri.host.split('.').length <= 3
|
@@ -23,7 +24,14 @@ module Onebox
|
|
23
24
|
|
24
25
|
def url
|
25
26
|
domain = URI(@url).host
|
26
|
-
|
27
|
+
question_id = match[:question_id]
|
28
|
+
answer_id = match[:answer_id2] || match[:answer_id1]
|
29
|
+
|
30
|
+
if answer_id
|
31
|
+
"https://api.stackexchange.com/2.2/answers/#{answer_id}?site=#{domain}&filter=!.FjueITQdx6-Rq3Ue9PWG.QZ2WNdW"
|
32
|
+
else
|
33
|
+
"https://api.stackexchange.com/2.2/questions/#{question_id}?site=#{domain}&filter=!5-duuxrJa-iw9oVvOA(JNimB5VIisYwZgwcfNI"
|
34
|
+
end
|
27
35
|
end
|
28
36
|
|
29
37
|
def data
|
@@ -32,9 +40,11 @@ module Onebox
|
|
32
40
|
result = raw['items'][0]
|
33
41
|
if result
|
34
42
|
result['creation_date'] =
|
35
|
-
|
43
|
+
Time.at(result['creation_date'].to_i).strftime("%I:%M%p - %d %b %y")
|
36
44
|
|
37
45
|
result['tags'] = result['tags'].take(4).join(', ')
|
46
|
+
result['is_answer'] = result.key?('answer_id')
|
47
|
+
result['is_question'] = result.key?('question_id')
|
38
48
|
end
|
39
49
|
@data = result
|
40
50
|
end
|
data/lib/onebox/version.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
{"items":[{"tags":["c","deobfuscation"],"owner":{"profile_image":"https://www.gravatar.com/avatar/4af3541c00d591e9a518b9c0b3b1190a?s=128&d=identicon&r=PG","display_name":"dasblinkenlight","link":"http://stackoverflow.com/users/335858/dasblinkenlight"},"last_activity_date":1461433376,"creation_date":1375356813,"answer_id":17992906,"link":"http://stackoverflow.com/questions/17992553/concept-behind-these-four-lines-of-tricky-c-code/17992906#17992906","title":"Concept behind these four lines of tricky C code"}],"has_more":false,"quota_max":300,"quota_remaining":291}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"items":[{"tags":["c","deobfuscation"],"owner":{"profile_image":"https://www.gravatar.com/avatar/a19d396231d67d604c92866b90fe723d?s=128&d=identicon&r=PG","display_name":"codeslayer1","link":"http://stackoverflow.com/users/2547190/codeslayer1"},"last_activity_date":1461433376,"creation_date":1375355768,"question_id":17992553,"link":"http://stackoverflow.com/questions/17992553/concept-behind-these-four-lines-of-tricky-c-code","title":"Concept behind these four lines of tricky C code"}],"has_more":false,"quota_max":300,"quota_remaining":292}
|
@@ -2,8 +2,8 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Onebox::Engine::AmazonOnebox do
|
4
4
|
before(:all) do
|
5
|
-
@link = "
|
6
|
-
@uri = "
|
5
|
+
@link = "https://www.amazon.com/Knit-Noro-Accessories-Colorful-Little/dp/193609620X"
|
6
|
+
@uri = "https://www.amazon.com/gp/aw/d/193609620X"
|
7
7
|
end
|
8
8
|
|
9
9
|
include_context "engines"
|
@@ -14,47 +14,47 @@ describe Onebox::Engine::AmazonOnebox do
|
|
14
14
|
def check_link(tdl, link)
|
15
15
|
onebox_cls = Onebox::Matcher.new(link).oneboxed
|
16
16
|
expect(onebox_cls).to_not be(nil)
|
17
|
-
expect(onebox_cls.new(link).url).to include("
|
17
|
+
expect(onebox_cls.new(link).url).to include("https://www.amazon.#{tdl}")
|
18
18
|
end
|
19
19
|
|
20
20
|
it "matches canadian domains" do
|
21
|
-
check_link("ca", "
|
21
|
+
check_link("ca", "https://www.amazon.ca/Too-Much-Happiness-Alice-Munro-ebook/dp/B0031TZ98K/")
|
22
22
|
end
|
23
23
|
|
24
24
|
it "matches german domains" do
|
25
|
-
check_link("de", "
|
25
|
+
check_link("de", "https://www.amazon.de/Buddenbrooks-Verfall-einer-Familie-Roman/dp/3596294312/")
|
26
26
|
end
|
27
27
|
|
28
28
|
it "matches uk domains" do
|
29
|
-
check_link("co.uk", "
|
29
|
+
check_link("co.uk", "https://www.amazon.co.uk/Pygmalion-George-Bernard-Shaw/dp/1420925237/")
|
30
30
|
end
|
31
31
|
|
32
32
|
it "matches japanese domains" do
|
33
|
-
check_link("co.jp", "
|
33
|
+
check_link("co.jp", "https://www.amazon.co.jp/%E9%9B%AA%E5%9B%BD-%E6%96%B0%E6%BD%AE%E6%96%87%E5%BA%AB-%E3%81%8B-1-1-%E5%B7%9D%E7%AB%AF-%E5%BA%B7%E6%88%90/dp/4101001014/")
|
34
34
|
end
|
35
35
|
|
36
36
|
it "matches chinese domains" do
|
37
|
-
check_link("cn", "
|
37
|
+
check_link("cn", "https://www.amazon.cn/%E5%AD%99%E5%AD%90%E5%85%B5%E6%B3%95-%E5%AD%99%E8%86%91%E5%85%B5%E6%B3%95-%E5%AD%99%E6%AD%A6/dp/B0011C40FC/")
|
38
38
|
end
|
39
39
|
|
40
40
|
it "matches french domains" do
|
41
|
-
check_link("fr", "
|
41
|
+
check_link("fr", "https://www.amazon.fr/Les-Mots-autres-%C3%A9crits-autobiographiques/dp/2070114147/")
|
42
42
|
end
|
43
43
|
|
44
44
|
it "matches italian domains" do
|
45
|
-
check_link("it", "
|
45
|
+
check_link("it", "https://www.amazon.it/Tutte-poesie-Salvatore-Quasimodo/dp/8804520477/")
|
46
46
|
end
|
47
47
|
|
48
48
|
it "matches spanish domains" do
|
49
|
-
check_link("es", "
|
49
|
+
check_link("es", "https://www.amazon.es/familia-Pascual-Duarte-Camilo-Jos%C3%A9-ebook/dp/B00EJRTKTW/")
|
50
50
|
end
|
51
51
|
|
52
52
|
it "matches brasilian domains" do
|
53
|
-
check_link("com.br", "
|
53
|
+
check_link("com.br", "https://www.amazon.com.br/A-p%C3%A1tria-chuteiras-Nelson-Rodrigues-ebook/dp/B00J2B414Y/")
|
54
54
|
end
|
55
55
|
|
56
56
|
it "matches indian domains" do
|
57
|
-
check_link("in", "
|
57
|
+
check_link("in", "https://www.amazon.in/Fireflies-Rabindranath-Tagore/dp/9381523169/")
|
58
58
|
end
|
59
59
|
|
60
60
|
end
|
@@ -65,7 +65,7 @@ describe Onebox::Engine::AmazonOnebox do
|
|
65
65
|
.to eq("https://www.amazon.fr/gp/aw/d/B01BYD0TZM")
|
66
66
|
|
67
67
|
expect(described_class.new("http://www.amazon.fr/gp/product/B01BYD0TZM").url)
|
68
|
-
.to eq("
|
68
|
+
.to eq("https://www.amazon.fr/gp/aw/d/B01BYD0TZM")
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
@@ -1,17 +1,97 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Onebox::Engine::StackExchangeOnebox do
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
describe 'domains' do
|
5
|
+
[
|
6
|
+
'stackoverflow.com', 'meta.stackoverflow.com',
|
7
|
+
'superuser.com', 'meta.superuser.com',
|
8
|
+
'serverfault.com', 'meta.serverfault.com',
|
9
|
+
'askubuntu.com', 'meta.askubuntu.com',
|
10
|
+
'mathoverflow.net', 'meta.mathoverflow.net',
|
11
|
+
'money.stackexchange.com', 'meta.money.stackexchange.com',
|
12
|
+
'stackapps.com'
|
13
|
+
].each do |domain|
|
14
|
+
it "matches question with short URL on #{domain}" do
|
15
|
+
expect(described_class === URI("http://#{domain}/q/55495")).to eq(true)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "matches question with long URL on #{domain}" do
|
19
|
+
expect(described_class === URI("http://#{domain}/questions/55495/title-of-question")).to eq(true)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "matches answer with short URL on #{domain}" do
|
23
|
+
expect(described_class === URI("http://#{domain}/a/55503")).to eq(true)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "matches question with long URL on #{domain}" do
|
27
|
+
expect(described_class === URI("http://#{domain}/questions/55495/title-of-question/55503#55503")).to eq(true)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it "doesn't match question on example.com" do
|
32
|
+
expect(described_class === URI('http://example.com/q/4711')).to eq(false)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "doesn't match answer on example.com" do
|
36
|
+
expect(described_class === URI('http://example.com/a/4711')).to eq(false)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
{
|
41
|
+
'long URL' => 'http://stackoverflow.com/questions/17992553/concept-behind-these-four-lines-of-tricky-c-code',
|
42
|
+
'short URL'=> 'http://stackoverflow.com/q/17992553'
|
43
|
+
}.each do |name, url|
|
44
|
+
describe "question with #{name}" do
|
45
|
+
before(:all) do
|
46
|
+
@link = url
|
47
|
+
fake('https://api.stackexchange.com/2.2/questions/17992553?site=stackoverflow.com&filter=!5-duuxrJa-iw9oVvOA(JNimB5VIisYwZgwcfNI', response('stackexchange-question'))
|
48
|
+
end
|
49
|
+
|
50
|
+
include_context 'engines'
|
51
|
+
it_behaves_like 'an engine'
|
52
|
+
|
53
|
+
describe '#to_html' do
|
54
|
+
it 'includes question title' do
|
55
|
+
expect(html).to include('Concept behind these four lines of tricky C code')
|
56
|
+
end
|
57
|
+
|
58
|
+
it "includes 'asked by'" do
|
59
|
+
expect(html).to include('asked by')
|
60
|
+
end
|
61
|
+
|
62
|
+
it "doesn't include 'answered by'" do
|
63
|
+
expect(html).not_to include('answered by')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
7
67
|
end
|
8
68
|
|
9
|
-
|
10
|
-
|
69
|
+
{
|
70
|
+
'long URL' => 'http://stackoverflow.com/questions/17992553/concept-behind-these-four-lines-of-tricky-c-code/17992906#17992906',
|
71
|
+
'short URL'=> 'http://stackoverflow.com/a/17992906'
|
72
|
+
}.each do |name, url|
|
73
|
+
describe "answer with #{name}" do
|
74
|
+
before(:all) do
|
75
|
+
@link = url
|
76
|
+
fake('https://api.stackexchange.com/2.2/answers/17992906?site=stackoverflow.com&filter=!.FjueITQdx6-Rq3Ue9PWG.QZ2WNdW', response('stackexchange-answer'))
|
77
|
+
end
|
78
|
+
|
79
|
+
include_context 'engines'
|
80
|
+
it_behaves_like 'an engine'
|
81
|
+
|
82
|
+
describe '#to_html' do
|
83
|
+
it 'includes question title' do
|
84
|
+
expect(html).to include('Concept behind these four lines of tricky C code')
|
85
|
+
end
|
86
|
+
|
87
|
+
it "includes 'answered by'" do
|
88
|
+
expect(html).to include('answered by')
|
89
|
+
end
|
11
90
|
|
12
|
-
|
13
|
-
|
14
|
-
|
91
|
+
it "doesn't include 'asked by'" do
|
92
|
+
expect(html).not_to include('asked by')
|
93
|
+
end
|
94
|
+
end
|
15
95
|
end
|
16
96
|
end
|
17
|
-
end
|
97
|
+
end
|
@@ -3,13 +3,13 @@ require "spec_helper"
|
|
3
3
|
describe Onebox::Preview do
|
4
4
|
|
5
5
|
before do
|
6
|
-
fake("
|
7
|
-
FakeWeb.register_uri(:get, "
|
8
|
-
FakeWeb.register_uri(:get, "
|
9
|
-
FakeWeb.register_uri(:get, "
|
10
|
-
FakeWeb.register_uri(:get, "
|
11
|
-
FakeWeb.register_uri(:get, "
|
12
|
-
FakeWeb.register_uri(:get, "
|
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
13
|
end
|
14
14
|
|
15
15
|
let(:preview_url) { "http://www.amazon.com/product" }
|
data/spec/lib/onebox_spec.rb
CHANGED
@@ -3,11 +3,18 @@ require "spec_helper"
|
|
3
3
|
describe Onebox do
|
4
4
|
|
5
5
|
before do
|
6
|
-
fake("
|
6
|
+
fake("https://www.amazon.com/product", response("amazon"))
|
7
7
|
end
|
8
8
|
|
9
9
|
describe ".preview" do
|
10
10
|
let(:url) { "http://www.amazon.com/product" }
|
11
|
+
|
12
|
+
let(:https_url) do
|
13
|
+
uri = URI(url)
|
14
|
+
uri.scheme = 'https'
|
15
|
+
uri.to_s
|
16
|
+
end
|
17
|
+
|
11
18
|
it "creates a cache that responds as expected" do
|
12
19
|
preview = Onebox.preview(url)
|
13
20
|
cache = preview.cache
|
@@ -18,13 +25,13 @@ describe Onebox do
|
|
18
25
|
preview = Onebox.preview(url)
|
19
26
|
preview.to_s
|
20
27
|
cache = preview.cache
|
21
|
-
expect(cache.key?(
|
28
|
+
expect(cache.key?(https_url)).to eq(true)
|
22
29
|
end
|
23
30
|
|
24
31
|
it "replaces the cache if the cache is expired" do
|
25
32
|
preview = Onebox.preview(url, cache: Moneta.new(:Memory, expires: 100_000, serializer: :json))
|
26
33
|
cache = preview.cache
|
27
|
-
expect(cache.fetch(
|
34
|
+
expect(cache.fetch(https_url)).to be(nil)
|
28
35
|
end
|
29
36
|
end
|
30
37
|
|
data/templates/_layout.mustache
CHANGED
data/templates/amazon.mustache
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
<img src="{{image}}" class="thumbnail"/>
|
2
2
|
|
3
|
-
<h3><a href='{{link}}'>{{title}}</a></h3>
|
3
|
+
<h3><a href='{{link}}' target='_blank'>{{title}}</a></h3>
|
4
4
|
{{#by_info}}<b>{{by_info}}</b>{{/by_info}}
|
5
5
|
<p>{{description}}</p>
|
6
|
-
<p><strong>{{price}}
|
6
|
+
<p><strong>{{price}}</strong></p>
|
data/templates/douban.mustache
CHANGED
@@ -12,7 +12,9 @@
|
|
12
12
|
</div>
|
13
13
|
|
14
14
|
<div class="date">
|
15
|
-
asked by
|
15
|
+
{{#is_question}}asked by{{/is_question}}
|
16
|
+
{{#is_answer}}answered by{{/is_answer}}
|
17
|
+
<a href="{{owner.link}}" target="_blank">
|
16
18
|
{{owner.display_name}}
|
17
19
|
</a>
|
18
20
|
on <a href="{{link}}" target="_blank">{{creation_date}}</a>
|
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.5.
|
4
|
+
version: 1.5.44
|
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: 2016-
|
13
|
+
date: 2016-08-02 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: multi_json
|
@@ -354,7 +354,8 @@ files:
|
|
354
354
|
- spec/fixtures/pubmed-xml.response
|
355
355
|
- spec/fixtures/pubmed.response
|
356
356
|
- spec/fixtures/slides.response
|
357
|
-
- spec/fixtures/stackexchange.response
|
357
|
+
- spec/fixtures/stackexchange-answer.response
|
358
|
+
- spec/fixtures/stackexchange-question.response
|
358
359
|
- spec/fixtures/steamstorewidget.response
|
359
360
|
- spec/fixtures/twitterstatus.response
|
360
361
|
- spec/fixtures/video.response
|
@@ -454,7 +455,8 @@ test_files:
|
|
454
455
|
- spec/fixtures/pubmed-xml.response
|
455
456
|
- spec/fixtures/pubmed.response
|
456
457
|
- spec/fixtures/slides.response
|
457
|
-
- spec/fixtures/stackexchange.response
|
458
|
+
- spec/fixtures/stackexchange-answer.response
|
459
|
+
- spec/fixtures/stackexchange-question.response
|
458
460
|
- spec/fixtures/steamstorewidget.response
|
459
461
|
- spec/fixtures/twitterstatus.response
|
460
462
|
- spec/fixtures/video.response
|
@@ -495,4 +497,3 @@ test_files:
|
|
495
497
|
- spec/lib/onebox_spec.rb
|
496
498
|
- spec/spec_helper.rb
|
497
499
|
- spec/support/html_spec_helper.rb
|
498
|
-
has_rdoc:
|
@@ -1 +0,0 @@
|
|
1
|
-
{"items":[{"tags":["c++","c","deobfuscation"],"owner":{"reputation":860,"user_id":2547190,"user_type":"registered","profile_image":"https://www.gravatar.com/avatar/a19d396231d67d604c92866b90fe723d?s=128&d=identicon&r=PG","display_name":"detonator123","link":"http://stackoverflow.com/users/2547190/detonator123"},"is_answered":true,"view_count":12676,"protected_date":1375930784,"accepted_answer_id":17992906,"answer_count":9,"score":244,"last_activity_date":1375930729,"creation_date":1375355768,"last_edit_date":1375645180,"question_id":17992553,"link":"http://stackoverflow.com/questions/17992553/concept-behind-these-four-lines-of-tricky-c-code","title":"Concept behind these four lines of tricky C++ code"}],"has_more":false,"quota_max":300,"quota_remaining":275}
|