Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. 1. Starting from the previous gists we reuse the auth_token in the following request
  2.  
  3. 2. We create a new Interceptor to handle Security Devices
  4.  
  5. class SecurityDevicesInterceptor < Gruf::Interceptors::ClientInterceptor
  6. def call(request_context:)
  7. logger.info "Got method #{request_context.method}!"
  8. yield
  9. end
  10. end
  11.  
  12. 3. Use the Interceptor to fetch Security Devices
  13.  
  14. begin
  15. client = ::Gruf::Client.new(
  16. service: ::Org::SecurityDevices,
  17. options: {hostname: ENV['TOTAL_ACCESS_API_HOSTNAME']},
  18. client_options: {
  19. interceptors: [SecurityDevicesInterceptor.new]
  20. }
  21. )
  22.  
  23. auth_hash = { "authorization" => "Bearer #{response.message.auth_token}" }
  24.  
  25. response = client.call(:ListSecurityDevices, { organization_slug: 'example_organization_slug' }, auth_hash)
  26.  
  27. security_devices = response.message.security_devices.select {|device| device.kind == :DOOR }
  28.  
  29. rescue Gruf::Client::Error => e
  30. logger.error "#{e.error.message}"
  31. end
  32.  
  33. 4. The security_devices variable now contains the correct ID:s to be used in requests when it comes to assigning doors to user groups. Note assigned devices need to have the kind of DOOR.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement