summaryrefslogtreecommitdiff
path: root/src/sources/HttpSource.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/sources/HttpSource.ts')
-rw-r--r--src/sources/HttpSource.ts22
1 files changed, 22 insertions, 0 deletions
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<string> {
+ return new Promise<string>((resolve, reject) => {
+ get(this._uri, (res) => {
+ let data = '';
+ res.on('error', reject);
+ res.on('data', chunk => data += chunk);
+ res.on('end', () => resolve(data));
+ });
+ });
+ }
+}