Skip to content

(wip) rust wrapper on the tumblr api

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

adrianmgg/tumblr_api

Repository files navigation

active development of this project is mostly on hold

I will still respond to issues/PRs. If you are looking to use this but need a particular endpoint (etc.) implemented in order for this to work for your project, feel free to open an issue asking for it and I will work on that.

Crates.io

tumblr_api

A rust implementation of the Tumblr API.

This is still very much in beta! see Major Planned/Unimplemented Features

Examples

Creating a simple post with the client

use tumblr_api::{npf, client::Client, auth::Credentials};
let client = Client::new(Credentials::new(
    "your consumer key",
    "your consumer secret",
));
client
    .create_post(
        "blog-name",
        vec![npf::ContentBlockText::builder("hello world").build()],
    )
    .send()
    .await?;

Creating a more complex post

use tumblr_api::client::CreatePostState;
// load the image that we'll be attaching to the post.
let my_image = std::fs::read("path/to/my_image.jpg")?;
// (currently, you need to manually create the reqwest::Body to pass in. that'll probably
//  change in a future version.)
let my_image = reqwest::Body::from(my_image);
client
    .create_post(
        "blog-name",
        vec![
            npf::ContentBlockText::builder("hello world").build(),
            npf::ContentBlockImage::builder(vec![npf::MediaObject::builder(
                npf::MediaObjectContent::Identifier("my-image-identifier".into()),
            )
            .build()])
            .build(),
            npf::ContentBlockText::builder("some bold text in a heading")
                .subtype(npf::TextSubtype::Heading1)
                .formatting(vec![npf::InlineFormat {
                    start: 5,
                    end: 9,
                    format: npf::InlineFormatType::Bold,
                }])
                .build(),
        ],
    )
    .add_attachment(my_image, "image/jpeg", "my-image-identifier")
    // add tags to your post
    // (this is currently a string since that's what the underlying api takes.
    //  Being able to pass a Vec<String> instead is a planned feature but hasn't been
    //  implemented quite yet.)
    .tags("tag_1,tag_2,tag_3")
    // add the post to your queue instead of immediately posting it
    .initial_state(CreatePostState::Queue)
    .send()
    .await?;

Modules & Feature Flags

This library is split into multiple modules - client, api, npf, and auth - and each has a feature flag of the same name that controls whether it's enabled. They'll all be enabled by default, but if you only need certain features (e.g. just npf parsing) you can enable just those instead.

Major Planned/Unimplemented Features

  • implement remaining api endpoints (currently it's just post creation plus a couple others)

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

(wip) rust wrapper on the tumblr api

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Languages