net-opensrs/trunk/lib/Net/OpenSRS.pm
author mahlon
Fri, 05 Sep 2008 05:15:48 +0000
branchperl-modules
changeset 0 315eb12b224b
permissions -rw-r--r--
Reorganizing for Trac.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
     1
=head1 Description
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
     2
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
     3
This is a wrapper interface to the DNS portions of the Tucows OpenSRS
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
     4
HTTPS XML API.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
     5
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
     6
The client library distributed by OpenSRS can be difficult to integrate
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
     7
into a custom environment, and their web interface becomes quickly
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
     8
tedious with heavy usage. This is a clean and relatively quick library
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
     9
to perform the most common API methods described in the OpenSRS API
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    10
documentation.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    11
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    12
=head1 Examples
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    13
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    14
 use Net::OpenSRS;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    15
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    16
 my $key = 'Your_API_Key_From_The_Reseller_Interface';
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    17
 my $srs = Net::OpenSRS->new();
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    18
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    19
 $srs->environment('live');
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    20
 $srs->set_key( $key );
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    21
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    22
 $srs->set_manage_auth( 'manage_username', 'manage_password' );
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    23
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    24
 my $cookie = $srs->get_cookie( 'spime.net' );
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    25
 if ($cookie) {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    26
     print "Cookie:  $cookie\n";
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    27
 } else {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    28
     print $srs->last_response() . "\n";
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    29
 }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    30
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    31
 # do a batch of domain locks
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    32
 $srs->bulk_lock([ 'example.com', 'example.net', ... ]);
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    33
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    34
 # renew a domain
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    35
 my $result = $srs->renew_domain( 'example.com' );
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    36
 ...
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    37
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    38
=head1 Notes
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    39
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    40
=head2 Prerequisites
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    41
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    42
This module requires some setup in the OpenSRS reseller environment
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    43
before it will work correctly.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    44
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    45
=over 4
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    46
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    47
=item Reseller account
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    48
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    49
You need to have an OpenSRS account, of course.  If you aren't an
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    50
OpenSRS reseller, this module will be of limited use to you. :)
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    51
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    52
=item Script API network access
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    53
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    54
The machine(s) using this module need to have their public IP addresses
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    55
added to your 'Script API allow' list in the OpenSRS web interface.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    56
(You'll only need to do this once, assuming your IP doesn't change.)
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    57
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    58
=item API key generation
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    59
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    60
You'll need to pregenerate your API keys - also in the the OpenSRS web
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    61
interface.  These keys are used for all reseller API authentication.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    62
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    63
=back
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    64
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    65
=head2 Assumptions
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    66
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    67
OpenSRS allows for a variety of ways to organize your domains.  Because
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    68
of this, writing a 'one size fits all' module is rather difficult.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    69
Instead, we make a few assumptions regarding the way people use their
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    70
OpenSRS reseller accounts.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    71
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    72
**** These assumptions will ultimately determine if this module is right for
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    73
you!  Please read them carefully! ****
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    74
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    75
=over 4
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    76
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    77
=item Management 'master' account.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    78
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    79
We assume that all domains are under one global management owner
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    80
account.  If customers want access to the management interface, we're
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    81
operating under the idea that you create subaccounts for them -
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    82
retainting the master account information for your own use.  (If you
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    83
aren't doing this, it really makes things easier for you in the long
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    84
run.)
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    85
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    86
For example, 'spime.net' is my master management account.  Before doing
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    87
any register_domain() calls, I call master_domain('spime.net') - then
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    88
any transfers or registrations from that point forward are linked to
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    89
'spime.net'.  If a customer wants access to the SRS web management
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    90
interface, I can then just create a subaccount for just their domain,
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    91
so I retain absolute control -- in the event a customer forgets their
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    92
password, I'm covered.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    93
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    94
=item Usernames
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    95
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    96
We assume that your management username 'master' account is identical to
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    97
your reseller username, and just the passwords differ.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    98
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
    99
