class Spaceship::Device

Represents a device from the Apple Developer Portal

def all

Returns:
  • (Array) - Returns all devices registered for this account
def all
  client.devices.map { |device| self.factory(device) }
end

def create!(name: nil, udid: nil)

Returns:
  • (Device) - : The newly created device

Parameters:
  • udid (String) -- (required): The UDID of the new device
  • name (String) -- (required): The name of the new device
def create!(name: nil, udid: nil)
  # Check whether the user has passed in a UDID and a name
  unless (udid and name)
    raise "You cannot create a device without a device_id (UDID) and name"
  end
  # Find the device by UDID, raise an exception if it already exists
  if self.find_by_udid(udid)
    raise "The device UDID '#{udid}' already exists on this team."
  end
  # Find the device by name, raise an exception if it already exists
  if self.find_by_name(name)
    raise "The device name '#{name}' already exists on this team, use different one."
  end
  device = client.create_device!(name, udid)
  # Update self with the new device
  self.new(device)
end

def factory(attrs)

This is used to create a new object based on the server response.
Create a new object based on a hash.
def factory(attrs)
  self.new(attrs)
end

def find(device_id)

Returns:
  • (Device) - Find a device based on the ID of the device. *Attention*:
def find(device_id)
  all.find do |device|
    device.id == device_id
  end
end

def find_by_name(device_name)

Returns:
  • (Device) - Find a device based on its name. nil if no device was found.
def find_by_name(device_name)
  all.find do |device|
    device.name == device_name
  end
end

def find_by_udid(device_udid)

Returns:
  • (Device) - Find a device based on the UDID of the device. nil if no device was found.
def find_by_udid(device_udid)
  all.find do |device|
    device.udid == device_udid
  end
end