lib/onebox/engine/amazon_onebox.rb in onebox-1.5.21 vs lib/onebox/engine/amazon_onebox.rb in onebox-1.5.22

- old
+ new

@@ -1,14 +1,16 @@ +require 'json' + module Onebox module Engine class AmazonOnebox include Engine include LayoutSupport include HTML - matches_regexp(/^http:\/\/(?:www)\.amazon\.(?<tld>com|ca|de|it|es|fr|co\.jp|co\.uk|cn|in|com\.br)\//) + matches_regexp(/^https?:\/\/(?:www)\.amazon\.(?<tld>com|ca|de|it|es|fr|co\.jp|co\.uk|cn|in|com\.br)\//) def url return "http://www.amazon.#{tld}/gp/aw/d/" + URI::encode(match[:id]) if match && match[:id] @url end @@ -28,26 +30,30 @@ end def image case when raw.css("#main-image").any? - raw.css("#main-image").first["src"] + ::JSON.parse( + raw.css("#main-image").first + .attributes["data-a-dynamic-image"] + .value + ).keys.first when raw.css("#landingImage").any? raw.css("#landingImage").first["src"] end end def data result = { link: link, - title: raw.css("h1").inner_text, + title: raw.css("title").inner_text, image: image, - price: raw.css(".priceLarge").inner_text } + price: raw.css("#priceblock_ourprice").inner_text } 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("#about-item span") - result[:description] = summary.inner_html if summary + summary = raw.at("#productDescription") + result[:description] = summary.inner_text if summary result end end end end