Crates.io | proxer |
lib.rs | proxer |
version | 0.3.5 |
source | src |
created_at | 2017-10-08 18:27:56.163681 |
updated_at | 2018-02-18 18:19:16.901618 |
description | Access the ProxerMe API with Rust |
homepage | https://0x000.net/proxer-rs |
repository | https://github.com/cuechan/proxer-rs |
max_upload_size | |
id | 34902 |
size | 1,180,718 |
Access proxer.me with rust
You can find all examples in the ./examples
directory and run these with cargo run --example <example-name>
.
However, here is a small summary:
Making requests is fairly simple:
let prxr = proxer::Client::new("yourapikey");
// ...or load the api-key from an environment variable
let prxr = proxer::Client::with_env_key("PROXER_API_KEY");
// everything is strong typed. You can't pass wrong parameters
let req = api::info::GetFullEntry { id: 53 };
// execute the request
let res = prxr.execute(req).unwrap();
// check the response
match res {
Ok(data) => println!("{:#?}", data),
Err(e) => {
match e {
error::Error::Api(k) => panic!("API error: {}", k),
error::Error::Json(k) => panic!("something is wrong: ", k),
error::Error::Http => panic!("interwebs error"),
error::Error::Unknown => panic!("i dont know what happened"),
}
}
}
This example creates a api object and fetches the full data for an entry
The library is as strong typed as possible (which is a good thing for guaranteeing type safety).
It tries to be a 1:1 wrapper to the api while providing some nice tweaks like Iterator
s for pageable endpoints.
let prxr = Client::with_env_key("PROXER_API_KEY").unwrap();
let req = api::info::GetComments {
id: 53,
p: None,
limit: Some(100),
sort: None,
};
// create a pager(`Iterator`) for the request
let pager = req.pager(prxr);
// iterate over the list
for comment in pager {
// Now, new comments are automagically fetched when the end of a page is reached
// there is still some error handling
let comment = comment.expect("something went wrong");
println!("{}: {}", comment.username, comment.rating);
}