class Appscreens::Client
Public Class Methods
new()
click to toggle source
# File lib/appscreens/client.rb, line 14 def initialize @search_url = ITUNES_SEARCH_ENDPOINT @country = 'US' end
Public Instance Methods
download_screenshots(app:, icon:, ipad:, destination:)
click to toggle source
# File lib/appscreens/client.rb, line 26 def download_screenshots(app:, icon:, ipad:, destination:) screenshots = app[ipad ? APP_SCREENSHOTS_KEY_IPAD : APP_SCREENSHOTS_KEY] app_name = app[APP_NAME_KEY].downcase.tr(" ","_") screenshots.each_with_index do |screen_url, index| screen_url = screen_url.sub('480x480', '960x960') if ipad puts "Downloading screenshot #{index + 1} of #{screenshots.length}..." file_name = "#{destination}/#{app_name}_#{index + 1}#{ipad ? "_ipad" : ""}.jpeg" File.open(file_name, 'wb') { |fp| fp.write(open(screen_url).read) } end if icon puts "Downloading app icon..." File.open("#{destination}/#{app_name}_icon.png", 'wb') { |fp| fp.write(open(app[APP_ICON_KEY]).read) } end puts '#######################################################################'.green puts "Finished grabbing artwork for #{app[APP_NAME_KEY]}".green puts '#######################################################################'.green end
lookup(app_id)
click to toggle source
# File lib/appscreens/client.rb, line 19 def lookup(app_id) uri = URI.join(@search_url, "lookup") uri.query = URI.encode_www_form( {id: app_id} ) json_response_from_uri(uri)[ITUNES_SEARCH_RESULTS_KEY].first end
Private Instance Methods
json_response_from_uri(uri)
click to toggle source
# File lib/appscreens/client.rb, line 50 def json_response_from_uri(uri) response = Net::HTTP.get_response(uri) JSON.parse(response.body) rescue nil end