class Spaceship::Portal::Device
Represents a device from the Apple Developer Portal
def all(mac: false)
-
(Array)
- Returns all devices registered for this account
Parameters:
-
mac
(Bool
) -- Fetches Mac devices if true
def all(mac: false) client.devices(mac: mac).map { |device| self.factory(device) } end
def all_apple_tvs
-
(Array)
- Returns all Apple TVs registered for this account
def all_apple_tvs client.devices_by_class('tvOS').map { |device| self.factory(device) } end
def all_for_profile_type(profile_type)
-
(Array)
- Returns all devices that can be used for iOS profiles (all devices except TVs)
def all_for_profile_type(profile_type) if profile_type.include? "tvOS" Spaceship::Device.all_apple_tvs else Spaceship::Device.all_ios_profile_devices end end
def all_ios_profile_devices
-
(Array)
- Returns all devices that can be used for iOS profiles (all devices except TVs)
def all_ios_profile_devices all.select { |device| device.device_type != "tvOS" } end
def all_ipads
-
(Array)
- Returns all iPads registered for this account
def all_ipads client.devices_by_class('ipad').map { |device| self.factory(device) } end
def all_iphones
-
(Array)
- Returns all iPhones registered for this account
def all_iphones client.devices_by_class('iphone').map { |device| self.factory(device) } end
def all_ipod_touches
-
(Array)
- Returns all iPods registered for this account
def all_ipod_touches client.devices_by_class('ipod').map { |device| self.factory(device) } end
def all_macs
-
(Array)
- Returns all Macs registered for this account
def all_macs all(mac: true) end
def all_watches
-
(Array)
- Returns all Watches registered for this account
def all_watches client.devices_by_class('watch').map { |device| self.factory(device) } end
def create!(name: nil, udid: nil, mac: false)
-
(Device)
- : The newly created device
Parameters:
-
mac
(Bool
) -- (optional): Pass Mac if device is a Mac -
udid
(String
) -- (required): The UDID of the new device -
name
(String
) -- (required): The name of the new device
def create!(name: nil, udid: nil, mac: false) # Check whether the user has passed in a UDID and a name unless udid && 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 existing = self.find_by_udid(udid, mac: mac) return existing if existing # It is valid to have the same name for multiple devices device = client.create_device!(name, udid, mac: mac) # Update self with the new device self.new(device) end
def factory(attrs)
Create a new object based on a hash.
def factory(attrs) self.new(attrs) end
def find(device_id, mac: false)
-
(Device)
- Find a device based on the ID of the device. *Attention*:
Parameters:
-
mac
(Bool
) -- Searches for Macs if true
def find(device_id, mac: false) all(mac: mac).find do |device| device.id == device_id end end
def find_by_name(device_name, mac: false)
-
(Device)
- Find a device based on its name. nil if no device was found.
Parameters:
-
mac
(Bool
) -- Searches for Macs if true
def find_by_name(device_name, mac: false) all(mac: mac).find do |device| device.name == device_name end end
def find_by_udid(device_udid, mac: false)
-
(Device)
- Find a device based on the UDID of the device. nil if no device was found.
Parameters:
-
mac
(Bool
) -- Searches for Macs if true
def find_by_udid(device_udid, mac: false) all(mac: mac).find do |device| device.udid.casecmp(device_udid) == 0 end end