Merge pull request #7845 from tkqubo/node-asana

Add node-asana
This commit is contained in:
Masahiro Wakame 2016-01-29 14:12:50 +09:00
commit 58520dba10
2 changed files with 2303 additions and 0 deletions

104
asana/asana-tests.ts Normal file
View File

@ -0,0 +1,104 @@
/// <reference path="asana.d.ts" />
/// <reference path="../request/request.d.ts" />
import * as asana from 'asana';
import * as util from 'util';
let version: string = asana.VERSION;
// https://github.com/Asana/node-asana#usage
// Usage
var client = asana.Client.create().useAccessToken('my_access_token');
client.users.me().then(function(me) {
console.log(me);
});
client = asana.Client.create({
clientId: 123,
clientSecret: 'my_client_secret',
redirectUri: 'my_redirect_uri'
});
client.useOauth({
credentials: 'my_access_token'
});
var credentials = {
// access_token: 'my_access_token',
refresh_token: 'my_refresh_token'
};
client.useOauth({
credentials: credentials
});
// https://github.com/Asana/node-asana#collections
// Collections
let tagId: string = null;
client.tasks.findByTag(tagId, { limit: 5 }).then((collection: any) => {
console.log(collection.data);
// [ .. array of up to 5 task objects .. ]
client.tasks.findByTag(tagId).then((firstPage: any) => {
console.log(firstPage.data);
collection.nextPage().then((secondPage: any) => {
console.log(secondPage.data);
});
});
});
client.tasks.findByTag(tagId).then((collection: any) => {
// Fetch up to 200 tasks, using multiple pages if necessary
collection.fetch(200).then((tasks: any) => {
console.log(tasks);
});
});
client.tasks.findByTag(tagId).then((collection: any) => {
collection.stream().on('data', (task: any) => {
console.log(task);
});
});
// https://github.com/Asana/node-asana#examples
// Examples
var Asana = asana;
// Using the API key for basic authentication. This is reasonable to get
// started with, but Oauth is more secure and provides more features.
var client = Asana.Client.create().useBasicAuth(process.env.ASANA_API_KEY);
client.users.me()
.then((user: any) => {
var userId = user.id;
// The user's "default" workspace is the first one in the list, though
// any user can have multiple workspaces so you can't always assume this
// is the one you want to work with.
var workspaceId = user.workspaces[0].id;
return client.tasks.findAll({
assignee: userId,
workspace: workspaceId,
completed_since: 'now',
opt_fields: 'id,name,assignee_status,completed'
});
})
.then((response: any) => {
// There may be more pages of data, we could stream or return a promise
// to request those here - for now, let's just return the first page
// of items.
return response.data;
})
.filter((task: any) => {
return task.assignee_status === 'today' ||
task.assignee_status === 'new';
})
.then((list: any) => {
console.log(util.inspect(list, {
colors: true,
depth: null
}));
});

2199
asana/asana.d.ts vendored Normal file

File diff suppressed because it is too large Load Diff