Crate jsonbank

Source
Expand description

§JsonBank SDK for Rust

Links: github | crates.io | docs.rs

§Initialization

The JsonBank struct can be initialized with or without api keys. Api Keys are only required when you want to access protected/private documents.

§Without Api Keys

Using this json file from jsonbank

use jsonbank::{JsonBank, JsonValue};

fn main() {
    let jsb = JsonBank::new_without_config();

    // get public content
    let data: JsonValue = jsb.get_content("jsonbank/sdk-test/index").unwrap();
    assert_eq!(data["author"], "jsonbank")
}

§With Api Keys

To get your api keys, visit jsonbank.io and create an account.

use jsonbank::{JsonBank, InitConfig, Keys};

fn main() {
    let mut  jsb = JsonBank::new(InitConfig {
        host: None, // use default host
        keys: Some(Keys {
            public: Some("Your public key".to_string()),
            private: Some("Your private key".to_string()),
        }),
    });

    // authenticate the api keys (optional)
    if !jsb.authenticate().is_ok() {
        panic!("Authentication failed");
     }
}

§Usage

Basic examples to get you started.

Using these json files:

use jsonbank::{JsonBank, JsonValue, JsonObject, JsonArray};

fn main() {
    /// initialize jsonbank
    let jsb = JsonBank::new_without_config();

    /// Get json object
    let data: JsonObject = jsb.get_content("jsonbank/sdk-test/index.json").unwrap();
    assert_eq!(data["author"], "jsonbank");

    /// Get json array
    let data: JsonArray = jsb.get_github_content("jsonbankio/documentation/github-test-array.json").unwrap();
    assert_eq!(data[0], 1);
    assert_eq!(data[1], "MultiType Array");
    assert_eq!(data[2].as_object().unwrap()["name"], "github-test-array.json");

    /// Get json value (when you don't know the exact type)
    let data: JsonValue = jsb.get_content("jsonbank/sdk-test/index.json").unwrap();
    if data.is_object() {
       assert_eq!(data["author"], "jsonbank");
    } else {
       panic!("Expected json object");
    }
}

§Extra Info

The struct JsonBank is well documented, so you can check the docs for more info.

Modules§

error
Package error module
structs
Package structs

Structs§

Config
The configuration struct
InitConfig
Minimal Config struct needed to initialize.
JsonBank
JsonBank SDK Instance
Keys
Holds the public and private keys

Constants§

DEFAULT_HOST
The default host
JSONBANK
The keyword jsonbank
JSONBANK_IO
The keyword jsonbankio

Type Aliases§

JsonArray
An alias for Vec<JsonValue>
JsonObject
An alias for HashMap<String, JsonValue>
JsonValue
An alias for serde_json::Value