bkash
Version:
bKash API client for Browser & Node.js
27 lines (20 loc) • 589 B
JavaScript
const deepmerge = require('../utils/deepmerge.js')
const validate = require('./validate.js')
const endpointMethod = (
apiClient,
endpointDefaults,
endpointParamsSpecs,
options = {},
callback
) => {
const endpointOptions = deepmerge(endpointDefaults, options)
const promise = Promise.resolve(endpointOptions)
.then(endpointOptions => validate(endpointParamsSpecs, endpointOptions))
.then(apiClient.request)
if (callback) {
promise.then(response => callback(null, response)).catch(callback)
return
}
return promise
}
module.exports = endpointMethod