diff --git a/client/history.go b/client/history.go index 1cdc8e1..0aa0594 100644 --- a/client/history.go +++ b/client/history.go @@ -254,7 +254,7 @@ func (c Client) GetHistoryItemList(ctx context.Context) ([]types.HistoryItemList if jerr != nil { return []types.HistoryItemList{}, jerr } - return []types.HistoryItemList{}, err + return history.History, err default: return []types.HistoryItemList{}, errors.Join(err, ErrUnspecified) diff --git a/client/user.go b/client/user.go index 430037b..a0e2b6e 100644 --- a/client/user.go +++ b/client/user.go @@ -2,16 +2,57 @@ package client import ( "context" + "encoding/json" + "errors" "net/http" - "strings" + + "github.com/taigrr/elevenlabs/client/types" ) -func (c Client) GetUserInfoV1UserGet(ctx context.Context) (UserResponseModel, *http.Response, error) { - localVarHttpMethod = strings.ToUpper("Get") - localVarPath := a.client.cfg.BasePath + "/v1/user" +func (c Client) GetUserInfo(ctx context.Context) (types.UserResponseModel, error) { + url := c.endpoint + "/v1/user" + client := &http.Client{} + req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) + if err != nil { + return types.UserResponseModel{}, err + } + req.Header.Set("xi-api-key", c.apiKey) + req.Header.Set("User-Agent", "github.com/taigrr/elevenlabs") + req.Header.Set("accept", "application/json") + res, err := client.Do(req) + + switch res.StatusCode { + case 422: + ve := types.ValidationError{} + defer res.Body.Close() + jerr := json.NewDecoder(res.Body).Decode(&ve) + if jerr != nil { + err = errors.Join(err, jerr) + } else { + err = errors.Join(err, ve) + } + return types.UserResponseModel{}, err + case 401: + return types.UserResponseModel{}, ErrUnauthorized + case 200: + if err != nil { + return types.UserResponseModel{}, err + } + + var user types.UserResponseModel + defer res.Body.Close() + jerr := json.NewDecoder(res.Body).Decode(&user) + if jerr != nil { + return types.UserResponseModel{}, jerr + } + return user, err + + default: + return types.UserResponseModel{}, errors.Join(err, ErrUnspecified) + } } -func (c Client) GetSubscriptionInfo(ctx context.Context) error { - localVarHttpMethod = strings.ToUpper("Get") - localVarPath := a.client.cfg.BasePath + "/v1/user/subscription" +func (c Client) GetSubscriptionInfo(ctx context.Context) (types.Subscription, error) { + info, err := c.GetUserInfo(ctx) + return info.Subscription, err } diff --git a/client/voices.go b/client/voices.go index 9057362..f362802 100644 --- a/client/voices.go +++ b/client/voices.go @@ -7,42 +7,42 @@ import ( "strings" ) -func (c Client) AddVoiceV1VoicesAddPost(ctx context.Context, name string, files []*os.File, description string, labels string, localVarOptionals *VoicesApiAddVoiceV1VoicesAddPostOpts) (AddVoiceResponseModel, *http.Response, error) { +func (c Client) CreateVoice(ctx context.Context, name string, files []*os.File, description string, labels string) (AddVoiceResponseModel, *http.Response, error) { localVarHttpMethod = strings.ToUpper("Post") localVarPath := a.client.cfg.BasePath + "/v1/voices/add" } -func (c Client) DeleteVoiceV1VoicesVoiceIdDelete(ctx context.Context, voiceId string, localVarOptionals *VoicesApiDeleteVoiceV1VoicesVoiceIdDeleteOpts) (Object, *http.Response, error) { +func (c Client) DeleteVoice(ctx context.Context, voiceId string) (Object, *http.Response, error) { localVarHttpMethod = strings.ToUpper("Delete") localVarPath := a.client.cfg.BasePath + "/v1/voices/{voice_id}" } -func (c Client) EditVoiceSettingsV1VoicesVoiceIdSettingsEditPost(ctx context.Context, body Settings, voiceId string, localVarOptionals *VoicesApiEditVoiceSettingsV1VoicesVoiceIdSettingsEditPostOpts) (Object, *http.Response, error) { +func (c Client) EditVoiceSettings(ctx context.Context, body Settings, voiceId string) (Object, *http.Response, error) { localVarHttpMethod = strings.ToUpper("Post") localVarPath := a.client.cfg.BasePath + "/v1/voices/{voice_id}/settings/edit" } -func (c Client) EditVoiceV1VoicesVoiceIdEditPost(ctx context.Context, name string, files []*os.File, description string, labels string, voiceId string, localVarOptionals *VoicesApiEditVoiceV1VoicesVoiceIdEditPostOpts) (Object, *http.Response, error) { +func (c Client) EditVoice(ctx context.Context, name string, files []*os.File, description string, labels string, voiceId string) (Object, *http.Response, error) { localVarHttpMethod = strings.ToUpper("Post") localVarPath := a.client.cfg.BasePath + "/v1/voices/{voice_id}/edit" } -func (c Client) GetDefaultVoiceSettingsV1VoicesSettingsDefaultGet(ctx context.Context) (VoiceSettingsResponseModel, *http.Response, error) { +func (c Client) DefaultVoiceSettings(ctx context.Context) (VoiceSettingsResponseModel, *http.Response, error) { localVarHttpMethod = strings.ToUpper("Get") localVarPath := a.client.cfg.BasePath + "/v1/voices/settings/default" } -func (c Client) GetVoiceSettingsV1VoicesVoiceIdSettingsGet(ctx context.Context, voiceId string, localVarOptionals *VoicesApiGetVoiceSettingsV1VoicesVoiceIdSettingsGetOpts) (VoiceSettingsResponseModel, *http.Response, error) { +func (c Client) GetVoiceSettings(ctx context.Context, voiceId string) (VoiceSettingsResponseModel, *http.Response, error) { localVarHttpMethod = strings.ToUpper("Get") localVarPath := a.client.cfg.BasePath + "/v1/voices/{voice_id}/settings" } -func (c Client) GetVoiceV1VoicesVoiceIdGet(ctx context.Context, voiceId string, localVarOptionals *VoicesApiGetVoiceV1VoicesVoiceIdGetOpts) (VoiceResponseModel, *http.Response, error) { +func (c Client) GetVoice(ctx context.Context, voiceId string) (VoiceResponseModel, *http.Response, error) { localVarHttpMethod = strings.ToUpper("Get") localVarPath := a.client.cfg.BasePath + "/v1/voices/{voice_id}" } -func (c Client) GetVoicesV1VoicesGet(ctx context.Context, localVarOptionals *VoicesApiGetVoicesV1VoicesGetOpts) (GetVoicesResponseModel, *http.Response, error) { +func (c Client) GetVoices(ctx context.Context) (GetVoicesResponseModel, *http.Response, error) { localVarHttpMethod = strings.ToUpper("Get") localVarPath := a.client.cfg.BasePath + "/v1/voices" }