diff --git a/event/event.go b/event/event.go index 8c79850..74c997d 100644 --- a/event/event.go +++ b/event/event.go @@ -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 diff --git a/event_test.go b/event_test.go index c07fe0e..41c9a59 100644 --- a/event_test.go +++ b/event_test.go @@ -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) { diff --git a/location/location.go b/location/location.go index 6a2ff23..378ac58 100644 --- a/location/location.go +++ b/location/location.go @@ -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 {