greenreader9/namesilo-php-api
Composer 安装命令:
composer require greenreader9/namesilo-php-api
包简介
PHP Wrapper for the NameSilo API
README 文档
README
PHP Wrapper for the NameSilo API
About Me
This PHP class is an API wrapper and supports all current NameSilo function as of September, 2024
(That's actually a lie, everything except for the bidAuctions call is supported)
This class was created for private use, but has been released under the MIT license for you to enjoy, because open-source is awesome
That said, it should work, but I don't gartentee it. Open a Issue or PR to fix any bugs.
Install Me
Install via Composer:
composer require greenreader9/namesilo-php-api
Or grab the /src/NameSiloAPI.php file, that works too
Use Me
- Install Me
- Initiate Me:
require_once __DIR__.'/vendor/autoload.php'; use Greenreader9\NameSiloAPI; $api = new NameSiloAPI('your-api-key', 'application-name', 'bulk', 'ote');
new NameSiloAPI($apiKey, $UserAgent, $BulkORnormal, $SandboxURL)
apiKey is your NameSilo API key. Don't share with others
UserAgent is the name of your application. Keep it short and descriptive
BulkORnormal (Optional) Set to "bulk" to use the BulkAPI, null or "normal" to use the normal API
SandboxURL (Optional) Set to false or omit for production use. Setting to any other value will set your API call to https://VALUE/namesilo.com/BULK/NORMAL
TIP: All commands can use either API type except the
registerDomainDropcommand, which requires the bulk API
TIP: Sandbox mode does not work during drop/catch times, and does not work with the
registerDomainDropcommand
- Call a function:
$apicall = $api->listDomains();
How to get function name?
Vist the API docs: https://www.namesilo.com/api-reference
Go to "Available Operations"
Find the API call you want to make and copy the part of the URL shown below
The URL shown in the docs: https://www.namesilo.com/api/getPrices?version=1&type=xml&key=12345
The part you copy: getPrices (Otherwise known as the part right after the final slash (/)
How to get the function paramaters?
Vist the API docs: https://www.namesilo.com/api-reference
Go to "Available Operations"
Find the API call you want to make and scroll to the Request Parameters section
The order in which the params are listed on the API page is the order this wrapper accept them (Easy, right?)
To omit a paramater
Two ways you can do this:
-
Just don't send it in. If the function has 1 optional param, and no required ones, just do
$api->func() -
Set it to null.
$api->func('ThisIsNeeded', null, 'ThisIsAlsoNeeded')
What Validation is done?
Pretty much none. It does check that you used the bulkAPI for registerDomainDrop, and that you are not trying to call the bidAuctions function. It also requires that you send in all paramaters that NameSilo marks as always required.
Any other mistakes are sent to the NameSilo API, and it will (hopefully) return a helpful error message. See API Errors Here -> Click Responce Codes
How to read the responce?
You get the responce as a SimpleXMLElement PHP object
Example for the checkRegisterAvailability call:
object(SimpleXMLElement)#63 (3) {
["code"]=>
string(3) "300"
["detail"]=>
string(7) "success"
["available"]=>
object(SimpleXMLElement)#61 (1) {
["domain"]=>
array(17) {
[0]=>
string(13) "example.com"
[1]=>
string(13) "example.org"
}
}
}
And the code that made that responce:
<?php require_once __DIR__.'/vendor/autoload.php'; use Greenreader9\NameSiloAPI; $api = new NameSiloAPI('xxxxxxxxxxxx', 'My Awesome Application', 'bulk'); $api_response = $api->checkRegisterAvailability('example.com,example.org'); var_dump($api->listDomains()); ?>
If the NameSilo API provides additional information as XML attributes for the call, you check the documentation, or view them like:
foreach ($api_response->available->domain as $domain){ var_dump($domain); }
Which will return something like:
object(SimpleXMLElement)#56 (2) {
["@attributes"]=>
array(4) {
["price"]=>
string(5) "11.05"
["renew"]=>
string(5) "11.05"
["premium"]=>
string(1) "0"
["duration"]=>
string(2) "10"
}
[0]=>
string(13) "example.com"
}
To access an attribute (Like "price" in our example), use can do:
foreach ($api_response->available->domain as $domain){ var_dump($domain['price']); }
which will return something like:
object(SimpleXMLElement)#62 (1) {
[0]=>
string(5) "11.05"
}
See more about the responce for the API call you are making by reading the NameSilo API docs
Get more information about your request
Most of these were used for debugging, but I left them in case you find them useful (Or if you need to debug it yourself)
// returns last HTTP code, or NULL (If no API requests have been made) $api->getHTTPCode(); // returns last HTTP body response, or NULL (If no API requests have been made) $api->getLastResult(); // returns last endpoint called, or NULL (If no API requests have been made) $api->getLastCall(); // returns last URL called, or NULL (If no API requests have been made) --WARNING:::: EXPOSES PRIVATE API KEY!!!! // NEVER USE IN PRODUCTION! $api->getLastURL();
Make a PR
Obviously there is not much here in terms of code. To make a PR, just fix the bug / add the endpoint / do what you want to do, then open a PR and type the following:
- What you did (Added the new API endpoint someEndpoint)
- Where I can verify your work, if needed (https://www.namesilo.com/api-reference#cat/some-endpoint)
- A programming joke (Not neceasry, but humor is generally a good thing)
- Anything else you feel like sharing
Get Support
I will provide support to a reasonable degree around this class. Open an Issue to get support.
If your question seems more appropriate for the NameSilo team (Like adding / changing endpoints, etc), ask them instead. I only created the wrapper, not the actual API
NameSilo support can be found here: https://www.namesilo.com/support/v2
greenreader9/namesilo-php-api 适用场景与选型建议
greenreader9/namesilo-php-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 655 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 09 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 greenreader9/namesilo-php-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 greenreader9/namesilo-php-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 655
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-09-16