Changes
2 changed files (+67/-6)
-
-
@@ -64,13 +64,41 @@ var validActivityTypes = [...]string{// Actor Types } // An Activity is a subtype of Object that describes some form of action that may happen, // is currently happening, or has already happened. // The Activity type itself serves as an abstract base type for all types of activities. // It is important to note that the Activity type itself does not carry any specific semantics // about the kind of action being taken. type Activity struct { BaseObject Actor Actor Object BaseObject Source Source *IntransitiveActivity // @see activitypub.Object Object ObjectOrLink `jsonld:"object,omitempty"` } // Instances of IntransitiveActivity are a subtype of Activity representing intransitive actions. // The object property is therefore inappropriate for these activities. type IntransitiveActivity struct { *BaseObject // Describes one or more entities that either performed or are expected to perform the activity. // Any single activity can have multiple actors. The actor may be specified using an indirect Link. Actor Actor `jsonld:"actor,omitempty"` // Describes the indirect object, or target, of the activity. // The precise meaning of the target is largely dependent on the type of action being described // but will often be the object of the English preposition "to". // For instance, in the activity "John added a movie to his wishlist", // the target of the activity is John's wishlist. An activity can have more than one target. Target ObjectOrLink `jsonld:"actor,omitempty"` // Describes the result of the activity. For instance, if a particular action results in the creation // of a new resource, the result property can be used to describe that new resource. Result ObjectOrLink `jsonld:"actor,omitempty"` // Describes an indirect object of the activity from which the activity is directed. // The precise meaning of the origin is the object of the English preposition "from". // For instance, in the activity "John moved an item to List B from List A", the origin of the activity is "List A". Origin ObjectOrLink `jsonld:"origin,omitempty"` // Identifies one or more objects used (or to be used) in the completion of an Activity. Instrument ObjectOrLink `jsonld:"instrument,omitempty"` Source Source } func ValidActivityType(_type string) bool { for _, v := range validActivityTypes {
-
@@ -81,12 +109,22 @@ func ValidActivityType(_type string) bool {return false } func ActivityNew(id ObjectId, _type string) Activity { func ActivityNew(id ObjectId, _type string) *Activity { if !ValidActivityType(_type) { _type = ActivityType } o := BaseObject{Id: id, Type: _type} a := IntransitiveActivity{BaseObject: &o} return &Activity{IntransitiveActivity: &a} } func IntransitiveActivityNew(id ObjectId, _type string) *IntransitiveActivity { if !ValidActivityType(_type) { _type = IntransitiveActivityType } o := BaseObject{Id: id, Type: _type} return Activity{BaseObject: o} return &IntransitiveActivity{BaseObject: &o} }
-
-
-
@@ -25,6 +25,29 @@ func TestActivityNew(t *testing.T) {} } func TestIntransitiveActivityNew(t *testing.T) { var testValue = ObjectId("test") var testType string = "Accept" a := IntransitiveActivityNew(testValue, testType) if a.Id != testValue { t.Errorf("IntransitiveActivity Id '%v' different than expected '%v'", a.Id, testValue) } if a.Type != testType { t.Errorf("IntransitiveActivity Type '%v' different than expected '%v'", a.Type, testType) } g := IntransitiveActivityNew(testValue, "") if g.Id != testValue { t.Errorf("IntransitiveActivity Id '%v' different than expected '%v'", g.Id, testValue) } if g.Type != IntransitiveActivityType { t.Errorf("IntransitiveActivity Type '%v' different than expected '%v'", g.Type, IntransitiveActivityType) } } func TestValidActivityType(t *testing.T) { var invalidType string = "RandomType"
-