« blib/lib/WWW/eNom/DomainRequest/Transfer.pm
↑ Summary
blib/lib/WWW/eNom/DomainRequest/Registration.pm »
| 1 | package WWW::eNom::Role::Command::Domain::Availability; | ||||||||||
| 2 | |||||||||||
| 3 | 44 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 44 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 44 | ▶ | use Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 44 | ▶ | use MooseX::Params::Validate; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 44 | ▶ | use WWW::eNom::Types qw( Bool HashRef Int Str Strs ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 44 | ▶ | use WWW::eNom::DomainAvailability; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 44 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | 44 | ▶ | use Readonly; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 44 | Readonly my $SUGGESTABLE_TLDS => [ qw( com net tv cc ) ]; | |||||||||
| 17 | |||||||||||
| 18 | 44 | requires 'submit'; | |||||||||
| 19 | |||||||||||
| 20 | 44 | our $VERSION = 'v2.0.0'; # VERSION | |||||||||
| 21 | # ABSTRACT: Domain Availability API Calls | ||||||||||
| 22 | |||||||||||
| 23 | sub check_domain_availability { | ||||||||||
| 24 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
check_domain_availability: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||
| 25 | 0 | my ( %args ) = validated_hash( | |||||||||
| 26 | \@_, | ||||||||||
| 27 | slds => { isa => Strs }, | ||||||||||
| 28 | tlds => { isa => Strs }, | ||||||||||
| 29 | suggestions => { isa => Bool, default => 0 }, | ||||||||||
| 30 | ); | ||||||||||
| 31 | |||||||||||
| 32 | 0 | ▶ | if( ( scalar @{ $args{slds} } * @{ $args{tlds} } ) > 30 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | 0 | croak 'The combination of slds and tlds you provided would require more than 30 checks. Please reduce your search.'; | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | 0 | my @domains_to_check; | |||||||||
| 37 | 0 | for my $sld (@{ $args{slds} }) { | |||||||||
| 38 | 0 | for my $tld (@{ $args{tlds} }) { | |||||||||
| 39 | 0 | push @domains_to_check, sprintf( '%s.%s', $sld, $tld ); | |||||||||
| 40 | } | ||||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | 0 | my $response = $self->submit({ | |||||||||
| 44 | method => 'Check', | ||||||||||
| 45 | params => { | ||||||||||
| 46 | DomainList => join( ',', @domains_to_check ), | ||||||||||
| 47 | } | ||||||||||
| 48 | }); | ||||||||||
| 49 | |||||||||||
| 50 | 0 | my @domain_availabilities; | |||||||||
| 51 | 0 | ▶ | for( my $domain_index = 0; $domain_index < ( scalar @{ $response->{Domain} } ); $domain_index++ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | push @domain_availabilities, WWW::eNom::DomainAvailability->new( | ||||||||||
| 53 | name => $response->{Domain}->[ $domain_index ], | ||||||||||
| 54 | 0 | is_available => ( $response->{RRPCode}->[ $domain_index ] == 210 ) | |||||||||
| 55 | ); | ||||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | 0 | ▶ | if( $args{suggestions} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | 0 | for my $sld (@{ $args{slds} }) { | |||||||||
| 60 | my $suggestions_domain_availabilities = $self->suggest_domain_names({ | ||||||||||
| 61 | phrase => $sld, | ||||||||||
| 62 | tlds => $args{tlds}, | ||||||||||
| 63 | 0 | related => 1, | |||||||||
| 64 | }); | ||||||||||
| 65 | |||||||||||
| 66 | 0 | push @domain_availabilities, @{ $suggestions_domain_availabilities }; | |||||||||
| 67 | } | ||||||||||
| 68 | } | ||||||||||
| 69 | |||||||||||
| 70 | 0 | return \@domain_availabilities; | |||||||||
| 71 | } | ||||||||||
| 72 | |||||||||||
| 73 | sub suggest_domain_names { | ||||||||||
| 74 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
suggest_domain_names: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||
| 75 | 0 | my ( %args ) = validated_hash( | |||||||||
| 76 | \@_, | ||||||||||
| 77 | phrase => { isa => Str }, | ||||||||||
| 78 | tlds => { isa => Strs }, | ||||||||||
| 79 | related => { isa => Bool, default => 0 }, | ||||||||||
| 80 | num_results => { isa => Int, default => 10 }, | ||||||||||
| 81 | ); | ||||||||||
| 82 | |||||||||||
| 83 | my @suggestable_tlds = grep { | ||||||||||
| 84 | 0 | my $valid_tld = $_; | |||||||||
| 85 | 0 | grep { $_ eq $valid_tld } @{ $args{tlds} }; | |||||||||
| 86 | 0 | } @{ $SUGGESTABLE_TLDS }; | |||||||||
| 87 | |||||||||||
| 88 | 0 | ▶ | if( scalar @suggestable_tlds == 0 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 89 | # No suggestions since none of the specified TLDs are support it | ||||||||||
| 90 | 0 | return [ ]; | |||||||||
| 91 | } | ||||||||||
| 92 | |||||||||||
| 93 | my $response = $self->submit({ | ||||||||||
| 94 | method => 'NameSpinner', | ||||||||||
| 95 | params => { | ||||||||||
| 96 | SLD => $args{phrase}, | ||||||||||
| 97 | 0 | ▶ | TLDList => join( ',', @{ $args{tlds} } ), | ||||||||
|
Branch: 1 branch
| |||||||||||
| 98 | Related => ( $args{related} ? 'High' : 'Off' ), | ||||||||||
| 99 | MaxResults => $args{num_results}, | ||||||||||
| 100 | } | ||||||||||
| 101 | 0 | }); | |||||||||
| 102 | |||||||||||
| 103 | 0 | my @domain_availabilities; | |||||||||
| 104 | 0 | for my $sld ( keys %{ $response->{namespin}{domains}{domain} } ) { | |||||||||
| 105 | 0 | my $domain_response = $response->{namespin}{domains}{domain}{$sld}; | |||||||||
| 106 | |||||||||||
| 107 | 0 | for my $tld (@{ $args{tlds} }) { | |||||||||
| 108 | 0 | ▶ | if( !exists $domain_response->{$tld} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 109 | 0 | next; | |||||||||
| 110 | } | ||||||||||
| 111 | |||||||||||
| 112 | push @domain_availabilities, WWW::eNom::DomainAvailability->new( | ||||||||||
| 113 | name => sprintf('%s.%s', lc $sld, $tld ), | ||||||||||
| 114 | 0 | is_available => ( $domain_response->{$tld} eq 'y' ), | |||||||||
| 115 | ); | ||||||||||
| 116 | } | ||||||||||
| 117 | } | ||||||||||
| 118 | |||||||||||
| 119 | 0 | return \@domain_availabilities; | |||||||||
| 120 | } | ||||||||||
| 121 | |||||||||||
| 122 | 44 | 1; | |||||||||
| 123 | |||||||||||
| 124 | __END__ | ||||||||||
| 125 | |||||||||||
| 126 | =pod | ||||||||||
| 127 | |||||||||||
| 128 | =head1 NAME | ||||||||||
| 129 | |||||||||||
| 130 | WWW::eNom::Role::Command::Domain::Availability - Domain Availability Related Operations | ||||||||||
| 131 | |||||||||||
| 132 | =head1 SYNOPSIS | ||||||||||
| 133 | |||||||||||
| 134 | use WWW::eNom; | ||||||||||
| 135 | |||||||||||
| 136 | my $eNom = WWW::eNom->new( ... ); | ||||||||||
| 137 | |||||||||||
| 138 | # Check If Domains Are Available | ||||||||||
| 139 | my $domain_availabilities = $eNom->check_domain_availability( | ||||||||||
| 140 | slds => [qw( cpan drzigman brainstormincubator )], | ||||||||||
| 141 | tlds => [qw( com net org )], | ||||||||||
| 142 | suggestions => 0, | ||||||||||
| 143 | ); | ||||||||||
| 144 | |||||||||||
| 145 | for my $domain_availability (@{ $domain_availabilities }) { | ||||||||||
| 146 | if( $domain_availability->is_available ) { | ||||||||||
| 147 | print 'Domain ' . $domain_availability->name . " is available!\n"; | ||||||||||
| 148 | } | ||||||||||
| 149 | else { | ||||||||||
| 150 | print 'Domain ' . $domain_availability->name . " is not available.\n"; | ||||||||||
| 151 | } | ||||||||||
| 152 | } | ||||||||||
| 153 | |||||||||||
| 154 | # Get Domain Suggestions | ||||||||||
| 155 | my $domain_availabilities = $eNom->suggest_domain_names( | ||||||||||
| 156 | phrase => 'fast race cars', | ||||||||||
| 157 | tlds => [qw( com net tv cc )], | ||||||||||
| 158 | related => 1, # Optional, Defaults to 0 | ||||||||||
| 159 | num_results => 10, # Optional, Defaults to 10 | ||||||||||
| 160 | ); | ||||||||||
| 161 | |||||||||||
| 162 | for my $domain_availability (@{ $domain_availabilities }) { | ||||||||||
| 163 | if( $domain_availability->is_available ) { | ||||||||||
| 164 | print 'Domain ' . $domain_availability->name . " is available!\n"; | ||||||||||
| 165 | } | ||||||||||
| 166 | else { | ||||||||||
| 167 | print 'Domain ' . $domain_availability->name . " is not available.\n"; | ||||||||||
| 168 | } | ||||||||||
| 169 | } | ||||||||||
| 170 | |||||||||||
| 171 | =head1 REQUIRES | ||||||||||
| 172 | |||||||||||
| 173 | submit | ||||||||||
| 174 | |||||||||||
| 175 | =head1 DESCRIPTION | ||||||||||
| 176 | |||||||||||
| 177 | Implements domain availability related operations with the L<eNom's|http://www.enom.com/APICommandCatalog/> API. | ||||||||||
| 178 | |||||||||||
| 179 | =head1 METHODS | ||||||||||
| 180 | |||||||||||
| 181 | =head2 check_domain_availability | ||||||||||
| 182 | |||||||||||
| 183 | use WWW::eNom; | ||||||||||
| 184 | |||||||||||
| 185 | my $eNom = WWW::eNom->new( ... ); | ||||||||||
| 186 | |||||||||||
| 187 | # Check If Domains Are Available | ||||||||||
| 188 | my $domain_availabilities = $eNom->check_domain_availability( | ||||||||||
| 189 | slds => [qw( cpan drzigman brainstormincubator )], | ||||||||||
| 190 | tlds => [qw( com net org )], | ||||||||||
| 191 | suggestions => 0, | ||||||||||
| 192 | ); | ||||||||||
| 193 | |||||||||||
| 194 | for my $domain_availability (@{ $domain_availabilities }) { | ||||||||||
| 195 | if( $domain_availability->is_available ) { | ||||||||||
| 196 | print 'Domain ' . $domain_availability->name . " is available!\n"; | ||||||||||
| 197 | } | ||||||||||
| 198 | else { | ||||||||||
| 199 | print 'Domain ' . $domain_availability->name . " is not available.\n"; | ||||||||||
| 200 | } | ||||||||||
| 201 | } | ||||||||||
| 202 | |||||||||||
| 203 | Abstraction of the L<Check|http://www.enom.com/APICommandCatalog/API%20topics/api_Check.htm?Highlight=Check> eNom API Call. Given an ArrayRef of slds and tlds returns an ArrayRef of L<WWW::eNom::DomainAvailability> objects. Optionally takes suggestions params (defaults to false), if specified then additional domain suggestions will be returned using the slds (one at a time) as the search phrase. | ||||||||||
| 204 | |||||||||||
| 205 | B<NOTE> There is a hard limit of 30 "checks" for a given combination of SLDs and TLDs (excluding suggestions), if the cartesian product of the SLDs and TLDs provided is greater than 30 this method will croak with the error 'The combination of slds and tlds you provided would require more than 30 checks. Please reduce your search.' | ||||||||||
| 206 | |||||||||||
| 207 | =head2 suggest_domain_names | ||||||||||
| 208 | |||||||||||
| 209 | use WWW::eNom; | ||||||||||
| 210 | |||||||||||
| 211 | my $eNom = WWW::eNom->new( ... ); | ||||||||||
| 212 | |||||||||||
| 213 | my $domain_availabilities = $eNom->suggest_domain_names( | ||||||||||
| 214 | phrase => 'fast race cars', | ||||||||||
| 215 | tlds => [qw( com net tv cc )], | ||||||||||
| 216 | related => 1, # Optional, Defaults to 0 | ||||||||||
| 217 | num_results => 10, # Optional, Defaults to 10 | ||||||||||
| 218 | ); | ||||||||||
| 219 | |||||||||||
| 220 | for my $domain_availability (@{ $domain_availabilities }) { | ||||||||||
| 221 | if( $domain_availability->is_available ) { | ||||||||||
| 222 | print 'Domain ' . $domain_availability->name . " is available!\n"; | ||||||||||
| 223 | } | ||||||||||
| 224 | else { | ||||||||||
| 225 | print 'Domain ' . $domain_availability->name . " is not available.\n"; | ||||||||||
| 226 | } | ||||||||||
| 227 | } | ||||||||||
| 228 | |||||||||||
| 229 | Abstraction of the L<NameSpinner|http://www.enom.com/APICommandCatalog/API%20topics/api_NameSpinner.htm> eNom API Call. | ||||||||||
| 230 | |||||||||||
| 231 | Accepts the following arguments: | ||||||||||
| 232 | |||||||||||
| 233 | =over 4 | ||||||||||
| 234 | |||||||||||
| 235 | =item B<phrase> | ||||||||||
| 236 | |||||||||||
| 237 | A search phrase to be used for domain suggestions | ||||||||||
| 238 | |||||||||||
| 239 | =item B<tlds> | ||||||||||
| 240 | |||||||||||
| 241 | ArrayRef of Public Suffixes to return domains for. | ||||||||||
| 242 | |||||||||||
| 243 | B<NOTE> eNom will only generated suggestions for com, net, tv, cc. No matter what TLDs are provided, only suggestions for these will provided. If you do not include one of these TLDs, you will get no domain suggestion results. | ||||||||||
| 244 | |||||||||||
| 245 | =item related | ||||||||||
| 246 | |||||||||||
| 247 | Default false, if true will include related domains based on related keyboard (if you specify 'fast' you may get results with 'quick', 'instant' and 'hurry'). | ||||||||||
| 248 | |||||||||||
| 249 | =item num_results | ||||||||||
| 250 | |||||||||||
| 251 | Default 10, number of results to return per provided (and supported) TLD. | ||||||||||
| 252 | |||||||||||
| 253 | =back | ||||||||||
| 254 | |||||||||||
| 255 | Return an ArrayRef of L<WWW::eNom::DomainAvailability> objects. | ||||||||||
| 256 | |||||||||||
| 257 | =cut | ||||||||||