| 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
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
$self->{"lastHTTPCode"} ne "" and $self->{"lastHTTPCode"} != 202
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
| |||||||||||||||||||||||||||||
| 77 | 0 | return 1; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | else { | ||||||||||||||||||||||||||||
| 80 | 0 | return 0; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 1 | 1; | |||||||||||||||||||||||||||