/[Frey]/branches/zimbardo/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

Annotation of /branches/zimbardo/lib/Frey/DelIcioUs.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 333 - (hide annotations)
Sat Nov 8 16:59:08 2008 UTC (15 years, 6 months ago) by dpavlin
Original Path: trunk/lib/Frey/DelIcioUs.pm
File size: 928 byte(s)
path is really accessor and not attribute
1 dpavlin 315 package Frey::DelIcioUs;
2 dpavlin 226 use Moose;
3    
4     with 'Frey::Storage';
5    
6 dpavlin 323 use LWP::UserAgent;
7     use XML::Simple;
8     use Data::Dump qw/dump/;
9    
10 dpavlin 226 has 'username' => (
11     is => 'rw',
12     isa => 'Str',
13     required => 1,
14     );
15    
16     has 'password' => (
17 dpavlin 323 is => 'ro',
18 dpavlin 226 isa => 'Str',
19     required => 1,
20     );
21    
22 dpavlin 333 sub path {
23     my $self = shift;
24     'var/delicious/' . $self->username;
25     }
26 dpavlin 226
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 dpavlin 323 $self->store( $self->path . '.yml', $posts );
46 dpavlin 226 return $posts;
47     }
48    
49     1;

  ViewVC Help
Powered by ViewVC 1.1.26