wedocreatives / wrike-php-library
Wrike PHP 库,通用实现。
v2.0.0
2019-07-03 10:24 UTC
Requires
- php: >=7.1,<7.3
- ext-json: *
- psr/http-message: >=1.0,<2.0
Requires (Dev)
- phpunit/phpunit: >=6.0,<8.0
README
简介
这是一个针对 Wrike (在线项目管理软件) REST API 的通用库。
此包包含所有功能的通用文档。此包与不必要的依赖解耦,不能在没有额外的 HTTP 客户端插件的情况下使用。
- 对于通用用途,请检查完整配置的 Wrike PHP SDK - 推荐给大多数用户。
- 对于 Symfony 框架,请检查基于此库的完整配置的 Wrike 包。
- 对于非标准用途,请检查以下内容:
- 此通用 Wrike PHP 库
- HTTP 客户端插件,基于 guzzlehttp/guzzle 包
- 响应转换插件,基于 jms/serializer 包
版本
项目状态
通用
分支 'master'
安装
打开命令行控制台,进入您的项目目录,并执行以下命令以下载此包的最新稳定版本
$ composer require wedocreatives/wrike-php-library "^3.0"
此命令要求您已全局安装 Composer,如 Composer 文档中的 安装章节 所述。
贡献
要自己尝试,请克隆存储库
git clone git@github.com:wedocreatives/wrike-php-library.git
cd wrike-php-library
并使用 composer 安装依赖项
composer install
运行 PHPUnit 测试
./vendor/bin/phpunit
使用方法
所有操作都是不可变的和无状态的。
/** * Resources access methods */ $api = ApiFactory::create(<PermanentToken>); // @see wedocreatives/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 wedocreatives/wrike-php-sdk $newApi = $api->recreateForNewAccessToken(<PermanentToken>); $responseTransformer = new RawResponseTransformer(); $newApi = $api->recreateForNewResponseTransformer($responseTransformer); $apiExceptionTransformer = new RawExceptionTransformer(); $newApi = $api->recreateForNewApiExceptionTransformer($apiExceptionTransformer);
响应转换器
响应可以以各种格式返回,具体取决于使用的响应转换器
ENUM
wedocreatives\WrikePhpLibrary\Enum\Api
- RequestMethodEnum
- RequestPathFormatEnum
- ResourceMethodEnum
- ResponseFormatEnum
namespace wedocreatives\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 的更改
V3.x 由于对 PHP >=7.1 的重构
- 移除了用于客户端 JSON 响应的 ArrayTransformer,只接受 PSR 响应
- 方法参数和响应的严格类型
参考
内部
完整配置的 Wrike PHP SDK
基于 Wrike PHP SDK 的完整配置的 Symfony 包
响应转换插件,用于 Wrike PHP 库
HTTP 客户端插件,用于 Wrike PHP 库
外部
官方 Wrike API 文档
本包的通用架构灵感来源于 mpclarkson/freshdesk-php-library
许可证
此软件包在 MIT 许可证 下提供。