/[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 425 - (hide annotations)
Tue Nov 18 23:24:53 2008 UTC (15 years, 6 months ago) by dpavlin
File size: 1362 byte(s)
documentation
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 dpavlin 425 documentation => 'login on del.icio.us',
15 dpavlin 226 );
16    
17     has 'password' => (
18 dpavlin 323 is => 'ro',
19 dpavlin 226 isa => 'Str',
20     required => 1,
21     );
22    
23 dpavlin 333 sub path {
24     my $self = shift;
25 dpavlin 337 'var/delicious/' . $self->username . '.yml';
26 dpavlin 333 }
27 dpavlin 226
28 dpavlin 337 sub posts {
29 dpavlin 226 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 dpavlin 337 $self->store( $self->path, $posts );
47 dpavlin 226 return $posts;
48     }
49    
50 dpavlin 337 sub data {
51     my $self = shift;
52 dpavlin 352 $self->posts;
53 dpavlin 337 }
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 dpavlin 226 1;

  ViewVC Help
Powered by ViewVC 1.1.26