Tambourine作業メモ

主にスキル習得のためにやった作業のメモ。他人には基本的に無用のものです。

画像を取得する

Amazonの画像のURLを取ってくる。タイトルを取ってきたりするのとほとんど一緒。

    #Amazonから情報を得る
    if @book.title.to_s == ""
      item = Asin.amazon_get(num)
      
      attributes = item.elements["ItemAttributes"]
      @book.title  = attributes.elements["Title"].text
      @book.auther = attributes.elements["Author"].text if attributes.elements["Author"]
      
      smallimage = item.elements["SmallImage"]
      if smallimage
        @book.smallimage_url = smallimage.elements["URL"].text
        @book.smallimage_height = smallimage.elements["Height"].text
        @book.smallimage_width = smallimage.elements["Width"].text
      end
      
      mediumimage = item.elements["MediumImage"]
      if mediumimage
        @book.mediumimage_url = mediumimage.elements["URL"].text
        @book.mediumimage_height = mediumimage.elements["Height"].text
        @book.mediumimage_width = mediumimage.elements["Width"].text
      end

      @book.status = 0
      @book.save
    end