Crates.io | pixelast |
lib.rs | pixelast |
version | 0.1.0 |
source | src |
created_at | 2018-10-18 07:28:31.926681 |
updated_at | 2018-10-18 07:28:31.926681 |
description | A simple Pixela client. |
homepage | |
repository | https://github.com/yamash723/pixelast |
max_upload_size | |
id | 91313 |
size | 35,653 |
This library is Pixela client for Rust.
Add this to your Cargo.toml
[dependencies]
pixelast = "0.1.0"
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();