lib/onebox/engine/amazon_onebox.rb in onebox-1.8.9 vs lib/onebox/engine/amazon_onebox.rb in onebox-1.8.10
- old
+ new
@@ -47,17 +47,23 @@
landing_image.first["src"].to_s
end
end
def data
- result = { link: link,
- title: CGI.unescapeHTML(raw.css("title").inner_text),
- image: image }
+ og = ::Onebox::Helpers.extract_opengraph(raw)
+ title = og[:title] || CGI.unescapeHTML(raw.css("title").inner_text)
+ result = {
+ link: link,
+ title: title,
+ image: og[:image] || image
+ }
+
result[:by_info] = raw.at("#by-line")
result[:by_info] = Onebox::Helpers.clean(result[:by_info].inner_html) if result[:by_info]
+
# get item price (Amazon markup is inconsistent, deal with it)
result[:price] =
if raw.css("#priceblock_ourprice .restOfPrice")[0] && raw.css("#priceblock_ourprice .restOfPrice")[0].inner_text
"#{raw.css("#priceblock_ourprice .restOfPrice")[0].inner_text}#{raw.css("#priceblock_ourprice .buyingPrice")[0].inner_text}.#{raw.css("#priceblock_ourprice .restOfPrice")[1].inner_text}"
elsif raw.css("#priceblock_dealprice") && (dealprice = raw.css("#priceblock_dealprice span")[0])
@@ -65,10 +71,10 @@
else
raw.css("#priceblock_ourprice").inner_text
end
summary = raw.at("#productDescription")
- result[:description] = summary.inner_text if summary
+ result[:description] = og[:description] || summary&.inner_text
result
end
end
end
end