forked from hyunchel/melon-chart-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (43 loc) · 1.22 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const populateOptions = require('./defaults');
const {
dateRange,
scrapeMelon,
composeUrl,
} = require('./helpers');
/**
* Melon class.
*/
function Melon(date, options) {
const opts = populateOptions(options);
const dateManager = dateRange(date);
return {
realtime() {
const dates = dateManager.realtime();
const period = 'realtime';
const url = composeUrl(period, dates, opts);
return scrapeMelon(url, dates, opts);
},
daily() {
// NOTE: Dates are not needed for daily chart
// as Melon Music Chart does not provide previous daily charts.
// Daily chart will always fetch today's chart.
const dates = dateManager.daily();
const period = 'day';
const url = composeUrl(period, dates, opts);
return scrapeMelon(url, dates, opts);
},
weekly() {
const dates = dateManager.weekly();
const period = 'week';
const url = composeUrl(period, dates, opts);
return scrapeMelon(url, dates, opts);
},
monthly() {
const dates = dateManager.monthly();
const period = 'month';
const url = composeUrl(period, dates, opts);
return scrapeMelon(url, dates, opts);
},
};
}
module.exports = { Melon };