-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathindex.js
38 lines (34 loc) · 959 Bytes
/
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
/*!
* Copyright(c) 2017 Hyungjoo Kwon
* MIT Licensed
*/
const DeliveryCompany = require('./lib/models/DeliveryCompany')
const DeliveryCompanyType = require('./lib/models/DeliveryCompanyType')
const i18n = require('./lib/utils/i18n')
module.exports = (options = {}) => {
options.timeout = options.timeout || 10000
options.locale = options.locale || 'ko'
i18n.setLocale(options.locale)
const delibee = require('./lib/crawler')(options)
return {
company: async () => {
return DeliveryCompanyType
},
tracking: async (companyCode, invoiceNumber) => {
try {
const company = new DeliveryCompany(companyCode)
const lowerCode = company.code.toLowerCase()
const invoice = await delibee[lowerCode](invoiceNumber)
return {
success: true,
invoice
}
} catch (e) {
return {
success: false,
message: e.message
}
}
}
}
}