Skip to content
This repository has been archived by the owner on Sep 20, 2019. It is now read-only.

cdaringe/asana-cache-local

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Codeship Status for cdaringe/asana-cache-local

asana-cache-local

cache all tasks within an asana workspace, onto your local machine. caches only tasks that have been assigned. tasks are all stored in a single NoSQL store. cache.refresh() uses the asana incrimental API, and only pulls down updates on tasks since they have last been modified, or new tasks since the store has last been updated. :)

// example
var asana = require('asana');
var client = asana.Client.create().useBasicAuth('your-api-key');
var Cacher = require('asana-cache-local');
var cacher = new Cache({
    client: client,
    workspace: 123456789,
    verbose: true
});
var log = function() { console.dir(arguments); };

cacher.refresh()
    .then(function() {
        cacher.tasks.all().then(log); // show all tasks!
        cacher.users.all().then(log); // show all users!
    });

api

constructor // new Cacher(opts)

  • @param {object} opts
  • @option {number} workspace - id of tasks to cache
  • @option {object} client - asana api client, with authorization set
  • @options {string=} dbpath - folder to store local database dbs/caches
  • @option {boolean=} verbose - enable logging of non-error/warning events
    • @default undefined
  • @option {string=} fields to include in task. must be formatted (kind of goofyish, as done with the @default below)
    • @default 'completed,completed_at,created_at,due_on,assignee_status,modified_at,parent,notes,name'

properties

  • @property tasks - Pouchy datastore of asana tasks
  • @property users - Pouchy of asana users

methods

refresh

Downloads all of the assigned tasks from the workspace, user-by-user, and stores them in a local db. On subsequent calls, tasks fetched that are new/updated are only recieved from the point of last update (so it speeds up after first run).

  • @return {proimse}
  • @resolves {undefined}

loadUsersToCache()

Loads the users onto the cache for ease of access. Users can be accessed via cacher.cache.users (array), or cacher.cache.usersById (object indexed by user id)

  • @return {promise}
  • @resolves {array} list of users
var promise1 = cacher.tasks.all();
var promise2 = cacher.loadUsersToCache();
Promise.all([promise1, promise2]).then(function assignNamesToAssignees(r) {
    var tasks = r[0];
    var users = r[1];
    tasks.forEach(function(task) {
        /* cacher.cache.usersById = {
         *    12345678: 'bill brasky',
         *    ...
         * }
         */
        task.assignmeeName = cacher.cache.usersById[task.assignee];
    });
})

About

cache all tasks within an asana workspace, locally

Resources

Stars

Watchers

Forks

Packages

No packages published