/[Frey]/trunk/lib/Frey/DelIcioUs.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/lib/Frey/DelIcioUs.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 333 - (show annotations)
Sat Nov 8 16:59:08 2008 UTC (15 years, 5 months ago) by dpavlin
File size: 928 byte(s)
path is really accessor and not attribute
1 package Frey::DelIcioUs;
2 use Moose;
3
4 with 'Frey::Storage';
5
6 use LWP::UserAgent;
7 use XML::Simple;
8 use Data::Dump qw/dump/;
9
10 has 'username' => (
11 is => 'rw',
12 isa => 'Str',
13 required => 1,
14 );
15
16 has 'password' => (
17 is => 'ro',
18 isa => 'Str',
19 required => 1,
20 );
21
22 sub path {
23 my $self = shift;
24 'var/delicious/' . $self->username;
25 }
26
27 sub data {
28 my $self = shift;
29
30 if ( my $posts = $self->load( $self->path ) ) {
31 return $posts;
32 }
33
34 my $ua = LWP::UserAgent->new;
35 my $req = HTTP::Request->new(GET => 'https://api.del.icio.us/v1/posts/all');
36 $req->authorization_basic( $self->username, $self->password );
37 my $content = $ua->request($req)->as_string;
38 warn "# got ",length($content), " bytes";
39
40 # strip headers
41 $content =~ s/^.+(<\?xml)/$1/s;
42 warn substr($content,0,100), ' ... ', substr($content,-100);
43 my $posts = XMLin( $content );
44 warn dump( $posts );
45 $self->store( $self->path . '.yml', $posts );
46 return $posts;
47 }
48
49 1;

  ViewVC Help
Powered by ViewVC 1.1.26