activitypub

package
v0.0.0-...-d47f070 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 7, 2019 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ActivityTypes = map[string]bool{
	"Activity":        true,
	"Accept":          true,
	"Add":             true,
	"Announce":        true,
	"Arrive":          true,
	"Block":           true,
	"Create":          true,
	"Delete":          true,
	"Dislike":         true,
	"Flag":            true,
	"Follow":          true,
	"Ignore":          true,
	"Invite":          true,
	"Join":            true,
	"Leave":           true,
	"Like":            true,
	"Listen":          true,
	"Move":            true,
	"Offer":           true,
	"Question":        true,
	"Reject":          true,
	"Read":            true,
	"Remove":          true,
	"TentativeReject": true,
	"TentativeAccept": true,
	"Travel":          true,
	"Undo":            true,
	"Update":          true,
	"View":            true,
}
View Source
var ActorTypes = map[string]bool{
	"Actor":        true,
	"Application":  true,
	"Group":        true,
	"Organization": true,
	"Person":       true,
	"Service":      true,
}
View Source
var BuiltInFields = map[string]string{
	"@id":          "@id",
	"id":           "@id",
	"@type":        "@type",
	"type":         "@type",
	"actor":        "www.w3.org/ns/activitystreams#actor",
	"attachment":   "www.w3.org/ns/activitystreams#attachment",
	"attributedTo": "www.w3.org/ns/activitystreams#attributedTo",
	"audience":     "www.w3.org/ns/activitystreams#audience",
	"bcc":          "www.w3.org/ns/activitystreams#bcc",
	"bto":          "www.w3.org/ns/activitystreams#bto",
	"cc":           "www.w3.org/ns/activitystreams#cc",
	"context":      "www.w3.org/ns/activitystreams#context",
	"current":      "www.w3.org/ns/activitystreams#current",
	"first":        "www.w3.org/ns/activitystreams#first",
	"generator":    "www.w3.org/ns/activitystreams#generator",
	"icon":         "www.w3.org/ns/activitystreams#icon",
	"image":        "www.w3.org/ns/activitystreams#image",
	"inReplyTo":    "www.w3.org/ns/activitystreams#inReplyTo",
	"instrument":   "www.w3.org/ns/activitystreams#instrument",
	"last":         "www.w3.org/ns/activitystreams#last",
	"location":     "www.w3.org/ns/activitystreams#location",
	"items":        "www.w3.org/ns/activitystreams#items",
	"oneOf":        "www.w3.org/ns/activitystreams#oneOf",
	"anyOf":        "www.w3.org/ns/activitystreams#anyOf",
	"closed":       "www.w3.org/ns/activitystreams#closed",
	"origin":       "www.w3.org/ns/activitystreams#origin",
	"next":         "www.w3.org/ns/activitystreams#next",
	"object":       "www.w3.org/ns/activitystreams#object",
	"prev":         "www.w3.org/ns/activitystreams#prev",
	"preview":      "www.w3.org/ns/activitystreams#preview",
	"result":       "www.w3.org/ns/activitystreams#result",
	"replies":      "www.w3.org/ns/activitystreams#replies",
	"tag":          "www.w3.org/ns/activitystreams#tag",
	"target":       "www.w3.org/ns/activitystreams#target",
	"to":           "www.w3.org/ns/activitystreams#to",
	"url":          "www.w3.org/ns/activitystreams#url",
	"accuracy":     "www.w3.org/ns/activitystreams#accuracy",
	"altitude":     "www.w3.org/ns/activitystreams#altitude",
	"content":      "www.w3.org/ns/activitystreams#content",
	"name":         "www.w3.org/ns/activitystreams#name",
	"duration":     "www.w3.org/ns/activitystreams#duration",
	"height":       "www.w3.org/ns/activitystreams#height",
	"href":         "www.w3.org/ns/activitystreams#href",
	"hreflang":     "www.w3.org/ns/activitystreams#hreflang",
	"partOf":       "www.w3.org/ns/activitystreams#partOf",
	"latitude":     "www.w3.org/ns/activitystreams#latitude",
	"longitude":    "www.w3.org/ns/activitystreams#longitude",
	"mediaType":    "www.w3.org/ns/activitystreams#mediaType",
	"endTime":      "www.w3.org/ns/activitystreams#endTime",
	"published":    "www.w3.org/ns/activitystreams#published",
	"startTime":    "www.w3.org/ns/activitystreams#startTime",
	"radius":       "www.w3.org/ns/activitystreams#radius",
	"rel":          "www.w3.org/ns/activitystreams#rel",
	"startIndex":   "www.w3.org/ns/activitystreams#startIndex",
	"summary":      "www.w3.org/ns/activitystreams#summary",
	"totalItems":   "www.w3.org/ns/activitystreams#totalItems",
	"units":        "www.w3.org/ns/activitystreams#units",
	"updated":      "www.w3.org/ns/activitystreams#updated",
	"width":        "www.w3.org/ns/activitystreams#width",
	"subject":      "www.w3.org/ns/activitystreams#subject",
	"relationship": "www.w3.org/ns/activitystreams#relationship",
	"describes":    "www.w3.org/ns/activitystreams#describes",
	"formerType":   "www.w3.org/ns/activitystreams#formerType",
	"deleted":      "www.w3.org/ns/activitystreams#deleted",
}

