zibios/wrike-php-library

此包已被废弃且不再维护。没有建议的替代包。

Wrike PHP 库,通用实现。

v1.0.0 2018-02-25 01:24 UTC

This package is auto-updated.

Last update: 2023-08-29 01:56:56 UTC


README

介绍

这是一个用于Wrike(在线项目管理软件)REST API的通用库。

此包包含所有功能的通用文档。此包与不必要的依赖解耦,无法在没有附加HTTP客户端插件的情况下使用。

版本

主版本 Wrike API PHP 兼容性 初始发布 支持
V3 V4 PHP 7.1, PHP 7.2, 待定 2018年10月 待定
V2 V4 PHP 5.5, PHP 5.6, PHP 7.0, PHP 7.1 2018年10月 支持截止于2019年10月
V1 V3 PHP 5.5, PHP 5.6, PHP 7.0, PHP 7.1 2018年2月 支持截止于2019年2月

项目状态

通用

Packagist License Packagist Downloads Packagist Version Packagist Version Libraries.io

CII Best Practices SensioLabsInsight Codacy Badge Code Climate Maintainability

分支 'master'

Scrutinizer Code Quality Scrutinizer Build Status Scrutinizer Code Coverage Travis Build Status StyleCI Coverage Status

安装

打开命令行,进入您的项目目录并执行以下命令以下载此包的最新稳定版本

$ composer require zibios/wrike-php-library "^3.0"

此命令需要您全局安装了Composer,如Composer文档中的安装章节中所述。

贡献

要亲自尝试,请克隆存储库

git clone git@github.com:zibios/wrike-php-library.git
cd wrike-php-library

并使用Composer安装依赖项

composer install

运行PHPUnit测试

./vendor/bin/phpunit

使用方法

所有操作都是不可变和状态无关的。

/**
 * Resources access methods
 */
$api = ApiFactory::create(<PermanentToken>); // @see zibios/wrike-php-sdk

$api->account()->getAll();
$api->account()->updateDefault($params);

$api->attachments()->getAll();
$api->attachments()->getAllForFolder($folderId);
$api->attachments()->getAllForTask($taskId);
$api->attachments()->getById($attachmentId);
$api->attachments()->getByIds([$attachmentId]);
$api->attachments()->update($attachmentId, $params);
$api->attachments()->uploadForFolder($attachmentId, $params);
$api->attachments()->uploadForTask($attachmentId, $params);
$api->attachments()->delete($attachmentId);
$api->attachments()->download($attachmentId);
$api->attachments()->downloadPreview($attachmentId);
$api->attachments()->getPublicUrl($attachmentId);

$api->colors()->getAll();

$api->comments()->getAll();
$api->comments()->getAllForFolder($folderId);
$api->comments()->getAllForTask($taskId);
$api->comments()->getById($commentId);
$api->comments()->getByIds([$commentId]);
$api->comments()->update($commentId, $params);
$api->comments()->createForFolder($folderId, $params);
$api->comments()->createForTask($taskId, $params);
$api->comments()->delete($commentId);

$api->contacts()->getAll();
$api->contacts()->getById($contactId);
$api->contacts()->getByIds([$contactId]);
$api->contacts()->update($contactId, $params);

$api->customFields()->getAll();
$api->customFields()->getById($customFieldId);
$api->customFields()->getByIds([$customFieldId]);
$api->customFields()->update($customFieldId, $params);
$api->customFields()->create($params);

$api->dependencies()->getAllForTask($taskId);
$api->dependencies()->getById($dependencyId);
$api->dependencies()->getByIds([$dependencyId]);
$api->dependencies()->update($dependencyId, $params);
$api->dependencies()->createForTask($taskId, $params);
$api->dependencies()->delete($dependencyId);

$api->folders()->getAll();
$api->folders()->getAllForFolder($folderId);
$api->folders()->getById($folderId);
$api->folders()->getByIds([$folderId]);
$api->folders()->update($folderId, $params);
$api->folders()->createForFolder($folderId, $params);
$api->folders()->copy($folderId, $params);
$api->folders()->delete($folderId);

