Skip to content

Commit a206d0a

Browse files
committed
add interface for project roles
1 parent c89b1e6 commit a206d0a

File tree

4 files changed

+103
-0
lines changed

4 files changed

+103
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
### 1.1.0 (Next)
2+
- Add support for project roles.
3+
14
### 1.0.0
25
- First official release.
36

src/interface/role.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//! # Role
2+
//!
3+
//! `interface::role` consists of functions for interfacing with the Ruddr Role endpoints.
4+
use std::fmt::Write;
5+
6+
use crate::client::client;
7+
use crate::model::role;
8+
use crate::model::{enums, types};
9+
10+
/// Retrieves a specific Ruddr Role object by id, and deserializes it to the corresponding model struct.
11+
/// [API Documentation](https://ruddr.readme.io/reference/get-a-project-role)
12+
/// ```ignore
13+
/// let role = role(&client, types::UUID::try_from("7ad5a34a-07b7-48e9-a760-bd220d52e354").expect("uuid conversion failed")).await?;
14+
/// ```
15+
pub async fn role(
16+
client: &client::Client,
17+
id: types::UUID,
18+
) -> Result<role::Role, Box<dyn std::error::Error>> {
19+
// retrieve role
20+
Ok(client
21+
.read::<role::Role>(&format!("project-roles/{id}"), None)
22+
.await?)
23+
}
24+
25+
/// Retrieves all Ruddr Role objects by filters, and deserializes it to the corresponding vector of model structs.
26+
/// [API Documentation](https://ruddr.readme.io/reference/list-project-roles)
27+
/// ```ignore
28+
/// let roles = roles(
29+
/// &client,
30+
/// Some(types::UUID::try_from("095e0780-48bf-472c-8deb-2fc3ebc7d90c").expect("uuid conversion failed")),
31+
/// ).await?;
32+
/// ```
33+
pub async fn roles(
34+
client: &client::Client,
35+
project: Option<types::UUID>,
36+
) -> Result<role::Roles, Box<dyn std::error::Error>> {
37+
// initialize params
38+
let mut params = String::from("limit=100");
39+
40+
// optional parameters for LIST
41+
if let Some(project) = project {
42+
write!(params, "&projectId={}", project)?;
43+
}
44+
45+
// retrieve roles
46+
Ok(client
47+
.read::<role::Roles>("project-roles", Some(&params))
48+
.await?)
49+
}
50+
51+
#[cfg(test)]
52+
mod tests;

src/interface/role/tests.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
use super::*;
2+
3+
#[test]
4+
fn test_role() {
5+
let test = async {
6+
let client = client::Client::new(Some("abcdefghi123456789"))
7+
.expect("client with token could not be constructed");
8+
assert_eq!(
9+
role(
10+
&client,
11+
types::UUID::try_from("7ad5a34a-07b7-48e9-a760-bd220d52e354")
12+
.expect("uuid conversion failed")
13+
)
14+
.await
15+
.unwrap_err()
16+
.to_string(),
17+
"client read response failed",
18+
"role retrieval did not fail on auth",
19+
)
20+
};
21+
let rt = tokio::runtime::Runtime::new().unwrap();
22+
rt.block_on(test);
23+
}
24+
25+
#[test]
26+
fn test_roles() {
27+
let test = async {
28+
let client = client::Client::new(Some("abcdefghi123456789"))
29+
.expect("client with token could not be constructed");
30+
assert_eq!(
31+
roles(
32+
&client,
33+
Some(
34+
types::UUID::try_from("095e0780-48bf-472c-8deb-2fc3ebc7d90c")
35+
.expect("uuid conversion failed")
36+
),
37+
)
38+
.await
39+
.unwrap_err()
40+
.to_string(),
41+
"client read response failed",
42+
"roles retrieval did not fail on auth",
43+
)
44+
};
45+
let rt = tokio::runtime::Runtime::new().unwrap();
46+
rt.block_on(test);
47+
}

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub mod interface {
1010
pub mod expense_report;
1111
pub mod member;
1212
pub mod project;
13+
pub mod role;
1314
pub mod time;
1415
pub mod utilization;
1516
}

0 commit comments

Comments
 (0)