-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTumblrAdapter.js
More file actions
114 lines (80 loc) · 3.23 KB
/
TumblrAdapter.js
File metadata and controls
114 lines (80 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/**
* Created by Roberto on 07-07-2014.
*/
var tumb = require('tumblr');
module.exports = (function(){
var adapter = {
identity: 'sails-tumblr',
syncable: false,
connections: {},
registerCollection: function (collection, cb) {
var oauth = {
consumer_key: collection.config.consumerKey,
consumer_secret: collection.config.consumerSecret,
token: collection.config.accessToken,
token_secret: collection.config.accessTokenSecret
}
this.connections[collection.identity] = {
apiBlog: new tumb.Blog(collection.config.blogUrl, oauth),
apiUser: new tumb.User(oauth)
};
cb();
},
posts: function (collectionName, criteria, cb) {
this.connections[collectionName].apiBlog.posts(criteria,function(err, result){
if (err) return cb(err);
if (!(result && result.posts) ) return cb(result.posts);
cb(err, result.posts);
});
},
blog: function (collectionName, cb) {
this.connections[collectionName].apiBlog.info(function(err, result){
if (err) return cb(err);
if (!(result && result.blog) ) return cb(result.blog);
cb(err, [result.blog]);
});
},
/* limit: function(collectionName, val, cb){
console.log(this);
return cb(null,'');
},*/
find: function(collectionName, options, cb) {
var criteria = options.where || {};
if(options.limit) criteria.limit = options.limit;
switch (collectionName) {
case 'tumblrpost': return this.posts(collectionName, criteria, afterwards); // "afterwards" em vez de "cb"
case 'tumblrblog': return this.blog(collectionName, afterwards);
default: return afterwards('Unknown usage of find() with model ('+collectionName+') ');
}
function afterwards (err, results){
if (err) return cb(err);
/* Useful to work on results if needed */
return cb(err,results);
}
/*this.connections[collectionName].apiUser.info(function(error,response){
if(error) {console.log(error);return;}
response.user
});*/
},
describe: function(collectionName, cb) {},
define: function(collectionName, definition, cb) {},
drop: function(collectionName, cb) {},
create: function(collectionName, data, cb) {},
/* todo:
text([options, ]callback)
quote([options, ]callback)
link([options, ]callback)
answer([options, ]callback)
video([options, ]callback)
audio([options, ]callback)
photo([options, ]callback)*/
stream: function(collectionName, options, stream) {},
update: function(collectionName, options, values, cb) {
//todo: client.edit()
},
destroy: function(collectionName, options, cb) {
//todo: client.deletePost()
}
};
return adapter;
})();