Skip to content

Commit

Permalink
feat(ffi): expose method for sending generic GET requests through the…
Browse files Browse the repository at this point in the history
… SDK's inner HTTP client.
  • Loading branch information
stefanceriu committed Jun 28, 2024
1 parent 1c92633 commit c9e8cc9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions bindings/matrix-sdk-ffi/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,11 @@ impl Client {
}
})))
}

pub async fn get_url(&self, url: String) -> Result<String, ClientError> {
let http_client = self.inner.http_client();
Ok(http_client.get(url).send().await?.text().await?)
}
}

impl Client {
Expand Down
8 changes: 7 additions & 1 deletion bindings/matrix-sdk-ffi/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt::Display;

use matrix_sdk::{
encryption::CryptoStoreError, event_cache::EventCacheError, oidc::OidcError,
encryption::CryptoStoreError, event_cache::EventCacheError, oidc::OidcError, reqwest,
send_queue::RoomSendQueueError, HttpError, IdParseError,
NotificationSettingsError as SdkNotificationSettingsError, StoreError,
};
Expand All @@ -26,6 +26,12 @@ impl From<anyhow::Error> for ClientError {
}
}

impl From<reqwest::Error> for ClientError {
fn from(e: reqwest::Error) -> Self {
Self::new(e)
}
}

impl From<UnexpectedUniFFICallbackError> for ClientError {
fn from(e: UnexpectedUniFFICallbackError) -> Self {
Self::new(e)
Expand Down
5 changes: 5 additions & 0 deletions crates/matrix-sdk/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,11 @@ impl Client {
&self.inner.base_client
}

/// The underlying HTTP client.
pub fn http_client(&self) -> &reqwest::Client {
&self.inner.http_client.inner
}

pub(crate) fn locks(&self) -> &ClientLocks {
&self.inner.locks
}
Expand Down

0 comments on commit c9e8cc9

Please sign in to comment.