Edge/Helper.pm

filter: Statementstmt 23.5% 20 / 85 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 22 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 60.0% 6 / 10 Podpod 100% 4 / 4 totaltotal 18.1% 30 / 165 CC 26 SCAR 47.8
CC
26
Cov
14%
refresh_developer_app
240.0
get_all_clients
56.0
get_top_developer_app
30.0
CRAP 118.9
↑ Summary Edge.pm »
1 package Apigee::Edge::Helper;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 our $VERSION = '0.08'; ## VERSION
6  
7 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use base 'Apigee::Edge';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use URI::Split qw(uri_split);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use vars qw/$errstr/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 0 ▶sub errstr { return $errstr || Apigee::Edge->errstr }
Subroutine errstr: not called CC=2 SCAR=17.9
Pod documented
Condition0%0/3
$Apigee::Edge::Helper::errstr || 'Apigee::Edge'->errstr
l!l&&r!l&&!r
000
MC/DC0%0/2
$Apigee::Edge::Helper::errstr || 'Apigee::Edge'->errstr
$Apigee::Edge::Helper::errstr 'Apigee::Edge'->errstr
Truth table0%0/3
A || B
A= $Apigee::Edge::Helper::errstrB= 'Apigee::Edge'->errstr
ABresult
1X1
011
000
13  
14 0 ▶sub get_top_developer_app {
Subroutine get_top_developer_app: not called CC=5 SCAR=34.0
Pod documented
15 0 my ($self, $email) = @_;
16  
17 0 my $apps = $self->get_developer_apps($email, {expand => 'true'});
18 0 ▶ return unless ($apps and $apps->{app} and scalar(@{$apps->{app}}));
Branch: 1 branch
BranchTrueFalseTotal
unless $apps and $apps->{"app"} and scalar @{$apps->{"app"};} 0 0 0
Condition0%0/5
$apps and $apps->{"app"} and scalar @{$apps->{"app"};}
!ll
00
$apps and $apps->{"app"}
!ll&&!rl&&r
000
MC/DC0%0/2
$apps and $apps->{"app"} and scalar @{$apps->{"app"};}
$apps $apps->{"app"}
Truth table0%0/3
A and B
A= $appsB= $apps->{"app"}
ABresult
0X0
100
111
19  
20 0 my $my_app = $apps->{app}->[0];
21  
22 # flatten attrs into $my_app
23 0 my %attrs = map { $_->{name} => $_->{value} } @{$my_app->{attributes}};
24 0 $my_app = {%$my_app, %attrs};
25  
26 0 ▶ $my_app->{display_name} = $attrs{DisplayName} || $my_app->{name}; # shortcut
Condition0%0/3
$attrs{'DisplayName'} || $my_app->{'name'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$attrs{'DisplayName'} || $my_app->{'name'}
$attrs{'DisplayName'} $my_app->{'name'}
Truth table0%0/3
A || B
A= $attrs{'DisplayName'}B= $my_app->{'name'}
ABresult
1X1
011
000
27  
28 0 return $my_app;
29 }
30  
31 0 ▶sub refresh_developer_app { ## no critic (ArgUnpacking)
Subroutine refresh_developer_app: not called CC=15 SCAR=54.8
Pod documented
32 0 my $self = shift;
33 0 ▶ my %params = @_ % 2 ? %{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ % 2 ? : 0 0 0
34  
35 0 my $name = $params{name};
36 0 ▶ if (!$name) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $name) { } 0 0 0
elsif (not $name =~ /^[\w\s-]{5,30}$/) { } 0 0 0
37 0 $errstr = 'Application Name must be provided.';
38 0 return;
39 } elsif ($name !~ /^[\w\s-]{5,30}$/) { # restrict to only 5-30 alphanumerics or spaces.
40 0 $errstr = 'Application Name data is invalid.';
41 0 return;
42 }
43 0 my $callback_url = $params{callbackUrl};
44 0 ▶ if (!$callback_url) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $callback_url) { } 0 0 0
elsif ($callback_url =~ /['"<>]/) { } 0 0 0
45 0 $errstr = 'Callback URL must be provided.';
46 0 return;
47 } elsif ($callback_url =~ /['"<>]/) { # rule out quotes or anglebrackets.
48 0 $errstr = 'Callback URL data is invalid.';
49 0 return;
50 } else {
51 0 my ($scheme, $host, $path) = uri_split($callback_url);
52 # in theory a uri can be almost anything; but for sanity insist on at least this much..
53 0 ▶ unless ($scheme && $host && $path) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($scheme and $host and $path) 0 0 0
Condition0%0/6
$scheme and $host and $path
!ll&&!rl&&r
000
$scheme and $host
!ll&&!rl&&r
000
MC/DC0%0/3
$scheme and $host and $path
$scheme $host $path
Truth table0%0/4
A and B and C
A= $schemeB= $hostC= $path
ABCresult
0XX0
10X0
1100
1111
54 0 $errstr = 'Callback URL format is invalid. ';
55 0 return;
56 }
57 }
58  
59 0 my $email = $params{email};
60 0 my $my_app = $params{app};
61 0 ▶ unless (exists $params{app}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $params{"app"}) 0 0 0
62 0 $my_app = $self->get_top_developer_app($email);
63 }
64  
65 0 ▶ if ($my_app) {
Branch: 1 branch
BranchTrueFalseTotal
if ($my_app) { } 0 0 0
66 # update app
67 $self->update_developer_app(
68 $email,
69 $my_app->{name},
70 {
71 0 attributes => [{
72 name => 'DisplayName',
73 value => $name,
74 }
75 ],
76 callbackUrl => $callback_url,
77 });
78 0 $my_app->{display_name} = $name;
79 0 $my_app->{callbackUrl} = $callback_url;
80 0 $errstr = 'Update successful';
81 } else {
82 0 my $developer = $self->get_developer($email);
83 0 ▶ unless ($developer and $developer->{developerId}) { # create on demand
Branch: 1 branch
BranchTrueFalseTotal
unless ($developer and $developer->{"developerId"}) 0 0 0
Condition0%0/3
$developer and $developer->{"developerId"}
!ll&&!rl&&r
000
MC/DC0%0/2
$developer and $developer->{"developerId"}
$developer $developer->{"developerId"}
Truth table0%0/3
A and B
A= $developerB= $developer->{"developerId"}
ABresult
0X0
100
111
84 $developer = $self->create_developer(
85 "email" => $email,
86 "firstName" => $params{firstName},
87 "lastName" => $params{lastName},
88 "userName" => $params{userName},
89 0 );
90 }
91  
92 $my_app = $self->create_developer_app(
93 $email,
94 {
95 name => $name,
96 callbackUrl => $callback_url,
97 0 ▶ $params{apiProducts} ? (apiProducts => $params{apiProducts}) : (),
Branch: 1 branch
BranchTrueFalseTotal
$params{'apiProducts'} ? : 0 0 0
98 });
99 0 ▶ if ($my_app->{message}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($my_app->{"message"}) 0 0 0
100 0 $errstr = $my_app->{message};
101 0 return;
102 }
103 0 $my_app->{display_name} = $name;
104 0 $errstr = "$name has been registered. New OAuth credentials are available";
105 }
106  
107 0 return $my_app;
108 }
109  
110 0 ▶sub get_all_clients {
Subroutine get_all_clients: not called CC=7 SCAR=40.3
Pod documented
111 0 my ($self) = @_;
112  
113 0 ▶ my $apps = $self->get_apps(
Branch: 1 branch
BranchTrueFalseTotal
my $apps = $self->get_apps("expand", "true", "includeCred", "true") or croak('Apigee::Edge failure: ' . $self->errstr) 0 0 0
114 expand => 'true',
115 includeCred => 'true'
116 ) or croak "Apigee::Edge failure: " . $self->errstr;
117 0 my $CLIENTS = {};
118 0 for my $app (@{$apps->{app}}) {
119 0 ▶ next unless $app->{status} eq 'approved';
Branch: 1 branch
BranchTrueFalseTotal
unless $app->{"status"} eq "approved" 0 0 0
120 0 ▶ my $consumerKey = eval {
Condition0%0/2
eval { do { my $credentials = $app->{'credentials'}; $credentials->[0]{'consumerKey'} } } || (next)
l!l
00
MC/DC0%0/1
eval { do { my $credentials = $app->{'credentials'}; $credentials->[0]{'consumerKey'} } } || (next)
eval { do { my $credentials = $app->{'credentials'}; $credentials->[0]{'consumerKey'} } }
Truth table0%0/2
A
A= eval { do { my $credentials = $app->{'credentials'}; $credentials->[0]{'consumerKey'} } }
Aresult
11
00
121 0 my $credentials = $app->{credentials};
122 0 $credentials->[0]->{consumerKey};
123 } || next;
124 0 ▶ if (my $attrs = $app->{attributes}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $attrs = $app->{"attributes"}) 0 0 0
125 0 my %attrs = map { $_->{name} => $_->{value} } @$attrs;
126 0 ▶ $app->{name} = $attrs{DisplayName} if $attrs{DisplayName};
Branch: 1 branch
BranchTrueFalseTotal
if $attrs{"DisplayName"} 0 0 0
127 }
128 0 $CLIENTS->{$consumerKey} = $app->{name};
129 }
130 0 return $CLIENTS;
131 }
132  
133 1 1;
134 __END__
↑ Summary Edge.pm »