wedocreatives / wrike-php-library
Wrike PHP Library, generic implementation.
Requires
- php: >=7.1,<7.3
- ext-json: *
- psr/http-message: >=1.0,<2.0
Requires (Dev)
- phpunit/phpunit: >=6.0,<8.0
README
Introduction
This is generic library for Wrike (online project management software) REST API.
This package contains general documentation for all features. This package is decoupled from unnecessary dependencies and can't be used without additional HTTP Client plugin.
- For general purpose please check full configured Wrike PHP SDK - recommended for most users.
- For Symfony Framework please check full configured Wrike bundle based on this library
- For none standard purposes please check:
- this generic Wrike PHP Library
- HTTP Client plugin based on guzzlehttp/guzzle package
- response transformer plugin based on jms/serializer package
Versions
Project status
General
Branch 'master'
Installation
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
$ composer require wedocreatives/wrike-php-library "^3.0"
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
Contribution
To try it yourself clone the repository:
git clone git@github.com:wedocreatives/wrike-php-library.git
cd wrike-php-library
and install dependencies with composer:
composer install
Run PHPUnit tests:
./vendor/bin/phpunit
Usage
All operations are immutable and stateless.
/** * 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);
Response transformers
Response can be returned in various formats according to used response transformer
ENUM's
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
Breaking Changes
V2.x due to changes in Wrike API V4
V3.x due to refactoring for PHP >=7.1
- ArrayTransformer for Client JSON response is removed, only PSR response is accepted
- Strict types for method params and responses
Reference
Internal
Full configured Wrike PHP SDK
Full configured Symfony bundle based on Wrike PHP SDK
Response transformer plugin for Wrike PHP Library
HTTP Client plugin for Wrike PHP Library
External
Official Wrike API Documentation
Package general architecture inspired by mpclarkson/freshdesk-php-library
License
This bundle is available under the MIT license.