@@ -132,8 +132,8 @@ impl FactoryAPI { | |||
.send().await | |||
.map_err(FactoryError::Protocol)?; | |||
//println!("result: {}", result.text().await.map_err(FactoryError::Protocol)?); | |||
//todo!() | |||
handle_json_response::<SearchResponse>(result).await | |||
//Err(FactoryError::Response(ErrorPayload { error: -42, error_message: "Disabled on purpose".to_owned() })) | |||
} | |||
pub async fn create_robot(&self, robot: CreateRobotPayload) -> Result<CreateRobotResponse, FactoryError> { | |||
@@ -219,7 +219,9 @@ impl FactoryAPI { | |||
.header("Authorization", "Bearer ".to_owned() + &token) | |||
.send().await | |||
.map_err(FactoryError::Protocol)?; | |||
//println!("result: {}", result.text().await.map_err(FactoryError::Protocol)?); | |||
handle_json_response::<FactoryInfoResponse>(result).await | |||
//Err(FactoryError::Response(ErrorPayload { error: -42, error_message: "Disabled on purpose".to_owned() })) | |||
} | |||
pub async fn my_robots(&self) -> Result<MyRobotsResponse, FactoryError> { | |||
@@ -258,7 +260,9 @@ impl FactoryAPI { | |||
.header("Authorization", "Bearer ".to_owned() + &token) | |||
.send().await | |||
.map_err(FactoryError::Protocol)?; | |||
//println!("result: {}", result.text().await.map_err(FactoryError::Protocol)?); | |||
handle_json_response::<GetRobotResponse>(result).await | |||
//Err(FactoryError::Response(ErrorPayload { error: -42, error_message: "Disabled on purpose".to_owned() })) | |||
} | |||
pub async fn moderate(&self, payload: ModerateRobotPayload, id: String) -> Result<(), FactoryError> { | |||
@@ -121,6 +121,8 @@ pub struct SearchResponseItem { | |||
pub prices: Vec<RobotPrice>, | |||
#[serde(rename = "purchased")] | |||
pub purchased: bool, | |||
#[serde(rename = "downloaded")] | |||
pub downloaded: bool, | |||
} | |||
#[derive(Deserialize, Serialize, Clone, Debug)] | |||
@@ -129,6 +131,8 @@ pub struct RobotInfo { | |||
pub id: String, // GUID | |||
#[serde(rename = "name")] | |||
pub name: String, | |||
#[serde(rename = "parentId")] | |||
pub parent_id: Option<String>, // GUID? | |||
#[serde(rename = "creatorId")] | |||
pub creator_id: String, // GUID | |||
#[serde(rename = "creatorName")] | |||
@@ -161,6 +165,15 @@ pub struct RobotInfo { | |||
pub maximum_offset_y: f64, | |||
#[serde(rename = "maximumOffsetZ")] | |||
pub maximum_offset_z: f64, | |||
// TODO additional fields | |||
// these seem to always be null so it is not worth deserializing them | |||
// and adding some placeholder type might cause them to break in the future | |||
// #[serde(rename = "colourPallet")] | |||
// #[serde(rename = "materialPalette")] | |||
// #[serde(rename = "materialPalette")] | |||
// #[serde(rename = "cosmeticBlockVariantPalette")] | |||
#[serde(rename = "version")] | |||
pub version: usize, | |||
} | |||
impl std::string::ToString for RobotInfo { | |||
@@ -281,6 +294,8 @@ pub struct GetRobotResponse { | |||
pub description: String, | |||
#[serde(rename = "created")] | |||
pub created: String, // date | |||
#[serde(rename = "moderated")] | |||
pub moderated: bool, | |||
} | |||
// moderate robot endpoint | |||
@@ -52,12 +52,24 @@ async fn robocraft2_factory_default_query() -> Result<(), ()> { | |||
Ok(()) | |||
} | |||
#[cfg(feature = "robocraft2")] | |||
#[tokio::test] | |||
#[allow(dead_code)] | |||
async fn robocraft2_factory_info_query() -> Result<(), ()> { | |||
let api = builder().await; | |||
let result = api.get("08dadf8d-1953-44bc-8d49-c432f6640723".to_owned()).await; | |||
assert!(result.is_ok()); | |||
let robo_info = unwrap_factory2(result); | |||
println!("GetRobotResponse {}", serde_json::to_string_pretty(&robo_info).unwrap()); | |||
Ok(()) | |||
} | |||
#[cfg(feature = "robocraft2")] | |||
#[tokio::test] | |||
async fn robocraft2_factory_sort() -> Result<(), ()> { | |||
let api = builder().await; | |||
let mut query = robocraft2::SearchPayload::default(); | |||
query.sort_by = robocraft2::sort::DEFAULT; | |||
query.sort_by = robocraft2::sort::DATE; | |||
query.order_by = robocraft2::order::ASCENDING; | |||
let result = api.search(query).await; | |||
let robo_info = unwrap_factory2(result); | |||
@@ -70,6 +82,7 @@ async fn robocraft2_factory_sort() -> Result<(), ()> { | |||
//println!("SearchResponseItem {}", serde_json::to_string_pretty(&robot).unwrap()); | |||
println!("date: {}", robot.robot.created); | |||
} | |||
println!("first url: {}", robo_info.results[0].robot.image.as_ref().unwrap()); | |||
Ok(()) | |||
} | |||