diff options
author | Jerry Trieu <jerry@advancedtelematic.com> | 2016-10-27 14:37:06 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-27 14:37:06 +0200 |
commit | 368109e4dc17c5d2041e132e63d18591c74e8800 (patch) | |
tree | a49bb53f6a7da877cce506960fa253c1fbb2081e | |
parent | 20d9ebb51b3bcace6558eabda71a078df97a4e48 (diff) | |
parent | 07380a9a8974890c5b484dc3524198daaa766d60 (diff) | |
download | rvi_sota_client-368109e4dc17c5d2041e132e63d18591c74e8800.tar.gz |
Merge pull request #135 from advancedtelematic/refactor/PRO-1673/use-mydevice-api
[PRO-1673] Use new 'mydevice' endpoint on sota-core
-rw-r--r-- | src/sota.rs | 15 |
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()))); |