1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//! This module contains the various end point definitions for stellar's horizon
//! API server. An endpoint is a struct that implements the `IntoRequest`, and `TryFromUri`
//! traits.  Endpoints can be given to a client for fetching into a response.
//!
//! # Example
//! ```
//! use stellar_client::sync::Client;
//! use stellar_client::endpoint::transaction;
//!
//! // Instantiate a client connected to the horizon test network
//! let client = Client::horizon_test().unwrap();
//!
//! // Create a struct that represents the "all" transactions endpoint
//! let txns = transaction::All::default();
//!
//! // Give the endpoint to the client and receive back a `Records` struct
//! // that provides the resulting set of transactions
//! let all_txns = client.request(txns).unwrap();
//! ```
use error::Result;
use http;
use serde::de::DeserializeOwned;

#[macro_use]
mod cursor;
#[macro_use]
mod limit;
#[macro_use]
mod order;

mod records;

pub mod account;
pub mod asset;
pub mod effect;
pub mod ledger;
pub mod operation;
pub mod orderbook;
pub mod payment;
pub mod trade;
pub mod transaction;

pub use self::cursor::Cursor;
pub use self::limit::Limit;
pub use self::order::{Direction, Order, ParseDirectionError};
pub use self::records::Records;

/// Represents the body of a request to an IntoRequest.
#[derive(Debug)]
pub enum Body {
    /// Declares that the endpoint does not have a body.
    None,
}

/// Declares the definition of a stellar endpoint and the return type.
pub trait IntoRequest {
    /// The deserializable type that is expected to come back from the stellar server.
    type Response: DeserializeOwned;
    /// The request body to be sent to stellar. Generally this is just a `()` unit.

    /// Converts the implementing struct into an http request.
    fn into_request(self, host: &str) -> Result<http::Request<Body>>;
}