Twilio/CredentialProvider/ClientCredentialProvider.pm

filter: Statementstmt 100% 36 / 36 Branchbran 100% 2 / 2 Conditioncond 80.0% 8 / 10 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 100% 11 / 11 Podpod 100% 5 / 5 totaltotal 91.4% 64 / 70 CC 7 SCAR 10.6
CC
7
Cov
96%
new
6.0
to_auth_strategy
2.0
BEGIN
1.0
CRAP 2.9
« Twilio.pm ↑ Summary Twilio/Stream.pm »
1 package Twilio::CredentialProvider::ClientCredentialProvider;
2  
3 3 ▶use 5.016;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use parent 'Twilio::CredentialProvider::CredentialProvider';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶use Twilio::AuthStrategy::TokenAuthStrategy;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Twilio::Exceptions::ConfigurationException;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use Twilio::Http::BearerToken::ApiTokenManager;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 our $VERSION = '2.001';
13  
14 30 ▶sub new {
Subroutine new: called CC=6 SCAR=17.9
Pod documented
15 30 my ($class, $options) = @_;
16 30 ▶ $options //= {};
Condition100%2/2
$options //= {}
l!l
291
MC/DC100%1/1
$options //= {}
$options
Truth table100%2/2
A
A= $options
Aresult
11
00
17  
18 30 for my $name (qw(client_id client_secret)) {
19 57 ▶ next if length($options->{$name} // q{});
Branch: 1 branch
BranchTrueFalseTotal
if length($options->{$name} // "") 53 4 57
Condition100%2/2
$options->{$name} // ""
l!l
543
MC/DC100%1/1
$options->{$name} // ""
$options->{$name}
Truth table100%2/2
A
A= $options->{$name}
Aresult
11
00
20 4 Twilio::Exceptions::ConfigurationException->throw("$name is required");
21 }
22  
23 26 my $self = $class->SUPER::new('client-credentials');
24 26 $self->{grant_type} = 'client_credentials';
25 26 $self->{client_id} = $options->{client_id};
26 26 $self->{client_secret} = $options->{client_secret};
27 $self->{token_manager} = $options->{token_manager} // $class->token_manager_class->new(
28 {
29 grant_type => $self->{grant_type},
30 client_id => $self->{client_id},
31 client_secret => $self->{client_secret},
32 }
33 26 ▶ );
Condition66%2/3
$options->{"token_manager"} // $class->token_manager_class->new({"grant_type", $self->{"grant_type"}, "client_id", $self->{"client_id"}, "client_secret", $self->{"client_secret"}})
l!l&&r!l&&!r
2240
MC/DC0%0/2
$options->{"token_manager"} // $class->token_manager_class->new({"grant_type", $self->{"grant_type"}, "client_id", $self->{"client_id"}, "client_secret", $self->{"client_secret"}})
$options->{"token_manager"} $class->token_manager_class->new({"grant_type", $self->{"grant_type"}, "client_id", $self->{"client_id"}, "client_secret", $self->{"client_secret"}})
Truth table66%2/3
A // B
A= $options->{"token_manager"}B= $class->token_manager_class->new({"grant_type", $self->{"grant_type"}, "client_id", $self->{"client_id"}, "client_secret", $self->{"client_secret"}})
ABresult
1X1
011
000
34 26 return $self;
35 }
36  
37 22 ▶sub token_manager_class { return 'Twilio::Http::BearerToken::ApiTokenManager' }
Subroutine token_manager_class: called CC=1 SCAR=0.0
Pod documented
38  
39 # twilio-php returns a new strategy each time, and so asks for a token on every request. One
40 # strategy per provider keeps the token until it is about to expire, as twilio-python does, and
41 # clients that share the provider share the token.
42 26 ▶sub to_auth_strategy {
Subroutine to_auth_strategy: called CC=2 SCAR=7.0
Pod documented
43 26 my ($self) = @_;
44 26 ▶ $self->{auth_strategy} //= Twilio::AuthStrategy::TokenAuthStrategy->new($self->{token_manager});
Condition66%2/3
$self->{"auth_strategy"} //= "Twilio::AuthStrategy::TokenAuthStrategy"->new($self->{"token_manager"})
l!l&&r!l&&!r
8180
MC/DC0%0/2
$self->{"auth_strategy"} //= "Twilio::AuthStrategy::TokenAuthStrategy"->new($self->{"token_manager"})
$self->{"auth_strategy"} "Twilio::AuthStrategy::TokenAuthStrategy"->new($self->{"token_manager"})
Truth table66%2/3
A //= B
A= $self->{"auth_strategy"}B= "Twilio::AuthStrategy::TokenAuthStrategy"->new($self->{"token_manager"})
ABresult
1X1
011
000
45 26 return $self->{auth_strategy};
46 }
47  
48 1 ▶sub get_client_id { return $_[0]{client_id} }
Subroutine get_client_id: called CC=1 SCAR=0.0
Pod documented
49 3 ▶sub get_token_manager { return $_[0]{token_manager} }
Subroutine get_token_manager: called CC=1 SCAR=0.0
Pod documented
50  
51 3 1;
52  
53 __END__
« Twilio.pm ↑ Summary Twilio/Stream.pm »