Expand description
§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§
Modules§
- header
- HTTP header types
Structs§
- Auth
Error - Error returned on failure to authorize with pixiv.
- Header
Map - 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
PixivRequestBuilder
. - Pixiv
Request - Pixiv request. You can create this using
PixivRequestBuilder::build
. This is for if you wish to inspect the request before sending. - Pixiv
Request Builder - Pixiv request builder. You can create this using any of the provided methods in
Pixiv
, or throughPixivRequestBuilder::new
.
Enums§
- Publicity
- Enum to set publicity param.
- Ranking
Mode - Enum to set ranking mode param.
- Ranking
Type - Enum to set ranking type param.
- Search
Mode - Enum to set search mode param.
- Search
Order - Enum to set search order param.
- Search
Period - Enum to set search period param.