Class: Fastlane::Actions::FileioUploadAction

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

Documentation collapse

Class Method Summary collapse

Class Method Details

.authorsObject



111
112
113
# File 'lib/fastlane/plugin/fileio_upload/actions/fileio_upload_action.rb', line 111

def self.authors
  ["https://github.com/paul1893"]
end

.available_optionsObject



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
# File 'lib/fastlane/plugin/fileio_upload/actions/fileio_upload_action.rb', line 72

def self.available_options
  # Define all options your action supports.
  [
    FastlaneCore::ConfigItem.new(key: :file,
                                 description: "The file you want to upload",
                                 verify_block: proc do |value|
                                    UI.user_error!("No file to upload, pass using `file: 'my-file.txt'` or couldn't find file at path '#{value}'") unless File.exist?(value)
                                 end),
    FastlaneCore::ConfigItem.new(key: :expiration,
                                 description: "Duration before expiration",
                                 is_string: true,
                                 default_value: false),
    FastlaneCore::ConfigItem.new(key: :apiKey,
                                 description: "ApiKey to use to upload large file",
                                 is_string: true,
                                 default_value: ""),
    FastlaneCore::ConfigItem.new(key: :maxDownloads,
                                 description: "Max downloads authorized",
                                 default_value: 0,
                                 type: Integer),
    FastlaneCore::ConfigItem.new(key: :autoDelete,
                                 description: "Should auto delete after max downloads reached",
                                 default_value: false,
                                 type: Boolean)
  ]
end

.descriptionObject



63
64
65
# File 'lib/fastlane/plugin/fileio_upload/actions/fileio_upload_action.rb', line 63

def self.description
  "Upload file to file.io and share the link with anyone!"
end

.detailsObject



67
68
69
70
# File 'lib/fastlane/plugin/fileio_upload/actions/fileio_upload_action.rb', line 67

def self.details
  # Optional:
  # this is your chance to provide a more detailed description of this action
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


115
116
117
# File 'lib/fastlane/plugin/fileio_upload/actions/fileio_upload_action.rb', line 115

def self.is_supported?(platform)
  [:ios, :mac].include?(platform)
end

.outputObject



99
100
101
102
103
104
105
# File 'lib/fastlane/plugin/fileio_upload/actions/fileio_upload_action.rb', line 99

def self.output
  # Define the shared values you are going to provide
  [
    ['UPLOAD_FILE_RESULT', 'Result of the upload success or failure'],
    ['UPLOAD_FILE_LINK', 'Link where the file is accessible after upload']
  ]
end

.return_valueObject



107
108
109
# File 'lib/fastlane/plugin/fileio_upload/actions/fileio_upload_action.rb', line 107

def self.return_value
  "Link where the file is accessible after upload"
end

.run(params) ⇒ Object



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
52
53
54
55
56
57
# File 'lib/fastlane/plugin/fileio_upload/actions/fileio_upload_action.rb', line 13

def self.run(params)
  Actions.verify_gem!('rest-client')
  require 'rest-client'
  
  file = params[:file]
  expiration = params[:expiration]
  apiKey = params[:apiKey]
  maxDownloads = params[:maxDownloads]
  autoDelete = params[:autoDelete]

  UI.message "Start uploading: #{file} with #{expiration} expiration"

  headers = {
    "Authorization"=>"Bearer #{apiKey}"
  }
  payload = {
              :multipart => true,
              :file => File.new("#{file}", 'rb')
            }
  if (expiration != false)
  then
    payload[:expires] = "#{expiration}"
  end
  if (maxDownloads != 0)
  then
    payload[:maxDownloads] = maxDownloads
  end
  if (autoDelete != false)
  then
    payload[:autoDelete] = autoDelete
  end
  
  upload = RestClient.post(
    "https://file.io/",
    payload,
    headers
  )
  upload_result = JSON.parse(upload)
  UI.message "#{upload_result}"

  Actions.lane_context[SharedValues::UPLOAD_FILE_RESULT] = upload_result['success']
  Actions.lane_context[SharedValues::UPLOAD_FILE_LINK] = upload_result['link']

  upload_result
end