Giter Club home page Giter Club logo

imgchest-rs's Introduction

imgchest-rs

A Rust library to interact with imgchest.com. It implements the entire API while also providing some scraping-based functionality without a login.

Examples

Create a Post

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let client = imgchest::Client::new();
    client.set_token("TOKEN");

    let mut builder = imgchest::CreatePostBuilder::new();
    builder
        .title("test title")
        .nsfw(false)
        .image(imgchest::UploadPostFile::from_path("img.png").await?);
    let post = client.create_post(builder).await?;
    
    dbg!(&post);
    
    Ok(())
}

Get a Post

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let client = imgchest::Client::new();
    
    let post = client
        .get_post("3qe4gdvj4j2")
        .await?;
    
    dbg!(&post);
    
    Ok(())
}

Scrape a Post

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let client = imgchest::Client::new();
    
    let post = client
        .get_scraped_post("https://imgchest.com/p/3qe4gdvj4j2")
        .await?;
    
    dbg!(&post);
    
    Ok(())
}

Design

This library will attempt to completely avoid official API usage. This is because of 2 reasons:

  1. The API requires a login to access public data.
  2. The API has obscene ratelimits, only 60 per hour.

As a result, a design based on scraping will be superior to one based on recommended API usage. If the API is fixed, this library will be likely be reworked to target that instead.

This library implements the API while also attempting to provide scraping-based alternatives where possible.

(Scraped) API objects in this library are tailored to match the official API's as much as possible, though some fields are missing and extra fields are included where needed. Usage of these objects is also noticablely more complicated. As an example, the Post object may not load all images in one API call and may need a second call.

References

imgchest-rs's People

Contributors

dependabot[bot] avatar nathaniel-daniel avatar adumbidiot avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.