forked from jarias/stormpath-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resources.go
66 lines (53 loc) · 1.64 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
61
62
63
64
65
66
package stormpath
import (
"strings"
"time"
)
//collectionResource represent the basic attributes of collection of resources (Application, Group, Account, etc.)
type collectionResource struct {
Href string `json:"href,omitempty"`
CreatedAt *time.Time `json:"createdAt,omitempty"`
ModifiedAt *time.Time `json:"modifiedAt,omitempty"`
Offset *int `json:"offset,omitempty"`
Limit *int `json:"limit,omitempty"`
}
func (r collectionResource) IsCacheable() bool {
return false
}
func (r collectionResource) GetOffset() int {
return *r.Offset
}
func (r collectionResource) GetLimit() int {
return *r.Limit
}
//resource resprents the basic attributes of any resource (Application, Group, Account, etc.)
type resource struct {
Href string `json:"href,omitempty"`
CreatedAt *time.Time `json:"createdAt,omitempty"`
ModifiedAt *time.Time `json:"modifiedAt,omitempty"`
}
func (r resource) IsCacheable() bool {
return true
}
//Delete deletes the given account, it wont modify the calling account
func (r *resource) Delete() error {
return client.delete(r.Href)
}
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()),
accounts,
)
return accounts, err
}
func GetToken(href string) string {
return href[strings.LastIndex(href, "/")+1:]
}