Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export RetrieveItems function for external use and standardize naming #53

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 33 additions & 33 deletions admin/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ type User struct {
}

// URLValues transforms a User into url.Values using the 'url' struct tag to
// define the key of the map. Fields are skiped if the value is empty.
// define the key of the map. Fields are skipped if the value is empty.
func (u *User) URLValues() url.Values {
params := url.Values{}

Expand Down Expand Up @@ -189,8 +189,8 @@ func (result *GetUsersResult) getResponse() interface{} {
}

func (result *GetUsersResult) appendResponse(users interface{}) {
asserted_users := users.([]User)
result.Response = append(result.Response, asserted_users...)
assertedUsers := users.([]User)
result.Response = append(result.Response, assertedUsers...)
}

// GetUsers calls GET /admin/v1/users
Expand All @@ -201,29 +201,29 @@ func (c *Client) GetUsers(options ...func(*url.Values)) (*GetUsersResult, error)
o(&params)
}

cb := func(params url.Values) (responsePage, error) {
cb := func(params url.Values) (ResponsePage, error) {
return c.retrieveUsers(params)
}
response, err := c.retrieveItems(params, cb)
response, err := c.RetrieveItems(params, cb)
if err != nil {
return nil, err
}

return response.(*GetUsersResult), nil
}

type responsePage interface {
type ResponsePage interface {
metadata() ListResultMetadata
getResponse() interface{}
appendResponse(interface{})
}

type pageFetcher func(params url.Values) (responsePage, error)
type pageFetcher func(params url.Values) (ResponsePage, error)

func (c *Client) retrieveItems(
func (c *Client) RetrieveItems(
params url.Values,
fetcher pageFetcher,
) (responsePage, error) {
) (ResponsePage, error) {
if params.Get("offset") == "" {
params.Set("offset", "0")
}
Expand Down Expand Up @@ -346,10 +346,10 @@ func (c *Client) GetUserGroups(userID string, options ...func(*url.Values)) (*Ge
o(&params)
}

cb := func(params url.Values) (responsePage, error) {
cb := func(params url.Values) (ResponsePage, error) {
return c.retrieveUserGroups(userID, params)
}
response, err := c.retrieveItems(params, cb)
response, err := c.RetrieveItems(params, cb)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -420,10 +420,10 @@ func (c *Client) GetUserPhones(userID string, options ...func(*url.Values)) (*Ge
o(&params)
}

cb := func(params url.Values) (responsePage, error) {
cb := func(params url.Values) (ResponsePage, error) {
return c.retrieveUserPhones(userID, params)
}
response, err := c.retrieveItems(params, cb)
response, err := c.RetrieveItems(params, cb)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -455,10 +455,10 @@ func (c *Client) GetUserTokens(userID string, options ...func(*url.Values)) (*Ge
o(&params)
}

cb := func(params url.Values) (responsePage, error) {
cb := func(params url.Values) (ResponsePage, error) {
return c.retrieveUserTokens(userID, params)
}
response, err := c.retrieveItems(params, cb)
response, err := c.RetrieveItems(params, cb)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -517,10 +517,10 @@ func (c *Client) GetUserU2FTokens(userID string, options ...func(*url.Values)) (
o(&params)
}

cb := func(params url.Values) (responsePage, error) {
cb := func(params url.Values) (ResponsePage, error) {
return c.retrieveUserU2FTokens(userID, params)
}
response, err := c.retrieveItems(params, cb)
response, err := c.RetrieveItems(params, cb)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -588,8 +588,8 @@ func (result *GetGroupsResult) getResponse() interface{} {
}

func (result *GetGroupsResult) appendResponse(groups interface{}) {
asserted_groups := groups.([]Group)
result.Response = append(result.Response, asserted_groups...)
assertedGroups := groups.([]Group)
result.Response = append(result.Response, assertedGroups...)
}

// GetGroups calls GET /admin/v1/groups
Expand All @@ -600,10 +600,10 @@ func (c *Client) GetGroups(options ...func(*url.Values)) (*GetGroupsResult, erro
o(&params)
}

cb := func(params url.Values) (responsePage, error) {
cb := func(params url.Values) (ResponsePage, error) {
return c.retrieveGroups(params)
}
response, err := c.retrieveItems(params, cb)
response, err := c.RetrieveItems(params, cb)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -677,8 +677,8 @@ func (result *GetPhonesResult) getResponse() interface{} {
}

func (result *GetPhonesResult) appendResponse(phones interface{}) {
asserted_phones := phones.([]Phone)
result.Response = append(result.Response, asserted_phones...)
assertedPhones := phones.([]Phone)
result.Response = append(result.Response, assertedPhones...)
}

// GetPhones calls GET /admin/v1/phones
Expand All @@ -689,10 +689,10 @@ func (c *Client) GetPhones(options ...func(*url.Values)) (*GetPhonesResult, erro
o(&params)
}

cb := func(params url.Values) (responsePage, error) {
cb := func(params url.Values) (ResponsePage, error) {
return c.retrievePhones(params)
}
response, err := c.retrieveItems(params, cb)
response, err := c.RetrieveItems(params, cb)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -778,8 +778,8 @@ func (result *GetTokensResult) getResponse() interface{} {
}

func (result *GetTokensResult) appendResponse(tokens interface{}) {
asserted_tokens := tokens.([]Token)
result.Response = append(result.Response, asserted_tokens...)
assertedTokens := tokens.([]Token)
result.Response = append(result.Response, assertedTokens...)
}

// GetTokens calls GET /admin/v1/tokens
Expand All @@ -790,10 +790,10 @@ func (c *Client) GetTokens(options ...func(*url.Values)) (*GetTokensResult, erro
o(&params)
}

cb := func(params url.Values) (responsePage, error) {
cb := func(params url.Values) (ResponsePage, error) {
return c.retrieveTokens(params)
}
response, err := c.retrieveItems(params, cb)
response, err := c.RetrieveItems(params, cb)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -853,8 +853,8 @@ func (result *GetU2FTokensResult) getResponse() interface{} {
}

func (result *GetU2FTokensResult) appendResponse(tokens interface{}) {
asserted_tokens := tokens.([]U2FToken)
result.Response = append(result.Response, asserted_tokens...)
assertedTokens := tokens.([]U2FToken)
result.Response = append(result.Response, assertedTokens...)
}

// GetU2FTokens calls GET /admin/v1/u2ftokens
Expand All @@ -865,10 +865,10 @@ func (c *Client) GetU2FTokens(options ...func(*url.Values)) (*GetU2FTokensResult
o(&params)
}

cb := func(params url.Values) (responsePage, error) {
cb := func(params url.Values) (ResponsePage, error) {
return c.retrieveU2FTokens(params)
}
response, err := c.retrieveItems(params, cb)
response, err := c.RetrieveItems(params, cb)
if err != nil {
return nil, err
}
Expand Down