pvoutput-client 0.0.3

Client for the PVOutput.org API
Documentation
use jiff::civil::Date;
use pvoutput_client::{
	Client, ClientError,
	types::{
		error::{AddOutputError, AddStatusError, DateTimeError, PostSystemError},
		params::{AddOutputParams, PostSystemParams},
	},
};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
	dotenvy::dotenv()?;
	let (Ok(api_key), Ok(system)) = (std::env::var("PVO_API_KEY"), std::env::var("PVO_SYSTEM")) else {
		panic!("PVO_API_KEY and PVO_SYSTEM must be set! Use .env file or export them.")
	};

	let Ok(system) = system.parse() else {
		panic!("PVO_SYSTEM must be a valid system ID!")
	};

	let client = Client::new(&api_key, system, None, None)?;

	assert!(matches!(
		client.add_outputs(vec![]).await,
		Err(ClientError::EndpointSpecific(AddOutputError::NoData))
	));
	assert!(matches!(
		client.add_batch_status(vec![], false).await,
		Err(ClientError::EndpointSpecific(AddStatusError::NoData))
	));
	assert!(matches!(
		client.add_batch_status_net(vec![]).await,
		Err(ClientError::EndpointSpecific(AddStatusError::NoData))
	));

	assert!(matches!(
		client.add_outputs(vec![AddOutputParams::new(Date::MAX)]).await,
		Err(ClientError::EndpointSpecific(AddOutputError::InvalidDateTime(DateTimeError::DateTooNew(date)))) if date == Date::MAX
	));

	assert!(matches!(
		client.post_system(PostSystemParams::new_rename(format!("{:01000}", 1))).await,
		Err(ClientError::EndpointSpecific(PostSystemError::SystemNameTooLong))
	));

	assert!(matches!(
		client.delete_status(Date::MAX, None).await,
		Err(ClientError::EndpointSpecific(DateTimeError::DateTooNew(date))) if date == Date::MAX
	));

	Ok(())
}