repositories are added
This commit is contained in:
parent
273bbd69fc
commit
8e182c0a55
8
.vscode/launch.json
vendored
8
.vscode/launch.json
vendored
|
@ -22,8 +22,8 @@
|
|||
"env": {
|
||||
"URL_BROKER": "nats://192.168.50.200:4222",
|
||||
"QUEUE_BROKER": "bet.beteran",
|
||||
"K_SECRET": "bet.beteran",
|
||||
"K_USERNAME": "bet.beteran",
|
||||
"K_SECRET": "c23d770b873b2ce95747abc57052beb0",
|
||||
"K_USERNAME": "Turbo77",
|
||||
},
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}"
|
||||
|
@ -47,8 +47,8 @@
|
|||
"env": {
|
||||
"URL_BROKER": "nats://192.168.50.200:4222",
|
||||
"QUEUE_BROKER": "bet.beteran",
|
||||
"K_SECRET": "bet.beteran",
|
||||
"K_USERNAME": "bet.beteran",
|
||||
"K_SECRET": "c23d770b873b2ce95747abc57052beb0",
|
||||
"K_USERNAME": "Turbo77",
|
||||
},
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}"
|
||||
|
|
|
@ -16,6 +16,7 @@ futures = { version = "0", default-features = false, features = [
|
|||
] }
|
||||
nats = { version = "0" }
|
||||
prost = { version = "0" }
|
||||
reqwest = { version = "0" }
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = { version = "1" }
|
||||
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
|
||||
|
|
7
src/repositories/account/mod.rs
Normal file
7
src/repositories/account/mod.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
//!
|
||||
//!
|
||||
|
||||
///
|
||||
pub mod models;
|
||||
///
|
||||
pub mod repository;
|
59
src/repositories/account/models.rs
Normal file
59
src/repositories/account/models.rs
Normal file
|
@ -0,0 +1,59 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub struct Error {
|
||||
pub code: i64,
|
||||
pub msg: Option<String>,
|
||||
}
|
||||
|
||||
pub struct FindBalanceRequest {
|
||||
pub username: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct FindBalanceResponse {
|
||||
pub code: i64,
|
||||
pub msg: Option<String>,
|
||||
pub balance: i64,
|
||||
pub balance_bota: i64,
|
||||
pub balance_sum: i64,
|
||||
pub companies: i64,
|
||||
}
|
||||
|
||||
pub struct FindPartnerBalanceRequest {}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct FindPartnerBalanceResponse {
|
||||
pub code: i64,
|
||||
pub msg: Option<String>,
|
||||
pub balance: i64,
|
||||
pub balance_bota: i64,
|
||||
}
|
||||
|
||||
pub struct SaveDepositRequest {
|
||||
pub username: String,
|
||||
pub cash_type: Option<String>,
|
||||
pub amount: i64,
|
||||
pub request_key: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct SaveDepositResponse {
|
||||
pub code: i64,
|
||||
pub msg: Option<String>,
|
||||
pub balance: i64,
|
||||
}
|
||||
|
||||
pub struct SaveWithdrawRequest {
|
||||
pub username: String,
|
||||
pub request_key: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct SaveWithdrawResponse {
|
||||
pub code: i64,
|
||||
pub msg: Option<String>,
|
||||
pub balance: i64,
|
||||
pub balance_cash: i64,
|
||||
pub balance_cash_bota: i64,
|
||||
pub amount: i64,
|
||||
}
|
183
src/repositories/account/repository.rs
Normal file
183
src/repositories/account/repository.rs
Normal file
|
@ -0,0 +1,183 @@
|
|||
use super::models;
|
||||
use std::collections::HashMap;
|
||||
|
||||
///
|
||||
pub struct Repository {
|
||||
client: reqwest::Client,
|
||||
k_secret: String,
|
||||
k_username: String,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for Repository {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
f.debug_struct("Repository of api.kgon.identity").finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl Repository {
|
||||
///
|
||||
pub fn new(k_secret: &str, k_username: &str) -> Repository {
|
||||
Repository {
|
||||
client: reqwest::Client::new(),
|
||||
k_secret: k_secret.to_string(),
|
||||
k_username: k_username.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
pub async fn find_balance(
|
||||
&self,
|
||||
data: models::FindBalanceRequest,
|
||||
) -> Result<models::FindBalanceResponse, models::Error> {
|
||||
let mut params = HashMap::new();
|
||||
|
||||
params.insert("username", data.username);
|
||||
|
||||
let res = match self
|
||||
.client
|
||||
.post("https://dev-mw.kgonapi.com/balance")
|
||||
.header(reqwest::header::ACCEPT, "application/json")
|
||||
.header(
|
||||
reqwest::header::CONTENT_TYPE,
|
||||
"application/x-www-form-urlencoded",
|
||||
)
|
||||
.header("k-secret", self.k_secret.as_str())
|
||||
.header("k-username", self.k_username.as_str())
|
||||
.form(¶ms)
|
||||
.send()
|
||||
.await
|
||||
{
|
||||
Ok(res) => res,
|
||||
Err(err) => {
|
||||
return Err(models::Error { code: 0, msg: None });
|
||||
}
|
||||
};
|
||||
|
||||
match res.status() {
|
||||
reqwest::StatusCode::OK => match res.json::<models::FindBalanceResponse>().await {
|
||||
Ok(r) => Ok(r),
|
||||
Err(e) => Err(models::Error { code: 0, msg: None }),
|
||||
},
|
||||
_ => Err(models::Error { code: 0, msg: None }),
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
pub async fn find_partner_balance(
|
||||
&self,
|
||||
data: models::FindPartnerBalanceRequest,
|
||||
) -> Result<models::FindPartnerBalanceResponse, models::Error> {
|
||||
let res = match self
|
||||
.client
|
||||
.post("https://dev-mw.kgonapi.com/partner/balance")
|
||||
.header(reqwest::header::ACCEPT, "application/json")
|
||||
.header(
|
||||
reqwest::header::CONTENT_TYPE,
|
||||
"application/x-www-form-urlencoded",
|
||||
)
|
||||
.header("k-secret", self.k_secret.as_str())
|
||||
.header("k-username", self.k_username.as_str())
|
||||
.send()
|
||||
.await
|
||||
{
|
||||
Ok(res) => res,
|
||||
Err(err) => {
|
||||
return Err(models::Error { code: 0, msg: None });
|
||||
}
|
||||
};
|
||||
|
||||
match res.status() {
|
||||
reqwest::StatusCode::OK => match res.json::<models::FindPartnerBalanceResponse>().await {
|
||||
Ok(r) => Ok(r),
|
||||
Err(e) => Err(models::Error { code: 0, msg: None }),
|
||||
},
|
||||
_ => Err(models::Error { code: 0, msg: None }),
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
pub async fn save_deposit(
|
||||
&self,
|
||||
data: models::SaveDepositRequest,
|
||||
) -> Result<models::SaveDepositResponse, models::Error> {
|
||||
let mut params = HashMap::new();
|
||||
|
||||
params.insert("username", data.username);
|
||||
if let Some(cash_type) = data.cash_type {
|
||||
params.insert("cashType", cash_type);
|
||||
}
|
||||
params.insert("amount", data.amount.to_string());
|
||||
if let Some(request_key) = data.request_key {
|
||||
params.insert("requestKey", request_key);
|
||||
}
|
||||
|
||||
let res = match self
|
||||
.client
|
||||
.post("https://dev-mw.kgonapi.com/deposit")
|
||||
.header(reqwest::header::ACCEPT, "application/json")
|
||||
.header(
|
||||
reqwest::header::CONTENT_TYPE,
|
||||
"application/x-www-form-urlencoded",
|
||||
)
|
||||
.header("k-secret", self.k_secret.as_str())
|
||||
.header("k-username", self.k_username.as_str())
|
||||
.form(¶ms)
|
||||
.send()
|
||||
.await
|
||||
{
|
||||
Ok(res) => res,
|
||||
Err(err) => {
|
||||
return Err(models::Error { code: 0, msg: None });
|
||||
}
|
||||
};
|
||||
|
||||
match res.status() {
|
||||
reqwest::StatusCode::OK => match res.json::<models::SaveDepositResponse>().await {
|
||||
Ok(r) => Ok(r),
|
||||
Err(e) => Err(models::Error { code: 0, msg: None }),
|
||||
},
|
||||
_ => Err(models::Error { code: 0, msg: None }),
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
pub async fn save_withdraw(
|
||||
&self,
|
||||
data: models::SaveWithdrawRequest,
|
||||
) -> Result<models::SaveWithdrawResponse, models::Error> {
|
||||
let mut params = HashMap::new();
|
||||
|
||||
params.insert("username", data.username);
|
||||
if let Some(request_key) = data.request_key {
|
||||
params.insert("requestKey", request_key);
|
||||
}
|
||||
|
||||
let res = match self
|
||||
.client
|
||||
.post("https://dev-mw.kgonapi.com/withdraw")
|
||||
.header(reqwest::header::ACCEPT, "application/json")
|
||||
.header(
|
||||
reqwest::header::CONTENT_TYPE,
|
||||
"application/x-www-form-urlencoded",
|
||||
)
|
||||
.header("k-secret", self.k_secret.as_str())
|
||||
.header("k-username", self.k_username.as_str())
|
||||
.form(¶ms)
|
||||
.send()
|
||||
.await
|
||||
{
|
||||
Ok(res) => res,
|
||||
Err(err) => {
|
||||
return Err(models::Error { code: 0, msg: None });
|
||||
}
|
||||
};
|
||||
|
||||
match res.status() {
|
||||
reqwest::StatusCode::OK => match res.json::<models::SaveWithdrawResponse>().await {
|
||||
Ok(r) => Ok(r),
|
||||
Err(e) => Err(models::Error { code: 0, msg: None }),
|
||||
},
|
||||
_ => Err(models::Error { code: 0, msg: None }),
|
||||
}
|
||||
}
|
||||
}
|
7
src/repositories/betting/mod.rs
Normal file
7
src/repositories/betting/mod.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
//!
|
||||
//!
|
||||
|
||||
///
|
||||
pub mod models;
|
||||
///
|
||||
pub mod repository;
|
57
src/repositories/betting/models.rs
Normal file
57
src/repositories/betting/models.rs
Normal file
|
@ -0,0 +1,57 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub struct Error {
|
||||
pub code: i64,
|
||||
pub msg: Option<String>,
|
||||
}
|
||||
|
||||
pub struct FindTransactionsRequest {
|
||||
pub vendor_key: Option<String>,
|
||||
pub sdate: Option<String>,
|
||||
pub edate: Option<String>,
|
||||
pub group_key: Option<String>,
|
||||
pub username: Option<String>,
|
||||
pub limit: i64,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct FindTransactionsResponse {
|
||||
pub code: i64,
|
||||
pub msg: Option<String>,
|
||||
pub transactions: Vec<String>,
|
||||
}
|
||||
|
||||
pub struct FindPragmaticHistoryRequest {
|
||||
pub id: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct FindPragmaticHistoryResponse {
|
||||
pub code: i64,
|
||||
pub msg: Option<String>,
|
||||
pub url: Option<String>,
|
||||
}
|
||||
|
||||
pub struct FindEvolutionTransactionDetailRequest {
|
||||
pub ids: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct FindEvolutionTransactionDetailResponse {
|
||||
pub code: i64,
|
||||
pub msg: Option<String>,
|
||||
pub transactions: Vec<String>,
|
||||
}
|
||||
|
||||
pub struct FindStatisticRequest {
|
||||
pub vendor_key: Option<String>,
|
||||
pub group_key: Option<String>,
|
||||
pub date: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct FindStatisticResponse {
|
||||
pub code: i64,
|
||||
pub msg: Option<String>,
|
||||
pub data: Option<String>,
|
||||
}
|
204
src/repositories/betting/repository.rs
Normal file
204
src/repositories/betting/repository.rs
Normal file
|
@ -0,0 +1,204 @@
|
|||
use super::models;
|
||||
use std::{collections::HashMap, time::Duration};
|
||||
|
||||
///
|
||||
pub struct Repository {
|
||||
client: reqwest::Client,
|
||||
k_secret: String,
|
||||
k_username: String,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for Repository {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
f.debug_struct("Repository of api.kgon.identity").finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl Repository {
|
||||
///
|
||||
pub fn new(k_secret: &str, k_username: &str) -> Repository {
|
||||
Repository {
|
||||
client: reqwest::Client::new(),
|
||||
k_secret: k_secret.to_string(),
|
||||
k_username: k_username.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
pub async fn find_transactions(
|
||||
&self,
|
||||
data: models::FindTransactionsRequest,
|
||||
) -> Result<models::FindTransactionsResponse, models::Error> {
|
||||
let mut params = HashMap::new();
|
||||
|
||||
if let Some(vendor_key) = data.vendor_key {
|
||||
params.insert("vendorKey", vendor_key);
|
||||
}
|
||||
if let Some(sdate) = data.sdate {
|
||||
params.insert("sdate", sdate);
|
||||
}
|
||||
if let Some(edate) = data.edate {
|
||||
params.insert("edate", edate);
|
||||
}
|
||||
if let Some(group_key) = data.group_key {
|
||||
params.insert("groupKey", group_key);
|
||||
}
|
||||
if let Some(username) = data.username {
|
||||
params.insert("username", username);
|
||||
}
|
||||
|
||||
params.insert("limit", data.limit.to_string());
|
||||
|
||||
let res = match self
|
||||
.client
|
||||
.post("https://dev-mw.kgonapi.com/transaction")
|
||||
.header(reqwest::header::ACCEPT, "application/json")
|
||||
.header(
|
||||
reqwest::header::CONTENT_TYPE,
|
||||
"application/x-www-form-urlencoded",
|
||||
)
|
||||
.header("k-secret", self.k_secret.as_str())
|
||||
.header("k-username", self.k_username.as_str())
|
||||
.send()
|
||||
.await
|
||||
{
|
||||
Ok(res) => res,
|
||||
Err(err) => {
|
||||
return Err(models::Error { code: 0, msg: None });
|
||||
}
|
||||
};
|
||||
|
||||
match res.status() {
|
||||
reqwest::StatusCode::OK => match res.json::<models::FindTransactionsResponse>().await {
|
||||
Ok(r) => Ok(r),
|
||||
Err(e) => Err(models::Error { code: 0, msg: None }),
|
||||
},
|
||||
_ => Err(models::Error { code: 0, msg: None }),
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
pub async fn find_gragmatic_history(
|
||||
&self,
|
||||
data: models::FindPragmaticHistoryRequest,
|
||||
) -> Result<models::FindPragmaticHistoryResponse, models::Error> {
|
||||
let mut params = HashMap::new();
|
||||
|
||||
params.insert("id", data.id);
|
||||
|
||||
let res = match self
|
||||
.client
|
||||
.post("https://dev-mw.kgonapi.com/pragmatic/history")
|
||||
.header(reqwest::header::ACCEPT, "application/json")
|
||||
.header(
|
||||
reqwest::header::CONTENT_TYPE,
|
||||
"application/x-www-form-urlencoded",
|
||||
)
|
||||
.header("k-secret", self.k_secret.as_str())
|
||||
.header("k-username", self.k_username.as_str())
|
||||
.form(¶ms)
|
||||
.send()
|
||||
.await
|
||||
{
|
||||
Ok(res) => res,
|
||||
Err(err) => {
|
||||
return Err(models::Error { code: 0, msg: None });
|
||||
}
|
||||
};
|
||||
|
||||
match res.status() {
|
||||
reqwest::StatusCode::OK => match res.json::<models::FindPragmaticHistoryResponse>().await {
|
||||
Ok(r) => Ok(r),
|
||||
Err(e) => Err(models::Error { code: 0, msg: None }),
|
||||
},
|
||||
_ => Err(models::Error { code: 0, msg: None }),
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
pub async fn find_evolution_transaction_detail(
|
||||
&self,
|
||||
data: models::FindEvolutionTransactionDetailRequest,
|
||||
) -> Result<models::FindEvolutionTransactionDetailResponse, models::Error> {
|
||||
let mut params = HashMap::new();
|
||||
|
||||
params.insert("ids", data.ids);
|
||||
|
||||
let res = match self
|
||||
.client
|
||||
.post("https://dev-mw.kgonapi.com/evolution/transaction/detail")
|
||||
.header(reqwest::header::ACCEPT, "application/json")
|
||||
.header(
|
||||
reqwest::header::CONTENT_TYPE,
|
||||
"application/x-www-form-urlencoded",
|
||||
)
|
||||
.header("k-secret", self.k_secret.as_str())
|
||||
.header("k-username", self.k_username.as_str())
|
||||
.form(¶ms)
|
||||
.send()
|
||||
.await
|
||||
{
|
||||
Ok(res) => res,
|
||||
Err(err) => {
|
||||
return Err(models::Error { code: 0, msg: None });
|
||||
}
|
||||
};
|
||||
|
||||
match res.status() {
|
||||
reqwest::StatusCode::OK => match res
|
||||
.json::<models::FindEvolutionTransactionDetailResponse>()
|
||||
.await
|
||||
{
|
||||
Ok(r) => Ok(r),
|
||||
Err(e) => Err(models::Error { code: 0, msg: None }),
|
||||
},
|
||||
_ => Err(models::Error { code: 0, msg: None }),
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
pub async fn find_statistic(
|
||||
&self,
|
||||
data: models::FindStatisticRequest,
|
||||
) -> Result<models::FindStatisticResponse, models::Error> {
|
||||
let mut params = HashMap::new();
|
||||
|
||||
if let Some(vendor_key) = data.vendor_key {
|
||||
params.insert("vendorKey", vendor_key);
|
||||
}
|
||||
if let Some(group_key) = data.group_key {
|
||||
params.insert("groupKey", group_key);
|
||||
}
|
||||
if let Some(date) = data.date {
|
||||
params.insert("date", date);
|
||||
}
|
||||
|
||||
let res = match self
|
||||
.client
|
||||
.post("https://dev-mw.kgonapi.com/statistic")
|
||||
.header(reqwest::header::ACCEPT, "application/json")
|
||||
.header(
|
||||
reqwest::header::CONTENT_TYPE,
|
||||
"application/x-www-form-urlencoded",
|
||||
)
|
||||
.header("k-secret", self.k_secret.as_str())
|
||||
.header("k-username", self.k_username.as_str())
|
||||
.form(¶ms)
|
||||
.send()
|
||||
.await
|
||||
{
|
||||
Ok(res) => res,
|
||||
Err(err) => {
|
||||
return Err(models::Error { code: 0, msg: None });
|
||||
}
|
||||
};
|
||||
|
||||
match res.status() {
|
||||
reqwest::StatusCode::OK => match res.json::<models::FindStatisticResponse>().await {
|
||||
Ok(r) => Ok(r),
|
||||
Err(e) => Err(models::Error { code: 0, msg: None }),
|
||||
},
|
||||
_ => Err(models::Error { code: 0, msg: None }),
|
||||
}
|
||||
}
|
||||
}
|
7
src/repositories/game/mod.rs
Normal file
7
src/repositories/game/mod.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
//!
|
||||
//!
|
||||
|
||||
///
|
||||
pub mod models;
|
||||
///
|
||||
pub mod repository;
|
47
src/repositories/game/models.rs
Normal file
47
src/repositories/game/models.rs
Normal file
|
@ -0,0 +1,47 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub struct Error {
|
||||
pub code: i64,
|
||||
pub msg: Option<String>,
|
||||
}
|
||||
|
||||
pub struct FindVendorsRequest {}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct FindVendorsResponse {
|
||||
pub code: i64,
|
||||
pub msg: Option<String>,
|
||||
pub vendors: Vec<String>,
|
||||
}
|
||||
|
||||
pub struct FindGamesRequest {
|
||||
pub vendor_key: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct FindGamesResponse {
|
||||
pub code: i64,
|
||||
pub msg: Option<String>,
|
||||
pub games: Vec<String>,
|
||||
}
|
||||
|
||||
pub struct PlayRequest {
|
||||
pub vendor_key: String,
|
||||
pub game_key: String,
|
||||
pub username: String,
|
||||
pub nickname: String,
|
||||
pub site_username: String,
|
||||
pub group_key: Option<String>,
|
||||
pub amount: i64,
|
||||
pub request_key: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct PlayResponse {
|
||||
pub code: i64,
|
||||
pub msg: Option<String>,
|
||||
#[serde(rename = "userId")]
|
||||
pub user_id: String,
|
||||
pub url: String,
|
||||
pub balance: i64,
|
||||
}
|
150
src/repositories/game/repository.rs
Normal file
150
src/repositories/game/repository.rs
Normal file
|
@ -0,0 +1,150 @@
|
|||
use super::models;
|
||||
use std::{collections::HashMap, time::Duration};
|
||||
|
||||
///
|
||||
pub struct Repository {
|
||||
client: reqwest::Client,
|
||||
k_secret: String,
|
||||
k_username: String,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for Repository {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
f.debug_struct("Repository of api.kgon.identity").finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl Repository {
|
||||
///
|
||||
pub fn new(k_secret: &str, k_username: &str) -> Repository {
|
||||
Repository {
|
||||
client: reqwest::Client::new(),
|
||||
k_secret: k_secret.to_string(),
|
||||
k_username: k_username.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
pub async fn find_vendors(
|
||||
&self,
|
||||
data: models::FindVendorsRequest,
|
||||
) -> Result<models::FindVendorsResponse, models::Error> {
|
||||
let res = match self
|
||||
.client
|
||||
.post("https://dev-mw.kgonapi.com/vendors")
|
||||
.header(reqwest::header::ACCEPT, "application/json")
|
||||
.header(
|
||||
reqwest::header::CONTENT_TYPE,
|
||||
"application/x-www-form-urlencoded",
|
||||
)
|
||||
.header("k-secret", self.k_secret.as_str())
|
||||
.header("k-username", self.k_username.as_str())
|
||||
.send()
|
||||
.await
|
||||
{
|
||||
Ok(res) => res,
|
||||
Err(err) => {
|
||||
return Err(models::Error { code: 0, msg: None });
|
||||
}
|
||||
};
|
||||
|
||||
match res.status() {
|
||||
reqwest::StatusCode::OK => match res.json::<models::FindVendorsResponse>().await {
|
||||
Ok(r) => Ok(r),
|
||||
Err(e) => Err(models::Error { code: 0, msg: None }),
|
||||
},
|
||||
_ => Err(models::Error { code: 0, msg: None }),
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
pub async fn find_games(
|
||||
&self,
|
||||
data: models::FindGamesRequest,
|
||||
) -> Result<models::FindGamesResponse, models::Error> {
|
||||
let mut params = HashMap::new();
|
||||
|
||||
params.insert("vendorKey", data.vendor_key);
|
||||
|
||||
let res = match self
|
||||
.client
|
||||
.post("https://dev-mw.kgonapi.com/games")
|
||||
.header(reqwest::header::ACCEPT, "application/json")
|
||||
.header(
|
||||
reqwest::header::CONTENT_TYPE,
|
||||
"application/x-www-form-urlencoded",
|
||||
)
|
||||
.header("k-secret", self.k_secret.as_str())
|
||||
.header("k-username", self.k_username.as_str())
|
||||
.form(¶ms)
|
||||
.send()
|
||||
.await
|
||||
{
|
||||
Ok(res) => res,
|
||||
Err(err) => {
|
||||
return Err(models::Error { code: 0, msg: None });
|
||||
}
|
||||
};
|
||||
|
||||
match res.status() {
|
||||
reqwest::StatusCode::OK => match res.json::<models::FindGamesResponse>().await {
|
||||
Ok(r) => Ok(r),
|
||||
Err(e) => Err(models::Error { code: 0, msg: None }),
|
||||
},
|
||||
_ => Err(models::Error { code: 0, msg: None }),
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
pub async fn play(
|
||||
&self,
|
||||
data: models::PlayRequest,
|
||||
) -> Result<models::PlayResponse, models::Error> {
|
||||
let mut params = HashMap::new();
|
||||
|
||||
params.insert("vendorKey", data.vendor_key);
|
||||
params.insert("gameKey", data.game_key);
|
||||
params.insert("username", data.username);
|
||||
params.insert("nickname", data.nickname);
|
||||
params.insert("siteUsername", data.site_username);
|
||||
|
||||
if let Some(group_key) = data.group_key {
|
||||
params.insert("groupKey", group_key);
|
||||
}
|
||||
|
||||
params.insert("amount", data.amount.to_string());
|
||||
|
||||
if let Some(request_key) = data.request_key {
|
||||
params.insert("requestKey", request_key);
|
||||
}
|
||||
|
||||
let res = match self
|
||||
.client
|
||||
.post("https://dev-mw.kgonapi.com/play")
|
||||
.header(reqwest::header::ACCEPT, "application/json")
|
||||
.header(
|
||||
reqwest::header::CONTENT_TYPE,
|
||||
"application/x-www-form-urlencoded",
|
||||
)
|
||||
.header("k-secret", self.k_secret.as_str())
|
||||
.header("k-username", self.k_username.as_str())
|
||||
.form(¶ms)
|
||||
.timeout(Duration::from_secs(10))
|
||||
.send()
|
||||
.await
|
||||
{
|
||||
Ok(res) => res,
|
||||
Err(err) => {
|
||||
return Err(models::Error { code: 0, msg: None });
|
||||
}
|
||||
};
|
||||
|
||||
match res.status() {
|
||||
reqwest::StatusCode::OK => match res.json::<models::PlayResponse>().await {
|
||||
Ok(r) => Ok(r),
|
||||
Err(e) => Err(models::Error { code: 0, msg: None }),
|
||||
},
|
||||
_ => Err(models::Error { code: 0, msg: None }),
|
||||
}
|
||||
}
|
||||
}
|
7
src/repositories/identity/mod.rs
Normal file
7
src/repositories/identity/mod.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
//!
|
||||
//!
|
||||
|
||||
///
|
||||
pub mod models;
|
||||
///
|
||||
pub mod repository;
|
46
src/repositories/identity/models.rs
Normal file
46
src/repositories/identity/models.rs
Normal file
|
@ -0,0 +1,46 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct Error {
|
||||
pub code: i64,
|
||||
pub msg: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct FindMembersRequest {
|
||||
pub group_key: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct FindMember {
|
||||
pub id: i64,
|
||||
pub username: String,
|
||||
pub cash: i64,
|
||||
pub cash_bota: i64,
|
||||
pub nickname: String,
|
||||
pub site_username: String,
|
||||
pub group_key: Option<String>,
|
||||
pub oriental_play: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct FindMembersResponse {
|
||||
pub code: i64,
|
||||
pub msg: Option<String>,
|
||||
pub users: Vec<FindMember>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct SaveMemberRequest {
|
||||
pub username: String,
|
||||
pub nickname: String,
|
||||
pub site_username: String,
|
||||
pub group_key: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct SaveMemberResponse {
|
||||
pub code: i64,
|
||||
pub msg: Option<String>,
|
||||
pub id: Option<i64>,
|
||||
}
|
145
src/repositories/identity/repository.rs
Normal file
145
src/repositories/identity/repository.rs
Normal file
|
@ -0,0 +1,145 @@
|
|||
use super::models;
|
||||
use std::collections::HashMap;
|
||||
|
||||
///
|
||||
pub struct Repository {
|
||||
client: reqwest::Client,
|
||||
k_secret: String,
|
||||
k_username: String,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for Repository {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
f.debug_struct("Repository of api.kgon.identity").finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl Repository {
|
||||
///
|
||||
pub fn new(k_secret: &str, k_username: &str) -> Repository {
|
||||
Repository {
|
||||
client: reqwest::Client::new(),
|
||||
k_secret: k_secret.to_string(),
|
||||
k_username: k_username.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
pub async fn find_members(
|
||||
&self,
|
||||
data: models::FindMembersRequest,
|
||||
) -> Result<models::FindMembersResponse, models::Error> {
|
||||
let mut params = HashMap::new();
|
||||
|
||||
if let Some(group_key) = data.group_key {
|
||||
params.insert("groupKey", group_key);
|
||||
}
|
||||
|
||||
let res = match self
|
||||
.client
|
||||
.post("https://dev-mw.kgonapi.com/users")
|
||||
.header(reqwest::header::ACCEPT, "application/json")
|
||||
.header(
|
||||
reqwest::header::CONTENT_TYPE,
|
||||
"application/x-www-form-urlencoded",
|
||||
)
|
||||
.header("k-secret", self.k_secret.as_str())
|
||||
.header("k-username", self.k_username.as_str())
|
||||
.form(¶ms)
|
||||
.send()
|
||||
.await
|
||||
{
|
||||
Ok(res) => res,
|
||||
Err(err) => {
|
||||
return Err(models::Error { code: 0, msg: None });
|
||||
}
|
||||
};
|
||||
|
||||
match res.status() {
|
||||
reqwest::StatusCode::OK => match res.json::<models::FindMembersResponse>().await {
|
||||
Ok(r) => Ok(r),
|
||||
Err(e) => Err(models::Error { code: 0, msg: None }),
|
||||
},
|
||||
_ => Err(models::Error { code: 0, msg: None }),
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
pub async fn save_member(
|
||||
&self,
|
||||
data: models::SaveMemberRequest,
|
||||
) -> Result<models::SaveMemberResponse, models::Error> {
|
||||
let mut params = HashMap::new();
|
||||
|
||||
params.insert("username", data.username);
|
||||
params.insert("nickname", data.nickname);
|
||||
params.insert("siteUsername", data.site_username);
|
||||
|
||||
if let Some(group_key) = data.group_key {
|
||||
params.insert("groupKey", group_key);
|
||||
}
|
||||
|
||||
let res = match self
|
||||
.client
|
||||
.post("https://dev-mw.kgonapi.com/register")
|
||||
.header(reqwest::header::ACCEPT, "application/json")
|
||||
.header(
|
||||
reqwest::header::CONTENT_TYPE,
|
||||
"application/x-www-form-urlencoded",
|
||||
)
|
||||
.header("k-secret", self.k_secret.as_str())
|
||||
.header("k-username", self.k_username.as_str())
|
||||
.form(¶ms)
|
||||
.send()
|
||||
.await
|
||||
{
|
||||
Ok(res) => res,
|
||||
Err(err) => {
|
||||
return Err(models::Error { code: 0, msg: None });
|
||||
}
|
||||
};
|
||||
|
||||
match res.status() {
|
||||
reqwest::StatusCode::OK => match res.json::<models::SaveMemberResponse>().await {
|
||||
Ok(r) => Ok(r),
|
||||
Err(e) => Err(models::Error { code: 0, msg: None }),
|
||||
},
|
||||
_ => Err(models::Error { code: 0, msg: None }),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::super::models;
|
||||
use super::*;
|
||||
|
||||
#[tokio::test]
|
||||
async fn find_members() {
|
||||
let repository = Repository::new("c23d770b873b2ce95747abc57052beb0", "Turbo77");
|
||||
|
||||
let r = repository
|
||||
.find_members(models::FindMembersRequest { group_key: None })
|
||||
.await
|
||||
.expect("");
|
||||
|
||||
println!("members: {:?}", r);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn save_member() {
|
||||
let repository = Repository::new("c23d770b873b2ce95747abc57052beb0", "Turbo77");
|
||||
|
||||
let r = repository
|
||||
.save_member(models::SaveMemberRequest {
|
||||
username: "".to_string(),
|
||||
nickname: "".to_string(),
|
||||
site_username: "".to_string(),
|
||||
group_key: None,
|
||||
})
|
||||
.await
|
||||
.expect("");
|
||||
|
||||
println!("member: {:?}", r);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
pub mod account;
|
||||
pub mod betting;
|
||||
pub mod game;
|
||||
pub mod identity;
|
Loading…
Reference in New Issue
Block a user