Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1. Generate session classes from codebase.
- grpc_tools_ruby_protoc -I proto/ --ruby_out=lib --grpc_out=lib proto/entities.proto
- grpc_tools_ruby_protoc -I proto/ --ruby_out=lib --grpc_out=lib proto/sessions.proto
- 2. We create an SessionsInterceptor
- class SessionsInterceptor < Gruf::Interceptors::ClientInterceptor
- def call(request_context:)
- logger.info "Got method #{request_context.method}!"
- yield
- end
- end
- 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.
- begin
- client = ::Gruf::Client.new(
- service: ::Org::Sessions,
- options: {hostname: ENV['TOTAL_ACCESS_API_URL']},
- client_options: {
- interceptors: [SessionsInterceptor.new]
- }
- )
- org_session = client.call(:CreateSession, { username: ENV['TOTAL_ACCESS_API_USERNAME'], password: ENV['TOTAL_ACCESS_API_PASSWORD'], device_uuid: ENV['TOTAL_ACCESS_API_UUID'] })
- rescue Gruf::Client::Error => e
- logger.error "#{e.error.message}"
- end
- 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