From c2cc81ff3bc67f493ca66fec8fea959a37ada9e8 Mon Sep 17 00:00:00 2001 From: Marius Orcsik Date: Wed, 15 May 2019 22:22:36 +0200 Subject: [PATCH] Added ToPerson function --- actors.go | 17 ++++++++++++++++- actors_test.go | 4 ++++ go.mod | 2 +- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/actors.go b/actors.go index ad1331e..069b7e2 100644 --- a/actors.go +++ b/actors.go @@ -1,6 +1,9 @@ package activitypub -import as "github.com/go-ap/activitystreams" +import ( + "errors" + as "github.com/go-ap/activitystreams" +) // Endpoints a json object which maps additional (typically server/domain-wide) // endpoints which may be useful either for this actor or someone referencing this actor. @@ -151,3 +154,15 @@ func (a *actor)UnmarshalJSON(data []byte) error { //a.Streams = as.JSONGetItems(data, "streams") return nil } + + +// ToObject +func ToPerson(it as.Item) (*Person, error) { + switch i := it.(type) { + case *actor: + return i, nil + case actor: + return &i, nil + } + return nil, errors.New("unable to convert object") +} diff --git a/actors_test.go b/actors_test.go index 2d2fa4a..b923f65 100644 --- a/actors_test.go +++ b/actors_test.go @@ -333,3 +333,7 @@ func TestService_IsLink(t *testing.T) { func TestService_IsObject(t *testing.T) { t.Skipf("TODO") } + +func TestToPerson(t *testing.T) { + t.Skipf("TODO") +} diff --git a/go.mod b/go.mod index 657fdff..128978f 100644 --- a/go.mod +++ b/go.mod @@ -2,6 +2,6 @@ module github.com/go-ap/activitypub require ( github.com/buger/jsonparser v0.0.0-20181023193515-52c6e1462ebd - github.com/go-ap/activitystreams v0.0.0-20190306111705-2a794fbd6a34 + github.com/go-ap/activitystreams v0.0.0-20190512181306-9255f5ce5de3 github.com/go-ap/jsonld v0.0.0-20190306111347-fbb94302fe92 )