Module: AxisNetcam::Camera::Users
- Included in:
- AxisNetcam::Camera
- Defined in:
- lib/axis-netcam/camera.rb
Overview
Functionality related to managing the camera’s user and group lists.
Instance Method Summary collapse
-
#add_or_update_user(user) ⇒ Object
Same as add_user, but updates the user account instead of creating it if it already exists.
-
#add_user(user) ⇒ Object
Adds a new user based on the given hash.
-
#remove_user(username) ⇒ Object
Deletes the user with the given username.
-
#update_user(username, attributes) ⇒ Object
Updates a user based on the given hash.
-
#user_exists?(username) ⇒ Boolean
Checks if the user with the given username exists.
-
#users ⇒ Object
Returns an array with the usernames of the users on the camera.
Instance Method Details
#add_or_update_user(user) ⇒ Object
Same as add_user, but updates the user account instead of creating it if it already exists.
251 252 253 254 255 256 257 |
# File 'lib/axis-netcam/camera.rb', line 251 def add_or_update_user(user) if user_exists?(user[:username], user) update_user(user[:username], user) else add_user(user) end end |
#add_user(user) ⇒ Object
Adds a new user based on the given hash. The hash must have :username, :password, and :comment elements.
222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/axis-netcam/camera.rb', line 222 def add_user(user) params = { 'action' => 'add', 'user' => user[:username], 'pwd' => user[:password], 'comment' => user[:comment], 'grp' => 'users', 'sgrp' => 'axview' } axis_action("admin/pwdgrp.cgi", params) end |
#remove_user(username) ⇒ Object
Deletes the user with the given username.
260 261 262 263 264 265 266 |
# File 'lib/axis-netcam/camera.rb', line 260 def remove_user(username) params = { 'action' => 'remove', 'user' => username, } axis_action("admin/pwdgrp.cgi", params) end |
#update_user(username, attributes) ⇒ Object
Updates a user based on the given hash.
- username
-
specifies the username of the user to update.
- attributes
-
must be a hash with new values for :password and :comment.
237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/axis-netcam/camera.rb', line 237 def update_user(username, attributes) params = { 'action' => 'update', 'user' => username, 'pwd' => user[:password], 'comment' => user[:comment], 'grp' => 'users', 'sgrp' => 'axview' } axis_action("admin/pwdgrp.cgi", params) end |
#user_exists?(username) ⇒ Boolean
Checks if the user with the given username exists.
285 286 287 |
# File 'lib/axis-netcam/camera.rb', line 285 def user_exists?(username) users.include? username end |
#users ⇒ Object
Returns an array with the usernames of the users on the camera.
269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/axis-netcam/camera.rb', line 269 def users str = axis_action("admin/pwdgrp.cgi", {'action' => 'get'}) return false unless str usernames = [] str.split.collect do |u| u =~ /.*?="(.*)"/ if $~ usernames += $~[1].split(',') else usernames += [] end end usernames.uniq! end |