Class: Supply::Setup

Inherits:
Object
  • Object
show all
Defined in:
supply/lib/supply/setup.rb

Instance Method Summary collapse

Instance Method Details

#create_screenshots_folder(listing) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
# File 'supply/lib/supply/setup.rb', line 72

def create_screenshots_folder(listing)
  UI.message("📱  Downloading screenshots (#{listing.language})")

  containing = File.join(, 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) ⇒ Object



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
# 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(, 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_downloadObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'supply/lib/supply/setup.rb', line 3

def perform_download
  UI.message("🕗  Downloading metadata, images, screenshots...")

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

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

  client.listings.each do |listing|
    (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 '#{}'")
end

#store_apk_listing(apk_listing) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
# 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(, 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) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'supply/lib/supply/setup.rb', line 30

def (listing)
  UI.message("📝  Downloading metadata (#{listing.language})")

  containing = File.join(, 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