Crate pixiv[−][src]
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...)
Re-exports
pub extern crate reqwest; |
pub extern crate http; |
Modules
header |
HTTP header types |
Structs
AuthError |
Error returned on failure to authorize with pixiv. |
HeaderMap |
A set of HTTP headers |
Method |
The Request Method (VERB) |
Pixiv |
Used to authenticate to the Pixiv servers and construct Pixiv requests through methods creating |
PixivRequest |
Pixiv request. You can create this using |
PixivRequestBuilder |
Pixiv request builder. You can create this using any of the provided methods in |
Enums
Publicity |
Enum to set publicity param. |
RankingMode |
Enum to set ranking mode param. |
RankingType |
Enum to set ranking type param. |
SearchMode |
Enum to set search mode param. |
SearchOrder |
Enum to set search order param. |
SearchPeriod |
Enum to set search period param. |