Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply fixes from StyleCI #1

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/Command/Domain.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php

namespace MadeITBelgium\Domainbox\Command;

use MadeITBelgium\Domainbox\Response\DomainAvailable;

/**
* Domainbox API.
*
Expand All @@ -18,7 +20,7 @@ class Domain

/**
* Construct Domainbox.
*
*
* @param $reseller
* @param $username
* @param $password
Expand All @@ -28,14 +30,14 @@ public function __construct($domainbox)
{
$this->domainbox = $domainbox;
}
public function checkDomainAvailability($domainname, $launchPhase = "GA")

public function checkDomainAvailability($domainname, $launchPhase = 'GA')
{
$response = $this->domainbox->call('CheckDomainAvailability', [
'DomainName' => $domainname,
'LaunchPhase' => $launchPhase
'DomainName' => $domainname,
'LaunchPhase' => $launchPhase,
]);

return new DomainAvailable($response);
}
}
}
162 changes: 80 additions & 82 deletions src/Domainbox.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace MadeITBelgium\Domainbox;

use GuzzleHttp\Client;
Expand All @@ -19,12 +20,12 @@ class Domainbox
private $username;
private $password;
private $sandbox;

private $client;

/**
* Construct Domainbox.
*
*
* @param $reseller
* @param $username
* @param $password
Expand All @@ -38,121 +39,118 @@ public function __construct($reseller, $username, $password, $sandbox)
$this->sandbox = $sandbox;
$this->client = new Client();
}

public function setClient($client)
{
$this->client = $client;
}

/**
* Execute Domainbox call.
*
*
* @param $endpoint
* @param $parameters
*/
public function call($endPoint, $parameters)
{
$url = "https://json.domainbox.net";
if($this->sandbox) {
$url = "https://json-sandbox.domainbox.net";
$url = 'https://json.domainbox.net';
if ($this->sandbox) {
$url = 'https://json-sandbox.domainbox.net';
}
$url .= "/" . $endPoint;
$url .= '/'.$endPoint;

$response = $this->client->post($url, [
'json' => [
'AuthenticationParameters' => [
'Reseller' => $this->reseller,
'Username' => $this->username,
'Password' => $this->password,
],
'CommandParameters' => $parameters]
],
'CommandParameters' => $parameters, ],
]);

if ($response->getStatusCode() == 200) {
$output = json_decode($response->getBody(), true);
}
else {
} else {
throw Exception();
}

$this->checkResultCode($output);

return $output;
}

