blib/lib/Webservice/Rosary/API.pm

filter: Statementstmt 51.2% 20 / 39 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 60.0% 6 / 10 Podpod 75.0% 3 / 4 totaltotal 49.1% 29 / 59 CC 4 SCAR 12.2
CC
4
Cov
44%
mp3Link
6.0
day
6.0
details
6.0
CRAP 3.4
↑ Summary
1 package Webservice::Rosary::API;
2  
3 1 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Util::H2O::More qw/baptise ddd HTTPTiny2h2o h2o/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use HTTP::Tiny qw//;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 our $VERSION = "0.1.2";
10  
11 1 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 BASEURL => "https://the-rosary-api.vercel.app/v1",
13 DAILYURL => "https://dailyrosary.cf",
14 1 };
15  
16 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
17 1 my $pkg = shift;
18 1 my $params = { @_, ua => HTTP::Tiny->new };
19 1 my $self = baptise $params, $pkg, qw//;
20 1 return $self;
21 }
22  
23 0 ▶sub _make_call {
Subroutine _make_call: not called CC=1 SCAR=6.9
24 0 my ($self, $when) = @_;
25 0 my $URL = sprintf "%s/%s", BASEURL, $when;
26 0 my $resp = HTTPTiny2h2o $self->ua->get($URL);
27 0 return $resp->content;
28 }
29  
30 #TODO - add "list", date/MMDDYY, and novena/MMDDYY
31 0 ▶sub mp3Link {
Subroutine mp3Link: not called CC=2 SCAR=17.9
Pod documented
32 0 my ($self, $when) = @_;
33 0 my @mp3 = qw/today yesterday tomorrow random/;
34 # invalid
35 0 ▶ return "" if (not grep { m/^$when$/i } @mp3);
Branch: 1 branch
BranchTrueFalseTotal
unless grep {/^$when$/i;} @mp3 0 0 0
36 # valid
37 0 return sprintf "%s/%s", DAILYURL, $self->_make_call($when)->get(0)->mp3Link;
38 }
39  
40 0 ▶sub day {
Subroutine day: not called CC=2 SCAR=17.9
Pod documented
41 0 my ($self, $when) = @_;
42 0 my @days = qw/sunday monday tuesday wednesday thursday friday/;
43 0 ▶ return "" if (not grep { m/^$when$/i } @days);
Branch: 1 branch
BranchTrueFalseTotal
unless grep {/^$when$/i;} @days 0 0 0
44 0 return $self->_make_call($when)->get(0);
45 }
46  
47 # Get detailed recitations
48 0 ▶sub details {
Subroutine details: not called CC=2 SCAR=17.9
Pod undocumented
49 0 my ($self, $when) = @_;
50 0 my @mysteries = qw/joyful glorious sorrowful luminous/;
51 0 ▶ return "" if (not grep { m/^$when$/i } @mysteries);
Branch: 1 branch
BranchTrueFalseTotal
unless grep {/^$when$/i;} @mysteries 0 0 0
52 0 return $self->_make_call($when);
53 }
54  
55 1 123
56  
57 __END__
↑ Summary