Class: Fastlane::Actions::DownloadJsonAction

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

Class Method Summary collapse

Class Method Details

.authorsObject



68
69
70
# File 'lib/fastlane/plugin/json/actions/download_json_action.rb', line 68

def self.authors
  ["Martin Gonzalez"]
end

.available_optionsObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/fastlane/plugin/json/actions/download_json_action.rb', line 39

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :json_url,
                                 description: "Url to json file",
                                 is_string: true,
                                 optional: false,
                                 verify_block: proc do |value|
                                   UI.user_error!("You must set json_url pointing to a json file") unless value && !value.empty?
                                 end),
    FastlaneCore::ConfigItem.new(key: :verbose,
                                 description: "verbose",
                                 optional: true,
                                 type: Boolean,
                                 default_value: false)

  ]
end

.descriptionObject



31
32
33
# File 'lib/fastlane/plugin/json/actions/download_json_action.rb', line 31

def self.description
  "Downloads a json file and expose a hash with symbolized names as result"
end

.detailsObject



35
36
37
# File 'lib/fastlane/plugin/json/actions/download_json_action.rb', line 35

def self.details
  "Use this action to download a json file and access to it as Hash with symbolized names"
end

.is_supported?(_platform) ⇒ Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/fastlane/plugin/json/actions/download_json_action.rb', line 72

def self.is_supported?(_platform)
  true
end


57
58
59
60
61
62
# File 'lib/fastlane/plugin/json/actions/download_json_action.rb', line 57

def self.print_params(options)
  table_title = "Params for download_json #{Fastlane::Json::VERSION}"
  FastlaneCore::PrintTable.print_values(config: options,
                                        hide_keys: [],
                                        title: table_title)
end

.puts_error!(message) ⇒ Object

Raises:

  • (StandardError)


26
27
28
29
# File 'lib/fastlane/plugin/json/actions/download_json_action.rb', line 26

def self.puts_error!(message)
  UI.user_error!(message)
  raise StandardError, message
end

.return_valueObject



64
65
66
# File 'lib/fastlane/plugin/json/actions/download_json_action.rb', line 64

def self.return_value
  "Hash"
end

.run(params) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/fastlane/plugin/json/actions/download_json_action.rb', line 9

def self.run(params)
  json_url = params[:json_url]
  @is_verbose = params[:verbose]
  uri = URI(json_url)
  print_params(params) if @is_verbose
  puts("Downloading json from #{uri}") if @is_verbose

  begin
    response = Net::HTTP.get_response(uri)
    JSON.parse(response.body, symbolize_names: true)
  rescue JSON::ParserError
    puts_error!("Downloaded json has invalid content ❌")
  rescue => exception
    puts_error!("Failed to download json. Message: #{exception.message}")
  end
end