class Fastlane::Actions::UploadToServerAction

Public Class Methods

authors() click to toggle source
# File lib/fastlane/plugin/upload_to_server/actions/upload_to_server_action.rb, line 68
def self.authors
  ["Maxim Toyberman"]
end
available_options() click to toggle source
# File lib/fastlane/plugin/upload_to_server/actions/upload_to_server_action.rb, line 81
def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :apk,
                            env_name: "",
                            description: ".apk file for the build",
                            optional: true,
                            default_value: Actions.lane_context[SharedValues::GRADLE_APK_OUTPUT_PATH]),
    FastlaneCore::ConfigItem.new(key: :ipa,
                            env_name: "",
                            description: ".ipa file for the build ",
                            optional: true,
                            default_value: Actions.lane_context[SharedValues::IPA_OUTPUT_PATH]),
    FastlaneCore::ConfigItem.new(key: :file,
                            env_name: "",
                            description: "file to be uploaded to the server",
                            optional: true),
    FastlaneCore::ConfigItem.new(key: :multipartPayload,
                            env_name: "",
                            description: "payload for the multipart request ",
                            optional: true,
                            type: Hash),
    FastlaneCore::ConfigItem.new(key: :headers,
                              env_name: "",
                              description: "headers of the request ",
                              optional: true,
                              type: Hash),
    FastlaneCore::ConfigItem.new(key: :endPoint,
                            env_name: "",
                            description: "file upload request url",
                            optional: false,
                            default_value: "",
                            type: String),
    FastlaneCore::ConfigItem.new(key: :method,
                            env_name: "",
                            description: "request method",
                            optional: true,
                            default_value: :post,
                            type: Symbol)

  ]
end
description() click to toggle source
# File lib/fastlane/plugin/upload_to_server/actions/upload_to_server_action.rb, line 64
def self.description
  "Upload IPA and APK to your own server"
end
details() click to toggle source
# File lib/fastlane/plugin/upload_to_server/actions/upload_to_server_action.rb, line 76
def self.details
  # Optional:
  "Upload IPA and APK to your custom server, with multipart/form-data"
end
is_supported?(platform) click to toggle source
# File lib/fastlane/plugin/upload_to_server/actions/upload_to_server_action.rb, line 123
def self.is_supported?(platform)
  platform == :ios || platform == :android
end
return_value() click to toggle source
# File lib/fastlane/plugin/upload_to_server/actions/upload_to_server_action.rb, line 72
def self.return_value
  # If your method provides a return value, you can describe here what it does
end
run(config) click to toggle source
# File lib/fastlane/plugin/upload_to_server/actions/upload_to_server_action.rb, line 8
def self.run(config)
  params = {}
  # extract parms from config received from fastlane
  params[:endPoint] = config[:endPoint]
  params[:apk] = config[:apk]
  params[:ipa] = config[:ipa]
  params[:file] = config[:file]
  params[:method] = config[:method]

  params[:multipartPayload] = config[:multipartPayload]
  params[:headers] = config[:headers]

  apk_file = params[:apk]
  ipa_file = params[:ipa]
  custom_file = params[:file]
  
  end_point = params[:endPoint]

  UI.user_error!("No endPoint given, pass using endPoint: 'endpoint'") if end_point.to_s.length == 0 && end_point.to_s.length == 0
  UI.user_error!("No IPA or APK or a file path given, pass using `ipa: 'ipa path'` or `apk: 'apk path' or file:`") if ipa_file.to_s.length == 0 && apk_file.to_s.length == 0 && custom_file.to_s.length == 0
  UI.user_error!("Please only give IPA path or APK path (not both)") if ipa_file.to_s.length > 0 && apk_file.to_s.length > 0

  upload_custom_file(params, apk_file) if apk_file.to_s.length > 0
  upload_custom_file(params, ipa_file) if ipa_file.to_s.length > 0
  upload_custom_file(params, custom_file) if custom_file.to_s.length > 0

end
upload_custom_file(params, custom_file) click to toggle source
# File lib/fastlane/plugin/upload_to_server/actions/upload_to_server_action.rb, line 36
def self.upload_custom_file(params, custom_file)
  multipart_payload = params[:multipartPayload]
  multipart_payload[:multipart] = true
  if multipart_payload[:fileFormFieldName]
    key = multipart_payload[:fileFormFieldName]
    multipart_payload["#{key}"] = File.new(custom_file, 'rb')
  else
    multipart_payload[:file] = File.new(custom_file, 'rb')
  end

UI.message multipart_payload
upload_file(params, multipart_payload)
end
upload_file(params, multipart_payload) click to toggle source
# File lib/fastlane/plugin/upload_to_server/actions/upload_to_server_action.rb, line 50
def self.upload_file(params, multipart_payload)
  request = RestClient::Request.new(
    method: params[:method],
    url: params[:endPoint],
    payload: multipart_payload,
    headers: params[:headers],
    log: Logger.new(STDOUT)
  )

  response = request.execute
  UI.message(response)
  UI.success("Successfully finished uploading the fille") if response.code == 200 || response.code == 201
end