Create a gist now

Instantly share code, notes, and snippets.

Searches the itunes store for ios applications that are compatible with the original iPad. Alter the term and rating parameters to filter results.
require 'net/http'
require 'uri'
require 'json'
term = 'calendar'
rating = 4
uri = URI("https://itunes.apple.com/search?term="+ term +"&country=us&media=software&entity=iPadSoftware&limit=50")
resp = Net::HTTP.get_response(uri)
results = JSON.parse(resp.body)
output = Hash.new(0)
results['results'].each_with_index do |app, i|
output[[i,0]] = i
if app['price'] == 0
output[[i,1]] = 'free'
else
output[[i,1]] = app['price']
end
output[[i,2]] = app['primaryGenreName']
output[[i,3]] = app['trackName']
output[[i,4]] = "Not Compatible"
app['supportedDevices'].each do |d|
if d == "iPadWifi"
output[[i,4]] = "iPadWifi Compatible"
end
end
if app['averageUserRating'].nil?
output[[i,5]] = 0
else
output[[i,5]] = app['averageUserRating']
end
if app['averageUserRatingForCurrentVersion'].nil?
output[[i,6]] = 0
else
output[[i,6]] = app['averageUserRatingForCurrentVersion']
end
end
(1...50).each do |i2|
if output[[i2,4]] == "iPadWifi Compatible"
if output[[i2,5]] >= rating
puts
puts 'Name: ' + output[[i2,3]]
puts 'Price: ' + output[[i2,1]].to_s
puts 'Genre: ' + output[[i2,2]]
puts 'Overall Rating: ' + output[[i2,5]].to_s
puts 'Current Version Rating: ' + output[[i2,6]].to_s
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment