2017 © Pedro Peláez
 

library guzzle-asana

Asana API client written on top of Guzzle PHP.

image

ajt/guzzle-asana

Asana API client written on top of Guzzle PHP.

  • Monday, September 7, 2015
  • by arendjantetteroo
  • Repository
  • 2 Watchers
  • 8 Stars
  • 616 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 2 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

Asana now also has an official API library for PHP: https://github.com/Asana/php-asana, (*1)

guzzle-asana

An Asana API client based on Guzzle PHP, (*2)

Installation

The library is available through Composer, so its easy to get it. Simply add this to your composer.json file:, (*3)

"require": {
    "ajt/guzzle-asana": "dev-master"
}

And run composer install, (*4)

Use 0.9.3 for the current stable version:, (*5)

"require": {
    "ajt/guzzle-asana": "0.9.3"
}

Features

  • Complete version 1.0 API
  • API Key authentication : http://developer.asana.com/documentation/#api_keys
  • Asana Connect authentication (Oauth2) : http://developer.asana.com/documentation/#AsanaConnect
  • Supports API rate limiting by using Backoff Retry plugin

Configuration - ApiKey

To use the Asana API Client simply instantiate the client with the api key. More information on the key available at http://developer.asana.com/documentation/#api_keys, (*6)

<?php

require dirname(__FILE__).'/../vendor/autoload.php';

use AJT\Asana\AsanaClient;
$asana_token = ''; // Fill in your token here
$asana_client = AsanaClient::factory(array('api_key' => $asana_token));

// if you want to see what is happening, add debug => true to the factory call
$asana_client = AsanaClient::factory(array('api_key' => $asana_token, 'debug' => true)); 

Configuration - Asana Connect (Oauth2)

To use the Asana API Client with oauth you need to use the Oauth client and use the getToken method. More information about Asana connect is available at http://developer.asana.com/documentation/#AsanaConnect, (*7)

See the examples/oauth.php for more information and a complete authentication example., (*8)

<?php

require dirname(__FILE__).'/../vendor/autoload.php';

use AJT\Asana\AsanaOauthClient;
$asana_client = AsanaOauthClient::factory();

// if you want to see what is happening, add debug => true to the factory call
$asana_client = AsanaOauthClient::factory(array('debug' => true)); 

Usage

Invoke Commands using our __call method (auto-complete phpDocs are included), (*9)

<?php 
// Or the AsanaOauthClient
$asana_client = AsanaClient::factory(array('api_key' => $asana_token));

$workspaces = $asana_client->getWorkspaces(array());

foreach($workspaces as $workspace){
    $id = $workspace['id'];
    print $workspace['name'] . "\n";
}

Or Use the getCommand method (in this case you need to work with the $response['data'] array:, (*10)

<?php 
// Or the AsanaOauthClient
$asana_client = AsanaClient::factory(array('api_key' => $asana_token));

//Retrieve the Command from Guzzle
$command = $client->getCommand('GetWorkspaces', array());
$command->prepare();

$response = $command->execute();

$workspaces = $response['data'];

foreach($workspaces as $workspace){
    $id = $workspace['id'];
    print $workspace['name'] . "\n";
}

Examples

Copy the apikey-dist.php to apikey.php (in the root directory) and add your apikey. Afterwards you can execute the examples in the examples directory., (*11)

Available examples with their included commands: - attachments.php: createTask, uploadAttachment, getAttachmentsForTask, getAttachment - get-users.php : getUsers, getUsersWithEmail, getUser, getMe, getUsersInWorkspace - get-workspaces.php: getWorkspaces, getTasksForWorkspace - projects.php: createProject, getProject, updateProject, getProjectsInWorkspace, getProjects, deleteProjects - tasks.php: createTask, getTask, updateTask, deleteTask, createSubTask, getSubTasks, getTaskStories, getStory, addTaskComment, getProjectsForTask - tasks-and-projects.php: createTask, getProjectsInWorkspace, addProjectToTask, getProjectsForTask, removeProjectFromTask - tasks-followers.php: createTask, getTask, addTaskFollowers, removeTaskFollowers - tags.php: createTag, getTag, updateTag, getTagsInWorkspace, getTags, (*12)

You can look at the services.json for details on what methods are available and what parameters are available to call them, (*13)

  • ratelimit.php shows how the backoffretry plugin works, (*14)

  • oauth.php is an Asana Connect example and needs to be run with a webserver. If you are on php 5.4, you can just use the internal webserver to try it out. First you need to configure the oauthparams.php file. Copy the oauthparams-dist.php file to oauthparams.php, fill in the details (get them in Asana on the Apps page by registering a new app) and then run the server., (*15)

// Run this in the examples directory and you're good to go.
php -S localhost:8888

Contributions welcome

Found a bug, open an issue, preferably with the debug output and what you did. Bugfix? Open a Pull Request and i'll look into it., (*16)

License

The Asana API client is available under an MIT License., (*17)

The Versions

07/09 2015

dev-master

9999999-dev http://github.com/arendjantetteroo/guzzle-asana

Asana API client written on top of Guzzle PHP.

  Sources   Download

MIT

The Requires

 

api guzzle asana ajt

02/11 2013

0.9.3

0.9.3.0 http://github.com/arendjantetteroo/guzzle-asana

Asana API client written on top of Guzzle PHP.

  Sources   Download

MIT

The Requires

 

api guzzle asana ajt

11/05 2013

0.9.2

0.9.2.0 http://github.com/arendjantetteroo/guzzle-asana

Asana API client written on top of Guzzle PHP.

  Sources   Download

MIT

The Requires

 

api guzzle asana ajt

02/05 2013

0.9.1

0.9.1.0 http://github.com/arendjantetteroo/guzzle-asana

Asana API client written on top of Guzzle PHP.

  Sources   Download

MIT

The Requires

 

api guzzle asana ajt

16/04 2013

0.9.0

0.9.0.0 http://github.com/arendjantetteroo/guzzle-asana

Asana API client written on top of Guzzle PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

api guzzle asana ajt