-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin' into add_wrapping_crate
- Loading branch information
Showing
17 changed files
with
244 additions
and
249 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 |
---|---|---|
|
@@ -5,5 +5,4 @@ members = [ | |
"springql-core", | ||
"foreign-service", | ||
"test-logger", | ||
"test-web-console-mock", | ||
] |
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
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,83 @@ | ||
// This file is part of https://github.com/SpringQL/SpringQL which is licensed under MIT OR Apache-2.0. See file LICENSE-MIT or LICENSE-APACHE for full license details. | ||
|
||
use std::time::Duration; | ||
|
||
use reqwest::StatusCode; | ||
use serde_json::Value; | ||
|
||
#[derive(Debug)] | ||
pub struct ReqwestClient(reqwest::blocking::Client); | ||
#[derive(Debug)] | ||
pub struct Response(reqwest::blocking::Response); | ||
|
||
#[derive(Debug)] | ||
pub struct ReqwestError(reqwest::Error); | ||
|
||
#[derive(Debug)] | ||
pub struct RequestBuilder { | ||
raw_builder: reqwest::blocking::RequestBuilder, | ||
json_value: Option<serde_json::Value>, | ||
} | ||
|
||
impl ReqwestClient { | ||
pub fn with_timeout(timeout: Duration) -> Self { | ||
Self( | ||
reqwest::blocking::Client::builder() | ||
.timeout(Some(timeout)) | ||
.build() | ||
.expect("failed to build a reqwest client"), | ||
) | ||
} | ||
|
||
pub fn post(&self, url: &str) -> RequestBuilder { | ||
RequestBuilder::new(self.0.post(url)) | ||
} | ||
} | ||
|
||
impl RequestBuilder { | ||
fn new(builder: reqwest::blocking::RequestBuilder) -> Self { | ||
Self { | ||
raw_builder: builder, | ||
json_value: None, | ||
} | ||
} | ||
pub fn json(self, json: Value) -> Self { | ||
Self { | ||
raw_builder: self.raw_builder, | ||
json_value: Some(json), | ||
} | ||
} | ||
|
||
pub fn send(self) -> Result<Response, ReqwestError> { | ||
if let Some(json_value) = self.json_value { | ||
Ok(Response(self.raw_builder.json(&json_value).send()?)) | ||
} else { | ||
unreachable!(".json() is not called yet") | ||
} | ||
} | ||
} | ||
|
||
impl Response { | ||
pub fn error_for_status_ref(&self) -> Result<&Response, ReqwestError> { | ||
match self.0.error_for_status_ref() { | ||
Ok(_) => Ok(self), | ||
Err(e) => Err(ReqwestError::from(e)), | ||
} | ||
} | ||
|
||
pub fn text(self) -> Result<String, ReqwestError> { | ||
Ok(self.0.text()?) | ||
} | ||
} | ||
|
||
impl ReqwestError { | ||
pub fn status(&self) -> Option<StatusCode> { | ||
self.0.status() | ||
} | ||
} | ||
|
||
impl From<reqwest::Error> for ReqwestError { | ||
fn from(e: reqwest::Error) -> Self { | ||
Self(e) | ||
} | ||
} |
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
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,86 @@ | ||
// This file is part of https://github.com/SpringQL/SpringQL which is licensed under MIT OR Apache-2.0. See file LICENSE-MIT or LICENSE-APACHE for full license details. | ||
|
||
use std::{sync::RwLock, time::Duration}; | ||
|
||
use once_cell::sync::OnceCell; | ||
use reqwest::StatusCode; | ||
use serde_json::Value; | ||
|
||
#[derive(Debug)] | ||
pub struct ReqwestClient; | ||
#[derive(Debug)] | ||
pub struct Response; | ||
|
||
#[derive(Debug)] | ||
pub struct ReqwestError; | ||
|
||
#[derive(Debug)] | ||
pub struct RequestBuilder { | ||
json_value: Option<serde_json::Value>, | ||
} | ||
|
||
impl ReqwestClient { | ||
pub fn with_timeout(_timeout: Duration) -> Self { | ||
Self | ||
} | ||
|
||
pub fn post(&self, _url: &str) -> RequestBuilder { | ||
RequestBuilder::new() | ||
} | ||
} | ||
|
||
static REQUESTS: OnceCell<RwLock<Vec<Value>>> = OnceCell::new(); | ||
|
||
/// gets stubed request JsonValues | ||
pub fn stubed_requests() -> Vec<Value> { | ||
let req_store = REQUESTS.get_or_init(|| RwLock::new(Vec::new())); | ||
let mut store = req_store.write().unwrap(); | ||
let result = store.clone(); | ||
store.clear(); | ||
result | ||
} | ||
|
||
impl RequestBuilder { | ||
fn new() -> Self { | ||
Self { json_value: None } | ||
} | ||
pub fn json(self, json: Value) -> Self { | ||
Self { | ||
json_value: Some(json), | ||
} | ||
} | ||
|
||
pub fn send(self) -> Result<Response, ReqwestError> { | ||
if let Some(json_value) = self.json_value { | ||
let req_store = REQUESTS.get_or_init(|| RwLock::new(Vec::new())); | ||
let mut store = req_store.write().unwrap(); | ||
store.push(json_value); | ||
|
||
Ok(Response) | ||
} else { | ||
unreachable!() | ||
} | ||
} | ||
} | ||
|
||
impl Response { | ||
pub fn error_for_status_ref(&self) -> Result<&Response, ReqwestError> { | ||
Ok(self) | ||
} | ||
|
||
pub fn text(self) -> Result<String, ReqwestError> { | ||
Ok("stubbed request".to_string()) | ||
} | ||
} | ||
|
||
impl ReqwestError { | ||
pub fn status(&self) -> Option<StatusCode> { | ||
Some(StatusCode::INTERNAL_SERVER_ERROR) | ||
} | ||
} | ||
|
||
impl From<reqwest::Error> for ReqwestError { | ||
fn from(_e: reqwest::Error) -> Self { | ||
Self | ||
} | ||
} |
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.