| 1 | package Google::Voice; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Mojo::UserAgent; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Mojo::JSON; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use IO::Socket::SSL 1.37; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Google::Voice::Feed; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Google::Voice::Call; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Mojo::Base -base; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | 1 | our $VERSION = 0.06; | |||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||
| 17 | 1 | __PACKAGE__->attr([qw/ ua rnr_se /]); | |||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 20 | 0 | my $self = bless {}, shift; | |||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | 0 | $self->ua(Mojo::UserAgent->new); | |||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | 0 | return $self; | |||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | sub login { | ||||||||||||||||||||||||||||||
|
Subroutine
login: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 28 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 29 | 0 | my ($user, $pass) = @_; | |||||||||||||||||||||||||||||||
| 30 | 0 | my $c = $self->ua; | |||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||
| 32 | 0 | $c->max_redirects(6); # Google seems to like redirects everywhere | |||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||
| 34 | # GALX value | ||||||||||||||||||||||||||||||||
| 35 | 0 | my $el = | |||||||||||||||||||||||||||||||
| 36 | $c->get('https://accounts.google.com/ServiceLogin') | ||||||||||||||||||||||||||||||||
| 37 | ->res->dom->at('input[name="GALX"]'); | ||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | my $galx = $el->attrs->{value} if $el; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||
| 41 | 0 | $c->post( | |||||||||||||||||||||||||||||||
| 42 | 'https://accounts.google.com/ServiceLogin', | ||||||||||||||||||||||||||||||||
| 43 | form => { Email => $user, | ||||||||||||||||||||||||||||||||
| 44 | Passwd => $pass, | ||||||||||||||||||||||||||||||||
| 45 | GALX => $galx, | ||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||
| 49 | # rnr_se required for subsequent requests | ||||||||||||||||||||||||||||||||
| 50 | 0 | $el = | |||||||||||||||||||||||||||||||
| 51 | $c->get('https://www.google.com/voice#inbox') | ||||||||||||||||||||||||||||||||
| 52 | ->res->dom->at('input[name="_rnr_se"]'); | ||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||
| 54 | # Login not accepted | ||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | return unless $el; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | 0 | $self->rnr_se($el->attrs->{value}); | |||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | 0 | return $self; | |||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | sub send_sms { | ||||||||||||||||||||||||||||||
|
Subroutine
send_sms: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 63 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 64 | 0 | my $c = $self->ua; | |||||||||||||||||||||||||||||||
| 65 | 0 | my ($phone, $content) = @_; | |||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | my $json = $c->post( | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$content || ''
MC/DC0%0/1
$content || ''
$content
Truth table0%0/2
A
A= $content
| |||||||||||||||||||||||||||||||||
| 68 | 'https://www.google.com/voice/b/0/sms/send', | ||||||||||||||||||||||||||||||||
| 69 | form => { id => undef, | ||||||||||||||||||||||||||||||||
| 70 | phoneNumber => $phone, | ||||||||||||||||||||||||||||||||
| 71 | text => $content || '', | ||||||||||||||||||||||||||||||||
| 72 | _rnr_se => $self->rnr_se | ||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||
| 74 | )->res->json; | ||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | $@ = $json->{data}->{code} and return unless $json->{ok}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
$json->{'ok'} || ($@ = $json->{'data'}{'code'}) && (return)
$@ = $json->{"data"}{"code"} and return
MC/DC0%0/2
$json->{'ok'} || ($@ = $json->{'data'}{'code'}) && (return)
$json->{'ok'}
$@ = $json->{"data"}{"code"}
Truth table0%0/3
A || B
A= $json->{'ok'}B= $@ = $json->{"data"}{"code"}
| |||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||
| 78 | 0 | return $json->{ok}; | |||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||
| 81 | 1 | for my $feed ( | |||||||||||||||||||||||||||||||
| 82 | qw/ all starred spam trash voicemail | ||||||||||||||||||||||||||||||||
| 83 | sms recorded placed received missed / | ||||||||||||||||||||||||||||||||
| 84 | ) | ||||||||||||||||||||||||||||||||
| 85 | { | ||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||
| 87 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 88 | 10 | ▶ | *{"Google::Voice::${feed}"} = sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||
| 89 | 0 | shift->feed('https://www.google.com/voice/inbox/recent/' . $feed); | |||||||||||||||||||||||||||||||
| 90 | 10 | }; | |||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | sub feed { | ||||||||||||||||||||||||||||||
|
Subroutine
feed: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 94 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 95 | 0 | my $url = shift; | |||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||
| 97 | 0 | my $c = $self->ua; | |||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||
| 99 | # Multiple conversations | ||||||||||||||||||||||||||||||||
| 100 | 0 | my $inbox = $c->get($url)->res->dom; | |||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||
| 102 | # metadata | ||||||||||||||||||||||||||||||||
| 103 | 0 | my $meta = Mojo::JSON->new->decode($inbox->at('response > json')->text); | |||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||
| 105 | # content | ||||||||||||||||||||||||||||||||
| 106 | 0 | my $xml = Mojo::DOM->new->parse($inbox->at('response > html')->text); | |||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||
| 108 | # Each conversation in a span.gc-message | ||||||||||||||||||||||||||||||||
| 109 | return map | ||||||||||||||||||||||||||||||||
| 110 | Google::Voice::Feed->new($_, $meta, $self->rnr_se, $c), | ||||||||||||||||||||||||||||||||
| 111 | 0 | @{$xml->find('.gc-message')}; | |||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | sub call { | ||||||||||||||||||||||||||||||
|
Subroutine
call: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 115 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 116 | 0 | my ($from, $to) = @_; | |||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||
| 118 | 0 | my $json = $self->ua->post( | |||||||||||||||||||||||||||||||
| 119 | 'https://www.google.com/voice/call/connect', | ||||||||||||||||||||||||||||||||
| 120 | form => { | ||||||||||||||||||||||||||||||||
| 121 | forwardingNumber => $from, | ||||||||||||||||||||||||||||||||
| 122 | outgoingNumber => $to, | ||||||||||||||||||||||||||||||||
| 123 | phoneType => 1, | ||||||||||||||||||||||||||||||||
| 124 | remember => 0, | ||||||||||||||||||||||||||||||||
| 125 | _rnr_se => $self->rnr_se | ||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||
| 127 | )->res->json; | ||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | $@ = $json->{error} and return unless $json->{ok}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
$json->{'ok'} || ($@ = $json->{'error'}) && (return)
$@ = $json->{"error"} and return
MC/DC0%0/2
$json->{'ok'} || ($@ = $json->{'error'}) && (return)
$json->{'ok'}
$@ = $json->{"error"}
Truth table0%0/3
A || B
A= $json->{'ok'}B= $@ = $json->{"error"}
| |||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||
| 131 | 0 | return Google::Voice::Call->new(@_, $self->rnr_se, $self->ua); | |||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||
| 134 | 1 | 1; | |||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||
| 136 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||
| 138 | Google::Voice - Easy interface for google voice | ||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||
| 140 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||
| 142 | Easy interface for google voice | ||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||
| 144 | =head1 USAGE | ||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||
| 146 | use Google::Voice; | ||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||
| 148 | my $g = Google::Voice->new->login('username', 'password'); | ||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||
| 150 | # Send sms | ||||||||||||||||||||||||||||||||
| 151 | $g->send_sms(5555555555 => 'Hello friend!'); | ||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||
| 153 | # Error code from google on fail | ||||||||||||||||||||||||||||||||
| 154 | print $@ if !$g->send_sms('invalid phone' => 'text message'); | ||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||
| 156 | # connect call & cancel it | ||||||||||||||||||||||||||||||||
| 157 | my $call = $g->call('+15555555555' => '+14444444444'); | ||||||||||||||||||||||||||||||||
| 158 | $call->cancel; | ||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||
| 161 | # Print all sms conversations | ||||||||||||||||||||||||||||||||
| 162 | foreach my $sms ($g->sms) { | ||||||||||||||||||||||||||||||||
| 163 | print $sms->name; | ||||||||||||||||||||||||||||||||
| 164 | print $_->time, ':', $_->text, "\n" foreach $sms->messages; | ||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||
| 166 | # Delete conversation | ||||||||||||||||||||||||||||||||
| 167 | $sms->delete; | ||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||
| 170 | # loop through voicemail messages | ||||||||||||||||||||||||||||||||
| 171 | foreach my $vm ($g->voicemail) { | ||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||
| 173 | # Name, number, and transcribed text | ||||||||||||||||||||||||||||||||
| 174 | print $vm->name . "\n"; | ||||||||||||||||||||||||||||||||
| 175 | print $vm->meta->{phoneNumber} . "\n"; | ||||||||||||||||||||||||||||||||
| 176 | print $vm->text . "\n"; | ||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||
| 178 | # Download mp3 | ||||||||||||||||||||||||||||||||
| 179 | $vm->download->move_to($vm->id . '.mp3'); | ||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||
| 181 | # Delete | ||||||||||||||||||||||||||||||||
| 182 | $vm->delete; | ||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||
| 185 | =head1 METHODS | ||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||
| 187 | =head2 new | ||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||
| 189 | Create object | ||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||
| 191 | =head2 login | ||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||
| 193 | Login. Returns object on success, false on failure. | ||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||
| 195 | =head2 call | ||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||
| 197 | Connect two phone numbers | ||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||
| 199 | =head2 send_sms | ||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||
| 201 | Send SMS message. Returns true/false. | ||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||
| 203 | =head2 sms | ||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||
| 205 | List of SMS messages | ||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||
| 207 | =head2 voicemail | ||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||
| 209 | List of voicemail messages | ||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||
| 211 | =head2 recorded | ||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||
| 213 | List of recorded calls | ||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||
| 215 | =head2 placed | ||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||
| 217 | List of placed calls | ||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||
| 219 | =head2 received | ||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||
| 221 | List of placed calls | ||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||
| 223 | =head2 missed | ||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||
| 225 | List of missed calls | ||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||
| 227 | =head2 starred | ||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||
| 229 | List of starred items (call, sms, or voicemail) | ||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||
| 231 | =head2 spam | ||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||
| 233 | List of items marked as spam (call, sms, or voicemail) | ||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||
| 235 | =head2 all | ||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||
| 237 | List of all items (call, sms, or voicemail) | ||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||
| 239 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||
| 241 | L<Mojo::UserAgent>, L<Mojo::DOM> | ||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||
| 243 | =head1 DEVELOPMENT | ||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||
| 245 | L<http://github.com/tempire/perl-google-voice> | ||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||
| 247 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||
| 249 | Glen Hinkle tempire@cpan.org | ||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||
| 251 | =head1 CREDITS | ||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||
| 253 | David Jones | ||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||
| 255 | Graham Forest | ||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||
| 257 | =cut | ||||||||||||||||||||||||||||||||