Skip to content
This repository has been archived by the owner on Oct 3, 2024. It is now read-only.

Commit

Permalink
Merge pull request #85 from tweedegolf/rework-client-ref
Browse files Browse the repository at this point in the history
Rework client ref
  • Loading branch information
tdittr authored Aug 20, 2024
2 parents 3ce2670 + 1a6d5c4 commit 5aa54e1
Show file tree
Hide file tree
Showing 13 changed files with 201 additions and 186 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions openadr-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ uuid.workspace = true

[dev-dependencies]
tokio = { workspace = true, features = ["full", "test-util"] }
openadr-vtn = { path = "../openadr-vtn" }
5 changes: 1 addition & 4 deletions openadr-client/src/bin/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ use openadr_wire::program::ProgramContent;
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = openadr_client::Client::with_url(
"http://localhost:3000/".try_into()?,
Some(ClientCredentials::new(
"admin".to_string(),
"admin".to_string(),
)),
Some(ClientCredentials::admin()),
);
let _created_program = client.create_program(ProgramContent::new("name")).await?;
// let created_program_1 = client.create_program(ProgramContent::new("name1")).await?;
Expand Down
4 changes: 2 additions & 2 deletions openadr-client/src/bin/everest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use openadr_wire::{
values_map::Value,
};

use openadr_client::{ClientRef, ProgramClient, Target, Timeline};
use openadr_client::{ProgramClient, Target, Timeline};
use std::{error::Error, time::Duration};
use tokio::sync::mpsc::{Receiver, Sender};
use tokio::{select, sync::mpsc};
Expand Down Expand Up @@ -59,7 +59,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
}

async fn poll_timeline(
mut program: ProgramClient<impl ClientRef>,
mut program: ProgramClient,
poll_interval: std::time::Duration,
sender: mpsc::Sender<Timeline>,
) -> Result<(), openadr_client::Error> {
Expand Down
16 changes: 8 additions & 8 deletions openadr-client/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ use openadr_wire::{
};

#[derive(Debug)]
pub struct EventClient<C> {
client: Arc<C>,
pub struct EventClient {
client: Arc<ClientRef>,
data: Event,
}

impl<C: ClientRef> EventClient<C> {
pub(super) fn from_event(client: Arc<C>, event: Event) -> Self {
impl EventClient {
pub(super) fn from_event(client: Arc<ClientRef>, event: Event) -> Self {
Self {
client,
data: event,
Expand Down Expand Up @@ -75,7 +75,7 @@ impl<C: ClientRef> EventClient<C> {
}

/// Create a new report for the event
pub async fn create_report(&self, report_data: ReportContent) -> Result<ReportClient<C>> {
pub async fn create_report(&self, report_data: ReportContent) -> Result<ReportClient> {
if report_data.program_id != self.data().program_id {
return Err(Error::InvalidParentObject);
}
Expand All @@ -93,7 +93,7 @@ impl<C: ClientRef> EventClient<C> {
client_name: Option<&str>,
skip: usize,
limit: usize,
) -> Result<Vec<ReportClient<C>>> {
) -> Result<Vec<ReportClient>> {
let skip_str = skip.to_string();
let limit_str = limit.to_string();

Expand All @@ -116,7 +116,7 @@ impl<C: ClientRef> EventClient<C> {
}

/// Get all reports from the VTN for a specific client, trying to paginate whenever possible
pub async fn get_client_reports(&self, client_name: &str) -> Result<Vec<ReportClient<C>>> {
pub async fn get_client_reports(&self, client_name: &str) -> Result<Vec<ReportClient>> {
let page_size = self.client.default_page_size();
let mut reports = vec![];
let mut page = 0;
Expand All @@ -140,7 +140,7 @@ impl<C: ClientRef> EventClient<C> {
}

/// Get all reports from the VTN, trying to paginate whenever possible
pub async fn get_all_reports(&self) -> Result<Vec<ReportClient<C>>> {
pub async fn get_all_reports(&self) -> Result<Vec<ReportClient>> {
let page_size = self.client.default_page_size();
let mut reports = vec![];
let mut page = 0;
Expand Down
Loading

0 comments on commit 5aa54e1

Please sign in to comment.