Maps the built-in field terms to their IRIs

View Source
var BuiltInObjectTypes = map[string]string{
	"Object":                "www.w3.org/ns/activitystreams#Object",
	"Link":                  "www.w3.org/ns/activitystreams#Link",
	"Activity":              "www.w3.org/ns/activitystreams#Activity",
	"IntransitiveActivity":  "www.w3.org/ns/activitystreams#IntransitiveActivity",
	"Collection":            "www.w3.org/ns/activitystreams#Collection",
	"OrderedCollection":     "www.w3.org/ns/activitystreams#OrderedCollection",
	"CollectionPage":        "www.w3.org/ns/activitystreams#CollectionPage",
	"OrderedCollectionPage": "www.w3.org/ns/activitystreams#OrderedCollectionPage",
	"Accept":                "www.w3.org/ns/activitystreams#Accept",
	"TentativeAccept":       "www.w3.org/ns/activitystreams#TentativeAccept",
	"Add":                   "www.w3.org/ns/activitystreams#Add",
	"Arrive":                "www.w3.org/ns/activitystreams#Arrive",
	"Create":                "www.w3.org/ns/activitystreams#Create",
	"Delete":                "www.w3.org/ns/activitystreams#Delete",
	"Follow":                "www.w3.org/ns/activitystreams#Follow",
	"Ignore":                "www.w3.org/ns/activitystreams#Ignore",
	"Join":                  "www.w3.org/ns/activitystreams#Join",
	"Leave":                 "www.w3.org/ns/activitystreams#Leave",
	"Like":                  "www.w3.org/ns/activitystreams#Like",
	"Offer":                 "www.w3.org/ns/activitystreams#Offer",
	"Invite":                "www.w3.org/ns/activitystreams#Invite",
	"Reject":                "www.w3.org/ns/activitystreams#Reject",
	"TentativeReject":       "www.w3.org/ns/activitystreams#TentativeReject",
	"Remove":                "www.w3.org/ns/activitystreams#Remove",
	"Undo":                  "www.w3.org/ns/activitystreams#Undo",
	"Update":                "www.w3.org/ns/activitystreams#Update",
	"View":                  "www.w3.org/ns/activitystreams#View",
	"Listen":                "www.w3.org/ns/activitystreams#Listen",
	"Read":                  "www.w3.org/ns/activitystreams#Read",
	"Move":                  "www.w3.org/ns/activitystreams#Move",
	"Travel":                "www.w3.org/ns/activitystreams#Travel",
	"Announce":              "www.w3.org/ns/activitystreams#Announce",
	"Block":                 "www.w3.org/ns/activitystreams#Block",
	"Flag":                  "www.w3.org/ns/activitystreams#Flag",
	"Dislike":               "www.w3.org/ns/activitystreams#Dislike",
	"Question":              "www.w3.org/ns/activitystreams#Question",
	"Application":           "www.w3.org/ns/activitystreams#Application",
	"Group":                 "www.w3.org/ns/activitystreams#Group",
	"Organization":          "www.w3.org/ns/activitystreams#Organization",
	"Person":                "www.w3.org/ns/activitystreams#Person",
	"Service":               "www.w3.org/ns/activitystreams#Service",
	"Relationship":          "www.w3.org/ns/activitystreams#Relationship",
	"Article":               "www.w3.org/ns/activitystreams#Article",
	"Document":              "www.w3.org/ns/activitystreams#Document",
	"Audio":                 "www.w3.org/ns/activitystreams#Audio",
	"Image":                 "www.w3.org/ns/activitystreams#Image",
	"Video":                 "www.w3.org/ns/activitystreams#Video",
	"Note":                  "www.w3.org/ns/activitystreams#Note",
	"Page":                  "www.w3.org/ns/activitystreams#Page",
	"Event":                 "www.w3.org/ns/activitystreams#Event",
	"Place":                 "www.w3.org/ns/activitystreams#Place",
	"Mention":               "www.w3.org/ns/activitystreams#Mention",
	"Profile":               "www.w3.org/ns/activitystreams#Profile",
	"Tombstone":             "www.w3.org/ns/activitystreams#Tombstone",
}

