Class: Fastlane::Actions::UploadToOneskyAction

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

Class Method Summary collapse

Class Method Details

.auth_hash(api_key, secret_key) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/fastlane/plugin/upload_to_onesky/actions/upload_to_onesky_action.rb', line 49

def self.auth_hash(api_key, secret_key)
  now = Time.now.to_i

  {
      api_key: api_key,
      timestamp: now,
      dev_hash: Digest::MD5.hexdigest(now.to_s + secret_key)
  }
end

.authorsObject



63
64
65
# File 'lib/fastlane/plugin/upload_to_onesky/actions/upload_to_onesky_action.rb', line 63

def self.authors
  ['JMoravec', 'joshrlesch']
end

.available_optionsObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/fastlane/plugin/upload_to_onesky/actions/upload_to_onesky_action.rb', line 67

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 not 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 not 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'.red unless (value and not value.empty?)
                                 end),
    FastlaneCore::ConfigItem.new(key: :strings_file_path,
                                 env_name: 'ONESKY_STRINGS_FILE_PATH',
                                 description: 'Base file path for the strings file to upload',
                                 is_string: true,
                                 optional: false,
                                 verify_block: proc do |value|
                                   raise "Couldn't find file at path '#{value}'".red unless File.exist?(value)
                                 end),
    FastlaneCore::ConfigItem.new(key: :strings_file_format,
                                 env_name: 'ONESKY_STRINGS_FORMAT',
                                 description: 'Format of the strings file: see https://github.com/onesky/api-documentation-platform/blob/master/reference/format.md',
                                 is_string: true,
                                 optional: false,
                                 verify_block: proc do |value|
                                   raise 'No file format given'.red unless (value and not value.empty?)
                                 end),
    FastlaneCore::ConfigItem.new(key: :is_keeping_all_strings,
                                env_name: 'IS_KEEPING_ALL_STRINGS',
                                description: 'Deprecate strings if not found in newly uploaded file',
                                is_string: false,
                                optional: true,
                                default_value: true),
    FastlaneCore::ConfigItem.new(key: :is_allow_translation_same_as_original,
                                env_name: 'IS_ALLOW_TRANSLATION_SAME_AS_ARIGINAL',
                                description: 'Skip importing translations that are the same as source text',
                                is_string: false,
                                optional: true,
                                default_value: false)
  ]
end

.descriptionObject



59
60
61
# File 'lib/fastlane/plugin/upload_to_onesky/actions/upload_to_onesky_action.rb', line 59

def self.description
  'Upload a strings file to OneSky'
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


123
124
125
126
127
128
129
# File 'lib/fastlane/plugin/upload_to_onesky/actions/upload_to_onesky_action.rb', line 123

def self.is_supported?(platform)
  # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
  # See: https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Platforms.md
  #
  # [:ios, :mac, :android].include?(platform)
  true
end

.run(params) ⇒ Object



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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/fastlane/plugin/upload_to_onesky/actions/upload_to_onesky_action.rb', line 4

def self.run(params)
  require 'rest-client'

  file_path = File.expand_path(params[:strings_file_path])

  file = File.new(file_path, 'rt')

  request_params = {
      content_type: :json,
      params: self.auth_hash(params[:public_key], params[:secret_key])

  }

  UI.success 'Starting the upload to OneSky'
  url = "https://platform.api.onesky.io/1/projects/#{params[:project_id]}/files"

  body_hash = {
      file: file,
      file_format: params[:strings_file_format],
      multipart: true
  }

  # True by default on onesky file upload
  # https://github.com/onesky/api-documentation-platform/blob/master/resources/file.md#upload---upload-a-file
  unless params[:is_keeping_all_strings]
    body_hash[:is_keeping_all_strings] = false
  end

  # False by default on onesky file upload
  # https://github.com/onesky/api-documentation-platform/blob/master/resources/file.md#upload---upload-a-file
  if params[:is_allow_translation_same_as_original]
    body_hash[:is_allow_translation_same_as_original] = true
  end

  resp = RestClient.post(url,
                         body_hash,
                         request_params)

  if resp.code == 201
    UI.success "#{File.basename params[:strings_file_path]} was successfully uploaded to project #{params[:project_id]} in OneSky"
  else
    UI.error "Error uploading file to OneSky, Status code is #{resp.code}"
  end
end