Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nigel Fish
committed
Jan 3, 2013
0 parents
commit d7bb1a3
Showing
3 changed files
with
309 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# node-minutedock (API wrapper for Node.js) | ||
|
||
A wrapper for the MinuteDock API v1 | ||
|
||
## Example usage | ||
|
||
var http = require('http'), | ||
Minutedock = require('./lib/minutedock'); | ||
|
||
var md = new Minutedock( | ||
'API_KEY' | ||
); | ||
|
||
http.createServer(function (req, res) { | ||
|
||
md.projects.all(function (err, projects) { | ||
if (err) | ||
res.end('Could not load your projects!'); | ||
|
||
res.end(projects); | ||
}); | ||
|
||
|
||
}).listen(8080); | ||
console.log('Server running at http://localhost:8080/'); | ||
|
||
## All methods from beta v1 on Minutedock are supported as per: http://minutedock.com/apidocs | ||
|
||
### accounts | ||
|
||
* `accounts.all(callback)` | ||
* `accounts.active(callback)` | ||
|
||
### users | ||
|
||
* `users.all(accountID, callback)` | ||
|
||
### entries | ||
|
||
* `entries.current(callback)` | ||
* `entries.update(id, data, callback)` | ||
* `entries.start(callback)` | ||
* `entries.pause(callback)` | ||
* `entries.log(callback)` | ||
* `entries.new(accountID, data, callback)` | ||
* `entries.search(data, callback)` | ||
|
||
### contacts | ||
|
||
* `contacts.all(accountID, callback)` | ||
* `contacts.new(accountID, data, callback)` | ||
* `contacts.update(id, data, callback)` | ||
|
||
### tasks | ||
|
||
* `tasks.all(accountID, callback)` | ||
* `tasks.new(accountID, data, callback)` | ||
* `tasks.update(id, data, callback)` | ||
* `tasks.delete(id, callback)` | ||
* `tasks.archive(id, callback)` | ||
|
||
### projects | ||
|
||
* `projects.all(accountID, callback)` | ||
* `projects.new(accountID, data, callback)` | ||
* `projects.update(id, data, callback)` | ||
* `projects.delete(id, callback)` | ||
* `projects.archive(id, callback)` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,216 @@ | ||
var https = require('https'); | ||
|
||
var Minutedock = function (key) { | ||
|
||
var self = this; | ||
this.key = key; | ||
|
||
this.api = { | ||
accounts:{ | ||
all:function (callback) { | ||
return self.request('accounts.json', "GET", function (err, accounts) { | ||
callback(err, accounts); | ||
}); | ||
}, | ||
active:function (callback) { | ||
return self.request('accounts/current.json', "GET", function (err, account) { | ||
callback(err, account); | ||
}); | ||
} | ||
}, | ||
users:{ | ||
all:function (accountID, callback) { | ||
var data = { account_id:accountID } | ||
return self.request('users.json', "GET", data, function (err, accounts) { | ||
callback(err, accounts); | ||
}); | ||
} | ||
}, | ||
entries:{ | ||
current:function (callback) { | ||
return self.request('entries/current.json', "GET", data, function (err, accounts) { | ||
callback(err, accounts); | ||
}); | ||
}, | ||
update:function (id, data, callback) { | ||
var form_data = { entry:data }; | ||
return self.request('entries/' + id + '.json', "PUT", form_data, function (err, accounts) { | ||
callback(err, accounts); | ||
}); | ||
}, | ||
start:function (callback) { | ||
return self.request('entries/current/start.json', "POST", data, function (err, accounts) { | ||
callback(err, accounts); | ||
}); | ||
}, | ||
pause:function (callback) { | ||
return self.request('entries/current/pause.json', "POST", function (err, accounts) { | ||
callback(err, accounts); | ||
}); | ||
|
||
}, | ||
log:function (callback) { | ||
return self.request('entries/current/log.json', "POST", function (err, accounts) { | ||
callback(err, accounts); | ||
}); | ||
}, | ||
new:function (accountID, data, callback) { | ||
var form_data = { | ||
entry:data, | ||
account_id:accountID | ||
}; | ||
return self.request('entries.json', "POST", form_data, function (err, accounts) { | ||
callback(err, accounts); | ||
}); | ||
}, | ||
search:function (data, callback) { | ||
return self.request('entries.json', "GET", data, function (err, accounts) { | ||
callback(err, accounts); | ||
}); | ||
} | ||
}, | ||
contacts:{ | ||
all:function (accountID, callback) { | ||
var data = { account_id:accountID }; | ||
return self.request('contacts.json', "GET", data, function (err, accounts) { | ||
callback(err, accounts); | ||
}); | ||
}, | ||
new:function (accountID, data, callback) { | ||
var form_data = { | ||
contact:data, | ||
account_id:accountID | ||
}; | ||
return self.request('contacts.json', "POST", form_data, function (err, accounts) { | ||
callback(err, accounts); | ||
}); | ||
}, | ||
update:function (id, data, callback) { | ||
var form_data = { contact:data }; | ||
return self.request('contacts/' + id + '.json', "PUT", form_data, function (err, accounts) { | ||
callback(err, accounts); | ||
}); | ||
} | ||
}, | ||
tasks:{ | ||
all:function (accountID, callback) { | ||
var data = {account_id:accountID }; | ||
return self.request('tasks.json', "GET", data, function (err, accounts) { | ||
callback(err, accounts); | ||
}); | ||
}, | ||
new:function (accountID, data, callback) { | ||
var form_data = { | ||
task:data, | ||
account_id:accountID | ||
}; | ||
return self.request('tasks.json', "POST", form_data, function (err, accounts) { | ||
callback(err, accounts); | ||
}); | ||
}, | ||
update:function (id, data, callback) { | ||
var form_data = { task:data }; | ||
return self.request('tasks/' + id + '.json', "PUT", form_data, function (err, accounts) { | ||
callback(err, accounts); | ||
}); | ||
}, | ||
delete:function (id, callback) { | ||
return self.request('tasks/' + id + '.json', "DELETE", function (err, accounts) { | ||
callback(err, accounts); | ||
}); | ||
}, | ||
archive:function (id, callback) { | ||
return self.request('tasks/' + id + '/archive.json', "POST", function (err, accounts) { | ||
callback(err, accounts); | ||
}); | ||
} | ||
}, | ||
projects:{ | ||
all:function (accountID, callback) { | ||
var data = { account_id:accountID }; | ||
return self.request('projects.json', "GET", data, function (err, accounts) { | ||
callback(err, accounts); | ||
}); | ||
}, | ||
new:function (accountID, data, callback) { | ||
var form_data = { | ||
project:data, | ||
account_id:accountID | ||
}; | ||
return self.request('projects.json', "POST", form_data, function (err, accounts) { | ||
callback(err, accounts); | ||
}); | ||
}, | ||
update:function (id, data, callback) { | ||
var form_data = { project:data }; | ||
return self.request('projects/' + id + '.json', "PUT", form_data, function (err, accounts) { | ||
callback(err, accounts); | ||
}); | ||
}, | ||
delete:function (id, callback) { | ||
return self.request('projects/' + id + '.json', "DELETE", function (err, accounts) { | ||
callback(err, accounts); | ||
}); | ||
}, | ||
archive:function (id, callback) { | ||
return self.request('projects/' + id + '/archive.json', "POST", function (err, accounts) { | ||
callback(err, accounts); | ||
}); | ||
} | ||
} | ||
}; | ||
|
||
return this.api; | ||
}; | ||
|
||
Minutedock.prototype.request = function (path, method, form_data, callback) { | ||
|
||
var data = { }; | ||
if (arguments.length == 3) { | ||
callback = form_data; | ||
} else { | ||
data = form_data; | ||
} | ||
data["api_key"] = this.key; | ||
|
||
var urlPath = "/api/v1/" + path; | ||
if (method === "GET") { | ||
urlPath += "?"; | ||
urlPath += "api_key=" + data["api_key"]; | ||
if (data["account_id"]) urlPath += "&account_id=" + data["account_id"]; | ||
} | ||
|
||
var dataString = JSON.stringify(data); | ||
|
||
var headers = { | ||
'Content-Type':'application/json', | ||
'Content-Length':dataString.length, | ||
'User-Agent':'NodeJS' | ||
}; | ||
|
||
var options = { | ||
"host":'minutedock.com', | ||
"path":urlPath, | ||
"method":method, | ||
"headers":headers | ||
}; | ||
|
||
var req = https.request(options, function (res) { | ||
var json = ''; | ||
res.on('data',function (chunk) { | ||
json = chunk.toString(); | ||
}).on('end', function () { | ||
if (res.statusCode != 200) { | ||
console.error('MinuteDock API error: ' + res.statusCode + ' ' + options.path); | ||
callback(true, {'status':res.statusCode}); | ||
return; | ||
} | ||
callback(false, json); | ||
}); | ||
}); | ||
|
||
req.write(dataString); | ||
req.end(); | ||
}; | ||
|
||
module.exports = Minutedock; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "node-minutedock", | ||
"version": "0.1.0", | ||
"author": { | ||
"name": "Nigel Fish", | ||
"url": "http://github.com/dphrag" | ||
}, | ||
"description": "MinuteDock API wrapper", | ||
"keywords": [ | ||
"api", | ||
"wrapper", | ||
"minutedock" | ||
], | ||
"homepage": "http://github.com/dphrag/node-minutedock", | ||
|
||
"main": "./lib/minutedock", | ||
"repository": { | ||
"type": "git", | ||
"url": "http://github.com/dphrag/node-minutedock.git" | ||
}, | ||
"dependencies": { }, | ||
"engines": { | ||
"node": ">=0.8" | ||
} | ||
} |