commit 9287023a4ea6175baf2db6e4d0b95190df2cfe0b
Author: Avi Alkalay <avibra...@gmail.com>
Date:   Wed Apr 25 08:51:18 2012 -0300

    Adding an example script due to poor API documentation.

 .gitignore |    2 +
 example.pl |   71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 sources    |    2 +-
 3 files changed, 74 insertions(+), 1 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 68545cc..3d815b3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,3 @@
 /WWW-Google-Contacts-0.33.tar.gz
+/WWW-Google-Contacts-0.34.tar.gz
+/example.pl
diff --git a/example.pl b/example.pl
new file mode 100755
index 0000000..482342a
--- /dev/null
+++ b/example.pl
@@ -0,0 +1,71 @@
+#!/usr/bin/perl
+
+
+#############################################################
+#
+# This is a useful example script that will:
+#
+# - iterate through all contacts
+# - select a few based on a group name
+# - check if it has phone numbers
+# - edit those phone numbers
+# - commit changes back to Google Contacts
+#
+# This script by Avi Alkalay <avi at unix dot sh>
+#
+# $Id: gcontacts.pl 526 2012-04-24 11:49:33Z aviram $
+#
+#############################################################
+
+use WWW::Google::Contacts;
+
+my $google = WWW::Google::Contacts->new( username => "YOUR_GOOGLE_USERNAME", 
password => "YOUR_GOOGLE_PASSWORD" );
+
+
+my $contactIterator = $google->contacts;
+my $contact;
+
+while ($contact = $contactIterator->next) {
+       my $modified=0;
+
+       # Filter contacts by group name
+       if (contactHasGroup($contact,'System Group: My Contacts')) {
+               # Check if has phone number
+               if ($contact->{phone_number}) {
+                       # Iterate through phone numbers
+                       foreach (@{$contact->{phone_number}}) {
+                               my $p=$_;
+
+                               # Check if phone number matches the pattern we 
are looking for
+                               if ($p->{value}=~m/^\(0(\d\d)\)/) {
+                                       my $old=$p->{value};
+
+                                       # Do some modifications of phone prefix 
and mark contact modified
+                                       $p->{value}=~s/^\(0(\d\d)\)/+55 
\($1\)/g;
+                                       $modified=1;
+
+                                       # Print on screen what we are doing
+                                       print $contact->full_name . " :: 
$p->{label} :: $old => $p->{value}\n";
+                               }
+                       }
+               }
+       }
+
+       # If contact was modified above, commit changes back to Google Contacts
+       if ($modified eq 1) {
+               $contact->update;
+       }
+}
+
+
+
+sub contactHasGroup() {
+       my $c=shift;
+       my $g=shift;
+       
+       foreach ($c->groups) {
+               return 1 if ($_->{title} eq $g);
+       }
+       
+       return 0;
+}
diff --git a/sources b/sources
index aae3bc9..67b9048 100644
--- a/sources
+++ b/sources
@@ -1 +1 @@
-3e33a1d0dc9f50fdd45652783b461383  WWW-Google-Contacts-0.33.tar.gz
+1dba94186ce5a558f80f735958e4996e  example.pl
--
Fedora Extras Perl SIG
http://www.fedoraproject.org/wiki/Extras/SIGs/Perl
perl-devel mailing list
perl-devel@lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/perl-devel

Reply via email to