forked from koltyakov/gosip
/
users.go
71 lines (60 loc) · 1.79 KB
/
users.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
package api
import (
"context"
"fmt"
"net/url"
"github.com/recolabs/gosip"
)
//go:generate ggen -ent Users -item User -conf -coll -mods Select,Expand,Filter,Top,OrderBy -helpers Data,Normalized
// Users represent SharePoint Site Users API queryable collection struct
// Always use NewUsers constructor instead of &Users{}
type Users struct {
client *gosip.SPClient
config *RequestConfig
endpoint string
modifiers *ODataMods
}
// UsersResp - site users response type with helper processor methods
type UsersResp []byte
// NewUsers - Users struct constructor function
func NewUsers(client *gosip.SPClient, endpoint string, config *RequestConfig) *Users {
return &Users{
client: client,
endpoint: endpoint,
config: config,
modifiers: NewODataMods(),
}
}
// ToURL gets endpoint with modificators raw URL
func (users *Users) ToURL() string {
return toURL(users.endpoint, users.modifiers)
}
// Get gets Users queryable collection
func (users *Users) Get(ctx context.Context) (UsersResp, error) {
client := NewHTTPClient(users.client)
return client.Get(ctx, users.ToURL(), users.config)
}
// GetByID gets a user by his/her ID (numeric ID from User Information List)
func (users *Users) GetByID(userID int) *User {
return NewUser(
users.client,
fmt.Sprintf("%s/GetById(%d)", users.endpoint, userID),
users.config,
)
}
// GetByLoginName gets a user by his/her login name
func (users *Users) GetByLoginName(loginName string) *User {
return NewUser(
users.client,
fmt.Sprintf("%s('%s')", users.endpoint, url.QueryEscape(loginName)),
users.config,
)
}
// GetByEmail gets a user by his/her email address
func (users *Users) GetByEmail(email string) *User {
return NewUser(
users.client,
fmt.Sprintf("%s/GetByEmail('%s')", users.endpoint, url.QueryEscape(email)),
users.config,
)
}