ruby_provisioning_api 0.0.1
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.
- data/.gitignore +28 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +30 -0
- data/Rakefile +2 -0
- data/lib/ruby_provisioning_api/config/google_apps.yml +3 -0
- data/lib/ruby_provisioning_api/configuration.rb +51 -0
- data/lib/ruby_provisioning_api/connection.rb +24 -0
- data/lib/ruby_provisioning_api/entity.rb +56 -0
- data/lib/ruby_provisioning_api/error.rb +24 -0
- data/lib/ruby_provisioning_api/group.rb +373 -0
- data/lib/ruby_provisioning_api/member.rb +116 -0
- data/lib/ruby_provisioning_api/owner.rb +117 -0
- data/lib/ruby_provisioning_api/ruby_provisioning_api.rb +21 -0
- data/lib/ruby_provisioning_api/user.rb +262 -0
- data/lib/ruby_provisioning_api/version.rb +3 -0
- data/lib/ruby_provisioning_api.rb +18 -0
- data/ruby_provisioning_api.gemspec +24 -0
- metadata +131 -0
@@ -0,0 +1,116 @@
|
|
1
|
+
module RubyProvisioningApi
|
2
|
+
|
3
|
+
module Member
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
base.extend(ClassMethods)
|
7
|
+
end
|
8
|
+
# Instance methods here
|
9
|
+
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
# Class methods here
|
13
|
+
end
|
14
|
+
# def self.find(member_id)
|
15
|
+
# super(member_id)
|
16
|
+
# end
|
17
|
+
|
18
|
+
# Retrieve user members for a group
|
19
|
+
# @note This method executes a <b>GET</b> request to <i>apps-apis.google.com/a/feeds/group/2.0/domain/groupId/member[?[start=]&[includeSuspendedUsers=true|false]]</i>
|
20
|
+
#
|
21
|
+
# @example Retrieve all user members for the group "foo"
|
22
|
+
# RubyProvisioningApi::Group.find("foo").user_members # => [Array<User>]
|
23
|
+
#
|
24
|
+
# @see https://developers.google.com/google-apps/provisioning/#retrieving_all_members_of_a_group
|
25
|
+
# @return [Array<User>] all user members for a group
|
26
|
+
#
|
27
|
+
def user_members
|
28
|
+
members("User")
|
29
|
+
end
|
30
|
+
|
31
|
+
# Retrieve group members for a group
|
32
|
+
# @note This method executes a <b>GET</b> request to <i>apps-apis.google.com/a/feeds/group/2.0/domain/groupId/member[?[start=]&[includeSuspendedUsers=true|false]]</i>
|
33
|
+
#
|
34
|
+
# @example Retrieve all group members for the group "foo"
|
35
|
+
# RubyProvisioningApi::Group.find("foo").group_members # => [Array<User>]
|
36
|
+
#
|
37
|
+
# @see https://developers.google.com/google-apps/provisioning/#retrieving_all_members_of_a_group
|
38
|
+
# @return [Array<User>] all group members for a group
|
39
|
+
#
|
40
|
+
def group_members
|
41
|
+
members("Group")
|
42
|
+
end
|
43
|
+
|
44
|
+
# Retrieve user member ids
|
45
|
+
# @note This method executes a <b>GET</b> request to <i>apps-apis.google.com/a/feeds/group/2.0/domain/groupId/member[?[start=]&[includeSuspendedUsers=true|false]]</i>
|
46
|
+
#
|
47
|
+
# @example Retrieve all user member ids for group "foo"
|
48
|
+
# RubyProvisioningApi::Group.find("foo").user_member_ids # => [Array<String>]
|
49
|
+
#
|
50
|
+
# @see https://developers.google.com/google-apps/provisioning/#retrieving_all_members_of_a_group
|
51
|
+
# @return [Array<String>] all user member ids
|
52
|
+
#
|
53
|
+
def user_member_ids
|
54
|
+
member_ids("User")
|
55
|
+
end
|
56
|
+
|
57
|
+
# Retrieve group member ids
|
58
|
+
# @note This method executes a <b>GET</b> request to <i>apps-apis.google.com/a/feeds/group/2.0/domain/groupId/member[?[start=]&[includeSuspendedUsers=true|false]]</i>
|
59
|
+
#
|
60
|
+
# @example Retrieve all user member ids for group "foo"
|
61
|
+
# RubyProvisioningApi::Group.find("foo").group_member_ids # => [Array<String>]
|
62
|
+
#
|
63
|
+
# @see https://developers.google.com/google-apps/provisioning/#retrieving_all_members_of_a_group
|
64
|
+
# @return [Array<String>] all group member ids
|
65
|
+
#
|
66
|
+
def group_member_ids
|
67
|
+
member_ids("Group")
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
# Retrieve member ids for an entity [Group or User]
|
73
|
+
# @note This method executes a <b>GET</b> request to <i>apps-apis.google.com/a/feeds/group/2.0/domain/groupId/member[?[start=]&[includeSuspendedUsers=true|false]]</i>
|
74
|
+
#
|
75
|
+
# @example Retrieve all group member ids for the group "foo"
|
76
|
+
# RubyProvisioningApi::Group.find("foo").member_ids("Group") # => [Array<String>]
|
77
|
+
#
|
78
|
+
# @see https://developers.google.com/google-apps/provisioning/#retrieving_all_members_of_a_group
|
79
|
+
# @return [Array<String>] all entity member ids for an entity [Group or User]
|
80
|
+
# @param [String] entity Entity name
|
81
|
+
#
|
82
|
+
def member_ids(entity)
|
83
|
+
params = self.class.prepare_params_for(:members, "groupId" => group_id)
|
84
|
+
response = self.class.perform(params)
|
85
|
+
self.class.check_response(response)
|
86
|
+
# Parse the response
|
87
|
+
xml = Nokogiri::XML(response.body)
|
88
|
+
# Prepare a User array
|
89
|
+
entity_ids = []
|
90
|
+
xml.children.css("entry").each do |entry|
|
91
|
+
# If the member is a user
|
92
|
+
if entry.css("apps|property[name]")[0].attributes["value"].value.eql?(entity)
|
93
|
+
# Fill the array with the username
|
94
|
+
entity_ids << entry.css("apps|property[name]")[1].attributes["value"].value.split("@")[0]
|
95
|
+
end
|
96
|
+
end
|
97
|
+
# Return the array of users ids (members)
|
98
|
+
entity_ids
|
99
|
+
end
|
100
|
+
|
101
|
+
# Retrieve entity members for a group
|
102
|
+
# @note This method executes a <b>GET</b> request to <i>apps-apis.google.com/a/feeds/group/2.0/domain/groupId/member[?[start=]&[includeSuspendedUsers=true|false]]</i>
|
103
|
+
#
|
104
|
+
# @example Retrieve all group members for the group "foo"
|
105
|
+
# RubyProvisioningApi::Group.find("foo").members("Group") # => [Array<User>]
|
106
|
+
#
|
107
|
+
# @see https://developers.google.com/google-apps/provisioning/#retrieving_all_members_of_a_group
|
108
|
+
# @return [Array<User>] all entity members for a group
|
109
|
+
# @param [String] entity Entity name
|
110
|
+
#
|
111
|
+
def members(entity)
|
112
|
+
member_ids(entity).map{ |member| "RubyProvisioningApi::#{entity}".constantize.send(:find, member) }
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
module RubyProvisioningApi
|
2
|
+
|
3
|
+
module Owner
|
4
|
+
|
5
|
+
|
6
|
+
def self.included(base)
|
7
|
+
base.extend(ClassMethods)
|
8
|
+
end
|
9
|
+
# Instance methods here
|
10
|
+
|
11
|
+
|
12
|
+
module ClassMethods
|
13
|
+
# Class methods here
|
14
|
+
end
|
15
|
+
# def self.find(member_id)
|
16
|
+
# super(member_id)
|
17
|
+
# end
|
18
|
+
|
19
|
+
# Retrieve user owners for a group
|
20
|
+
# @note This method executes a <b>GET</b> request to <i>apps-apis.google.com/a/feeds/group/2.0/domain/groupId/owner[?[start=]]</i>
|
21
|
+
#
|
22
|
+
# @example Retrieve all user owners for the group "foo"
|
23
|
+
# RubyProvisioningApi::Group.find("foo").user_owners # => [Array<User>]
|
24
|
+
#
|
25
|
+
# @see https://developers.google.com/google-apps/provisioning/#querying_for_all_owners_of_a_group
|
26
|
+
# @return [Array<User>] all user owners for a group
|
27
|
+
#
|
28
|
+
def user_owners
|
29
|
+
owners("User")
|
30
|
+
end
|
31
|
+
|
32
|
+
# Retrieve group owners for a group
|
33
|
+
# @note This method executes a <b>GET</b> request to <i>apps-apis.google.com/a/feeds/group/2.0/domain/groupId/owner[?[start=]]</i>
|
34
|
+
#
|
35
|
+
# @example Retrieve all group owners for the group "foo"
|
36
|
+
# RubyProvisioningApi::Group.find("foo").group_owners # => [Array<User>]
|
37
|
+
#
|
38
|
+
# @see https://developers.google.com/google-apps/provisioning/#querying_for_all_owners_of_a_group
|
39
|
+
# @return [Array<User>] all group owners for a group
|
40
|
+
#
|
41
|
+
def group_owners
|
42
|
+
owners("Group")
|
43
|
+
end
|
44
|
+
|
45
|
+
# Retrieve user owner ids
|
46
|
+
# @note This method executes a <b>GET</b> request to <i>apps-apis.google.com/a/feeds/group/2.0/domain/groupId/owner[?[start=]]</i>
|
47
|
+
#
|
48
|
+
# @example Retrieve all user owner ids for group "foo"
|
49
|
+
# RubyProvisioningApi::Group.find("foo").user_owner_ids # => [Array<String>]
|
50
|
+
#
|
51
|
+
# @see https://developers.google.com/google-apps/provisioning/#querying_for_all_owners_of_a_group
|
52
|
+
# @return [Array<String>] all user owner ids
|
53
|
+
#
|
54
|
+
def user_owner_ids
|
55
|
+
owner_ids("User")
|
56
|
+
end
|
57
|
+
|
58
|
+
# Retrieve group owner ids
|
59
|
+
# @note This method executes a <b>GET</b> request to <i>apps-apis.google.com/a/feeds/group/2.0/domain/groupId/owner[?[start=]]</i>
|
60
|
+
#
|
61
|
+
# @example Retrieve all user owner ids for group "foo"
|
62
|
+
# RubyProvisioningApi::Group.find("foo").group_member_ids # => [Array<String>]
|
63
|
+
#
|
64
|
+
# @see https://developers.google.com/google-apps/provisioning/#querying_for_all_owners_of_a_group
|
65
|
+
# @return [Array<String>] all group owner ids
|
66
|
+
#
|
67
|
+
def group_owner_ids
|
68
|
+
owner_ids("Group")
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
# Retrieve entity owners for a group
|
74
|
+
# @note This method executes a <b>GET</b> request to <i>apps-apis.google.com/a/feeds/group/2.0/domain/groupId/owner[?[start=]]</i>
|
75
|
+
#
|
76
|
+
# @example Retrieve all group owners for the group "foo"
|
77
|
+
# RubyProvisioningApi::Group.find("foo").owners("Group") # => [Array<User>]
|
78
|
+
#
|
79
|
+
# @see https://developers.google.com/google-apps/provisioning/#querying_for_all_owners_of_a_group
|
80
|
+
# @return [Array<User>] all entity owners for a group
|
81
|
+
# @param [String] entity Entity name
|
82
|
+
#
|
83
|
+
def owners(entity)
|
84
|
+
owners_ids(entity).map{ |owner| "RubyProvisioningApi::#{entity}".constantize.send(:find, owner) }
|
85
|
+
end
|
86
|
+
|
87
|
+
# Retrieve owner ids for an entity [Group or User]
|
88
|
+
# @note This method executes a <b>GET</b> request to <i>apps-apis.google.com/a/feeds/group/2.0/domain/groupId/owner[?[start=]]</i>
|
89
|
+
#
|
90
|
+
# @example Retrieve all group owner ids for the group "foo"
|
91
|
+
# RubyProvisioningApi::Group.find("foo").owner_ids("Group") # => [Array<String>]
|
92
|
+
#
|
93
|
+
# @see https://developers.google.com/google-apps/provisioning/#querying_for_all_owners_of_a_group
|
94
|
+
# @return [Array<String>] all entity owner ids for an entity [Group or User]
|
95
|
+
# @param [String] entity Entity name
|
96
|
+
#
|
97
|
+
def owner_ids
|
98
|
+
params = self.class.prepare_params_for(:owners, "groupId" => group_id)
|
99
|
+
response = self.class.perform(params)
|
100
|
+
self.class.check_response(response)
|
101
|
+
# Parse the response
|
102
|
+
xml = Nokogiri::XML(response.body)
|
103
|
+
# Prepare a User array
|
104
|
+
entity_ids = []
|
105
|
+
xml.children.css("entry").each do |entry|
|
106
|
+
# If the member is a user
|
107
|
+
if entry.css("apps|property[name]")[1].attributes["value"].value.eql?(entity)
|
108
|
+
# Fill the array with the username
|
109
|
+
entity_ids << entry.css("apps|property[name]")[0].attributes["value"].value.split("@")[0]
|
110
|
+
end
|
111
|
+
end
|
112
|
+
# Return the array of users ids (members)
|
113
|
+
entity_ids
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module RubyProvisioningApi
|
2
|
+
class << self
|
3
|
+
|
4
|
+
attr_writer :configuration
|
5
|
+
attr_reader :connection
|
6
|
+
|
7
|
+
# Adds configuration ability to the gem
|
8
|
+
def configuration
|
9
|
+
@configuration ||= RubyProvisioningApi::Configuration.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def configure
|
13
|
+
yield(configuration)
|
14
|
+
end
|
15
|
+
|
16
|
+
def connection
|
17
|
+
@connection ||= RubyProvisioningApi::Connection.new
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,262 @@
|
|
1
|
+
module RubyProvisioningApi
|
2
|
+
|
3
|
+
# @attr [String] user_name User's username
|
4
|
+
# @attr [String] given_name User's first name
|
5
|
+
# @attr [String] family_name User's last name
|
6
|
+
# @attr [Boolean] suspended User's state (suspended if true, active if false)
|
7
|
+
# @attr [String] quota User's disk space quota
|
8
|
+
#
|
9
|
+
class User
|
10
|
+
extend Entity
|
11
|
+
extend Member
|
12
|
+
extend Owner
|
13
|
+
|
14
|
+
include ActiveModel::Validations
|
15
|
+
include ActiveModel::Dirty
|
16
|
+
|
17
|
+
attr_accessor :user_name, :family_name, :given_name, :suspended, :quota
|
18
|
+
alias_method :suspended?, :suspended
|
19
|
+
define_attribute_methods [:user_name]
|
20
|
+
validates :user_name, :family_name, :given_name, :presence => true
|
21
|
+
|
22
|
+
# @param [Hash] params the options to create a User with.
|
23
|
+
# @option params [String] :user_name User identification
|
24
|
+
# @option params [String] :given_name User's first name
|
25
|
+
# @option params [String] :family_name User's last name
|
26
|
+
# @option params [String] :quota User's disk space quota (optional, default is 1024)
|
27
|
+
# @option params [Boolean] :suspended true if user is suspended, false otherwise (optional, default is false)
|
28
|
+
#
|
29
|
+
def initialize(params = {})
|
30
|
+
params.each do |name, value|
|
31
|
+
send("#{name}=", value)
|
32
|
+
end
|
33
|
+
self.quota = "1024" if quota.nil?
|
34
|
+
self.suspended = false if suspended.nil?
|
35
|
+
end
|
36
|
+
|
37
|
+
# Retrieve all users in the domain
|
38
|
+
# @note This method executes a <b>GET</b> request to <i>apps-apis.google.com/a/feeds/domain/user/2.0</i>
|
39
|
+
#
|
40
|
+
# @example Retrieve all users in the current domain
|
41
|
+
# RubyProvisioningApi::User.all # => [Array<User>]
|
42
|
+
#
|
43
|
+
# @see https://developers.google.com/google-apps/provisioning/#retrieving_all_users_in_a_domain
|
44
|
+
# @return [Array<User>] all users in the domain
|
45
|
+
#
|
46
|
+
def self.all
|
47
|
+
users = []
|
48
|
+
response = perform(RubyProvisioningApi.configuration.user_actions[:retrieve_all])
|
49
|
+
check_response(response)
|
50
|
+
doc = Nokogiri::XML(response.body)
|
51
|
+
doc.css("entry").each do |user_entry|
|
52
|
+
users << extract_user(user_entry)
|
53
|
+
end
|
54
|
+
users
|
55
|
+
end
|
56
|
+
|
57
|
+
# Retrieve a user account
|
58
|
+
# @note This method executes a <b>GET</b> request to <i>https://apps-apis.google.com/a/feeds/domain/user/2.0/userName</i>
|
59
|
+
#
|
60
|
+
# @example Retrieve the user account for "test"
|
61
|
+
# user = RubyProvisioningApi::User.find("test") # => [User]
|
62
|
+
#
|
63
|
+
# @see https://developers.google.com/google-apps/provisioning/#retrieving_user_accounts
|
64
|
+
# @param [String] user_name
|
65
|
+
# @return [User]
|
66
|
+
# @raise [Error] if user does not exist
|
67
|
+
#
|
68
|
+
def self.find(user_name)
|
69
|
+
params = prepare_params_for(:retrieve, "userName" => userName)
|
70
|
+
response = perform(params)
|
71
|
+
check_response(response)
|
72
|
+
doc = Nokogiri::XML(response.body)
|
73
|
+
extract_user(doc)
|
74
|
+
end
|
75
|
+
|
76
|
+
# Save a user account. If the user account exists it will be updated, if not, a new user account will be created
|
77
|
+
#
|
78
|
+
# @note This method executes a <b>POST</b> request to <i>apps-apis.google.com/a/feeds/domain/user/2.0</i> for the create action
|
79
|
+
# @note This method executes a <b>PUT</b> request to <i>apps-apis.google.com/a/feeds/domain/user/2.0/userName</i> for the update action
|
80
|
+
#
|
81
|
+
# @example Create a user account in multiple steps
|
82
|
+
# user = RubyProvisioningApi::User.new
|
83
|
+
# user.user_name = "test" # => "test"
|
84
|
+
# user.given_name = "foo" # => "foo"
|
85
|
+
# user.family_name = "bar" # => "bar"
|
86
|
+
# user.save # => true
|
87
|
+
#
|
88
|
+
# @example Create a user account in a unique step
|
89
|
+
# user = RubyProvisioningApi::User.new(:user_name => "test",
|
90
|
+
# :given_name => "foo",
|
91
|
+
# :family_name => "bar",
|
92
|
+
# :quota => "2000") # => [User]
|
93
|
+
# user.save # => true
|
94
|
+
#
|
95
|
+
# @example Update a user account
|
96
|
+
# user = RubyProvisioningApi::User.find("test") # => [User]
|
97
|
+
# user.given_name = "foo2" # => "foo2"
|
98
|
+
# user.save # => true
|
99
|
+
#
|
100
|
+
# @see https://developers.google.com/google-apps/provisioning/#creating_a_user_account
|
101
|
+
# @see https://developers.google.com/google-apps/provisioning/#updating_a_user_account
|
102
|
+
# @param [Hash] save_options
|
103
|
+
# @option save_options [Boolean] :validate skip validations before save if false, validate otherwise (defaults to true)
|
104
|
+
# @return [Boolean] true if saved, false if not valid or not saved
|
105
|
+
# @raise [Error] if the user already exists (user_name must be unique)
|
106
|
+
#
|
107
|
+
def save(save_options = {:validate => true})
|
108
|
+
if save_options[:validate]
|
109
|
+
return false unless valid?
|
110
|
+
end
|
111
|
+
builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
|
112
|
+
xml.send(:'atom:entry', 'xmlns:atom' => 'http://www.w3.org/2005/Atom', 'xmlns:apps' => 'http://schemas.google.com/apps/2006') {
|
113
|
+
xml.send(:'atom:category', 'scheme' => 'http://schemas.google.com/g/2005#kind', 'term' => 'http://schemas.google.com/apps/2006#user')
|
114
|
+
xml.send(:'apps:login', 'userName' => user_name, 'password' => '51eea05d46317fadd5cad6787a8f562be90b4446', 'suspended' => suspended)
|
115
|
+
xml.send(:'apps:quota', 'limit' => quota)
|
116
|
+
xml.send(:'apps:name', 'familyName' => family_name, 'givenName' => given_name)
|
117
|
+
}
|
118
|
+
end
|
119
|
+
if User.present?(user_name_was)
|
120
|
+
# UPDATING an old record
|
121
|
+
params = self.class.prepare_params_for(:update, "userName" => user_name_was)
|
122
|
+
response = self.class.perform(params, builder.to_xml)
|
123
|
+
else
|
124
|
+
# SAVING a new record
|
125
|
+
response = self.class.perform(RubyProvisioningApi.configuration.user_actions[:create], builder.to_xml)
|
126
|
+
end
|
127
|
+
User.check_response(response)
|
128
|
+
end
|
129
|
+
|
130
|
+
# Initialize and save a user.
|
131
|
+
# @param [Hash] params the options to create a User with
|
132
|
+
# @option params [String] :user_name User identification
|
133
|
+
# @option params [String] :given_name User's first name
|
134
|
+
# @option params [String] :family_name User's last name
|
135
|
+
# @option params [String] :quota User's disk space quota (optional, default is 1024)
|
136
|
+
# @option params [Boolean] :suspended true if user is suspended, false otherwise (optional, default is false)
|
137
|
+
# @note This method executes a <b>POST</b> request to <i>apps-apis.google.com/a/feeds/domain/user/2.0</i>
|
138
|
+
#
|
139
|
+
# @example Create the user "test"
|
140
|
+
# user = RubyProvisioningApi::User.create(:user_name => "test",
|
141
|
+
# :given_name => "foo",
|
142
|
+
# :family_name => "bar",
|
143
|
+
# :quota => "2000") # => true
|
144
|
+
#
|
145
|
+
# @see https://developers.google.com/google-apps/provisioning/#creating_a_user_account
|
146
|
+
# @return [Boolean] true if created, false if not valid or not created
|
147
|
+
# @raise [Error] if user already exists (user_name must be unique)
|
148
|
+
#
|
149
|
+
def self.create(params = {})
|
150
|
+
user = User.new(params)
|
151
|
+
user.save
|
152
|
+
end
|
153
|
+
|
154
|
+
# Update user attributes (except suspend) and save
|
155
|
+
#
|
156
|
+
# @param [Hash] params the options to update the User with
|
157
|
+
# @option params [String] :user_name User identification
|
158
|
+
# @option params [String] :given_name User's first name
|
159
|
+
# @option params [String] :family_name User's last name
|
160
|
+
# @option params [String] :quota User's disk space quota
|
161
|
+
#
|
162
|
+
# @note This method executes a <b>PUT</b> request to <i>apps-apis.google.com/a/feeds/domain/user/2.0/userName</i> for the update action
|
163
|
+
# @note With {User#update_attributes update_attributes} it's not possible to suspend or restore a user account. For these actions take a look
|
164
|
+
# at the {User#suspend suspend} and {User#restore restore} methods.
|
165
|
+
#
|
166
|
+
# @example Change the family name and the given_name of a user
|
167
|
+
# user = RubyProvisioningApi::User.find("foo") # => [User]
|
168
|
+
# user.update_attributes(:family_name => "smith", :given_name => "john") # => true
|
169
|
+
#
|
170
|
+
# @see https://developers.google.com/google-apps/provisioning/#updating_a_user_account
|
171
|
+
# @return [Boolean] true if updated, false if not valid or not updated
|
172
|
+
# @raise [Error] if user already exists (user_name must be unique)
|
173
|
+
#
|
174
|
+
def update_attributes(params)
|
175
|
+
if params.has_key? :user_name and params[:user_name] != self.user_name
|
176
|
+
user_name_will_change!
|
177
|
+
self.user_name = params[:user_name]
|
178
|
+
end
|
179
|
+
self.family_name = params[:family_name] if params.has_key? :family_name
|
180
|
+
self.given_name = params[:given_name] if params.has_key? :given_name
|
181
|
+
self.quota = params[:quota] if params.has_key? :quota
|
182
|
+
save
|
183
|
+
end
|
184
|
+
|
185
|
+
# Suspend a user account
|
186
|
+
# @note This method executes a <b>PUT</b> request to <i>apps-apis.google.com/a/feeds/domain/user/2.0/userName</i> for the update action
|
187
|
+
#
|
188
|
+
# @example Suspend the user account of the user "foo"
|
189
|
+
# user = RubyProvisioningApi::User.find("foo") # => [User]
|
190
|
+
# user.suspend # => true
|
191
|
+
#
|
192
|
+
# @see https://developers.google.com/google-apps/provisioning/#suspending_a_user_account
|
193
|
+
# @return [Boolean] true if the operation succeeded, false otherwise
|
194
|
+
#
|
195
|
+
def suspend
|
196
|
+
self.suspended = true
|
197
|
+
save(:validate => false)
|
198
|
+
end
|
199
|
+
|
200
|
+
# Restore a user account
|
201
|
+
# @note This method executes a <b>PUT</b> request to <i>apps-apis.google.com/a/feeds/domain/user/2.0/userName</i> for the update action
|
202
|
+
#
|
203
|
+
# @example Restore the user account of the user "foo"
|
204
|
+
# user = RubyProvisioningApi::User.find("foo") # => [User]
|
205
|
+
# user.restore # => true
|
206
|
+
#
|
207
|
+
# @see https://developers.google.com/google-apps/provisioning/#restoring_a_user_account
|
208
|
+
# @return [Boolean] true if the operation succeeded, false otherwise
|
209
|
+
#
|
210
|
+
def restore
|
211
|
+
self.suspended = false
|
212
|
+
save(:validate => false)
|
213
|
+
end
|
214
|
+
|
215
|
+
#Delete user DELETE https://apps-apis.google.com/a/feeds/domain/user/2.0/userName
|
216
|
+
def delete
|
217
|
+
params = self.class.prepare_params_for(:delete, "userName" => user_name)
|
218
|
+
response = self.class.perform(params)
|
219
|
+
end
|
220
|
+
|
221
|
+
# Returns all the groups which the user is subscribed to
|
222
|
+
# TODO: move this inside member
|
223
|
+
def groups
|
224
|
+
Group.groups(user_name)
|
225
|
+
end
|
226
|
+
|
227
|
+
# Check if the user is a member of the given group
|
228
|
+
# @note This method executes a <b>GET</b> request to <i>apps-apis.google.com/a/feeds/group/2.0/domain/groupId/member/memberId</i>
|
229
|
+
#
|
230
|
+
# @example Find a user and check if is member of the group 'test'
|
231
|
+
# user = RubyProvisioningApi::User.find("username")
|
232
|
+
# user.is_member_of? "test" # => true
|
233
|
+
#
|
234
|
+
# @see https://developers.google.com/google-apps/provisioning/#retrieving_all_members_of_a_group
|
235
|
+
# @return [Boolean] true if the user is member of the group, false otherwise
|
236
|
+
# @raise [Error] if group_id does not exist
|
237
|
+
#
|
238
|
+
def is_member_of?(group_id)
|
239
|
+
params = self.class.prepare_params_for(:group_id, {"groupId" => group_id, "memberId" => user_name} )
|
240
|
+
begin
|
241
|
+
self.class.check_response(self.class.perform(params))
|
242
|
+
rescue
|
243
|
+
Group.find(group_id)
|
244
|
+
false
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
private
|
249
|
+
|
250
|
+
def self.extract_user(doc)
|
251
|
+
u = new
|
252
|
+
u.user_name = doc.css("apps|login").first.attributes["userName"].value
|
253
|
+
u.suspended = doc.css("apps|login").first.attributes["suspended"].value
|
254
|
+
u.family_name = doc.css("apps|name").first.attributes["familyName"].value
|
255
|
+
u.given_name = doc.css("apps|name").first.attributes["givenName"].value
|
256
|
+
u.quota = doc.css("apps|quota").first.attributes["limit"].value
|
257
|
+
u
|
258
|
+
end
|
259
|
+
|
260
|
+
end
|
261
|
+
|
262
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless ($:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__))))
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
require 'faraday'
|
5
|
+
require 'nokogiri'
|
6
|
+
require 'active_support/all'
|
7
|
+
require 'active_model'
|
8
|
+
|
9
|
+
require 'ruby_provisioning_api/ruby_provisioning_api'
|
10
|
+
require 'ruby_provisioning_api/version'
|
11
|
+
require 'ruby_provisioning_api/connection'
|
12
|
+
require 'ruby_provisioning_api/entity'
|
13
|
+
require 'ruby_provisioning_api/configuration'
|
14
|
+
require 'ruby_provisioning_api/member'
|
15
|
+
require 'ruby_provisioning_api/owner'
|
16
|
+
require 'ruby_provisioning_api/group'
|
17
|
+
require 'ruby_provisioning_api/user'
|
18
|
+
require 'ruby_provisioning_api/error'
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ruby_provisioning_api/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.authors = ["Davide Targa", "Damiano Braga"]
|
8
|
+
gem.email = ["davide.targa@gmail.com", "damiano.braga@gmail.com"]
|
9
|
+
gem.description = %q{a ruby wrapper for google provisioning api}
|
10
|
+
gem.summary = %q{a ruby wrapper for google provisioning api}
|
11
|
+
gem.homepage = "https://github.com/digitalprog/ruby_provisioning_api"
|
12
|
+
|
13
|
+
gem.files = `git ls-files`.split($\)
|
14
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
15
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
16
|
+
gem.name = "ruby_provisioning_api"
|
17
|
+
gem.require_paths = ["lib"]
|
18
|
+
gem.version = RubyProvisioningApi::VERSION
|
19
|
+
gem.add_dependency 'faraday'
|
20
|
+
gem.add_dependency 'nokogiri'
|
21
|
+
gem.add_dependency 'activesupport'
|
22
|
+
gem.add_dependency 'activemodel'
|
23
|
+
|
24
|
+
end
|