Added query API with parameter aliasing. Improvements to parameter value normalization.
This commit is contained in:
1 parent
56fa1f03e4
commit
e117f9ceb3
5 files changed
+188
-24
No files matched your search
+36
-24
@@ -1,11 +1,31 @@
|
||||
config = require './config'
|
||||
common = require './common'
|
||||
|
||||
|
||||
normalizers = {}
|
||||
|
||||
normalizers.default = (input, normType) ->
|
||||
if normType is 'query' and common.typeOf(input) is common.STRING_TYPE
|
||||
vals = []
|
||||
str = normalizers.string(input, normType)
|
||||
if common.typeOf(str) == common.ARRAY_TYPE
|
||||
vals = vals.concat(str)
|
||||
else
|
||||
vals.push(str)
|
||||
|
||||
f = parseFloat(input)
|
||||
if not isNaN(f)
|
||||
vals.push(f)
|
||||
|
||||
d = new Date(input)
|
||||
if input.length >= 8 and d.getFullYear() > 1983
|
||||
vals.push(d)
|
||||
return vals
|
||||
return input
|
||||
|
||||
|
||||
FLOAT_REGEX = /^([\-\+]?[0-9\.]+)/
|
||||
normalizers.float = (input) ->
|
||||
normalizers.float = (input, normType) ->
|
||||
res = FLOAT_REGEX.exec(input)
|
||||
if res != null
|
||||
parseFloat(res[1])
|
||||
@@ -13,27 +33,19 @@ normalizers.float = (input) ->
|
||||
null
|
||||
|
||||
|
||||
exports.normalize = (path, value) ->
|
||||
if path of parameters
|
||||
return normalizers[parameters[path].type](value)
|
||||
normalizers.date = (input, normType) ->
|
||||
return new Date(input)
|
||||
|
||||
|
||||
normalizers.string = (input, normType) ->
|
||||
if normType is 'query'
|
||||
if /^\/(.*?)\/(g?i?m?y?)$/.test(input)
|
||||
return [{'$regex' : eval(input)}, input]
|
||||
input
|
||||
|
||||
|
||||
exports.normalize = (path, value, normType) ->
|
||||
if path of config.PARAMETERS
|
||||
return normalizers[config.PARAMETERS[path].type](value)
|
||||
else
|
||||
return value
|
||||
|
||||
|
||||
parameters = {
|
||||
'InternetGatewayDevice.WiMAX.Status.RSSI' : {
|
||||
type : 'float',
|
||||
},
|
||||
'InternetGatewayDevice.WiMAX.Status.CINR1' : {
|
||||
type : 'float',
|
||||
},
|
||||
'InternetGatewayDevice.WiMAX.Status.CINR2' : {
|
||||
type : 'float',
|
||||
},
|
||||
'InternetGatewayDevice.X_MTK_WiMAX_Param.CINR_level' : {
|
||||
type : 'float',
|
||||
},
|
||||
'InternetGatewayDevice.X_MTK_WiMAX_Param.RSSI_level' : {
|
||||
type : 'float',
|
||||
},
|
||||
}
|
||||
return normalizers['default'](value, normType)
|
||||
Reference in new issue
Block a user