Maps the built-in type terms to their IRIs

View Source
var BuiltinFieldTypes = map[string]TypeNode{
	"@id":                                 TypeNode{false, []string{"iri"}},
	"@type":                               TypeNode{true, []string{"iri"}},
	"www.w3.org/ns/activitystreams#actor": TypeNode{true, []string{"iri/obj"}},
	"www.w3.org/ns/activitystreams#attachment": TypeNode{true,
		[]string{"iri/obj"}},
	"www.w3.org/ns/activitystreams#attributedTo": TypeNode{true,
		[]string{"iri/obj"}},
	"www.w3.org/ns/activitystreams#audience": TypeNode{true,
		[]string{"iri/obj"}},
	"www.w3.org/ns/activitystreams#bcc": TypeNode{true, []string{"iri/obj"}},
	"www.w3.org/ns/activitystreams#bto": TypeNode{true, []string{"iri/obj"}},
	"www.w3.org/ns/activitystreams#cc":  TypeNode{true, []string{"iri/obj"}},
	"www.w3.org/ns/activitystreams#context": TypeNode{true,
		[]string{"iri/obj"}},
	"www.w3.org/ns/activitystreams#current": TypeNode{false,
		[]string{"iri/obj"}},
	"www.w3.org/ns/activitystreams#first": TypeNode{false, []string{"iri/obj"}},
	"www.w3.org/ns/activitystreams#generator": TypeNode{true,
		[]string{"iri/obj"}},
	"www.w3.org/ns/activitystreams#icon":  TypeNode{true, []string{"iri/obj"}},
	"www.w3.org/ns/activitystreams#image": TypeNode{true, []string{"iri/obj"}},
	"www.w3.org/ns/activitystreams#inReplyTo": TypeNode{true,
		[]string{"iri/obj"}},
	"www.w3.org/ns/activitystreams#instrument": TypeNode{true,
		[]string{"iri/obj"}},
	"www.w3.org/ns/activitystreams#last": TypeNode{false, []string{"iri/obj"}},
	"www.w3.org/ns/activitystreams#location": TypeNode{true,
		[]string{"iri/obj"}},
	"www.w3.org/ns/activitystreams#items": TypeNode{true, []string{"iri/obj"}},
	"www.w3.org/ns/activitystreams#oneOf": TypeNode{true, []string{"iri/obj"}},
	"www.w3.org/ns/activitystreams#anyOf": TypeNode{true, []string{"iri/obj"}},
	"www.w3.org/ns/activitystreams#closed": TypeNode{false,
		[]string{"bool", "datetime", "iri/obj"}},
	"www.w3.org/ns/activitystreams#origin": TypeNode{true, []string{"iri/obj"}},
	"www.w3.org/ns/activitystreams#next":   TypeNode{false, []string{"iri/obj"}},
	"www.w3.org/ns/activitystreams#object": TypeNode{true, []string{"iri/obj"}},
	"www.w3.org/ns/activitystreams#prev":   TypeNode{false, []string{"iri/obj"}},
	"www.w3.org/ns/activitystreams#preview": TypeNode{true,
		[]string{"iri/obj"}},
	"www.w3.org/ns/activitystreams#result": TypeNode{true, []string{"iri/obj"}},
	"www.w3.org/ns/activitystreams#replies": TypeNode{false,
		[]string{"iri/obj"}},
	"www.w3.org/ns/activitystreams#tag":    TypeNode{true, []string{"iri/obj"}},
	"www.w3.org/ns/activitystreams#target": TypeNode{true, []string{"iri/obj"}},
	"www.w3.org/ns/activitystreams#to":     TypeNode{true, []string{"iri/obj"}},
	"www.w3.org/ns/activitystreams#url":    TypeNode{true, []string{"iri/obj"}},
	"www.w3.org/ns/activitystreams#accuracy": TypeNode{false,
		[]string{"float"}},
	"www.w3.org/ns/activitystreams#altitude": TypeNode{false,
		[]string{"float"}},
	"www.w3.org/ns/activitystreams#content": TypeNode{false,
		[]string{"string", "langMap"}},
	"www.w3.org/ns/activitystreams#contentMap": TypeNode{false,
		[]string{"langMap", "string"}},
	"www.w3.org/ns/activitystreams#name": TypeNode{false,
		[]string{"string", "langMap"}},
	"www.w3.org/ns/activitystreams#nameMap": TypeNode{false,
		[]string{"langMap", "string"}},
	"www.w3.org/ns/activitystreams#duration": TypeNode{false,
		[]string{"duration"}},
	"www.w3.org/ns/activitystreams#height": TypeNode{false, []string{"uint"}},
	"www.w3.org/ns/activitystreams#href":   TypeNode{false, []string{"iri/obj"}},
	"www.w3.org/ns/activitystreams#hreflang": TypeNode{false,
		[]string{"string"}},
	"www.w3.org/ns/activitystreams#partOf": TypeNode{false,
		[]string{"iri/obj"}},
	"www.w3.org/ns/activitystreams#latitude": TypeNode{false,
		[]string{"float"}},
	"www.w3.org/ns/activitystreams#longitude": TypeNode{false,
		[]string{"float"}},
	"www.w3.org/ns/activitystreams#mediaType": TypeNode{false,
		[]string{"string"}},
	"www.w3.org/ns/activitystreams#endTime": TypeNode{false,
		[]string{"datetime"}},
	"www.w3.org/ns/activitystreams#published": TypeNode{false,
		[]string{"datetime"}},
	"www.w3.org/ns/activitystreams#startTime": TypeNode{false,
		[]string{"datetime"}},
	"www.w3.org/ns/activitystreams#radius": TypeNode{false, []string{"float"}},
	"www.w3.org/ns/activitystreams#rel":    TypeNode{true, []string{"string"}},
	"www.w3.org/ns/activitystreams#startIndex": TypeNode{false,
		[]string{"uint"}},
	"www.w3.org/ns/activitystreams#summary": TypeNode{false,
		[]string{"string", "langMap"}},
	"www.w3.org/ns/activitystreams#summaryMap": TypeNode{false,
		[]string{"langMap", "string"}},
	"www.w3.org/ns/activitystreams#totalItems": TypeNode{false,
		[]string{"uint"}},
	"www.w3.org/ns/activitystreams#units": TypeNode{false,
		[]string{"iri", "string"}},
	"www.w3.org/ns/activitystreams#updated": TypeNode{false,
		[]string{"datetime"}},
	"www.w3.org/ns/activitystreams#width": TypeNode{false, []string{"width"}},
	"www.w3.org/ns/activitystreams#subject": TypeNode{false,
		[]string{"subject"}},
	"www.w3.org/ns/activitystreams#relationship": TypeNode{true,
		[]string{"iri/obj"}},
	"www.w3.org/ns/activitystreams#describes": TypeNode{false,
		[]string{"iri/obj"}},
	"www.w3.org/ns/activitystreams#formerType": TypeNode{true,
		[]string{"iri/obj"}},
	"www.w3.org/ns/activitystreams#deleted": TypeNode{false,
		[]string{"datetime"}},
}

