class Fastlane::Actions::DownloadJsonAction

Public Class Methods

authors() click to toggle source
# File lib/fastlane/plugin/json/actions/download_json_action.rb, line 68
def self.authors
  ["Martin Gonzalez"]
end
available_options() click to toggle source
# 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
description() click to toggle source
# 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
details() click to toggle source
# 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) click to toggle source
# File lib/fastlane/plugin/json/actions/download_json_action.rb, line 72
def self.is_supported?(_platform)
  true
end
print_params(options) click to toggle source
puts_error!(message) click to toggle source
# 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_value() click to toggle source
# File lib/fastlane/plugin/json/actions/download_json_action.rb, line 64
def self.return_value
  "Hash"
end
run(params) click to toggle source
# 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