Class: Fastlane::Actions::AddKeysToLokaliseAction
- Inherits:
-
Action
- Object
- Action
- Fastlane::Actions::AddKeysToLokaliseAction
- Defined in:
- lib/fastlane/plugin/lokalise/actions/add_keys_to_lokalise_action.rb
Documentation collapse
- .authors ⇒ Object
- .available_options ⇒ Object
- .description ⇒ Object
- .is_supported?(platform) ⇒ Boolean
Class Method Summary collapse
Class Method Details
.authors ⇒ Object
103 104 105 |
# File 'lib/fastlane/plugin/lokalise/actions/add_keys_to_lokalise_action.rb', line 103 def self. "Fedya-L" end |
.available_options ⇒ Object
64 65 66 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 |
# File 'lib/fastlane/plugin/lokalise/actions/add_keys_to_lokalise_action.rb', line 64 def self. [ FastlaneCore::ConfigItem.new(key: :api_token, env_name: "LOKALISE_API_TOKEN", description: "API Token for Lokalise", is_string: true, verify_block: proc do |value| raise "No API token for Lokalise given, pass using `api_token: 'token'`".red unless (value and not value.empty?) end), FastlaneCore::ConfigItem.new(key: :project_identifier, env_name: "LOKALISE_PROJECT_ID", description: "Lokalise Project Identifier", is_string: true, verify_block: proc do |value| raise "No Project Identifier for Lokalise given, pass using `project_identifier: 'identifier'`".red unless (value and not value.empty?) end), FastlaneCore::ConfigItem.new(key: :platform_mask, description: "Platform mask where 1 is iOS, 2 is Android, 4 is Web and 16 is Other", optional: true, is_string: false, default_value: 1, verify_block: proc do |value| raise "Platfrom mask is an integer value".red unless value.is_a?(Integer) end), FastlaneCore::ConfigItem.new(key: :keys, description: "Keys to add", optional: false, is_string: false, verify_block: proc do |value| raise "Keys must be passed as array of strings".red unless (value.kind_of? Array and not value.empty?) value.each_with_index do |key, index| raise "Key at index #{index} must be string".red unless key.kind_of? String raise "Key at index #{index} can't be empty".red if key.empty? end end) ] end |
.description ⇒ Object
59 60 61 |
# File 'lib/fastlane/plugin/lokalise/actions/add_keys_to_lokalise_action.rb', line 59 def self.description "Add keys to lokalise" end |
.is_supported?(platform) ⇒ Boolean
108 109 110 |
# File 'lib/fastlane/plugin/lokalise/actions/add_keys_to_lokalise_action.rb', line 108 def self.is_supported?(platform) [:ios, :android, :mac].include? platform end |
.run(params) ⇒ Object
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 48 49 50 51 |
# File 'lib/fastlane/plugin/lokalise/actions/add_keys_to_lokalise_action.rb', line 8 def self.run(params) token = params[:api_token] project_identifier = params[:project_identifier] keys = params[:keys] platform_mask = params[:platform_mask] keysObjects = [] keys.each do |key| keysObjects << { key: key, platform_mask: platform_mask } end request_data = { api_token: token, id: project_identifier, data: keysObjects.to_json } uri = URI("https://api.lokalise.co/api/string/set") request = Net::HTTP::Post.new(uri) request.set_form_data(request_data) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true response = http.request(request) jsonResponse = JSON.parse(response.body) raise "Bad response 🉐\n#{response.body}".red unless jsonResponse.kind_of? Hash if jsonResponse["response"]["status"] == "success" then inserted = jsonResponse["result"]["inserted"] updated = jsonResponse["result"]["updated"] Helper.log.info "Keys uploaded. #{inserted} inserted and #{updated} updated 🚀".green elsif jsonResponse["response"]["status"] == "error" code = jsonResponse["response"]["code"] = jsonResponse["response"]["message"] raise "Response error code #{code} (#{}) 📟".red else raise "Bad response 🉐\n#{jsonResponse}".red end end |