-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinksclient.go
70 lines (63 loc) · 1.9 KB
/
linksclient.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
package vctr
type linksClient struct {
*Client
}
// List returns a list of links.
//
// limit defines the maximum ammount of response
// entities and offset defines the number of entities
// to be skipped.
func (c *linksClient) List(limit, offset int) (res []*LinkModel, err error) {
res = make([]*LinkModel, 0)
err = c.r.Get("links", getLimitOffsetQuery(limit, offset), &res)
for _, r := range res {
r.hydrate(c.Client)
}
return
}
// Create creates a new link with the given properties
// and returns the resulting link entity.
func (c *linksClient) Create(link *LinkCreateModel) (res *LinkModel, err error) {
res = new(LinkModel)
err = c.r.Post("links", link, nil, res)
res.hydrate(c.Client)
return
}
// Search searches all links by the given query and
// returns a list of results.
//
// limit defines the maximum ammount of response
// entities and offset defines the number of entities
// to be skipped.
func (c *linksClient) Search(query string, limit, offset int) (res []*LinkModel, err error) {
res = make([]*LinkModel, 0)
urlQuery := getLimitOffsetQuery(limit, offset)
urlQuery.Add("query", query)
err = c.r.Get("links/search", urlQuery, &res)
for _, r := range res {
r.hydrate(c.Client)
}
return
}
// Get returns a link entity by its id.
func (c *linksClient) Get(id string) (res *LinkModel, err error) {
res = new(LinkModel)
err = c.r.Get("links/"+id, nil, res)
return
}
// Update sets the given properties to the given
// link by id and returns the updated link entity model.
func (c *linksClient) Update(id string, newLink *LinkCreateModel) (res *LinkModel, err error) {
res = new(LinkModel)
err = c.r.Post("links/"+id, newLink, nil, res)
return
}
// Delete removes the passed link by its
// id.
//
// The delete action returns no response, so it is
// considered to be successful, when err != nil.
func (c *linksClient) Delete(id string) (err error) {
err = c.r.Delete("links/"+id, nil)
return
}