github.com/clerkinc/clerk-sdk-go@v1.49.1/clerk/allowlists.go (about)

     1  package clerk
     2  
     3  import "net/http"
     4  
     5  type AllowlistsService service
     6  
     7  type AllowlistIdentifierResponse struct {
     8  	Object         string `json:"object"`
     9  	ID             string `json:"id"`
    10  	InvitationID   string `json:"invitation_id,omitempty"`
    11  	Identifier     string `json:"identifier"`
    12  	IdentifierType string `json:"identifier_type"`
    13  	CreatedAt      int64  `json:"created_at"`
    14  	UpdatedAt      int64  `json:"updated_at"`
    15  }
    16  
    17  type CreateAllowlistIdentifierParams struct {
    18  	Identifier string `json:"identifier"`
    19  	Notify     bool   `json:"notify"`
    20  }
    21  
    22  func (s *AllowlistsService) CreateIdentifier(params CreateAllowlistIdentifierParams) (*AllowlistIdentifierResponse, error) {
    23  	req, _ := s.client.NewRequest(http.MethodPost, AllowlistsUrl, &params)
    24  
    25  	var allowlistIdentifierResponse AllowlistIdentifierResponse
    26  	_, err := s.client.Do(req, &allowlistIdentifierResponse)
    27  	if err != nil {
    28  		return nil, err
    29  	}
    30  	return &allowlistIdentifierResponse, nil
    31  }
    32  
    33  func (s *AllowlistsService) DeleteIdentifier(identifierID string) (*DeleteResponse, error) {
    34  	req, _ := s.client.NewRequest(http.MethodDelete, AllowlistsUrl+"/"+identifierID)
    35  
    36  	var deleteResponse DeleteResponse
    37  	_, err := s.client.Do(req, &deleteResponse)
    38  	if err != nil {
    39  		return nil, err
    40  	}
    41  	return &deleteResponse, nil
    42  }
    43  
    44  type AllowlistIdentifiersResponse struct {
    45  	Data       []*AllowlistIdentifierResponse `json:"data"`
    46  	TotalCount int64                          `json:"total_count"`
    47  }
    48  
    49  func (s *AllowlistsService) ListAllIdentifiers() (*AllowlistIdentifiersResponse, error) {
    50  	req, _ := s.client.NewRequest(http.MethodGet, AllowlistsUrl)
    51  
    52  	var allowlistIdentifiersResponse []*AllowlistIdentifierResponse
    53  	_, err := s.client.Do(req, &allowlistIdentifiersResponse)
    54  	if err != nil {
    55  		return nil, err
    56  	}
    57  	return &AllowlistIdentifiersResponse{
    58  		Data:       allowlistIdentifiersResponse,
    59  		TotalCount: int64(len(allowlistIdentifiersResponse)),
    60  	}, nil
    61  }