-
Notifications
You must be signed in to change notification settings - Fork 549
/
tumblr.js
110 lines (88 loc) · 1.82 KB
/
tumblr.js
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
(function(hello) {
hello.init({
tumblr: {
// Ensure that you define an oauth_proxy
oauth: {
version: '1.0a',
auth: 'https://www.tumblr.com/oauth/authorize',
request: 'https://www.tumblr.com/oauth/request_token',
token: 'https://www.tumblr.com/oauth/access_token'
},
// Set default window height
login: function(p) {
p.options.popup.width = 600;
p.options.popup.height = 510;
},
base: 'https://api.tumblr.com/v2/',
get: {
me: 'user/info',
'me/like': 'user/likes',
'default': function(p, callback) {
if (p.path.match(/(^|\/)blog\//)) {
delete p.query.access_token;
p.query.api_key = hello.services.tumblr.id;
}
callback(p.path);
}
},
post: {
'me/like': function(p, callback) {
p.path = 'user/like';
query(p, callback);
}
},
del: {
'me/like': function(p, callback) {
p.method = 'post';
p.path = 'user/unlike';
query(p, callback);
}
},
wrap: {
me: function(o) {
if (o && o.response && o.response.user) {
o = o.response.user;
}
return o;
},
'me/like': function(o) {
if (o && o.response && o.response.liked_posts) {
o.data = o.response.liked_posts;
delete o.response;
}
return o;
},
'default': function(o) {
if (o.response) {
var r = o.response;
if (r.posts) {
o.data = r.posts;
}
}
return o;
}
},
xhr: function(p, qs) {
if (p.method !== 'get') {
return true;
}
return false;
}
}
});
// Converts post parameters to query
function query(p, callback) {
if (p.data) {
extend(p.query, p.data);
p.data = null;
}
callback(p.path);
}
function extend(a, b) {
for (var x in b) {
if (b.hasOwnProperty(x)) {
a[x] = b[x];
}
}
}
})(hello);