Skip to content

Commit

Permalink
Merge branch 'restlessDomainHandover' into 'master'
Browse files Browse the repository at this point in the history
added domain handover and defaul contacts

See merge request transip/restapi-cli-client!157
  • Loading branch information
Jeroen Smit committed Apr 25, 2022
2 parents 5e46c7b + 0d53410 commit a42bcdf
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 8 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
CHANGELOG
=========

6.22.0
-----
* Added domain handover

6.21.0
-----
* Added default domain contacts endpoint

6.19.0
-----
* Added includes to domain:getbyname and domain:getall
Expand Down
15 changes: 8 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions src/Command/Domain/Handover.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Transip\Api\CLI\Command\Domain;

use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Transip\Api\CLI\Command\AbstractCommand;
use Transip\Api\CLI\Command\Field;

class Handover extends AbstractCommand
{
protected function configure(): void
{
$this->setName('domain:handover')
->setDescription('Handover a Domain to another TransIP Customer')
->addArgument(Field::DOMAIN_NAME, InputArgument::REQUIRED, Field::DOMAIN_NAME__DESC)
->addArgument(Field::CUSTOMER_NAME, InputArgument::REQUIRED, Field::CUSTOMER_NAME__DESC);
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$domainName = $input->getArgument(Field::DOMAIN_NAME);
$customerName = $input->getArgument(Field::CUSTOMER_NAME);

$this->getTransipApi()->domains()->handover($domainName, $customerName);

return 0;
}
}
87 changes: 87 additions & 0 deletions src/Command/DomainDefaults/UpdateContact.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

namespace Transip\Api\CLI\Command\DomainDefaults;

use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Transip\Api\CLI\Command\AbstractCommand;
use Transip\Api\CLI\Command\Field;
use Transip\Api\Library\Entity\Domain\WhoisContact;

class UpdateContact extends AbstractCommand
{
protected function configure(): void
{
$this->setName('domain-defaults:update-contact')
->setDescription('Update default WHOIS contact information for a customer')
->setHelp('Provide all the information for a type contact to update')
->addArgument(Field::DOMAIN_CONTACT_TYPE, InputArgument::REQUIRED, Field::DOMAIN_CONTACT_TYPE__DESC)
->addArgument(Field::DOMAIN_FIRST_NAME, InputArgument::REQUIRED, Field::DOMAIN_FIRST_NAME__DESC)
->addArgument(Field::DOMAIN_LAST_NAME, InputArgument::REQUIRED, Field::DOMAIN_LAST_NAME__DESC)
->addArgument(Field::DOMAIN_COMPANY_NAME, InputArgument::REQUIRED, Field::DOMAIN_COMPANY_NAME__DESC)
->addArgument(Field::DOMAIN_COMPANY_KVK, InputArgument::REQUIRED, Field::DOMAIN_COMPANY_KVK__DESC)
->addArgument(Field::DOMAIN_COMPANY_TYPE, InputArgument::REQUIRED, Field::DOMAIN_COMPANY_TYPE__DESC)
->addArgument(Field::DOMAIN_STREET, InputArgument::REQUIRED, Field::DOMAIN_STREET__DESC)
->addArgument(Field::DOMAIN_NUMBER, InputArgument::REQUIRED, Field::DOMAIN_NUMBER__DESC)
->addArgument(Field::DOMAIN_POSTAL_CODE, InputArgument::REQUIRED, Field::DOMAIN_POSTAL_CODE__DESC)
->addArgument(Field::DOMAIN_CITY, InputArgument::REQUIRED, Field::DOMAIN_CITY__DESC)
->addArgument(Field::DOMAIN_PHONE_NUMBER, InputArgument::REQUIRED, Field::DOMAIN_PHONE_NUMBER__DESC)
->addArgument(Field::DOMAIN_EMAIL, InputArgument::REQUIRED, Field::DOMAIN_EMAIL__DESC)
->addArgument(Field::DOMAIN_COUNTRY, InputArgument::REQUIRED, Field::DOMAIN_COUNTRY__DESC)
->addArgument(Field::DOMAIN_FAX_NUMBER, InputArgument::OPTIONAL, Field::DOMAIN_FAX_NUMBER__DESC . Field::OPTIONAL);
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$type = $input->getArgument(Field::DOMAIN_CONTACT_TYPE);
$firstName = $input->getArgument(Field::DOMAIN_FIRST_NAME);
$lastName = $input->getArgument(Field::DOMAIN_LAST_NAME);
$companyName = $input->getArgument(Field::DOMAIN_COMPANY_NAME);
$companyKvk = $input->getArgument(Field::DOMAIN_COMPANY_KVK);
$companyType = $input->getArgument(Field::DOMAIN_COMPANY_TYPE);
$street = $input->getArgument(Field::DOMAIN_STREET);
$number = $input->getArgument(Field::DOMAIN_NUMBER);
$postalCode = $input->getArgument(Field::DOMAIN_POSTAL_CODE);
$city = $input->getArgument(Field::DOMAIN_CITY);
$phoneNumber = $input->getArgument(Field::DOMAIN_PHONE_NUMBER);
$email = $input->getArgument(Field::DOMAIN_EMAIL);
$country = $input->getArgument(Field::DOMAIN_COUNTRY);
$faxNumber = $input->getArgument(Field::DOMAIN_FAX_NUMBER) ?? '';

$whoisContact = new WhoisContact();
$whoisContact->setType($type);
$whoisContact->setFirstName($firstName);
$whoisContact->setLastName($lastName);
$whoisContact->setCompanyName($companyName);
$whoisContact->setCompanyKvk($companyKvk);
$whoisContact->setCompanyType($companyType);
$whoisContact->setStreet($street);
$whoisContact->setNumber($number);
$whoisContact->setPostalCode($postalCode);
$whoisContact->setCity($city);
$whoisContact->setPhoneNumber($phoneNumber);
$whoisContact->setEmail($email);
$whoisContact->setCountry($country);
$whoisContact->setFaxNumber($faxNumber);

/**
* This PUT function will override all current contacts. therefore we get the current contacts first
* and override only one contact (type). this is a bit more practical when using CLI
*/

$newContacts = [];
$currentContacts = $this->getTransipApi()->defaultDomainContacts()->getAll();

foreach ($currentContacts as $currentContact) {
if ($currentContact->getType() === $type) {
$newContacts[] = $whoisContact;
} else {
$newContacts[] = $currentContact;
}
}

$this->getTransipApi()->defaultDomainContacts()->update($newContacts);
return 0;
}
}
2 changes: 1 addition & 1 deletion src/Settings/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Settings
private const CONFIG_FILE_NAME = 'cli-config.json';

public const TRANSIP_API_ENDPOINT = 'https://api.transip.nl/v6';
public const TRANSIP_CLI_VERSION = '6.19.0';
public const TRANSIP_CLI_VERSION = '6.22.0';

/**
* @var string
Expand Down

0 comments on commit a42bcdf

Please sign in to comment.