A fluent PHP library for Asana's REST API
Documentation: https://hfw.github.io/asana
composer require hfw/asana:6.x-dev
For Laravel, see /src/Api/Laravel
use Helix\Asana\Api;
$api = new Api( ACCESS TOKEN );
The Api
instance is the central access point for entities, and pools entities to avoid redundant network calls and prevent object duplication.
It's also used as a library-wide factory. Subclassing Api
and overriding factory()
lets you return whatever you want for any given endpoint.
You don't need to call new
outside of instantiating the Api
class.
All library objects are injected with the Api
instance and use factory()
to give you what you want.
$me = $api->getMe();
echo $me->getUrl();
// if you're only in one workspace, then it's a safe default
$workspace = $api->getWorkspace();
// or you can set a default
$api->setWorkspace( GID );
$workspace = $api->getWorkspace();
// or you can get a specific workspace any time
$workspace = $api->getWorkspace( GID );
// create a project
$project = $workspace->newProject()
->setName('Test Project')
->setNotes('A test project.')
->setOwner($me)
->create();
echo $project->getUrl();
// get a project
$project = $api->getProject( GID );
// create a task
$task = $project->newTask()
->setAssignee($me)
->setName('Test Task')
->setNotes('A test task.')
->create();
echo $task->getUrl();
// iterate your tasks
$taskList = $me->getTaskList();
foreach ($taskList as $task){
// ...
}