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 41c6c73 commit b31e2ca
Show file tree
Hide file tree
Showing 15 changed files with 43 additions and 312 deletions.
7 changes: 0 additions & 7 deletions .vscode/launch.json

This file was deleted.

231 changes: 0 additions & 231 deletions HOWTO.md

This file was deleted.

5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,4 @@ You can manage your apps here https://developers.facebook.com/apps/
From Whatsapp Developer Dashboard you can try and send a test message to your phone number.
to be sure that everything is working fine before you start using this api.

When all the above is done you can start using this api.


Head over to [HOWTO](/HOWTO.md) file
When all the above is done you can start using this api.
52 changes: 0 additions & 52 deletions http/response.go

This file was deleted.

3 changes: 0 additions & 3 deletions internal/client/client.go

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
50 changes: 41 additions & 9 deletions http/http.go → pkg/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,13 +317,6 @@ type (
Password string
}

// requestNameKey is a type that holds the name of a request. This is usually passed
// extracted from Request.Context.Name and passed down to the Do function.
// then passed down with to the request hooks. In request hooks, the name can be
// used to identify the request and other multiple use cases like instrumentation,
// logging etc.
requestNameKey string

// Request is a struct that holds the details that can be used to make a http request.
// It is used by the Do function to make a request.
// It contains Payload which is an interface that can be used to pass any data type
Expand Down Expand Up @@ -604,15 +597,24 @@ func extractRequestBody(payload interface{}) (io.Reader, error) {
}
}

// requestNameKey is a type that holds the name of a request. This is usually passed
// extracted from Request.Context.Name and passed down to the Do function.
// then passed down with to the request hooks. In request hooks, the name can be
// used to identify the request and other multiple use cases like instrumentation,
// logging etc.
type requestNameKey string

const requestNameValue = "request-name"

// withRequestName takes a string and a context and returns a new context with the string
// as the request name.
func withRequestName(ctx context.Context, name string) context.Context {
return context.WithValue(ctx, requestNameKey("request-name"), name)
return context.WithValue(ctx, requestNameKey(requestNameValue), name)
}

// RequestNameFromContext returns the request name from the context.
func RequestNameFromContext(ctx context.Context) string {
name, ok := ctx.Value(requestNameKey("request-name")).(string)
name, ok := ctx.Value(requestNameKey(requestNameValue)).(string)
if !ok {
return "unknown request name"
}
Expand Down Expand Up @@ -645,3 +647,33 @@ func (e *ResponseError) Error() string {
func (e *ResponseError) Unwrap() error {
return e.Err
}

type (

// ResponseDecoder decodes the response body into the given interface.
ResponseDecoder interface {
DecodeResponse(response *http.Response, v interface{}) error
}

// ResponseDecoderFunc is an adapter to allow the use of ordinary functions as
// response decoders. If f is a function with the appropriate signature,
// ResponseDecoderFunc(f) is a ResponseDecoder that calls f.
ResponseDecoderFunc func(response *http.Response, v interface{}) error

// RawResponseDecoder ...
RawResponseDecoder func(response *http.Response) error
)

// DecodeResponse calls f(response, v).
func (f RawResponseDecoder) DecodeResponse(response *http.Response,
_ interface{},
) error {
return f(response)
}

// DecodeResponse calls f(ctx, response, v).
func (f ResponseDecoderFunc) DecodeResponse(response *http.Response,
v interface{},
) error {
return f(response, v)
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion models/models.go → pkg/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ type (
//
// Template A template (object). Required when type=template. A template object.
//
// Text text (object). Required for text messages. A text objects.
// Text (object). Required for text messages. A text objects.
//
// To string. Required. WhatsApp ID or phone number for the person you want to send a message to.
// See Phone Numbers, Formatting for more information. If needed, On-Premises API users can get this number by
Expand Down
File renamed without changes.
Loading

0 comments on commit b31e2ca

Please sign in to comment.