hfw/asana

A fluent library for Asana's REST API. Includes a Laravel facade.

6.0.0-beta 2024-11-05 20:24 UTC

README

A fluent PHP library for Asana's REST API

php stable unstable score downloads license

Documentation: https://hfw.github.io/asana

composer require hfw/asana:6.x-dev

For Laravel, see /src/Api/Laravel

Introduction

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.

Example: You

$me = $api->getMe();
echo $me->getUrl();

Example: Workspaces

// 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 );

Example: Projects

// 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 );

Example: Tasks

// 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){
    // ...
}

Class Diagram