From 35a5297d2f3ce5b5780fab22bfdfad0b712f3651 Mon Sep 17 00:00:00 2001 From: Aaron Huisinga Date: Thu, 24 Apr 2014 00:44:08 -0500 Subject: [PATCH 1/4] Add Renew and GetPricing methods Add a few more official Namecheap supported methods to the API. --- src/Namecheap/Api.php | 4 ++ src/Namecheap/Command/Domains/Renew.php | 53 +++++++++++++++++++++ src/Namecheap/Command/Users/GetPricing.php | 53 +++++++++++++++++++++ src/Namecheap/examples/domains.renew.php | 34 +++++++++++++ src/Namecheap/examples/users.getPricing.php | 33 +++++++++++++ 5 files changed, 177 insertions(+) create mode 100644 src/Namecheap/Command/Domains/Renew.php create mode 100644 src/Namecheap/Command/Users/GetPricing.php create mode 100644 src/Namecheap/examples/domains.renew.php create mode 100644 src/Namecheap/examples/users.getPricing.php diff --git a/src/Namecheap/Api.php b/src/Namecheap/Api.php index 5db6a24..a0c2e19 100644 --- a/src/Namecheap/Api.php +++ b/src/Namecheap/Api.php @@ -16,6 +16,7 @@ class Exception extends \Exception {} include_once 'Command/Domains/Check.php'; include_once 'Command/Domains/Create.php'; include_once 'Command/Domains/GetTldList.php'; + include_once 'Command/Domains/Renew.php'; include_once 'Command/Domains/Dns/SetDefault.php'; include_once 'Command/Domains/Dns/SetCustom.php'; include_once 'Command/Domains/Dns/GetList.php'; @@ -26,6 +27,7 @@ class Exception extends \Exception {} include_once 'Command/Domains/Ns/GetInfo.php'; include_once 'Command/Domains/Ns/Update.php'; include_once 'Command/Users/GetBalances.php'; + include_once 'Command/Users/GetPricing.php'; include_once 'Command/Users/Address/GetList.php'; class Api @@ -39,6 +41,7 @@ class Api 'domains.getContacts' => 'Namecheap\Command\Domains\GetContacts', 'domains.create' => 'Namecheap\Command\Domains\Create', 'domains.check' => 'Namecheap\Command\Domains\Check', + 'domains.renew' => 'Namecheap\Command\Domains\Renew', 'domains.getTldList' => 'Namecheap\Command\Domains\GetTldList', 'domains.dns.setDefault' => 'Namecheap\Command\Domains\Dns\SetDefault', 'domains.dns.setCustom' => 'Namecheap\Command\Domains\Dns\SetCustom', @@ -50,6 +53,7 @@ class Api 'domains.ns.getInfo' => 'Namecheap\Command\Domains\Ns\GetInfo', 'domains.ns.update' => 'Namecheap\Command\Domains\Ns\Update', 'users.getBalances' => 'Namecheap\Command\Users\GetBalances', + 'users.getPricing' => 'Namecheap\Command\Users\GetPricing', 'users.address.getList' => 'Namecheap\Command\Users\Address\GetList', 'users.address.getInfo' => 'Namecheap\Command\Users\Address\GetInfo', ); diff --git a/src/Namecheap/Command/Domains/Renew.php b/src/Namecheap/Command/Domains/Renew.php new file mode 100644 index 0000000..41be180 --- /dev/null +++ b/src/Namecheap/Command/Domains/Renew.php @@ -0,0 +1,53 @@ + null, + 'Years' => 1, + ); + } + + /** + * Process domains array + */ + protected function _postDispatch() + { + foreach ($this->_response->DomainRenewResult->attributes() as $key => $value) + { + $this->domain[$key] = (string) $value; + } + } + + /** + * Get/set method for domain list, limited to 1024 characters + * @param string|array $value + * @return mixed + */ + public function domainName($value = null) + { + if (null !== $value) + { + $this->setParam('DomainName', (string) substr($value, 0, 70)); + return $this; + } + $this->getParam('DomainName'); + } + } +} diff --git a/src/Namecheap/Command/Users/GetPricing.php b/src/Namecheap/Command/Users/GetPricing.php new file mode 100644 index 0000000..52174a1 --- /dev/null +++ b/src/Namecheap/Command/Users/GetPricing.php @@ -0,0 +1,53 @@ + 'DOMAIN', + 'ProductCategory' => null, + ); + } + + /** + * Process domains array + */ + protected function _postDispatch() + { + foreach ($this->_response->UserGetPricingResult->attributes() as $key => $value) + { + $this->data[$key] = (string) $value; + } + } + + /** + * Get/set method for domain list, limited to 1024 characters + * @param string|array $value + * @return mixed + */ + public function domainName($value = null) + { + if (null !== $value) + { + $this->setParam('DomainName', (string) substr($value, 0, 70)); + return $this; + } + $this->getParam('DomainName'); + } + } +} diff --git a/src/Namecheap/examples/domains.renew.php b/src/Namecheap/examples/domains.renew.php new file mode 100644 index 0000000..9ea7274 --- /dev/null +++ b/src/Namecheap/examples/domains.renew.php @@ -0,0 +1,34 @@ +apiUser('api-username') + ->apiKey('api-key') + ->clientIp('your-ip') + ->sandbox(true); + + $command = Namecheap\Api::factory($config, 'domains.renew'); + $command->setParams(array( + 'DomainName' => 'example1.com', + 'Years' => 1 + ))->dispatch(); +} catch (\Exception $e) { + die($e->getMessage()); +} + +if ($command->status() == 'error') { die($command->errorMessage); } +d($command); + +function d($value = array()) +{ + echo '
' . "\n";
+	print_r($value);
+	die('
' . "\n"); +} diff --git a/src/Namecheap/examples/users.getPricing.php b/src/Namecheap/examples/users.getPricing.php new file mode 100644 index 0000000..d8faf62 --- /dev/null +++ b/src/Namecheap/examples/users.getPricing.php @@ -0,0 +1,33 @@ +apiUser('api-username') + ->apiKey('api-key') + ->clientIp('your-ip') + ->sandbox(true); + + $command = Namecheap\Api::factory($config, 'users.getPricing'); + $command->setParams(array( + 'ProductType' => 'DOMAIN', + 'ProductCategory' => 'REGISTER' + ))->dispatch(); +} catch (\Exception $e) { + die($e->getMessage()); +} + +d($command); + +function d($value = array()) +{ + echo '
' . "\n";
+	print_r($value);
+	die('
' . "\n"); +} From a2d7adce01ebe3ceba33ddd44667d339ee349972 Mon Sep 17 00:00:00 2001 From: Aaron Date: Thu, 26 Jun 2014 10:01:55 -0500 Subject: [PATCH 2/4] Update docblock for domainName function $value is limited to 70 characters and can only be a string. --- src/Namecheap/Command/Domains/Renew.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Namecheap/Command/Domains/Renew.php b/src/Namecheap/Command/Domains/Renew.php index 41be180..dd00d81 100644 --- a/src/Namecheap/Command/Domains/Renew.php +++ b/src/Namecheap/Command/Domains/Renew.php @@ -36,8 +36,8 @@ protected function _postDispatch() } /** - * Get/set method for domain list, limited to 1024 characters - * @param string|array $value + * Get/set method for domain list, limited to 70 characters + * @param string $value * @return mixed */ public function domainName($value = null) From a69c10f084f782637cb6a05f7cc578f0030ba635 Mon Sep 17 00:00:00 2001 From: Aaron Date: Thu, 26 Jun 2014 10:12:20 -0500 Subject: [PATCH 3/4] Add return call for Domain Renew get method No return was stated for the getter, meaning that it wouldn't function properly. --- src/Namecheap/Command/Domains/Renew.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Namecheap/Command/Domains/Renew.php b/src/Namecheap/Command/Domains/Renew.php index dd00d81..d854c9f 100644 --- a/src/Namecheap/Command/Domains/Renew.php +++ b/src/Namecheap/Command/Domains/Renew.php @@ -47,7 +47,7 @@ public function domainName($value = null) $this->setParam('DomainName', (string) substr($value, 0, 70)); return $this; } - $this->getParam('DomainName'); + return $this->getParam('DomainName'); } } } From 62b76687ed59d38ae94868b513876a3d8f4c7cc8 Mon Sep 17 00:00:00 2001 From: Aaron Date: Thu, 26 Jun 2014 10:13:31 -0500 Subject: [PATCH 4/4] Add return call for Domain Create get method --- src/Namecheap/Command/Domains/Create.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Namecheap/Command/Domains/Create.php b/src/Namecheap/Command/Domains/Create.php index 1cef111..da702d5 100644 --- a/src/Namecheap/Command/Domains/Create.php +++ b/src/Namecheap/Command/Domains/Create.php @@ -47,7 +47,7 @@ public function domainName($value = null) $this->setParam('DomainName', (string) substr($value, 0, 70)); return $this; } - $this->getParam('DomainName'); + return $this->getParam('DomainName'); } } }