Class: ITunes::Store::Transporter::Command::Base

Inherits:
Object
  • Object
show all
Includes:
Option
Defined in:
lib/itunes/store/transporter/command.rb

Direct Known Subclasses

Mode, Version

Constant Summary

Constants included from Option

Option::APPLE_ID, Option::DESTINATION, Option::FAILURE, Option::ITC_PROVIDER, Option::SHORTNAME, Option::SUCCESS, Option::TRANSPORT, Option::VENDOR_ID

Instance Method Summary collapse

Constructor Details

#initialize(config, default_options = {}) ⇒ Base

Returns a new instance of Base.



15
16
17
18
19
# File 'lib/itunes/store/transporter/command.rb', line 15

def initialize(config, default_options = {})
  @config = config
  @shell = Shell.new(@config[:path])
  @default_options = default_options
end

Instance Method Details

#run(options = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/itunes/store/transporter/command.rb', line 21

def run(options = {})
  options = default_options.merge(options)
  argv = create_transporter_options(options)
  stdout_lines = []
  stderr_lines = []

  # TODO: hooks
  exitcode = @shell.exec(argv) do |line, name|
    if name == :stdout
      stdout_lines << line
      $stdout.puts line if config[:print_stdout]
    else
      stderr_lines << line
      $stderr.puts line if config[:print_stderr]
    end
  end

  # TODO: problem as some errors exit 0, e.g., account locked
  if exitcode == 0
    handle_success(stdout_lines, stderr_lines, options)
  else
    handle_error(stdout_lines, stderr_lines, options, exitcode)
  end
end