Client

Struct Client 

Source
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: A reqwest::Client instance used for making HTTP requests.
  • secret_id: A SecretString that represents the client’s secret ID.
  • secret_key: A SecretString that represents the client’s secret key.
  • created_token: An Option<CreateTokenResponse> that represents the token created by the client. It is None if 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

Source

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 the Into<SecretString> trait. This is converted into a SecretString that represents the client’s secret ID.
  • secret_key: An implementor of the Into<SecretString> trait. This is converted into a SecretString that 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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Auto Trait Implementations§

§

impl Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,