lib/spaceship/portal/device.rb in spaceship-0.4.0 vs lib/spaceship/portal/device.rb in spaceship-0.5.0

- old
+ new

@@ -25,16 +25,32 @@ # @return (String) Status of the device. Probably always "c" # @example # "c" attr_accessor :status + # @return (String) Model (can be nil) + # @example + # 'iPhone 6', 'iPhone 4 GSM' + attr_accessor :model + + # @return (String) Device type + # @example + # 'pc' - Apple TV + # 'watch' - Apple Watch + # 'ipad' - iPad + # 'iphone' - iPhone + # 'ipod' - iPod + attr_accessor :device_type + attr_mapping({ 'deviceId' => :id, 'name' => :name, 'deviceNumber' => :udid, 'devicePlatform' => :platform, - 'status' => :status + 'status' => :status, + 'deviceClass' => :device_type, + 'model' => :model }) class << self # Create a new object based on a hash. # This is used to create a new object based on the server response. @@ -45,10 +61,35 @@ # @return (Array) Returns all devices registered for this account def all client.devices.map { |device| self.factory(device) } end + # @return (Array) Returns all Apple TVs registered for this account + def all_apple_tvs + client.devices_by_class('pc').map { |device| self.factory(device) } + end + + # @return (Array) Returns all Watches registered for this account + def all_watches + client.devices_by_class('watch').map { |device| self.factory(device) } + end + + # @return (Array) Returns all iPads registered for this account + def all_ipads + client.devices_by_class('ipad').map { |device| self.factory(device) } + end + + # @return (Array) Returns all iPhones registered for this account + def all_iphones + client.devices_by_class('iphone').map { |device| self.factory(device) } + end + + # @return (Array) Returns all iPods registered for this account + def all_ipod_touches + client.devices_by_class('ipod').map { |device| self.factory(device) } + end + # @return (Device) Find a device based on the ID of the device. *Attention*: # This is *not* the UDID. nil if no device was found. def find(device_id) all.find do |device| device.id == device_id @@ -75,22 +116,19 @@ # @example # Spaceship.device.create!(name: "Felix Krause's iPhone 6", udid: "4c24a7ee5caaa4847f49aaab2d87483053f53b65") # @return (Device): The newly created device def create!(name: nil, udid: nil) # Check whether the user has passed in a UDID and a name - unless (udid and 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 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 + # It is valid to have the same name for multiple devices device = client.create_device!(name, udid) # Update self with the new device self.new(device)