Class: EmergeCLI::Commands::OrderFiles::Download
- Inherits:
-
GlobalOptions
- Object
- Dry::CLI::Command
- GlobalOptions
- EmergeCLI::Commands::OrderFiles::Download
- Defined in:
- lib/commands/order_files/download_order_files.rb
Constant Summary collapse
- EMERGE_ORDER_FILE_URL =
'order-files-prod.emergetools.com'.freeze
Instance Method Summary collapse
- #call(**options) ⇒ Object
-
#initialize(network: nil) ⇒ Download
constructor
A new instance of Download.
Methods inherited from GlobalOptions
Constructor Details
#initialize(network: nil) ⇒ Download
Returns a new instance of Download.
25 26 27 |
# File 'lib/commands/order_files/download_order_files.rb', line 25 def initialize(network: nil) @network = network end |
Instance Method Details
#call(**options) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/commands/order_files/download_order_files.rb', line 29 def call(**) @options = before() begin api_token = @options[:api_token] || ENV.fetch('EMERGE_API_TOKEN', nil) raise 'API token is required' unless api_token raise 'Bundle ID is required' unless @options[:bundle_id] raise 'App version is required' unless @options[:app_version] @network ||= EmergeCLI::Network.new(api_token:, base_url: EMERGE_ORDER_FILE_URL) output_name = @options[:output] || "#{@options[:bundle_id]}-#{@options[:app_version]}.gz" output_name = "#{output_name}.gz" unless output_name.end_with?('.gz') Sync do request = get_order_file([:bundle_id], [:app_version]) response = request.read File.write(output_name, response) if @options[:unzip] Logger.info 'Unzipping order file...' Zlib::GzipReader.open(output_name) do |gz| File.write(output_name.gsub('.gz', ''), gz.read) end end Logger.info 'Order file downloaded successfully' end rescue StandardError => e Logger.error "Failed to download order file: #{e.}" Logger.error 'Check your parameters and try again' raise e ensure @network&.close end end |