Class: Spaceship::ConnectAPI::Device
- Inherits:
-
Object
- Object
- Spaceship::ConnectAPI::Device
- Includes:
- Model
- Defined in:
- spaceship/lib/spaceship/connect_api/models/device.rb
Defined Under Namespace
Modules: DeviceClass, Status
Instance Attribute Summary collapse
-
#added_date ⇒ Object
Returns the value of attribute added_date.
-
#device_class ⇒ Object
Returns the value of attribute device_class.
-
#model ⇒ Object
Returns the value of attribute model.
-
#name ⇒ Object
Returns the value of attribute name.
-
#platform ⇒ Object
Returns the value of attribute platform.
-
#status ⇒ Object
Returns the value of attribute status.
-
#udid ⇒ Object
Returns the value of attribute udid.
Attributes included from Model
Class Method Summary collapse
-
.all(client: nil, filter: {}, includes: nil, limit: nil, sort: nil) ⇒ Object
API.
-
.create(client: nil, name: nil, platform: nil, udid: nil) ⇒ Device
Find a device based on the UDID of the device.
-
.disable(device_udid, client: nil) ⇒ Device
Modified device based on the UDID of the device.
-
.enable(device_udid, client: nil) ⇒ Device
Modified device based on the UDID of the device.
-
.find_by_udid(device_udid, client: nil, include_disabled: false) ⇒ Device
Find a device based on the UDID of the device.
-
.find_or_create(device_udid, client: nil, name: nil, platform: nil) ⇒ Device
Find a device based on the UDID of the device.
-
.modify(device_udid, client: nil, enabled: nil, new_name: nil) ⇒ Device
Modified device based on the UDID of the device.
-
.rename(device_udid, new_name, client: nil) ⇒ Device
Modified device based on the UDID of the device.
- .type ⇒ Object
Instance Method Summary collapse
Methods included from Model
#attr_mapping, included, #initialize, #reverse_attr_mapping, #to_json, #update_attributes
Instance Attribute Details
#added_date ⇒ Object
Returns the value of attribute added_date.
13 14 15 |
# File 'spaceship/lib/spaceship/connect_api/models/device.rb', line 13 def added_date @added_date end |
#device_class ⇒ Object
Returns the value of attribute device_class.
7 8 9 |
# File 'spaceship/lib/spaceship/connect_api/models/device.rb', line 7 def device_class @device_class end |
#model ⇒ Object
Returns the value of attribute model.
8 9 10 |
# File 'spaceship/lib/spaceship/connect_api/models/device.rb', line 8 def model @model end |
#name ⇒ Object
Returns the value of attribute name.
9 10 11 |
# File 'spaceship/lib/spaceship/connect_api/models/device.rb', line 9 def name @name end |
#platform ⇒ Object
Returns the value of attribute platform.
10 11 12 |
# File 'spaceship/lib/spaceship/connect_api/models/device.rb', line 10 def platform @platform end |
#status ⇒ Object
Returns the value of attribute status.
11 12 13 |
# File 'spaceship/lib/spaceship/connect_api/models/device.rb', line 11 def status @status end |
#udid ⇒ Object
Returns the value of attribute udid.
12 13 14 |
# File 'spaceship/lib/spaceship/connect_api/models/device.rb', line 12 def udid @udid end |
Class Method Details
.all(client: nil, filter: {}, includes: nil, limit: nil, sort: nil) ⇒ Object
API
54 55 56 57 58 |
# File 'spaceship/lib/spaceship/connect_api/models/device.rb', line 54 def self.all(client: nil, filter: {}, includes: nil, limit: nil, sort: nil) client ||= Spaceship::ConnectAPI resps = client.get_devices(filter: filter, includes: includes).all_pages return resps.flat_map(&:to_models) end |
.create(client: nil, name: nil, platform: nil, udid: nil) ⇒ Device
Returns Find a device based on the UDID of the device. nil if no device was found.
85 86 87 88 89 |
# File 'spaceship/lib/spaceship/connect_api/models/device.rb', line 85 def self.create(client: nil, name: nil, platform: nil, udid: nil) client ||= Spaceship::ConnectAPI resp = client.post_device(name: name, platform: platform, udid: udid) return resp.to_models.first end |
.disable(device_udid, client: nil) ⇒ Device
Returns Modified device based on the UDID of the device. nil if no device was found.
120 121 122 |
# File 'spaceship/lib/spaceship/connect_api/models/device.rb', line 120 def self.disable(device_udid, client: nil) self.modify(device_udid, client: client, enabled: false) end |
.enable(device_udid, client: nil) ⇒ Device
Returns Modified device based on the UDID of the device. nil if no device was found.
113 114 115 |
# File 'spaceship/lib/spaceship/connect_api/models/device.rb', line 113 def self.enable(device_udid, client: nil) self.modify(device_udid, client: client, enabled: true) end |
.find_by_udid(device_udid, client: nil, include_disabled: false) ⇒ Device
Returns Find a device based on the UDID of the device. nil if no device was found.
64 65 66 67 68 |
# File 'spaceship/lib/spaceship/connect_api/models/device.rb', line 64 def self.find_by_udid(device_udid, client: nil, include_disabled: false) self.all(client: client).find do |device| device.udid.casecmp(device_udid) == 0 && (include_disabled ? true : device.enabled?) end end |
.find_or_create(device_udid, client: nil, name: nil, platform: nil) ⇒ Device
Returns Find a device based on the UDID of the device. If no device was found, nil if no device was found.
74 75 76 77 78 |
# File 'spaceship/lib/spaceship/connect_api/models/device.rb', line 74 def self.find_or_create(device_udid, client: nil, name: nil, platform: nil) existing = self.find_by_udid(device_udid, client: client) return existing if existing return self.create(client: client, name: name, platform: platform, udid: device_udid) end |
.modify(device_udid, client: nil, enabled: nil, new_name: nil) ⇒ Device
Returns Modified device based on the UDID of the device. nil if no device was found.
96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'spaceship/lib/spaceship/connect_api/models/device.rb', line 96 def self.modify(device_udid, client: nil, enabled: nil, new_name: nil) client ||= Spaceship::ConnectAPI existing = self.find_by_udid(device_udid, client: client, include_disabled: true) return nil if existing.nil? enabled = existing.enabled? if enabled.nil? new_name ||= existing.name return existing if existing.name == new_name && existing.enabled? == enabled new_status = enabled ? Status::ENABLED : Status::DISABLED resp = client.patch_device(id: existing.id, new_name: new_name, status: new_status) return resp.to_models.first end |
.rename(device_udid, new_name, client: nil) ⇒ Device
Returns Modified device based on the UDID of the device. nil if no device was found.
128 129 130 |
# File 'spaceship/lib/spaceship/connect_api/models/device.rb', line 128 def self.rename(device_udid, new_name, client: nil) self.modify(device_udid, client: client, new_name: new_name) end |
.type ⇒ Object
42 43 44 |
# File 'spaceship/lib/spaceship/connect_api/models/device.rb', line 42 def self.type return "devices" end |