Sha256: 6c9be85136ca7d9e5eee91846fa990ea1cc967f51232a5b122e54692bd832225

Contents?: true

Size: 1.57 KB

Versions: 9

Compression:

Stored size: 1.57 KB

Contents

module Deliver
  class DownloadScreenshots
    def self.run(options, path)
      UI.message("Downloading all existing screenshots...")
      download(options, path)
      UI.success("Successfully downloaded all existing screenshots")
    rescue => ex
      UI.error(ex)
      UI.error("Couldn't download already existing screenshots from iTunes Connect.")
    end

    def self.download(options, folder_path)
      v = options[:app].latest_version

      v.screenshots.each do |language, screenshots|
        screenshots.each do |screenshot|
          file_name = [screenshot.sort_order, screenshot.device_type, screenshot.sort_order].join("_")
          original_file_extension = File.basename(screenshot.original_file_name)
          file_name += "." + original_file_extension

          UI.message("Downloading existing screenshot '#{file_name}' for language '#{language}'")

          # If the screen shot is for an appleTV we need to store it in a way that we'll know it's an appleTV
          # screen shot later as the screen size is the same as an iPhone 6 Plus in landscape.
          if screenshot.device_type == "appleTV"
            containing_folder = File.join(folder_path, "appleTV", screenshot.language)
          else
            containing_folder = File.join(folder_path, screenshot.language)
          end

          begin
            FileUtils.mkdir_p(containing_folder)
          rescue
            # if it's already there
          end
          path = File.join(containing_folder, file_name)
          File.write(path, open(screenshot.url).read)
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
deliver-1.16.1 lib/deliver/download_screenshots.rb
deliver-1.16.0 lib/deliver/download_screenshots.rb
deliver-1.15.1 lib/deliver/download_screenshots.rb
deliver-1.15.0 lib/deliver/download_screenshots.rb
deliver-1.14.5 lib/deliver/download_screenshots.rb
deliver-1.14.4 lib/deliver/download_screenshots.rb
deliver-1.14.3 lib/deliver/download_screenshots.rb
deliver-1.14.2 lib/deliver/download_screenshots.rb
deliver-1.14.1 lib/deliver/download_screenshots.rb