/[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 425 - (show annotations)
Tue Nov 18 23:24:53 2008 UTC (15 years, 5 months ago) by dpavlin
File size: 1362 byte(s)
documentation
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 documentation => 'login on del.icio.us',
15 );
16
17 has 'password' => (
18 is => 'ro',
19 isa => 'Str',
20 required => 1,
21 );
22
23 sub path {
24 my $self = shift;
25 'var/delicious/' . $self->username . '.yml';
26 }
27
28 sub posts {
29 my $self = shift;
30
31 if ( my $posts = $self->load( $self->path ) ) {
32 return $posts;
33 }
34
35 my $ua = LWP::UserAgent->new;
36 my $req = HTTP::Request->new(GET => 'https://api.del.icio.us/v1/posts/all');
37 $req->authorization_basic( $self->username, $self->password );
38 my $content = $ua->request($req)->as_string;
39 warn "# got ",length($content), " bytes";
40
41 # strip headers
42 $content =~ s/^.+(<\?xml)/$1/s;
43 warn substr($content,0,100), ' ... ', substr($content,-100);
44 my $posts = XMLin( $content );
45 warn dump( $posts );
46 $self->store( $self->path, $posts );
47 return $posts;
48 }
49
50 sub data {
51 my $self = shift;
52 $self->posts;
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