imper86 / php-asana-api
Simple and cool PHP Asana API client
Requires
- php: ^7.1
- ext-json: *
- imper86/php-oauth2-client: ^1.1
Requires (Dev)
This package is auto-updated.
Last update: 2024-10-15 05:45:31 UTC
README
Installation
Just use composer:
composer require imper86/php-asana-api
Authentication
Library has a bunch of mechanisms that allows you to forget about tokens, expirations etc. But in order to start using it you must authorize user using Oauth flow.
Create Credentials object:
$credentials = new Credentials( 'your_client_id', 'your_client_secret', 'http://localhost:8000/asana' //redirect_uri );
Create TokenRepository object:
$tokenRepository = new FileTokenRepository(__DIR__ . '/asana_tokens');
You can invent your own TokenRepository, just implement TokenRepositoryInterface. You can use your DB, Redis, or anything you want.
Create client:
$client = new Client($credentials, $tokenRepository);
Get the authorization URL, and redirect your user:
$state = 'your-random-secret-state'; header(sprintf('Location: %s', $client->auth()->authUri($state)));
After successfull authorization, user will be redirected to your redirect_uri with state and code parameters.
Verify the state and authenticate your Client:
if ($state === $_GET['state'] ?? null) { throw new Exception('CSRF?!'); } $client->authenticateWithCode($_GET['code']);
Library will use your TokenRepository to store the token, and from now on you should only care about storing user's Asana gid.
You can get that id with:
$client->getUserGid();
Usage
Just like in Auth part, create client:
$userGid = 'your-user-gid'; $client = new Client($credentials, $tokenRepository, $userGid);
From now you can use these methods on $client:
$client->organizations()->(...) $client->projects()->(...) $client->sections()->(...) $client->tags()->(...) $client->tasks()->(...) $client->teams()->(...) $client->users()->(...) $client->workspaces()->(...)
Fast example:
$projects = $client->teams()->projects()->list('teamgid');
CRUD operations naming:
- list() - GET collection
- show() - GET item
- remove() - DELETE item
- update() - PUT item
If you use IDE with typehinting such as PHPStorm, you'll easily figure it out. If not, please take a look in Resource directory
Contributing
Any help will be very appreciated.
This library is not finished, not all resources are covered. x