Skip to content

Commit

Permalink
Add AccountService UpdateProfile
Browse files Browse the repository at this point in the history
  • Loading branch information
dghubble committed Jul 12, 2022
1 parent cdf1c5e commit aecb58d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
21 changes: 21 additions & 0 deletions twitter/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,24 @@ func (s *AccountService) VerifyCredentials(params *AccountVerifyParams) (*User,
resp, err := s.sling.New().Get("verify_credentials.json").QueryStruct(params).Receive(user, apiError)
return user, resp, relevantError(err, *apiError)
}

// AccountUpdateProfileParams are the params for AccountService.UpdateProfile.
type AccountUpdateProfileParams struct {
Name string `url:"name,omitempty"`
URL string `url:"url,omitempty"`
Location string `url:"location,omitempty"`
Description string `url:"description,omitempty"`
IncludeEntities *bool `url:"include_entities,omitempty"`
SkipStatus *bool `url:"skip_status,omitempty"`
}

// UpdateProfile updates the account profile with specified fields and returns
// the User.
// Requires a user auth context.
// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/manage-account-settings/api-reference/post-account-update_profile
func (s *AccountService) UpdateProfile(params *AccountUpdateProfileParams) (*User, *http.Response, error) {
user := new(User)
apiError := new(APIError)
resp, err := s.sling.New().Post("update_profile.json").QueryStruct(params).Receive(user, apiError)
return user, resp, relevantError(err, *apiError)
}
18 changes: 18 additions & 0 deletions twitter/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,21 @@ func TestAccountService_VerifyCredentials(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, expected, user)
}
func TestAccountService_UpdateProfile(t *testing.T) {
httpClient, mux, server := testServer()
defer server.Close()

mux.HandleFunc("/1.1/account/update_profile.json", func(w http.ResponseWriter, r *http.Request) {
assertMethod(t, "POST", r)
assertQuery(t, map[string]string{"location": "anywhere"}, r)
w.Header().Set("Content-Type", "application/json")
fmt.Fprintf(w, `{"name": "xkcdComic", "location":"anywhere"}`)
})

client := NewClient(httpClient)
params := &AccountUpdateProfileParams{Location: "anywhere"}
user, _, err := client.Accounts.UpdateProfile(params)
expected := &User{Name: "xkcdComic", Location: "anywhere"}
assert.Nil(t, err)
assert.Equal(t, expected, user)
}

0 comments on commit aecb58d

Please sign in to comment.