-
Notifications
You must be signed in to change notification settings - Fork 0
/
orderedCollectionPage.go
71 lines (58 loc) · 3.31 KB
/
orderedCollectionPage.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
package streams
import (
"encoding/json"
"github.com/benpate/derp"
"github.com/benpate/hannibal/vocab"
"github.com/benpate/rosetta/mapof"
)
// OrderedCollectionPage is used to represent ordered subsets of items from an OrderedCollection. Refer to the Activity Streams 2.0 Core for a complete description of the OrderedCollectionPage object.
// https://www.w3.org/ns/activitystreams#OrderedCollectionPage
type OrderedCollectionPage struct {
Context Context `json:"@context"`
Type string `json:"type"`
Summary string `json:"summary,omitempty"` // A natural language summarization of the object encoded as HTML. Multiple language tagged summaries may be provided.
TotalItems int `json:"totalItems,omitempty"` // A non-negative integer specifying the total number of objects contained by the logical view of the collection. This number might not reflect the actual number of items serialized within the Collection object instance.
Current string `json:"current,omitempty"` // In a paged Collection, indicates the page that contains the most recently updated member items.
First string `json:"first,omitempty"` // In a paged Collection, indicates the furthest preceeding page of items in the collection.
Last string `json:"last,omitempty"` // In a paged Collection, indicates the furthest proceeding page of the collection.
StartIndex int `json:"startIndex,omitempty"` // A non-negative integer value identifying the relative position within the logical view of a strictly ordered collection.
PartOf string `json:"partOf,omitempty"` // dentifies the Collection to which a CollectionPage objects items belong.
Prev string `json:"prev,omitempty"` // In a paged Collection, identifies the previous page of items.
Next string `json:"next,omitempty"` // In a paged Collection, indicates the next page of items.
OrderedItems []any `json:"orderedItems"` // Identifies the items contained in a collection. The items might be ordered or unordered.
}
func NewOrderedCollectionPage() OrderedCollectionPage {
return OrderedCollectionPage{
Context: DefaultContext(),
Type: vocab.CoreTypeOrderedCollectionPage,
OrderedItems: make([]any, 0),
}
}
func (c *OrderedCollectionPage) UnmarshalJSON(data []byte) error {
result := mapof.NewAny()
if err := json.Unmarshal(data, &result); err != nil {
return derp.Wrap(err, "activitystreams.OrderedCollectionPage.UnmarshalJSON", "Error unmarshalling JSON", string(data))
}
return c.UnmarshalMap(result)
}
func (c *OrderedCollectionPage) UnmarshalMap(data mapof.Any) error {
if dataType := data.GetString("type"); dataType != vocab.CoreTypeOrderedCollectionPage {
return derp.NewInternalError("activitystreams.OrderedCollectionPage.UnmarshalMap", "Invalid type", dataType)
}
c.Type = vocab.CoreTypeOrderedCollectionPage
c.Summary = data.GetString("summary")
c.TotalItems = data.GetInt("totalItems")
c.Current = data.GetString("current")
c.First = data.GetString("first")
c.Last = data.GetString("last")
c.StartIndex = data.GetInt("startIndex")
c.PartOf = data.GetString("partOf")
c.Prev = data.GetString("prev")
c.Next = data.GetString("next")
if dataItems, ok := data["items"]; ok {
if items, ok := UnmarshalItems(dataItems); ok {
c.OrderedItems = items
}
}
return nil
}