Method: EasyUpnp::DeviceControlPoint#initialize

Defined in:
lib/easy_upnp/control_point/device_control_point.rb

#initialize(urn, service_endpoint, events_endpoint, definition, options, &block) ⇒ DeviceControlPoint

Returns a new instance of DeviceControlPoint.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/easy_upnp/control_point/device_control_point.rb', line 43

def initialize(urn, service_endpoint, events_endpoint, definition, options, &block)
  @urn = urn
  @service_endpoint = service_endpoint
  @definition = definition
  @options = Options.new(options, &block)

  @events_endpoint = events_endpoint
  @events_client = EasyUpnp::EventClient.new(events_endpoint)

  @client = ClientWrapper.new(
    service_endpoint,
    urn,
    @options.call_options,
    @options.advanced_typecasting,
    @options.log_enabled,
    @options.log_level,
    @options.cookies
  )

  definition_xml = Nokogiri::XML(definition)
  definition_xml.remove_namespaces!

  @validator_provider = EasyUpnp::ValidatorProvider.from_xml(definition_xml)

  @service_methods = {}
  definition_xml.xpath('//actionList/action').map do |action|
    method = EasyUpnp::ServiceMethod.from_xml(action)
    @service_methods[method.name] = method

    # Adds a method to the class
    define_service_method(method, @client, @validator_provider, @options)
  end

  @event_vars = definition_xml.
    xpath('//serviceStateTable/stateVariable[@sendEvents = "yes"]/name').
    map(&:text).
    map(&:to_sym)
end