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 {
|
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 {
|
fn mandatory_parameters_as_form_builder(&self) -> TokenStream {
|
||||||
|
@ -177,7 +187,7 @@ impl<'a> GroupMethod<'a> {
|
||||||
|
|
||||||
pub struct SendMethodBuilder<'a> {
|
pub struct SendMethodBuilder<'a> {
|
||||||
group: Option<&'a GroupMethod<'a>>,
|
group: Option<&'a GroupMethod<'a>>,
|
||||||
method_name: &'a Ident,
|
method_name: Ident,
|
||||||
parameters: Vec<TokenStream>,
|
parameters: Vec<TokenStream>,
|
||||||
auth_access: TokenStream,
|
auth_access: TokenStream,
|
||||||
form_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 {
|
pub fn new(method_name: &'a Ident, auth_access: TokenStream, form_access: TokenStream) -> Self {
|
||||||
Self {
|
Self {
|
||||||
group: Option::None,
|
group: Option::None,
|
||||||
method_name,
|
method_name: method_name.clone(),
|
||||||
parameters: vec![],
|
parameters: vec![],
|
||||||
auth_access,
|
auth_access,
|
||||||
form_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 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 form_factory = self.form_factory();
|
||||||
let parameters = self.parameters;
|
let parameters = self.parameters.clone();
|
||||||
let form_access = self.form_access;
|
let form_access = self.form_access.clone();
|
||||||
let method_name = self.method_name;
|
let method_name = self.method_name.clone();
|
||||||
let auth_access = self.auth_access;
|
let auth_access = self.auth_access.clone();
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
pub async fn #method_name(self, #(#parameters),*) -> super::super::Result<#response_type> {
|
pub async fn #method_name(self, #(#parameters),*) -> super::super::Result<#response_type> {
|
||||||
|
@ -223,7 +233,10 @@ impl<'a> SendMethodBuilder<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn response_type(&self) -> (TokenStream, TokenStream) {
|
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() {
|
match self.group().method.types.response() {
|
||||||
Some(resp) => {
|
Some(resp) => {
|
||||||
if resp.is_list {
|
if resp.is_list {
|
||||||
|
@ -238,6 +251,7 @@ impl<'a> SendMethodBuilder<'a> {
|
||||||
None => (quote! { String }, quote! { .text() }),
|
None => (quote! { String }, quote! { .text() }),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn method_url(&self) -> String {
|
fn method_url(&self) -> String {
|
||||||
format!(
|
format!(
|
||||||
|
@ -266,6 +280,12 @@ impl<'a> SendMethodBuilder<'a> {
|
||||||
self
|
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 {
|
fn set_group(mut self, group: &'a GroupMethod<'a>) -> Self {
|
||||||
self.group = Option::Some(group);
|
self.group = Option::Some(group);
|
||||||
self
|
self
|
||||||
|
|
Loading…
Reference in New Issue
Block a user