WWW::Twitpic::API::Response - A response from Twitpic


WWW-Twitpic documentation Contained in the WWW-Twitpic distribution.

Index


Code Index:

NAME

Top

WWW::Twitpic::API::Response - A response from Twitpic

SYNOPSIS

Top

METHODS

Top

is_success

    Boolean flag to check the response status.

    You can check the error() message when false. 

error

    Returns the error message if any.

id

    The id asigned to the uploaded image.

url

    The URI for the uploaded image.

url_thumb

    The URI of the generated thumbnail for the uploaded image.

url_mini

    The URI of the generated mini-view for the uploaded image.

xml

    The response xml source.

struct

    The respnse href struct.

_resize_uri

    Helper method to generate rezize uri's

meta See Moose. =cut

AUTHOR

Top

Diego Kuperman, <diego at freekeylabs.com>

BUGS

Top

Please report any bugs or feature requests to bug-www-twitpic-api at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WWW-Twitpic. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc WWW::Twitpic




You can also look for information at:

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=WWW-Twitpic

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/WWW-Twitpic

* CPAN Ratings

http://cpanratings.perl.org/d/WWW-Twitpic

* Search CPAN

http://search.cpan.org/dist/WWW-Twitpic

ACKNOWLEDGEMENTS

Top

COPYRIGHT & LICENSE

Top


WWW-Twitpic documentation Contained in the WWW-Twitpic distribution.
package WWW::Twitpic::API::Response;
use Moose;

use XML::Simple qw( XMLin );

has 'xml' => (
    is      => 'rw',
    isa     => 'Str',
    trigger => sub { $_[0]->struct( XMLin( $_[1] ) ) }
);

has 'struct' => (
    is        => 'rw',
    isa       => 'HashRef',
);

sub is_success {
    my $self = shift; 
    
    if ( my $status = $self->struct->{'status'} || $self->struct->{'stat'} ) {
        return $status eq 'ok';
    }
    return 0;
}

sub error {
    my $self = shift; 

    unless ( $self->is_success ) {
        if ( exists $self->struct->{'err'}{msg} ) {
            return $self->struct->{'err'}{msg};
        }
    }

    return undef;
}

sub id {
    my $self = shift;
    
    return $self->is_success ? $self->struct->{mediaid} : undef; 
}

sub url {
    my $self = shift;
    
    return $self->is_success ? URI->new( $self->struct->{mediaurl} ) : undef; 
}

sub url_thumb { $_[0]->_resize_uri('thumb'); }

sub url_mini  { $_[0]->_resize_uri('mini'); }

sub _resize_uri {
    my ( $self, $size ) = @_;
    $size ||= 'thumb';

    return $self->is_success
        ? URI->new( 'http://twitpic.com/show/' . $size . '/' . $self->id )
        : undef;
}

1;