Skip to content

Commit

Permalink
skip tests without gv account
Browse files Browse the repository at this point in the history
perltidy
remove logout (didn't work anyway)
  • Loading branch information
tempire committed Sep 21, 2010
1 parent 8991ffc commit 3086acc
Show file tree
Hide file tree
Showing 6 changed files with 221 additions and 225 deletions.
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -2,5 +2,4 @@
.DS_Store
a.pl
env
fixtures
cover_db
186 changes: 90 additions & 96 deletions lib/Google/Voice.pm
Expand Up @@ -6,131 +6,125 @@ use warnings;
use Mojo::Client;
use Mojo::JSON;
use IO::Socket::SSL;
use Data::Dumper;

use Google::Voice::Feed;
use Google::Voice::Call;

use base 'Mojo::Base';

__PACKAGE__->attr( [ qw/ client rnr_se / ] );
__PACKAGE__->attr([qw/ client rnr_se /]);

sub new {
my $self = bless {}, shift;
my $self = bless {}, shift;

$self->client( Mojo::Client->new );
$self->client(Mojo::Client->new);

return $self;
return $self;
}

sub login {
my $self = shift;
my ($user, $pass) = @_;
my $c = $self->client;
my $self = shift;
my ($user, $pass) = @_;
my $c = $self->client;

# GALX value
my $el = $c->get('https://www.google.com/accounts/ServiceLogin')
->res->dom->at('input[name="GALX"]');

my $galx = $el->attrs->{value} if $el;
# GALX value
my $el =
$c->get('https://www.google.com/accounts/ServiceLogin')
->res->dom->at('input[name="GALX"]');

$c->post_form('https://www.google.com/accounts/ServiceLoginAuth', {
Email => $user,
Passwd => $pass,
GALX => $galx,
} );

# rnr_se required for subsequent requests
$c->max_redirects(4); # 3-4 redirects before rnr_se is available
$el = $c->get('https://www.google.com/voice#inbox')
->res->dom->at('input[name="_rnr_se"]');

# Login not accepted
return unless $el;

$self->rnr_se( $el->attrs->{value} );
my $galx = $el->attrs->{value} if $el;

return $self;
}
$c->post_form(
'https://www.google.com/accounts/ServiceLoginAuth',
{ Email => $user,
Passwd => $pass,
GALX => $galx,
}
);

#sub logout {
# my $self = shift;
# my $c = $self->client;
#
# $c->max_redirects(0);
#
# return 1 if $c->get('https://www.google.com/voice/account/signout')
# ->res->cookie('gv')->value eq 'EXPIRED';
#}
# rnr_se required for subsequent requests
$c->max_redirects(4); # 3-4 redirects before rnr_se is available
$el =
$c->get('https://www.google.com/voice#inbox')
->res->dom->at('input[name="_rnr_se"]');

# Login not accepted
return unless $el;

$self->rnr_se($el->attrs->{value});

return $self;
}

sub send_sms {
my $self = shift;
my $c = $self->client;
my ($phone, $content) = @_;
my $json = $c->post_form(
'https://www.google.com/voice/b/0/sms/send', {
id => undef,
phoneNumber => $phone,
text => $content || '',
_rnr_se => $self->rnr_se
}
)->res->json;

$@ = $json->{data}->{code} and return unless $json->{ok};
return $json->{ok};
my $self = shift;
my $c = $self->client;
my ($phone, $content) = @_;

my $json = $c->post_form(
'https://www.google.com/voice/b/0/sms/send',
{ id => undef,
phoneNumber => $phone,
text => $content || '',
_rnr_se => $self->rnr_se
}
)->res->json;

$@ = $json->{data}->{code} and return unless $json->{ok};

return $json->{ok};
}

for my $feed ( qw/ all starred spam trash voicemail
sms recorded placed received missed / ) {

no strict 'refs';
*{"Google::Voice::${feed}"} = sub {
shift->feed( 'https://www.google.com/voice/inbox/recent/' . $feed );
};
for my $feed (
qw/ all starred spam trash voicemail
sms recorded placed received missed /
)
{

no strict 'refs';
*{"Google::Voice::${feed}"} = sub {
shift->feed('https://www.google.com/voice/inbox/recent/' . $feed);
};
}

sub feed {
my $self = shift;
my $url = shift;
my $self = shift;
my $url = shift;

my $c = $self->client;

# Multiple conversations
my $inbox = $c->get( $url )->res->dom;
my $c = $self->client;

# metadata
my $meta = Mojo::JSON->new->decode(
$inbox->at('response > json')->text );

# content
my $xml = Mojo::DOM->new->parse(
$inbox->at('response > html')->text );

# Each conversation in a span.gc-message
return map
Google::Voice::Feed->new( $_, $meta, $self->rnr_se, $c ),
@{$xml->find('.gc-message')};
# Multiple conversations
my $inbox = $c->get($url)->res->dom;

# metadata
my $meta = Mojo::JSON->new->decode($inbox->at('response > json')->text);

# content
my $xml = Mojo::DOM->new->parse($inbox->at('response > html')->text);

# Each conversation in a span.gc-message
return map
Google::Voice::Feed->new($_, $meta, $self->rnr_se, $c),
@{$xml->find('.gc-message')};
}

sub call {
my $self = shift;
my ($from, $to) = @_;

my $json = $self->client->post_form(
'https://www.google.com/voice/call/connect' => {
forwardingNumber => $from,
outgoingNumber => $to,
phoneType => 1,
remember => 0,
_rnr_se => $self->rnr_se
}
)->res->json;

$@ = $json->{error} and return unless $json->{ok};

return Google::Voice::Call->new( @_, $self->rnr_se, $self->client );
my $self = shift;
my ($from, $to) = @_;

my $json = $self->client->post_form(
'https://www.google.com/voice/call/connect' => {
forwardingNumber => $from,
outgoingNumber => $to,
phoneType => 1,
remember => 0,
_rnr_se => $self->rnr_se
}
)->res->json;

$@ = $json->{error} and return unless $json->{ok};

return Google::Voice::Call->new(@_, $self->rnr_se, $self->client);
}

1;
Expand Down
42 changes: 21 additions & 21 deletions lib/Google/Voice/Call.pm
Expand Up @@ -5,35 +5,35 @@ use warnings;

use base 'Mojo::Base';

__PACKAGE__->attr( [ qw/ from to rnr_se client / ] );
__PACKAGE__->attr([qw/ from to rnr_se client /]);

sub new {
my $self = bless {}, shift;

$self->from( shift );
$self->to( shift );
$self->rnr_se( shift );
$self->client( shift );
return $self;
my $self = bless {}, shift;

$self->from(shift);
$self->to(shift);
$self->rnr_se(shift);
$self->client(shift);

return $self;
}

sub cancel {
my $self = shift;
my ($from, $to) = @_;
my $self = shift;
my ($from, $to) = @_;

my $json = $self->client->post_form(
'https://www.google.com/voice/call/cancel/' => {
forwardingNumber => undef,
outgoingNumber => undef,
cancelType => 'C2C',
_rnr_se => $self->rnr_se
}
)->res->json;
my $json = $self->client->post_form(
'https://www.google.com/voice/call/cancel/' => {
forwardingNumber => undef,
outgoingNumber => undef,
cancelType => 'C2C',
_rnr_se => $self->rnr_se
}
)->res->json;

$@ = $json->{data}->{code} and return unless $json->{ok};
$@ = $json->{data}->{code} and return unless $json->{ok};

return $json->{ok};
return $json->{ok};
}

1;
Expand Down

0 comments on commit 3086acc

Please sign in to comment.