Added Supplier Domain importing - using dreamscape API

This commit is contained in:
Deon George
2022-08-10 15:18:56 +10:00
parent 53c665787e
commit e4c1305da5
8 changed files with 268 additions and 45 deletions

View File

@@ -165,6 +165,16 @@ class Supplier extends Model
return $this->api_class() && (collect(['api_key','api_secret'])->diff($this->detail->connections->keys())->count() === 0);
}
/**
* If this supplier has a domain registrar, return it.
*
* @return DomainRegistrar|null
*/
public function registrar(): ?DomainRegistrar
{
return ($x=config('services.supplier.'.strtolower($this->name).'.registrar')) ? DomainRegistrar::where('name',$x)->single() : NULL;
}
/**
* Return the traffic records, that were not matched to a service.
*

View File

@@ -2,6 +2,8 @@
namespace App\Models\Supplier;
use Illuminate\Support\Collection;
use App\Interfaces\SupplierItem;
use App\Models\Product\Domain as ProductDomain;
use App\Models\TLD;
@@ -29,6 +31,22 @@ final class Domain extends Type implements SupplierItem
return $this->hasMany(ProductDomain::class,'supplier_item_id','id');
}
/* STATIC */
/**
* Determine the owner of the name servers used for the domain
*
*/
public static function nameserver_name(Collection $nameservers): string
{
foreach (config('nameservers') as $key => $ns) {
if ($nameservers->diff($ns)->count() < count($ns))
return $key;
}
return 'custom';
}
/* RELATIONS */
public function tld()

View File

@@ -3,15 +3,65 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
use App\Models\Service\Domain;
class TLD extends Model
{
protected $table = 'tlds';
/* RELATIONS */
public function domains()
{
return $this->hasMany(Domain::class,'tld_id');
}
/* STATIC */
/**
* Given a domain name, return the TLD component
*
* @param string $domainname
* @return TLD|null
*/
public static function domaintld(string $domainname): ?TLD
{
$tld = NULL;
foreach (self::get() as $o) {
// Find the most specific match
if (preg_match('/'.$o->name.'$/i',$domainname) && (! $tld || (strlen($o->name) > strlen($tld->name))))
$tld = $o;
}
return $tld;
}
/* ATTRIBUTES */
public function getNameAttribute($value): string
{
return strtoupper($value);
}
/* METHOD */
/**
* Given a domain name, return the domain part
*
* @param string $domainname
* @return string|null
*/
public function domain_part(string $domainname): ?string
{
$domainname = strtoupper($domainname);
// Quick check that this domain is part of this model
if (! Str::endsWith($domainname,'.'.$this->name))
return NULL;
return Str::replaceLast('.'.$this->name,'',$domainname);
}
}