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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
use activitystreams_vocabulary::create_activity;
create_activity! {
/// Indicates that the `actor` is canceling `target`’s access to a resource specified by `context` under the role specified by instrument, making the [Grant](crate::Grant) activities specified by `object` unusable anymore in other activities' `capability` field.
///
/// # Example
///
/// ```rust
/// use activityforge::{Revoke, context};
/// use activitystreams_vocabulary::Iri;
///
/// # fn main() {
/// let id = Iri::try_from("https://example.dev/myproject/outbox/nlTxb").unwrap();
/// let actor = Iri::try_from("http://example.dev/myproject").unwrap();
///
/// let object = Iri::try_from("https://example.dev/myproject/outbox/reBGo").unwrap();
/// let context = Iri::try_from("https://example.dev/myproject").unwrap();
/// let instrument = Iri::try_from("https://example.dev/roles/developer").unwrap();
/// let target = Iri::try_from("https://example.dev/users/aviva").unwrap();
///
/// let to0 = Iri::try_from("https://example.dev/myproject/followers").unwrap();
/// let to1 = Iri::try_from("https://example.dev/users/aviva").unwrap();
///
/// let json_str = format!(
/// r#"{{
/// "@context": [
/// "https://www.w3.org/ns/activitystreams",
/// "https://forgefed.org/ns"
/// ],
/// "type": "Revoke",
/// "id": "{id}",
/// "context": "{context}",
/// "to": [
/// "{to0}",
/// "{to1}"
/// ],
/// "actor": "{actor}",
/// "object": "{object}",
/// "target": "{target}",
/// "instrument": "{instrument}"
/// }}"#
/// );
///
/// let context_property = context::forgefed_context();
///
/// let to = [to0, to1];
///
/// let revoke = Revoke::new()
/// .with_context_property(context_property)
/// .with_id(id)
/// .with_actor(actor)
/// .with_object(object)
/// .with_instrument(instrument)
/// .with_context(context)
/// .with_target(target)
/// .with_to(to);
///
/// assert_eq!(serde_json::to_string_pretty(&revoke).unwrap(), json_str);
/// assert_eq!(
/// serde_json::from_str::<Revoke>(json_str.as_str()).unwrap(),
/// revoke
/// );
/// # }
Revoke: crate::ActivityType::Revoke {}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::context;
use activitystreams_vocabulary::Iri;
#[test]
fn test_revoke() {
let id = Iri::try_from("https://example.dev/myproject/outbox/nlTxb").unwrap();
let actor = Iri::try_from("http://example.dev/myproject").unwrap();
let object = Iri::try_from("https://example.dev/myproject/outbox/reBGo").unwrap();
let context = Iri::try_from("https://example.dev/myproject").unwrap();
let instrument = Iri::try_from("https://example.dev/roles/developer").unwrap();
let target = Iri::try_from("https://example.dev/users/aviva").unwrap();
let to0 = Iri::try_from("https://example.dev/myproject/followers").unwrap();
let to1 = Iri::try_from("https://example.dev/users/aviva").unwrap();
let json_str = format!(
r#"{{
"@context": [
"https://www.w3.org/ns/activitystreams",
"https://forgefed.org/ns"
],
"type": "Revoke",
"id": "{id}",
"context": "{context}",
"to": [
"{to0}",
"{to1}"
],
"actor": "{actor}",
"object": "{object}",
"target": "{target}",
"instrument": "{instrument}"
}}"#
);
let context_property = context::forgefed_context();
let to = [to0, to1];
let revoke = Revoke::new()
.with_context_property(context_property)
.with_id(id)
.with_actor(actor)
.with_object(object)
.with_instrument(instrument)
.with_context(context)
.with_target(target)
.with_to(to);
assert_eq!(serde_json::to_string_pretty(&revoke).unwrap(), json_str);
assert_eq!(
serde_json::from_str::<Revoke>(json_str.as_str()).unwrap(),
revoke
);
}
}