PHP code example of shellrent / arubapec-api

1. Go to this page and download the library: Download shellrent/arubapec-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

shellrent / arubapec-api example snippets




hellrent\Arubapec\ArubapecClient;
use Shellrent\Arubapec\Auth\Dto\TokenRequest;
use Shellrent\Arubapec\Account\Dto\AccountInfoRequest;
use Shellrent\Arubapec\AdditionalService\Dto\AdditionalServiceCreateRequest;
use Shellrent\Arubapec\Domain\Dto\DomainByNameRequest;
use Shellrent\Arubapec\Domain\Dto\DomainInfoRequest;
use Shellrent\Arubapec\Domain\Dto\DomainSearchRequest;
use Shellrent\Arubapec\Owner\Dto\OwnerContactData;
use Shellrent\Arubapec\Owner\Dto\OwnerCreateRequest;
use Shellrent\Arubapec\Owner\Dto\OwnerSearchOptions;
use Shellrent\Arubapec\Shared\Dto\OwnerSearchRequest;
use Shellrent\Arubapec\Shared\Dto\RenewalData;
use Shellrent\Arubapec\Shared\Dto\PageRequestOptions;

// Optionally customise the base URI or default headers
$client = new ArubapecClient(config: [
    'base_uri' => 'https://api.pec.aruba.it',
]);

$response = $client->auth()->token(new TokenRequest(
    '[email protected]',
    'super-secret-password'
));

if ($token = $response->getData()) {
    printf('Access token: %s', $token->getAccessToken());
    printf('Expires in: %d seconds', $token->getExpiresIn());
}

if ($response->getDatetime() !== null) {
    echo 'Response datetime: ' . $response->getDatetime()->toRfc3339String();
}

$accountInfo = $client->account()->info(new AccountInfoRequest('[email protected]'));

if ($account = $accountInfo->getData()) {
    printf('Account %s is currently %s', $account->getName(), $account->getStatus());
    printf('Renewal type: %s', $account->getRenewalData()->getType());
}

$additionalService = $client->additionalService()->create(new AdditionalServiceCreateRequest(
    '[email protected]',
    'NEWSLETTER',
    new RenewalData('T', 1)
));

if ($service = $additionalService->getData()) {
    printf('Additional service %d is %s', $service->getId(), $service->getStatus());
}

// Manage owners and reuse shared DTOs across modules
$ownerResponse = $client->owner()->create(new OwnerCreateRequest(
    'PRIVATO',
    'Mario',
    'Rossi',
    'AAABBB00A00A000A',
    contacts: new OwnerContactData(
        'Via Roma 10',
        'Arezzo',
        '52100',
        'AR',
        '[email protected]',
        '+39.000000000'
    )
));

if (($owner = $ownerResponse->getData()) !== null) {
    printf("Owner %d belongs to %s %s\n", $owner->getId(), $owner->getName(), $owner->getSurname());
}

$ownerSearch = $client->owner()->search(
    new OwnerSearchRequest(taxCode: 'AAABBB00A00A000A'),
    new OwnerSearchOptions(size: 10, sort: ['name,asc'])
);

if (($ownerPage = $ownerSearch->getData()) !== null) {
    foreach ($ownerPage->getContent() as $result) {
        printf("Found owner %s %s with tax code %s\n", $result->getName(), $result->getSurname(), $result->getTaxCode());
    }
}

// Retrieve the country catalogue used by various onboarding workflows
$countries = $client->country()->countries();

foreach ($countries->getData() as $country) {
    printf("Country #%d: %s\n", $country->getId(), $country->getName());
}

// Inspect an existing domain and verify whether it is certifiable
$domainInfo = $client->domain()->info(new DomainInfoRequest(fullName: 'pec.example.com', loadExtraData: true));

if ($domain = $domainInfo->getData()) {
    printf('Domain %s expires on %s', $domain->getFullName(), $domain->getEndDate()->toRfc3339String());
}

$canBeCertified = $client->domain()->verifyCertifiability(new DomainByNameRequest('new-domain.example.com'));

if ($canBeCertified->getData() === true) {
    echo 'The domain can be certified.';
}

// Search domains by status with pagination helpers shared across modules
$search = $client->domain()->search(
    new DomainSearchRequest(status: 'CERTIFICATO'),
    new PageRequestOptions(page: 0, size: 20, sort: ['fullName,asc'])
);

if (($page = $search->getData()) !== null) {
    foreach ($page->getContent() as $item) {
        printf("Found domain %s owned by %s %s\n", $item->getFullName(), $item->getOwner()->getName(), $item->getOwner()->getSurname());
    }
}