CustomerIO/Trigger.pm

filter: Statementstmt 100% 35 / 35 Branchbran 55.5% 10 / 18 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 11 / 11 Podpod 85.7% 6 / 7 totaltotal 79.0% 64 / 81 CC 13 SCAR 16.7
CC
13
Cov
80%
errors
11.8
new
3.0
status
2.0
CRAP 5.3
↑ Summary CustomerIO.pm »
1 package WebService::Async::CustomerIO::Trigger;
2  
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =head1 NAME
7  
8 WebService::Async::CustomerIO::Trigger - Class for working with triggers end points
9  
10 =head1 SYNOPSIS
11  
12 =head1 DESCRIPTION
13  
14 =cut
15  
16 5 ▶use Carp qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 5 our $VERSION = '0.002'; ## VERSION
19  
20 =head2 new
21  
22 Creates a new API client object
23  
24 Usage: C<< new(%params) -> obj >>
25  
26 Parameters:
27  
28 =over 4
29  
30 =item * C<campaign_id>
31  
32 =item * C<api_client>
33  
34 =back
35  
36 =cut
37  
38 7 ▶sub new {
Subroutine new: called CC=3 SCAR=11.0
Pod documented
39 7 my ($cls, %param) = @_;
40  
41 7 ▶ $param{$_} or Carp::croak "Missing required argument: $_" for (qw(campaign_id api_client));
Branch: 1 branch
BranchTrueFalseTotal
$param{$_} or Carp::croak("Missing required argument: $_") 11 2 13
42  
43 5 return bless \%param, $cls;
44 }
45  
46 =head2 api
47  
48 =cut
49  
50 4 ▶sub api { return shift->{api_client} }
Subroutine api: called CC=1 SCAR=0.0
Pod documented
51  
52 =head2 id
53  
54 =cut
55  
56 7 ▶sub id { return shift->{id} }
Subroutine id: called CC=1 SCAR=0.0
Pod documented
57  
58 =head2 campaign_id
59  
60 =cut
61  
62 4 ▶sub campaign_id { return shift->{campaign_id} }
Subroutine campaign_id: called CC=1 SCAR=0.0
Pod documented
63  
64 =head2 activate
65  
66 Trigger broadcast campaign
67  
68 Usage: C<< activate(%param) -> Future($obj) >>
69  
70 =cut
71  
72 1 ▶sub activate {
Subroutine activate: called CC=2 SCAR=7.0
Pod documented
73 1 my ($self, $params) = @_;
74  
75 1 ▶ Carp::croak 'This trigger is already activated' if $self->id;
Branch: 1 branch
BranchTrueFalseTotal
if $self->id 0 1 1
76  
77 1 my $campaign_id = $self->campaign_id;
78 return $self->api->api_request('POST', "campaigns/$campaign_id/triggers", $params, 'trigger')->then(
79 1 ▶ sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
80 1 my ($response) = @_;
81  
82 return Future->fail("UNEXPECTED_RESPONSE_FORMAT", 'customerio', $response)
83 1 ▶ if !defined $response->{id};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $response->{"id"} 0 1 1
84  
85 1 $self->{id} = $response->{id};
86  
87 1 return Future->done($response);
88 1 });
89 }
90  
91 =head2 status
92  
93 Retrieve status of a broadcast
94  
95 Usage: C<< status() -> Future($response) >>
96  
97 =cut
98  
99 1 ▶sub status {
Subroutine status: called CC=2 SCAR=7.1
Pod documented
100 1 my ($self) = @_;
101  
102 1 ▶ Carp::croak 'This trigger has not been activated yet' unless $self->id;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->id 0 1 1
103  
104 1 return $self->api->api_request(GET => 'campaigns/' . $self->campaign_id . '/triggers/' . $self->id);
105 }
106  
107 =head2 get_errors
108  
109 Retrieve per-user data file processing errors.
110  
111 Usage: C<< get_errors($start, $limit) -> Future(%$result) >>
112  
113 =cut
114  
115 1 ▶sub errors {
Subroutine errors: called CC=8 SCAR=24.7
Pod undocumented
116 1 my ($self, $start, $limit) = @_;
117  
118 1 my $trigger_id = $self->id;
119 1 my $campaign_id = $self->campaign_id;
120  
121 1 ▶ Carp::croak 'Trying to get errors for unsaved trigger' unless defined $trigger_id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $trigger_id 0 1 1
122 1 ▶ Carp::croak "Invalid value for start $start" if defined $start && int($start) < 0;
Branch: 1 branch
BranchTrueFalseTotal
if defined $start and int $start < 0 0 1 1
Condition33%1/3
defined $start and int $start < 0
!ll&&!rl&&r
100
MC/DC0%0/2
defined $start and int $start < 0
defined $start int $start < 0
Truth table33%1/3
A and B
A= defined $startB= int $start < 0
ABresult
0X0
100
111
123 1 ▶ Carp::croak "Invalid value for limit $limit" if defined $limit && int($limit) <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if defined $limit and int $limit <= 0 0 1 1
Condition33%1/3
defined $limit and int $limit <= 0
!ll&&!rl&&r
100
MC/DC0%0/2
defined $limit and int $limit <= 0
defined $limit int $limit <= 0
Truth table33%1/3
A and B
A= defined $limitB= int $limit <= 0
ABresult
0X0
100
111
124  
125 1 ▶ return $self->api->api_request(
Branch: 2 branches
BranchTrueFalseTotal
defined $start ? : 0 1 1
defined $limit ? : 0 1 1
126 GET => "campaigns/$campaign_id/triggers/$trigger_id/errors",
127 {(defined $start ? (start => int($start)) : ()), (defined $limit ? (limit => int($limit)) : ()),},
128 );
129 }
130  
131 5 1;
↑ Summary CustomerIO.pm »