gary101/redmine-api

Redmine API 客户端

v1.5.21 2019-03-15 17:37 UTC

README

一个简单的 PHP 面向对象的 Redmine API 包装器。

使用 Redmine API

功能

  • 遵循 PSR-0 规范和编码标准:易于自动加载
  • API 入口点实现状态
  • OK 附件
  • OK 组
  • OK 自定义字段
  • OK 问题
  • OK 问题分类
  • OK 问题优先级
  • NOK 问题关系 - 只部分实现
  • OK 问题状态
  • OK 新闻
  • OK 项目
  • OK 项目成员
  • OK 查询
  • OK 角色
  • OK 时间条目
  • OK 时间条目活动
  • OK 跟踪器
  • OK 用户
  • OK 版本
  • OK 维基

待办事项

限制

Redmine 缺少一些 API 以实现数据的完全远程管理

解决此问题的可能方法是为缺少的入口点创建额外的 API。有关现有努力的例子,请参阅: https://github.com/rschobbert/redmine-miss-api

要求

  • PHP >= 5.4
  • PHP cURL 扩展
  • PHP SimpleXML 扩展
  • PHP JSON 扩展
  • PHPUnit >= 4.0(可选)以运行测试套件
  • 为您的 Redmine 项目启用“启用 REST Web 服务”(/settings/edit?tab=authentication)
  • 然后,在您的个人资料页面中获取您的 API 访问密钥:/my/account
  • 或使用您的 用户名和密码

安装

Composer

Composer 用户可以在其项目的根目录中简单运行:

$ php composer.phar require kbsali/redmine-api:~1.0

为了使用库,在将使用 Redmine 类的脚本中包含 Composer 的 vendor/autoload.php

例如,

<?php
// This file is generated by Composer
require_once 'vendor/autoload.php';
$client = new Redmine\Client('http://redmine.example.com', 'username', 'password');

手动

还可以手动安装库,无论是在本地项目中还是在全局范围内;例如,在 /usr/share/php 中。

首先,在某个位置下载并提取库。例如,以下步骤将库 v1.5.18 提取到 vendor/php-redmine-api-1.5.18 目录

$ mkdir vendor
$ wget -q https://github.com/kbsali/php-redmine-api/archive/v1.5.18.tar.gz
$ tar -xf v1.5.18.tar.gz -C vendor/
$ rm v1.5.18.tar.gz

现在,在任何将使用 Redmine 类的脚本中,包含从 php-redmine-api 目录中的 src/autoload.php 文件。例如,

<?php
// This file ships with php-redmine-api
require 'vendor/php-redmine-api-1.5.18/src/autoload.php';
$client = new Redmine\Client('http://redmine.example.com', 'username', 'password');

运行测试套件

您可以通过运行项目目录中的 vendor/bin/phpunit 来运行测试套件,以确保库可以在您的系统上正常工作。

$ vendor/bin/phpunit
PHPUnit 6.5.14 by Sebastian Bergmann and contributors.

Error:         No code coverage driver is available

...............................................................  63 / 285 ( 22%)
............................................................... 126 / 285 ( 44%)
............................................................... 189 / 285 ( 66%)
............................................................... 252 / 285 ( 88%)
.................................                               285 / 285 (100%)

Time: 107 ms, Memory: 8.00MB

OK (285 tests, 662 assertions)

php-redmine-api 客户端的基本使用

<?php

// For Composer users (this file is generated by Composer)
require_once 'vendor/autoload.php';

// Or if you've installed the library manually, use this instead.
// require 'vendor/php-redmine-api-x.y.z/src/autoload.php';

$client = new Redmine\Client('http://redmine.example.com', 'API_ACCESS_KEY');
//-- OR --
$client = new Redmine\Client('http://redmine.example.com', 'username', 'password');

$client->user->all();
$client->user->listing();

$client->issue->create([
    'project_id'  => 'test',
    'subject'     => 'some subject',
    'description' => 'a long description blablabla',
    'assigned_to_id' => 123, // or 'assigned_to' => 'user1'
]);
$client->issue->all([
    'limit' => 1000
]);

请参阅 example.php 以获取更多示例。

用户伪装

从 Redmine V2.2 开始,您可以通过 REST API 伪装用户

$client = new Redmine\Client('http://redmine.example.com', 'API_ACCESS_KEY');

// impersonate user
$client->setImpersonateUser('jsmith');

// create a time entry for jsmith
$client->time_entry->create($data);

// remove impersonation for further calls
$client->setImpersonateUser(null);

谢谢!