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   155567 use Modern::Perl;
  4         9  
  4         34  
20 4     4   1131 use Moo::Role;
  4         16981  
  4         26  
21 4     4   2003 use HTTP::Headers;
  4         6792  
  4         157  
22 4     4   29 use Digest::MD5 qw(md5_base64);
  4         10  
  4         302  
23 4     4   528 use MooX::Types::MooseLike::Base qw(:all);
  4         6623  
  4         1419  
24 4     4   2330 use UUID::Tiny ':std';
  4         43230  
  4         818  
25 4     4   525 use namespace::clean;
  4         10974  
  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 21 my ($self)=@_;
61 9         40 my $h=new HTTP::Headers;
62 9         110 $h->header(Authorization=>'Bearer ' .$self->token);
63 9         453 $h->header('Content-Type', 'application/json; charset=UTF-8');
64 9         362 return $h;
65             }
66              
67             =back
68              
69             =head1 AUTHOR
70              
71             Michael Shipper <AKALINUX@CPAN.ORG>
72              
73             =cut
74              
75             1;