anycomment/php-sdk

此包的最新版本(0.1.2)没有可用的许可证信息。

用于与AnyComment REST API通信的PHP SDK

0.1.2 2020-09-19 11:15 UTC

This package is auto-updated.

Last update: 2024-09-19 20:03:30 UTC


README

Build Status

AnyComment API是一个基于HTTP的接口,专为开发者创建,以帮助他们与AnyComment REST服务一起工作。

文档可以在这里找到。

最低要求是PHP 5.6。

安装

新包添加到您的项目目录中的composer.json

composer require anycomment/php-sdk

或者

{
  "require":{
    "anycomment/php-sdk":"^0.1.2"
  }
}

测试

运行以下命令开始测试

composer run test

示例

示例可以在/examples文件夹中找到。

请注意,您需要为每个示例提供您的API密钥才能使其正常工作。

使用方法

您需要准备一个配置类并将您的API密钥传递给构造函数。

请看示例

<?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);

然后调用某些端点。每个端点都会返回相同的映射响应封装,例如AnyComment\Dto\ResponseEnveloper

让我们看看实际操作,如果我们调用获取网站信息的端点

var_dump($api->getWebsite()->getInfo());

这将输出

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

网站

getInfo()

获取网站信息。

示例

$data = $api->getWebsite()->getInfo();

页面

getCommentCount(string $url)

获取请求的页面URL的评论数量。

示例

$data = $api->getPage()->getCommentCount('https://anycomment.io/demo');

个人资料

getInfo(int $id, string $oauthToken)

获取给定个人资料ID的个人资料信息。

示例

$data = $api->getProfile()->getInfo(1, 'oauth-token');

评论

getList(?string $createdDate = null, ?string $pageUrl = null)

获取从给定日期(如果有)以来的评论列表。

您还可以提供要获取评论的页面URL。

示例

var_dump($api->getComment()->getList());

create(CommentCreateRequest $commentObject)

使用给定数据创建新的评论。

示例

$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));