class Fastlane::Actions::YafirimAction

Public Class Methods

authors() click to toggle source
# File lib/fastlane/plugin/yafirim/actions/yafirim_action.rb, line 105
def self.authors
  ["wd"]
end
available_options() click to toggle source
# File lib/fastlane/plugin/yafirim/actions/yafirim_action.rb, line 118
def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :api_token,
                                 short_option: "-a",
                                 optional: true,
                                 description: "fir.im user api token"),

    # Content path
    FastlaneCore::ConfigItem.new(key: :ipa,
                                 short_option: "-i",
                                 optional: true,
                                 description: "Path to your ipa file",
                                 default_value: Dir["*.ipa"].first,
                                 verify_block: proc do |value|
                                   UI.user_error!("Could not find ipa file at path '#{value}'") unless File.exist?(value)
                                   UI.user_error!("'#{value}' doesn't seem to be an ipa file") unless value.end_with?(".ipa")
                                 end,
                                 conflicting_options: [:apk_path],
                                 conflict_block: proc do |value|
                                   UI.user_error!("You can't use 'ipa' and '#{value.key}' options in one run.")
                                 end),

    FastlaneCore::ConfigItem.new(key: :apk_path,
                                 short_option: "-p",
                                 optional: true,
                                 description: "Path to your apk file",
                                 verify_block: proc do |value|
                                   UI.user_error!("Directory '#{value}' not exists.") unless Dir.exist?(value)
                                 end,
                                 conflicting_options: [:ipa],
                                 conflict_block: proc do |value|
                                   UI.user_error!("You can't use 'apk_path' and '#{value.key}' options in one run.")
                                 end),

    FastlaneCore::ConfigItem.new(key: :file,
                                 description: "file",
                                 optional: true),

    FastlaneCore::ConfigItem.new(key: :bundle_id,
                                 description: "bundle id",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :name,
                                 description: "app name",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :version,
                                 description: "app version",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :build_version,
                                 description: "app build version number",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :build_type,
                                 description: "app build type",
                                 optional: true),
  ]
end
description() click to toggle source
# File lib/fastlane/plugin/yafirim/actions/yafirim_action.rb, line 101
def self.description
  "Yet another fastlane fir.im plugin"
end
details() click to toggle source
# File lib/fastlane/plugin/yafirim/actions/yafirim_action.rb, line 113
def self.details
  # Optional:
  "A fastlane plugin to help you upload your ipa/apk to fir.im"
end
get_upload_token() click to toggle source
# File lib/fastlane/plugin/yafirim/actions/yafirim_action.rb, line 41
def self.get_upload_token
  firim_client = Faraday.new(@token_url,
                             {
                               request: {
                                 timeout:       300,
                                 open_timeout:  300
                               }
                             }
                            ) do |c|
    c.request  :url_encoded             # form-encode POST params
    c.adapter  :net_http
    c.response :json, :content_type => /\bjson$/
  end
  
  response = firim_client.post do |req|
    req.url @token_url
    req.body = { :type => @platform, :bundle_id => @options[:bundle_id], :api_token => @options[:api_token] }
  end

  info = response.body
  self.validation_response info

  UI.message(info)
  UI.message(info['cert']['binary'])
  return info['cert']['binary']
end
is_supported?(platform) click to toggle source
# File lib/fastlane/plugin/yafirim/actions/yafirim_action.rb, line 174
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, :android].include?(platform)
end
return_value() click to toggle source
# File lib/fastlane/plugin/yafirim/actions/yafirim_action.rb, line 109
def self.return_value
  # If your method provides a return value, you can describe here what it does
end
run(params) click to toggle source
# File lib/fastlane/plugin/yafirim/actions/yafirim_action.rb, line 9
def self.run(params)
  UI.message("Yafirim Begin process")
  @options = params
  if @options[:ipa]
    @platform = 'ios'
    Yafirim::DetectIosValues.new.run!(@options)
    @options[:file] = @options[:ipa]
  else
    @platform = 'android'
    Yafirim::DetectAndroidValues.new.run!(@options)
    @options[:file] = @options[:apk_path] + @options[:name] + "_" + @options[:version] + "_" + @options[:build_version] + "_" + @options[:build_type] + ".apk"
  end

  UI.user_error!("Error, file #{@options[:file]} not exists.") unless File.exist?(@options[:file])
  FastlaneCore::PrintTable.print_values(config: @options)

  binary_info = self.get_upload_token

  begin
    self.upload_binary binary_info
  rescue Exception => e
    raise e
  end
end
upload_binary(binary_info) click to toggle source
# File lib/fastlane/plugin/yafirim/actions/yafirim_action.rb, line 68
def self.upload_binary binary_info
  params = {
    'key' => binary_info['key'],
    'token' => binary_info['token'],
    'file' => Faraday::UploadIO.new(@options[:file], 'application/octet-stream'),
    'x:name' => @options[:name],
    'x:version' => @options[:version],
    'x:build' => @options[:build_version]
  }

  UI.message "Start upload #{@options[:name]} binary..."

  firim_client = Faraday.new(nil,
                             {
                               request: {
                                 timeout:       6000,
                                 open_timeout:  300
                               }
                             }
                            ) do |c|
    c.request :multipart
    c.request :url_encoded
    c.response :json, content_type: /\bjson$/
    c.adapter :net_http
  end

  response = firim_client.post binary_info['upload_url'], params
  unless response.body['is_completed']
    raise UI.user_error!("Upload binary to Qiniu error #{response.body}")
  end
  UI.success 'Upload binary successed!'
end
validation_response(response_data) click to toggle source
# File lib/fastlane/plugin/yafirim/actions/yafirim_action.rb, line 34
def self.validation_response response_data
  error_code = response_data['code'].to_i rescue 0
  if error_code == 100020
    UI.user_error!("Firim API Token(#{@options[:api_token]}) not correct")
  end
end