通过代码调用的方式
上面的通过配置的方式使用 Point Up 需要对应的 Blocklet 已经支持了 Point Up 的能力。实现这些能力也很简单,只需要通过 Blocklet SDK 进行特定能力的 API 调用即可实现。如果你也在开发自己的 Blocklet,并且想把 Point Up 的积分能力融入到你的 Blocklet 业务逻辑中,那么下面的文档将对你非常的有帮助。
接下来,我们将会将 Point Up 中可以被其他 Blocklet 组合调用的 API 一一罗列出来。
1 为指定的用户 DID 基于指定的规则新增积分#
请求示例代码:
const component = require('@blocklet/sdk/lib/component');
// ...
const { data } = await component.call({
name: 'z2qa2ZST7Frp8w1XGqyw9v85u12R3mBbB2oaA',
path: '/api/add-point-cc',
data: { ruleId: 'Add Point Rule ID', userDID: 'User DID' },
});
成功返回示例:
{
id: 'xxxx',
type: 0,
points: x,
userDID: 'User DID',
ruleId: 'Add Point Rule ID',
preRecordId: '',
isUndone: false
}
可以结合自己的逻辑,将 id 和其他有用的信息存储好备用。
2 基于积分领取记录撤销一次积分领取#
请求示例代码:
const component = require('@blocklet/sdk/lib/component');
// ...
const { data } = await component.call({
name: 'z2qa2ZST7Frp8w1XGqyw9v85u12R3mBbB2oaA',
path: '/api/undo-add-point-cc',
data: { ruleId: 'Add Point Rule ID', userDID: 'User DID', addPointRecordId: 'Add Point Record ID' }, // This addPointRecordId is saved from add-point-cc call
});
成功返回示例:
{
id: 'xxxx',
type: 2,
points: -x,
userDID: 'User DID',
ruleId: 'Add Point Rule ID',
preRecordId: 'xxxx',
isUndone: false
}
可以结合自己的逻辑,将 id 和其他有用的信息存储好备用。
3 为指定的用户 DID 基于指定的规则消费积分#
请求示例代码:
const component = require('@blocklet/sdk/lib/component');
// ...
const { data } = await component.call({
name: 'z2qa2ZST7Frp8w1XGqyw9v85u12R3mBbB2oaA',
path: '/api/consume-point-cc',
data: { ruleId: 'Consume Point Rule ID', userDID: 'User DID' },
});
成功返回示例:
{
id: 'xxxx',
type: 1,
points: x,
userDID: 'User DID',
ruleId: 'Consume Point Rule ID',
preRecordId: '',
isUndone: false
}
可以结合自己的逻辑,将 id 和其他有用的信息存储好备用。
4 查询一个新增积分规则的详情#
请求示例代码:
const component = require('@blocklet/sdk/lib/component');
// ...
const { data } = await component.call({
name: 'z2qa2ZST7Frp8w1XGqyw9v85u12R3mBbB2oaA',
path: `/api/get-add-point-rule-info-cc/${id}`,
method: 'GET',
data: { },
});
成功返回示例:
{
id: 'xxxx',
points: x,
isLimited: x,
periodicType: x,
maxTimes: x,
desc: 'desc',
title: 'title',
isDisabled: x,
addedBy: 'Creator DID',
tTranslation: 'Title translation',
}
5 查询一个使用积分规则的详情#
请求示例代码:
const component = require('@blocklet/sdk/lib/component');
// ...
const { data } = await component.call({
name: 'z2qa2ZST7Frp8w1XGqyw9v85u12R3mBbB2oaA',
path: `/api/get-consume-point-rule-info-cc/${id}`,
method: 'GET',
data: { },
});
成功返回示例:
{
id: 'xxxx',
points: x,
desc: 'desc',
title: 'title',
isDisabled: x,
addedBy: 'Creator DID',
tTranslation: 'Title translation',
}
6 查询一批用户的积分概况#
请求示例代码:
const component = require('@blocklet/sdk/lib/component');
// ...
const { data } = await component.call({
name: 'z2qa2ZST7Frp8w1XGqyw9v85u12R3mBbB2oaA',
path: '/api/batch-get-user-points-info-cc',
params: { userDID: 'xxx,xxx,xxx' },
method: 'GET',
});
成功返回示例:
[
{
did: 'xxxx',
maxPoints: x,
unUsedPoints: x,
},
{
did: 'xxxx',
maxPoints: x,
unUsedPoints: x,
},
//...
]
7 查询某个用户的积分概况#
请求示例代码:
const component = require('@blocklet/sdk/lib/component');
// ...
const { data } = await component.call({
name: 'z2qa2ZST7Frp8w1XGqyw9v85u12R3mBbB2oaA',
path: `/api/get-user-points-info-cc/${userDID}`,
data: { },
method: 'GET',
});
成功返回示例:
{
did: 'xxxx',
maxPoints: x,
unUsedPoints: x,
}
8 为指定的用户 DID 领取徽章#
请求示例代码:
const component = require('@blocklet/sdk/lib/component');
// ...
const { data } = await component.call({
name: 'z2qa2ZST7Frp8w1XGqyw9v85u12R3mBbB2oaA',
path: '/api/add-badge-cc',
data: { ruleId: 'Badge Rule ID', userDID: 'User DID'},
method: 'POST',
});
成功返回示例:
{
id: 'xxxx',
userDID: 'User DID',
ruleId: 'Badge Rule ID',
}