Class: Deliver::DownloadScreenshots

Inherits:
Object
  • Object
show all
Defined in:
deliver/lib/deliver/download_screenshots.rb

Class Method Summary collapse

Class Method Details

.download(options, folder_path) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'deliver/lib/deliver/download_screenshots.rb', line 16

def self.download(options, folder_path)
  app = Deliver.cache[:app]

  platform = Spaceship::ConnectAPI::Platform.map(options[:platform])
  if options[:use_live_version]
    version = app.get_live_app_store_version(platform: platform)
    UI.user_error!("Could not find a live version on App Store Connect. Try using '--use_live_version false'") if version.nil?
  else
    version = app.get_edit_app_store_version(platform: platform)
    UI.user_error!("Could not find an edit version on App Store Connect. Try using '--use_live_version true'") if version.nil?
  end

  localizations = version.get_app_store_version_localizations
  threads = []
  localizations.each do |localization|
    threads << Thread.new do
      download_screenshots(folder_path, localization)
    end
  end
  threads.each(&:join)
end

.download_screenshots(folder_path, localization) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'deliver/lib/deliver/download_screenshots.rb', line 38

def self.download_screenshots(folder_path, localization)
  language = localization.locale
  screenshot_sets = localization.get_app_screenshot_sets
  screenshot_sets.each do |screenshot_set|
    screenshot_set.app_screenshots.each_with_index do |screenshot, index|
      file_name = [index, screenshot_set.screenshot_display_type, index].join("_")
      original_file_extension = File.extname(screenshot.file_name).strip.downcase[1..-1]
      file_name += "." + original_file_extension

      url = screenshot.image_asset_url(type: original_file_extension)
      next if url.nil?

      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_set.apple_tv?
        containing_folder = File.join(folder_path, "appleTV", language)
      else
        containing_folder = File.join(folder_path, language)
      end

      if screenshot_set.imessage?
        containing_folder = File.join(folder_path, "iMessage", language)
      end

      begin
        FileUtils.mkdir_p(containing_folder)
      rescue
        # if it's already there
      end

      path = File.join(containing_folder, file_name)
      File.binwrite(path, URI.open(url).read)
    end
  end
end

.run(options, path) ⇒ Object



7
8
9
10
11
12
13
14
# File 'deliver/lib/deliver/download_screenshots.rb', line 7

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 App Store Connect.")
end