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

CREDENTIALS_PATH =

default settings from google for all users

Since:

  • 0.1.0

ENV['CREDENTIALS_JSON_PATH']
SUB_ACCOUNT =

Since:

  • 0.1.0

ENV['SUB_ACCOUNT_NAME']

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



39
40
41
42
# File 'lib/google_directory/connection.rb', line 39

def initialize( service: Google::Apis::AdminDirectoryV1::DirectoryService )
  @service   = service.new
  @service.authorization = authorize
end

Instance Method Details

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

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



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/google_directory/connection.rb', line 51

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



44
45
46
# File 'lib/google_directory/connection.rb', line 44

def version
  VERSION
end