SelectPdf/AsyncJobClient.pm

filter: Statementstmt 36.0% 9 / 25 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 40.0% 2 / 5 Podpod 100% 3 / 3 totaltotal 33.3% 14 / 42 CC 4 SCAR 18.7
CC
4
Cov
28%
finished
12.0
getResult
6.0
new
2.0
CRAP 6.5
« SelectPdf/DemoExceptions.pm ↑ Summary SelectPdf/InvoiceClient.pm »
1 package SelectPdf::AsyncJobClient;
2
3 1 ▶use SelectPdf::ApiClient;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 our @ISA = qw(SelectPdf::ApiClient);
6
7 1 our $VERSION = '1.6.0';
8
9 =head1 NAME
10
11 SelectPdf::AsyncJobClient - Get the result of an asynchronous call.
12
13 =head1 METHODS
14
15 =head2 new( $apiKey, $JobId )
16
17 Construct the async job client.
18
19 my $client = SelectPdf::AsyncJobClient->new($apiKey, $jobId);
20
21 Parameters:
22
23 - $apiKey API Key.
24
25 - $jobId Job ID.
26 =cut
27 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
28 0 my $type = shift;
29 0 my $self = $type->SUPER::new;
30
31 # API endpoint
32 0 $self->{apiEndpoint} = "https://selectpdf.com/api2/asyncjob/";
33
34 0 $self->{parameters}{"key"} = shift;
35 0 $self->{parameters}{"job_id"} = shift;
36
37 0 bless $self, $type;
38 0 return $self;
39 }
40
41 =head2 getResult
42
43 Get result of the asynchronous job.
44
45 Returns:
46
47 - Byte array containing the resulted file if the job is finished. Returns 'undef' if the job is still running.
48 =cut
49 0 ▶sub getResult() {
Subroutine getResult: not called CC=2 SCAR=17.9
Pod documented
50 0 my($self) = @_;
51
52 0 my $result = $self->SUPER::performPost();
53
54 0 ▶ if ($self->{jobId}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'jobId'}) { } 0 0 0
55 0 return undef;
56 }
57 else {
58 0 return $result;
59 }
60 }
61
62 =head2 finished
63
64 Check if asynchronous job is finished.
65
66 Returns:
67
68 - True if job finished.
69 =cut
70 0 ▶sub finished() {
Subroutine finished: not called CC=3 SCAR=24.8
Pod documented
71 0 my($self) = @_;
72
73 # 200 OK - the job is finished (successfully).
74 # 202 Accepted - the job is still running.
75 # Some other code - error - the job is finished (with error).
76 0 ▶ if ($self->{lastHTTPCode} ne "" and $self->{lastHTTPCode} != 202) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'lastHTTPCode'} ne '' and $self->{'lastHTTPCode'} != 202) { } 0 0 0
Condition0%0/3
$self->{"lastHTTPCode"} ne "" and $self->{"lastHTTPCode"} != 202
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"lastHTTPCode"} ne "" and $self->{"lastHTTPCode"} != 202
$self->{"lastHTTPCode"} ne "" $self->{"lastHTTPCode"} != 202
Truth table0%0/3
A and B
A= $self->{"lastHTTPCode"} ne ""B= $self->{"lastHTTPCode"} != 202
ABresult
0X0
100
111
77 0 return 1;
78 }
79 else {
80 0 return 0;
81 }
82 }
83
84 1 1;
« SelectPdf/DemoExceptions.pm ↑ Summary SelectPdf/InvoiceClient.pm »