Skip to content
This repository has been archived by the owner on Mar 18, 2023. It is now read-only.

Commit

Permalink
Merge pull request #43 from kusold/apiv3
Browse files Browse the repository at this point in the history
Apiv3
  • Loading branch information
kusold authored Aug 13, 2016
2 parents 0db5faa + 3ab44ee commit 2feb41a
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 64 deletions.
19 changes: 10 additions & 9 deletions habitSync.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ habitSync.prototype.run = function(done) {
self.getTodoistSync(cb);
},
function(res, cb) {
history.seqNo = res.body.seq_no;
self.updateHistoryForTodoistItems(res.body.Items);
history.sync_token = res.body.sync_token;
self.updateHistoryForTodoistItems(res.body.items);
var changedTasks = self.findTasksThatNeedUpdating(history, oldHistory);
self.syncItemsToHabitRpg(changedTasks, cb);
}
Expand Down Expand Up @@ -97,7 +97,7 @@ habitSync.prototype.findTasksThatNeedUpdating = function(newHistory, oldHistory)

habitSync.prototype.updateHistoryForTodoistItems = function(items) {
var self = this;
var habit = new habitapi(self.uid, self.token);
var habit = new habitapi(self.uid, self.token, null, 'v2');
_.forEach(items, function(item) {
if(history.tasks[item.id]) {
if(item.is_deleted) {
Expand Down Expand Up @@ -128,19 +128,20 @@ habitSync.prototype.readHistoryFromFile = function(path) {

habitSync.prototype.getTodoistSync = function(cb) {
var self = this;
var seqNo = history.seqNo || 0;
var sync_token = history.sync_token || 0;

request.post('https://api.todoist.com/TodoistSync/v5.3/get')
.send('api_token=' + self.todoist)
.send('seq_no='+seqNo)
request.get('https://todoist.com/API/v7/sync')
.send('token=' + self.todoist)
.send('sync_token=' + sync_token)
.send('resource_types=["all"]')
.end(function(err, res) {
cb(err,res);
});
};

habitSync.prototype.syncItemsToHabitRpg = function(items, cb) {
var self = this;
var habit = new habitapi(self.uid, self.token);
var self = this
var habit = new habitapi(self.uid, self.token, null, 'v2');
// Cannot execute in parallel. See: https://github.com/HabitRPG/habitrpg/issues/2301
async.eachSeries(items, function(item, next) {
async.waterfall([
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "todoist-habitrpg",
"version": "0.3.5",
"version": "1.0.0",
"description": "One way sync from Todoist -> HabitRPG.",
"main": "index.js",
"homepage": "https://github.com/Kusold/todoist-habitrpg",
Expand Down Expand Up @@ -49,7 +49,7 @@
],
"license": "GPL v3",
"dependencies": {
"habitrpg-api": "~0.1.0",
"habitrpg-api": "1.0.1",
"commander": "~2.2.0",
"superagent": "~0.18.0",
"async": "~0.9.0",
Expand Down
Loading

0 comments on commit 2feb41a

Please sign in to comment.