sandwave-io / realtimeregister-php Goto Github PK
View Code? Open in Web Editor NEWA http client for the Realtime Register REST API.
License: MIT License
A http client for the Realtime Register REST API.
License: MIT License
As described within the IsProxy page of the documentation, the API for IsProxy functions based on a telnet connection.
In this page of the documentation, a code sample is given as a possible way of implementing the API.
<?php
/**
* Realtime Register is proxy
*
* <code>
* require_once 'IsProxy.php';
*
* $ip = new IsProxy("apikey");
* $ip->check('domainname', 'com');
*
* $result = $ip->result();
* echo $result['domain'].' '.$result['result'];
*
* $ip->close();
* </code>
*/
class IsProxy {
/**
* Connection
*
* @var object
*/
var $_fp;
/**
* Construct
*
* @param string The api key
* @param string The IsProxy host, defaults to "is.yoursrs.com"
* @param int The IsProxy port, defaults to 2001
* @return void
*/
function IsProxy($apikey, $host = "is.yoursrs.com", $port = 2001) {
$this->apikey = $apikey;
$this->host = $host;
$this->port = $port;
}
/**
* Close
*
* @return void
*/
function close() {
$this->write('CLOSE');
@fclose($this->_fp);
}
/**
* Connect
*
* @return bool Connection established?
*/
function connect() {
$this->_fp = @fsockopen($this->host, $this->port, $errno, $errstr, 10);
if(!is_resource($this->_fp)) {
return false;
}
/**
* Login
*/
return $this->login();
}
/**
* Check
*
* @param string Domainname
* @param mixed TLD(s)
* @return void
*/
function check($domainname, $tlds) {
if(!is_array($tlds)) {
$tlds = (array) $tlds;
}
foreach($tlds as $tld) {
$this->write('IS '.$domainname.'.'.$tld);
}
}
/**
* Result
*
* @return array [ domain, result ]
*/
function result() {
$response = $this->read();
if(preg_match('#^([\-\w.]+)\s(available|not\savailable|invalid\sdomain|error)#', $response, $match)) {
return array('domain' => $match[1], 'result' => $match[2]);
}
return array('domain' => '-', 'result' => 'error');
}
/**
* Is connected?
*
* @return bool Connection?
*/
function is_connected() {
return is_resource($this->_fp);
}
/**
* Login
*
* @return bool Login successfull?
*/
function login() {
if(!$this->write('LOGIN '.$this->apikey)) {
return false;
}
$response = $this->read();
if(preg_match('#^400\sLogin\sfailed#', $response)) {
return false;
}
return preg_match('#^100\sLogin\sok#', $response);
}
/**
* Read
*
* @return string Response
*/
function read() {
if(!$this->is_connected()) {
$this->connect();
}
if(!$response = fgets($this->_fp, 1024)) {
return false;
}
return trim($response);
}
/**
* Write
*
* @param string Message
* @return bool Writing successfull?
*/
function write($message) {
if(!$this->is_connected()) {
$this->connect();
}
return @fputs($this->_fp, $message."\r\n");
}
}
?>
Some usage example code:
<?php
/**
* Realtime Register is proxy example usage
*/
/**
* Realtime Register is proxy api key
*/
$apikey = 'apikey';
/**
* TLDs
*/
$tlds = array('com', 'net', 'org', 'info');
/**
* Text
*/
$text = array(
'error' => 'Error',
'available' => 'Available',
'not available' => 'Not available',
'invalid domain' => 'Invalid domain',
);
$domainname = isset($_REQUEST['domainname']) ? $_REQUEST['domainname'] : null;
$tld = isset($_REQUEST['tld']) ? $_REQUEST['tld'] : null;
echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post">';
echo ' <table>';
echo ' <tr>';
echo ' <td><input type="text" name="domainname" value="'.$domainname.'" /></td>';
echo ' <td>.</td>';
echo ' <td><select name="tld"><option value="all" '.($tld == 'all' ? 'selected="selected"' : null).'>(all)</option>';
foreach($tlds as $opt) {
echo ' <option value="'.$opt.'"'.($tld == $opt ? 'selected="selected"' : null).'>'.$opt.'</option>';
}
echo ' </select></td>';
echo ' <td><input type="submit" value="Check" /></td>';
echo ' </tr>';
echo ' </table>';
echo '</form>';
if($_SERVER['REQUEST_METHOD'] == 'POST') {
if(is_null($domainname) || is_null($tld)) {
echo '<p>Ongeldige domeinnaam</p>';
}
else {
/**
* Initiate Realtime Register whois proxy
*/
require_once 'IsProxy.php';
$ip = new IsProxy($apikey);
$tld_check = $tld == 'all' ? $tlds : (array) $tld;
$tld_count = sizeof($tld_check);
$a = 0;
echo '<table>';
$ip->check($domainname, $tld_check);
while($result = $ip->result()) {
$a++;
echo '<tr><td>'.$result['domain'].'</td><td>'.$text[$result['result']].'</td></tr>';
flush();
if($a == $tld_count) {
$ip->close();
break;
}
}
echo '</table>';
}
}
?>
Documentation: https://dm.realtimeregister.com/docs/api/brands
Module:
BrandsApi
module in the Api
namespaceRealtimeRegister
class.Endpoints:
When implementing the endpoints, make sure to include links to the documentation using the @see
annotation in docblocks.
Tests:
In src/Api/DomainsApi.php
we expect a ContactCollection in the update, but this needs to be a DomainContactCollection, see:
https://dm.realtimeregister.com/docs/api/domains/update
Documentation: https://dm.realtimeregister.com/docs/api/hosts
Module:
HostsApi
module in the Api
namespaceRealtimeRegister
class.Endpoints:
When implementing the endpoints, make sure to include links to the documentation using the @see
annotation in docblocks.
Tests:
Documentation: https://dm.realtimeregister.com/docs/api/ssl
Module:
SslApi
module in the Api
namespaceRealtimeRegister
class.Endpoints:
When implementing the endpoints, make sure to include links to the documentation using the @see
annotation in docblocks.
Tests:
Documentation: https://dm.realtimeregister.com/docs/api/notifications
Module:
NotificationsApi
module in the Api
namespaceRealtimeRegister
class.Endpoints:
When implementing the endpoints, make sure to include links to the documentation using the @see
annotation in docblocks.
Tests:
I would like to see a feature when i am in a debugging state i have the option to see what payload was send to the remote api. You should be able to provide the client constructor with an optional PSR-Log service that can log this payload when a remote call is being executed.
Documentation: https://dm.realtimeregister.com/docs/api/financial
Module:
FinancialApi
module in the Api
namespaceRealtimeRegister
class.Endpoints:
When implementing the endpoints, make sure to include links to the documentation using the @see
annotation in docblocks.
Tests:
Documentation: https://dm.realtimeregister.com/docs/api/processes
Module:
ProcessesApi
module in the Api
namespaceRealtimeRegister
class.Endpoints:
When implementing the endpoints, make sure to include links to the documentation using the @see
annotation in docblocks.
Tests:
placeholder issue
As mentioned in the following thread we are missing url encoding on the provided parameters in most of the API clients:
#69 (comment)
For consistency, let's update all methods with parameters that accept strings to urlencode these values before sending it to the RTR API.
This code:
realtimeregister-php/src/Domain/Zone.php
Lines 17 to 23 in 475e386
{
"domainName": "somedomain.nl",
"registrant": "some_registrant",
"status": [
"OK"
],
"authcode": "___secret___",
"createdDate": "2018-08-03T09:49:40Z",
"updatedDate": "2023-04-19T11:46:06Z",
"expiryDate": "2023-11-03T09:49:40Z",
"ns": [
"ns1.yoursrs.com",
"ns2.yoursrs.com"
],
"autoRenew": true,
"autoRenewPeriod": 12,
"zone": {
"id": 1334243663,
"service": "BASIC",
"dnssec": false
},
"premium": false,
"gateway": false,
"privacyProtect": false,
"contacts": [
{
"role": "ADMIN",
"handle": "some_registrant"
},
{
"role": "TECH",
"handle": "some_registrant"
},
{
"role": "BILLING",
"handle": "some_registrant"
}
],
"customer": "savvii",
"registry": "Sidn"
}
Error:
PHP Warning: Undefined array key "template" in vendor/sandwave-io/realtimeregister-php/src/Domain/Zone.php on line 20
PR #66 exposed some issues with mutual exclusivity across request input. For example domains/create
has a zone input that can't be used together with ns
and keyData
.
Do other calls have this kind of mutual exclusivity too? Can we proactively prevent bad requests like these?
Documentation: https://dm.realtimeregister.com/docs/api/providers
Module:
ProvidersApi
module in the Api
namespaceRealtimeRegister
class.Endpoints:
When implementing the endpoints, make sure to include links to the documentation using the @see
annotation in docblocks.
Tests:
documentation: https://dm.realtimeregister.com/docs/api/processes/info
Module:
Endpoints:
Tests:
DomainSyntax assumes there is only a single language code but in reality its a collection of language codes.
public static function fromArray(array $json): DomainSyntax
{
return new DomainSyntax(
$json['minLength'],
$json['maxLength'],
$json['idnSupport'],
$json['allowedCharacters'] ?? null,
isset($json['languageCodes']) ? LanguageCodes::fromArray($json['languageCodes']) : null
);
}
The above code assumes the Language code is only a single item. But in reality when this element is available this is a collection of codes.
public static function fromArray(array $json): LanguageCodes
{
return new LanguageCodes(
$json['name'],
$json['allowedCharacters'] ?? null
);
}
The following endpoints are missing from the DomainsApi. These need to be implemented:
Currently, on all list endpoints, an optional ?string $search = null
is available.
The docs say that this functionality exists, the query parameter q
has to be given, this will search across all fields. However the current implementation assigns this value to search
instead, this of course, does nothing.
All list endpoints should be updated so the search value is set on the q
query parameter instead of search
.
The function parameter can stay the same and still be named $search
, as this is nice and clear for the user.
Based on the docs, this functionality is available on all list endpoints:
Thanks @tanorojas for spotting this!
Documentation: https://dm.realtimeregister.com/docs/api/templates
Module:
TemplatesApi
module in the Api
namespaceRealtimeRegister
class.Endpoints:
When implementing the endpoints, make sure to include links to the documentation using the @see
annotation in docblocks.
Tests:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.