-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (44 loc) · 1.22 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
const rp = require('request-promise')
const { stringify } = require('querystring')
module.exports = async opts => {
if (!opts) {
throw Error('Missing required input: options')
}
if (!opts.url) {
throw Error('Missing required input: url')
}
if (!opts.credentials) {
throw Error('Missing required input: options.credentials')
}
if (!opts.credentials.auth) {
throw Error('Missing required input: options.credentials.auth')
}
if (!opts.credentials.auth.username) {
throw Error('Missing required input: username')
}
if (!opts.credentials.auth.password) {
throw Error('Missing required input: password')
}
if (!opts.credentials.client) {
throw Error('Missing required input: options.credentials.client')
}
if (!opts.credentials.client.client_id) {
throw Error('Missing required input: client_id')
}
if (!opts.credentials.client.client_secret) {
throw Error('Missing required input: client_secret')
}
const { url, credentials } = opts
const httpOpts = {
uri: url + '?' + stringify(credentials.client),
method: 'POST',
json: true,
form: credentials.auth
}
try {
const data = await rp(httpOpts)
return data
} catch (error) {
throw error
}
}