1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
package Business::BatchPayment::Transport::HTTPS;
=head2 HTTPS transport
Sends a request by HTTPS POST, and downloads the response the same way.
Options are 'server', 'port', 'get_path', 'put_path', optionally
'content_type'.
=cut
use Net::HTTPS::Any 0.10;
use Moose;
with 'Business::BatchPayment::Transport';
has [ qw( host port get_path put_path ) ] => (
is => 'ro',
isa => 'Str'
);
has 'content_type' => (
is => 'rw',
isa => 'Str',
default => 'text/plain'
);
sub https_post {
my $self = shift;
my $path = shift;
my $content = shift;
warn "starting https_post...\n" if $self->debug;
my ( $page, $response, %reply_headers ) = Net::HTTPS::Any::https_post(
host => $self->host,
port => $self->port,
path => $path,
content => $content,
debug => ($self->debug >= 3),
);
warn "PAGE:\n$page\n\nRESPONSE:\n$response\n\n" if $self->debug >= 2;
return ($page, $response, %reply_headers);
}
sub upload {
my $self = shift;
my $content = shift;
$self->https_post($self->put_path, $content);
}
sub download {
# will probably need to be overridden in most cases
my $self = shift;
my ($page, $response, %reply_headers) = $self->https_post($self->get_path);
$page;
}
__PACKAGE__->meta->make_immutable;
1;
|