Class: GData::Apps::Provisioning

Inherits:
Object
  • Object
show all
Defined in:
lib/gdata/apps/provisioning.rb

Overview

Administrative object for accessing your domain

Examples

adminuser = "[email protected]"
password  = "PaSsWo4d!"
gapp = GApps.new('[email protected]','PaSsWoRd')
myapps = Provisioning.new(gapp)
(see examples in  ProvisioningApi.new documentation for handling proxies)

new_user = myapps.create_user("jsmith", "john", "smith", "secret", nil, "2048")
puts new_user.family_name
puts new_user.given_name

Want to update a user ?

user = myapps.retrieve_user('jsmith')
user_updated = myapps.update_user(user.username, user.given_name, user.family_name, nil, nil, "true")

Want to add an alias or nickname ?

new_nickname = myapps.create_nickname("jsmith", "john.smith")

Want to handle errors ?

begin
        user = myapps.retrieve_user('noone')
        puts "givenName : "+user.given_name, "familyName : "+user.family_name, "username : "+user.username"
        puts "admin ? : "+user.admin
rescue GDataError => e
        puts "errorcode = " +e.code, "input : "+e.input, "reason : "+e.reason
end

Group ?

new_list = myapps.create_group("sale-dep")
new_address = myapps.add_to_group("sale-dep", "[email protected]")

Constant Summary collapse

@@google_host =
'apps-apis.google.com'

Instance Method Summary collapse

Constructor Details

#initialize(apps) ⇒ Provisioning

Creates a new Provisioning object

apps:  Google Apps Object (GData::GApps)

Examples :

standard : no proxy
gapp = GApps.new('[email protected]','PaSsWoRd')
myapps = Provisioning.new(gapp)
proxy :
gapp = GApps.new('[email protected]','PaSsWoRd','domain.proxy.com',8080)
myapps = Provisioning.new(gapp)
authenticated proxy :
gapp = GApps.new('[email protected]','PaSsWoRd','domain.proxy.com',8080,'foo','bAr')
myapps = ProvisioningApi.new(gapp)


66
67
68
69
# File 'lib/gdata/apps/provisioning.rb', line 66

def initialize(apps)
  @apps = apps
  setup_actions()
end

Instance Method Details

#add_member_to_groupObject

Raises:

  • (NotImplementedError)


247
248
249
# File 'lib/gdata/apps/provisioning.rb', line 247

def add_member_to_group
  raise NotImplementedError
end

#add_owner_to_groupObject

Raises:

  • (NotImplementedError)


259
260
261
# File 'lib/gdata/apps/provisioning.rb', line 259

def add_owner_to_group
  raise NotImplementedError
end

#create_groupObject

Raises:

  • (NotImplementedError)


231
232
233
# File 'lib/gdata/apps/provisioning.rb', line 231

def create_group
  raise NotImplementedError
end

#create_nickname(username, nickname) ⇒ Object

Creates a nickname for the username in your domain and returns a NicknameEntry instance

gapp = GApps.new('[email protected]','PaSsWoRd')
myapps = ProvisioningApi.new(gapp)
mynewnick = myapps.create_nickname('jsmith', 'john.smith')


168
169
170
171
172
173
174
# File 'lib/gdata/apps/provisioning.rb', line 168

def create_nickname(username, nickname)
  msg = ProvisioningMessage.new
  msg.(username)
  msg.about_nickname(nickname)
  response  = @apps.request(:nickname_create,nil, msg.to_s)
  #nickname_entry = NicknameEntry.new(response.elements["entry"])
end

#create_user(username, given_name, family_name, password, passwd_hash_function = nil, quota = nil) ⇒ Object

Creates an account in your domain, returns a UserEntry instance

params :
                username, given_name, family_name and password are required
                passwd_hash_function (optional) : nil (default) or "SHA-1"
                quota (optional) : nil (default) or integer for limit in MB
ex :
                gapp = GApps.new('[email protected]','PaSsWoRd')
                myapps = ProvisioningApi.new(gapp)
                user = myapps.create('jsmith', 'John', 'Smith', 'p455wD')

By default, a new user must change his password at first login. Please use update_user if you want to change this just after the creation.



82
83
84
85
86
87
88
89
# File 'lib/gdata/apps/provisioning.rb', line 82

def create_user(username, given_name, family_name, password, passwd_hash_function=nil, quota=nil)
  msg = ProvisioningMessage.new
  msg.(username,password,passwd_hash_function,"false","false", "true")
  msg.about_name(family_name, given_name)
  msg.about_quota(quota.to_s) if quota
  response  = @apps.request(:user_create,nil, msg.to_s)
  #user_entry = UserEntry.new(response.elements["entry"])
