2 releases

0.1.1 Oct 3, 2024
0.1.0 Oct 2, 2024

#123 in Authentication

Download history 74/week @ 2024-09-26 229/week @ 2024-10-03 10/week @ 2024-10-10

313 downloads per month

GPL-3.0-only

230KB
7K SLoC

Dropbox for Rust

Unofficial Dropbox API SDK for Rust

This crate provides a simple and idiomatic Rust interface to interact with the Dropbox API. It supports common Dropbox operations such as file uploads, downloads, and handling OAuth2 tokens. This SDK is asynchronous and integrates well with Rust's async ecosystem, utilizing tokio.

Features

  • Partial support for Dropbox API v2, planned full support.
  • Token authentication.
  • Async and sync API calls.

Supported Endpoints

The following Dropbox API categories have support in the SDK:

  • account
  • auth
  • check
  • contacts
  • file_properties
  • file_requests

Planned:

  • files, sharing, users

Full support for all Dropbox API endpoints is coming soon!

Installation

Add the following to your Cargo.toml:

[dependencies]
rusty_dropbox_sdk = "0.1"
tokio = { version = "1", features = ["full"] }

Usage

Here's a basic example showing how to revoke an OAuth2 token.

Sync Example

use dropbox_api::api;
use dropbox_api::api::Service;

fn main() {
    let request = api::auth::token_revoke::TokenRevokeRequest {
        access_token: "your_access_token",
        payload: None,
    };

    match Service::call_sync(&request) {
        Ok(Some(result)) => println!("Token revoked: {:?}", result),
        _ => println!("Failed to revoke token or connection not present"),
    }
}

Async Example

use dropbox_api::api;
use tokio;

#[tokio::main]
async fn main() {
    let request = api::auth::token_revoke::TokenRevokeRequest {
        access_token: "your_access_token",
        payload: None,
    };

    match request.call().await {
        Ok(result) => println!("Token revoked: {:?}", result),
        Err(e) => println!("Error: {:?}", e),
    }
}

Advanced Usage

Here’s an advanced example of creating a file request using Dropbox API:

use dropbox_api::api::file_requests::{CreateFileRequestArgs, FileRequestDeadline};
use dropbox_api::api::Service;
use chrono::DateTime;

#[tokio::main]
async fn main() {
    let request = api::file_requests::create::CreateFileRequest {
        access_token: "your_access_token",
        payload: Some(CreateFileRequestArgs {
            title: "File Request".to_string(),
            destination: "/path/to/destination".to_string(),
            deadline: Some(FileRequestDeadline {
                deadline: DateTime::from_timestamp_millis(1690000000000).unwrap(),
                allow_late_uploads: None,
            }),
            open: false,
            description: Some("A request for a file.".to_string()),
            video_project_id: None,
        }),
    };

    match request.call().await {
        Ok(result) => println!("File request created: {:?}", result),
        Err(e) => println!("Error: {:?}", e),
    }
}

Running Tests

To run integration tests, use the following command:

cargo test --test '*'

To run local tests, use following commands:

cargo test --features "test-utils"

Contributing

This is an unofficial release of the Dropbox API SDK for Rust. Contributions and issues are welcome. Please follow the standard GitHub flow for contributions.

License

This project is licensed under the GNU General Public License v3.0

Dependencies

~11–23MB
~347K SLoC