Class: Spaceship::Portal::Device
- Inherits:
-
Spaceship::PortalBase
- Object
- Base
- Spaceship::PortalBase
- Spaceship::Portal::Device
- Defined in:
- 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.
-
#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) ⇒ 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 that can be used for iOS profiles (all devices except TVs).
-
.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.
-
.factory(attrs) ⇒ Object
Create a new object based on a hash.
-
.find(device_id, mac: false) ⇒ Device
Find a device based on the ID of the device.
-
.find_by_name(device_name, mac: false) ⇒ Device
Find a device based on its name.
-
.find_by_udid(device_udid, mac: false) ⇒ Device
Find a device based on the UDID of the device.
Methods inherited from Spaceship::PortalBase
Methods inherited from Base
attr_accessor, attr_mapping, #attributes, attributes, #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.
42 43 44 |
# File 'lib/spaceship/portal/device.rb', line 42 def device_type @device_type end |
#id ⇒ String
Returns The ID given from the developer portal. You’ll probably not need it.
8 9 10 |
# File 'lib/spaceship/portal/device.rb', line 8 def id @id end |
#model ⇒ String
Returns Model (can be nil).
33 34 35 |
# File 'lib/spaceship/portal/device.rb', line 33 def model @model end |
#name ⇒ String
Returns The name of the device.
13 14 15 |
# File 'lib/spaceship/portal/device.rb', line 13 def name @name end |
#platform ⇒ String
Returns The platform of the device. This is probably always “ios”.
23 24 25 |
# File 'lib/spaceship/portal/device.rb', line 23 def platform @platform end |
#status ⇒ String
Returns Status of the device. Probably always “c”.
28 29 30 |
# File 'lib/spaceship/portal/device.rb', line 28 def status @status end |
#udid ⇒ String
Returns The UDID of the device.
18 19 20 |
# File 'lib/spaceship/portal/device.rb', line 18 def udid @udid end |
Class Method Details
.all(mac: false) ⇒ Array
Returns all devices registered for this account
63 64 65 |
# File 'lib/spaceship/portal/device.rb', line 63 def all(mac: false) client.devices(mac: mac).map { |device| self.factory(device) } end |
.all_apple_tvs ⇒ Array
Returns all Apple TVs registered for this account
68 69 70 |
# File 'lib/spaceship/portal/device.rb', line 68 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 that can be used for iOS profiles (all devices except TVs)
103 104 105 106 107 108 109 |
# File 'lib/spaceship/portal/device.rb', line 103 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 |
.all_ios_profile_devices ⇒ Array
Returns all devices that can be used for iOS profiles (all devices except TVs)
98 99 100 |
# File 'lib/spaceship/portal/device.rb', line 98 def all_ios_profile_devices all.select { |device| device.device_type != "tvOS" } end |
.all_ipads ⇒ Array
Returns all iPads registered for this account
78 79 80 |
# File 'lib/spaceship/portal/device.rb', line 78 def all_ipads client.devices_by_class('ipad').map { |device| self.factory(device) } end |
.all_iphones ⇒ Array
Returns all iPhones registered for this account
83 84 85 |
# File 'lib/spaceship/portal/device.rb', line 83 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
88 89 90 |
# File 'lib/spaceship/portal/device.rb', line 88 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
93 94 95 |
# File 'lib/spaceship/portal/device.rb', line 93 def all_macs all(mac: true) end |
.all_watches ⇒ Array
Returns all Watches registered for this account
73 74 75 |
# File 'lib/spaceship/portal/device.rb', line 73 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
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/spaceship/portal/device.rb', line 143 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 |
.factory(attrs) ⇒ Object
Create a new object based on a hash. This is used to create a new object based on the server response.
57 58 59 |
# File 'lib/spaceship/portal/device.rb', line 57 def factory(attrs) self.new(attrs) end |
.find(device_id, mac: 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 'lib/spaceship/portal/device.rb', line 114 def find(device_id, mac: false) all(mac: mac).find do |device| device.id == device_id end end |
.find_by_name(device_name, mac: false) ⇒ Device
Returns Find a device based on its name. nil if no device was found.
130 131 132 133 134 |
# File 'lib/spaceship/portal/device.rb', line 130 def find_by_name(device_name, mac: false) all(mac: mac).find do |device| device.name == device_name end end |
.find_by_udid(device_udid, mac: false) ⇒ Device
Returns Find a device based on the UDID of the device. nil if no device was found.
122 123 124 125 126 |
# File 'lib/spaceship/portal/device.rb', line 122 def find_by_udid(device_udid, mac: false) all(mac: mac).find do |device| device.udid.casecmp(device_udid) == 0 end end |