class Madowu::BookInfo

Constants

ASSOCIATEID_FILE
ROOT_KEY_FILE

Attributes

author[R]
img_url[R]
isbn[R]
publication_date[R]
publisher[R]
title[R]
url[R]

Public Class Methods

load_isbn(isbn) click to toggle source
# File lib/madowu/bookinfo.rb, line 47
def self.load_isbn(isbn)
  [ROOT_KEY_FILE, ASSOCIATEID_FILE].each do |file|
    raise AccountFileError, "Not found #{file}" unless File.exist? file
  end

  hash = {}
  hash[:associate_tag] = File.open(ASSOCIATEID_FILE, 'r').gets.chomp
  File.open(ROOT_KEY_FILE, 'r').readlines.each do |i|
    /(.*)=(.*)/ =~ i
    key, val = $1, $2
    hash[:AWS_access_key_id] = val.chomp if key == 'AWSAccessKeyId'
    hash[:AWS_secret_key]    = val.chomp if key == 'AWSSecretKey'
  end
  Amazon::Ecs.options = hash

  info = nil
  3.times do |i|
    begin
      info = Amazon::Ecs.item_search(
        isbn,
        {:search_index => 'Books',
         :response_group => 'Medium',
         :country => 'jp'
        }
      )
      #pp i
      #pp info
    rescue Amazon::RequestError
      sleep 1
    end
    break if info
  end

  unless info
    raise Amazon::RequestError
  end

  properties = {}
  info.items.each do |item|
    properties[:title           ] = item.get('ItemAttributes/Title')
    properties[:author          ] = item.get('ItemAttributes/Author')
    properties[:isbn            ] = item.get('ItemAttributes/ISBN')
    properties[:publisher       ] = item.get('ItemAttributes/Publisher')
    properties[:publication_date] = item.get('ItemAttributes/PublicationDate')
    properties[:url             ] = item.get('DetailPageURL')
    properties[:img_url         ] = item.get('SmallImage/URL')
  end
  self.new(properties)
end
new(title: '', author: '', isbn: '', publisher: '', publication_date: '', url: '', img_url: '') click to toggle source
# File lib/madowu/bookinfo.rb, line 31
def initialize(title: '',
               author: '',
               isbn: '',
               publisher: '',
               publication_date: '',
               url: '',
               img_url: '')
  @title            = title
  @author           = author
  @isbn             = isbn
  @publisher        = publisher
  @publication_date = publication_date
  @url              = url
  @img_url          = img_url
end