[vuser] r586 committed - - Add code to create and delete groups...

7 views
Skip to first unread message

codesite...@google.com

unread,
Dec 4, 2009, 1:36:50 AM12/4/09
to vuser-...@googlegroups.com
Revision: 586
Author: perlstalker
Date: Thu Dec 3 22:36:05 2009
Log: - Add code to create and delete groups
- Create test classes for groups

http://code.google.com/p/vuser/source/detail?r=586

Added:
/VUser-Google-ProvisioningAPI/trunk/t/tests/Test/VUser/Google/Groups

/VUser-Google-ProvisioningAPI/trunk/t/tests/Test/VUser/Google/Groups/V2_0.pm
/VUser-Google-ProvisioningAPI/trunk/t/tests/Test/VUser/Google/Groups.pm
Modified:
/VUser-Google-ProvisioningAPI/trunk/lib/VUser/Google/Groups/V2_0.pm
/VUser-Google-ProvisioningAPI/trunk/lib/VUser/Google/Groups.pm
/VUser-Google-ProvisioningAPI/trunk/t/tests/My/Test/Class.pm

/VUser-Google-ProvisioningAPI/trunk/t/tests/Test/VUser/Google/Provisioning.pm

=======================================
--- /dev/null
+++
/VUser-Google-ProvisioningAPI/trunk/t/tests/Test/VUser/Google/Groups/V2_0.pm
Thu Dec 3 22:36:05 2009
@@ -0,0 +1,33 @@
+package Test::VUser::Google::Groups::V2_0;
+use warnings;
+use strict;
+
+use Test::Most;
+use base 'Test::VUser::Google::Groups';
+
+sub CreateGroup : Tests(4) {
+ my $test = shift;
+ my $class = $test->class;
+
+ my $api = $class->new(google => $test->create_google);
+ can_ok $api, 'CreateGroup';
+
+ my $group = $test->get_test_group;
+
+ my $entry = $api->CreateGroup(
+ groupId => $group,
+ groupName => "test group $group",
+ description => 'test group descr',
+ emailPermission => 'Domain',
+ );
+
+ isa_ok $entry, 'VUser::Google::Groups::GroupEntry',
+ '... and the create succeeded';
+
+ ## Clean up
+ can_ok $api, 'DeleteGroup';
+ ok $api->DeleteGroup($group),
+ '... and delete suceeded';
+}
+
+1;
=======================================
--- /dev/null
+++ /VUser-Google-ProvisioningAPI/trunk/t/tests/Test/VUser/Google/Groups.pm
Thu Dec 3 22:36:05 2009
@@ -0,0 +1,39 @@
+package Test::VUser::Google::Groups;
+use warnings;
+use strict;
+
+use Test::Most;
+use base 'My::Test::Class';
+
+my $acct;
+
+sub constructor : Tests(3) {
+ my $test = shift;
+ my $class = $test->class;
+
+ can_ok $class, 'new';
+ ok my $api = $class->new(google => $test->create_google),
+ '... and the constructor should succeed';
+ isa_ok $api, $class, '... and the object it returns';
+}
+
+sub get_test_group {
+ my $self = shift;
+
+ if (1 || not defined $acct) {
+ my @time = localtime;
+ $acct = sprintf (
+ 'test.group.%04d.%02d.%02d.%02d.%02d.%02d',
+ $time[5]+1900,
+ $time[4]+1,
+ $time[3],
+ $time[2],
+ $time[1],
+ $time[0]
+ );
+ }
+
+ return $acct;
+}
+
+1;
=======================================
--- /VUser-Google-ProvisioningAPI/trunk/lib/VUser/Google/Groups/V2_0.pm Wed
Dec 2 21:35:45 2009
+++ /VUser-Google-ProvisioningAPI/trunk/lib/VUser/Google/Groups/V2_0.pm Thu
Dec 3 22:36:05 2009
@@ -1,4 +1,4 @@
-use VUser::Google::Groups::V2_0;
+package VUser::Google::Groups::V2_0;
use warnings;
use strict;

