Skip to content

Instantly share code, notes, and snippets.

@kawahara
Last active December 22, 2015 23:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kawahara/6548109 to your computer and use it in GitHub Desktop.
Save kawahara/6548109 to your computer and use it in GitHub Desktop.
source 'https://rubygems.org'
gem 'httpclient'
GEM
remote: https://rubygems.org/
specs:
httpclient (2.3.4.1)
PLATFORMS
ruby
DEPENDENCIES
httpclient
# coding: utf-8
require 'httpclient'
require 'json'
begin
httpClient = HTTPClient.new
data = httpClient.get_content('https://app.rakuten.co.jp/services/api/IchibaItem/Search/20130805', {
'applicationId' => '1025899060325418115',
'affiliateId' => '0dd78f8a.26c4c8c0.0dd78f8b.0ee811d2',
'keyword' => 'うどん'
})
jsonData = JSON.parse data
jsonData['Items'].each do | itemData |
item = itemData['Item']
p "#{item['itemName']} #{item['itemPrice']}円"
end
rescue HTTPClient::BadResponseError => e
p e.res.code # Error Code
p e.res.body # Body
rescue HTTPClient::TimeoutError => e
p "Timeout Error"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment