Class: Fastlane::Actions::DownloadAction

Inherits:
Fastlane::Action show all
Defined in:
lib/fastlane/actions/download.rb

Constant Summary

Constants inherited from Fastlane::Action

Fastlane::Action::AVAILABLE_CATEGORIES

Documentation collapse

Class Method Summary collapse

Methods inherited from Fastlane::Action

action_name, author, lane_context, method_missing, other_action, return_value, sample_return_value, sh, step_text

Class Method Details

.authorsObject



67
68
69
# File 'lib/fastlane/actions/download.rb', line 67

def self.authors
  ["KrauseFx"]
end

.available_optionsObject



40
41
42
43
44
45
46
47
48
49
# File 'lib/fastlane/actions/download.rb', line 40

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :url,
                                 env_name: "FL_DOWNLOAD_URL",
                                 description: "The URL that should be downloaded",
                                 verify_block: proc do |value|
                                   UI.important("The URL doesn't start with http or https") unless value.start_with?("http")
                                 end)
  ]
end

.categoryObject



63
64
65
# File 'lib/fastlane/actions/download.rb', line 63

def self.category
  :misc
end

.descriptionObject



28
29
30
# File 'lib/fastlane/actions/download.rb', line 28

def self.description
  "Download a file from a remote server (e.g. JSON file)"
end

.detailsObject



32
33
34
35
36
37
38
# File 'lib/fastlane/actions/download.rb', line 32

def self.details
  [
    "Specify the URL to download and get the content as a return value",
    "For more advanced networking code, use the Ruby functions instead:",
    "http://docs.ruby-lang.org/en/2.0.0/Net/HTTP.html"
  ].join("\n")
end

.example_codeObject



57
58
59
60
61
# File 'lib/fastlane/actions/download.rb', line 57

def self.example_code
  [
    'data = download(url: "https://host.com/api.json")'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/fastlane/actions/download.rb', line 71

def self.is_supported?(platform)
  true
end

.outputObject



51
52
53
54
55
# File 'lib/fastlane/actions/download.rb', line 51

def self.output
  [
    ['DOWNLOAD_CONTENT', 'The content of the file we just downloaded']
  ]
end

.run(params) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/fastlane/actions/download.rb', line 8

def self.run(params)
  require 'net/http'

  begin
    result = Net::HTTP.get(URI(params[:url]))
    begin
      result = JSON.parse(result) # try to parse and see if it's valid JSON data
    rescue
      # never mind, using standard text data instead
    end
    Actions.lane_context[SharedValues::DOWNLOAD_CONTENT] = result
  rescue => ex
    UI.user_error!("Error fetching remote file: #{ex}")
  end
end