Class: Localedata::Downloader

Inherits:
Object
  • Object
show all
Defined in:
lib/localedata/downloader.rb

Instance Method Summary collapse

Instance Method Details

#download(locales) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/localedata/downloader.rb', line 3

def download(locales)
  configuration = Localedata::Configuration.new
  configuration.load_config_file

  client = Localedata::Client.new(configuration.access_token)
  configuration.projects.each do |project|
    project["locales"].each do |language_code, relative_file_path|
      next if locales.any? && !locales.include?(language_code)

      print "Downloading #{language_code} into #{relative_file_path}..."
      data = client.pull(project["id"], language_code)
      if data[:success]
        file_path = File.expand_path(relative_file_path)
        File.write(file_path, data[:yaml])
        puts "Done."
      else
        puts "FAIL!"
        puts "Error #{data[:status_code]}: #{data[:error]}"
      end
    end
  end
end