HTTP/Spark.pm

filter: Statementstmt 57.6% 159 / 276 Branchbran 44.2% 31 / 70 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 49.0% 25 / 51 Podpod 94.7% 18 / 19 totaltotal 53.2% 233 / 438 CC 42 SCAR 24.2
CC
42
Cov
53%
__ANON__
56.0
__ANON__
42.0
handle_paginate
20.0
CRAP 11.2
« SparkBot.pm ↑ Summary SparkBot/SharedRole.pm »
1 package AnyEvent::HTTP::Spark;
2  
3 3 ▶use Modern::Perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use MooX::Types::MooseLike::Base qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use JSON qw(to_json from_json);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use HTTP::Request::Common qw(POST);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Ref::Util qw(is_plain_arrayref is_plain_hashref);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use URI::Escape qw(uri_escape_utf8);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use Scalar::Util qw(looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use AnyEvent;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 3 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
16 3 ▶ no namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 3 with 'HTTP::MultiGet::Role','Log::LogMethods','AnyEvent::SparkBot::SharedRole';
18 }
19  
20 3 has api_url=>(
21 isa=>Str,
22 is=>'ro',
23 lazy=>1,
24 #default=>'https://api.ciscospark.com/v1/',
25 default=>'https://webexapis.com/v1/',
26 );
27  
28 3 has retryCount=>(
29 isa=>Int,
30 is=>'ro',
31 default=>1,
32 );
33  
34 3 has retryTimeout=>(
35 isa=>Int,
36 is=>'ro',
37 default=>1,
38 );
39  
40 3 has retryAfter=>(
41 isa=>Int,
42 is=>'ro',
43 default=>10,
44 );
45  
46 has retries=>(
47 isa=>HashRef,
48 is=>'ro',
49 3 ▶ default=>sub { return {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
50 3 );
51  
52 =head1 NAME
53  
54 AnyEvent::HTTP::Spark - Syncrnous/Asyncrnous HTTP Rest Client for Cisco Spark
55  
56 =head1 SYNOPSIS
57  
58 use AnyEvent::HTTP::Spark;
59 my $obj=new AnyEvent::HTTP::Spark(token=>$ENV{SPARK_TOKEN});
60  
61 =head1 DESCRIPTION
62  
63 Dual Nature Syncrnous/Asyncrnous AnyEvent friendly Spark v1 HTTP Client library.
64  
65 =head1 Moo Roles Used
66  
67 This class uses the following Moo Roles
68  
69 HTTP::MultiGet::Role
70 Log::LogMethods
71 Data::Result::Moo
72 AnyEvent::SpakBot::SharedRole
73  
74 =head1 OO Arguments and accessors
75  
76 Required OO Arguments
77  
78 token: required for spark authentication
79  
80 Optional OO Arguments
81  
82 logger: sets the logging object
83 agent: AnyEvent::HTTP::MultiGet object
84  
85 api_url: https://webexapis.com/v1/
86 # sets the web service the requests point to
87 retryCount: 1, how many retries to attempt when getting a 429 error
88  
89 Options set at runtime
90  
91 retries: anymous hash, used to trak AnyEvent->timer objects
92  
93 =cut
94  
95 # This method runs after the new constructor
96 3 ▶sub BUILD {
Subroutine BUILD: called CC=1 SCAR=0.0
Pod undocumented
97 3 my ($self)=@_;
98 }
99  
100 # this method runs before the new constructor, and can be used to change the arguments passed to the module
101 3 ▶around BUILDARGS => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
102 3 my ($org,$class,@args)=@_;
103
104 3 return $class->$org(@args);
105 3 };
106  
107 =head1 OO Web Methods and special Handlers
108  
109 Each web method has a blocking and a non blocking context.
110  
111 Any Method with a prefix of que_ can be called in either a blocking or a non blocking context. Most people will use the blocking interface of the client.
112  
113 Non Blocking context for use with AnyEvent Loops
114  
115 my $cb=sub {
116 my ($self,$id,$result,$request,$response)=@_;
117 if($result) {
118 print Dumper($result->get_data);
119 } else {
120 ...
121 }
122 };
123 my $id=$self->que_listPeople($cb,$args);
124 $self->agent->run_next;
125  
126 Blocking Context
127  
128 my $result=$self->listPeople($args);
129 if($result) {
130 print Dumper($result->get_data);
131 } else {
132 die $result;
133 }
134  
135  
136 =head1 People
137  
138 =head2 Get Me
139  
140 =over 4
141  
142 =item * Blocking my $result=$self->getMe()
143  
144 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
145  
146 =item * Non-Blocking my $id=$self->que_getMe($cb)
147  
148 Example Callback
149  
150 $cb=sub {
151 my ($self,$id,$result,$request,$response,$hashRef)=@_;
152 # 0: $self The current AnyEvent::HTTP::Slack object
153 # 1: $id the id of the http request
154 # 2: Data::Result Object
155 # 3: HTTP::Request Object
156 # 4: HTTP::Result Object
157 };
158  
159  
160 =cut
161  
162 0 ▶sub que_getMe {
Subroutine que_getMe: not called CC=1 SCAR=6.9
Pod documented
163 0 my ($self,$cb)=@_;
164 0 return $self->que_get($cb,"people/me");
165 }
166  
167 =back
168  
169 =head2 List People
170  
171 =over 4
172  
173 =item * Blocking my $result=$self->listPeople($hashRef)
174  
175 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
176  
177 =item * Non-Blocking my $id=$self->que_listPeople($cb,$hashRef)
178  
179 Example Callback
180  
181 $cb=sub {
182 my ($self,$id,$result,$request,$response,$hashRef)=@_;
183 # 0: $self The current AnyEvent::HTTP::Slack object
184 # 1: $id the id of the http request
185 # 2: Data::Result Object
186 # 3: HTTP::Request Object
187 # 4: HTTP::Result Object
188 };
189  
190  
191 =back
192  
193 =head2 Get Person
194  
195 =over 4
196  
197 =item * Blocking my $result=$self->getPerson($personId)
198  
199 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
200  
201 =item * Non-Blocking my $id=$self->que_getPerson($cb,$personId)
202  
203 Example Callback
204  
205 $cb=sub {
206 my ($self,$id,$result,$request,$response,$personId)=@_;
207 # 0: $self The current AnyEvent::HTTP::Slack object
208 # 1: $id the id of the http request
209 # 2: Data::Result Object
210 # 3: HTTP::Request Object
211 # 4: HTTP::Result Object
212 };
213  
214  
215 =back
216  
217 =head2 Create Person
218  
219 =over 4
220  
221 =item * Blocking my $result=$self->createPerson($hashRef)
222  
223 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
224  
225 =item * Non-Blocking my $id=$self->que_createPerson($cb,$hashRef)
226  
227 Example Callback
228  
229 $cb=sub {
230 my ($self,$id,$result,$request,$response,$hashRef)=@_;
231 # 0: $self The current AnyEvent::HTTP::Slack object
232 # 1: $id the id of the http request
233 # 2: Data::Result Object
234 # 3: HTTP::Request Object
235 # 4: HTTP::Result Object
236 };
237  
238  
239 =back
240  
241 =head2 Delete Person
242  
243 =over 4
244  
245 =item * Blocking my $result=$self->deletePerson($personId)
246  
247 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
248  
249 =item * Non-Blocking my $id=$self->que_deletePerson($cb,$personId)
250  
251 Example Callback
252  
253 $cb=sub {
254 my ($self,$id,$result,$request,$response,$personId)=@_;
255 # 0: $self The current AnyEvent::HTTP::Slack object
256 # 1: $id the id of the http request
257 # 2: Data::Result Object
258 # 3: HTTP::Request Object
259 # 4: HTTP::Result Object
260 };
261  
262  
263 =back
264  
265 =head2 Update Person
266  
267 =over 4
268  
269 =item * Blocking my $result=$self->updatePerson($personId,$hashRef)
270  
271 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
272  
273 =item * Non-Blocking my $id=$self->que_updatePerson($cb,$personId,$hashRef)
274  
275 Example Callback
276  
277 $cb=sub {
278 my ($self,$id,$result,$request,$response,$personId,$hashRef)=@_;
279 # 0: $self The current AnyEvent::HTTP::Slack object
280 # 1: $id the id of the http request
281 # 2: Data::Result Object
282 # 3: HTTP::Request Object
283 # 4: HTTP::Result Object
284 };
285  
286  
287 =back
288  
289 =head1 Rooms
290  
291 =head2 List Rooms
292  
293 =over 4
294  
295 =item * Blocking my $result=$self->listRooms($hashRef)
296  
297 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
298  
299 =item * Non-Blocking my $id=$self->que_listRooms($cb,$hashRef)
300  
301 Example Callback
302  
303 $cb=sub {
304 my ($self,$id,$result,$request,$response,$hashRef)=@_;
305 # 0: $self The current AnyEvent::HTTP::Slack object
306 # 1: $id the id of the http request
307 # 2: Data::Result Object
308 # 3: HTTP::Request Object
309 # 4: HTTP::Result Object
310 };
311  
312  
313 =back
314  
315 =head2 Get Room
316  
317 =over 4
318  
319 =item * Blocking my $result=$self->getRoom($roomId)
320  
321 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
322  
323 =item * Non-Blocking my $id=$self->que_getRoom($cb,$roomId)
324  
325 Example Callback
326  
327 $cb=sub {
328 my ($self,$id,$result,$request,$response,$roomId)=@_;
329 # 0: $self The current AnyEvent::HTTP::Slack object
330 # 1: $id the id of the http request
331 # 2: Data::Result Object
332 # 3: HTTP::Request Object
333 # 4: HTTP::Result Object
334 };
335  
336  
337 =back
338  
339 =head2 Create Room
340  
341 =over 4
342  
343 =item * Blocking my $result=$self->createRoom($hashRef)
344  
345 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
346  
347 =item * Non-Blocking my $id=$self->que_createRoom($cb,$hashRef)
348  
349 Example Callback
350  
351 $cb=sub {
352 my ($self,$id,$result,$request,$response,$hashRef)=@_;
353 # 0: $self The current AnyEvent::HTTP::Slack object
354 # 1: $id the id of the http request
355 # 2: Data::Result Object
356 # 3: HTTP::Request Object
357 # 4: HTTP::Result Object
358 };
359  
360  
361 =back
362  
363 =head2 Delete Room
364  
365 =over 4
366  
367 =item * Blocking my $result=$self->deleteRoom($roomId)
368  
369 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
370  
371 =item * Non-Blocking my $id=$self->que_deleteRoom($cb,$roomId)
372  
373 Example Callback
374  
375 $cb=sub {
376 my ($self,$id,$result,$request,$response,$roomId)=@_;
377 # 0: $self The current AnyEvent::HTTP::Slack object
378 # 1: $id the id of the http request
379 # 2: Data::Result Object
380 # 3: HTTP::Request Object
381 # 4: HTTP::Result Object
382 };
383  
384  
385 =back
386  
387 =head2 Update Room
388  
389 =over 4
390  
391 =item * Blocking my $result=$self->updateRoom($roomId,$hashRef)
392  
393 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
394  
395 =item * Non-Blocking my $id=$self->que_updateRoom($cb,$roomId,$hashRef)
396  
397 Example Callback
398  
399 $cb=sub {
400 my ($self,$id,$result,$request,$response,$roomId,$hashRef)=@_;
401 # 0: $self The current AnyEvent::HTTP::Slack object
402 # 1: $id the id of the http request
403 # 2: Data::Result Object
404 # 3: HTTP::Request Object
405 # 4: HTTP::Result Object
406 };
407  
408  
409 =back
410  
411 =head1 Memberships
412  
413 =head2 List Memberships
414  
415 =over 4
416  
417 =item * Blocking my $result=$self->listMemberships($hashRef)
418  
419 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
420  
421 =item * Non-Blocking my $id=$self->que_listMemberships($cb,$hashRef)
422  
423 Example Callback
424  
425 $cb=sub {
426 my ($self,$id,$result,$request,$response,$hashRef)=@_;
427 # 0: $self The current AnyEvent::HTTP::Slack object
428 # 1: $id the id of the http request
429 # 2: Data::Result Object
430 # 3: HTTP::Request Object
431 # 4: HTTP::Result Object
432 };
433  
434  
435 =back
436  
437 =head2 Get Membership
438  
439 =over 4
440  
441 =item * Blocking my $result=$self->getMembership($membershipId)
442  
443 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
444  
445 =item * Non-Blocking my $id=$self->que_getMembership($cb,$membershipId)
446  
447 Example Callback
448  
449 $cb=sub {
450 my ($self,$id,$result,$request,$response,$membershipId)=@_;
451 # 0: $self The current AnyEvent::HTTP::Slack object
452 # 1: $id the id of the http request
453 # 2: Data::Result Object
454 # 3: HTTP::Request Object
455 # 4: HTTP::Result Object
456 };
457  
458  
459 =back
460  
461 =head2 Create Membership
462  
463 =over 4
464  
465 =item * Blocking my $result=$self->createMembership($hashRef)
466  
467 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
468  
469 =item * Non-Blocking my $id=$self->que_createMembership($cb,$hashRef)
470  
471 Example Callback
472  
473 $cb=sub {
474 my ($self,$id,$result,$request,$response,$hashRef)=@_;
475 # 0: $self The current AnyEvent::HTTP::Slack object
476 # 1: $id the id of the http request
477 # 2: Data::Result Object
478 # 3: HTTP::Request Object
479 # 4: HTTP::Result Object
480 };
481  
482  
483 =back
484  
485 =head2 Delete Membership
486  
487 =over 4
488  
489 =item * Blocking my $result=$self->deleteMembership($membershipId)
490  
491 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
492  
493 =item * Non-Blocking my $id=$self->que_deleteMembership($cb,$membershipId)
494  
495 Example Callback
496  
497 $cb=sub {
498 my ($self,$id,$result,$request,$response,$membershipId)=@_;
499 # 0: $self The current AnyEvent::HTTP::Slack object
500 # 1: $id the id of the http request
501 # 2: Data::Result Object
502 # 3: HTTP::Request Object
503 # 4: HTTP::Result Object
504 };
505  
506  
507 =back
508  
509 =head2 Update Membership
510  
511 =over 4
512  
513 =item * Blocking my $result=$self->updateMembership($membershipId,$hashRef)
514  
515 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
516  
517 =item * Non-Blocking my $id=$self->que_updateMembership($cb,$membershipId,$hashRef)
518  
519 Example Callback
520  
521 $cb=sub {
522 my ($self,$id,$result,$request,$response,$membershipId,$hashRef)=@_;
523 # 0: $self The current AnyEvent::HTTP::Slack object
524 # 1: $id the id of the http request
525 # 2: Data::Result Object
526 # 3: HTTP::Request Object
527 # 4: HTTP::Result Object
528 };
529  
530  
531 =back
532  
533 =head1 Messages
534  
535 =head2 List Messages
536  
537 Special Notes on bots for this method, bots can only list messages refering to the bot itself. This means there are 2 manditory arguments when using a bot. If mentionedPeople is not set to the litteral string 'me' a bot will encounter a 403 error.
538  
539 $hashRef Required options
540  
541 roomId: the id for the room
542 mentionedPeople: me
543  
544 =over 4
545  
546 =item * Blocking my $result=$self->listMessages($hashRef)
547  
548 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
549  
550 =item * Non-Blocking my $id=$self->que_listMessages($cb,$hashRef)
551  
552 Example Callback
553  
554 $cb=sub {
555 my ($self,$id,$result,$request,$response,$hashRef)=@_;
556 # 0: $self The current AnyEvent::HTTP::Slack object
557 # 1: $id the id of the http request
558 # 2: Data::Result Object
559 # 3: HTTP::Request Object
560 # 4: HTTP::Result Object
561 };
562  
563  
564 =back
565  
566 =head2 Get Message
567  
568 =over 4
569  
570 =item * Blocking my $result=$self->getMessage($messageId)
571  
572 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
573  
574 =item * Non-Blocking my $id=$self->que_getMessage($cb,$messageId)
575  
576 Example Callback
577  
578 $cb=sub {
579 my ($self,$id,$result,$request,$response,$messageId)=@_;
580 # 0: $self The current AnyEvent::HTTP::Slack object
581 # 1: $id the id of the http request
582 # 2: Data::Result Object
583 # 3: HTTP::Request Object
584 # 4: HTTP::Result Object
585 };
586  
587  
588 =back
589  
590 =head2 Create Message
591  
592 =over 4
593  
594 =item * Blocking my $result=$self->createMessage($hashRef)
595  
596 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
597  
598 =item * Non-Blocking my $id=$self->que_createMessage($cb,$hashRef)
599  
600 Example Callback
601  
602 $cb=sub {
603 my ($self,$id,$result,$request,$response,$hashRef)=@_;
604 # 0: $self The current AnyEvent::HTTP::Slack object
605 # 1: $id the id of the http request
606 # 2: Data::Result Object
607 # 3: HTTP::Request Object
608 # 4: HTTP::Result Object
609 };
610  
611  
612 =back
613  
614 =head2 Delete Message
615  
616 =over 4
617  
618 =item * Blocking my $result=$self->deleteMessage($messageId)
619  
620 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
621  
622 =item * Non-Blocking my $id=$self->que_deleteMessage($cb,$messageId)
623  
624 Example Callback
625  
626 $cb=sub {
627 my ($self,$id,$result,$request,$response,$messageId)=@_;
628 # 0: $self The current AnyEvent::HTTP::Slack object
629 # 1: $id the id of the http request
630 # 2: Data::Result Object
631 # 3: HTTP::Request Object
632 # 4: HTTP::Result Object
633 };
634  
635  
636 =back
637  
638 =head1 Teams
639  
640 =head2 List Teams
641  
642 =over 4
643  
644 =item * Blocking my $result=$self->listTeams($hashRef)
645  
646 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
647  
648 =item * Non-Blocking my $id=$self->que_listTeams($cb,$hashRef)
649  
650 Example Callback
651  
652 $cb=sub {
653 my ($self,$id,$result,$request,$response,$hashRef)=@_;
654 # 0: $self The current AnyEvent::HTTP::Slack object
655 # 1: $id the id of the http request
656 # 2: Data::Result Object
657 # 3: HTTP::Request Object
658 # 4: HTTP::Result Object
659 };
660  
661  
662 =back
663  
664 =head2 Get Team
665  
666 =over 4
667  
668 =item * Blocking my $result=$self->getTeam($teamId)
669  
670 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
671  
672 =item * Non-Blocking my $id=$self->que_getTeam($cb,$teamId)
673  
674 Example Callback
675  
676 $cb=sub {
677 my ($self,$id,$result,$request,$response,$teamId)=@_;
678 # 0: $self The current AnyEvent::HTTP::Slack object
679 # 1: $id the id of the http request
680 # 2: Data::Result Object
681 # 3: HTTP::Request Object
682 # 4: HTTP::Result Object
683 };
684  
685  
686 =back
687  
688 =head2 Create Team
689  
690 =over 4
691  
692 =item * Blocking my $result=$self->createTeam($hashRef)
693  
694 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
695  
696 =item * Non-Blocking my $id=$self->que_createTeam($cb,$hashRef)
697  
698 Example Callback
699  
700 $cb=sub {
701 my ($self,$id,$result,$request,$response,$hashRef)=@_;
702 # 0: $self The current AnyEvent::HTTP::Slack object
703 # 1: $id the id of the http request
704 # 2: Data::Result Object
705 # 3: HTTP::Request Object
706 # 4: HTTP::Result Object
707 };
708  
709  
710 =back
711  
712 =head2 Delete Team
713  
714 =over 4
715  
716 =item * Blocking my $result=$self->deleteTeam($teamId)
717  
718 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
719  
720 =item * Non-Blocking my $id=$self->que_deleteTeam($cb,$teamId)
721  
722 Example Callback
723  
724 $cb=sub {
725 my ($self,$id,$result,$request,$response,$teamId)=@_;
726 # 0: $self The current AnyEvent::HTTP::Slack object
727 # 1: $id the id of the http request
728 # 2: Data::Result Object
729 # 3: HTTP::Request Object
730 # 4: HTTP::Result Object
731 };
732  
733  
734 =back
735  
736 =head2 Update Team
737  
738 =over 4
739  
740 =item * Blocking my $result=$self->updateTeam($teamId,$hashRef)
741  
742 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
743  
744 =item * Non-Blocking my $id=$self->que_updateTeam($cb,$teamId,$hashRef)
745  
746 Example Callback
747  
748 $cb=sub {
749 my ($self,$id,$result,$request,$response,$teamId,$hashRef)=@_;
750 # 0: $self The current AnyEvent::HTTP::Slack object
751 # 1: $id the id of the http request
752 # 2: Data::Result Object
753 # 3: HTTP::Request Object
754 # 4: HTTP::Result Object
755 };
756  
757  
758 =back
759  
760 =head1 Team Memberships
761  
762 =head2 List Team Memberships
763  
764 =over 4
765  
766 =item * Blocking my $result=$self->listTeamMemberships($hashRef)
767  
768 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
769  
770 =item * Non-Blocking my $id=$self->que_listTeamMemberships($cb,$hashRef)
771  
772 Example Callback
773  
774 $cb=sub {
775 my ($self,$id,$result,$request,$response,$hashRef)=@_;
776 # 0: $self The current AnyEvent::HTTP::Slack object
777 # 1: $id the id of the http request
778 # 2: Data::Result Object
779 # 3: HTTP::Request Object
780 # 4: HTTP::Result Object
781 };
782  
783  
784 =back
785  
786 =head2 Get Team Membership
787  
788 =over 4
789  
790 =item * Blocking my $result=$self->getTeamMembership($teamMembershipId)
791  
792 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
793  
794 =item * Non-Blocking my $id=$self->que_getTeamMembership($cb,$teamMembershipId)
795  
796 Example Callback
797  
798 $cb=sub {
799 my ($self,$id,$result,$request,$response,$teamMembershipId)=@_;
800 # 0: $self The current AnyEvent::HTTP::Slack object
801 # 1: $id the id of the http request
802 # 2: Data::Result Object
803 # 3: HTTP::Request Object
804 # 4: HTTP::Result Object
805 };
806  
807  
808 =back
809  
810 =head2 Create Team Membership
811  
812 =over 4
813  
814 =item * Blocking my $result=$self->createTeamMembership($hashRef)
815  
816 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
817  
818 =item * Non-Blocking my $id=$self->que_createTeamMembership($cb,$hashRef)
819  
820 Example Callback
821  
822 $cb=sub {
823 my ($self,$id,$result,$request,$response,$hashRef)=@_;
824 # 0: $self The current AnyEvent::HTTP::Slack object
825 # 1: $id the id of the http request
826 # 2: Data::Result Object
827 # 3: HTTP::Request Object
828 # 4: HTTP::Result Object
829 };
830  
831  
832 =back
833  
834 =head2 Delete Team Membership
835  
836 =over 4
837  
838 =item * Blocking my $result=$self->deleteTeamMembership($teamMembershipId)
839  
840 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
841  
842 =item * Non-Blocking my $id=$self->que_deleteTeamMembership($cb,$teamMembershipId)
843  
844 Example Callback
845  
846 $cb=sub {
847 my ($self,$id,$result,$request,$response,$teamMembershipId)=@_;
848 # 0: $self The current AnyEvent::HTTP::Slack object
849 # 1: $id the id of the http request
850 # 2: Data::Result Object
851 # 3: HTTP::Request Object
852 # 4: HTTP::Result Object
853 };
854  
855  
856 =back
857  
858 =head2 Update Team Membership
859  
860 =over 4
861  
862 =item * Blocking my $result=$self->updateTeamMembership($teamMembershipId,$hashRef)
863  
864 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
865  
866 =item * Non-Blocking my $id=$self->que_updateTeamMembership($cb,$teamMembershipId,$hashRef)
867  
868 Example Callback
869  
870 $cb=sub {
871 my ($self,$id,$result,$request,$response,$teamMembershipId,$hashRef)=@_;
872 # 0: $self The current AnyEvent::HTTP::Slack object
873 # 1: $id the id of the http request
874 # 2: Data::Result Object
875 # 3: HTTP::Request Object
876 # 4: HTTP::Result Object
877 };
878  
879  
880 =back
881  
882 =head1 Webhooks
883  
884 =head2 List Webhooks
885  
886 =over 4
887  
888 =item * Blocking my $result=$self->listWebhooks($hashRef)
889  
890 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
891  
892 =item * Non-Blocking my $id=$self->que_listWebhooks($cb,$hashRef)
893  
894 Example Callback
895  
896 $cb=sub {
897 my ($self,$id,$result,$request,$response,$hashRef)=@_;
898 # 0: $self The current AnyEvent::HTTP::Slack object
899 # 1: $id the id of the http request
900 # 2: Data::Result Object
901 # 3: HTTP::Request Object
902 # 4: HTTP::Result Object
903 };
904  
905  
906 =back
907  
908 =head2 Get Webhook
909  
910 =over 4
911  
912 =item * Blocking my $result=$self->getWebhook($webhookId)
913  
914 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
915  
916 =item * Non-Blocking my $id=$self->que_getWebhook($cb,$webhookId)
917  
918 Example Callback
919  
920 $cb=sub {
921 my ($self,$id,$result,$request,$response,$webhookId)=@_;
922 # 0: $self The current AnyEvent::HTTP::Slack object
923 # 1: $id the id of the http request
924 # 2: Data::Result Object
925 # 3: HTTP::Request Object
926 # 4: HTTP::Result Object
927 };
928  
929  
930 =back
931  
932 =head2 Create Webhook
933  
934 =over 4
935  
936 =item * Blocking my $result=$self->createWebhook($hashRef)
937  
938 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
939  
940 =item * Non-Blocking my $id=$self->que_createWebhook($cb,$hashRef)
941  
942 Example Callback
943  
944 $cb=sub {
945 my ($self,$id,$result,$request,$response,$hashRef)=@_;
946 # 0: $self The current AnyEvent::HTTP::Slack object
947 # 1: $id the id of the http request
948 # 2: Data::Result Object
949 # 3: HTTP::Request Object
950 # 4: HTTP::Result Object
951 };
952  
953  
954 =back
955  
956 =head2 Delete Webhook
957  
958 =over 4
959  
960 =item * Blocking my $result=$self->deleteWebhook($webhookId)
961  
962 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
963  
964 =item * Non-Blocking my $id=$self->que_deleteWebhook($cb,$webhookId)
965  
966 Example Callback
967  
968 $cb=sub {
969 my ($self,$id,$result,$request,$response,$webhookId)=@_;
970 # 0: $self The current AnyEvent::HTTP::Slack object
971 # 1: $id the id of the http request
972 # 2: Data::Result Object
973 # 3: HTTP::Request Object
974 # 4: HTTP::Result Object
975 };
976  
977  
978 =back
979  
980 =head2 Update Webhook
981  
982 =over 4
983  
984 =item * Blocking my $result=$self->updateWebhook($webhookId,$hashRef)
985  
986 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
987  
988 =item * Non-Blocking my $id=$self->que_updateWebhook($cb,$webhookId,$hashRef)
989  
990 Example Callback
991  
992 $cb=sub {
993 my ($self,$id,$result,$request,$response,$webhookId,$hashRef)=@_;
994 # 0: $self The current AnyEvent::HTTP::Slack object
995 # 1: $id the id of the http request
996 # 2: Data::Result Object
997 # 3: HTTP::Request Object
998 # 4: HTTP::Result Object
999 };
1000  
1001  
1002 =back
1003  
1004 =head1 Organizations
1005  
1006 =head2 List Organizations
1007  
1008 =over 4
1009  
1010 =item * Blocking my $result=$self->listOrganizations($hashRef)
1011  
1012 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
1013  
1014 =item * Non-Blocking my $id=$self->que_listOrganizations($cb,$hashRef)
1015  
1016 Example Callback
1017  
1018 $cb=sub {
1019 my ($self,$id,$result,$request,$response,$hashRef)=@_;
1020 # 0: $self The current AnyEvent::HTTP::Slack object
1021 # 1: $id the id of the http request
1022 # 2: Data::Result Object
1023 # 3: HTTP::Request Object
1024 # 4: HTTP::Result Object
1025 };
1026  
1027  
1028 =back
1029  
1030 =head2 Get Organization
1031  
1032 =over 4
1033  
1034 =item * Blocking my $result=$self->getOrganization($organizationId)
1035  
1036 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
1037  
1038 =item * Non-Blocking my $id=$self->que_getOrganization($cb,$organizationId)
1039  
1040 Example Callback
1041  
1042 $cb=sub {
1043 my ($self,$id,$result,$request,$response,$organizationId)=@_;
1044 # 0: $self The current AnyEvent::HTTP::Slack object
1045 # 1: $id the id of the http request
1046 # 2: Data::Result Object
1047 # 3: HTTP::Request Object
1048 # 4: HTTP::Result Object
1049 };
1050  
1051  
1052 =back
1053  
1054 =head1 Licenses
1055  
1056 =head2 List Licenses
1057  
1058 =over 4
1059  
1060 =item * Blocking my $result=$self->listLicenses($hashRef)
1061  
1062 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
1063  
1064 =item * Non-Blocking my $id=$self->que_listLicenses($cb,$hashRef)
1065  
1066 Example Callback
1067  
1068 $cb=sub {
1069 my ($self,$id,$result,$request,$response,$hashRef)=@_;
1070 # 0: $self The current AnyEvent::HTTP::Slack object
1071 # 1: $id the id of the http request
1072 # 2: Data::Result Object
1073 # 3: HTTP::Request Object
1074 # 4: HTTP::Result Object
1075 };
1076  
1077  
1078 =back
1079  
1080 =head2 Get License
1081  
1082 =over 4
1083  
1084 =item * Blocking my $result=$self->getLicense($licenseId)
1085  
1086 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
1087  
1088 =item * Non-Blocking my $id=$self->que_getLicense($cb,$licenseId)
1089  
1090 Example Callback
1091  
1092 $cb=sub {
1093 my ($self,$id,$result,$request,$response,$licenseId)=@_;
1094 # 0: $self The current AnyEvent::HTTP::Slack object
1095 # 1: $id the id of the http request
1096 # 2: Data::Result Object
1097 # 3: HTTP::Request Object
1098 # 4: HTTP::Result Object
1099 };
1100  
1101  
1102 =back
1103  
1104 =head1 Roles
1105  
1106 =head2 List Roles
1107  
1108 =over 4
1109  
1110 =item * Blocking my $result=$self->listRoles($hashRef)
1111  
1112 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
1113  
1114 =item * Non-Blocking my $id=$self->que_listRoles($cb,$hashRef)
1115  
1116 Example Callback
1117  
1118 $cb=sub {
1119 my ($self,$id,$result,$request,$response,$hashRef)=@_;
1120 # 0: $self The current AnyEvent::HTTP::Slack object
1121 # 1: $id the id of the http request
1122 # 2: Data::Result Object
1123 # 3: HTTP::Request Object
1124 # 4: HTTP::Result Object
1125 };
1126  
1127  
1128 =back
1129  
1130 =head2 Get Role
1131  
1132 =over 4
1133  
1134 =item * Blocking my $result=$self->getRole($roleId)
1135  
1136 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
1137  
1138 =item * Non-Blocking my $id=$self->que_getRole($cb,$roleId)
1139  
1140 Example Callback
1141  
1142 $cb=sub {
1143 my ($self,$id,$result,$request,$response,$roleId)=@_;
1144 # 0: $self The current AnyEvent::HTTP::Slack object
1145 # 1: $id the id of the http request
1146 # 2: Data::Result Object
1147 # 3: HTTP::Request Object
1148 # 4: HTTP::Result Object
1149 };
1150  
1151  
1152 =back
1153  
1154 =head1 Events
1155  
1156 =head2 List Events
1157  
1158 =over 4
1159  
1160 =item * Blocking my $result=$self->listEvents($hashRef)
1161  
1162 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
1163  
1164 =item * Non-Blocking my $id=$self->que_listEvents($cb,$hashRef)
1165  
1166 Example Callback
1167  
1168 $cb=sub {
1169 my ($self,$id,$result,$request,$response,$hashRef)=@_;
1170 # 0: $self The current AnyEvent::HTTP::Slack object
1171 # 1: $id the id of the http request
1172 # 2: Data::Result Object
1173 # 3: HTTP::Request Object
1174 # 4: HTTP::Result Object
1175 };
1176  
1177  
1178 =back
1179  
1180 =head2 Get Event
1181  
1182 =over 4
1183  
1184 =item * Blocking my $result=$self->getEvent($eventId)
1185  
1186 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
1187  
1188 =item * Non-Blocking my $id=$self->que_getEvent($cb,$eventId)
1189  
1190 Example Callback
1191  
1192 $cb=sub {
1193 my ($self,$id,$result,$request,$response,$eventId)=@_;
1194 # 0: $self The current AnyEvent::HTTP::Slack object
1195 # 1: $id the id of the http request
1196 # 2: Data::Result Object
1197 # 3: HTTP::Request Object
1198 # 4: HTTP::Result Object
1199 };
1200  
1201  
1202 =back
1203  
1204 =cut
1205  
1206 3 __PACKAGE__->_build_common("people",qw(list get create delete update));
1207 3 __PACKAGE__->_build_common("rooms",qw(list get create delete update));
1208 3 __PACKAGE__->_build_common("meetings",qw(list get create delete update));
1209 3 __PACKAGE__->_build_common("memberships",qw(list get create delete update));
1210 3 __PACKAGE__->_build_common("teams",qw(list get create delete update));
1211 3 __PACKAGE__->_build_common("team/memberships",qw(list get create delete update));
1212 3 __PACKAGE__->_build_common("webhooks",qw(list get create delete update));
1213 3 __PACKAGE__->_build_common("organizations",qw(list get));
1214 3 __PACKAGE__->_build_common("licenses",qw(list get));
1215 3 __PACKAGE__->_build_common("roles",qw(list get));
1216 3 __PACKAGE__->_build_common("events",qw(list get));
1217  
1218 3 __PACKAGE__->_build_common("messages",qw(list get create delete));
1219 36 ▶sub _build_common {
Subroutine _build_common: called CC=8 SCAR=25.5
1220 36 my ($class,$path,@todo)=@_;
1221 36 foreach my $method (@todo) {
1222 141 my $label=$path;
1223 141 $label=~ s/^(.)/uc($1)/se;
1224 141 $label="que_".$method.$label;
1225 141 my $code;
1226 141 ▶ if($method ne 'list') {
Branch: 1 branch
BranchTrueFalseTotal
if ($method ne "list") 105 36 141
1227 105 $label=~ s/s$//s ;
1228 105 $label=~ s/People/Person/s;
1229 }
1230 141 $label=~ s#/(.)#uc($1)#se;
1231
1232 141 ▶ if($method eq 'list') {
Branch: 5 branches
BranchTrueFalseTotal
if ($method eq 'list') { } 36 105 141
elsif ($method eq 'update') { } 21 84 105
elsif ($method eq 'get') { } 36 48 84
elsif ($method eq 'delete') { } 24 24 48
elsif ($method eq 'create') { } 24 0 24
1233 0 ▶ $code=sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1234 0 my ($self,$cb,$args)=@_;
1235 0 my $url=$path;
1236  
1237 0 ▶ my $run=sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1238 0 my ($self,$id,$result,$request,$response)=@_;
1239 0 $self->handle_paginate($id,$result,$request,$response,$cb);
1240 0 };
1241 0 return $self->que_get($run,$url,$args);
1242 36 };
1243 } elsif($method eq 'update') {
1244 0 ▶ $code=sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1245 0 my ($self,$cb,$targetId,$data)=@_;
1246 0 ▶ return $self->queue_result($cb,$self->new_false("${method}Id is a requried argument")) unless defined($targetId);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $targetId 0 0 0
1247 0 return $self->que_put_json($cb,"$path/$targetId",$data);
1248 21 };
1249 } elsif($method eq 'get') {
1250 0 ▶ $code=sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1251 0 my ($self,$cb,$targetId,$data)=@_;
1252 0 ▶ return $self->queue_result($cb,$self->new_false("${method}Id is a requried argument")) unless defined($targetId);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $targetId 0 0 0
1253 0 return $self->que_get($cb,"$path/$targetId",$data);
1254 36 };
1255 } elsif($method eq 'delete') {
1256 0 ▶ $code=sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1257 0 my ($self,$cb,$targetId,$data)=@_;
1258 0 ▶ return $self->queue_result($cb,$self->new_false("${method}Id is a requried argument")) unless defined($targetId);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $targetId 0 0 0
1259 0 return $self->que_delete($cb,"$path/$targetId",$data);
1260 24 };
1261 } elsif($method eq 'create') {
1262 0 ▶ $code=sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1263 0 my ($self,$cb,$data)=@_;
1264 0 return $self->que_post_json($cb,"$path",$data);
1265 24 };
1266 } else {
1267 0 die "Er um.. $method isn't supported yet";
1268 }
1269 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1270 141 *{$label}=$code;
1271 }
1272 }
1273  
1274 =head1 Meetingss
1275  
1276 =head2 List Meetingss
1277  
1278 =over 4
1279  
1280 =item * Blocking my $result=$self->listMeetingss($hashRef)
1281  
1282 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
1283  
1284 =item * Non-Blocking my $id=$self->que_listMeetingss($cb,$hashRef)
1285  
1286 Example Callback
1287  
1288 $cb=sub {
1289 my ($self,$id,$result,$request,$response,$hashRef)=@_;
1290 # 0: $self The current AnyEvent::HTTP::Slack object
1291 # 1: $id the id of the http request
1292 # 2: Data::Result Object
1293 # 3: HTTP::Request Object
1294 # 4: HTTP::Result Object
1295 };
1296  
1297  
1298 =back
1299  
1300 =head2 Get Meetings
1301  
1302 =over 4
1303  
1304 =item * Blocking my $result=$self->getMeetings($roomId)
1305  
1306 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
1307  
1308 =item * Non-Blocking my $id=$self->que_getMeetings($cb,$roomId)
1309  
1310 Example Callback
1311  
1312 $cb=sub {
1313 my ($self,$id,$result,$request,$response,$roomId)=@_;
1314 # 0: $self The current AnyEvent::HTTP::Slack object
1315 # 1: $id the id of the http request
1316 # 2: Data::Result Object
1317 # 3: HTTP::Request Object
1318 # 4: HTTP::Result Object
1319 };
1320  
1321  
1322 =back
1323  
1324 =head2 Create Meetings
1325  
1326 =over 4
1327  
1328 =item * Blocking my $result=$self->createMeetings($hashRef)
1329  
1330 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
1331  
1332 =item * Non-Blocking my $id=$self->que_createMeetings($cb,$hashRef)
1333  
1334 Example Callback
1335  
1336 $cb=sub {
1337 my ($self,$id,$result,$request,$response,$hashRef)=@_;
1338 # 0: $self The current AnyEvent::HTTP::Slack object
1339 # 1: $id the id of the http request
1340 # 2: Data::Result Object
1341 # 3: HTTP::Request Object
1342 # 4: HTTP::Result Object
1343 };
1344  
1345  
1346 =back
1347  
1348 =head2 Delete Meetings
1349  
1350 =over 4
1351  
1352 =item * Blocking my $result=$self->deleteMeetings($roomId)
1353  
1354 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
1355  
1356 =item * Non-Blocking my $id=$self->que_deleteMeetings($cb,$roomId)
1357  
1358 Example Callback
1359  
1360 $cb=sub {
1361 my ($self,$id,$result,$request,$response,$roomId)=@_;
1362 # 0: $self The current AnyEvent::HTTP::Slack object
1363 # 1: $id the id of the http request
1364 # 2: Data::Result Object
1365 # 3: HTTP::Request Object
1366 # 4: HTTP::Result Object
1367 };
1368  
1369  
1370 =back
1371  
1372 =head2 Update Meetings
1373  
1374 =over 4
1375  
1376 =item * Blocking my $result=$self->updateMeetings($roomId,$hashRef)
1377  
1378 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
1379  
1380 =item * Non-Blocking my $id=$self->que_updateMeetings($cb,$roomId,$hashRef)
1381  
1382 Example Callback
1383  
1384 $cb=sub {
1385 my ($self,$id,$result,$request,$response,$roomId,$hashRef)=@_;
1386 # 0: $self The current AnyEvent::HTTP::Slack object
1387 # 1: $id the id of the http request
1388 # 2: Data::Result Object
1389 # 3: HTTP::Request Object
1390 # 4: HTTP::Result Object
1391 };
1392  
1393  
1394 =back
1395  
1396 =head1 Attaching files to messages
1397  
1398 Posting files to channel steps outside of the traditional json data format.
1399  
1400 =over 4
1401  
1402 =item * Blocking my $result=$self->uploadFile('/path/to/file',%args);
1403  
1404 Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.
1405  
1406 =item * Non-Blocking my $result=$self->que_uploadFile($cb,'/path/to/file',%args);
1407  
1408 Example Callback
1409  
1410 $cb=sub {
1411 my ($self,$id,$result,$request,$response,$roomId,$hashRef)=@_;
1412 # 0: $self The current AnyEvent::HTTP::Slack object
1413 # 1: $id the id of the http request
1414 # 2: Data::Result Object
1415 # 3: HTTP::Request Object
1416 # 4: HTTP::Result Object
1417 };
1418  
1419 =back
1420  
1421 =cut
1422  
1423 0 ▶sub que_uploadFile {
Subroutine que_uploadFile: not called CC=1 SCAR=6.9
Pod documented
1424 0 my ($self,$cb,$file,%args)=@_;
1425  
1426 0 my $post=[
1427 %args,
1428 files=>[$file],
1429 ];
1430  
1431 0 my $url=$self->api_url.'messages';
1432 0 my $request=POST($url,Content_type=>'form-data',Content=>$post);
1433 0 $request->header(Authorization=>"Bearer ".$self->token);
1434 0 return $self->queue_request($request,$cb);
1435 }
1436  
1437 =head1 Low Level Request functions
1438  
1439 This section documents low level request functions.
1440  
1441 =over 4
1442  
1443 =cut
1444  
1445 =item * $self->handle_paginate($id,$result,$request,$response,$cb)
1446  
1447 Internal Method wrapper for parsing pagination headers.
1448  
1449 Example:
1450  
1451 my $code=sub {
1452 my ($self,$id,$result,$request,$response)=@_;
1453 $self->handle_paginate($id,$result,$request,$response,$cb);
1454 };
1455 return $self->que_get($code,$url,$args);
1456  
1457 Pagination information can be found in the following result fields.
1458  
1459 cursorPosition: last|next|prev|first
1460 pageLink: (undef when cursorPosition eq 'last') Url to the next page
1461  
1462 =cut
1463  
1464 0 ▶sub handle_paginate {
Subroutine handle_paginate: not called CC=4 SCAR=30.0
Pod documented
1465 0 my ($self,$id,$result,$request,$response,$cb)=@_;
1466 0 ▶ if($result) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result) 0 0 0
1467 0 my $headers={$response->headers->flatten};
1468 0 my $data=$result->get_data;
1469 0 $data->{cursorPosition}='last';
1470 0 $data->{pageLink}='';
1471 0 ▶ if(exists $headers->{Link}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $headers->{"Link"}) 0 0 0
1472 0 my $link=$headers->{Link};
1473 0 ▶ if($link=~ /^<([^>]+)>;\s+rel="(\w+)"\s*$/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($link =~ /^<([^>]+)>;\s+rel="(\w+)"\s*$/su) 0 0 0
1474 0 $data->{pageLink}=$1;
1475 0 $data->{cursorPosition}=$2;
1476 }
1477 }
1478 }
1479  
1480 0 $cb->(@_);
1481 }
1482  
1483 =item * my $result=$self->build_post_json($url,$data);
1484  
1485 Returns a Data::Result object; When true it contains an HTTP::Request Object For $url, the body will consist of $data converted to json. When false it contains why it failed.
1486  
1487 =cut
1488  
1489 1 ▶sub build_post_json {
Subroutine build_post_json: called CC=2 SCAR=7.0
Pod documented
1490 1 my ($self,$url,$data)=@_;
1491  
1492 1 my $uri=$self->api_url.$url;
1493 1 my $json=eval {to_json($data)};
1494 1 ▶ return $self->new_false("Failed to convert \$data to json, error was $@") if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1 1
1495  
1496 1 my $request=new HTTP::Request(POST=>$uri,$self->default_headers,$json);
1497 1 return $self->new_true($request);
1498 }
1499  
1500 =item * my $id=$self->queue_builder($cb,$method,$url,$data);
1501  
1502 Returns the ID of the object in the request for $method.
1503  
1504 =cut
1505  
1506 0 ▶sub queue_builder {
Subroutine queue_builder: not called CC=3 SCAR=24.8
Pod documented
1507 0 my ($self,$cb,$method,$url,$data)=@_;
1508  
1509 0 my $result=$self->$method($url,$data);
1510 0 ▶ return $self->queue_result($cb,$result) unless $result;
Branch: 1 branch
BranchTrueFalseTotal
unless $result 0 0 0
1511 0 my $request=$result->get_data;
1512  
1513 0 my $wrap;
1514 0 my $count=$self->retryCount;
1515 0 ▶ if($self->is_blocking) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_blocking) { } 0 0 0
1516 0 ▶ $wrap=sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
1517 0 my ($self,$id,$result,undef,$response)=@_;
1518  
1519 0 ▶ return $cb->(@_) if $result or !($response->code==429 and $count-- >0);
Branch: 1 branch
BranchTrueFalseTotal
if $result or not $response->code == 429 && $count-- > 0 0 0 0
Condition0%0/6
$result or not $response->code == 429 && $count-- > 0
l!l&&r!l&&!r
000
$response->code == 429 && $count-- > 0
!ll&&!rl&&r
000
MC/DC0%0/3
$result or not $response->code == 429 && $count-- > 0
$result $response->code == 429 $count-- > 0
Truth table0%0/4
A or not(B && C)
A= $resultB= $response->code == 429C= $count-- > 0
ABCresult
1XX1
00X1
0101
0110
1520 0 ▶ my $timeout=looks_like_number($response->header('Retry-After')) ? $response->header('Retry-After') : $self->retryTimeout;
Branch: 1 branch
BranchTrueFalseTotal
&looks_like_number(scalar $response->header('Retry-After')) ? : 0 0 0
1521 0 $self->log_warn("Request: $id recived a 429 response, will retry in $timeout seconds");
1522
1523  
1524 0 ▶ if($count>0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count > 0) 0 0 0
1525 0 ▶ my $next_id=$self->queue_request($request,sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1526 0 my ($self,undef,$result,undef,$response)=@_;
1527 0 $wrap->($self,$id,$result,$request,$response);
1528 0 });
1529 0 $self->add_ids_for_blocking($next_id);
1530 0 return $self->agent->run_next;
1531 }
1532  
1533 0 sleep $timeout;
1534 0 ▶ my $code=sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1535 0 my ($self,undef,$result,undef,$response)=@_;
1536 0 $cb->($self,$id,$result,$request,$response);
1537 0 };
1538
1539 0 my $next_id=$self->queue_request($request,$code);
1540 0 $self->add_ids_for_blocking($next_id);
1541 0 $self->agent->run_next;
1542 0 };
1543 } else {
1544 0 ▶ $wrap=sub {
Subroutine __ANON__: not called CC=7 SCAR=40.3
1545 0 my ($self,$id,$result,undef,$response)=@_;
1546 0 ▶ return $cb->(@_) if $result || !(($response->code==429 || $response->code==404) && $count-- >0);
Branch: 1 branch
BranchTrueFalseTotal
if $result or not +($response->code == 429 || $response->code == 404) && $count-- > 0 0 0 0
Condition0%0/9
$result or not +($response->code == 429 || $response->code == 404) && $count-- > 0
l!l&&r!l&&!r
000
($response->code == 429 || $response->code == 404) && $count-- > 0
!ll&&!rl&&r
000
$response->code == 429 or $response->code == 404
l!l&&r!l&&!r
000
MC/DC0%0/4
$result or not +($response->code == 429 || $response->code == 404) && $count-- > 0
$result $response->code == 429 $response->code == 404 $count-- > 0
Truth table0%0/6
A or not(B or C && D)
A= $resultB= $response->code == 429C= $response->code == 404D= $count-- > 0
ABCDresult
1XXX1
000X1
01X01
00101
01X10
00110
1547 0 ▶ my $timeout=looks_like_number($response->header('Retry-After')) ? $response->header('Retry-After') : $self->retryTimeout;
Branch: 1 branch
BranchTrueFalseTotal
&looks_like_number(scalar $response->header('Retry-After')) ? : 0 0 0
1548 0 $self->log_warn("Request: $id recived a 429 response, will retry in $timeout seconds");
1549  
1550 0 ▶ if($count>0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count > 0) 0 0 0
1551 0 my $ae;
1552 0 ▶ $ae=AnyEvent->timer(after=>$timeout,cb=>sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1553 0 ▶ my $next_id=$self->queue_request($request,sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1554 0 my ($self,undef,$result,undef,$response)=@_;
1555 0 $wrap->($self,$id,$result,$request,$response);
1556 0 });
1557 0 $self->add_ids_for_blocking($next_id);
1558 0 $self->agent->run_next;
1559 0 delete $self->retries->{$ae};
1560 0 undef $ae;
1561 0 });
1562 0 return $self->retries->{$ae}=$ae;
1563 }
1564 0 ▶ my $code=sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1565 0 my ($self,undef,$result,undef,$response)=@_;
1566 0 $cb->($self,$id,$result,$request,$response);
1567 0 };
1568  
1569 0 my $ae;
1570 0 ▶ $ae=AnyEvent->timer(after=>$timeout,cb=>sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1571 0 my $next_id=$self->queue_request($request,$code);
1572 0 $self->add_ids_for_blocking($next_id);
1573 0 $self->agent->run_next;
1574 0 delete $self->retries->{$ae};
1575 0 undef $ae;
1576 0 });
1577 0 return $self->retries->{$ae}=$ae;
1578  
1579 0 };
1580 }
1581  
1582  
1583  
1584 0 return $self->queue_request($request,$wrap);
1585 }
1586  
1587  
1588 =item * my $id=$self->que_post_json($cb,$url,$data);
1589  
1590 Queue's a json post and returns the id
1591  
1592 =cut
1593  
1594 0 ▶sub que_post_json {
Subroutine que_post_json: not called CC=1 SCAR=6.9
Pod documented
1595 0 my ($self,$cb,$url,$data)=@_;
1596 0 return $self->queue_builder($cb,'build_post_json',$url,$data);
1597 }
1598  
1599 =item * my $result=$self->build_put_json($url,$data);
1600  
1601 Returns a Data::Result object; When true it contains an HTTP::Request Object For $url, the body will consist of $data converted to json. When false it contains why it failed.
1602  
1603 =cut
1604  
1605 1 ▶sub build_put_json {
Subroutine build_put_json: called CC=2 SCAR=7.0
Pod documented
1606 1 my ($self,$url,$data)=@_;
1607  
1608 1 my $uri=$self->api_url.$url;
1609 1 my $json=eval {to_json($data)};
1610 1 ▶ return $self->new_false("Failed to convert \$data to json, error was $@") if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1 1
1611  
1612 1 my $request=new HTTP::Request(PUT=>$uri,$self->default_headers,$json);
1613 1 return $self->new_true($request);
1614 }
1615  
1616 =item * my $id=$self->que_put_json($cb,$url,$data);
1617  
1618 Queue's a json put and returns the id
1619  
1620 =cut
1621  
1622 0 ▶sub que_put_json {
Subroutine que_put_json: not called CC=1 SCAR=6.9
Pod documented
1623 0 my ($self,$cb,$url,$data)=@_;
1624 0 return $self->queue_builder($cb,'build_put_json',$url,$data);
1625 }
1626  
1627 =item * my $result=$self->build_post_form($url,$data);
1628  
1629 Returns a Data::Result Object, when true it contains the correctly fromatted HTTP::Request Object, when false it contains why it failed.
1630  
1631 =cut
1632  
1633 1 ▶sub build_post_form {
Subroutine build_post_form: called CC=4 SCAR=14.1
Pod documented
1634 1 my ($self,$url,$data)=@_;
1635  
1636 1 my $uri=$self->api_url.$url;
1637 1 my $form_ref;
1638 1 ▶ if(is_plain_arrayref($data)) {
Branch: 2 branches
BranchTrueFalseTotal
if (Ref::Util::XS::is_plain_arrayref($data)) { } 0 1 1
elsif (Ref::Util::XS::is_plain_hashref($data)) { } 1 0 1
1639 0 $form_ref=$data;
1640 } elsif(is_plain_hashref($data)) {
1641 1 $form_ref=[%{$data}];
1642 } else {
1643 0 $self->new_failse('Failed to create form post, error was: $data is not a hash or array ref');
1644 }
1645  
1646 1 my $headers=$self->default_headers;
1647 1 $headers->header('Content-Type', 'multipart/form-data');
1648  
1649 1 my $post=POST $uri,$data;
1650 1 my @list=$headers->flatten;
1651  
1652 1 ▶ while(my ($key,$value)=splice @list,0,2) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@list, 0, 2)) 3 1 4
1653 3 $post->header($key,$value);
1654 }
1655  
1656 1 return $self->new_true($post);
1657 }
1658  
1659 =item * my $id=$self->que_post_form($cb,$url,$data);
1660  
1661 Queue's a form post and returns the id
1662  
1663 =cut
1664  
1665 0 ▶sub que_post_form {
Subroutine que_post_form: not called CC=1 SCAR=6.9
Pod documented
1666 0 my ($self,$cb,$url,$data)=@_;
1667 0 return $self->queue_builder($cb,'build_post_form',$url,$data);
1668 }
1669  
1670 =item * my $result=$self->build_get($url,$data);
1671  
1672 Returns a Data::Result Object, when true it contains the correctly fromatted HTTP::Request Object, when false it contains why it failed.
1673  
1674 =cut
1675  
1676 1 ▶sub build_get {
Subroutine build_get: called CC=4 SCAR=14.1
Pod documented
1677 1 my ($self,$url,$data)=@_;
1678  
1679 1 my $uri=$self->api_url.$url.'?';
1680 1 my @list;
1681 1 ▶ if(is_plain_arrayref($data)) {
Branch: 2 branches
BranchTrueFalseTotal
if (Ref::Util::XS::is_plain_arrayref($data)) { } 0 1 1
elsif (Ref::Util::XS::is_plain_hashref($data)) { } 1 0 1
1682 0 @list=@{$data};
1683 } elsif(is_plain_hashref($data)) {
1684 1 @list=%{$data};
1685 }
1686  
1687 1 my $headers=$self->default_headers;
1688  
1689 1 my @args;
1690 1 ▶ while(my ($key,$value)=splice @list,0,2) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@list, 0, 2)) 1 1 2
1691 1 push @args,uri_escape_utf8($key).'='.uri_escape_utf8($value);
1692 }
1693 1 my $args=join '&',@args;
1694 1 $uri .=$args;
1695  
1696 1 $uri=~ s/\?$//s;
1697 1 my $get=new HTTP::Request(GET=>$uri,$self->default_headers);
1698  
1699 1 return $self->new_true($get);
1700 }
1701  
1702 =item * my $self->que_getRaw($cb,$raw_url)
1703  
1704 Que's a diy get request
1705  
1706 =cut
1707  
1708 0 ▶sub que_getRaw {
Subroutine que_getRaw: not called CC=1 SCAR=6.9
Pod documented
1709 0 my ($self,$cb,$url)=@_;
1710 0 my $req=HTTP::Request->new(GET=>$url,$self->default_headers);
1711 0 return $self->queue_request($req,$cb);
1712 }
1713  
1714 =item * my $id=$self->que_get($cb,$url,$data);
1715  
1716 Queue's a form post and returns the id
1717  
1718 =cut
1719  
1720 0 ▶sub que_get {
Subroutine que_get: not called CC=1 SCAR=6.9
Pod documented
1721 0 my ($self,$cb,$url,$data)=@_;
1722 0 return $self->queue_builder($cb,'build_get',$url,$data);
1723 }
1724  
1725 =item * my $result=$self->build_head($url,$data);
1726  
1727 Returns a Data::Result Object, when true it contains the correctly fromatted HTTP::Request Object, when false it contains why it failed.
1728  
1729 =cut
1730  
1731 1 ▶sub build_head {
Subroutine build_head: called CC=4 SCAR=14.1
Pod documented
1732 1 my ($self,$url,$data)=@_;
1733  
1734 1 my $uri=$self->api_url.$url.'?';
1735 1 my @list;
1736 1 ▶ if(is_plain_arrayref($data)) {
Branch: 2 branches
BranchTrueFalseTotal
if (Ref::Util::XS::is_plain_arrayref($data)) { } 0 1 1
elsif (Ref::Util::XS::is_plain_hashref($data)) { } 1 0 1
1737 0 @list=@{$data};
1738 } elsif(is_plain_hashref($data)) {
1739 1 @list=%{$data};
1740 }
1741  
1742 1 my $headers=$self->default_headers;
1743  
1744  
1745 1 my @args;
1746 1 ▶ while(my ($key,$value)=splice @list,0,2) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@list, 0, 2)) 1 1 2
1747 1 push @args,uri_escape_utf8($key).'='.uri_escape_utf8($value);
1748 }
1749 1 my $args=join '&',@args;
1750 1 $uri .=$args;
1751  
1752 1 my $get=new HTTP::Request(HEAD=>$uri,$self->default_headers);
1753  
1754 1 return $self->new_true($get);
1755 }
1756  
1757 =item * my $id=$self->que_head($cb,$url,$data);
1758  
1759 Queue's a form post and returns the id
1760  
1761 =cut
1762  
1763 0 ▶sub que_head{
Subroutine que_head: not called CC=1 SCAR=6.9
Pod documented
1764 0 my ($self,$cb,$url,$data)=@_;
1765 0 return $self->queue_builder($cb,'build_head',$url,$data);
1766 }
1767  
1768 =item * my $result=$self->build_delete($url,$data);
1769  
1770 Returns a Data::Result Object, when true it contains the delete request, when false it contains why it failed.
1771  
1772 =cut
1773  
1774 1 ▶sub build_delete {
Subroutine build_delete: called CC=4 SCAR=14.1
Pod documented
1775 1 my ($self,$url,$data)=@_;
1776  
1777 1 my $uri=$self->api_url.$url.'?';
1778 1 my @list;
1779 1 ▶ if(is_plain_arrayref($data)) {
Branch: 2 branches
BranchTrueFalseTotal
if (Ref::Util::XS::is_plain_arrayref($data)) { } 0 1 1
elsif (Ref::Util::XS::is_plain_hashref($data)) { } 1 0 1
1780 0 @list=@{$data};
1781 } elsif(is_plain_hashref($data)) {
1782 1 @list=%{$data};
1783 }
1784  
1785 1 my $headers=$self->default_headers;
1786  
1787 1 my @args;
1788 1 ▶ while(my ($key,$value)=splice @list,0,2) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@list, 0, 2)) 1 1 2
1789 1 push @args,uri_escape_utf8($key).'='.uri_escape_utf8($value);
1790 }
1791 1 my $args=join '&',@args;
1792 1 $uri .=$args;
1793  
1794 1 my $get=new HTTP::Request(DELETE=>$uri,$self->default_headers);
1795  
1796 1 return $self->new_true($get);
1797 }
1798  
1799 =item * my $id=$self->que_delete($cb,$url,$data);
1800  
1801 Ques a delete to run.
1802  
1803 =cut
1804  
1805 0 ▶sub que_delete {
Subroutine que_delete: not called CC=1 SCAR=6.9
Pod documented
1806 0 my ($self,$cb,$url,$data)=@_;
1807  
1808 0 ▶ my $code=sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1809 0 my ($self,$id,$result,$request,$response)=@_;
1810 0 $self->handle_delete($cb,$id,$result,$request,$response);
1811 0 };
1812 0 return $self->queue_builder($code,'build_delete',$url,$data);
1813 }
1814  
1815 =item * $self->handle_delete($cb,$id,$result,$result)
1816  
1817 Internal handler for delete results
1818  
1819 =cut
1820  
1821 2 ▶sub handle_delete {
Subroutine handle_delete: called CC=2 SCAR=6.9
Pod documented
1822 2 my ($self,$cb,$id,undef,$request,$response)=@_;
1823 2 ▶ if($response->code==204) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->code == 204) { } 1 1 2
1824 1 my $result=$self->new_true({message=>'Deleted'});
1825 1 $cb->($self,$id,$result,$request,$response);
1826 } else {
1827 1 my $result=$self->new_false("Delete Failed, error was: ".$response->status_line);
1828 1 $cb->($self,$id,$result,$request,$response);
1829 }
1830 }
1831  
1832 =back
1833  
1834 =head1 AUTHOR
1835  
1836 Michael Shipper <AKALINUX@CPAN.ORG>
1837  
1838 =cut
1839  
1840 3 1;
« SparkBot.pm ↑ Summary SparkBot/SharedRole.pm »