-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathusers.go
More file actions
115 lines (95 loc) · 2.38 KB
/
Copy pathusers.go
File metadata and controls
115 lines (95 loc) · 2.38 KB
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
package mediawiki
import (
"context"
"fmt"
"strconv"
"strings"
)
// Get information about a list of users.
//
// Flags:
// * This module requires read rights.
// Users
type UsersOption func(map[string]string)
type UsersResponse struct {
QueryResponse
Query *UsersQuery `json:"query,omitempty"`
}
type UsersQuery struct {
Users []UsersResponseUser `json:"users"`
}
type UsersResponseUser struct {
UserId int `json:"userid,omitempty"`
Name string `json:"name,omitempty"`
Missing any `json:"missing,omitempty"`
}
type UsersClient struct {
o []QueryOption
c *Client
}
func (c *Client) Users() *UsersClient {
return &UsersClient{c: c}
}
// Usprop
func (w *UsersClient) Prop(s ...string) *UsersClient {
w.o = append(w.o, func(m map[string]string) {
m["usprop"] = strings.Join(s, "|")
})
return w
}
// Usattachedwiki
// With usprop=centralids, indicate whether the user is attached with the wiki identified by this ID.
func (w *UsersClient) Attachedwiki(s string) *UsersClient {
w.o = append(w.o, func(m map[string]string) {
m["usattachedwiki"] = s
})
return w
}
// Ususers
// A list of users to obtain information for.
// Separate values with | or alternative.
// Maximum number of values is 50 (500 for clients allowed higher limits).
func (w *UsersClient) Users(s ...string) *UsersClient {
w.o = append(w.o, func(m map[string]string) {
m["ususers"] = strings.Join(s, "|")
})
return w
}
// Ususerids
// A list of user IDs to obtain information for.
// Separate values with | or alternative.
// Maximum number of values is 50 (500 for clients allowed higher limits).
func (w *UsersClient) Userids(i ...int) *UsersClient {
w.o = append(w.o, func(m map[string]string) {
var s []string
for _, n := range i {
s = append(s, strconv.FormatInt(int64(n), 10))
}
m["ususerids"] = strings.Join(s, "|")
})
return w
}
func (w *UsersClient) Do(ctx context.Context) (UsersResponse, error) {
if err := w.c.checkKeepAlive(ctx); err != nil {
return UsersResponse{}, err
}
// Specify parameters to send.
parameters := Values{
"action": "query",
"list": "users",
}
for _, o := range w.o {
o(parameters)
}
// Make the request.
r := UsersResponse{}
j, err := w.c.PostInto(ctx, parameters, &r)
r.RawJSON = j
if err != nil {
return r, fmt.Errorf("failed to post: %w", err)
}
if e := r.Error; e != nil {
return r, fmt.Errorf("%s: %s", e.Code, e.Info)
}
return r, nil
}