Class: GoogleDirectory::Connection

Inherits:
Object
  • Object
show all
Includes:
UserCommands, Version
Defined in:
lib/google_directory/connection.rb

Overview

Note:

Its important to have your oauth setup and its client_secret.json file downloaded in the root directory

Note:

You can also use environment variables to override google defaults as wanted.

The GoogleDirectory, makes it easy to work with Google Directory.

Since:

  • 0.1.0

Constant Summary collapse

OOB_URI =

default settings from google for all users

Since:

  • 0.1.0

ENV['OOB_URI'] || 'urn:ietf:wg:oauth:2.0:oob'
CREDENTIALS_PATH =

Since:

  • 0.1.0

ENV['CREDENTIALS_PATH'] || File.join( Dir.home, '.credentials', "admin-directory_v1-ruby-accounts.yaml")
CLIENT_SECRETS_PATH =

Since:

  • 0.1.0

ENV['CLIENT_SECRETS_PATH'] || 'client_secret.json'
SCOPE =

Since:

  • 0.1.0

Google::Apis::AdminDirectoryV1::AUTH_ADMIN_DIRECTORY_USER

Constants included from Version

Version::VERSION

Instance Method Summary collapse

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

Note:

make connection to google directory services

Returns a new instance of Connection.

Parameters:

  • service (Class) (defaults to: Google::Apis::AdminDirectoryV1::DirectoryService)

    the default is: Google::Apis::AdminDirectoryV1::DirectoryService

Since:

  • 0.1.0



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.client_options.application_name = app_name
  @service.authorization = authorize
end

Instance Method Details

#run(command:, attributes: {}) ⇒ Hash Also known as: execute

Note:

Run a command against Google Directory

Returns formatted as: ‘{command: :command, attributes: {primary_email: “user@domain”, response: GoogleAnswer} }`.

Parameters:

  • command (Symbol)

    choose command to perform these include: :user_get, :user_exists? (t/f), :user_create, :user_delete, :user_update & convience commands :user_suspend, :user_reactivate, :user_change_password

  • attributes (Hash) (defaults to: {})

    attributes needed to perform command

Returns:

  • (Hash)

    formatted as: ‘{command: :command, attributes: {primary_email: “user@domain”, response: GoogleAnswer} }`

Since:

  • 0.1.0



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

#versionObject

Since:

  • 0.1.0



48
49
50
# File 'lib/google_directory/connection.rb', line 48

def version
  VERSION
end