class Shenzhen::Plugins::FTP::Client

Public Class Methods

new(host, port, user, password) click to toggle source
# File lib/shenzhen/plugins/ftp.rb, line 8
def initialize(host, port, user, password)
  @host, @port, @user, @password = host, port, user, password
end

Public Instance Methods

upload(ipa, options = {}) click to toggle source
# File lib/shenzhen/plugins/ftp.rb, line 12
def upload(ipa, options = {})
  connection = Net::FTP.new
  connection.passive = true
  connection.connect(@host, @port)

  path = expand_path_with_substitutions_from_ipa_plist(ipa, options[:path])

  begin
    connection.login(@user, @password) rescue raise "Login authentication failed"

    if options[:mkdir]
      components, pwd = path.split(/\//).reject(&:empty?), nil
      components.each do |component|
        pwd = File.join(*[pwd, component].compact)

        begin
          connection.mkdir pwd
        rescue => exception
          raise exception unless /File exists/ === exception.message
        end
      end
    end

    connection.chdir path unless path.empty?
    connection.putbinaryfile ipa, File.basename(ipa)
    connection.putbinaryfile(options[:dsym], File.basename(options[:dsym])) if options[:dsym]
  ensure
    connection.close
  end
end

Private Instance Methods

expand_path_with_substitutions_from_ipa_plist(ipa, path) click to toggle source
# File lib/shenzhen/plugins/ftp.rb, line 45
def expand_path_with_substitutions_from_ipa_plist(ipa, path)
  substitutions = path.scan(/\{CFBundle[^}]+\}/)
  return path if substitutions.empty?

  Dir.mktmpdir do |dir|
    system "unzip -q #{ipa} -d #{dir} 2> /dev/null"

    plist = Dir["#{dir}/**/*.app/Info.plist"].last

    substitutions.uniq.each do |substitution|
      key = substitution[1...-1]
      value = Shenzhen::PlistBuddy.print(plist, key)

      path.gsub!(Regexp.new(substitution), value) if value
    end
  end

  return path
end