1 unstable release

0.1.0 Feb 24, 2024

#146 in #api-wrapper

MIT license

12KB
151 lines

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.

Dependencies

~4–16MB
~220K SLoC