Skip to content

Commit

Permalink
refactor client
Browse files Browse the repository at this point in the history
  • Loading branch information
piusalfred committed Aug 12, 2023
1 parent eafdc2f commit 6f41951
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
4 changes: 1 addition & 3 deletions qrcodes/qr.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import (
whttp "github.com/piusalfred/whatsapp/http"
)

var ErrUnexpectedResponseCode = fmt.Errorf("unexpected response code")

const (
ImageFormatPNG ImageFormat = "PNG"
ImageFormatSVG ImageFormat = "SVG"
Expand Down Expand Up @@ -95,7 +93,7 @@ func Create(ctx context.Context, client *http.Client, rtx *RequestContext,
return &response, nil
}

func List(ctx context.Context, client *http.Client, rctx *RequestContext, hooks ...whttp.Hook) (*ListResponse, error) {
func List(ctx context.Context, client *gphttp.Client, rctx *RequestContext, hooks ...whttp.Hook) (*ListResponse, error) {
reqCtx := &whttp.RequestContext{
Name: "list qr codes",
BaseURL: rctx.BaseURL,
Expand Down
8 changes: 4 additions & 4 deletions whatsapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ func (client *Client) RequestVerificationCode(ctx context.Context,
Form: map[string]string{"code_method": string(codeMethod), "language": language},
Payload: nil,
}
err := whttp.Do(ctx, client.http, params, nil, client.hooks...)
err := client.http.Do(ctx, params, nil)
if err != nil {
return fmt.Errorf("failed to send request: %w", err)
}
Expand Down Expand Up @@ -584,7 +584,7 @@ func (client *Client) VerifyCode(ctx context.Context, code string) (*StatusRespo
}

var resp StatusResponse
err := whttp.Do(ctx, client.http, params, &resp, client.hooks...)
err := client.http.Do(ctx, params, &resp)
if err != nil {
return nil, fmt.Errorf("failed to send request: %w", err)
}
Expand Down Expand Up @@ -681,7 +681,7 @@ func (client *Client) ListPhoneNumbers(ctx context.Context, filters []*FilterPar
params.Query["filtering"] = string(jsonParams)
}
var phoneNumbersList PhoneNumbersList
err := whttp.Do(ctx, client.http, params, &phoneNumbersList, client.hooks...)
err := client.http.Do(ctx, params, &phoneNumbersList)
if err != nil {
return nil, fmt.Errorf("failed to send request: %w", err)
}
Expand All @@ -706,7 +706,7 @@ func (client *Client) PhoneNumberByID(ctx context.Context) (*PhoneNumber, error)
},
}
var phoneNumber PhoneNumber
if err := whttp.Do(ctx, client.http, request, &phoneNumber, client.hooks...); err != nil {
if err := client.http.Do(ctx, request, &phoneNumber); err != nil {
return nil, fmt.Errorf("get phone muber by id: %w", err)
}

Expand Down

0 comments on commit 6f41951

Please sign in to comment.