-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
43 lines (39 loc) · 1.05 KB
/
index.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
'use strict';
const alfy = require('alfy');
const alfredNotifier = require('alfred-notifier');
const Promise = require("bluebird");
const request = require('request-promise');
const hosts = alfy.config.get('hosts');
const auth = alfy.config.get('auth');
var requestList = [];
for (var host in hosts) {
requestList.push({
url: hosts[host] + '/rest/api/latest/plan?max-result=300',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Basic ' + auth,
'Accept': 'application/json'
},
method: 'GET'
});
}
Promise.map(requestList, function(obj) {
return request(obj).then(function(body) {
return JSON.parse(body);
});
}).then(function(data) {
var items = [];
for (var entry in data) {
const list = data[entry]['plans']['plan'];
items = items.concat(alfy
.matches(alfy.input, list, 'name')
.map(x => ({
title: x.name,
subtitle: x.shortName,
arg: x['link'].href.substring(0, x['link'].href.lastIndexOf("/rest")) + '/browse/' + x['planKey'].key
})));
}
alfy.output(items);
}, function(err) {
alfy.error(err);
});