digitalkaoz/versioneye-php

VersionEye API 的 PHP CLI 工具

1.0.2 2017-05-22 08:55 UTC

README

有关 API 文档,请访问 https://www.versioneye.com/api/

Build Status Dependency Status Scrutinizer Code Quality Code Coverage SensioLabsInsight Latest Stable Version Total Downloads StyleCI

安装

安装方式有两种

  • 下载 Phar 文件(推荐)
  • 从源代码安装

下载 Phar 文件(推荐)

发布部分或 CLI 下载最新版本

$ wget https://github.com/digitalkaoz/versioneye-php/releases/download/1.0.0/versioneye.phar //or latest stable

作为全局 Composer 包安装

$ composer g require digitalkaoz/versioneye-php

现在您可以运行 ~/.composer/vendor/bin/versioneye,也许可以将此文件夹添加到您的 PATH 变量中。

从源代码安装

首先,您需要决定使用哪个 http 适配器。该库支持 php-http/httpplug 所支持的所有适配器。

$ composer require digitalkaoz/versioneye-php

## 使用方法

所有 API 端点均已实现,有关详细文档,请访问 https://www.versioneye.com/api/

编程

<?php

use Rs\VersionEye\Client;

$api = (new Client())->api('services');     // Rs\VersionEye\Api\Services
$api->ping(); //array

//other implemented APIs
$api = (new Client())->api('github');       // Rs\VersionEye\Api\Github
$api = (new Client())->api('me');           // Rs\VersionEye\Api\Me
$api = (new Client())->api('projects');     // Rs\VersionEye\Api\Projects
$api = (new Client())->api('products');     // Rs\VersionEye\Api\Products
$api = (new Client())->api('sessions');     // Rs\VersionEye\Api\Sessions
$api = (new Client())->api('users');        // Rs\VersionEye\Api\Users

CLI

以下是一些使用示例。

$ bin/versioneye services:ping
$ bin/versioneye products:search symfony

或者使用 Phar 文件。

php versioneye.phar products:search "symfony"
php versioneye.phar products:show "php" "symfony:symfony"

最后一个命令要求您正确设置了您的 API 密钥

## 配置

要全局存储您的 生成的 API 令牌,您可以在您的家目录中创建一个全局配置文件

~/.veye.rc 我们与 ruby CLI https://github.com/versioneye/veye 共享相同的配置文件

文件将如下所示

:api_key: YOUR_API_TOKEN

现在您无需在每次调用时都传递您的令牌!

## CLI 工具

要构建独立的 Phar,只需执行以下命令。

$ composer require --dev kherge/box
$ vendor/bin/box build
$ php versioneye.phar

命令

命令是通过检查 API 实现自动生成的。每个公共方法都是一个命令,每个方法参数将被转换为 InputArgument 或 InputOption。

 github
  github:delete           remove imported project.
  github:hook             GitHub Hook.
  github:import           imports project file from github.
  github:repos            lists your's github repos.
  github:show             shows the detailed information for the repository.
  github:sync             re-load github data.
 me
  me:comments             shows comments of authorized user.
  me:favorites            shows favorite packages for authorized user.
  me:notifications        shows unread notifications of authorized user.
  me:profile              shows profile of authorized user.
 products
  products:follow         follow your favorite software package.
  products:follow_status  check your following status.
  products:references     shows all references for the given package.
  products:search         search packages.
  products:show           detailed information for specific package.
  products:unfollow       unfollow given software package.
  products:versions       shows all version for the given package.
 projects
  projects:all            shows user`s projects.
  projects:create         upload project file.
  projects:delete         delete given project.
  projects:licenses       get grouped view of licences for dependencies.
  projects:merge          merge two projects together.
  projects:merge_ga       merge two projects together (only for maven projects).
  projects:show           shows the project's information.
  projects:unmerge        unmerge two projects.
  projects:update         update project with new file.
 services
  services:ping           Answers to request with basic pong.
 sessions
  sessions:close          delete current session aka log out.
  sessions:open           creates new sessions.
  sessions:show           returns session info for authorized users.
 users
  users:comments          shows user's comments.
  users:favorites         shows user's favorite packages.
  users:show              shows profile of given user_id.

常见问题解答

默认 HTTP-适配器

由于我们依赖于 php-http,我们不提供默认的 http 实现。(对于开发我们做到了)

选择以下 客户端适配器 之一,并通过 composer 安装它,然后 puli 会为您发现它,我们将使用它!

实现新的 HTTP 适配器

只需实现 Rs\VersionEye\Http\HttpClient 接口

<?php
class MyHttpClient implements HttpClient
{
    /**
     * @inheritDoc
     */
    public function request($method, $url, array $params = [])
    {
        //implement your own special http handling here
    }
}

然后将其传递给客户端

<?php 

$api = (new Client(new MyHttpClient))->api('users');

编写新的 API

只需实现 Rs\VersionEye\Api\Api 接口

<?php
namespace Rs\VersionEye\Api;

class Foo implements Api
{
    /**
     * awesome api endpoint
     */
    public function bar($bar, $bazz=1)
    {
        //implement api endpoint
    }
}

然后您必须将 API 注册到 CommandFactory 中(也许甚至可以通过搜索实现 Interface Rs\VersionEye\Api\Api 的所有实现来自动生成)

<?php 
class CommandFactory
{
    /**
     * generates Commands from all Api Methods
     *
     * @param  array     $classes
     * @return Command[]
     */
    public function generateCommands(array $classes = [])
    {
        $classes = $classes ?: [
            //...
            'Rs\VersionEye\Api\Foo'
        ];
    }
}    

请注意,每个公共方法都将作为 Command 公开。必填参数将是 InputArgument,可选参数将是 InputOption。命令描述将来自 phpdoc

因此,上述示例将生成以下 Command

foo:bar --bazz=1 bar      //awesome api endpoint

编写新的控制台输出格式化程序

默认情况下,Command 会尝试在输出类中查找相同的 API 方法(如果没有,则将数据作为简单的 print_r 输出)

Rs\VersionEye\Api\Github:sync API ----> Rs\VersionEye\Output\Github:sync 输出

因此,对于上述示例,只需创建以下类

<?php

namespace Rs\VersionEye\Output;

class Foo
{
    public function bar(OutputInterface $output, $response)
    {
        //output the $response (API Result)
    }
}

这就完了。

##测试

$ composer test