Class: Hikvision::ISAPI

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/hikvision/isapi.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ip, username, password, args = { auth_type: 'digest_auth', https: false }) ⇒ ISAPI

Returns a new instance of ISAPI.



30
31
32
33
34
35
36
37
# File 'lib/hikvision/isapi.rb', line 30

def initialize(ip, username, password, args = { auth_type: 'digest_auth', https: false })
  @cache = {}
  @auth_type = args[:auth_type]
  @base_uri = "http#{args[:https] ? 's' : ''}://#{ip}"
  @auth = { username: username, password: password }
  @streaming = Hikvision::Streaming.new(self)
  @system = Hikvision::System.new(self)
end

Instance Attribute Details

#cacheObject

Returns the value of attribute cache.



27
28
29
# File 'lib/hikvision/isapi.rb', line 27

def cache
  @cache
end

#streamingObject (readonly)

Returns the value of attribute streaming.



28
29
30
# File 'lib/hikvision/isapi.rb', line 28

def streaming
  @streaming
end

#systemObject (readonly)

Returns the value of attribute system.



28
29
30
# File 'lib/hikvision/isapi.rb', line 28

def system
  @system
end

Instance Method Details

#get(path, options = {}) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/hikvision/isapi.rb', line 39

def get(path, options = {})
  options = default_request_options.merge(options)
  if @cache.has_key?(path) and options.fetch(:cache, true)
    @cache[path]
  else
    @cache[path] = self.class.get(@base_uri + path, options)
  end
end

#get_original(path, options = {}) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/hikvision/isapi.rb', line 48

def get_original(path, options = {})
  options = default_request_options.merge(options)
  if @cache.has_key?(path) and options.fetch(:cache, true)
    @cache[path]
  else
    @cache[path] = self.class.get(path, options)
  end
end

#get_xml(path, options = {}) ⇒ Object



57
58
59
60
61
62
# File 'lib/hikvision/isapi.rb', line 57

def get_xml(path, options = {})
  data = get(path, options)
  raise "could not get xml of #{path} code:#{data.response.code}" unless ['200'].include?(data.response.code)

  Nokogiri::XML(data.body).remove_namespaces!
end

#post(path, options = {}) ⇒ Object



70
71
72
73
74
# File 'lib/hikvision/isapi.rb', line 70

def post(path, options = {})
  @cache.delete(path)
  options = default_request_options.merge(options)
  self.class.post(@base_uri + path, options)
end

#put(path, options = {}) ⇒ Object



64
65
66
67
68
# File 'lib/hikvision/isapi.rb', line 64

def put(path, options = {})
  @cache.delete(path)
  options = default_request_options.merge(options)
  self.class.put(@base_uri + path, options)
end

#put_xml(path, options = {}) ⇒ Object

Raises:



76
77
78
79
80
81
82
83
# File 'lib/hikvision/isapi.rb', line 76

def put_xml(path, options = {})
  data = put(path, options)

  return true if data.response.code == '200'

  xml = Nokogiri::XML(data.body).remove_namespaces!
  raise ResponseError, xml
end