Giter Club home page Giter Club logo

rustydav_async's Introduction

rustydav

Async
Add function: parse_xml to file list, see file.rs
Warning: This is deeply customized for my personal need of read Synology file

Usage

use webdavc::client;
use webdavc::file::parse_xml;
use webdavc::prelude::*;

async fn scan() -> Result<(), String> {
    let webdav_client = client::Client::init("username", "pwd");
    let base_url = "https://yourwebdav.com";
    let resp = webdav_client
        .list(base_url, "1")
        .await
        .map_err(|e| e.to_string())?;
    let resp = resp
        .text()
        .await
        .map_err(|e| e.to_string())
        .and_then(|x| parse_xml(&x)).and_then(|x|
        // remove first element if any
        if x.len() > 0 {
            Ok(x[1..].to_vec())
        } else {
            Ok(x)
        }
        )?;
    println!("{:?}", resp);
    Ok(())
}

Implementation of webdav requests in rust

This is a small library written in rust and inspired by hyperdav and uses reqwest library as the base.

This library can be used to make calls to webdav server.

Supported methods are:

  • get
  • put
  • delete
  • unzip
  • mkcol
  • mv
  • list

Changelog

Example

Small example on how to use this library

Include rustydav as a dependency

[dependencies]
rustydav = "0.1.3"

Then add this to your code

extern crate rustydav;

use rustydav::client;
use rustydav::prelude::*;

Short examples of call methods

// Every method will return a Result<Response, Error>

if (result.is_ok() {
    // the method completed with success
} else {
    // somenting when wrong
}

// Create the client
let webdav_client = client::Client::init(/*username*/, /*password*/);

// Get some file from server
// The result will contain the file data
let result = webdav_client.get(/*absolute url to the server file location*/);

// Upload a file to server. It can be any type of file as long as it is transformed to a vector of bytes (Vec<u8>).
// This can be achieved with std::fs::File or zip-rs for sending zip files.
let result = webdav_client.put(/*Vec<u8>*/, /*absolute path to the server file location*/);

// Delete a remote file from the server
let result = webdav_client.delete(/*absolute path to the file on the server*/);

// Unzip a zip archive on the server
let result = webdav_client.unzip(/*absolute path to the zip archive on the server*/);

// Create a new directory on server
let result = webdav_client.mkcol(/*absolute path to the server where to create the new folder*/);

// Rename or move a file / folder / zip on the server
// If the file location changes it will move the file, if only the file name changes it will rename it.
let result = webdav_client.mv(/*absolute path on the server for old file location/name*/, /*absolute on the server for new file location/name*/);

// List files and folders at the given path on the server
// Depth of "0" applies only to the resource, "1" to the resource and it's children, "infinity" to the resource and all it's children recursively
// The result will contain an xml list with the remote folder contents.
let result = webdav_client.list(/*absolute path on the server to list the files*/, /*depth being "0", "1" or "infinity"*/);

For some description about them please see the client.rs file.

rustydav_async's People

Contributors

andreinbio avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

mlthlschr

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.