Class: DeviceAPI::IOS::IDeviceProvision

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

Overview

Namespace for all methods encapsulating ideviceprovision calls

Class Method Summary collapse

Class Method Details

.get_profile_info(file) ⇒ Hash

Gets information about a provisioning profile

Parameters:

  • file (String)

    path to the provisioning profile

Returns:

  • (Hash)

    hash containing provisioning profile information

Raises:



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/device_api/ios/ideviceprovision.rb', line 74

def self.get_profile_info(file)
  result = execute("ideviceprovision dump #{file}")

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

  lines = result.stdout.split("\n")

  info = {}
  lines.each do |l|
    if /(.*):\s+(.*)/.match(l)
      info[Regexp.last_match[1]] = Regexp.last_match[2]
    end
  end
  info
end

.has_profile?(options = {}) ⇒ Boolean

Checks to see if a profile is installed on the specified device

Parameters:

  • options (Hash) (defaults to: {})

    options used for checking profiles

Options Hash (options):

  • :name (String)

    name of the profile (optional when uuid provided)

  • :uuid (String)

    UUID of the profile (optional when name provided)

  • :serial (String)

    serial of the device to check

Returns:

  • (Boolean)

    true if the profile is installed, false otherwise



24
25
26
27
28
29
30
31
32
# File 'lib/device_api/ios/ideviceprovision.rb', line 24

def self.has_profile?(options = {})
  name = options[:name]
  uuid = options[:uuid]
  serial = options[:serial]

  profiles = list_profiles(serial)

  profiles.key?(uuid) || profiles.value?(name)
end

.install_profile(options = {}) ⇒ Boolean, IDeviceProvisionError

Installs the specified profile to the device

Parameters:

  • options (Hash) (defaults to: {})

    options used for installing a profile

Options Hash (options):

  • :file (String)

    path to the provisioning profile

  • :serial (String)

    serial of the device to install the profile to

Returns:

Raises:



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

def self.install_profile(options = {})
  serial = options[:serial]
  file = options[:file]

  info = get_profile_info(file)

  # Check to see if the profile has already been added to the device
  return true if has_profile?(serial: serial, uuid: info['UUID'])

  result = execute("ideviceprovision -u #{serial} install #{file}")

  raise IDeviceProvisionError.new(result.stderr) if result.exit != 0
  true
end

.list_profiles(serial) ⇒ Hash

Lists all profiles on the specified device

Parameters:

  • serial (String)

    serial of the device to check

Returns:

  • (Hash)

    hash of profile name and UUID

Raises:



10
11
12
13
14
15
16
# File 'lib/device_api/ios/ideviceprovision.rb', line 10

def self.list_profiles(serial)
  result = execute("ideviceprovision -u #{serial} list")

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

  Hash[result.stdout.split("\n").map { |a| b = a.split(' - '); [b[0], b[1]] }[1..-1]]
end

.remove_profile(options = {}) ⇒ Boolean, IDeviceProvisionError

Removes the specified profile from the device

Parameters:

  • options (Hash) (defaults to: {})

    options used for removing a profile

Options Hash (options):

  • :uuid (String)

    UUID of the profile to be removed

  • :serial (String)

    serial of the device to remove the profile from

Returns:

  • (Boolean, IDeviceProvisionError)

    true if the profile is removed from the device, an error otherwise

Raises:



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/device_api/ios/ideviceprovision.rb', line 39

def self.remove_profile(options = {})
  uuid = options[:uuid]
  serial = options[:serial]

  return true unless has_profile?(serial: serial, uuid: uuid)

  result = execute("ideviceprovision -u #{serial} remove #{uuid}")

  raise IDeviceProvisionError.new(result.stderr) if result.exit != 0
  true
end