diff options
Diffstat (limited to 'rust/fatcat-cli/src/api.rs')
-rw-r--r-- | rust/fatcat-cli/src/api.rs | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/rust/fatcat-cli/src/api.rs b/rust/fatcat-cli/src/api.rs index 3fa67e9..2db2efb 100644 --- a/rust/fatcat-cli/src/api.rs +++ b/rust/fatcat-cli/src/api.rs @@ -1,11 +1,8 @@ use crate::{parse_macaroon_editor_id, ClientStatus, EntityType, Specifier}; use anyhow::{anyhow, Context, Result}; -use fatcat_openapi::client::Client; use fatcat_openapi::models; use fatcat_openapi::{ApiNoContext, ContextWrapperExt}; -use hyper::client::ResponseFuture; use swagger::{auth, AuthData, ContextBuilder, EmptyContext, Push, XSpanIdString}; -use tokio::runtime::current_thread::Runtime; type FatcatApiContextType = swagger::make_context_ty!( ContextBuilder, @@ -14,17 +11,16 @@ type FatcatApiContextType = swagger::make_context_ty!( XSpanIdString ); -pub struct FatcatApiClient<'a> { - pub api: fatcat_openapi::ContextWrapper<'a, Client<ResponseFuture>, FatcatApiContextType>, - pub rt: tokio::runtime::current_thread::Runtime, +pub struct FatcatApiClient { + pub api: Box<dyn ApiNoContext<FatcatApiContextType>>, + pub rt: tokio::runtime::Runtime, api_token: Option<String>, api_host: String, pub editor_id: Option<String>, } -impl<'a> FatcatApiClient<'a> { +impl FatcatApiClient { pub fn new( - client: &'a fatcat_openapi::client::Client<ResponseFuture>, api_host: String, api_token: Option<String>, ) -> Result<Self> { @@ -42,11 +38,10 @@ impl<'a> FatcatApiClient<'a> { XSpanIdString::default() ); - let wrapped_client: fatcat_openapi::ContextWrapper< - Client<ResponseFuture>, - FatcatApiContextType, - > = client.with_context(context); - let rt: Runtime = Runtime::new().expect("create tokio runtime"); + //let wrapped_client: swagger::ContextWrapper< + let client = fatcat_openapi::client::Client::try_new(&api_host).context("failed to create HTTP(S) client")?; + let wrapped_client = Box::new(client.with_context(context)); + let rt: tokio::runtime::Runtime = tokio::runtime::Runtime::new().expect("create tokio runtime"); let editor_id = match api_token { Some(ref token) => { |