summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJerry Trieu <jerry@advancedtelematic.com>2016-10-26 14:55:53 +0200
committerJerry Trieu <jerry@advancedtelematic.com>2016-10-26 18:03:15 +0200
commit07380a9a8974890c5b484dc3524198daaa766d60 (patch)
treea49bb53f6a7da877cce506960fa253c1fbb2081e
parent20d9ebb51b3bcace6558eabda71a078df97a4e48 (diff)
downloadrvi_sota_client-07380a9a8974890c5b484dc3524198daaa766d60.tar.gz
Use new 'mydevice' endpoint on sota-core
-rw-r--r--src/sota.rs15
1 files changed, 7 insertions, 8 deletions
diff --git a/src/sota.rs b/src/sota.rs
index 57f9308..64abacd 100644
--- a/src/sota.rs
+++ b/src/sota.rs
@@ -3,7 +3,7 @@ use std::{fs, io};
use std::fs::File;
use std::path::PathBuf;
-use datatype::{Config, DeviceReport, DownloadComplete, Error, Package,
+use datatype::{Config, DownloadComplete, Error, Package,
UpdateReport, UpdateRequest, UpdateRequestId, Url};
use http::{Client, Response};
@@ -22,9 +22,9 @@ impl<'c, 'h> Sota<'c, 'h> {
}
/// Takes a path and returns a new endpoint of the format
- /// `<Core server>/api/v1/device_updates/<device-id>$path`.
+ /// `<Core server>/api/v1/mydevice/<device-id>$path`.
fn endpoint(&self, path: &str) -> Url {
- let endpoint = format!("/api/v1/device_updates/{}{}", self.config.device.uuid, path);
+ let endpoint = format!("/api/v1/mydevice/{}{}", self.config.device.uuid, path);
self.config.core.server.join(&endpoint).expect("couldn't build endpoint url")
}
@@ -38,7 +38,7 @@ impl<'c, 'h> Sota<'c, 'h> {
/// Query the Core server for any pending or in-flight package updates.
pub fn get_update_requests(&mut self) -> Result<Vec<UpdateRequest>, Error> {
- let resp_rx = self.client.get(self.endpoint("/queued"), None);
+ let resp_rx = self.client.get(self.endpoint("/updates"), None);
let resp = try!(resp_rx.recv().ok_or(Error::Client("couldn't get new updates".to_string())));
let data = match resp {
Response::Success(data) => data,
@@ -52,7 +52,7 @@ impl<'c, 'h> Sota<'c, 'h> {
/// Download a specific update from the Core server.
pub fn download_update(&mut self, id: UpdateRequestId) -> Result<DownloadComplete, Error> {
- let resp_rx = self.client.get(self.endpoint(&format!("/{}/download", id)), None);
+ let resp_rx = self.client.get(self.endpoint(&format!("/updates/{}/download", id)), None);
let resp = try!(resp_rx.recv().ok_or(Error::Client("couldn't download update".to_string())));
let data = match resp {
Response::Success(data) => data,
@@ -97,9 +97,8 @@ impl<'c, 'h> Sota<'c, 'h> {
/// Send the outcome of a package update to the Core server.
pub fn send_update_report(&mut self, update_report: &UpdateReport) -> Result<(), Error> {
- let report = DeviceReport::new(&self.config.device.uuid, update_report);
- let body = try!(json::encode(&report));
- let url = self.endpoint(&format!("/{}", report.device));
+ let body = try!(json::encode(&update_report.operation_results));
+ let url = self.endpoint(&format!("/updates/{}", update_report.update_id));
let resp_rx = self.client.post(url, Some(body.into_bytes()));
let resp = try!(resp_rx.recv().ok_or(Error::Client("couldn't send update report".to_string())));