private function checkResultCode($output)
{
if(!isset($output['d']['ResultCode']))
{
if (!isset($output['d']['ResultCode'])) {
throw Exception('Wrong output.');
}

switch($output['d']['ResultCode'])
{

switch ($output['d']['ResultCode']) {
//Command Successful
case 100: return true; break; //Command Successful
case 101; return true; break; //Application Submitted
case 102; return true; break; //Queued
case 104; return true; break; //Pending Restore
case 110; return true; break; //But Apply Lock Failed
case 121; return true; break; //But Part Failure
case 201; throw Exception('Authentication Failure'); break; //Authentication Failure
case 210; throw Exception('Part Failure'); break; //Part Failure (Part of the command failed)
case 215; throw Exception('Timeout'); break; //Timeout
case 220; throw Exception('Billing Failure - Insufficient Funds'); break; //Billing Failure - Insufficient Funds
case 230; throw Exception('Command Unavailable'); break; //Command Unavailable
case 240; throw Exception('Required Parameter Missing'); break; //Required Parameter Missing
case 250; throw Exception('TLD Not Supported'); break; //TLD Not Supported
case 260; throw Exception('Invalid Parameter'); break; //Invalid Parameter
case 261; throw Exception('IDN Not Supported'); break; //IDN Not Supported
case 262; throw Exception('Invalid Contacts'); break; //Invalid Contacts
case 263; throw Exception('Invalid Contacts Proxy Available'); break; //Invalid Contacts Proxy Available
case 270; throw Exception('Transfer Unavailable'); break; //Transfer Unavailable
case 275; throw Exception('DomainExpired'); break; //DomainExpired
case 276; throw Exception('DomainPendingSync'); break; //DomainPendingSync
case 277; throw Exception('DomainRenewable'); break; //DomainRenewable
case 278; throw Exception('DomainPendingPremiumAction'); break; //DomainPendingPremiumAction
case 280; throw Exception('Domain Locked'); break; //Domain Locked
case 285; throw Exception('Premium Domain Not Listed'); break; //Premium Domain Not Listed
case 286; throw Exception('Premium Domain Already Listed'); break; //Premium Domain Already Listed
case 287; throw Exception('Premium Domain Unavailable'); break; //Premium Domain Unavailable
case 290; throw Exception('Domain Exists'); break; //Domain Exists
case 291; throw Exception('Nameserver Exists'); break; //Nameserver Exists
case 292; throw Exception('Parameter Incompatible'); break; //Parameter Incompatible
case 293; throw Exception('Transfer Incorrect Status'); break; //Transfer Incorrect Status
case 294; throw Exception('Tel Object Incorrect Status'); break; //Tel Object Incorrect Status
case 295; throw Exception('Domain Not Found'); break; //Domain Not Found
case 296; throw Exception('Nameserver Not Found'); break; //Nameserver Not Found
case 297; throw Exception('Transfer Not Found'); break; //Transfer Not Found
case 298; throw Exception('IP Address Error'); break; //IP Address Error
case 301; throw Exception('SSL Product Type Not Supported'); break; //SSL Product Type Not Supported
case 302; throw Exception('SSL Order Not Found'); break; //SSL Order Not Found
case 303; throw Exception('SSL Order Incorrect Status'); break; //SSL Order Incorrect Status
case 305; throw Exception('Email Type Not Supported'); break; //Email Type Not Supported
case 306; throw Exception('Email Not Found'); break; //Email Not Found
case 307; throw Exception('Email Incorrect'); break; //Email Incorrect
case 308; throw Exception('Email Exists'); break; //Email Exists
case 309; throw Exception('DNS Zone/Record Not Found'); break; //DNS Zone/Record Not Found
case 310; throw Exception('DNS Zone/Record Incorrect'); break; //DNS Zone/Record Incorrect
case 311; throw Exception('DNS Zone/Record Exists'); break; //DNS Zone/Record Exists
case 312; throw Exception('DNS Not Supported'); break; //DNS Not Supported
case 320; throw Exception('Transition Not Found'); break; //Transition Not Found
case 321; throw Exception('Transition Incorrect Status'); break; //Transition Incorrect Status
case 322; throw Exception('Contact Not Found'); break; //Contact Not Found
case 331; throw Exception('Queue Message Not Found'); break; //Queue Message Not Found
case 361; throw Exception('Trademark Not Found'); break; //Trademark Not Found
case 391; throw Exception('PublishingTypeNotSupported'); break; //PublishingTypeNotSupported
case 392; throw Exception('PublishingDomainExists'); break; //PublishingDomainExists
case 460; throw Exception('Registry System Unavailable'); break; //Registry System Unavailable
case 461; throw Exception('SSL System Unavailable'); break; //SSL System Unavailable
case 462; throw Exception('Email System Unavailable'); break; //Email System Unavailable
case 463; throw Exception('DNS System Unavailable'); break; //DNS System Unavailable
case 465; throw Exception('PublishingSystemUnavailable'); break; //PublishingSystemUnavailable
case 500; throw Exception('System Error'); break; //System Error
case 101: return true; break; //Application Submitted
case 102: return true; break; //Queued
case 104: return true; break; //Pending Restore
case 110: return true; break; //But Apply Lock Failed
case 121: return true; break; //But Part Failure

case 201: throw Exception('Authentication Failure'); break; //Authentication Failure
case 210: throw Exception('Part Failure'); break; //Part Failure (Part of the command failed)
case 215: throw Exception('Timeout'); break; //Timeout
case 220: throw Exception('Billing Failure - Insufficient Funds'); break; //Billing Failure - Insufficient Funds
case 230: throw Exception('Command Unavailable'); break; //Command Unavailable
case 240: throw Exception('Required Parameter Missing'); break; //Required Parameter Missing
case 250: throw Exception('TLD Not Supported'); break; //TLD Not Supported
case 260: throw Exception('Invalid Parameter'); break; //Invalid Parameter
case 261: throw Exception('IDN Not Supported'); break; //IDN Not Supported
case 262: throw Exception('Invalid Contacts'); break; //Invalid Contacts
case 263: throw Exception('Invalid Contacts Proxy Available'); break; //Invalid Contacts Proxy Available
case 270: throw Exception('Transfer Unavailable'); break; //Transfer Unavailable
case 275: throw Exception('DomainExpired'); break; //DomainExpired
case 276: throw Exception('DomainPendingSync'); break; //DomainPendingSync
case 277: throw Exception('DomainRenewable'); break; //DomainRenewable
case 278: throw Exception('DomainPendingPremiumAction'); break; //DomainPendingPremiumAction
case 280: throw Exception('Domain Locked'); break; //Domain Locked
case 285: throw Exception('Premium Domain Not Listed'); break; //Premium Domain Not Listed
case 286: throw Exception('Premium Domain Already Listed'); break; //Premium Domain Already Listed
case 287: throw Exception('Premium Domain Unavailable'); break; //Premium Domain Unavailable
case 290: throw Exception('Domain Exists'); break; //Domain Exists
case 291: throw Exception('Nameserver Exists'); break; //Nameserver Exists
case 292: throw Exception('Parameter Incompatible'); break; //Parameter Incompatible
case 293: throw Exception('Transfer Incorrect Status'); break; //Transfer Incorrect Status
case 294: throw Exception('Tel Object Incorrect Status'); break; //Tel Object Incorrect Status
case 295: throw Exception('Domain Not Found'); break; //Domain Not Found
case 296: throw Exception('Nameserver Not Found'); break; //Nameserver Not Found
case 297: throw Exception('Transfer Not Found'); break; //Transfer Not Found
case 298: throw Exception('IP Address Error'); break; //IP Address Error
case 301: throw Exception('SSL Product Type Not Supported'); break; //SSL Product Type Not Supported
case 302: throw Exception('SSL Order Not Found'); break; //SSL Order Not Found
case 303: throw Exception('SSL Order Incorrect Status'); break; //SSL Order Incorrect Status
case 305: throw Exception('Email Type Not Supported'); break; //Email Type Not Supported
case 306: throw Exception('Email Not Found'); break; //Email Not Found
case 307: throw Exception('Email Incorrect'); break; //Email Incorrect
case 308: throw Exception('Email Exists'); break; //Email Exists
case 309: throw Exception('DNS Zone/Record Not Found'); break; //DNS Zone/Record Not Found
case 310: throw Exception('DNS Zone/Record Incorrect'); break; //DNS Zone/Record Incorrect
case 311: throw Exception('DNS Zone/Record Exists'); break; //DNS Zone/Record Exists
case 312: throw Exception('DNS Not Supported'); break; //DNS Not Supported
case 320: throw Exception('Transition Not Found'); break; //Transition Not Found
case 321: throw Exception('Transition Incorrect Status'); break; //Transition Incorrect Status
case 322: throw Exception('Contact Not Found'); break; //Contact Not Found
case 331: throw Exception('Queue Message Not Found'); break; //Queue Message Not Found
case 361: throw Exception('Trademark Not Found'); break; //Trademark Not Found
case 391: throw Exception('PublishingTypeNotSupported'); break; //PublishingTypeNotSupported
case 392: throw Exception('PublishingDomainExists'); break; //PublishingDomainExists
case 460: throw Exception('Registry System Unavailable'); break; //Registry System Unavailable
case 461: throw Exception('SSL System Unavailable'); break; //SSL System Unavailable
case 462: throw Exception('Email System Unavailable'); break; //Email System Unavailable
case 463: throw Exception('DNS System Unavailable'); break; //DNS System Unavailable
case 465: throw Exception('PublishingSystemUnavailable'); break; //PublishingSystemUnavailable
case 500: throw Exception('System Error'); break; //System Error
}
}

public function domain()
{
return new Command\Domain($this);
Expand Down
2 changes: 1 addition & 1 deletion src/DomainboxServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class DomainboxServiceProvider extends ServiceProvider
public function boot()
{
$this->publishes([
__DIR__ . '/config/domainbox.php' => config_path('domainbox.php'),
__DIR__.'/config/domainbox.php' => config_path('domainbox.php'),
]);
}

Expand Down
39 changes: 23 additions & 16 deletions src/Response/DomainAvailable.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace MadeITBelgium\Domainbox\Response;

/**
Expand All @@ -22,43 +23,49 @@ class DomainAvailable
const AvailableRegistryTimeout = 9;
const UnavailableRegistryTimeout = 9;
const AvailableWithProvidedDomainId = 11;

private $status;
private $available;
private $launchPhase;
private $dropDate;
private $backOrderAvailable;

function __construct($data) {

public function __construct($data)
{
$constants = array_flip((new \ReflectionClass(__CLASS__))->getConstants());
$this->status = $constants[$data['d']['AvailabilityStatus']];

$this->available = false;
if(in_array($this->status, ['Available', 'AvailableOfflineLookup', 'AvailableRegistryTimeout', 'AvailableWithProvidedDomainId'])) {
if (in_array($this->status, ['Available', 'AvailableOfflineLookup', 'AvailableRegistryTimeout', 'AvailableWithProvidedDomainId'])) {
$this->available = true;
}
$this->launchPhase = $data['d']['LaunchPhase'];
$this->dropDate = $data['d']['DropDate'];
$this->backOrderAvailable = $data['d']['BackOrderAvailable'];
}

public function getStatus() {

public function getStatus()
{
return $this->status;
}

public function isAvailable() {

public function isAvailable()
{
return $this->available;
}

public function getLauchPhase() {

public function getLauchPhase()
{
return $this->launchPhase;
}

public function getDropDate() {

public function getDropDate()
{
return $this->dropDate;
}

public function canBackOrder() {

public function canBackOrder()
{
return $this->backOrderAvailable;
}
}
}
5 changes: 3 additions & 2 deletions src/config/domainbox.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

return [
'reseller' => env('DOMAINBOX_RESELLER'),
'username' => env('DOMAINBOX_USERNAME'),
'password' => env('DOMAINBOX_PASSWORD'),

'sandbox' => env('DOMAINBOX_SANDBOX', false),
];
];
Loading