Skip to content

Commit d4e0635

Browse files
committed
Added Functions checkDomain and domainsList
1 parent 0f864a8 commit d4e0635

File tree

5 files changed

+89
-18
lines changed

5 files changed

+89
-18
lines changed

Examples/CheckDomain.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
* Subreg - Usage Example
4+
*
5+
* @author Vítězslav Dvořák <[email protected]>
6+
* @copyright (C) 2018 Spoje.Net
7+
*/
8+
9+
namespace Subreg;
10+
11+
require_once '../vendor/autoload.php';
12+
13+
\Ease\Shared::instanced()->loadConfig('../config.json');
14+
15+
$client = new Client(\Ease\Shared::instanced()->configuration);
16+
17+
18+
$unexistentDomain = strtolower(\Ease\Sand::randomString()).'.cz';
19+
20+
$response = $client->checkDomain($unexistentDomain);
21+
22+
$existingDomain = 'spoje.net';
23+
24+
$response = $client->checkDomain($existingDomain);
25+
var_dump($response);

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ Jak to celé funguje ?
6363
Ústřední komponentou celé knihovny je Třída Client, která je schopna pomocí
6464
PHP rozšíření SoapClient komunikovat se soap.subreg.cz.
6565

66+
http://demoreg.net/en/settings/settings
67+
6668

6769
Docker
6870
------

phpunit.xml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,8 @@
88

99
<filter>
1010
<whitelist>
11-
<directory suffix=".php">src/FlexiPeeHP</directory>
11+
<directory suffix=".php">src/Subreg</directory>
1212
</whitelist>
1313
</filter>
1414

15-
<!-- logging>
16-
<log type="tap" target="build/report.tap"/>
17-
<log type="junit" target="build/report.junit.xml"/>
18-
<log type="coverage-text" target="php://stdout"/>
19-
<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
20-
<log type="coverage-clover" target="build/logs/clover.xml"/>
21-
</logging -->
2215
</phpunit>

src/Subreg/Client.php

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,27 +78,35 @@ public function __construct($config)
7878
*/
7979
public function call($command, $params = [])
8080
{
81-
$this->lastError = null;
81+
$this->lastError = null;
8282
$this->lastStatus = null;
8383
$this->lastResult = null;
8484
if ($this->token && !array_key_exists('ssid', $params)) {
8585
$params['ssid'] = $this->token;
8686
}
8787
$responseRaw = $this->soaper->__call($command, ['data' => $params]);
88-
if ($responseRaw['status'] == 'error') {
89-
90-
$this->logError($responseRaw['error']);
91-
}
92-
93-
if(isset($responseRaw['status'])){
88+
89+
if (isset($responseRaw['status'])) {
9490
$this->lastStatus = $responseRaw['status'];
91+
if ($this->lastStatus == 'error') {
92+
$this->logError($responseRaw['error']);
93+
}
94+
}
95+
96+
if (array_key_exists('data', $responseRaw)) {
97+
$this->lastResult = $responseRaw['data'];
98+
} else {
99+
$this->lastResult = $this->lastStatus;
95100
}
96-
97-
$this->lastResult = array_key_exists('data', $responseRaw) ? $responseRaw['data'] : array_key_exists('status', $responseRaw) ? $responseRaw['status'] : null ;
98-
101+
99102
return $this->lastResult;
100103
}
101104

105+
/**
106+
* log Error
107+
*
108+
* @param array $errorData
109+
*/
102110
public function logError($errorData)
103111
{
104112
$this->lastError = $errorData;
@@ -125,4 +133,30 @@ public function login()
125133
}
126134
return $result;
127135
}
136+
137+
/**
138+
* Check if domain is available or not
139+
*
140+
* @link https://subreg.cz/manual/?cmd=Check_Domain Command: Check_Domain
141+
*
142+
* @param string $domain
143+
*
144+
* @return array
145+
*/
146+
public function checkDomain($domain)
147+
{
148+
return $this->call('Check_Domain', ['domain' => $domain]);
149+
}
150+
151+
/**
152+
* Get all domains from your account
153+
*
154+
* @link https://subreg.cz/manual/?cmd=Domains_List Command: Domains_List
155+
*
156+
* @return array
157+
*/
158+
public function domainsList()
159+
{
160+
return $this->call('Domains_List');
161+
}
128162
}

tests/src/Subreg/ClientTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,21 @@ public function testLogin()
5454
{
5555
$this->object->login();
5656
}
57+
58+
/**
59+
* @covers Subreg\Client::checkDomain
60+
*/
61+
public function testCheckDomain()
62+
{
63+
return $this->object->checkDomain('spoje.net');
64+
}
65+
66+
/**
67+
* @covers Subreg\Client::domainList
68+
*/
69+
public function testDomainsList()
70+
{
71+
return $this->object->domainsList();
72+
}
73+
5774
}

0 commit comments

Comments
 (0)