Class: RUPNP::CP::Base
- Inherits:
-
Object
- Object
- RUPNP::CP::Base
- Defined in:
- lib/rupnp/cp/base.rb
Overview
Base class for devices and services
Direct Known Subclasses
Constant Summary collapse
- HTTP_COMMON_CONFIG =
Common HTTP headers for description requests
{ :head => { :user_agent => USER_AGENT, :host => "#{HOST_IP}:#{DISCOVERY_PORT}", }, }
Constants included from LogMixin
Instance Method Summary collapse
-
#get_description(location, getter) ⇒ void
Get description from
location. -
#initialize ⇒ Base
constructor
A new instance of Base.
-
#inspect ⇒ Object
String.
Methods included from LogMixin
Methods included from Tools
#build_url, #snake_case, #urn_are_equivalent?, #usn2udn
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
25 26 27 |
# File 'lib/rupnp/cp/base.rb', line 25 def initialize @parser = Nori.new(:convert_tags_to => ->(tag){ tag.snakecase.to_sym }) end |
Instance Method Details
#get_description(location, getter) ⇒ void
This method returns an undefined value.
Get description from location
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rupnp/cp/base.rb', line 35 def get_description(location, getter) log :info, "getting description for #{location}" http = EM::HttpRequest.new(location).get(HTTP_COMMON_CONFIG) http.errback do |error| getter.set_deferred_status :failed, 'Cannot get description' end callback = Proc.new do description = @parser.parse(http.response) log :debug, 'Description received' getter.succeed description end http.headers do |h| unless h['SERVER'] =~ /UPnP\/1\.\d/ log :error, "Not a supported UPnP response : #{h['SERVER']}" http.cancel_callback callback end end http.callback &callback end |
#inspect ⇒ Object
Returns String.
60 61 62 |
# File 'lib/rupnp/cp/base.rb', line 60 def inspect "#<#{self.class}:#{object_id} type=#{type.inspect}>" end |