Class: GoogleDirectory::Connection
- Inherits:
-
Object
- Object
- GoogleDirectory::Connection
- Includes:
- UserCommands, Version
- Defined in:
- lib/google_directory/connection.rb
Overview
Its important to have your oauth setup and its client_secret.json file downloaded in the root directory
You can also use environment variables to override google defaults as wanted.
The GoogleDirectory, makes it easy to work with Google Directory.
Constant Summary collapse
- OOB_URI =
default settings from google for all users
ENV['OOB_URI'] || 'urn:ietf:wg:oauth:2.0:oob'
- CREDENTIALS_PATH =
ENV['CREDENTIALS_PATH'] || File.join( Dir.home, '.credentials', "admin-directory_v1-ruby-accounts.yaml")
- CLIENT_SECRETS_PATH =
Get info the Google Cloud Admin console.cloud.google.com/apis/ or build using: developers.google.com/api-client-library/ruby/guide/aaa_client_secrets
ENV['CLIENT_SECRETS_PATH'] || 'client_secret.json'
- SCOPE =
Google::Apis::AdminDirectoryV1::AUTH_ADMIN_DIRECTORY_USER
Constants included from Version
Instance Method Summary collapse
-
#initialize(service: Google::Apis::AdminDirectoryV1::DirectoryService) ⇒ Connection
constructor
A new instance of Connection.
-
#run(command:, attributes: {}) ⇒ Hash
(also: #execute)
Formatted as: ‘{command: :command, attributes: {primary_email: “user@domain”, response: GoogleAnswer} }`.
- #version ⇒ Object
Methods included from UserCommands
#user_change_password, #user_create, #user_delete, #user_exists?, #user_get, #user_reactivate, #user_suspend, #user_update
Constructor Details
#initialize(service: Google::Apis::AdminDirectoryV1::DirectoryService) ⇒ Connection
make connection to google directory services
Returns a new instance of Connection.
41 42 43 44 45 46 |
# File 'lib/google_directory/connection.rb', line 41 def initialize( service: Google::Apis::AdminDirectoryV1::DirectoryService ) app_name ||= ENV['APPLICATION_NAME'] || 'google_cloud_app_name' @service = service.new @service..application_name = app_name @service. = end |
Instance Method Details
#run(command:, attributes: {}) ⇒ Hash Also known as: execute
Run a command against Google Directory
Returns formatted as: ‘{command: :command, attributes: {primary_email: “user@domain”, response: GoogleAnswer} }`.
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/google_directory/connection.rb', line 57 def run( command:, attributes: {} ) response = {} begin response = send( command, attributes: attributes ) response[:status] = 'success' rescue Google::Apis::ClientError => error response = {status: 'error', response: error, attributes: attributes, command: command, } end response end |
#version ⇒ Object
48 49 50 |
# File 'lib/google_directory/connection.rb', line 48 def version VERSION end |