Class: Hikvision::ISAPI
- Inherits:
-
Object
- Object
- Hikvision::ISAPI
- Includes:
- HTTParty
- Defined in:
- lib/hikvision/isapi.rb
Instance Attribute Summary collapse
-
#cache ⇒ Object
Returns the value of attribute cache.
-
#streaming ⇒ Object
readonly
Returns the value of attribute streaming.
-
#system ⇒ Object
readonly
Returns the value of attribute system.
Instance Method Summary collapse
- #get(path, options = {}) ⇒ Object
- #get_original(path, options = {}) ⇒ Object
- #get_xml(path, options = {}) ⇒ Object
-
#initialize(ip, username, password, args = { auth_type: 'digest_auth', https: false }) ⇒ ISAPI
constructor
A new instance of ISAPI.
- #post(path, options = {}) ⇒ Object
- #put(path, options = {}) ⇒ Object
- #put_xml(path, options = {}) ⇒ Object
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
#cache ⇒ Object
Returns the value of attribute cache.
27 28 29 |
# File 'lib/hikvision/isapi.rb', line 27 def cache @cache end |
#streaming ⇒ Object (readonly)
Returns the value of attribute streaming.
28 29 30 |
# File 'lib/hikvision/isapi.rb', line 28 def streaming @streaming end |
#system ⇒ Object (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, = {}) = .merge() if @cache.has_key?(path) and .fetch(:cache, true) @cache[path] else @cache[path] = self.class.get(@base_uri + path, ) 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, = {}) = .merge() if @cache.has_key?(path) and .fetch(:cache, true) @cache[path] else @cache[path] = self.class.get(path, ) end end |
#get_xml(path, options = {}) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/hikvision/isapi.rb', line 57 def get_xml(path, = {}) data = get(path, ) 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, = {}) @cache.delete(path) = .merge() self.class.post(@base_uri + path, ) end |
#put(path, options = {}) ⇒ Object
64 65 66 67 68 |
# File 'lib/hikvision/isapi.rb', line 64 def put(path, = {}) @cache.delete(path) = .merge() self.class.put(@base_uri + path, ) end |
#put_xml(path, options = {}) ⇒ Object
76 77 78 79 80 81 82 83 |
# File 'lib/hikvision/isapi.rb', line 76 def put_xml(path, = {}) data = put(path, ) return true if data.response.code == '200' xml = Nokogiri::XML(data.body).remove_namespaces! raise ResponseError, xml end |