|
1 | | -const debug = require('debug')('API') |
2 | | -const config = require('config') |
3 | | -const Scraper = require('./src/Scraper') |
| 1 | +const debug = require('debug')('API'); |
| 2 | +const config = require('config'); |
| 3 | +const Scraper = require('./src/Scraper'); |
4 | 4 |
|
5 | 5 | class API extends Scraper { |
6 | | - async getContent (url) { |
7 | | - const patterns = config.get('patterns') |
8 | | - const rootURL = patterns.root |
9 | | - const login = rootURL + patterns.login |
10 | | - const home = rootURL + patterns.home |
11 | | - const course = rootURL + patterns.course |
12 | | - const forum = rootURL + patterns.forum |
13 | | - const material = rootURL + patterns.material |
14 | | - const activity = rootURL + patterns.activity |
| 6 | + async getContent(url) { |
| 7 | + const patterns = config.get('patterns'); |
| 8 | + const rootURL = patterns.root; |
| 9 | + const login = rootURL + patterns.login; |
| 10 | + const home = rootURL + patterns.home; |
| 11 | + const course = rootURL + patterns.course; |
| 12 | + const forum = rootURL + patterns.forum; |
| 13 | + const material = rootURL + patterns.material; |
| 14 | + const activity = rootURL + patterns.activity; |
15 | 15 |
|
16 | | - let promise |
| 16 | + let promise; |
17 | 17 |
|
18 | 18 | switch (true) { |
19 | 19 | case url.includes(login): |
20 | | - debug('getContent: login - %s', url) |
21 | | - promise = this.login() |
22 | | - break |
| 20 | + debug('getContent: login - %s', url); |
| 21 | + promise = this.login(); |
| 22 | + break; |
23 | 23 | case url.includes(home): |
24 | | - debug('getContent: home - %s', url) |
25 | | - promise = this.getHomeContent() |
26 | | - break |
| 24 | + debug('getContent: home - %s', url); |
| 25 | + promise = this.getHomeContent(); |
| 26 | + break; |
27 | 27 | case url.includes(course): |
28 | | - debug('getContent: course - %s', url) |
29 | | - promise = this.getCourseContent(url) |
30 | | - break |
| 28 | + debug('getContent: course - %s', url); |
| 29 | + promise = this.getCourseContent(url); |
| 30 | + break; |
31 | 31 | case url.includes(forum): |
32 | | - debug('getContent: forum - %s', url) |
33 | | - break |
| 32 | + debug('getContent: forum - %s', url); |
| 33 | + break; |
34 | 34 | case url.includes(material): |
35 | | - debug('getContent: material - %s', url) |
36 | | - promise = this.getMaterialContent(url) |
37 | | - break |
| 35 | + debug('getContent: material - %s', url); |
| 36 | + promise = this.getMaterialContent(url); |
| 37 | + break; |
38 | 38 | case url.includes(activity): |
39 | | - debug('getContent: activity - %s', url) |
40 | | - promise = this.getActivityContent(url) |
41 | | - break |
| 39 | + debug('getContent: activity - %s', url); |
| 40 | + promise = this.getActivityContent(url); |
| 41 | + break; |
42 | 42 | default: |
43 | | - debug('getContent: can\'t resolve - %s', url) |
44 | | - promise = this.unknownContext(url) |
| 43 | + debug('getContent: can\'t resolve - %s', url); |
| 44 | + promise = this.unknownContext(url); |
45 | 45 | } |
46 | 46 |
|
47 | | - return promise |
| 47 | + return promise; |
48 | 48 | } |
49 | 49 | } |
50 | 50 |
|
51 | | -module.exports = API |
| 51 | +module.exports = API; |
0 commit comments