google_directory 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf3b16f0223835642133e6f6f2e7cbdc2012c0459923543f218d762a8e03e89d
|
4
|
+
data.tar.gz: 87258d6b5de32692cb0f5016619388ebf5257e0c8152f21569558ad67c797554
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7033882f9889578aba25ad3f41166258d8f682696c300ab1ad4fee899646d3a0d41672035a4e7518d5b32b7e273507900d64584b43d2faac7d7d25cb5b5ae6f0
|
7
|
+
data.tar.gz: dd31543c65ae56e3caf8aa5d17aa86f1d7c659f025eb7c5ee78fc1ee51e7002ec417d465e02ccb2f17ecfa20a7b2eea0e4981ea764152eb088bcd3878c7bcdc9
|
@@ -44,27 +44,27 @@ module GoogleDirectory
|
|
44
44
|
|
45
45
|
# @note Run a command against Google Directory
|
46
46
|
#
|
47
|
-
# @param
|
48
|
-
# @param attributes [Hash] attributes needed to perform
|
49
|
-
# @return [Hash]
|
50
|
-
def run(
|
47
|
+
# @param 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
|
48
|
+
# @param attributes [Hash] attributes needed to perform command
|
49
|
+
# @return [Hash] formatted as: `{success: {command: :command, attributes: {primary_email: "user@domain"}, response: GoogleAnswer} }`
|
50
|
+
def run( command:, attributes: {} )
|
51
51
|
response = { success: nil, error: nil }
|
52
52
|
begin
|
53
|
-
response[:success] = send(
|
53
|
+
response[:success] = send( command, attributes: attributes )
|
54
54
|
rescue Google::Apis::ClientError => error
|
55
|
-
response[:error] = {
|
55
|
+
response[:error] = {command: command, attributes: attributes,
|
56
56
|
error: error}
|
57
57
|
end
|
58
58
|
response
|
59
59
|
end
|
60
60
|
alias_method :execute, :run
|
61
61
|
|
62
|
-
# # answer = GoogleDirectory.(
|
62
|
+
# # answer = GoogleDirectory.(command: :user_get, attributes: {primary_email: "btihen@las.ch"})
|
63
63
|
# def self.call(service: Google::Apis::AdminDirectoryV1::DirectoryService,
|
64
64
|
# app_name: nil,
|
65
|
-
#
|
65
|
+
# command:, attributes: {} )
|
66
66
|
# new(service: service, app_name: app_name).
|
67
|
-
# run(
|
67
|
+
# run(command: command, attributes: attributes)
|
68
68
|
# end
|
69
69
|
|
70
70
|
private
|
@@ -10,23 +10,23 @@ module GoogleDirectory
|
|
10
10
|
# @note Get GoogleDirectory User Info
|
11
11
|
#
|
12
12
|
# @param attributes [Hash] this attribute MUST include: { primary_email: "username@domain.com" }
|
13
|
-
# @return [Hash] formatted as {success: {
|
13
|
+
# @return [Hash] formatted as {success: {command: :user_get, attributes: {primary_email: "user@domain"}, response: GoogleUserObject } }
|
14
14
|
def user_get( attributes: )
|
15
15
|
response = service.get_user( attributes[:primary_email] )
|
16
|
-
{
|
16
|
+
{command: :user_get, user: attributes[:primary_email], response: response}
|
17
17
|
end
|
18
18
|
|
19
19
|
# @note Test if user exists in Google Directory
|
20
20
|
#
|
21
21
|
# @param attributes [Hash] this attribute MUST include: { primary_email: "username@domain.com" }
|
22
|
-
# @return [Hash] formatted as {success: {
|
22
|
+
# @return [Hash] formatted as {success: {command: :user_exists?, attributes: {primary_email: "user@domain"}, response: Boolean } }
|
23
23
|
def user_exists?( attributes: )
|
24
24
|
begin
|
25
25
|
response = service.get_user( attributes[:primary_email] )
|
26
|
-
return {
|
26
|
+
return {command: :user_exists?, user: attributes[:primary_email], response: true}
|
27
27
|
rescue Google::Apis::ClientError => error
|
28
28
|
if error.message.include? 'notFound'
|
29
|
-
return {
|
29
|
+
return {command: :user_exists?, user: attributes[:primary_email], response: false}
|
30
30
|
else
|
31
31
|
raise error
|
32
32
|
end
|
@@ -36,7 +36,7 @@ module GoogleDirectory
|
|
36
36
|
# @note creates a new Google Directory User
|
37
37
|
#
|
38
38
|
# @param attributes [Hash] this attribute MUST include: { primary_email: "username@domain.com", name: {given_name: "First Names", family_name: "LAST NAMES" } }
|
39
|
-
# @return [Hash] formatted as {success: {
|
39
|
+
# @return [Hash] formatted as {success: {command: :user_create, attributes: {primary_email: "user@domain"}, response: GoogleUserObject } }
|
40
40
|
def user_create( attributes: )
|
41
41
|
# http://blog.liveedu.tv/ruby-generate-random-string/
|
42
42
|
password = SecureRandom.base64
|
@@ -46,63 +46,63 @@ module GoogleDirectory
|
|
46
46
|
user_object = Google::Apis::AdminDirectoryV1::User.new user_attr
|
47
47
|
# create user in directory services
|
48
48
|
response = service.insert_user( user_object )
|
49
|
-
{
|
49
|
+
{command: :user_create, user: attributes[:primary_email], response: response}
|
50
50
|
end
|
51
51
|
|
52
52
|
# @note updates an exising Google Directory User
|
53
53
|
#
|
54
54
|
# @param attributes [Hash] this attribute MUST include: { primary_email: "username@domain.com", attributes_to_change: "" } }
|
55
|
-
# @return [Hash] formatted as {success: {
|
55
|
+
# @return [Hash] formatted as {success: {command: :user_update, attributes: {primary_email: "user@domain"}, response: GoogleUserObject } }
|
56
56
|
def user_update( attributes: )
|
57
57
|
# create a user object for google to update
|
58
58
|
response = update_user( attributes )
|
59
|
-
{
|
59
|
+
{command: :user_update, user: attributes[:primary_email], response: response}
|
60
60
|
end
|
61
61
|
|
62
62
|
# @note updates an exising Google Directory User password - convience method instead of using :user_update
|
63
63
|
#
|
64
64
|
# @param attributes [Hash] this attribute MUST include: { primary_email: "username@domain.com", password: "secret" } - if no password is included a random password will be assigned
|
65
|
-
# @return [Hash] formatted as {success: {
|
65
|
+
# @return [Hash] formatted as {success: {command: :user_change_password, attributes: {primary_email: "user@domain"}, response: GoogleUserObject } }
|
66
66
|
def user_change_password( attributes: )
|
67
67
|
password = SecureRandom.base64
|
68
68
|
defaults = { password: password, change_password_at_next_login: true }
|
69
69
|
user_attr = defaults.merge( attributes )
|
70
70
|
|
71
71
|
response = update_user( user_attr )
|
72
|
-
{
|
72
|
+
{command: :user_change_password, user: attributes[:primary_email], response: response}
|
73
73
|
end
|
74
74
|
|
75
75
|
# @note activates an exising Google Directory User password - convience method instead of using :user_update
|
76
76
|
#
|
77
77
|
# @param attributes [Hash] this attribute MUST include: { primary_email: "username@domain.com" }
|
78
|
-
# @return [Hash] formatted as {success: {
|
78
|
+
# @return [Hash] formatted as {success: {command: :user_reactivate, attributes: {primary_email: "user@domain"}, response: GoogleUserObject } }
|
79
79
|
def user_reactivate( attributes: )
|
80
80
|
defaults = { :suspended => false }
|
81
81
|
user_attr = defaults.merge( attributes )
|
82
82
|
|
83
83
|
response = update_user( user_attr )
|
84
|
-
{
|
84
|
+
{command: :user_reactivate, user: attributes[:primary_email], response: response}
|
85
85
|
end
|
86
86
|
|
87
87
|
# @note suspends an exising Google Directory User password - convience method instead of using :user_update
|
88
88
|
#
|
89
89
|
# @param attributes [Hash] this attribute MUST include: { primary_email: "username@domain.com" }
|
90
|
-
# @return [Hash] formatted as {success: {
|
90
|
+
# @return [Hash] formatted as {success: {command: :user_suspend, attributes: {primary_email: "user@domain"}, response: GoogleUserObject } }
|
91
91
|
def user_suspend( attributes: )
|
92
92
|
defaults = { :suspended => true }
|
93
93
|
user_attr = defaults.merge( attributes )
|
94
94
|
|
95
95
|
response = update_user( user_attr )
|
96
|
-
{
|
96
|
+
{command: :user_suspend, user: attributes[:primary_email], response: response}
|
97
97
|
end
|
98
98
|
|
99
99
|
# @note deletes an exising Google Directory User
|
100
100
|
#
|
101
101
|
# @param attributes [Hash] this attribute MUST include: { primary_email: "username@domain.com" }
|
102
|
-
# @return [Hash] formatted as {success: {
|
102
|
+
# @return [Hash] formatted as {success: {command: :user_delete, attributes: {primary_email: "user@domain"}, response: "" } }
|
103
103
|
def user_delete( attributes: )
|
104
104
|
response = service.delete_user( attributes[:primary_email] )
|
105
|
-
{
|
105
|
+
{command: :user_delete, user: attributes[:primary_email], response: response}
|
106
106
|
end
|
107
107
|
|
108
108
|
private
|
@@ -17,7 +17,7 @@ module GoogleDirectory
|
|
17
17
|
defaults = { max_results: 10, order_by: 'email' }
|
18
18
|
filters = defaults.merge( attributes )
|
19
19
|
response = service.list_users( filters )
|
20
|
-
{
|
20
|
+
{command: :users_list, filters: filters, response: response}
|
21
21
|
end
|
22
22
|
|
23
23
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google_directory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bill Tihen
|
@@ -117,5 +117,5 @@ rubyforge_project:
|
|
117
117
|
rubygems_version: 2.7.6
|
118
118
|
signing_key:
|
119
119
|
specification_version: 4
|
120
|
-
summary: Simple ruby wrapper to manage google accounts.
|
120
|
+
summary: Simple ruby wrapper to manage google accounts - using oauth2.
|
121
121
|
test_files: []
|