-
Notifications
You must be signed in to change notification settings - Fork 7
/
api.js
54 lines (52 loc) · 1.4 KB
/
api.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
var search = require('./lib/search').search
var getInfo = require('./lib/info').getInfo
var oauth = require('./lib/oauth')
module.exports = [{
path: '/search',
method: 'GET',
description: 'Search YouTube. Example: /search?part=id,snippet&q=hello%20world%20aloe&type=video&maxResults=10',
fn: function (callback, args) {
search(args.query, function (err, result) {
if (err) {
Homey.error(err)
callback(err)
} else {
callback(null, result)
}
})
}
}, {
method: 'GET',
path: '/videoInfo',
description: 'Get YouTube video info. Example: /videoInfo?id=mFrghyAyNTg',
fn: function (callback, args) {
info(args.query.url, args.query, callback)
}
}, {
method: 'GET',
path: '/videoInfo/:id',
description: 'Get YouTube video info. Example: /videoInfo?id=mFrghyAyNTg',
fn: function (callback, args) {
info(args.params.id, args.query, callback)
}
}, {
description: 'Log-in',
method: 'POST',
path: '/settings/authorize',
fn: function (callback) {
oauth.authorize(callback)
}
}
]
function info (idOrUrl, options, callback) {
if (options['filter.type']) {
var filterType = options['filter.type']
options.filter = function (format) {
return format.type && format.type.startsWith(filterType)
}
delete options['filter.type']
}
getInfo(idOrUrl, options)
.then(result => callback(null, result))
.catch(callback)
}