海拉尔CLI
给 Haller 的命令行界面 。 它也可用于在程序上访问海拉尔.
使用为 Cli
所有后端 Socket API 命令都可以在 CLI 中获取.
已提供分页补全 .
每个命令的结果都存储在 result 变量.
安装
npm install -g @hailer/cli
用法 :
hailer-cli --user [email protected]
示例用途
示例用法:
await api.wall2.new_post({ subject: 'This is a wall post.', text: 'Look, this is a cool wallpost made from the Cli.' })
await api.wall2.remove_post(result._id)
程序用途
登录用户名和密码
这个例子在海拉尔创建了壁柱,再在5秒后取出后退出.
创建一个新的节点项目( N)npm init)或使用已有的。 添加 hailer-cli 作为依赖,使用 npm install @hailer/cli
mkdir my-hailer-app
cd my-hailer-app
npm init
npm install @hailer/cli
创建新文件 run.js 并粘贴以下代码(并使用导入行使用打字符):
// import { Client } from '@hailer/cli'; // Use with typescript
const { Client } = require('@hailer/cli');
const options = {
host: 'https://api.hailer.com',
username: 'set-this',
password: 'set-this',
};
Client.create(options).then(async (client) => {
// Listen to signals from Hailer
client.on('signals', ([name, meta]) => {
// print all signals
console.log('Signal:', name, meta);
});
// Make API request to create a new feed (wall) post.
const post = await client.request('wall2.new_post', [{ subject: 'This is a wall post.', text: 'The content of my post' }]);
console.log('Post created:', post);
// client.disconnect();
}).catch(error => {
console.log('Error:', error);
process.exit(1);
});
设定 username 财务报告和审定财务报表 password 参数为有效的海拉尔账户.
使用浏览器登录到海拉尔并前往 Feed 可以看到剧本在行动.
启动程序 :
node run.js
自动同步函数内部
// import { Client } from '@hailer/cli';
const { Client } = require('@hailer/cli');
// ...
const options = {
host: 'https://api.hailer.com',
username: 'set-this',
password: 'set-this',
};
const client = await Client.create(options).catch(error => { console.log('Error:', error); process.exit(1); });
// Listen to signals from Hailer
client.on('signals', ([name, meta]) => {
// print all signals
console.log('Signal:', name, meta);
});
const post = await client.request('wall2.new_post', [{ subject: 'This is a wall post.', text: 'The content of my post' }]);
console.log('Post created:', post);
client.disconnect();
Haller API 文档
为了了解你对海拉尔API能做什么,访问: