rbzk 0.1.7 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1290a1fd6cc12310c5471f045a47e0c8d5b598326d7e5db899bde02ec6bc96ee
4
- data.tar.gz: 172c829144c8aa97e998c19803d5d19fd9d379f38c93170295f149f4a163c2c0
3
+ metadata.gz: 73a55ff7a558ac52bd29c070e50d62cecaff6881a04e5426777a70a3f4f67cd3
4
+ data.tar.gz: 697c3d0eddfbc1e7c2c71a2fdcdbd937727863776bf03c16beb729797ea507c7
5
5
  SHA512:
6
- metadata.gz: 4ee4a5a83b9f129158ea253868b4033d6c0013360d67fe05ba7518a67c6baaf971eeaf764ef447638a0e029a927524ccc51e7871ef0c22ea89b98d3608579542
7
- data.tar.gz: 75af5b6ac2c57fe3e0dce24be118ac1fc69cb941d8d78bb8d706da6913ddcc9cf36e669c12e2f114c366eded3be18da5e3bec956e071657250a0812acf57810d
6
+ metadata.gz: ca7705c199d61813975fc7200d747cca655f4743c3db9f3a3d23a1dc5967dd2e26e993d4450d62bfca7084cfbff497485f8caed9500b3be6d58a4bc3f9e546ca
7
+ data.tar.gz: c150348cb994e1c30fd3990852e27508d80090df6d3ae66fe7ed74076309d2fbd5f41f800fbc4715162d3444e52d7a6b0c1cf67411dbdf6c964d6560c9cf4093
@@ -427,17 +427,35 @@ module RBZK
427
427
  with_connection(ip, options) do |conn|
428
428
  puts 'Adding/updating user...'
429
429
 
430
- result = conn.set_user(
431
- uid: options[:uid],
432
- name: options[:name] || '',
433
- privilege: options[:privilege] || 0,
434
- password: options[:password] || '',
435
- group_id: options[:group_id] || '',
436
- user_id: options[:user_id] || '',
437
- card: options[:card] || 0
438
- )
439
-
440
- puts '✓ User added/updated successfully!' if result
430
+ # Disable device for exclusive access during modification
431
+ begin
432
+ conn.disable_device
433
+ rescue StandardError
434
+ nil
435
+ end
436
+
437
+ begin
438
+ result = conn.set_user(
439
+ uid: options[:uid],
440
+ name: options[:name] || '',
441
+ privilege: options[:privilege] || 0,
442
+ password: options[:password] || '',
443
+ group_id: options[:group_id] || '',
444
+ user_id: options[:user_id] || '',
445
+ card: options[:card] || 0
446
+ )
447
+ puts '✓ User added/updated successfully!' if result
448
+ rescue RBZK::ZKError => e
449
+ # Reraise to let the with_connection handler print device messages
450
+ raise e
451
+ ensure
452
+ # Re-enable device after modification (always)
453
+ begin
454
+ conn.enable_device
455
+ rescue StandardError
456
+ nil
457
+ end
458
+ end
441
459
  end
442
460
  end
443
461
 
@@ -743,6 +761,8 @@ module RBZK
743
761
  rescue RBZK::ZKNetworkError => e
744
762
  puts "✗ Network Error: #{e.message}"
745
763
  puts 'Please check the IP address and ensure the device is reachable.'
764
+ rescue RBZK::ZKErrorExists => e
765
+ puts "✗ Device Error: #{e.message}"
746
766
  rescue RBZK::ZKErrorResponse => e
747
767
  puts "✗ Device Error: #{e.message}"
748
768
  puts 'The device returned an error response.'
@@ -815,11 +835,10 @@ module RBZK
815
835
 
816
836
  def format_privilege(privilege)
817
837
  case privilege
818
- when 0 then 'User'
819
- when 1 then 'Enroller'
820
- when 2 then 'Manager'
821
- when 3 then 'Administrator'
822
- when 14 then 'Super Admin'
838
+ when RBZK::Constants::USER_DEFAULT then 'User'
839
+ when RBZK::Constants::USER_ENROLLER then 'Enroller'
840
+ when RBZK::Constants::USER_MANAGER then 'Manager'
841
+ when RBZK::Constants::USER_ADMIN then 'Admin'
823
842
  else "Unknown (#{privilege})"
824
843
  end
825
844
  end
@@ -20,4 +20,10 @@ module RBZK
20
20
  super
21
21
  end
22
22
  end
23
+
24
+ class ZKErrorExists < ZKError
25
+ def initialize(msg = 'Data already exists')
26
+ super
27
+ end
28
+ end
23
29
  end
data/lib/rbzk/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RBZK
4
- VERSION = '0.1.7'
4
+ VERSION = '0.1.8'
5
5
  end