-
Notifications
You must be signed in to change notification settings - Fork 0
/
document_vocabulary.go
400 lines (318 loc) · 12.2 KB
/
document_vocabulary.go
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
package streams
import (
"time"
"github.com/benpate/hannibal/vocab"
)
/******************************************
* ActivityStreams 2.0 Properties
* https://www.w3.org/TR/activitystreams-vocabulary
******************************************/
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-id
func (document Document) ID() string {
// Try the ActivityPub standard "id" property first
if id := document.Get(vocab.PropertyID); !id.IsNil() {
return id.String()
}
// Try the JSON-LD standard "@id" property second
if id := document.Get(vocab.PropertyID_Alternate); !id.IsNil() {
return document.Get(vocab.PropertyID).String()
}
// LOL, no.
return ""
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-actor
func (document Document) Actor() Document {
return document.Get(vocab.PropertyActor).MustLoad()
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-attachment
func (document Document) Attachment() Document {
return document.Get(vocab.PropertyAttachment)
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-attributedto
func (document Document) AttributedTo() Document {
return document.Get(vocab.PropertyAttributedTo).MustLoad()
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-audience
func (document Document) Audience() Document {
return document.Get(vocab.PropertyAudience)
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-bcc
func (document Document) BCC() Document {
return document.Get(vocab.PropertyBCC).MustLoad()
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-bto
func (document Document) BTo() Document {
return document.Get(vocab.PropertyBTo).MustLoad()
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-cc
func (document Document) CC() Document {
return document.Get(vocab.PropertyCC).MustLoad()
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-context
// IMPORTANT: THIS IS NOT THE @context PROPERTY REQUIRED FOR EVERY JSON-LD DOCUMENT
func (document Document) Context() string {
return document.Get(vocab.PropertyContext).String()
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-current
func (document Document) Current() Document {
return document.Get(vocab.PropertyCurrent)
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-deleted
func (document Document) Deleted() time.Time {
return document.Get(vocab.PropertyDeleted).Time()
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-describes
func (document Document) Describes() Document {
return document.Get(vocab.PropertyDescribes)
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-first
func (document Document) First() Document {
return document.Get(vocab.PropertyFirst)
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-formertype
func (document Document) FormerType() string {
return document.Get(vocab.PropertyFormerType).String()
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-generator
func (document Document) Generator() Document {
return document.Get(vocab.PropertyGenerator)
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-icon
func (document Document) Icon() Image {
return NewImage(document.Get(vocab.PropertyIcon))
}
// IconOrImage is a hybrid accessor that returns the "icon" property (if not nil),
// otherwise it returns the "image" property. This is useful for working with different
// ActivityPub objects, which may use either property.
func (document Document) IconOrImage() Image {
if icon := document.Icon(); icon.NotNil() {
return icon
}
return document.Image()
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-image
func (document Document) Image() Image {
return NewImage(document.Get(vocab.PropertyImage))
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-inreplyto
func (document Document) InReplyTo() Document {
return document.Get(vocab.PropertyInReplyTo)
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-instrument
func (document Document) Instrument() Document {
return document.Get(vocab.PropertyInstrument)
}
// Items returns the items collection for this Document. If the
// document contains an "orderedItems" collection, then it is
// returned instead.
func (document Document) Items() Document {
// Search the "orderedItems" property first (guessing this will be more common)
if result := document.Get(vocab.PropertyOrderedItems); !result.IsNil() {
return result
}
// Search the "items" property second (guessing this will be less common)
if result := document.Get(vocab.PropertyItems); !result.IsNil() {
return result
}
// Value not found :(
return NilDocument()
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-last
func (document Document) Last() Document {
return document.Get(vocab.PropertyLast)
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-location
func (document Document) Location() Document {
return document.Get(vocab.PropertyLocation)
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-oneof
func (document Document) OneOf() Document {
return document.Get(vocab.PropertyOneOf)
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-anyof
func (document Document) AnyOf() Document {
return document.Get(vocab.PropertyAnyOf)
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-closed
func (document Document) Closed() Document {
return document.Get(vocab.PropertyClosed)
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-origin
func (document Document) Origin() Document {
return document.Get(vocab.PropertyOrigin)
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-next
func (document Document) Next() Document {
return document.Get(vocab.PropertyNext)
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-object
func (document Document) Object() Document {
return document.Get(vocab.PropertyObject).MustLoad()
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-prev
func (document Document) Prev() Document {
return document.Get(vocab.PropertyPrev)
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-preview
func (document Document) Preview() Document {
return document.Get(vocab.PropertyPreview)
}
func (document Document) PublicKey() Document {
return document.Get(vocab.PropertyPublicKey)
}
func (document Document) PublicKeyPEM() string {
return document.Get(vocab.PropertyPublicKeyPEM).String()
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-result
func (document Document) Result() Document {
return document.Get(vocab.PropertyResult)
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-replies
func (document Document) Replies() Document {
return document.Get(vocab.PropertyReplies)
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-tag
func (document Document) Tag() Document {
return document.Get(vocab.PropertyTag)
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-target
func (document Document) Target() Document {
return document.Get(vocab.PropertyTarget).MustLoad()
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-to
func (document Document) To() Document {
return document.Get(vocab.PropertyTo).MustLoad()
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-type
func (document Document) Type() string {
// Try the ActivityPub standard "type" property first
if value := document.Get(vocab.PropertyType); !value.IsNil() {
return value.String()
}
// Try the JSON-LD standard "@type" property second
if value := document.Get(vocab.PropertyType_Alternate); !value.IsNil() {
return value.String()
}
// LOL, Fail
return vocab.Unknown
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-url
func (document Document) Url() Document {
return document.Get(vocab.PropertyURL)
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-accuracy
func (document Document) Accuracy() float64 {
return document.Get(vocab.PropertyAccuracy).Float()
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-altitude
func (document Document) Altitude() float64 {
return document.Get(vocab.PropertyAltitude).Float()
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-content
func (document Document) Content() string {
return document.Get(vocab.PropertyContent).HTMLString()
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-name
func (document Document) Name() string {
// TODO: Re-Implement Language Maps
return document.Get(vocab.PropertyName).String()
}
// TODO: Implement Durations per
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-duration
func (document Document) Duration() string {
return document.Get(vocab.PropertyDuration).String()
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-height
func (document Document) Height() int {
return document.Get(vocab.PropertyHeight).Int()
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-href
func (document Document) Href() string {
return document.Get(vocab.PropertyHref).String()
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-hreflang
func (document Document) Hreflang() string {
return document.Get(vocab.PropertyHrefLang).String()
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-partof
func (document Document) PartOf() Document {
return document.Get(vocab.PropertyPartOf)
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-latitude
func (document Document) Latitude() float64 {
return document.Get(vocab.PropertyLatitude).Float()
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-longitude
func (document Document) Longitude() float64 {
return document.Get(vocab.PropertyLongitude).Float()
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-mediatype
func (document Document) MediaType() string {
return document.Get(vocab.PropertyMediaType).String()
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-endtime
func (document Document) EndTime() time.Time {
return document.Get(vocab.PropertyEndTime).Time()
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-published
func (document Document) Published() time.Time {
return document.Get(vocab.PropertyPublished).Time()
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-starttime
func (document Document) StartTime() time.Time {
return document.Get(vocab.PropertyStartTime).Time()
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-radius
func (document Document) Radius() float64 {
return document.Get(vocab.PropertyRadius).Float()
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-rel
// Rel is expected to be a string, but this function
// returns a document because it may contain multiple values (rel:["canonical", "preview"])
func (document Document) Rel() Document {
return document.Get(vocab.PropertyRel)
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-relationship
func (document Document) Relationship() string {
return document.Get(vocab.PropertyRelationship).String()
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-startindex
func (document Document) StartIndex() int {
return document.Get(vocab.PropertyStartIndex).Int()
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-subject
func (document Document) Subject() Document {
return document.Get(vocab.PropertySubject)
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-summary
// TODO: Implement Language Maps
func (document Document) Summary() string {
return document.Get(vocab.PropertySummary).String()
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-totalitems
func (document Document) TotalItems() int {
return document.Get(vocab.PropertyTotalItems).Int()
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-width
func (document Document) URL() string {
return document.Get(vocab.PropertyURL).String()
}
// URLOrID returns the URL of the document, if it exists, otherwise it returns the ID.
func (document Document) URLOrID() string {
if url := document.URL(); url != "" {
return url
}
return document.ID()
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-units
func (document Document) Units() string {
return document.Get(vocab.PropertyUnits).String()
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-updated
func (document Document) Updated() time.Time {
return document.Get(vocab.PropertyUpdated).Time()
}
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-width
func (document Document) Width() int {
return document.Get(vocab.PropertyWidth).Int()
}