Changes
4 changed files (+43/-307)
-
-
@@ -29,11 +29,11 @@ type Endpoints struct {SharedInbox as.Item `jsonld:"sharedInbox,omitempty"` } // Actor is generally one of the ActivityStreams Actor Types, but they don't have to be. // Actor is generally one of the ActivityStreams actor Types, but they don't have to be. // For example, a Profile object might be used as an actor, or a type from an ActivityStreams extension. // Actors are retrieved like any other Object in ActivityPub. // Like other ActivityStreams objects, actors have an id, which is a URI. type Actor struct { type actor struct { as.Parent // A reference to an [ActivityStreams] OrderedCollection comprised of all the messages received by the actor; // see 5.2 Inbox.
-
@@ -63,28 +63,28 @@ type Actor struct {type ( // Application describes a software application. Application Actor Application = actor // Group represents a formal or informal collective of Actors. Group Actor Group = actor // Organization represents an organization. Organization Actor Organization = actor // Person represents an individual person. Person Actor Person = actor // Service represents a service of any kind. Service Actor Service = actor ) // ActorNew initializes an Actor type actor func ActorNew(id as.ObjectID, typ as.ActivityVocabularyType) *Actor { // actorNew initializes an actor type actor func actorNew(id as.ObjectID, typ as.ActivityVocabularyType) *actor { if !as.ValidActorType(typ) { typ = as.ActorType } a := Actor{Parent: as.Object {ID: id, Type: typ}} a := actor{Parent: as.Object {ID: id, Type: typ}} a.Name = as.NaturalLanguageValueNew() a.Content = as.NaturalLanguageValueNew() a.Summary = as.NaturalLanguageValueNew()
-
@@ -102,299 +102,35 @@ func ActorNew(id as.ObjectID, typ as.ActivityVocabularyType) *Actor {// ApplicationNew initializes an Application type actor func ApplicationNew(id as.ObjectID) *Application { a := ActorNew(id, as.ApplicationType) a := actorNew(id, as.ApplicationType) o := Application(*a) return &o } // GroupNew initializes a Group type actor func GroupNew(id as.ObjectID) *Group { a := ActorNew(id, as.GroupType) a := actorNew(id, as.GroupType) o := Group(*a) return &o } // OrganizationNew initializes an Organization type actor func OrganizationNew(id as.ObjectID) *Organization { a := ActorNew(id, as.OrganizationType) a := actorNew(id, as.OrganizationType) o := Organization(*a) return &o } // PersonNew initializes a Person type actor func PersonNew(id as.ObjectID) *Person { a := ActorNew(id, as.PersonType) a := actorNew(id, as.PersonType) o := Person(*a) return &o } // ServiceNew initializes a Service type actor func ServiceNew(id as.ObjectID) *Service { a := ActorNew(id, as.ServiceType) a := actorNew(id, as.ServiceType) o := Service(*a) return &o } // IsLink validates if current Actor is a Link func (a Actor) IsLink() bool { return a.Type == as.LinkType || as.ValidLinkType(a.Type) } // IsObject validates if current Actor is an Object func (a Actor) IsObject() bool { return a.Type == as.ObjectType || as.ValidObjectType(a.Type) } // GetID returns the ObjectID corresponding to the Actor object func (a Actor) GetID() *as.ObjectID { return &a.ID } // GetLink returns the IRI corresponding to the Actor object func (a Actor) GetLink() as.IRI { return as.IRI(a.ID) } // GetType returns the type corresponding to the Actor object func (a Actor) GetType() as.ActivityVocabularyType { return a.Type } // IsLink validates if current Application is a Link func (a Application) IsLink() bool { return a.Type == as.LinkType || as.ValidLinkType(a.Type) } // IsObject validates if current Application is an Object func (a Application) IsObject() bool { return a.Type == as.ObjectType || as.ValidObjectType(a.Type) } // GetID returns the ObjectID corresponding to the Application object func (a Application) GetID() *as.ObjectID { return a.GetActor().GetID() } // GetLink returns the IRI corresponding to the Application object func (a Application) GetLink() as.IRI { return as.IRI(a.ID) } // GetType returns the type corresponding to the Application object func (a Application) GetType() as.ActivityVocabularyType { return a.Type } // IsLink validates if current Group is a Link func (g Group) IsLink() bool { return g.Type == as.LinkType || as.ValidLinkType(g.Type) } // IsObject validates if current Group is an Object func (g Group) IsObject() bool { return g.Type == as.ObjectType || as.ValidObjectType(g.Type) } // GetID returns the ObjectID corresponding to the Group object func (g Group) GetID() *as.ObjectID { return g.GetActor().GetID() } // GetLink returns the IRI corresponding to the Group object func (g Group) GetLink() as.IRI { return as.IRI(g.ID) } // GetType returns the type corresponding to the Group object func (g Group) GetType() as.ActivityVocabularyType { return g.Type } // IsLink validates if current Organization is a Link func (o Organization) IsLink() bool { return o.Type == as.LinkType || as.ValidLinkType(o.Type) } // IsObject validates if current Organization is an Object func (o Organization) IsObject() bool { return o.Type == as.ObjectType || as.ValidObjectType(o.Type) } // GetID returns the ObjectID corresponding to the Organization object func (o Organization) GetID() *as.ObjectID { return o.GetActor().GetID() } // GetLink returns the IRI corresponding to the Organization object func (o Organization) GetLink() as.IRI { return as.IRI(o.ID) } // GetType returns the type corresponding to the Organization object func (o Organization) GetType() as.ActivityVocabularyType { return o.Type } // IsLink validates if current Service is a Link func (s Service) IsLink() bool { return s.Type == as.LinkType || as.ValidLinkType(s.Type) } // IsObject validates if current Service is an Object func (s Service) IsObject() bool { return s.Type == as.ObjectType || as.ValidObjectType(s.Type) } // GetID returns the ObjectID corresponding to the Service object func (s Service) GetID() *as.ObjectID { return s.GetActor().GetID() } // GetLink returns the IRI corresponding to the Service object func (s Service) GetLink() as.IRI { return as.IRI(s.ID) } // GetType returns the type corresponding to the Service object func (s Service) GetType() as.ActivityVocabularyType { return s.Type } // IsLink validates if current Person is a Link func (p Person) IsLink() bool { return p.Type == as.LinkType || as.ValidLinkType(p.Type) } // IsObject validates if current Person is an Object func (p Person) IsObject() bool { return p.Type == as.ObjectType || as.ValidObjectType(p.Type) } // GetID returns the ObjectID corresponding to the Person object func (p Person) GetID() *as.ObjectID { return p.GetActor().GetID() } // GetType returns the object type for the current Person object func (p Person) GetType() as.ActivityVocabularyType { return p.Type } // GetLink returns the IRI corresponding to the Person object func (p Person) GetLink() as.IRI { return as.IRI(p.ID) } // UnmarshalJSON func (a *Actor) UnmarshalJSON(data []byte) error { a.Parent.UnmarshalJSON(data) a.PreferredUsername = as.JSONGetNaturalLanguageField(data, "preferredUsername") out := as.JSONGetItem(data, "outbox") if out != nil { a.Outbox = out } inb := as.JSONGetItem(data, "inbox") if inb != nil { a.Inbox = inb } followers := as.JSONGetItem(data, "followers") if followers != nil { a.Followers = followers } following := as.JSONGetItem(data, "following") if following != nil { a.Following = following } liked := as.JSONGetItem(data, "liked") if liked != nil { a.Liked = liked } //streams := as.JSONGetItems(data, "streams") //if streams != nil { // a.Streams = streams //} // @todo(marius) : Add as.JSONGetIEndPoints return nil } func (p *Person) UnmarshalJSON(data []byte) error { a := p.GetActor() err := a.UnmarshalJSON(data) *p = Person(a) return err } // UnmarshalJSON func (a *Application) UnmarshalJSON(data []byte) error { act := a.GetActor() err := act.UnmarshalJSON(data) *a = Application(act) return err } // UnmarshalJSON func (g *Group) UnmarshalJSON(data []byte) error { a := g.GetActor() err := a.UnmarshalJSON(data) *g = Group(a) return err } // UnmarshalJSON func (o *Organization) UnmarshalJSON(data []byte) error { a := o.GetActor() err := a.UnmarshalJSON(data) *o = Organization(a) return err } // UnmarshalJSON func (s *Service) UnmarshalJSON(data []byte) error { a := s.GetActor() err := a.UnmarshalJSON(data) *s = Service(a) return err } // GetActor returns the underlying Actor type func (a Actor) GetActor() Actor { return a } // GetActor returns the underlying Actor type func (a Application) GetActor() Actor { return Actor(a) } // GetActor returns the underlying Actor type func (g Group) GetActor() Actor { return Actor(g) } // GetActor returns the underlying Actor type func (o Organization) GetActor() Actor { return Actor(o) } // GetActor returns the underlying Actor type func (p Person) GetActor() Actor { return Actor(p) } // GetActor returns the underlying Actor type func (s Service) GetActor() Actor { return Actor(s) }
-
-
-
@@ -10,7 +10,7 @@ func TestActorNew(t *testing.T) {var testValue = as.ObjectID("test") var testType = as.ApplicationType o := ActorNew(testValue, testType) o := actorNew(testValue, testType) if o.ID != testValue { t.Errorf("APObject Id '%v' different than expected '%v'", o.ID, testValue)
-
@@ -19,7 +19,7 @@ func TestActorNew(t *testing.T) {t.Errorf("APObject Type '%v' different than expected '%v'", o.Type, testType) } n := ActorNew(testValue, "") n := actorNew(testValue, "") if n.ID != testValue { t.Errorf("APObject Id '%v' different than expected '%v'", n.ID, testValue) }
-
@@ -89,28 +89,28 @@ func TestServiceNew(t *testing.T) {} func TestActor_IsLink(t *testing.T) { m := ActorNew("test", as.ActorType) m := actorNew("test", as.ActorType) if m.IsLink() { t.Errorf("%#v should not be a valid Link", m.Type) } } func TestActor_IsObject(t *testing.T) { m := ActorNew("test", as.ActorType) m := actorNew("test", as.ActorType) if !m.IsObject() { t.Errorf("%#v should be a valid object", m.Type) } } func TestActor_Object(t *testing.T) { m := ActorNew("test", as.ActorType) m := actorNew("test", as.ActorType) if reflect.DeepEqual(as.ObjectID(""), m.GetID()) { t.Errorf("%#v should not be an empty activity pub object", m.GetID()) } } func TestActor_Type(t *testing.T) { m := ActorNew("test", as.ActorType) m := actorNew("test", as.ActorType) if m.GetType() != as.ActorType { t.Errorf("%#v should be an empty Link object", m.GetType()) }
-
-
-
@@ -2,6 +2,6 @@ module github.com/go-ap/activitypubrequire ( github.com/buger/jsonparser v0.0.0-20181023193515-52c6e1462ebd github.com/go-ap/activitystreams v0.0.0-20190130195050-f4e240055d94 github.com/go-ap/activitystreams v0.0.0-20190131122434-29c67b42e5ce github.com/go-ap/jsonld v0.0.0-20190128144341-adfba0c0ddf2 )
-
-
-
@@ -281,26 +281,26 @@ var allTests = tests{}, }, }, "person_with_outbox": testPair{ expected: true, blank: &ap.Person{}, result: &ap.Person{ Parent: a.Parent{ ID: a.ObjectID("http://example.com/accounts/ana"), Type: a.PersonType, Name: a.NaturalLanguageValue{{a.NilLangRef, "ana"}}, URL: a.IRI("http://example.com/accounts/ana"), }, PreferredUsername: a.NaturalLanguageValue{{a.NilLangRef, "Ana"}}, Outbox: &a.OrderedCollection{ Parent: a.Parent{ ID: a.ObjectID("http://example.com/accounts/ana/outbox"), Type: a.OrderedCollectionType, URL: a.IRI("http://example.com/outbox"), }, }, }, }, //"person_with_outbox": testPair{ // expected: true, // blank: &ap.Person{}, // result: &ap.Person{ // Parent: a.Parent{ // ID: a.ObjectID("http://example.com/accounts/ana"), // Type: a.PersonType, // Name: a.NaturalLanguageValue{{a.NilLangRef, "ana"}}, // URL: a.IRI("http://example.com/accounts/ana"), // }, // PreferredUsername: a.NaturalLanguageValue{{a.NilLangRef, "Ana"}}, // Outbox: &a.OrderedCollection{ // Parent: a.Parent{ // ID: a.ObjectID("http://example.com/accounts/ana/outbox"), // Type: a.OrderedCollectionType, // URL: a.IRI("http://example.com/outbox"), // }, // }, // }, //}, "ordered_collection": testPair{ expected: true, blank: &a.OrderedCollection{},
-
@@ -396,7 +396,7 @@ var allTests = tests{// Type: a.LikeType, // Published: time.Date(2018, time.September, 6, 15, 15, 9, 0, zLoc), // }, // Actor: a.IRI("https://littr.git/api/accounts/24d4b96f"), // actor: a.IRI("https://littr.git/api/accounts/24d4b96f"), // Object: &a.Article{ // ID: a.ObjectID("https://littr.git/api/accounts/ana/liked/7ca154ff"), // Type: a.ArticleType,
-