Skip to content

Commit

Permalink
Support API for getting team member information (PagerDuty#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
dtan4 authored and heimweh committed Sep 3, 2019
1 parent 87ddb87 commit 5a16d0d
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
37 changes: 37 additions & 0 deletions pagerduty/team.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ type Team struct {
Type string `json:"type,omitempty"`
}

// Member represents a team member.
type Member struct {
User *UserReference `json:"user,omitempty"`
Role string `json:"role,omitempty"`
}

// ListTeamsOptions represents options when listing teams.
type ListTeamsOptions struct {
Limit int `url:"limit,omitempty"`
Expand All @@ -36,6 +42,24 @@ type ListTeamsResponse struct {
Teams []*Team `json:"teams,omitempty"`
}

// GetMembersOptions represents options when get member informations in team.
type GetMembersOptions struct {
Limit int `url:"limit,omitempty"`
More bool `url:"more,omitempty"`
Offset int `url:"offset,omitempty"`
Total int `url:"total,omitempty"`
Includes []string `url:"include,omitempty,brackets"`
}

// GetMembersResponse represents member informations response of a team.
type GetMembersResponse struct {
Limit int `json:"limit,omitempty"`
More bool `json:"more,omitempty"`
Offset int `json:"offset,omitempty"`
Total int `json:"total,omitempty"`
Members []*Member `json:"members,omitempty"`
}

type teamRole struct {
Role string `json:"role,omitempty"`
}
Expand Down Expand Up @@ -117,6 +141,19 @@ func (s *TeamService) AddUserWithRole(teamID, userID string, role string) (*Resp
return s.client.newRequestDo("PUT", u, nil, tr, nil)
}

// GetMembers retrieves information about members on a team.
func (s *TeamService) GetMembers(teamID string, o *GetMembersOptions) (*GetMembersResponse, *Response, error) {
u := fmt.Sprintf("/teams/%s/members", teamID)
v := new(GetMembersResponse)

resp, err := s.client.newRequestDo("GET", u, o, nil, &v)
if err != nil {
return nil, nil, err
}

return v, resp, nil
}

// RemoveEscalationPolicy removes an escalation policy from a team.
func (s *TeamService) RemoveEscalationPolicy(teamID, escID string) (*Response, error) {
u := fmt.Sprintf("/teams/%s/escalation_policies/%s", teamID, escID)
Expand Down
30 changes: 30 additions & 0 deletions pagerduty/team_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,36 @@ func TestTeamsRemoveUser(t *testing.T) {
}
}

func TestTeamsGetMembers(t *testing.T) {
setup()
defer teardown()

mux.HandleFunc("/teams/1/members", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
w.Write([]byte(`{"members": [{"user": {"id": "1"}, "role": "manager"}]}`))
})

resp, _, err := client.Teams.GetMembers("1", &GetMembersOptions{})
if err != nil {
t.Fatal(err)
}

want := &GetMembersResponse{
Members: []*Member{
{
User: &UserReference{
ID: "1",
},
Role: "manager",
},
},
}

if !reflect.DeepEqual(resp, want) {
t.Errorf("returned \n\n%#v want \n\n%#v", resp, want)
}
}

func TestTeamsAddEscalationPolicy(t *testing.T) {
setup()
defer teardown()
Expand Down

0 comments on commit 5a16d0d

Please sign in to comment.