blib/lib/Kanboard/API.pm

filter: Statementstmt 56.1% 32 / 57 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 42.8% 9 / 21 Podpod 100% 10 / 10 totaltotal 53.6% 51 / 95 CC 5 SCAR 19.8
CC
5
Cov
51%
_request
30.0
__ANON__
2.0
get_version
2.0
CRAP 7.2
↑ Summary
1 package Kanboard::API; ## no critic
2  
3 1 ▶use v5.40;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use MIME::Base64;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 =head1 NAME
14  
15 Kanboard::API - A Perl interface to the Kanboard API
16  
17 =head1 VERSION
18  
19 Version 0.01
20  
21 =cut
22  
23 1 our $VERSION = '0.01';
24  
25 =head1 SYNOPSIS
26  
27 Kanboard::API is a Perl interface to the Kanboard API. It provides a simple way to interact with a Kanboard instance.
28  
29 use Kanboard::API;
30  
31 my $kanboard = Kanboard::API->new(username => 'yourusername|jsonrpc', password => 'apikey', endpoint => 'https://yourkanboardinstance.com');
32 ...
33  
34 =head1 ATTRIBUTES
35  
36 =head2 username
37  
38 The username to use for authentication. Defaults to "jsonrpc".
39  
40 =cut
41  
42 1 has username => ( is => 'ro', default => 'jsonrpc' );
43  
44 =head2 password
45  
46 The password to use for authentication.
47  
48 =cut
49  
50 1 has password => ( is => 'ro', required => 1 );
51  
52 =head2 endpoint
53  
54 The JSON RPC Endpoint of the Kanboard instance.
55  
56 =cut
57  
58 1 has endpoint => ( is => 'ro', required => 1 );
59  
60 =head2 ua
61  
62 The LWP::UserAgent object used to make requests.
63  
64 =cut
65  
66 has 'ua' => (
67 is => 'lazy',
68 0 ▶ builder => sub { LWP::UserAgent->new },
Subroutine __ANON__: not called CC=1 SCAR=6.9
69 1 );
70  
71 =head1 PRIVATE METHODS
72  
73 =head2 _request
74  
75 =cut
76  
77 0 ▶sub _request( $self, $method, $params = [] ) {
Subroutine _request: not called CC=5 SCAR=34.0
78 0 my $auth = encode_base64( "$self->{username}:$self->{password}", "" );
79 0 my $headers = [
80 'Content-Type' => 'application/json',
81 'Authorization' => "Basic $auth",
82 ];
83 0 ▶ my $request_json = {
Condition0%0/2
$params // []
l!l
00
MC/DC0%0/1
$params // []
$params
Truth table0%0/2
A
A= $params
Aresult
11
00
84 jsonrpc => "2.0",
85 id => 1,
86 method => $method,
87 params => $params // [],
88 };
89 0 my $body = encode_json($request_json);
90 0 my $request =
91 HTTP::Request->new( 'POST', $self->endpoint, $headers, $body );
92  
93 0 my $response = $self->ua->request($request);
94  
95 0 ▶ if ( $response->is_success ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success) { } 0 0 0
96 0 my $content = $response->decoded_content;
97 0 my $content_json = decode_json($content);
98 0 ▶ if ( $content_json->{error} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content_json->{"error"}) 0 0 0
99 0 die
100 "$content_json->{error}{message} - $content_json->{error}{data}";
101 }
102 0 return $content_json->{result};
103 }
104 else {
105 0 die $response->status_line;
106 }
107 }
108  
109 =head1 PUBLIC METHODS
110  
111 =head2 get_version
112  
113  
114 Purpose: Get the application version
115 Parameters: none
116 Result: version (Example: 1.0.12, master)
117  
118  
119 =cut
120  
121 0 ▶sub get_version( $self) {
Subroutine get_version: not called CC=1 SCAR=6.9
Pod documented
122 0 return $self->_request('getVersion');
123 }
124  
125 =head2 get_me
126  
127  
128 Purpose: Get the current user profile
129 Parameters:
130 None
131 Result on success: user properties
132 Result on failure: empty list
133  
134  
135 =cut
136  
137 0 ▶sub get_me( $self) {
Subroutine get_me: not called CC=1 SCAR=6.9
Pod documented
138 0 return $self->_request('getMe');
139 }
140  
141 =head2 create_project
142  
143  
144 Purpose: Create a new project
145 Parameters:
146 name (string, required)
147 description (string, optional)
148 owner_id (integer, optional)
149 identifier (string, optional)
150 Result on success: project ID
151 Result on failure: false
152  
153  
154 =cut
155  
156 0 ▶sub create_project( $self, $params) {
Subroutine create_project: not called CC=1 SCAR=6.9
Pod documented
157 0 return $self->_request('createProject', $params);
158 }
159  
160 =head2 remove_project
161  
162  
163 Purpose: Remove a project
164 Parameters:
165 project_id (integer, required)
166 Result on success: true
167 Result on failure: false
168  
169  
170 =cut
171  
172 0 ▶sub remove_project( $self, $params) {
Subroutine remove_project: not called CC=1 SCAR=6.9
Pod documented
173 0 return $self->_request('removeProject', $params);
174 }
175  
176 =head2 get_project
177  
178  
179 Purpose: Get project details
180 Parameters:
181 project_id (integer, required)
182 Result on success: project properties
183 Result on failure: empty list
184  
185  
186 =cut
187  
188 0 ▶sub get_project( $self, $params) {
Subroutine get_project: not called CC=1 SCAR=6.9
Pod documented
189 0 return $self->_request('getProject', $params);
190 }
191  
192 =head2 create_task
193  
194  
195 Purpose: Create a new task
196 Parameters:
197 title (string, required)
198 project_id (integer, required)
199 description (string, optional)
200 category_id (integer, optional)
201 owner_id (integer, optional)
202 color_id (string, optional)
203 column_id (integer, optional)
204 swimlane_id (integer, optional)
205 priority (integer, optional)
206 date_due (timestamp, optional)
207 Result on success: task ID
208 Result on failure: false
209  
210  
211 =cut
212  
213 0 ▶sub create_task( $self, $params) {
Subroutine create_task: not called CC=1 SCAR=6.9
Pod documented
214 0 return $self->_request('createTask', $params);
215 }
216  
217 =head2 remove_task
218  
219  
220 Purpose: Remove a task
221 Parameters:
222 task_id (integer, required)
223 Result on success: true
224 Result on failure: false
225  
226  
227 =cut
228  
229 0 ▶sub remove_task( $self, $params) {
Subroutine remove_task: not called CC=1 SCAR=6.9
Pod documented
230 0 return $self->_request('removeTask', $params);
231 }
232  
233 =head2 get_task
234  
235  
236 Purpose: Get task details
237 Parameters:
238 task_id (integer, required)
239 Result on success: task properties
240 Result on failure: empty list
241  
242  
243 =cut
244  
245 0 ▶sub get_task( $self, $params) {
Subroutine get_task: not called CC=1 SCAR=6.9
Pod documented
246 0 return $self->_request('getTask', $params);
247 }
248  
249 =head2 get_all_tasks
250  
251  
252 Purpose: Get all tasks for a project
253 Parameters:
254 project_id (integer, required)
255 Result on success: list of tasks
256 Result on failure: empty list
257  
258  
259 =cut
260  
261 0 ▶sub get_all_tasks( $self, $params) {
Subroutine get_all_tasks: not called CC=1 SCAR=6.9
Pod documented
262 0 return $self->_request('getAllTasks', $params);
263 }
264  
265 =head2 get_board
266  
267  
268 Purpose: Get all necessary information to display a board
269 Parameters:
270 project_id (integer, required)
271 Result on success: board properties
272 Result on failure: empty list
273  
274  
275 =cut
276  
277 0 ▶sub get_board( $self, $params) {
Subroutine get_board: not called CC=1 SCAR=6.9
Pod documented
278 0 return $self->_request('getBoard', $params);
279 }
280  
281  
282 =head1 AUTHOR
283  
284 Dan Barbarito, C<< <dan at barbarito.me> >>
285  
286 =head1 BUGS
287  
288 Please report any bugs or feature requests to C<bug-kanboard-api at rt.cpan.org>, or through
289 the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Kanboard-API>. I will be notified, and then you'll
290 automatically be notified of progress on your bug as I make changes.
291  
292 =head1 SUPPORT
293  
294 You can find documentation for this module with the perldoc command.
295  
296 perldoc Kanboard::API
297  
298  
299 You can also look for information at:
300  
301 =over 4
302  
303 =item * RT: CPAN's request tracker (report bugs here)
304  
305 L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Kanboard-API>
306  
307 =item * CPAN Ratings
308  
309 L<https://cpanratings.perl.org/d/Kanboard-API>
310  
311 =item * Search CPAN
312  
313 L<https://metacpan.org/release/Kanboard-API>
314  
315 =back
316  
317  
318 =head1 ACKNOWLEDGEMENTS
319  
320  
321 =head1 LICENSE AND COPYRIGHT
322  
323 This software is Copyright (c) 2024 by Dan Barbarito.
324  
325 This is free software, licensed under:
326  
327 The Artistic License 2.0 (GPL Compatible)
328  
329  
330 =cut
331  
332 1 1; # End of Kanboard::API
↑ Summary