@@ -7,7 +7,9 @@
use Moose;
extends 'VUser::Google::Groups';

-has '+base_url' => (default
=> 'https://apps-api.google.com/a/feeds/group/2.0/');
+use VUser::Google::Groups::GroupEntry;
+
+has '+base_url' => (default
=> 'https://apps-apis.google.com/a/feeds/group/2.0/');

#### Methods ####
sub CreateGroup {
@@ -22,6 +24,29 @@
%options = @_;
}

+ my $url = $self->base_url.$self->google->domain;
+
+ 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">';
+ $post .= '<apps:property name="groupId" value="'
+ .$options{groupId}.'"/>';
+ $post .= '<apps:property name="groupName" value="'
+ .$options{groupName}.'"/>';
+ $post .= '<apps:property name="description" value="'
+ .$options{description}.'"/>';
+ $post .= '<apps:property name="emailPermission" value="'
+ .$options{emailPermission}.'"/>';
+
+ $post .= '</atom:entry>';
+
+
+ if ($self->google->Request('POST', $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 UpdateGroup {
@@ -37,6 +62,19 @@
}

sub DeleteGroup {
+ my $self = shift;
+ my $groupId = shift;
+
+ die "Cannot delete group: No group specified.\n" if not $groupId;
+
+ my $url = $self->base_url.$self->google->domain."/$groupId";
+
+ if ($self->google->Request('DELETE', $url)) {
+ return 1;
+ }
+ else {
+ die "Cannot delete group: ".$self->google->result->{'reason'};
+ }
}

sub AddMemberToGroup {
@@ -60,5 +98,31 @@
sub RemoveOwnerFromGroup {
}

+sub _build_group_entry {
+ my $self = shift;
+ my $xml = shift;
+
+ 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'});
+ }
+ }
+
+ return $entry;
+}
+
+no Moose;
+__PACKAGE__->meta->make_immutable;

1;
=======================================
--- /VUser-Google-ProvisioningAPI/trunk/lib/VUser/Google/Groups.pm Tue Nov
17 23:17:24 2009
+++ /VUser-Google-ProvisioningAPI/trunk/lib/VUser/Google/Groups.pm Thu Dec
3 22:36:05 2009
@@ -1,4 +1,4 @@
-use VUser::Google::Groups;
+package VUser::Google::Groups;
use warnings;
use strict;

@@ -7,8 +7,8 @@
use Moose;

has 'google' => (
- is => 'rw',
- isa => 'VUser::Google::ApiProtocol',
+ is => 'rw',
+ isa => 'VUser::Google::ApiProtocol',
required => 1
);

@@ -17,7 +17,7 @@
# Turn on deugging
has 'debug' => (is => 'rw', default => 0);

-#### Methods
+#### Methods ####

## Util
#print out debugging to STDERR if debug is set
=======================================
--- /VUser-Google-ProvisioningAPI/trunk/t/tests/My/Test/Class.pm Sat Nov 28
20:23:58 2009
+++ /VUser-Google-ProvisioningAPI/trunk/t/tests/My/Test/Class.pm Thu Dec 3
22:36:05 2009
@@ -27,7 +27,7 @@
domain => $ENV{GAPPS_DOMAIN},
admin => $ENV{GAPPS_ADMIN},
password => $ENV{GAPPS_PASSWD},
-# debug => 1
+ debug => 1
);

return $google;
=======================================
---
/VUser-Google-ProvisioningAPI/trunk/t/tests/Test/VUser/Google/Provisioning.pm
Tue Nov 17 23:17:24 2009
+++
/VUser-Google-ProvisioningAPI/trunk/t/tests/Test/VUser/Google/Provisioning.pm
Thu Dec 3 22:36:05 2009
@@ -1,4 +1,4 @@
-package Test::VUser::Google::Provisioning::V2_0;
+package Test::VUser::Google::Provisioning;
use warnings;
use strict;

Reply all
Reply to author
Forward
0 new messages