line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::Postex; |
2
|
3
|
|
|
3
|
|
359830
|
use v5.26; |
|
3
|
|
|
|
|
42
|
|
3
|
3
|
|
|
3
|
|
2146
|
use Object::Pad; |
|
3
|
|
|
|
|
33796
|
|
|
3
|
|
|
|
|
13
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.004'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# ABSTRACT: A Postex WebService implemenation in Perl |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
class WebService::Postex; |
10
|
3
|
|
|
3
|
|
1278
|
use Carp qw(croak); |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
143
|
|
11
|
3
|
|
|
3
|
|
1603
|
use HTTP::Request::Common; |
|
3
|
|
|
|
|
77970
|
|
|
3
|
|
|
|
|
286
|
|
12
|
3
|
|
|
3
|
|
2263
|
use JSON::XS; |
|
3
|
|
|
|
|
16068
|
|
|
3
|
|
|
|
|
191
|
|
13
|
3
|
|
|
3
|
|
2161
|
use LWP::UserAgent; |
|
3
|
|
|
|
|
101284
|
|
|
3
|
|
|
|
|
154
|
|
14
|
3
|
|
|
3
|
|
30
|
use URI; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
9604
|
|
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
|
|
15
|
method _set_ua_defaults() { |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
4
|
|
23
|
3
|
|
|
|
|
16
|
$ua->default_header(Accept => 'application/json'); |
24
|
3
|
|
|
|
|
187
|
$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
|
|
16
|
method _call($req) { |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
5
|
|
40
|
3
|
|
|
|
|
19
|
my $res = $ua->request($req); |
41
|
3
|
50
|
|
|
|
2117
|
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
|
|
|
|
|
50
|
my $json = decode_json($res->decoded_content); |
47
|
3
|
50
|
|
|
|
678
|
if ($json->{status} eq 'error') { |
48
|
0
|
|
|
|
|
0
|
die "Error occurred calling Postex", $/; |
49
|
|
|
|
|
|
|
} |
50
|
3
|
|
|
|
|
53
|
return $json; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
2
|
|
|
2
|
1
|
19623
|
method generation_rest_upload(%payload) { |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
2
|
|
54
|
|
|
|
|
|
|
|
55
|
2
|
|
|
|
|
10
|
my $uri = $self->_build_uri(qw(generation raw), $generator_id); |
56
|
2
|
|
|
|
|
14
|
my $req = $self->_prepare_post($uri, %payload); |
57
|
2
|
|
|
|
|
1020
|
return $self->_call($req); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
0
|
1
|
0
|
method generation_rest_upload_check(%payload) { |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
61
|
0
|
|
|
|
|
0
|
my $uri = $self->_build_uri(qw(generation raw), $generator_id); |
62
|
0
|
|
|
|
|
0
|
my $req = $self->_prepare_get($uri, %payload); |
63
|
0
|
|
|
|
|
0
|
return $self->_call($req); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
1
|
|
|
1
|
1
|
17866
|
method generation_file_upload(%payload) { |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
2
|
|
67
|
1
|
|
|
|
|
5
|
my $uri = $self->_build_uri(qw(generation upload), $generator_id); |
68
|
1
|
|
|
|
|
6
|
my $req = $self->_prepare_post($uri, %payload); |
69
|
1
|
|
|
|
|
19607
|
return $self->_call($req); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
0
|
1
|
0
|
method generation_file_upload_check(%payload) { |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
73
|
0
|
|
|
|
|
0
|
my $uri = $self->_build_uri(qw(generation upload), $generator_id); |
74
|
0
|
|
|
|
|
0
|
my $req = $self->_prepare_get($uri, %payload); |
75
|
0
|
|
|
|
|
0
|
return $self->_call($req); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
0
|
1
|
0
|
method generation_session_status($session_id) { |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
79
|
0
|
|
|
|
|
0
|
my $uri = $self->_build_uri(qw(generation session), $session_id); |
80
|
0
|
|
|
|
|
0
|
my $req = $self->_prepare_get($uri); |
81
|
0
|
|
|
|
|
0
|
return $self->_call($req); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
0
|
1
|
0
|
method profile_file_upload($recipient_id, %payload) { |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
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
|
|
7
|
method _build_uri($type, $call, $id) { |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
49
|
|
|
3
|
|
|
|
|
6
|
|
91
|
3
|
|
|
|
|
21
|
my $uri = $base_uri->clone; |
92
|
3
|
|
|
|
|
161
|
my @segments = $uri->path_segments; |
93
|
3
|
|
|
|
|
102
|
$uri->path_segments(@segments, qw(rest data v1), $type, $call, $id); |
94
|
3
|
|
|
|
|
319
|
return $uri; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
3
|
|
|
3
|
|
7
|
method _prepare_request($uri, %payload) { |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
5
|
|
98
|
3
|
100
|
|
|
|
15
|
if (my $file = delete $payload{file}) { |
99
|
1
|
|
|
|
|
4
|
$payload{file} = [$file, delete $payload{filename}]; |
100
|
|
|
|
|
|
|
return ( |
101
|
1
|
|
|
|
|
8
|
$uri, |
102
|
|
|
|
|
|
|
Content => [%payload], |
103
|
|
|
|
|
|
|
'Content-Type' => 'form-data', |
104
|
|
|
|
|
|
|
); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
return ( |
108
|
2
|
50
|
|
|
|
32
|
$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
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
4
|
|
120
|
3
|
|
|
|
|
14
|
return POST($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__ |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=pod |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=encoding UTF-8 |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 NAME |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
WebService::Postex - A Postex WebService implemenation in Perl |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 VERSION |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
version 0.004 |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 SYNOPSIS |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
use WebService::Postex; |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
my $postex = WebService::Postex->new( |
148
|
|
|
|
|
|
|
base_uri => 'https://demo.postex.com', |
149
|
|
|
|
|
|
|
generator_id => 1234, |
150
|
|
|
|
|
|
|
secret => 'yoursecret', |
151
|
|
|
|
|
|
|
); |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
my %args = (); |
154
|
|
|
|
|
|
|
$postex->generation_file_upload(%args); |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 DESCRIPTION |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
A Perl API for connecting with the Postex REST API |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head2 base_uri |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Required. The endpoint to which to talk to |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head2 generator_id |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Required. The generator ID you get from Postex |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head2 secret |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
Required. The secret for the authorization token. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head1 METHODS |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head2 generation_file_upload |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head2 generation_file_upload_check |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head2 generation_rest_upload |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=head2 generation_rest_upload_check |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head2 generation_session_status |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head2 profile_file_upload |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head1 SEE ALSO |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=over |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=item L<Postex|https://www.postex.com> |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=back |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head1 AUTHOR |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
Wesley Schwengle <waterkip@cpan.org> |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
This software is Copyright (c) 2020 by Wesley Schwengle. |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
This is free software, licensed under: |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
The (three-clause) BSD License |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=cut |