Skip to content

Commit

Permalink
Fixup the PR
Browse files Browse the repository at this point in the history
  • Loading branch information
svanharmelen committed May 31, 2021
1 parent 366ce27 commit deb0c37
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
23 changes: 13 additions & 10 deletions avatar.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"net/http"
)

// AccessRequestsService handles communication with the avatar
// avatar related methods of the GitLab API.
// AvatarRequestsService handles communication with the avatar related methods
// of the GitLab API.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/avatar.html
type AvatarRequestsService struct {
Expand All @@ -35,24 +35,27 @@ type Avatar struct {
AvatarURL string `json:"avatar_url"`
}

// AccessRequest represents a access request for a user avatars.
// GetAvatarOptions represents the available GetAvatar() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/avatar.html
// https://docs.gitlab.com/ee/api/avatar.html#get-a-single-avatar-url
type GetAvatarOptions struct {
Email *string `json:"email"`
Size *int `json:"size"`
Email *string `url:"email,omitempty" json:"email,omitempty"`
Size *int `url:"size,omitempty" json:"size,omitempty"`
}

func (s *AvatarRequestsService) GetAvatar(opts *GetAvatarOptions, options ...RequestOptionFunc) (*Avatar, *Response, error) {
req, err := s.client.NewRequest(http.MethodGet, "avatar", opts, options)
// GetAvatar gets the avatar URL for a user with the given email address.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/avatar.html#get-a-single-avatar-url
func (s *AvatarRequestsService) GetAvatar(opt *GetAvatarOptions, options ...RequestOptionFunc) (*Avatar, *Response, error) {
req, err := s.client.NewRequest(http.MethodGet, "avatar", opt, options)
if err != nil {
return nil, nil, err
}

avatar := new(Avatar)

response, err := s.client.Do(req, &avatar)
response, err := s.client.Do(req, avatar)
if err != nil {
return nil, response, err
}
Expand Down
13 changes: 6 additions & 7 deletions avatar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,20 @@ func TestGetAvatar(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)

const host = "https://google.com"
const url = "https://www.gravatar.com/avatar/10e6bf7bcf22c2f00a3ef684b4ada178"

mux.HandleFunc("/api/v4/avatar",
func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
w.WriteHeader(http.StatusAccepted)
avatar := Avatar{AvatarURL: host}
avatar := Avatar{AvatarURL: url}
resp, _ := json.Marshal(avatar)
_, _ = w.Write(resp)
},
)

email := "test"

avatar, resp, err := client.Avatar.GetAvatar(&GetAvatarOptions{Email: &email})
opt := &GetAvatarOptions{Email: String("[email protected]")}
avatar, resp, err := client.Avatar.GetAvatar(opt)
if err != nil {
t.Fatalf("Avatar.GetAvatar returned error: %v", err)
}
Expand All @@ -49,7 +48,7 @@ func TestGetAvatar(t *testing.T) {
t.Fatalf("Avatar.GetAvatar returned wrong status code: %v", resp.Status)
}

if host != avatar.AvatarURL {
t.Errorf("Avatar.GetAvatar wrong result %s, want %s", avatar.AvatarURL, host)
if url != avatar.AvatarURL {
t.Errorf("Avatar.GetAvatar wrong result %s, want %s", avatar.AvatarURL, url)
}
}
2 changes: 1 addition & 1 deletion boards.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (b BoardList) String() string {
//
// GitLab API docs: https://docs.gitlab.com/ee/api/boards.html#create-a-board-starter
type CreateIssueBoardOptions struct {
Name *string `url:"name" json:"name"`
Name *string `url:"name,omitempty" json:"name,omitempty"`
}

// CreateIssueBoard creates a new issue board.
Expand Down

0 comments on commit deb0c37

Please sign in to comment.