Skip Menu |

This queue is for tickets about the Google-Voice CPAN distribution.

Report information
The Basics
Id: 66386
Status: new
Priority: 0/
Queue: Google-Voice

People
Owner: Nobody in particular
Requestors: bitcard.org [...] munkynet.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.02
Fixed in: (no value)



Subject: PATCH: Enable and disable phones
Added a call in the login method to fetch phone info. Added methods enable_phone and disable_phone which take phone names. They look up the name in the phone info. In the case where more than one phone has the same name, only one of them is enabled or disabled. (This could be considered a bug.) Hope you find this useful.
Subject: p5-google-voice-enable-disable-phones.patch
diff -ur Google-Voice-0.02/lib/Google/Voice.pm Google-Voice-0.02.NEW/lib/Google/Voice.pm --- Google-Voice-0.02/lib/Google/Voice.pm 2011-02-21 22:44:30.000000000 -0500 +++ Google-Voice-0.02.NEW/lib/Google/Voice.pm 2011-03-04 14:55:19.000000000 -0500 @@ -5,6 +5,7 @@ use Mojo::Client; use Mojo::JSON; +use Mojo::URL; use IO::Socket::SSL 1.37; use Google::Voice::Feed; @@ -14,7 +15,7 @@ our $VERSION = 0.02; -__PACKAGE__->attr([qw/ client rnr_se /]); +__PACKAGE__->attr([qw/ client rnr_se phones /]); sub new { my $self = bless {}, shift; @@ -54,6 +55,12 @@ return unless $el; $self->rnr_se($el->attrs->{value}); + + #sam# Get phone info for later enable/disable operations + my $cfg = Mojo::JSON->new->decode( + $c->get('https://www.google.com/voice/settings/tab/phones') + ->res->dom->at('json')->text); + $self->phones($cfg->{phones}); return $self; } @@ -129,6 +136,42 @@ return Google::Voice::Call->new(@_, $self->rnr_se, $self->client); } +sub enable_phone { + return (shift)->_enable_or_disable_phone(1, @_); +} + +sub disable_phone { + return (shift)->_enable_or_disable_phone(0, @_); +} + +sub _find_phone_by_name { + my $self = shift; + my ($name) = @_; + + my ($id) = grep { $self->{phones}{$_}{name} eq $name } keys %{$self->phones}; + return $id; +} + +sub _enable_or_disable_phone { + my $self = shift; + my ($state, $name) = @_; + + my $id = $self->_find_phone_by_name($name); + die "$name: phone not found" unless defined $id; + + my $json = $self->client->post_form( + 'https://www.google.com/voice/settings/editDefaultForwarding/' => { + phoneId => $id, + enabled => $state, + _rnr_se => $self->rnr_se + } + )->res->json; + + $@ = $json->{error} and return unless $json->{ok}; + + return $state; +} + 1; =head1 NAME