Class: Fastlane::Actions::UploadToServerAction

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

Class Method Summary collapse

Class Method Details

.authorsObject



67
68
69
# File 'lib/fastlane/plugin/upload_to_server/actions/upload_to_server_action.rb', line 67

def self.authors
  ["Maxim Toyberman"]
end

.available_optionsObject



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
# File 'lib/fastlane/plugin/upload_to_server/actions/upload_to_server_action.rb', line 80

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)

  ]
end

.descriptionObject



63
64
65
# File 'lib/fastlane/plugin/upload_to_server/actions/upload_to_server_action.rb', line 63

def self.description
  "Upload IPA and APK to your own server"
end

.detailsObject



75
76
77
78
# File 'lib/fastlane/plugin/upload_to_server/actions/upload_to_server_action.rb', line 75

def self.details
  # Optional:
  "Upload IPA and APK to your custom server, with multipart/form-data"
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


116
117
118
# File 'lib/fastlane/plugin/upload_to_server/actions/upload_to_server_action.rb', line 116

def self.is_supported?(platform)
  platform == :ios || platform == :android
end

.return_valueObject



71
72
73
# File 'lib/fastlane/plugin/upload_to_server/actions/upload_to_server_action.rb', line 71

def self.return_value
  # If your method provides a return value, you can describe here what it does
end

.run(config) ⇒ 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
# 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[: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) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/fastlane/plugin/upload_to_server/actions/upload_to_server_action.rb', line 35

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) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/fastlane/plugin/upload_to_server/actions/upload_to_server_action.rb', line 49

def self.upload_file(params, multipart_payload)
  request = RestClient::Request.new(
    method: :post,
    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