use std::collections::BTreeMap;
use serde::{Deserialize, Serialize};
use crate::{Client, ClientError};
pub const CONTRACT_VERSION: &str = "0.2.0";
pub const OPERATION_NAMES: [&str; 16] = [
"status",
"context",
"image",
"history",
"manifest_get",
"manifest_set",
"pause",
"resume",
"cancel",
"start_print",
"set_feedrate_factor",
"set_flowrate_factor",
"set_tool_target_c",
"set_bed_target_c",
"set_fan_percent",
"acknowledge_failure",
];
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum AcknowledgementDisposition {
#[serde(rename = "continue")]
Continue,
#[serde(rename = "watch")]
Watch,
#[serde(rename = "stop")]
Stop,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ActionAnswer {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub intervention: Option<Intervention>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub printer_refusal: Option<String>,
pub record: ActionRecord,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ActionExecutedPayload {
pub action_id: ActionId,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub intervention_id: Option<InterventionId>,
}
pub type ActionId = String;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum ActionKind {
#[serde(rename = "pause")]
Pause,
#[serde(rename = "resume")]
Resume,
#[serde(rename = "cancel")]
Cancel,
#[serde(rename = "start_print")]
StartPrint,
#[serde(rename = "set_feedrate_factor")]
SetFeedrateFactor,
#[serde(rename = "set_flowrate_factor")]
SetFlowrateFactor,
#[serde(rename = "set_tool_target_c")]
SetToolTargetC,
#[serde(rename = "set_bed_target_c")]
SetBedTargetC,
#[serde(rename = "set_fan_percent")]
SetFanPercent,
#[serde(rename = "acknowledge_failure")]
AcknowledgeFailure,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ActionRecord {
pub decision: PolicyDecision,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub executed_at: Option<Timestamp>,
pub id: ActionId,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub outcome: Option<ExecutionOutcome>,
pub print_id: PrintId,
pub request: ActionRequest,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ActionRejectedPayload {
pub action_id: ActionId,
pub decision: PolicyDecision,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ActionRequest {
pub action: PrintAction,
pub actor: Actor,
pub requested_at: Timestamp,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ActionRequestedPayload {
pub action: PrintAction,
pub action_id: ActionId,
pub actor: Actor,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum Actor {
#[serde(rename = "agent")]
Agent {
session_name: String,
},
#[serde(rename = "operator")]
Operator,
#[serde(rename = "system")]
System,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum ActorClass {
#[serde(rename = "agent")]
Agent,
#[serde(rename = "operator")]
Operator,
#[serde(rename = "system")]
System,
}
pub type Adjustable = String;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct AgentAssessment {
pub confidence: Confidence,
pub did: String,
pub escalating: bool,
pub should_continue: bool,
pub summary: String,
pub why: String,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct AgentAssessmentPayload {
pub assessment: AgentAssessment,
pub session_name: String,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum Confidence {
#[serde(rename = "low")]
Low,
#[serde(rename = "medium")]
Medium,
#[serde(rename = "high")]
High,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ContextAnswer {
pub context: PrintContext,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub image_path: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct EffectiveBounds {
pub allowed: BTreeMap<String, Range>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ErrorAnswer {
pub error: String,
}
pub type EventId = String;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct EventRecord {
pub id: EventId,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub image: Option<ImageRef>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub print_id: Option<PrintId>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub raw: Option<RawBytes>,
pub received_at: Timestamp,
pub source: EventSource,
#[serde(flatten)]
pub kind: EventRecordKind,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(tag = "kind")]
pub enum EventRecordKind {
#[serde(rename = "obico_failure_alert")]
ObicoFailureAlert {
payload: ObicoFailureAlertPayload,
},
#[serde(rename = "obico_printer_notification")]
ObicoPrinterNotification {
payload: ObicoPrinterNotificationPayload,
},
#[serde(rename = "malformed_external_event")]
MalformedExternalEvent {
payload: MalformedExternalEventPayload,
},
#[serde(rename = "action_requested")]
ActionRequested {
payload: ActionRequestedPayload,
},
#[serde(rename = "action_executed")]
ActionExecuted {
payload: ActionExecutedPayload,
},
#[serde(rename = "action_rejected")]
ActionRejected {
payload: ActionRejectedPayload,
},
#[serde(rename = "intervention_expired")]
InterventionExpired {
payload: InterventionExpiredPayload,
},
#[serde(rename = "supervision_session_opened")]
SupervisionSessionOpened {
payload: SupervisionSessionOpenedPayload,
},
#[serde(rename = "supervision_session_closed")]
SupervisionSessionClosed {
payload: SupervisionSessionClosedPayload,
},
#[serde(rename = "agent_assessment")]
AgentAssessment {
payload: AgentAssessmentPayload,
},
#[serde(rename = "operator_acknowledgement")]
OperatorAcknowledgement {
payload: OperatorAcknowledgementPayload,
},
#[serde(rename = "port_failure")]
PortFailure {
payload: PortFailurePayload,
},
#[serde(rename = "startup_reconciliation")]
StartupReconciliation {
payload: StartupReconciliationPayload,
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum EventSource {
#[serde(rename = "obico")]
Obico,
#[serde(rename = "operator")]
Operator,
#[serde(rename = "agent")]
Agent,
#[serde(rename = "system")]
System,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum ExecutionOutcome {
#[serde(rename = "succeeded")]
Succeeded,
#[serde(rename = "failed")]
Failed {
reason: String,
},
}
pub type FileName = String;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct HeaterSnapshot {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub actual_c: Option<Reported>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub offset_c: Option<Reported>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub target_c: Option<Reported>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct HistoryAnswer {
pub events: Vec<EventRecord>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ImageAnswer {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub path: Option<String>,
pub record: ImageRecord,
}
pub type ImageId = String;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ImageRecord {
pub byte_len: i64,
pub content_type: String,
pub event_id: EventId,
pub fetched_at: Timestamp,
pub id: ImageId,
pub print_id: PrintId,
pub relative_path: String,
pub sha256: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub source_url: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ImageRef {
pub id: ImageId,
pub sha256: String,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Intervention {
pub action_id: ActionId,
pub adjustable: Adjustable,
pub applied_at: Timestamp,
pub applied_value: f64,
pub expires_at: Timestamp,
pub id: InterventionId,
pub outcome: InterventionOutcome,
pub print_id: PrintId,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub prior_value: Option<f64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub restored_at: Option<Timestamp>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct InterventionExpiredPayload {
pub adjustable: Adjustable,
pub intervention_id: InterventionId,
pub outcome: InterventionOutcome,
}
pub type InterventionId = String;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum InterventionOutcome {
#[serde(rename = "still_active")]
StillActive,
#[serde(rename = "restored")]
Restored,
#[serde(rename = "restore_unavailable")]
RestoreUnavailable,
#[serde(rename = "restore_failed")]
RestoreFailed {
reason: String,
},
#[serde(rename = "superseded")]
Superseded {
by: InterventionId,
},
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct JobManifest {
pub allowed: BTreeMap<String, Range>,
pub file_name: String,
pub material: String,
pub metadata: BTreeMap<String, String>,
pub nozzle_diameter_mm: f64,
pub slicer_profile: String,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct JobSnapshot {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub completion: Option<Reported>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub error: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub estimated_print_time_s: Option<i64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub file_name: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub file_origin: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub print_time_left_s: Option<i64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub print_time_s: Option<i64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub size_bytes: Option<i64>,
pub state: PrinterState,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct MalformedExternalEventPayload {
pub detail: String,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ManifestAnswer {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub manifest: Option<JobManifest>,
pub narrowings: Vec<ManifestNarrowing>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ManifestNarrowing {
pub adjustable: Adjustable,
pub applied: Range,
pub requested: Range,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ObicoFailureAlertPayload {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub ended_at: Option<Timestamp>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub file_name: Option<String>,
pub is_warning: bool,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub obico_print_id: Option<i64>,
pub print_paused: bool,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub started_at: Option<Timestamp>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum ObicoNotificationType {
#[serde(rename = "started")]
Started,
#[serde(rename = "done")]
Done,
#[serde(rename = "cancelled")]
Cancelled,
#[serde(rename = "paused")]
Paused,
#[serde(rename = "resumed")]
Resumed,
#[serde(rename = "filament_change")]
FilamentChange,
#[serde(rename = "heater_cooled")]
HeaterCooled,
#[serde(rename = "heater_target")]
HeaterTarget,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ObicoPrinterNotificationPayload {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub ended_at: Option<Timestamp>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub file_name: Option<String>,
pub notification_type: ObicoNotificationType,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub obico_print_id: Option<i64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub started_at: Option<Timestamp>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct OperatorAcknowledgementPayload {
pub acknowledged_event_id: EventId,
pub disposition: AcknowledgementDisposition,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum PolicyDecision {
#[serde(rename = "accepted")]
Accepted,
#[serde(rename = "rejected")]
Rejected(RejectionReason),
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PortFailurePayload {
pub detail: String,
pub event_id: EventId,
pub site: PortFailureSite,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum PortFailureSite {
#[serde(rename = "printer_snapshot")]
PrinterSnapshot,
#[serde(rename = "printer_job")]
PrinterJob,
#[serde(rename = "image_write")]
ImageWrite,
#[serde(rename = "supervision_turn")]
SupervisionTurn,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(tag = "action")]
pub enum PrintAction {
#[serde(rename = "pause")]
Pause {
actor: Actor,
reason: String,
},
#[serde(rename = "resume")]
Resume {
actor: Actor,
reason: String,
},
#[serde(rename = "cancel")]
Cancel {
actor: Actor,
reason: String,
},
#[serde(rename = "start_print")]
StartPrint {
actor: Actor,
file_name: FileName,
manifest: JobManifest,
reason: String,
},
#[serde(rename = "set_feedrate_factor")]
SetFeedrateFactor {
actor: Actor,
#[serde(default, skip_serializing_if = "Option::is_none")]
duration_s: Option<i64>,
factor: f64,
reason: String,
},
#[serde(rename = "set_flowrate_factor")]
SetFlowrateFactor {
actor: Actor,
#[serde(default, skip_serializing_if = "Option::is_none")]
duration_s: Option<i64>,
factor: f64,
reason: String,
},
#[serde(rename = "set_tool_target_c")]
SetToolTargetC {
actor: Actor,
#[serde(default, skip_serializing_if = "Option::is_none")]
duration_s: Option<i64>,
reason: String,
target_c: f64,
tool: i64,
},
#[serde(rename = "set_bed_target_c")]
SetBedTargetC {
actor: Actor,
#[serde(default, skip_serializing_if = "Option::is_none")]
duration_s: Option<i64>,
reason: String,
target_c: f64,
},
#[serde(rename = "set_fan_percent")]
SetFanPercent {
actor: Actor,
#[serde(default, skip_serializing_if = "Option::is_none")]
duration_s: Option<i64>,
percent: f64,
reason: String,
},
#[serde(rename = "acknowledge_failure")]
AcknowledgeFailure {
actor: Actor,
disposition: AcknowledgementDisposition,
event_id: EventId,
reason: String,
},
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PrintContext {
pub bounds: EffectiveBounds,
pub interventions: Vec<Intervention>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub job: Option<JobSnapshot>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub latest_image: Option<ImageRef>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub manifest: Option<JobManifest>,
pub print: PrintRecord,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub printer: Option<PrinterSnapshot>,
pub recent_events: Vec<EventRecord>,
}
pub type PrintId = String;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PrintRecord {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub end_reason: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub ended_at: Option<Timestamp>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub file_name: Option<String>,
pub id: PrintId,
pub narrowings: Vec<ManifestNarrowing>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub obico_print_id: Option<i64>,
pub opened_at: Timestamp,
pub state: PrinterState,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PrinterSnapshot {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub bed: Option<HeaterSnapshot>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub chamber: Option<HeaterSnapshot>,
pub connection: PrinterState,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub fan_percent: Option<Reported>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub feedrate_factor: Option<Reported>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub flowrate_factor: Option<Reported>,
pub observed_at: Timestamp,
pub tools: Vec<HeaterSnapshot>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum PrinterState {
#[serde(rename = "operational")]
Operational,
#[serde(rename = "paused")]
Paused,
#[serde(rename = "printing")]
Printing,
#[serde(rename = "cancelling")]
Cancelling,
#[serde(rename = "error")]
Error,
#[serde(rename = "offline")]
Offline,
#[serde(rename = "unknown")]
Unknown(String),
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Range {
pub max: f64,
pub min: f64,
}
pub type RawBytes = String;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum RejectionReason {
#[serde(rename = "out_of_bounds")]
OutOfBounds {
adjustable: Adjustable,
allowed: Range,
requested: f64,
},
#[serde(rename = "actor_may_not_request")]
ActorMayNotRequest {
action: ActionKind,
actor_class: ActorClass,
},
#[serde(rename = "no_active_print")]
NoActivePrint,
#[serde(rename = "invalid_from_state")]
InvalidFromState {
state: PrinterState,
},
#[serde(rename = "min_interval_not_elapsed")]
MinIntervalNotElapsed {
interval_s: i64,
since_last_s: i64,
},
#[serde(rename = "unsupported_adjustable")]
UnsupportedAdjustable {
adjustable: Adjustable,
},
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Reported {
pub out_of_range: bool,
pub value: f64,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum StartupOutcome {
#[serde(rename = "print_adopted")]
PrintAdopted,
#[serde(rename = "session_resumed")]
SessionResumed {
session_name: String,
},
#[serde(rename = "intervention_expired")]
InterventionExpired {
adjustable: Adjustable,
intervention_id: InterventionId,
outcome: InterventionOutcome,
},
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct StartupReconciliationPayload {
pub outcome: StartupOutcome,
pub print_id: PrintId,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct StatusAnswer {
pub interventions: Vec<Intervention>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub job: Option<JobSnapshot>,
pub print: PrintRecord,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub printer: Option<PrinterSnapshot>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub session: Option<SupervisionSession>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct SupervisionSession {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub close_reason: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub closed_at: Option<Timestamp>,
pub created_at: Timestamp,
pub harness_identity: String,
pub last_turn_at: Timestamp,
pub print_id: PrintId,
pub session_name: String,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct SupervisionSessionClosedPayload {
pub close_reason: String,
pub session_name: String,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct SupervisionSessionOpenedPayload {
pub harness_identity: String,
pub session_name: String,
}
pub type Timestamp = String;
impl Client {
pub fn status(&self, print_id: &str) -> Result<StatusAnswer, ClientError> {
let target = format!("/v1/prints/{print_id}/status");
let asked: Vec<(String, String)> = Vec::new();
let sending: Option<serde_json::Value> = None;
self.call("GET", &target, &asked, sending.as_ref())
}
pub fn context(&self, print_id: &str) -> Result<ContextAnswer, ClientError> {
let target = format!("/v1/prints/{print_id}/context");
let asked: Vec<(String, String)> = Vec::new();
let sending: Option<serde_json::Value> = None;
self.call("GET", &target, &asked, sending.as_ref())
}
pub fn image(&self, image_id: &str) -> Result<ImageAnswer, ClientError> {
let target = format!("/v1/images/{image_id}");
let asked: Vec<(String, String)> = Vec::new();
let sending: Option<serde_json::Value> = None;
self.call("GET", &target, &asked, sending.as_ref())
}
pub fn history(
&self,
print_id: &str,
limit: Option<i64>,
) -> Result<HistoryAnswer, ClientError> {
let target = format!("/v1/prints/{print_id}/history");
let mut asked: Vec<(String, String)> = Vec::new();
if let Some(value) = limit {
asked.push(("limit".to_owned(), value.to_string()));
}
let sending: Option<serde_json::Value> = None;
self.call("GET", &target, &asked, sending.as_ref())
}
pub fn manifest_get(&self, print_id: &str) -> Result<ManifestAnswer, ClientError> {
let target = format!("/v1/prints/{print_id}/manifest");
let asked: Vec<(String, String)> = Vec::new();
let sending: Option<serde_json::Value> = None;
self.call("GET", &target, &asked, sending.as_ref())
}
pub fn manifest_set(
&self,
print_id: &str,
reason: &str,
manifest: &JobManifest,
) -> Result<ManifestAnswer, ClientError> {
crate::reason_given(reason)?;
let target = format!("/v1/prints/{print_id}/manifest");
let asked: Vec<(String, String)> = Vec::new();
let mut sending = serde_json::Map::new();
sending.insert("reason".to_owned(), crate::as_value(&reason)?);
sending.insert("manifest".to_owned(), crate::as_value(&manifest)?);
let sending = Some(serde_json::Value::Object(sending));
self.call("PUT", &target, &asked, sending.as_ref())
}
pub fn pause(&self, print_id: &str, reason: &str) -> Result<ActionAnswer, ClientError> {
crate::reason_given(reason)?;
let target = format!("/v1/prints/{print_id}/actions/pause");
let asked: Vec<(String, String)> = Vec::new();
let mut sending = serde_json::Map::new();
sending.insert("actor".to_owned(), crate::as_value(&self.actor())?);
sending.insert("reason".to_owned(), crate::as_value(&reason)?);
let sending = Some(serde_json::Value::Object(sending));
self.call("POST", &target, &asked, sending.as_ref())
}
pub fn resume(&self, print_id: &str, reason: &str) -> Result<ActionAnswer, ClientError> {
crate::reason_given(reason)?;
let target = format!("/v1/prints/{print_id}/actions/resume");
let asked: Vec<(String, String)> = Vec::new();
let mut sending = serde_json::Map::new();
sending.insert("actor".to_owned(), crate::as_value(&self.actor())?);
sending.insert("reason".to_owned(), crate::as_value(&reason)?);
let sending = Some(serde_json::Value::Object(sending));
self.call("POST", &target, &asked, sending.as_ref())
}
pub fn cancel(&self, print_id: &str, reason: &str) -> Result<ActionAnswer, ClientError> {
crate::reason_given(reason)?;
let target = format!("/v1/prints/{print_id}/actions/cancel");
let asked: Vec<(String, String)> = Vec::new();
let mut sending = serde_json::Map::new();
sending.insert("actor".to_owned(), crate::as_value(&self.actor())?);
sending.insert("reason".to_owned(), crate::as_value(&reason)?);
let sending = Some(serde_json::Value::Object(sending));
self.call("POST", &target, &asked, sending.as_ref())
}
pub fn start_print(
&self,
print_id: &str,
file_name: &FileName,
manifest: &JobManifest,
reason: &str,
) -> Result<ActionAnswer, ClientError> {
crate::reason_given(reason)?;
let target = format!("/v1/prints/{print_id}/actions/start_print");
let asked: Vec<(String, String)> = Vec::new();
let mut sending = serde_json::Map::new();
sending.insert("actor".to_owned(), crate::as_value(&self.actor())?);
sending.insert("file_name".to_owned(), crate::as_value(&file_name)?);
sending.insert("manifest".to_owned(), crate::as_value(&manifest)?);
sending.insert("reason".to_owned(), crate::as_value(&reason)?);
let sending = Some(serde_json::Value::Object(sending));
self.call("POST", &target, &asked, sending.as_ref())
}
pub fn set_feedrate_factor(
&self,
print_id: &str,
factor: f64,
reason: &str,
duration_s: Option<i64>,
) -> Result<ActionAnswer, ClientError> {
crate::reason_given(reason)?;
let target = format!("/v1/prints/{print_id}/actions/set_feedrate_factor");
let asked: Vec<(String, String)> = Vec::new();
let mut sending = serde_json::Map::new();
sending.insert("actor".to_owned(), crate::as_value(&self.actor())?);
if let Some(value) = duration_s {
sending.insert("duration_s".to_owned(), crate::as_value(&value)?);
}
sending.insert("factor".to_owned(), crate::as_value(&factor)?);
sending.insert("reason".to_owned(), crate::as_value(&reason)?);
let sending = Some(serde_json::Value::Object(sending));
self.call("POST", &target, &asked, sending.as_ref())
}
pub fn set_flowrate_factor(
&self,
print_id: &str,
factor: f64,
reason: &str,
duration_s: Option<i64>,
) -> Result<ActionAnswer, ClientError> {
crate::reason_given(reason)?;
let target = format!("/v1/prints/{print_id}/actions/set_flowrate_factor");
let asked: Vec<(String, String)> = Vec::new();
let mut sending = serde_json::Map::new();
sending.insert("actor".to_owned(), crate::as_value(&self.actor())?);
if let Some(value) = duration_s {
sending.insert("duration_s".to_owned(), crate::as_value(&value)?);
}
sending.insert("factor".to_owned(), crate::as_value(&factor)?);
sending.insert("reason".to_owned(), crate::as_value(&reason)?);
let sending = Some(serde_json::Value::Object(sending));
self.call("POST", &target, &asked, sending.as_ref())
}
pub fn set_tool_target_c(
&self,
print_id: &str,
reason: &str,
target_c: f64,
tool: i64,
duration_s: Option<i64>,
) -> Result<ActionAnswer, ClientError> {
crate::reason_given(reason)?;
let target = format!("/v1/prints/{print_id}/actions/set_tool_target_c");
let asked: Vec<(String, String)> = Vec::new();
let mut sending = serde_json::Map::new();
sending.insert("actor".to_owned(), crate::as_value(&self.actor())?);
if let Some(value) = duration_s {
sending.insert("duration_s".to_owned(), crate::as_value(&value)?);
}
sending.insert("reason".to_owned(), crate::as_value(&reason)?);
sending.insert("target_c".to_owned(), crate::as_value(&target_c)?);
sending.insert("tool".to_owned(), crate::as_value(&tool)?);
let sending = Some(serde_json::Value::Object(sending));
self.call("POST", &target, &asked, sending.as_ref())
}
pub fn set_bed_target_c(
&self,
print_id: &str,
reason: &str,
target_c: f64,
duration_s: Option<i64>,
) -> Result<ActionAnswer, ClientError> {
crate::reason_given(reason)?;
let target = format!("/v1/prints/{print_id}/actions/set_bed_target_c");
let asked: Vec<(String, String)> = Vec::new();
let mut sending = serde_json::Map::new();
sending.insert("actor".to_owned(), crate::as_value(&self.actor())?);
if let Some(value) = duration_s {
sending.insert("duration_s".to_owned(), crate::as_value(&value)?);
}
sending.insert("reason".to_owned(), crate::as_value(&reason)?);
sending.insert("target_c".to_owned(), crate::as_value(&target_c)?);
let sending = Some(serde_json::Value::Object(sending));
self.call("POST", &target, &asked, sending.as_ref())
}
pub fn set_fan_percent(
&self,
print_id: &str,
percent: f64,
reason: &str,
duration_s: Option<i64>,
) -> Result<ActionAnswer, ClientError> {
crate::reason_given(reason)?;
let target = format!("/v1/prints/{print_id}/actions/set_fan_percent");
let asked: Vec<(String, String)> = Vec::new();
let mut sending = serde_json::Map::new();
sending.insert("actor".to_owned(), crate::as_value(&self.actor())?);
if let Some(value) = duration_s {
sending.insert("duration_s".to_owned(), crate::as_value(&value)?);
}
sending.insert("percent".to_owned(), crate::as_value(&percent)?);
sending.insert("reason".to_owned(), crate::as_value(&reason)?);
let sending = Some(serde_json::Value::Object(sending));
self.call("POST", &target, &asked, sending.as_ref())
}
pub fn acknowledge_failure(
&self,
print_id: &str,
disposition: &AcknowledgementDisposition,
event_id: &EventId,
reason: &str,
) -> Result<ActionAnswer, ClientError> {
crate::reason_given(reason)?;
let target = format!("/v1/prints/{print_id}/actions/acknowledge_failure");
let asked: Vec<(String, String)> = Vec::new();
let mut sending = serde_json::Map::new();
sending.insert("actor".to_owned(), crate::as_value(&self.actor())?);
sending.insert("disposition".to_owned(), crate::as_value(&disposition)?);
sending.insert("event_id".to_owned(), crate::as_value(&event_id)?);
sending.insert("reason".to_owned(), crate::as_value(&reason)?);
let sending = Some(serde_json::Value::Object(sending));
self.call("POST", &target, &asked, sending.as_ref())
}
}