| 1 | package WWW::Contact::Plaxo; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 1 | ▶ | use Moose; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 1 | extends 'WWW::Contact::Base'; | |||||||||||||
| 5 | |||||||||||||||
| 6 | 1 | our $VERSION = '0.16'; | |||||||||||||
| 7 | 1 | our $AUTHORITY = 'cpan:SACHINJSK'; | |||||||||||||
| 8 | |||||||||||||||
| 9 | sub get_contacts { | ||||||||||||||
| 10 | 0 | ▶ | my ($self, $email, $password) = @_; | ||||||||||||
|
Subroutine
get_contacts: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||
| 11 | |||||||||||||||
| 12 | # reset errstr | ||||||||||||||
| 13 | 0 | $self->errstr(undef); | |||||||||||||
| 14 | 0 | my @contacts; | |||||||||||||
| 15 | |||||||||||||||
| 16 | 0 | my $ua = $self->ua; | |||||||||||||
| 17 | 0 | $self->debug("start get_contacts from Plaxo"); | |||||||||||||
| 18 | |||||||||||||||
| 19 | # get to login form | ||||||||||||||
| 20 | 0 | ▶ | $self->get('https://www.plaxo.com/signin') || return; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 21 | |||||||||||||||
| 22 | 0 | ▶ | $self->submit_form( | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 23 | form_name => 'form', | ||||||||||||||
| 24 | fields => { | ||||||||||||||
| 25 | 'signin.email' => $email, | ||||||||||||||
| 26 | 'signin.password' => $password, | ||||||||||||||
| 27 | }, | ||||||||||||||
| 28 | ) || return; | ||||||||||||||
| 29 | |||||||||||||||
| 30 | 0 | my $content = $ua->content(); | |||||||||||||
| 31 | 0 | ▶ | if ($content =~ /too many login failures/ig) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 32 | 0 | $self->errstr('Account has had too many login failures recently and has been temporarily locked'); | |||||||||||||
| 33 | 0 | return; | |||||||||||||
| 34 | } | ||||||||||||||
| 35 | elsif ($content =~ /Sign in to Plaxo/ig) { | ||||||||||||||
| 36 | 0 | $self->errstr('Wrong Username or Password'); | |||||||||||||
| 37 | 0 | return; | |||||||||||||
| 38 | } | ||||||||||||||
| 39 | |||||||||||||||
| 40 | 0 | $self->debug('Login OK'); | |||||||||||||
| 41 | |||||||||||||||
| 42 | 0 | $self->get("http://www.plaxo.com/export/plaxo_ab_outlook.csv"); | |||||||||||||
| 43 | |||||||||||||||
| 44 | 0 | ▶ | $self->submit_form( | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 45 | form_name => 'form' | ||||||||||||||
| 46 | ) || return; | ||||||||||||||
| 47 | |||||||||||||||
| 48 | 0 | my $address_content = $ua->content(); | |||||||||||||
| 49 | 0 | @contacts = get_contacts_from_csv($address_content); | |||||||||||||
| 50 | |||||||||||||||
| 51 | 0 | ▶ | return wantarray ? @contacts : \@contacts; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 52 | } | ||||||||||||||
| 53 | |||||||||||||||
| 54 | sub get_contacts_from_csv { | ||||||||||||||
| 55 | 0 | ▶ | my ($csv) = shift; | ||||||||||||
|
Subroutine
get_contacts_from_csv: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||
| 56 | 0 | my @contacts; | |||||||||||||
| 57 | |||||||||||||||
| 58 | # title, first_name, middle_name, last_name, suffix, e-mail. | ||||||||||||||
| 59 | 0 | my @lines = split(/\n/, $csv); | |||||||||||||
| 60 | 0 | shift @lines; # skip the first line | |||||||||||||
| 61 | 0 | foreach my $line (@lines) { | |||||||||||||
| 62 | 0 | $line =~ s/"//g; | |||||||||||||
| 63 | 0 | my @cols = split(',', $line); | |||||||||||||
| 64 | 0 | push @contacts, { | |||||||||||||
| 65 | name => $cols[1].' '.$cols[3], | ||||||||||||||
| 66 | email => $cols[5] | ||||||||||||||
| 67 | }; | ||||||||||||||
| 68 | } | ||||||||||||||
| 69 | |||||||||||||||
| 70 | 0 | ▶ | return wantarray ? @contacts : \@contacts; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 71 | } | ||||||||||||||
| 72 | |||||||||||||||
| 73 | 1 | ▶ | no Moose; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 74 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||||||
| 75 | |||||||||||||||
| 76 | 1 | 1; | |||||||||||||
| 77 | __END__ | ||||||||||||||
| 78 | |||||||||||||||
| 79 | =head1 NAME | ||||||||||||||
| 80 | |||||||||||||||
| 81 | WWW::Contact::Plaxo - Get contacts from Plaxo | ||||||||||||||
| 82 | |||||||||||||||
| 83 | =head1 SYNOPSIS | ||||||||||||||
| 84 | |||||||||||||||
| 85 | use WWW::Contact; | ||||||||||||||
| 86 | use Data::Dumper; | ||||||||||||||
| 87 | |||||||||||||||
| 88 | my $wc = WWW::Contact->new(); | ||||||||||||||
| 89 | # Note that the last argument for get_contacts is mandatory, | ||||||||||||||
| 90 | # or else it will try to fetch contacts from email.com | ||||||||||||||
| 91 | my @contacts = $wc->get_contacts('itsa@email.com', 'password', 'plaxo'); | ||||||||||||||
| 92 | my $errstr = $wc->errstr; | ||||||||||||||
| 93 | if ($errstr) { | ||||||||||||||
| 94 | die $errstr; | ||||||||||||||
| 95 | } else { | ||||||||||||||
| 96 | print Dumper(\@contacts); | ||||||||||||||
| 97 | } | ||||||||||||||
| 98 | |||||||||||||||
| 99 | =head1 DESCRIPTION | ||||||||||||||
| 100 | |||||||||||||||
| 101 | Get contacts from Plaxo. Extends L<WWW::Contact::Base> | ||||||||||||||
| 102 | |||||||||||||||
| 103 | =head1 SEE ALSO | ||||||||||||||
| 104 | |||||||||||||||
| 105 | L<WWW::Contact>, L<WWW::Contact::Base>, L<WWW::Mechanize> | ||||||||||||||
| 106 | |||||||||||||||
| 107 | =head1 AUTHOR | ||||||||||||||
| 108 | |||||||||||||||
| 109 | Sachin Sebastian, C<< <sachinjsk at cpan.org> >> | ||||||||||||||
| 110 | |||||||||||||||
| 111 | =head1 COPYRIGHT & LICENSE | ||||||||||||||
| 112 | |||||||||||||||
| 113 | Copyright 2008 Sachin Sebastian, all rights reserved. | ||||||||||||||
| 114 | |||||||||||||||
| 115 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||
| 116 | under the same terms as Perl itself. | ||||||||||||||
| 117 | |||||||||||||||
| 118 | =cut | ||||||||||||||