-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
61 lines (51 loc) · 1.42 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
const media = require('./utils/media')
const concatenate = require('./utils/concatenate')
const request = require('request')
const isDev = process.env.NODE_ENV === 'development'
const BASE_URL = 'http://api.giphy.com/v1/gifs/search'
// The public BETA KEY!!
// @see https://github.com/Giphy/GiphyAPI
const API_KEY = 'dc6zaTOxFJmzC'
module.exports = {
keyword: 'giphy',
// @TODO: Allow copy to clipboard on ENTER
action: 'copy',
helper: {
title: 'giphy',
subtitle: 'Your wish is my command! start your wish with "giphy"',
},
query: q => new Promise(resolve => {
const items = []
const headers = { 'Content-Type': 'application/json' }
if (!q) {
resolve({ items })
return
}
const URL = `${BASE_URL}?q=${concatenate(q)}&api_key=${API_KEY}`
request
.get({ url: URL, headers, method: 'GET' }, (error, responseObj) => {
if (error) {
if (isDev)
console.warn('GIPHY: There was an issue with the request')
resolve({ items })
return
}
if (isDev)
console.info('GIPHY: Request has been successful')
const body = JSON.parse(responseObj.body)
const mediaItems = body.data.map(media)
resolve({ items: mediaItems })
})
}),
details: {
type: 'html',
render,
},
}
function render ({
context: {
images: { downsized_medium: { url } },
},
}) {
return `<img src="${url}" />`
}