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



66
67
68
69
70
71
72
73
74
75
# File 'supply/lib/supply/setup.rb', line 66

def create_screenshots_folder(listing)
  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



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
# File 'supply/lib/supply/setup.rb', line 39

def download_images(listing)
  # 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
# File 'supply/lib/supply/setup.rb', line 3

def perform_download
  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



77
78
79
80
81
82
83
84
85
86
# File 'supply/lib/supply/setup.rb', line 77

def store_apk_listing(apk_listing)
  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



28
29
30
31
32
33
34
35
36
37
# File 'supply/lib/supply/setup.rb', line 28

def (listing)
  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