Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1. Starting from the previous gists we reuse the auth_token in the following request
- 2. We create a new Interceptor to handle Security Devices
- class SecurityDevicesInterceptor < Gruf::Interceptors::ClientInterceptor
- def call(request_context:)
- logger.info "Got method #{request_context.method}!"
- yield
- end
- end
- 3. Use the Interceptor to fetch Security Devices
- begin
- client = ::Gruf::Client.new(
- service: ::Org::SecurityDevices,
- options: {hostname: ENV['TOTAL_ACCESS_API_HOSTNAME']},
- client_options: {
- interceptors: [SecurityDevicesInterceptor.new]
- }
- )
- auth_hash = { "authorization" => "Bearer #{response.message.auth_token}" }
- response = client.call(:ListSecurityDevices, { organization_slug: 'example_organization_slug' }, auth_hash)
- security_devices = response.message.security_devices.select {|device| device.kind == :DOOR }
- rescue Gruf::Client::Error => e
- logger.error "#{e.error.message}"
- end
- 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