Subject: | return codes patch |
Date: | Tue, 7 Mar 2006 23:18:46 -0500 |
To: | bug-www-myspace [...] rt.cpan.org |
From: | Olaf Alders <olaf [...] vilerichard.com> |
Hi,
Here's a little patch for send_friend_request The only difference is
if you call it in list mode, you get a full response message as well
as the code:
my ($response_code, $response_message) = $myspace->send_friend_request
( $id );
My editor doesn't use tabs, so I hope it doesn't look too messed on
your end:
1855a1856,1866
Show quoted text
> my %status_codes = (
>
> FF => 'Failed, this person is already your friend.',
> FN => 'Failed, network error (couldn\'t get the page,
etc).',
Show quoted text > FP => 'Failed, you already have a pending friend request
for this person',
Show quoted text > FC => 'Failed, CAPTCHA response requested.',
> P => 'Passed! Verification string received.',
> F => 'Failed, verification string not found on page
after posting.',
Show quoted text >
> );
>
1859a1871,1872
Show quoted text > my $return_code = undef;
>
1862c1875
< return "FN";
---
Show quoted text > $return_code = 'FN';
1865,1890c1878,1909
< my $page = $self->current_page->content;
< $page =~ s/[ \t\n\r]+/ /g;
<
< # Check for success
< if ( $page =~ /An email has been sent to the user/i ) {
< return "P";
< }
<
< # Check for "already your friend"
< if ( $page =~ /already your friend/i ) {
< return "FF";
< }
<
< # Check for pending friend request
< if ( $page =~ /pending friend request/i ) {
< return "FP";
< }
<
< # Check for CAPTCHA
< if ( $page =~ /CAPTCHA/ ) {
< return "FC";
< }
<
< # Failed.
< return "F";
<
---
Show quoted text > else {
>
> my $page = $self->current_page->content;
> $page =~ s/[ \t\n\r]+/ /g;
>
> # Check for success
> if ( $page =~ /An email has been sent to the user/i ) {
> $return_code = 'P';
> }
>
> # Check for "already your friend"
> elsif ( $page =~ /already your friend/i ) {
> $return_code = 'FF';
> }
>
> # Check for pending friend request
> elsif ( $page =~ /pending friend request/i ) {
> $return_code = 'FP';
> }
>
> # Check for CAPTCHA
> elsif ( $page =~ /CAPTCHA/ ) {
> $return_code = 'FC';
> }
>
> # Failed.
> unless ($return_code) {
> $return_code = 'F';
> }
> }
>
> return $return_code, $status_codes{$return_code};
If you don't find it useful, I won't be offended of course!
BTW, here's what I've been doing to get around the CAPTCHA stuff. I
coded this before I patched the status response:
use IO::Prompt;
my %status_codes = (
FF => 'Failed, this person is already your friend.',
FN => 'Failed, network error (couldn\'t get the page, etc).',
FP => 'Failed, you already have a pending friend request for
this person',
FC => 'Failed, CAPTCHA response requested.',
P => 'Passed! Verification string received.',
F => 'Failed, verification string not found on page after
posting.',
);
my $sleep = 10;
# pass a list of friend ids to this sub
sub friend_request {
my @ids = @_;
foreach my $id ( @ids ) {
my $status = $myspace->send_friend_request( $id );
++$status{$status};
print "$id:\t$status\n";
if ($status eq 'FC') {
print "captcha response. please fill in the form at the
following url before continuing.\n";
print "\n\nhttp://collect.myspace.com/index.cfm?
fuseaction=invite.addfriend_verify&friendID=$id\n\n";
my $continue = prompt "Continue? (y/n)\n", -yn;
unless ($continue) {
print "exiting nicely.";
last;
}
}
sleep $sleep;
}
print "Final status report...\n\n######################\n";
foreach my $key (keys %status_codes) {
if (exists $status{$key} ) {
print "$status{$key} $status_codes{$key} ($key)\n";
}
}
}
Maybe it would be helpful to add an "interactive" method that could
do this sort of thing to help sort out the CAPTCHA stuff. In this
context $myspace->captcha was always coming back empty, so I use this
as my workaround.
Best,
Olaf
--
Olaf Alders
olaf@vilerichard.com
http://www.vilerichard.com -- pop tunes
http://cdbaby.com/cd/vilerichard