class DeviceAPI::IOS::Device

Namespace for the Device object.

Attributes

qualifier[RW]

Public Class Methods

create(options = {}) click to toggle source
# File lib/device_api/ios/device.rb, line 16
def self.create options = {}
  self.new(options)
end
new(options = {}) click to toggle source
# File lib/device_api/ios/device.rb, line 20
def initialize(options = {})
  @qualifier = options[:qualifier]
  @serial = options[:serial] || options[:qualifier]
  @state = options[:state]
end

Public Instance Methods

device_class() click to toggle source

Return the device class - i.e. iPad, iPhone, etc @return (String) iOS device class

# File lib/device_api/ios/device.rb, line 56
def device_class
  get_prop('DeviceClass')
end
imei() click to toggle source

Get the IMEI number of the device @return (String) IMEI number of current device

# File lib/device_api/ios/device.rb, line 68
def imei
  get_prop('InternationalMobileEquipmentIdentity')
end
install(ipa) click to toggle source

Install a specified IPA @param [String] ipa string containing path to the IPA to install @return [Boolean, Exception] true when the IPA installed successfully, otherwise an error is raised

# File lib/device_api/ios/device.rb, line 93
def install(ipa)
  fail StandardError, 'No IPA or app specified.', caller if ipa.empty?

  res = install_ipa(ipa)

  fail StandardError, res, caller unless res
  true
end
ip_address() click to toggle source

Get the IP Address from the device @return [String] IP Address of current device

# File lib/device_api/ios/device.rb, line 80
def ip_address
  IPAddress.address(serial)
end
list_installed_packages() click to toggle source
# File lib/device_api/ios/device.rb, line 122
def list_installed_packages
  IDeviceInstaller.list_installed_packages(serial)
end
model() click to toggle source

Look up device model using the ios-devices gem - changing 'iPad4,7' to 'iPad mini 3' @return (String) human readable model and version (where applicable)

# File lib/device_api/ios/device.rb, line 44
def model
  Ios::Devices.search(get_prop('ProductType')).name
end
name() click to toggle source

Look up device name - i.e. Bob's iPhone @return (String) iOS device name

# File lib/device_api/ios/device.rb, line 38
def name
  IDeviceName.name(serial)
end
reboot() click to toggle source

Reboot the device

# File lib/device_api/ios/device.rb, line 127
def reboot
  restart
end
restart() click to toggle source
# File lib/device_api/ios/device.rb, line 131
def restart
  IDeviceDiagnostics.restart(serial)
end
screenshot(args = {}) click to toggle source

Capture screenshot on device

# File lib/device_api/ios/device.rb, line 61
def screenshot(args = {})
  args[:device_id] = serial
  IDeviceScreenshot.capture(args)
end
status() click to toggle source

Mapping of device status - used to provide a consistent status across platforms @return (String) common status string

# File lib/device_api/ios/device.rb, line 28
def status
  {
      'device' => :ok,
      'no device' => :dead,
      'offline' => :offline
  }[@state]
end
trusted?() click to toggle source

Has the 'Trust this device' dialog been accepted? @return (Boolean) true if the device is trusted, otherwise false

# File lib/device_api/ios/device.rb, line 74
def trusted?
  IDevice.trusted?(serial)
end
type() click to toggle source

Return whether or not the device is a tablet or mobile @return [Symbol] :tablet or :mobile depending on device_class

# File lib/device_api/ios/device.rb, line 114
def type
  if device_class.downcase == 'ipad'
    :tablet
  else
    :mobile
  end
end
uninstall(package_name) click to toggle source

Uninstall a specified package @param [String] package_name string containing name of package to uninstall @return [Boolean, Exception] true when the package is uninstalled successfully, otherwise an error is raised

# File lib/device_api/ios/device.rb, line 105
def uninstall(package_name)
  res = uninstall_package(package_name)

  fail StandardError, res, caller unless res
  true
end
version() click to toggle source

Returns the devices iOS version number - i.e. 8.2 @return (String) iOS version number

# File lib/device_api/ios/device.rb, line 50
def version
  get_prop('ProductVersion')
end
wifi_mac_address() click to toggle source

Get the Wifi Mac address for the current device @return [String] Mac address of current device

# File lib/device_api/ios/device.rb, line 86
def wifi_mac_address
  get_prop('WiFiAddress')
end

Private Instance Methods

get_prop(key) click to toggle source
# File lib/device_api/ios/device.rb, line 137
def get_prop(key)
  if !@props || !@props[key]
    @props = IDevice.get_props(serial)
  end
  @props[key]
end
install_ipa(ipa) click to toggle source
# File lib/device_api/ios/device.rb, line 144
def install_ipa(ipa)
  IDeviceInstaller.install_ipa(ipa: ipa, serial: serial)
end
uninstall_package(package_name) click to toggle source
# File lib/device_api/ios/device.rb, line 148
def uninstall_package(package_name)
  IDeviceInstaller.uninstall_package(package: package_name, serial: serial)
end