Module: GoogleDirectory::UserCommands
- Included in:
- Connection
- Defined in:
- lib/google_directory/user_commands.rb
Overview
DirectoryService Ruby API Commands - www.rubydoc.info/github/google/google-api-ruby-client/Google/Apis/AdminDirectoryV1/DirectoryService
GoogleUser Attributes - www.rubydoc.info/github/google/google-api-ruby-client/Google/Apis/AdminDirectoryV1/User
Instance Method Summary collapse
-
#user_change_password(attributes:) ⇒ Hash
Formatted as {command: :user_change_password, attributes: {primary_email: “user@domain”, response: GoogleUserObject } }.
-
#user_create(attributes:) ⇒ Hash
Formatted as {command: :user_create, attributes: {primary_email: “user@domain”, response: GoogleUserObject } }.
-
#user_delete(attributes:) ⇒ Hash
Formatted as {command: :user_delete, attributes: {primary_email: “user@domain”, response: “” } }.
-
#user_exists?(attributes:) ⇒ Hash
Formatted as {command: :user_exists?, attributes: {primary_email: “user@domain”, response: Boolean } }.
-
#user_get(attributes:) ⇒ Hash
Formatted as {command: :user_get, attributes: {primary_email: “user@domain”, response: GoogleUserObject } }.
-
#user_reactivate(attributes:) ⇒ Hash
Formatted as {command: :user_reactivate, attributes: {primary_email: “user@domain”, response: GoogleUserObject } }.
-
#user_suspend(attributes:) ⇒ Hash
Formatted as {command: :user_suspend, attributes: {primary_email: “user@domain”, response: GoogleUserObject } }.
-
#user_update(attributes:) ⇒ Hash
Formatted as {command: :user_update, attributes: {primary_email: “user@domain”, response: GoogleUserObject } }.
Instance Method Details
#user_change_password(attributes:) ⇒ Hash
updates an exising Google Directory User password - convience method instead of using :user_update
Returns formatted as {command: :user_change_password, attributes: {primary_email: “user@domain”, response: GoogleUserObject } }.
66 67 68 69 70 71 72 73 |
# File 'lib/google_directory/user_commands.rb', line 66 def user_change_password( attributes: ) password = SecureRandom.base64 defaults = { password: password, change_password_at_next_login: true } user_attr = defaults.merge( attributes ) response = update_user( user_attr ) {response: response, attributes: attributes[:primary_email], command: :user_change_password} end |
#user_create(attributes:) ⇒ Hash
creates a new Google Directory User
Returns formatted as {command: :user_create, attributes: {primary_email: “user@domain”, response: GoogleUserObject } }.
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/google_directory/user_commands.rb', line 40 def user_create( attributes: ) # http://blog.liveedu.tv/ruby-generate-random-string/ password = SecureRandom.base64 defaults = { suspended: true, password: password, change_password_at_next_login: true } user_attr = defaults.merge( attributes ) # create a google user object user_object = Google::Apis::AdminDirectoryV1::User.new user_attr # create user in directory services response = service.insert_user( user_object ) {response: response, attributes: attributes[:primary_email], command: :user_create} end |
#user_delete(attributes:) ⇒ Hash
deletes an exising Google Directory User
Returns formatted as {command: :user_delete, attributes: {primary_email: “user@domain”, response: “” } }.
103 104 105 106 |
# File 'lib/google_directory/user_commands.rb', line 103 def user_delete( attributes: ) response = service.delete_user( attributes[:primary_email] ) {response: response, attributes: attributes[:primary_email], command: :user_delete} end |
#user_exists?(attributes:) ⇒ Hash
Test if user exists in Google Directory
Returns formatted as {command: :user_exists?, attributes: {primary_email: “user@domain”, response: Boolean } }.
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/google_directory/user_commands.rb', line 23 def user_exists?( attributes: ) begin response = service.get_user( attributes[:primary_email] ) return {response: true, attributes: attributes[:primary_email], command: :user_exists?} rescue Google::Apis::ClientError => error if error..include? 'notFound' return {response: false, attributes: attributes[:primary_email], command: :user_exists?} else raise error end end end |
#user_get(attributes:) ⇒ Hash
Get GoogleDirectory User Info
Returns formatted as {command: :user_get, attributes: {primary_email: “user@domain”, response: GoogleUserObject } }.
14 15 16 17 |
# File 'lib/google_directory/user_commands.rb', line 14 def user_get( attributes: ) response = service.get_user( attributes[:primary_email] ) {response: response, attributes: attributes[:primary_email], command: :user_get} end |
#user_reactivate(attributes:) ⇒ Hash
activates an exising Google Directory User password - convience method instead of using :user_update
Returns formatted as {command: :user_reactivate, attributes: {primary_email: “user@domain”, response: GoogleUserObject } }.
79 80 81 82 83 84 85 |
# File 'lib/google_directory/user_commands.rb', line 79 def user_reactivate( attributes: ) defaults = { :suspended => false } user_attr = defaults.merge( attributes ) response = update_user( user_attr ) {response: response, attributes: attributes[:primary_email], command: :user_reactivate} end |
#user_suspend(attributes:) ⇒ Hash
suspends an exising Google Directory User password - convience method instead of using :user_update
Returns formatted as {command: :user_suspend, attributes: {primary_email: “user@domain”, response: GoogleUserObject } }.
91 92 93 94 95 96 97 |
# File 'lib/google_directory/user_commands.rb', line 91 def user_suspend( attributes: ) defaults = { :suspended => true } user_attr = defaults.merge( attributes ) response = update_user( user_attr ) {response: response, attributes: attributes[:primary_email], command: :user_suspend} end |
#user_update(attributes:) ⇒ Hash
updates an exising Google Directory User
Returns formatted as {command: :user_update, attributes: {primary_email: “user@domain”, response: GoogleUserObject } }.
56 57 58 59 60 |
# File 'lib/google_directory/user_commands.rb', line 56 def user_update( attributes: ) # create a user object for google to update response = update_user( attributes ) {response: response, attributes: attributes[:primary_email], command: :user_update} end |