lib/onebox/engine/amazon_onebox.rb in onebox-1.8.79 vs lib/onebox/engine/amazon_onebox.rb in onebox-1.8.80
- old
+ new
@@ -1,6 +1,7 @@
require 'json'
+require "onebox/open_graph"
module Onebox
module Engine
class AmazonOnebox
include Engine
@@ -74,11 +75,11 @@
author_list.each { |a| authors << a.inner_text.strip }
authors.join(", ")
end
def data
- og = ::Onebox::Helpers.extract_opengraph(raw)
+ og = ::Onebox::OpenGraph.new(raw)
if raw.at_css('#dp.book_mobile') #printed books
title = raw.at("h1#title")&.inner_text
authors = raw.at_css('#byline_secondary_view_div') ? multiple_authors("//div[@id='byline_secondary_view_div']//span[@class='a-text-bold']") : raw.at("#byline")&.inner_text
rating = raw.at("#averageCustomerReviews_feature_div .a-icon")&.inner_text || raw.at("#cmrsArcLink .a-icon")&.inner_text
@@ -98,11 +99,11 @@
result = {
link: link,
title: title,
by_info: authors,
- image: og[:image] || image,
+ image: og.image || image,
description: raw.at("#productDescription")&.inner_text,
rating: "#{rating}#{', ' if rating && (!isbn&.empty? || !price&.empty?)}",
price: price,
isbn_asin_text: "ISBN",
isbn_asin: isbn,
@@ -129,33 +130,33 @@
result = {
link: link,
title: title,
by_info: authors,
- image: og[:image] || image,
+ image: og.image || image,
description: raw.at("#productDescription")&.inner_text,
rating: "#{rating}#{', ' if rating && (!asin&.empty? || !price&.empty?)}",
price: price,
isbn_asin_text: "ASIN",
isbn_asin: asin,
publisher: publisher,
published: "#{published}#{', ' if published && !price&.empty?}"
}
else
- title = og[:title] || CGI.unescapeHTML(raw.css("title").inner_text)
+ title = og.title || CGI.unescapeHTML(raw.css("title").inner_text)
result = {
link: link,
title: title,
- image: og[:image] || image,
+ image: og.image || image,
price: price
}
result[:by_info] = raw.at("#by-line")
result[:by_info] = Onebox::Helpers.clean(result[:by_info].inner_html) if result[:by_info]
summary = raw.at("#productDescription")
- result[:description] = og[:description] || (summary && summary.inner_text)
+ result[:description] = og.description || (summary && summary.inner_text)
end
result[:price] = nil if result[:price].start_with?("$0") || result[:price] == 0
result