lib/spaceship/portal/device.rb in spaceship-0.37.0 vs lib/spaceship/portal/device.rb in spaceship-0.38.0

- old
+ new

@@ -20,11 +20,11 @@ # @return (String) The platform of the device. This is probably always "ios" # @example # "ios" attr_accessor :platform - # @return (String) Status of the device. Probably always "c" + # @return (String) Status of the device. "c" for enabled devices, "r" for disabled devices. # @example # "c" attr_accessor :status # @return (String) Model (can be nil) @@ -57,13 +57,14 @@ def factory(attrs) self.new(attrs) end # @param mac [Bool] Fetches Mac devices if true + # @param include_disabled [Bool] Whether to include disable devices. false by default. # @return (Array) Returns all devices registered for this account - def all(mac: false) - client.devices(mac: mac).map { |device| self.factory(device) } + def all(mac: false, include_disabled: false) + client.devices(mac: mac, include_disabled: include_disabled).map { |device| self.factory(device) } end # @return (Array) Returns all Apple TVs registered for this account def all_apple_tvs client.devices_by_class('tvOS').map { |device| self.factory(device) } @@ -107,30 +108,33 @@ Spaceship::Device.all_ios_profile_devices end end # @param mac [Bool] Searches for Macs if true + # @param include_disabled [Bool] Whether to include disable devices. false by default. # @return (Device) Find a device based on the ID of the device. *Attention*: # This is *not* the UDID. nil if no device was found. - def find(device_id, mac: false) - all(mac: mac).find do |device| + def find(device_id, mac: false, include_disabled: false) + all(mac: mac, include_disabled: include_disabled).find do |device| device.id == device_id end end # @param mac [Bool] Searches for Macs if true + # @param include_disabled [Bool] Whether to include disable devices. false by default. # @return (Device) Find a device based on the UDID of the device. nil if no device was found. - def find_by_udid(device_udid, mac: false) - all(mac: mac).find do |device| + def find_by_udid(device_udid, mac: false, include_disabled: false) + all(mac: mac, include_disabled: include_disabled).find do |device| device.udid.casecmp(device_udid) == 0 end end # @param mac [Bool] Searches for Macs if true + # @param include_disabled [Bool] Whether to include disable devices. false by default. # @return (Device) Find a device based on its name. nil if no device was found. - def find_by_name(device_name, mac: false) - all(mac: mac).find do |device| + def find_by_name(device_name, mac: false, include_disabled: false) + all(mac: mac, include_disabled: include_disabled).find do |device| device.name == device_name end end # Register a new device to this account @@ -154,9 +158,34 @@ device = client.create_device!(name, udid, mac: mac) # Update self with the new device self.new(device) + end + end + + def enabled? + return self.status == "c" + end + + def disabled? + return self.status == "r" + end + + # Enable current device. + def enable! + unless enabled? + attr = client.enable_device!(self.id, self.udid, mac: self.platform == 'mac') + initialize(attr) + end + end + + # Disable current device. This will invalidate all provisioning profiles that use this device. + def disable! + if enabled? + client.disable_device!(self.id, self.udid, mac: self.platform == 'mac') + # disable request doesn't return device json, so we assume that the new status is "r" if response succeeded + self.status = "r" end end end end end