switching back to awc for actix_web 4
This commit is contained in:
22
src/lib.rs
22
src/lib.rs
@ -45,13 +45,13 @@ pub fn derive_http_get_request(input: TokenStream) -> TokenStream {
|
||||
}
|
||||
|
||||
quote! {
|
||||
impl #name {
|
||||
impl Queryable for #name {
|
||||
pub async fn send(
|
||||
&self,
|
||||
client: std::sync::Arc<actix_web::Client>,
|
||||
client: std::sync::Arc<awc::Client>,
|
||||
headers: Option<Vec<(&str, &str)>>,
|
||||
api_key: Option<&str>,
|
||||
) -> Result<actix_web::ClientResponse, actix_web::error::SendRequestError> {
|
||||
) -> Result<awc::ClientResponse, actix_web::error::SendRequestError> {
|
||||
use urlencoding::encode;
|
||||
|
||||
let mut query_params: Vec<(String, String)> = Vec::new();
|
||||
@ -103,10 +103,10 @@ pub fn derive_http_get_request(input: TokenStream) -> TokenStream {
|
||||
impl #name {
|
||||
pub async fn send(
|
||||
&self,
|
||||
client: std::sync::Arc<actix_web::Client>,
|
||||
client: std::sync::Arc<awc::Client>,
|
||||
headers: Option<Vec<(&str, &str)>>,
|
||||
api_key: Option<&str>,
|
||||
) -> Result<actix_web::ClientResponse, actix_web::error::SendRequestError> {
|
||||
) -> Result<awc::ClientResponse, actix_web::error::SendRequestError> {
|
||||
match self {
|
||||
#(#variant_arms)*
|
||||
}
|
||||
@ -128,7 +128,7 @@ pub fn derive_http_response(input: TokenStream) -> TokenStream {
|
||||
|
||||
let expanded = quote! {
|
||||
impl #name {
|
||||
pub async fn receive(resp: actix_web::ClientResponse) -> Result<Self, actix_web::error::JsonPayloadError> {
|
||||
pub async fn receive(resp: awc::ClientResponse) -> Result<Self, actix_web::error::JsonPayloadError> {
|
||||
resp.json().await
|
||||
}
|
||||
}
|
||||
@ -147,10 +147,10 @@ pub fn derive_send_vec(input: TokenStream) -> TokenStream {
|
||||
/// Sends all items in the vec sequentially, awaiting each.
|
||||
pub async fn send_vec(
|
||||
items: Vec<Self>,
|
||||
client: std::sync::Arc<actix_web::Client>,
|
||||
client: std::sync::Arc<awc::Client>,
|
||||
headers: Option<Vec<(&str, &str)>>,
|
||||
api_key: Option<&str>,
|
||||
) -> Result<Vec<actix_web::ClientResponse>, actix_web::error::SendRequestError> {
|
||||
) -> Result<Vec<awc::ClientResponse>, actix_web::error::SendRequestError> {
|
||||
let mut responses = Vec::with_capacity(items.len());
|
||||
for item in items {
|
||||
let resp = item.send(client.clone(), headers.clone(), api_key).await?;
|
||||
@ -174,8 +174,8 @@ pub fn derive_response_vec(input: TokenStream) -> TokenStream {
|
||||
/// Deserializes all responses sequentially into a Vec<Self>.
|
||||
/// Assumes `Self` implements `DeserializeOwned`.
|
||||
pub async fn response_vec(
|
||||
responses: Vec<actix_web::ClientResponse>,
|
||||
) -> Result<Vec<Self>, actix_web::error::JsonPayloadError>
|
||||
responses: Vec<awc::ClientResponse>,
|
||||
) -> Result<Vec<Self>, awc::error::JsonPayloadError>
|
||||
where
|
||||
Self: Sized + serde::de::DeserializeOwned,
|
||||
{
|
||||
@ -231,7 +231,7 @@ pub fn alpaca_cli(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
||||
const THREADS: usize = 4;
|
||||
|
||||
// Initialize shared HTTP client and API key
|
||||
let client = Arc::new(actix_web::Client::default());
|
||||
let client = Arc::new(awc::Client::default());
|
||||
let api_key = std::env::var("APCA_API_KEY_ID")?;
|
||||
let cmd = #enum_name::from_args();
|
||||
|
||||
|
Reference in New Issue
Block a user