forked from jarias/stormpath-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resources.go
60 lines (49 loc) · 1.68 KB
/
resources.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
package stormpath
//collectionResource represent the basic attributes of collection of resources (Application, Group, Account, etc.)
type collectionResource struct {
Href string `json:"href,omitempty"`
CreatedAt string `json:"createdAt,omitempty"`
ModifiedAt string `json:"modifiedAt,omitempty"`
Offset int `json:"offset"`
Limit int `json:"limit"`
}
func (r collectionResource) IsCacheable() bool {
return false
}
//resource resprents the basic attributes of any resource (Application, Group, Account, etc.)
type resource struct {
Href string `json:"href,omitempty"`
CreatedAt string `json:"createdAt,omitempty"`
ModifiedAt string `json:"modifiedAt,omitempty"`
}
func (r resource) IsCacheable() bool {
return true
}
//Refresh refreshes the resource by doing a GET to the resource href endpoint
func (r *resource) Refresh() error {
return client.get(r.Href, emptyPayload(), r)
}
//Save updates the given resource, by doing a POST to the resource Href
func (r *resource) Save() error {
return client.post(r.Href, r, r)
}
//Delete deletes the given account, it wont modify the calling account
func (r *resource) Delete() error {
return client.delete(r.Href, emptyPayload())
}
type accountStoreResource struct {
customDataAwareResource
Accounts *Accounts `json:"accounts,omitempty"`
}
//GetAccounts returns all the accounts of the application
//
//See: http://docs.stormpath.com/rest/product-guide/#application-accounts
func (r *accountStoreResource) GetAccounts(criteria Criteria) (*Accounts, error) {
accounts := &Accounts{}
err := client.get(
buildAbsoluteURL(r.Accounts.Href, criteria.ToQueryString()),
emptyPayload(),
accounts,
)
return accounts, err
}