| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package WWW::eNom; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 5 |  |  | 5 |  | 115744 | use strict; | 
|  | 5 |  |  |  |  | 10 |  | 
|  | 5 |  |  |  |  | 143 |  | 
| 4 | 5 |  |  | 5 |  | 26 | use warnings; | 
|  | 5 |  |  |  |  | 10 |  | 
|  | 5 |  |  |  |  | 164 |  | 
| 5 | 5 |  |  | 5 |  | 3959 | use utf8; | 
|  | 5 |  |  |  |  | 47 |  | 
|  | 5 |  |  |  |  | 30 |  | 
| 6 | 5 |  |  | 5 |  | 3521 | use Moo 1.001000; | 
|  | 5 |  |  |  |  | 70677 |  | 
|  | 5 |  |  |  |  | 41 |  | 
| 7 | 5 |  |  | 5 |  | 14218 | use Type::Tiny 0.032 (); | 
|  | 5 |  |  |  |  | 112055 |  | 
|  | 5 |  |  |  |  | 206 |  | 
| 8 | 5 |  |  | 5 |  | 4766 | use Type::Utils qw(class_type subtype as where message); | 
|  | 5 |  |  |  |  | 73306 |  | 
|  | 5 |  |  |  |  | 54 |  | 
| 9 | 5 |  |  | 5 |  | 9212 | use Types::Standard qw(Bool Str); | 
|  | 5 |  |  |  |  | 229947 |  | 
|  | 5 |  |  |  |  | 71 |  | 
| 10 | 5 |  |  | 5 |  | 4672 | use Carp qw(croak); | 
|  | 5 |  |  |  |  | 10 |  | 
|  | 5 |  |  |  |  | 318 |  | 
| 11 | 5 |  |  | 5 |  | 6482 | use Mozilla::PublicSuffix qw(public_suffix); | 
|  | 5 |  |  |  |  | 101300 |  | 
|  | 5 |  |  |  |  | 1078 |  | 
| 12 | 5 |  |  | 5 |  | 4895 | use URI 1.60; | 
|  | 5 |  |  |  |  | 25210 |  | 
|  | 5 |  |  |  |  | 3491 |  | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | our $VERSION = 'v1.3.1'; # VERSION | 
| 15 |  |  |  |  |  |  | # ABSTRACT: Interact with eNom, Inc.'s reseller API | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | with 'WWW::eNom::Role::Commands'; | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  | # Supported response types: | 
| 20 |  |  |  |  |  |  | my @response_types = qw(xml_simple xml html text); | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | my $URIObject = class_type({ class => 'URI' })->plus_coercions( | 
| 23 |  |  |  |  |  |  | Str, sub { URI->new($_) } | 
| 24 |  |  |  |  |  |  | ); | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | my $eNomResponseType = subtype as Str, | 
| 27 |  |  |  |  |  |  | where { | 
| 28 |  |  |  |  |  |  | my $type = $_; | 
| 29 |  |  |  |  |  |  | { $type eq $_ and return 1 for @response_types; 0 } | 
| 30 |  |  |  |  |  |  | }, | 
| 31 |  |  |  |  |  |  | message { 'response_type must be one of: ' . join ', ', @response_types }; | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | has username => ( | 
| 34 |  |  |  |  |  |  | isa      => Str, | 
| 35 |  |  |  |  |  |  | is       => 'ro', | 
| 36 |  |  |  |  |  |  | required => 1 | 
| 37 |  |  |  |  |  |  | ); | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | has password => ( | 
| 40 |  |  |  |  |  |  | isa      => Str, | 
| 41 |  |  |  |  |  |  | is       => 'ro', | 
| 42 |  |  |  |  |  |  | required => 1 | 
| 43 |  |  |  |  |  |  | ); | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | has test => ( | 
| 46 |  |  |  |  |  |  | isa     => Bool, | 
| 47 |  |  |  |  |  |  | is      => 'ro', | 
| 48 |  |  |  |  |  |  | default => 0 | 
| 49 |  |  |  |  |  |  | ); | 
| 50 |  |  |  |  |  |  |  | 
| 51 |  |  |  |  |  |  | has response_type => ( | 
| 52 |  |  |  |  |  |  | isa     => $eNomResponseType, | 
| 53 |  |  |  |  |  |  | is      => 'ro', | 
| 54 |  |  |  |  |  |  | default => 'xml_simple' | 
| 55 |  |  |  |  |  |  | ); | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | has _uri => ( | 
| 58 |  |  |  |  |  |  | isa     => $URIObject, | 
| 59 |  |  |  |  |  |  | is      => 'ro', | 
| 60 |  |  |  |  |  |  | coerce  => $URIObject->coercion, | 
| 61 |  |  |  |  |  |  | lazy    => 1, | 
| 62 |  |  |  |  |  |  | default => \&_default__uri, | 
| 63 |  |  |  |  |  |  | ); | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | sub _split_domain { | 
| 66 | 0 |  |  | 0 |  |  | my ($self, $domain) = @_; | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | # Look for an eNom wildcard TLD: | 
| 69 | 0 |  |  |  |  |  | my $wildcard_tld = qr{\.([*12@]+)$}x; | 
| 70 | 0 | 0 |  |  |  |  | my ($subbed_tld) = $domain =~ $wildcard_tld | 
| 71 |  |  |  |  |  |  | and $domain =~ s/$wildcard_tld/.com/x; | 
| 72 | 0 | 0 |  |  |  |  | my $suffix = eval { public_suffix($domain) } | 
|  | 0 |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | or croak "Domain name, $domain, does not look like a valid domain."; | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | # Finally, add in the neccesary API arguments: | 
| 76 | 0 |  |  |  |  |  | my ($sld) = $domain =~ /^(.+)\.$suffix$/x; | 
| 77 | 0 | 0 |  |  |  |  | $suffix = $subbed_tld if $subbed_tld; | 
| 78 |  |  |  |  |  |  |  | 
| 79 | 0 |  |  |  |  |  | return ($sld, $suffix); | 
| 80 |  |  |  |  |  |  | } | 
| 81 |  |  |  |  |  |  |  | 
| 82 |  |  |  |  |  |  | sub _make_query_string { | 
| 83 | 0 |  |  | 0 |  |  | my ($self, $command, %opts) = @_; | 
| 84 | 0 |  |  |  |  |  | my $uri = $self->_uri; | 
| 85 | 0 | 0 | 0 |  |  |  | if ( $command ne "CertGetApproverEmail" && exists $opts{Domain} ) { | 
| 86 | 0 |  |  |  |  |  | @opts{qw(SLD TLD)} = $self->_split_domain(delete $opts{Domain}); | 
| 87 |  |  |  |  |  |  | } | 
| 88 |  |  |  |  |  |  |  | 
| 89 | 0 | 0 |  |  |  |  | my $response_type = $self->response_type eq 'xml_simple' | 
| 90 |  |  |  |  |  |  | ? 'xml' | 
| 91 |  |  |  |  |  |  | : $self->response_type; | 
| 92 |  |  |  |  |  |  |  | 
| 93 | 0 |  |  |  |  |  | $uri->query_form( | 
| 94 |  |  |  |  |  |  | command      => $command, | 
| 95 |  |  |  |  |  |  | uid          => $self->username, | 
| 96 |  |  |  |  |  |  | pw           => $self->password, | 
| 97 |  |  |  |  |  |  | responseType => $response_type, | 
| 98 |  |  |  |  |  |  | %opts | 
| 99 |  |  |  |  |  |  | ); | 
| 100 |  |  |  |  |  |  |  | 
| 101 | 0 |  |  |  |  |  | return $uri; | 
| 102 |  |  |  |  |  |  | } | 
| 103 |  |  |  |  |  |  |  | 
| 104 |  |  |  |  |  |  | sub _default__uri { | 
| 105 | 0 |  |  | 0 |  |  | my $self = shift; | 
| 106 | 0 | 0 |  |  |  |  | my $subdomain = $self->test ? 'resellertest' : 'reseller'; | 
| 107 | 0 |  |  |  |  |  | return URI->new("http://$subdomain.enom.com/interface.asp"); | 
| 108 |  |  |  |  |  |  | } | 
| 109 |  |  |  |  |  |  |  | 
| 110 |  |  |  |  |  |  | 1; | 
| 111 |  |  |  |  |  |  | =encoding utf8 | 
| 112 |  |  |  |  |  |  |  | 
| 113 |  |  |  |  |  |  | =head1 NAME | 
| 114 |  |  |  |  |  |  |  | 
| 115 |  |  |  |  |  |  | WWW::eNom - Interact with eNom, Inc.'s reseller API | 
| 116 |  |  |  |  |  |  |  | 
| 117 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 118 |  |  |  |  |  |  |  | 
| 119 |  |  |  |  |  |  | use WWW::eNom; | 
| 120 |  |  |  |  |  |  |  | 
| 121 |  |  |  |  |  |  | my $enom = WWW::eNom->new( | 
| 122 |  |  |  |  |  |  | username      => "resellid", | 
| 123 |  |  |  |  |  |  | password      => "resellpw", | 
| 124 |  |  |  |  |  |  | response_type => "xml_simple", | 
| 125 |  |  |  |  |  |  | test          => 1 | 
| 126 |  |  |  |  |  |  | ); | 
| 127 |  |  |  |  |  |  |  | 
| 128 |  |  |  |  |  |  | $enom->AddToCart( | 
| 129 |  |  |  |  |  |  | EndUserIP => "1.2.3.4", | 
| 130 |  |  |  |  |  |  | ProductType => "Register", | 
| 131 |  |  |  |  |  |  | SLD => "myspiffynewdomain", | 
| 132 |  |  |  |  |  |  | TLD => "com" | 
| 133 |  |  |  |  |  |  | ); | 
| 134 |  |  |  |  |  |  |  | 
| 135 |  |  |  |  |  |  | ... | 
| 136 |  |  |  |  |  |  |  | 
| 137 |  |  |  |  |  |  | =head1 METHODS | 
| 138 |  |  |  |  |  |  |  | 
| 139 |  |  |  |  |  |  | =head2 new | 
| 140 |  |  |  |  |  |  |  | 
| 141 |  |  |  |  |  |  | Constructs a new object for interacting with the eNom API. If the | 
| 142 |  |  |  |  |  |  | "test" parameter is given, then the API calls will be made to the test | 
| 143 |  |  |  |  |  |  | server instead of the live one. | 
| 144 |  |  |  |  |  |  |  | 
| 145 |  |  |  |  |  |  | As of v0.3.1, an optional "response_type" parameter is supported. For the sake | 
| 146 |  |  |  |  |  |  | of backward compatibility, the default is "xml_simple"; see below for an | 
| 147 |  |  |  |  |  |  | explanation of this response type. Use of any other valid option will lead to | 
| 148 |  |  |  |  |  |  | the return of string responses straight from the eNom API. These options are: | 
| 149 |  |  |  |  |  |  |  | 
| 150 |  |  |  |  |  |  | =for Pod::Coverage username password response_type test | 
| 151 |  |  |  |  |  |  |  | 
| 152 |  |  |  |  |  |  | =over | 
| 153 |  |  |  |  |  |  |  | 
| 154 |  |  |  |  |  |  | =item * xml | 
| 155 |  |  |  |  |  |  |  | 
| 156 |  |  |  |  |  |  | =item * html | 
| 157 |  |  |  |  |  |  |  | 
| 158 |  |  |  |  |  |  | =item * text | 
| 159 |  |  |  |  |  |  |  | 
| 160 |  |  |  |  |  |  | =back | 
| 161 |  |  |  |  |  |  |  | 
| 162 |  |  |  |  |  |  | =head2 AddBulkDomains (and many others) | 
| 163 |  |  |  |  |  |  |  | 
| 164 |  |  |  |  |  |  | my $response = $enom->AddBulkDomains( | 
| 165 |  |  |  |  |  |  | ProductType => "register", | 
| 166 |  |  |  |  |  |  | ListCount   => 1, | 
| 167 |  |  |  |  |  |  | SLD1        => "myspiffynewdomain", | 
| 168 |  |  |  |  |  |  | TLD1        => "com", | 
| 169 |  |  |  |  |  |  | UseCart     => 1 | 
| 170 |  |  |  |  |  |  | ); | 
| 171 |  |  |  |  |  |  |  | 
| 172 |  |  |  |  |  |  | Performs the specified command - see the | 
| 173 |  |  |  |  |  |  | L for the commands | 
| 174 |  |  |  |  |  |  | and their arguments. | 
| 175 |  |  |  |  |  |  |  | 
| 176 |  |  |  |  |  |  | For convenience, if you pass the "Domain" argument, it will be split | 
| 177 |  |  |  |  |  |  | into "SLD" and "TLD"; that is, you can say | 
| 178 |  |  |  |  |  |  |  | 
| 179 |  |  |  |  |  |  | my $response = $enom->Check( SLD => "myspiffynewdomain", TLD => "com" ); | 
| 180 |  |  |  |  |  |  |  | 
| 181 |  |  |  |  |  |  | or | 
| 182 |  |  |  |  |  |  |  | 
| 183 |  |  |  |  |  |  | my $response = $enom->Check( Domain => "myspiffynewdomain.com" ); | 
| 184 |  |  |  |  |  |  |  | 
| 185 |  |  |  |  |  |  | The default return value is a Perl hash (via L) representing the | 
| 186 |  |  |  |  |  |  | response XML from the eNom API; the only differences are | 
| 187 |  |  |  |  |  |  |  | 
| 188 |  |  |  |  |  |  | =over 3 | 
| 189 |  |  |  |  |  |  |  | 
| 190 |  |  |  |  |  |  | =item * | 
| 191 |  |  |  |  |  |  |  | 
| 192 |  |  |  |  |  |  | The "errors" key returns an array instead of a hash | 
| 193 |  |  |  |  |  |  |  | 
| 194 |  |  |  |  |  |  | =item * | 
| 195 |  |  |  |  |  |  |  | 
| 196 |  |  |  |  |  |  | "responses" returns an array of hashes | 
| 197 |  |  |  |  |  |  |  | 
| 198 |  |  |  |  |  |  | =item * | 
| 199 |  |  |  |  |  |  |  | 
| 200 |  |  |  |  |  |  | Keys which end with a number are transformed into an array | 
| 201 |  |  |  |  |  |  |  | 
| 202 |  |  |  |  |  |  | =back | 
| 203 |  |  |  |  |  |  |  | 
| 204 |  |  |  |  |  |  | So for instance, a command C "enom.@" )> (the "@" means | 
| 205 |  |  |  |  |  |  | "com, net, org, biz, info") might return: | 
| 206 |  |  |  |  |  |  |  | 
| 207 |  |  |  |  |  |  | { | 
| 208 |  |  |  |  |  |  | Domain  => [qw(enom.com enom.net enom.org enom.biz enom.info)], | 
| 209 |  |  |  |  |  |  | Command => "CHECK", | 
| 210 |  |  |  |  |  |  | RRPCode => [qw(211 211 211 211 211)], | 
| 211 |  |  |  |  |  |  | RRPText => [ | 
| 212 |  |  |  |  |  |  | "Domain not available", | 
| 213 |  |  |  |  |  |  | "Domain not available", | 
| 214 |  |  |  |  |  |  | "Domain not available", | 
| 215 |  |  |  |  |  |  | "Domain not available", | 
| 216 |  |  |  |  |  |  | "Domain not available" | 
| 217 |  |  |  |  |  |  | ] | 
| 218 |  |  |  |  |  |  | } | 
| 219 |  |  |  |  |  |  |  | 
| 220 |  |  |  |  |  |  | You will need to read the API guide to check whether to expect responses | 
| 221 |  |  |  |  |  |  | in "RRPText" or "responses"; it's not exactly consistent. | 
| 222 |  |  |  |  |  |  |  | 
| 223 |  |  |  |  |  |  | =head1 RELEASE NOTE | 
| 224 |  |  |  |  |  |  |  | 
| 225 |  |  |  |  |  |  | As of v1.0.0, this module has been renamed to WWW::eNom. Net::eNom is now a thin | 
| 226 |  |  |  |  |  |  | wrapper to preserve backward compatibility. | 
| 227 |  |  |  |  |  |  |  | 
| 228 |  |  |  |  |  |  | =head1 AUTHOR | 
| 229 |  |  |  |  |  |  |  | 
| 230 |  |  |  |  |  |  | Richard Simões, C<<  >> | 
| 231 |  |  |  |  |  |  |  | 
| 232 |  |  |  |  |  |  | Original version by Simon Cozens. | 
| 233 |  |  |  |  |  |  |  | 
| 234 |  |  |  |  |  |  | =head1 COPYRIGHT & LICENSE | 
| 235 |  |  |  |  |  |  |  | 
| 236 |  |  |  |  |  |  | Copyright © 2013 Richard Simões. This module is released under the terms of the | 
| 237 |  |  |  |  |  |  | B and may be modified and/or redistributed under the same or any | 
| 238 |  |  |  |  |  |  | compatible license. |