/[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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 323 - (hide annotations)
Thu Nov 6 17:58:20 2008 UTC (15 years, 6 months ago) by dpavlin
File size: 985 byte(s)
finish rename from Data::DelIcioUs to Frey::DelIcioUs and
remove Frey::Config from it because it's used by Frey::Run as
it should.
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     has 'path' => (
23     is => 'ro',
24     isa => 'Str',
25     default => sub {
26     my $self = shift;
27     'var/delicious/' . $self->username;
28     }
29     );
30    
31     sub data {
32     my $self = shift;
33    
34     if ( my $posts = $self->load( $self->path ) ) {
35     return $posts;
36     }
37    
38     my $ua = LWP::UserAgent->new;
39     my $req = HTTP::Request->new(GET => 'https://api.del.icio.us/v1/posts/all');
40     $req->authorization_basic( $self->username, $self->password );
41     my $content = $ua->request($req)->as_string;
42     warn "# got ",length($content), " bytes";
43    
44     # strip headers
45     $content =~ s/^.+(<\?xml)/$1/s;
46     warn substr($content,0,100), ' ... ', substr($content,-100);
47     my $posts = XMLin( $content );
48     warn dump( $posts );
49 dpavlin 323 $self->store( $self->path . '.yml', $posts );
50 dpavlin 226 return $posts;
51     }
52    
53     1;

  ViewVC Help
Powered by ViewVC 1.1.26