Crates.io | lta |
lib.rs | lta |
version | 0.6.0 |
source | src |
created_at | 2019-04-13 14:51:22.493818 |
updated_at | 2022-06-06 17:25:02.774075 |
description | 🚍 Singapore LTA Datamall Rust Client written in pure rust with support for asynchronous requests |
homepage | https://github.com/BudiNverse/lta-rs |
repository | https://github.com/BudiNverse/lta-rs |
max_upload_size | |
id | 127676 |
size | 204,330 |
🚍 Singapore LTA Datamall async first Rust client. lta-rs is used to interact with lta-datamall
[dependencies]
# extra features available: blocking
lta = { version = "0.6.0" }
You can get your API key from here
use lta::{LTAResult, LTAClient, Client, Traffic, TrafficRequests};
#[tokio::main]
async fn main() -> LTAResult<()> {
let api_key = std::env::var("API_KEY").expect("API_KEY not found!");
let client = LTAClient::with_api_key(api_key)?;
let erp_rates = Traffic::get_erp_rates(&client, None).await?;
println!("{:?}", erp_rates);
Ok(())
}
use lta::{LTAResult, LTAClient, Client, Bus, BusRequests};
fn get_bus_arrival() -> LTAResult<()> {
let api_key = std::env::var("API_KEY").expect("API_KEY not found!");
let client = LTAClient::with_api_key(api_key);
let arrivals = Bus::get_arrival(&client, 83139, None)?;
println!("{:?}", arrivals);
Ok(())
}
// All the APIs in this library are designed to be used like this
// `lta::RequestType::get_something`
// All of them return lta::utils::LTAResult<T>
// The example below is Bus::get_bus_services()
// and Traffic::get_erp_rates()
// Do note that the API calling convention is similar across all the APIs except for
// bus::get_arrival
// Most of the APIs returns only 500 record
// If you want to get records 501 - 1000 take a look at get_erp() example
use lta::{LTAResult, LTAClient, Client, Bus, Traffic, BusRequests, TrafficRequests};
async fn bus_services() -> LTAResult<()> {
let api_key = std::env::var("API_KEY").expect("API_KEY not found!");
let client = LTAClient::with_api_key(api_key)?;
let bus_services= Bus::get_bus_services(&client, None)?;
println!("{:?}", bus_services);
Ok(())
}
async fn get_erp() -> LTAResult<()> {
let api_key = std::env::var("API_KEY").expect("API_KEY not found!");
let client = LTAClient::with_api_key(api_key)?;
let erp_rates = Traffic::get_erp_rates(&client, 500)?;
println!("{:?}", erp_rates);
Ok(())
}
use lta::r#async::client::LTAClient;
use lta::reqwest::ClientBuilder;
use std::time::Duration;
use lta::Client;
fn my_custom_client() -> LTAClient {
let client = ClientBuilder::new()
.no_gzip()
.connect_timeout(Duration::new(420, 0))
.build()
.unwrap();
LTAClient::new("API_KEY", client)
}
LTAClient
as it holds a connection pool internallyUpdate Freq
in the documentation and prevent
yourself from getting blacklisted. Use a caching mechanism.Changelog can be found here
Is this library being actively developed?
What are the APIs available?
Where do I get the official docs from lta?
lta-rs is licensed under MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
For Singapore based users, you can donate using paylah!