Changes
11 changed files (+273/-163)
-
-
@@ -2,37 +2,37 @@ package activitypubconst ( // Activity Types AcceptType string = "Accept" AddType string = "Add" AnnounceType string = "Announce" ArriveType string = "Arrive" BlockType string = "Block" CreateType string = "Create" DeleteType string = "Delete" DislikeType string = "Dislike" FlagType string = "Flag" FollowType string = "Follow" IgnoreType string = "Ignore" InviteType string = "Invite" JoinType string = "Join" LeaveType string = "Leave" LikeType string = "Like" ListenType string = "Listen" MoveType string = "Move" OfferType string = "Offer" QuestionType string = "Question" RejectType string = "Reject" ReadType string = "Read" RemoveType string = "Remove" TentativeRejectType string = "TentativeReject" TentativeAcceptType string = "TentativeAccept" TravelType string = "Travel" UndoType string = "Undo" UpdateType string = "Update" ViewType string = "View" AcceptType ActivityVocabularyType = "Accept" AddType ActivityVocabularyType = "Add" AnnounceType ActivityVocabularyType = "Announce" ArriveType ActivityVocabularyType = "Arrive" BlockType ActivityVocabularyType = "Block" CreateType ActivityVocabularyType = "Create" DeleteType ActivityVocabularyType = "Delete" DislikeType ActivityVocabularyType = "Dislike" FlagType ActivityVocabularyType = "Flag" FollowType ActivityVocabularyType = "Follow" IgnoreType ActivityVocabularyType = "Ignore" InviteType ActivityVocabularyType = "Invite" JoinType ActivityVocabularyType = "Join" LeaveType ActivityVocabularyType = "Leave" LikeType ActivityVocabularyType = "Like" ListenType ActivityVocabularyType = "Listen" MoveType ActivityVocabularyType = "Move" OfferType ActivityVocabularyType = "Offer" QuestionType ActivityVocabularyType = "Question" RejectType ActivityVocabularyType = "Reject" ReadType ActivityVocabularyType = "Read" RemoveType ActivityVocabularyType = "Remove" TentativeRejectType ActivityVocabularyType = "TentativeReject" TentativeAcceptType ActivityVocabularyType = "TentativeAccept" TravelType ActivityVocabularyType = "Travel" UndoType ActivityVocabularyType = "Undo" UpdateType ActivityVocabularyType = "Update" ViewType ActivityVocabularyType = "View" ) var validActivityTypes = [...]string{ var validActivityTypes = [...]ActivityVocabularyType{ AcceptType, AddType, AnnounceType,
-
@@ -70,23 +70,23 @@ type IntransitiveActivity struct {*Object // 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"` 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"` Target ObjectOrLink `jsonld:"target,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"` Result ObjectOrLink `jsonld:"result,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"` 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"` Source Source Instrument ObjectOrLink `jsonld:"instrument,omitempty"` Source Source `jsonld:"source,omitempty"` } // An Activity is a subtype of Object that describes some form of action that may happen,
-
@@ -100,7 +100,7 @@ type Activity struct {// For instance, in the activity "John added a movie to his wishlist", // the object of the activity is the movie added. // When used within a Relationship describes the entity to which the subject is related. Object ObjectOrLink `jsonld:"object"` Object ObjectOrLink `jsonld:"object,omitempty"` } type (
-
@@ -219,12 +219,12 @@ type Question struct {*IntransitiveActivity // Identifies an exclusive option for a Question. Use of oneOf implies that the Question // can have only a single answer. To indicate that a Question can have multiple answers, use anyOf. OneOf ObjectOrLink `jsonld:"oneOf"` OneOf ObjectOrLink `jsonld:"oneOf,omitempty"` // Identifies an inclusive option for a Question. Use of anyOf implies that the Question can have multiple answers. // To indicate that a Question can have only one answer, use oneOf. AnyOf ObjectOrLink `jsonld:"anyOf"` AnyOf ObjectOrLink `jsonld:"anyOf,omitempty"` // Indicates that a question has been closed, and answers are no longer accepted. Closed bool `jsonld:"closed"` Closed bool `jsonld:"closed,omitempty"` } func AcceptNew(id ObjectId) *Accept {
-
@@ -368,7 +368,7 @@ func QuestionNew(id ObjectId) *Question {return &o } func ValidActivityType(_type string) bool { func ValidActivityType(_type ActivityVocabularyType) bool { for _, v := range validActivityTypes { if v == _type { return true
-
@@ -377,7 +377,7 @@ func ValidActivityType(_type string) bool {return false } func ActivityNew(id ObjectId, _type string) *Activity { func ActivityNew(id ObjectId, _type ActivityVocabularyType) *Activity { if !ValidActivityType(_type) { _type = ActivityType }
-
@@ -387,7 +387,7 @@ func ActivityNew(id ObjectId, _type string) *Activity {return &Activity{IntransitiveActivity: &a} } func IntransitiveActivityNew(id ObjectId, _type string) *IntransitiveActivity { func IntransitiveActivityNew(id ObjectId, _type ActivityVocabularyType) *IntransitiveActivity { if !ValidActivityType(_type) { _type = IntransitiveActivityType }
-
-
-
@@ -4,7 +4,7 @@ import "testing"func TestActivityNew(t *testing.T) { var testValue = ObjectId("test") var testType string = "Accept" var testType ActivityVocabularyType = "Accept" a := ActivityNew(testValue, testType) if a.Id != testValue {
-
@@ -26,7 +26,7 @@ func TestActivityNew(t *testing.T) {func TestIntransitiveActivityNew(t *testing.T) { var testValue = ObjectId("test") var testType string = "Accept" var testType ActivityVocabularyType = "Accept" a := IntransitiveActivityNew(testValue, testType)
-
@@ -48,7 +48,7 @@ func TestIntransitiveActivityNew(t *testing.T) {} func TestValidActivityType(t *testing.T) { var invalidType string = "RandomType" var invalidType ActivityVocabularyType = "RandomType" if ValidActivityType(ActivityType) { t.Errorf("Generic Activity Type '%v' should not be valid", ActivityType)
-
-
-
@@ -2,14 +2,14 @@ package activitypubconst ( // Actor Types ApplicationType string = "Application" GroupType string = "Group" OrganizationType string = "Organization" PersonType string = "Person" ServiceType string = "Service" ApplicationType ActivityVocabularyType = "Application" GroupType ActivityVocabularyType = "Group" OrganizationType ActivityVocabularyType = "Organization" PersonType ActivityVocabularyType = "Person" ServiceType ActivityVocabularyType = "Service" ) var validActorTypes = [...]string{ var validActorTypes = [...]ActivityVocabularyType{ ApplicationType, GroupType, OrganizationType,
-
@@ -19,25 +19,25 @@ var validActorTypes = [...]string{type Endpoints struct { // Upload endpoint URI for this user for binary data. UploadMedia ObjectOrLink `jsonld:"uploadMedia"` UploadMedia ObjectOrLink `jsonld:"uploadMedia,omitempty"` // Endpoint URI so this actor's clients may access remote ActivityStreams objects which require authentication // to access. To use this endpoint, the client posts an x-www-form-urlencoded id parameter with the value being // the id of the requested ActivityStreams object. OauthAuthorizationEndpoint ObjectOrLink `jsonld:"oauthAuthorizationEndpoint"` OauthAuthorizationEndpoint ObjectOrLink `jsonld:"oauthAuthorizationEndpoint,omitempty"` // If OAuth 2.0 bearer tokens [RFC6749] [RFC6750] are being used for authenticating client to server interactions, // this endpoint specifies a URI at which a browser-authenticated user may obtain a new authorization grant. OauthTokenEndpoint ObjectOrLink `jsonld:"oauthTokenEndpoint"` OauthTokenEndpoint ObjectOrLink `jsonld:"oauthTokenEndpoint,omitempty"` // If OAuth 2.0 bearer tokens [RFC6749] [RFC6750] are being used for authenticating client to server interactions, // this endpoint specifies a URI at which a client may acquire an access token. ProvideClientKey ObjectOrLink `jsonld:"provideClientKey"` ProvideClientKey ObjectOrLink `jsonld:"provideClientKey,omitempty"` // If Linked Data Signatures and HTTP Signatures are being used for authentication and authorization, // this endpoint specifies a URI at which browser-authenticated users may authorize a client's public // key for client to server interactions. SignClientKey ObjectOrLink `jsonld:"signClientKey"` SignClientKey ObjectOrLink `jsonld:"signClientKey,omitempty"` // If Linked Data Signatures and HTTP Signatures are being used for authentication and authorization, // this endpoint specifies a URI at which a client key may be signed by the actor's key for a time window to // act on behalf of the actor in interacting with foreign servers. SharedInbox ObjectOrLink `jsonld:"sharedInbox"` SharedInbox ObjectOrLink `jsonld:"sharedInbox,omitempty"` } // Actor types are Object types that are capable of performing activities.
-
@@ -45,28 +45,28 @@ type Actor struct {*Object // A reference to an [ActivityStreams] OrderedCollection comprised of all the messages received by the actor; // see 5.2 Inbox. Inbox InboxStream `jsonld:"inbox"` Inbox InboxStream `jsonld:"inbox,omitempty"` // An [ActivityStreams] OrderedCollection comprised of all the messages produced by the actor; // see 5.1 Outbox. Outbox OutboxStream `jsonld:"outbox"` Outbox OutboxStream `jsonld:"outbox,omitempty"` // A link to an [ActivityStreams] collection of the actors that this actor is following; // see 5.4 Following Collection Following FollowingCollection `jsonld:"following"` Following FollowingCollection `jsonld:"following,omitempty"` // A link to an [ActivityStreams] collection of the actors that follow this actor; // see 5.3 Followers Collection. Followers FollowersCollection `jsonld:"followers"` Followers FollowersCollection `jsonld:"followers,omitempty"` // A link to an [ActivityStreams] collection of the actors that follow this actor; // see 5.3 Followers Collection. Liked LikedCollection `jsonld:"liked"` Liked LikedCollection `jsonld:"liked,omitempty"` // A short username which may be used to refer to the actor, with no uniqueness guarantees. PreferredUsername NaturalLanguageValue `jsonld:"preferredUsername"` PreferredUsername NaturalLanguageValue `jsonld:"preferredUsername,omitempty,collapsible"` // A json object which maps additional (typically server/domain-wide) endpoints which may be useful either // for this actor or someone referencing this actor. // This mapping may be nested inside the actor document as the value or may be a link // to a JSON-LD document with these properties. Endpoints Endpoints `jsonld:"endpoints"` Endpoints Endpoints `jsonld:"endpoints,omitempty"` // A list of supplementary Collections which may be of interest. Streams []Collection `jsonld:"streams"` Streams []Collection `jsonld:"streams,omitempty"` } type (
-
@@ -86,7 +86,7 @@ type (Service Actor ) func ValidActorType(_type string) bool { func ValidActorType(_type ActivityVocabularyType) bool { for _, v := range validActorTypes { if v == _type { return true
-
@@ -95,7 +95,7 @@ func ValidActorType(_type string) bool {return false } func ActorNew(id ObjectId, _type string) *Actor { func ActorNew(id ObjectId, _type ActivityVocabularyType) *Actor { if !ValidActorType(_type) { _type = ActorType }
-
-
-
@@ -85,3 +85,16 @@ func TestServiceNew(t *testing.T) {t.Errorf("Object Type '%v' different than expected '%v'", o.Type, ServiceType) } } func TestValidActorType(t *testing.T) { var invalidType ActivityVocabularyType = "RandomType" if ValidActorType(invalidType) { t.Errorf("Object Type '%v' should not be valid", invalidType) } for _, validType := range validActorTypes { if !ValidActorType(validType) { t.Errorf("Object Type '%v' should be valid", validType) } } }
-
-
-
@@ -1,6 +1,6 @@package activitypub var validCollectionTypes = [...]string{CollectionType, OrderedCollectionType} var validCollectionTypes = [...]ActivityVocabularyType{CollectionType, OrderedCollectionType} type Page ObjectOrLink
-
@@ -8,51 +8,51 @@ type Collection struct {*Object // A non-negative integer specifying the total number of objects contained by the logical view of the collection. // This number might not reflect the actual number of items serialized within the Collection object instance. TotalItems uint `jsonld:"totalItems"` TotalItems uint `jsonld:"totalItems,omitempty"` // Identifies the items contained in a collection. The items might be ordered or unordered. Items ItemCollection `jsonld:"items"` Items ItemCollection `jsonld:"items,omitempty"` } type OrderedCollection struct { *Object // A non-negative integer specifying the total number of objects contained by the logical view of the collection. // This number might not reflect the actual number of items serialized within the Collection object instance. TotalItems uint `jsonld:"totalItems"` TotalItems uint `jsonld:"totalItems,omitempty"` // Identifies the items contained in a collection. The items might be ordered or unordered. OrderedItems ItemCollection `jsonld:"orderedItems"` OrderedItems ItemCollection `jsonld:"orderedItems,omitempty"` } type CollectionPage struct { PartOf *Collection // In a paged Collection, indicates the page that contains the most recently updated member items. Current Page `jsonld:"current"` Current Page `jsonld:"current,omitempty"` // In a paged Collection, indicates the furthest preceeding page of items in the collection. First Page `jsonld:"first"` First Page `jsonld:"first,omitempty"` // In a paged Collection, indicates the furthest proceeding page of the collection. Last Page `jsonld:"last"` Last Page `jsonld:"last,omitempty"` // In a paged Collection, indicates the next page of items. Next Page `jsonld:"next"` Next Page `jsonld:"next,omitempty"` // In a paged Collection, identifies the previous page of items. Prev Page `jsonld:"prev"` Prev Page `jsonld:"prev,omitempty"` } type OrderedCollectionPage struct { PartOf *OrderedCollection // In a paged Collection, indicates the page that contains the most recently updated member items. Current Page `jsonld:"current"` Current Page `jsonld:"current,omitempty"` // In a paged Collection, indicates the furthest preceeding page of items in the collection. First Page `jsonld:"first"` First Page `jsonld:"first,omitempty"` // In a paged Collection, indicates the furthest proceeding page of the collection. Last Page `jsonld:"last"` Last Page `jsonld:"last,omitempty"` // In a paged Collection, indicates the next page of items. Next Page `jsonld:"next"` Next Page `jsonld:"next,omitempty"` // In a paged Collection, identifies the previous page of items. Prev Page `jsonld:"prev"` Prev Page `jsonld:"prev,omitempty"` // A non-negative integer value identifying the relative position within the logical view of a strictly ordered collection. StartIndex uint `jsonld:"startIndex"` StartIndex uint `jsonld:"startIndex,omitempty"` } func ValidCollectionType(_type string) bool { func ValidCollectionType(_type ActivityVocabularyType) bool { for _, v := range validCollectionTypes { if v == _type { return true
-
-
-
@@ -1,6 +1,6 @@package activitypub var validLinkTypes = [...]string{ var validLinkTypes = [...]ActivityVocabularyType{ MentionType, }
-
@@ -20,23 +20,23 @@ type Link struct {// When used on a Link, identifies the MIME media type of the referenced resource. // When used on an Object, identifies the MIME media type of the value of the content property. // If not specified, the content property is assumed to contain text/html content. MediaType MimeType `jsonld:"mediaType"` MediaType MimeType `jsonld:"mediaType,omitempty"` // On a Link, specifies a hint as to the rendering height in device-independent pixels of the linked resource. Height uint `jsonld:"height"` Height uint `jsonld:"height,omitempty"` // On a Link, specifies a hint as to the rendering width in device-independent pixels of the linked resource. Width uint `jsonld:"width"` Width uint `jsonld:"width,omitempty"` // Identifies an entity that provides a preview of this object. Preview ObjectOrLink `jsonld:"preview"` Preview ObjectOrLink `jsonld:"preview,omitempty"` // The target resource pointed to by a Link. Href URI `jsonld:"href"` Href URI `jsonld:"href,omitempty"` // Hints as to the language used by the target resource. // Value must be a [BCP47](https://tools.ietf.org/html/bcp47) Language-Tag. HrefLang LangRef `jsonld:"hrefLang"` HrefLang LangRef `jsonld:"hrefLang,omitempty"` } type Mention Link func ValidLinkType(_type string) bool { func ValidLinkType(_type ActivityVocabularyType) bool { for _, v := range validLinkTypes { if v == _type { return true
-
@@ -45,10 +45,31 @@ func ValidLinkType(_type string) bool {return false } func LinkNew(id ObjectId, _type string) *Link { func LinkNew(id ObjectId, _type ActivityVocabularyType) *Link { if !ValidLinkType(_type) { _type = LinkType } p := BaseObject{Id: id, Type: _type} return &Link{BaseObject: &p} } func MentionNew(id ObjectId) *Mention { p := BaseObject{Id: id, Type: MentionType} return &Mention{BaseObject: &p} } func (l *Link) IsLink() bool { return l.Type == LinkType || ValidLinkType(l.Type) } func (l *Link) IsObject() bool { return l.Type == ObjectType || ValidObjectType(l.Type) } func (l *Mention) IsLink() bool { return l.Type == MentionType || ValidLinkType(l.Type) } func (l *Mention) IsObject() bool { return l.Type == ObjectType || ValidObjectType(l.Type) }
-
-
-
@@ -4,7 +4,7 @@ import "testing"func TestLinkNew(t *testing.T) { var testValue = ObjectId("test") var testType string var testType ActivityVocabularyType l := LinkNew(testValue, testType)
-
@@ -17,7 +17,7 @@ func TestLinkNew(t *testing.T) {} func TestValidLinkType(t *testing.T) { var invalidType string = "RandomType" var invalidType ActivityVocabularyType = "RandomType" if ValidLinkType(LinkType) { t.Errorf("Generic Link Type '%v' should not be valid", LinkType)
-
@@ -31,3 +31,39 @@ func TestValidLinkType(t *testing.T) {} } } func TestLink_IsLink(t *testing.T) { l := LinkNew("test", LinkType) if !l.IsLink() { t.Errorf("%#v should be a valid link", l.Type) } m := LinkNew("test", MentionType) if !m.IsLink() { t.Errorf("%#v should be a valid link", m.Type) } } func TestLink_IsObject(t *testing.T) { l := LinkNew("test", LinkType) if l.IsObject() { t.Errorf("%#v should not be a valid object", l.Type) } m := LinkNew("test", MentionType) if m.IsObject() { t.Errorf("%#v should not be a valid object", m.Type) } } func TestMention_IsMention(t *testing.T) { m := MentionNew("test") if !m.IsLink() { t.Errorf("%#v should be a valid Mention", m.Type) } } func TestMention_IsObject(t *testing.T) { m := MentionNew("test") if m.IsObject() { t.Errorf("%#v should not be a valid object", m.Type) } }
-
-
-
@@ -8,44 +8,49 @@ import (type ObjectId string const ( ActivityBaseURI URI = URI("https://www.w3.org/ns/activitystreams#") ObjectType string = "Object" LinkType string = "Link" ActivityType string = "Activity" IntransitiveActivityType string = "IntransitiveActivity" ActorType string = "Actor" CollectionType string = "Collection" OrderedCollectionType string = "OrderedCollection" ActivityBaseURI URI = URI("https://www.w3.org/ns/activitystreams#") ObjectType ActivityVocabularyType = "Object" LinkType ActivityVocabularyType = "Link" ActivityType ActivityVocabularyType = "Activity" IntransitiveActivityType ActivityVocabularyType = "IntransitiveActivity" ActorType ActivityVocabularyType = "Actor" CollectionType ActivityVocabularyType = "Collection" OrderedCollectionType ActivityVocabularyType = "OrderedCollection" // Object Types ArticleType string = "Article" AudioType string = "Audio" DocumentType string = "Document" EventType string = "Event" ImageType string = "Image" NoteType string = "Note" PageType string = "Page" PlaceType string = "Place" ProfileType string = "Profile" RelationshipType string = "Relationship" TombstoneType string = "Tombstone" VideoType string = "Video" ArticleType ActivityVocabularyType = "Article" AudioType ActivityVocabularyType = "Audio" DocumentType ActivityVocabularyType = "Document" EventType ActivityVocabularyType = "Event" ImageType ActivityVocabularyType = "Image" NoteType ActivityVocabularyType = "Note" PageType ActivityVocabularyType = "Page" PlaceType ActivityVocabularyType = "Place" ProfileType ActivityVocabularyType = "Profile" RelationshipType ActivityVocabularyType = "Relationship" TombstoneType ActivityVocabularyType = "Tombstone" VideoType ActivityVocabularyType = "Video" // Link Types MentionType string = "Mention" MentionType ActivityVocabularyType = "Mention" ) var validGenericTypes = [...]string{ var validGenericObjectTypes = [...]ActivityVocabularyType{ ActivityType, IntransitiveActivityType, ObjectType, LinkType, ActorType, CollectionType, OrderedCollectionType, } var validObjectTypes = [...]string{ var validGenericLinkTypes = [...]ActivityVocabularyType{ LinkType, } var validGenericTypes = append(validGenericObjectTypes[:], validGenericLinkTypes[:]...) var validObjectTypes = [...]ActivityVocabularyType{ ArticleType, AudioType, DocumentType,
-
@@ -61,14 +66,23 @@ var validObjectTypes = [...]string{} type ( ObjectOrLink interface{} LinkOrUri interface{} ImageOrLink interface{} MimeType string LangRef string NaturalLanguageValue map[LangRef]string ActivityVocabularyType string ObjectOrLink interface{} LinkOrUri interface{} ImageOrLink interface{} MimeType string LangRef string NaturalLanguageValue map[LangRef]string ) func (o *Object) IsLink() bool { return ValidLinkType(o.Type) } func (o *Object) IsObject() bool { return ValidObjectType(o.Type) } func (n NaturalLanguageValue) MarshalJSON() ([]byte, error) { if len(n) == 1 { for _, v := range n {
-
@@ -84,86 +98,86 @@ func (n NaturalLanguageValue) MarshalJSON() ([]byte, error) {// including other Core types such as Activity, IntransitiveActivity, Collection and OrderedCollection. type BaseObject struct { // Provides the globally unique identifier for an Object or Link. Id ObjectId `jsonld:"id"` Id ObjectId `jsonld:"id,omitempty"` // Identifies the Object or Link type. Multiple values may be specified. Type string `jsonld:"type"` Type ActivityVocabularyType `jsonld:"type,omitempty"` // A simple, human-readable, plain-text name for the object. // HTML markup MUST NOT be included. The name MAY be expressed using multiple language-tagged values. Name NaturalLanguageValue `jsonld:"name"` Name NaturalLanguageValue `jsonld:"name,omitempty,collapsible"` } type Object struct { *BaseObject // Identifies a resource attached or related to an object that potentially requires special handling. // The intent is to provide a model that is at least semantically similar to attachments in email. Attachment ObjectOrLink `jsonld:"attachment"` Attachment ObjectOrLink `jsonld:"attachment,omitempty"` // Identifies one or more entities to which this object is attributed. The attributed entities might not be Actors. // For instance, an object might be attributed to the completion of another activity. AttributedTo ObjectOrLink `jsonld:"attributedTo"` AttributedTo ObjectOrLink `jsonld:"attributedTo,omitempty"` // Identifies one or more entities that represent the total population of entities // for which the object can considered to be relevant. Audience ObjectOrLink `jsonld:"audience"` Audience ObjectOrLink `jsonld:"audience,omitempty"` // The content or textual representation of the Object encoded as a JSON string. // By default, the value of content is HTML. // The mediaType property can be used in the object to indicate a different content type. // (The content MAY be expressed using multiple language-tagged values.) Content NaturalLanguageValue `jsonld:"content"` Content NaturalLanguageValue `jsonld:"content,omitempty,collapsible"` // Identifies the context within which the object exists or an activity was performed. // The notion of "context" used is intentionally vague. // The intended function is to serve as a means of grouping objects and activities that share a // common originating context or purpose. An example could be all activities relating to a common project or event. Context ObjectOrLink `jsonld:"context"` Context ObjectOrLink `jsonld:"context,collapsible"` // The date and time describing the actual or expected ending time of the object. // When used with an Activity object, for instance, the endTime property specifies the moment // the activity concluded or is expected to conclude. EndTime time.Time `jsonld:"endTime"` EndTime time.Time `jsonld:"endTime,omitempty"` // Identifies the entity (e.g. an application) that generated the object. Generator ObjectOrLink `jsonld:"generator"` Generator ObjectOrLink `jsonld:"generator,omitempty"` // Indicates an entity that describes an icon for this object. // The image should have an aspect ratio of one (horizontal) to one (vertical) // and should be suitable for presentation at a small size. Icon ImageOrLink `jsonld:"icon"` Icon ImageOrLink `jsonld:"icon,omitempty"` // Indicates an entity that describes an image for this object. // Unlike the icon property, there are no aspect ratio or display size limitations assumed. Image ImageOrLink `jsonld:"image"` Image ImageOrLink `jsonld:"image,omitempty"` // Indicates one or more entities for which this object is considered a response. InReplyTo ObjectOrLink `jsonld:"inReplyTo"` InReplyTo ObjectOrLink `jsonld:"inReplyTo,omitempty"` // Indicates one or more physical or logical locations associated with the object. Location ObjectOrLink `jsonld:"location"` Location ObjectOrLink `jsonld:"location,omitempty"` // Identifies an entity that provides a preview of this object. Preview ObjectOrLink `jsonld:"preview"` Preview ObjectOrLink `jsonld:"preview,omitempty"` // The date and time at which the object was published Published time.Time `jsonld:"published"` Published time.Time `jsonld:"published,omitempty"` // Identifies a Collection containing objects considered to be responses to this object. Replies Collection `jsonld:"replies"` Replies Collection `jsonld:"replies,omitempty"` // The date and time describing the actual or expected starting time of the object. // When used with an Activity object, for instance, the startTime property specifies // the moment the activity began or is scheduled to begin. StartTime time.Time `jsonld:"startTime"` StartTime time.Time `jsonld:"startTime,omitempty"` // A natural language summarization of the object encoded as HTML. // *Multiple language tagged summaries may be provided.) Summary NaturalLanguageValue `jsonld:"summary"` Summary NaturalLanguageValue `jsonld:"summary,omitempty,collapsible"` // One or more "tags" that have been associated with an objects. A tag can be any kind of Object. // The key difference between attachment and tag is that the former implies association by inclusion, // while the latter implies associated by reference. Tag ObjectOrLink `jsonld:"tag"` Tag ObjectOrLink `jsonld:"tag,omitempty"` // The date and time at which the object was updated Updated time.Time `jsonld:"updated"` Updated time.Time `jsonld:"updated,omitempty"` // Identifies one or more links to representations of the object Url LinkOrUri `jsonld:"url"` Url LinkOrUri `jsonld:"url,omitempty"` // Identifies an entity considered to be part of the public primary audience of an Object To ObjectOrLink `jsonld:"to"` To ObjectOrLink `jsonld:"to,omitempty"` // Identifies an Object that is part of the private primary audience of this Object. Bto ObjectOrLink `jsonld:"bto"` Bto ObjectOrLink `jsonld:"bto,omitempty"` // Identifies an Object that is part of the public secondary audience of this Object. Cc ObjectOrLink `jsonld:"cc"` Cc ObjectOrLink `jsonld:"cc,omitempty"` // Identifies one or more Objects that are part of the private secondary audience of this Object. Bcc ObjectOrLink `jsonld:"bcc"` Bcc ObjectOrLink `jsonld:"bcc,omitempty"` // When the object describes a time-bound resource, such as an audio or video, a meeting, etc, // the duration property indicates the object's approximate duration. // The value must be expressed as an xsd:duration as defined by [ xmlschema11-2], // section 3.3.6 (e.g. a period of 5 seconds is represented as "PT5S"). Duration time.Duration `jsonld:"duration"` Duration time.Duration `jsonld:"duration,omitempty"` } type ContentType string
-
@@ -173,8 +187,8 @@ type Source struct {MediaType string } func ValidGenericType(_type string) bool { for _, v := range validGenericTypes { func ValidGenericType(_type ActivityVocabularyType) bool { for _, v := range validGenericObjectTypes { if v == _type { return true }
-
@@ -182,7 +196,7 @@ func ValidGenericType(_type string) bool {return false } func ValidObjectType(_type string) bool { func ValidObjectType(_type ActivityVocabularyType) bool { for _, v := range validObjectTypes { if v == _type { return true
-
@@ -191,7 +205,7 @@ func ValidObjectType(_type string) bool {return ValidActivityType(_type) || ValidActorType(_type) || ValidCollectionType(_type) || ValidGenericType(_type) } func ObjectNew(id ObjectId, _type string) *Object { func ObjectNew(id ObjectId, _type ActivityVocabularyType) *Object { if !(ValidObjectType(_type)) { _type = ObjectType }
-
-
-
@@ -28,7 +28,7 @@ func TestObjectNew(t *testing.T) {} func TestValidGenericType(t *testing.T) { for _, validType := range validGenericTypes { for _, validType := range validGenericObjectTypes { if !ValidObjectType(validType) { t.Errorf("Generic Type '%v' should be valid", validType) }
-
@@ -36,7 +36,7 @@ func TestValidGenericType(t *testing.T) {} func TestValidObjectType(t *testing.T) { var invalidType string = "RandomType" var invalidType ActivityVocabularyType = "RandomType" if ValidObjectType(invalidType) { t.Errorf("Object Type '%v' should not be valid", invalidType)
-
@@ -103,3 +103,25 @@ func TestNaturalLanguageValue_MarshalJSON(t *testing.T) {t.Errorf("Different marshal result '%s', instead of '%s'", out1, txt) } } func TestObject_IsLink(t *testing.T) { o := ObjectNew("test", ObjectType) if o.IsLink() { t.Errorf("%#v should not be a valid link", o.Type) } m := ObjectNew("test", AcceptType) if m.IsLink() { t.Errorf("%#v should not be a valid link", m.Type) } } func TestObject_IsObject(t *testing.T) { o := ObjectNew("test", ObjectType) if !o.IsObject() { t.Errorf("%#v should be a valid object", o.Type) } m := ObjectNew("test", AcceptType) if !m.IsObject() { t.Errorf("%#v should be a valid object", m.Type) } }
-
-
-
@@ -2,14 +2,15 @@ package jsonldimport ( "encoding/json" "activitypub" ) type Ref string type Context struct { URL Ref `json:"_"` Language activitypub.NaturalLanguageValue `json:"@language"` URL Ref `jsonld:"_"` Language activitypub.NaturalLanguageValue `jsonld:"@language,omitempty,collapsible"` } func (c *Context) Ref() Ref {
-
-
-
@@ -27,13 +27,16 @@ func TestCreateActivityHTTPSerialization(t *testing.T) {baseUri := string(activitypub.ActivityBaseURI) c := jsonld.Context{ URL: jsonld.Ref(baseUri + o.Type), URL: jsonld.Ref(baseUri + string(o.Type)), } out, err := jsonld.Marshal(o, &c) //out, err := jsonld.Marshal(o) if err != nil { t.Error(err) } t.Logf("%s", out) outNoC, errNoC := jsonld.Marshal(o, nil) if errNoC != nil { t.Error(errNoC) } t.Logf("%s\n\n%s", out, outNoC) }
-