Class: ONVIF::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_onvif_client/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Client

Returns a new instance of Client.



7
8
9
10
11
# File 'lib/ruby_onvif_client/client.rb', line 7

def initialize options
    @options = {
        connect_timeout: 5,
    }.merge(options)
end

Instance Method Details

#send(data) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ruby_onvif_client/client.rb', line 13

def send data
    puts "send data to #{@options} ", data 
    http_options = {
        connect_timeout: @options[:connect_timeout]
    }
    request_options = {
        body: data
    }
    http = EventMachine::HttpRequest.new(
        @options[:address], 
        http_options
    ).post(request_options)
    http.errback { yield false, {} }
    http.callback do
        puts "========================="
        puts "receive message =>", http.response
        puts "========================="
        if http.response_header.status != 200
            yield false, {header: http.response_header}
        else
            #nori = Nori.new(:strip_namespaces => true)
            yield true, {
                header: http.response_header,
                #content: nori.parse(http.response)
                content: http.response
            }
        end
    end
end