Business-UTV
view release on metacpan or search on metacpan
0.05 Monday 2 October 2006
- Remember to include icon
0.04 Monday 18 September 2006
- Added signal handler so windows system tray script exits correctly on system reboot
0.03 Sunday 17 September 2006
- Fixed bug caused by 0 upload and download
- Added windows system tray script
0.02 Tuesday 6 June 2006
- Added some real tests
- Removed errstr from public interface
- Now checking for http errors
- Now treating name as string not a regexp
- Usage now returns current usage in MB without unit eg 1 not 1MB
- License code under same terms as perl
Business-UTV version 0.01
=========================
This module provides access to UTV Internet account information.
Specifically it enables you to programmatically retrieve
your current monthly download/upload usage and call details
from your monthly phone bill.
A gnome2 tray icon is provided that allows you to monitor
you monthly usage without going to the UTV website.
By definition I have only tested this module against my own account.
I will endeavour to support other account configurations where possible.
INSTALLATION
bin/utv_usage_applet.pl view on Meta::CPAN
my $name = "";
my $label;
my $utv = Business::UTV->login( $id , $password , { "name" => $name } );
if( $utv )
{
my $usage = $utv->usage();
if( $usage )
{
print "Upload - " . $usage->{"upload"} . "\n";
print "Download - " . $usage->{"download"} . "\n";
Gtk2->init();
my $icon = Gtk2::TrayIcon->new( "utv broadband usage notification" );
$label = Gtk2::Label->new( "loading" );
$icon->add( $label );
update_text();
$icon->show_all;
Glib::Timeout->add ( 3600000 , \&update_text );
bin/utv_usage_applet.pl view on Meta::CPAN
}
else
{
print "Login failed :(\n";
exit(1);
}
sub update_text
{
my $usage = $utv->usage();
my $up = $usage->{"upload"};
my $down = $usage->{"download"};
Gtk2::Label::set_text( $label , strftime( "%H:%M" , localtime() ) . " Up " . int($up) . " Down " . int($down ) );
return 1;
}
=head1 NAME
utv_usage_applet.pl - Gnome2 tray icon displaying monthly bandwidth usage
=head1 SYNOPSIS
This script adds a tray icon to your gnome notification area.
The tray icon will display the current monthly upload/download
usage in megabytes of your UTV internet account.
The displayed values will be updated every 60 minutes but
typically the values provided by the utv website only update
every couple of day.
=head1 CONFIGURATION
Currently the script is configured by editing 3 perl variables.
bin/utv_usage_tray.pl view on Meta::CPAN
unless($utv)
{
$utv = Business::UTV->login( $id , $password , { "name" => $name } );
}
if( $utv )
{
my $usage = $utv->usage();
if( $usage )
{
$usage = "up " . int($usage->{"upload"}) . " Down " . int($usage->{"download"});
}
else
{
$usage = "ERROR - " . $Business::UTV::errstr;
}
}
else
{
$usage = "ERROR - " . $Business::UTV::errstr;
}
bin/utv_usage_tray.pl view on Meta::CPAN
=head1 NAME
utv_usage_tray.pl - Windows system tray icon displaying monthly bandwidth usage
=head1 SYNOPSIS
This script adds a tray icon to your system tray.
When the mouse pointer hovers over it the tray icon will display the current
monthly upload/download usage in megabytes of your UTV internet account.
To remove the icon right click on it and select quit.
The displayed values will be updated every 60 minutes but
typically the values provided by the utv website only update
every couple of day.
=head1 CONFIGURATION
Currently the script is configured by editing 4 perl variables.
lib/Business/UTV.pm view on Meta::CPAN
bless( \%self , $class );
}
sub usage
{
my ( $self ) = @_;
errstr( "" );
my $upload;
my $download;
my $usage_request = $self->{"ua"}->get( $self->{"usage_url"} );
if( $usage_request->is_error() )
{
errstr( "Usage failed : http problem" );
return undef;
}
my $usage = $usage_request->content();
if( $usage =~ /Incoming:\s*(\d+(\.\d+)?)MB/ )
{
$upload = $1;
}
if( $usage =~ /Outgoing:\s*(\d+(\.\d+)?)MB/ )
{
$download = $1;
}
if( defined($upload) && defined($download) )
{
return { "upload" => $upload , "download" => $download };
}
else
{
errstr( "Could not retrieve upload and download usage" );
return undef;
}
}
sub current_statement
{
my ( $self ) = @_;
errstr( "" );
lib/Business/UTV.pm view on Meta::CPAN
=head1 NAME
Business::UTV - Module for retrieiving UTV internet account information
=head1 SYNOPSIS
use Business::UTV;
my $utv = Business::UTV->login( $id , $password , { "name" => "me" } );
my $usage = $utv->usage();
print "Upload = " . $usage->{"upload"} . "MB\n";
=head1 DESCRIPTION
This module enables you to access your UTV account information using perl.
Currently the only supported data is your current monthly upload/download
usage and call data from your latest phone bill.
This module provides the following methods
=head2 login
$utv = Business::UTV->login( $id , $password , { "name" => $name }
The constructor takes your utv id , password and a hash reference
and logs into the utv website. Login is verified be checking the
name of the account holder is correctly returned.
On failure undef is returned and an error message stored in $Business::UTV::errstr
=head2 usage
my $usage = $utv->usage();
print "Upload - " . $usage->{"upload"} . "\n";
print "Download - " . $usage->{"download"} . "\n";
This method retrieves the accounts current upload and download in
megabytes as a hash reference.
On failure undef is returned and an error message is stored in $Business::UTV::errstr
=head2 current_statement
my ( $total , $calls ) = $utv->current_statement();
This method returns the total of the latest bill and details of any phone calls.
my $rc = Business::UTV->login( 1 , "not real" , {"name" => "a real post"} );
isa_ok( $rc , "Business::UTV" , "Make sure login succeeds and returns a Business::UTV object" );
is( $Business::UTV::errstr , undef , "Make sure errstr is undef after sucessful login" );
warning_is { $rc->usage() } "Usage failed : http problem" , "Make sure first usage fails as this returns http 500";
is( $Business::UTV::errstr , "Usage failed : http problem" , "Make sure usage failure is recorded in errstr" );
test_failure( "Make sure usage fails as nothing is available" );
test_failure( "Make sure usage fails as only upload is available" );
test_failure( "Make sure usage fails as only download is available" );
test_success( "131.12" , "124.230" , "Make sure spaces are optional and more than one is allowed" );
test_success( "12" , "630.00" , "Make sure integer upload is allowed and trailing 0 is preserved" );
test_success( "12.01" , "98" , "Make sure integer download is allowed" );
test_success( "0" , "0" , "Make sure zero upload and download is allowed" );
sub test_failure
{
my ( $test ) = @_;
warning_is { $rc->usage() } "Could not retrieve upload and download usage" , $test;
is( $Business::UTV::errstr , "Could not retrieve upload and download usage" , "Making sure usage failure is recorded in errstr" );
}
sub test_success
{
my ( $upload , $download ) = @_;
my $usage = $rc->usage();
isnt( $usage , undef , "Make sure successful return from usage is not undef" );
is( ref( $usage ) , "HASH" , "Make sure successful return from usage is a hash" );
ok( $usage->{"upload"} == $upload , "Make sure upload is == $upload" );
ok( $usage->{"upload"} eq $upload , "Make sure upload is eq $upload" );
ok( $usage->{"download"} == $download , "Make sure download == $download" );
ok( $usage->{"download"} eq $download , "Make sure download eq $download" );
is( $Business::UTV::errstr , undef , "Make sure errstr is reset on success" );
}
( run in 0.788 second using v1.01-cache-2.11-cpan-b16cb0d3907 )