File Coverage

blib/lib/AnyEvent/SparkBot/SharedRole.pm
Criterion Covered Total %
statement 26 27 96.3
branch n/a
condition n/a
subroutine 8 9 88.8
pod 2 2 100.0
total 36 38 94.7


line stmt bran cond sub pod time code
1             package AnyEvent::SparkBot::SharedRole;
2              
3             =head1 NAME
4              
5             AnyEvent::SparkBot::SharedRole - Shared methods for SparkBot
6              
7             =head1 SYNOPSIS
8              
9             use Modern::Perl;
10             use Moo;
11             BEGIN { with 'AnyEvent::SparkBot::SharedRole' }
12              
13             =head1 DESCRIPTION
14              
15             Shared functions used between different sparkbot classes.
16              
17             =cut
18              
19 4     4   152464 use Modern::Perl;
  4         11  
  4         40  
20 4     4   1152 use Moo::Role;
  4         17576  
  4         43  
21 4     4   2060 use HTTP::Headers;
  4         7102  
  4         188  
22 4     4   26 use Digest::MD5 qw(md5_base64);
  4         9  
  4         284  
23 4     4   563 use MooX::Types::MooseLike::Base qw(:all);
  4         6905  
  4         1450  
24 4     4   2324 use UUID::Tiny ':std';
  4         43776  
  4         740  
25 4     4   520 use namespace::clean;
  4         11462  
  4         34  
26              
27             has token=>(
28             required=>1,
29             is=>'ro',
30             isa=>Str,
31             );
32              
33             =head1 Constructor Arguments added
34              
35             The following arguments are required when creating a new instance of a class that uses this role:
36              
37             token: This is the cisco authentication token for your app
38              
39             =head1 Role methods
40              
41             =over 4
42              
43             =item * my $uuid=$self->uuidv4()
44              
45             Returns the next uuid.v4 ( md5 sum base64 encoded, due to limitations of cisco spark )
46              
47             =cut
48              
49             sub uuidv4 {
50 0     0 1 0 return md5_base64(create_uuid(UUID_V4));
51             }
52              
53             =item * my $headers=$self->default_headers()
54              
55             Returns an HTTP::Headers Object that contains the default header values
56              
57             =cut
58              
59             sub default_headers {
60 9     9 1 18 my ($self)=@_;
61 9         36 my $h=new HTTP::Headers;
62 9         101 $h->header(Authorization=>'Bearer ' .$self->token);
63 9         466 $h->header('Content-Type', 'application/json; charset=UTF-8');
64 9         368 return $h;
65             }
66              
67             =back
68              
69             =head1 AUTHOR
70              
71             Michael Shipper <AKALINUX@CPAN.ORG>
72              
73             =cut
74              
75             1;