class Establish::ItunesTransporter

Constants

ERROR_REGEX
OUTPUT_REGEX
WARNING_REGEX

Public Class Methods

new(user = nil, password = nil) click to toggle source
# File lib/establish/itunes_transporter.rb, line 12
def initialize(user = nil, password = nil)
  @user = (user || PasswordManager.new.username)
  @password = (password || PasswordManager.new.password)
end

Public Instance Methods

download(app, dir = nil) click to toggle source
# File lib/establish/itunes_transporter.rb, line 17
def download(app, dir = nil)
  raise "No valid Establish::App given" unless app.kind_of?Establish::App

  dir ||= app.get_metadata_directory
  command = build_download_command(@user, @password, app.apple_id, dir)

  self.execute_transporter(command)
end
execute_transporter(command) click to toggle source
# File lib/establish/itunes_transporter.rb, line 37
def execute_transporter(command)
  # Taken from https://github.sshaw/itunes_store_transporter/blob/master/lib/itunes/store/transporter/output_parser.rb

  errors = []
  warnings = []

  begin
    PTY.spawn(command) do |stdin, stdout, pid|
      stdin.each do |line|
        if line =~ ERROR_REGEX
          errors << $1
        elsif line =~ WARNING_REGEX
          warnings << $1
        end

        if line =~ OUTPUT_REGEX
          # General logging for debug purposes
          Helper.log.debug "[Transporter Output]: #{$1}"
        end
      end
    end
  rescue Exception => ex
    Helper.log.fatal(ex.to_s)
    errors << ex.to_s
  end

  if errors.count > 0
    Helper.log.debug(caller)
    raise errors.join("\n")
  end

  true
end
upload(app, dir) click to toggle source
# File lib/establish/itunes_transporter.rb, line 26
def upload(app, dir)
  raise "No valid Establish::App given" unless app.kind_of?Establish::App

  dir ||= app.get_metadata_directory
  dir += "/#{app.apple_id}.itmsp"

  command = build_upload_command(@user, @password, app.apple_id, dir)

  self.execute_transporter(command)
end

Private Instance Methods

build_download_command(username, password, apple_id, destination = "/tmp") click to toggle source
# File lib/establish/itunes_transporter.rb, line 72
def build_download_command(username, password, apple_id, destination = "/tmp")
  [
      Helper.transporter_path,
      "-m lookupMetadata",
      "-u \"#{useername}\"",
      "-p '#{escaped_password(password)}'",
      "-apple_id #{apple_id}",
      "-destination '#{destination}'"
  ].join(' ')
end
build_upload_command(username, password, apple_id, source = "/tmp") click to toggle source
# File lib/establish/itunes_transporter.rb, line 83
def build_upload_command(username, password, apple_id, source = "/tmp")
  [
      Helper.transporter_path,
      "-m upload",
      "-u \"#{username}\"",
      "-p '#{escaped_password(password)}'",
      "-f '#{source}'"
  ].join(' ')
end
escaped_password(password) click to toggle source
# File lib/establish/itunes_transporter.rb, line 93
def escaped_password(password)
  password.gsub('$', '\\$')
end