class Bravtroller::Remote::IrccClientFactory

Public Class Methods

new(host) click to toggle source
# File lib/bravtroller/remote.rb, line 19
def initialize(host)
  @client = Bravtroller::Client.new(host)
end

Public Instance Methods

create() click to toggle source
# 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.authorized?
      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.authorize({}))
    end
  end

  @ircc_client
end