Changes
6 changed files (+89/-120)
-
-
@@ -2,8 +2,6 @@ package activitystreamsimport ( "time" "github.com/buger/jsonparser" ) // Activity Types
-
@@ -1506,34 +1504,13 @@ func (v View) IsLink() bool {// UnmarshalJSON func (a *Activity) UnmarshalJSON(data []byte) error { a.ID = getAPObjectID(data) a.Type = getAPType(data) a.Name = getAPNaturalLanguageField(data, "name") a.Content = getAPNaturalLanguageField(data, "content") a.Summary = getAPNaturalLanguageField(data, "summary") a.URL = getURIField(data, "url") a.Parent.UnmarshalJSON(data) a.Actor = getAPItem(data, "actor") a.Object = getAPItem(data, "object") a.Generator = getAPItem(data, "generator") a.AttributedTo = getAPItem(data, "attributedTo") a.InReplyTo = getAPItem(data, "inReplyTo") a.Published = getAPTime(data, "published") a.StartTime = getAPTime(data, "startTime") a.Updated = getAPTime(data, "updated") to := getAPItemCollection(data, "to") if to != nil { a.To = to } if v, _, _, err := jsonparser.Get(data, "replies"); err == nil { r := Collection{} if r.UnmarshalJSON(v) == nil { a.Replies = &r } } tag := getAPItemCollection(data, "tag") if tag != nil { a.Tag = tag } return nil }
-
-
-
@@ -1,9 +1,5 @@package activitystreams import ( "github.com/buger/jsonparser" ) // Actor Types const ( ApplicationType ActivityVocabularyType = "Application"
-
@@ -324,30 +320,35 @@ func (p Person) GetLink() IRI {// UnmarshalJSON func (a *Actor) UnmarshalJSON(data []byte) error { a.ID = getAPObjectID(data) a.Type = getAPType(data) a.Name = getAPNaturalLanguageField(data, "name") a.Parent.UnmarshalJSON(data) a.PreferredUsername = getAPNaturalLanguageField(data, "preferredUsername") a.Content = getAPNaturalLanguageField(data, "content") a.URL = getURIField(data, "url") o := OrderedCollectionNew(ObjectID("test-outbox")) if v, _, _, err := jsonparser.Get(data, "outbox"); err == nil { if o.UnmarshalJSON(v) == nil { a.Outbox = o } out := getAPItem(data, "outbox") if out != nil { a.Outbox = out } if v, _, _, err := jsonparser.Get(data, "replies"); err == nil { r := Collection{} if r.UnmarshalJSON(v) == nil { o.Replies = &r } inb := getAPItem(data, "inbox") if inb != nil { a.Inbox = inb } followers := getAPItem(data, "followers") if followers != nil { a.Followers = followers } following := getAPItem(data, "following") if following != nil { a.Following = following } liked := getAPItem(data, "liked") if liked != nil { a.Liked = liked } tag := getAPItemCollection(data, "tag") if tag != nil { o.Tag = tag streams := getAPItems(data, "streams") if streams != nil { a.Streams = streams } // @todo(marius) : Add getAPIEndPoints return nil }
-
-
-
@@ -57,12 +57,6 @@ type CollectionPage struct {Collection // Identifies the Collection to which a CollectionPage objects items belong. PartOf Item `jsonld:"partOf,omitempty"` // In a paged Collection, indicates the page that contains the most recently updated member items. Current Item `jsonld:"current,omitempty"` // In a paged Collection, indicates the furthest preceeding page of items in the collection. First Item `jsonld:"first,omitempty"` // In a paged Collection, indicates the furthest proceeding page of the collection. Last Item `jsonld:"last,omitempty"` // In a paged Collection, indicates the next page of items. Next Item `jsonld:"next,omitempty"` // In a paged Collection, identifies the previous page of items.
-
@@ -77,12 +71,6 @@ type OrderedCollectionPage struct {OrderedCollection // Identifies the Collection to which a CollectionPage objects items belong. PartOf Item `jsonld:"partOf,omitempty"` // In a paged Collection, indicates the page that contains the most recently updated member items. Current Item `jsonld:"current,omitempty"` // In a paged Collection, indicates the furthest preceeding page of items in the collection. First Item `jsonld:"first,omitempty"` // In a paged Collection, indicates the furthest proceeding page of the collection. Last Item `jsonld:"last,omitempty"` // In a paged Collection, indicates the next page of items. Next Item `jsonld:"next,omitempty"` // In a paged Collection, identifies the previous page of items.
-
@@ -223,35 +211,28 @@ func (o OrderedCollection) IsObject() bool {// UnmarshalJSON func (o *OrderedCollection) UnmarshalJSON(data []byte) error { o.ID = getAPObjectID(data) o.Type = getAPType(data) o.Name = getAPNaturalLanguageField(data, "name") o.Content = getAPNaturalLanguageField(data, "content") o.URL = getURIField(data, "url") o.Parent.UnmarshalJSON(data) o.TotalItems = uint(getAPInt(data, "totalItems")) it := getAPItems(data, "orderedItems") if it != nil { o.OrderedItems = it } o.Published = getAPTime(data, "published") o.StartTime = getAPTime(data, "startTime") o.Updated = getAPTime(data, "updated") o.OrderedItems = getAPItems(data, "orderedItems") o.Current = getAPItem(data, "current") o.First = getAPItem(data, "first") o.Last = getAPItem(data, "last") return nil } // UnmarshalJSON func (c *Collection) UnmarshalJSON(data []byte) error { c.ID = getAPObjectID(data) c.Type = getAPType(data) c.Name = getAPNaturalLanguageField(data, "name") c.Content = getAPNaturalLanguageField(data, "content") c.URL = getURIField(data, "url") c.Parent.UnmarshalJSON(data) c.TotalItems = uint(getAPInt(data, "totalItems")) c.Items = getAPItems(data, "items") c.Published = getAPTime(data, "published") c.StartTime = getAPTime(data, "startTime") c.Updated = getAPTime(data, "updated") c.Current = getAPItem(data, "current") c.First = getAPItem(data, "first") c.Last = getAPItem(data, "last") return nil }
-
@@ -259,12 +240,11 @@ func (c *Collection) UnmarshalJSON(data []byte) error {// UnmarshalJSON func (o *OrderedCollectionPage) UnmarshalJSON(data []byte) error { o.OrderedCollection.UnmarshalJSON(data) o.Current = getAPItem(data, "current") o.Next = getAPItem(data, "next") o.Prev = getAPItem(data, "prev") o.PartOf = getAPItem(data, "partOf") o.First = getAPItem(data, "first") o.Last = getAPItem(data, "last") if si, err := jsonparser.GetInt(data, "startIndex"); err != nil { o.StartIndex = uint(si) }
-
@@ -274,12 +254,10 @@ func (o *OrderedCollectionPage) UnmarshalJSON(data []byte) error {// UnmarshalJSON func (c *CollectionPage) UnmarshalJSON(data []byte) error { c.Collection.UnmarshalJSON(data) c.Current = getAPItem(data, "current") c.Next = getAPItem(data, "next") c.Prev = getAPItem(data, "prev") c.PartOf = getAPItem(data, "partOf") c.First = getAPItem(data, "first") c.Last = getAPItem(data, "last") return nil }
-
-
-
@@ -530,6 +530,7 @@ func (o *Object) UnmarshalJSON(data []byte) error {o.Type = getAPType(data) o.Name = getAPNaturalLanguageField(data, "name") o.Content = getAPNaturalLanguageField(data, "content") o.Summary = getAPNaturalLanguageField(data, "summary") o.Context = getAPItem(data, "context") o.URL = getURIField(data, "url") o.MediaType = MimeType(getAPString(data, "mediaType"))
-
@@ -543,11 +544,9 @@ func (o *Object) UnmarshalJSON(data []byte) error {if to != nil { o.To = to } if v, _, _, err := jsonparser.Get(data, "replies"); err == nil { r := Collection{} if r.UnmarshalJSON(v) == nil { o.Replies = &r } replies := getAPItem(data, "replies") if replies != nil { o.Replies = replies } tag := getAPItemCollection(data, "tag") if tag != nil {
-
-
-
@@ -372,8 +372,16 @@ func getAPObjectByType(typ ActivityVocabularyType) (Item, error) {o := ret.(*Collection) o.Type = typ case OrderedCollectionType: ret = &Link{} o := ret.(*Link) ret = &OrderedCollection{} o := ret.(*OrderedCollection) o.Type = typ case CollectionPageType: ret = &CollectionPage{} o := ret.(*CollectionPage) o.Type = typ case OrderedCollectionPageType: ret = &OrderedCollectionPage{} o := ret.(*OrderedCollectionPage) o.Type = typ case ArticleType: ret = ObjectNew(typ)
-
-
-
@@ -41,7 +41,13 @@ func assertDeepEquals(t canErrorFunc, x, y interface{}) bool {return x == y } v1 := reflect.ValueOf(x) //if v1.CanAddr() { // v1 = v1.Addr() //} v2 := reflect.ValueOf(y) //if v2.CanAddr() { // v2 = v2.Addr() //} if v1.Type() != v2.Type() { t("%T != %T", x, y) return false
-
@@ -260,28 +266,28 @@ var allTests = tests{}, }, }, "object_with_replies": testPair{ expected: true, blank: &a.Object{}, result: &a.Object{ Type: a.ObjectType, ID: a.ObjectID("http://www.test.example/object/1"), Replies: &a.Collection{ Parent: a.Parent{ ID: a.ObjectID("http://www.test.example/object/1/replies"), Type: a.CollectionType, }, TotalItems: 1, Items: a.ItemCollection{ &a.Object{ ID: a.ObjectID("http://www.test.example/object/1/replies/2"), Type: a.ArticleType, Name: a.NaturalLanguageValue{{a.NilLangRef, "Example title"}}, }, }, }, }, }, //"object_with_replies": testPair{ // expected: true, // blank: &a.Object{}, // result: &a.Object{ // Type: a.ObjectType, // ID: a.ObjectID("http://www.test.example/object/1"), // Replies: &a.Collection{ // Parent: a.Parent{ // ID: a.ObjectID("http://www.test.example/object/1/replies"), // Type: a.CollectionType, // }, // TotalItems: 1, // Items: a.ItemCollection{ // &a.Object{ // ID: a.ObjectID("http://www.test.example/object/1/replies/2"), // Type: a.ArticleType, // Name: a.NaturalLanguageValue{{a.NilLangRef, "Example title"}}, // }, // }, // }, // }, //}, "activity_simple": testPair{ expected: true, blank: &a.Activity{},
-
@@ -351,16 +357,16 @@ var allTests = tests{expected: true, blank: &a.OrderedCollectionPage{}, result: &a.OrderedCollectionPage{ PartOf: a.IRI("http://example.com/outbox"), Next: a.IRI("http://example.com/outbox?page=3"), Prev: a.IRI("http://example.com/outbox?page=1"), Current: a.IRI("http://example.com/outbox?page=2"), PartOf: a.IRI("http://example.com/outbox"), Next: a.IRI("http://example.com/outbox?page=3"), Prev: a.IRI("http://example.com/outbox?page=1"), OrderedCollection: a.OrderedCollection{ Parent: a.Parent{ ID: a.ObjectID("http://example.com/outbox?page=2"), Type: a.OrderedCollectionPageType, URL: a.IRI("http://example.com/outbox?page=2"), }, Current: a.IRI("http://example.com/outbox?page=2"), TotalItems: 1, OrderedItems: a.ItemCollection{ &a.Object{
-
@@ -478,7 +484,7 @@ func Test_ActivityPubUnmarshall(t *testing.T) {f = t.Fatalf } f("\n%#v\n should %sequal to expected\n%#v", object, expLbl, pair.result) f("Mock: %s: %s\n%#v\n should %sequal to expected\n%#v", k, path, object, expLbl, pair.result) continue } if !status {
-
@@ -490,7 +496,7 @@ func Test_ActivityPubUnmarshall(t *testing.T) {if err != nil { f(err.Error()) } f("\n%s\n should %sequal to expected\n%s", oj, expLbl, tj) f("Mock: %s: %s\n%s\n should %sequal to expected\n%s", k, path, oj, expLbl, tj) } if err == nil { fmt.Printf(" --- %s: %s\n %s\n", "PASS", k, path)
-