File Coverage

blib/lib/WWW/Phanfare/Class.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             package WWW::Phanfare::Class;
2 1     1   26359 use Moose;
  0            
  0            
3             use MooseX::Method::Signatures;
4             use WWW::Phanfare::Class::CacheAPI;
5             use WWW::Phanfare::API;
6             use WWW::Phanfare::Class::Account;
7              
8             has 'api_key' => ( is=>'ro', isa=>'Str', required=>1 );
9             has 'private_key' => ( is=>'ro', isa=>'Str', required=>1 );
10             has 'email_address' => ( is=>'ro', isa=>'Str' );
11             has 'password' => ( is=>'ro', isa=>'Str' );
12             sub _childclass { 'WWW::Phanfare::Class::Account' }
13              
14             # Initialize account
15             has 'account' => (
16             is => 'ro',
17             isa => 'WWW::Phanfare::Class::Account',
18             lazy_build => 1,
19             );
20             sub _build_account {
21             my $self = shift;
22              
23             my $api = $self->api;
24              
25             # Login to create session
26             my $session;
27             if ( $self->email_address and $self->password ) {
28             $session = $api->Authenticate(
29             email_address => $self->email_address,
30             password => $self->password,
31             );
32             } else {
33             $session = $api->AuthenticateGuest();
34             }
35              
36             warn sprintf "*** Error: Could not login: %s\n", $session->{code_value}
37             unless $session->{stat} eq 'ok';
38              
39             # Create account object with session data
40             #my $account = WWW::Phanfare::Class::Account->new(
41             my $type = $self->_childclass;
42             my $account = $type->new(
43             uid => $session->{session}{uid},
44             gid => $session->{session}{public_group_id},
45             parent => $self,
46             name => '',
47             id => 0,
48             );
49             $account->setattributes( $session->{session} );
50             return $account;
51             }
52              
53             # Initialize API
54             has api => (
55             isa => 'WWW::Phanfare::API',
56             is => 'rw',
57             lazy_build => 1,
58             );
59             sub _build_api {
60             my $self = shift;
61              
62             # Create an API Agent
63             WWW::Phanfare::Class::CacheAPI->new(
64             api_key => $self->api_key,
65             private_key => $self->private_key,
66             );
67             }
68              
69              
70             # Get a subnode, by name of name.id
71             #
72             method get ( Str $name ) {
73             $self->account->list;
74             }
75              
76             sub AUTOLOAD {
77             my $self = shift @_;
78             our $AUTOLOAD;
79              
80             my $name = $AUTOLOAD;
81             $name =~ s/.*:://;
82              
83             return $self->get($name);
84             }
85              
86              
87             =head1 NAME
88              
89             WWW::Phanfare::Class - Object interface to Phanfare library
90              
91             =head1 VERSION
92              
93             Version 0.03
94              
95             =cut
96              
97             our $VERSION = '0.03';
98              
99             =head1 SYNOPSIS
100              
101             use WWW::Phanfare::Class;
102              
103             $class = WWW::Phanfare::Class->new(
104             api_key => 'secret',
105             private_key => 'secret',
106             email_address => 's@c.et',
107             password => 'secret',
108             );
109              
110             # Site Name
111             my($sitename) = $class->account->names;
112              
113             # Site Object
114             my $site = $class->account->$sitename;
115              
116             # Album Names
117             my @albums = $site->names;
118              
119             # Photo filenames in Album's Main Section
120             my @filenames = $site->"Family Vacation"->"Main Section"->Full->names;
121              
122             # Upload Image and set Caption
123             my $folder = $site->"Family Vacation"->"Main Section"->Full;
124             my $image = $folder->add( 'filename.jpg', slurp 'filename.jpg', '2009-09-15T00:00:00' );
125             $image->attribute( Caption => 'Family on Vacation' );
126              
127              
128             =head1 DESCRIPTION
129              
130             WWW::Phanfare::Class creates an object tree for Phanfare site. Each
131             Phanfare object can be referred to by name or by object reference.
132              
133              
134             =head1 BEFORE GETTING STARTED
135              
136             Users of this module must possess own Phanfare account and API key.
137              
138              
139             =head1 TREE HIERARKI
140              
141             Class is the top object and it has one Account to access data using
142             Phanfare API.
143              
144             The tree hierarki is as follows:
145              
146             =over
147              
148             An Account has a nuber of Sites.
149             A Site has a number of Years.
150             A Year has a number of Albums.
151             An Album has a number of Sections.
152             A Section has a number of Renditions.
153             A Rendition has a number of Images.
154              
155             =back
156              
157              
158             =head1 NAME CLASH
159              
160             In Phanfare it's possible for multiple objects to have same name. For example
161             multi albums can have same name. In such cases WWW::Phanfare::Class will
162             append the id on the names that are not uniq. Example:
163              
164             Kids Photos
165             Family Vacation.12345678
166             Family Vacation.12345789
167              
168              
169             =head1 METHODS
170              
171             Each object implements the following methods.
172              
173             =head2 parent
174              
175             $object->parent();
176              
177             The parent object.
178              
179             =head2 names
180              
181             my @childrennames = $object->names;
182              
183             The names of child objects. For example for an Album it will return the
184             names of all sections.
185              
186             =head2 list
187              
188             my @children_objects = $object->list;
189              
190             All child objects.
191              
192             =head2 get($name)
193              
194             my $child = $object->get($name);
195             my $child = $object->$name;
196              
197             Access child object by name. Append ID when there is a name clash.
198              
199             If no ID is appended on name clash, then a random matching object is
200             returned.
201              
202             =head2 add($name, $value?, $date?)
203              
204             # Create Branch Node
205             $object->add($name);
206              
207             # Create Leaf Node
208             $object->add($name, $value);
209              
210             # Create Image with Date
211             $object->add($name, $value, $date);
212              
213             Create a new child object. When creating a Branch, such as for example an
214             Album, no value must be set.
215              
216             For Images, a value can be provided, which is the raw image data.
217             Date may be optionally provided as well.
218              
219             =head2 remove($name)
220              
221             $object->remove($name);
222              
223             Remove a child object by name. For certain objects it
224             removes all child objects recursive. For example when removing an Album,
225             it will also remove all Sections and Images belonging to Album.
226              
227             Removing a Year is not possible as long as there are Albums in the Year.
228             The Year will be automatically remove when all Albums in the Year have
229             been removed.
230              
231             Site and Account cannot be removed.
232              
233              
234             =head1 ATTRIBUTES
235              
236             Account. Album, Section and Image objects have attributes.
237              
238             For classes with attributes, the follow addition attribute accessors are
239             available to the object.
240              
241             =head2 attributes
242              
243             @attribute_names = $object->attributes;
244              
245             List of names of attributes.
246              
247             =head2 setattributes($hashreference)
248              
249             $object->setattributes({
250             name1 => $value1,
251             name2 => $value2,
252             ... => ...,
253             });
254              
255             Set values of multiple attributes.
256              
257             =head2 attribute($name, $value?)
258              
259             $object->attribute( $name => $value );
260             $value = $object->attribute( $name );
261              
262             Read or write an attribute value.
263              
264              
265             =head1 VALUE
266              
267             Image raw data is uploaded or downloaded with value accessor.
268             No other object have value.
269              
270             =head2 value($data?)
271              
272             $image = slurp 'filename.jpg';
273             $object->value( $image );
274             $image = $object->value;
275              
276             Get or set image data.
277              
278             Images can only be upload in Full rendition. All other renditions are
279             for download only.
280              
281             =head1 DATES
282              
283             Dates follow same formats as on Phanfare. Example:
284              
285             2009-09-15T00:00:00
286              
287              
288             =head1 PERFORMANCE CONSIDERATIONS
289              
290             WWW::Phanfare::API is used for communication with Phanfare Rest/XML API.
291             Results of queries are each cached for 30 seconds to limit network traffic
292             and to improve performance.
293              
294              
295             =head1 SEE ALSO
296              
297             L<WWW::Phanfare::API>
298              
299              
300             =head1 AUTHOR
301              
302             Soren Dossing, C<< <netcom at sauber.net> >>
303              
304              
305             =head1 BUGS
306              
307             Please report any bugs or feature requests to C<bug-www-phanfare-class at rt.cpan.org>, or through
308             the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WWW-Phanfare-Class>. I will be notified, and then you'll
309             automatically be notified of progress on your bug as I make changes.
310              
311              
312             =head1 SUPPORT
313              
314             You can find documentation for this module with the perldoc command.
315              
316             perldoc WWW::Phanfare::Class
317              
318              
319             You can also look for information at:
320              
321             =over 4
322              
323             =item * RT: CPAN's request tracker
324              
325             L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=WWW-Phanfare-Class>
326              
327             =item * AnnoCPAN: Annotated CPAN documentation
328              
329             L<http://annocpan.org/dist/WWW-Phanfare-Class>
330              
331             =item * CPAN Ratings
332              
333             L<http://cpanratings.perl.org/d/WWW-Phanfare-Class>
334              
335             =item * Search CPAN
336              
337             L<http://search.cpan.org/dist/WWW-Phanfare-Class/>
338              
339             =back
340              
341              
342             =head1 ACKNOWLEDGEMENTS
343              
344              
345             =head1 LICENSE AND COPYRIGHT
346              
347             Copyright 2011 Soren Dossing.
348              
349             This program is free software; you can redistribute it and/or modify it
350             under the terms of either: the GNU General Public License as published
351             by the Free Software Foundation; or the Artistic License.
352              
353             See http://dev.perl.org/licenses/ for more information.
354              
355             =cut
356              
357             1;