Skip to main content

atlassian_rust_api/jira/endpoints/application_properties/
get_properties.rs

1use std::sync::Arc;
2
3use crate::{Jira, Result, rest_client::RestClient, web::{Endpoint, QueryParams}};
4
5#[derive(Debug, Clone)]
6pub struct GetPropertyBuilder {
7	client: Arc<RestClient>,
8	request: GetPropertyRequest,
9}
10
11#[derive(Debug, Clone, Default)]
12struct GetPropertyRequest {
13	key: Option<String>,
14	permission_level: Option<String>,
15	key_filter: Option<String>,
16}
17
18impl Endpoint for GetPropertyRequest {
19	fn endpoint(&self) -> std::borrow::Cow<'static, str> {
20		"application-properties".into()
21	}
22
23	fn parameters(&self) -> crate::web::QueryParams<'_> {
24		let mut params = QueryParams::default();
25		params
26			.push_opt("key", self.key.as_ref())
27			.push_opt("permissionLevel", self.permission_level.as_ref())
28			.push_opt("keyFilter", self.key_filter.as_ref());
29		params
30	}
31}
32
33impl GetPropertyBuilder {
34	fn new(client: Arc<RestClient>) -> GetPropertyBuilder {
35		GetPropertyBuilder { client, request: GetPropertyRequest::default() }
36	}
37
38	/// A String containing the property key.
39	pub fn key(mut self, key: impl Into<String>) -> GetPropertyBuilder {
40		self.request.key = Some(key.into());
41		self
42	}
43
44	/// When fetching a list, specifies the permission level of all items in the list.
45	pub fn permission_level(mut self, permission_level: impl Into<String>) -> GetPropertyBuilder {
46		self.request.permission_level = Some(permission_level.into());
47		self
48	}
49
50	/// When fetching a list, allows the list to be filtered by the property's start of key e.g. `"jira.if.*"` would
51	/// fetch only those permissions that are editable and whose keys start with `"jira.if."`. This is a regex.
52	pub fn key_filter(mut self, key_filter: impl Into<String>) -> GetPropertyBuilder {
53		self.request.key_filter = Some(key_filter.into());
54		self
55	}
56
57	pub async fn send(self) -> Result<serde_json::Value> {
58		self.client.get(self.request).await
59	}
60}
61
62impl Jira {
63	/// Returns an application property or a list of application properties.
64	/// 
65	/// ```no_run
66	/// let jira = Jira::builder().url("http://jira.example.com")
67	/// 	.username("user")
68	/// 	.password("password")
69	/// 	.build()?;
70	/// // Single property
71	/// let prop = jira.get_properties()
72	/// 	.key("jira.home").await?;
73	/// // Mutlitple properties
74	/// let props = jira.get_properties().await?;
75	/// ```
76	pub fn get_properties(&self) -> GetPropertyBuilder {
77		GetPropertyBuilder::new(Arc::clone(&self.client))
78	}
79}