Crate pixiv [] [src]

pixiv

The pixiv crate provides an unofficial library for the Pixiv API.

This crate uses the crates reqwest and serde_json.

Logging In

To log in, you need to create a new Pixiv struct and pass in a reqwest::Client as such:

    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.

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...)

Structs

Pixiv

Used to authenticate to the Pixiv servers and construct Pixiv requests through methods creating PixivRequestBuilder.

PixivRequest

Pixiv request. You can create this using PixivRequestBuilder::build. This is for if you wish to inspect the request before sending.

PixivRequestBuilder

Pixiv request builder. You can create this using any of the provided methods in Pixiv, or through PixivRequestBuilder::new.

Enums

Method

Enum for which HTTP method to use.

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.