-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathifttt.js
More file actions
25 lines (20 loc) · 720 Bytes
/
ifttt.js
File metadata and controls
25 lines (20 loc) · 720 Bytes
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
/* global fetch */
import helper from './modules/helper'
export default class IFTTT {
constructor (key) {
if (!key || typeof key !== 'string') throw new Error('You need to set a key before making a request')
this.key = key
}
async post (eventName, value) {
if (!eventName) throw new Error('No event name given.')
if (value && !Array.isArray(value)) throw new TypeError('The values must be in an array.')
const res = await fetch(
helper.createUrl(eventName, this.key),
helper.createRequestOptions('post', value)
)
if (res.status !== 200) {
throw new Error(`POST request failed with the following code: ${res.status}, ${res.statusText}`)
}
return res
}
}