pub struct Client { /* private fields */ }Expand description
Client is a public struct that represents a client for making requests to the API.
Fields:
req_client: Areqwest::Clientinstance used for making HTTP requests.secret_id: ASecretStringthat represents the client’s secret ID.secret_key: ASecretStringthat represents the client’s secret key.created_token: AnOption<CreateTokenResponse>that represents the token created by the client. It isNoneif no token has been created yet.
The Client struct is used to interact with the API. It uses the reqwest crate for making HTTP requests and the secrecy crate for handling secret strings.
The secret_id and secret_key are used for authentication with the API.
The created_token field is used to store the token received from the API after successful authentication.
Implementations§
Source§impl Client
impl Client
Sourcepub async fn new(
secret_id: impl Into<SecretString>,
secret_key: impl Into<SecretString>,
) -> Result<Self, Box<dyn Error>>
pub async fn new( secret_id: impl Into<SecretString>, secret_key: impl Into<SecretString>, ) -> Result<Self, Box<dyn Error>>
new is an associated function that creates a new instance of the Client struct.
§Arguments
secret_id: An implementor of theInto<SecretString>trait. This is converted into aSecretStringthat represents the client’s secret ID.secret_key: An implementor of theInto<SecretString>trait. This is converted into aSecretStringthat represents the client’s secret key.
§Returns
This function returns a Client instance.
§Examples
let secret_id = "my_secret_id".to_string();
let secret_key = "my_secret_key".to_string();
let client = Client::new(secret_id, secret_key);§Async
This function is async and should be awaited.
Sourcepub async fn create_token(&self) -> Result<CreateTokenResponse, Box<dyn Error>>
pub async fn create_token(&self) -> Result<CreateTokenResponse, Box<dyn Error>>
create_token is an async method that sends a POST request to the URL_CREATE_TOKEN endpoint to create a new token.
§Returns
This method returns a Result that is either a CreateTokenResponse on success or a Box<dyn std::error::Error> on failure.
§Async
This method is async and should be awaited.
§Examples
let secret_id = "my_secret_id".to_string();
let secret_key = "my_secret_key".to_string();
let mut client = Client::new(secret_id, secret_key).await?;
let create_token_response = client.create_token().await?;This method is typically called within the Client::new method to automatically create a token when a new Client is created.
Sourcepub async fn get_institutions(&self) -> Result<Vec<Institution>, Box<dyn Error>>
pub async fn get_institutions(&self) -> Result<Vec<Institution>, Box<dyn Error>>
get_institutions is an async method that sends a GET request to the URL_GET_INSTITUTIONS endpoint to retrieve a list of institutions.
§Returns
This method returns a Result that is either a Vec<Institution> on success or a Box<dyn std::error::Error> on failure.
§Async
This method is async and should be awaited.
§Examples
let secret_id = "my_secret_id".to_string();
let secret_key = "my_secret_key".to_string();
let mut client = Client::new(secret_id, secret_key).await?;
let institutions = client.get_institutions().await?;This method requires that a token has been created and stored in the created_token field of the Client struct. If no token has been created, this method will return an error.
Sourcepub async fn create_end_user_agreement(
&self,
institution_id: &str,
max_historical_days: i32,
) -> Result<EndUserAgreement, Box<dyn Error>>
pub async fn create_end_user_agreement( &self, institution_id: &str, max_historical_days: i32, ) -> Result<EndUserAgreement, Box<dyn Error>>
create_end_user_agreement is an async method that sends a POST request to the URL_CREATE_END_USER_AGREEMENT endpoint to create an end user agreement.
§Arguments
institution_id: A reference to a string that represents the ID of the institution for which the end user agreement is being created.
§Returns
This method returns a Result that is either an EndUserAgreement on success or a Box<dyn std::error::Error> on failure.
§Async
This method is async and should be awaited.
§Examples
let secret_id = "my_secret_id".to_string();
let secret_key = "my_secret_key".to_string();
let mut client = Client::new(secret_id, secret_key).await?;
let institution_id = "institution_id".to_string();
let end_user_agreement = client.create_end_user_agreement(&institution_id).await?;This method requires that a token has been created and stored in the created_token field of the Client struct. If no token has been created, this method will return an error.
Sourcepub async fn list_requisitions(
&self,
) -> Result<ListRequisitionsResponse, Box<dyn Error>>
pub async fn list_requisitions( &self, ) -> Result<ListRequisitionsResponse, Box<dyn Error>>
list_requisitions is an async method that sends a GET request to the URL_REQUISITIONS endpoint to retrieve a list of requisitions.
§Returns
This method returns a Result that is either a ListRequisitionsResponse on success or a Box<dyn std::error::Error> on failure.
§Async
This method is async and should be awaited.
§Examples
let secret_id = "my_secret_id".to_string();
let secret_key = "my_secret_key".to_string();
let mut client = Client::new(secret_id, secret_key).await?;
let requisitions = client.list_requisitions().await?;This method requires that a token has been created and stored in the created_token field of the Client struct. If no token has been created, this method will return an error.
Sourcepub async fn create_requisition(
&self,
redirect: &str,
institution_id: &str,
agreement_id: Option<&str>,
reference: Option<&str>,
) -> Result<Requisition, Box<dyn Error>>
pub async fn create_requisition( &self, redirect: &str, institution_id: &str, agreement_id: Option<&str>, reference: Option<&str>, ) -> Result<Requisition, Box<dyn Error>>
create_requisition is an async method that sends a POST request to the URL_REQUISITIONS endpoint to create a new requisition.
§Arguments
redirect: A reference to a string that represents the URL to which the user will be redirected after completing the requisition.institution_id: A reference to a string that represents the ID of the institution for which the requisition is being created.agreement_id: A reference to a string that represents the ID of the end user agreement associated with the requisition.reference: A reference to a string that represents a unique reference for the requisition.
§Returns
This method returns a Result that is either a Requisition on success or a Box<dyn std::error::Error> on failure.
§Async
This method is async and should be awaited.
§Examples
let secret_id = "my_secret_id".to_string();
let secret_key = "my_secret_key".to_string();
let mut client = Client::new(secret_id, secret_key).await?;
let redirect = "http://localhost:3000/callback".to_string();
let institution_id = "institution_id".to_string();
let agreement_id = "agreement_id".to_string();
let reference = "reference".to_string();
let requisition = client.create_requisition(&redirect, &institution_id, Some(&agreement_id), Some(&reference)).await?;This method requires that a token has been created and stored in the created_token field of the Client struct. If no token has been created, this method will return an error.
Sourcepub async fn list_transactions(
&self,
account_id: &str,
) -> Result<ListTransactionsResponse, Box<dyn Error>>
pub async fn list_transactions( &self, account_id: &str, ) -> Result<ListTransactionsResponse, Box<dyn Error>>
list_transactions is an async method that sends a GET request to the https://bankaccountdata.gocardless.com/api/v2/accounts/{account_id}/transactions endpoint to retrieve a list of transactions for a specific account.
§Arguments
account_id: A reference to a string that represents the ID of the account for which the transactions are being retrieved.
§Returns
This method returns a Result that is either a ListTransactionsResponse on success or a Box<dyn std::error::Error> on failure.
§Async
This method is async and should be awaited.
§Examples
let secret_id = "my_secret_id".to_string();
let secret_key = "my_secret_key".to_string();
let mut client = Client::new(secret_id, secret_key).await?;
let account_id = "account_id".to_string();
let transactions = client.list_transactions(&account_id).await?;This method requires that a token has been created and stored in the created_token field of the Client struct. If no token has been created, this method will return an error.
Sourcepub async fn list_balances(
&self,
account_id: &str,
) -> Result<ListBalancesResponse, Box<dyn Error>>
pub async fn list_balances( &self, account_id: &str, ) -> Result<ListBalancesResponse, Box<dyn Error>>
list_balances is an async method that sends a GET request to the https://bankaccountdata.gocardless.com/api/v2/accounts/{account_id}/balances endpoint to retrieve a list of balances for a specific account.
§Arguments
account_id: A reference to a string that represents the ID of the account for which the balances are being retrieved.
§Returns
This method returns a Result that is either a ListBalancesResponse on success or a Box<dyn std::error::Error> on failure.
§Async
This method is async and should be awaited.
§Examples
let secret_id = "my_secret_id".to_string();
let secret_key = "my_secret_key".to_string();
let mut client = Client::new(secret_id, secret_key).await?;
let account_id = "account_id".to_string();
let balances = client.list_balances(&account_id).await?;This method requires that a token has been created and stored in the created_token field of the Client struct. If no token has been created, this method will return an error.
Sourcepub async fn get_account_details(
&self,
account_id: &str,
) -> Result<AccountDetailsResponse, Box<dyn Error>>
pub async fn get_account_details( &self, account_id: &str, ) -> Result<AccountDetailsResponse, Box<dyn Error>>
get_account_details is an async method that sends a GET request to the https://bankaccountdata.gocardless.com/api/v2/accounts/{account_id}/details endpoint to retrieve the details of a specific account.
§Arguments
account_id: A reference to a string that represents the ID of the account for which the details are being retrieved.
§Returns
This method returns a Result that is either an AccountDetailsResponse on success or a Box<dyn std::error::Error> on failure.
§Async
This method is async and should be awaited.
§Examples
let secret_id = "my_secret_id".to_string();
let secret_key = "my_secret_key".to_string();
let mut client = Client::new(secret_id, secret_key).await?;
let account_id = "account_id".to_string();
let account_details = client.get_account_details(&account_id).await?;This method requires that a token has been created and stored in the created_token field of the Client struct. If no token has been created, this method will return an error.