Class: Spaceship::Portal::Device
- Inherits:
-
Spaceship::PortalBase
- Object
- Base
- Spaceship::PortalBase
- Spaceship::Portal::Device
- Defined in:
- spaceship/lib/spaceship/portal/device.rb
Overview
Represents a device from the Apple Developer Portal
Instance Attribute Summary collapse
-
#device_type ⇒ String
Device type.
-
#id ⇒ String
The ID given from the developer portal.
-
#model ⇒ String
Model (can be nil).
-
#name ⇒ String
The name of the device, must be 50 characters or less.
-
#platform ⇒ String
The platform of the device.
-
#status ⇒ String
Status of the device.
-
#udid ⇒ String
The UDID of the device.
Attributes inherited from Base
Class Method Summary collapse
-
.all(mac: false, include_disabled: false) ⇒ Array
Returns all devices registered for this account.
-
.all_apple_tvs ⇒ Array
Returns all Apple TVs registered for this account.
-
.all_for_profile_type(profile_type) ⇒ Array
Returns all devices matching the provided profile_type.
-
.all_ios_profile_devices ⇒ Array
Returns all devices that can be used for iOS profiles (all devices except TVs).
-
.all_ipads ⇒ Array
Returns all iPads registered for this account.
-
.all_iphones ⇒ Array
Returns all iPhones registered for this account.
-
.all_ipod_touches ⇒ Array
Returns all iPods registered for this account.
-
.all_macs ⇒ Array
Returns all Macs registered for this account.
-
.all_watches ⇒ Array
Returns all Watches registered for this account.
-
.create!(name: nil, udid: nil, mac: false) ⇒ Device
Register a new device to this account.
-
.find(device_id, mac: false, include_disabled: false) ⇒ Device
Find a device based on the ID of the device.
-
.find_by_name(device_name, mac: false, include_disabled: false) ⇒ Device
Find a device based on its name.
-
.find_by_udid(device_udid, mac: false, include_disabled: false) ⇒ Device
Find a device based on the UDID of the device.
Instance Method Summary collapse
-
#disable! ⇒ Object
Disable current device.
- #disabled? ⇒ Boolean
-
#enable! ⇒ Object
Enable current device.
- #enabled? ⇒ Boolean
Methods inherited from Spaceship::PortalBase
Methods inherited from Base
attr_accessor, attr_mapping, attributes, #attributes, factory, #initialize, #inspect, mapping_module, method_missing, set_client, #setup, #to_s
Constructor Details
This class inherits a constructor from Spaceship::Base
Instance Attribute Details
#device_type ⇒ String
Returns Device type.
44 45 46 |
# File 'spaceship/lib/spaceship/portal/device.rb', line 44 def device_type @device_type end |
#id ⇒ String
Returns The ID given from the developer portal. You’ll probably not need it.
10 11 12 |
# File 'spaceship/lib/spaceship/portal/device.rb', line 10 def id @id end |
#model ⇒ String
Returns Model (can be nil).
35 36 37 |
# File 'spaceship/lib/spaceship/portal/device.rb', line 35 def model @model end |
#name ⇒ String
Returns The name of the device, must be 50 characters or less.
15 16 17 |
# File 'spaceship/lib/spaceship/portal/device.rb', line 15 def name @name end |
#platform ⇒ String
Returns The platform of the device. This is probably always “ios”.
25 26 27 |
# File 'spaceship/lib/spaceship/portal/device.rb', line 25 def platform @platform end |
#status ⇒ String
Returns Status of the device. “c” for enabled devices, “r” for disabled devices.
30 31 32 |
# File 'spaceship/lib/spaceship/portal/device.rb', line 30 def status @status end |
#udid ⇒ String
Returns The UDID of the device.
20 21 22 |
# File 'spaceship/lib/spaceship/portal/device.rb', line 20 def udid @udid end |
Class Method Details
.all(mac: false, include_disabled: false) ⇒ Array
Returns all devices registered for this account
60 61 62 |
# File 'spaceship/lib/spaceship/portal/device.rb', line 60 def all(mac: false, include_disabled: false) client.devices(mac: mac, include_disabled: include_disabled).map { |device| self.factory(device) } end |
.all_apple_tvs ⇒ Array
Returns all Apple TVs registered for this account
65 66 67 |
# File 'spaceship/lib/spaceship/portal/device.rb', line 65 def all_apple_tvs client.devices_by_class('tvOS').map { |device| self.factory(device) } end |
.all_for_profile_type(profile_type) ⇒ Array
Returns all devices matching the provided profile_type
100 101 102 103 104 105 106 107 108 |
# File 'spaceship/lib/spaceship/portal/device.rb', line 100 def all_for_profile_type(profile_type) if profile_type.include?("tvOS") Spaceship::Portal::Device.all_apple_tvs elsif profile_type.include?("Mac") Spaceship::Portal::Device.all_macs else Spaceship::Portal::Device.all_ios_profile_devices end end |
.all_ios_profile_devices ⇒ Array
Returns all devices that can be used for iOS profiles (all devices except TVs)
95 96 97 |
# File 'spaceship/lib/spaceship/portal/device.rb', line 95 def all_ios_profile_devices all.reject { |device| device.device_type == "tvOS" } end |
.all_ipads ⇒ Array
Returns all iPads registered for this account
75 76 77 |
# File 'spaceship/lib/spaceship/portal/device.rb', line 75 def all_ipads client.devices_by_class('ipad').map { |device| self.factory(device) } end |
.all_iphones ⇒ Array
Returns all iPhones registered for this account
80 81 82 |
# File 'spaceship/lib/spaceship/portal/device.rb', line 80 def all_iphones client.devices_by_class('iphone').map { |device| self.factory(device) } end |
.all_ipod_touches ⇒ Array
Returns all iPods registered for this account
85 86 87 |
# File 'spaceship/lib/spaceship/portal/device.rb', line 85 def all_ipod_touches client.devices_by_class('ipod').map { |device| self.factory(device) } end |
.all_macs ⇒ Array
Returns all Macs registered for this account
90 91 92 |
# File 'spaceship/lib/spaceship/portal/device.rb', line 90 def all_macs all(mac: true) end |
.all_watches ⇒ Array
Returns all Watches registered for this account
70 71 72 |
# File 'spaceship/lib/spaceship/portal/device.rb', line 70 def all_watches client.devices_by_class('watch').map { |device| self.factory(device) } end |
.create!(name: nil, udid: nil, mac: false) ⇒ Device
Register a new device to this account
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'spaceship/lib/spaceship/portal/device.rb', line 145 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 raise "Device name must be 50 characters or less. \"#{name}\" has a #{name.length} character length." if name.length > 50 # 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 |
.find(device_id, mac: false, include_disabled: false) ⇒ Device
Returns Find a device based on the ID of the device. Attention: This is not the UDID. nil if no device was found.
114 115 116 117 118 |
# File 'spaceship/lib/spaceship/portal/device.rb', line 114 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 |
.find_by_name(device_name, mac: false, include_disabled: false) ⇒ Device
Returns Find a device based on its name. nil if no device was found.
132 133 134 135 136 |
# File 'spaceship/lib/spaceship/portal/device.rb', line 132 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 |
.find_by_udid(device_udid, mac: false, include_disabled: false) ⇒ Device
Returns Find a device based on the UDID of the device. nil if no device was found.
123 124 125 126 127 |
# File 'spaceship/lib/spaceship/portal/device.rb', line 123 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 |
Instance Method Details
#disable! ⇒ Object
Disable current device. This will invalidate all provisioning profiles that use this device.
182 183 184 185 186 187 188 |
# File 'spaceship/lib/spaceship/portal/device.rb', line 182 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 |
#disabled? ⇒ Boolean
169 170 171 |
# File 'spaceship/lib/spaceship/portal/device.rb', line 169 def disabled? return self.status == "r" end |
#enable! ⇒ Object
Enable current device.
174 175 176 177 178 179 |
# File 'spaceship/lib/spaceship/portal/device.rb', line 174 def enable! unless enabled? attr = client.enable_device!(self.id, self.udid, mac: self.platform == 'mac') initialize(attr) end end |
#enabled? ⇒ Boolean
165 166 167 |
# File 'spaceship/lib/spaceship/portal/device.rb', line 165 def enabled? return self.status == "c" end |