end

#delete_groupObject

Raises:

  • (NotImplementedError)


243
244
245
# File 'lib/gdata/apps/provisioning.rb', line 243

def delete_group
  raise NotImplementedError
end

#delete_nickname(nickname) ⇒ Object

Deletes the nickname in your domain

gapp = GApps.new('[email protected]','PaSsWoRd')
myapps = ProvisioningApi.new(gapp)
myapps.delete_nickname('john.smith')


215
216
217
# File 'lib/gdata/apps/provisioning.rb', line 215

def delete_nickname(nickname)
  response  = @apps.request(:nickname_delete,nickname)
end

#delete_user(username) ⇒ Object

Deletes an account in your domain

ex :
        gapp = GApps.new('[email protected]','PaSsWoRd')
        myapps = ProvisioningApi.new(gapp)
        myapps.delete('jsmith')


160
161
162
# File 'lib/gdata/apps/provisioning.rb', line 160

def delete_user(username)
  response  = @apps.request(:user_delete,username)
end

#remove_member_from_groupObject

Raises:

  • (NotImplementedError)


255
256
257
# File 'lib/gdata/apps/provisioning.rb', line 255

def remove_member_from_group
  raise NotImplementedError
end

#remove_owner_from_groupObject

Raises:

  • (NotImplementedError)


267
268
269
# File 'lib/gdata/apps/provisioning.rb', line 267

def remove_owner_from_group
  raise NotImplementedError
end

#retrieve_all_nicknamesObject

Returns a NicknameEntry array for the whole domain. May take a while depending on the number of users in your domain.

gapp = GApps.new('[email protected]','PaSsWoRd')
myapps = ProvisioningApi.new(gapp)
allnicks = myapps.retrieve_all_nicknames
allnicks.each {|nick| puts nick.nickname }


205
206
207
208
209
# File 'lib/gdata/apps/provisioning.rb', line 205

def retrieve_all_nicknames
  xml_response = @apps.request(:nickname_retrieve_all_in_domain, nil, @headers)
  nicknames_feed = Feed.new(xml_response.elements["feed"],  NicknameEntry)
  nicknames_feed = add_next_feeds(nicknames_feed, xml_response, NicknameEntry)
end

#retrieve_all_usersObject

Returns a UserEntry array populated with all the users in the domain. May take a while depending on the number of users in your domain.

ex :
                gapp = GApps.new('[email protected]','PaSsWoRd')
                myapps = ProvisioningApi.new(gapp)
                list= myapps.retrieve_all_users
                list.each{ |user| puts user.username}
                puts 'nb users : ',list.size


113
114
115
116
117
# File 'lib/gdata/apps/provisioning.rb', line 113

def retrieve_all_users
  response = @apps.request(:user_retrieve_all)
  user_feed = Feed.new(response.elements["feed"],  UserEntry)
  user_feed = add_next_feeds(user_feed, response, UserEntry)
end

#retrieve_groupObject

Raises:

  • (NotImplementedError)


239
240
241
# File 'lib/gdata/apps/provisioning.rb', line 239

def retrieve_group
  raise NotImplementedError
end

#retrieve_members_of_groupObject

Raises:

  • (NotImplementedError)


251
252
253
# File 'lib/gdata/apps/provisioning.rb', line 251

def retrieve_members_of_group
  raise NotImplementedError
end

#retrieve_nickname(nickname) ⇒ Object

Returns a NicknameEntry instance from a nickname

ex :
                gapp = GApps.new('[email protected]','PaSsWoRd')
                myapps = ProvisioningApi.new(gapp)
                nickname = myapps.retrieve_nickname('jsmith')
                puts "login : "+nickname.login


182
183
184
185
# File 'lib/gdata/apps/provisioning.rb', line 182

def retrieve_nickname(nickname)
  xml_response = @apps.request(:nickname_retrieve, nickname)
  nickname_entry = NicknameEntry.new(xml_response.elements["entry"])
end

#retrieve_nicknames(username) ⇒ Object

Returns a NicknameEntry array from a username

ex : lists jsmith's nicknames
        gapp = GApps.new('[email protected]','PaSsWoRd')
        myapps = ProvisioningApi.new(gapp)
        mynicks = myapps.retrieve('jsmith')
        mynicks.each {|nick| puts nick.nickname }


