db-vendo-client/index.js

46 lines
1.3 KiB
JavaScript
Raw Normal View History

2016-06-22 01:39:04 +02:00
'use strict'
2017-11-11 22:35:41 +01:00
const parseLocation = require('./parse/location')
const parseLine = require('./parse/line')
const parseRemark = require('./parse/remark')
const parseOperator = require('./parse/operator')
2017-11-11 22:49:04 +01:00
const request = require('./lib/request')
2016-06-22 02:09:02 +02:00
2017-11-11 22:49:04 +01:00
const id = x => x
2016-06-22 02:09:02 +02:00
2017-11-11 22:49:04 +01:00
const defaultProfile = {
transformReqBody: id,
transformReq: id,
2017-11-11 22:35:41 +01:00
parseLocation: parseLocation,
parseLine: parseLine,
parseRemark: parseRemark,
parseOperator: parseOperator
2016-06-22 02:09:02 +02:00
}
2016-06-22 01:39:59 +02:00
2017-11-11 22:49:04 +01:00
const createClient = (profile) => {
profile = Object.assign({}, defaultProfile, profile)
if ('function' !== profile.transformReqBody) {
throw new Error('profile.transformReqBody must be a function.')
}
if ('function' !== profile.transformReq) {
throw new Error('profile.transformReq must be a function.')
}
if ('function' !== profile.parseLocation) {
throw new Error('profile.parseLocation must be a function.')
}
if ('function' !== profile.parseLine) {
throw new Error('profile.parseLine must be a function.')
}
if ('function' !== profile.parseRemark) {
throw new Error('profile.parseRemark must be a function.')
}
if ('function' !== profile.parseOperator) {
throw new Error('profile.parseOperator must be a function.')
2016-06-22 01:39:59 +02:00
}
2017-10-03 17:36:42 +02:00
2017-11-11 22:49:04 +01:00
const client = data => request(profile, data)
return client
2016-06-22 01:39:59 +02:00
}
2017-10-03 17:36:42 +02:00
module.exports = createRequest