| WWW-TarPipe documentation | Contained in the WWW-TarPipe distribution. |
WWW::TarPipe - An interface to tarpipe.com's REST based web service.
This document describes WWW::TarPipe version 0.01
use WWW::TarPipe;
my $tp = WWW::TarPipe->new(
key => '77c38f56696963fa13f5b6cd97a2556c'
);
$tp->upload(
title => 'The outside temperature is 27C'
);
tarpipe.com is a publishing mediation and distribution platform that simplifies regular upload activities:
You can learn more by visiting http://tarpipe.com/.
newCreate a new WWW::TarPipe. Accepts a number of key, value pairs. The following arguments are recognised:
base_uriThe base URI for the tarpit REST service. Defaults to
http://rest.receptor.tarpipe.net:8000/
titleThe title of the data being posted.
bodyA larger chunk of text associated with this post such as a blog post.
imageA chunk of binary data - perhaps an image - for this post.
keyThe token generated when you save a REST API workflow.
Any options not passed to new may be passed to a subsequent call
to upload, for example:
my $tp = WWW::TarPipe->new(
key => '77c38f56696963fa13f5b6cd97a2556c'
);
$tp->upload(
title => 'The outside temperature is 27C'
);
is equivalent to
my $tp = WWW::TarPipe->new;
$tp->upload(
key => '77c38f56696963fa13f5b6cd97a2556c',
title => 'The outside temperature is 27C'
);
When making multiple posts to the same workflow it is convenient to
supply unchanging options as arguments to new and pass those that
change to upload.
uploadSend an upload request to the tarpit.com REST service. A number of key,
value argument pairs should be passed. See new above for details
of the arguments that can be specified.
$tp->upload(
key => '77c38f56696963fa13f5b6cd97a2556c',
title => 'Hello, World',
body => "First Post!\nYay me!\n"
);
If the request fails an exception will be thrown.
Each of the options that may be supplied to new and upload
have a corresponding read only accessor.
base_uriThe base URI for the tarput service.
titleThe title of the post.
bodyThe body of the post.
imageArbitrary image data.
keyThe REST key for the workflow.
default_base_uriReturns the default URI for the tarpipe service. May be overridden in
subclasses or by supplying the base_uri option to new or
upload.
WWW::TarPipe requires no configuration files or environment variables.
None.
None reported.
No bugs have been reported.
Please report any bugs or feature requests to
bug-www-tarpipe@rt.cpan.org, or through the web interface at
http://rt.cpan.org.
Andy Armstrong <andy@hexten.net>
Copyright (c) 2008, Andy Armstrong <andy@hexten.net>.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.
| WWW-TarPipe documentation | Contained in the WWW-TarPipe distribution. |
package WWW::TarPipe; use warnings; use strict; use Carp; use LWP::UserAgent;
our $VERSION = '0.01'; my @ATTR; BEGIN { @ATTR = qw( base_uri body image key title ); for my $attr ( @ATTR ) { no strict 'refs'; *$attr = sub { my $self = shift; croak "$attr may not be set" if @_; return $self->{$attr}; }; } }
sub new { my $class = shift; return bless { base_uri => $class->default_base_uri, $class->_check_args( @_ ) }, $class; }
sub upload { my $self = shift; my %args = ( %$self, $self->_check_args( @_ ) ); my $ua = LWP::UserAgent->new; my $uri = delete $args{base_uri} or croak "base_uri must be supplied"; my $key = delete $args{key} or croak "key must be supplied"; my $resp = $ua->post( "$uri?key=$key", Content_Type => 'form-data', Content => \%args ); croak $resp->status_line if $resp->is_error; return $resp->content; } sub _check_args { my $self = shift; croak "Please supply a number of key, value pairs" if @_ % 1; my %args = @_; my %got = (); for my $attr ( @ATTR ) { $got{$attr} = delete $args{$attr} if exists $args{$attr}; } croak "Invalid options: ", join ', ', sort keys %args if keys %args; return %got; }
sub default_base_uri { 'http://rest.receptor.tarpipe.net:8000/' } 1; __END__