/[Frey]/trunk/lib/Data/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/Data/DelIcioUs.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 226 - (show annotations)
Sat Nov 1 01:03:40 2008 UTC (15 years, 4 months ago) by dpavlin
File size: 1139 byte(s)
simple data provider for del.icio.us

It required much more manual tweaking than I liked, mostly
because of plain http authentification. It probably not
utf-8 safe yet.
1 package Data::DelIcioUs;
2 use Moose;
3
4 with 'Frey::Config';
5 with 'Frey::Storage';
6
7 has 'username' => (
8 is => 'rw',
9 isa => 'Str',
10 required => 1,
11 default => sub {
12 my $self = shift;
13 $self->config->{username};
14 },
15 );
16
17 has 'password' => (
18 is => 'rw',
19 isa => 'Str',
20 required => 1,
21 default => sub {
22 my $self = shift;
23 $self->config->{password};
24 },
25 );
26
27 has 'path' => (
28 is => 'ro',
29 isa => 'Str',
30 default => sub {
31 my $self = shift;
32 'var/delicious/' . $self->username;
33 }
34 );
35
36 use LWP::UserAgent;
37 use XML::Simple;
38 use Data::Dump qw/dump/;
39
40 sub data {
41 my $self = shift;
42
43 if ( my $posts = $self->load( $self->path ) ) {
44 return $posts;
45 }
46
47 my $ua = LWP::UserAgent->new;
48 my $req = HTTP::Request->new(GET => 'https://api.del.icio.us/v1/posts/all');
49 $req->authorization_basic( $self->username, $self->password );
50 my $content = $ua->request($req)->as_string;
51 warn "# got ",length($content), " bytes";
52
53 # strip headers
54 $content =~ s/^.+(<\?xml)/$1/s;
55 warn substr($content,0,100), ' ... ', substr($content,-100);
56 my $posts = XMLin( $content );
57 warn dump( $posts );
58 $self->store( $self->path, $posts );
59 return $posts;
60 }
61
62 1;

  ViewVC Help
Powered by ViewVC 1.1.26