/[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 606 - (show annotations)
Fri Nov 28 22:22:07 2008 UTC (15 years, 4 months ago) by dpavlin
File size: 1384 byte(s)
cleanup dependencies
1 package Frey::DelIcioUs;
2 use Moose;
3
4 extends 'Frey';
5 with 'Frey::Storage';
6
7 use LWP::UserAgent;
8 use XML::Simple;
9 use Data::Dump qw/dump/;
10
11 has 'username' => (
12 is => 'rw',
13 isa => 'Str',
14 required => 1,
15 documentation => 'login on del.icio.us',
16 );
17
18 has 'password' => (
19 is => 'ro',
20 isa => 'Str',
21 required => 1,
22 );
23
24 sub path {
25 my $self = shift;
26 'var/delicious/' . $self->username . '.yml';
27 }
28
29 sub posts {
30 my $self = shift;
31
32 if ( my $posts = $self->load( $self->path ) ) {
33 return $posts;
34 }
35
36 my $ua = LWP::UserAgent->new;
37 my $req = HTTP::Request->new(GET => 'https://api.del.icio.us/v1/posts/all');
38 $req->authorization_basic( $self->username, $self->password );
39 my $content = $ua->request($req)->as_string;
40 warn "# got ",length($content), " bytes";
41
42 # strip headers
43 $content =~ s/^.+(<\?xml)/$1/s;
44 warn substr($content,0,100), ' ... ', substr($content,-100);
45 my $posts = XMLin( $content );
46 warn dump( $posts );
47 $self->store( $self->path, $posts );
48 return $posts;
49 }
50
51 sub as_data {
52 my $self = shift;
53 $self->posts;
54 }
55
56 sub as_sponge {
57 my $self = shift;
58
59 my $posts = $self->posts->{post};
60 die "not ARRAY ",dump( $posts ) unless ref($posts) eq 'ARRAY';
61
62 my @NAME = keys %{ $posts->[0] };
63 my @rows;
64
65 foreach my $post ( @$posts ) {
66 my @row;
67 push @row, $post->{ $_ } foreach @NAME;
68 push @rows, \@row;
69 }
70
71
72 return {
73 rows => \@rows,
74 NAME => \@NAME,
75 }
76 }
77
78 1;

  ViewVC Help
Powered by ViewVC 1.1.26