-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for listing account activity
This adds a new service to enable listing NS1 account activity. The endpoint supports many url parameters to adjust response behavior (such as changing/limiting how many activity entries are returned, etc), but for this initial approach, the sdk just uses the endpoint directly with the endpoint's normal default values. I used a small Terraform config to generate 50 dummy DNS records on my NS1 account to generate some account activity and have confirmed that the endpoint operates as expected -- the values I expected are returned, the response is limited to the last 20 activity entries like the endpoint default, etc. Signed-off-by: TJ Hoplock <t.hoplock@gmail.com>
- Loading branch information
Showing
5 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package mockns1 | ||
|
||
import ( | ||
"net/http" | ||
|
||
"gopkg.in/ns1/ns1-go.v2/rest/model/account" | ||
) | ||
|
||
// AddActivityListTestCase sets up a test case for the api.Client.Activity.List() | ||
// function | ||
func (s *Service) AddActivityListTestCase( | ||
requestHeaders, responseHeaders http.Header, | ||
response []*account.Activity, | ||
) error { | ||
return s.AddTestCase( | ||
http.MethodGet, "/account/activity", http.StatusOK, requestHeaders, | ||
responseHeaders, "", response, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package rest | ||
|
||
import ( | ||
"net/http" | ||
|
||
"gopkg.in/ns1/ns1-go.v2/rest/model/account" | ||
) | ||
|
||
// ActivityService handles 'account/activity' endpoint. | ||
type ActivityService service | ||
|
||
// List returns all activity in the account. | ||
// | ||
// NS1 API docs: https://developer.ibm.com/apis/catalog/ns1--ibm-ns1-connect-api/api/API--ns1--ibm-ns1-connect-api#getActivity | ||
func (s *ActivityService) List() ([]*account.Activity, *http.Response, error) { | ||
// TODO: add support for url parameters to adjust endpoint behavior? | ||
req, err := s.client.NewRequest("GET", "account/activity", nil) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
al := []*account.Activity{} | ||
resp, err := s.client.Do(req, &al) | ||
if err != nil { | ||
return nil, resp, err | ||
} | ||
|
||
return al, resp, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package account | ||
|
||
// Activity wraps an NS1 /account/activity resource | ||
type Activity struct { | ||
UserID string `json:"user_id,omitempty"` | ||
ResourceID string `json:"resource_id,omitempty"` | ||
Timestamp int `json:"timestamp,omitempty"` | ||
UserType string `json:"user_type,omitempty"` | ||
Action string `json:"action,omitempty"` | ||
UserName string `json:"user_name,omitempty"` | ||
ID string `json:"id,omitempty"` | ||
ResourceType string `json:"resource_type,omitempty"` | ||
} |