rvdv/react-nntp

为 React 实现的 Network News Transfer Protocol (NNTP) 绑定。

dev-master / 0.1.x-dev 2014-01-10 17:56 UTC

This package is auto-updated.

Last update: 2024-08-29 03:26:13 UTC


README

Network News Transfer Protocol (NNTP) 绑定于 React。此组件基于 SocketClient 组件实现 NNTP。

Latest Stable Version Total Downloads Latest Unstable Version Build Status Coverage Status SensioLabsInsight

安装

推荐使用 composer 安装 react-nntp。

{
    "require": {
        "rvdv/react-nntp": "1.0.*@dev"
    }
}

基本用法

以下是一个简单的示例,它从 PHP 邮件列表的 'php.doc' 新组中获取前 100 篇文章。

use React\Dns\Resolver\Factory as ResolverFactory;
use React\EventLoop\Factory as EventLoopFactory;
use Rvdv\React\Nntp\Client;
use Rvdv\React\Nntp\Command\CommandInterface;
use Rvdv\React\Nntp\Response\ResponseInterface;

$loop = EventLoopFactory::create();

$dnsResolverFactory = new ResolverFactory();
$dns = $dnsResolverFactory->createCached('8.8.8.8', $loop);

$client = Client::factory($loop, $dns);

$group = null;
$format = null;

$client
    ->connect('news.php.net', 119)
    ->then(function (ResponseInterface $response) use ($client) {
        return $client->overviewFormat();
    })
    ->then(function (CommandInterface $command) use (&$format, $client) {
        $format = $command->getResult();

        return $client->group('php.doc');
    })
    ->then(function (CommandInterface $command) use (&$group, &$format, $client) {
        $group = $command->getResult();

        return $client->overview($group->getFirst() . '-' . ($group->getFirst() + 99), $format);
    })
    ->then(function (CommandInterface $command) use ($client) {
        $articles = $command->getResult();
        // Process the articles further.

        $client->stop();
    });

$client->run();

测试

要运行测试套件,您需要 PHPUnit。

$ phpunit

Vagrant

您还可以使用配置好的 Vagrant 虚拟机进行本地开发。进入 /vagrant 目录并运行以下命令;

# Resolve the Puppet dependencies through librarian-puppet.
$ gem install librarian-puppet
$ librarian-puppet install

$ vagrant up