Crate yupdates

Source
Expand description

§Yupdates Rust SDK

The Yupdates Rust SDK lets you easily use the Yupdates API from your own software and scripts.

The code is hosted on GitHub. Also see the Yupdates Python SDK.

The api module provides a low-level functions that wrap calls to the HTTP+JSON API, serializing and deserializing the requests and responses.

The clients module provides an async client that is more convenient, and clients::sync provides a synchronous version of the client that hides any need to set up an async runtime.

The following examples require setting the YUPDATES_API_TOKEN environment variable.

Synchronous client example:

use yupdates::api::YupdatesV0;
use yupdates::clients::sync::new_sync_client;
use yupdates::errors::Error;

fn main() -> Result<(), Error> {
    let feed_id = "02fb24a4478462a4491067224b66d9a8b2338ddca2737";
    let yup = new_sync_client()?;
    for item in yup.read_items(feed_id)? {
        println!("Title: {}", item.title);
    }
    Ok(())
}

The following asynchronous client example requires adding tokio to your Cargo.toml. For example: tokio = { version = "1", features = ["macros"] }

use yupdates::clients::new_async_client;
use yupdates::errors::Error;

#[tokio::main]
async fn main() -> Result<(), Error> {
    let feed_id = "02fb24a4478462a4491067224b66d9a8b2338ddca2737";
    let yup = new_async_client()?;
    for item in yup.read_items(feed_id).await? {
        println!("Title: {}", item.title);
    }
    Ok(())
}

See the README. The SDK is distributed under the MIT license, see LICENSE.

Modules§

api
Functions to interact with the API directly (typically, you would use the client wrappers found in the crate::clients module)
clients
Wrappers that allow you set up the configurations once and then make many calls
errors
Error and result types
models
Clean structs for API objects, marshalled to and from JSON via serde

Constants§

X_AUTH_TOKEN_HEADER
The HTTP header we need on every API call
YUPDATES_API_TOKEN
Environment variable to consult for the API token (you can bypass this by passing the token directly to certain functions)
YUPDATES_API_URL
Environment variable to consult for the base API URL. It’s not usually needed: you would typically only use this to exercise against an alternative API endpoint, or if you wanted to downgrade API versions in the future (right now, there is only /api/v0/).
YUPDATES_DEFAULT_API_URL
The default base URL

Functions§

api_token
Retrieve the API token from the environment.
env_or_default_url
Retrieve the API URL from the environment or use the default.
normalize_item_time
Accept many forms of item time, validate it, and return a normalized version.
normalize_item_time_ms
This is normalize_item_time for when you are using integer timestamps.