onebox 1.8.9 → 1.8.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/onebox/engine/amazon_onebox.rb +10 -4
- data/lib/onebox/engine/standard_embed.rb +1 -18
- data/lib/onebox/helpers.rb +21 -0
- data/lib/onebox/version.rb +1 -1
- data/spec/fixtures/amazon-og.response +3675 -0
- data/spec/lib/onebox/engine/amazon_onebox_spec.rb +85 -58
- metadata +4 -2
@@ -1,90 +1,117 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Onebox::Engine::AmazonOnebox do
|
4
|
-
before(:all) do
|
5
|
-
@link = "https://www.amazon.com/Knit-Noro-Accessories-Colorful-Little/dp/193609620X"
|
6
|
-
@uri = "https://www.amazon.com/gp/aw/d/193609620X"
|
7
|
-
end
|
8
|
-
|
9
|
-
include_context "engines"
|
10
|
-
it_behaves_like "an engine"
|
11
4
|
|
12
|
-
describe "works with international domains" do
|
13
5
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
6
|
+
context "regular amazon page" do
|
7
|
+
before do
|
8
|
+
@link = "https://www.amazon.com/Knit-Noro-Accessories-Colorful-Little/dp/193609620X"
|
9
|
+
@uri = "https://www.amazon.com/gp/aw/d/193609620X"
|
18
10
|
end
|
11
|
+
include_context "engines"
|
12
|
+
it_behaves_like "an engine"
|
19
13
|
|
20
|
-
|
21
|
-
check_link("ca", "https://www.amazon.ca/Too-Much-Happiness-Alice-Munro-ebook/dp/B0031TZ98K/")
|
22
|
-
end
|
14
|
+
describe "works with international domains" do
|
23
15
|
|
24
|
-
|
25
|
-
|
26
|
-
|
16
|
+
def check_link(tdl, link)
|
17
|
+
onebox_cls = Onebox::Matcher.new(link).oneboxed
|
18
|
+
expect(onebox_cls).to_not be(nil)
|
19
|
+
expect(onebox_cls.new(link).url).to include("https://www.amazon.#{tdl}")
|
20
|
+
end
|
27
21
|
|
28
|
-
|
29
|
-
|
30
|
-
|
22
|
+
it "matches canadian domains" do
|
23
|
+
check_link("ca", "https://www.amazon.ca/Too-Much-Happiness-Alice-Munro-ebook/dp/B0031TZ98K/")
|
24
|
+
end
|
31
25
|
|
32
|
-
|
33
|
-
|
34
|
-
|
26
|
+
it "matches german domains" do
|
27
|
+
check_link("de", "https://www.amazon.de/Buddenbrooks-Verfall-einer-Familie-Roman/dp/3596294312/")
|
28
|
+
end
|
35
29
|
|
36
|
-
|
37
|
-
|
38
|
-
|
30
|
+
it "matches uk domains" do
|
31
|
+
check_link("co.uk", "https://www.amazon.co.uk/Pygmalion-George-Bernard-Shaw/dp/1420925237/")
|
32
|
+
end
|
39
33
|
|
40
|
-
|
41
|
-
|
42
|
-
|
34
|
+
it "matches japanese domains" do
|
35
|
+
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/")
|
36
|
+
end
|
43
37
|
|
44
|
-
|
45
|
-
|
46
|
-
|
38
|
+
it "matches chinese domains" do
|
39
|
+
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/")
|
40
|
+
end
|
47
41
|
|
48
|
-
|
49
|
-
|
50
|
-
|
42
|
+
it "matches french domains" do
|
43
|
+
check_link("fr", "https://www.amazon.fr/Les-Mots-autres-%C3%A9crits-autobiographiques/dp/2070114147/")
|
44
|
+
end
|
45
|
+
|
46
|
+
it "matches italian domains" do
|
47
|
+
check_link("it", "https://www.amazon.it/Tutte-poesie-Salvatore-Quasimodo/dp/8804520477/")
|
48
|
+
end
|
49
|
+
|
50
|
+
it "matches spanish domains" do
|
51
|
+
check_link("es", "https://www.amazon.es/familia-Pascual-Duarte-Camilo-Jos%C3%A9-ebook/dp/B00EJRTKTW/")
|
52
|
+
end
|
53
|
+
|
54
|
+
it "matches brasilian domains" do
|
55
|
+
check_link("com.br", "https://www.amazon.com.br/A-p%C3%A1tria-chuteiras-Nelson-Rodrigues-ebook/dp/B00J2B414Y/")
|
56
|
+
end
|
57
|
+
|
58
|
+
it "matches indian domains" do
|
59
|
+
check_link("in", "https://www.amazon.in/Fireflies-Rabindranath-Tagore/dp/9381523169/")
|
60
|
+
end
|
51
61
|
|
52
|
-
it "matches brasilian domains" do
|
53
|
-
check_link("com.br", "https://www.amazon.com.br/A-p%C3%A1tria-chuteiras-Nelson-Rodrigues-ebook/dp/B00J2B414Y/")
|
54
62
|
end
|
55
63
|
|
56
|
-
|
57
|
-
|
64
|
+
describe "#url" do
|
65
|
+
it "maintains the same http/https scheme as the requested URL" do
|
66
|
+
expect(described_class.new("https://www.amazon.fr/gp/product/B01BYD0TZM").url)
|
67
|
+
.to eq("https://www.amazon.fr/gp/aw/d/B01BYD0TZM")
|
68
|
+
|
69
|
+
expect(described_class.new("http://www.amazon.fr/gp/product/B01BYD0TZM").url)
|
70
|
+
.to eq("https://www.amazon.fr/gp/aw/d/B01BYD0TZM")
|
71
|
+
end
|
58
72
|
end
|
59
73
|
|
60
|
-
|
74
|
+
describe "#to_html" do
|
75
|
+
it "includes image" do
|
76
|
+
expect(html).to include("http://ecx.images-amazon.com/images/I/51opYcR6kVL._SY400_.jpg")
|
77
|
+
end
|
61
78
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
.to eq("https://www.amazon.fr/gp/aw/d/B01BYD0TZM")
|
79
|
+
it "includes description" do
|
80
|
+
expect(html).to include("I have been programming for 25 years in a variety of hardware and software languages.")
|
81
|
+
end
|
66
82
|
|
67
|
-
|
68
|
-
.to
|
83
|
+
it "includes price" do
|
84
|
+
expect(html).to include("$25.34")
|
85
|
+
end
|
86
|
+
|
87
|
+
it "includes title" do
|
88
|
+
expect(html).to include("Seven Languages in Seven Weeks: A Pragmatic Guide to Learning Programming Languages (Pragmatic Programmers)")
|
89
|
+
end
|
69
90
|
end
|
70
91
|
end
|
71
92
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
end
|
93
|
+
context "amazon with opengraph" do
|
94
|
+
let(:link) { "https://www.amazon.com/dp/B01MFXN4Y2" }
|
95
|
+
let(:html) { described_class.new(link).to_html }
|
76
96
|
|
77
|
-
|
78
|
-
|
97
|
+
before do
|
98
|
+
fake("https://www.amazon.com/gp/aw/d/B01MFXN4Y2", response("amazon-og"))
|
79
99
|
end
|
80
100
|
|
81
|
-
|
82
|
-
|
83
|
-
|
101
|
+
describe "#to_html" do
|
102
|
+
it "includes image" do
|
103
|
+
expect(html).to include("https://images-na.ssl-images-amazon.com/images/I/51nOF2iBa6L._SX940_.jpg")
|
104
|
+
end
|
84
105
|
|
85
|
-
|
86
|
-
|
106
|
+
it "includes description" do
|
107
|
+
expect(html).to include("CHRISTINE is the story of an aspiring newswoman caught in the midst of a personal and professional life crisis. Between unrequited love, frustration at work, a tumultuous home, and self-doubt; she begins to spiral down a dark path.")
|
108
|
+
end
|
109
|
+
|
110
|
+
it "includes title" do
|
111
|
+
expect(html).to include("Watch Christine online - Amazon Video")
|
112
|
+
end
|
87
113
|
end
|
114
|
+
|
88
115
|
end
|
89
116
|
|
90
117
|
end
|
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.
|
4
|
+
version: 1.8.10
|
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-06-
|
13
|
+
date: 2017-06-02 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: multi_json
|
@@ -393,6 +393,7 @@ files:
|
|
393
393
|
- lib/onebox/web.rb
|
394
394
|
- lib/onebox/web_helpers.rb
|
395
395
|
- onebox.gemspec
|
396
|
+
- spec/fixtures/amazon-og.response
|
396
397
|
- spec/fixtures/amazon.response
|
397
398
|
- spec/fixtures/dailymail.response
|
398
399
|
- spec/fixtures/douban.response
|
@@ -512,6 +513,7 @@ signing_key:
|
|
512
513
|
specification_version: 4
|
513
514
|
summary: A gem for turning URLs into previews.
|
514
515
|
test_files:
|
516
|
+
- spec/fixtures/amazon-og.response
|
515
517
|
- spec/fixtures/amazon.response
|
516
518
|
- spec/fixtures/dailymail.response
|
517
519
|
- spec/fixtures/douban.response
|