From ac85779f3b67ffc2953c17d0824be62b1f0acc86 Mon Sep 17 00:00:00 2001 From: Tim Schiewe Date: Mon, 30 Apr 2018 19:18:46 +0200 Subject: Implement interface/config based infrastructure Fixes #2 --- src/sources/HttpSource.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/sources/HttpSource.ts (limited to 'src/sources/HttpSource.ts') diff --git a/src/sources/HttpSource.ts b/src/sources/HttpSource.ts new file mode 100644 index 0000000..45ddd7a --- /dev/null +++ b/src/sources/HttpSource.ts @@ -0,0 +1,22 @@ +import {get} from 'http'; + +import {ISource} from './ISource'; + +export class HttpSource implements ISource { + private _uri: string; + + constructor(path: string) { + this._uri = path; + } + + getData(): Promise { + return new Promise((resolve, reject) => { + get(this._uri, (res) => { + let data = ''; + res.on('error', reject); + res.on('data', chunk => data += chunk); + res.on('end', () => resolve(data)); + }); + }); + } +} -- cgit v1.3.1