use super::{configuration, Error};
use crate::{apis::ResponseContent, models};
use reqwest::StatusCode;
use serde::{de, Deserialize, Deserializer, Serialize};
#[derive(Clone, Debug)]
pub struct ChangePasswordParams {
pub change_password: models::ChangePassword,
}
impl ChangePasswordParams {
pub fn new(change_password: models::ChangePassword) -> Self {
Self { change_password }
}
}
#[derive(Clone, Debug)]
pub struct GetBankItemsParams {
pub item_code: Option<String>,
pub page: Option<u32>,
pub size: Option<u32>,
}
impl GetBankItemsParams {
pub fn new(item_code: Option<String>, page: Option<u32>, size: Option<u32>) -> Self {
Self {
item_code,
page,
size,
}
}
}
#[derive(Clone, Debug)]
pub struct GetGeSellHistoryParams {
pub id: Option<String>,
pub code: Option<String>,
pub page: Option<u32>,
pub size: Option<u32>,
}
impl GetGeSellHistoryParams {
pub fn new(
id: Option<String>,
code: Option<String>,
page: Option<u32>,
size: Option<u32>,
) -> Self {
Self {
id,
code,
page,
size,
}
}
}
#[derive(Clone, Debug)]
pub struct GetGeSellOrdersParams {
pub code: Option<String>,
pub page: Option<u32>,
pub size: Option<u32>,
}
impl GetGeSellOrdersParams {
pub fn new(code: Option<String>, page: Option<u32>, size: Option<u32>) -> Self {
Self { code, page, size }
}
}
#[derive(Debug, Clone, Serialize)]
#[serde(untagged)]
pub enum ChangePasswordError {
Status458(models::ErrorResponseSchema),
Status459(models::ErrorResponseSchema),
Status422(models::ErrorResponseSchema),
}
impl<'de> Deserialize<'de> for ChangePasswordError {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
match raw.error.code {
458 => Ok(Self::Status458(raw)),
459 => Ok(Self::Status459(raw)),
422 => Ok(Self::Status422(raw)),
_ => Err(de::Error::custom(format!(
"Unexpected error code: {}",
raw.error.code
))),
}
}
}
#[derive(Debug, Clone, Serialize)]
#[serde(untagged)]
pub enum GetAccountDetailsError {}
impl<'de> Deserialize<'de> for GetAccountDetailsError {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
Err(de::Error::custom(format!(
"Unexpected error code: {}",
raw.error.code
)))
}
}
#[derive(Debug, Clone, Serialize)]
#[serde(untagged)]
pub enum GetBankDetailsError {}
impl<'de> Deserialize<'de> for GetBankDetailsError {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
Err(de::Error::custom(format!(
"Unexpected error code: {}",
raw.error.code
)))
}
}
#[derive(Debug, Clone, Serialize)]
#[serde(untagged)]
pub enum GetBankItemsError {}
impl<'de> Deserialize<'de> for GetBankItemsError {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
Err(de::Error::custom(format!(
"Unexpected error code: {}",
raw.error.code
)))
}
}
#[derive(Debug, Clone, Serialize)]
#[serde(untagged)]
pub enum GetGeSellHistoryError {}
impl<'de> Deserialize<'de> for GetGeSellHistoryError {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
Err(de::Error::custom(format!(
"Unexpected error code: {}",
raw.error.code
)))
}
}
#[derive(Debug, Clone, Serialize)]
#[serde(untagged)]
pub enum GetGeSellOrdersError {}
impl<'de> Deserialize<'de> for GetGeSellOrdersError {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let raw = models::ErrorResponseSchema::deserialize(deserializer)?;
Err(de::Error::custom(format!(
"Unexpected error code: {}",
raw.error.code
)))
}
}
pub async fn change_password(
configuration: &configuration::Configuration,
params: ChangePasswordParams,
) -> Result<models::ResponseSchema, Error<ChangePasswordError>> {
let local_var_configuration = configuration;
let change_password = params.change_password;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/my/change_password", local_var_configuration.base_path);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
local_var_req_builder = local_var_req_builder.json(&change_password);
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<ChangePasswordError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
pub async fn get_account_details(
configuration: &configuration::Configuration,
) -> Result<models::MyAccountDetailsSchema, Error<GetAccountDetailsError>> {
let local_var_configuration = configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/my/details", local_var_configuration.base_path);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<GetAccountDetailsError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
pub async fn get_bank_details(
configuration: &configuration::Configuration,
) -> Result<models::BankResponseSchema, Error<GetBankDetailsError>> {
let local_var_configuration = configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/my/bank", local_var_configuration.base_path);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<GetBankDetailsError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
pub async fn get_bank_items(
configuration: &configuration::Configuration,
params: GetBankItemsParams,
) -> Result<models::DataPageSimpleItemSchema, Error<GetBankItemsError>> {
let local_var_configuration = configuration;
let item_code = params.item_code;
let page = params.page;
let size = params.size;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/my/bank/items", local_var_configuration.base_path);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
if let Some(ref local_var_str) = item_code {
local_var_req_builder =
local_var_req_builder.query(&[("item_code", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = page {
local_var_req_builder =
local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = size {
local_var_req_builder =
local_var_req_builder.query(&[("size", &local_var_str.to_string())]);
}
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<GetBankItemsError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
pub async fn get_ge_sell_history(
configuration: &configuration::Configuration,
params: GetGeSellHistoryParams,
) -> Result<models::DataPageGeOrderHistorySchema, Error<GetGeSellHistoryError>> {
let local_var_configuration = configuration;
let id = params.id;
let code = params.code;
let page = params.page;
let size = params.size;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/my/grandexchange/history",
local_var_configuration.base_path
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
if let Some(ref local_var_str) = id {
local_var_req_builder = local_var_req_builder.query(&[("id", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = code {
local_var_req_builder =
local_var_req_builder.query(&[("code", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = page {
local_var_req_builder =
local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = size {
local_var_req_builder =
local_var_req_builder.query(&[("size", &local_var_str.to_string())]);
}
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<GetGeSellHistoryError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
pub async fn get_ge_sell_orders(
configuration: &configuration::Configuration,
params: GetGeSellOrdersParams,
) -> Result<models::DataPageGeOrderSchema, Error<GetGeSellOrdersError>> {
let local_var_configuration = configuration;
let code = params.code;
let page = params.page;
let size = params.size;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/my/grandexchange/orders",
local_var_configuration.base_path
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
if let Some(ref local_var_str) = code {
local_var_req_builder =
local_var_req_builder.query(&[("code", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = page {
local_var_req_builder =
local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = size {
local_var_req_builder =
local_var_req_builder.query(&[("size", &local_var_str.to_string())]);
}
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<GetGeSellOrdersError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}