Struct Client

Source
pub struct Client<C>
where C: Inner,
{ /* private fields */ }
Expand description

A Monzo API client

Implementations§

Source§

impl Client<Quick>

Source

pub fn new(access_token: impl Into<String>) -> Self

Create a new Monzo Client..

This Client needs only an access token to authenticate against the Monzo API, but is incapable of refreshing its access if the token expires.

Source

pub fn with_refresh_tokens( self, client_id: impl Into<String>, client_secret: impl Into<String>, refresh_token: impl Into<String>, ) -> Client<Refreshable>

Upgrade a Client by adding refresh tokens.

A client that has refresh tokens is able to refresh it’s authentication when the access token expires.

Source§

impl Client<Refreshable>

Source

pub const fn client_id(&self) -> &String

Get a reference to the client id

Source

pub const fn client_secret(&self) -> &String

Get a reference to the client secret

Source

pub const fn refresh_token(&self) -> &String

Get a reference to the refresh token

Source

pub async fn refresh_auth(&mut self) -> Result<i64>

Refresh the access and refresh tokens for this client

Returns the time (in seconds) until the token expires

Source§

impl<C> Client<C>
where C: Inner,

Source

pub fn access_token(&self) -> &String

Return a reference to the current access token

Source

pub fn set_access_token(&mut self, access_token: impl Into<String>)

Manually update the access token

Source

pub async fn accounts(&self) -> Result<Vec<Account>>

Return a list of accounts

§Example
let accounts = client.accounts().await?;
Source

pub async fn balance(&self, account_id: &str) -> Result<Balance>

Return the balance of a given account

§Example
let balance = client.balance(ACCOUNT_ID).await?;
Source

pub async fn pots(&self, account_id: &str) -> Result<Vec<Pot>>

Return a list of Pots

§Example
let pots = client.pots(ACCOUNT_ID).await?;
Source

pub const fn basic_feed_item<'a>( &'a self, account_id: &'a str, title: &'a str, image_url: &'a str, ) -> Request<'a, C>

Post a basic item on the account feed.

§Example
let account_id = "ACCOUNT_ID";
let title = "Feed Item Title";
let image_url = "http://www.nyan.cat/cats/original.gif";

client
    .basic_feed_item(account_id, title, image_url)
    .body("i figured out how to send messages to monzo from my computer...")
    .send()
    .await?;
Source

pub async fn deposit_into_pot( &self, pot_id: &str, source_account_id: &str, amount: u32, ) -> Result<Pot>

Deposit money into a pot

Source

pub async fn withdraw_from_pot( &self, pot_id: &str, destination_account_id: &str, amount: u32, ) -> Result<Pot>

Withdraw money from a pot

Source

pub fn transactions<'a>(&'a self, account_id: &'a str) -> List<'a, C>

Get a list of transactions

The only required field is the account id, however optional pagination parameters can be supplied.

§Example
use chrono::{Duration, Utc};
use monzo::Client;
let account_id = "ACCOUNT_ID";

let transactions = client
    .transactions(account_id)
    .since(Utc::now() - Duration::days(10))
    .limit(10)
    .send()
    .await?;
§Note

The Monzo API will only return transactions from more than 90 days ago in the first 5 minutes after authorising the Client. You can avoid this by using the ‘since’ method.

Source

pub fn transaction<'a>(&'a self, transaction_id: &'a str) -> Get<'a, C>

Retrieve a transaction by transaction id

§Example
use monzo::Client;
let transaction_id = "TRANSACTION_ID";

let transactions = client.transaction(transaction_id).send().await?;
§Note

The Monzo API will only return transactions from more than 90 days ago in the first 5 minutes after authorising the Client.

Source

pub async fn who_am_i(&self) -> Result<Response>

Return information about the current session

Trait Implementations§

Source§

impl<C> Debug for Client<C>
where C: Inner + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<C> Freeze for Client<C>
where C: Freeze,

§

impl<C> RefUnwindSafe for Client<C>
where C: RefUnwindSafe,

§

impl<C> Send for Client<C>

§

impl<C> Sync for Client<C>

§

impl<C> Unpin for Client<C>
where C: Unpin,

§

impl<C> UnwindSafe for Client<C>
where C: UnwindSafe,

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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,