use crate::client::SharedClient;
use anyhow::Result;
use reqwest::Method;
pub struct WithdrawsJpy {
client: SharedClient,
}
pub mod model {
use crate::types::*;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use serde_with::{serde_as, DisplayFromStr};
#[derive(Debug, Serialize, Deserialize)]
pub struct BankAccounts {
pub success: bool,
pub data: Vec<BankAccount>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct BankAccount {
pub id: IdType,
pub bank_name: String,
pub branch_name: String,
pub bank_account_type: String,
pub number: String,
pub name: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Withdraws {
pub success: bool,
pub pagination: Pagination,
pub data: Vec<Withdraw>,
}
#[serde_as]
#[derive(Debug, Serialize, Deserialize)]
pub struct Withdraw {
pub id: IdType,
pub status: String,
#[serde_as(as = "DisplayFromStr")]
pub amount: PriceType,
pub currency: String,
pub created_at: DateTime<Utc>,
pub bank_account_id: IdType,
#[serde_as(as = "DisplayFromStr")]
pub fee: PriceType,
pub is_fast: bool,
}
}
impl WithdrawsJpy {
pub fn new(client: SharedClient) -> Self {
Self { client }
}
const USE_AUTH: bool = true;
pub async fn bank_accounts(&mut self) -> Result<model::BankAccounts> {
self.client
.borrow_mut()
.request_and_get_json(Method::GET, "/api/bank_accounts", None, Self::USE_AUTH)
.await
}
pub async fn withdraws(&mut self) -> Result<model::Withdraws> {
self.client
.borrow_mut()
.request_and_get_json(Method::GET, "/api/withdraws", None, Self::USE_AUTH)
.await
}
}
#[cfg(test)]
mod tests {
use crate::Coincheck;
#[tokio::test]
#[serial_test::serial]
async fn private_withdraw_jpy_api() {
let mut coincheck = Coincheck::new_with_env_keys();
let api = &mut coincheck.private.withdraws_jpy;
assert!(api.bank_accounts().await.is_ok());
assert!(api.withdraws().await.is_ok());
}
}