Changes
15 changed files (+509/-0)
-
actors.go (new)
-
@@ -0,0 +1,77 @@package activitypub type ActorCollection = []Actor type Actor struct { BaseObject Inbox InboxStream Outbox OutboxStream Following FollowingCollection Followers FollowersCollection Liked LikedCollection PreferredUsername NaturalLanguageValue Url Url Summary NaturalLanguageValue Icon Url /*/ streams preferredUsername endpoints { uploadMedia oauthAuthorizationEndpoint oauthTokenEndpoint provideClientKey signClientKey sharedInbox } /**/ } var validActorTypes = [...]string{ ApplicationType, GroupType, OrganizationType, PersonType, ServiceType, } func ValidActorType(_type string) bool { for _, v := range validActorTypes { if v == _type { return true } } return false } func ActorNew(id ObjectId, _type string) Actor { if !ValidActorType(_type) { _type = ActorType } o := BaseObject{Id: id, Type: _type} return Actor{BaseObject: o} } func ApplicationNew(id ObjectId) Actor { return ActorNew(id, ApplicationType) } func GroupNew(id ObjectId) Actor { return ActorNew(id, GroupType) } func OrganizationNew(id ObjectId) Actor { return ActorNew(id, OrganizationType) } func PersonNew(id ObjectId) Actor { return ActorNew(id, PersonType) } func ServiceNew(id ObjectId) Actor { return ActorNew(id, ServiceType) }
-
-
actors_test.go (new)
-
@@ -0,0 +1,87 @@package activitypub import ( "testing" ) func TestActorNew(t *testing.T) { var testValue = ObjectId("test") var testType = ApplicationType o := ActorNew(testValue, testType) if o.Id != testValue { t.Errorf("Object Id '%v' different than expected '%v'", o.Id, testValue) } if o.Type != testType { t.Errorf("Object Type '%v' different than expected '%v'", o.Type, testType) } n := ActorNew(testValue, "") if n.Id != testValue { t.Errorf("Object Id '%v' different than expected '%v'", n.Id, testValue) } if n.Type != ActorType { t.Errorf("Object Type '%v' different than expected '%v'", n.Type, ActorType) } } func TestPersonNew(t *testing.T) { var testValue= ObjectId("test") o := PersonNew(testValue) if o.Id != testValue { t.Errorf("Object Id '%v' different than expected '%v'", o.Id, testValue) } if o.Type != PersonType { t.Errorf("Object Type '%v' different than expected '%v'", o.Type, PersonType) } } func TestApplicationNew(t *testing.T) { var testValue= ObjectId("test") o := ApplicationNew(testValue) if o.Id != testValue { t.Errorf("Object Id '%v' different than expected '%v'", o.Id, testValue) } if o.Type != ApplicationType { t.Errorf("Object Type '%v' different than expected '%v'", o.Type, ApplicationType) } } func TestGroupNew(t *testing.T) { var testValue= ObjectId("test") o := GroupNew(testValue) if o.Id != testValue { t.Errorf("Object Id '%v' different than expected '%v'", o.Id, testValue) } if o.Type != GroupType { t.Errorf("Object Type '%v' different than expected '%v'", o.Type, GroupType) } } func TestOrganizationNew(t *testing.T) { var testValue= ObjectId("test") o := OrganizationNew(testValue) if o.Id != testValue { t.Errorf("Object Id '%v' different than expected '%v'", o.Id, testValue) } if o.Type != OrganizationType { t.Errorf("Object Type '%v' different than expected '%v'", o.Type, OrganizationType) } } func TestServiceNew(t *testing.T) { var testValue= ObjectId("test") o := ServiceNew(testValue) if o.Id != testValue { t.Errorf("Object Id '%v' different than expected '%v'", o.Id, testValue) } if o.Type != ServiceType { t.Errorf("Object Type '%v' different than expected '%v'", o.Type, ServiceType) } }
-
-
collections.go (new)
-
@@ -0,0 +1,47 @@package activitypub type Collection struct { *BaseObject Summary string TotalItems int Items ItemCollection Current Page First Page Last Page Next Page Prev Page } type OrderedCollection struct { *BaseObject *CollectionPage Summary string TotalItems int OrderedItems ItemCollection } type Page Url type CollectionPage struct { Current Page First Page Last Page Next Page Prev Page } // // //func Test() { // o := &BaseObject{ // Id: "test", // } // p := &CollectionPage{Current: "http://localhost"} // t := &OrderedCollection{ // BaseObject: o, // CollectionPage: p, // Summary: "tes", // } // // fmt.Print(t) //}
-
-
create_activity.go (new)
-
@@ -0,0 +1,10 @@package activitypub import "time" type CreateActivity struct { ActivityObject Published time.Time To Actor CC Actor }
-
-
followers.go (new)
-
@@ -0,0 +1,5 @@package activitypub type FollowersCollection Followers type Followers Collection
-
-
following.go (new)
-
@@ -0,0 +1,5 @@package activitypub type FollowingCollection Following type Following Collection
-
-
inbox.go (new)
-
@@ -0,0 +1,5 @@package activitypub type InboxStream Inbox type Inbox OrderedCollection
-
-
item.go (new)
-
@@ -0,0 +1,6 @@package activitypub type ItemCollection []Item type Item struct { }
-
-
liked.go (new)
-
@@ -0,0 +1,5 @@package activitypub type LikedCollection Liked type Liked OrderedCollection
-
-
likes.go (new)
-
@@ -0,0 +1,5 @@package activitypub type LikesCollection Likes type Likes OrderedCollection
-
-
object.go (new)
-
@@ -0,0 +1,188 @@package activitypub type ObjectId string const ( ObjectType string = "Object" LinkType string = "Link" ActivityType string = "Activity" ActorType string = "Actor" // 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" // Link Types MentionType string = "Mention" // 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" // Actor Types ApplicationType string = "Application" GroupType string = "Group" OrganizationType string = "Organization" PersonType string = "Person" ServiceType string = "Service" ) var validObjectTypes = [...]string{ ArticleType, AudioType, DocumentType, EventType, ImageType, NoteType, PageType, PlaceType, ProfileType, RelationshipType, TombstoneType, VideoType, } var validLinkTypes = [...]string{ MentionType, } var validActivityTypes = [...]string{ AcceptType, AddType, AnnounceType, ArriveType, BlockType, CreateType, DeleteType, DislikeType, FlagType, FollowType, IgnoreType, InviteType, JoinType, LeaveType, LikeType, ListenType, MoveType, OfferType, QuestionType, RejectType, ReadType, RemoveType, TentativeRejectType, TentativeAcceptType, TravelType, UndoType, UpdateType, ViewType, // Actor Types } type NaturalLanguageValue map[string]string type BaseObject struct { Id ObjectId Type string Name NaturalLanguageValue Href string HrefLang string MediaType string } type ContentType string type Source struct { Content ContentType MediaType string } type ActivityObject struct { BaseObject Actor Actor Object BaseObject Source Source } func ValidObjectType(_type string) bool { for _, v := range validObjectTypes { if v == _type { return true } } return false } func ValidLinkType(_type string) bool { for _, v := range validLinkTypes { if v == _type { return true } } return false } func ValidActivityType(_type string) bool { for _, v := range validActivityTypes { if v == _type { return true } } return false } func ObjectNew(id ObjectId, _type string) BaseObject { if !ValidObjectType(_type) { _type = ObjectType } return BaseObject{Id: id, Type: _type} } func LinkNew(id ObjectId, _type string) BaseObject { if !ValidLinkType(_type) { _type = LinkType } return BaseObject{Id: id, Type:_type} } func ActivityNew(id ObjectId, _type string) ActivityObject { if !ValidActivityType(_type) { _type = ActivityType } o := BaseObject{Id: id, Type: _type} return ActivityObject{BaseObject: o} }
-
-
objects_test.go (new)
-
@@ -0,0 +1,56 @@package activitypub import ( "testing" ) func TestObjectNew(t *testing.T) { var testValue = ObjectId("test") var testType = ArticleType o := ObjectNew(testValue, testType) if o.Id != testValue { t.Errorf("Object Id '%v' different than expected '%v'", o.Id, testValue) } if o.Type != testType { t.Errorf("Object Type '%v' different than expected '%v'", o.Type, testType) } n := ObjectNew(testValue, "") if n.Id != testValue { t.Errorf("Object Id '%v' different than expected '%v'", n.Id, testValue) } if n.Type != ObjectType { t.Errorf("Object Type '%v' different than expected '%v'", n.Type, ObjectType) } } func TestLinkNew(t *testing.T) { var testValue = ObjectId("test") var testType string l := LinkNew(testValue, testType) if l.Id != testValue { t.Errorf("Object Id '%v' different than expected '%v'", l.Id, testValue) } if l.Type != LinkType { t.Errorf("Object Type '%v' different than expected '%v'", l.Type, LinkType) } } func TestActivityNew(t *testing.T) { var testValue = ObjectId("test") var testType string = "Accept" a := ActivityNew(testValue, testType) if a.Id != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", a.Id, testValue) } if a.Type != testType { t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, testType) } }
-
-
outbox.go (new)
-
@@ -0,0 +1,5 @@package activitypub type OutboxStream Outbox type Outbox OrderedCollection
-
-
shares.go (new)
-
@@ -0,0 +1,5 @@package activitypub type SharesCollection Shares type Shares OrderedCollection
-
-
url.go (new)
-
@@ -0,0 +1,3 @@package activitypub type Url string
-