| 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
| |||||||||||
| 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
| |||||||||||
| 72 | 0 | return 1; | |||||||||
| 73 | } | ||||||||||
| 74 | else { | ||||||||||
| 75 | 0 | return 0; | |||||||||
| 76 | } | ||||||||||
| 77 | } | ||||||||||
| 78 | |||||||||||
| 79 | 1 | 1; | |||||||||