...

Source file src/github.com/xanzy/go-gitlab/avatar.go

Documentation: github.com/xanzy/go-gitlab

     1  //
     2  // Copyright 2021, Pavel Kostohrys
     3  //
     4  // Licensed under the Apache License, Version 2.0 (the "License");
     5  // you may not use this file except in compliance with the License.
     6  // You may obtain a copy of the License at
     7  //
     8  //     http://www.apache.org/licenses/LICENSE-2.0
     9  //
    10  // Unless required by applicable law or agreed to in writing, software
    11  // distributed under the License is distributed on an "AS IS" BASIS,
    12  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  // See the License for the specific language governing permissions and
    14  // limitations under the License.
    15  //
    16  
    17  package gitlab
    18  
    19  import (
    20  	"net/http"
    21  )
    22  
    23  // AvatarRequestsService handles communication with the avatar related methods
    24  // of the GitLab API.
    25  //
    26  // GitLab API docs: https://docs.gitlab.com/ee/api/avatar.html
    27  type AvatarRequestsService struct {
    28  	client *Client
    29  }
    30  
    31  // Avatar represents a GitLab avatar.
    32  //
    33  // GitLab API docs: https://docs.gitlab.com/ee/api/avatar.html
    34  type Avatar struct {
    35  	AvatarURL string `json:"avatar_url"`
    36  }
    37  
    38  // GetAvatarOptions represents the available GetAvatar() options.
    39  //
    40  // GitLab API docs:
    41  // https://docs.gitlab.com/ee/api/avatar.html#get-a-single-avatar-url
    42  type GetAvatarOptions struct {
    43  	Email *string `url:"email,omitempty" json:"email,omitempty"`
    44  	Size  *int    `url:"size,omitempty" json:"size,omitempty"`
    45  }
    46  
    47  // GetAvatar gets the avatar URL for a user with the given email address.
    48  //
    49  // GitLab API docs:
    50  // https://docs.gitlab.com/ee/api/avatar.html#get-a-single-avatar-url
    51  func (s *AvatarRequestsService) GetAvatar(opt *GetAvatarOptions, options ...RequestOptionFunc) (*Avatar, *Response, error) {
    52  	req, err := s.client.NewRequest(http.MethodGet, "avatar", opt, options)
    53  	if err != nil {
    54  		return nil, nil, err
    55  	}
    56  
    57  	avatar := new(Avatar)
    58  	response, err := s.client.Do(req, avatar)
    59  	if err != nil {
    60  		return nil, response, err
    61  	}
    62  
    63  	return avatar, response, nil
    64  }
    65  

View as plain text