// Code generated by ndpgen. DO NOT EDIT. // // This file contains client wrappers for the ScrobbleRetriever host service. // It is intended for use in Navidrome plugins built with extism-pdk. use extism_pdk::*; use serde::{Deserialize, Serialize}; /// ScrobbleCountOptions carries optional parameters for counting user scrobbles #[derive(Debug, Clone, Default, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct ScrobbleCountOptions { #[serde(default)] pub from_timestamp: Option, #[serde(default)] pub to_timestamp: Option, } /// ScrobbleOptions carries optional parameters for retrieving user scrobbles #[derive(Debug, Clone, Default, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct ScrobbleOptions { #[serde(default)] pub from_timestamp: Option, #[serde(default)] pub to_timestamp: Option, pub descending: bool, pub max_items: i32, #[serde(default)] pub offset: i32, } /// ScrobbleRef represents one instance of a scrobble (instance id, file id, submission time) #[derive(Debug, Clone, Default, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct ScrobbleRef { pub id: i64, pub media_file_id: String, pub submission_time: i64, } #[derive(Debug, Clone, Serialize)] #[serde(rename_all = "camelCase")] struct ScrobbleRetrieverGetFirstTimestampRequest { username: String, } #[derive(Debug, Clone, Deserialize)] #[serde(rename_all = "camelCase")] struct ScrobbleRetrieverGetFirstTimestampResponse { #[serde(default)] result: Option, #[serde(default)] error: Option, } #[derive(Debug, Clone, Serialize)] #[serde(rename_all = "camelCase")] struct ScrobbleRetrieverGetLastTimestampRequest { username: String, } #[derive(Debug, Clone, Deserialize)] #[serde(rename_all = "camelCase")] struct ScrobbleRetrieverGetLastTimestampResponse { #[serde(default)] result: Option, #[serde(default)] error: Option, } #[derive(Debug, Clone, Serialize)] #[serde(rename_all = "camelCase")] struct ScrobbleRetrieverGetScrobblesRequest { username: String, options: ScrobbleOptions, } #[derive(Debug, Clone, Deserialize)] #[serde(rename_all = "camelCase")] struct ScrobbleRetrieverGetScrobblesResponse { #[serde(default)] scrobbles: Vec, #[serde(default)] next: Option, #[serde(default)] error: Option, } #[derive(Debug, Clone, Serialize)] #[serde(rename_all = "camelCase")] struct ScrobbleRetrieverGetScrobbleCountRequest { username: String, options: ScrobbleCountOptions, } #[derive(Debug, Clone, Deserialize)] #[serde(rename_all = "camelCase")] struct ScrobbleRetrieverGetScrobbleCountResponse { #[serde(default)] result: i64, #[serde(default)] error: Option, } #[host_fn] extern "ExtismHost" { fn scrobbleretriever_getfirsttimestamp(input: Json) -> Json; fn scrobbleretriever_getlasttimestamp(input: Json) -> Json; fn scrobbleretriever_getscrobbles(input: Json) -> Json; fn scrobbleretriever_getscrobblecount(input: Json) -> Json; } /// GetFirstTimestamp returns the unix timestamp of the oldest scrobble for the user. /// If the user has no scrobbles, returns nil /// /// # Arguments /// * `username` - String parameter. /// /// # Returns /// The result value. /// /// # Errors /// Returns an error if the host function call fails. pub fn get_first_timestamp(username: &str) -> Result, Error> { let response = unsafe { scrobbleretriever_getfirsttimestamp(Json(ScrobbleRetrieverGetFirstTimestampRequest { username: username.to_owned(), }))? }; if let Some(err) = response.0.error { return Err(Error::msg(err)); } Ok(response.0.result) } /// GetLastTimestamp returns the unix timestamp of the most recent scrobble for the user /// If the user has no scrobbles, return nil /// /// # Arguments /// * `username` - String parameter. /// /// # Returns /// The result value. /// /// # Errors /// Returns an error if the host function call fails. pub fn get_last_timestamp(username: &str) -> Result, Error> { let response = unsafe { scrobbleretriever_getlasttimestamp(Json(ScrobbleRetrieverGetLastTimestampRequest { username: username.to_owned(), }))? }; if let Some(err) = response.0.error { return Err(Error::msg(err)); } Ok(response.0.result) } /// GetScrobbles returns one page of scrobbles for a user. /// /// Parameters: /// - username: the user to query for scrobbles /// - options.FromTimestamp: If specified, the first UNIX timestamp to start fetching scrobbles (inclusive). Otherwise, start from the first scrobble /// - options.ToTimestamp: If specified, the last UNIX timestamp to fetch (inclusive). Otherwise, end at the last scrobble /// - options.Descending: If true, order from newest to oldest. Otherwise, oldest to newest /// - options.MaxItems: The maximum number of items to retrieve. The maximum value (and default) if not specified is 5000 /// - options.Offset: Pagination state; only valid as received on the options returned by a previous call. Never set it manually /// /// Returns: /// - scrobbles: The scrobbles in the requested range, ordered by submission time /// (ties broken by scrobble ID) in the direction given by options.Descending /// - next: The options for the following page, or nil once no scrobbles remain. /// Pass it back to GetScrobbles unchanged and repeat until it is nil. It carries an /// adjusted FromTimestamp/ToTimestamp, so keep a copy if you still need the original range /// /// # Arguments /// * `username` - String parameter. /// * `options` - ScrobbleOptions parameter. /// /// # Returns /// A tuple of (scrobbles, next). /// /// # Errors /// Returns an error if the host function call fails. pub fn get_scrobbles(username: &str, options: ScrobbleOptions) -> Result<(Vec, Option), Error> { let response = unsafe { scrobbleretriever_getscrobbles(Json(ScrobbleRetrieverGetScrobblesRequest { username: username.to_owned(), options: options, }))? }; if let Some(err) = response.0.error { return Err(Error::msg(err)); } Ok((response.0.scrobbles, response.0.next)) } /// GetScrobbleCount returns the number of scrobbles for a user in a given range /// /// Parameters: /// - username: the user to query for scrobbles /// - options.FromTimestamp: If specified, the first UNIX timestamp to start fetching scrobbles (inclusive). Otherwise, start from the first scrobble /// - options.ToTimestamp: If specified, the last UNIX timestamp to fetch (inclusive). Otherwise, end at the last scrobble /// /// Returns: /// - the number of scrobbles in the given range, or 0 /// /// # Arguments /// * `username` - String parameter. /// * `options` - ScrobbleCountOptions parameter. /// /// # Returns /// The result value. /// /// # Errors /// Returns an error if the host function call fails. pub fn get_scrobble_count(username: &str, options: ScrobbleCountOptions) -> Result { let response = unsafe { scrobbleretriever_getscrobblecount(Json(ScrobbleRetrieverGetScrobbleCountRequest { username: username.to_owned(), options: options, }))? }; if let Some(err) = response.0.error { return Err(Error::msg(err)); } Ok(response.0.result) }