=item Default registration info
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   100
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   101
We assume you've properly set up default technical contact information,
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   102
including your default nameservers, in the OpenSRS reseller web
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   103
interface.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   104
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   105
=item Return codes
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   106
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   107
Unless otherwise noted, all methods return true on success, false on
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   108
failure, and undefined on caller error.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   109
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   110
=back
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   111
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   112
=head2 Default environment
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   113
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   114
This library defaults to the TEST environment. (horizon.)  Many API
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   115
methods don't work in the test environment (SET COOKIE being the most
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   116
notable example, as any API method relying on a cookie doesn't work
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   117
either.)  Neither does batch processing.  Most everything else should be
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   118
ok.  ( See environment() )
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   119
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   120
=head2 The '$c' variable
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   121
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   122
Many methods require customer information.  I leave the method of
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   123
fetching this information entirely to you.  All examples below that show
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   124
a $c variable expect a hashref (or object) that contain these keys:
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   125
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   126
    my $c = {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   127
        firstname => 'John',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   128
        lastname  => 'Doe',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   129
        city      => 'Portland',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   130
        state     => 'Oregon',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   131
        country   => 'US',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   132
        address   => '555 Someplace Street',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   133
        email     => 'john@example.com',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   134
        phone     => '503-555-1212',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   135
        company   => 'n/a'
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   136
    };
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   137
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   138
=cut
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   139
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   140
package Net::OpenSRS;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   141
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   142
use strict;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   143
use warnings;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   144
use LWP::UserAgent;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   145
use XML::Simple;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   146
use Digest::MD5;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   147
use Date::Calc qw/ Add_Delta_Days Today This_Year /;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   148
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   149
our $VERSION = '0.02';
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   150
my $rv;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   151
*hash = \&Digest::MD5::md5_hex;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   152
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   153
#----------------------------------------------------------------------
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   154
# utility methods
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   155
#----------------------------------------------------------------------
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   156
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   157
=head1 Utility methods
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   158
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   159
=over 4
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   160
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   161
=item new()
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   162
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   163
 my $srs = Net::OpenSRS->new();
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   164
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   165
Create a new Net::OpenSRS object.  There are no options for this
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   166
method.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   167
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   168
=cut
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   169
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   170
sub new
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   171
{
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   172
    my ($class, %opts) = @_;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   173
    my $self = {};
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   174
    bless $self, $class;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   175
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   176
    $self->{config} = {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   177
        use_test_env  => 1,
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   178
        debug         => 0,
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   179
        master_domain => undef,
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   180
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   181
        bulkhost => 'https://batch.opensrs.net:55443',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   182
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   183
        # reseller auth keys, as generated via the reseller website.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   184
        live => {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   185
            key  => undef,
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   186
            host => 'https://rr-n1-tor.opensrs.net:55443',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   187
        },
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   188
        test => {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   189
            key  => undef,
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   190
            host => 'https://horizon.opensrs.net:55443',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   191
        }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   192
    };
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   193
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   194
    return $self;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   195
}
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   196
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   197
sub debug
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   198
{
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   199
    my $self = shift;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   200
    return unless $self->debug_level;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   201
    print STDERR shift() . "\n";
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   202
}
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   203
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   204
=item debug_level()
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   205
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   206
Setting the debug level will print various pieces of information to
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   207
STDERR when connecting to OpenSRS.  Use this if something isn't working
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   208
the way you think it should be.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   209
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   210
=item 0
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   211
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   212
Disable debugging.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   213
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   214
=item 1
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   215
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   216
Print current environment, host, and HTTP response.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   217
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   218
=item 2
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   219
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   220
Add XML request and response to output.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   221
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   222
=item 3
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   223
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   224
Add SSL debugging to output.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   225
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   226
Debugging is off by default.  When called without an argument, returns
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   227
the current debug level.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   228
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   229
=cut
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   230
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   231
sub debug_level
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   232
{
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   233
    my ($self, $level) = @_;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   234
    return $self->{config}->{debug} unless $level;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   235
    $self->{config}->{debug} = $level;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   236
    return;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   237
}
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   238
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   239
=item last_response()
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   240
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   241
All Net::OpenSRS methods set the last OpenSRS API reply in a temporary
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   242
variable.  You can view the contents of this variable using the
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   243
last_response() method.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   244
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   245
Note that it is reset on each method call.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   246
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   247
Returns the last OpenSRS return code and result string, or if passed any
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   248
true value, instead returns the full XML (parsed into a hashref) of the
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   249
last OpenSRS return. (perfect for Data::Dumper)
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   250
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   251
Examples:
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   252
   200: Command Successful
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   253
   400: Domain example.com does not exist with OpenSRS
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   254
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   255
=cut
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   256
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   257
sub last_response
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   258
{
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   259
    my ($self, $obj) = @_;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   260
    return $obj ? $rv : $self->{last_response} || '';
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   261
}
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   262
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   263
=item set_manage_auth()
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   264
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   265
 $srs->set_manage_auth( $username, $password );
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   266
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   267
Set the owner management username and password.  This is used to fetch
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   268
cookies, and perform any API methods that require the management cookie.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   269
For specifics on this, see the OpenSRS API documentation.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   270
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   271
=cut
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   272
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   273
sub set_manage_auth
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   274
{
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   275
    my ($self, $user, $pass) = @_;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   276
    return undef unless $user && $pass;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   277
    $self->{config}->{username} = $user;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   278
    $self->{config}->{password} = $pass;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   279
    return 1;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   280
}
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   281
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   282
=item set_key()
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   283
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   284
Tell the OpenSRS object what secret key to use for authentication.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   285
You can generate a new secret key by using the OpenSRS reseller web
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   286
interface.  This key is required to perform any API functions.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   287
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   288
set_key() is affected by the current environment().  Calling the
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   289
set_key() method while in the test environment only sets the key for the
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   290
test environment - likewise for the live environment.  To set a key for
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   291
the live environment, you need to call environment('live') B<first>.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   292
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   293
=cut
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   294
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   295
sub set_key
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   296
{
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   297
    my ($self, $key) = @_;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   298
    return undef unless $key;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   299
    $self->{config}->{ $self->environment }->{key} = $key;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   300
    return 1;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   301
}
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   302
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   303
=item environment()
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   304
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   305
 my $env = $srs->environment;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   306
 $srs->environment('live');
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   307
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   308
Without an argument, returns a string - either 'test', or 'live',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   309
depending on the environment the object is currently using.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   310
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   311
The test environment is the default.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   312
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   313
If passed an argument (either 'test' or 'live') - switches into the
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   314
desired environment.  You will need to set_key() if you were previously
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   315
using a different environment, or if you hadn't set_key() yet.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   316
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   317
=cut
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   318
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   319
sub environment
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   320
{
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   321
    my ($self, $env) = @_;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   322
    return ($self->{config}->{use_test_env} ? 'test' : 'live')
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   323
        unless $env && $env =~ /(test|live)/i;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   324
    $self->{config}->{use_test_env} = 
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   325
        $1 eq 'test' ? 1 : 0;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   326
    return;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   327
}
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   328
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   329
=item master_domain()
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   330
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   331
 my $master = $srs->master_domain;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   332
 $srs->master_domain('spime.net');
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   333
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   334
Without an argument, returns the currently set 'master domain' account.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   335
Otherwise, it sets the master domain.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   336
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   337
New transfers and registrations are linked under this domain, for
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   338
centralized management.  See the 'Assumptions' section, above.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   339
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   340
=cut
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   341
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   342
sub master_domain
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   343
{
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   344
    my ($self, $domain) = @_;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   345
    return $self->{config}->{master_domain} unless $domain;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   346
    $self->{config}->{master_domain} = $domain;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   347
    return;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   348
}
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   349
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   350
# set last status messages/codes in $self,
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   351
# for the benefit of the caller.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   352
sub _set_response
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   353
{
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   354
    my $self = shift;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   355
    $rv->{response_text} =~ s/Error: //;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   356
    $self->{last_response} = $rv->{response_code} . ": " . $rv->{response_text};
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   357
    return;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   358
}
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   359
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   360
#----------------------------------------------------------------------
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   361
# SRS API methods
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   362
#----------------------------------------------------------------------
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   363
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   364
=back
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   365
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   366
=head1 OpenSRS API methods
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   367
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   368
=over 4
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   369
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   370
=item bulk_lock() / bulk_unlock()
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   371
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   372
Locks or unlocks up to 1000 domains at a time.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   373
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   374
 my $result = $srs->bulk_lock([ 'example.com', 'example.net' ]);
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   375
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   376
Returns remote bulk queue id on successful batch submission.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   377
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   378
=cut
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   379
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   380
sub bulk_lock
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   381
{
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   382
    my $self = shift;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   383
    return $self->_bulk_action( 'lock', @_ );
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   384
}
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   385
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   386
sub bulk_unlock
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   387
{
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   388
    my $self = shift;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   389
    return $self->_bulk_action( 'unlock', @_ );
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   390
}
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   391
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   392
sub _bulk_action
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   393
{
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   394
    my ( $self, $toggle, $domains ) = @_;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   395
    return undef unless $toggle =~ /lock|unlock/i && 
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   396
                        ref $domains;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   397
    return undef if scalar @$domains >= 1000;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   398
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   399
    $rv = $self->make_request(
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   400
        {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   401
            batch   => 1,
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   402
            action  => 'submit',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   403
            object  => 'bulk_change',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   404
            attributes => {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   405
                change_type => 'domain_lock',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   406
                change_items => $domains,
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   407
                op_type => lc $toggle,
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   408
            }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   409
        }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   410
    );
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   411
    return undef unless $rv;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   412
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   413
    $self->_set_response;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   414
    return $rv->{is_success} ? $rv->{bulk_change_req_id} : 0;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   415
}
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   416
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   417
=item check_queued_request()
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   418
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   419
 my $result = $srs->check_queued_request( $queue_id );
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   420
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   421
Requires queue id - returned from batch methods such as bulk_lock().
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   422
Always returns hashref of queue command on success.  
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   423
Check $srs->last_response() for status progress.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   424
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   425
=cut
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   426
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   427
sub check_queued_request
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   428
{
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   429
    my ( $self, $id ) = @_;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   430
    return undef unless $id;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   431
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   432
    $rv = $self->make_request(
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   433
        {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   434
            action  => 'query_queued_request',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   435
            object  => 'domain',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   436
            attributes => {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   437
                request_id => $id,
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   438
            }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   439
        }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   440
    );
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   441
    return undef unless $rv;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   442
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   443
    $self->_set_response;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   444
    return $rv->{attributes}->{request_data};
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   445
}
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   446
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   447
=item check_transfer()
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   448
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   449
 my $result = $srs->check_transfer( 'example.com' );
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   450
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   451
Checks the status of a transfer in progress.  Returns hashref of
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   452
'contact_email', 'status', and 'last_update_time' for a given domain
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   453
transfer.  The 'status' key is always one of the following:
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   454
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   455
        pending_owner  (waiting on owner confirmation)
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   456
        pending_admin  (waiting on opensrs staff confirmation)
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   457
        pending_registry  (waiting on register to complete)
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   458
        completed  (transfer done)
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   459
        cancelled  (reseller cancelled transfer in progress)
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   460
        undefined  (no transfer in progress)
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   461
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   462
If the domain in question has no transfer in progress - instead checks
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   463
to see if the domain is capable of transfer.  Returns hashref of
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   464
'transferrable' (boolean) and 'reason' (string).
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   465
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   466
=cut
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   467
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   468
sub check_transfer
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   469
{
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   470
    my ( $self, $domain ) = @_;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   471
    return undef unless $domain;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   472
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   473
    $rv = $self->make_request(
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   474
        {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   475
            action     => 'check_transfer',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   476
            object     => 'domain',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   477
            attributes => {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   478
                domain              => $domain,
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   479
                get_request_address => 1,
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   480
            }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   481
        }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   482
    );
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   483
    return undef unless $rv;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   484
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   485
    $self->_set_response;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   486
    if ( $rv->{attributes}->{status} ) {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   487
        return {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   488
            status           => $rv->{attributes}->{status},
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   489
            last_update_time => $rv->{attributes}->{unixtime},
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   490
            contact_email    => $rv->{attributes}->{request_address}
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   491
        };
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   492
    }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   493
    else {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   494
        return $rv->{attributes}; #(transferrable bool and reason)
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   495
    }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   496
}
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   497
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   498
=item get_cookie()
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   499
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   500
OpenSRS management APIs require a cookie to be generated, and sent along
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   501
with the API request.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   502
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   503
 $cookie = $srs->get_cookie( 'example.com ');
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   504
 ($cookie, $expiration_date) = $srs->get_cookie( 'example.com ');
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   505
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   506
Make sure you've set_manage_auth() before attempting any cookie required
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   507
APIs.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   508
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   509
Returns cookie on success, undefined on error.  (Check error with
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   510
last_response())
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   511
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   512
In array context, returns cookie and expiration date of the domain.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   513
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   514
=cut
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   515
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   516
sub get_cookie
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   517
{
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   518
    my ($self, $domain) = @_;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   519
    return undef unless $domain;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   520
    $rv = $self->make_request(
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   521
        {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   522
            action     => 'set',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   523
            object     => 'cookie',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   524
            attributes => {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   525
                reg_username => $self->{config}->{username},
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   526
                reg_password => $self->{config}->{password},
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   527
                domain => $domain
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   528
            }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   529
        }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   530
    );
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   531
    return undef unless $rv;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   532
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   533
    $self->_set_response;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   534
    if ($rv->{is_success}) {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   535
        return
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   536
          wantarray
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   537
          ? ( $rv->{attributes}->{cookie}, $rv->{attributes}->{expiredate} )
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   538
          : $rv->{attributes}->{cookie};
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   539
    }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   540
    return undef;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   541
}
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   542
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   543
=item get_expiring_domains()
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   544
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   545
 my $results = $srs->get_expiring_domains( 60 );
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   546
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   547
 Fetch and return OpenSRS hashref of expiring domains, within
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   548
 the specified timeperiod.  (In days.)
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   549
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   550
 Time period defaults to 30 days.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   551
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   552
=cut
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   553
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   554
sub get_expiring_domains
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   555
{
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   556
    my ($self, $timeframe) = @_;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   557
    $timeframe ||= 30;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   558
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   559
    my $today   = join '-', map { sprintf( "%02d", $_ ) } Date::Calc::Today();
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   560
    my $expdate = join '-', map { sprintf( "%02d", $_ ) }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   561
      Date::Calc::Add_Delta_Days( ( split '-', $today ), $timeframe );
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   562
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   563
    $rv = $self->make_request(
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   564
        {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   565
            action     => 'get_domains_by_expiredate',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   566
            object     => 'domain',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   567
            attributes => {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   568
                limit    => 1000,
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   569
                exp_from => $today,
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   570
                exp_to   => $expdate,
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   571
            }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   572
        }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   573
    );
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   574
    return undef unless $rv;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   575
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   576
    $self->_set_response;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   577
    return $rv->{attributes}->{exp_domains} if $rv->{is_success};
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   578
    return undef;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   579
}
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   580
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   581
=item is_available()
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   582
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   583
Hey OpenSRS! Is this domain registered, or is it available?
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   584
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   585
 my $result = $srs->is_available( 'example.com ');
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   586
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   587
Returns true if the domain is available, false if it is already
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   588
registered.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   589
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   590
=cut
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   591
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   592
sub is_available
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   593
{
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   594
    my ($self, $domain) = @_;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   595
    return undef unless $domain;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   596
    $rv = $self->make_request(
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   597
        {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   598
            action     => 'lookup',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   599
            object     => 'domain',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   600
            attributes => {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   601
                domain => $domain
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   602
            }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   603
        }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   604
    );
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   605
    return undef unless $rv;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   606
    $self->_set_response;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   607
    return undef unless $rv->{is_success};
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   608
    return $rv->{response_code} == 210 ? 1 : 0;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   609
}
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   610
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   611
=item register_domain()
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   612
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   613
 my $result = $srs->register_domain( 'example.com', $c );
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   614
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   615
Register a new domain.  Default nameserver and tech info used from
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   616
OpenSRS settings.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   617
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   618
=cut
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   619
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   620
sub register_domain
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   621
{
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   622
    my ($self, $domain, $c, $transfer) = @_;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   623
    return undef unless $domain;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   624
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   625
    # sanity checks
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   626
    unless ($self->{config}->{username}) {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   627
        $self->debug("Management auth not set.");
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   628
        return undef;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   629
    }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   630
    unless (ref $c) {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   631
        $self->debug("2nd arg must be a reference to customer info.");
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   632
        return undef;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   633
    }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   634
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   635
    my $epp_phone = $c->{phone};
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   636
    $epp_phone =~ s/[\.\-]//g;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   637
    $epp_phone = '+1.' . $epp_phone;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   638
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   639
    # blah, this sucks.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   640
    # it would be really nice if OpenSRS figured out the country -> code
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   641
    # conversion on their end of things.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   642
    my %country_codes = (
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   643
        'Afghanistan'                            => 'AF',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   644
        'Albania'                                => 'AL',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   645
        'Algeria'                                => 'DZ',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   646
        'American Samoa'                         => 'AS',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   647
        'Andorra'                                => 'AD',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   648
        'Angola'                                 => 'AO',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   649
        'Anguilla'                               => 'AI',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   650
        'Antarctica'                             => 'AQ',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   651
        'Antigua And Barbuda'                    => 'AG',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   652
        'Argentina'                              => 'AR',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   653
        'Armenia'                                => 'AM',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   654
        'Aruba'                                  => 'AW',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   655
        'Australia'                              => 'AU',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   656
        'Austria'                                => 'AT',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   657
        'Azerbaijan'                             => 'AZ',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   658
        'Bahamas'                                => 'BS',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   659
        'Bahrain'                                => 'BH',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   660
        'Bangladesh'                             => 'BD',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   661
        'Barbados'                               => 'BB',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   662
        'Belarus'                                => 'BY',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   663
        'Belgium'                                => 'BE',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   664
        'Belize'                                 => 'BZ',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   665
        'Benin'                                  => 'BJ',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   666
        'Bermuda'                                => 'BM',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   667
        'Bhutan'                                 => 'BT',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   668
        'Bolivia'                                => 'BO',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   669
        'Bosnia Hercegovina'                     => 'BA',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   670
        'Botswana'                               => 'BW',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   671
        'Bouvet Island'                          => 'BV',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   672
        'Brazil'                                 => 'BR',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   673
        'British Indian Ocean Territory'         => 'IO',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   674
        'Brunei Darussalam'                      => 'BN',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   675
        'Bulgaria'                               => 'BG',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   676
        'Burkina Faso'                           => 'BF',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   677
        'Burundi'                                => 'BI',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   678
        'Cambodia'                               => 'KH',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   679
        'Cameroon'                               => 'CM',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   680
        'Canada'                                 => 'CA',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   681
        'Cape Verde'                             => 'CV',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   682
        'Cayman Islands'                         => 'KY',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   683
        'Central African Republic'               => 'CF',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   684
        'Chad'                                   => 'TD',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   685
        'Chile'                                  => 'CL',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   686
        'China'                                  => 'CN',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   687
        'Christmas Island'                       => 'CX',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   688
        'Cocos (Keeling) Islands'                => 'CC',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   689
        'Colombia'                               => 'CO',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   690
        'Comoros'                                => 'KM',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   691
        'Congo'                                  => 'CG',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   692
        'Congo The Democratic Republic Of'       => 'CD',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   693
        'Cook Islands'                           => 'CK',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   694
        'Costa Rica'                             => 'CR',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   695
        'Cote D\'Ivoire'                         => 'CI',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   696
        'Croatia'                                => 'HR',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   697
        'Cuba'                                   => 'CU',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   698
        'Cyprus'                                 => 'CY',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   699
        'Czech Republic'                         => 'CZ',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   700
        'Denmark'                                => 'DK',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   701
        'Djibouti'                               => 'DJ',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   702
        'Dominica'                               => 'DM',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   703
        'Dominican Republic'                     => 'DO',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   704
        'Ecuador'                                => 'EC',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   705
        'Egypt'                                  => 'EG',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   706
        'El Salvador'                            => 'SV',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   707
        'Equatorial Guinea'                      => 'GQ',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   708
        'Eritrea'                                => 'ER',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   709
        'Estonia'                                => 'EE',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   710
        'Ethiopia'                               => 'ET',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   711
        'Falkland Islands (Malvinas)'            => 'FK',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   712
        'Faroe Islands'                          => 'FO',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   713
        'Fiji'                                   => 'FJ',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   714
        'Finland'                                => 'FI',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   715
        'France'                                 => 'FR',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   716
        'French Guiana'                          => 'GF',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   717
        'French Polynesia'                       => 'PF',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   718
        'French Southern Territories'            => 'TF',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   719
        'Gabon'                                  => 'GA',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   720
        'Gambia'                                 => 'GM',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   721
        'Georgia'                                => 'GE',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   722
        'Germany'                                => 'DE',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   723
        'Ghana'                                  => 'GH',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   724
        'Gibraltar'                              => 'GI',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   725
        'Greece'                                 => 'GR',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   726
        'Greenland'                              => 'GL',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   727
        'Grenada'                                => 'GD',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   728
        'Guadeloupe'                             => 'GP',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   729
        'Guam'                                   => 'GU',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   730
        'Guatemela'                              => 'GT',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   731
        'Guinea'                                 => 'GN',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   732
        'Guinea-Bissau'                          => 'GW',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   733
        'Guyana'                                 => 'GY',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   734
        'Haiti'                                  => 'HT',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   735
        'Heard and McDonald Islands'             => 'HM',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   736
        'Honduras'                               => 'HN',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   737
        'Hong Kong'                              => 'HK',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   738
        'Hungary'                                => 'HU',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   739
        'Iceland'                                => 'IS',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   740
        'India'                                  => 'IN',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   741
        'Indonesia'                              => 'ID',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   742
        'Iran (Islamic Republic Of)'             => 'IR',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   743
        'Iraq'                                   => 'IQ',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   744
        'Ireland'                                => 'IE',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   745
        'Israel'                                 => 'IL',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   746
        'Italy'                                  => 'IT',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   747
        'Jamaica'                                => 'JM',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   748
        'Japan'                                  => 'JP',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   749
        'Jordan'                                 => 'JO',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   750
        'Kazakhstan'                             => 'KZ',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   751
        'Kenya'                                  => 'KE',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   752
        'Kiribati'                               => 'KI',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   753
        'Korea, Democratic People\'s Republic Of' => 'KP',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   754
        'Korea, Republic Of'                     => 'KR',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   755
        'Kuwait'                                 => 'KW',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   756
        'Kyrgyzstan'                             => 'KG',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   757
        'Lao People\'s Democratic Republic'      => 'LA',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   758
        'Latvia'                                 => 'LV',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   759
        'Lebanon'                                => 'LB',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   760
        'Lesotho'                                => 'LS',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   761
        'Liberia'                                => 'LR',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   762
        'Libyan Arab Jamahiriya'                 => 'LY',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   763
        'Liechtenstein'                          => 'LI',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   764
        'Lithuania'                              => 'LT',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   765
        'Luxembourg'                             => 'LU',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   766
        'Macau'                                  => 'MO',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   767
        'Macedonia'                              => 'MK',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   768
        'Madagascar'                             => 'MG',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   769
        'Malawi'                                 => 'MW',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   770
        'Malaysia'                               => 'MY',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   771
        'Maldives'                               => 'MV',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   772
        'Mali'                                   => 'ML',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   773
        'Malta'                                  => 'MT',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   774
        'Marshall Islands'                       => 'MH',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   775
        'Martinique'                             => 'MQ',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   776
        'Mauritania'                             => 'MR',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   777
        'Mauritius'                              => 'MU',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   778
        'Mayotte'                                => 'YT',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   779
        'Mexico'                                 => 'MX',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   780
        'Micronesia, Federated States Of'        => 'FM',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   781
        'Moldova, Republic Of'                   => 'MD',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   782
        'Monaco'                                 => 'MC',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   783
        'Mongolia'                               => 'MN',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   784
        'Montserrat'                             => 'MS',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   785
        'Morocco'                                => 'MA',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   786
        'Mozambique'                             => 'MZ',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   787
        'Myanmar'                                => 'MM',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   788
        'Namibia'                                => 'NA',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   789
        'Nauru'                                  => 'NR',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   790
        'Nepal'                                  => 'NP',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   791
        'Netherlands'                            => 'NL',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   792
        'Netherlands Antilles'                   => 'AN',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   793
        'New Caledonia'                          => 'NC',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   794
        'New Zealand'                            => 'NZ',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   795
        'Nicaragua'                              => 'NI',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   796
        'Niger'                                  => 'NE',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   797
        'Nigeria'                                => 'NG',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   798
        'Niue'                                   => 'NU',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   799
        'Norfolk Island'                         => 'NF',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   800
        'Northern Mariana Islands'               => 'MP',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   801
        'Norway'                                 => 'NO',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   802
        'Oman'                                   => 'OM',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   803
        'Pakistan'                               => 'PK',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   804
        'Palau'                                  => 'PW',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   805
        'Palestine'                              => 'PS',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   806
        'Panama'                                 => 'PA',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   807
        'Papua New Guinea'                       => 'PG',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   808
        'Paraguay'                               => 'PY',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   809
        'Peru'                                   => 'PE',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   810
        'Philippines'                            => 'PH',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   811
        'Pitcairn'                               => 'PN',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   812
        'Poland'                                 => 'PL',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   813
        'Portugal'                               => 'PT',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   814
        'Puerto Rico'                            => 'PR',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   815
        'Qatar'                                  => 'QA',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   816
        'Reunion'                                => 'RE',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   817
        'Romania'                                => 'RO',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   818
        'Russian Federation'                     => 'RU',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   819
        'Rwanda'                                 => 'RW',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   820
        'Saint Helena'                           => 'SH',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   821
        'Saint Kitts And Nevis'                  => 'KN',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   822
        'Saint Lucia'                            => 'LC',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   823
        'Saint Pierre and Miquelon'              => 'PM',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   824
        'Saint Vincent and The Grenadines'       => 'VC',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   825
        'Samoa'                                  => 'WS',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   826
        'San Marino'                             => 'SM',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   827
        'Sao Tome and Principe'                  => 'ST',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   828
        'Saudi Arabia'                           => 'SA',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   829
        'Senegal'                                => 'SN',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   830
        'Serbia and Montenegro'                  => 'CS',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   831
        'Seychelles'                             => 'SC',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   832
        'Sierra Leone'                           => 'SL',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   833
        'Singapore'                              => 'SG',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   834
        'Slovakia'                               => 'SK',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   835
        'Slovenia'                               => 'SI',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   836
        'Solomon Islands'                        => 'SB',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   837
        'Somalia'                                => 'SO',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   838
        'South Africa'                           => 'ZA',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   839
        'South Georgia and The Sandwich Islands' => 'GS',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   840
        'Spain'                                  => 'ES',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   841
        'Sri Lanka'                              => 'LK',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   842
        'Sudan'                                  => 'SD',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   843
        'Suriname'                               => 'SR',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   844
        'Svalbard and Jan Mayen Islands'         => 'SJ',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   845
        'Swaziland'                              => 'SZ',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   846
        'Sweden'                                 => 'SE',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   847
        'Switzerland'                            => 'CH',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   848
        'Syrian Arab Republic'                   => 'SY',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   849
        'Taiwan'                                 => 'TW',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   850
        'Tajikista'                              => 'TJ',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   851
        'Tanzania, United Republic Of'           => 'TZ',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   852
        'Thailand'                               => 'TH',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   853
        'Timor-Leste'                            => 'TL',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   854
        'Togo'                                   => 'TG',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   855
        'Tokelau'                                => 'TK',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   856
        'Tonga'                                  => 'TO',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   857
        'Trinidad and Tobago'                    => 'TT',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   858
        'Tunisia'                                => 'TN',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   859
        'Turkey'                                 => 'TR',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   860
        'Turkmenistan'                           => 'TM',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   861
        'Turks and Caicos Islands'               => 'TC',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   862
        'Tuvalu'                                 => 'TV',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   863
        'Uganda'                                 => 'UG',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   864
        'Ukraine'                                => 'UA',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   865
        'United Arab Emirates'                   => 'AE',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   866
        'United Kingdom (GB)'                    => 'GB',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   867
        'United Kingdom (UK)'                    => 'UK',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   868
        'United States'                          => 'US',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   869
        'United States Minor Outlying Islands'   => 'UM',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   870
        'Uruguay'                                => 'UY',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   871
        'Uzbekistan'                             => 'UZ',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   872
        'Vanuatu'                                => 'VU',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   873
        'Vatican City State'                     => 'VA',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   874
        'Venezuela'                              => 'VE',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   875
        'Vietnam'                                => 'VN',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   876
        'Virgin Islands (British)'               => 'VG',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   877
        'Virgin Islands (U.S.)'                  => 'VI',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   878
        'Wallis and Futuna Islands'              => 'WF',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   879
        'Western Sahara'                         => 'EH',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   880
        'Yemen Republic of'                      => 'YE',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   881
        'Zambia'                                 => 'ZM',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   882
        'Zimbabwe'                               => 'ZW'
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   883
    );  # end suckage
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   884
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   885
    # attempt countryname translation if needed
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   886
    if ( $c->{country} !~ m/^[A-Z]{2,3}$/ ) {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   887
    	$c->{country} = $country_codes{$c->{country}};
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   888
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   889
        unless ( defined( $c->{country} ) ) {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   890
            $self->debug("Invalid country.");
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   891
            return undef;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   892
        }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   893
    }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   894
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   895
    # build contact hashref from customer info.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   896
    my $contact_info = {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   897
        first_name  => $c->{firstname},
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   898
        last_name   => $c->{lastname},
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   899
        city        => $c->{city},
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   900
        state       => $c->{state},
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   901
        country     => $c->{country},
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   902
        address1    => $c->{address},
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   903
        postal_code => $c->{zip},
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   904
        email       => $c->{email},
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   905
        phone       => $epp_phone,
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   906
        org_name    => $c->{company} || 'n/a',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   907
    };
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   908
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   909
    $rv = $self->make_request(
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   910
        {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   911
            action     => 'sw_register',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   912
            object     => 'domain',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   913
            attributes => {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   914
                domain              => $domain,
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   915
                custom_nameservers  => 0,
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   916
                custom_tech_contact => 0,
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   917
                auto_renew          => 0,
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   918
                period              => 1,
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   919
                f_lock_domain       => 1,
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   920
                contact_set         => {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   921
                    admin   => $contact_info,
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   922
                    billing => $contact_info,
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   923
                    owner   => $contact_info
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   924
                },
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   925
                reg_username => $self->{config}->{username},
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   926
                reg_password => $self->{config}->{password},
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   927
                reg_type   => $transfer ? 'transfer' : 'new',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   928
                reg_domain => $self->{config}->{master_domain}, # link domain to the 'master' account
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   929
            }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   930
        }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   931
    );
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   932
    $self->_set_response;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   933
    return $rv->{is_success};
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   934
}
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   935
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   936
=item renew_domain()
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   937
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   938
 my $result = $srs->renew_domain( 'example.com', 1 );
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   939
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   940
Renew a domain for a period of time in years. 1 year is the default.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   941
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   942
=cut
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   943
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   944
sub renew_domain
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   945
{
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   946
    my ($self, $domain, $years) = @_;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   947
    return undef unless $domain;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   948
    $years ||= 1;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   949
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   950
    # sanity checks
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   951
    unless ($self->{config}->{username}) {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   952
        $self->debug("Management auth not set.");
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   953
        return undef;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   954
    }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   955
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   956
    # get current expiration year (why do they need this, again?)
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   957
    my (undef, $expiration) = $self->get_cookie( $domain );
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   958
    $expiration = $1 if $expiration =~ /^(\d{4})-/;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   959
    $expiration ||= Date::Calc::This_Year();
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   960
    
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   961
    $rv = $self->make_request(
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   962
        {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   963
            action     => 'renew',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   964
            object     => 'domain',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   965
            attributes => {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   966
                domain                => $domain,
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   967
                auto_renew            => 0,
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   968
                handle                => 'process',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   969
                period                => $years,
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   970
                currentexpirationyear => $expiration,
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   971
            }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   972
        }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   973
    );
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   974
    $self->_set_response;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   975
    return $rv->{is_success};
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   976
}
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   977
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   978
=item revoke_domain()
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   979
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   980
Revoke a previously registered domain.  This only works if the domain is
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   981
still within the grace period as defined by the registrar.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   982
Requires you to have called set_manage_auth() B<first>.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   983
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   984
 my $result = $srs->revoke_domain( 'example.com' );
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   985
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   986
Returns true if the revoke is successful, false otherwise.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   987
Returns undefined on error.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   988
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   989
=cut
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   990
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   991
sub revoke_domain
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   992
{
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   993
    my ($self, $domain) = @_;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   994
    return undef unless $domain;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   995
    unless ($self->{config}->{username}) {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   996
        $self->debug("Management auth not set.");
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   997
        return undef;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   998
    }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
   999
    $rv = $self->make_request(
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1000
        {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1001
            action     => 'revoke',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1002
            object     => 'domain',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1003
            attributes => {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1004
                reseller => $self->{config}->{username},
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1005
                domain => $domain,
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1006
            }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1007
        }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1008
    );
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1009
    $self->_set_response;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1010
    return $rv->{is_success};
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1011
}
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1012
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1013
=item transfer_domain()
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1014
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1015
 my $result = $srs->transfer_domain( 'example.com', $c );
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1016
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1017
Transfer a domain under your control.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1018
Returns true on success, false on failure, and undefined on caller error.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1019
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1020
=cut
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1021
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1022
sub transfer_domain
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1023
{
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1024
    my $self = shift;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1025
    return $self->register_domain( @_, 1 );
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1026
}
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1027
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1028
=item make_request()
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1029
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1030
This method is the real workhorse of this module.  If any OpenSRS API
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1031
isn't explicity implemented in this module as a method call (such as
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1032
get_cookie(), bulk_lock(), etc), you can use make_request() to build and send
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1033
the API yourself.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1034
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1035
Examples:
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1036
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1037
 my $result = $srs->make_request(
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1038
     {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1039
         batch   => 1,
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1040
         action  => 'submit',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1041
         object  => 'bulk_change',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1042
         attributes => {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1043
             change_type => 'domain_lock',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1044
             change_items => [ 'example.com', 'example.net' ],
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1045
             op_type => 'lock',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1046
         }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1047
     }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1048
 );
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1049
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1050
 my $result = $srs->make_request(
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1051
     {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1052
         action     => 'lookup',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1053
         object     => 'domain',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1054
         attributes => {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1055
             domain => 'example.com'
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1056
         }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1057
     }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1058
 );
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1059
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1060
Returns a hashref containing parsed XML results from OpenSRS.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1061
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1062
Example return:
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1063
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1064
 {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1065
     'protocol' => 'XCP',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1066
     'object' => 'DOMAIN',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1067
     'response_text' => 'Domain taken',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1068
     'action' => 'REPLY',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1069
     'response_code' => '211',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1070
     'attributes' => {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1071
         'status' => 'taken',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1072
         'match' => {}
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1073
     },
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1074
     'is_success' => '1'
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1075
 }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1076
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1077
=cut
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1078
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1079
# build opensrs xml protocol string.  submit.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1080
# convert xml response to data structure, and return.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1081
sub make_request
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1082
{
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1083
    my ($self, $data) = @_;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1084
    return undef unless ref $data;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1085
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1086
    $self->debug("Using " . $self->environment . " environment.");
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1087
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1088
    my $key  = $self->{config}->{ $self->environment }->{key};
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1089
    my $host = $self->{config}->{ $self->environment }->{host};
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1090
    $ENV{HTTPS_DEBUG} = 1 if $self->debug_level > 2;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1091
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1092
    unless ($key) {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1093
        $self->debug("Authentication key not set.");
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1094
        return undef;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1095
    }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1096
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1097
    my $action = uc $data->{action};
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1098
    my $object = uc $data->{object};
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1099
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1100
    # build our XML request.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1101
    # lets not bother with anything super fancy, 
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1102
    # everything but the item keys are always static anyway.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1103
    my $xml;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1104
    $xml = <<XML;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1105
<?xml version='1.0' encoding="UTF-8" standalone="no" ?>
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1106
<!DOCTYPE OPS_envelope SYSTEM "ops.dtd">
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1107
<OPS_envelope>
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1108
<header><version>0.9</version></header>
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1109
<body>
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1110
<data_block>
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1111
<dt_assoc>
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1112
  <item key="protocol">XCP</item>
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1113
  <item key="action">$action</item>
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1114
  <item key="object">$object</item>
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1115
XML
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1116
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1117
    $xml .= "  <item key=\"cookie\">$data->{cookie}</item>\n" if $data->{cookie};
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1118
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1119
$xml .= <<XML;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1120
  <item key="attributes">
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1121
    <dt_assoc>
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1122
XML
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1123
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1124
    foreach (sort keys %{ $data->{attributes} }) {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1125
        my $val = $data->{attributes}->{$_};
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1126
        $xml .= $self->_format( $val, 4 );
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1127
    }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1128
    $xml .= <<XML;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1129
    </dt_assoc>
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1130
  </item>
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1131
</dt_assoc>
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1132
</data_block>
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1133
</body>
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1134
</OPS_envelope>
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1135
XML
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1136
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1137
    # whoof, ok.  got our request built.  lets ship it off.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1138
    if ($self->debug_level > 1) {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1139
        $self->debug("\nClient Request XML:\n" . '-' x 30);
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1140
        $self->debug($xml);
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1141
    }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1142
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1143
    $host = $self->{config}->{bulkhost} if $data->{batch};
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1144
    $self->debug("Making request to $host...");
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1145
    my $ua = LWP::UserAgent->new( timeout => 20, agent => "Net::OpenSRS/$VERSION" );
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1146
    unless ($ua) {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1147
        $self->debug("Unable to contact remote host.");
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1148
        return undef;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1149
    }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1150
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1151
    my $res = $ua->post( 
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1152
        $host,
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1153
        'Content-Type' => 'text/xml',
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1154
        'X-Username'   => $self->{config}->{username},
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1155
        'X-Signature'  => hash( hash( $xml, $key ), $key ),
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1156
        'Content'      => $xml
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1157
    );
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1158
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1159
    my $struct;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1160
    if ( $res->is_success ) {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1161
        $self->debug("HTTP result: " . $res->status_line);
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1162
        eval { $struct = XML::Simple::XMLin( $res->content); };
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1163
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1164
        if ($self->debug_level > 1) {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1165
            $self->debug("\nOpenSRS Response XML:\n" . '-' x 30);
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1166
            $self->debug($res->content);
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1167
            $self->debug('');
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1168
        }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1169
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1170
        # get the struct looking just how we want it.
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1171
        # (de-nastify it.)
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1172
        $xml = XML::Simple::XMLout( $struct->{body}->{data_block}->{dt_assoc}->{item} );
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1173
        $struct = XML::Simple::XMLin( $xml );
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1174
        $xml = XML::Simple::XMLout( $struct->{attributes}->{item} );
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1175
        $struct->{attributes} = XML::Simple::XMLin( $xml );
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1176
    }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1177
    else {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1178
        $self->debug("HTTP error: " . $res->status_line);
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1179
        return undef;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1180
    }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1181
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1182
    $rv = $struct;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1183
    $self->_set_response;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1184
    return $self->last_response(1);
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1185
}
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1186
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1187
# format perl structs into opensrs XML
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1188
sub _format
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1189
{
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1190
    my ($self, $val, $indent) = @_;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1191
    my $xml;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1192
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1193
    $indent ||= 6;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1194
    my $sp = ' ' x $indent;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1195
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1196
    if ( ref $val eq 'ARRAY' ) {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1197
        my $c = 0;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1198
        $xml .= "$sp<item key=\"$_\">\n";
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1199
        $xml .= "$sp  <dt_array>\n";
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1200
        foreach (sort @$val) {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1201
            $xml .= "$sp    <item key=\"$c\">$_</item>\n";
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1202
            $c++;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1203
        }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1204
        $xml .= "$sp  </dt_array>\n";
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1205
        $xml .= "$sp</item>\n";
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1206
    }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1207
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1208
    elsif ( ref $val eq 'HASH' ) {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1209
        $xml .= "$sp<item key=\"$_\">\n";
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1210
        $xml .= "$sp<dt_assoc>\n";
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1211
        foreach (sort keys %$val) {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1212
            $xml .= $self->_format( $val->{$_} );
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1213
        }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1214
        $xml .= "$sp</dt_assoc>\n";
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1215
        $xml .= "$sp</item>\n";
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1216
    }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1217
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1218
    else {
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1219
        $xml .= "$sp<item key=\"$_\">$val</item>\n";
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1220
    }
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1221
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1222
    return $xml;
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1223
}
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1224
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1225
=back
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1226
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1227
=head1 Author
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1228
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1229
Mahlon E. Smith I<mahlon@martini.nu> for Spime Solutions Group
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1230
I<(www.spime.net)>
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1231
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1232
=cut
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1233
315eb12b224b Reorganizing for Trac.
mahlon
parents:
diff changeset
  1234
1;