LoginSignup
4
3

More than 5 years have passed since last update.

ruby-dmmを使ってDMMのAPIを用いたアイテム検索結果の大きなアイテム画像を一気にWebブラウザで確認しよう

Posted at

まずは、ruby-dmmを使った基本的なアイテム検索方法はこちらを参照してください。
http://qiita.com/bash0C7/items/ccaf95c4177fbe7ecfdd

さて、検索結果が望みのものかを確認するには名前や説明文を読むより画像を見るほうが直感的で捗ります。

DMM::Response::Item#imagesで複数のサイズの画像URLを取得できるので、これをWebブラウザで実際に開いて確認してみましょう

require 'ruby-dmm'
client = DMM.new(:api_id => [APIID], :affiliate_id => [アフィリエイトID], :result_only => true)
client.item_list(<キーワード>).items.each { |item| `open "#{item.images[:large]}"`}

これで、DMM::Response::Item#images[:large]にある大きな画像URLを取得し、macのopenコマンドに渡します。
WebブラウザがたいていはURLに関連付けられているので、画像をWebブラウザで一気に確認できるという仕組みです。

もしいったんローカルに保存した上で確認したい場合は、open-uriをrequireの上、ファイルとして読み込み、ローカルファイルに書きだせばいいでしょう。

4
3
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3