Class: Spaceship::Portal::Device

Inherits:
Spaceship::PortalBase show all
Defined in:
lib/spaceship/portal/device.rb

Overview

Represents a device from the Apple Developer Portal

Instance Attribute Summary collapse

Attributes inherited from Base

#raw_data

Class Method Summary collapse

Methods inherited from Spaceship::PortalBase

client

Methods inherited from Base

attr_mapping, #client, #initialize, #inspect, mapping_module, method_missing, set_client, #setup

Constructor Details

This class inherits a constructor from Spaceship::Base

Instance Attribute Details

#idString

Returns The ID given from the developer portal. You’ll probably not need it.

Examples:

"XJXGVS46MW"

Returns:

  • (String)

    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

#nameString

Returns The name of the device.

Examples:

"Felix Krause's iPhone 6"

Returns:

  • (String)

    The name of the device



13
14
15
# File 'lib/spaceship/portal/device.rb', line 13

def name
  @name
end

#platformString

Returns The platform of the device. This is probably always “ios”.

Examples:

"ios"

Returns:

  • (String)

    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

#statusString

Returns Status of the device. Probably always “c”.

Examples:

"c"

Returns:

  • (String)

    Status of the device. Probably always “c”



28
29
30
# File 'lib/spaceship/portal/device.rb', line 28

def status
  @status
end

#udidString

Returns The UDID of the device.

Examples:

"4c24a7ee5caaa4847f49aaab2d87483053f53b65"

Returns:

  • (String)

    The UDID of the device



18
19
20
# File 'lib/spaceship/portal/device.rb', line 18

def udid
  @udid
end

Class Method Details

.allArray

Returns all devices registered for this account

Returns:

  • (Array)

    Returns all devices registered for this account



46
47
48
# File 'lib/spaceship/portal/device.rb', line 46

def all
  client.devices.map { |device| self.factory(device) }
end

.create!(name: nil, udid: nil) ⇒ Device

Register a new device to this account

Examples:

Spaceship.device.create!(name: "Felix Krause's iPhone 6", udid: "4c24a7ee5caaa4847f49aaab2d87483053f53b65")

Parameters:

  • name (String) (defaults to: nil)

    (required): The name of the new device

  • udid (String) (defaults to: nil)

    (required): The UDID of the new device

Returns:

  • (Device)

    : The newly created device



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/spaceship/portal/device.rb', line 78

def create!(name: nil, udid: nil)
  # Check whether the user has passed in a UDID and a name
  unless (udid and 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
  if self.find_by_udid(udid)
    raise "The device UDID '#{udid}' already exists on this team."
  end

  # Find the device by name, raise an exception if it already exists
  if self.find_by_name(name)
    raise "The device name '#{name}' already exists on this team, use different one."
  end

  device = client.create_device!(name, udid)

  # 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.



41
42
43
# File 'lib/spaceship/portal/device.rb', line 41

def factory(attrs)
  self.new(attrs)
end

.find(device_id) ⇒ Device

Returns Find a device based on the ID of the device. Attention: This is not the UDID. nil if no device was found.

Returns:

  • (Device)

    Find a device based on the ID of the device. Attention: This is not the UDID. nil if no device was found.



52
53
54
55
56
# File 'lib/spaceship/portal/device.rb', line 52

def find(device_id)
  all.find do |device|
    device.id == device_id
  end
end

.find_by_name(device_name) ⇒ Device

Returns Find a device based on its name. nil if no device was found.

Returns:

  • (Device)

    Find a device based on its name. nil if no device was found.



66
67
68
69
70
# File 'lib/spaceship/portal/device.rb', line 66

def find_by_name(device_name)
  all.find do |device|
    device.name == device_name
  end
end

.find_by_udid(device_udid) ⇒ Device

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

Returns:

  • (Device)

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



59
60
61
62
63
# File 'lib/spaceship/portal/device.rb', line 59

def find_by_udid(device_udid)
  all.find do |device|
    device.udid == device_udid
  end
end