forked from open-networks/go-msgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Attendee.go
48 lines (40 loc) · 1.59 KB
/
Attendee.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
package msgraph
import (
"encoding/json"
"fmt"
)
// Attendee struct represents an attendee for a CalendarEvent
type Attendee struct {
Type string // the type of the invitation, e.g. required, optional etc.
Name string // the name of the person, comes from the E-Mail Address - hence not a reliable name to search for
Email string // the e-mail address of the person - use this to identify the user
ResponseStatus ResponseStatus // the ResponseStatus for that particular Attendee for the CalendarEvent
}
func (a Attendee) String() string {
return fmt.Sprintf("Name: %s, Type: %s, E-mail: %s, ResponseStatus: %v", a.Name, a.Type, a.Email, a.ResponseStatus)
}
// Equal compares the Attendee to the other Attendee and returns true
// if the two given Attendees are equal. Otherwise returns false
func (a Attendee) Equal(other Attendee) bool {
return a.Type == other.Type && a.Name == other.Name && a.Email == other.Email && a.ResponseStatus.Equal(other.ResponseStatus)
}
// UnmarshalJSON implements the json unmarshal to be used by the json-library
func (a *Attendee) UnmarshalJSON(data []byte) error {
tmp := struct {
Type string `json:"type"`
Status ResponseStatus `json:"status"`
EmailAddress struct {
Name string `json:"name"`
Address string `json:"address"`
} `json:"emailAddress"`
}{}
err := json.Unmarshal(data, &tmp)
if err != nil {
return fmt.Errorf("Attendee: %v", err.Error())
}
a.Type = tmp.Type
a.Name = tmp.EmailAddress.Name
a.Email = tmp.EmailAddress.Address
a.ResponseStatus = tmp.Status
return nil
}