-
Notifications
You must be signed in to change notification settings - Fork 55
chore: review context changes #290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
manisha1997
wants to merge
12
commits into
main
Choose a base branch
from
introduce-context-preview
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7305224
feat: Introduce Context
manisha1997 a3fd1a4
feat: Introduce Context
manisha1997 f30cccf
chore: Introduce context
manisha1997 34b0dc3
chore: Introduce context
manisha1997 970ec00
Merge branch 'main' into introduce-context
manisha1997 78ccbce
chore: add context to request handler
manisha1997 3f9b6c2
chore: add context to request handler
manisha1997 3ed211d
chore: review context changes
manisha1997 efc9671
chore: add context to request handler
manisha1997 d421058
chore: add context to request handler
manisha1997 e7685ba
chore: add context to request handler
manisha1997 36a3c4c
chore: add context to request handler
manisha1997 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| package client | ||
|
|
||
| import ( | ||
| "context" | ||
| "net/http" | ||
| "net/url" | ||
| "os" | ||
|
|
@@ -12,25 +13,18 @@ type RequestHandler struct { | |
| Client BaseClient | ||
| Edge string | ||
| Region string | ||
| ctx context.Context | ||
| } | ||
|
|
||
| func NewRequestHandler(client BaseClient) *RequestHandler { | ||
| return &RequestHandler{ | ||
| Client: client, | ||
| Edge: os.Getenv("TWILIO_EDGE"), | ||
| Region: os.Getenv("TWILIO_REGION"), | ||
| ctx: context.TODO(), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see where we use this, it makes me nervous that we're using this here |
||
| } | ||
| } | ||
|
|
||
| func (c *RequestHandler) sendRequest(method string, rawURL string, data url.Values, | ||
| headers map[string]interface{}, body ...byte) (*http.Response, error) { | ||
| parsedURL, err := c.BuildUrl(rawURL) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return c.Client.SendRequest(method, parsedURL, data, headers, body...) | ||
| } | ||
|
|
||
| // BuildUrl builds the target host string taking into account region and edge configurations. | ||
| func (c *RequestHandler) BuildUrl(rawURL string) (string, error) { | ||
| u, err := url.Parse(rawURL) | ||
|
|
@@ -82,22 +76,22 @@ func (c *RequestHandler) BuildUrl(rawURL string) (string, error) { | |
| return u.String(), nil | ||
| } | ||
|
|
||
| func (c *RequestHandler) Post(path string, bodyData url.Values, headers map[string]interface{}, body ...byte) (*http.Response, error) { | ||
| return c.sendRequest(http.MethodPost, path, bodyData, headers, body...) | ||
| func (c *RequestHandler) PostWithContext(ctx context.Context, path string, bodyData url.Values, headers map[string]interface{}, body ...byte) (*http.Response, error) { | ||
| return c.Client.SendRequestWithContext(ctx, http.MethodPost, path, bodyData, headers, body...) | ||
| } | ||
|
|
||
| func (c *RequestHandler) Put(path string, bodyData url.Values, headers map[string]interface{}, body ...byte) (*http.Response, error) { | ||
| return c.sendRequest(http.MethodPut, path, bodyData, headers, body...) | ||
| func (c *RequestHandler) PutWithContext(ctx context.Context, path string, bodyData url.Values, headers map[string]interface{}, body ...byte) (*http.Response, error) { | ||
| return c.Client.SendRequestWithContext(ctx, http.MethodPut, path, bodyData, headers, body...) | ||
| } | ||
|
|
||
| func (c *RequestHandler) Patch(path string, bodyData url.Values, headers map[string]interface{}, body ...byte) (*http.Response, error) { | ||
| return c.sendRequest(http.MethodPatch, path, bodyData, headers, body...) | ||
| func (c *RequestHandler) PatchWithContext(ctx context.Context, path string, bodyData url.Values, headers map[string]interface{}, body ...byte) (*http.Response, error) { | ||
| return c.Client.SendRequestWithContext(ctx, http.MethodPatch, path, bodyData, headers, body...) | ||
| } | ||
|
|
||
| func (c *RequestHandler) Get(path string, queryData url.Values, headers map[string]interface{}) (*http.Response, error) { | ||
| return c.sendRequest(http.MethodGet, path, queryData, headers) | ||
| func (c *RequestHandler) GetWithContext(ctx context.Context, path string, queryData url.Values, headers map[string]interface{}) (*http.Response, error) { | ||
| return c.Client.SendRequestWithContext(ctx, http.MethodGet, path, queryData, headers) | ||
| } | ||
|
|
||
| func (c *RequestHandler) Delete(path string, queryData url.Values, headers map[string]interface{}) (*http.Response, error) { | ||
| return c.sendRequest(http.MethodDelete, path, queryData, headers) | ||
| func (c *RequestHandler) DeleteWithContext(ctx context.Context, path string, queryData url.Values, headers map[string]interface{}) (*http.Response, error) { | ||
| return c.Client.SendRequestWithContext(ctx, http.MethodDelete, path, queryData, headers) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,3 +37,10 @@ func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { | |
| func NewApiServiceWithClient(client twilio.BaseClient) *ApiService { | ||
| return NewApiService(twilio.NewRequestHandler(client)) | ||
| } | ||
|
|
||
| func NewApiServiceWithCtx(requestHandler *twilio.RequestHandler) *ApiService { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure we need this method |
||
| return &ApiService{ | ||
| requestHandler: requestHandler, | ||
| baseURL: "https://accounts.twilio.com", | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For all of these - TODO is "we plan to add context later" but there's no way for us to do that.