Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. 1. Generate session classes from codebase.
  2.  
  3. grpc_tools_ruby_protoc -I proto/ --ruby_out=lib --grpc_out=lib proto/entities.proto
  4. grpc_tools_ruby_protoc -I proto/ --ruby_out=lib --grpc_out=lib proto/sessions.proto
  5.  
  6. 2. We create an SessionsInterceptor
  7.  
  8. class SessionsInterceptor < Gruf::Interceptors::ClientInterceptor
  9. def call(request_context:)
  10. logger.info "Got method #{request_context.method}!"
  11. yield
  12. end
  13. end
  14.  
  15. 3. We use the SessionsInterceptor with the Gruf client to communicate. You can see which methods that is possible to call in the generated ruby files.
  16.  
  17. begin
  18. client = ::Gruf::Client.new(
  19. service: ::Org::Sessions,
  20. options: {hostname: ENV['TOTAL_ACCESS_API_URL']},
  21. client_options: {
  22. interceptors: [SessionsInterceptor.new]
  23. }
  24. )
  25.  
  26. org_session = client.call(:CreateSession, { username: ENV['TOTAL_ACCESS_API_USERNAME'], password: ENV['TOTAL_ACCESS_API_PASSWORD'], device_uuid: ENV['TOTAL_ACCESS_API_UUID'] })
  27.  
  28. rescue Gruf::Client::Error => e
  29. logger.error "#{e.error.message}"
  30. end
  31.  
  32. 3. In the org_session variable there will be an auth_token that is to be reused in the following requests.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement