File Coverage

blib/lib/WWW/Trello/Lite.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1             =pod
2              
3             =head1 NAME
4              
5             WWW::Trello::Lite - Simple wrapper around the Trello web service.
6              
7             =head1 SYNOPSIS
8              
9             # Get the currently open lists from a given board...
10             my $trello = WWW::Trello::Lite->new(
11             key => 'invalidkey',
12             token => 'invalidtoken'
13             );
14             my $lists = $trello->get( "boards/$id/lists" )
15              
16             # Add a new card...
17             $trello->post( "cards", {name => 'New card', idList => $id} );
18              
19             =head1 DESCRIPTION
20              
21             L<Trello|https://www.trello.com> manages lists of I<stuff>.
22             L<Trello|https://www.trello.com> provides an API for remote control.
23             B<WWW::Trello::Lite> provides Perl scripts easy access to the API. I use it
24             to add cards on my to-do list.
25              
26             Translating the Trello API documentation into functional calls is straight
27             forward.
28              
29             # Trello API documentation says:
30             # GET /1/cards/[card_id]
31             my $card = $trello->get( "cards/$id" );
32              
33             The first word (I<GET>, I<POST>, I<PUT>, I<DELETE>) becomes the method call.
34             Ignore the number. That is the Trello API version number. B<WWW::Trello::Lite>
35             handles that for you automatically.
36              
37             The rest of the API URL slides into the first parameter of the method.
38              
39             Some API calls, such as this one, also accept B<Arguments>. Pass the arguments
40             as a hash reference in the second parameter. The argument name is a key. And
41             the argument value is the value.
42              
43             # Trello API documentation says:
44             # GET /1/cards/[card_id]
45             my $card = $trello->get( "cards/$id", {attachments => 'true'} );
46              
47             =cut
48              
49             package WWW::Trello::Lite;
50 1     1   27054 use strict;
  1         3  
  1         35  
51 1     1   5 use warnings;
  1         2  
  1         26  
52              
53 1     1   532 use Moose;
  0            
  0            
54             with 'Role::REST::Client';
55              
56             use 5.008;
57             our $VERSION = '1.00';
58              
59             use URI::Escape;
60              
61              
62             =head1 METHODS & ATTRIBUTES
63              
64             =head3 get / delete / post / put
65              
66             The method name corresponds with the first word in the Trello API
67             documentation. It tells Trello what you are trying to do. Each method expects
68             two parameters:
69              
70             =over
71              
72             =item 1. URL
73              
74             The URL (minus the server name) for the API call. You can also leave off the
75             version number. Begin with the item such as I<boards> or I<cards>.
76              
77             =item 2. arguments
78              
79             An optional hash reference of arguments for the API call. The class
80             automatically adds your development key and token. It is not necessary to
81             include them in the arguments.
82              
83             =back
84              
85             See the corresponding method in L<Role::REST::Client> for information about the
86             return value.
87              
88             =cut
89              
90             around qw/get delete put post/ => sub {
91             my ($original, $self, $url, $arguments, @the_rest) = @_;
92              
93             $arguments = {} unless defined $arguments;
94             $arguments->{key } = $self->key;
95             $arguments->{token} = $self->token;
96              
97             # Only "$api" is part of the URL. The token and key are escaped by the REST
98             # function when it builds the full URL.
99             my $api = uri_escape( $self->version );
100              
101             return $self->$original( "$api/$url", $arguments, @the_rest );
102             };
103              
104              
105             =head3 key
106              
107             This attribute accepts your L<Trello|https://www.trello.com> developer key.
108             L<Trello|https://www.trello.com> requires that all users of the API have a
109             unique key. Please refer to the L<Trello|https://www.trello.com> API
110             documentation to obtain a key.
111              
112             =cut
113              
114             has 'key' => (
115             is => 'rw',
116             isa => 'Str',
117             );
118              
119              
120             =head3 server
121              
122             This attribute holds the URL to the L<Trello|https://www.trello.com> web
123             server. The class sets this for you. You can read the value from this attribute
124             if your code wants to know the URL for some reason.
125              
126             =cut
127              
128             has '+server' => (
129             default => 'https://api.trello.com/',
130             );
131              
132              
133             =head3 token
134              
135             This attribute holds the L<Trello|https://www.trello.com> authorization token.
136             The authorization token tells L<Trello|https://www.trello.com> that this script
137             can modify your boards and lists.
138              
139             For example, I use these scripts in C<cron> jobs. So I generate a forever token
140             once, then code it into the script.
141              
142             =cut
143              
144             has 'token' => (
145             is => 'rw',
146             isa => 'Str',
147             );
148              
149              
150             =head3 version
151              
152             This attribute tells L<Trello|https://www.trello.com> that we are using version
153             1 of the API. L<Trello|https://www.trello.com> supports API changes by
154             including the version number in each request. Currently there is only one
155             version. This atribute lets the object handle future versions without any code
156             changes.
157              
158             You may pass the version to the constructor, if the default value of B<1> does
159             not meet your needs.
160              
161             =cut
162              
163             has 'version' => (
164             default => 1,
165             is => 'rw',
166             isa => 'Int',
167             );
168              
169              
170             =head1 BUGS/CAVEATS/etc
171              
172             B<WWW::Trello::Lite> is not associated with L<Trello|https://www.trello.com>
173             or L<Fog Creek Software|http://www.fogcreek.com/> in any way.
174              
175             B<WWW::Trello::Lite> is a very simplistic wrapper around the Trello API. It
176             provides no validity checks and does not create nice objects for each item. You
177             get the raw data as decoded from JSON.
178              
179             =head1 AUTHOR
180              
181             Robert Wohlfarth <rbwohlfarth@gmail.com>
182              
183             =head1 SEE ALSO
184              
185             L<Role::REST::Client>, L<Role::REST::Client::Response>
186              
187             =head1 LICENSE
188              
189             Copyright 2013 Robert Wohlfarth
190              
191             You can redistribute and/or modify this module under the same terms as Perl
192             itself.
193              
194             =cut
195              
196             no Moose;
197             __PACKAGE__->meta->make_immutable;
198              
199             1;