class Lita::GsuiteGateway
Wrapper class for interacting with the gsuite directory API. Use this to list users, groups, group members.
It only has read-only permissions, so cannot make any changes.
Usage:
gateway = GsuiteGateway.new( user_authorization: auth )
The user_authorization argument should be an auth object generated the googleauth gem - check its documentation for more details on the ways to build one of these objects.
Constants
- OAUTH_SCOPES
Public Class Methods
new(user_authorization: nil)
click to toggle source
# File lib/lita/gsuite_gateway.rb, line 34 def initialize(user_authorization: nil) @user_authorization = user_authorization end
Public Instance Methods
account_summary()
click to toggle source
return an object with some basic data on the entire gsuite account
# File lib/lita/gsuite_gateway.rb, line 39 def account_summary data = directory_service.get_customer("my_customer") GoogleAccount.from_api(data) end
admin_activities(start_time, end_time)
click to toggle source
# File lib/lita/gsuite_gateway.rb, line 44 def admin_activities(start_time, end_time) data = reports_service.list_activities("all", "admin", start_time: start_time.iso8601, end_time: end_time.iso8601) activities = data.items || [] activities.map { |item| GoogleActivity.from_api(item) }.flatten end
delegated_admins()
click to toggle source
return administrators with delegated administration of some users or groups
# File lib/lita/gsuite_gateway.rb, line 83 def delegated_admins list_users("isDelegatedAdmin=true") end
groups()
click to toggle source
return an Array of all groups
# File lib/lita/gsuite_gateway.rb, line 53 def groups data = directory_service.list_groups(max_results: 500, customer: "my_customer") data.groups.map { |group| GoogleGroup.from_api(group) } end
organisational_units()
click to toggle source
# File lib/lita/gsuite_gateway.rb, line 60 def organisational_units data = directory_service.list_org_units("my_customer", type: "children") data.organization_units.map { |ou| GoogleOrganisationUnit.from_api(ou) } end
super_admins()
click to toggle source
return super administrators
# File lib/lita/gsuite_gateway.rb, line 78 def super_admins list_users("isAdmin=true") end
two_factor_users()
click to toggle source
return a list of users that have Two Factor Auth enabled
# File lib/lita/gsuite_gateway.rb, line 68 def two_factor_users list_users("isEnrolledIn2Sv=true") end
users()
click to toggle source
return all users
# File lib/lita/gsuite_gateway.rb, line 73 def users list_users end
Private Instance Methods
directory_service()
click to toggle source
# File lib/lita/gsuite_gateway.rb, line 96 def directory_service @directory_service ||= Google::Apis::AdminDirectoryV1::DirectoryService.new.tap { |service| service.authorization = @user_authorization } end
list_users(query = nil)
click to toggle source
# File lib/lita/gsuite_gateway.rb, line 89 def list_users(query = nil) data = directory_service.list_users(max_results: 500, customer: "my_customer", query: query) data.users.map { |user| GoogleUser.from_api_user(user) } end
reports_service()
click to toggle source
# File lib/lita/gsuite_gateway.rb, line 102 def reports_service @reports_service ||= Google::Apis::AdminReportsV1::ReportsService.new.tap { |service| service.authorization = @user_authorization } end