diff --git a/examples/actions/IcsExample.ts b/examples/actions/IcsExample.ts new file mode 100644 index 0000000..39d0857 --- /dev/null +++ b/examples/actions/IcsExample.ts @@ -0,0 +1,36 @@ +import Action from './../../packages/runner/actions/action.ts' +import State from './../../packages/runner/_state.ts' +import ical from 'node-ical' + +/** + * getting ics from url and parse it to object + * + * @author Björn Hase + * @license http://opensource.org/licenses/MIT The MIT License + * @link https://git.node001.net/HerrHase/super-hog.git + * + */ + +class IcsExample extends Action { + async run() { + let response + + try { + response = await fetch(this.config.url) + } catch(error) { + throw new Error(error) + } + + // if code is 200 + if (response && response.status === 200) { + const body = await response.text() + const events = ical.sync.parseICS(body) + + if (events) { + this.result = events + } + } + } +} + +export default IcsExample