randomfox (randomfox) wrote,

Adocu client in Perl script

Adocu is a nanoblogging service. It is similar to Twitter, except that it limits your status update to one word. This script posts a status to Adocu. See the embedded POD at the end of the script for details on Adocu login configuration.

# Client for Adocu.
# This script posts a one-word status to Adocu.

use strict;
use LWP::UserAgent; 
use MIME::Base64;
use Config::Auto;

my $config_fname = "adocu.conf";

# Get information from config file.
sub get_config {
    my $config = Config::Auto::parse($config_fname, format=>'equal');

    (defined $config->{login}) or die "Please define login in $config_fname\n";
    ($config->{login}, $config->{proxy}, $config->{proxylogin});

# Post a status to Adocu.
sub post_adocu {
    my ($login, $proxy, $proxylogin, $status) = @_;

    my $ua = new LWP::UserAgent;

    defined $proxy and $ua->proxy('http', "http://$proxy");

    $login =~ /:/ and $login = encode_base64($login);
    $ua->default_header('Authorization' => "Basic $login");

    if (defined $proxylogin) {
	$proxylogin =~ /:/ and $proxylogin = encode_base64($proxylogin);
	$ua->default_header('Proxy-Authorization' => "Basic $proxylogin");

    # Post status to Adocu.
    my $response = $ua->post("http://adocu.com/api/status.xml", 
	{ 'msg'=>$status });
    $response->is_success or die $response->status_line."\n";

    print "Response from Adocu: ", $response->content, "\n";

my ($login, $proxy, $proxylogin) = get_config();

@ARGV >= 1 or die "Usage: $0 status\n";
my $status = shift;

post_adocu($login, $proxy, $proxylogin, $status);


=head1 NAME

Adocu.pl - Post a status to Adocu.


adocu.pl I<status>


Adocu is a nanoblogging service at L<http://adocu.com>. It differs from microblogging services in that Adocu limits you to one word when posting your status. This script posts a one-word status to Adocu.

Before using this script, you need to set your Adocu login information in C<adocu.conf>. If you're using a HTTP proxy, you can set proxy and proxy login (if necessary) information in that file too.

C<adocu.conf> may be placed in any location accepted by Config::Auto. See L<Config::Auto> for more information.

The format of adocu.conf is as follows:

    login = user:password
    proxy = proxyserver:proxyport
    proxylogin = proxyuser:proxypassword

If desired, the C<user:password> and C<proxyuser:proxypassword> strings may be Base64 encoded.

=head1 AUTHOR

Po Shan Cheah (morton@mortonfox.com) L<http://www.mortonfox.com>


Comments for this post were disabled by the author