misc/plugin/amazon.rb in tdiary-5.1.0 vs misc/plugin/amazon.rb in tdiary-5.1.1

- old
+ new

@@ -25,12 +25,12 @@ rescue '-' end end -def amazon_title(json) - json["ItemInfo"]["Title"]["DisplayValue"] +def amazon_title(item) + item["ItemInfo"]["Title"]["DisplayValue"] end def amazon_image(item) image = {} begin @@ -147,26 +147,26 @@ begin cache = "#{@cache_path}/amazon" Dir::mkdir( cache ) unless File::directory?( cache ) begin - json = JSON.parse(File::read("#{cache}/#{country}#{item_id}.json")) + json = File::read("#{cache}/#{country}#{item_id}.json") rescue Errno::ENOENT access_key = @conf['amazon.access_key'] secret_key = @conf['amazon.secret_key'] + return asin unless access_key && secret_key partner_tag = @conf['amazon.aid'] paapi = AWS::PAAPI.new(access_key, secret_key, partner_tag) json = paapi.get_items(item_id, country.to_sym) File::open("#{cache}/#{country}#{item_id}.json", 'wb'){|f| f.write(json)} end - item = json["ItemsResult"]["Items"][0] + item = JSON.parse(json)["ItemsResult"]["Items"][0] if pos == 'detail' then amazon_detail_html(item) else amazon_to_html(item, with_image, label, pos) end rescue Net::HTTPUnauthorized - p country, item_id @logger.error "amazon.rb: Amazon API Unauthorized." message = asin if @mode == 'preview' then message << %Q|<span class="message">(Amazon API Unauthorized))</span>| end