Created
March 31, 2010 19:50
-
-
Save btrott/350788 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
use strict; | |
use IO::Prompt; | |
use Try::Tiny; | |
use WWW::TypePad; | |
use WWW::TypePad::CmdLine; | |
my $tp = WWW::TypePad::CmdLine->initialize( requires_auth => 1 ); | |
# Fetch the list of the authenticated user's blogs, then put up a prompt | |
# asking the user to choose a blog. | |
my $blogs = $tp->users->blogs( '@self' ); | |
my $tp_blog_id = prompt( 'Choose a TypePad blog: ', -menu => { | |
map { $_->{title} => $_->{urlId} } @{ $blogs->{entries} } | |
} ); | |
die "You need to choose a TypePad blog" unless $tp_blog_id; | |
my $post = { | |
title => 'Test Post', | |
content => '<p>hi</p>', | |
textFormat => 'html', | |
}; | |
my $obj; | |
try { | |
$obj = $tp->blogs->new_post_asset( $tp_blog_id, $post ); | |
} catch { | |
if ( UNIVERSAL::isa( $_, 'WWW::TypePad::Error::HTTP' ) ) { | |
die sprintf "Error posting: %s (%d)", $_->content, $_->code; | |
} else { | |
die $_; | |
} | |
}; | |
print $obj->{permalinkUrl}, "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment