2
=>
'voicemail'
,
10
=>
'sms'
,
4
=>
'recorded'
,
7
=>
'placed'
,
1
=>
'received'
,
0
=>
'missed'
,
11
=>
'trash'
,
10
=>
'starred'
,
};
__PACKAGE__->attr([
qw/ xml id type name meta text rnr_se ua /
]);
sub
new {
my
$self
=
bless
{},
shift
;
my
$xml
=
shift
;
my
$meta
=
shift
;
my
$rnr_se
=
shift
;
my
$ua
=
shift
;
$self
->xml(
$xml
);
$self
->id(
$xml
->attrs->{id});
$self
->name(
$self
->_message_name(
$xml
->at(
'.gc-message-name-link'
)));
$self
->meta(
$meta
->{messages}->{
$self
->id});
$self
->type(FEED_TYPE->{
$self
->meta->{type}});
$self
->text(
"@{[map $_->text, @{$xml->find('.gc-orig-trans > span')}]}"
);
$self
->rnr_se(
$rnr_se
);
$self
->ua(
$ua
);
return
$self
;
}
sub
_message_name {
my
$self
=
shift
;
my
$node
=
shift
;
return
$node
->text
if
$node
;
return
''
;
}
sub
messages {
my
$self
=
shift
;
return
map
Google::Voice::SMS::Message->new(
$_
,
$self
->meta,
$self
->rnr_se,
$self
->ua),
@{
$self
->xml->find(
'.gc-message-sms-row'
)};
}
sub
latest {
return
(
shift
->messages)[-1] }
sub
delete
{
my
$self
=
shift
;
my
$json
=
$self
->ua->post(
messages
=>
$self
->id,
trash
=> 1,
_rnr_se
=>
$self
->rnr_se
}
)->res->json;
$@ =
$json
->{data}->{code} and
return
unless
$json
->{ok};
return
$json
->{ok};
}
sub
download {
my
$self
=
shift
;
my
(
$from
,
$to
) =
@_
;
my
$res
=
$self
->ua->get(
$@ =
$res
->message and
return
if
$res
->code != 200;
return
$res
->content->asset;
}
1;