pasty-rs

Crates.iopasty-rs
lib.rspasty-rs
version0.1.0
sourcesrc
created_at2024-02-24 22:00:36.751777
updated_at2024-02-24 22:00:36.751777
descriptionA low level API wrapper for pasty.
homepage
repositoryhttps://github.com/zekrotja/pasty-rs
max_upload_size
id1151952
size12,096
Ringo Hoffmann (zekroTJA)

documentation

https://docs.rs/pasty-rs

README

pasty-rs

A low level API wrapper for pasty.

cargo add pasty-rs

Because this SDK currently only allows async requests, you might want to install an async runtime like tokio, async-std or smol.

Example Usage

The following example uses tokio as async runtime.

cargo add tokio --features all
use pasty_rs::client::UnauthenticatedClient;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    // Create an API client for unauthenticated requests.
    let client = UnauthenticatedClient::new("https://pasty.lus.pm")?;

    // Create a paste.
    let paste = client.create_paste("hello pasty!", None).await?;
    dbg!(&paste);

    // Store the modification_token of that paste.
    let modification_token = paste.modification_token;

    // Get a paste by id (the one we've created).
    let paste = client.paste(&paste.paste.id).await?;
    dbg!(&paste);

    // Transform the unauthenticated client into an authenticated client
    // using the modification_token of the created paste.
    let client = client.authenticate(&modification_token);

    // Update the previously created paste with the authenticated client.
    client
        .update_paste(&paste.id, "new hello world", None)
        .await?;

    // Retireve the updated posts content.
    let paste = client.inner().paste(&paste.id).await?;
    dbg!(&paste);

    // Delete the created post.
    client.delete_paste(&paste.id).await?;

    Ok(())
}

Limitations

Because this is a somewhat quick and dirty implementation I need for another project, this crate currently has some limitations.

  • Currently only supports async requests.
  • Currently does not support the report paste endpoint.

License

This crate is licensed under the MIT License.

pasty is licensed under the MIT License, (c) 2020 Lukas SP.

Commit count: 0

cargo fmt