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.
Add new package to composer.json
in your project directory:
composer require anycomment/php-sdk
or
{
"require":{
"anycomment/php-sdk":"^0.1.2"
}
}
Run the following command to start tests:
composer run test
Examples can be found in /examples
folder.
Notice that you need to provide your API key for each example to make it work.
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
}
Get website information.
Example:
$data = $api->getWebsite()->getInfo();
Get number of comments per requested page URL.
Example:
$data = $api->getPage()->getCommentCount('https://anycomment.io/demo');
Get profile information for given profile ID.
Example:
$data = $api->getProfile()->getInfo(1, 'oauth-token');
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 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));