Remove URI type in favour of IRI

This commit is contained in:
Marius Orcsik 2018-10-11 20:13:34 +02:00
parent 56627df017
commit f21b60ad61
No known key found for this signature in database
GPG key ID: 889CE8E4FB2D877A
7 changed files with 28 additions and 90 deletions

View file

@ -371,8 +371,8 @@ func (p Person) GetType() ActivityVocabularyType {
}
// Link returns the URI for the current Person object
func (p Person) GetLink() URI {
return p.URL.(URI)
func (p Person) GetLink() IRI {
return p.URL.(IRI)
}
// UnmarshalJSON

View file

@ -32,7 +32,7 @@ type Link struct {
// Identifies an entity that provides a preview of this object.
Preview Item `jsonld:"preview,omitempty"`
// The target resource pointed to by a Link.
Href URI `jsonld:"href,omitempty"`
Href IRI `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,omitempty"`

View file

@ -26,7 +26,7 @@ type ObjectID IRI
const (
// ActivityBaseURI the basic URI for the activity streams namespaces
ActivityBaseURI = URI("https://www.w3.org/ns/activitystreams")
ActivityBaseURI = IRI("https://www.w3.org/ns/activitystreams")
ObjectType ActivityVocabularyType = "Object"
LinkType ActivityVocabularyType = "Link"
ActivityType ActivityVocabularyType = "Activity"
@ -106,11 +106,11 @@ type (
// LinkOrURI is an interface that Object and Link structs implement, and at the same time
// they are kept disjointed
LinkOrURI interface {
GetLink() URI
GetLink() IRI
}
// ImageOrLink is an interface that Image and Link structs implement
ImageOrLink interface {
Item
ObjectOrLink
LinkOrURI
}
// MimeType is the type for MIME types
@ -379,6 +379,11 @@ func (o Object) GetID() *ObjectID {
return &o.ID
}
// GetID returns the ObjectID corresponding to the current object
func (o Object) GetLink() IRI {
return IRI(o.ID)
}
// Link returns the Link corresponding to the current object
func (o Object) GetType() ActivityVocabularyType {
return o.Type

View file

@ -199,7 +199,7 @@ func getAPItems(data []byte, prop string) ItemCollection {
}, prop)
case jsonparser.String:
s, _ := jsonparser.GetString(val)
it.Append(URI(s))
it.Append(IRI(s))
}
return it
}
@ -237,12 +237,12 @@ func getAPItemCollection(data []byte, prop string) ItemCollection {
return it
}
func getURIField(data []byte, prop string) URI {
func getURIField(data []byte, prop string) IRI {
val, err := jsonparser.GetString(data, prop)
if err != nil {
return URI("")
return IRI("")
}
return URI(val)
return IRI(val)
}
func getAPLangRefField(data []byte, prop string) LangRef {

View file

@ -6,36 +6,17 @@ import (
type (
// IRI is a Internationalized Resource Identifiers (IRIs) RFC3987
IRI URI
// URI is a Uniform Resource Identifier (URI) RFC3986
URI string
IRI string
)
// String returns the String value of the URI object
func (u URI) String() string {
return string(u)
}
// String returns the String value of the IRI object
func (i IRI) String() string {
return string(i)
}
// GetLink returns a copy of itself
func (u URI) GetLink() URI {
return u
}
// GetLink returns a URI type coercion of the IRI object
func (i IRI) GetLink() URI {
return URI(i)
}
// UnmarshalJSON
func (u *URI) UnmarshalJSON(s []byte) error {
*u = URI(strings.Trim(string(s), "\""))
return nil
// GetLink
func (i IRI) GetLink() IRI {
return i
}
// UnmarshalJSON
@ -44,53 +25,21 @@ func (i *IRI) UnmarshalJSON(s []byte) error {
return nil
}
// UnmarshalText
func (u URI) UnmarshalText(s []byte) error {
u = URI(strings.Trim(string(s), "\""))
return nil
}
// UnmarshalText
func (i IRI) UnmarshalText(s []byte) error {
i = IRI(strings.Trim(string(s), "\""))
return nil
}
// IsObject
func (u URI) GetID() *ObjectID {
return nil
}
// IsObject
func (i IRI) GetID() *ObjectID {
return nil
}
// GetType
func (u URI) GetType() ActivityVocabularyType {
return LinkType
}
// GetType
func (i IRI) GetType() ActivityVocabularyType {
return LinkType
}
// IsLink
func (u URI) IsLink() bool {
return true
}
// IsLink
func (i IRI) IsLink() bool {
return true
}
// IsObject
func (u URI) IsObject() bool {
return false
}
// IsObject
func (i IRI) IsObject() bool {
return false

View file

@ -2,27 +2,11 @@ package activitystreams
import "testing"
func TestURI_GetLink(t *testing.T) {
val := "http://example.com"
u := URI(val)
if u.GetLink() != URI(val) {
t.Errorf("URI %q should equal %q", u, val)
}
}
func TestURI_String(t *testing.T) {
val := "http://example.com"
u := URI(val)
if u.String() != val {
t.Errorf("URI %q should equal %q", u, val)
}
}
func TestIRI_GetLink(t *testing.T) {
val := "http://example.com"
u := IRI(val)
if u.GetLink() != URI(val) {
t.Errorf("URI %q should equal %q", u, val)
if u.GetLink() != IRI(val) {
t.Errorf("IRI %q should equal %q", u, val)
}
}
@ -30,6 +14,6 @@ func TestIRI_String(t *testing.T) {
val := "http://example.com"
u := IRI(val)
if u.String() != val {
t.Errorf("URI %q should equal %q", u, val)
t.Errorf("IRI %q should equal %q", u, val)
}
}

View file

@ -198,7 +198,7 @@ var allTests = tests{
blank: &a.Link{},
result: &a.Link{
Type: a.LinkType,
Href: a.URI("http://example.org/abc"),
Href: a.IRI("http://example.org/abc"),
HrefLang: a.LangRef("en"),
MediaType: a.MimeType("text/html"),
Name: a.NaturalLanguageValue{{
@ -210,7 +210,7 @@ var allTests = tests{
expected: true,
blank: &a.Object{},
result: &a.Object{
URL: a.URI("http://littr.git/api/accounts/system"),
URL: a.IRI("http://littr.git/api/accounts/system"),
},
},
"object_simple": testPair{
@ -268,11 +268,11 @@ var allTests = tests{
Type: a.PersonType,
Name: a.NaturalLanguageValue{{a.NilLangRef, "ana"}},
PreferredUsername: a.NaturalLanguageValue{{a.NilLangRef, "Ana"}},
URL: a.URI("http://example.com/accounts/ana"),
URL: a.IRI("http://example.com/accounts/ana"),
Outbox: &a.OrderedCollection{
ID: a.ObjectID("http://example.com/accounts/ana/outbox"),
Type: a.OrderedCollectionType,
URL: a.URI("http://example.com/outbox"),
URL: a.IRI("http://example.com/outbox"),
},
},
},
@ -282,7 +282,7 @@ var allTests = tests{
result: &a.OrderedCollection{
ID: a.ObjectID("http://example.com/outbox"),
Type: a.OrderedCollectionType,
URL: a.URI("http://example.com/outbox"),
URL: a.IRI("http://example.com/outbox"),
TotalItems: 1,
OrderedItems: a.ItemCollection{
&a.Object{
@ -290,7 +290,7 @@ var allTests = tests{
Type: a.ArticleType,
Name: a.NaturalLanguageValue{{a.NilLangRef, "Example title"}},
Content: a.NaturalLanguageValue{{a.NilLangRef, "Example content!"}},
URL: a.URI("http://example.com/53c6fb47"),
URL: a.IRI("http://example.com/53c6fb47"),
MediaType: a.MimeType("text/markdown"),
Published: time.Date(2018, time.July, 5, 16, 46, 44, 0, zLoc),
Generator: a.IRI("http://example.com"),