ticks

Crates.ioticks
lib.rsticks
version1.0.1
sourcesrc
created_at2024-07-09 16:01:29.296264
updated_at2024-07-10 05:38:50.490065
descriptionSimple, ergonomic Rust wrapper for the TickTick Open API
homepage
repositoryhttps://github.com/jordi-star/ticks
max_upload_size
id1297242
size33,289
jordi (jordi-star)

documentation

README

Ticks

Simple, ergonomic Rust wrapper for the TickTick Open API

docs.rs

Getting Started

First, register your application with the TickTick Developer Center:

To get started using the TickTick Open API, you will need to register your application and obtain a client ID and client secret. You can register your application by visiting the TickTick Developer Center. Once registered, you will receive a client ID and client secret which you will use to authenticate your requests.

Once you have registered your application, add ticks to your project's Cargo.toml:

cargo add ticks

To use the TickTick API, you must authorize your app at runtime. Let's talk about Authorization.

Authorization

The TickTick API uses OAuth for authentication. Ticks handles most of the authentication for you, leaving only reading the API's HTTP OAuth response to you.

/// Get Authorization URL, this is the link the user must visit to allow our Application access to their account.
/// redirect_uri must be the same URL specified in the TickTick Developer Center.
let auth = Authorization::begin_auth(/* client_id */, /* redirect_uri */)?;
println!("Browse to: {:?}", auth.get_url());
/// Wait for response from TickTick's API. TickTick will send the required auth info over HTTP to the redirect_uri we specified.
let (access_code, state) = /* Get access_code & state from redirect_uri over HTTP */;
/// Get access token
let token = auth.finish_auth({client_secret}, code, state).await?;
/// Done! Create TickTick instance using AccessToken.
let ticktick = TickTick::new(token.clone())?;

For testing, you may want to set your redirect_uri to localhost. To read the OAuth HTTP Response locally, try a TcpListener

let listener = TcpListener::bind("127.0.0.1:{port of redirect_uri}")?;
let (mut stream, _) = listener.accept()?;
let mut stream_reader = BufReader::new(&stream);
let mut response = String::new();
stream_reader.read_line(&mut response)?;
stream.write_all("HTTP/1.1 200 OK".as_bytes())?;
println!("Response {:?}", response);

Documentation

The docs can be found at https://docs.rs/ticks/latest.

Commit count: 11

cargo fmt