#!/usr/bin/env perl

=pod

=head1 NAME

arxmobile-query-smsid - Query status of an SMS message using the ArxMobile HTTP API

=head1 SYNOPSIS

  arxmobile-query-smsid --auth_code <your-code-here> --smsid <smsid>

Example:

  arxmobile-query-smsid --auth_code my_code --smsid 3b1120314668143bb9108fb6d384d5

=head1 DESCRIPTION

Queries the status of a SMS message that's already been sent using its
B<smsid>. The smsid is returned when sending a message using the C<Send SMS> API.

The XML result of the API call will be printed on STDOUT.

=head1 AUTHOR

Cosimo Streppone, <cosimo@opera.com>

=head1 COPYRIGHT

This software is copyright (c) 2011 Opera Software ASA

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut

use strict;
use warnings;

use Getopt::Long ();
use JSON;
use Net::SMS::ArxMobile;
use Pod::Usage ();

Getopt::Long::GetOptions(
    'auth_code|auth-code|code:s' => \my $code,
    'smsid:s' => \my $smsid,
);

if (! $code || ! $smsid) {
    Pod::Usage::pod2usage(-verbose => 2);
}

my $sms = Net::SMS::ArxMobile->new(
    _auth_code => $code,
);

if (! $sms) {
    warn "Do you have a valid code? (--auth_code option)\n";
    exit 1;
}

my $result = $sms->query_smsid(smsid => $smsid);

print JSON->new->pretty->indent(4)->encode($result);

