6 releases
Uses old Rust 2015
0.2.0 | Oct 1, 2018 |
---|---|
0.1.4 | Mar 30, 2018 |
#761 in Images
42KB
840 lines
pixiv
Unofficial rust library for the Pixiv API.
Check out the documentation for some examples and usage.
Contributing
Any help is appreciated! The author of this crate is REALLY new to rust (@fairingrey), so feel free to give any helpful advice or open up an issue on what this project might need.
lib.rs
:
pixiv
The pixiv
crate provides an unofficial library for the Pixiv API.
This crate uses the crates reqwest
and serde_json
.
Authentication
To authenticate, you need to create a new Pixiv
struct and pass in a reqwest::Client
, then login with your username and password.
let client = Client::new();
let mut pixiv: Pixiv = Pixiv::new(&client);
pixiv.login("username", "password");
If and when your access token does expire, you should use the refresh_auth()
or login()
methods.
Alternatively, if you have your access token and/or request token cached somwhere for you to reuse:
let client = Client::new();
let mut pixiv: Pixiv = Pixiv::new(&client);
let my_access_token = String::from("supersecret");
*pixiv.access_token_mut() = my_access_token;
Accessor methods such as access_token()
and refresh_token()
are provided for these purposes.
Making a Request
This crate relies on the builder pattern for using and modifying a request. A typical request may look like this:
let work: Value = pixiv
.work(66024340)
.send()
.expect("Request failed.")
.json()
.expect("Failed to parse as json.");
A more complicated response may look like this:
let following_works: Value = pixiv
.following_works()
.image_sizes(&["large"])
.include_sanity_level(false)
.send()
.expect("Request failed.")
.json()
.expect("Failed to parse as json.");
Since work
is of type serde_json::Value
, it's up to you to figure out how you want to parse this response for your program.
You may want to refer here for what a response from Pixiv may look like.
Future Support (Maybe)
- More examples!
- More versatile support for handling and parsing responses (instead of just the raw response)
- More API support (although pixiv doesn't document their public API anywhere to my knowledge...)
Dependencies
~20MB
~441K SLoC