-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
63 lines (56 loc) · 1.17 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const got = require('got');
// default API endpoint
const ENDPOINT = 'https://rubygems.org/api/v1/search.json';
const makeRequest = (options) => {
const opts = Object.assign({}, { json: true }, options);
const prom = got(ENDPOINT, opts);
return new Promise((resolve) => {
prom.then(res => resolve(res.body));
});
};
const mapItems = item => Object.assign({}, {
title: item.name,
subtitle: item.info,
arg: item.project_uri,
text: {
copy: `gem install ${item.name}`
},
icon: {
path: './icon.png'
},
mods: {
cmd: {
arg: item.homepage_uri,
subtitle: 'View project homepage.'
},
alt: {
arg: item.source_code_uri,
subtitle: 'View project source code.'
}
}
});
module.exports = {
keyword: 'gem',
action: 'openurl',
helper: {
title: 'Search ruby gems.',
subtitle: 'Example: gem rails',
icon: {
path: './icon.png'
}
},
query: q => new Promise((resolve) => {
const opts = {
query: {
query: q
}
};
makeRequest(opts)
.then((body) => {
const items = body
.slice(0, 20)
.map(mapItems)
resolve({ items });
});
}),
};