DomainOperations

 view release on metacpan or  search on metacpan

lib/DomainOperations/ResellerClubHTTP.pm  view on Meta::CPAN

}

sub checkDomainAWithoutSuggestion {
	my $self    = shift;
	my $options = shift;
	$self->checkDomainA(
		{
			'checkwithsuggestion' => 0,
			tlds                  => $options->{'tlds'},
			domains               => $options->{'domains'},
		}
	);

}

sub checkDomainAWithSuggestion {
	my $self    = shift;
	my $options = shift;
	$self->checkDomainA(
		{
			'checkwithsuggestion' => 1,
			tlds                  => $options->{'tlds'},
			domains               => $options->{'domains'},
		}
	);

}

sub checkDomainA {
	my $self       = shift;
	my $options    = shift;
	my $suggestion = 'true';

	if ( !$options->{checkwithsuggestion} ) {
		$suggestion = 'false';
	}
	$self->{req}->uri( $self->{url}
		  . 'domains/available.json?auth-userid='
		  . $self->{username}
		  . '&auth-password='
		  . $self->{password}
		  . '&domain-name='
		  . join( '&domain-name=', @{ $options->{'domains'} } )
		  . '&tlds='
		  . join( '&tlds=', @{ $options->{'tlds'} } )
		  . '&suggest-alternative='
		  . $suggestion );

	# send request
	my $res = $self->{ua}->request( $self->{req} );

	# check the outcome
	if ( $res->is_success ) {
		my $coder = JSON::XS->new->ascii->pretty->allow_nonref;

		# $pretty_printed_unencoded = $coder->encode ($perl_scalar);
		my $perl_scalar = $coder->decode( $res->content );

		#		print Dumper $perl_scalar;

		#$res->decoded_content;
		return { $self->formatdomains($perl_scalar), 'error' => 0, };
	}
	else {

		#		print Dumper $req;
		return { error => 1, errormessage => $res->status_line, };
	}
}

sub formatdomains() {
	my $self             = shift;
	my $perl_scalar      = shift;
	my $formatted_scalar = {};
	my $suggestions      = {};
	foreach my $domain ( keys %$perl_scalar ) {
		if ( $domain =~ /\./ && $perl_scalar->{$domain}->{status} ) {
			if ( $perl_scalar->{$domain}->{status} eq 'available' ) {
				$formatted_scalar->{$domain}->{status} = 'a';
			}
			elsif ( $perl_scalar->{$domain}->{status} eq 'regthroughothers' ) {
				$formatted_scalar->{$domain}->{status} = 'o';
			}
			else {
				$formatted_scalar->{$domain}->{status} = 's';
			}
			$formatted_scalar->{$domain}->{name} =
			  ( split( /\./, $domain, 2 ) )[0];
			$formatted_scalar->{$domain}->{tld} =
			  ( split( /\./, $domain, 2 ) )[1];

			#			$formatted_scalar->{$_}->{search}
		}
		else {
			foreach my $sdomain ( keys %{ $perl_scalar->{$domain} } ) {

				#				print Dumper $sdomain;
				foreach
				  my $stld ( keys %{ $perl_scalar->{$domain}->{$sdomain} } )
				{
					if ( $perl_scalar->{$domain}->{$sdomain}->{$stld} eq
						'available' )
					{
						$suggestions->{$sdomain}->{$stld} = 'a';
					}
					elsif ( $perl_scalar->{$domain}->{$sdomain}->{$stld} eq
						'regthroughothers' )
					{
						$suggestions->{$sdomain}->{$stld} = 'o';
					}
					else {
						$suggestions->{$sdomain}->{$stld} = 's';
					}
				}
			}
		}

	}
	return ( 'searchres', $formatted_scalar, 'suggestions', $suggestions );
}



( run in 0.445 second using v1.01-cache-2.11-cpan-df04353d9ac )