193
194
195
196
197
198
# File 'lib/gdata/apps/provisioning.rb', line 193

def retrieve_nicknames(username)
  xml_response = @apps.request(:nickname_retrieve_all_for_user, username, @headers)
  
  nicknames_feed = Feed.new(xml_response.elements["feed"],  NicknameEntry)
  nicknames_feed = add_next_feeds(nicknames_feed, xml_response, NicknameEntry)
end

#retrieve_owner_of_groupObject

Raises:

  • (NotImplementedError)


263
264
265
# File 'lib/gdata/apps/provisioning.rb', line 263

def retrieve_owner_of_group
  raise NotImplementedError
end

#retrieve_page_of_nicknames(start_nickname) ⇒ Object

Returns a NicknameEntry array populated with 100 nicknames, starting from a nickname

ex :
       gapp = GApps.new('[email protected]','PaSsWoRd')
       myapps = ProvisioningApi.new(gapp)
       list= myapps.retrieve_page_of_nicknames("joe")
       list.each{ |nick| puts nick.login}


225
226
227
228
229
# File 'lib/gdata/apps/provisioning.rb', line 225

def retrieve_page_of_nicknames(start_nickname)
  param='?startNickname='+start_nickname
  xml_response = @apps.request(:nickname_retrieve_all_in_domain, param, @headers)
  nicknames_feed = Feed.new(xml_response.elements["feed"],  NicknameEntry)
end

#retrieve_page_of_users(start_username) ⇒ Object

Returns a UserEntry array populated with 100 users, starting from a username

ex :
                gapp = GApps.new('[email protected]','PaSsWoRd')
                myapps = ProvisioningApi.new(gapp)
                list= myapps.retrieve_page_of_users("jsmtih")
                list.each{ |user| puts user.username}


125
126
127
128
129
# File 'lib/gdata/apps/provisioning.rb', line 125

def retrieve_page_of_users(start_username)
  param='?startUsername='+start_username
  response = @apps.request(:user_retrieve_all,param)
  user_feed = Feed.new(response.elements["feed"],  UserEntry)
end

#retrieve_user(username) ⇒ Object

Returns a UserEntry instance from a username

ex :
                gapp = GApps.new('[email protected]','PaSsWoRd')
                myapps = ProvisioningApi.new(gapp)
                user = myapps.retrieve_user('jsmith')
                puts "givenName : "+user.given_name
                puts "familyName : "+user.family_name


99
100
101
102
103
104
# File 'lib/gdata/apps/provisioning.rb', line 99

def retrieve_user(username)
  xml_response = @apps.request(:user_retrieve, username)
  if xml_response.respond_to? :elements
    user_entry = UserEntry.new(xml_response.elements["entry"])
  end
end

#update_groupObject

Raises:

  • (NotImplementedError)


235
236
237
# File 'lib/gdata/apps/provisioning.rb', line 235

def update_group
  raise NotImplementedError
end

#update_user(username, given_name, family_name, password = nil, passwd_hash_function = nil, admin = nil, suspended = nil, changepasswd = nil, quota = nil) ⇒ Object

Updates an account in your domain, returns a UserEntry instance

params :
                username is required and can't be updated.
                given_name and family_name are required, may be updated.
                if set to nil, every other parameter won't update the attribute.
                        passwd_hash_function :  string "SHA-1" or nil (default)
                        admin :  string "true" or string "false" or nil (no boolean : true or false).
                        suspended :  string "true" or string "false" or nil (no boolean : true or false)
                        change_passwd :  string "true" or string "false" or nil (no boolean : true or false)
                        quota : limit en MB, ex :  string "2048"
        ex :
                gapp = GApps.new('[email protected]','PaSsWoRd')
                myapps = ProvisioningApi.new(gapp)
                user = myapps.update('jsmith', 'John', 'Smith', nil, nil, "true", nil, "true", nil)
                puts user.admin         => "true"


146
147
148
149
150
151
152
153
# File 'lib/gdata/apps/provisioning.rb', line 146

def update_user(username, given_name, family_name, password=nil, passwd_hash_function=nil, admin=nil, suspended=nil, changepasswd=nil, quota=nil)
  msg = ProvisioningMessage.new
  msg.(username,password,passwd_hash_function,admin,suspended, changepasswd)
  msg.about_name(family_name, given_name)
  msg.about_quota(quota) if quota
  response  = @apps.request(:user_update,username, msg.to_s)
  #user_entry = UserEntry.new(response.elements["entry"])
end