diff --git a/Cargo.toml b/Cargo.toml index 5ad9ba3..cd37669 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "amp-client" description = "The Amphitheatre API client for Rust" -version = "0.3.3" +version = "0.4.0" edition = "2021" license = "Apache-2.0" homepage = "https://amphitheatre.app" diff --git a/src/accounts.rs b/src/accounts.rs index 2937e9f..7642b15 100644 --- a/src/accounts.rs +++ b/src/accounts.rs @@ -15,8 +15,6 @@ use amp_common::http::{Client, Endpoint, HTTPError}; use serde::{Deserialize, Serialize}; -use crate::Wrapper; - #[derive(Debug, Deserialize, Serialize)] pub struct Account { /// The account ID @@ -34,7 +32,7 @@ pub struct Account { struct AccountEndpoint; impl Endpoint for AccountEndpoint { - type Output = Wrapper; + type Output = Account; } /// The Accounts Service handles the account endpoint of the Amphitheatre API. @@ -58,6 +56,6 @@ impl Accounts<'_> { /// ``` pub fn me(&self) -> Result { let res = self.client.get::("/me", None)?; - Ok(res.data.unwrap().data) + Ok(res.data.unwrap()) } } diff --git a/src/actors.rs b/src/actors.rs index cac7206..90751e4 100644 --- a/src/actors.rs +++ b/src/actors.rs @@ -19,8 +19,6 @@ use amp_common::sync::Synchronization; use serde::{Deserialize, Serialize}; use serde_json::Value; -use crate::Wrapper; - #[derive(Debug, Deserialize, Serialize)] pub struct Actor { /// The actor id @@ -38,19 +36,19 @@ pub struct Actor { struct ActorEndpoint; impl Endpoint for ActorEndpoint { - type Output = Wrapper; + type Output = Actor; } struct ActorsEndpoint; impl Endpoint for ActorsEndpoint { - type Output = Wrapper>; + type Output = Vec; } struct ValueEndpoint; impl Endpoint for ValueEndpoint { - type Output = Wrapper; + type Output = Value; } /// The Actors Service handles the actors endpoint of the Amphitheatre API. @@ -75,7 +73,7 @@ impl Actors<'_> { ) -> Result, HTTPError> { let path = format!("/playbooks/{}/actors", playbook_id); let res = self.client.get::(&path, options)?; - Ok(res.data.unwrap().data) + Ok(res.data.unwrap()) } /// Retrieve a actor @@ -87,7 +85,7 @@ impl Actors<'_> { pub fn get(&self, pid: &str, name: &str) -> Result { let path = format!("/actors/{}/{}", pid, name); let res = self.client.get::(&path, None)?; - Ok(res.data.unwrap().data) + Ok(res.data.unwrap()) } /// Retrieve the log streams of actor @@ -110,7 +108,7 @@ impl Actors<'_> { pub fn info(&self, pid: &str, name: &str) -> Result { let path = format!("/actors/{}/{}/info", pid, name); let res = self.client.get::(&path, None)?; - Ok(res.data.unwrap().data) + Ok(res.data.unwrap()) } /// Retrieve actor's stats @@ -122,7 +120,7 @@ impl Actors<'_> { pub fn stats(&self, pid: &str, name: &str) -> Result { let path = format!("/actors/{}/{}/stats", pid, name); let res = self.client.get::(&path, None)?; - Ok(res.data.unwrap().data) + Ok(res.data.unwrap()) } /// Sync the actor's source code diff --git a/src/client.rs b/src/client.rs index b4ccfcd..1a168bf 100644 --- a/src/client.rs +++ b/src/client.rs @@ -24,7 +24,7 @@ use super::playbooks::Playbooks; /// Represents the Rust client for the Amphitheatre API /// /// The client is your entrypoint to the Amphitheatre API. Using it you will be -/// able to call all the enpoints of the Amphitheatre API and their respective functions. +/// able to call all the endpoints of the Amphitheatre API and their respective functions. /// /// # Examples /// diff --git a/src/lib.rs b/src/lib.rs index 3199985..53c1ee0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,33 +14,10 @@ // // Heavily inspired by https://github.com/dnsimple/dnsimple-rust -use serde::{Deserialize, Serialize}; +// use serde::{Deserialize, Serialize}; pub mod accounts; pub mod actors; pub mod client; pub mod oauth; pub mod playbooks; - -#[derive(Debug, Deserialize, Serialize)] -pub struct Wrapper { - pub data: T, - /// Any API endpoint that returns a list of items requires pagination. - pub pagination: Option, -} - -/// Any API endpoint that returns a list of items requires pagination. -/// By default we will return 30 records from any listing endpoint. If an API -/// endpoint returns a list of items, then it will include a pagination object -/// that contains pagination information. -#[derive(Serialize, Deserialize, Debug)] -pub struct Pagination { - /// The page currently returned (default: 1) - pub current_page: u64, - /// The number of entries returned per page (default: 30) - pub per_page: u64, - /// The Total number of entries available in the entrire collection. - pub total_entries: u64, - /// The total number of pages available given the current `per_page` value - pub total_pages: u64, -} diff --git a/src/playbooks.rs b/src/playbooks.rs index 14906a8..fd2f580 100644 --- a/src/playbooks.rs +++ b/src/playbooks.rs @@ -20,8 +20,6 @@ use amp_common::{ }; use serde::{Deserialize, Serialize}; -use crate::Wrapper; - #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Playbook { /// The playbook ID in Amphitheatre. @@ -49,13 +47,13 @@ pub struct PlaybookPayload { struct PlaybookEndpoint; impl Endpoint for PlaybookEndpoint { - type Output = Wrapper; + type Output = Playbook; } struct PlaybooksEndpoint; impl Endpoint for PlaybooksEndpoint { - type Output = Wrapper>; + type Output = Vec; } /// The Playbooks Service handles the playbooks endpoint of the Amphitheatre API. @@ -74,7 +72,7 @@ impl Playbooks<'_> { /// - Sort: `id`, `label`, `email` pub fn list(&self, options: Option>) -> Result, HTTPError> { let res = self.client.get::("/playbooks", options)?; - Ok(res.data.unwrap().data) + Ok(res.data.unwrap()) } /// Create a playbook in the account. @@ -87,7 +85,7 @@ impl Playbooks<'_> { match serde_json::to_value(payload) { Ok(json) => { let res = self.client.post::("/playbooks", json)?; - Ok(res.data.unwrap().data) + Ok(res.data.unwrap()) } Err(_) => Err(HTTPError::Deserialization(String::from( "Cannot deserialize json payload", @@ -103,7 +101,7 @@ impl Playbooks<'_> { pub fn get(&self, pid: &str) -> Result { let path = format!("/playbooks/{}", pid); let res = self.client.get::(&path, None)?; - Ok(res.data.unwrap().data) + Ok(res.data.unwrap()) } /// Update a playbook @@ -118,7 +116,7 @@ impl Playbooks<'_> { match serde_json::to_value(payload) { Ok(json) => { let res = self.client.patch::(&path, json)?; - Ok(res.data.unwrap().data) + Ok(res.data.unwrap()) } Err(_) => Err(HTTPError::Deserialization(String::from( "Cannot deserialize json payload", diff --git a/tests/fixtures/v1/api/accounts/get-me-success.http b/tests/fixtures/v1/api/accounts/get-me-success.http index e314477..4c61e5b 100644 --- a/tests/fixtures/v1/api/accounts/get-me-success.http +++ b/tests/fixtures/v1/api/accounts/get-me-success.http @@ -12,4 +12,4 @@ X-Request-Id: 15a7f3a5-7ee5-4e36-ac5a-8c21c2e1fffd X-Runtime: 0.141588 Strict-Transport-Security: max-age=31536000 -{"data":{"id":1,"email":"example-account@example.com","name":"example-account","created_at":"2015-09-18T23:04:37Z","updated_at":"2016-06-09T20:03:39Z"}} +{"id":1,"email":"example-account@example.com","name":"example-account","created_at":"2015-09-18T23:04:37Z","updated_at":"2016-06-09T20:03:39Z"} diff --git a/tests/fixtures/v1/api/actors/get-actor-info-success.http b/tests/fixtures/v1/api/actors/get-actor-info-success.http index 570454d..439f6f1 100644 --- a/tests/fixtures/v1/api/actors/get-actor-info-success.http +++ b/tests/fixtures/v1/api/actors/get-actor-info-success.http @@ -13,4 +13,4 @@ X-Request-Id: 9f577b9e-5bc4-4a8f-adfb-09dbb1992b0e X-Runtime: 0.061482 Strict-Transport-Security: max-age=31536000 -{"data":{"environments":{"K3S_TOKEN":"RdqNLMXRiRsHJhmxKurR","K3S_KUBECONFIG_OUTPU":"/output/kubeconfig.yaml","PATH":"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/bin/aux","CRI_CONFIG_FILE":"/var/lib/rancher/k3s/agent/etc/crictl.yaml"},"mounts":{"/VAR/LIB/RANCHER/K3S":"/var/lib/docker/volumes/a78bcb9f7654701e0cfaef4447ef61ced4864e5b93dee7102ec639afb5cf2e1d/_data","/VAR/LOG":"/var/lib/docker/volumes/f64c2f2cf81cfde89879f2a17924b31bd2f2e6a6a738f7df949bf6bd57102d25/_data","/VAR/LIB/CNI":"/var/lib/docker/volumes/00f49631b07ccd74de44d3047d5f889395ac871e05b622890b6dd788d34a59f4/_data","/VAR/LIB/KUBELET":"/var/lib/docker/volumes/bc1b16d39a0e204841695de857122412cfdefd0f672af185b1fa43e635397848/_data"},"port":{"6443/tcp":"0.0.0.0:42397"}}} \ No newline at end of file +{"environments":{"K3S_TOKEN":"RdqNLMXRiRsHJhmxKurR","K3S_KUBECONFIG_OUTPU":"/output/kubeconfig.yaml","PATH":"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/bin/aux","CRI_CONFIG_FILE":"/var/lib/rancher/k3s/agent/etc/crictl.yaml"},"mounts":{"/VAR/LIB/RANCHER/K3S":"/var/lib/docker/volumes/a78bcb9f7654701e0cfaef4447ef61ced4864e5b93dee7102ec639afb5cf2e1d/_data","/VAR/LOG":"/var/lib/docker/volumes/f64c2f2cf81cfde89879f2a17924b31bd2f2e6a6a738f7df949bf6bd57102d25/_data","/VAR/LIB/CNI":"/var/lib/docker/volumes/00f49631b07ccd74de44d3047d5f889395ac871e05b622890b6dd788d34a59f4/_data","/VAR/LIB/KUBELET":"/var/lib/docker/volumes/bc1b16d39a0e204841695de857122412cfdefd0f672af185b1fa43e635397848/_data"},"port":{"6443/tcp":"0.0.0.0:42397"}} diff --git a/tests/fixtures/v1/api/actors/get-actor-stats-success.http b/tests/fixtures/v1/api/actors/get-actor-stats-success.http index 0b0c472..224b78b 100644 --- a/tests/fixtures/v1/api/actors/get-actor-stats-success.http +++ b/tests/fixtures/v1/api/actors/get-actor-stats-success.http @@ -13,4 +13,4 @@ X-Request-Id: 9f577b9e-5bc4-4a8f-adfb-09dbb1992b0e X-Runtime: 0.061482 Strict-Transport-Security: max-age=31536000 -{"data":{"CPU USAGE":"1.98%","DISK READ/WRITE":"5.3MB / 43.7 MB","MEMORY USAGE":"65.8MB","NETWORK I/O":"5.7 kB / 3 kB"}} \ No newline at end of file +{"CPU USAGE":"1.98%","DISK READ/WRITE":"5.3MB / 43.7 MB","MEMORY USAGE":"65.8MB","NETWORK I/O":"5.7 kB / 3 kB"} diff --git a/tests/fixtures/v1/api/actors/get-actor-success.http b/tests/fixtures/v1/api/actors/get-actor-success.http index cc29189..f235290 100644 --- a/tests/fixtures/v1/api/actors/get-actor-success.http +++ b/tests/fixtures/v1/api/actors/get-actor-success.http @@ -13,4 +13,4 @@ X-Request-Id: 9f577b9e-5bc4-4a8f-adfb-09dbb1992b0e X-Runtime: 0.061482 Strict-Transport-Security: max-age=31536000 -{"data":{"id":1,"title":"Default","description":"First","created_at":"2016-01-19T20:50:26Z","updated_at":"2016-01-19T20:50:26Z"}} +{"id":1,"title":"Default","description":"First","created_at":"2016-01-19T20:50:26Z","updated_at":"2016-01-19T20:50:26Z"} diff --git a/tests/fixtures/v1/api/actors/list-actors-success.http b/tests/fixtures/v1/api/actors/list-actors-success.http index 414e64c..1e1a04c 100644 --- a/tests/fixtures/v1/api/actors/list-actors-success.http +++ b/tests/fixtures/v1/api/actors/list-actors-success.http @@ -13,4 +13,4 @@ X-Request-Id: 9f577b9e-5bc4-4a8f-adfb-09dbb1992b0e X-Runtime: 0.061482 Strict-Transport-Security: max-age=31536000 -{"data":[{"id":1,"title":"Default","description":"First","created_at":"2016-01-19T20:50:26Z","updated_at":"2016-01-19T20:50:26Z"},{"id":2,"title":"Default","description":"First","created_at":"2016-01-19T20:50:26Z","updated_at":"2016-01-19T20:50:26Z"}]} +[{"id":1,"title":"Default","description":"First","created_at":"2016-01-19T20:50:26Z","updated_at":"2016-01-19T20:50:26Z"},{"id":2,"title":"Default","description":"First","created_at":"2016-01-19T20:50:26Z","updated_at":"2016-01-19T20:50:26Z"}] diff --git a/tests/fixtures/v1/api/playbooks/create-playbook-created.http b/tests/fixtures/v1/api/playbooks/create-playbook-created.http index b7f6c71..5814083 100644 --- a/tests/fixtures/v1/api/playbooks/create-playbook-created.http +++ b/tests/fixtures/v1/api/playbooks/create-playbook-created.http @@ -13,4 +13,4 @@ X-Request-Id: 9f577b9e-5bc4-4a8f-adfb-09dbb1992b0e X-Runtime: 0.061482 Strict-Transport-Security: max-age=31536000 -{"data":{"id":"1","title":"Default","description":"First","created_at":"2016-01-19T20:50:26Z","updated_at":"2016-01-19T20:50:26Z"}} +{"id":"1","title":"Default","description":"First","created_at":"2016-01-19T20:50:26Z","updated_at":"2016-01-19T20:50:26Z"} diff --git a/tests/fixtures/v1/api/playbooks/get-playbook-success.http b/tests/fixtures/v1/api/playbooks/get-playbook-success.http index 6e8a74c..af38bf8 100644 --- a/tests/fixtures/v1/api/playbooks/get-playbook-success.http +++ b/tests/fixtures/v1/api/playbooks/get-playbook-success.http @@ -13,4 +13,4 @@ X-Request-Id: 9f577b9e-5bc4-4a8f-adfb-09dbb1992b0e X-Runtime: 0.061482 Strict-Transport-Security: max-age=31536000 -{"data":{"id":"1","title":"Default","description":"First","created_at":"2016-01-19T20:50:26Z","updated_at":"2016-01-19T20:50:26Z"}} +{"id":"1","title":"Default","description":"First","created_at":"2016-01-19T20:50:26Z","updated_at":"2016-01-19T20:50:26Z"} diff --git a/tests/fixtures/v1/api/playbooks/list-playbooks-success.http b/tests/fixtures/v1/api/playbooks/list-playbooks-success.http index 2eec1cc..241b861 100644 --- a/tests/fixtures/v1/api/playbooks/list-playbooks-success.http +++ b/tests/fixtures/v1/api/playbooks/list-playbooks-success.http @@ -13,4 +13,4 @@ X-Request-Id: 9f577b9e-5bc4-4a8f-adfb-09dbb1992b0e X-Runtime: 0.061482 Strict-Transport-Security: max-age=31536000 -{"data":[{"id":"1","title":"Default","description":"First","created_at":"2016-01-19T20:50:26Z","updated_at":"2016-01-19T20:50:26Z"},{"id":"2","title":"Default","description":"First","created_at":"2016-01-19T20:50:26Z","updated_at":"2016-01-19T20:50:26Z"}]} +[{"id":"1","title":"Default","description":"First","created_at":"2016-01-19T20:50:26Z","updated_at":"2016-01-19T20:50:26Z"},{"id":"2","title":"Default","description":"First","created_at":"2016-01-19T20:50:26Z","updated_at":"2016-01-19T20:50:26Z"}] diff --git a/tests/fixtures/v1/api/playbooks/update-playbook-success.http b/tests/fixtures/v1/api/playbooks/update-playbook-success.http index 6e8a74c..af38bf8 100644 --- a/tests/fixtures/v1/api/playbooks/update-playbook-success.http +++ b/tests/fixtures/v1/api/playbooks/update-playbook-success.http @@ -13,4 +13,4 @@ X-Request-Id: 9f577b9e-5bc4-4a8f-adfb-09dbb1992b0e X-Runtime: 0.061482 Strict-Transport-Security: max-age=31536000 -{"data":{"id":"1","title":"Default","description":"First","created_at":"2016-01-19T20:50:26Z","updated_at":"2016-01-19T20:50:26Z"}} +{"id":"1","title":"Default","description":"First","created_at":"2016-01-19T20:50:26Z","updated_at":"2016-01-19T20:50:26Z"}