File Coverage

blib/lib/Net/DRI/Protocol/OpenSRS/XCP/Connection.pm
Criterion Covered Total %
statement 24 41 58.5
branch 0 4 0.0
condition 0 3 0.0
subroutine 8 11 72.7
pod 0 3 0.0
total 32 62 51.6


line stmt bran cond sub pod time code
1             ## Domain Registry Interface, OpenSRS XCP Connection handling
2             ##
3             ## Copyright (c) 2008-2010,2013 Patrick Mevzek . All rights reserved.
4             ##
5             ## This file is part of Net::DRI
6             ##
7             ## Net::DRI is free software; you can redistribute it and/or modify
8             ## it under the terms of the GNU General Public License as published by
9             ## the Free Software Foundation; either version 2 of the License, or
10             ## (at your option) any later version.
11             ##
12             ## See the LICENSE file that comes with this distribution for more details.
13             ####################################################################################################
14              
15             package Net::DRI::Protocol::OpenSRS::XCP::Connection;
16              
17 1     1   1544 use strict;
  1         2  
  1         55  
18 1     1   8 use warnings;
  1         1  
  1         50  
19              
20 1     1   6 use Digest::MD5 ();
  1         2  
  1         19  
21 1     1   6 use HTTP::Request ();
  1         1  
  1         29  
22              
23 1     1   6 use Net::DRI::Util;
  1         1  
  1         28  
24 1     1   68 use Net::DRI::Exception;
  1         3  
  1         31  
25 1     1   7 use Net::DRI::Data::Raw;
  1         1  
  1         7  
26 1     1   34 use Net::DRI::Protocol::ResultStatus;
  1         3  
  1         7  
27              
28             =pod
29              
30             =head1 NAME
31              
32             Net::DRI::Protocol::OpenSRS::XCP::Connection - OpenSRS XCP Connection handling for Net::DRI
33              
34             =head1 DESCRIPTION
35              
36             Please see the README file for details.
37              
38             =head1 SUPPORT
39              
40             For now, support questions should be sent to:
41              
42             Enetdri@dotandco.comE
43              
44             Please also see the SUPPORT file in the distribution.
45              
46             =head1 SEE ALSO
47              
48             Ehttp://www.dotandco.com/services/software/Net-DRI/E
49              
50             =head1 AUTHOR
51              
52             Patrick Mevzek, Enetdri@dotandco.comE
53              
54             =head1 COPYRIGHT
55              
56             Copyright (c) 2008-2010,2013 Patrick Mevzek .
57             All rights reserved.
58              
59             This program is free software; you can redistribute it and/or modify
60             it under the terms of the GNU General Public License as published by
61             the Free Software Foundation; either version 2 of the License, or
62             (at your option) any later version.
63              
64             See the LICENSE file that comes with this distribution for more details.
65              
66             =cut
67              
68             ####################################################################################################
69              
70             sub init
71             {
72 0     0 0   my ($class,$to)=@_;
73 0           my $t=$to->transport_data();
74              
75 0           foreach my $p (qw/client_login client_password remote_url/)
76             {
77 0 0 0       Net::DRI::Exception::usererr_insufficient_parameters($p.' must be defined') unless (exists($t->{$p}) && $t->{$p});
78             }
79 0           return;
80             }
81              
82             ## From Protocol Message object to something suitable for transport (various types)
83             sub write_message
84             {
85 0     0 0   my ($class,$to,$msg)=@_;
86 0           my $t=$to->transport_data();
87 0           my $req=HTTP::Request->new('POST',$t->{remote_url});
88 0           $req->header('Content-Type','text/xml');
89 0           $req->header('X-Username',$t->{client_login});
90 0           my $body=Net::DRI::Util::encode_utf8($msg->get_body());
91 0           $req->header('X-Signature',Digest::MD5::md5_hex(Digest::MD5::md5_hex($body,$t->{client_password}),$t->{client_password})); ## client_password is in fact the reseller key
92 0           $req->content($body);
93             ## Content-Length will be automatically computed during Transport by LWP::UserAgent
94 0           return $req;
95             }
96              
97             ## From transport (various types) to Net::DRI::Data::Raw object (which will be parsed inside Protocol::reaction)
98             sub read_data
99             {
100 0     0 0   my ($class,$to,$res)=@_;
101 0 0         die(Net::DRI::Protocol::ResultStatus->new_error('COMMAND_FAILED_CLOSING',sprintf('Got unsuccessfull HTTP response: %d %s',$res->code(),$res->message()),'en')) unless $res->is_success();
102 0           return Net::DRI::Data::Raw->new_from_xmlstring($res->decoded_content());
103             }
104              
105             ####################################################################################################
106             1;