Class: Bravtroller::Remote::IrccClientFactory
- Inherits:
-
Object
- Object
- Bravtroller::Remote::IrccClientFactory
- Defined in:
- lib/bravtroller/remote.rb
Instance Method Summary collapse
- #create ⇒ Object
-
#initialize(host) ⇒ IrccClientFactory
constructor
A new instance of IrccClientFactory.
Constructor Details
#initialize(host) ⇒ IrccClientFactory
Returns a new instance of IrccClientFactory.
19 20 21 |
# File 'lib/bravtroller/remote.rb', line 19 def initialize(host) @client = Bravtroller::Client.new(host) end |
Instance Method Details
#create ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/bravtroller/remote.rb', line 23 def create if @ircc_client.nil? searcher = EasyUpnp::SsdpSearcher.new results = searcher.search(IRCC_URN) authenticator = Bravtroller::Authenticator.new(@client) if !authenticator. raise RuntimeError.new 'Not authorized yet. Please authorize Bravtroller using Bravtroller::Authenticator.' end if results.empty? raise RuntimeError.new "Couldn't find any UPnP devices on the network that looks like a supported Sony device" elsif results.count != 1 raise RuntimeError.new "Found more than one supported Sony device. Please construct Remote manually. Found devices: #{results.inspect}" else device = results.first @ircc_client = device.service(IRCC_URN, cookies: authenticator.({})) end end @ircc_client end |