1 |
package Frey::DelIcioUs; |
package Frey::DelIcioUs; |
2 |
use Moose; |
use Moose; |
3 |
|
|
4 |
|
extends 'Frey'; |
5 |
with 'Frey::Storage'; |
with 'Frey::Storage'; |
6 |
|
|
7 |
use LWP::UserAgent; |
use LWP::UserAgent; |
12 |
is => 'rw', |
is => 'rw', |
13 |
isa => 'Str', |
isa => 'Str', |
14 |
required => 1, |
required => 1, |
15 |
|
documentation => 'login on del.icio.us', |
16 |
); |
); |
17 |
|
|
18 |
has 'password' => ( |
has 'password' => ( |
23 |
|
|
24 |
sub path { |
sub path { |
25 |
my $self = shift; |
my $self = shift; |
26 |
'var/delicious/' . $self->username; |
'var/delicious/' . $self->username . '.yml'; |
27 |
} |
} |
28 |
|
|
29 |
sub data { |
sub posts { |
30 |
my $self = shift; |
my $self = shift; |
31 |
|
|
32 |
if ( my $posts = $self->load( $self->path ) ) { |
if ( my $posts = $self->load( $self->path ) ) { |
44 |
warn substr($content,0,100), ' ... ', substr($content,-100); |
warn substr($content,0,100), ' ... ', substr($content,-100); |
45 |
my $posts = XMLin( $content ); |
my $posts = XMLin( $content ); |
46 |
warn dump( $posts ); |
warn dump( $posts ); |
47 |
$self->store( $self->path . '.yml', $posts ); |
$self->store( $self->path, $posts ); |
48 |
return $posts; |
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; |
1; |