1 Star 0 Fork 0

y-t99 / vika.rust

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

vika.rust

👋 Introduce

🦀 rust for vikadata api. To use this crate, it's good for you to understand some vikadata's concept. for example, space, node, datasheet, view, field, record and soon. You can go here, it's vika office produce manual.

Vikadata is a Commercial version of Open Source APITable which added full enterprise-ready features. Vikadata is the on-line visual database. It means that we can save structured data to vikadata by vikadata api, when we want to make some interesting and fun tools. Instead of using heavy database.

🚀 Using

🌌 Firstly, adding vika_community crate to your dependence.

# Cargo.toml
[dependencies]
vika_community = "0.1.2"
# or
# vika_community = { git = "https://github.com/y-t99/vika.rust.git" }
serde_json = "1.0"

🌠 Importing the crate, and create the vika_client by your vikadata's token.

use vika_community::*;

let vika_client: VIKAClient= VIKAClient::new("your_token".to_string());

🪐 Querying your all spaces.

let spaces: Vec<Space> = vika_client.spaces.query_all().unwrap();
for space in spaces {
    println!(
        "the space's id is {} and name is {}. you {} are the space's admin", 
        space.id, space.name, space.is_admin
    );
}

☁️ You can get the space's all nodes, and query one node's detail information.

let space_id = "spcXxx".to_string();
let node_id = "nodXxx".to_string();
// the space's all nodes
let nodes: Vec<Node> = vika_client
        .spaces.space(&space_id)
        .nodes.query_all()
        .unwrap();
for node in nodes {
    println!(
        "the node info [id: {}, name: {}, type: {}, icon: {}, isFav: {}]. \nthe node's children is: {:?}",
        node.id, node.name, node.node_type, node.icon, node.is_fav, node.children
    );
}
// the specified node
let node: Node = vika_client
        .spaces.space(&space_id)
        .nodes.node(&node_id)
        .unwrap();
println!(
    "the node info: id: {}, name {}, type {}, icon {}, isFav {} \n. the node's children is: {:?}",
    node.id, node.name, node.node_type, node.icon, node.is_fav, node.children
)

🌈 The datasheet's field manager.

use serde_json::Value;

let space_id = "spcXxx".to_string();
let datasheet_id = "dstXxx".to_string();
let fields = vika_client
    .spaces.space(&space_id)
    .datasheets.datasheet(&datasheet_id)
    .fields;
// the new field info
let field_post_req = PostFieldReq::builder()
    .name("name".to_string())
    .as_single_text_req()
    .default_value("default_value".to_string())
    .build();
// the datasheet append the new field
let new_field: PostFieldResp = fields.post(field_post_req).unwrap();
// query the datasheet's all fields info
let fields_value: Vec<Value> = fields.query_all().unwrap();
for field_value in fields_value {
   for field_value in fields_value {
        println!(
            "the field info [id: {}, name: {}, type: {}] \n the field's property: [{}].",
            field_value["id"], field_value["name"], field_value["type"], field_value["property"]
        );
    }
}
// delete field by the field's id
fields.field_id(&new_field.id).delete();

☄️ We can crete the datasheet.

let space_id = "spaceXxx".to_string();
let datasheets = vika_client.spaces.space(&space_id).datasheets;
let field_post_req = PostFieldReq::builder()
    .name("field_name".to_string())
    .as_single_text_req()
    .default_value("default_value".to_string())
    .build();
let datasheet_post_req: PostDatasheetReq = PostDatasheetReq::builder()
    .name("datasheet_name".to_string())
    .description("description".to_string())
    .folder_id("fodXxx".to_string())
    .pre_node_id("dstXxx".to_string())
    .fields(vec![field_post_req])
    .build();
let new_datasheet: PostDatasheetsResp = datasheets.post(datasheet_post_req).unwrap();

✨ Query the datasheet's record.

let space_id = "spcXxx".to_string();
let datasheet_id= "dstXxx".to_string();
let records = vika_client
    .spaces.space(&space_id)
    .datasheets.datasheet(&datasheet_id)
    .records;
let records_req = GetRecordsReq::builder()
    .page_size(1)
    .max_records(1)
    .page_num(1)
    .field_key(FieldID::ID)
    .sort(vec![
        ("fldXxx".to_string(), Sort::DESC)
    ])
    .filter_by_formula("formula".to_string())
    .build();
let records_resp: GetRecordsResp = records.query(records_req).unwrap();
println!(
    "the records' page [current page number.: {}, the page's record size: {}, total number of records that met filter: {}]. \n records: [{:?}]",
    records_resp.page_num, records_resp.page_size, records_resp.total, records_resp.records
)

🛸 Managing the records.

// add records
let filed_map = vec![
    "fldXxx".to_string(),
    "fldYyy".to_string(),
    "fldZzz".to_string(),
];
let record = RecordMap::builder()
    .put_string(&filed_map[0], "value".to_string())
    .put_strings(&filed_map[1], vec!["value".to_string()])
    .build();
let post_records_req = PostRecordsReq::builder()
    .field_key(FieldID::ID)
    .records(vec![record])
    .build();
let post_records_resp: PostRecordsResp = records.post(post_records_req).unwrap();
let record_id = post_records_resp.records[0].record_id.clone();
// update records
let record: RecordMap = RecordMap::builder()
    .record_id(record_id.clone())
    .put_string(&filed_map[2], "value".to_string())
    .build();
let patch_records_req: PatchRecordsReq = PatchRecordsReq::builder()
    .field_key(FieldID::ID)
    .records(vec![record])
    .build();
// delete records
records.delete(vec![record_id.clone()]);

🚚 Waiting & Expecting

🛠️. more manager: view manager

👣. better error reporting

💪. more robust low-level code

🛹. easier API

🦀. more rust

MIT License Copyright (c) 2022 y-t99 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

rust for vika api. 展开 收起
Rust
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Rust
1
https://gitee.com/yuantao99/vika.rust.git
git@gitee.com:yuantao99/vika.rust.git
yuantao99
vika.rust
vika.rust
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891