Class: Airplay::Device

Inherits:
Object
  • Object
show all
Includes:
Playable, Viewable
Defined in:
lib/airplay/device.rb,
lib/airplay/device/info.rb,
lib/airplay/device/features.rb

Overview

Public: Represents an Airplay Node

Defined Under Namespace

Classes: Features, Info

Constant Summary collapse

MissingAttributes =
Class.new(KeyError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Playable

#play, #player, #playlist, #playlists

Constructor Details

#initialize(attributes = {}) ⇒ Device

Returns a new instance of Device.



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/airplay/device.rb', line 18

def initialize(attributes = {})
  validate_attributes(attributes)

  @name     = attributes[:name]
  @address  = attributes[:address]
  @type     = attributes[:type]
  @password = attributes[:password]

  @it_has_password = false

  Airplay.configuration.load
end

Instance Attribute Details

#addressObject

Returns the value of attribute address.



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

def address
  @address
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#passwordObject

Returns the value of attribute password.



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

def password
  @password
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#connectionObject

Public: Establishes a conection to the device

Returns the Connection



109
110
111
# File 'lib/airplay/device.rb', line 109

def connection
  @_connection ||= Airplay::Connection.new(self)
end

#featuresObject

Public: Access the Features of the device

Returns the Featurs of the device



85
86
87
# File 'lib/airplay/device.rb', line 85

def features
  @_features ||= Features.new(self)
end

#idObject

Public: The unique id of the device (mac address)

Returns the mac address based on basic_info or server_info



125
126
127
128
129
# File 'lib/airplay/device.rb', line 125

def id
  @_id ||= begin
    basic_info.fetch("macAddress", server_info["macAddress"])
  end
end

#infoObject

Public: Access the Info of the device

Returns the Info of the device



93
94
95
# File 'lib/airplay/device.rb', line 93

def info
  @_info ||= Info.new(self)
end

#ipObject

Public: Access the ip of the device

Returns the memoized ip address



35
36
37
# File 'lib/airplay/device.rb', line 35

def ip
  @_ip ||= address.split(":").first
end

#password?Boolean

Public: Checks if the devices has a password

Returns boolean for the presence of a password

Returns:

  • (Boolean)


66
67
68
69
# File 'lib/airplay/device.rb', line 66

def password?
  return @it_has_password if @it_has_password
  !!password && !password.empty?
end

#refresh_connectionObject

Public: Forces the refresh of the connection

Returns nothing



117
118
119
# File 'lib/airplay/device.rb', line 117

def refresh_connection
  @_connection = nil
end

#server_infoObject

Public: Access the full information of the device

Returns a hash with all the information



101
102
103
# File 'lib/airplay/device.rb', line 101

def server_info
  @_server_info ||= basic_info.merge(extra_info)
end

#text_records=(record) ⇒ Object

Public: Sets server information based on text records

Returns text records hash.



43
44
45
46
47
48
49
50
# File 'lib/airplay/device.rb', line 43

def text_records=(record)
  @text_records = {
    "model"      => record["model"],
    "features"   => record["features"],
    "macAddress" => record["deviceid"],
    "srcvers"    => record["srcvers"]
  }
end