Skip to content

Instantly share code, notes, and snippets.

@horimislime
Created December 1, 2016 05:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save horimislime/53e6406d4f73c1ef5fc7dc1977e566e9 to your computer and use it in GitHub Desktop.
Save horimislime/53e6406d4f73c1ef5fc7dc1977e566e9 to your computer and use it in GitHub Desktop.
# coding: utf-8
require 'open-uri'
module Fastlane
module Actions
class DownloadCrowdinResourceAction < Action
HOST_NAME = 'https://api.crowdin.com'
def self.run(params)
token = params[:api_token]
project_id = params[:project_identifier]
language = params[:language]
path = params[:download_path]
file = params[:file_to_download]
download_url = "#{HOST_NAME}/api/project/#{project_id}/export-file?key=#{token}&language=#{language}&file=#{file}"
File.open(path, "wb") do |saved_file|
open(download_url, "rb") do |read_file|
saved_file.write(read_file.read)
end
end
UI.success "Successfully downloaded localization."
end
def self.description
"Download localization resource from Crowdin"
end
def self.authors
["horimislime"]
end
def self.available_options
[
FastlaneCore::ConfigItem.new(key: :api_token,
env_name: "CROWDIN_API_TOKEN",
description: "API Token for Crowdin Access",
optional: false,
type: String,
verify_block: proc do |value|
UI.user_error!("No API token given, pass using `api_token: 'token'`") if value.to_s.length == 0
end),
FastlaneCore::ConfigItem.new(key: :project_identifier,
env_name: "CROWDIN_PROJECT_IDENTIFIER",
description: "Public identifier of the Crowdin project",
optional: false,
type: String,
verify_block: proc do |value|
UI.user_error!("No public identifier given, pass using `public_identifier: 'public_identifier'`") if value.to_s.length == 0
end),
FastlaneCore::ConfigItem.new(key: :language,
env_name: "CROWDIN_LANGUAGE_CODE",
description: "Language code of localization you want to download",
optional: true,
type: String,
default_value: 'en'),
FastlaneCore::ConfigItem.new(key: :download_path,
env_name: "CROWDIN_RESOURCE_DOWNLOAD_PATH",
description: "The location you want to save Crowdin resource in",
optional: false,
type: String),
FastlaneCore::ConfigItem.new(key: :file_to_download,
env_name: "CROWDIN_RESOURCE_DOWNLOAD_FILE",
description: "The localization file you want to download",
optional: false,
type: String)
]
end
def self.is_supported?(platform)
[:ios, :tvos, :osx, :watchos].include?(platform)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment