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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
//! # JRD
//!
//! from [Packetizer](https://www.packetizer.com/json/jrd/):
//! > The JSON Resource Descriptor (JRD) is a simple [JSON](https://www.techabulary.com/j/json/) object that describes a "resource" on the Internet,
//! > where a "resource" is any entity on the Internet that is identified via a URI or IRI.
//! > For example, a person's account URI (e.g., acct:bob@example.com) is a resource.
//! > So are all web URIs (e.g., https://www.packetizer.com/).
//!
//!
//! > The JSON Resource Descriptor, originally introduced in [RFC 6415](https://www.packetizer.com/rfc/rfc6415/) and
//! > based on the Extensible Resource Descriptor (XRD) format, was adopted for use
//! > in the [WebFinger](https://www.techabulary.com/w/webfinger/) protocol, though its use is not restricted
//! > to WebFinger or RFC 6415.
//!
//! This tiny crate provides a struct representation of JRDs, [JsonResourceDescriptor], together with
//! [serde::Serialize] and [serde::Deserialize] implementations.
//!
//! All documentation is copied as-is from packetizer.com.
//!
//! # usage
//! ```rust
//! let jrd_string = r#"{
//! "subject": "acct:paulej@packetizer.com",
//! "properties": {
//! "http://packetizer.com/ns/name": "Paul E. Jones"
//! },
//! "links": [
//! {
//! "rel": "http://webfinger.net/rel/profile-page",
//! "href": "http://www.packetizer.com/people/paulej/"
//! },
//! {
//! "rel": "http://packetizer.com/rel/blog",
//! "type": "text/html",
//! "href": "http://www.packetizer.com/people/paulej/blog/",
//! "titles": {
//! "en-us": "Paul E. Jones' Blog"
//! }
//! }
//! ]
//! }"#;
//!
//! let jrd_struct = jrd::JsonResourceDescriptor {
//! subject: "acct:paulej@packetizer.com".into(),
//! aliases: Vec::new(),
//! properties: [("http://packetizer.com/ns/name".to_string(), "Paul E. Jones".to_string())].into(),
//! expires: None,
//! links: vec![
//! jrd::JsonResourceDescriptorLink {
//! rel: "http://webfinger.net/rel/profile-page".into(),
//! href: Some("http://www.packetizer.com/people/paulej/".into()),
//! link_type: None,
//! titles: jrd::Map::default(),
//! properties: jrd::Map::default(),
//! },
//! jrd::JsonResourceDescriptorLink {
//! rel: "http://packetizer.com/rel/blog".into(),
//! href: Some("http://www.packetizer.com/people/paulej/blog/".into()),
//! link_type: Some("text/html".into()),
//! titles: [("en-us".to_string(), "Paul E. Jones' Blog".to_string())].into(),
//! properties: jrd::Map::default(),
//! },
//! ],
//! };
//!
//! // deserialize
//! assert_eq!(serde_json::from_str::<jrd::JsonResourceDescriptor>(jrd_string).unwrap(), jrd_struct);
//!
//! // serialize
//! assert_eq!(serde_json::to_string_pretty(&jrd_struct).unwrap(), jrd_string)
//! ```
pub type Map = BTreeMap;
pub type Time = DateTime;
/// The JSON Resource Descriptor (JRD) is a simple JSON object that describes a "resource" on the Internet, where a "resource" is any entity on the Internet that is identified via a URI or IRI.
///
/// For example, a person's account URI (e.g., acct:bob@example.com) is a resource. So are all web URIs (e.g., https://www.packetizer.com/).
/// The JSON Resource Descriptor, originally introduced in [RFC 6415](https://www.packetizer.com/rfc/rfc6415/) and based on the Extensible Resource Descriptor (XRD) format,
/// was adopted for use in the WebFinger protocol, though its use is not restricted to WebFinger or [RFC 6415](https://www.packetizer.com/rfc/rfc6415/).
/// A JRD object comprises the following name/value pairs:
/// * expires
/// * subject
/// * aliases
/// * properties
/// * links
///
/// A JRD describes a URI or IRI by returning structured information about the identifier.
/// For example, a JRD that describes a person named Paul might include information about Paul's full name, homepage, blog, etc.
///
/// Here is an example JRD that describes a user named Paul:
/// ```json
/// {
/// "subject" : "acct:paulej@packetizer.com",
/// "properties" :
/// {
/// "http://packetizer.com/ns/name" : "Paul E. Jones"
/// },
/// "links" :
/// [
/// {
/// "rel" : "http://webfinger.net/rel/profile-page",
/// "href" : "http://www.packetizer.com/people/paulej/"
/// },
/// {
/// "rel" : "http://packetizer.com/rel/blog",
/// "type" : "text/html",
/// "href" : "http://www.packetizer.com/people/paulej/blog/",
/// "titles" :
/// {
/// "en-us" : "Paul E. Jones' Blog"
/// }
/// }
/// ]
/// }
/// ```
/// Each of these link objects can have the following members:
/// * rel
/// * type
/// * href
/// * titles
/// * properties
///
/// The “rel” and “href” members are strings representing the link's relation type and the target URI, respectively. The context of the link is the “subject”.
/// The “type” member is a string indicating what the media type of the result of dereferencing the link ought to be.
/// The order of elements in the “links” array MAY be interpreted as indicating an of preference. Thus, if there are two or more link relations having the same “rel” value, the first link relation would indicate the user’s preferred link.