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