LoginSignup
30
30

More than 5 years have passed since last update.

ruby-dmmを使ってDMMのAPIを用いてアイテム検索を簡単にしよう

Posted at

登録を行うことでDMMのAPIを使うことができます。
https://affiliate.dmm.com/api/

Rubyには https://rubygems.org/gems/ruby-dmm というライブラリがあり、これを用いるとDMMのAPIを簡単に叩くことができます。

まずはrequireした後、クライアントのインスタンスを作りましょう。

require 'ruby-dmm'
client = DMM.new(:api_id => [APIID], :affiliate_id => [アフィリエイトID], :result_only => true)

この後、一番シンプルなかたちとしては下記キーワードだけ指定すれば何らかの結果がでてきます。

result = client.item_list('BiS')

とはいえ、普段使う上ではおそらく特定のサービスや種別に絞って検索をしたいことでしょう。

result = client.item_list('BiS', site: 'DMM.com', service: 'digital', floor: 'idol')
  • siteには、一般向けのDMM.com、表現の自由度の高いコンテンツのDMM.co.jpのいずれを対象にするかを指定します。
  • serviceには、DMMのサービスごとに定められた名前を指定します。
  • floorには、DMMのサービスを細分化したフロアごとに定められた名前を指定します。

その他、様々なオプションがあるので、APIリファレンスを読みながら、ご所望のコンテンツに最短でたどり着く術を見出してみてください。

30
30
0

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
30
30