Changeset 1535

Show
Ignore:
Timestamp:
03/31/05 20:35:19
Author:
miyagawa
Message:

0.02

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • XML-Atom-Lifeblog/trunk/Changes

    r1529 r1535  
    11Revision history for Perl extension XML::Atom::Lifeblog 
     2 
     30.02  Thu Mar 31 20:29:05 JST 2005 
     4        * Added non-image files like video/3gpp post 
     5        (Thanks to Ben Trott) 
     6        - Depreciated scalarref post: No way to figure out magic of 3gpp 
     7 
    28 
    390.01  Tue Mar 29 14:35:16 2005 
  • XML-Atom-Lifeblog/trunk/Makefile.PL

    r1529 r1535  
    55    'PREREQ_PM' => { 
    66        Test::More => 0.32, 
    7         Image::Info => 0, 
     7        MIME::Types => 0, 
    88        XML::Atom => 0.11, 
    99    }, 
  • XML-Atom-Lifeblog/trunk/lib/XML/Atom/Lifeblog.pm

    r1529 r1535  
    33use strict; 
    44use vars qw($VERSION); 
    5 $VERSION = '0.01'; 
     5$VERSION = '0.02'; 
    66 
    77use Encode; 
     8use File::Basename; 
     9use MIME::Types; 
    810use XML::Atom::Client; 
    911use XML::Atom::Entry; 
    10 use Image::Info qw(image_info); 
    1112use base qw(XML::Atom::Client); 
    1213 
    1314sub postLifeblog { 
    14     my($self, $post_uri, $title, $body, $image) = @_; 
    15     my($content, $image_title); 
    16     if (ref($image) && ref($image) eq 'SCALAR') { 
    17         $content     = $$image; 
    18         $image_title = $title; 
    19     } else { 
    20         require File::Basename; 
    21         local $/; 
    22         open my $fh, $image or return $self->error("$image: $!"); 
    23         $content = <$fh>; 
    24         $image_title = File::Basename::basename($image); 
     15    my($self, $post_uri, $title, $body, $media) = @_; 
     16    my($content, $media_title); 
     17    if (ref($media)) { 
     18        return $self->error("post scalarref is now depreciated."); 
    2519    } 
    2620 
    27     my $mime_type = image_info(\$content)->{file_media_type}; 
    28     my $atom_image   = $self->_create_image($image_title, $content, $mime_type); 
    29     my $posted_image = $self->_post_entry($post_uri, $atom_image); 
    30     my $atom_body    = $self->_create_body($title, $body, $posted_image->id, $mime_type); 
     21    # XXX should it support chunked POST? 
     22    local $/; 
     23    open my $fh, $media or return $self->error("$media: $!"); 
     24    $content = <$fh>; 
     25    $media_title = File::Basename::basename($media); 
     26 
     27    my $mime_type  = $self->_guess_mime_type($media); 
     28    my $atom_media = $self->_create_media($media_title, $content, $mime_type); 
     29    my $posted = $self->_post_entry($post_uri, $atom_media) 
     30        or return $self->error("POST ($media) failed: " . $self->errstr); 
     31    my $atom_body = $self->_create_body($title, $body, $posted->id, $mime_type); 
    3132    return $self->_post_entry($post_uri, $atom_body); 
    3233} 
    3334 
    34 sub _create_image { 
    35     my($self, $image_title, $content, $mime_type) = @_; 
     35sub _guess_mime_type { 
     36    my($self, $media) = @_; 
     37    # MIME::Types doesn't support 3gpp 
     38    if ($media =~ /\.3gpp?$/) { 
     39        # XXX what about audio/3gpp? 
     40        return "video/3gpp"; 
     41    } else { 
     42        my $mime = MIME::Types->new->mimeTypeOf($media); 
     43        return $mime ? $mime->type : "application/octet-stream"; 
     44    } 
     45
     46 
     47sub _create_media { 
     48    my($self, $media_title, $content, $mime_type) = @_; 
    3649 
    3750    my $entry = XML::Atom::Entry->new(); 
    38     $entry->title($image_title); 
     51    $entry->title($media_title); 
    3952    $entry->content($content); 
    4053    $entry->content->type($mime_type); 
     
    110123=head1 postLifeblog 
    111124 
    112   my $entry = $client->postLifeblog($PostURI, $title, $body, $image); 
     125  my $entry = $client->postLifeblog($PostURI, $title, $body, $media); 
    113126 
    114127Creates a new Lifeblog entry and post it to a Lifeblog aware server 
    115 using C<< <standalone> >> element. C<$image> is either a filename as 
    116 a scalar or an image binary as a scalarref. 
     128using C<< <standalone> >> element. C<$image> is a filepath of image or video files to be posted. 
    117129 
    118130Returns XML::Atom::Entry object for the posted entry. 
  • XML-Atom-Lifeblog/trunk/t/01_live.t

    r1529 r1535  
    1414my($uri, $user, $pass) = split /\|/, $ENV{LIFEBLOG_API}; 
    1515 
    16 use LWP::Simple; 
    17 my $image = get "http://blog.bulknews.net/me.jpg"; 
    18  
    1916my $client = XML::Atom::Lifeblog->new(); 
    2017$client->username($user); 
    2118$client->password($pass); 
    2219 
    23 my $entry = $client->postLifeblog($uri, "Hello", "This is me", \$image); 
     20use LWP::Simple qw(mirror); 
     21my $tmp = "t/me.jpg"; 
     22mirror "http://blog.bulknews.net/me.jpg" => $tmp; 
    2423 
     24my $entry = $client->postLifeblog($uri, "Hello", "This is me", $tmp); 
    2525ok $entry->link->href, $entry->link->href; 
    2626 
     27$tmp = "t/jedi.3gp"; 
     28mirror "http://joi.ito.com/images/jedi.3gp" => $tmp; 
    2729 
     30$entry = $client->postLifeblog($uri, "Hello", "From Joi", $tmp) or warn $client->errstr; 
     31ok $entry->link->href, $entry->link->href; 
     32 
     33END { unlink $_ for qw(t/me.jpg t/jedi.3gp) }; 
     34 
     35 
     36