Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
piusalfred committed Dec 24, 2023
1 parent 920ee02 commit 3423991
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions pkg/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (

const (
BaseURL = "https://graph.facebook.com"
DefaultApiVersion = "v16.0" // This is the lowest version of the API that is supported
DefaultAPIVersion = "v16.0" // This is the lowest version of the API that is supported
)

type (
Expand Down Expand Up @@ -390,7 +390,7 @@ func MakeRequest(options ...RequestOption) *Request {
request := &Request{
Context: &RequestContext{
BaseURL: BaseURL,
ApiVersion: DefaultApiVersion,
ApiVersion: DefaultAPIVersion,
},
Method: http.MethodPost,
Headers: map[string]string{"Content-Type": "application/json"},
Expand Down
24 changes: 12 additions & 12 deletions qr.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,19 @@ type (
}
)

func (c *BaseClient) CreateQR(ctx context.Context, rtx *RequestContext,
func (c *BaseClient) CreateQR(ctx context.Context, rtx *whttp.RequestContext,
req *CreateRequest,
) (*CreateResponse, error) {
queryParams := map[string]string{
"prefilled_message": req.PrefilledMessage,
"generate_qr_image": string(req.ImageFormat),
"access_token": rtx.AccessToken,
"access_token": rtx.Bearer,
}
reqCtx := &whttp.RequestContext{
Name: "create qr code",
BaseURL: rtx.BaseURL,
ApiVersion: rtx.ApiVersion,
PhoneNumberID: rtx.PhoneID,
PhoneNumberID: rtx.PhoneNumberID,
Endpoints: []string{"message_qrdls"},
}
params := &whttp.Request{
Expand Down Expand Up @@ -126,7 +126,7 @@ type RequestContext struct {

var ErrNoDataFound = fmt.Errorf("no data found")

func (c *BaseClient) Get(ctx context.Context, request *RequestContext, qrCodeID string,
func (c *BaseClient) Get(ctx context.Context, request *whttp.RequestContext, qrCodeID string,
) (*Information, error) {
var (
list ListResponse
Expand All @@ -136,14 +136,14 @@ func (c *BaseClient) Get(ctx context.Context, request *RequestContext, qrCodeID
Name: "get qr code",
BaseURL: request.BaseURL,
ApiVersion: request.ApiVersion,
PhoneNumberID: request.PhoneID,
PhoneNumberID: request.PhoneNumberID,
Endpoints: []string{"message_qrdls", qrCodeID},
}

req := &whttp.Request{
Context: reqCtx,
Method: http.MethodGet,
Query: map[string]string{"access_token": request.AccessToken},
Query: map[string]string{"access_token": request.Bearer},
}

err := c.base.Do(ctx, req, &list)
Expand All @@ -160,14 +160,14 @@ func (c *BaseClient) Get(ctx context.Context, request *RequestContext, qrCodeID
return &resp, nil
}

func (c *BaseClient) UpdateQR(ctx context.Context, rtx *RequestContext, qrCodeID string,
func (c *BaseClient) UpdateQR(ctx context.Context, rtx *whttp.RequestContext, qrCodeID string,
req *CreateRequest) (*SuccessResponse, error,
) {
reqCtx := &whttp.RequestContext{
Name: "update qr code",
BaseURL: rtx.BaseURL,
ApiVersion: rtx.ApiVersion,
PhoneNumberID: rtx.PhoneID,
PhoneNumberID: rtx.PhoneNumberID,
Endpoints: []string{"message_qrdls", qrCodeID},
}

Expand All @@ -177,7 +177,7 @@ func (c *BaseClient) UpdateQR(ctx context.Context, rtx *RequestContext, qrCodeID
Query: map[string]string{
"prefilled_message": req.PrefilledMessage,
"generate_qr_image": string(req.ImageFormat),
"access_token": rtx.AccessToken,
"access_token": rtx.Bearer,
},
}

Expand All @@ -190,20 +190,20 @@ func (c *BaseClient) UpdateQR(ctx context.Context, rtx *RequestContext, qrCodeID
return &resp, nil
}

func (c *BaseClient) DeleteQR(ctx context.Context, rtx *RequestContext, qrCodeID string,
func (c *BaseClient) DeleteQR(ctx context.Context, rtx *whttp.RequestContext, qrCodeID string,
) (*SuccessResponse, error) {
reqCtx := &whttp.RequestContext{
Name: "delete qr code",
BaseURL: rtx.BaseURL,
ApiVersion: rtx.ApiVersion,
PhoneNumberID: rtx.PhoneID,
PhoneNumberID: rtx.PhoneNumberID,
Endpoints: []string{"message_qrdls", qrCodeID},
}

req := &whttp.Request{
Context: reqCtx,
Method: http.MethodDelete,
Query: map[string]string{"access_token": rtx.AccessToken},
Query: map[string]string{"access_token": rtx.Bearer},
}
var resp SuccessResponse
err := c.base.Do(ctx, req, &resp)
Expand Down

0 comments on commit 3423991

Please sign in to comment.