Revision: 599
Author: perlstalker
Date: Tue Aug 14 21:15:52 2012
Log: - Add AliasEntry class
- Add CreateEntry
Note: Completely untested.
http://code.google.com/p/vuser/source/detail?r=599
Added:
/VUser-Google-ProvisioningAPI/trunk/lib/VUser/Google/Provisioning/AliasEntry.pm
Modified:
/VUser-Google-ProvisioningAPI/trunk/lib/VUser/Google/ApiProtocol.pm
/VUser-Google-ProvisioningAPI/trunk/lib/VUser/Google/Provisioning/V2_0.pm
=======================================
--- /dev/null
+++
/VUser-Google-ProvisioningAPI/trunk/lib/VUser/Google/Provisioning/AliasEntry.pm
Tue Aug 14 21:15:52 2012
@@ -0,0 +1,26 @@
+package VUser::Google::Provisioning::AliasEntry;
+use warnings;
+use strict;
+
+our $VERSION = '0.1.0';
+
+use Moose;
+
+has 'id' => (is => 'rw', 'isa' => 'Str');
+has 'UserEmail' => (is => 'rw', 'isa' => 'Str');
+has 'AliasEmail' => (is => 'rw', 'isa' => 'Str');
+
+sub as_hash {
+ my $self = shift;
+
+ my %hash = (
+ userEmail => $self->UserEmail,
+ aliasEmail => $self->AliasEmail
+ );
+
+ return %hash;
+}
+
+no Moose;
+__PACKAGE__->meta->make_immutable;
+1;
=======================================
--- /VUser-Google-ProvisioningAPI/trunk/lib/VUser/Google/ApiProtocol.pm Mon
May 30 08:03:44 2011
+++ /VUser-Google-ProvisioningAPI/trunk/lib/VUser/Google/ApiProtocol.pm Tue
Aug 14 21:15:52 2012
@@ -199,6 +199,7 @@
If set to a true value, C<Login()> will refresh the authentication token
even if it's not necessary.
+
=back
=head2 Read-only members
=======================================
---
/VUser-Google-ProvisioningAPI/trunk/lib/VUser/Google/Provisioning/V2_0.pm
Sat Dec 12 22:21:21 2009
+++
/VUser-Google-ProvisioningAPI/trunk/lib/VUser/Google/Provisioning/V2_0.pm
Tue Aug 14 21:15:52 2012
@@ -397,6 +397,50 @@
sub DeleteNickname {
}
+
+## Aliases
+# see
https://developers.google.com/google-apps/provisioning/#managing_user_aliases_in_multiple_domains
+sub CreateAlias {
+ my $self = shift;
+ my $alias = shift; # email address
+ my $target = shift; # email address
+
+ $self->google()->Login();
+
+ my $alias_dom = $alias;
+ $alias_dom =~ s/^.+@//; # remove the user@ part
+
+ my $url = "
https://apps-apis.google.com/a/feeds/alias/2.0/$alias_dom";
+
+ my $post = "<atom:entry xmlns:atom='
http://www.w3.org/2005/Atom'
xmlns:apps='
http://schemas.google.com/apps/2006'>";
+ $post .= "<apps:property name=\"aliasEmail\" value=\"$alias\" />";
+ $post .= "<apps:property name=\"userEmail\" value=\"$target\" />";
+ $post .= '</atom:entry>';
+
+ if ($self->google->Request('POST', $url, $post)) {
+ $self->dprint('Created alias');
+ my $entry = $self->_build_alias_entry($self->google->result);
+ return $entry;
+ }
+ else {
+ $self->dprint('CreateAlias failed: '.$self->google->result->{reason});
+ die "Error creating alias: ".$self->google->result->{reason}."\n";
+ }
+}
+
+sub UpdateAlias {
+ my $self = shift;
+ my $alias = shift;
+ my $target = shift;
+
+ return $self->CreateAlias($alias, $target);
+}
+
+sub RetrieveAlias {
+}
+
+sub RetrieveAllAliases {
+}
# Takes the parsed XML object
sub _build_user_entry {
@@ -449,6 +493,25 @@
return $entry;
}
+
+sub _build_alias_entry {
+ my $self = shift;
+ my $xml = shift;
+
+ my $entry = VUser::Google::Provisioning::AliasEntry->new();
+
+ $entry->id($xml->{'entry'}[0]{'id'}[0]);
+ foreach my $property (@{ $xml->{'entry'}[0]{'apps:property'} }) {
+ if ($property->{'userEmail'}) {
+ $entry->UserEmail($property->{'userEmail'});
+ }
+ elsif ($property->{'aliasEntry'}) {
+ $entry->AliasEmail($property->{'aliasEmail'});
+ }
+ }
+
+ return $entry;
+}
no Moose;
__PACKAGE__->meta->make_immutable;