line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SelectPdf::AsyncJobClient;
|
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
8
|
use SelectPdf::ApiClient;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
4
|
1
|
|
|
1
|
|
8
|
use strict;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
226
|
|
5
|
|
|
|
|
|
|
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
|
|
|
0
|
1
|
|
my $type = shift;
|
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
|
|
|
0
|
1
|
|
my($self) = @_;
|
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
my $result = $self->SUPER::performPost();
|
51
|
|
|
|
|
|
|
|
52
|
0
|
0
|
|
|
|
|
if ($self->{jobId}) {
|
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
|
|
|
0
|
1
|
|
my($self) = @_;
|
70
|
|
|
|
|
|
|
|
71
|
0
|
0
|
|
|
|
|
if ($self->{lastHTTPCode} eq 200) {
|
72
|
0
|
|
|
|
|
|
return 1;
|
73
|
|
|
|
|
|
|
}
|
74
|
|
|
|
|
|
|
else {
|
75
|
0
|
|
|
|
|
|
return 0;
|
76
|
|
|
|
|
|
|
}
|
77
|
|
|
|
|
|
|
}
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1; |