SelectPdf/AsyncJobClient.pm

filter: Statementstmt 33.3% 8 / 24 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 40.0% 2 / 5 Podpod 100% 3 / 3 totaltotal 36.1% 13 / 36 SCAR 18.4
CC
3
Cov
29%
getResult
6.0
finished
6.0
new
2.0
CRAP 6.3
« SelectPdf/UsageClient.pm ↑ Summary SelectPdf/WebElementsClient.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 =head1 NAME
8
9 SelectPdf::AsyncJobClient - Get the result of an asynchronous call.
10
11 =head1 METHODS
12
13 =head2 new( $apiKey, $JobId )
14
15 Construct the async job client.
16
17 my $client = SelectPdf::AsyncJobClient->new($apiKey, $jobId);
18
19 Parameters:
20
21 - $apiKey API Key.
22
23 - $jobId Job ID.
24 =cut
25 sub new {
26 0 ▶ my $type = shift;
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
27 0 my $self = $type->SUPER::new;
28
29 # API endpoint
30 0 $self->{apiEndpoint} = "https://selectpdf.com/api2/asyncjob/";
31
32 0 $self->{parameters}{"key"} = shift;
33 0 $self->{parameters}{"job_id"} = shift;
34
35 0 bless $self, $type;
36 0 return $self;
37 }
38
39 =head2 getResult
40
41 Get result of the asynchronous job.
42
43 Returns:
44
45 - Byte array containing the resulted file if the job is finished. Returns 'undef' if the job is still running.
46 =cut
47 sub getResult() {
48 0 ▶ my($self) = @_;
Subroutine getResult: not called CC=2 SCAR=17.9
Pod documented
49
50 0 my $result = $self->SUPER::performPost();
51
52 0 ▶ if ($self->{jobId}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'jobId'}) { } 0 0 0
53 0 return undef;
54 }
55 else {
56 0 return $result;
57 }
58 }
59
60 =head2 finished
61
62 Check if asynchronous job is finished.
63
64 Returns:
65
66 - True if job finished.
67 =cut
68 sub finished() {
69 0 ▶ my($self) = @_;
Subroutine finished: not called CC=2 SCAR=17.9
Pod documented
70
71 0 ▶ if ($self->{lastHTTPCode} eq 200) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'lastHTTPCode'} eq 200) { } 0 0 0
72 0 return 1;
73 }
74 else {
75 0 return 0;
76 }
77 }
78
79 1 1;
« SelectPdf/UsageClient.pm ↑ Summary SelectPdf/WebElementsClient.pm »