mod enums;
mod structs;
pub use self::enums::*;
pub use self::structs::*;
use api_request_utils_rs::{
RequestInfo,
RequestModifiers,
RequestDefaults,
RequestHandler,
ErrorHandler,
reqwest::{
Client,
RequestBuilder,
},
serde_json::Value
};
pub struct Inventory<'a> {
client : Client,
api_key : &'a str,
error_handler : &'a ErrorHandler<()>
}
impl RequestInfo for Inventory<'_> {
const BASE_URL : &'static str = "https://app.ticketmaster.com/inventory-status/v1";
fn client(&self) -> &Client {
&self.client
}
}
impl RequestModifiers for Inventory<'_> {}
impl RequestDefaults for Inventory<'_> {
fn default_parameters(&self,request_builder: RequestBuilder) -> RequestBuilder {
request_builder.query(&[("apikey", self.api_key)])
}
}
impl RequestHandler for Inventory<'_> {}
impl<'a> Inventory<'a> {
pub fn new(api_key: &'a str, error_handler: &'a ErrorHandler<()>) -> Self {
let client = Client::new();
Self::new_with_client(client, api_key, error_handler)
}
pub fn new_with_client(client: Client, api_key: &'a str, error_handler: &'a ErrorHandler<()>) -> Self {
Self {
client,
api_key,
error_handler,
}
}
pub async fn inventory_status(&self, event_ids: &[u32]) -> Option<InventoryStatus> {
let parameters = std::collections::HashMap::from([("track_isrc", Value::from(event_ids))]);
self.get_request_handler::<InventoryStatus, ()>("availability", ¶meters, self.error_handler).await
}
}