forked from mhewedy/ews
-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_people.go
103 lines (83 loc) · 2.78 KB
/
find_people.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
package ews
import (
"encoding/xml"
"errors"
)
type BaseShape string
const (
BaseShapeIdOnly BaseShape = "IdOnly"
BaseShapeDefault BaseShape = "Default"
BaseShapeAllProperties BaseShape = "AllProperties"
)
type BasePoint string
const (
BasePointBeginning BasePoint = "Beginning"
BasePointEnd BasePoint = "End"
)
type FindPeopleRequest struct {
XMLName struct{} `xml:"m:FindPeople"`
PersonaShape *PersonaShape `xml:"m:PersonaShape,omitempty"`
IndexedPageItemView IndexedPageItemView `xml:"m:IndexedPageItemView"`
ParentFolderId ParentFolderId `xml:"m:ParentFolderId"`
QueryString string `xml:"m:QueryString,omitempty"`
// add additional fields
}
type PersonaShape struct {
BaseShape BaseShape `xml:"t:BaseShape,omitempty"`
AdditionalProperties AdditionalProperties `xml:"t:AdditionalProperties,omitempty"`
}
type AdditionalProperties struct {
FieldURI []FieldURI `xml:"t:FieldURI,omitempty"`
// add additional fields
}
type FieldURI struct {
// List of possible values:
// https://docs.microsoft.com/en-us/exchange/client-developer/web-service-reference/fielduri
FieldURI string `xml:"FieldURI,attr,omitempty"`
}
type IndexedPageItemView struct {
MaxEntriesReturned int `xml:"MaxEntriesReturned,attr,omitempty"`
Offset int `xml:"Offset,attr"`
BasePoint BasePoint `xml:"BasePoint,attr"`
}
type ParentFolderId struct {
DistinguishedFolderId DistinguishedFolderId `xml:"t:DistinguishedFolderId"`
}
type findPeopleResponseEnvelop struct {
XMLName struct{} `xml:"Envelope"`
Body findPeopleResponseBody `xml:"Body"`
}
type findPeopleResponseBody struct {
FindPeopleResponse FindPeopleResponse `xml:"FindPeopleResponse"`
}
type FindPeopleResponse struct {
Response
People People `xml:"People"`
TotalNumberOfPeopleInView int `xml:"TotalNumberOfPeopleInView"`
FirstMatchingRowIndex int `xml:"FirstMatchingRowIndex"`
FirstLoadedRowIndex int `xml:"FirstLoadedRowIndex"`
}
type People struct {
Persona []Persona `xml:"Persona"`
}
// GetUserAvailability
//https://docs.microsoft.com/en-us/exchange/client-developer/web-service-reference/findpeople-operation
func FindPeople(c Client, r *FindPeopleRequest) (*FindPeopleResponse, 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 findPeopleResponseEnvelop
err = xml.Unmarshal(bb, &soapResp)
if err != nil {
return nil, err
}
if soapResp.Body.FindPeopleResponse.ResponseClass == ResponseClassError {
return nil, errors.New(soapResp.Body.FindPeopleResponse.MessageText)
}
return &soapResp.Body.FindPeopleResponse, nil
}