pub trait SyncProvider {
Show 14 methods // Required methods fn api_url(&self) -> &'static str; fn provider_name(&self) -> &'static str; fn oauth2_token( &mut self ) -> Result<StandardTokenResponse<EmptyExtraTokenFields, BasicTokenType>>; fn initial_authenticate(&mut self) -> Result<()>; fn initial_import(&mut self) -> Result<()>; fn reauthenticate(&mut self) -> Result<()>; fn sync_data(&mut self) -> Result<()>; // Provided methods fn get<T: DeserializeOwned>(&mut self, method: &str) -> Result<T> { ... } fn post<T: DeserializeOwned>( &mut self, method: &str, data: Value ) -> Result<T> { ... } fn exchange_refresh_token( &self, client: &BasicClient ) -> Result<StandardTokenResponse<EmptyExtraTokenFields, BasicTokenType>> { ... } fn schema(&self) -> Schema { ... } fn token(&self) -> Result<Option<RefreshToken>> { ... } fn set_token(&self, value: RefreshToken) -> Result<()> { ... } fn start_listen_server( authorize_url: &str ) -> Result<(AuthorizationCode, CsrfToken)> { ... }
}
Expand description

SyncProvider is a trait that should be implemented by all 3rd party providers.

Required Methods§

source

fn api_url(&self) -> &'static str

Returns the URL to the API Endpoint

source

fn provider_name(&self) -> &'static str

Returns the name of the provider (which is used for storing it in the keyring).

source

fn oauth2_token( &mut self ) -> Result<StandardTokenResponse<EmptyExtraTokenFields, BasicTokenType>>

Gets the OAuth2 token or reauthenticates with the refresh token if no token has been set yet.

source

fn initial_authenticate(&mut self) -> Result<()>

Perform the initial authentication. This should open the user’s browser so they can authenticate with their provider.

source

fn initial_import(&mut self) -> Result<()>

Start the initial import. This should import all data from the sync provider to the Tracker DB.

source

fn reauthenticate(&mut self) -> Result<()>

Exchange the refresh token we already stored for an access token.

source

fn sync_data(&mut self) -> Result<()>

This should sync data that has been added since the last sync.

Provided Methods§

source

fn get<T: DeserializeOwned>(&mut self, method: &str) -> Result<T>

Make a GET request against the specified method.

Arguments
  • method - The API method to query
Returns

The deserialized JSON response

source

fn post<T: DeserializeOwned>(&mut self, method: &str, data: Value) -> Result<T>

Make a POST request against the specified method.

Arguments
  • method - The API method to query
Returns

The deserialized JSON response

source

fn exchange_refresh_token( &self, client: &BasicClient ) -> Result<StandardTokenResponse<EmptyExtraTokenFields, BasicTokenType>>

Exchange a refresh token for an access token.

source

fn schema(&self) -> Schema

Get the libsecret Schema used by Health

source

fn token(&self) -> Result<Option<RefreshToken>>

Retrieve the RefreshToken from the secret store.

Returns

A RefreshToken if a refresh token is set, or None if no refresh token is set. May return an error if querying the secret store fails.

source

fn set_token(&self, value: RefreshToken) -> Result<()>

Set the RefreshToken in the secret store.

Arguments
Returns

May return an error if querying the secret store fails.

source

fn start_listen_server( authorize_url: &str ) -> Result<(AuthorizationCode, CsrfToken)>

Starts a server which listens for the user to finish authenticating with their OAuth2 provider and captures the OAuth2 code once the user is redirect to the server.

Arguments
  • authorize_url - The URL which should be opened in the user’s browser so they can authenticate.
Returns

The AuthorizationCode and CsrfToken that were returned by the sync provider, or an error if reading the response fails. Please keep in mind that the returned CrfsToken should always be compared to what you sent to the provider to make sure the request went through fine.

Implementors§