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
use reqwest::header;

pub(crate) mod collection;
pub(crate) mod tensorswap;
pub(crate) mod user;

mod constants;

pub use crate::{
    collection::collection_mints_query::{CollectionMintsFilters, CollectionMintsSortBy},
    user::user_active_listings_query::{ActiveListingsCursorInputV2, ActiveListingsSortBy},
};

impl Default for CollectionMintsSortBy {
    fn default() -> Self {
        Self::RankHrttAsc
    }
}

#[derive(Debug, Clone)]
pub struct TensorTradeClient {
    pub(crate) client: reqwest::Client,
}

impl TensorTradeClient {
    pub fn new(api_key: &str) -> anyhow::Result<Self> {
        let mut headers = header::HeaderMap::new();
        headers.insert(
            header::CONTENT_TYPE,
            header::HeaderValue::from_static("application/json"),
        );
        headers.insert("X-TENSOR-API-KEY", header::HeaderValue::from_str(&api_key)?);

        let client = reqwest::Client::builder()
            .default_headers(headers)
            .build()?;

        Ok(Self { client })
    }

    pub fn collection(&self) -> collection::Collection {
        collection::Collection(self)
    }

    pub fn user(&self) -> user::User {
        user::User(self)
    }

    pub fn tensorswap(&self) -> tensorswap::Tensorswap {
        tensorswap::Tensorswap(self)
    }
}