-
Notifications
You must be signed in to change notification settings - Fork 1
/
user.gleam
49 lines (42 loc) · 1007 Bytes
/
user.gleam
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import gleam/result
pub type User {
Update
Authorization(Authorization)
}
pub type InvalidUserSubscription {
InvalidUserSubscription
}
pub fn from_string(str: String) -> Result(User, InvalidUserSubscription) {
case str {
"user.update" -> Ok(Update)
_ ->
str
|> authorization_from_string
|> result.map(Authorization)
}
}
pub fn to_string(user: User) -> String {
case user {
Update -> "user.update"
Authorization(authorization) -> authorization_to_string(authorization)
}
}
pub type Authorization {
Grant
Revoke
}
pub fn authorization_to_string(authorization: Authorization) -> String {
case authorization {
Grant -> "user.authorization.grant"
Revoke -> "user.authorization.revoke"
}
}
pub fn authorization_from_string(
str: String,
) -> Result(Authorization, InvalidUserSubscription) {
case str {
"user.authorization.grant" -> Ok(Grant)
"user.authorization.revoke" -> Ok(Revoke)
_ -> Error(InvalidUserSubscription)
}
}