Skip to content

Commit

Permalink
New AcceptUser request
Browse files Browse the repository at this point in the history
  • Loading branch information
mrz1836 committed Jan 20, 2020
1 parent f230f10 commit 5b26170
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
9 changes: 9 additions & 0 deletions examples/examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ func main() {
log.Printf("user %d created and referred by user %d", refUser.ID, refUser.ReferredByUserID)
}

//
// Example: Accept/Approve the User (if required by application config)
//
if err = TonicPowAPI.AcceptUser(user.ID); err != nil {
log.Fatalf("get user failed error %s - api error: %s", err.Error(), TonicPowAPI.LastRequest.Error.Message)
} else {
log.Printf("user accepted: %d", user.ID)
}

//
// Example: Get new updated balance for user
//
Expand Down
26 changes: 26 additions & 0 deletions users.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
// permitFields will remove fields that cannot be used
func (u *User) permitFields() {
u.Balance = 0
u.Earned = 0
u.InternalAddress = ""
u.Status = ""
}
Expand Down Expand Up @@ -370,6 +371,31 @@ func (c *Client) CompletePhoneVerification(phone, code string) (err error) {
return
}

// AcceptUser will accept a user (if approval is required for new users)
//
// For more information: https://docs.tonicpow.com/#65c3962d-c309-4ef4-b85f-7ec1f08f031b
func (c *Client) AcceptUser(userID uint64) (err error) {

// Basic requirements
if userID == 0 {
err = fmt.Errorf("missing required attribute: %s", fieldUserID)
return
}

// Start the post data
data := map[string]string{fieldID: fmt.Sprintf("%d", userID)}

// Fire the request
var response string
if response, err = c.request(fmt.Sprintf("%s/status/accept", modelUser), http.MethodPut, data, ""); err != nil {
return
}

// Only a 200 is treated as a success
err = c.error(http.StatusOK, response)
return
}

// ActivateUser will activate a user (if all application criteria is met)
//
// For more information: https://docs.tonicpow.com/#aa499fdf-2492-43ee-99d4-fc9735676431
Expand Down

0 comments on commit 5b26170

Please sign in to comment.