forked from mhewedy/ews
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_user_availability.go
236 lines (196 loc) · 7.1 KB
/
get_user_availability.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
package ews
import (
"encoding/xml"
"errors"
"time"
)
type AttendeeType string
const (
AttendeeTypeOrganizer AttendeeType = "Organizer"
AttendeeTypeRequired AttendeeType = "Required"
AttendeeTypeOptional AttendeeType = "Optional"
AttendeeTypeRoom AttendeeType = "Room"
AttendeeTypeResource AttendeeType = "Resource"
)
const (
RequestedViewNone = "None"
RequestedViewMergedOnly = "MergedOnly"
RequestedViewFreeBusy = "FreeBusy"
RequestedViewFreeBusyMerged = "FreeBusyMerged"
RequestedViewDetailed = "Detailed"
RequestedViewDetailedMerged = "DetailedMerged"
)
type BusyType string
const (
BusyTypeFree = "Free"
BusyTypeTentative = "Tentative"
BusyTypeBusy = "Busy"
BusyTypeOOF = "OOF"
BusyTypeNoData = "NoData"
)
type GetUserAvailabilityRequest struct {
XMLName struct{} `xml:"m:GetUserAvailabilityRequest"`
TimeZone TimeZone `xml:"t:TimeZone"`
MailboxDataArray MailboxDataArray `xml:"m:MailboxDataArray"`
FreeBusyViewOptions FreeBusyViewOptions `xml:"t:FreeBusyViewOptions"`
}
type FreeBusyViewOptions struct {
TimeWindow TimeWindow `xml:"t:TimeWindow"`
MergedFreeBusyIntervalInMinutes int `xml:"t:MergedFreeBusyIntervalInMinutes,omitempty"`
RequestedView string `xml:"t:RequestedView"`
}
type TimeWindow struct {
StartTime time.Time `xml:"t:StartTime"`
EndTime time.Time `xml:"t:EndTime"`
}
type TimeZone struct {
Bias int `xml:"t:Bias"`
StandardTime TimeZoneTime `xml:"t:StandardTime"`
DaylightTime TimeZoneTime `xml:"t:DaylightTime"`
}
type TimeZoneTime struct {
Bias int `xml:"t:Bias"`
Time string `xml:"t:Time"`
DayOrder int16 `xml:"t:DayOrder"`
Month int16 `xml:"t:Month"`
DayOfWeek string `xml:"t:DayOfWeek"`
Year string `xml:"Year,omitempty"`
}
type MailboxDataArray struct {
MailboxData []MailboxData `xml:"t:MailboxData"`
}
type MailboxData struct {
Email Email `xml:"t:Email"`
AttendeeType AttendeeType `xml:"t:AttendeeType"`
ExcludeConflicts bool `xml:"t:ExcludeConflicts"`
}
type Email struct {
Name string `xml:"t:Name"`
Address string `xml:"t:Address"`
RoutingType string `xml:"t:RoutingType"`
}
type GetUserAvailabilityResponse struct {
FreeBusyResponseArray FreeBusyResponseArray `xml:"FreeBusyResponseArray"`
SuggestionsResponse SuggestionsResponse `xml:"SuggestionsResponse"`
}
type SuggestionsResponse struct {
ResponseMessage ResponseMessage `xml:"ResponseMessage"`
SuggestionDayResultArray SuggestionDayResultArray `xml:"SuggestionDayResultArray"`
}
type SuggestionDayResultArray struct {
SuggestionDayResult []SuggestionDayResult `xml:"SuggestionDayResult"`
}
type SuggestionDayResult struct {
Date time.Time `xml:"Date"`
DayQuality string `xml:"DayQuality"`
SuggestionArray SuggestionArray `xml:"SuggestionArray"`
}
type SuggestionArray struct {
Suggestion []Suggestion `xml:"Suggestion"`
}
type Suggestion struct {
MeetingTime time.Time `xml:"MeetingTime"`
IsWorkTime bool `xml:"IsWorkTime"`
SuggestionQuality string `xml:"SuggestionQuality"`
ArrayOfAttendeeConflictData ArrayOfAttendeeConflictData `xml:"ArrayOfAttendeeConflictData"`
}
type ArrayOfAttendeeConflictData struct {
UnknownAttendeeConflictData string `xml:"UnknownAttendeeConflictData"`
IndividualAttendeeConflictData string `xml:"IndividualAttendeeConflictData"`
TooBigGroupAttendeeConflictData string `xml:"TooBigGroupAttendeeConflictData"`
GroupAttendeeConflictData GroupAttendeeConflictData `xml:"GroupAttendeeConflictData"`
}
type GroupAttendeeConflictData struct {
NumberOfMembers int `xml:"NumberOfMembers"`
NumberOfMembersAvailable int `xml:"NumberOfMembersAvailable"`
NumberOfMembersWithConflict int `xml:"NumberOfMembersWithConflict"`
NumberOfMembersWithNoData int `xml:"NumberOfMembersWithNoData"`
}
type FreeBusyResponseArray struct {
FreeBusyResponse []FreeBusyResponse `xml:"FreeBusyResponse"`
}
type FreeBusyResponse struct {
ResponseMessage ResponseMessage `xml:"ResponseMessage"`
FreeBusyView FreeBusyView `xml:"FreeBusyView"`
}
type ResponseMessage struct {
Response
DescriptiveLinkKey int `xml:"DescriptiveLinkKey"`
}
type FreeBusyView struct {
FreeBusyViewType string `xml:"FreeBusyViewType"`
MergedFreeBusy string `xml:"MergedFreeBusy"`
CalendarEventArray CalendarEventArray `xml:"CalendarEventArray"`
WorkingHours WorkingHours `xml:"WorkingHours"`
}
type WorkingHours struct {
TimeZone TimeZone `xml:"TimeZone"`
WorkingPeriodArray WorkingPeriodArray `xml:"WorkingPeriodArray"`
}
type WorkingPeriodArray struct {
WorkingPeriod []WorkingPeriod `xml:"WorkingPeriod"`
}
type WorkingPeriod struct {
DayOfWeek string `xml:"DayOfWeek"`
StartTimeInMinutes int `xml:"StartTimeInMinutes"`
EndTimeInMinutes int `xml:"EndTimeInMinutes"`
}
type CalendarEventArray struct {
CalendarEvent []CalendarEvent `xml:"CalendarEvent"`
}
type CalendarEvent struct {
StartTime Time `xml:"StartTime"`
EndTime Time `xml:"EndTime"`
BusyType BusyType `xml:"BusyType"`
CalendarEventDetails CalendarEventDetails `xml:"CalendarEventDetails"`
}
type CalendarEventDetails struct {
ID string `xml:"ID"`
Subject string `xml:"Subject"`
Location string `xml:"Location"`
IsMeeting bool `xml:"IsMeeting"`
IsRecurring bool `xml:"IsRecurring"`
IsException bool `xml:"IsException"`
IsReminderSet bool `xml:"IsReminderSet"`
IsPrivate bool `xml:"IsPrivate"`
}
type getUserAvailabilityResponseEnvelop struct {
XMLName struct{} `xml:"Envelope"`
Body getUserAvailabilityResponseBody `xml:"Body"`
}
type getUserAvailabilityResponseBody struct {
GetUserAvailabilityResponse GetUserAvailabilityResponse `xml:"GetUserAvailabilityResponse"`
}
// GetUserAvailability
//https://docs.microsoft.com/en-us/exchange/client-developer/web-service-reference/getuseravailability-operation
func GetUserAvailability(c Client, r *GetUserAvailabilityRequest) (*GetUserAvailabilityResponse, error) {
xmlBytes, err := xml.MarshalIndent(r, "", " ")
if err != nil {
return nil, err
}
bb, err := c.SendAndReceive(xmlBytes)
if err != nil {
return nil, err
}
var soapResp getUserAvailabilityResponseEnvelop
err = xml.Unmarshal(bb, &soapResp)
if err != nil {
return nil, err
}
resp := soapResp.Body.GetUserAvailabilityResponse
err = checkForFunctionalError(&resp)
if err != nil {
return nil, err
}
return &resp, nil
}
func checkForFunctionalError(resp *GetUserAvailabilityResponse) error {
if len(resp.FreeBusyResponseArray.FreeBusyResponse) > 0 {
for _, rr := range resp.FreeBusyResponseArray.FreeBusyResponse {
if rr.ResponseMessage.ResponseClass == ResponseClassError {
return errors.New(rr.ResponseMessage.MessageText)
}
}
}
return nil
}