automatons_github/resource/
app.rs1use std::collections::HashMap;
2use std::fmt::{Display, Formatter};
3
4use chrono::{DateTime, Utc};
5use serde::{Deserialize, Serialize};
6use url::Url;
7
8use crate::resource::{Account, NodeId};
9use crate::{id, name};
10
11id!(
12 AppId
17);
18
19name!(
20 AppName
25);
26
27name!(
28 AppSlug
32);
33
34#[derive(Clone, Eq, PartialEq, Debug, Deserialize, Serialize)]
40pub struct App {
41 id: AppId,
42 node_id: NodeId,
43 name: AppName,
44 slug: AppSlug,
45 owner: Account,
46 description: String,
47 external_url: Url,
48 html_url: Url,
49 created_at: DateTime<Utc>,
50 updated_at: DateTime<Utc>,
51 permissions: HashMap<String, String>,
52 events: Vec<String>,
53}
54
55impl App {
56 #[cfg_attr(feature = "tracing", tracing::instrument)]
58 pub fn id(&self) -> AppId {
59 self.id
60 }
61
62 #[cfg_attr(feature = "tracing", tracing::instrument)]
64 pub fn node_id(&self) -> &NodeId {
65 &self.node_id
66 }
67
68 #[cfg_attr(feature = "tracing", tracing::instrument)]
70 pub fn name(&self) -> &AppName {
71 &self.name
72 }
73
74 #[cfg_attr(feature = "tracing", tracing::instrument)]
76 pub fn slug(&self) -> &AppSlug {
77 &self.slug
78 }
79
80 #[cfg_attr(feature = "tracing", tracing::instrument)]
82 pub fn owner(&self) -> &Account {
83 &self.owner
84 }
85
86 #[cfg_attr(feature = "tracing", tracing::instrument)]
88 pub fn description(&self) -> &String {
89 &self.description
90 }
91
92 #[cfg_attr(feature = "tracing", tracing::instrument)]
94 pub fn external_url(&self) -> &Url {
95 &self.external_url
96 }
97
98 #[cfg_attr(feature = "tracing", tracing::instrument)]
100 pub fn html_url(&self) -> &Url {
101 &self.html_url
102 }
103
104 #[cfg_attr(feature = "tracing", tracing::instrument)]
106 pub fn created_at(&self) -> &DateTime<Utc> {
107 &self.created_at
108 }
109
110 #[cfg_attr(feature = "tracing", tracing::instrument)]
112 pub fn updated_at(&self) -> &DateTime<Utc> {
113 &self.updated_at
114 }
115
116 #[cfg_attr(feature = "tracing", tracing::instrument)]
118 pub fn permissions(&self) -> &HashMap<String, String> {
119 &self.permissions
120 }
121
122 #[cfg_attr(feature = "tracing", tracing::instrument)]
124 pub fn events(&self) -> &Vec<String> {
125 &self.events
126 }
127}
128
129impl Display for App {
130 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
131 write!(f, "{}", self.name)
132 }
133}
134
135#[cfg(test)]
136mod tests {
137 use super::App;
138
139 #[test]
140 fn trait_deserialize() {
141 let app: App =
142 serde_json::from_str(include_str!("../../tests/fixtures/resource/app.json")).unwrap();
143
144 assert_eq!("devxbots/checkbot", app.name().get());
145 }
146
147 #[test]
148 fn trait_display() {
149 let app: App =
150 serde_json::from_str(include_str!("../../tests/fixtures/resource/app.json")).unwrap();
151
152 assert_eq!("devxbots/checkbot", app.to_string());
153 }
154
155 #[test]
156 fn trait_send() {
157 fn assert_send<T: Send>() {}
158 assert_send::<App>();
159 }
160
161 #[test]
162 fn trait_sync() {
163 fn assert_sync<T: Sync>() {}
164 assert_sync::<App>();
165 }
166}