PHP code example of dormilich / arin-client

1. Go to this page and download the library: Download dormilich/arin-client 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/ */

    

dormilich / arin-client example snippets


use Dormilich\WebService\ARIN\Elements\Element;
use Dormilich\WebService\ARIN\Payloads\Customer;
use Dormilich\WebService\ARIN\Payloads\Country;
use Dormilich\WebService\ARIN\Payloads\Net;
use Dormilich\WebService\ARIN\Payloads\NetBlock;

$customer = new Customer;

// adding simple values
$customer
  ->set('city', 'MyTown')
  ->set('postalCode', 12345)
;
// set values array style
$customer['city'] = 'AnyTown';

// delete values
unset($customer['city']);

// some elements know what to save
$customer['private'] = 'on';
var_dump($customer['private']->getValue()); // bool(true)
// …even if you use their alias
echo $customer['private']->getName(); // customerPrivate

// set up sub-payloads…
// …partially…
$customer['country']['code2'] = 'US';
// …or at once
$country = new Country;
$country['code3'] = 'USA';
$country['e164'] = 1;       # that’s the country calling code, btw.
$customer['country'] = $country;

// set up multi-line elements’ values…
$customer
  ->add('comment', 'line 1')
  ->add('comment', 'line 2')
;
$customer['comment'][] = 'line 3';
$customer['comment']->addValue('line 4');

// …edit them…
$customer['comment'][3] = 'LINE 4';

// …or delete selected ones
unset($customer['comment'][2]);

// element groups work similar (but you have to know what to put in!)
$net = new Net;
$net['ASN'][0] = Element::createWith('originAS', 'AS-007');

// and of course they are editable
$net['net'][0] = new NetBlock;
$net['net'][0]['start'] = '192.168.10.32';
$net['net'][0]['end']   = '192.168.10.63';

use Dormilich\WebService\ARIN\WebService\CommonRWS;
use Dormilich\WebService\ARIN\Payloads\Customer;
use Dormilich\WebService\ARIN\Payloads\Net;

$client = new MyClient(…);
$arin = new CommonRWS($client, [
    'environment' => 'live',
    'password'    => 'my-arin-password',
]);

/* set up customer */

$customer = new Customer;

# set up customer object…

// don’t ask me why customers have to be newly created for every net
$customer = $arin->create($customer, 'PARENT-NET-HANDLE');

/* set up net with that customer */

$net = new Net;

# assign network properties, among that…
$net['customer']  = $customer->getHandle();
$net['parentNet'] = 'PARENT-NET-HANDLE';

// don’t ask me why there is a need for a wrapper
$response = $arin->create($net);

// mind that a network assignment will result 
// in a ticket if the automated process failed.
try {
    $net = $response['net'];
}
catch (Exception $e) {
    $ticket = $response['ticket'];
}

// alternately fetch the first element
$net = $response[0];

if ($net instanceof Net) {
    # net successfully assigned
}