Class: Airplay::Device
- Inherits:
-
Object
- Object
- Airplay::Device
- 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
Constant Summary collapse
- MissingAttributes =
Class.new(KeyError)
Instance Attribute Summary collapse
-
#address ⇒ Object
Returns the value of attribute address.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#password ⇒ Object
Returns the value of attribute password.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#connection ⇒ Object
Public: Establishes a conection to the device.
-
#features ⇒ Object
Public: Access the Features of the device.
-
#id ⇒ Object
Public: The unique id of the device (mac address).
-
#info ⇒ Object
Public: Access the Info of the device.
-
#initialize(attributes = {}) ⇒ Device
constructor
A new instance of Device.
-
#ip ⇒ Object
Public: Access the ip of the device.
-
#password? ⇒ Boolean
Public: Checks if the devices has a password.
-
#refresh_connection ⇒ Object
Public: Forces the refresh of the connection.
-
#server_info ⇒ Object
Public: Access the full information of the device.
-
#text_records=(record) ⇒ Object
Public: Sets server information based on text records.
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
#address ⇒ Object
Returns the value of attribute address.
13 14 15 |
# File 'lib/airplay/device.rb', line 13 def address @address end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
13 14 15 |
# File 'lib/airplay/device.rb', line 13 def name @name end |
#password ⇒ Object
Returns the value of attribute password.
13 14 15 |
# File 'lib/airplay/device.rb', line 13 def password @password end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
13 14 15 |
# File 'lib/airplay/device.rb', line 13 def type @type end |
Instance Method Details
#connection ⇒ Object
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 |
#features ⇒ Object
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 |
#id ⇒ Object
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 |
#info ⇒ Object
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 |
#ip ⇒ Object
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
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_connection ⇒ Object
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_info ⇒ Object
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 |