Generate raw response methods
This commit is contained in:
parent
2ad53985ba
commit
b565fcee44
|
@ -158,7 +158,17 @@ impl<'a> GroupMethod<'a> {
|
|||
}
|
||||
|
||||
fn generate_send_method(&self, builder: SendMethodBuilder) -> TokenStream {
|
||||
builder.set_group(self).generate_send_method()
|
||||
let builder = builder.set_group(self);
|
||||
let send_method = builder.generate_send_method();
|
||||
let send_method_raw = builder
|
||||
.set_override_return_type(quote! { String })
|
||||
.append_to_method_name("_raw")
|
||||
.generate_send_method();
|
||||
|
||||
quote! {
|
||||
#send_method
|
||||
#send_method_raw
|
||||
}
|
||||
}
|
||||
|
||||
fn mandatory_parameters_as_form_builder(&self) -> TokenStream {
|
||||
|
@ -177,7 +187,7 @@ impl<'a> GroupMethod<'a> {
|
|||
|
||||
pub struct SendMethodBuilder<'a> {
|
||||
group: Option<&'a GroupMethod<'a>>,
|
||||
method_name: &'a Ident,
|
||||
method_name: Ident,
|
||||
parameters: Vec<TokenStream>,
|
||||
auth_access: TokenStream,
|
||||
form_access: TokenStream,
|
||||
|
@ -189,7 +199,7 @@ impl<'a> SendMethodBuilder<'a> {
|
|||
pub fn new(method_name: &'a Ident, auth_access: TokenStream, form_access: TokenStream) -> Self {
|
||||
Self {
|
||||
group: Option::None,
|
||||
method_name,
|
||||
method_name: method_name.clone(),
|
||||
parameters: vec![],
|
||||
auth_access,
|
||||
form_access,
|
||||
|
@ -198,14 +208,14 @@ impl<'a> SendMethodBuilder<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
fn generate_send_method(self) -> TokenStream {
|
||||
fn generate_send_method(&self) -> TokenStream {
|
||||
let method_url = self.method_url();
|
||||
let (response_type, response_parse) = self.response_type();
|
||||
let (response_type, response_parse) = self.return_type();
|
||||
let form_factory = self.form_factory();
|
||||
let parameters = self.parameters;
|
||||
let form_access = self.form_access;
|
||||
let method_name = self.method_name;
|
||||
let auth_access = self.auth_access;
|
||||
let parameters = self.parameters.clone();
|
||||
let form_access = self.form_access.clone();
|
||||
let method_name = self.method_name.clone();
|
||||
let auth_access = self.auth_access.clone();
|
||||
|
||||
quote! {
|
||||
pub async fn #method_name(self, #(#parameters),*) -> super::super::Result<#response_type> {
|
||||
|
@ -223,19 +233,23 @@ impl<'a> SendMethodBuilder<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
fn response_type(&self) -> (TokenStream, TokenStream) {
|
||||
match self.group().method.types.response() {
|
||||
Some(resp) => {
|
||||
if resp.is_list {
|
||||
(
|
||||
quote! { std::vec::Vec<Response> },
|
||||
quote! { .json::<std::vec::Vec<Response>>() },
|
||||
)
|
||||
} else {
|
||||
(quote! { Response }, quote! { .json::<Response>() })
|
||||
fn return_type(&self) -> (TokenStream, TokenStream) {
|
||||
if let Some(override_return_type) = self.override_return_type.clone() {
|
||||
(override_return_type, quote! { .text() })
|
||||
} else {
|
||||
match self.group().method.types.response() {
|
||||
Some(resp) => {
|
||||
if resp.is_list {
|
||||
(
|
||||
quote! { std::vec::Vec<Response> },
|
||||
quote! { .json::<std::vec::Vec<Response>>() },
|
||||
)
|
||||
} else {
|
||||
(quote! { Response }, quote! { .json::<Response>() })
|
||||
}
|
||||
}
|
||||
None => (quote! { String }, quote! { .text() }),
|
||||
}
|
||||
None => (quote! { String }, quote! { .text() }),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -266,6 +280,12 @@ impl<'a> SendMethodBuilder<'a> {
|
|||
self
|
||||
}
|
||||
|
||||
fn append_to_method_name(mut self, append: &str) -> Self {
|
||||
let new_name = util::to_ident(&format!("{}{}", self.method_name, append));
|
||||
self.method_name = new_name;
|
||||
self
|
||||
}
|
||||
|
||||
fn set_group(mut self, group: &'a GroupMethod<'a>) -> Self {
|
||||
self.group = Option::Some(group);
|
||||
self
|
||||
|
|
Loading…
Reference in New Issue
Block a user