Maps built in field IRIs to their type descriptor

View Source
var CollectionTypes = map[string]bool{
	"Collection":        true,
	"OrderedCollection": true,
	"Availability":      true,
}
View Source
var ExtensionFieldTypes = map[string]TypeNode{}

Maps field IRIs to their type descriptor

View Source
var Logging bool
View Source
var TypeValidators = map[string]func(value interface{}) (valid bool){
	"float":    validateFloat,
	"datetime": validateDatetime,
	"duration": validateDuration,
	"iri":      validateIRI,
	"string":   validateString,
	"bool":     validateBool,
	"iri/obj":  validateIRIObject,
	"obj":      validateSubObject,
	"complex":  validateComplexData,
	"int":      validateInt,
	"uint":     validateUInt,
}

Functions

func ClipIRI

func ClipIRI(iri string) (clippedIRI string)

func ExpandTerm

func ExpandTerm(term string) (implemented bool, IRI string)

func FieldType

func FieldType(candidate string) (iri bool, compact bool, term bool)

func Objectify

func Objectify(data map[string]interface{}) (obj *Object, report *ValidationReport)

func ValidateContext

func ValidateContext(data interface{}, report *ValidationReport) (aliases map[string]string)

func ValidateField

func ValidateField(name string, value interface{}, aliases map[string]string) (validName bool, implementedName bool, validType bool)

