/[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 337 - (show annotations)
Sat Nov 8 23:22:03 2008 UTC (15 years, 5 months ago) by dpavlin
File size: 1337 byte(s)
fix cacheing, produce sponge data for DBD::Sponge
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 . '.yml';
25 }
26
27 sub posts {
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, $posts );
46 return $posts;
47 }
48
49 sub data {
50 my $self = shift;
51 # $self->posts;
52 $self->sponge;
53 }
54
55 sub sponge {
56 my $self = shift;
57
58 my $posts = $self->posts->{post};
59 die "not ARRAY ",dump( $posts ) unless ref($posts) eq 'ARRAY';
60
61 my @NAME = keys %{ $posts->[0] };
62 my @rows;
63
64 foreach my $post ( @$posts ) {
65 my @row;
66 push @row, $post->{ $_ } foreach @NAME;
67 push @rows, \@row;
68 }
69
70
71 return {
72 rows => \@rows,
73 NAME => \@NAME,
74 }
75 }
76
77 1;

  ViewVC Help
Powered by ViewVC 1.1.26