anycomment/php-sdk
Composer 安装命令:
composer require anycomment/php-sdk
包简介
PHP SDK to communicate with AnyComment REST API
README 文档
README
AnyComment API is an HTTP-based interface created for developers to help to work with AnyComment REST services.
The documentation can be found here.
Minimum requirement is PHP 5.6.
Installation
Add new package to composer.json in your project directory:
composer require anycomment/php-sdk
or
{
"require":{
"anycomment/php-sdk":"^0.1.2"
}
}
Tests
Run the following command to start tests:
composer run test
Examples
Examples can be found in /examples folder.
Notice that you need to provide your API key for each example to make it work.
Usage
You need to prepare a configuration class and pass your API key to constructor.
See example:
<?php require __DIR__ . '/vendor/autoload.php'; use AnyComment\Api; use AnyComment\Config; $apiKey = 'YOUR-API-KEY'; // Replace with your key $config = new Config($apiKey); $api = new Api($config);
Then call some endpoint. Every endpoint would return same mapped response envelope, such
as AnyComment\Dto\ResponseEnveloper.
Let's see in action, if we call endpoint to get website information:
var_dump($api->getWebsite()->getInfo());
This would be the output:
class AnyComment\Dto\Envelopes\ResponseEnvelope#27 (3) { public $status => string(2) "ok" public $response => class AnyComment\Dto\Website\AppInfo\AppInfo#26 (2) { public $id => int(1) public $url => string(21) "https://anycomment.io" } public $error => NULL }
API
Website
getInfo()
Get website information.
Example:
$data = $api->getWebsite()->getInfo();
Page
getCommentCount(string $url)
Get number of comments per requested page URL.
Example:
$data = $api->getPage()->getCommentCount('https://anycomment.io/demo');
Profile
getInfo(int $id, string $oauthToken)
Get profile information for given profile ID.
Example:
$data = $api->getProfile()->getInfo(1, 'oauth-token');
Comment
getList(?string $createdDate = null, ?string $pageUrl = null)
Get list of comments chronologically since given date (when provided).
You may also provide page URL for which to get comments for.
Example:
var_dump($api->getComment()->getList());
create(CommentCreateRequest $commentObject)
Create new comment with given data.
Example:
$page = new Page( 'https://anycomment.io/demo', 'Demo' ); $comment = new Comment( 1, null, 1, 'This is my comment', '127.0.0.1', date('Y-m-d H:i:s') ); $author = new Author('John Doe'); $createRequest = new CommentCreateRequest( $page, $comment, $author ); var_dump($api->getComment()->create($createRequest));
统计信息
- 总下载量: 22
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2020-07-29