Skip to content
This repository has been archived by the owner on Jul 4, 2024. It is now read-only.

Commit

Permalink
add domain check function which returns if a domain is availiable and…
Browse files Browse the repository at this point in the history
… the price (done during #pyhack Tokyo)
  • Loading branch information
Thomas Kuiper committed May 21, 2016
1 parent 38fde82 commit b696d18
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
14 changes: 13 additions & 1 deletion gandi/cli/commands/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import click

from gandi.cli.core.cli import cli
from gandi.cli.core.utils import output_contact_info, output_domain
from gandi.cli.core.utils import output_contact_info, output_domain, output_domain_check
from gandi.cli.core.params import pass_gandi


Expand Down Expand Up @@ -37,6 +37,18 @@ def info(gandi, resource):
return result


@cli.command()
@click.argument('resource', metavar='DOMAIN', required=False)
@pass_gandi
def check(gandi, resource):
"""Check domain availability and price."""

result = gandi.domain.check(resource)
output_domain_check(gandi, result, justify=12)

return result


@cli.command()
@click.option('--domain', default=None, help='Name of the domain.')
@click.option('--duration', default=1, prompt=True,
Expand Down
23 changes: 23 additions & 0 deletions gandi/cli/core/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,29 @@ def output_hostedcert(gandi, hcert, output_keys, justify=12):
output_sub_line(gandi, 'type', vhost['type'], 10)


def output_domain_check(gandi, domain, justify=12):
""" Helper to output a domain information."""

if (domain['available'] == 'available'):
output_line(gandi, 'Domain', domain['extension'], justify)
for domains_avail in domain['prices']:
r_phase = str(domains_avail['action']['param']['tld_phase'])
for domain_prices in domains_avail['unit_price']:
output_line (gandi, 'Phase', r_phase, justify)
output_line (gandi, 'Min Duration', str(domain_prices['min_duration']), justify)
output_line (gandi, 'Max Duration', str(domain_prices['min_duration']), justify)
output_line (gandi, 'Price', str(domain_prices['price']), justify)
output_line (gandi, 'Currency', str(domain_prices['currency']), justify)
output_line (gandi, 'Price Type', str(domain_prices['price_type']), justify)
for phases in domain['phases']:
tldphase = "Start: " + str(phases['date_start']) + " "
tldphase += "Start Gandi: " + str(phases['date_start_gandi']) + " ";
tldphase += "End: " + str(phases['date_end']);
output_line(gandi, str(phases['phase']), tldphase, justify)
else:
output_line (gandi, 'Status', str(domain['available']), justify)


def output_domain(gandi, domain, output_keys, justify=12):
""" Helper to output a domain information."""
if 'nameservers' in domain:
Expand Down
14 changes: 14 additions & 0 deletions gandi/cli/modules/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Domain(GandiModule):

""" Module to handle CLI commands.
$ gandi domain check
$ gandi domain create
$ gandi domain info
$ gandi domain list
Expand All @@ -26,6 +27,19 @@ def info(cls, fqdn):
"""Display information about a domain."""
return cls.call('domain.info', fqdn)

@classmethod
def check(cls, fqdn):
"""Check domain availability and price."""
fqdn = fqdn.lower()

result = cls.call('domain.price', [fqdn])

while result[0]['available'] == 'pending':
time.sleep(1)
result = cls.call('domain.price', [fqdn])

return (result[0])

@classmethod
def create(cls, fqdn, duration, owner, admin, tech, bill, nameserver,
background):
Expand Down
1 change: 1 addition & 0 deletions gandicli.man.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Namespaces:
* disk rollback Rollback a disk from a snapshot.
* disk update Update a disk.
* docker Manage docker instances.
* domain check Check domain availability and price.
* domain create Buy a domain.
* domain renew Renew a domain.
* domain info Display information about a domain.
Expand Down

1 comment on commit b696d18

@Simakink
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please merge commit to master ?

Please sign in to comment.