Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,28 +107,28 @@ func (e *Event) UnmarshalJSON(data []byte) error {
return err
}

func (e *Body) UnmarshalJSON(data []byte) error {
func (b *Body) UnmarshalJSON(data []byte) error {
type tmp *Body
return unmarshalJSON(tmp(e), data)
return unmarshalJSON(tmp(b), data)
}

func (e *Link) UnmarshalJSON(data []byte) error {
func (l *Link) UnmarshalJSON(data []byte) error {
type tmp *Link
return unmarshalJSON(tmp(e), data)
return unmarshalJSON(tmp(l), data)
}

func (e *User) UnmarshalJSON(data []byte) error {
func (u *User) UnmarshalJSON(data []byte) error {
type tmp *User
return unmarshalJSON(tmp(e), data)
return unmarshalJSON(tmp(u), data)
}

func (e *Image) UnmarshalJSON(data []byte) error {
func (i *Image) UnmarshalJSON(data []byte) error {
if string(data) == "[]" {
return nil
}

type tmp *Image
if err := unmarshalJSON(tmp(e), data); err != nil {
if err := unmarshalJSON(tmp(i), data); err != nil {
return err
}
return nil
Expand Down
6 changes: 5 additions & 1 deletion event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ func TestEvent(t *testing.T) {
if value.Image.File.ReferenceId != "1d978950-9016-4451-84ba-4f7d5817abe2" {
t.Errorf("Expected Image File Id '1d978950-9016-4451-84ba-4f7d5817abe2', got: %s", value.Image.File.ReferenceId)
}

if len(value.Offline) != 1 {
t.Errorf("Expected event to have 1 location")
} else if value.Offline[0].UUID != "0db82018-d5e8-419d-8fe4-ec6f945415b3" {
t.Errorf("Expected Offline UUID '0db82018-d5e8-419d-8fe4-ec6f945415b3', got: %s", value.Offline[0].UUID)
}
}

func TestEventNoImage(t *testing.T) {
Expand Down
21 changes: 15 additions & 6 deletions location/location.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,28 @@ type Map struct {
SchemaOrgShape string `json:"schemaorg_shape"`
}

func (e *Location) UnmarshalJSON(data []byte) error {
func (l *Location) UnmarshalJSON(data []byte) error {
type tmp *Location
return unmarshalJSON(tmp(e), data)
if err := unmarshalJSON(tmp(l), data); err != nil {
return err
}
// There is an inconsistency in the api: when querying events the `UUID` is
// missing from the location and the `Id` field is holding the `UUID` value
// instead.
if len(l.UUID) == 0 {
l.UUID = l.Id
}
return nil
}

func (e *Address) UnmarshalJSON(data []byte) error {
func (a *Address) UnmarshalJSON(data []byte) error {
type tmp *Address
return unmarshalJSON(tmp(e), data)
return unmarshalJSON(tmp(a), data)
}

func (e *Map) UnmarshalJSON(data []byte) error {
func (m *Map) UnmarshalJSON(data []byte) error {
type tmp *Map
return unmarshalJSON(tmp(e), data)
return unmarshalJSON(tmp(m), data)
}

func unmarshalJSON(e interface{}, data []byte) error {
Expand Down