-
Notifications
You must be signed in to change notification settings - Fork 1
/
location.go
119 lines (106 loc) · 3.55 KB
/
location.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package gcloudcx
import (
"encoding/json"
"net/url"
"github.com/gildas/go-core"
"github.com/gildas/go-errors"
)
// LocationDefinition describes a location (office, etc)
type LocationDefinition struct {
ID string `json:"id"`
SelfURI URI `json:"selfUri"`
Name string `json:"name"`
ContactUser *AddressableEntityRef `json:"contactUser"`
EmergencyNumber *LocationEmergencyNumber `json:"emergencyNumber"`
Address *LocationAddress `json:"address"`
AddressVerified bool `json:"addressVerified"`
State string `json:"state"`
Notes string `json:"notes"`
Path []string `json:"path"`
ProfileImage []*LocationImage `json:"profileImage"`
FloorplanImage []*LocationImage `json:"flooreImage"`
Version int `json:"version"`
}
// LocationEmergencyNumber describes a Location's Emergency Number
type LocationEmergencyNumber struct {
Type string `json:"type"` // default, elin
Number string `json:"number"`
E164 string `json:"e164"`
}
// LocationAddress describes the address of a Location
type LocationAddress struct {
Country string `json:"country"`
CountryName string `json:"countryName"`
State string `json:"State"`
City string `json:"City"`
ZipCode string `json:"zipcode"`
Street1 string `json:"street1"`
Street2 string `json:"street2"`
}
// LocationImage describes the image of a Location
type LocationImage struct {
ImageURL *url.URL `json:"-"`
Resolution string `json:"resolution"`
}
// GeoLocation describes a location with coordinates
type GeoLocation struct {
ID string `json:"id"`
SelfURI URI `json:"selfUri"`
Name string `json:"name"`
Locations []*LocationDefinition `json:"locations"`
}
// Location describes a location in a building
type Location struct {
ID string `json:"id"`
FloorplanID string `json:"floorplanId"`
Coordinates map[string]float64 `json:"coordinates"`
Notes string `json:"notes"`
LocationDefinition *LocationDefinition `json:"locationDefinition"`
}
// MarshalJSON marshals this into JSON
func (locationImage LocationImage) MarshalJSON() ([]byte, error) {
type surrogate LocationImage
data, err := json.Marshal(struct {
surrogate
I *core.URL `json:"imageUrl"`
}{
surrogate: surrogate(locationImage),
I: (*core.URL)(locationImage.ImageURL),
})
return data, errors.JSONMarshalError.Wrap(err)
}
// UnmarshalJSON unmarshals JSON into this
func (locationImage *LocationImage) UnmarshalJSON(payload []byte) (err error) {
type surrogate LocationImage
var inner struct {
surrogate
I *core.URL `json:"imageUrl"`
}
if err = json.Unmarshal(payload, &inner); err != nil {
return errors.JSONUnmarshalError.Wrap(err)
}
*locationImage = LocationImage(inner.surrogate)
locationImage.ImageURL = (*url.URL)(inner.I)
return
}
// GetID gets the identifier of this
//
// implements Identifiable
func (location LocationDefinition) GetID() string {
return location.ID
}
// GetURI gets the URI of this
//
// implements Addressable
func (location LocationDefinition) GetURI() URI {
return location.SelfURI
}
// String gets a string version
//
// implements the fmt.Stringer interface
func (location LocationDefinition) String() string {
if len(location.Name) != 0 {
return location.Name
}
return location.ID
}