Class: DeviceAPI::IOS::IDeviceInstaller

Inherits:
Execution
  • Object
show all
Defined in:
lib/device_api/ios/ideviceinstaller.rb

Overview

Namespace for all methods encapsulating idevice calls

Class Method Summary collapse

Class Method Details

.change_package(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
# File 'lib/device_api/ios/ideviceinstaller.rb', line 29

def self.change_package(options = {})
  package = options[:package]
  ipa = options[:ipa]
  serial = options[:serial]
  action = options[:action]

  command = nil
  if action == :install
    command = "ideviceinstaller -u '#{serial}' -i '#{ipa}'"
  elsif action == :uninstall
    command = "ideviceinstaller -u '#{serial}' -U '#{package}'"
  end

  raise IDeviceInstallerError.new('No action specified') if command.nil?

  result = execute(command)

  raise IDeviceInstallerError.new(result.stderr) if result.exit != 0

  lines = result.stdout.split("\n").map { |line| line.gsub('-', '').strip }

  return true if lines.last.match('Complete')
  false
end

.install_ipa(options = {}) ⇒ Boolean

Installs a given IPA to the specified device

Options Hash (options):

  • :ipa (String)

    path to the IPA to install

  • :serial (String)

    serial of the target device



14
15
16
17
# File 'lib/device_api/ios/ideviceinstaller.rb', line 14

def self.install_ipa(options = {})
  options[:action] = :install
  change_package(options)
end

.list_installed_packages(serial) ⇒ Hash

Lists packages installed on the specified device



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/device_api/ios/ideviceinstaller.rb', line 57

def self.list_installed_packages(serial)
  result = execute("ideviceinstaller -u '#{serial}' -l")

  raise IDeviceInstallerError.new(result.stderr) if result.exit != 0

  lines = result.stdout.split("\n")
  lines.shift
  packages = {}
  lines.each do |line|
    if /(.*)\s+-\s+(.*)\s+(\d.*)/.match(line)
      packages[Regexp.last_match[2]] = { package_name: Regexp.last_match[1], version: Regexp.last_match[3] }
    end
  end
  packages
end

.package_installed?(options = {}) ⇒ Boolean

Check to see if a package is installed

Options Hash (options):

  • :package (String)

    package ID to check for

  • :serial (String)

    serial of the target device



78
79
80
81
82
83
84
85
86
# File 'lib/device_api/ios/ideviceinstaller.rb', line 78

def self.package_installed?(options = {})
  package = options[:package]
  serial  = options[:serial]

  installed_packages = list_installed_packages(serial)

  matches = installed_packages.select { |_, values| values[:package_name] == package }
  return !matches.empty?
end

.uninstall_package(options = {}) ⇒ Boolean

Uninstalls a specified package from a device

Options Hash (options):

  • :package (String)

    bundle ID of the package to be uninstalled

  • :serial (String)

    serial of the target device



24
25
26
27
# File 'lib/device_api/ios/ideviceinstaller.rb', line 24

def self.uninstall_package(options = {})
  options[:action] = :uninstall
  change_package(options)
end