shuttle-sdk 0.1.0

Stellar Horizon Server client.
Documentation
use std::convert::AsRef;
use serde::de::DeserializeOwned;
use reqwest::{Client, RequestBuilder, Response, Url};
use error::Result;

#[derive(Debug, Clone)]
pub struct InnerClient {
    client: Client,
    horizon_url: Url,
}

impl InnerClient {
    pub fn new(horizon_url: Url) -> Result<InnerClient> {
        let client = Client::builder().build()?;
        Ok(InnerClient {
            client,
            horizon_url,
        })
    }

    pub fn get<S>(&self, path: &[S]) -> Result<RequestBuilder>
    where
        S: AsRef<str>,
    {
        let mut url = self.horizon_url.clone();
        url.path_segments_mut()?.extend(path);
        Ok(self.client.get(url))
    }

    pub fn post<S>(&self, path: &[S]) -> Result<RequestBuilder>
    where
        S: AsRef<str>,
    {
        let mut url = self.horizon_url.clone();
        url.path_segments_mut()?.extend(path);
        Ok(self.client.post(url))
    }
}

pub fn parse_response<T: DeserializeOwned>(response: &mut Response) -> Result<T> {
    if response.status().is_success() {
        Ok(response.json()?)
    } else {
        unimplemented!()
    }
}