Add SplinterRestClient method `list_biome_users`
Adds an implementation for the `list_biome_users` method for the
`SplinterRestClient`.
// See the License for the specific language governing permissions and
// limitations under the License.
+use reqwest::blocking::Client;
use serde::Deserialize;
-use crate::action::api::SplinterRestClient;
+use crate::action::api::{ServerError, SplinterRestClient};
use crate::error::CliError;
pub(super) const PAGING_LIMIT: &str = "1000";
@@ -23,7 +24,43 @@ pub(super) const CLI_SPLINTER_USER_PROTOCOL_VERSION: &str = "1";
impl SplinterRestClient {
pub fn list_biome_users(&self) -> Result<Vec<ClientBiomeUser>, CliError> {
- unimplemented!();
+ Client::new()
+ .get(&format!("{}/biome/users", self.url))
+ .header(
+ "SplinterProtocolVersion",
+ CLI_SPLINTER_USER_PROTOCOL_VERSION,
+ )
+ .header("Authorization", &self.auth)
+ .send()
+ .map_err(|err| CliError::ActionError(format!("Failed to list biome users: {}", err)))
+ .and_then(|res| {
+ let status = res.status();
+ if status.is_success() {
+ let response_data = res.json::<Vec<ClientBiomeUser>>().map_err(|_| {
+ CliError::ActionError(
+ "List Biome users request succeeded, but response was not valid"
+ .to_string(),
+ )
+ })?;
+ Ok(response_data)
+ } else {
+ let message = res
+ .json::<ServerError>()
+ .map_err(|_| {
+ CliError::ActionError(format!(
+ "List Biome users request failed with status code '{}', but \
+ error response was not valid",
+ status
+ ))
+ })?
+ .message;
+
+ Err(CliError::ActionError(format!(
+ "Failed to list Biome users: {}",
+ message
+ )))
+ }
+ })
}
/// Submits a request to list Biome's OAuth users
