class Supply::Setup

Public Instance Methods

create_screenshots_folder(listing) click to toggle source
# File supply/lib/supply/setup.rb, line 72
def create_screenshots_folder(listing)
  UI.message("📱  Downloading screenshots (#{listing.language})")

  containing = File.join(metadata_path, listing.language)

  FileUtils.mkdir_p(File.join(containing, IMAGES_FOLDER_NAME))
  Supply::SCREENSHOT_TYPES.each do |screenshot_type|
    FileUtils.mkdir_p(File.join(containing, IMAGES_FOLDER_NAME, screenshot_type))
  end

  UI.message("📵  Due to a limitation of the Google Play API, there is no way for `supply` to download your existing screenshots. Please copy your screenshots into `metadata/android/#{listing.language}/images/`")
end
download_images(listing) click to toggle source
# File supply/lib/supply/setup.rb, line 43
def download_images(listing)
  UI.message("🖼️  Downloading images (#{listing.language})")

  # We cannot download existing screenshots as they are compressed
  # But we can at least download the images
  require 'net/http'

  IMAGES_TYPES.each do |image_type|
    if ['featureGraphic'].include?(image_type)
      # we don't get all files in full resolution :(
      UI.message("📵  Due to a limitation of the Google Play API, there is no way for `supply` to download your existing feature graphic. Please copy your feature graphic to `metadata/android/#{listing.language}/images/featureGraphic.png`")
      next
    end

    begin
      UI.message("Downloading `#{image_type}` for #{listing.language}...")

      url = client.fetch_images(image_type: image_type, language: listing.language).last
      next unless url

      path = File.join(metadata_path, listing.language, IMAGES_FOLDER_NAME, "#{image_type}.png")
      File.write(path, Net::HTTP.get(URI.parse(url)))
    rescue => ex
      UI.error(ex.to_s)
      UI.error("Error downloading '#{image_type}' for #{listing.language}...")
    end
  end
end
perform_download() click to toggle source
# File supply/lib/supply/setup.rb, line 3
def perform_download
  UI.message("🕗  Downloading metadata, images, screenshots...")

  if File.exist?(metadata_path)
    UI.important("Metadata already exists at path '#{metadata_path}'")
    return
  end

  client.begin_edit(package_name: Supply.config[:package_name])

  client.listings.each do |listing|
    store_metadata(listing)
    create_screenshots_folder(listing)
    download_images(listing)
  end

  client.apks_version_codes.each do |apk_version_code|
    client.apk_listings(apk_version_code).each do |apk_listing|
      store_apk_listing(apk_listing)
    end
  end

  client.abort_current_edit

  UI.success("✅  Successfully stored metadata in '#{metadata_path}'")
end
store_apk_listing(apk_listing) click to toggle source
# File supply/lib/supply/setup.rb, line 85
def store_apk_listing(apk_listing)
  UI.message("🔨  Downloading changelogs (#{apk_listing.language}, #{apk_listing.apk_version_code})")

  containing = File.join(metadata_path, apk_listing.language, CHANGELOGS_FOLDER_NAME)
  unless File.exist?(containing)
    FileUtils.mkdir_p(containing)
  end

  path = File.join(containing, "#{apk_listing.apk_version_code}.txt")
  UI.message("Writing to #{path}...")
  File.write(path, apk_listing.recent_changes)
end
store_metadata(listing) click to toggle source
# File supply/lib/supply/setup.rb, line 30
def store_metadata(listing)
  UI.message("📝  Downloading metadata (#{listing.language})")

  containing = File.join(metadata_path, listing.language)
  FileUtils.mkdir_p(containing)

  Supply::AVAILABLE_METADATA_FIELDS.each do |key|
    path = File.join(containing, "#{key}.txt")
    UI.message("Writing to #{path}...")
    File.open(path, 'w:UTF-8') { |file| file.write(listing.send(key)) }
  end
end

Private Instance Methods

client() click to toggle source
# File supply/lib/supply/setup.rb, line 108
def client
  @client ||= Client.make_from_config
end
metadata_path() click to toggle source
# File supply/lib/supply/setup.rb, line 100
def metadata_path
  @metadata_path ||= Supply.config[:metadata_path]
  @metadata_path ||= "fastlane/metadata/android" if Helper.fastlane_enabled?
  @metadata_path ||= "metadata" unless Helper.fastlane_enabled?

  return @metadata_path
end