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

Add ContactMethods operations #169

Merged
merged 1 commit into from
Feb 5, 2020
Merged
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
36 changes: 29 additions & 7 deletions user.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ type ListUsersOptions struct {
Includes []string `url:"include,omitempty,brackets"`
}

// ListContactMethodResponse is the data structure returned from calling the GetUserContactMethod API endpoint.
// ListContactMethodsResponse is the data structure returned from calling the GetUserContactMethod API endpoint.
type ListContactMethodsResponse struct {
APIListObject
ContactMethods []ContactMethod `json:"contact_methods"`
Expand Down Expand Up @@ -139,19 +139,41 @@ func getUserFromResponse(c *Client, resp *http.Response, err error) (*User, erro
return &t, nil
}

// ListUserContactMethod fetches contact methods of the existing user.
func (c *Client) ListUserContactMethods(userId string) (*ListContactMethodsResponse, error) {
resp, err := c.get("/users/" + userId + "/contact_methods")
// ListUserContactMethods fetches contact methods of the existing user.
func (c *Client) ListUserContactMethods(userID string) (*ListContactMethodsResponse, error) {
resp, err := c.get("/users/" + userID + "/contact_methods")
if err != nil {
return nil, err
}
var result ListContactMethodsResponse
return &result, c.decodeJSON(resp, &result)
}

// GetContactMethod gets details about a contact method.
func (c *Client) GetUserContactMethod(userID, id string) (*ContactMethod, error) {
resp, err := c.get("/users/" + userID + "/contact_methods/" + id)
// GetUserContactMethod gets details about a contact method.
func (c *Client) GetUserContactMethod(userID, contactMethodID string) (*ContactMethod, error) {
resp, err := c.get("/users/" + userID + "/contact_methods/" + contactMethodID)
return getContactMethodFromResponse(c, resp, err)
}

// DeleteUserContactMethod deletes a user.
func (c *Client) DeleteUserContactMethod(userID, contactMethodID string) error {
_, err := c.delete("/users/" + userID + "/contact_methods/" + contactMethodID)
return err
}

// CreateUserContactMethod creates a new contact method for user.
func (c *Client) CreateUserContactMethod(userID string, cm ContactMethod) (*ContactMethod, error) {
data := make(map[string]ContactMethod)
data["contact_method"] = cm
resp, err := c.post("/users/"+userID+"/contact_methods", data, nil)
return getContactMethodFromResponse(c, resp, err)
}

// UpdateUserContactMethod updates an existing user.
func (c *Client) UpdateUserContactMethod(userID string, cm ContactMethod) (*ContactMethod, error) {
v := make(map[string]ContactMethod)
v["contact_method"] = cm
resp, err := c.put("/users/"+userID+"/contact_methods/"+cm.ID, v, nil)
return getContactMethodFromResponse(c, resp, err)
}

Expand Down