blib/lib/WWW/LogicBoxes/Role/Command/Domain/Availability.pm

filter: Statementstmt 50.0% 27 / 54 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 8 / 10 Podpod 100% 2 / 2 totaltotal 47.4% 37 / 78 CC 11 SCAR 35.0
CC
11
Cov
41%
check_domain_availability
72.0
suggest_domain_names
20.0
BEGIN
1.0
CRAP 33.2
« blib/lib/WWW/LogicBoxes/Customer.pm ↑ Summary blib/lib/WWW/LogicBoxes.pm »
1 package WWW::LogicBoxes::Role::Command::Domain::Availability;
2  
3 37 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 37 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 37 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 37 ▶use MooseX::Params::Validate;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 37 ▶use WWW::LogicBoxes::Types qw( Bool Int Str Strs );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 37 ▶use WWW::LogicBoxes::DomainAvailability;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 37 ▶use Data::Validate::Domain qw( is_domain );
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 37 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 37 requires 'submit';
18  
19 37 our $VERSION = '1.2.0'; # VERSION
20 # ABSTRACT: Domain Availability API Calls
21  
22 sub check_domain_availability {
23 0 ▶ my $self = shift;
Subroutine check_domain_availability: not called CC=8 SCAR=42.8
Pod documented
24 0 my (%args) = validated_hash(
25 \@_,
26 slds => { isa => Strs },
27 tlds => { isa => Strs },
28 suggestions => { isa => Bool, default => 0 },
29 );
30  
31 my $response = $self->submit({
32 method => 'domains__available',
33 params => {
34 'domain-name' => $args{slds},
35 'tlds' => $args{tlds},
36 }
37 0 });
38  
39 0 my @domain_availabilities;
40 0 for my $domain_name ( keys %{ $response }) {
41 0 ▶ if( is_domain( $domain_name ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_domain($domain_name)) { } 0 0 0
42 # Standard Response Record
43 push @domain_availabilities, WWW::LogicBoxes::DomainAvailability->new({
44 name => $domain_name,
45 0 ▶ is_available => $response->{$domain_name}{status} eq "available" ? 1 : 0,
Branch: 1 branch
BranchTrueFalseTotal
$response->{$domain_name}{'status'} eq 'available' ? : 0 0 0
46 });
47 }
48 else {
49 # Suggestion Response Record
50 0 for my $sld ( keys %{ $response->{ $domain_name } } ) {
51 0 for my $tld ( keys %{ $response->{ $domain_name }{ $sld } } ) {
52 push @domain_availabilities, WWW::LogicBoxes::DomainAvailability->new({
53 name => lc sprintf('%s.%s', $sld, $tld ),
54 0 ▶ is_available => $response->{$domain_name}{$sld}{$tld} eq "available" ? 1 : 0,
Branch: 1 branch
BranchTrueFalseTotal
$response->{$domain_name}{$sld}{$tld} eq 'available' ? : 0 0 0
55 });
56 }
57 }
58 }
59 }
60  
61 0 ▶ if( $args{suggestions} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"suggestions"}) 0 0 0
62 push @domain_availabilities, $self->suggest_domain_names(
63 0 phrase => join(' ', @{ $args{slds} } ),
64 tlds => $args{tlds},
65 0 related => 1,
66 );
67 }
68  
69 0 return \@domain_availabilities;
70 }
71  
72 sub suggest_domain_names {
73 0 ▶ my $self = shift;
Subroutine suggest_domain_names: not called CC=4 SCAR=30.0
Pod documented
74 0 my (%args) = validated_hash(
75 \@_,
76 phrase => { isa => Str },
77 tlds => { isa => Strs },
78 hyphen => { isa => Bool, optional => 1 },
79 related => { isa => Bool, default => 0 },
80 num_results => { isa => Int, default => 10 },
81 );
82  
83 0 ▶ exists $args{hyphen} and carp 'The hyphen argument is deprecated, please see POD for more information';
Branch: 1 branch
BranchTrueFalseTotal
exists $args{"hyphen"} and carp("The hyphen argument is deprecated, please see POD for more information") 0 0 0
84  
85 my $response = $self->submit({
86 method => 'domains__v5__suggest_names',
87 params => {
88 keyword => $args{phrase},
89 'tld-only' => $args{tlds},
90 'exact-match' => !$args{related},
91 }
92 0 });
93  
94 0 my @domain_availabilities;
95 0 for my $domain_name (keys %{ $response }) {
96 push @domain_availabilities, WWW::LogicBoxes::DomainAvailability->new({
97 name => lc $domain_name,
98 0 ▶ is_available => $response->{$domain_name}{status} eq "available" ? 1 : 0,
Branch: 1 branch
BranchTrueFalseTotal
$response->{$domain_name}{'status'} eq 'available' ? : 0 0 0
99 });
100 }
101  
102 0 return [ splice( @domain_availabilities, 0, $args{num_results} * scalar @{ $args{tlds} } ) ];
103 }
104  
105 37 1;
106  
107 __END__
108 =pod
109  
110 =head1 NAME
111  
112 WWW::LogicBoxes::Role::Command::Domain::Availability - Domain Availability Related Operations
113  
114 =head1 SYNOPSIS
115  
116 use WWW::LogicBoxes;
117  
118 my $logic_boxes = WWW::LogicBoxes->new( ... );
119  
120 # Check If Domains Are Available
121 my $domain_availabilities = $logic_boxes->check_domain_availability(
122 slds => [qw( cpan drzigman brainstormincubator )],
123 tlds => [qw( com net org )],
124 suggestions => 0,
125 );
126  
127 for my $domain_availability (@{ $domain_availabilities }) {
128 if( $domain_availability->is_available ) {
129 print 'Domain ' . $domain_availability->name . " is available!\n";
130 }
131 else {
132 print 'Domain ' . $domain_availability->name . " is not available.\n";
133 }
134 }
135  
136 # Get Domain Suggestions
137 my $domain_availabilities = $logic_boxes->suggest_domain_names(
138 phrase => 'fast race cars',
139 tlds => [qw( com net org )],
140 hyphen => 0, # DEPRECATED! Will Generate Warnings (see Method for more information)
141 related => 1,
142 num_results => 10,
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 =head1 REQUIRES
155  
156 submit
157  
158 =head1 DESCRIPTION
159  
160 Implements domain availability related operations with the L<LogicBoxes's|http://www.logicboxes.com> API.
161  
162 =head1 METHODS
163  
164 =head2 check_domain_availability
165  
166 use WWW::LogicBoxes;
167  
168 my $logic_boxes = WWW::LogicBoxes->new( ... );
169  
170 # Check If Domains Are Available
171 my $domain_availabilities = $logic_boxes->check_domain_availability(
172 slds => [qw( cpan drzigman brainstormincubator )],
173 tlds => [qw( com net org )],
174 suggestions => 0,
175 );
176  
177 for my $domain_availability (@{ $domain_availabilities }) {
178 if( $domain_availability->is_available ) {
179 print 'Domain ' . $domain_availability->name . " is available!\n";
180 }
181 else {
182 print 'Domain ' . $domain_availability->name . " is not available.\n";
183 }
184 }
185  
186 Given an ArrayRef of slds and tlds returns an ArrayRef of L<WWW::LogicBoxes::DomainAvailability> objects. Optionally takes suggestions params (defaults to false), if specified then additional domain suggestions will be returned using a search term of the list of slds concatenated together with spaces.
187  
188 =head2 suggest_domain_names
189  
190 use WWW::LogicBoxes;
191  
192 my $logic_boxes = WWW::LogicBoxes->new( ... );
193  
194 my $domain_availabilities = $logic_boxes->suggest_domain_names(
195 phrase => 'fast race cars',
196 tlds => [qw( com net org )],
197 hyphen => 0, # DEPRECATED! Will Generate Warnings.
198 related => 0,
199 num_results => 10,
200 );
201  
202 for my $domain_availability (@{ $domain_availabilities }) {
203 if( $domain_availability->is_available ) {
204 print 'Domain ' . $domain_availability->name . " is available!\n";
205 }
206 else {
207 print 'Domain ' . $domain_availability->name . " is not available.\n";
208 }
209 }
210  
211 Accepts the following arguments:
212  
213 =over 4
214  
215 =item B<phrase>
216  
217 A search phrase to be used for domain suggestions
218  
219 =item B<tlds>
220  
221 ArrayRef of Public Suffixes to return domains for.
222  
223 =item hyphen
224  
225 Default false, if true will include - hacks.
226  
227 B<NOTE> THIS ATTRIBUTE IS DEPRECATED. Passing it is still supported (for backwards compaitability) but it has not effect on the results. Usage will generated the carp'ed warning 'The hyphen argument is deprecated, please see POD for more information''
228  
229 =item related
230  
231 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')
232  
233 =item num_results
234  
235 Default 10, number of results to return.
236  
237 =back
238  
239 Return an ArrayRef of L<WWW::LogicBoxes::DomainAvailability> objects.
240  
241 =cut
« blib/lib/WWW/LogicBoxes/Customer.pm ↑ Summary blib/lib/WWW/LogicBoxes.pm »