$api->groups()->getAll();
$api->groups()->getById($groupId);
$api->groups()->update($groupId, $params);
$api->groups()->create($params);
$api->groups()->delete($groupId);

$api->ids()->getAll($params); // $params required

$api->invitations()->getAll();
$api->invitations()->update($invitationId, $params);
$api->invitations()->create($params);
$api->invitations()->delete($invitationId);

$api->tasks()->getAll();
$api->tasks()->getAllForFolder($folderId);
$api->tasks()->getById($taskId);
$api->tasks()->getByIds([$taskId]);
$api->tasks()->update($taskId, $params);
$api->tasks()->createForFolder($folderId, $params);
$api->tasks()->delete($taskId);

$api->timelogs()->getAll();
$api->timelogs()->getAllForFolder($folderId);
$api->timelogs()->getAllForTask($taskId);
$api->timelogs()->getAllForContact($contactId);
$api->timelogs()->getAllForTimelogCategory($timelogCategoryId);
$api->timelogs()->getById($timelogId);
$api->timelogs()->update($timelogId, $params);
$api->timelogs()->createForTask($taskId, $params);
$api->timelogs()->delete($timelogId);

$api->timelogCategories()->getAll();

$api->users()->getById($userId);
$api->users()->update($userId, $params);

$api->version()->getAll();

$api->workflows()->getAll();
$api->workflows()->update($workflowId, $params);
$api->workflows()->create($params);
/**
 * Params normalizer
 */
$params = $api->normalizeParams([
    'foo' => 'test',
    'bar' => ['test' => 'test'],
]);

// Array
// (
//     [foo] => test
//     [bar] => {"test":"test"}
// )
/**
 * Basic API usage
 */
$params = $api->normalizeParams([
    'fields' => ['metadata'],
    'metadata' => ['key' => 'importantMetadataKey'],
]);
$allContacts = $api->contacts()->getAll($params);

$params = $api->normalizeParams([
    'metadata' => [
        [
            'key' => 'metadataKey',
            'value' => 'metadataValue',
        ]
    ],
]);
$updatedContact = $api->contacts()->update($contactId, $params);
/**
 * Upload Attachment Request require two params: resource and name
 */
$params = $api->normalizeParams([
    'resource' => fopen(__FILE__, 'rb'),
    'name' => 'name.png',
]);
$updatedContact = $api->attachments()->uploadForFolder($folderId, $params);
$updatedContact = $api->attachments()->uploadForTask($taskId, $params);

/**
 * Download Attachment Requests returns none transformed Psr\Http\Message\ResponseInterface
 */
$response = $api->attachments()->download($attachmentId);
$response = $api->attachments()->downloadPreview($attachmentId);
/**
 * Advanced API usage
 *
 * $api->recreateForNew*() - returns new Api instance
 */
$api = ApiFactory::create(<PermanentToken>); // @see zibios/wrike-php-sdk

$newApi = $api->recreateForNewAccessToken(<PermanentToken>);

$responseTransformer = new RawResponseTransformer();
$newApi = $api->recreateForNewResponseTransformer($responseTransformer);

$apiExceptionTransformer = new RawExceptionTransformer();
$newApi = $api->recreateForNewApiExceptionTransformer($apiExceptionTransformer);

响应转换器

响应可以根据使用的响应转换器返回不同的格式

转换器 响应 注释
PsrResponseTransformer Psr\Http\Message\ResponseInterface PSR响应
PsrBodyTransformer Psr\Http\Message\StreamInterface PSR响应体
StringBodyTransformer JSON字符串 PSR响应体转换为JSON字符串
ArrayBodyTransformer 数组 PSR响应体转换为数组
ResponseModelTransformer ResponseModelInterface 检查 响应转换插件
ResourceModelTransformer ResourceModelInterface 检查 响应转换插件

枚举

Zibios\WrikePhpLibrary\Enum\Api

  • RequestMethodEnum
  • RequestPathFormatEnum
  • ResourceMethodEnum
  • ResponseFormatEnum

