Module: AxisNetcam::Camera::Info
- Included in:
- AxisNetcam::Camera
- Defined in:
- lib/axis-netcam/camera.rb
Overview
Functionality related to obtaining information about the camera, such as its status, model number, etc.
Instance Method Summary collapse
-
#model ⇒ Object
Returns the camera’s model name.
-
#server_report(force_refresh = false) ⇒ Object
Returns the raw camera server report.
-
#status_code ⇒ Object
Returns a code describing the camera’s current status.
-
#status_message ⇒ Object
Returns the result of the status message resulting from the last status_code call.
Instance Method Details
#model ⇒ Object
Returns the camera’s model name.
268 269 270 271 272 273 274 275 276 |
# File 'lib/axis-netcam/camera.rb', line 268 def model begin server_report =~ /prodshortname\s*=\s*"(.*?)"/i $~[1] rescue RemoteTimeout, RemoteError => e @error = e nil end end |
#server_report(force_refresh = false) ⇒ Object
Returns the raw camera server report.
The report is a string with info about the camera’s status and parameters, and differs considerably from model to model.
If you have the Easycache Rails plugin installed, report data will be cached unless the force_refresh argument is true. This is done to help improve performance, as the server_report method is often called by other methods to retrieve various camera info.
252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/axis-netcam/camera.rb', line 252 def server_report(force_refresh = false) if Object.const_defined? "Easycache" if force_refresh Easycache.write("#{hostname}_server_report", @report = axis_action("admin/serverreport.cgi")) else @report ||= Easycache.cache("#{hostname}_server_report") do axis_action("admin/serverreport.cgi") end end else axis_action("admin/serverreport.cgi") end end |
#status_code ⇒ Object
Returns a code describing the camera’s current status. The codes are as follows:
- :ok
-
Camera is responding as expected.
- :down
-
Camera is not responding at all (connection is timing out).
- :error
-
Camera responded with an error.
- :no_server_report
-
Camera responded but for some reason did not return a server report.
Calling this method updates the @status_message attribute with some more detailed information about the camera’s status (for example, the full error message in case of an error).
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 |
# File 'lib/axis-netcam/camera.rb', line 289 def status_code begin if self.server_report(true).empty? @status_message = "Server did not send report" :no_server_report else @status_message = "OK" :ok end rescue InvalidLogin => e @status_message = "Invalid login" :invalid_login rescue RemoteTimeout => e @status_message = "Timeout" :down rescue RemoteError => e @status_message = "Error: #{e}" :error end end |
#status_message ⇒ Object
Returns the result of the status message resulting from the last status_code call. If no status message is available, status_code will be automatically called first.
313 314 315 316 317 318 319 320 |
# File 'lib/axis-netcam/camera.rb', line 313 def if @status_message @status_message else status_code @status_message end end |