Class: Fastlane::Actions::DownloadJsonAction
- Inherits:
-
Action
- Object
- Action
- Fastlane::Actions::DownloadJsonAction
- Defined in:
- lib/fastlane/plugin/json_auth/actions/download_json_action.rb
Class Method Summary collapse
- .authors ⇒ Object
- .available_options ⇒ Object
- .description ⇒ Object
- .details ⇒ Object
- .is_supported?(_platform) ⇒ Boolean
- .print_params(options) ⇒ Object
- .puts_error!(message) ⇒ Object
- .return_value ⇒ Object
- .run(params) ⇒ Object
Class Method Details
.authors ⇒ Object
95 96 97 |
# File 'lib/fastlane/plugin/json_auth/actions/download_json_action.rb', line 95 def self. ["Martin Gonzalez", "Thang Nguyen"] end |
.available_options ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/fastlane/plugin/json_auth/actions/download_json_action.rb', line 56 def self. [ 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: :username, description: "Basic auth username to download", optional: true, is_string: true, default_value: nil), FastlaneCore::ConfigItem.new(key: :password, description: "Basic auth password to download", optional: true, is_string: true, default_value: nil), FastlaneCore::ConfigItem.new(key: :verbose, description: "verbose", optional: true, type: Boolean, default_value: false) ] end |
.description ⇒ Object
48 49 50 |
# File 'lib/fastlane/plugin/json_auth/actions/download_json_action.rb', line 48 def self.description "Downloads a json file and expose a hash with symbolized names as result" end |
.details ⇒ Object
52 53 54 |
# File 'lib/fastlane/plugin/json_auth/actions/download_json_action.rb', line 52 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
99 100 101 |
# File 'lib/fastlane/plugin/json_auth/actions/download_json_action.rb', line 99 def self.is_supported?(_platform) true end |
.print_params(options) ⇒ Object
84 85 86 87 88 89 |
# File 'lib/fastlane/plugin/json_auth/actions/download_json_action.rb', line 84 def self.print_params() table_title = "Params for download_json #{Fastlane::JsonAuth::VERSION}" FastlaneCore::PrintTable.print_values(config: , hide_keys: [], title: table_title) end |
.puts_error!(message) ⇒ Object
43 44 45 46 |
# File 'lib/fastlane/plugin/json_auth/actions/download_json_action.rb', line 43 def self.puts_error!() UI.user_error!() raise StandardError, end |
.return_value ⇒ Object
91 92 93 |
# File 'lib/fastlane/plugin/json_auth/actions/download_json_action.rb', line 91 def self.return_value "Hash" 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 |
# File 'lib/fastlane/plugin/json_auth/actions/download_json_action.rb', line 13 def self.run(params) json_url = params[:json_url] @is_verbose = params[:verbose] username = params[:username] password = params[:password] uri = URI(json_url) print_params(params) if @is_verbose puts("Downloading json from #{uri}") if @is_verbose begin Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https', verify_mode: OpenSSL::SSL::VERIFY_NONE) do |http| request = Net::HTTP::Get.new(uri.request_uri) if !username.nil? && !username.empty? && !password.nil? && !password.empty? request.basic_auth(params[:username], params[:password]) end response = http.request(request) JSON.parse(response.body, symbolize_names: true) end rescue JSON::ParserError puts_error!("Downloaded json has invalid content.") rescue StandardError => e puts_error!("Failed to download json. Message: #{e.}.") end end |