namespace Zibios\WrikePhpLibrary\Enum

  • AttachmentPreviewSizeEnum
  • AttachmentTypeEnum
  • CustomFieldAggregationEnum
  • CustomFieldCurrencyEnum
  • CustomFieldInheritanceTypeEnum
  • CustomFieldTypeEnum
  • CustomStatusColorEnum
  • DependencyRelationTypeEnum
  • InvitationStatusEnum
  • LegacyEntityTypeEnum
  • OptionalFieldEnum
  • ProjectStatusEnum
  • RescheduleModeEnum
  • ScopeEnum
  • SubscriptionTypeEnum
  • TaskDatesTypeEnum
  • TaskImportanceEnum
  • TaskStatusEnum
  • TreeScopeEnum
  • UserRoleEnum
  • UserTypeEnum
  • WeekDayEnum

重大变更

V2.x 由于 Wrike API V4 的变更

请求 替换/描述
$api->getAccountResource()->getAll(); 现在只返回一个(当前)账户
$api->getAccountResource()->getById($accountId); 已移除
$api->getAccountResource()->update($accountId, $params); $api->getAccountResource()->updateDefault($params);
$api->getAttachmentResource()->getAllForAccount($accountId); $api->getAttachmentResource()->getAll();
$api->getCommentResource()->getAllForAccount($accountId); $api->getCommentResource()->getAll();
$api->getContactResource()->getAllForAccount($accountId); $api->getContactResource()->getAll();
$api->getCustomFieldResource()->getAllForAccount($accountId); $api->getCustomFieldResource()->getAll();
$api->getCustomFieldResource()->createForAccount($accountId, $params); $api->getCustomFieldResource()->create($params);
$api->getFolderResource()->getAllForAccount($accountId); $api->getFolderResource()->getAll();
$api->getGroupResource()->getAllForAccount($accountId); $api->getGroupResource()->getAll();
$api->getGroupResource()->createForAccount($accountId, $params); $api->getGroupResource()->create($params);
$api->getInvitationResource()->getAllForAccount($accountId); $api->getInvitationResource()->getAll();
$api->getInvitationResource()->createForAccount($accountId, $params); $api->getInvitationResource()->create($params);
$api->getTaskResource()->getAllForAccount($accountId); $api->getTaskResource()->getAll();
$api->getTimelogResource()->getAllForAccount($accountId); $api->getTimelogResource()->getAll();
$api->getWorkflowResource()->getAllForAccount($accountId); $api->getWorkflowResource()->getAll();
$api->getWorkflowResource()->createForAccount($accountId, $params); $api->getWorkflowResource()->create($params);

V3.x 由于 PHP >=7.1 的重构

  • 客户端 JSON 响应的 ArrayTransformer 已移除,只接受 PSR 响应
  • 方法参数和响应的严格类型
已弃用方法 新方法
$api->getAccountResource(); $api->account();
$api->getAttachmentResource(); $api->attachments();
$api->getColorResource(); $api->colors();
$api->getCommentResource(); $api->comments();
$api->getContactResource(); $api->contacts();
$api->getCustomFieldResource(); $api->customFields();
$api->getDependencyResource(); $api->dependencies();
$api->getFolderResource(); $api->folders();
$api->getGroupResource(); $api->groups();
$api->getIdResource(); $api->ids();
$api->getInvitationResource(); $api->invitations();
$api->getTaskResource(); $api->tasks();
$api->getTimelogResource(); $api->timelogs();
$api->getTimelogCategoryResource(); $api->timelogCategories();
$api->getUserResource(); $api->users();
$api->getVersionResource(); $api->version();
$api->getWorkflowResource(); $api->workflows();

参考

内部

完全配置的 Wrike PHP SDK

完整配置的基于Wrike PHP SDK的Symfony 扩展包

为Wrike PHP库提供的响应转换插件

为Wrike PHP库提供的HTTP 客户端插件

外部

官方Wrike API 文档

PSR 命名规范

受到mpclarkson/freshdesk-php-library启发的包通用架构

许可

此扩展包在MIT 许可证下可用。