func ValidateType

func ValidateType(data interface{}, aliases map[string]string) (valid bool)

func ValidateValue

func ValidateValue(value interface{}, typeDescriptor *TypeNode) (validType bool)

Types

type Object

type Object struct {
	Id string // Set to @id if it exists, embed ID otherwise
	// Object data
	Data map[string]interface{}
	// Other data, *not* JSONified
	Shadow string // The remote object this is a cache of
}

strings are single-value, []strings are multi-value map[string]strings are language maps

func DecodeJSON

func DecodeJSON(data []byte) (obj *Object, err error)

func NewObject

func NewObject() (obj *Object)

func (*Object) GetField

func (o *Object) GetField(fieldName string) (value interface{})

func (*Object) GetFieldAsString

func (o *Object) GetFieldAsString(fieldName string) (value string, otherValue bool)

func (*Object) GetFieldAsStringList

func (o *Object) GetFieldAsStringList(fieldName string) (value []string, otherValue bool)

func (*Object) GetID

func (o *Object) GetID() (objID string)

func (*Object) IsActivity

func (o *Object) IsActivity() bool

func (*Object) IsActor

func (o *Object) IsActor() bool

func (*Object) IsCollection

func (o *Object) IsCollection() bool

func (*Object) Mapify

func (o *Object) Mapify() (mapped map[string]interface{})

func (*Object) SetField

func (o *Object) SetField(fieldName string, value interface{})

func (*Object) SetID

func (o *Object) SetID(objID string)

type TypeNode

type TypeNode struct {
	Multi bool // Can this field be a list?
	Types []string
}

func BuiltinType

func BuiltinType(IRI string) (typeDescriptor *TypeNode)

func ExpandCompact

func ExpandCompact(compact string, aliases map[string]string) (implemented bool, IRI string, typeDescriptor *TypeNode)

func ValidateFieldName

func ValidateFieldName(field string, aliases map[string]string) (implemented bool, valid bool, internalName string, typeDescriptor *TypeNode)

type ValidationReport

type ValidationReport struct {
	MissingContext      bool   // No @context field
	InvalidContext      bool   // @context field invalid type
	MissingVocab        bool   // No vocabulary reference found
	ImproperVocab       bool   // ActivityPub vocabulary not used
	DefaultLanguage     string // Contents of the @language field
	NoType              bool   // No type field detected
	TypeAlias           bool   // Using "type" instead of "@type"
	ContainsInvalidType bool
	NoId                bool // No id field detected
	IdAlias             bool // Using "id" instead of "@id"
	InvalidFieldNames   []string
	UnknownFieldNames   []string // Unaliased fields that are not recognized
	BadFieldTypes       []string // Known fields with invalid datatypes
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL