forked from andlabs/ews
-
Notifications
You must be signed in to change notification settings - Fork 28
/
get_user_photo.go
53 lines (43 loc) · 1.27 KB
/
get_user_photo.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
package ews
import (
"encoding/xml"
"errors"
)
type GetUserPhotoRequest struct {
XMLName struct{} `xml:"m:GetUserPhoto"`
Email string `xml:"m:Email"`
SizeRequested string `xml:"m:SizeRequested"`
}
type GetUserPhotoResponse struct {
Response
HasChanged bool `xml:"HasChanged"`
PictureData string `xml:"PictureData"`
}
type getUserPhotoResponseEnvelop struct {
XMLName struct{} `xml:"Envelope"`
Body getUserPhotoResponseBody `xml:"Body"`
}
type getUserPhotoResponseBody struct {
GetUserPhotoResponse GetUserPhotoResponse `xml:"GetUserPhotoResponse"`
}
// GetUserPhoto
//https://docs.microsoft.com/en-us/exchange/client-developer/web-service-reference/getuserphoto-operation
func GetUserPhoto(c Client, r *GetUserPhotoRequest) (*GetUserPhotoResponse, 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 getUserPhotoResponseEnvelop
err = xml.Unmarshal(bb, &soapResp)
if err != nil {
return nil, err
}
if soapResp.Body.GetUserPhotoResponse.ResponseClass == ResponseClassError {
return nil, errors.New(soapResp.Body.GetUserPhotoResponse.MessageText)
}
return &soapResp.Body.GetUserPhotoResponse, nil
}