anycomment/php-sdk

There is no license information available for the latest version (0.1.2) of this package.

PHP SDK to communicate with AnyComment REST API

0.1.2 2020-09-19 11:15 UTC

This package is auto-updated.

Last update: 2024-04-19 19:03:21 UTC


README

Build Status

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