-
Notifications
You must be signed in to change notification settings - Fork 1
/
request.go
57 lines (48 loc) · 1.53 KB
/
request.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
package stretchr
import (
"github.com/stretchr/sdk-go/api"
)
// Request represents a kind of interaction that can be made against
// the Stretchr services.
type Request struct {
UnderlyingRequest *api.Request
session *Session
}
// NewRequest makes a new Request object with the given session, and path.
//
// It is recommended that you use Session.At to generate a Request instead of calling this
// method directly.
func NewRequest(session *Session, path string) *Request {
request := new(Request)
request.UnderlyingRequest = api.NewRequest(session.underlyingSession, path)
request.session = session
return request
}
// Session gets the Session object that this request relies on.
func (r *Request) Session() *Session {
return r.session
}
// Where adds a filter to the request.
func (r *Request) Where(field, match string) *Request {
r.UnderlyingRequest.Where(field, match)
return r
}
// Limit sets a limit on the number of resources to get back from Stretchr.
func (r *Request) Limit(value int64) *Request {
r.UnderlyingRequest.Limit(value)
return r
}
// Skip sets the number of resources to skip before getting them back from Stretchr.
func (r *Request) Skip(value int64) *Request {
r.UnderlyingRequest.Skip(value)
return r
}
func (r *Request) Page(pageNumber, resourcesPerPage int64) *Request {
r.UnderlyingRequest.Page(pageNumber, resourcesPerPage)
return r
}
// WithParam sets a query parameter in the request.
func (r *Request) WithParam(key, value string) *Request {
r.UnderlyingRequest.WithParam(key, value)
return r
}