Class: Supply::Setup

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

Instance Method Summary collapse

Instance Method Details

#create_screenshots_folder(listing) ⇒ Object



56
57
58
59
60
61
62
63
64
65
# File 'lib/supply/setup.rb', line 56

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

  Helper.log.info "Due to the limit of the Google Play API `supply` can't download your existing screenshots..."
end

#download_images(listing) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/supply/setup.rb', line 33

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|
    next if ['featureGraphic'].include?(image_type) # we don't get all files in full resolution :(

    begin
      Helper.log.info "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
      Helper.log.error ex.to_s
      Helper.log.error "Error downloading '#{image_type}' for #{listing.language}...".red
    end
  end
end

#perform_downloadObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/supply/setup.rb', line 3

def perform_download
  if File.exist?()
    Helper.log.info "Metadata already exists at path '#{metadata_path}'".yellow
    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.abort_current_edit

  Helper.log.info "Successfully stored metadata in '#{metadata_path}'".green
end

#store_metadata(listing) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/supply/setup.rb', line 22

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

  Supply::.each do |key|
    path = File.join(containing, "#{key}.txt")
    Helper.log.info "Writing to #{path}..."
    File.write(path, listing.send(key))
  end
end