<% if @date_flag %>use chrono::prelude::*; <% end %><% if enum_flag %>use itertools::Itertools; use std::collections::HashSet; <% end %><% if serde_flag %>use serde::{Serialize, Deserialize}; <% end %><% if fields.present? %>use crate::fields::{<%= fields.map{|it| "#{it[:name].make_field()}::#{it[:name].ucc}"}.join(", ") %>}; <% end %><% if refs.present? %>use crate::responses::{<%= refs.map{|it| "#{it}::#{it.ucc}"}.join(", ") %>}; <% end %>use reqwest::RequestBuilder; use crate::{error::Error, headers::Headers, api::{apply_options, execute_twitter, Authentication, make_url, TwapiOptions}}; const URL: &str = "<%= yml[:url] %>"; <% if bodies.present? %><%= bodies.join("\n\n") %><% end %> <%= expantions.join("\n\n") %> <%= api_struct %> impl Api { <%= api_new %> <%= setter %> pub fn build(self, authentication: &impl Authentication) -> RequestBuilder { <%= parameters %> let client = reqwest::Client::new(); let url = make_url(&self.twapi_options, <%= paths.empty? ? "" : "&" %>URL<%= paths.empty? ? "" : paths.map{|it| ".replace(\":#{it[:name].make_field}\", &self.#{it[:name].make_field})"}.join("") %>); let builder = client .<%= yml[:method] %>(&url)<% if queries.present? %> .query(&query_parameters)<% end %><% if form.present? %> .form(&form_parameters)<% end %><% if bodies.present? %> .json(&self.body)<% end %> ; authentication.execute(apply_options(builder, &self.twapi_options), "<%= yml[:method].upcase %>", &url, <%= queries.present? ? :"&query_parameters.iter().map(|it| (it.0, it.1.as_str())).collect::>()" : "&[]" %>) } pub async fn execute(self, authentication: &impl Authentication) -> Result<(Response, Headers), Error> { execute_twitter(self.build(authentication)).await } } <%= response_list.join("\n") %>