Class: Spaceship::ConnectAPI::Device

Inherits:
Object
  • Object
show all
Includes:
Model
Defined in:
spaceship/lib/spaceship/connect_api/models/device.rb

Defined Under Namespace

Modules: DeviceClass, Status

Instance Attribute Summary collapse

Attributes included from Model

#id, #reverse_attr_map

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Model

#attr_mapping, included, #initialize, #reverse_attr_mapping, #to_json, #update_attributes

Instance Attribute Details

#added_dateObject

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_classObject

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

#modelObject

Returns the value of attribute model.



8
9
10
# File 'spaceship/lib/spaceship/connect_api/models/device.rb', line 8

def model
  @model
end

#nameObject

Returns the value of attribute name.



9
10
11
# File 'spaceship/lib/spaceship/connect_api/models/device.rb', line 9

def name
  @name
end

#platformObject

Returns the value of attribute platform.



10
11
12
# File 'spaceship/lib/spaceship/connect_api/models/device.rb', line 10

def platform
  @platform
end

#statusObject

Returns the value of attribute status.



11
12
13
# File 'spaceship/lib/spaceship/connect_api/models/device.rb', line 11

def status
  @status
end

#udidObject

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



51
52
53
54
55
# File 'spaceship/lib/spaceship/connect_api/models/device.rb', line 51

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.

Parameters:

  • client (ConnectAPI) (defaults to: nil)

    ConnectAPI client.

  • name (String) (defaults to: nil)

    The name to be assigned to the device.

  • platform (String) (defaults to: nil)

    The platform of the device.

  • udid (String) (defaults to: nil)

    The udid of the device being created.

Returns:

  • (Device)

    Find a device based on the UDID of the device. nil if no device was found.



83
84
85
86
87
# File 'spaceship/lib/spaceship/connect_api/models/device.rb', line 83

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

.find_by_udid(device_udid, client: nil, platform: nil, include_disabled: false) ⇒ Device

Returns Find a device based on the UDID of the device. nil if no device was found.

Parameters:

  • client (ConnectAPI) (defaults to: nil)

    ConnectAPI client.

  • platform (String) (defaults to: nil)

    The platform of the device.

  • include_disabled (Bool) (defaults to: false)

    Whether to include disable devices. false by default.

Returns:

  • (Device)

    Find a device based on the UDID of the device. nil if no device was found.



61
62
63
64
65
# File 'spaceship/lib/spaceship/connect_api/models/device.rb', line 61

def self.find_by_udid(device_udid, client: nil, platform: 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, include_disabled: false) ⇒ Device

Returns Find a device based on the UDID of the device. If no device was found, nil if no device was found.

Parameters:

  • client (ConnectAPI) (defaults to: nil)

    ConnectAPI client.

  • name (String) (defaults to: nil)

    The name to be assigned to the device, if it needs to be created.

  • platform (String) (defaults to: nil)

    The platform of the device.

  • include_disabled (Bool) (defaults to: false)

    Whether to include disable devices. false by default.

Returns:

  • (Device)

    Find a device based on the UDID of the device. If no device was found, nil if no device was found.



72
73
74
75
76
# File 'spaceship/lib/spaceship/connect_api/models/device.rb', line 72

def self.find_or_create(device_udid, client: nil, name: nil, platform: nil, include_disabled: false)
  existing = self.find_by_udid(device_udid, client: client, platform: platform)
  return existing if existing
  return self.create(client: client, name: name, platform: platform, udid: device_udid)
end

.typeObject



39
40
41
# File 'spaceship/lib/spaceship/connect_api/models/device.rb', line 39

def self.type
  return "devices"
end

Instance Method Details

#enabled?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'spaceship/lib/spaceship/connect_api/models/device.rb', line 43

def enabled?
  return status == Status::ENABLED
end