Skip to content

Commit 8b95c57

Browse files
committed
SetAutoRenew function added
1 parent 98e7a01 commit 8b95c57

File tree

8 files changed

+70
-40
lines changed

8 files changed

+70
-40
lines changed

Examples/CheckDomain.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
require_once '../vendor/autoload.php';
1212

13-
\Ease\Shared::instanced()->loadConfig('../config.json');
13+
\Ease\Shared::instanced()->loadConfig('../tests/config.json');
1414

1515
$client = new Client(\Ease\Shared::instanced()->configuration);
1616

src/demo.php renamed to Examples/GetDomainList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
require_once '../vendor/autoload.php';
1212

13-
\Ease\Shared::instanced()->loadConfig('../config.json');
13+
\Ease\Shared::instanced()->loadConfig('../tests/config.json');
1414

1515
$client = new Client(\Ease\Shared::instanced()->configuration);
1616

Examples/GetPriceList.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010

1111
require_once '../vendor/autoload.php';
1212

13-
\Ease\Shared::instanced()->loadConfig('../config.json');
13+
\Ease\Shared::instanced()->loadConfig('../tests/config.json');
1414

1515
$client = new Client(\Ease\Shared::instanced()->configuration);
1616

1717

18-
print_r($client->getPricelist('KONCOVA'));
18+
print_r($client->pricelist('KONCOVA'));
1919

2020
//print_r($client->pricelist());
2121

Examples/RegisterDomain.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
require_once '../vendor/autoload.php';
1212

13-
\Ease\Shared::instanced()->loadConfig('../config.json');
13+
\Ease\Shared::instanced()->loadConfig('../tests/config.json');
1414

1515
$client = new Client(\Ease\Shared::instanced()->configuration);
1616

config.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,10 @@
44
"location": "https://ote-soap.subreg.cz/cmd.php",
55
"uri": "https://ote-soap.subreg.cz/soap",
66
"login": "php-subreg",
7-
"password": "661a2725fb"
7+
"password": "661a2725fb",
8+
9+
"Xlocation": "https://soap.subreg.cz/cmd.php",
10+
"Xuri": "https://soap.subreg.cz/soap",
11+
"Xlogin": "spojenetapi#spoje.net",
12+
"Xpassword": "KfbBPb?Uk6Q@%uca"
813
}

src/Subreg/Client.php

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22
/**
3-
* Subreg - Usage Example
3+
* Subreg - Client Class
44
*
55
* @author Vítězslav Dvořák <[email protected]>
6-
* @copyright (C) 2018 Spoje.Net
6+
* @copyright (C) 2018-2019 Spoje.Net
77
*/
88

99
namespace Subreg;
@@ -84,8 +84,8 @@ public function __construct($config)
8484
public function logBanner($additions = null)
8585
{
8686
return $this->addStatusMessage('API '.str_replace('://',
87-
'://'.$this->config['login'].'@', $this->config['uri']).' php-subreg v'.self::$libVersion.' EasePHP Framework v'.\Ease\Atom::$frameworkVersion.' '.$additions,
88-
'debug');
87+
'://'.$this->config['login'].'@', $this->config['uri']).' php-subreg v'.self::$libVersion.' EasePHP Framework v'.\Ease\Atom::$frameworkVersion.' '.$additions,
88+
'debug');
8989
}
9090

9191
/**
@@ -96,7 +96,7 @@ public function logBanner($additions = null)
9696
*
9797
* @return array
9898
*/
99-
public function call($command, $params = [])
99+
public function call(string $command, array $params = [])
100100
{
101101
$this->lastError = null;
102102
$this->lastStatus = null;
@@ -243,44 +243,47 @@ public function domainsList()
243243
}
244244

