diff options
Diffstat (limited to 'ipfs-api')
117 files changed, 0 insertions, 8590 deletions
diff --git a/ipfs-api/src/client/from_uri.rs b/ipfs-api/src/client/from_uri.rs deleted file mode 100644 index be51cd8..0000000 --- a/ipfs-api/src/client/from_uri.rs +++ /dev/null @@ -1,202 +0,0 @@ -// Copyright 2020 rust-ipfs-api Developers -// -// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or -// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or -// http://opensource.org/licenses/MIT>, at your option. This file may not be -// copied, modified, or distributed except according to those terms. -// -use http::uri::{Builder, InvalidUri, PathAndQuery, Scheme, Uri}; -use parity_multiaddr::{self as multiaddr, Multiaddr, Protocol}; -use std::{ - fs, - net::{SocketAddr, SocketAddrV4, SocketAddrV6}, - str::FromStr, -}; - -const VERSION_PATH_V0: &str = "/api/v0"; - -/// Builds the base url path for the Ipfs api. -/// -fn build_base_path(builder: Builder) -> Result<Uri, http::Error> { - builder.path_and_query(VERSION_PATH_V0).build() -} - -pub trait TryFromUri: Sized { - /// Builds a new client from a base URI to the IPFS API. - /// - fn build_with_base_uri(uri: Uri) -> Self; - - /// Creates a new client from a str. - /// - /// Note: This constructor will overwrite the path/query part of the URI. - /// - fn from_str(uri: &str) -> Result<Self, InvalidUri> { - let uri: Uri = uri.parse()?; - let mut parts = uri.into_parts(); - - parts.path_and_query = Some(PathAndQuery::from_static(VERSION_PATH_V0)); - - Ok(Self::build_with_base_uri(Uri::from_parts(parts).unwrap())) - } - - /// Creates a new client from a host name and port. - /// - fn from_host_and_port(scheme: Scheme, host: &str, port: u16) -> Result<Self, http::Error> { - let authority = format!("{}:{}", host, port); - let builder = Builder::new().scheme(scheme).authority(&authority[..]); - - build_base_path(builder).map(Self::build_with_base_uri) - |