Changes
5 changed files (+58/-2)
-
-
@@ -332,6 +332,9 @@ func (o *OrderedCollection) UnmarshalJSON(data []byte) error {if it != nil { o.OrderedItems = it } o.Published = getAPTime(data, "published") o.StartTime = getAPTime(data, "startTime") o.Updated = getAPTime(data, "updated") return nil }
-
-
-
@@ -432,6 +432,13 @@ func (o *Object) UnmarshalJSON(data []byte) error {o.MediaType = MimeType(getAPString(data, "mediaType")) o.Generator = getAPItem(data, "generator") o.AttributedTo = getAPItem(data, "attributedTo") o.Published = getAPTime(data, "published") o.StartTime = getAPTime(data, "startTime") o.Updated = getAPTime(data, "updated") //to := getAPObjectsArr(data, "to") //if to != nil { // o.To = to //} //fmt.Printf("%s\n %#v", data, o) return nil
-
-
-
@@ -6,6 +6,7 @@ import ("net/url" "reflect" "strings" "time" "github.com/buger/jsonparser" )
-
@@ -88,6 +89,13 @@ func getAPNaturalLanguageField(data []byte, prop string) NaturalLanguageValue {return n } func getAPTime(data []byte, prop string) time.Time { t := time.Time{} str, _ := jsonparser.GetUnsafeString(data, prop) t.UnmarshalText([]byte(str)) return t } func unmarshallToAPObject(data []byte) Item { if _, err := url.ParseRequestURI(string(data)); err == nil { // try to see if it's an IRI
-
@@ -152,6 +160,40 @@ func getAPItems(data []byte, prop string) ItemCollection {} return it } func getAPObjectsArr(data []byte, prop string) ObjectsArr { val, typ, _, err := jsonparser.Get(data, prop) if err != nil { return nil } var it ObjectsArr switch typ { case jsonparser.Array: jsonparser.ArrayEach(data, func(value []byte, dataType jsonparser.ValueType, offset int, err error) { i, err := getAPObjectByType(getAPType(value)) if err != nil { return } err = i.(json.Unmarshaler).UnmarshalJSON(value) if err != nil { return } it.Append(i) }, prop) case jsonparser.Object: jsonparser.ObjectEach(data, func(key []byte, value []byte, dataType jsonparser.ValueType, offset int) error { i := Object{} err := i.UnmarshalJSON(val) it.Append(i) return err }, prop) case jsonparser.String: s, _ := jsonparser.GetString(val) it.Append(URI(s)) } return it } func getURIField(data []byte, prop string) URI { val, err := jsonparser.GetString(data, prop)
-
-
-
@@ -12,7 +12,7 @@"content": "Example content!", "url": "http://example.com/53c6fb47", "mediaType": "text/markdown", "published": "2018-07-05T16:46:44.66836Z", "published": "2018-07-05T16:46:44.00000UTC", "generator": "http://example.com", "attributedTo": "http://example.com/account/alice" }
-
-
-
@@ -7,6 +7,7 @@ import ("os" "reflect" "testing" "time" "unsafe" a "github.com/mariusor/activitypub.go/activitypub"
-
@@ -180,6 +181,8 @@ func deepValueEqual(t canErrorFunc, v1, v2 reflect.Value, visited map[visit]boolreturn true // i guess? } var zLoc, _ = time.LoadLocation("UTC") var allTests = tests{ "empty": testPair{ path: "./mocks/empty.json",
-
@@ -276,10 +279,11 @@ var allTests = tests{&a.Object{ ID: a.ObjectID("http://example.com/outbox/53c6fb47"), Type: a.ArticleType, URL: a.URI("http://example.com/53c6fb47"), Name: a.NaturalLanguageValue{a.NullLangRef: "Example title"}, Content: a.NaturalLanguageValue{a.NullLangRef: "Example content!"}, URL: a.URI("http://example.com/53c6fb47"), MediaType: a.MimeType("text/markdown"), Published: time.Date(2018, time.July, 5, 16, 46, 44, 0, zLoc), Generator: a.IRI("http://example.com"), AttributedTo: a.IRI("http://example.com/accounts/alice"), },
-