google_directory 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: be15ff583f69da807620a4b2aef6466b6a896e5d9fc50bdd36f5855fb63b4d50
4
- data.tar.gz: b7ecff040096c31c35a8b29ff13859e763f9cb4fcb3d025247c255f32fb6e801
3
+ metadata.gz: cf3b16f0223835642133e6f6f2e7cbdc2012c0459923543f218d762a8e03e89d
4
+ data.tar.gz: 87258d6b5de32692cb0f5016619388ebf5257e0c8152f21569558ad67c797554
5
5
  SHA512:
6
- metadata.gz: dc47b4ce9e1d17d53ff5ec0a109feec4b0cc82951917cdfe3b1392aa16688d594152710a321d7c7225654348962995ddef87c2b368d0250412a4992ac675d17a
7
- data.tar.gz: 0f482a2d2cfc9ae100b0e5b0617c8892a5445821ac64da29fc9334c32aedd0bb616748b63751e500ca3a1e97dddffdc6863659b0bdd3ea1ff4d081af82a86cb6
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 action [Symbol] choose action 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 action
49
- # @return [Hash] will hopefully return a hash with {success: {action: :action, attributes: {primary_email: "user@domain"}, response: "whatever google answered - usually a hash"} }
50
- def run( action:, attributes: {} )
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( action, attributes: attributes )
53
+ response[:success] = send( command, attributes: attributes )
54
54
  rescue Google::Apis::ClientError => error
55
- response[:error] = {action: action, attributes: attributes,
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.(action: :user_get, attributes: {primary_email: "btihen@las.ch"})
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
- # action:, attributes: {} )
65
+ # command:, attributes: {} )
66
66
  # new(service: service, app_name: app_name).
67
- # run(action: action, attributes: attributes)
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: {action: :user_get, attributes: {primary_email: "user@domain"}, response: GoogleUserObject } }
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
- {action: :user_get, user: attributes[:primary_email], response: response}
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: {action: :user_exists?, attributes: {primary_email: "user@domain"}, response: Boolean } }
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 {action: :user_exists?, user: attributes[:primary_email], response: true}
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 {action: :user_exists?, user: attributes[:primary_email], response: false}
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: {action: :user_create, attributes: {primary_email: "user@domain"}, response: GoogleUserObject } }
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
- {action: :user_create, user: attributes[:primary_email], response: response}
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: {action: :user_update, attributes: {primary_email: "user@domain"}, response: GoogleUserObject } }
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
- {action: :user_update, user: attributes[:primary_email], response: response}
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: {action: :user_change_password, attributes: {primary_email: "user@domain"}, response: GoogleUserObject } }
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
- {action: :user_change_password, user: attributes[:primary_email], response: response}
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: {action: :user_reactivate, attributes: {primary_email: "user@domain"}, response: GoogleUserObject } }
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
- {action: :user_reactivate, user: attributes[:primary_email], response: response}
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: {action: :user_suspend, attributes: {primary_email: "user@domain"}, response: GoogleUserObject } }
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
- {action: :user_suspend, user: attributes[:primary_email], response: response}
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: {action: :user_delete, attributes: {primary_email: "user@domain"}, response: "" } }
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
- {action: :user_delete, user: attributes[:primary_email], response: response}
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
- {action: :users_list, filters: filters, response: response}
20
+ {command: :users_list, filters: filters, response: response}
21
21
  end
22
22
 
23
23
  end
@@ -1,5 +1,5 @@
1
1
  module GoogleDirectory
2
2
  module Version
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  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.1.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: []