The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

WWW::Google::Contacts - Google Contacts Data API

VERSION

version 0.05

SYNOPSIS

    use WWW::Google::Contacts;

    my $gcontacts = WWW::Google::Contacts->new();
    $gcontacts->login('fayland@gmail.com', 'pass') or die 'login failed';
    
    # create contact
    my $status = $gcontacts->create_contact( {
        givenName => 'FayTestG',
        familyName => 'FayTestF',
        fullName   => 'Fayland Lam',
        Notes     => 'just a note',
        primaryMail => 'primary@example.com',
        displayName => 'FayTest Dis',
        secondaryMail => 'secndary@test.com', # optional
    } );
    print "Create OK" if $status;
    
    my @contacts = $gcontacts->get_contacts;
    foreach my $contact (@contacts) {
        my @emails = map { $_->{address} } @{ $contact->{email} };
        print "$contact->{name}->{'gd:fullName'}: " . join(', ', @emails) . "\n";
        $gcontacts->delete_contact($contact->{id})
            if $contact->{name}->{'gd:givenName'} eq 'Test';
    }

DESCRIPTION

This module implements 'Google Contacts Data API' according http://code.google.com/apis/contacts/docs/3.0/developers_guide_protocol.html

METHODS

  • new/login

        my $gcontacts = WWW::Google::Contacts->new();
        $gcontacts->login('fayland@gmail.com', 'pass') or die 'login failed';
  • create_contact

        $gcontacts->create_contact( {
            givenName => 'FayTestG',
            familyName => 'FayTestF',
            fullName   => 'Fayland Lam',
            Notes     => 'just a note',
            primaryMail => 'primary@example.com',
            displayName => 'FayTest Dis',
            secondaryMail => 'secndary@test.com', # optional
        } );

    return 1 if created

  • get_contacts

        my @contacts = $gcontacts->get_contacts;
        my @contacts = $gcontacts->get_contacts( {
            group => 'thin', # default to 'full'
        } )
        my @contacts = $gcontacts->get_contacts( {
            updated-min => '2007-03-16T00:00:00',
            start-index => 10,
            max-results => 99, # default as 9999
        } );

    get contacts from this account.

    group refers http://code.google.com/apis/contacts/docs/2.0/reference.html#Projections

    start-index, max_results etc refer http://code.google.com/apis/contacts/docs/2.0/reference.html#Parameters

  • get_contact($id)

        my $contact = $gcontacts->get_contact('http://www.google.com/m8/feeds/contacts/account%40gmail.com/base/1');

    get a contact by id

  • update_contact

        my $status = $gcontacts->update_contact('http://www.google.com/m8/feeds/contacts/account%40gmail.com/base/123623e48cb4e70a', {
            givenName => 'FayTestG2',
            familyName => 'FayTestF2',
            fullName   => 'Fayland Lam2',
            Notes     => 'just a note2',
            primaryMail => 'primary@example2.com',
            displayName => 'FayTest2 Dis',
            secondaryMail => 'secndary@test62.com', # optional
        } );

    update a contact

  • delete_contact($id)

        my $status = $gcontacts->delete_contact('http://www.google.com/m8/feeds/contacts/account%40gmail.com/base/1');

    The id is from get_contacts.

  • create_group

        my $status = $gcontacts->create_group( { title => 'Test Group' } );

    Create a new group

  • get_groups

        my @groups = $gcontacts->get_groups;
        my @groups = $gcontacts->get_groups( {
            updated-min => '2007-03-16T00:00:00',
            start-index => 10,
            max-results => 99, # default as 9999
        } );

    Get all groups.

  • get_group($id)

        my $group = $gcontacts->get_group('http://www.google.com/m8/feeds/groups/account%40gmail.com/base/6e744e7d0a4b398c');

    get a group by id

  • update_group($id, { title => $title })

        my $status = $gcontacts->update_group( 'http://www.google.com/m8/feeds/groups/account%40gmail.com/base/6e744e7d0a4b398c', { title => 'New Test Group 66' } );

    Update a group

  • delete_group

        my $status = $gcontacts->delete_contact('http://www.google.com/m8/feeds/groups/account%40gmail.com/base/6e744e7d0a4b398c');

ACKNOWLEDGE

John Clyde - who share me with his code about Contacts API

AUTHOR

  Fayland Lam <fayland@gmail.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2010 by Fayland Lam.

This is free software; you can redistribute it and/or modify it under the same terms as perl itself.