ajt/guzzle-asana

基于 Guzzle PHP 的 Asana API 客户端。

0.9.3 2013-11-02 10:43 UTC

This package is auto-updated.

Last update: 2024-08-28 12:46:06 UTC


README

警告:Api 密钥将被 Asana 弃用。

Asana 现在也有一个官方的 PHP API 库:https://github.com/Asana/php-asana

guzzle-asana

基于 Guzzle PHP 的 Asana API 客户端

安装

该库通过 Composer 提供,因此很容易获取。只需将其添加到您的 composer.json 文件中

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

然后运行 composer install

使用 0.9.3 作为当前稳定版本

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

功能

配置 - ApiKey

要使用 Asana API 客户端,只需使用 api 密钥实例化客户端。有关密钥的更多信息,请参阅 http://developer.asana.com/documentation/#api_keys

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

配置 - Asana Connect (OAuth2)

要使用 OAuth 使用 Asana API 客户端,您需要使用 OAuth 客户端并使用 getToken 方法。有关 Asana connect 的更多信息,请参阅 http://developer.asana.com/documentation/#AsanaConnect

有关更多信息和一个完整的身份验证示例,请参阅 examples/oauth.php。

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

使用

使用我们的 __call 方法调用命令(包括自动完成 phpDocs)

<?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";
}

或使用 getCommand 方法(在这种情况下,您需要处理 $response['data'] 数组)

<?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";
}

示例

将 apikey-dist.php 复制到 apikey.php(在根目录中)并添加您的 apikey。然后您可以执行 examples 目录中的示例。

可用示例及其包含的命令

  • 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

您可以通过查看 services.json 了解可用方法和调用它们的参数

  • ratelimit.php 展示了 backoffretry 插件的工作方式

  • oauth.php 是一个 Asana Connect 示例,需要使用 Web 服务器运行。如果您使用的是 php 5.4,则可以使用内部 Web 服务器进行测试。首先,您需要配置 oauthparams.php 文件。将 oauthparams-dist.php 文件复制到 oauthparams.php,填写详细信息(在 Asana 的 Apps 页面上注册新应用程序以获取这些详细信息)然后运行服务器。

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

欢迎贡献

发现了一个错误,请打开一个问题,最好附上调试输出和您所做的事情。修复错误?打开一个 Pull Request,我会查看。

许可

Asana API 客户端在 MIT 许可下可用。