pixelast

Crates.iopixelast
lib.rspixelast
version0.1.0
sourcesrc
created_at2018-10-18 07:28:31.926681
updated_at2018-10-18 07:28:31.926681
descriptionA simple Pixela client.
homepage
repositoryhttps://github.com/yamash723/pixelast
max_upload_size
id91313
size35,653
Shuhei Yamashita (yamash723)

documentation

README

pixelast

This library is Pixela client for Rust.

Usage

Add this to your Cargo.toml

[dependencies]
pixelast = "0.1.0"

Example

use pixelast::{PixelaClient, ConsentAnswer, GraphType, GraphColor};

fn main() {
    let res = PixelaClient::create_new_user(
        "username",
        "usertoken",
        ConsentAnswer::Yes,
        ConsentAnswer::Yes
    );

    match res {
        Ok(()) => println!("create new user."),
        Err(v) => panic!("create new user failed. {}", v),
    }

    let client = PixelaClient::new("username", "usertoken");
    client.create_graph("graphid", "graphname", "cal", GraphType::Int, GraphColor::Shibafu).unwrap();

    client.record_pixel("graphid", "20181017", "10").unwrap();
    let svg = client.get_graph_svg("graphid", Some("20181020")).unwrap();
    
    println!("{}", svg);
}

User

// Create new user.
let res = PixelaClient::create_new_user(
    "username",
    "usertoken",
    ConsentAnswer::Yes,
    ConsentAnswer::Yes
);
// Update user token.
let client = PixelaClient::new("username", "usertoken");
client.update_user_token("newusertoken").unwrap();
// Delete user.
let client = PixelaClient::new("username", "usertoken");
client.update_user_token("newusertoken").unwrap();

Graph

// Create graph.
let client = PixelaClient::new("username", "usertoken");
client.create_graph("graphid", "graphname", "cal", GraphType::Int, GraphColor::Shibafu).unwrap();
// Update graph definition.
let client = PixelaClient::new("username", "usertoken");
client.update_graph("graphid", "graphname", "kcal", GraphColor::Shibafu).unwrap();
// Delete graph.
let client = PixelaClient::new("username", "usertoken");
client.delete_graph("graphid").unwrap();
// Get all graphs.
let client = PixelaClient::new("username", "usertoken");
let graphs = client.get_graphs().unwrap();
println!("{:?}", graphs);
// Get graph SVG.
let client = PixelaClient::new("username", "usertoken");
let svg = client.get_graph_svg("graphid", Some("20181020")).unwrap();
// let svg = client.get_graph_svg("graphid", None).unwrap();
println!("{}", svg);
// Get graph SVG.
let client = PixelaClient::new("username", "usertoken");
let svg = client.get_graph_svg("graphid", Some("20181020")).unwrap();
// let svg = client.get_graph_svg("graphid", None).unwrap();
println!("{}", svg);

Pixel

// Record pixel.
let client = PixelaClient::new("username", "usertoken");
client.record_pixel("graphid", "20181016", "10").unwrap();
// Update pixel.
let client = PixelaClient::new("username", "usertoken");
client.update_pixel("graphid", "20181018", "20").unwrap();
// Delete pixel.
let client = PixelaClient::new("username", "usertoken");
client.delete_pixel("graphid", "20181016").unwrap();
// Get pixel quantity.
let client = PixelaClient::new("username", "usertoken");
let pixel = client.get_pixel("graphid", "20181018").unwrap();
println!("{:?}", pixel);
// Increment pixel.
let client = PixelaClient::new("username", "usertoken");
client.increment("graphid").unwrap();
// Decrement pixel.
let client = PixelaClient::new("username", "usertoken");
client.decrement("graphid").unwrap();
Commit count: 3

cargo fmt