MCPcopy Create free account
hub / github.com/Moosync/Moosync / create_api_client

Method create_api_client

src-tauri/src/providers/youtube.rs:148–177  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

146
147 #[tracing::instrument(level = "debug", skip(self))]
148 async fn create_api_client(&self) {
149 if let Some(token) = self.tokens.lock().await.as_ref() {
150 tracing::debug!("Creating youtube api client");
151 let client =
152 hyper_util::client::legacy::Client::builder(hyper_util::rt::TokioExecutor::new())
153 .build(
154 hyper_rustls::HttpsConnectorBuilder::new()
155 .with_native_roots()
156 .unwrap()
157 .https_or_http()
158 .enable_http1()
159 .build(),
160 );
161
162 *self.api_client.write().await = Some(ApiClient {
163 api_client: google_youtube3::YouTube::new(client, token.access_token.clone()),
164 token_expiry: Instant::now() + Duration::from_secs(token.expires_in),
165 });
166
167 let res = self.fetch_user_details().await;
168 let mut status_tx = self.status_tx.lock().await;
169 if let Ok(res) = res {
170 let _ = status_tx.send(res).await;
171 } else {
172 let _ = status_tx
173 .send(self.get_provider_status(Some("".into())).await)
174 .await;
175 }
176 }
177 }
178
179 async fn get_api_client(&self) -> RwLockReadGuard<'_, Option<ApiClient>> {
180 if let Some(expired) = self

Callers 2

refresh_loginMethod · 0.45
authorizeMethod · 0.45

Calls 5

writeMethod · 0.80
cloneMethod · 0.80
sendMethod · 0.80
fetch_user_detailsMethod · 0.45
get_provider_statusMethod · 0.45

Tested by

no test coverage detected