Sha256: ad638ddaee71d14d9a9b2f05f39063d705a592a55175a7ea3f989539a47420bd

Contents?: true

Size: 1.91 KB

Versions: 35

Compression:

Stored size: 1.91 KB

Contents

module Fastlane
  module Actions
    module SharedValues
      DOWNLOAD_CONTENT = :DOWNLOAD_CONTENT
    end

    class DownloadAction < Action
      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

      #####################################################
      # @!group Documentation
      #####################################################

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

      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

      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

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

      def self.authors
        ["KrauseFx"]
      end

      def self.is_supported?(platform)
        true
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
fastlane-1.104.0 lib/fastlane/actions/download.rb
fastlane-1.103.0 lib/fastlane/actions/download.rb
fastlane-1.102.0 lib/fastlane/actions/download.rb
fastlane-1.101.0 lib/fastlane/actions/download.rb
fastlane-1.100.0 lib/fastlane/actions/download.rb
fastlane-1.99.0 lib/fastlane/actions/download.rb
fastlane-1.98.0 lib/fastlane/actions/download.rb
fastlane-1.97.2 lib/fastlane/actions/download.rb
fastlane-1.97.1 lib/fastlane/actions/download.rb
fastlane-1.97.0 lib/fastlane/actions/download.rb
fastlane-1.96.0 lib/fastlane/actions/download.rb
fastlane-1.95.0 lib/fastlane/actions/download.rb
fastlane-1.94.1 lib/fastlane/actions/download.rb
fastlane-1.94.0 lib/fastlane/actions/download.rb
fastlane-1.93.1 lib/fastlane/actions/download.rb
fastlane-1.93.0 lib/fastlane/actions/download.rb
fastlane-1.92.0 lib/fastlane/actions/download.rb
fastlane-1.92.0.beta2 lib/fastlane/actions/download.rb
fastlane-1.92.0.beta1 lib/fastlane/actions/download.rb
fastlane-1.91.0 lib/fastlane/actions/download.rb