Revision: 587
Author: perlstalker
Date: Sat Dec 12 22:21:21 2009
Log: - Add support for creating, updating, deleting and retrieving a group.
http://code.google.com/p/vuser/source/detail?r=587
Modified:
/VUser-Google-ProvisioningAPI/trunk/lib/VUser/Google/Groups/GroupEntry.pm
/VUser-Google-ProvisioningAPI/trunk/lib/VUser/Google/Groups/V2_0.pm
/VUser-Google-ProvisioningAPI/trunk/lib/VUser/Google/Provisioning/V2_0.pm
/VUser-Google-ProvisioningAPI/trunk/t/tests/Test/VUser/Google/Groups/V2_0.pm
=======================================
---
/VUser-Google-ProvisioningAPI/trunk/lib/VUser/Google/Groups/GroupEntry.pm
Wed Dec 2 21:35:45 2009
+++
/VUser-Google-ProvisioningAPI/trunk/lib/VUser/Google/Groups/GroupEntry.pm
Sat Dec 12 22:21:21 2009
@@ -6,10 +6,10 @@
use Moose;
-has 'GroupId' => (is => 'rw', isa => 'Str');
-has 'GroupName' => (is => 'rw', isa => 'Str');
-has 'Description' => (is => 'rw', isa => 'Str');
-has 'emailPermission' => (is => 'rw', isa => 'Str');
+has 'GroupId' => (is => 'rw', isa => 'Str | Undef');
+has 'GroupName' => (is => 'rw', isa => 'Str | Undef');
+has 'Description' => (is => 'rw', isa => 'Str | Undef');
+has 'EmailPermission' => (is => 'rw', isa => 'Str | Undef');
sub as_hash {
my $self = shift;
=======================================
--- /VUser-Google-ProvisioningAPI/trunk/lib/VUser/Google/Groups/V2_0.pm Thu
Dec 3 22:36:05 2009
+++ /VUser-Google-ProvisioningAPI/trunk/lib/VUser/Google/Groups/V2_0.pm Sat
Dec 12 22:21:21 2009
@@ -12,6 +12,11 @@
has '+base_url' => (default
=> '
https://apps-apis.google.com/a/feeds/group/2.0/');
#### Methods ####
+# %options
+# groupId*
+# groupName*
+# description
+# emailPermission* (Owner | Member | Domain | Anyone)
sub CreateGroup {
my $self = shift;
my %options = ();
@@ -49,16 +54,88 @@
}
}
+# Cannot be used to rename the group
+# %options
+# groupId*
+# newGroupId --- no
+# groupName*
+# description
+# emailPermission*
sub UpdateGroup {
+ my $self = shift;
+ my %options = ();
+
+ if (ref $_[0]
+ and $_[0]->isa('VUser::Google::Groups::GroupEntry')) {
+ %options = $_[0]->as_hash;
+ }
+ else {
+ %options = @_;
+ }
+
+ my $url = $self->base_url.$self->google->domain."/$options{groupId}";
+
+ my $post = '<?xml version="1.0" encoding="UTF-8"?>
+<atom:entry xmlns:atom="
http://www.w3.org/2005/Atom"
xmlns:apps="
http://schemas.google.com/apps/2006"
xmlns:gd="
http://schemas.google.com/g/2005">';
+
+ if (0 and $options{newGroupId}) {
+ $post .= '<apps:property name="groupId" value="'
+ .$options{newGroupId}.'"/>';
+ }
+
+ if ($options{groupName}) {
+ $post .= '<apps:property name="groupName" value="'
+ .$options{groupName}.'"/>';
+ }
+
+ if ($options{description}) {
+ $post .= '<apps:property name="description" value="'
+ .$options{description}.'"/>';
+ };
+
+ if ($options{emailPermission}) {
+ $post .= '<apps:property name="emailPermission" value="'
+ .$options{emailPermission}.'"/>';
+ };
+
+ $post .= '</atom:entry>';
+
+
+ if ($self->google->Request('PUT', $url, $post)) {
+ my $entry = $self->_build_group_entry($self->google->result);
+ return $entry;
+ }
+ else {
+ die "Unable to create group: ".$self->google->result->{'reason'}."\n";
+ }
}
sub RetrieveGroup {
+ my $self = shift;
+ my $groupid = shift;
+
+ my $url = $self->base_url.$self->google->domain."/$groupid";
+
+ if ($self->google->Request('GET', $url)) {
+ return $self->_build_group_entry($self->google->result);
+ }
+ else {
+ if ($self->google->result->{'reason'} =~ /EntityDoesNotExist/) {
+ return undef;
+ }
+ else {
+ die "Error retrieving group: ".$self->google->result->{'reason'}."\n";
+ }
+ }
}
sub RetrieveAllGroupsInDomain {
+ my $self = shift;
}
sub RetrieveAllGroupsForMember {
+ my $self = shift;
+ my $member = shift;
}
sub DeleteGroup {
@@ -73,7 +150,7 @@
return 1;
}
else {
- die "Cannot delete group: ".$self->google->result->{'reason'};
+ die "Cannot delete group ($groupId): ".$self->google->result->{'reason'};
}
}
@@ -104,20 +181,10 @@
my $entry = VUser::Google::Groups::GroupEntry->new();
- foreach my $property (@{ $xml->{'apps:property'} }) {
- if ($property->{'name'} eq 'groupId') {
- $entry->GroupId($property->{'value'});
- }
- elsif ($property->{'name'} eq 'groupName') {
- $entry->GroupName($property->{'value'});
- }
- elsif ($property->{'name'} eq 'description') {
- $entry->Description($property->{'value'});
- }
- elsif ($property->{'name'} eq 'emailPermission') {
- $entry->EmailPermission($property->{'value'});
- }
- }
+ $entry->GroupId($xml->{'apps:property'}{'groupId'}{'value'});
+ $entry->GroupName($xml->{'apps:property'}{'groupName'}{'value'});
+ $entry->Description($xml->{'apps:property'}{'description'}{'value'});
+
$entry->EmailPermission($xml->{'apps:property'}{'emailPermission'}{'value'});
return $entry;
}
=======================================
---
/VUser-Google-ProvisioningAPI/trunk/lib/VUser/Google/Provisioning/V2_0.pm
Wed Dec 2 20:57:26 2009
+++
/VUser-Google-ProvisioningAPI/trunk/lib/VUser/Google/Provisioning/V2_0.pm
Sat Dec 12 22:21:21 2009
@@ -109,7 +109,7 @@
return $self->_build_user_entry($self->google->result);
}
else {
- if ($self->google->result->{'reason'} =~ 'EntityDoesNotExist') {
+ if ($self->google->result->{'reason'} =~ /EntityDoesNotExist/) {
return undef;
}
else {
=======================================
---
/VUser-Google-ProvisioningAPI/trunk/t/tests/Test/VUser/Google/Groups/V2_0.pm
Thu Dec 3 22:36:05 2009
+++
/VUser-Google-ProvisioningAPI/trunk/t/tests/Test/VUser/Google/Groups/V2_0.pm
Sat Dec 12 22:21:21 2009
@@ -5,7 +5,7 @@
use Test::Most;
use base 'Test::VUser::Google::Groups';
-sub CreateGroup : Tests(4) {
+sub CreateGroup : Tests(8) {
my $test = shift;
my $class = $test->class;
@@ -24,10 +24,107 @@
isa_ok $entry, 'VUser::Google::Groups::GroupEntry',
'... and the create succeeded';
+ is $entry->GroupId, $group,
+ '... and group id matches';
+
+ is $entry->GroupName, "test group $group",
+ '... and group name matches';
+
+ is $entry->Description, 'test group descr',
+ '... and description matches';
+
+ is $entry->EmailPermission, 'Domain',
+ '... and email permission matches';
+
## Clean up
can_ok $api, 'DeleteGroup';
ok $api->DeleteGroup($group),
'... and delete suceeded';
}
+
+sub RetrieveUser : Tests(6) {
+ my $test = shift;
+ my $class = $test->class;
+
+ my $api = $class->new(google => $test->create_google);
+ can_ok $api, 'UpdateGroup';
+
+ my $group = $test->get_test_group;
+
+ my $entry = $api->CreateGroup(
+ groupId => $group,
+ groupName => "test group $group",
+ description => 'test group descr',
+ emailPermission => 'Domain',
+ );
+
+ my $new_entry = $api->RetrieveGroup($group);
+
+ is $new_entry->GroupId, $group.'@'.$api->google->domain,
+ '... and group id matches';
+
+ is $new_entry->GroupName, "test group $group",
+ '... and group name matches';
+
+ is $new_entry->Description, 'test group descr',
+ '... and description matches';
+
+ is $new_entry->EmailPermission, 'Domain',
+ '... and email permission matches';
+
+ ok $api->DeleteGroup($group),
+ '... and delete suceeded';
+}
+
+sub UpdateGroup : Tests(7) {
+ my $test = shift;
+ my $class = $test->class;
+
+ my $api = $class->new(google => $test->create_google);
+ can_ok $api, 'UpdateGroup';
+
+ my $group = $test->get_test_group;
+
+ my $entry = $api->CreateGroup(
+ groupId => $group,
+ groupName => "test group $group",
+ description => 'test group descr',
+ emailPermission => 'Domain',
+ );
+
+ my $new_entry = $api->UpdateGroup(
+ groupId => $group,
+ #newGroupId => $group.'.new',
+ groupName => "test group $
group.new",
+ description => 'test group descr new',
+ emailPermission => 'Member',
+
+ );
+
+
+ # Can't rename groups
+ #$entry = $api->RetrieveGroup($group);
+ #ok !defined $entry,
+ # '... and the old group is gone';
+
+ isa_ok $new_entry, 'VUser::Google::Groups::GroupEntry',
+ '... and the create succeeded';
+
+ # Can't rename group
+ #is $new_entry->GroupId, $group.'.new' #.'@'.$api->google->domain,,
+ # '... and group id matches';
+
+ is $new_entry->GroupName, "test group $
group.new",
+ '... and group name matches';
+
+ is $new_entry->Description, 'test group descr new',
+ '... and description matches';
+
+ is $new_entry->EmailPermission, 'Member',
+ '... and email permission matches';
+
+ ok $api->DeleteGroup($group),
+ '... and delete suceeded';
+}
1;