Class: Fastlane::Actions::OneskyDownloadAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/onesky/actions/onesky_download_action.rb

Class Method Summary collapse

Class Method Details

.authorsObject



20
21
22
# File 'lib/fastlane/plugin/onesky/actions/onesky_download_action.rb', line 20

def self.authors
  ['danielkiedrowski']
end

.available_optionsObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
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 'lib/fastlane/plugin/onesky/actions/onesky_download_action.rb', line 24

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :public_key,
                                 env_name: 'ONESKY_PUBLIC_KEY',
                                 description: 'Public key for OneSky',
                                 is_string: true,
                                 optional: false,
                                 verify_block: proc do |value|
                                   raise "No Public Key for OneSky given, pass using `public_key: 'token'`".red unless value and !value.empty?
                                 end),
    FastlaneCore::ConfigItem.new(key: :secret_key,
                                 env_name: 'ONESKY_SECRET_KEY',
                                 description: 'Secret Key for OneSky',
                                 is_string: true,
                                 optional: false,
                                 verify_block: proc do |value|
                                   raise "No Secret Key for OneSky given, pass using `secret_key: 'token'`".red unless value and !value.empty?
                                 end),
    FastlaneCore::ConfigItem.new(key: :project_id,
                                 env_name: 'ONESKY_PROJECT_ID',
                                 description: 'Project Id to upload file to',
                                 optional: false,
                                 verify_block: proc do |value|
                                   raise "No project id given, pass using `project_id: 'id'`".red unless value and !value.empty?
                                 end),
    FastlaneCore::ConfigItem.new(key: :locale,
                                 env_name: 'ONESKY_DOWNLOAD_LOCALE',
                                 description: 'Locale to download the translation for',
                                 is_string: true,
                                 optional: false,
                                 verify_block: proc do |value|
                                   raise 'No locale for translation given'.red unless value and !value.empty?
                                 end),
    FastlaneCore::ConfigItem.new(key: :filename,
                                 env_name: 'ONESKY_DOWNLOAD_FILENAME',
                                 description: 'Name of the file to download the localization for',
                                 is_string: true,
                                 optional: false,
                                 verify_block: proc do |value|
                                   raise "No filename given. Please specify the filename of the file you want to download the translations for using `filename: 'filename'`".red unless value and !value.empty?
                                 end),
    FastlaneCore::ConfigItem.new(key: :destination,
                                 env_name: 'ONESKY_DOWNLOAD_DESTINATION',
                                 description: 'Destination file to write the downloaded file to',
                                 is_string: true,
                                 optional: false,
                                 verify_block: proc do |value|
                                   raise "Please specify the filename of the desrtination file you want to download the translations to using `destination: 'filename'`".red unless value and !value.empty?
                                 end)
  ]
end

.descriptionObject



16
17
18
# File 'lib/fastlane/plugin/onesky/actions/onesky_download_action.rb', line 16

def self.description
  'Download a translation file from OneSky'
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/fastlane/plugin/onesky/actions/onesky_download_action.rb', line 76

def self.is_supported?(platform)
  true
end

.run(params) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/fastlane/plugin/onesky/actions/onesky_download_action.rb', line 4

def self.run(params)
  Actions.verify_gem!('onesky-ruby')
  require 'onesky'

  client = ::Onesky::Client.new(params[:public_key], params[:secret_key])
  project = client.project(params[:project_id])

  UI.success "Downloading translation '#{params[:locale]}' of file '#{params[:filename]}' from OneSky to: '#{params[:destination]}'"
  resp = project.export_translation(source_file_name: params[:filename], locale: params[:locale])
  File.open(params[:destination], 'w') { |file| file.write(resp) }
end