/
gists.js
125 lines (95 loc) · 2.78 KB
/
gists.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
var github = require('octonode'),
settings = require('../modules/settings'),
ghgist = null;
exports.auth = function(req, res) {
res.contentType('application/json');
// authenticate
github.auth.config({
username: req.params.user,
password: req.params.pass
}).login(['user', 'repo', 'gist'], function(err, id, token) {
settings.token = token; // save the client token
settings.client = github.client(settings.token); // create a client object
settings.client.get('/user', function(err, status, body) { // get user details
settings.info = body;
});
ghgist = settings.client.gist(); // create a reference to gist api
res.send({
id: id,
token: token,
err: err
});
});
}
exports.listGists = function(req, res) {
res.contentType('application/json');
ghgist.list(function(err, data) {
res.send(data);
})
};
exports.getStarredGists = function(req, res) {
res.contentType('application/json');
ghgist.starred(function(err, data) {
res.send(data);
})
};
exports.getGistById = function(req, res) {
res.contentType('application/json');
ghgist.get(req.params.id, function(err, data) {
res.send(data);
})
};
exports.createGist = function(req, res) {
res.contentType('application/json');
ghgist.create({
description: req.body.description,
"public": req.body.public,
files: req.body.files
}, function(err, data) {
if (err) {
res.send({status: 'error', error: err});
}
res.send({status: 'ok', data: data});
});
};
exports.editGist = function(req, res) {
ghgist.edit(req.body.id, {
description: req.body.description,
files: req.body.files
}, function(err, data) {
if (err) {
res.send({status: 'error', error: err});
}
res.send({'status': "ok", data: data});
});
};
exports.deleteGist = function(req, res) {
console.log(req.params.id);
console.log(req.body.id);
ghgist.delete(req.params.id);
res.send({'status': "ok"});
};
exports.starGistById = function(req, res) {
res.contentType('application/json');
ghgist.star(req.params.id);
res.send({
complete: 'complete'
});
};
exports.unStarGistById = function(req, res) {
res.contentType('application/json');
ghgist.unstar(req.params.id);
res.send({
complete: 'complete'
});
};
exports.getGistCommentsByGistId = function(req, res) {
res.contentType('application/json');
ghgist.comments(req.params.id, function(err, data) {
res.send(data);
});
};
exports.deleteGistCommentById = function(req, res) {
};
exports.editGistCommentById = function(req, res) {
};