satun14 / redmine-api
Redmine API 客户端
v2.0
2020-12-29 06:44 UTC
Requires
- php: ^5.4 || ^7.2
- ext-curl: *
- ext-json: *
- ext-simplexml: *
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.0
- phpunit/phpunit: ^4.8.36 || ^5.4.8 || ^6.0
- dev-master
- v2.0
- v1.5.22
- v1.5.21
- v1.5.20
- v1.5.19
- v1.5.18
- v1.5.16
- v1.5.15
- v1.5.14
- v1.5.13
- v1.5.12
- v1.5.11
- v1.5.10
- v1.5.9
- v1.5.8
- v1.5.7
- v1.5.6
- v1.5.5
- v1.5.4
- v1.5.3
- v1.5.2
- v1.5.1
- v1.5.0
- v1.4
- v1.3
- 1.2.x-dev
- v1.2.1
- v1.2
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.10
- 1.0.9
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.2
- 1.0.0
- 0.4.11
- 0.4.10
- 0.4.9
- 0.4.8
- 0.4.7
- 0.4.6
- 0.4.5
- 0.4.4
- 0.4.3
- 0.4.2
- 0.4.1
- 0.4.0
- 0.3.0
- 0.2.2
- 0.2.1
- 0.2
- 0.1
- dev-cs-fixes
- dev-rector
This package is auto-updated.
Last update: 2024-09-29 05:43:04 UTC
README
Redmine API 的简单 PHP 面向对象包装器。
使用 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 以实现数据的完整远程管理
- 活动和角色的列表:https://redmine.ruby-lang.org.cn/issues/11464
- ...
解决这个问题的一个可能方法是创建额外的 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 用户可以简单地运行
$ composer require satun14/redmine-api
在项目根目录下。要使用库,请在将使用 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([ 'issue' => [ 'project_id' => 'test', 'subject' => 'some subject', 'description' => 'a long description blablabla', 'assigned_to_id' => 123, // or 'assigned_to' => 'user1' ] ]); // OR $client->issue->create([ 'ticket' => [ 'issue' => [ 'project_id' => 'test', 'tracker_id' => '1', 'status_id' => '1', 'subject' => 'subject', 'description' => 'description', ], 'contact' => [ 'email' => 'test@mail.com', 'first_name' => 'first name' ] ] ], '/helpdesk/create_ticket.xml'); $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);
谢谢!
- 感谢 Thomas Spycher 为类的第一个版本所做的贡献。
- 感谢 Thibault Duplessis aka. ornicar 为 php-github-api 库所做的贡献,这是一个非常好的灵感来源!
- 以及所有 贡献者
- 特别感谢 JanMalte 为测试覆盖率所做的令人印象深刻的贡献!:)