summaryrefslogtreecommitdiff
path: root/src/sources
diff options
context:
space:
mode:
Diffstat (limited to 'src/sources')
-rw-r--r--src/sources/FileSource.ts5
-rw-r--r--src/sources/HttpSource.ts25
-rw-r--r--src/sources/ISource.ts2
3 files changed, 16 insertions, 16 deletions
diff --git a/src/sources/FileSource.ts b/src/sources/FileSource.ts
index fd4f6f7..57e51ae 100644
--- a/src/sources/FileSource.ts
+++ b/src/sources/FileSource.ts
@@ -6,11 +6,10 @@ export class FileSource implements ISource {
private _path: string;
private _data: string = null;
- constructor(path: string) {
- this._path = path;
+ constructor(course: string) {
}
- getData(): Promise<string> {
+ getData(weekOfYear: number): Promise<string> {
if (this._data) {
return Promise.resolve(this._data);
}
diff --git a/src/sources/HttpSource.ts b/src/sources/HttpSource.ts
index 45ddd7a..f9391aa 100644
--- a/src/sources/HttpSource.ts
+++ b/src/sources/HttpSource.ts
@@ -1,22 +1,23 @@
-import {get} from 'http';
+import * as request from 'request-promise-native';
import {ISource} from './ISource';
export class HttpSource implements ISource {
- private _uri: string;
+ private _base_uri = 'http://splus.ostfalia.de/semesterplan123.php';
- constructor(path: string) {
- this._uri = path;
+ constructor(private _course: string) {
}
- 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));
- });
+ getData(weekOfYear: number): PromiseLike<string> {
+ return request({
+ method: 'POST',
+ uri: this._base_uri,
+ qs: {
+ identifier: this._course,
+ },
+ formData: {
+ weeks: weekOfYear.toString(),
+ },
});
}
}
diff --git a/src/sources/ISource.ts b/src/sources/ISource.ts
index 042aaae..3605260 100644
--- a/src/sources/ISource.ts
+++ b/src/sources/ISource.ts
@@ -1,3 +1,3 @@
export interface ISource {
- getData(): Promise<string>;
+ getData(weekOfYear: number): PromiseLike<string>;
}