Permalink
Browse files

follow/unfollow in with new api methods

  • Loading branch information...
1 parent df62cb5 commit 774233b0c57afe149893e4e5930912da880b0a67 @chapel committed May 5, 2012
Showing with 73 additions and 5 deletions.
  1. +47 −1 lib/geeklist.js
  2. +26 −4 lib/resources.js
View
@@ -145,14 +145,60 @@ Geeklist.prototype._get = function (url, tokens, callback) {
Geeklist.prototype._post = function (url, data, tokens, callback) {
this.client.post(
this._makeUrl(url)
- , tokens.access
+ , tokens.token
, tokens.secret
, data
, 'json'
, callback
)
}
+/**
+ * Put data
+ *
+ * @param {String} url
+ * @param {Object} data
+ * @param {Object} tokens
+ * @param {Callback} callback
+ *
+ * @api private
+ */
+
+Geeklist.prototype._put = function (url, data, tokens, callback) {
+ if (!callback) {
+ callback = tokens
+ tokens = data
+ data = null
+ }
+ this.client.put(
+ this._makeUrl(url)
+ , tokens.token
+ , tokens.secret
+ , data
+ , 'json'
+ , callback
+ )
+}
+
+/**
+ * Delete resource
+ *
+ * @param {String} url
+ * @param {Object} tokens
+ * @param {Callback} callback
+ *
+ * @api private
+ */
+
+Geeklist.prototype._del = function (url, tokens, callback) {
+ this.client.delete(
+ this._makeUrl(url)
+ , tokens.token
+ , tokens.secret
+ , callback
+ )
+}
+
Geeklist.prototype.auth = function(tokens) {
this.access = {
token: tokens.token
View
@@ -21,10 +21,7 @@ Resources.prototype.profile = function(callback) {
, this.tokens
, function(err, res) {
if (err) return callback(err)
- self.gklst.toObject(res, function(err, obj) {
- if (err) return callback(err)
- callback(null, obj)
- })
+ self.gklst.toObject(res, callback)
}
)
}
@@ -40,6 +37,31 @@ Resources.prototype._get = function(resource, callback) {
)
}
+var followRes = [
+ {name: 'follow', method: 'put'}
+ , {name: 'unfollow', method: 'del'}
+]
+
+followRes.forEach(function(resource) {
+ Resources.prototype[resource.name] = function(callback) {
+ var self = this
+
+ callback = this.gklst.safe(callback)
+
+ if (!this.id) return callback(new Error('You cannot follow/unfollow yourself'))
+
+ this.gklst['_' + resource.method](
+ [this.uri, this.id, 'follow'].join('/')
+ , this.tokens
+ , function(err, res) {
+ if (err) return callback(err)
+
+ self.gklst.toObject(res, callback)
+ }
+ )
+ }
+})
+
function resObj() {
return {
name: arguments[0]

0 comments on commit 774233b

Please sign in to comment.