| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package WebService::Postex; |
|
2
|
4
|
|
|
4
|
|
586034
|
use v5.26; |
|
|
4
|
|
|
|
|
17
|
|
|
3
|
4
|
|
|
4
|
|
3120
|
use Object::Pad; |
|
|
4
|
|
|
|
|
57198
|
|
|
|
4
|
|
|
|
|
70
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.006'; |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# ABSTRACT: A Postex WebService implemenation in Perl |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
class WebService::Postex; |
|
10
|
4
|
|
|
4
|
|
2176
|
use Carp qw(croak); |
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
277
|
|
|
11
|
4
|
|
|
4
|
|
2487
|
use HTTP::Request::Common; |
|
|
4
|
|
|
|
|
154139
|
|
|
|
4
|
|
|
|
|
543
|
|
|
12
|
4
|
|
|
4
|
|
3582
|
use JSON::XS; |
|
|
4
|
|
|
|
|
27361
|
|
|
|
4
|
|
|
|
|
328
|
|
|
13
|
4
|
|
|
4
|
|
3518
|
use LWP::UserAgent; |
|
|
4
|
|
|
|
|
208292
|
|
|
|
4
|
|
|
|
|
1002
|
|
|
14
|
4
|
|
|
4
|
|
56
|
use URI; |
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
14931
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
field $base_uri :param; |
|
17
|
|
|
|
|
|
|
field $generator_id :param; |
|
18
|
|
|
|
|
|
|
field $secret :param; |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
field $ua :param = undef; |
|
21
|
|
|
|
|
|
|
|
|
22
|
3
|
|
|
3
|
|
9
|
method _set_ua_defaults() { |
|
|
3
|
|
|
|
|
14
|
|
|
|
3
|
|
|
|
|
6
|
|
|
23
|
3
|
|
|
|
|
14
|
$ua->default_header(Accept => 'application/json'); |
|
24
|
3
|
|
|
|
|
217
|
$ua->default_header(Authorization => "Bearer $secret"); |
|
25
|
|
|
|
|
|
|
} |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
ADJUSTPARAMS { |
|
28
|
|
|
|
|
|
|
my $args = shift; |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
$ua //= LWP::UserAgent->new( |
|
31
|
|
|
|
|
|
|
agent => sprintf('%s/%s', __PACKAGE__, $VERSION), |
|
32
|
|
|
|
|
|
|
timeout => 30, |
|
33
|
|
|
|
|
|
|
); |
|
34
|
|
|
|
|
|
|
$self->_set_ua_defaults; |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
$base_uri = URI->new($base_uri) unless ref $base_uri; |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
3
|
|
|
3
|
|
11
|
method _call($req) { |
|
|
3
|
|
|
|
|
16
|
|
|
|
3
|
|
|
|
|
21
|
|
|
|
3
|
|
|
|
|
6
|
|
|
40
|
3
|
|
|
|
|
33
|
my $res = $ua->request($req); |
|
41
|
3
|
50
|
|
|
|
2690
|
unless ($res->is_success) { |
|
42
|
0
|
|
|
|
|
0
|
my $uri = $req->uri . ""; |
|
43
|
0
|
|
|
|
|
0
|
die "Unsuccesful request to $uri: " . $res->status_line, $/; |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
3
|
|
|
|
|
61
|
my $json = decode_json($res->decoded_content); |
|
47
|
3
|
50
|
|
|
|
838
|
if ($json->{data}{status} eq 'error') { |
|
48
|
0
|
|
|
|
|
0
|
die "Error occurred calling Postex", $/; |
|
49
|
|
|
|
|
|
|
} |
|
50
|
3
|
|
|
|
|
51
|
return $json; |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
2
|
|
|
2
|
1
|
39568
|
method generation_rest_upload(%payload) { |
|
|
2
|
|
|
|
|
12
|
|
|
|
2
|
|
|
|
|
7
|
|
|
|
2
|
|
|
|
|
5
|
|
|
54
|
2
|
|
|
|
|
12
|
my $uri = $self->_build_uri('generators', $generator_id, 'generate'); |
|
55
|
2
|
|
|
|
|
14
|
my $req = $self->_prepare_post($uri, %payload); |
|
56
|
2
|
|
|
|
|
1228
|
return $self->_call($req); |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
0
|
|
|
0
|
1
|
0
|
method generation_rest_upload_check(%payload) { |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
60
|
0
|
|
|
|
|
0
|
my $uri = $self->_build_uri('generators', $generator_id); |
|
61
|
0
|
|
|
|
|
0
|
my $req = $self->_prepare_get($uri, %payload); |
|
62
|
0
|
|
|
|
|
0
|
return $self->_call($req); |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
1
|
|
|
1
|
1
|
26984
|
method generation_file_upload(%payload) { |
|
|
1
|
|
|
|
|
8
|
|
|
|
1
|
|
|
|
|
5
|
|
|
|
1
|
|
|
|
|
2
|
|
|
66
|
1
|
|
|
|
|
7
|
my $uri = $self->_build_uri('generators', $generator_id, 'generate'); |
|
67
|
1
|
|
|
|
|
10
|
my $req = $self->_prepare_post($uri, %payload); |
|
68
|
1
|
|
|
|
|
25310
|
return $self->_call($req); |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
0
|
|
|
0
|
1
|
0
|
method generation_file_upload_check(%payload) { |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
72
|
0
|
|
|
|
|
0
|
my $uri = $self->_build_uri('generators', $generator_id, 'generate'); |
|
73
|
0
|
|
|
|
|
0
|
my $req = $self->_prepare_get($uri, %payload); |
|
74
|
0
|
|
|
|
|
0
|
return $self->_call($req); |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
0
|
|
|
0
|
1
|
0
|
method generation_session_status($session_id) { |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
78
|
0
|
|
|
|
|
0
|
my $uri = $self->_build_uri('generators', $generator_id, 'generate'); |
|
79
|
0
|
|
|
|
|
0
|
my $req = $self->_prepare_get($uri); |
|
80
|
0
|
|
|
|
|
0
|
return $self->_call($req); |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
0
|
|
|
0
|
1
|
0
|
method profile_file_upload($recipient_id, %payload) { |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
84
|
0
|
|
|
|
|
0
|
die "Unsupported method", $/; |
|
85
|
0
|
|
|
|
|
0
|
my $uri = $self->_build_uri(qw(recipients upload), $recipient_id); |
|
86
|
0
|
|
|
|
|
0
|
my $req = $self->_prepare_post($uri, %payload); |
|
87
|
0
|
|
|
|
|
0
|
return $self->_call($req); |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
3
|
|
|
3
|
|
8
|
method _build_uri(@data) { |
|
|
3
|
|
|
|
|
9
|
|
|
|
3
|
|
|
|
|
12
|
|
|
|
3
|
|
|
|
|
7
|
|
|
91
|
3
|
|
|
|
|
28
|
my $uri = $base_uri->clone; |
|
92
|
3
|
|
|
|
|
210
|
my @segments = $uri->path_segments; |
|
93
|
3
|
|
|
|
|
202
|
$uri->path_segments(@segments, qw(rest v2), @data); |
|
94
|
3
|
|
|
|
|
391
|
return $uri; |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
3
|
|
|
3
|
|
8
|
method _prepare_request($uri, %payload) { |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
13
|
|
|
|
3
|
|
|
|
|
5
|
|
|
98
|
3
|
100
|
|
|
|
18
|
if (my $file = delete $payload{file}) { |
|
99
|
1
|
|
|
|
|
6
|
$payload{file} = [$file, delete $payload{filename}]; |
|
100
|
|
|
|
|
|
|
return ( |
|
101
|
1
|
|
|
|
|
11
|
$uri, |
|
102
|
|
|
|
|
|
|
Content => [%payload], |
|
103
|
|
|
|
|
|
|
'Content-Type' => 'form-data', |
|
104
|
|
|
|
|
|
|
); |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
return ( |
|
108
|
2
|
50
|
|
|
|
90
|
$uri, |
|
109
|
|
|
|
|
|
|
%payload |
|
110
|
|
|
|
|
|
|
? ( |
|
111
|
|
|
|
|
|
|
Content => encode_json(\%payload), |
|
112
|
|
|
|
|
|
|
'Content-Type' => 'application/json', |
|
113
|
|
|
|
|
|
|
) |
|
114
|
|
|
|
|
|
|
: (), |
|
115
|
|
|
|
|
|
|
); |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
|
|
119
|
3
|
|
|
3
|
|
9
|
method _prepare_post($uri, %payload) { |
|
|
3
|
|
|
|
|
14
|
|
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
11
|
|
|
|
3
|
|
|
|
|
6
|
|
|
120
|
3
|
|
|
|
|
21
|
return PUT($self->_prepare_request($uri, %payload)); |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
|
|
123
|
0
|
|
|
0
|
|
|
method _prepare_get($uri, %payload) { |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
return GET($self->_prepare_request($uri, %payload)); |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
1; |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
__END__ |