-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from WFCD/refactor
- Loading branch information
Showing
20 changed files
with
606 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
{ | ||
// Place your warframe workspace snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and | ||
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope | ||
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is | ||
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are: | ||
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. | ||
// Placeholders with the same ids are connected. | ||
// Example: | ||
"Test a model (RTObj)": { | ||
"scope": "rust", | ||
"prefix": "model_test", | ||
"body": [ | ||
"#[cfg(test)]" | ||
"mod test {" | ||
" use super::${1:model};" | ||
" use crate::worldstate::{client::Client, error::ApiError};" | ||
"" | ||
" #[cfg(not(feature = \"multilangual\"))]" | ||
" #[tokio::test]" | ||
" async fn test_${1/(.*)/${1:/downcase}/}() -> Result<(), ApiError> {" | ||
" let client = Client::new();" | ||
"" | ||
" match client.fetch::<${1:model}>().await {" | ||
" Ok(_${1/(.*)/${1:/downcase}/}) => Ok(())," | ||
" Err(why) => Err(why)," | ||
" }" | ||
" }" | ||
"" | ||
" #[cfg(feature = \"multilangual\")]" | ||
" #[tokio::test]" | ||
" async fn test_${1/(.*)/${1:/downcase}/}() -> Result<(), ApiError> {" | ||
" use crate::worldstate::prelude::Language;" | ||
"" | ||
" let client = Client::new();" | ||
"" | ||
" match client.fetch::<${1:model}>(Language::ZH).await {" | ||
" Ok(_${1/(.*)/${1:/downcase}/}) => Ok(())," | ||
" Err(why) => Err(why)," | ||
" }" | ||
" }" | ||
"}" | ||
] | ||
}, | ||
"Test a model (RTArray)": { | ||
"scope": "rust", | ||
"prefix": "model_test_array", | ||
"body": [ | ||
"#[cfg(test)]" | ||
"mod test {" | ||
" use super::${1:model};" | ||
" use crate::worldstate::{client::Client, error::ApiError};" | ||
"" | ||
" #[cfg(not(feature = \"multilangual\"))]" | ||
" #[tokio::test]" | ||
" async fn test_${1/(.*)/${1:/downcase}/}() -> Result<(), ApiError> {" | ||
" let client = Client::new();" | ||
"" | ||
" match client.fetch_arr::<${1:model}>().await {" | ||
" Ok(_${1/(.*)/${1:/downcase}/}s) => Ok(())," | ||
" Err(why) => Err(why)," | ||
" }" | ||
" }" | ||
"" | ||
" #[cfg(feature = \"multilangual\")]" | ||
" #[tokio::test]" | ||
" async fn test_${1/(.*)/${1:/downcase}/}() -> Result<(), ApiError> {" | ||
" use crate::worldstate::prelude::Language;" | ||
"" | ||
" let client = Client::new();" | ||
"" | ||
" match client.fetch_arr::<${1:model}>(Language::ZH).await {" | ||
" Ok(_${1/(.*)/${1:/downcase}/}s) => Ok(())," | ||
" Err(why) => Err(why)," | ||
" }" | ||
" }" | ||
"}" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#[cfg(not(feature = "multilangual"))] | ||
pub mod basic; | ||
|
||
#[cfg(feature = "multilangual")] | ||
pub mod multilangual; | ||
|
||
#[derive(Default)] | ||
pub struct Client { | ||
session: reqwest::Client, | ||
} | ||
|
||
impl Client { | ||
pub fn new() -> Self { | ||
Default::default() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use crate::worldstate::{error::ApiError, prelude::Language}; | ||
|
||
use super::super::models::base::{Endpoint, Model, RTArray, RTObject}; | ||
|
||
impl super::Client { | ||
pub async fn fetch<T>(&self, language: Language) -> Result<T, ApiError> | ||
where | ||
T: Model + Endpoint + RTObject, | ||
{ | ||
let response = self | ||
.session | ||
.get(format!( | ||
"{}?language={}", | ||
T::endpoint(), | ||
String::from(language) | ||
)) | ||
.send() | ||
.await | ||
.unwrap(); | ||
match response.status().as_u16() { | ||
200 => Ok(response.json::<T>().await.unwrap()), // unwrap should be safe - the API only responds with a JSON | ||
_code => Err(ApiError::from(response).await), | ||
} | ||
} | ||
|
||
pub async fn fetch_arr<T>(&self, language: Language) -> Result<Vec<T>, ApiError> | ||
where | ||
T: Model + Endpoint + RTArray, | ||
{ | ||
let response = self | ||
.session | ||
.get(format!( | ||
"{}?language={}", | ||
T::endpoint(), | ||
String::from(language) | ||
)) | ||
.send() | ||
.await | ||
.unwrap(); | ||
|
||
match response.status().as_u16() { | ||
200 => Ok(response.json::<Vec<T>>().await.unwrap()), // unwrap should be safe - the API only responds with a JSON | ||
_code => Err(ApiError::from(response).await), | ||
} | ||
} | ||
} | ||
|
||
#[cfg(feature = "multilangual")] | ||
#[tokio::test] | ||
async fn test_fissure() -> Result<(), ApiError> { | ||
use crate::worldstate::prelude::*; | ||
|
||
let client = Client::new(); | ||
|
||
match client.fetch_arr::<Fissure>(Language::EN).await { | ||
Ok(_fissures) => Ok(()), | ||
Err(why) => Err(why), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
pub enum Language { | ||
DE, | ||
ES, | ||
FR, | ||
IT, | ||
KO, | ||
PL, | ||
PT, | ||
RU, | ||
ZH, | ||
EN, | ||
UK, | ||
} | ||
|
||
impl From<Language> for String { | ||
fn from(value: Language) -> Self { | ||
use Language::*; | ||
match value { | ||
DE => "de", | ||
ES => "es", | ||
FR => "fr", | ||
IT => "it", | ||
KO => "ko", | ||
PL => "pl", | ||
PT => "pt", | ||
RU => "ru", | ||
ZH => "zh", | ||
EN => "en", | ||
UK => "uk", | ||
} | ||
.into() | ||
} | ||
} | ||
|
||
impl From<Language> for &'static str { | ||
fn from(value: Language) -> Self { | ||
use Language::*; | ||
match value { | ||
DE => "de", | ||
ES => "es", | ||
FR => "fr", | ||
IT => "it", | ||
KO => "ko", | ||
PL => "pl", | ||
PT => "pt", | ||
RU => "ru", | ||
ZH => "zh", | ||
EN => "en", | ||
UK => "uk", | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.