Class: DeviceAPI::IOS::Device

Inherits:
Device
  • Object
show all
Defined in:
lib/device_api/ios/device.rb

Overview

Namespace for the Device object.

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Device

Returns a new instance of Device.



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

def initialize(options = {})
  @serial = options[:serial]
  @state = options[:state]
end

Instance Method Details

#app_version_number(app) ⇒ String

Get the app version from the specified app

Returns:

  • (String)

    app version



74
75
76
77
# File 'lib/device_api/ios/device.rb', line 74

def app_version_number(app)
  app_info = Plistutil.get_bundle_id_from_app(app)
  app_info['CFBundleVersion']
end

#device_classString

Return the device class - i.e. iPad, iPhone, etc

Returns:

  • (String)

    iOS device class



49
50
51
# File 'lib/device_api/ios/device.rb', line 49

def device_class
  get_prop('DeviceClass')
end

#imeiString

Get the IMEI number of the device

Returns:

  • (String)

    IMEI number of current device



55
56
57
# File 'lib/device_api/ios/device.rb', line 55

def imei
  get_prop('InternationalMobileEquipmentIdentity')
end

#install(ipa) ⇒ Boolean, Exception

Install a specified IPA

Parameters:

  • ipa (String)

    string containing path to the IPA to install

Returns:

  • (Boolean, Exception)

    true when the IPA installed successfully, otherwise an error is raised



94
95
96
97
98
99
100
101
# File 'lib/device_api/ios/device.rb', line 94

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_addressString

Get the IP Address from the device

Returns:

  • (String)

    IP Address of current device



81
82
83
# File 'lib/device_api/ios/device.rb', line 81

def ip_address
  IPAddress.address(serial)
end

#modelString

Look up device model using the ios-devices gem - changing ‘iPad4,7’ to ‘iPad mini 3’

Returns:

  • (String)

    human readable model and version (where applicable)



37
38
39
# File 'lib/device_api/ios/device.rb', line 37

def model
  Ios::Devices.search(get_prop('ProductType')).name
end

#nameString

Look up device name - i.e. Bob’s iPhone

Returns:

  • (String)

    iOS device name



31
32
33
# File 'lib/device_api/ios/device.rb', line 31

def name
  IDeviceName.name(serial)
end

#package_name(app) ⇒ String

Get the app bundle ID from the specified app

Returns:

  • (String)

    app bundle id



67
68
69
70
# File 'lib/device_api/ios/device.rb', line 67

def package_name(app)
  app_info = Plistutil.get_bundle_id_from_app(app)
  app_info['CFBundleIdentifier']
end

#statusString

Mapping of device status - used to provide a consistent status across platforms

Returns:

  • (String)

    common status string



21
22
23
24
25
26
27
# File 'lib/device_api/ios/device.rb', line 21

def status
  {
      'device' => :ok,
      'no device' => :dead,
      'offline' => :offline
  }[@state]
end

#trusted?Boolean

Has the ‘Trust this device’ dialog been accepted?

Returns:

  • (Boolean)

    true if the device is trusted, otherwise false



61
62
63
# File 'lib/device_api/ios/device.rb', line 61

def trusted?
  IDevice.trusted?(serial)
end

#typeSymbol

Return whether or not the device is a tablet or mobile

Returns:

  • (Symbol)

    :tablet or :mobile depending on device_class



115
116
117
118
119
120
121
# File 'lib/device_api/ios/device.rb', line 115

def type
  if device_class.downcase == 'ipad'
    :tablet
  else
    :mobile
  end
end

#uninstall(package_name) ⇒ Boolean, Exception

Uninstall a specified package

Parameters:

  • package_name (String)

    string containing name of package to uninstall

Returns:

  • (Boolean, Exception)

    true when the package is uninstalled successfully, otherwise an error is raised



106
107
108
109
110
111
# File 'lib/device_api/ios/device.rb', line 106

def uninstall(package_name)
  res = uninstall_package(package_name)

  fail StandardError, res, caller unless res
  true
end

#versionString

Returns the devices iOS version number - i.e. 8.2

Returns:

  • (String)

    iOS version number



43
44
45
# File 'lib/device_api/ios/device.rb', line 43

def version
  get_prop('ProductVersion')
end

#wifi_mac_addressString

Get the Wifi Mac address for the current device

Returns:

  • (String)

    Mac address of current device



87
88
89
# File 'lib/device_api/ios/device.rb', line 87

def wifi_mac_address
  get_prop('WiFiAddress')
end