Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. 1. As a third step we also fetch any users we have created either in the portal or through the Total Access API.
  2.  
  3. 2. We create an Interceptor for Users.
  4.  
  5. class UsersInterceptor < Gruf::Interceptors::ClientInterceptor
  6. def call(request_context:)
  7. logger.info "Got method #{request_context.method}!"
  8. yield
  9. end
  10. end
  11.  
  12. begin
  13. client = ::Gruf::Client.new(
  14. service: ::Org::Users,
  15. options: {hostname: ENV['TOTAL_ACCESS_API_HOSTNAME']},
  16. client_options: {
  17. interceptors: [UsersInterceptor.new]
  18. }
  19. )
  20.  
  21. auth_hash = { "authorization" => "Bearer #{response.message.auth_token}" }
  22.  
  23. users = client.call(:ListUsers, { organization_slug: 'example_organization_slug' }, auth_hash)
  24.  
  25. rescue Gruf::Client::Error => e
  26. logger.error "#{e.error.message}"
  27. end
  28.  
  29. 3. In the users variable there will be an auth_token that is to be reused in the following request to assign users to a user group.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement