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