Class: Lita::GsuiteGateway
- Inherits:
-
Object
- Object
- Lita::GsuiteGateway
- Defined in:
- lib/lita/gsuite_gateway.rb
Overview
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.
Constant Summary collapse
- OAUTH_SCOPES =
[ "https://www.googleapis.com/auth/admin.directory.user.readonly", "https://www.googleapis.com/auth/admin.directory.orgunit.readonly", "https://www.googleapis.com/auth/admin.reports.audit.readonly", "https://www.googleapis.com/auth/admin.directory.group.readonly", "https://www.googleapis.com/auth/admin.directory.customer.readonly", ]
Instance Method Summary collapse
-
#account_summary ⇒ Object
return an object with some basic data on the entire gsuite account.
- #admin_activities(start_time, end_time) ⇒ Object
-
#delegated_admins ⇒ Object
return administrators with delegated administration of some users or groups.
-
#groups ⇒ Object
return an Array of all groups.
-
#initialize(user_authorization: nil) ⇒ GsuiteGateway
constructor
A new instance of GsuiteGateway.
- #organisational_units ⇒ Object
-
#super_admins ⇒ Object
return super administrators.
-
#two_factor_users ⇒ Object
return a list of users that have Two Factor Auth enabled.
-
#users ⇒ Object
return all users.
Constructor Details
#initialize(user_authorization: nil) ⇒ GsuiteGateway
Returns a new instance of GsuiteGateway.
34 35 36 |
# File 'lib/lita/gsuite_gateway.rb', line 34 def initialize(user_authorization: nil) @user_authorization = end |
Instance Method Details
#account_summary ⇒ Object
return an object with some basic data on the entire gsuite account
39 40 41 42 |
# 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) ⇒ Object
44 45 46 47 48 49 50 |
# 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 ⇒ Object
return administrators with delegated administration of some users or groups
83 84 85 |
# File 'lib/lita/gsuite_gateway.rb', line 83 def delegated_admins list_users("isDelegatedAdmin=true") end |
#groups ⇒ Object
return an Array of all groups
53 54 55 56 57 58 |
# 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 ⇒ Object
60 61 62 63 64 65 |
# 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 ⇒ Object
return super administrators
78 79 80 |
# File 'lib/lita/gsuite_gateway.rb', line 78 def super_admins list_users("isAdmin=true") end |
#two_factor_users ⇒ Object
return a list of users that have Two Factor Auth enabled
68 69 70 |
# File 'lib/lita/gsuite_gateway.rb', line 68 def two_factor_users list_users("isEnrolledIn2Sv=true") end |
#users ⇒ Object
return all users
73 74 75 |
# File 'lib/lita/gsuite_gateway.rb', line 73 def users list_users end |