-
Notifications
You must be signed in to change notification settings - Fork 72
/
search.go
77 lines (69 loc) · 2.23 KB
/
search.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
// Copyright © 2016 Aaron Longwell
//
// Use of this source code is governed by an MIT license.
// Details in the LICENSE file.
package trello
// SearchResult represents a search result as collections of various
// types returned by a search, e.g. Cards or Boards.
type SearchResult struct {
Options SearchOptions `json:"options"`
Actions []*Action `json:"actions,omitempty"`
Cards []*Card `json:"cards,omitempty"`
Boards []*Board `json:"boards,omitempty"`
Members []*Member `json:"members,omitempty"`
}
// SearchOptions contains options for search requests.
type SearchOptions struct {
Terms []SearchTerm `json:"terms"`
Modifiers []SearchModifier `json:"modifiers,omitempty"`
ModelTypes []string `json:"modelTypes,omitempty"`
Partial bool `json:"partial"`
}
// SearchModifier is wrapper for a search string.
type SearchModifier struct {
Text string `json:"text"`
}
// SearchTerm is a string that may be negated in a search query.
type SearchTerm struct {
Text string `json:"text"`
Negated bool `json:"negated,omitempty"`
}
// SearchCards takes a query string and Arguments and returns a slice of Cards or an error.
func (c *Client) SearchCards(query string, extraArgs ...Arguments) (cards []*Card, err error) {
args := Arguments{
"query": query,
"modelTypes": "cards",
}
args.flatten(extraArgs)
res := SearchResult{}
err = c.Get("search", args, &res)
cards = res.Cards
for _, card := range cards {
card.SetClient(c)
}
return
}
// SearchBoards takes a query string and Arguments and returns a slice of Boards or an error.
func (c *Client) SearchBoards(query string, extraArgs ...Arguments) (boards []*Board, err error) {
args := Arguments{
"query": query,
"modelTypes": "boards",
}
args.flatten(extraArgs)
res := SearchResult{}
err = c.Get("search", args, &res)
boards = res.Boards
for _, board := range boards {
board.SetClient(c)
}
return
}
// SearchMembers takes a query string and Arguments and returns a slice of Members or an error.
func (c *Client) SearchMembers(query string, extraArgs ...Arguments) (members []*Member, err error) {
args := Arguments{
"query": query,
}
args.flatten(extraArgs)
err = c.Get("search/members", args, &members)
return
}