Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEV: Small Amazon fixes #463

Merged
merged 7 commits into from Apr 2, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 12 additions & 4 deletions lib/onebox/engine/amazon_onebox.rb
Expand Up @@ -45,7 +45,11 @@ def http_params
private

def match
@match ||= @url.match(/(?:d|g)p\/(?:product\/|video\/detail\/)?(?<id>[^\/]+)(?:\/|$)/mi)
@match ||= @url.match(/(?:d|g)p\/(?:product\/|video\/detail\/)?(?<id>[A-Z0-9]+)(?:\/|\?|$)/mi)
CvX marked this conversation as resolved.
Show resolved Hide resolved
end

def link
jbrw marked this conversation as resolved.
Show resolved Hide resolved
@link ||= ::Onebox::Helpers.uri_encode(url)
end

def image
Expand All @@ -60,6 +64,10 @@ def image
end

if (landing_image = raw.css("#landingImage")) && landing_image.any?
attributes = landing_image.first.attributes

return attributes["data-old-hires"].to_s if attributes["data-old-hires"]

landing_image.first["src"].to_s
end

Expand Down Expand Up @@ -110,7 +118,7 @@ def data
end

result = {
link: link,
link: url,
title: title,
by_info: authors,
image: og.image || image,
Expand Down Expand Up @@ -141,7 +149,7 @@ def data
end

result = {
link: link,
link: url,
title: title,
by_info: authors,
image: og.image || image,
Expand All @@ -157,7 +165,7 @@ def data
else
title = og.title || CGI.unescapeHTML(raw.css("title").inner_text)
result = {
link: link,
link: url,
title: title,
image: og.image || image,
price: price
Expand Down
2 changes: 1 addition & 1 deletion lib/onebox/version.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Onebox
VERSION = "2.2.9"
VERSION = "2.2.10"
end
11 changes: 11 additions & 0 deletions spec/lib/onebox/engine/amazon_onebox_spec.rb
Expand Up @@ -73,6 +73,13 @@ def check_link(tdl, link)
expect(described_class.new("http://www.amazon.fr/gp/product/B01BYD0TZM").url)
.to eq("https://www.amazon.fr/dp/B01BYD0TZM")
end

let(:long_url) { "https://www.amazon.ca/gp/product/B087Z3N428?pf_rd_r=SXABADD0ZZ3NF9Q5F8TW&pf_rd_p=05378fd5-c43e-4948-99b1-a65b129fdd73&pd_rd_r=0237fb28-7f47-49f4-986a-be0c78e52863&pd_rd_w=FfIoI&pd_rd_wg=Hw4qq&ref_=pd_gw_unk" }

it "removes parameters from the URL" do
expect(described_class.new(long_url).url)
.not_to include("?pf_rd_r")
end
end

describe "#to_html" do
Expand All @@ -91,6 +98,10 @@ def check_link(tdl, link)
it "includes title" do
expect(html).to include("Seven Languages in Seven Weeks: A Pragmatic Guide to Learning Programming Languages (Pragmatic Programmers)")
end

it "includes canonical link" do
expect(html).to include(@uri)
end
end
end

Expand Down