245245
/**
246-
* Get pricelist from your account
246+
* Get pricelist from your account
247247
*
248248
* @link https://subreg.cz/manual/?cmd=Pricelist Command: Pricelist
249249
*
250-
* @return array
250+
* @return array pricelist details
251251
*/
252252
public function pricelist()
253253
{
254254
return $this->call('Pricelist');
255255
}
256-
256+
257257
/**
258-
* Get specified pricelist from your account
258+
* Renew a existing domain from your account
259259
*
260-
* @link https://subreg.cz/manual/?cmd=Get_Pricelist Command: Get_Pricelist
260+
* @link https://subreg.cz/manual/?cmd=Renew_Domain Command: Renew_Domain
261261
*
262-
* @param string requested pricelist name
262+
* @param string $domain name
263+
* @param int $years
263264
*
264-
* @return array
265+
* @return string|array OK or Result array
265266
*/
266-
public function getPricelist($pricelist)
267+
public function renewDomain(string $domain, int $years = 1)
267268
{
268-
return $this->call('Get_Pricelist', ['pricelist'=>$pricelist]);
269+
return $this->call('Make_Order',
270+
['order' => ['domain' => $domain, 'params' => ['period' => $years],
271+
'type' => 'Renew_Domain']]);
269272
}
270-
273+
271274
/**
275+
* Set autorenew policy for your domain.
272276
*
273-
* @link https://subreg.cz/manual/?cmd=Renew_Domain Command: Renew_Domain
277+
* @link https://subreg.cz/manual/?cmd=Set_Autorenew Command: Set_Autorenew
274278
*
275-
* @param string $domain name
276-
* @param int $years
279+
* @param string $domain
280+
* @param string $renew only EXPIRE, AUTORENEW or RENEWONCE
277281
*
278-
* @return type
282+
* @return string|array OK or Result array
279283
*/
280-
public function renewDomain(string $domain, int $years = 1)
284+
public function setAutorenew(string $domain, string $renew)
281285
{
282-
return $this->call('Make_Order', ['order' => ['domain' => $domain, 'params' => ['period' => $years], 'type' => 'Renew_Domain']] );
286+
return $this->call('Set_Autorenew',
287+
['domain' => $domain, 'autorenew' => $renew]);
283288
}
284-
285-
286289
}

tests/config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"EASE_APPNAME": "PHP Subreg",
3+
"EASE_LOGGER": "syslog|console",
4+
"location": "https://ote-soap.subreg.cz/cmd.php",
5+
"uri": "https://ote-soap.subreg.cz/soap",
6+
"login": "php-subreg",
7+
"password": "661a2725fb"
8+
}

tests/src/Subreg/ClientTest.php

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,23 @@ class ClientTest extends \Test\Ease\MoleculeTest
1212
*/
1313
protected $object;
1414

15+
/**
16+
* Currently registered domains
17+
* @var array
18+
*/
19+
public $testDomains = [];
20+
1521
/**
1622
* Sets up the fixture, for example, opens a network connection.
1723
* This method is called before a test is executed.
1824
*/
1925
protected function setUp(): void
2026
{
2127
$this->object = new \Subreg\Client(\Ease\Shared::instanced()->configuration);
28+
$domainsRaw = $this->object->call('Domains_List');
29+
if (array_key_exists('domains', $domainsRaw)) {
30+
$this->testDomains = $domainsRaw['domains'];
31+
}
2232
}
2333

2434
/**
@@ -69,6 +79,9 @@ public function testCall()
6979
], $fail);
7080
$success = $this->object->call('Get_Credit');
7181
$this->arrayHasKey(array_key_exists('credit', $success));
82+
83+
$success = $this->object->call('In_Subreg',
84+
['domain' => 'php-subreg.cz']);
7285
}
7386

7487
/**
@@ -119,15 +132,6 @@ public function testPricelist()
119132
$this->assertTrue(array_key_exists('cz', $pricelist));
120133
}
121134

122-
/**
123-
* @covers Subreg\Client::getPricelist
124-
*/
125-
public function testGetPricelist()
126-
{
127-
$pricelist = $this->object->getPricelist('???');
128-
$this->assertTrue(array_key_exists('cz', $pricelist));
129-
}
130-
131135
/**
132136
* @covers Subreg\Client::registerDomain
133137
*/
@@ -138,7 +142,7 @@ public function testRegisterDomain()
138142
$nsHosts = array("ns.spoje.net", "ns2.spoje.net");
139143

140144
$result = $this->object->registerDomain($unexistentDomain, 'G-000001',
141-
'G-000001', 'G-000001', 'ukulele', $nsHosts);
145+
'G-000001', 'G-000001', 'ukulele', $nsHosts, 'NSS:ARA-LABS:1');
142146

143147
$this->assertTrue(array_key_exists('orderid', $result));
144148
}
@@ -148,6 +152,16 @@ public function testRegisterDomain()
148152
*/
149153
public function testRenewDomain()
150154
{
151-
$this->assertArrayHasKey('orderid',$this->object->renewDomain('vitexsoftware.cz',1));
155+
$this->assertNotEmpty($this->object->renewDomain('php-subreg.cz', 1));
156+
}
157+
158+
/**
159+
* @covers Subreg\Client::setAutoRenew
160+
*/
161+
public function testSetAutoRenew()
162+
{
163+
$domain = current($this->testDomains);
164+
$this->assertEquals('ok',
165+
$this->object->setAutoRenew($domain['name'], 'RENEWONCE'));
152166
}
153167
}

0 commit comments

Comments
 (0)