github.com/aiven/aiven-go-client@v1.36.0/organization_user.go (about)

     1  // Package aiven provides a client for using the Aiven API.
     2  package aiven
     3  
     4  type (
     5  	// OrganizationUserHandler is the client which interacts with the Organization Users API on Aiven.
     6  	OrganizationUserHandler struct {
     7  		// client is the API client to use.
     8  		client *Client
     9  	}
    10  
    11  	// OrganizationUserList is a response from Aiven for a list of organization users.
    12  	OrganizationUserList struct {
    13  		APIResponse
    14  
    15  		// Users is a list of organization users.
    16  		Users []OrganizationMemberInfo `json:"users"`
    17  	}
    18  
    19  	// OrganizationMemberInfo is a struct that represents a user's membership in an organization.
    20  	OrganizationMemberInfo struct {
    21  		APIResponse
    22  
    23  		// UserID is the unique identifier of the user.
    24  		UserID string `json:"user_id"`
    25  		// JoinTime is the time when the user joined the organization.
    26  		JoinTime string `json:"join_time"`
    27  		// UserInfo is the information of the user.
    28  		UserInfo OrganizationUserInfo `json:"user_info"`
    29  	}
    30  
    31  	// OrganizationUserInfo is a struct that represents a user in an organization.
    32  	OrganizationUserInfo struct {
    33  		// UserEmail is the email of the user.
    34  		UserEmail string `json:"user_email"`
    35  		// RealName is the real name of the user.
    36  		RealName string `json:"real_name"`
    37  		// State is the state of the user.
    38  		State string `json:"state"`
    39  		// JobTitle is the job title of the user.
    40  		JobTitle string `json:"job_title"`
    41  		// Country is the country of the user.
    42  		Country string `json:"country"`
    43  		// Department is the department of the user.
    44  		Department string `json:"department"`
    45  	}
    46  )
    47  
    48  // List returns a list of all organization user invitations.
    49  func (h *OrganizationUserHandler) List(id string) (*OrganizationUserList, error) {
    50  	path := buildPath("organization", id, "user")
    51  
    52  	bts, err := h.client.doGetRequest(path, nil)
    53  	if err != nil {
    54  		return nil, err
    55  	}
    56  
    57  	var r OrganizationUserList
    58  
    59  	return &r, checkAPIResponse(bts, &r)
    60  }
    61  
    62  // Get returns a single organization user invitation.
    63  func (h *OrganizationUserHandler) Get(id, userID string) (*OrganizationMemberInfo, error) {
    64  	path := buildPath("organization", id, "user", userID)
    65  
    66  	bts, err := h.client.doGetRequest(path, nil)
    67  	if err != nil {
    68  		return nil, err
    69  	}
    70  
    71  	var r OrganizationMemberInfo
    72  
    73  	return &r, checkAPIResponse(bts, &r)
    74  }
    75  
    76  // Delete deletes a single organization user invitation.
    77  func (h *OrganizationUserHandler) Delete(id, userID string) error {
    78  	path := buildPath("organization", id, "user", userID)
    79  
    80  	bts, err := h.client.doDeleteRequest(path, nil)
    81  	if err != nil {
    82  		return err
    83  	}
    84  
    85  	return checkAPIResponse(bts, nil)
    86  }