-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
df22f76
commit 56b7eb8
Showing
11 changed files
with
174 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use crate::api::Api; | ||
use crate::commands::CommandError; | ||
use crate::commands; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] | ||
pub struct AssetSignature { | ||
pub(crate) signature: String, | ||
} | ||
|
||
impl Api { | ||
pub fn get_version_asset_signatures( | ||
&self, | ||
app_id: &str, | ||
revision: u32, | ||
) -> Result<Vec<AssetSignature>, CommandError> { | ||
Ok(serde_json::from_value(commands::get( | ||
&self.authentication, | ||
&format!( | ||
"v4/assets?select=signature&app_id=eq.{}&app_revision=eq.{}&type=eq.edge-app-file", | ||
app_id, revision | ||
), | ||
)?)?) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use crate::api::Api; | ||
use crate::commands::CommandError; | ||
use crate::commands; | ||
|
||
use serde_json::json; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
|
||
#[derive(Debug)] | ||
pub struct EdgeApps { | ||
pub value: serde_json::Value, | ||
} | ||
|
||
impl Api { | ||
pub fn create_app(&self, name: String) -> Result<String, CommandError> { | ||
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] | ||
pub struct ApiResponse { | ||
#[serde(default)] | ||
pub id: String, | ||
#[serde(default)] | ||
pub name: String, | ||
} | ||
|
||
let response = commands::post( | ||
&self.authentication, | ||
"v4/edge-apps?select=id,name", | ||
&json!({ "name": name }), | ||
)?; | ||
|
||
let json_response = serde_json::from_value::<Vec<ApiResponse>>(response)?; | ||
let app_id = json_response[0].id.clone(); | ||
|
||
if app_id.is_empty() { | ||
return Err(CommandError::MissingField); | ||
} | ||
|
||
Ok(app_id) | ||
} | ||
|
||
pub fn list_apps(&self) -> Result<EdgeApps, CommandError> { | ||
Ok(EdgeApps::new(commands::get( | ||
&self.authentication, | ||
"v4/edge-apps?select=id,name", | ||
)?)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use crate::authentication::Authentication; | ||
|
||
pub mod edge_app; | ||
pub mod version; | ||
pub mod asset; | ||
|
||
pub struct Api { | ||
pub authentication: Authentication | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use crate::api::Api; | ||
use crate::commands::CommandError; | ||
use crate::commands; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] | ||
pub struct EdgeAppVersion { | ||
#[serde(default)] | ||
pub user_version: Option<String>, | ||
#[serde(default)] | ||
pub description: Option<String>, | ||
#[serde(default)] | ||
pub icon: Option<String>, | ||
#[serde(default)] | ||
pub author: Option<String>, | ||
#[serde(default)] | ||
pub homepage_url: Option<String>, | ||
#[serde(default)] | ||
pub ready_signal: bool, | ||
#[serde(default)] | ||
pub revision: u32, | ||
} | ||
|
||
|
||
impl Api { | ||
pub fn get_latest_revision( | ||
&self, | ||
app_id: &str, | ||
) -> Result<Option<EdgeAppVersion>, CommandError> { | ||
let response = commands::get( | ||
&self.authentication, | ||
&format!( | ||
"v4.1/edge-apps/versions?select=user_version,description,icon,author,homepage_url,revision,ready_signal&app_id=eq.{}&order=revision.desc&limit=1", | ||
app_id | ||
), | ||
)?; | ||
|
||
let versions: Vec<EdgeAppVersion> = | ||
serde_json::from_value::<Vec<EdgeAppVersion>>(response)?; | ||
|
||
if versions.is_empty() { | ||
return Ok(None); | ||
} | ||
Ok(versions.first().cloned()) | ||
} | ||
} |
Oops, something went wrong.