getRules - Examples
In the following, an example call and the according return values using the getRules method of a DanubeClient instance are shown.You can also download and try a set of working demo examples for each danube.ai service using the SDK here:
https://gitlab.com/danube.ai/sdkconst { DanubeClient } = require('danube-sdk');
// Initialize a DanubeClient with your API key.
const danubeClient = new DanubeClient(
'my-api-key',
);
async function runTest() {
const rulesId_1 = 'my-sdk-test-rule-set-1';
const override_1 = true;
const rules_1 = [
{
property: 'p1',
type: 'PERCENTAGE',
},
{
property: 'p2',
type: 'PERCENTAGE',
},
];
await danubeClient.setRules(
rulesId_1,
override_1,
rules_1,
);
const rulesId_2 = 'my-sdk-test-rule-set-1';
const override_2 = true;
const rules_2 = [
{{
property: 'p3',
type: 'PERCENTAGE',
},
{
property: 'p4',
type: 'EQUALS',
equalityScores: [
{
value: 'v1',
score: 1,
},
{
value: 'v2',
score: 2,
},
],
},
];
await danubeClient.setRules(
rulesId_2,
override_2,
rules_2,
);
const savedRulesSets = await danubeClient.getRules();
}
runTest();
// Output retrieved rules-sets.
console.log(savedRulesSets);
/*
[
{
id: 'my-sdk-test-rule-set-1',
rules: [
{ property: 'p1', type: 'PERCENTAGE' },
{ property: 'p2', type: 'PERCENTAGE' }
],
},
{
id: 'my-sdk-test-rule-set-2',
rules: [
{ property: 'p3', type: 'PERCENTAGE' },
{
property: 'p4',
type: 'EQUALS',
equalityScores: [
{ value: 'v1', score: 1 },
{ value: 'v2', score: 2 }
]
}
]
}
]
*/