github.com/aiven/aiven-go-client@v1.36.0/organization_user_invitations.go (about) 1 // Package aiven provides a client for using the Aiven API. 2 package aiven 3 4 type ( 5 // OrganizationUserInvitationsHandler is the client which interacts with the Organization Invitations API on Aiven. 6 OrganizationUserInvitationsHandler struct { 7 // client is the API client to use. 8 client *Client 9 } 10 11 // OrganizationUserInvitationsList is a response from Aiven for a list of organization user invitations. 12 OrganizationUserInvitationsList struct { 13 APIResponse 14 15 // Invitations is a list of organization user invitations. 16 Invitations []OrganizationUserInvitationInfo `json:"invitations"` 17 } 18 19 // OrganizationUserInvitationInfo is a response from Aiven for a single organization user invitation. 20 OrganizationUserInvitationInfo struct { 21 // UserEmail is the email of the user that was invited to the organization. 22 UserEmail string `json:"user_email"` 23 // InvitedBy is the email of the user that invited the user to the organization. 24 InvitedBy *string `json:"invited_by,omitempty"` 25 // CreateTime is the time when the invitation was created. 26 CreateTime string `json:"create_time"` 27 // ExpiryTime is the time when the invitation expires. 28 ExpiryTime string `json:"expiry_time"` 29 } 30 31 // OrganizationUserInvitationAddRequest are the parameters to add an organization user invitation. 32 OrganizationUserInvitationAddRequest struct { 33 // UserEmail is the email of the user to invite to the organization. 34 UserEmail string `json:"user_email"` 35 } 36 ) 37 38 // List returns a list of all organization user invitations. 39 func (h *OrganizationUserInvitationsHandler) List(id string) (*OrganizationUserInvitationsList, error) { 40 path := buildPath("organization", id, "invitation") 41 42 bts, err := h.client.doGetRequest(path, nil) 43 if err != nil { 44 return nil, err 45 } 46 47 var r OrganizationUserInvitationsList 48 49 return &r, checkAPIResponse(bts, &r) 50 } 51 52 // Invite invites a user to the organization. 53 func (h *OrganizationUserInvitationsHandler) Invite(id string, req OrganizationUserInvitationAddRequest) error { 54 path := buildPath("organization", id, "invitation") 55 56 bts, err := h.client.doPostRequest(path, req) 57 if err != nil { 58 return err 59 } 60 61 return checkAPIResponse(bts, nil) 62 } 63 64 // Delete deletes an organization user invitation. 65 func (h *OrganizationUserInvitationsHandler) Delete(id, userEmail string) error { 66 path := buildPath("organization", id, "invitation", userEmail) 67 68 bts, err := h.client.doDeleteRequest(path, nil) 69 if err != nil { 70 return err 71 } 72 73 return checkAPIResponse(bts, nil) 74 }