licenses, publish fields in toml, version handling
This commit is contained in:
38
src/lib.rs
38
src/lib.rs
@@ -1,40 +1,8 @@
|
||||
//! # Up API
|
||||
//!
|
||||
//! A convenient and easy to use wrapper for the [UP Bank API](https://developer.up.com.au).
|
||||
//! A convenient and easy to use wrapper for the [Up Bank API](https://developer.up.com.au).
|
||||
|
||||
// Include examples so that this exactly matches the README.
|
||||
|
||||
/// Error types and trait implementations.
|
||||
pub mod error;
|
||||
/// Types for modelling and interacting with [accounts](https://developer.up.com.au/#accounts).
|
||||
pub mod accounts;
|
||||
/// INCOMPLETE: Types for modelling and interacting with [categories](https://developer.up.com.au/#categories).
|
||||
pub mod categories;
|
||||
/// Types for modelling and interacting with [tags](https://developer.up.com.au/#tags).
|
||||
pub mod tags;
|
||||
/// INCOMPLETE: Types for modelling and interacting with [transactions](https://developer.up.com.au/#transactions).
|
||||
pub mod transactions;
|
||||
/// Types for modelling and interacting with [utilities](https://developer.up.com.au/#utility_endpoints).
|
||||
pub mod utilities;
|
||||
/// INCOMPLETE: Types for modelling and interacting with [webhooks](https://developer.up.com.au/#webhooks).
|
||||
pub mod webhooks;
|
||||
|
||||
static BASE_URL : &str = "https://api.up.com.au/api/v1";
|
||||
|
||||
/// A client for interacting with the Up API.
|
||||
pub struct Client {
|
||||
access_token : String,
|
||||
}
|
||||
|
||||
impl Client {
|
||||
/// Creates an instance of the `Client` from the access token. Visit [this page](https://api.up.com.au/getting_started) to get such a token.
|
||||
pub fn new(access_token : String) -> Self {
|
||||
Client {
|
||||
access_token
|
||||
}
|
||||
}
|
||||
|
||||
fn auth_header(&self) -> String {
|
||||
format!("Bearer {}", self.access_token)
|
||||
}
|
||||
}
|
||||
/// Module for interacting with the v1 (beta) release of the Up API.
|
||||
pub mod v1;
|
||||
|
@@ -1,4 +1,4 @@
|
||||
use crate::{Client, error};
|
||||
use crate::v1::{Client, error, BASE_URL};
|
||||
|
||||
use serde::Deserialize;
|
||||
|
||||
@@ -131,7 +131,7 @@ impl ListAccountsOptions {
|
||||
impl Client {
|
||||
/// Retrieve a paginated list of all accounts for the currently authenticated user. The returned list is paginated and can be scrolled by following the `prev` and `next` links where present.
|
||||
pub async fn list_accounts(&self, options : &ListAccountsOptions) -> Result<ListAccountsResponse, error::Error> {
|
||||
let mut url = reqwest::Url::parse(&format!("{}/accounts", crate::BASE_URL)).map_err(error::Error::UrlParse)?;
|
||||
let mut url = reqwest::Url::parse(&format!("{}/accounts", BASE_URL)).map_err(error::Error::UrlParse)?;
|
||||
options.add_params(&mut url);
|
||||
|
||||
let res = reqwest::Client::new()
|
||||
@@ -166,7 +166,7 @@ impl Client {
|
||||
panic!("The provided account ID must not be empty.");
|
||||
}
|
||||
|
||||
let url = reqwest::Url::parse(&format!("{}/accounts/{}", crate::BASE_URL, id)).map_err(error::Error::UrlParse)?;
|
||||
let url = reqwest::Url::parse(&format!("{}/accounts/{}", BASE_URL, id)).map_err(error::Error::UrlParse)?;
|
||||
|
||||
let res = reqwest::Client::new()
|
||||
.get(url)
|
34
src/v1/mod.rs
Normal file
34
src/v1/mod.rs
Normal file
@@ -0,0 +1,34 @@
|
||||
/// Error types and trait implementations.
|
||||
pub mod error;
|
||||
/// Types for modelling and interacting with [accounts](https://developer.up.com.au/#accounts).
|
||||
pub mod accounts;
|
||||
/// INCOMPLETE: Types for modelling and interacting with [categories](https://developer.up.com.au/#categories).
|
||||
pub mod categories;
|
||||
/// Types for modelling and interacting with [tags](https://developer.up.com.au/#tags).
|
||||
pub mod tags;
|
||||
/// INCOMPLETE: Types for modelling and interacting with [transactions](https://developer.up.com.au/#transactions).
|
||||
pub mod transactions;
|
||||
/// Types for modelling and interacting with [utilities](https://developer.up.com.au/#utility_endpoints).
|
||||
pub mod utilities;
|
||||
/// INCOMPLETE: Types for modelling and interacting with [webhooks](https://developer.up.com.au/#webhooks).
|
||||
pub mod webhooks;
|
||||
|
||||
static BASE_URL : &str = "https://api.up.com.au/api/v1";
|
||||
|
||||
/// A client for interacting with the Up API.
|
||||
pub struct Client {
|
||||
access_token : String,
|
||||
}
|
||||
|
||||
impl Client {
|
||||
/// Creates an instance of the `Client` from the access token. Visit [this page](https://api.up.com.au/getting_started) to get such a token.
|
||||
pub fn new(access_token : String) -> Self {
|
||||
Client {
|
||||
access_token
|
||||
}
|
||||
}
|
||||
|
||||
fn auth_header(&self) -> String {
|
||||
format!("Bearer {}", self.access_token)
|
||||
}
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
use crate::{Client, error};
|
||||
use crate::v1::{Client, error, BASE_URL};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -77,7 +77,7 @@ struct TagRequest {
|
||||
impl Client {
|
||||
/// Retrieve a list of all tags currently in use. The returned list is paginated and can be scrolled by following the `next` and `prev` links where present. Results are ordered lexicographically. The transactions relationship for each tag exposes a link to get the transactions with the given tag.
|
||||
pub async fn list_tags(&self, options : &ListTagsOptions) -> Result<ListTagsResponse, error::Error> {
|
||||
let mut url = reqwest::Url::parse(&format!("{}/tags", crate::BASE_URL)).map_err(error::Error::UrlParse)?;
|
||||
let mut url = reqwest::Url::parse(&format!("{}/tags", BASE_URL)).map_err(error::Error::UrlParse)?;
|
||||
options.add_params(&mut url);
|
||||
|
||||
let res = reqwest::Client::new()
|
||||
@@ -106,7 +106,7 @@ impl Client {
|
||||
|
||||
/// Associates one or more tags with a specific transaction. No more than 6 tags may be present on any single transaction. Duplicate tags are silently ignored. The associated tags, along with this request URL, are also exposed via the tags relationship on the transaction resource returned from `get_transaction`.
|
||||
pub async fn add_tags(&self, transaction_id : &str, tags : Vec<String>) -> Result<(), error::Error> {
|
||||
let url = reqwest::Url::parse(&format!("{}/transactions/{}/relationships/tags", crate::BASE_URL, transaction_id)).map_err(error::Error::UrlParse)?;
|
||||
let url = reqwest::Url::parse(&format!("{}/transactions/{}/relationships/tags", BASE_URL, transaction_id)).map_err(error::Error::UrlParse)?;
|
||||
|
||||
let tags =
|
||||
tags
|
||||
@@ -143,7 +143,7 @@ impl Client {
|
||||
|
||||
/// Disassociates one or more tags from a specific transaction. Tags that are not associated are silently ignored. The associated tags, along with this request URL, are also exposed via the tags relationship on the transaction resource returned from `get_transaction`.
|
||||
pub async fn delete_tags(&self, transaction_id : &str, tags : Vec<String>) -> Result<(), error::Error> {
|
||||
let url = reqwest::Url::parse(&format!("{}/transactions/{}/relationships/tags", crate::BASE_URL, transaction_id)).map_err(error::Error::UrlParse)?;
|
||||
let url = reqwest::Url::parse(&format!("{}/transactions/{}/relationships/tags", BASE_URL, transaction_id)).map_err(error::Error::UrlParse)?;
|
||||
|
||||
let tags =
|
||||
tags
|
||||
@@ -176,7 +176,6 @@ impl Client {
|
||||
Err(error::Error::Api(error))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
use crate::{Client, error};
|
||||
use crate::v1::{Client, error, BASE_URL};
|
||||
|
||||
use serde::Deserialize;
|
||||
|
||||
@@ -19,7 +19,7 @@ pub struct Meta {
|
||||
impl Client {
|
||||
/// Make a basic ping request to the API. This is useful to verify that authentication is functioning correctly.
|
||||
pub async fn ping(&self) -> Result<PingResponse, error::Error> {
|
||||
let url = reqwest::Url::parse(&format!("{}/util/ping", crate::BASE_URL)).map_err(error::Error::UrlParse)?;
|
||||
let url = reqwest::Url::parse(&format!("{}/util/ping", BASE_URL)).map_err(error::Error::UrlParse)?;
|
||||
|
||||
let res = reqwest::Client::new()
|
||||
.get(url)
|
Reference in New Issue
Block a user