diff --git a/client/base_client.go b/client/base_client.go index 6e84a19cd..f511985ea 100644 --- a/client/base_client.go +++ b/client/base_client.go @@ -1,6 +1,7 @@ package client import ( + "context" "net/http" "net/url" "time" @@ -13,4 +14,6 @@ type BaseClient interface { headers map[string]interface{}, body ...byte) (*http.Response, error) SetOauth(auth OAuth) OAuth() OAuth + SendRequestWithContext(ctx context.Context, method string, rawURL string, data url.Values, + headers map[string]interface{}, body ...byte) (*http.Response, error) } diff --git a/client/client.go b/client/client.go index d4b58ace9..1222302e2 100644 --- a/client/client.go +++ b/client/client.go @@ -140,6 +140,12 @@ var userAgentOnce sync.Once func (c *Client) SendRequest(method string, rawURL string, data url.Values, headers map[string]interface{}, body ...byte) (*http.Response, error) { + return c.SendRequestWithContext(context.TODO(), method, rawURL, data, headers, body...) +} + +func (c *Client) SendRequestWithContext(ctx context.Context, method string, rawURL string, data url.Values, + headers map[string]interface{}, body ...byte) (*http.Response, error) { + contentType := extractContentTypeHeader(headers) u, err := url.Parse(rawURL) @@ -167,7 +173,7 @@ func (c *Client) SendRequest(method string, rawURL string, data url.Values, //data is already processed and information will be added to u(the url) in the //previous step. Now body will solely contain json payload if contentType == jsonContentType { - req, err = http.NewRequest(method, u.String(), bytes.NewBuffer(body)) + req, err = http.NewRequestWithContext(ctx, method, u.String(), bytes.NewBuffer(body)) if err != nil { return nil, err } @@ -177,7 +183,7 @@ func (c *Client) SendRequest(method string, rawURL string, data url.Values, if method == http.MethodPost || method == http.MethodPut || method == http.MethodPatch { valueReader = strings.NewReader(data.Encode()) } - req, err = http.NewRequestWithContext(context.Background(), method, u.String(), valueReader) + req, err = http.NewRequestWithContext(ctx, method, u.String(), valueReader) if err != nil { return nil, err } @@ -203,7 +209,7 @@ func (c *Client) SendRequest(method string, rawURL string, data url.Values, } if c.OAuth() != nil { oauth := c.OAuth() - token, _ := c.OAuth().GetAccessToken(context.TODO()) + token, _ := c.OAuth().GetAccessToken(ctx) if token != "" { req.Header.Add("Authorization", "Bearer "+token) } diff --git a/client/page_util.go b/client/page_util.go index a9b722f71..ba295d645 100644 --- a/client/page_util.go +++ b/client/page_util.go @@ -1,6 +1,7 @@ package client import ( + "context" "encoding/json" "fmt" "strings" @@ -25,13 +26,17 @@ func ReadLimits(pageSize *int, limit *int) int { } } -func GetNext(baseUrl string, response interface{}, getNextPage func(nextPageUri string) (interface{}, error)) (interface{}, error) { +func GetNext(baseUrl string, response interface{}, getNextPage func(ctx context.Context, nextPageUri string) (interface{}, error)) (interface{}, error) { + return GetNextWithContext(context.TODO(), baseUrl, response, getNextPage) +} + +func GetNextWithContext(ctx context.Context, baseUrl string, response interface{}, getNextPage func(ctx context.Context, nextPageUri string) (interface{}, error)) (interface{}, error) { nextPageUrl, err := getNextPageUrl(baseUrl, response) if err != nil { return nil, err } - return getNextPage(nextPageUrl) + return getNextPage(ctx, nextPageUrl) } func toMap(s interface{}) (map[string]interface{}, error) { diff --git a/client/page_util_test.go b/client/page_util_test.go index ebfd85509..490b1c66a 100644 --- a/client/page_util_test.go +++ b/client/page_util_test.go @@ -2,6 +2,7 @@ package client import ( "bytes" + "context" "encoding/json" "io" "net/http" @@ -140,7 +141,7 @@ type testMessage struct { To *string `json:"to,omitempty"` } -func getSomething(nextPageUrl string) (interface{}, error) { +func getSomething(ctx context.Context, nextPageUrl string) (interface{}, error) { return nextPageUrl, nil } @@ -151,11 +152,11 @@ func TestPageUtil_GetNext(t *testing.T) { ps := &testResponse{} _ = json.NewDecoder(response.Body).Decode(ps) - nextPageUrl, err := GetNext(baseUrl, ps, getSomething) + nextPageUrl, err := GetNextWithContext(context.TODO(), baseUrl, ps, getSomething) assert.Equal(t, "https://api.twilio.com/2010-04-01/Accounts/ACXX/Messages.json?From=9999999999&PageNumber=&To=4444444444&PageSize=2&Page=1&PageToken=PASMXX", nextPageUrl) assert.Nil(t, err) - nextPageUrl, err = GetNext(baseUrl, nil, getSomething) + nextPageUrl, err = GetNextWithContext(context.TODO(), baseUrl, nil, getSomething) assert.Empty(t, nextPageUrl) assert.Nil(t, err) } diff --git a/client/request_handler.go b/client/request_handler.go index 5c0fdcb8e..7e1addbb7 100644 --- a/client/request_handler.go +++ b/client/request_handler.go @@ -2,6 +2,7 @@ package client import ( + "context" "net/http" "net/url" "os" @@ -12,6 +13,7 @@ type RequestHandler struct { Client BaseClient Edge string Region string + ctx context.Context } func NewRequestHandler(client BaseClient) *RequestHandler { @@ -19,18 +21,10 @@ func NewRequestHandler(client BaseClient) *RequestHandler { Client: client, Edge: os.Getenv("TWILIO_EDGE"), Region: os.Getenv("TWILIO_REGION"), + ctx: context.TODO(), } } -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) } diff --git a/client/request_handler_test.go b/client/request_handler_test.go index 1756ae521..fb3515ce3 100644 --- a/client/request_handler_test.go +++ b/client/request_handler_test.go @@ -1,6 +1,7 @@ package client_test import ( + "context" "errors" "net/http" "net/http/httptest" @@ -83,7 +84,7 @@ func TestRequestHandler_SendGetRequest(t *testing.T) { defer errorServer.Close() requestHandler := NewRequestHandler("user", "pass") - resp, err := requestHandler.Get(errorServer.URL, nil, nil) //nolint:bodyclose + resp, err := requestHandler.GetWithContext(context.TODO(), errorServer.URL, nil, nil) //nolint:bodyclose twilioError := err.(*client.TwilioRestError) assert.Nil(t, resp) assert.Equal(t, 400, twilioError.Status) @@ -108,7 +109,7 @@ func TestRequestHandler_SendPostRequest(t *testing.T) { defer errorServer.Close() requestHandler := NewRequestHandler("user", "pass") - resp, err := requestHandler.Post(errorServer.URL, nil, nil) //nolint:bodyclose + resp, err := requestHandler.PostWithContext(context.TODO(), errorServer.URL, nil, nil) //nolint:bodyclose twilioError := err.(*client.TwilioRestError) assert.Nil(t, resp) assert.Equal(t, 400, twilioError.Status) diff --git a/cluster_test.go b/cluster_test.go index febf839f0..0d6edf58a 100644 --- a/cluster_test.go +++ b/cluster_test.go @@ -4,6 +4,7 @@ package twilio import ( + "context" "os" "testing" @@ -268,3 +269,26 @@ func TestOrgsScimUerList(t *testing.T) { assert.Nil(t, err) assert.NotNil(t, users) } + +func TestSendingATextWithContext(t *testing.T) { + params := &Api.CreateMessageParams{} + params.SetTo(to) + params.SetFrom(from) + params.SetBody("Hello there") + + resp, err := testClient.Api.CreateMessageWithContext(context.TODO(), params) + assert.Nil(t, err) + assert.NotNil(t, resp) + assert.Equal(t, "Hello there", *resp.Body) + assert.Equal(t, from, *resp.From) + assert.Equal(t, to, *resp.To) +} + +func TestOrgsAccountsListWithContext(t *testing.T) { + listAccounts, err := orgsClient.PreviewIamOrganization.ListOrganizationAccountsWithContext(context.TODO(), orgSid, &PreviewIam.ListOrganizationAccountsParams{}) + assert.Nil(t, err) + assert.NotNil(t, listAccounts) + accounts, err := orgsClient.PreviewIamOrganization.FetchOrganizationAccountWithContext(context.TODO(), orgSid, &PreviewIam.FetchOrganizationAccountParams{PathAccountSid: &accountSidOrgs}) + assert.Nil(t, err) + assert.NotNil(t, accounts) +} diff --git a/go.mod b/go.mod index 80b2e0069..827b4e549 100644 --- a/go.mod +++ b/go.mod @@ -16,6 +16,6 @@ require ( ) retract ( - v1.25.0 // Contains build issue - v1.22.0 // Contains known bug + v1.25.0 // Contains build issue + v1.22.0 // Contains known bug ) diff --git a/rest/accounts/v1/api_service.go b/rest/accounts/v1/api_service.go index 6c6d34b9a..3c4a76128 100644 --- a/rest/accounts/v1/api_service.go +++ b/rest/accounts/v1/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://accounts.twilio.com", + } +} diff --git a/rest/accounts/v1/auth_tokens_promote.go b/rest/accounts/v1/auth_tokens_promote.go index 50c4f8a25..688756d31 100644 --- a/rest/accounts/v1/auth_tokens_promote.go +++ b/rest/accounts/v1/auth_tokens_promote.go @@ -15,12 +15,16 @@ package openapi import ( + "context" "encoding/json" "net/url" ) // Promote the secondary Auth Token to primary. After promoting the new token, all requests to Twilio using your old primary Auth Token will result in an error. func (c *ApiService) UpdateAuthTokenPromotion() (*AccountsV1AuthTokenPromotion, error) { + return c.UpdateAuthTokenPromotionWithContext(context.TODO()) +} +func (c *ApiService) UpdateAuthTokenPromotionWithContext(ctx context.Context) (*AccountsV1AuthTokenPromotion, error) { path := "/v1/AuthTokens/Promote" data := url.Values{} @@ -28,7 +32,7 @@ func (c *ApiService) UpdateAuthTokenPromotion() (*AccountsV1AuthTokenPromotion, "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/accounts/v1/auth_tokens_secondary.go b/rest/accounts/v1/auth_tokens_secondary.go index a99a69193..a25432810 100644 --- a/rest/accounts/v1/auth_tokens_secondary.go +++ b/rest/accounts/v1/auth_tokens_secondary.go @@ -15,12 +15,16 @@ package openapi import ( + "context" "encoding/json" "net/url" ) // Create a new secondary Auth Token func (c *ApiService) CreateSecondaryAuthToken() (*AccountsV1SecondaryAuthToken, error) { + return c.CreateSecondaryAuthTokenWithContext(context.TODO()) +} +func (c *ApiService) CreateSecondaryAuthTokenWithContext(ctx context.Context) (*AccountsV1SecondaryAuthToken, error) { path := "/v1/AuthTokens/Secondary" data := url.Values{} @@ -28,7 +32,7 @@ func (c *ApiService) CreateSecondaryAuthToken() (*AccountsV1SecondaryAuthToken, "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -45,6 +49,9 @@ func (c *ApiService) CreateSecondaryAuthToken() (*AccountsV1SecondaryAuthToken, // Delete the secondary Auth Token from your account func (c *ApiService) DeleteSecondaryAuthToken() error { + return c.DeleteSecondaryAuthTokenWithContext(context.TODO()) +} +func (c *ApiService) DeleteSecondaryAuthTokenWithContext(ctx context.Context) error { path := "/v1/AuthTokens/Secondary" data := url.Values{} @@ -52,7 +59,7 @@ func (c *ApiService) DeleteSecondaryAuthToken() error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } diff --git a/rest/accounts/v1/consents_bulk.go b/rest/accounts/v1/consents_bulk.go index c257c617c..5c2241166 100644 --- a/rest/accounts/v1/consents_bulk.go +++ b/rest/accounts/v1/consents_bulk.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" ) @@ -30,8 +31,10 @@ func (params *CreateBulkConsentsParams) SetItems(Items []map[string]interface{}) return params } -// func (c *ApiService) CreateBulkConsents(params *CreateBulkConsentsParams) (*AccountsV1BulkConsents, error) { + return c.CreateBulkConsentsWithContext(context.TODO(), params) +} +func (c *ApiService) CreateBulkConsentsWithContext(ctx context.Context, params *CreateBulkConsentsParams) (*AccountsV1BulkConsents, error) { path := "/v1/Consents/Bulk" data := url.Values{} @@ -51,7 +54,7 @@ func (c *ApiService) CreateBulkConsents(params *CreateBulkConsentsParams) (*Acco } } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/accounts/v1/contacts_bulk.go b/rest/accounts/v1/contacts_bulk.go index 754bda375..6b527208e 100644 --- a/rest/accounts/v1/contacts_bulk.go +++ b/rest/accounts/v1/contacts_bulk.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" ) @@ -30,8 +31,10 @@ func (params *CreateBulkContactsParams) SetItems(Items []map[string]interface{}) return params } -// func (c *ApiService) CreateBulkContacts(params *CreateBulkContactsParams) (*AccountsV1BulkContacts, error) { + return c.CreateBulkContactsWithContext(context.TODO(), params) +} +func (c *ApiService) CreateBulkContactsWithContext(ctx context.Context, params *CreateBulkContactsParams) (*AccountsV1BulkContacts, error) { path := "/v1/Contacts/Bulk" data := url.Values{} @@ -51,7 +54,7 @@ func (c *ApiService) CreateBulkContacts(params *CreateBulkContactsParams) (*Acco } } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/accounts/v1/credentials_aws.go b/rest/accounts/v1/credentials_aws.go index e52646c03..ec601f362 100644 --- a/rest/accounts/v1/credentials_aws.go +++ b/rest/accounts/v1/credentials_aws.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -48,6 +49,9 @@ func (params *CreateCredentialAwsParams) SetAccountSid(AccountSid string) *Creat // Create a new AWS Credential func (c *ApiService) CreateCredentialAws(params *CreateCredentialAwsParams) (*AccountsV1CredentialAws, error) { + return c.CreateCredentialAwsWithContext(context.TODO(), params) +} +func (c *ApiService) CreateCredentialAwsWithContext(ctx context.Context, params *CreateCredentialAwsParams) (*AccountsV1CredentialAws, error) { path := "/v1/Credentials/AWS" data := url.Values{} @@ -65,7 +69,7 @@ func (c *ApiService) CreateCredentialAws(params *CreateCredentialAwsParams) (*Ac data.Set("AccountSid", *params.AccountSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -82,6 +86,9 @@ func (c *ApiService) CreateCredentialAws(params *CreateCredentialAwsParams) (*Ac // Delete a Credential from your account func (c *ApiService) DeleteCredentialAws(Sid string) error { + return c.DeleteCredentialAwsWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteCredentialAwsWithContext(ctx context.Context, Sid string) error { path := "/v1/Credentials/AWS/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -90,7 +97,7 @@ func (c *ApiService) DeleteCredentialAws(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -102,6 +109,9 @@ func (c *ApiService) DeleteCredentialAws(Sid string) error { // Fetch the AWS credentials specified by the provided Credential Sid func (c *ApiService) FetchCredentialAws(Sid string) (*AccountsV1CredentialAws, error) { + return c.FetchCredentialAwsWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchCredentialAwsWithContext(ctx context.Context, Sid string) (*AccountsV1CredentialAws, error) { path := "/v1/Credentials/AWS/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -110,7 +120,7 @@ func (c *ApiService) FetchCredentialAws(Sid string) (*AccountsV1CredentialAws, e "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -144,6 +154,11 @@ func (params *ListCredentialAwsParams) SetLimit(Limit int) *ListCredentialAwsPar // Retrieve a single page of CredentialAws records from the API. Request is executed immediately. func (c *ApiService) PageCredentialAws(params *ListCredentialAwsParams, pageToken, pageNumber string) (*ListCredentialAwsResponse, error) { + return c.PageCredentialAwsWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of CredentialAws records from the API. Request is executed immediately. +func (c *ApiService) PageCredentialAwsWithContext(ctx context.Context, params *ListCredentialAwsParams, pageToken, pageNumber string) (*ListCredentialAwsResponse, error) { path := "/v1/Credentials/AWS" data := url.Values{} @@ -162,7 +177,7 @@ func (c *ApiService) PageCredentialAws(params *ListCredentialAwsParams, pageToke data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -179,7 +194,12 @@ func (c *ApiService) PageCredentialAws(params *ListCredentialAwsParams, pageToke // Lists CredentialAws records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListCredentialAws(params *ListCredentialAwsParams) ([]AccountsV1CredentialAws, error) { - response, errors := c.StreamCredentialAws(params) + return c.ListCredentialAwsWithContext(context.TODO(), params) +} + +// Lists CredentialAws records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListCredentialAwsWithContext(ctx context.Context, params *ListCredentialAwsParams) ([]AccountsV1CredentialAws, error) { + response, errors := c.StreamCredentialAwsWithContext(ctx, params) records := make([]AccountsV1CredentialAws, 0) for record := range response { @@ -195,6 +215,11 @@ func (c *ApiService) ListCredentialAws(params *ListCredentialAwsParams) ([]Accou // Streams CredentialAws records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamCredentialAws(params *ListCredentialAwsParams) (chan AccountsV1CredentialAws, chan error) { + return c.StreamCredentialAwsWithContext(context.TODO(), params) +} + +// Streams CredentialAws records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamCredentialAwsWithContext(ctx context.Context, params *ListCredentialAwsParams) (chan AccountsV1CredentialAws, chan error) { if params == nil { params = &ListCredentialAwsParams{} } @@ -203,19 +228,19 @@ func (c *ApiService) StreamCredentialAws(params *ListCredentialAwsParams) (chan recordChannel := make(chan AccountsV1CredentialAws, 1) errorChannel := make(chan error, 1) - response, err := c.PageCredentialAws(params, "", "") + response, err := c.PageCredentialAwsWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamCredentialAws(response, params, recordChannel, errorChannel) + go c.streamCredentialAwsWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamCredentialAws(response *ListCredentialAwsResponse, params *ListCredentialAwsParams, recordChannel chan AccountsV1CredentialAws, errorChannel chan error) { +func (c *ApiService) streamCredentialAwsWithContext(ctx context.Context, response *ListCredentialAwsResponse, params *ListCredentialAwsParams, recordChannel chan AccountsV1CredentialAws, errorChannel chan error) { curRecord := 1 for response != nil { @@ -230,7 +255,7 @@ func (c *ApiService) streamCredentialAws(response *ListCredentialAwsResponse, pa } } - record, err := client.GetNext(c.baseURL, response, c.getNextListCredentialAwsResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListCredentialAwsResponseWithContext) if err != nil { errorChannel <- err break @@ -245,11 +270,11 @@ func (c *ApiService) streamCredentialAws(response *ListCredentialAwsResponse, pa close(errorChannel) } -func (c *ApiService) getNextListCredentialAwsResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListCredentialAwsResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -276,6 +301,9 @@ func (params *UpdateCredentialAwsParams) SetFriendlyName(FriendlyName string) *U // Modify the properties of a given Account func (c *ApiService) UpdateCredentialAws(Sid string, params *UpdateCredentialAwsParams) (*AccountsV1CredentialAws, error) { + return c.UpdateCredentialAwsWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateCredentialAwsWithContext(ctx context.Context, Sid string, params *UpdateCredentialAwsParams) (*AccountsV1CredentialAws, error) { path := "/v1/Credentials/AWS/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -288,7 +316,7 @@ func (c *ApiService) UpdateCredentialAws(Sid string, params *UpdateCredentialAws data.Set("FriendlyName", *params.FriendlyName) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/accounts/v1/credentials_public_keys.go b/rest/accounts/v1/credentials_public_keys.go index def5334d4..93dae5b47 100644 --- a/rest/accounts/v1/credentials_public_keys.go +++ b/rest/accounts/v1/credentials_public_keys.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -48,6 +49,9 @@ func (params *CreateCredentialPublicKeyParams) SetAccountSid(AccountSid string) // Create a new Public Key Credential func (c *ApiService) CreateCredentialPublicKey(params *CreateCredentialPublicKeyParams) (*AccountsV1CredentialPublicKey, error) { + return c.CreateCredentialPublicKeyWithContext(context.TODO(), params) +} +func (c *ApiService) CreateCredentialPublicKeyWithContext(ctx context.Context, params *CreateCredentialPublicKeyParams) (*AccountsV1CredentialPublicKey, error) { path := "/v1/Credentials/PublicKeys" data := url.Values{} @@ -65,7 +69,7 @@ func (c *ApiService) CreateCredentialPublicKey(params *CreateCredentialPublicKey data.Set("AccountSid", *params.AccountSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -82,6 +86,9 @@ func (c *ApiService) CreateCredentialPublicKey(params *CreateCredentialPublicKey // Delete a Credential from your account func (c *ApiService) DeleteCredentialPublicKey(Sid string) error { + return c.DeleteCredentialPublicKeyWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteCredentialPublicKeyWithContext(ctx context.Context, Sid string) error { path := "/v1/Credentials/PublicKeys/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -90,7 +97,7 @@ func (c *ApiService) DeleteCredentialPublicKey(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -102,6 +109,9 @@ func (c *ApiService) DeleteCredentialPublicKey(Sid string) error { // Fetch the public key specified by the provided Credential Sid func (c *ApiService) FetchCredentialPublicKey(Sid string) (*AccountsV1CredentialPublicKey, error) { + return c.FetchCredentialPublicKeyWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchCredentialPublicKeyWithContext(ctx context.Context, Sid string) (*AccountsV1CredentialPublicKey, error) { path := "/v1/Credentials/PublicKeys/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -110,7 +120,7 @@ func (c *ApiService) FetchCredentialPublicKey(Sid string) (*AccountsV1Credential "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -144,6 +154,11 @@ func (params *ListCredentialPublicKeyParams) SetLimit(Limit int) *ListCredential // Retrieve a single page of CredentialPublicKey records from the API. Request is executed immediately. func (c *ApiService) PageCredentialPublicKey(params *ListCredentialPublicKeyParams, pageToken, pageNumber string) (*ListCredentialPublicKeyResponse, error) { + return c.PageCredentialPublicKeyWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of CredentialPublicKey records from the API. Request is executed immediately. +func (c *ApiService) PageCredentialPublicKeyWithContext(ctx context.Context, params *ListCredentialPublicKeyParams, pageToken, pageNumber string) (*ListCredentialPublicKeyResponse, error) { path := "/v1/Credentials/PublicKeys" data := url.Values{} @@ -162,7 +177,7 @@ func (c *ApiService) PageCredentialPublicKey(params *ListCredentialPublicKeyPara data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -179,7 +194,12 @@ func (c *ApiService) PageCredentialPublicKey(params *ListCredentialPublicKeyPara // Lists CredentialPublicKey records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListCredentialPublicKey(params *ListCredentialPublicKeyParams) ([]AccountsV1CredentialPublicKey, error) { - response, errors := c.StreamCredentialPublicKey(params) + return c.ListCredentialPublicKeyWithContext(context.TODO(), params) +} + +// Lists CredentialPublicKey records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListCredentialPublicKeyWithContext(ctx context.Context, params *ListCredentialPublicKeyParams) ([]AccountsV1CredentialPublicKey, error) { + response, errors := c.StreamCredentialPublicKeyWithContext(ctx, params) records := make([]AccountsV1CredentialPublicKey, 0) for record := range response { @@ -195,6 +215,11 @@ func (c *ApiService) ListCredentialPublicKey(params *ListCredentialPublicKeyPara // Streams CredentialPublicKey records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamCredentialPublicKey(params *ListCredentialPublicKeyParams) (chan AccountsV1CredentialPublicKey, chan error) { + return c.StreamCredentialPublicKeyWithContext(context.TODO(), params) +} + +// Streams CredentialPublicKey records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamCredentialPublicKeyWithContext(ctx context.Context, params *ListCredentialPublicKeyParams) (chan AccountsV1CredentialPublicKey, chan error) { if params == nil { params = &ListCredentialPublicKeyParams{} } @@ -203,19 +228,19 @@ func (c *ApiService) StreamCredentialPublicKey(params *ListCredentialPublicKeyPa recordChannel := make(chan AccountsV1CredentialPublicKey, 1) errorChannel := make(chan error, 1) - response, err := c.PageCredentialPublicKey(params, "", "") + response, err := c.PageCredentialPublicKeyWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamCredentialPublicKey(response, params, recordChannel, errorChannel) + go c.streamCredentialPublicKeyWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamCredentialPublicKey(response *ListCredentialPublicKeyResponse, params *ListCredentialPublicKeyParams, recordChannel chan AccountsV1CredentialPublicKey, errorChannel chan error) { +func (c *ApiService) streamCredentialPublicKeyWithContext(ctx context.Context, response *ListCredentialPublicKeyResponse, params *ListCredentialPublicKeyParams, recordChannel chan AccountsV1CredentialPublicKey, errorChannel chan error) { curRecord := 1 for response != nil { @@ -230,7 +255,7 @@ func (c *ApiService) streamCredentialPublicKey(response *ListCredentialPublicKey } } - record, err := client.GetNext(c.baseURL, response, c.getNextListCredentialPublicKeyResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListCredentialPublicKeyResponseWithContext) if err != nil { errorChannel <- err break @@ -245,11 +270,11 @@ func (c *ApiService) streamCredentialPublicKey(response *ListCredentialPublicKey close(errorChannel) } -func (c *ApiService) getNextListCredentialPublicKeyResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListCredentialPublicKeyResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -276,6 +301,9 @@ func (params *UpdateCredentialPublicKeyParams) SetFriendlyName(FriendlyName stri // Modify the properties of a given Account func (c *ApiService) UpdateCredentialPublicKey(Sid string, params *UpdateCredentialPublicKeyParams) (*AccountsV1CredentialPublicKey, error) { + return c.UpdateCredentialPublicKeyWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateCredentialPublicKeyWithContext(ctx context.Context, Sid string, params *UpdateCredentialPublicKeyParams) (*AccountsV1CredentialPublicKey, error) { path := "/v1/Credentials/PublicKeys/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -288,7 +316,7 @@ func (c *ApiService) UpdateCredentialPublicKey(Sid string, params *UpdateCredent data.Set("FriendlyName", *params.FriendlyName) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/accounts/v1/safe_list_numbers.go b/rest/accounts/v1/safe_list_numbers.go index 8d27724af..8af32010d 100644 --- a/rest/accounts/v1/safe_list_numbers.go +++ b/rest/accounts/v1/safe_list_numbers.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" ) @@ -32,6 +33,9 @@ func (params *CreateSafelistParams) SetPhoneNumber(PhoneNumber string) *CreateSa // Add a new phone number or phone number 1k prefix to SafeList. func (c *ApiService) CreateSafelist(params *CreateSafelistParams) (*AccountsV1Safelist, error) { + return c.CreateSafelistWithContext(context.TODO(), params) +} +func (c *ApiService) CreateSafelistWithContext(ctx context.Context, params *CreateSafelistParams) (*AccountsV1Safelist, error) { path := "/v1/SafeList/Numbers" data := url.Values{} @@ -43,7 +47,7 @@ func (c *ApiService) CreateSafelist(params *CreateSafelistParams) (*AccountsV1Sa data.Set("PhoneNumber", *params.PhoneNumber) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -71,6 +75,9 @@ func (params *DeleteSafelistParams) SetPhoneNumber(PhoneNumber string) *DeleteSa // Remove a phone number or phone number 1k prefix from SafeList. func (c *ApiService) DeleteSafelist(params *DeleteSafelistParams) error { + return c.DeleteSafelistWithContext(context.TODO(), params) +} +func (c *ApiService) DeleteSafelistWithContext(ctx context.Context, params *DeleteSafelistParams) error { path := "/v1/SafeList/Numbers" data := url.Values{} @@ -82,7 +89,7 @@ func (c *ApiService) DeleteSafelist(params *DeleteSafelistParams) error { data.Set("PhoneNumber", *params.PhoneNumber) } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -105,6 +112,9 @@ func (params *FetchSafelistParams) SetPhoneNumber(PhoneNumber string) *FetchSafe // Check if a phone number or phone number 1k prefix exists in SafeList. func (c *ApiService) FetchSafelist(params *FetchSafelistParams) (*AccountsV1Safelist, error) { + return c.FetchSafelistWithContext(context.TODO(), params) +} +func (c *ApiService) FetchSafelistWithContext(ctx context.Context, params *FetchSafelistParams) (*AccountsV1Safelist, error) { path := "/v1/SafeList/Numbers" data := url.Values{} @@ -116,7 +126,7 @@ func (c *ApiService) FetchSafelist(params *FetchSafelistParams) (*AccountsV1Safe data.Set("PhoneNumber", *params.PhoneNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts.go b/rest/api/v2010/accounts.go index bb95c812b..a1281e354 100644 --- a/rest/api/v2010/accounts.go +++ b/rest/api/v2010/accounts.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -36,6 +37,9 @@ func (params *CreateAccountParams) SetFriendlyName(FriendlyName string) *CreateA // Create a new Twilio Subaccount from the account making the request func (c *ApiService) CreateAccount(params *CreateAccountParams) (*ApiV2010Account, error) { + return c.CreateAccountWithContext(context.TODO(), params) +} +func (c *ApiService) CreateAccountWithContext(ctx context.Context, params *CreateAccountParams) (*ApiV2010Account, error) { path := "/2010-04-01/Accounts.json" data := url.Values{} @@ -47,7 +51,7 @@ func (c *ApiService) CreateAccount(params *CreateAccountParams) (*ApiV2010Accoun data.Set("FriendlyName", *params.FriendlyName) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -64,6 +68,9 @@ func (c *ApiService) CreateAccount(params *CreateAccountParams) (*ApiV2010Accoun // Fetch the account specified by the provided Account Sid func (c *ApiService) FetchAccount(Sid string) (*ApiV2010Account, error) { + return c.FetchAccountWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchAccountWithContext(ctx context.Context, Sid string) (*ApiV2010Account, error) { path := "/2010-04-01/Accounts/{Sid}.json" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -72,7 +79,7 @@ func (c *ApiService) FetchAccount(Sid string) (*ApiV2010Account, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -118,6 +125,11 @@ func (params *ListAccountParams) SetLimit(Limit int) *ListAccountParams { // Retrieve a single page of Account records from the API. Request is executed immediately. func (c *ApiService) PageAccount(params *ListAccountParams, pageToken, pageNumber string) (*ListAccountResponse, error) { + return c.PageAccountWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Account records from the API. Request is executed immediately. +func (c *ApiService) PageAccountWithContext(ctx context.Context, params *ListAccountParams, pageToken, pageNumber string) (*ListAccountResponse, error) { path := "/2010-04-01/Accounts.json" data := url.Values{} @@ -142,7 +154,7 @@ func (c *ApiService) PageAccount(params *ListAccountParams, pageToken, pageNumbe data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -159,7 +171,12 @@ func (c *ApiService) PageAccount(params *ListAccountParams, pageToken, pageNumbe // Lists Account records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListAccount(params *ListAccountParams) ([]ApiV2010Account, error) { - response, errors := c.StreamAccount(params) + return c.ListAccountWithContext(context.TODO(), params) +} + +// Lists Account records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListAccountWithContext(ctx context.Context, params *ListAccountParams) ([]ApiV2010Account, error) { + response, errors := c.StreamAccountWithContext(ctx, params) records := make([]ApiV2010Account, 0) for record := range response { @@ -175,6 +192,11 @@ func (c *ApiService) ListAccount(params *ListAccountParams) ([]ApiV2010Account, // Streams Account records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamAccount(params *ListAccountParams) (chan ApiV2010Account, chan error) { + return c.StreamAccountWithContext(context.TODO(), params) +} + +// Streams Account records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamAccountWithContext(ctx context.Context, params *ListAccountParams) (chan ApiV2010Account, chan error) { if params == nil { params = &ListAccountParams{} } @@ -183,19 +205,19 @@ func (c *ApiService) StreamAccount(params *ListAccountParams) (chan ApiV2010Acco recordChannel := make(chan ApiV2010Account, 1) errorChannel := make(chan error, 1) - response, err := c.PageAccount(params, "", "") + response, err := c.PageAccountWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamAccount(response, params, recordChannel, errorChannel) + go c.streamAccountWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamAccount(response *ListAccountResponse, params *ListAccountParams, recordChannel chan ApiV2010Account, errorChannel chan error) { +func (c *ApiService) streamAccountWithContext(ctx context.Context, response *ListAccountResponse, params *ListAccountParams, recordChannel chan ApiV2010Account, errorChannel chan error) { curRecord := 1 for response != nil { @@ -210,7 +232,7 @@ func (c *ApiService) streamAccount(response *ListAccountResponse, params *ListAc } } - record, err := client.GetNext(c.baseURL, response, c.getNextListAccountResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListAccountResponseWithContext) if err != nil { errorChannel <- err break @@ -225,11 +247,11 @@ func (c *ApiService) streamAccount(response *ListAccountResponse, params *ListAc close(errorChannel) } -func (c *ApiService) getNextListAccountResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListAccountResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -262,6 +284,9 @@ func (params *UpdateAccountParams) SetStatus(Status string) *UpdateAccountParams // Modify the properties of a given Account func (c *ApiService) UpdateAccount(Sid string, params *UpdateAccountParams) (*ApiV2010Account, error) { + return c.UpdateAccountWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateAccountWithContext(ctx context.Context, Sid string, params *UpdateAccountParams) (*ApiV2010Account, error) { path := "/2010-04-01/Accounts/{Sid}.json" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -277,7 +302,7 @@ func (c *ApiService) UpdateAccount(Sid string, params *UpdateAccountParams) (*Ap data.Set("Status", fmt.Sprint(*params.Status)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_addresses.go b/rest/api/v2010/accounts_addresses.go index a1683a419..dcd9b1025 100644 --- a/rest/api/v2010/accounts_addresses.go +++ b/rest/api/v2010/accounts_addresses.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -94,8 +95,10 @@ func (params *CreateAddressParams) SetStreetSecondary(StreetSecondary string) *C return params } -// func (c *ApiService) CreateAddress(params *CreateAddressParams) (*ApiV2010Address, error) { + return c.CreateAddressWithContext(context.TODO(), params) +} +func (c *ApiService) CreateAddressWithContext(ctx context.Context, params *CreateAddressParams) (*ApiV2010Address, error) { path := "/2010-04-01/Accounts/{AccountSid}/Addresses.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -139,7 +142,7 @@ func (c *ApiService) CreateAddress(params *CreateAddressParams) (*ApiV2010Addres data.Set("StreetSecondary", *params.StreetSecondary) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -165,8 +168,10 @@ func (params *DeleteAddressParams) SetPathAccountSid(PathAccountSid string) *Del return params } -// func (c *ApiService) DeleteAddress(Sid string, params *DeleteAddressParams) error { + return c.DeleteAddressWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) DeleteAddressWithContext(ctx context.Context, Sid string, params *DeleteAddressParams) error { path := "/2010-04-01/Accounts/{AccountSid}/Addresses/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -180,7 +185,7 @@ func (c *ApiService) DeleteAddress(Sid string, params *DeleteAddressParams) erro "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -201,8 +206,10 @@ func (params *FetchAddressParams) SetPathAccountSid(PathAccountSid string) *Fetc return params } -// func (c *ApiService) FetchAddress(Sid string, params *FetchAddressParams) (*ApiV2010Address, error) { + return c.FetchAddressWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) FetchAddressWithContext(ctx context.Context, Sid string, params *FetchAddressParams) (*ApiV2010Address, error) { path := "/2010-04-01/Accounts/{AccountSid}/Addresses/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -216,7 +223,7 @@ func (c *ApiService) FetchAddress(Sid string, params *FetchAddressParams) (*ApiV "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -280,6 +287,11 @@ func (params *ListAddressParams) SetLimit(Limit int) *ListAddressParams { // Retrieve a single page of Address records from the API. Request is executed immediately. func (c *ApiService) PageAddress(params *ListAddressParams, pageToken, pageNumber string) (*ListAddressResponse, error) { + return c.PageAddressWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Address records from the API. Request is executed immediately. +func (c *ApiService) PageAddressWithContext(ctx context.Context, params *ListAddressParams, pageToken, pageNumber string) (*ListAddressResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/Addresses.json" if params != nil && params.PathAccountSid != nil { @@ -316,7 +328,7 @@ func (c *ApiService) PageAddress(params *ListAddressParams, pageToken, pageNumbe data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -333,7 +345,12 @@ func (c *ApiService) PageAddress(params *ListAddressParams, pageToken, pageNumbe // Lists Address records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListAddress(params *ListAddressParams) ([]ApiV2010Address, error) { - response, errors := c.StreamAddress(params) + return c.ListAddressWithContext(context.TODO(), params) +} + +// Lists Address records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListAddressWithContext(ctx context.Context, params *ListAddressParams) ([]ApiV2010Address, error) { + response, errors := c.StreamAddressWithContext(ctx, params) records := make([]ApiV2010Address, 0) for record := range response { @@ -349,6 +366,11 @@ func (c *ApiService) ListAddress(params *ListAddressParams) ([]ApiV2010Address, // Streams Address records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamAddress(params *ListAddressParams) (chan ApiV2010Address, chan error) { + return c.StreamAddressWithContext(context.TODO(), params) +} + +// Streams Address records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamAddressWithContext(ctx context.Context, params *ListAddressParams) (chan ApiV2010Address, chan error) { if params == nil { params = &ListAddressParams{} } @@ -357,19 +379,19 @@ func (c *ApiService) StreamAddress(params *ListAddressParams) (chan ApiV2010Addr recordChannel := make(chan ApiV2010Address, 1) errorChannel := make(chan error, 1) - response, err := c.PageAddress(params, "", "") + response, err := c.PageAddressWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamAddress(response, params, recordChannel, errorChannel) + go c.streamAddressWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamAddress(response *ListAddressResponse, params *ListAddressParams, recordChannel chan ApiV2010Address, errorChannel chan error) { +func (c *ApiService) streamAddressWithContext(ctx context.Context, response *ListAddressResponse, params *ListAddressParams, recordChannel chan ApiV2010Address, errorChannel chan error) { curRecord := 1 for response != nil { @@ -384,7 +406,7 @@ func (c *ApiService) streamAddress(response *ListAddressResponse, params *ListAd } } - record, err := client.GetNext(c.baseURL, response, c.getNextListAddressResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListAddressResponseWithContext) if err != nil { errorChannel <- err break @@ -399,11 +421,11 @@ func (c *ApiService) streamAddress(response *ListAddressResponse, params *ListAd close(errorChannel) } -func (c *ApiService) getNextListAddressResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListAddressResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -482,8 +504,10 @@ func (params *UpdateAddressParams) SetStreetSecondary(StreetSecondary string) *U return params } -// func (c *ApiService) UpdateAddress(Sid string, params *UpdateAddressParams) (*ApiV2010Address, error) { + return c.UpdateAddressWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateAddressWithContext(ctx context.Context, Sid string, params *UpdateAddressParams) (*ApiV2010Address, error) { path := "/2010-04-01/Accounts/{AccountSid}/Addresses/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -525,7 +549,7 @@ func (c *ApiService) UpdateAddress(Sid string, params *UpdateAddressParams) (*Ap data.Set("StreetSecondary", *params.StreetSecondary) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_addresses_dependent_phone_numbers.go b/rest/api/v2010/accounts_addresses_dependent_phone_numbers.go index a0ef67222..04a26c2b4 100644 --- a/rest/api/v2010/accounts_addresses_dependent_phone_numbers.go +++ b/rest/api/v2010/accounts_addresses_dependent_phone_numbers.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -48,6 +49,11 @@ func (params *ListDependentPhoneNumberParams) SetLimit(Limit int) *ListDependent // Retrieve a single page of DependentPhoneNumber records from the API. Request is executed immediately. func (c *ApiService) PageDependentPhoneNumber(AddressSid string, params *ListDependentPhoneNumberParams, pageToken, pageNumber string) (*ListDependentPhoneNumberResponse, error) { + return c.PageDependentPhoneNumberWithContext(context.TODO(), AddressSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of DependentPhoneNumber records from the API. Request is executed immediately. +func (c *ApiService) PageDependentPhoneNumberWithContext(ctx context.Context, AddressSid string, params *ListDependentPhoneNumberParams, pageToken, pageNumber string) (*ListDependentPhoneNumberResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/Addresses/{AddressSid}/DependentPhoneNumbers.json" if params != nil && params.PathAccountSid != nil { @@ -73,7 +79,7 @@ func (c *ApiService) PageDependentPhoneNumber(AddressSid string, params *ListDep data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -90,7 +96,12 @@ func (c *ApiService) PageDependentPhoneNumber(AddressSid string, params *ListDep // Lists DependentPhoneNumber records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListDependentPhoneNumber(AddressSid string, params *ListDependentPhoneNumberParams) ([]ApiV2010DependentPhoneNumber, error) { - response, errors := c.StreamDependentPhoneNumber(AddressSid, params) + return c.ListDependentPhoneNumberWithContext(context.TODO(), AddressSid, params) +} + +// Lists DependentPhoneNumber records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListDependentPhoneNumberWithContext(ctx context.Context, AddressSid string, params *ListDependentPhoneNumberParams) ([]ApiV2010DependentPhoneNumber, error) { + response, errors := c.StreamDependentPhoneNumberWithContext(ctx, AddressSid, params) records := make([]ApiV2010DependentPhoneNumber, 0) for record := range response { @@ -106,6 +117,11 @@ func (c *ApiService) ListDependentPhoneNumber(AddressSid string, params *ListDep // Streams DependentPhoneNumber records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamDependentPhoneNumber(AddressSid string, params *ListDependentPhoneNumberParams) (chan ApiV2010DependentPhoneNumber, chan error) { + return c.StreamDependentPhoneNumberWithContext(context.TODO(), AddressSid, params) +} + +// Streams DependentPhoneNumber records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamDependentPhoneNumberWithContext(ctx context.Context, AddressSid string, params *ListDependentPhoneNumberParams) (chan ApiV2010DependentPhoneNumber, chan error) { if params == nil { params = &ListDependentPhoneNumberParams{} } @@ -114,19 +130,19 @@ func (c *ApiService) StreamDependentPhoneNumber(AddressSid string, params *ListD recordChannel := make(chan ApiV2010DependentPhoneNumber, 1) errorChannel := make(chan error, 1) - response, err := c.PageDependentPhoneNumber(AddressSid, params, "", "") + response, err := c.PageDependentPhoneNumberWithContext(ctx, AddressSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamDependentPhoneNumber(response, params, recordChannel, errorChannel) + go c.streamDependentPhoneNumberWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamDependentPhoneNumber(response *ListDependentPhoneNumberResponse, params *ListDependentPhoneNumberParams, recordChannel chan ApiV2010DependentPhoneNumber, errorChannel chan error) { +func (c *ApiService) streamDependentPhoneNumberWithContext(ctx context.Context, response *ListDependentPhoneNumberResponse, params *ListDependentPhoneNumberParams, recordChannel chan ApiV2010DependentPhoneNumber, errorChannel chan error) { curRecord := 1 for response != nil { @@ -141,7 +157,7 @@ func (c *ApiService) streamDependentPhoneNumber(response *ListDependentPhoneNumb } } - record, err := client.GetNext(c.baseURL, response, c.getNextListDependentPhoneNumberResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListDependentPhoneNumberResponseWithContext) if err != nil { errorChannel <- err break @@ -156,11 +172,11 @@ func (c *ApiService) streamDependentPhoneNumber(response *ListDependentPhoneNumb close(errorChannel) } -func (c *ApiService) getNextListDependentPhoneNumberResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListDependentPhoneNumberResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_applications.go b/rest/api/v2010/accounts_applications.go index 31746d94c..08da3bf96 100644 --- a/rest/api/v2010/accounts_applications.go +++ b/rest/api/v2010/accounts_applications.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -132,6 +133,9 @@ func (params *CreateApplicationParams) SetPublicApplicationConnectEnabled(Public // Create a new application within your account func (c *ApiService) CreateApplication(params *CreateApplicationParams) (*ApiV2010Application, error) { + return c.CreateApplicationWithContext(context.TODO(), params) +} +func (c *ApiService) CreateApplicationWithContext(ctx context.Context, params *CreateApplicationParams) (*ApiV2010Application, error) { path := "/2010-04-01/Accounts/{AccountSid}/Applications.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -193,7 +197,7 @@ func (c *ApiService) CreateApplication(params *CreateApplicationParams) (*ApiV20 data.Set("PublicApplicationConnectEnabled", fmt.Sprint(*params.PublicApplicationConnectEnabled)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -221,6 +225,9 @@ func (params *DeleteApplicationParams) SetPathAccountSid(PathAccountSid string) // Delete the application by the specified application sid func (c *ApiService) DeleteApplication(Sid string, params *DeleteApplicationParams) error { + return c.DeleteApplicationWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) DeleteApplicationWithContext(ctx context.Context, Sid string, params *DeleteApplicationParams) error { path := "/2010-04-01/Accounts/{AccountSid}/Applications/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -234,7 +241,7 @@ func (c *ApiService) DeleteApplication(Sid string, params *DeleteApplicationPara "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -257,6 +264,9 @@ func (params *FetchApplicationParams) SetPathAccountSid(PathAccountSid string) * // Fetch the application specified by the provided sid func (c *ApiService) FetchApplication(Sid string, params *FetchApplicationParams) (*ApiV2010Application, error) { + return c.FetchApplicationWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) FetchApplicationWithContext(ctx context.Context, Sid string, params *FetchApplicationParams) (*ApiV2010Application, error) { path := "/2010-04-01/Accounts/{AccountSid}/Applications/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -270,7 +280,7 @@ func (c *ApiService) FetchApplication(Sid string, params *FetchApplicationParams "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -316,6 +326,11 @@ func (params *ListApplicationParams) SetLimit(Limit int) *ListApplicationParams // Retrieve a single page of Application records from the API. Request is executed immediately. func (c *ApiService) PageApplication(params *ListApplicationParams, pageToken, pageNumber string) (*ListApplicationResponse, error) { + return c.PageApplicationWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Application records from the API. Request is executed immediately. +func (c *ApiService) PageApplicationWithContext(ctx context.Context, params *ListApplicationParams, pageToken, pageNumber string) (*ListApplicationResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/Applications.json" if params != nil && params.PathAccountSid != nil { @@ -343,7 +358,7 @@ func (c *ApiService) PageApplication(params *ListApplicationParams, pageToken, p data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -360,7 +375,12 @@ func (c *ApiService) PageApplication(params *ListApplicationParams, pageToken, p // Lists Application records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListApplication(params *ListApplicationParams) ([]ApiV2010Application, error) { - response, errors := c.StreamApplication(params) + return c.ListApplicationWithContext(context.TODO(), params) +} + +// Lists Application records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListApplicationWithContext(ctx context.Context, params *ListApplicationParams) ([]ApiV2010Application, error) { + response, errors := c.StreamApplicationWithContext(ctx, params) records := make([]ApiV2010Application, 0) for record := range response { @@ -376,6 +396,11 @@ func (c *ApiService) ListApplication(params *ListApplicationParams) ([]ApiV2010A // Streams Application records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamApplication(params *ListApplicationParams) (chan ApiV2010Application, chan error) { + return c.StreamApplicationWithContext(context.TODO(), params) +} + +// Streams Application records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamApplicationWithContext(ctx context.Context, params *ListApplicationParams) (chan ApiV2010Application, chan error) { if params == nil { params = &ListApplicationParams{} } @@ -384,19 +409,19 @@ func (c *ApiService) StreamApplication(params *ListApplicationParams) (chan ApiV recordChannel := make(chan ApiV2010Application, 1) errorChannel := make(chan error, 1) - response, err := c.PageApplication(params, "", "") + response, err := c.PageApplicationWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamApplication(response, params, recordChannel, errorChannel) + go c.streamApplicationWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamApplication(response *ListApplicationResponse, params *ListApplicationParams, recordChannel chan ApiV2010Application, errorChannel chan error) { +func (c *ApiService) streamApplicationWithContext(ctx context.Context, response *ListApplicationResponse, params *ListApplicationParams, recordChannel chan ApiV2010Application, errorChannel chan error) { curRecord := 1 for response != nil { @@ -411,7 +436,7 @@ func (c *ApiService) streamApplication(response *ListApplicationResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListApplicationResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListApplicationResponseWithContext) if err != nil { errorChannel <- err break @@ -426,11 +451,11 @@ func (c *ApiService) streamApplication(response *ListApplicationResponse, params close(errorChannel) } -func (c *ApiService) getNextListApplicationResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListApplicationResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -553,6 +578,9 @@ func (params *UpdateApplicationParams) SetPublicApplicationConnectEnabled(Public // Updates the application's properties func (c *ApiService) UpdateApplication(Sid string, params *UpdateApplicationParams) (*ApiV2010Application, error) { + return c.UpdateApplicationWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateApplicationWithContext(ctx context.Context, Sid string, params *UpdateApplicationParams) (*ApiV2010Application, error) { path := "/2010-04-01/Accounts/{AccountSid}/Applications/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -615,7 +643,7 @@ func (c *ApiService) UpdateApplication(Sid string, params *UpdateApplicationPara data.Set("PublicApplicationConnectEnabled", fmt.Sprint(*params.PublicApplicationConnectEnabled)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_authorized_connect_apps.go b/rest/api/v2010/accounts_authorized_connect_apps.go index 49468f523..a9379f3e6 100644 --- a/rest/api/v2010/accounts_authorized_connect_apps.go +++ b/rest/api/v2010/accounts_authorized_connect_apps.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -36,6 +37,9 @@ func (params *FetchAuthorizedConnectAppParams) SetPathAccountSid(PathAccountSid // Fetch an instance of an authorized-connect-app func (c *ApiService) FetchAuthorizedConnectApp(ConnectAppSid string, params *FetchAuthorizedConnectAppParams) (*ApiV2010AuthorizedConnectApp, error) { + return c.FetchAuthorizedConnectAppWithContext(context.TODO(), ConnectAppSid, params) +} +func (c *ApiService) FetchAuthorizedConnectAppWithContext(ctx context.Context, ConnectAppSid string, params *FetchAuthorizedConnectAppParams) (*ApiV2010AuthorizedConnectApp, error) { path := "/2010-04-01/Accounts/{AccountSid}/AuthorizedConnectApps/{ConnectAppSid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -49,7 +53,7 @@ func (c *ApiService) FetchAuthorizedConnectApp(ConnectAppSid string, params *Fet "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -89,6 +93,11 @@ func (params *ListAuthorizedConnectAppParams) SetLimit(Limit int) *ListAuthorize // Retrieve a single page of AuthorizedConnectApp records from the API. Request is executed immediately. func (c *ApiService) PageAuthorizedConnectApp(params *ListAuthorizedConnectAppParams, pageToken, pageNumber string) (*ListAuthorizedConnectAppResponse, error) { + return c.PageAuthorizedConnectAppWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of AuthorizedConnectApp records from the API. Request is executed immediately. +func (c *ApiService) PageAuthorizedConnectAppWithContext(ctx context.Context, params *ListAuthorizedConnectAppParams, pageToken, pageNumber string) (*ListAuthorizedConnectAppResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/AuthorizedConnectApps.json" if params != nil && params.PathAccountSid != nil { @@ -113,7 +122,7 @@ func (c *ApiService) PageAuthorizedConnectApp(params *ListAuthorizedConnectAppPa data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -130,7 +139,12 @@ func (c *ApiService) PageAuthorizedConnectApp(params *ListAuthorizedConnectAppPa // Lists AuthorizedConnectApp records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListAuthorizedConnectApp(params *ListAuthorizedConnectAppParams) ([]ApiV2010AuthorizedConnectApp, error) { - response, errors := c.StreamAuthorizedConnectApp(params) + return c.ListAuthorizedConnectAppWithContext(context.TODO(), params) +} + +// Lists AuthorizedConnectApp records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListAuthorizedConnectAppWithContext(ctx context.Context, params *ListAuthorizedConnectAppParams) ([]ApiV2010AuthorizedConnectApp, error) { + response, errors := c.StreamAuthorizedConnectAppWithContext(ctx, params) records := make([]ApiV2010AuthorizedConnectApp, 0) for record := range response { @@ -146,6 +160,11 @@ func (c *ApiService) ListAuthorizedConnectApp(params *ListAuthorizedConnectAppPa // Streams AuthorizedConnectApp records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamAuthorizedConnectApp(params *ListAuthorizedConnectAppParams) (chan ApiV2010AuthorizedConnectApp, chan error) { + return c.StreamAuthorizedConnectAppWithContext(context.TODO(), params) +} + +// Streams AuthorizedConnectApp records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamAuthorizedConnectAppWithContext(ctx context.Context, params *ListAuthorizedConnectAppParams) (chan ApiV2010AuthorizedConnectApp, chan error) { if params == nil { params = &ListAuthorizedConnectAppParams{} } @@ -154,19 +173,19 @@ func (c *ApiService) StreamAuthorizedConnectApp(params *ListAuthorizedConnectApp recordChannel := make(chan ApiV2010AuthorizedConnectApp, 1) errorChannel := make(chan error, 1) - response, err := c.PageAuthorizedConnectApp(params, "", "") + response, err := c.PageAuthorizedConnectAppWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamAuthorizedConnectApp(response, params, recordChannel, errorChannel) + go c.streamAuthorizedConnectAppWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamAuthorizedConnectApp(response *ListAuthorizedConnectAppResponse, params *ListAuthorizedConnectAppParams, recordChannel chan ApiV2010AuthorizedConnectApp, errorChannel chan error) { +func (c *ApiService) streamAuthorizedConnectAppWithContext(ctx context.Context, response *ListAuthorizedConnectAppResponse, params *ListAuthorizedConnectAppParams, recordChannel chan ApiV2010AuthorizedConnectApp, errorChannel chan error) { curRecord := 1 for response != nil { @@ -181,7 +200,7 @@ func (c *ApiService) streamAuthorizedConnectApp(response *ListAuthorizedConnectA } } - record, err := client.GetNext(c.baseURL, response, c.getNextListAuthorizedConnectAppResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListAuthorizedConnectAppResponseWithContext) if err != nil { errorChannel <- err break @@ -196,11 +215,11 @@ func (c *ApiService) streamAuthorizedConnectApp(response *ListAuthorizedConnectA close(errorChannel) } -func (c *ApiService) getNextListAuthorizedConnectAppResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListAuthorizedConnectAppResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_available_phone_numbers.go b/rest/api/v2010/accounts_available_phone_numbers.go index 70eb92c21..99e383dac 100644 --- a/rest/api/v2010/accounts_available_phone_numbers.go +++ b/rest/api/v2010/accounts_available_phone_numbers.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -34,8 +35,10 @@ func (params *FetchAvailablePhoneNumberCountryParams) SetPathAccountSid(PathAcco return params } -// func (c *ApiService) FetchAvailablePhoneNumberCountry(CountryCode string, params *FetchAvailablePhoneNumberCountryParams) (*ApiV2010AvailablePhoneNumberCountry, error) { + return c.FetchAvailablePhoneNumberCountryWithContext(context.TODO(), CountryCode, params) +} +func (c *ApiService) FetchAvailablePhoneNumberCountryWithContext(ctx context.Context, CountryCode string, params *FetchAvailablePhoneNumberCountryParams) (*ApiV2010AvailablePhoneNumberCountry, error) { path := "/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -49,7 +52,7 @@ func (c *ApiService) FetchAvailablePhoneNumberCountry(CountryCode string, params "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -89,6 +92,11 @@ func (params *ListAvailablePhoneNumberCountryParams) SetLimit(Limit int) *ListAv // Retrieve a single page of AvailablePhoneNumberCountry records from the API. Request is executed immediately. func (c *ApiService) PageAvailablePhoneNumberCountry(params *ListAvailablePhoneNumberCountryParams, pageToken, pageNumber string) (*ListAvailablePhoneNumberCountryResponse, error) { + return c.PageAvailablePhoneNumberCountryWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of AvailablePhoneNumberCountry records from the API. Request is executed immediately. +func (c *ApiService) PageAvailablePhoneNumberCountryWithContext(ctx context.Context, params *ListAvailablePhoneNumberCountryParams, pageToken, pageNumber string) (*ListAvailablePhoneNumberCountryResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers.json" if params != nil && params.PathAccountSid != nil { @@ -113,7 +121,7 @@ func (c *ApiService) PageAvailablePhoneNumberCountry(params *ListAvailablePhoneN data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -130,7 +138,12 @@ func (c *ApiService) PageAvailablePhoneNumberCountry(params *ListAvailablePhoneN // Lists AvailablePhoneNumberCountry records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListAvailablePhoneNumberCountry(params *ListAvailablePhoneNumberCountryParams) ([]ApiV2010AvailablePhoneNumberCountry, error) { - response, errors := c.StreamAvailablePhoneNumberCountry(params) + return c.ListAvailablePhoneNumberCountryWithContext(context.TODO(), params) +} + +// Lists AvailablePhoneNumberCountry records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListAvailablePhoneNumberCountryWithContext(ctx context.Context, params *ListAvailablePhoneNumberCountryParams) ([]ApiV2010AvailablePhoneNumberCountry, error) { + response, errors := c.StreamAvailablePhoneNumberCountryWithContext(ctx, params) records := make([]ApiV2010AvailablePhoneNumberCountry, 0) for record := range response { @@ -146,6 +159,11 @@ func (c *ApiService) ListAvailablePhoneNumberCountry(params *ListAvailablePhoneN // Streams AvailablePhoneNumberCountry records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamAvailablePhoneNumberCountry(params *ListAvailablePhoneNumberCountryParams) (chan ApiV2010AvailablePhoneNumberCountry, chan error) { + return c.StreamAvailablePhoneNumberCountryWithContext(context.TODO(), params) +} + +// Streams AvailablePhoneNumberCountry records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamAvailablePhoneNumberCountryWithContext(ctx context.Context, params *ListAvailablePhoneNumberCountryParams) (chan ApiV2010AvailablePhoneNumberCountry, chan error) { if params == nil { params = &ListAvailablePhoneNumberCountryParams{} } @@ -154,19 +172,19 @@ func (c *ApiService) StreamAvailablePhoneNumberCountry(params *ListAvailablePhon recordChannel := make(chan ApiV2010AvailablePhoneNumberCountry, 1) errorChannel := make(chan error, 1) - response, err := c.PageAvailablePhoneNumberCountry(params, "", "") + response, err := c.PageAvailablePhoneNumberCountryWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamAvailablePhoneNumberCountry(response, params, recordChannel, errorChannel) + go c.streamAvailablePhoneNumberCountryWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamAvailablePhoneNumberCountry(response *ListAvailablePhoneNumberCountryResponse, params *ListAvailablePhoneNumberCountryParams, recordChannel chan ApiV2010AvailablePhoneNumberCountry, errorChannel chan error) { +func (c *ApiService) streamAvailablePhoneNumberCountryWithContext(ctx context.Context, response *ListAvailablePhoneNumberCountryResponse, params *ListAvailablePhoneNumberCountryParams, recordChannel chan ApiV2010AvailablePhoneNumberCountry, errorChannel chan error) { curRecord := 1 for response != nil { @@ -181,7 +199,7 @@ func (c *ApiService) streamAvailablePhoneNumberCountry(response *ListAvailablePh } } - record, err := client.GetNext(c.baseURL, response, c.getNextListAvailablePhoneNumberCountryResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListAvailablePhoneNumberCountryResponseWithContext) if err != nil { errorChannel <- err break @@ -196,11 +214,11 @@ func (c *ApiService) streamAvailablePhoneNumberCountry(response *ListAvailablePh close(errorChannel) } -func (c *ApiService) getNextListAvailablePhoneNumberCountryResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListAvailablePhoneNumberCountryResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_available_phone_numbers_local.go b/rest/api/v2010/accounts_available_phone_numbers_local.go index 251b987dc..41826ad72 100644 --- a/rest/api/v2010/accounts_available_phone_numbers_local.go +++ b/rest/api/v2010/accounts_available_phone_numbers_local.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -156,6 +157,11 @@ func (params *ListAvailablePhoneNumberLocalParams) SetLimit(Limit int) *ListAvai // Retrieve a single page of AvailablePhoneNumberLocal records from the API. Request is executed immediately. func (c *ApiService) PageAvailablePhoneNumberLocal(CountryCode string, params *ListAvailablePhoneNumberLocalParams, pageToken, pageNumber string) (*ListAvailablePhoneNumberLocalResponse, error) { + return c.PageAvailablePhoneNumberLocalWithContext(context.TODO(), CountryCode, params, pageToken, pageNumber) +} + +// Retrieve a single page of AvailablePhoneNumberLocal records from the API. Request is executed immediately. +func (c *ApiService) PageAvailablePhoneNumberLocalWithContext(ctx context.Context, CountryCode string, params *ListAvailablePhoneNumberLocalParams, pageToken, pageNumber string) (*ListAvailablePhoneNumberLocalResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}/Local.json" if params != nil && params.PathAccountSid != nil { @@ -235,7 +241,7 @@ func (c *ApiService) PageAvailablePhoneNumberLocal(CountryCode string, params *L data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -252,7 +258,12 @@ func (c *ApiService) PageAvailablePhoneNumberLocal(CountryCode string, params *L // Lists AvailablePhoneNumberLocal records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListAvailablePhoneNumberLocal(CountryCode string, params *ListAvailablePhoneNumberLocalParams) ([]ApiV2010AvailablePhoneNumberLocal, error) { - response, errors := c.StreamAvailablePhoneNumberLocal(CountryCode, params) + return c.ListAvailablePhoneNumberLocalWithContext(context.TODO(), CountryCode, params) +} + +// Lists AvailablePhoneNumberLocal records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListAvailablePhoneNumberLocalWithContext(ctx context.Context, CountryCode string, params *ListAvailablePhoneNumberLocalParams) ([]ApiV2010AvailablePhoneNumberLocal, error) { + response, errors := c.StreamAvailablePhoneNumberLocalWithContext(ctx, CountryCode, params) records := make([]ApiV2010AvailablePhoneNumberLocal, 0) for record := range response { @@ -268,6 +279,11 @@ func (c *ApiService) ListAvailablePhoneNumberLocal(CountryCode string, params *L // Streams AvailablePhoneNumberLocal records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamAvailablePhoneNumberLocal(CountryCode string, params *ListAvailablePhoneNumberLocalParams) (chan ApiV2010AvailablePhoneNumberLocal, chan error) { + return c.StreamAvailablePhoneNumberLocalWithContext(context.TODO(), CountryCode, params) +} + +// Streams AvailablePhoneNumberLocal records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamAvailablePhoneNumberLocalWithContext(ctx context.Context, CountryCode string, params *ListAvailablePhoneNumberLocalParams) (chan ApiV2010AvailablePhoneNumberLocal, chan error) { if params == nil { params = &ListAvailablePhoneNumberLocalParams{} } @@ -276,19 +292,19 @@ func (c *ApiService) StreamAvailablePhoneNumberLocal(CountryCode string, params recordChannel := make(chan ApiV2010AvailablePhoneNumberLocal, 1) errorChannel := make(chan error, 1) - response, err := c.PageAvailablePhoneNumberLocal(CountryCode, params, "", "") + response, err := c.PageAvailablePhoneNumberLocalWithContext(ctx, CountryCode, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamAvailablePhoneNumberLocal(response, params, recordChannel, errorChannel) + go c.streamAvailablePhoneNumberLocalWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamAvailablePhoneNumberLocal(response *ListAvailablePhoneNumberLocalResponse, params *ListAvailablePhoneNumberLocalParams, recordChannel chan ApiV2010AvailablePhoneNumberLocal, errorChannel chan error) { +func (c *ApiService) streamAvailablePhoneNumberLocalWithContext(ctx context.Context, response *ListAvailablePhoneNumberLocalResponse, params *ListAvailablePhoneNumberLocalParams, recordChannel chan ApiV2010AvailablePhoneNumberLocal, errorChannel chan error) { curRecord := 1 for response != nil { @@ -303,7 +319,7 @@ func (c *ApiService) streamAvailablePhoneNumberLocal(response *ListAvailablePhon } } - record, err := client.GetNext(c.baseURL, response, c.getNextListAvailablePhoneNumberLocalResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListAvailablePhoneNumberLocalResponseWithContext) if err != nil { errorChannel <- err break @@ -318,11 +334,11 @@ func (c *ApiService) streamAvailablePhoneNumberLocal(response *ListAvailablePhon close(errorChannel) } -func (c *ApiService) getNextListAvailablePhoneNumberLocalResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListAvailablePhoneNumberLocalResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_available_phone_numbers_machine_to_machine.go b/rest/api/v2010/accounts_available_phone_numbers_machine_to_machine.go index fd312a49c..21fa410db 100644 --- a/rest/api/v2010/accounts_available_phone_numbers_machine_to_machine.go +++ b/rest/api/v2010/accounts_available_phone_numbers_machine_to_machine.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -156,6 +157,11 @@ func (params *ListAvailablePhoneNumberMachineToMachineParams) SetLimit(Limit int // Retrieve a single page of AvailablePhoneNumberMachineToMachine records from the API. Request is executed immediately. func (c *ApiService) PageAvailablePhoneNumberMachineToMachine(CountryCode string, params *ListAvailablePhoneNumberMachineToMachineParams, pageToken, pageNumber string) (*ListAvailablePhoneNumberMachineToMachineResponse, error) { + return c.PageAvailablePhoneNumberMachineToMachineWithContext(context.TODO(), CountryCode, params, pageToken, pageNumber) +} + +// Retrieve a single page of AvailablePhoneNumberMachineToMachine records from the API. Request is executed immediately. +func (c *ApiService) PageAvailablePhoneNumberMachineToMachineWithContext(ctx context.Context, CountryCode string, params *ListAvailablePhoneNumberMachineToMachineParams, pageToken, pageNumber string) (*ListAvailablePhoneNumberMachineToMachineResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}/MachineToMachine.json" if params != nil && params.PathAccountSid != nil { @@ -235,7 +241,7 @@ func (c *ApiService) PageAvailablePhoneNumberMachineToMachine(CountryCode string data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -252,7 +258,12 @@ func (c *ApiService) PageAvailablePhoneNumberMachineToMachine(CountryCode string // Lists AvailablePhoneNumberMachineToMachine records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListAvailablePhoneNumberMachineToMachine(CountryCode string, params *ListAvailablePhoneNumberMachineToMachineParams) ([]ApiV2010AvailablePhoneNumberMachineToMachine, error) { - response, errors := c.StreamAvailablePhoneNumberMachineToMachine(CountryCode, params) + return c.ListAvailablePhoneNumberMachineToMachineWithContext(context.TODO(), CountryCode, params) +} + +// Lists AvailablePhoneNumberMachineToMachine records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListAvailablePhoneNumberMachineToMachineWithContext(ctx context.Context, CountryCode string, params *ListAvailablePhoneNumberMachineToMachineParams) ([]ApiV2010AvailablePhoneNumberMachineToMachine, error) { + response, errors := c.StreamAvailablePhoneNumberMachineToMachineWithContext(ctx, CountryCode, params) records := make([]ApiV2010AvailablePhoneNumberMachineToMachine, 0) for record := range response { @@ -268,6 +279,11 @@ func (c *ApiService) ListAvailablePhoneNumberMachineToMachine(CountryCode string // Streams AvailablePhoneNumberMachineToMachine records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamAvailablePhoneNumberMachineToMachine(CountryCode string, params *ListAvailablePhoneNumberMachineToMachineParams) (chan ApiV2010AvailablePhoneNumberMachineToMachine, chan error) { + return c.StreamAvailablePhoneNumberMachineToMachineWithContext(context.TODO(), CountryCode, params) +} + +// Streams AvailablePhoneNumberMachineToMachine records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamAvailablePhoneNumberMachineToMachineWithContext(ctx context.Context, CountryCode string, params *ListAvailablePhoneNumberMachineToMachineParams) (chan ApiV2010AvailablePhoneNumberMachineToMachine, chan error) { if params == nil { params = &ListAvailablePhoneNumberMachineToMachineParams{} } @@ -276,19 +292,19 @@ func (c *ApiService) StreamAvailablePhoneNumberMachineToMachine(CountryCode stri recordChannel := make(chan ApiV2010AvailablePhoneNumberMachineToMachine, 1) errorChannel := make(chan error, 1) - response, err := c.PageAvailablePhoneNumberMachineToMachine(CountryCode, params, "", "") + response, err := c.PageAvailablePhoneNumberMachineToMachineWithContext(ctx, CountryCode, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamAvailablePhoneNumberMachineToMachine(response, params, recordChannel, errorChannel) + go c.streamAvailablePhoneNumberMachineToMachineWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamAvailablePhoneNumberMachineToMachine(response *ListAvailablePhoneNumberMachineToMachineResponse, params *ListAvailablePhoneNumberMachineToMachineParams, recordChannel chan ApiV2010AvailablePhoneNumberMachineToMachine, errorChannel chan error) { +func (c *ApiService) streamAvailablePhoneNumberMachineToMachineWithContext(ctx context.Context, response *ListAvailablePhoneNumberMachineToMachineResponse, params *ListAvailablePhoneNumberMachineToMachineParams, recordChannel chan ApiV2010AvailablePhoneNumberMachineToMachine, errorChannel chan error) { curRecord := 1 for response != nil { @@ -303,7 +319,7 @@ func (c *ApiService) streamAvailablePhoneNumberMachineToMachine(response *ListAv } } - record, err := client.GetNext(c.baseURL, response, c.getNextListAvailablePhoneNumberMachineToMachineResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListAvailablePhoneNumberMachineToMachineResponseWithContext) if err != nil { errorChannel <- err break @@ -318,11 +334,11 @@ func (c *ApiService) streamAvailablePhoneNumberMachineToMachine(response *ListAv close(errorChannel) } -func (c *ApiService) getNextListAvailablePhoneNumberMachineToMachineResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListAvailablePhoneNumberMachineToMachineResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_available_phone_numbers_mobile.go b/rest/api/v2010/accounts_available_phone_numbers_mobile.go index 63a4f69cb..a55a96bb7 100644 --- a/rest/api/v2010/accounts_available_phone_numbers_mobile.go +++ b/rest/api/v2010/accounts_available_phone_numbers_mobile.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -156,6 +157,11 @@ func (params *ListAvailablePhoneNumberMobileParams) SetLimit(Limit int) *ListAva // Retrieve a single page of AvailablePhoneNumberMobile records from the API. Request is executed immediately. func (c *ApiService) PageAvailablePhoneNumberMobile(CountryCode string, params *ListAvailablePhoneNumberMobileParams, pageToken, pageNumber string) (*ListAvailablePhoneNumberMobileResponse, error) { + return c.PageAvailablePhoneNumberMobileWithContext(context.TODO(), CountryCode, params, pageToken, pageNumber) +} + +// Retrieve a single page of AvailablePhoneNumberMobile records from the API. Request is executed immediately. +func (c *ApiService) PageAvailablePhoneNumberMobileWithContext(ctx context.Context, CountryCode string, params *ListAvailablePhoneNumberMobileParams, pageToken, pageNumber string) (*ListAvailablePhoneNumberMobileResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}/Mobile.json" if params != nil && params.PathAccountSid != nil { @@ -235,7 +241,7 @@ func (c *ApiService) PageAvailablePhoneNumberMobile(CountryCode string, params * data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -252,7 +258,12 @@ func (c *ApiService) PageAvailablePhoneNumberMobile(CountryCode string, params * // Lists AvailablePhoneNumberMobile records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListAvailablePhoneNumberMobile(CountryCode string, params *ListAvailablePhoneNumberMobileParams) ([]ApiV2010AvailablePhoneNumberMobile, error) { - response, errors := c.StreamAvailablePhoneNumberMobile(CountryCode, params) + return c.ListAvailablePhoneNumberMobileWithContext(context.TODO(), CountryCode, params) +} + +// Lists AvailablePhoneNumberMobile records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListAvailablePhoneNumberMobileWithContext(ctx context.Context, CountryCode string, params *ListAvailablePhoneNumberMobileParams) ([]ApiV2010AvailablePhoneNumberMobile, error) { + response, errors := c.StreamAvailablePhoneNumberMobileWithContext(ctx, CountryCode, params) records := make([]ApiV2010AvailablePhoneNumberMobile, 0) for record := range response { @@ -268,6 +279,11 @@ func (c *ApiService) ListAvailablePhoneNumberMobile(CountryCode string, params * // Streams AvailablePhoneNumberMobile records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamAvailablePhoneNumberMobile(CountryCode string, params *ListAvailablePhoneNumberMobileParams) (chan ApiV2010AvailablePhoneNumberMobile, chan error) { + return c.StreamAvailablePhoneNumberMobileWithContext(context.TODO(), CountryCode, params) +} + +// Streams AvailablePhoneNumberMobile records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamAvailablePhoneNumberMobileWithContext(ctx context.Context, CountryCode string, params *ListAvailablePhoneNumberMobileParams) (chan ApiV2010AvailablePhoneNumberMobile, chan error) { if params == nil { params = &ListAvailablePhoneNumberMobileParams{} } @@ -276,19 +292,19 @@ func (c *ApiService) StreamAvailablePhoneNumberMobile(CountryCode string, params recordChannel := make(chan ApiV2010AvailablePhoneNumberMobile, 1) errorChannel := make(chan error, 1) - response, err := c.PageAvailablePhoneNumberMobile(CountryCode, params, "", "") + response, err := c.PageAvailablePhoneNumberMobileWithContext(ctx, CountryCode, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamAvailablePhoneNumberMobile(response, params, recordChannel, errorChannel) + go c.streamAvailablePhoneNumberMobileWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamAvailablePhoneNumberMobile(response *ListAvailablePhoneNumberMobileResponse, params *ListAvailablePhoneNumberMobileParams, recordChannel chan ApiV2010AvailablePhoneNumberMobile, errorChannel chan error) { +func (c *ApiService) streamAvailablePhoneNumberMobileWithContext(ctx context.Context, response *ListAvailablePhoneNumberMobileResponse, params *ListAvailablePhoneNumberMobileParams, recordChannel chan ApiV2010AvailablePhoneNumberMobile, errorChannel chan error) { curRecord := 1 for response != nil { @@ -303,7 +319,7 @@ func (c *ApiService) streamAvailablePhoneNumberMobile(response *ListAvailablePho } } - record, err := client.GetNext(c.baseURL, response, c.getNextListAvailablePhoneNumberMobileResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListAvailablePhoneNumberMobileResponseWithContext) if err != nil { errorChannel <- err break @@ -318,11 +334,11 @@ func (c *ApiService) streamAvailablePhoneNumberMobile(response *ListAvailablePho close(errorChannel) } -func (c *ApiService) getNextListAvailablePhoneNumberMobileResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListAvailablePhoneNumberMobileResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_available_phone_numbers_national.go b/rest/api/v2010/accounts_available_phone_numbers_national.go index 808b80b37..c4fb3fd70 100644 --- a/rest/api/v2010/accounts_available_phone_numbers_national.go +++ b/rest/api/v2010/accounts_available_phone_numbers_national.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -156,6 +157,11 @@ func (params *ListAvailablePhoneNumberNationalParams) SetLimit(Limit int) *ListA // Retrieve a single page of AvailablePhoneNumberNational records from the API. Request is executed immediately. func (c *ApiService) PageAvailablePhoneNumberNational(CountryCode string, params *ListAvailablePhoneNumberNationalParams, pageToken, pageNumber string) (*ListAvailablePhoneNumberNationalResponse, error) { + return c.PageAvailablePhoneNumberNationalWithContext(context.TODO(), CountryCode, params, pageToken, pageNumber) +} + +// Retrieve a single page of AvailablePhoneNumberNational records from the API. Request is executed immediately. +func (c *ApiService) PageAvailablePhoneNumberNationalWithContext(ctx context.Context, CountryCode string, params *ListAvailablePhoneNumberNationalParams, pageToken, pageNumber string) (*ListAvailablePhoneNumberNationalResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}/National.json" if params != nil && params.PathAccountSid != nil { @@ -235,7 +241,7 @@ func (c *ApiService) PageAvailablePhoneNumberNational(CountryCode string, params data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -252,7 +258,12 @@ func (c *ApiService) PageAvailablePhoneNumberNational(CountryCode string, params // Lists AvailablePhoneNumberNational records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListAvailablePhoneNumberNational(CountryCode string, params *ListAvailablePhoneNumberNationalParams) ([]ApiV2010AvailablePhoneNumberNational, error) { - response, errors := c.StreamAvailablePhoneNumberNational(CountryCode, params) + return c.ListAvailablePhoneNumberNationalWithContext(context.TODO(), CountryCode, params) +} + +// Lists AvailablePhoneNumberNational records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListAvailablePhoneNumberNationalWithContext(ctx context.Context, CountryCode string, params *ListAvailablePhoneNumberNationalParams) ([]ApiV2010AvailablePhoneNumberNational, error) { + response, errors := c.StreamAvailablePhoneNumberNationalWithContext(ctx, CountryCode, params) records := make([]ApiV2010AvailablePhoneNumberNational, 0) for record := range response { @@ -268,6 +279,11 @@ func (c *ApiService) ListAvailablePhoneNumberNational(CountryCode string, params // Streams AvailablePhoneNumberNational records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamAvailablePhoneNumberNational(CountryCode string, params *ListAvailablePhoneNumberNationalParams) (chan ApiV2010AvailablePhoneNumberNational, chan error) { + return c.StreamAvailablePhoneNumberNationalWithContext(context.TODO(), CountryCode, params) +} + +// Streams AvailablePhoneNumberNational records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamAvailablePhoneNumberNationalWithContext(ctx context.Context, CountryCode string, params *ListAvailablePhoneNumberNationalParams) (chan ApiV2010AvailablePhoneNumberNational, chan error) { if params == nil { params = &ListAvailablePhoneNumberNationalParams{} } @@ -276,19 +292,19 @@ func (c *ApiService) StreamAvailablePhoneNumberNational(CountryCode string, para recordChannel := make(chan ApiV2010AvailablePhoneNumberNational, 1) errorChannel := make(chan error, 1) - response, err := c.PageAvailablePhoneNumberNational(CountryCode, params, "", "") + response, err := c.PageAvailablePhoneNumberNationalWithContext(ctx, CountryCode, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamAvailablePhoneNumberNational(response, params, recordChannel, errorChannel) + go c.streamAvailablePhoneNumberNationalWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamAvailablePhoneNumberNational(response *ListAvailablePhoneNumberNationalResponse, params *ListAvailablePhoneNumberNationalParams, recordChannel chan ApiV2010AvailablePhoneNumberNational, errorChannel chan error) { +func (c *ApiService) streamAvailablePhoneNumberNationalWithContext(ctx context.Context, response *ListAvailablePhoneNumberNationalResponse, params *ListAvailablePhoneNumberNationalParams, recordChannel chan ApiV2010AvailablePhoneNumberNational, errorChannel chan error) { curRecord := 1 for response != nil { @@ -303,7 +319,7 @@ func (c *ApiService) streamAvailablePhoneNumberNational(response *ListAvailableP } } - record, err := client.GetNext(c.baseURL, response, c.getNextListAvailablePhoneNumberNationalResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListAvailablePhoneNumberNationalResponseWithContext) if err != nil { errorChannel <- err break @@ -318,11 +334,11 @@ func (c *ApiService) streamAvailablePhoneNumberNational(response *ListAvailableP close(errorChannel) } -func (c *ApiService) getNextListAvailablePhoneNumberNationalResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListAvailablePhoneNumberNationalResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_available_phone_numbers_shared_cost.go b/rest/api/v2010/accounts_available_phone_numbers_shared_cost.go index 39d575f35..455295f98 100644 --- a/rest/api/v2010/accounts_available_phone_numbers_shared_cost.go +++ b/rest/api/v2010/accounts_available_phone_numbers_shared_cost.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -156,6 +157,11 @@ func (params *ListAvailablePhoneNumberSharedCostParams) SetLimit(Limit int) *Lis // Retrieve a single page of AvailablePhoneNumberSharedCost records from the API. Request is executed immediately. func (c *ApiService) PageAvailablePhoneNumberSharedCost(CountryCode string, params *ListAvailablePhoneNumberSharedCostParams, pageToken, pageNumber string) (*ListAvailablePhoneNumberSharedCostResponse, error) { + return c.PageAvailablePhoneNumberSharedCostWithContext(context.TODO(), CountryCode, params, pageToken, pageNumber) +} + +// Retrieve a single page of AvailablePhoneNumberSharedCost records from the API. Request is executed immediately. +func (c *ApiService) PageAvailablePhoneNumberSharedCostWithContext(ctx context.Context, CountryCode string, params *ListAvailablePhoneNumberSharedCostParams, pageToken, pageNumber string) (*ListAvailablePhoneNumberSharedCostResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}/SharedCost.json" if params != nil && params.PathAccountSid != nil { @@ -235,7 +241,7 @@ func (c *ApiService) PageAvailablePhoneNumberSharedCost(CountryCode string, para data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -252,7 +258,12 @@ func (c *ApiService) PageAvailablePhoneNumberSharedCost(CountryCode string, para // Lists AvailablePhoneNumberSharedCost records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListAvailablePhoneNumberSharedCost(CountryCode string, params *ListAvailablePhoneNumberSharedCostParams) ([]ApiV2010AvailablePhoneNumberSharedCost, error) { - response, errors := c.StreamAvailablePhoneNumberSharedCost(CountryCode, params) + return c.ListAvailablePhoneNumberSharedCostWithContext(context.TODO(), CountryCode, params) +} + +// Lists AvailablePhoneNumberSharedCost records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListAvailablePhoneNumberSharedCostWithContext(ctx context.Context, CountryCode string, params *ListAvailablePhoneNumberSharedCostParams) ([]ApiV2010AvailablePhoneNumberSharedCost, error) { + response, errors := c.StreamAvailablePhoneNumberSharedCostWithContext(ctx, CountryCode, params) records := make([]ApiV2010AvailablePhoneNumberSharedCost, 0) for record := range response { @@ -268,6 +279,11 @@ func (c *ApiService) ListAvailablePhoneNumberSharedCost(CountryCode string, para // Streams AvailablePhoneNumberSharedCost records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamAvailablePhoneNumberSharedCost(CountryCode string, params *ListAvailablePhoneNumberSharedCostParams) (chan ApiV2010AvailablePhoneNumberSharedCost, chan error) { + return c.StreamAvailablePhoneNumberSharedCostWithContext(context.TODO(), CountryCode, params) +} + +// Streams AvailablePhoneNumberSharedCost records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamAvailablePhoneNumberSharedCostWithContext(ctx context.Context, CountryCode string, params *ListAvailablePhoneNumberSharedCostParams) (chan ApiV2010AvailablePhoneNumberSharedCost, chan error) { if params == nil { params = &ListAvailablePhoneNumberSharedCostParams{} } @@ -276,19 +292,19 @@ func (c *ApiService) StreamAvailablePhoneNumberSharedCost(CountryCode string, pa recordChannel := make(chan ApiV2010AvailablePhoneNumberSharedCost, 1) errorChannel := make(chan error, 1) - response, err := c.PageAvailablePhoneNumberSharedCost(CountryCode, params, "", "") + response, err := c.PageAvailablePhoneNumberSharedCostWithContext(ctx, CountryCode, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamAvailablePhoneNumberSharedCost(response, params, recordChannel, errorChannel) + go c.streamAvailablePhoneNumberSharedCostWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamAvailablePhoneNumberSharedCost(response *ListAvailablePhoneNumberSharedCostResponse, params *ListAvailablePhoneNumberSharedCostParams, recordChannel chan ApiV2010AvailablePhoneNumberSharedCost, errorChannel chan error) { +func (c *ApiService) streamAvailablePhoneNumberSharedCostWithContext(ctx context.Context, response *ListAvailablePhoneNumberSharedCostResponse, params *ListAvailablePhoneNumberSharedCostParams, recordChannel chan ApiV2010AvailablePhoneNumberSharedCost, errorChannel chan error) { curRecord := 1 for response != nil { @@ -303,7 +319,7 @@ func (c *ApiService) streamAvailablePhoneNumberSharedCost(response *ListAvailabl } } - record, err := client.GetNext(c.baseURL, response, c.getNextListAvailablePhoneNumberSharedCostResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListAvailablePhoneNumberSharedCostResponseWithContext) if err != nil { errorChannel <- err break @@ -318,11 +334,11 @@ func (c *ApiService) streamAvailablePhoneNumberSharedCost(response *ListAvailabl close(errorChannel) } -func (c *ApiService) getNextListAvailablePhoneNumberSharedCostResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListAvailablePhoneNumberSharedCostResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_available_phone_numbers_toll_free.go b/rest/api/v2010/accounts_available_phone_numbers_toll_free.go index 34df01eb5..f00a55bff 100644 --- a/rest/api/v2010/accounts_available_phone_numbers_toll_free.go +++ b/rest/api/v2010/accounts_available_phone_numbers_toll_free.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -156,6 +157,11 @@ func (params *ListAvailablePhoneNumberTollFreeParams) SetLimit(Limit int) *ListA // Retrieve a single page of AvailablePhoneNumberTollFree records from the API. Request is executed immediately. func (c *ApiService) PageAvailablePhoneNumberTollFree(CountryCode string, params *ListAvailablePhoneNumberTollFreeParams, pageToken, pageNumber string) (*ListAvailablePhoneNumberTollFreeResponse, error) { + return c.PageAvailablePhoneNumberTollFreeWithContext(context.TODO(), CountryCode, params, pageToken, pageNumber) +} + +// Retrieve a single page of AvailablePhoneNumberTollFree records from the API. Request is executed immediately. +func (c *ApiService) PageAvailablePhoneNumberTollFreeWithContext(ctx context.Context, CountryCode string, params *ListAvailablePhoneNumberTollFreeParams, pageToken, pageNumber string) (*ListAvailablePhoneNumberTollFreeResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}/TollFree.json" if params != nil && params.PathAccountSid != nil { @@ -235,7 +241,7 @@ func (c *ApiService) PageAvailablePhoneNumberTollFree(CountryCode string, params data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -252,7 +258,12 @@ func (c *ApiService) PageAvailablePhoneNumberTollFree(CountryCode string, params // Lists AvailablePhoneNumberTollFree records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListAvailablePhoneNumberTollFree(CountryCode string, params *ListAvailablePhoneNumberTollFreeParams) ([]ApiV2010AvailablePhoneNumberTollFree, error) { - response, errors := c.StreamAvailablePhoneNumberTollFree(CountryCode, params) + return c.ListAvailablePhoneNumberTollFreeWithContext(context.TODO(), CountryCode, params) +} + +// Lists AvailablePhoneNumberTollFree records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListAvailablePhoneNumberTollFreeWithContext(ctx context.Context, CountryCode string, params *ListAvailablePhoneNumberTollFreeParams) ([]ApiV2010AvailablePhoneNumberTollFree, error) { + response, errors := c.StreamAvailablePhoneNumberTollFreeWithContext(ctx, CountryCode, params) records := make([]ApiV2010AvailablePhoneNumberTollFree, 0) for record := range response { @@ -268,6 +279,11 @@ func (c *ApiService) ListAvailablePhoneNumberTollFree(CountryCode string, params // Streams AvailablePhoneNumberTollFree records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamAvailablePhoneNumberTollFree(CountryCode string, params *ListAvailablePhoneNumberTollFreeParams) (chan ApiV2010AvailablePhoneNumberTollFree, chan error) { + return c.StreamAvailablePhoneNumberTollFreeWithContext(context.TODO(), CountryCode, params) +} + +// Streams AvailablePhoneNumberTollFree records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamAvailablePhoneNumberTollFreeWithContext(ctx context.Context, CountryCode string, params *ListAvailablePhoneNumberTollFreeParams) (chan ApiV2010AvailablePhoneNumberTollFree, chan error) { if params == nil { params = &ListAvailablePhoneNumberTollFreeParams{} } @@ -276,19 +292,19 @@ func (c *ApiService) StreamAvailablePhoneNumberTollFree(CountryCode string, para recordChannel := make(chan ApiV2010AvailablePhoneNumberTollFree, 1) errorChannel := make(chan error, 1) - response, err := c.PageAvailablePhoneNumberTollFree(CountryCode, params, "", "") + response, err := c.PageAvailablePhoneNumberTollFreeWithContext(ctx, CountryCode, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamAvailablePhoneNumberTollFree(response, params, recordChannel, errorChannel) + go c.streamAvailablePhoneNumberTollFreeWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamAvailablePhoneNumberTollFree(response *ListAvailablePhoneNumberTollFreeResponse, params *ListAvailablePhoneNumberTollFreeParams, recordChannel chan ApiV2010AvailablePhoneNumberTollFree, errorChannel chan error) { +func (c *ApiService) streamAvailablePhoneNumberTollFreeWithContext(ctx context.Context, response *ListAvailablePhoneNumberTollFreeResponse, params *ListAvailablePhoneNumberTollFreeParams, recordChannel chan ApiV2010AvailablePhoneNumberTollFree, errorChannel chan error) { curRecord := 1 for response != nil { @@ -303,7 +319,7 @@ func (c *ApiService) streamAvailablePhoneNumberTollFree(response *ListAvailableP } } - record, err := client.GetNext(c.baseURL, response, c.getNextListAvailablePhoneNumberTollFreeResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListAvailablePhoneNumberTollFreeResponseWithContext) if err != nil { errorChannel <- err break @@ -318,11 +334,11 @@ func (c *ApiService) streamAvailablePhoneNumberTollFree(response *ListAvailableP close(errorChannel) } -func (c *ApiService) getNextListAvailablePhoneNumberTollFreeResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListAvailablePhoneNumberTollFreeResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_available_phone_numbers_voip.go b/rest/api/v2010/accounts_available_phone_numbers_voip.go index 6c6ca8bf9..239e77434 100644 --- a/rest/api/v2010/accounts_available_phone_numbers_voip.go +++ b/rest/api/v2010/accounts_available_phone_numbers_voip.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -156,6 +157,11 @@ func (params *ListAvailablePhoneNumberVoipParams) SetLimit(Limit int) *ListAvail // Retrieve a single page of AvailablePhoneNumberVoip records from the API. Request is executed immediately. func (c *ApiService) PageAvailablePhoneNumberVoip(CountryCode string, params *ListAvailablePhoneNumberVoipParams, pageToken, pageNumber string) (*ListAvailablePhoneNumberVoipResponse, error) { + return c.PageAvailablePhoneNumberVoipWithContext(context.TODO(), CountryCode, params, pageToken, pageNumber) +} + +// Retrieve a single page of AvailablePhoneNumberVoip records from the API. Request is executed immediately. +func (c *ApiService) PageAvailablePhoneNumberVoipWithContext(ctx context.Context, CountryCode string, params *ListAvailablePhoneNumberVoipParams, pageToken, pageNumber string) (*ListAvailablePhoneNumberVoipResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}/Voip.json" if params != nil && params.PathAccountSid != nil { @@ -235,7 +241,7 @@ func (c *ApiService) PageAvailablePhoneNumberVoip(CountryCode string, params *Li data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -252,7 +258,12 @@ func (c *ApiService) PageAvailablePhoneNumberVoip(CountryCode string, params *Li // Lists AvailablePhoneNumberVoip records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListAvailablePhoneNumberVoip(CountryCode string, params *ListAvailablePhoneNumberVoipParams) ([]ApiV2010AvailablePhoneNumberVoip, error) { - response, errors := c.StreamAvailablePhoneNumberVoip(CountryCode, params) + return c.ListAvailablePhoneNumberVoipWithContext(context.TODO(), CountryCode, params) +} + +// Lists AvailablePhoneNumberVoip records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListAvailablePhoneNumberVoipWithContext(ctx context.Context, CountryCode string, params *ListAvailablePhoneNumberVoipParams) ([]ApiV2010AvailablePhoneNumberVoip, error) { + response, errors := c.StreamAvailablePhoneNumberVoipWithContext(ctx, CountryCode, params) records := make([]ApiV2010AvailablePhoneNumberVoip, 0) for record := range response { @@ -268,6 +279,11 @@ func (c *ApiService) ListAvailablePhoneNumberVoip(CountryCode string, params *Li // Streams AvailablePhoneNumberVoip records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamAvailablePhoneNumberVoip(CountryCode string, params *ListAvailablePhoneNumberVoipParams) (chan ApiV2010AvailablePhoneNumberVoip, chan error) { + return c.StreamAvailablePhoneNumberVoipWithContext(context.TODO(), CountryCode, params) +} + +// Streams AvailablePhoneNumberVoip records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamAvailablePhoneNumberVoipWithContext(ctx context.Context, CountryCode string, params *ListAvailablePhoneNumberVoipParams) (chan ApiV2010AvailablePhoneNumberVoip, chan error) { if params == nil { params = &ListAvailablePhoneNumberVoipParams{} } @@ -276,19 +292,19 @@ func (c *ApiService) StreamAvailablePhoneNumberVoip(CountryCode string, params * recordChannel := make(chan ApiV2010AvailablePhoneNumberVoip, 1) errorChannel := make(chan error, 1) - response, err := c.PageAvailablePhoneNumberVoip(CountryCode, params, "", "") + response, err := c.PageAvailablePhoneNumberVoipWithContext(ctx, CountryCode, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamAvailablePhoneNumberVoip(response, params, recordChannel, errorChannel) + go c.streamAvailablePhoneNumberVoipWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamAvailablePhoneNumberVoip(response *ListAvailablePhoneNumberVoipResponse, params *ListAvailablePhoneNumberVoipParams, recordChannel chan ApiV2010AvailablePhoneNumberVoip, errorChannel chan error) { +func (c *ApiService) streamAvailablePhoneNumberVoipWithContext(ctx context.Context, response *ListAvailablePhoneNumberVoipResponse, params *ListAvailablePhoneNumberVoipParams, recordChannel chan ApiV2010AvailablePhoneNumberVoip, errorChannel chan error) { curRecord := 1 for response != nil { @@ -303,7 +319,7 @@ func (c *ApiService) streamAvailablePhoneNumberVoip(response *ListAvailablePhone } } - record, err := client.GetNext(c.baseURL, response, c.getNextListAvailablePhoneNumberVoipResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListAvailablePhoneNumberVoipResponseWithContext) if err != nil { errorChannel <- err break @@ -318,11 +334,11 @@ func (c *ApiService) streamAvailablePhoneNumberVoip(response *ListAvailablePhone close(errorChannel) } -func (c *ApiService) getNextListAvailablePhoneNumberVoipResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListAvailablePhoneNumberVoipResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_balance.go b/rest/api/v2010/accounts_balance.go index 721ec158e..d2473b1f0 100644 --- a/rest/api/v2010/accounts_balance.go +++ b/rest/api/v2010/accounts_balance.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -33,6 +34,9 @@ func (params *FetchBalanceParams) SetPathAccountSid(PathAccountSid string) *Fetc // Fetch the balance for an Account based on Account Sid. Balance changes may not be reflected immediately. Child accounts do not contain balance information func (c *ApiService) FetchBalance(params *FetchBalanceParams) (*ApiV2010Balance, error) { + return c.FetchBalanceWithContext(context.TODO(), params) +} +func (c *ApiService) FetchBalanceWithContext(ctx context.Context, params *FetchBalanceParams) (*ApiV2010Balance, error) { path := "/2010-04-01/Accounts/{AccountSid}/Balance.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -45,7 +49,7 @@ func (c *ApiService) FetchBalance(params *FetchBalanceParams) (*ApiV2010Balance, "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_calls.go b/rest/api/v2010/accounts_calls.go index 87868dfec..2371e5e97 100644 --- a/rest/api/v2010/accounts_calls.go +++ b/rest/api/v2010/accounts_calls.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -247,6 +248,9 @@ func (params *CreateCallParams) SetApplicationSid(ApplicationSid string) *Create // Create a new outgoing call to phones, SIP-enabled endpoints or Twilio Client connections func (c *ApiService) CreateCall(params *CreateCallParams) (*ApiV2010Call, error) { + return c.CreateCallWithContext(context.TODO(), params) +} +func (c *ApiService) CreateCallWithContext(ctx context.Context, params *CreateCallParams) (*ApiV2010Call, error) { path := "/2010-04-01/Accounts/{AccountSid}/Calls.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -369,7 +373,7 @@ func (c *ApiService) CreateCall(params *CreateCallParams) (*ApiV2010Call, error) data.Set("ApplicationSid", *params.ApplicationSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -397,6 +401,9 @@ func (params *DeleteCallParams) SetPathAccountSid(PathAccountSid string) *Delete // Delete a Call record from your account. Once the record is deleted, it will no longer appear in the API and Account Portal logs. func (c *ApiService) DeleteCall(Sid string, params *DeleteCallParams) error { + return c.DeleteCallWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) DeleteCallWithContext(ctx context.Context, Sid string, params *DeleteCallParams) error { path := "/2010-04-01/Accounts/{AccountSid}/Calls/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -410,7 +417,7 @@ func (c *ApiService) DeleteCall(Sid string, params *DeleteCallParams) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -433,6 +440,9 @@ func (params *FetchCallParams) SetPathAccountSid(PathAccountSid string) *FetchCa // Fetch the call specified by the provided Call SID func (c *ApiService) FetchCall(Sid string, params *FetchCallParams) (*ApiV2010Call, error) { + return c.FetchCallWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) FetchCallWithContext(ctx context.Context, Sid string, params *FetchCallParams) (*ApiV2010Call, error) { path := "/2010-04-01/Accounts/{AccountSid}/Calls/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -446,7 +456,7 @@ func (c *ApiService) FetchCall(Sid string, params *FetchCallParams) (*ApiV2010Ca "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -546,6 +556,11 @@ func (params *ListCallParams) SetLimit(Limit int) *ListCallParams { // Retrieve a single page of Call records from the API. Request is executed immediately. func (c *ApiService) PageCall(params *ListCallParams, pageToken, pageNumber string) (*ListCallResponse, error) { + return c.PageCallWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Call records from the API. Request is executed immediately. +func (c *ApiService) PageCallWithContext(ctx context.Context, params *ListCallParams, pageToken, pageNumber string) (*ListCallResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/Calls.json" if params != nil && params.PathAccountSid != nil { @@ -600,7 +615,7 @@ func (c *ApiService) PageCall(params *ListCallParams, pageToken, pageNumber stri data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -617,7 +632,12 @@ func (c *ApiService) PageCall(params *ListCallParams, pageToken, pageNumber stri // Lists Call records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListCall(params *ListCallParams) ([]ApiV2010Call, error) { - response, errors := c.StreamCall(params) + return c.ListCallWithContext(context.TODO(), params) +} + +// Lists Call records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListCallWithContext(ctx context.Context, params *ListCallParams) ([]ApiV2010Call, error) { + response, errors := c.StreamCallWithContext(ctx, params) records := make([]ApiV2010Call, 0) for record := range response { @@ -633,6 +653,11 @@ func (c *ApiService) ListCall(params *ListCallParams) ([]ApiV2010Call, error) { // Streams Call records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamCall(params *ListCallParams) (chan ApiV2010Call, chan error) { + return c.StreamCallWithContext(context.TODO(), params) +} + +// Streams Call records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamCallWithContext(ctx context.Context, params *ListCallParams) (chan ApiV2010Call, chan error) { if params == nil { params = &ListCallParams{} } @@ -641,19 +666,19 @@ func (c *ApiService) StreamCall(params *ListCallParams) (chan ApiV2010Call, chan recordChannel := make(chan ApiV2010Call, 1) errorChannel := make(chan error, 1) - response, err := c.PageCall(params, "", "") + response, err := c.PageCallWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamCall(response, params, recordChannel, errorChannel) + go c.streamCallWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamCall(response *ListCallResponse, params *ListCallParams, recordChannel chan ApiV2010Call, errorChannel chan error) { +func (c *ApiService) streamCallWithContext(ctx context.Context, response *ListCallResponse, params *ListCallParams, recordChannel chan ApiV2010Call, errorChannel chan error) { curRecord := 1 for response != nil { @@ -668,7 +693,7 @@ func (c *ApiService) streamCall(response *ListCallResponse, params *ListCallPara } } - record, err := client.GetNext(c.baseURL, response, c.getNextListCallResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListCallResponseWithContext) if err != nil { errorChannel <- err break @@ -683,11 +708,11 @@ func (c *ApiService) streamCall(response *ListCallResponse, params *ListCallPara close(errorChannel) } -func (c *ApiService) getNextListCallResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListCallResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -768,6 +793,9 @@ func (params *UpdateCallParams) SetTimeLimit(TimeLimit int) *UpdateCallParams { // Initiates a call redirect or terminates a call func (c *ApiService) UpdateCall(Sid string, params *UpdateCallParams) (*ApiV2010Call, error) { + return c.UpdateCallWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateCallWithContext(ctx context.Context, Sid string, params *UpdateCallParams) (*ApiV2010Call, error) { path := "/2010-04-01/Accounts/{AccountSid}/Calls/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -809,7 +837,7 @@ func (c *ApiService) UpdateCall(Sid string, params *UpdateCallParams) (*ApiV2010 data.Set("TimeLimit", fmt.Sprint(*params.TimeLimit)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_calls_events.go b/rest/api/v2010/accounts_calls_events.go index 02954efad..6fe84cac4 100644 --- a/rest/api/v2010/accounts_calls_events.go +++ b/rest/api/v2010/accounts_calls_events.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -48,6 +49,11 @@ func (params *ListCallEventParams) SetLimit(Limit int) *ListCallEventParams { // Retrieve a single page of CallEvent records from the API. Request is executed immediately. func (c *ApiService) PageCallEvent(CallSid string, params *ListCallEventParams, pageToken, pageNumber string) (*ListCallEventResponse, error) { + return c.PageCallEventWithContext(context.TODO(), CallSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of CallEvent records from the API. Request is executed immediately. +func (c *ApiService) PageCallEventWithContext(ctx context.Context, CallSid string, params *ListCallEventParams, pageToken, pageNumber string) (*ListCallEventResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Events.json" if params != nil && params.PathAccountSid != nil { @@ -73,7 +79,7 @@ func (c *ApiService) PageCallEvent(CallSid string, params *ListCallEventParams, data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -90,7 +96,12 @@ func (c *ApiService) PageCallEvent(CallSid string, params *ListCallEventParams, // Lists CallEvent records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListCallEvent(CallSid string, params *ListCallEventParams) ([]ApiV2010CallEvent, error) { - response, errors := c.StreamCallEvent(CallSid, params) + return c.ListCallEventWithContext(context.TODO(), CallSid, params) +} + +// Lists CallEvent records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListCallEventWithContext(ctx context.Context, CallSid string, params *ListCallEventParams) ([]ApiV2010CallEvent, error) { + response, errors := c.StreamCallEventWithContext(ctx, CallSid, params) records := make([]ApiV2010CallEvent, 0) for record := range response { @@ -106,6 +117,11 @@ func (c *ApiService) ListCallEvent(CallSid string, params *ListCallEventParams) // Streams CallEvent records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamCallEvent(CallSid string, params *ListCallEventParams) (chan ApiV2010CallEvent, chan error) { + return c.StreamCallEventWithContext(context.TODO(), CallSid, params) +} + +// Streams CallEvent records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamCallEventWithContext(ctx context.Context, CallSid string, params *ListCallEventParams) (chan ApiV2010CallEvent, chan error) { if params == nil { params = &ListCallEventParams{} } @@ -114,19 +130,19 @@ func (c *ApiService) StreamCallEvent(CallSid string, params *ListCallEventParams recordChannel := make(chan ApiV2010CallEvent, 1) errorChannel := make(chan error, 1) - response, err := c.PageCallEvent(CallSid, params, "", "") + response, err := c.PageCallEventWithContext(ctx, CallSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamCallEvent(response, params, recordChannel, errorChannel) + go c.streamCallEventWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamCallEvent(response *ListCallEventResponse, params *ListCallEventParams, recordChannel chan ApiV2010CallEvent, errorChannel chan error) { +func (c *ApiService) streamCallEventWithContext(ctx context.Context, response *ListCallEventResponse, params *ListCallEventParams, recordChannel chan ApiV2010CallEvent, errorChannel chan error) { curRecord := 1 for response != nil { @@ -141,7 +157,7 @@ func (c *ApiService) streamCallEvent(response *ListCallEventResponse, params *Li } } - record, err := client.GetNext(c.baseURL, response, c.getNextListCallEventResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListCallEventResponseWithContext) if err != nil { errorChannel <- err break @@ -156,11 +172,11 @@ func (c *ApiService) streamCallEvent(response *ListCallEventResponse, params *Li close(errorChannel) } -func (c *ApiService) getNextListCallEventResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListCallEventResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_calls_notifications.go b/rest/api/v2010/accounts_calls_notifications.go index 824db4614..2996d973f 100644 --- a/rest/api/v2010/accounts_calls_notifications.go +++ b/rest/api/v2010/accounts_calls_notifications.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -34,8 +35,10 @@ func (params *FetchCallNotificationParams) SetPathAccountSid(PathAccountSid stri return params } -// func (c *ApiService) FetchCallNotification(CallSid string, Sid string, params *FetchCallNotificationParams) (*ApiV2010CallNotificationInstance, error) { + return c.FetchCallNotificationWithContext(context.TODO(), CallSid, Sid, params) +} +func (c *ApiService) FetchCallNotificationWithContext(ctx context.Context, CallSid string, Sid string, params *FetchCallNotificationParams) (*ApiV2010CallNotificationInstance, error) { path := "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Notifications/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -50,7 +53,7 @@ func (c *ApiService) FetchCallNotification(CallSid string, Sid string, params *F "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -114,6 +117,11 @@ func (params *ListCallNotificationParams) SetLimit(Limit int) *ListCallNotificat // Retrieve a single page of CallNotification records from the API. Request is executed immediately. func (c *ApiService) PageCallNotification(CallSid string, params *ListCallNotificationParams, pageToken, pageNumber string) (*ListCallNotificationResponse, error) { + return c.PageCallNotificationWithContext(context.TODO(), CallSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of CallNotification records from the API. Request is executed immediately. +func (c *ApiService) PageCallNotificationWithContext(ctx context.Context, CallSid string, params *ListCallNotificationParams, pageToken, pageNumber string) (*ListCallNotificationResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Notifications.json" if params != nil && params.PathAccountSid != nil { @@ -151,7 +159,7 @@ func (c *ApiService) PageCallNotification(CallSid string, params *ListCallNotifi data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -168,7 +176,12 @@ func (c *ApiService) PageCallNotification(CallSid string, params *ListCallNotifi // Lists CallNotification records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListCallNotification(CallSid string, params *ListCallNotificationParams) ([]ApiV2010CallNotification, error) { - response, errors := c.StreamCallNotification(CallSid, params) + return c.ListCallNotificationWithContext(context.TODO(), CallSid, params) +} + +// Lists CallNotification records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListCallNotificationWithContext(ctx context.Context, CallSid string, params *ListCallNotificationParams) ([]ApiV2010CallNotification, error) { + response, errors := c.StreamCallNotificationWithContext(ctx, CallSid, params) records := make([]ApiV2010CallNotification, 0) for record := range response { @@ -184,6 +197,11 @@ func (c *ApiService) ListCallNotification(CallSid string, params *ListCallNotifi // Streams CallNotification records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamCallNotification(CallSid string, params *ListCallNotificationParams) (chan ApiV2010CallNotification, chan error) { + return c.StreamCallNotificationWithContext(context.TODO(), CallSid, params) +} + +// Streams CallNotification records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamCallNotificationWithContext(ctx context.Context, CallSid string, params *ListCallNotificationParams) (chan ApiV2010CallNotification, chan error) { if params == nil { params = &ListCallNotificationParams{} } @@ -192,19 +210,19 @@ func (c *ApiService) StreamCallNotification(CallSid string, params *ListCallNoti recordChannel := make(chan ApiV2010CallNotification, 1) errorChannel := make(chan error, 1) - response, err := c.PageCallNotification(CallSid, params, "", "") + response, err := c.PageCallNotificationWithContext(ctx, CallSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamCallNotification(response, params, recordChannel, errorChannel) + go c.streamCallNotificationWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamCallNotification(response *ListCallNotificationResponse, params *ListCallNotificationParams, recordChannel chan ApiV2010CallNotification, errorChannel chan error) { +func (c *ApiService) streamCallNotificationWithContext(ctx context.Context, response *ListCallNotificationResponse, params *ListCallNotificationParams, recordChannel chan ApiV2010CallNotification, errorChannel chan error) { curRecord := 1 for response != nil { @@ -219,7 +237,7 @@ func (c *ApiService) streamCallNotification(response *ListCallNotificationRespon } } - record, err := client.GetNext(c.baseURL, response, c.getNextListCallNotificationResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListCallNotificationResponseWithContext) if err != nil { errorChannel <- err break @@ -234,11 +252,11 @@ func (c *ApiService) streamCallNotification(response *ListCallNotificationRespon close(errorChannel) } -func (c *ApiService) getNextListCallNotificationResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListCallNotificationResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_calls_payments.go b/rest/api/v2010/accounts_calls_payments.go index 445ae7e11..38d2f4bb8 100644 --- a/rest/api/v2010/accounts_calls_payments.go +++ b/rest/api/v2010/accounts_calls_payments.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -130,6 +131,9 @@ func (params *CreatePaymentsParams) SetValidCardTypes(ValidCardTypes string) *Cr // create an instance of payments. This will start a new payments session func (c *ApiService) CreatePayments(CallSid string, params *CreatePaymentsParams) (*ApiV2010Payments, error) { + return c.CreatePaymentsWithContext(context.TODO(), CallSid, params) +} +func (c *ApiService) CreatePaymentsWithContext(ctx context.Context, CallSid string, params *CreatePaymentsParams) (*ApiV2010Payments, error) { path := "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Payments.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -198,7 +202,7 @@ func (c *ApiService) CreatePayments(CallSid string, params *CreatePaymentsParams data.Set("ValidCardTypes", *params.ValidCardTypes) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -250,6 +254,9 @@ func (params *UpdatePaymentsParams) SetStatus(Status string) *UpdatePaymentsPara // update an instance of payments with different phases of payment flows. func (c *ApiService) UpdatePayments(CallSid string, Sid string, params *UpdatePaymentsParams) (*ApiV2010Payments, error) { + return c.UpdatePaymentsWithContext(context.TODO(), CallSid, Sid, params) +} +func (c *ApiService) UpdatePaymentsWithContext(ctx context.Context, CallSid string, Sid string, params *UpdatePaymentsParams) (*ApiV2010Payments, error) { path := "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Payments/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -277,7 +284,7 @@ func (c *ApiService) UpdatePayments(CallSid string, Sid string, params *UpdatePa data.Set("Status", fmt.Sprint(*params.Status)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_calls_recordings.go b/rest/api/v2010/accounts_calls_recordings.go index 7e7de34cc..9bcf3f4c4 100644 --- a/rest/api/v2010/accounts_calls_recordings.go +++ b/rest/api/v2010/accounts_calls_recordings.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -72,6 +73,9 @@ func (params *CreateCallRecordingParams) SetRecordingTrack(RecordingTrack string // Create a recording for the call func (c *ApiService) CreateCallRecording(CallSid string, params *CreateCallRecordingParams) (*ApiV2010CallRecording, error) { + return c.CreateCallRecordingWithContext(context.TODO(), CallSid, params) +} +func (c *ApiService) CreateCallRecordingWithContext(ctx context.Context, CallSid string, params *CreateCallRecordingParams) (*ApiV2010CallRecording, error) { path := "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Recordings.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -106,7 +110,7 @@ func (c *ApiService) CreateCallRecording(CallSid string, params *CreateCallRecor data.Set("RecordingTrack", *params.RecordingTrack) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -134,6 +138,9 @@ func (params *DeleteCallRecordingParams) SetPathAccountSid(PathAccountSid string // Delete a recording from your account func (c *ApiService) DeleteCallRecording(CallSid string, Sid string, params *DeleteCallRecordingParams) error { + return c.DeleteCallRecordingWithContext(context.TODO(), CallSid, Sid, params) +} +func (c *ApiService) DeleteCallRecordingWithContext(ctx context.Context, CallSid string, Sid string, params *DeleteCallRecordingParams) error { path := "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Recordings/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -148,7 +155,7 @@ func (c *ApiService) DeleteCallRecording(CallSid string, Sid string, params *Del "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -171,6 +178,9 @@ func (params *FetchCallRecordingParams) SetPathAccountSid(PathAccountSid string) // Fetch an instance of a recording for a call func (c *ApiService) FetchCallRecording(CallSid string, Sid string, params *FetchCallRecordingParams) (*ApiV2010CallRecording, error) { + return c.FetchCallRecordingWithContext(context.TODO(), CallSid, Sid, params) +} +func (c *ApiService) FetchCallRecordingWithContext(ctx context.Context, CallSid string, Sid string, params *FetchCallRecordingParams) (*ApiV2010CallRecording, error) { path := "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Recordings/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -185,7 +195,7 @@ func (c *ApiService) FetchCallRecording(CallSid string, Sid string, params *Fetc "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -243,6 +253,11 @@ func (params *ListCallRecordingParams) SetLimit(Limit int) *ListCallRecordingPar // Retrieve a single page of CallRecording records from the API. Request is executed immediately. func (c *ApiService) PageCallRecording(CallSid string, params *ListCallRecordingParams, pageToken, pageNumber string) (*ListCallRecordingResponse, error) { + return c.PageCallRecordingWithContext(context.TODO(), CallSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of CallRecording records from the API. Request is executed immediately. +func (c *ApiService) PageCallRecordingWithContext(ctx context.Context, CallSid string, params *ListCallRecordingParams, pageToken, pageNumber string) (*ListCallRecordingResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Recordings.json" if params != nil && params.PathAccountSid != nil { @@ -277,7 +292,7 @@ func (c *ApiService) PageCallRecording(CallSid string, params *ListCallRecording data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -294,7 +309,12 @@ func (c *ApiService) PageCallRecording(CallSid string, params *ListCallRecording // Lists CallRecording records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListCallRecording(CallSid string, params *ListCallRecordingParams) ([]ApiV2010CallRecording, error) { - response, errors := c.StreamCallRecording(CallSid, params) + return c.ListCallRecordingWithContext(context.TODO(), CallSid, params) +} + +// Lists CallRecording records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListCallRecordingWithContext(ctx context.Context, CallSid string, params *ListCallRecordingParams) ([]ApiV2010CallRecording, error) { + response, errors := c.StreamCallRecordingWithContext(ctx, CallSid, params) records := make([]ApiV2010CallRecording, 0) for record := range response { @@ -310,6 +330,11 @@ func (c *ApiService) ListCallRecording(CallSid string, params *ListCallRecording // Streams CallRecording records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamCallRecording(CallSid string, params *ListCallRecordingParams) (chan ApiV2010CallRecording, chan error) { + return c.StreamCallRecordingWithContext(context.TODO(), CallSid, params) +} + +// Streams CallRecording records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamCallRecordingWithContext(ctx context.Context, CallSid string, params *ListCallRecordingParams) (chan ApiV2010CallRecording, chan error) { if params == nil { params = &ListCallRecordingParams{} } @@ -318,19 +343,19 @@ func (c *ApiService) StreamCallRecording(CallSid string, params *ListCallRecordi recordChannel := make(chan ApiV2010CallRecording, 1) errorChannel := make(chan error, 1) - response, err := c.PageCallRecording(CallSid, params, "", "") + response, err := c.PageCallRecordingWithContext(ctx, CallSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamCallRecording(response, params, recordChannel, errorChannel) + go c.streamCallRecordingWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamCallRecording(response *ListCallRecordingResponse, params *ListCallRecordingParams, recordChannel chan ApiV2010CallRecording, errorChannel chan error) { +func (c *ApiService) streamCallRecordingWithContext(ctx context.Context, response *ListCallRecordingResponse, params *ListCallRecordingParams, recordChannel chan ApiV2010CallRecording, errorChannel chan error) { curRecord := 1 for response != nil { @@ -345,7 +370,7 @@ func (c *ApiService) streamCallRecording(response *ListCallRecordingResponse, pa } } - record, err := client.GetNext(c.baseURL, response, c.getNextListCallRecordingResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListCallRecordingResponseWithContext) if err != nil { errorChannel <- err break @@ -360,11 +385,11 @@ func (c *ApiService) streamCallRecording(response *ListCallRecordingResponse, pa close(errorChannel) } -func (c *ApiService) getNextListCallRecordingResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListCallRecordingResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -403,6 +428,9 @@ func (params *UpdateCallRecordingParams) SetPauseBehavior(PauseBehavior string) // Changes the status of the recording to paused, stopped, or in-progress. Note: Pass `Twilio.CURRENT` instead of recording sid to reference current active recording. func (c *ApiService) UpdateCallRecording(CallSid string, Sid string, params *UpdateCallRecordingParams) (*ApiV2010CallRecording, error) { + return c.UpdateCallRecordingWithContext(context.TODO(), CallSid, Sid, params) +} +func (c *ApiService) UpdateCallRecordingWithContext(ctx context.Context, CallSid string, Sid string, params *UpdateCallRecordingParams) (*ApiV2010CallRecording, error) { path := "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Recordings/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -424,7 +452,7 @@ func (c *ApiService) UpdateCallRecording(CallSid string, Sid string, params *Upd data.Set("PauseBehavior", *params.PauseBehavior) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_calls_siprec.go b/rest/api/v2010/accounts_calls_siprec.go index 40619a27a..63e160cc5 100644 --- a/rest/api/v2010/accounts_calls_siprec.go +++ b/rest/api/v2010/accounts_calls_siprec.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -1252,6 +1253,9 @@ func (params *CreateSiprecParams) SetParameter99Value(Parameter99Value string) * // Create a Siprec func (c *ApiService) CreateSiprec(CallSid string, params *CreateSiprecParams) (*ApiV2010Siprec, error) { + return c.CreateSiprecWithContext(context.TODO(), CallSid, params) +} +func (c *ApiService) CreateSiprecWithContext(ctx context.Context, CallSid string, params *CreateSiprecParams) (*ApiV2010Siprec, error) { path := "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Siprec.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -1875,7 +1879,7 @@ func (c *ApiService) CreateSiprec(CallSid string, params *CreateSiprecParams) (* data.Set("Parameter99.Value", *params.Parameter99Value) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -1909,6 +1913,9 @@ func (params *UpdateSiprecParams) SetStatus(Status string) *UpdateSiprecParams { // Stop a Siprec using either the SID of the Siprec resource or the `name` used when creating the resource func (c *ApiService) UpdateSiprec(CallSid string, Sid string, params *UpdateSiprecParams) (*ApiV2010Siprec, error) { + return c.UpdateSiprecWithContext(context.TODO(), CallSid, Sid, params) +} +func (c *ApiService) UpdateSiprecWithContext(ctx context.Context, CallSid string, Sid string, params *UpdateSiprecParams) (*ApiV2010Siprec, error) { path := "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Siprec/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -1927,7 +1934,7 @@ func (c *ApiService) UpdateSiprec(CallSid string, Sid string, params *UpdateSipr data.Set("Status", fmt.Sprint(*params.Status)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_calls_streams.go b/rest/api/v2010/accounts_calls_streams.go index 01e2ec442..ec0131010 100644 --- a/rest/api/v2010/accounts_calls_streams.go +++ b/rest/api/v2010/accounts_calls_streams.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -1252,6 +1253,9 @@ func (params *CreateStreamParams) SetParameter99Value(Parameter99Value string) * // Create a Stream func (c *ApiService) CreateStream(CallSid string, params *CreateStreamParams) (*ApiV2010Stream, error) { + return c.CreateStreamWithContext(context.TODO(), CallSid, params) +} +func (c *ApiService) CreateStreamWithContext(ctx context.Context, CallSid string, params *CreateStreamParams) (*ApiV2010Stream, error) { path := "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Streams.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -1875,7 +1879,7 @@ func (c *ApiService) CreateStream(CallSid string, params *CreateStreamParams) (* data.Set("Parameter99.Value", *params.Parameter99Value) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -1909,6 +1913,9 @@ func (params *UpdateStreamParams) SetStatus(Status string) *UpdateStreamParams { // Stop a Stream using either the SID of the Stream resource or the `name` used when creating the resource func (c *ApiService) UpdateStream(CallSid string, Sid string, params *UpdateStreamParams) (*ApiV2010Stream, error) { + return c.UpdateStreamWithContext(context.TODO(), CallSid, Sid, params) +} +func (c *ApiService) UpdateStreamWithContext(ctx context.Context, CallSid string, Sid string, params *UpdateStreamParams) (*ApiV2010Stream, error) { path := "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Streams/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -1927,7 +1934,7 @@ func (c *ApiService) UpdateStream(CallSid string, Sid string, params *UpdateStre data.Set("Status", fmt.Sprint(*params.Status)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_calls_transcriptions.go b/rest/api/v2010/accounts_calls_transcriptions.go index d12b7e075..7b154512d 100644 --- a/rest/api/v2010/accounts_calls_transcriptions.go +++ b/rest/api/v2010/accounts_calls_transcriptions.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -118,6 +119,9 @@ func (params *CreateRealtimeTranscriptionParams) SetIntelligenceService(Intellig // Create a Transcription func (c *ApiService) CreateRealtimeTranscription(CallSid string, params *CreateRealtimeTranscriptionParams) (*ApiV2010RealtimeTranscription, error) { + return c.CreateRealtimeTranscriptionWithContext(context.TODO(), CallSid, params) +} +func (c *ApiService) CreateRealtimeTranscriptionWithContext(ctx context.Context, CallSid string, params *CreateRealtimeTranscriptionParams) (*ApiV2010RealtimeTranscription, error) { path := "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Transcriptions.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -174,7 +178,7 @@ func (c *ApiService) CreateRealtimeTranscription(CallSid string, params *CreateR data.Set("IntelligenceService", *params.IntelligenceService) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -208,6 +212,9 @@ func (params *UpdateRealtimeTranscriptionParams) SetStatus(Status string) *Updat // Stop a Transcription using either the SID of the Transcription resource or the `name` used when creating the resource func (c *ApiService) UpdateRealtimeTranscription(CallSid string, Sid string, params *UpdateRealtimeTranscriptionParams) (*ApiV2010RealtimeTranscription, error) { + return c.UpdateRealtimeTranscriptionWithContext(context.TODO(), CallSid, Sid, params) +} +func (c *ApiService) UpdateRealtimeTranscriptionWithContext(ctx context.Context, CallSid string, Sid string, params *UpdateRealtimeTranscriptionParams) (*ApiV2010RealtimeTranscription, error) { path := "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Transcriptions/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -226,7 +233,7 @@ func (c *ApiService) UpdateRealtimeTranscription(CallSid string, Sid string, par data.Set("Status", fmt.Sprint(*params.Status)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_calls_user_defined_message_subscriptions.go b/rest/api/v2010/accounts_calls_user_defined_message_subscriptions.go index 8cf8eff48..7062c68fb 100644 --- a/rest/api/v2010/accounts_calls_user_defined_message_subscriptions.go +++ b/rest/api/v2010/accounts_calls_user_defined_message_subscriptions.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -51,6 +52,9 @@ func (params *CreateUserDefinedMessageSubscriptionParams) SetMethod(Method strin // Subscribe to User Defined Messages for a given Call SID. func (c *ApiService) CreateUserDefinedMessageSubscription(CallSid string, params *CreateUserDefinedMessageSubscriptionParams) (*ApiV2010UserDefinedMessageSubscription, error) { + return c.CreateUserDefinedMessageSubscriptionWithContext(context.TODO(), CallSid, params) +} +func (c *ApiService) CreateUserDefinedMessageSubscriptionWithContext(ctx context.Context, CallSid string, params *CreateUserDefinedMessageSubscriptionParams) (*ApiV2010UserDefinedMessageSubscription, error) { path := "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/UserDefinedMessageSubscriptions.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -74,7 +78,7 @@ func (c *ApiService) CreateUserDefinedMessageSubscription(CallSid string, params data.Set("Method", *params.Method) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -102,6 +106,9 @@ func (params *DeleteUserDefinedMessageSubscriptionParams) SetPathAccountSid(Path // Delete a specific User Defined Message Subscription. func (c *ApiService) DeleteUserDefinedMessageSubscription(CallSid string, Sid string, params *DeleteUserDefinedMessageSubscriptionParams) error { + return c.DeleteUserDefinedMessageSubscriptionWithContext(context.TODO(), CallSid, Sid, params) +} +func (c *ApiService) DeleteUserDefinedMessageSubscriptionWithContext(ctx context.Context, CallSid string, Sid string, params *DeleteUserDefinedMessageSubscriptionParams) error { path := "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/UserDefinedMessageSubscriptions/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -116,7 +123,7 @@ func (c *ApiService) DeleteUserDefinedMessageSubscription(CallSid string, Sid st "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } diff --git a/rest/api/v2010/accounts_calls_user_defined_messages.go b/rest/api/v2010/accounts_calls_user_defined_messages.go index 53ad8d5ac..a775b094e 100644 --- a/rest/api/v2010/accounts_calls_user_defined_messages.go +++ b/rest/api/v2010/accounts_calls_user_defined_messages.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -45,6 +46,9 @@ func (params *CreateUserDefinedMessageParams) SetIdempotencyKey(IdempotencyKey s // Create a new User Defined Message for the given Call SID. func (c *ApiService) CreateUserDefinedMessage(CallSid string, params *CreateUserDefinedMessageParams) (*ApiV2010UserDefinedMessage, error) { + return c.CreateUserDefinedMessageWithContext(context.TODO(), CallSid, params) +} +func (c *ApiService) CreateUserDefinedMessageWithContext(ctx context.Context, CallSid string, params *CreateUserDefinedMessageParams) (*ApiV2010UserDefinedMessage, error) { path := "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/UserDefinedMessages.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -65,7 +69,7 @@ func (c *ApiService) CreateUserDefinedMessage(CallSid string, params *CreateUser data.Set("IdempotencyKey", *params.IdempotencyKey) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_conferences.go b/rest/api/v2010/accounts_conferences.go index 209a6d74c..2182d7945 100644 --- a/rest/api/v2010/accounts_conferences.go +++ b/rest/api/v2010/accounts_conferences.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -36,6 +37,9 @@ func (params *FetchConferenceParams) SetPathAccountSid(PathAccountSid string) *F // Fetch an instance of a conference func (c *ApiService) FetchConference(Sid string, params *FetchConferenceParams) (*ApiV2010Conference, error) { + return c.FetchConferenceWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) FetchConferenceWithContext(ctx context.Context, Sid string, params *FetchConferenceParams) (*ApiV2010Conference, error) { path := "/2010-04-01/Accounts/{AccountSid}/Conferences/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -49,7 +53,7 @@ func (c *ApiService) FetchConference(Sid string, params *FetchConferenceParams) "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -137,6 +141,11 @@ func (params *ListConferenceParams) SetLimit(Limit int) *ListConferenceParams { // Retrieve a single page of Conference records from the API. Request is executed immediately. func (c *ApiService) PageConference(params *ListConferenceParams, pageToken, pageNumber string) (*ListConferenceResponse, error) { + return c.PageConferenceWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Conference records from the API. Request is executed immediately. +func (c *ApiService) PageConferenceWithContext(ctx context.Context, params *ListConferenceParams, pageToken, pageNumber string) (*ListConferenceResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/Conferences.json" if params != nil && params.PathAccountSid != nil { @@ -185,7 +194,7 @@ func (c *ApiService) PageConference(params *ListConferenceParams, pageToken, pag data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -202,7 +211,12 @@ func (c *ApiService) PageConference(params *ListConferenceParams, pageToken, pag // Lists Conference records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListConference(params *ListConferenceParams) ([]ApiV2010Conference, error) { - response, errors := c.StreamConference(params) + return c.ListConferenceWithContext(context.TODO(), params) +} + +// Lists Conference records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListConferenceWithContext(ctx context.Context, params *ListConferenceParams) ([]ApiV2010Conference, error) { + response, errors := c.StreamConferenceWithContext(ctx, params) records := make([]ApiV2010Conference, 0) for record := range response { @@ -218,6 +232,11 @@ func (c *ApiService) ListConference(params *ListConferenceParams) ([]ApiV2010Con // Streams Conference records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamConference(params *ListConferenceParams) (chan ApiV2010Conference, chan error) { + return c.StreamConferenceWithContext(context.TODO(), params) +} + +// Streams Conference records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamConferenceWithContext(ctx context.Context, params *ListConferenceParams) (chan ApiV2010Conference, chan error) { if params == nil { params = &ListConferenceParams{} } @@ -226,19 +245,19 @@ func (c *ApiService) StreamConference(params *ListConferenceParams) (chan ApiV20 recordChannel := make(chan ApiV2010Conference, 1) errorChannel := make(chan error, 1) - response, err := c.PageConference(params, "", "") + response, err := c.PageConferenceWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamConference(response, params, recordChannel, errorChannel) + go c.streamConferenceWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamConference(response *ListConferenceResponse, params *ListConferenceParams, recordChannel chan ApiV2010Conference, errorChannel chan error) { +func (c *ApiService) streamConferenceWithContext(ctx context.Context, response *ListConferenceResponse, params *ListConferenceParams, recordChannel chan ApiV2010Conference, errorChannel chan error) { curRecord := 1 for response != nil { @@ -253,7 +272,7 @@ func (c *ApiService) streamConference(response *ListConferenceResponse, params * } } - record, err := client.GetNext(c.baseURL, response, c.getNextListConferenceResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListConferenceResponseWithContext) if err != nil { errorChannel <- err break @@ -268,11 +287,11 @@ func (c *ApiService) streamConference(response *ListConferenceResponse, params * close(errorChannel) } -func (c *ApiService) getNextListConferenceResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListConferenceResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -315,8 +334,10 @@ func (params *UpdateConferenceParams) SetAnnounceMethod(AnnounceMethod string) * return params } -// func (c *ApiService) UpdateConference(Sid string, params *UpdateConferenceParams) (*ApiV2010Conference, error) { + return c.UpdateConferenceWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateConferenceWithContext(ctx context.Context, Sid string, params *UpdateConferenceParams) (*ApiV2010Conference, error) { path := "/2010-04-01/Accounts/{AccountSid}/Conferences/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -340,7 +361,7 @@ func (c *ApiService) UpdateConference(Sid string, params *UpdateConferenceParams data.Set("AnnounceMethod", *params.AnnounceMethod) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_conferences_participants.go b/rest/api/v2010/accounts_conferences_participants.go index 9e827c772..a5c32c2fd 100644 --- a/rest/api/v2010/accounts_conferences_participants.go +++ b/rest/api/v2010/accounts_conferences_participants.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -322,8 +323,10 @@ func (params *CreateParticipantParams) SetCallToken(CallToken string) *CreatePar return params } -// func (c *ApiService) CreateParticipant(ConferenceSid string, params *CreateParticipantParams) (*ApiV2010Participant, error) { + return c.CreateParticipantWithContext(context.TODO(), ConferenceSid, params) +} +func (c *ApiService) CreateParticipantWithContext(ctx context.Context, ConferenceSid string, params *CreateParticipantParams) (*ApiV2010Participant, error) { path := "/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Participants.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -490,7 +493,7 @@ func (c *ApiService) CreateParticipant(ConferenceSid string, params *CreateParti data.Set("CallToken", *params.CallToken) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -518,6 +521,9 @@ func (params *DeleteParticipantParams) SetPathAccountSid(PathAccountSid string) // Kick a participant from a given conference func (c *ApiService) DeleteParticipant(ConferenceSid string, CallSid string, params *DeleteParticipantParams) error { + return c.DeleteParticipantWithContext(context.TODO(), ConferenceSid, CallSid, params) +} +func (c *ApiService) DeleteParticipantWithContext(ctx context.Context, ConferenceSid string, CallSid string, params *DeleteParticipantParams) error { path := "/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Participants/{CallSid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -532,7 +538,7 @@ func (c *ApiService) DeleteParticipant(ConferenceSid string, CallSid string, par "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -555,6 +561,9 @@ func (params *FetchParticipantParams) SetPathAccountSid(PathAccountSid string) * // Fetch an instance of a participant func (c *ApiService) FetchParticipant(ConferenceSid string, CallSid string, params *FetchParticipantParams) (*ApiV2010Participant, error) { + return c.FetchParticipantWithContext(context.TODO(), ConferenceSid, CallSid, params) +} +func (c *ApiService) FetchParticipantWithContext(ctx context.Context, ConferenceSid string, CallSid string, params *FetchParticipantParams) (*ApiV2010Participant, error) { path := "/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Participants/{CallSid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -569,7 +578,7 @@ func (c *ApiService) FetchParticipant(ConferenceSid string, CallSid string, para "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -627,6 +636,11 @@ func (params *ListParticipantParams) SetLimit(Limit int) *ListParticipantParams // Retrieve a single page of Participant records from the API. Request is executed immediately. func (c *ApiService) PageParticipant(ConferenceSid string, params *ListParticipantParams, pageToken, pageNumber string) (*ListParticipantResponse, error) { + return c.PageParticipantWithContext(context.TODO(), ConferenceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Participant records from the API. Request is executed immediately. +func (c *ApiService) PageParticipantWithContext(ctx context.Context, ConferenceSid string, params *ListParticipantParams, pageToken, pageNumber string) (*ListParticipantResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Participants.json" if params != nil && params.PathAccountSid != nil { @@ -661,7 +675,7 @@ func (c *ApiService) PageParticipant(ConferenceSid string, params *ListParticipa data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -678,7 +692,12 @@ func (c *ApiService) PageParticipant(ConferenceSid string, params *ListParticipa // Lists Participant records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListParticipant(ConferenceSid string, params *ListParticipantParams) ([]ApiV2010Participant, error) { - response, errors := c.StreamParticipant(ConferenceSid, params) + return c.ListParticipantWithContext(context.TODO(), ConferenceSid, params) +} + +// Lists Participant records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListParticipantWithContext(ctx context.Context, ConferenceSid string, params *ListParticipantParams) ([]ApiV2010Participant, error) { + response, errors := c.StreamParticipantWithContext(ctx, ConferenceSid, params) records := make([]ApiV2010Participant, 0) for record := range response { @@ -694,6 +713,11 @@ func (c *ApiService) ListParticipant(ConferenceSid string, params *ListParticipa // Streams Participant records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamParticipant(ConferenceSid string, params *ListParticipantParams) (chan ApiV2010Participant, chan error) { + return c.StreamParticipantWithContext(context.TODO(), ConferenceSid, params) +} + +// Streams Participant records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamParticipantWithContext(ctx context.Context, ConferenceSid string, params *ListParticipantParams) (chan ApiV2010Participant, chan error) { if params == nil { params = &ListParticipantParams{} } @@ -702,19 +726,19 @@ func (c *ApiService) StreamParticipant(ConferenceSid string, params *ListPartici recordChannel := make(chan ApiV2010Participant, 1) errorChannel := make(chan error, 1) - response, err := c.PageParticipant(ConferenceSid, params, "", "") + response, err := c.PageParticipantWithContext(ctx, ConferenceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamParticipant(response, params, recordChannel, errorChannel) + go c.streamParticipantWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamParticipant(response *ListParticipantResponse, params *ListParticipantParams, recordChannel chan ApiV2010Participant, errorChannel chan error) { +func (c *ApiService) streamParticipantWithContext(ctx context.Context, response *ListParticipantResponse, params *ListParticipantParams, recordChannel chan ApiV2010Participant, errorChannel chan error) { curRecord := 1 for response != nil { @@ -729,7 +753,7 @@ func (c *ApiService) streamParticipant(response *ListParticipantResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListParticipantResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListParticipantResponseWithContext) if err != nil { errorChannel <- err break @@ -744,11 +768,11 @@ func (c *ApiService) streamParticipant(response *ListParticipantResponse, params close(errorChannel) } -func (c *ApiService) getNextListParticipantResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListParticipantResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -847,6 +871,9 @@ func (params *UpdateParticipantParams) SetCallSidToCoach(CallSidToCoach string) // Update the properties of the participant func (c *ApiService) UpdateParticipant(ConferenceSid string, CallSid string, params *UpdateParticipantParams) (*ApiV2010Participant, error) { + return c.UpdateParticipantWithContext(context.TODO(), ConferenceSid, CallSid, params) +} +func (c *ApiService) UpdateParticipantWithContext(ctx context.Context, ConferenceSid string, CallSid string, params *UpdateParticipantParams) (*ApiV2010Participant, error) { path := "/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Participants/{CallSid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -898,7 +925,7 @@ func (c *ApiService) UpdateParticipant(ConferenceSid string, CallSid string, par data.Set("CallSidToCoach", *params.CallSidToCoach) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_conferences_recordings.go b/rest/api/v2010/accounts_conferences_recordings.go index 0341f3a6d..4abedf698 100644 --- a/rest/api/v2010/accounts_conferences_recordings.go +++ b/rest/api/v2010/accounts_conferences_recordings.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -36,6 +37,9 @@ func (params *DeleteConferenceRecordingParams) SetPathAccountSid(PathAccountSid // Delete a recording from your account func (c *ApiService) DeleteConferenceRecording(ConferenceSid string, Sid string, params *DeleteConferenceRecordingParams) error { + return c.DeleteConferenceRecordingWithContext(context.TODO(), ConferenceSid, Sid, params) +} +func (c *ApiService) DeleteConferenceRecordingWithContext(ctx context.Context, ConferenceSid string, Sid string, params *DeleteConferenceRecordingParams) error { path := "/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Recordings/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -50,7 +54,7 @@ func (c *ApiService) DeleteConferenceRecording(ConferenceSid string, Sid string, "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -73,6 +77,9 @@ func (params *FetchConferenceRecordingParams) SetPathAccountSid(PathAccountSid s // Fetch an instance of a recording for a call func (c *ApiService) FetchConferenceRecording(ConferenceSid string, Sid string, params *FetchConferenceRecordingParams) (*ApiV2010ConferenceRecording, error) { + return c.FetchConferenceRecordingWithContext(context.TODO(), ConferenceSid, Sid, params) +} +func (c *ApiService) FetchConferenceRecordingWithContext(ctx context.Context, ConferenceSid string, Sid string, params *FetchConferenceRecordingParams) (*ApiV2010ConferenceRecording, error) { path := "/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Recordings/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -87,7 +94,7 @@ func (c *ApiService) FetchConferenceRecording(ConferenceSid string, Sid string, "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -145,6 +152,11 @@ func (params *ListConferenceRecordingParams) SetLimit(Limit int) *ListConference // Retrieve a single page of ConferenceRecording records from the API. Request is executed immediately. func (c *ApiService) PageConferenceRecording(ConferenceSid string, params *ListConferenceRecordingParams, pageToken, pageNumber string) (*ListConferenceRecordingResponse, error) { + return c.PageConferenceRecordingWithContext(context.TODO(), ConferenceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ConferenceRecording records from the API. Request is executed immediately. +func (c *ApiService) PageConferenceRecordingWithContext(ctx context.Context, ConferenceSid string, params *ListConferenceRecordingParams, pageToken, pageNumber string) (*ListConferenceRecordingResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Recordings.json" if params != nil && params.PathAccountSid != nil { @@ -179,7 +191,7 @@ func (c *ApiService) PageConferenceRecording(ConferenceSid string, params *ListC data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -196,7 +208,12 @@ func (c *ApiService) PageConferenceRecording(ConferenceSid string, params *ListC // Lists ConferenceRecording records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListConferenceRecording(ConferenceSid string, params *ListConferenceRecordingParams) ([]ApiV2010ConferenceRecording, error) { - response, errors := c.StreamConferenceRecording(ConferenceSid, params) + return c.ListConferenceRecordingWithContext(context.TODO(), ConferenceSid, params) +} + +// Lists ConferenceRecording records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListConferenceRecordingWithContext(ctx context.Context, ConferenceSid string, params *ListConferenceRecordingParams) ([]ApiV2010ConferenceRecording, error) { + response, errors := c.StreamConferenceRecordingWithContext(ctx, ConferenceSid, params) records := make([]ApiV2010ConferenceRecording, 0) for record := range response { @@ -212,6 +229,11 @@ func (c *ApiService) ListConferenceRecording(ConferenceSid string, params *ListC // Streams ConferenceRecording records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamConferenceRecording(ConferenceSid string, params *ListConferenceRecordingParams) (chan ApiV2010ConferenceRecording, chan error) { + return c.StreamConferenceRecordingWithContext(context.TODO(), ConferenceSid, params) +} + +// Streams ConferenceRecording records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamConferenceRecordingWithContext(ctx context.Context, ConferenceSid string, params *ListConferenceRecordingParams) (chan ApiV2010ConferenceRecording, chan error) { if params == nil { params = &ListConferenceRecordingParams{} } @@ -220,19 +242,19 @@ func (c *ApiService) StreamConferenceRecording(ConferenceSid string, params *Lis recordChannel := make(chan ApiV2010ConferenceRecording, 1) errorChannel := make(chan error, 1) - response, err := c.PageConferenceRecording(ConferenceSid, params, "", "") + response, err := c.PageConferenceRecordingWithContext(ctx, ConferenceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamConferenceRecording(response, params, recordChannel, errorChannel) + go c.streamConferenceRecordingWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamConferenceRecording(response *ListConferenceRecordingResponse, params *ListConferenceRecordingParams, recordChannel chan ApiV2010ConferenceRecording, errorChannel chan error) { +func (c *ApiService) streamConferenceRecordingWithContext(ctx context.Context, response *ListConferenceRecordingResponse, params *ListConferenceRecordingParams, recordChannel chan ApiV2010ConferenceRecording, errorChannel chan error) { curRecord := 1 for response != nil { @@ -247,7 +269,7 @@ func (c *ApiService) streamConferenceRecording(response *ListConferenceRecording } } - record, err := client.GetNext(c.baseURL, response, c.getNextListConferenceRecordingResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListConferenceRecordingResponseWithContext) if err != nil { errorChannel <- err break @@ -262,11 +284,11 @@ func (c *ApiService) streamConferenceRecording(response *ListConferenceRecording close(errorChannel) } -func (c *ApiService) getNextListConferenceRecordingResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListConferenceRecordingResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -305,6 +327,9 @@ func (params *UpdateConferenceRecordingParams) SetPauseBehavior(PauseBehavior st // Changes the status of the recording to paused, stopped, or in-progress. Note: To use `Twilio.CURRENT`, pass it as recording sid. func (c *ApiService) UpdateConferenceRecording(ConferenceSid string, Sid string, params *UpdateConferenceRecordingParams) (*ApiV2010ConferenceRecording, error) { + return c.UpdateConferenceRecordingWithContext(context.TODO(), ConferenceSid, Sid, params) +} +func (c *ApiService) UpdateConferenceRecordingWithContext(ctx context.Context, ConferenceSid string, Sid string, params *UpdateConferenceRecordingParams) (*ApiV2010ConferenceRecording, error) { path := "/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Recordings/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -326,7 +351,7 @@ func (c *ApiService) UpdateConferenceRecording(ConferenceSid string, Sid string, data.Set("PauseBehavior", *params.PauseBehavior) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_connect_apps.go b/rest/api/v2010/accounts_connect_apps.go index 0df2f7fa4..8a6427ae9 100644 --- a/rest/api/v2010/accounts_connect_apps.go +++ b/rest/api/v2010/accounts_connect_apps.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -36,6 +37,9 @@ func (params *DeleteConnectAppParams) SetPathAccountSid(PathAccountSid string) * // Delete an instance of a connect-app func (c *ApiService) DeleteConnectApp(Sid string, params *DeleteConnectAppParams) error { + return c.DeleteConnectAppWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) DeleteConnectAppWithContext(ctx context.Context, Sid string, params *DeleteConnectAppParams) error { path := "/2010-04-01/Accounts/{AccountSid}/ConnectApps/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -49,7 +53,7 @@ func (c *ApiService) DeleteConnectApp(Sid string, params *DeleteConnectAppParams "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -72,6 +76,9 @@ func (params *FetchConnectAppParams) SetPathAccountSid(PathAccountSid string) *F // Fetch an instance of a connect-app func (c *ApiService) FetchConnectApp(Sid string, params *FetchConnectAppParams) (*ApiV2010ConnectApp, error) { + return c.FetchConnectAppWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) FetchConnectAppWithContext(ctx context.Context, Sid string, params *FetchConnectAppParams) (*ApiV2010ConnectApp, error) { path := "/2010-04-01/Accounts/{AccountSid}/ConnectApps/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -85,7 +92,7 @@ func (c *ApiService) FetchConnectApp(Sid string, params *FetchConnectAppParams) "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -125,6 +132,11 @@ func (params *ListConnectAppParams) SetLimit(Limit int) *ListConnectAppParams { // Retrieve a single page of ConnectApp records from the API. Request is executed immediately. func (c *ApiService) PageConnectApp(params *ListConnectAppParams, pageToken, pageNumber string) (*ListConnectAppResponse, error) { + return c.PageConnectAppWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of ConnectApp records from the API. Request is executed immediately. +func (c *ApiService) PageConnectAppWithContext(ctx context.Context, params *ListConnectAppParams, pageToken, pageNumber string) (*ListConnectAppResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/ConnectApps.json" if params != nil && params.PathAccountSid != nil { @@ -149,7 +161,7 @@ func (c *ApiService) PageConnectApp(params *ListConnectAppParams, pageToken, pag data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -166,7 +178,12 @@ func (c *ApiService) PageConnectApp(params *ListConnectAppParams, pageToken, pag // Lists ConnectApp records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListConnectApp(params *ListConnectAppParams) ([]ApiV2010ConnectApp, error) { - response, errors := c.StreamConnectApp(params) + return c.ListConnectAppWithContext(context.TODO(), params) +} + +// Lists ConnectApp records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListConnectAppWithContext(ctx context.Context, params *ListConnectAppParams) ([]ApiV2010ConnectApp, error) { + response, errors := c.StreamConnectAppWithContext(ctx, params) records := make([]ApiV2010ConnectApp, 0) for record := range response { @@ -182,6 +199,11 @@ func (c *ApiService) ListConnectApp(params *ListConnectAppParams) ([]ApiV2010Con // Streams ConnectApp records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamConnectApp(params *ListConnectAppParams) (chan ApiV2010ConnectApp, chan error) { + return c.StreamConnectAppWithContext(context.TODO(), params) +} + +// Streams ConnectApp records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamConnectAppWithContext(ctx context.Context, params *ListConnectAppParams) (chan ApiV2010ConnectApp, chan error) { if params == nil { params = &ListConnectAppParams{} } @@ -190,19 +212,19 @@ func (c *ApiService) StreamConnectApp(params *ListConnectAppParams) (chan ApiV20 recordChannel := make(chan ApiV2010ConnectApp, 1) errorChannel := make(chan error, 1) - response, err := c.PageConnectApp(params, "", "") + response, err := c.PageConnectAppWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamConnectApp(response, params, recordChannel, errorChannel) + go c.streamConnectAppWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamConnectApp(response *ListConnectAppResponse, params *ListConnectAppParams, recordChannel chan ApiV2010ConnectApp, errorChannel chan error) { +func (c *ApiService) streamConnectAppWithContext(ctx context.Context, response *ListConnectAppResponse, params *ListConnectAppParams, recordChannel chan ApiV2010ConnectApp, errorChannel chan error) { curRecord := 1 for response != nil { @@ -217,7 +239,7 @@ func (c *ApiService) streamConnectApp(response *ListConnectAppResponse, params * } } - record, err := client.GetNext(c.baseURL, response, c.getNextListConnectAppResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListConnectAppResponseWithContext) if err != nil { errorChannel <- err break @@ -232,11 +254,11 @@ func (c *ApiService) streamConnectApp(response *ListConnectAppResponse, params * close(errorChannel) } -func (c *ApiService) getNextListConnectAppResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListConnectAppResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -311,6 +333,9 @@ func (params *UpdateConnectAppParams) SetPermissions(Permissions []string) *Upda // Update a connect-app with the specified parameters func (c *ApiService) UpdateConnectApp(Sid string, params *UpdateConnectAppParams) (*ApiV2010ConnectApp, error) { + return c.UpdateConnectAppWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateConnectAppWithContext(ctx context.Context, Sid string, params *UpdateConnectAppParams) (*ApiV2010ConnectApp, error) { path := "/2010-04-01/Accounts/{AccountSid}/ConnectApps/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -351,7 +376,7 @@ func (c *ApiService) UpdateConnectApp(Sid string, params *UpdateConnectAppParams } } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_incoming_phone_numbers.go b/rest/api/v2010/accounts_incoming_phone_numbers.go index ca5bf8ce7..8b1250df7 100644 --- a/rest/api/v2010/accounts_incoming_phone_numbers.go +++ b/rest/api/v2010/accounts_incoming_phone_numbers.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -180,6 +181,9 @@ func (params *CreateIncomingPhoneNumberParams) SetAreaCode(AreaCode string) *Cre // Purchase a phone-number for the account. func (c *ApiService) CreateIncomingPhoneNumber(params *CreateIncomingPhoneNumberParams) (*ApiV2010IncomingPhoneNumber, error) { + return c.CreateIncomingPhoneNumberWithContext(context.TODO(), params) +} +func (c *ApiService) CreateIncomingPhoneNumberWithContext(ctx context.Context, params *CreateIncomingPhoneNumberParams) (*ApiV2010IncomingPhoneNumber, error) { path := "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -265,7 +269,7 @@ func (c *ApiService) CreateIncomingPhoneNumber(params *CreateIncomingPhoneNumber data.Set("AreaCode", *params.AreaCode) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -293,6 +297,9 @@ func (params *DeleteIncomingPhoneNumberParams) SetPathAccountSid(PathAccountSid // Delete a phone-numbers belonging to the account used to make the request. func (c *ApiService) DeleteIncomingPhoneNumber(Sid string, params *DeleteIncomingPhoneNumberParams) error { + return c.DeleteIncomingPhoneNumberWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) DeleteIncomingPhoneNumberWithContext(ctx context.Context, Sid string, params *DeleteIncomingPhoneNumberParams) error { path := "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -306,7 +313,7 @@ func (c *ApiService) DeleteIncomingPhoneNumber(Sid string, params *DeleteIncomin "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -329,6 +336,9 @@ func (params *FetchIncomingPhoneNumberParams) SetPathAccountSid(PathAccountSid s // Fetch an incoming-phone-number belonging to the account used to make the request. func (c *ApiService) FetchIncomingPhoneNumber(Sid string, params *FetchIncomingPhoneNumberParams) (*ApiV2010IncomingPhoneNumber, error) { + return c.FetchIncomingPhoneNumberWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) FetchIncomingPhoneNumberWithContext(ctx context.Context, Sid string, params *FetchIncomingPhoneNumberParams) (*ApiV2010IncomingPhoneNumber, error) { path := "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -342,7 +352,7 @@ func (c *ApiService) FetchIncomingPhoneNumber(Sid string, params *FetchIncomingP "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -406,6 +416,11 @@ func (params *ListIncomingPhoneNumberParams) SetLimit(Limit int) *ListIncomingPh // Retrieve a single page of IncomingPhoneNumber records from the API. Request is executed immediately. func (c *ApiService) PageIncomingPhoneNumber(params *ListIncomingPhoneNumberParams, pageToken, pageNumber string) (*ListIncomingPhoneNumberResponse, error) { + return c.PageIncomingPhoneNumberWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of IncomingPhoneNumber records from the API. Request is executed immediately. +func (c *ApiService) PageIncomingPhoneNumberWithContext(ctx context.Context, params *ListIncomingPhoneNumberParams, pageToken, pageNumber string) (*ListIncomingPhoneNumberResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers.json" if params != nil && params.PathAccountSid != nil { @@ -442,7 +457,7 @@ func (c *ApiService) PageIncomingPhoneNumber(params *ListIncomingPhoneNumberPara data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -459,7 +474,12 @@ func (c *ApiService) PageIncomingPhoneNumber(params *ListIncomingPhoneNumberPara // Lists IncomingPhoneNumber records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListIncomingPhoneNumber(params *ListIncomingPhoneNumberParams) ([]ApiV2010IncomingPhoneNumber, error) { - response, errors := c.StreamIncomingPhoneNumber(params) + return c.ListIncomingPhoneNumberWithContext(context.TODO(), params) +} + +// Lists IncomingPhoneNumber records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListIncomingPhoneNumberWithContext(ctx context.Context, params *ListIncomingPhoneNumberParams) ([]ApiV2010IncomingPhoneNumber, error) { + response, errors := c.StreamIncomingPhoneNumberWithContext(ctx, params) records := make([]ApiV2010IncomingPhoneNumber, 0) for record := range response { @@ -475,6 +495,11 @@ func (c *ApiService) ListIncomingPhoneNumber(params *ListIncomingPhoneNumberPara // Streams IncomingPhoneNumber records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamIncomingPhoneNumber(params *ListIncomingPhoneNumberParams) (chan ApiV2010IncomingPhoneNumber, chan error) { + return c.StreamIncomingPhoneNumberWithContext(context.TODO(), params) +} + +// Streams IncomingPhoneNumber records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamIncomingPhoneNumberWithContext(ctx context.Context, params *ListIncomingPhoneNumberParams) (chan ApiV2010IncomingPhoneNumber, chan error) { if params == nil { params = &ListIncomingPhoneNumberParams{} } @@ -483,19 +508,19 @@ func (c *ApiService) StreamIncomingPhoneNumber(params *ListIncomingPhoneNumberPa recordChannel := make(chan ApiV2010IncomingPhoneNumber, 1) errorChannel := make(chan error, 1) - response, err := c.PageIncomingPhoneNumber(params, "", "") + response, err := c.PageIncomingPhoneNumberWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamIncomingPhoneNumber(response, params, recordChannel, errorChannel) + go c.streamIncomingPhoneNumberWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamIncomingPhoneNumber(response *ListIncomingPhoneNumberResponse, params *ListIncomingPhoneNumberParams, recordChannel chan ApiV2010IncomingPhoneNumber, errorChannel chan error) { +func (c *ApiService) streamIncomingPhoneNumberWithContext(ctx context.Context, response *ListIncomingPhoneNumberResponse, params *ListIncomingPhoneNumberParams, recordChannel chan ApiV2010IncomingPhoneNumber, errorChannel chan error) { curRecord := 1 for response != nil { @@ -510,7 +535,7 @@ func (c *ApiService) streamIncomingPhoneNumber(response *ListIncomingPhoneNumber } } - record, err := client.GetNext(c.baseURL, response, c.getNextListIncomingPhoneNumberResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListIncomingPhoneNumberResponseWithContext) if err != nil { errorChannel <- err break @@ -525,11 +550,11 @@ func (c *ApiService) streamIncomingPhoneNumber(response *ListIncomingPhoneNumber close(errorChannel) } -func (c *ApiService) getNextListIncomingPhoneNumberResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListIncomingPhoneNumberResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -694,6 +719,9 @@ func (params *UpdateIncomingPhoneNumberParams) SetBundleSid(BundleSid string) *U // Update an incoming-phone-number instance. func (c *ApiService) UpdateIncomingPhoneNumber(Sid string, params *UpdateIncomingPhoneNumberParams) (*ApiV2010IncomingPhoneNumber, error) { + return c.UpdateIncomingPhoneNumberWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateIncomingPhoneNumberWithContext(ctx context.Context, Sid string, params *UpdateIncomingPhoneNumberParams) (*ApiV2010IncomingPhoneNumber, error) { path := "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -777,7 +805,7 @@ func (c *ApiService) UpdateIncomingPhoneNumber(Sid string, params *UpdateIncomin data.Set("BundleSid", *params.BundleSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_incoming_phone_numbers_assigned_add_ons.go b/rest/api/v2010/accounts_incoming_phone_numbers_assigned_add_ons.go index 2a1d3bab5..9dda8edf9 100644 --- a/rest/api/v2010/accounts_incoming_phone_numbers_assigned_add_ons.go +++ b/rest/api/v2010/accounts_incoming_phone_numbers_assigned_add_ons.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -42,6 +43,9 @@ func (params *CreateIncomingPhoneNumberAssignedAddOnParams) SetInstalledAddOnSid // Assign an Add-on installation to the Number specified. func (c *ApiService) CreateIncomingPhoneNumberAssignedAddOn(ResourceSid string, params *CreateIncomingPhoneNumberAssignedAddOnParams) (*ApiV2010IncomingPhoneNumberAssignedAddOn, error) { + return c.CreateIncomingPhoneNumberAssignedAddOnWithContext(context.TODO(), ResourceSid, params) +} +func (c *ApiService) CreateIncomingPhoneNumberAssignedAddOnWithContext(ctx context.Context, ResourceSid string, params *CreateIncomingPhoneNumberAssignedAddOnParams) (*ApiV2010IncomingPhoneNumberAssignedAddOn, error) { path := "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{ResourceSid}/AssignedAddOns.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -59,7 +63,7 @@ func (c *ApiService) CreateIncomingPhoneNumberAssignedAddOn(ResourceSid string, data.Set("InstalledAddOnSid", *params.InstalledAddOnSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -87,6 +91,9 @@ func (params *DeleteIncomingPhoneNumberAssignedAddOnParams) SetPathAccountSid(Pa // Remove the assignment of an Add-on installation from the Number specified. func (c *ApiService) DeleteIncomingPhoneNumberAssignedAddOn(ResourceSid string, Sid string, params *DeleteIncomingPhoneNumberAssignedAddOnParams) error { + return c.DeleteIncomingPhoneNumberAssignedAddOnWithContext(context.TODO(), ResourceSid, Sid, params) +} +func (c *ApiService) DeleteIncomingPhoneNumberAssignedAddOnWithContext(ctx context.Context, ResourceSid string, Sid string, params *DeleteIncomingPhoneNumberAssignedAddOnParams) error { path := "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{ResourceSid}/AssignedAddOns/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -101,7 +108,7 @@ func (c *ApiService) DeleteIncomingPhoneNumberAssignedAddOn(ResourceSid string, "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -124,6 +131,9 @@ func (params *FetchIncomingPhoneNumberAssignedAddOnParams) SetPathAccountSid(Pat // Fetch an instance of an Add-on installation currently assigned to this Number. func (c *ApiService) FetchIncomingPhoneNumberAssignedAddOn(ResourceSid string, Sid string, params *FetchIncomingPhoneNumberAssignedAddOnParams) (*ApiV2010IncomingPhoneNumberAssignedAddOn, error) { + return c.FetchIncomingPhoneNumberAssignedAddOnWithContext(context.TODO(), ResourceSid, Sid, params) +} +func (c *ApiService) FetchIncomingPhoneNumberAssignedAddOnWithContext(ctx context.Context, ResourceSid string, Sid string, params *FetchIncomingPhoneNumberAssignedAddOnParams) (*ApiV2010IncomingPhoneNumberAssignedAddOn, error) { path := "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{ResourceSid}/AssignedAddOns/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -138,7 +148,7 @@ func (c *ApiService) FetchIncomingPhoneNumberAssignedAddOn(ResourceSid string, S "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -178,6 +188,11 @@ func (params *ListIncomingPhoneNumberAssignedAddOnParams) SetLimit(Limit int) *L // Retrieve a single page of IncomingPhoneNumberAssignedAddOn records from the API. Request is executed immediately. func (c *ApiService) PageIncomingPhoneNumberAssignedAddOn(ResourceSid string, params *ListIncomingPhoneNumberAssignedAddOnParams, pageToken, pageNumber string) (*ListIncomingPhoneNumberAssignedAddOnResponse, error) { + return c.PageIncomingPhoneNumberAssignedAddOnWithContext(context.TODO(), ResourceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of IncomingPhoneNumberAssignedAddOn records from the API. Request is executed immediately. +func (c *ApiService) PageIncomingPhoneNumberAssignedAddOnWithContext(ctx context.Context, ResourceSid string, params *ListIncomingPhoneNumberAssignedAddOnParams, pageToken, pageNumber string) (*ListIncomingPhoneNumberAssignedAddOnResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{ResourceSid}/AssignedAddOns.json" if params != nil && params.PathAccountSid != nil { @@ -203,7 +218,7 @@ func (c *ApiService) PageIncomingPhoneNumberAssignedAddOn(ResourceSid string, pa data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -220,7 +235,12 @@ func (c *ApiService) PageIncomingPhoneNumberAssignedAddOn(ResourceSid string, pa // Lists IncomingPhoneNumberAssignedAddOn records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListIncomingPhoneNumberAssignedAddOn(ResourceSid string, params *ListIncomingPhoneNumberAssignedAddOnParams) ([]ApiV2010IncomingPhoneNumberAssignedAddOn, error) { - response, errors := c.StreamIncomingPhoneNumberAssignedAddOn(ResourceSid, params) + return c.ListIncomingPhoneNumberAssignedAddOnWithContext(context.TODO(), ResourceSid, params) +} + +// Lists IncomingPhoneNumberAssignedAddOn records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListIncomingPhoneNumberAssignedAddOnWithContext(ctx context.Context, ResourceSid string, params *ListIncomingPhoneNumberAssignedAddOnParams) ([]ApiV2010IncomingPhoneNumberAssignedAddOn, error) { + response, errors := c.StreamIncomingPhoneNumberAssignedAddOnWithContext(ctx, ResourceSid, params) records := make([]ApiV2010IncomingPhoneNumberAssignedAddOn, 0) for record := range response { @@ -236,6 +256,11 @@ func (c *ApiService) ListIncomingPhoneNumberAssignedAddOn(ResourceSid string, pa // Streams IncomingPhoneNumberAssignedAddOn records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamIncomingPhoneNumberAssignedAddOn(ResourceSid string, params *ListIncomingPhoneNumberAssignedAddOnParams) (chan ApiV2010IncomingPhoneNumberAssignedAddOn, chan error) { + return c.StreamIncomingPhoneNumberAssignedAddOnWithContext(context.TODO(), ResourceSid, params) +} + +// Streams IncomingPhoneNumberAssignedAddOn records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamIncomingPhoneNumberAssignedAddOnWithContext(ctx context.Context, ResourceSid string, params *ListIncomingPhoneNumberAssignedAddOnParams) (chan ApiV2010IncomingPhoneNumberAssignedAddOn, chan error) { if params == nil { params = &ListIncomingPhoneNumberAssignedAddOnParams{} } @@ -244,19 +269,19 @@ func (c *ApiService) StreamIncomingPhoneNumberAssignedAddOn(ResourceSid string, recordChannel := make(chan ApiV2010IncomingPhoneNumberAssignedAddOn, 1) errorChannel := make(chan error, 1) - response, err := c.PageIncomingPhoneNumberAssignedAddOn(ResourceSid, params, "", "") + response, err := c.PageIncomingPhoneNumberAssignedAddOnWithContext(ctx, ResourceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamIncomingPhoneNumberAssignedAddOn(response, params, recordChannel, errorChannel) + go c.streamIncomingPhoneNumberAssignedAddOnWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamIncomingPhoneNumberAssignedAddOn(response *ListIncomingPhoneNumberAssignedAddOnResponse, params *ListIncomingPhoneNumberAssignedAddOnParams, recordChannel chan ApiV2010IncomingPhoneNumberAssignedAddOn, errorChannel chan error) { +func (c *ApiService) streamIncomingPhoneNumberAssignedAddOnWithContext(ctx context.Context, response *ListIncomingPhoneNumberAssignedAddOnResponse, params *ListIncomingPhoneNumberAssignedAddOnParams, recordChannel chan ApiV2010IncomingPhoneNumberAssignedAddOn, errorChannel chan error) { curRecord := 1 for response != nil { @@ -271,7 +296,7 @@ func (c *ApiService) streamIncomingPhoneNumberAssignedAddOn(response *ListIncomi } } - record, err := client.GetNext(c.baseURL, response, c.getNextListIncomingPhoneNumberAssignedAddOnResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListIncomingPhoneNumberAssignedAddOnResponseWithContext) if err != nil { errorChannel <- err break @@ -286,11 +311,11 @@ func (c *ApiService) streamIncomingPhoneNumberAssignedAddOn(response *ListIncomi close(errorChannel) } -func (c *ApiService) getNextListIncomingPhoneNumberAssignedAddOnResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListIncomingPhoneNumberAssignedAddOnResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_incoming_phone_numbers_assigned_add_ons_extensions.go b/rest/api/v2010/accounts_incoming_phone_numbers_assigned_add_ons_extensions.go index 2c5a3899c..816883533 100644 --- a/rest/api/v2010/accounts_incoming_phone_numbers_assigned_add_ons_extensions.go +++ b/rest/api/v2010/accounts_incoming_phone_numbers_assigned_add_ons_extensions.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -36,6 +37,9 @@ func (params *FetchIncomingPhoneNumberAssignedAddOnExtensionParams) SetPathAccou // Fetch an instance of an Extension for the Assigned Add-on. func (c *ApiService) FetchIncomingPhoneNumberAssignedAddOnExtension(ResourceSid string, AssignedAddOnSid string, Sid string, params *FetchIncomingPhoneNumberAssignedAddOnExtensionParams) (*ApiV2010IncomingPhoneNumberAssignedAddOnExtension, error) { + return c.FetchIncomingPhoneNumberAssignedAddOnExtensionWithContext(context.TODO(), ResourceSid, AssignedAddOnSid, Sid, params) +} +func (c *ApiService) FetchIncomingPhoneNumberAssignedAddOnExtensionWithContext(ctx context.Context, ResourceSid string, AssignedAddOnSid string, Sid string, params *FetchIncomingPhoneNumberAssignedAddOnExtensionParams) (*ApiV2010IncomingPhoneNumberAssignedAddOnExtension, error) { path := "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{ResourceSid}/AssignedAddOns/{AssignedAddOnSid}/Extensions/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -51,7 +55,7 @@ func (c *ApiService) FetchIncomingPhoneNumberAssignedAddOnExtension(ResourceSid "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -91,6 +95,11 @@ func (params *ListIncomingPhoneNumberAssignedAddOnExtensionParams) SetLimit(Limi // Retrieve a single page of IncomingPhoneNumberAssignedAddOnExtension records from the API. Request is executed immediately. func (c *ApiService) PageIncomingPhoneNumberAssignedAddOnExtension(ResourceSid string, AssignedAddOnSid string, params *ListIncomingPhoneNumberAssignedAddOnExtensionParams, pageToken, pageNumber string) (*ListIncomingPhoneNumberAssignedAddOnExtensionResponse, error) { + return c.PageIncomingPhoneNumberAssignedAddOnExtensionWithContext(context.TODO(), ResourceSid, AssignedAddOnSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of IncomingPhoneNumberAssignedAddOnExtension records from the API. Request is executed immediately. +func (c *ApiService) PageIncomingPhoneNumberAssignedAddOnExtensionWithContext(ctx context.Context, ResourceSid string, AssignedAddOnSid string, params *ListIncomingPhoneNumberAssignedAddOnExtensionParams, pageToken, pageNumber string) (*ListIncomingPhoneNumberAssignedAddOnExtensionResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{ResourceSid}/AssignedAddOns/{AssignedAddOnSid}/Extensions.json" if params != nil && params.PathAccountSid != nil { @@ -117,7 +126,7 @@ func (c *ApiService) PageIncomingPhoneNumberAssignedAddOnExtension(ResourceSid s data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -134,7 +143,12 @@ func (c *ApiService) PageIncomingPhoneNumberAssignedAddOnExtension(ResourceSid s // Lists IncomingPhoneNumberAssignedAddOnExtension records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListIncomingPhoneNumberAssignedAddOnExtension(ResourceSid string, AssignedAddOnSid string, params *ListIncomingPhoneNumberAssignedAddOnExtensionParams) ([]ApiV2010IncomingPhoneNumberAssignedAddOnExtension, error) { - response, errors := c.StreamIncomingPhoneNumberAssignedAddOnExtension(ResourceSid, AssignedAddOnSid, params) + return c.ListIncomingPhoneNumberAssignedAddOnExtensionWithContext(context.TODO(), ResourceSid, AssignedAddOnSid, params) +} + +// Lists IncomingPhoneNumberAssignedAddOnExtension records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListIncomingPhoneNumberAssignedAddOnExtensionWithContext(ctx context.Context, ResourceSid string, AssignedAddOnSid string, params *ListIncomingPhoneNumberAssignedAddOnExtensionParams) ([]ApiV2010IncomingPhoneNumberAssignedAddOnExtension, error) { + response, errors := c.StreamIncomingPhoneNumberAssignedAddOnExtensionWithContext(ctx, ResourceSid, AssignedAddOnSid, params) records := make([]ApiV2010IncomingPhoneNumberAssignedAddOnExtension, 0) for record := range response { @@ -150,6 +164,11 @@ func (c *ApiService) ListIncomingPhoneNumberAssignedAddOnExtension(ResourceSid s // Streams IncomingPhoneNumberAssignedAddOnExtension records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamIncomingPhoneNumberAssignedAddOnExtension(ResourceSid string, AssignedAddOnSid string, params *ListIncomingPhoneNumberAssignedAddOnExtensionParams) (chan ApiV2010IncomingPhoneNumberAssignedAddOnExtension, chan error) { + return c.StreamIncomingPhoneNumberAssignedAddOnExtensionWithContext(context.TODO(), ResourceSid, AssignedAddOnSid, params) +} + +// Streams IncomingPhoneNumberAssignedAddOnExtension records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamIncomingPhoneNumberAssignedAddOnExtensionWithContext(ctx context.Context, ResourceSid string, AssignedAddOnSid string, params *ListIncomingPhoneNumberAssignedAddOnExtensionParams) (chan ApiV2010IncomingPhoneNumberAssignedAddOnExtension, chan error) { if params == nil { params = &ListIncomingPhoneNumberAssignedAddOnExtensionParams{} } @@ -158,19 +177,19 @@ func (c *ApiService) StreamIncomingPhoneNumberAssignedAddOnExtension(ResourceSid recordChannel := make(chan ApiV2010IncomingPhoneNumberAssignedAddOnExtension, 1) errorChannel := make(chan error, 1) - response, err := c.PageIncomingPhoneNumberAssignedAddOnExtension(ResourceSid, AssignedAddOnSid, params, "", "") + response, err := c.PageIncomingPhoneNumberAssignedAddOnExtensionWithContext(ctx, ResourceSid, AssignedAddOnSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamIncomingPhoneNumberAssignedAddOnExtension(response, params, recordChannel, errorChannel) + go c.streamIncomingPhoneNumberAssignedAddOnExtensionWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamIncomingPhoneNumberAssignedAddOnExtension(response *ListIncomingPhoneNumberAssignedAddOnExtensionResponse, params *ListIncomingPhoneNumberAssignedAddOnExtensionParams, recordChannel chan ApiV2010IncomingPhoneNumberAssignedAddOnExtension, errorChannel chan error) { +func (c *ApiService) streamIncomingPhoneNumberAssignedAddOnExtensionWithContext(ctx context.Context, response *ListIncomingPhoneNumberAssignedAddOnExtensionResponse, params *ListIncomingPhoneNumberAssignedAddOnExtensionParams, recordChannel chan ApiV2010IncomingPhoneNumberAssignedAddOnExtension, errorChannel chan error) { curRecord := 1 for response != nil { @@ -185,7 +204,7 @@ func (c *ApiService) streamIncomingPhoneNumberAssignedAddOnExtension(response *L } } - record, err := client.GetNext(c.baseURL, response, c.getNextListIncomingPhoneNumberAssignedAddOnExtensionResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListIncomingPhoneNumberAssignedAddOnExtensionResponseWithContext) if err != nil { errorChannel <- err break @@ -200,11 +219,11 @@ func (c *ApiService) streamIncomingPhoneNumberAssignedAddOnExtension(response *L close(errorChannel) } -func (c *ApiService) getNextListIncomingPhoneNumberAssignedAddOnExtensionResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListIncomingPhoneNumberAssignedAddOnExtensionResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_incoming_phone_numbers_local.go b/rest/api/v2010/accounts_incoming_phone_numbers_local.go index 5229907cd..7a2b65c2b 100644 --- a/rest/api/v2010/accounts_incoming_phone_numbers_local.go +++ b/rest/api/v2010/accounts_incoming_phone_numbers_local.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -172,8 +173,10 @@ func (params *CreateIncomingPhoneNumberLocalParams) SetBundleSid(BundleSid strin return params } -// func (c *ApiService) CreateIncomingPhoneNumberLocal(params *CreateIncomingPhoneNumberLocalParams) (*ApiV2010IncomingPhoneNumberLocal, error) { + return c.CreateIncomingPhoneNumberLocalWithContext(context.TODO(), params) +} +func (c *ApiService) CreateIncomingPhoneNumberLocalWithContext(ctx context.Context, params *CreateIncomingPhoneNumberLocalParams) (*ApiV2010IncomingPhoneNumberLocal, error) { path := "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/Local.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -256,7 +259,7 @@ func (c *ApiService) CreateIncomingPhoneNumberLocal(params *CreateIncomingPhoneN data.Set("BundleSid", *params.BundleSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -320,6 +323,11 @@ func (params *ListIncomingPhoneNumberLocalParams) SetLimit(Limit int) *ListIncom // Retrieve a single page of IncomingPhoneNumberLocal records from the API. Request is executed immediately. func (c *ApiService) PageIncomingPhoneNumberLocal(params *ListIncomingPhoneNumberLocalParams, pageToken, pageNumber string) (*ListIncomingPhoneNumberLocalResponse, error) { + return c.PageIncomingPhoneNumberLocalWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of IncomingPhoneNumberLocal records from the API. Request is executed immediately. +func (c *ApiService) PageIncomingPhoneNumberLocalWithContext(ctx context.Context, params *ListIncomingPhoneNumberLocalParams, pageToken, pageNumber string) (*ListIncomingPhoneNumberLocalResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/Local.json" if params != nil && params.PathAccountSid != nil { @@ -356,7 +364,7 @@ func (c *ApiService) PageIncomingPhoneNumberLocal(params *ListIncomingPhoneNumbe data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -373,7 +381,12 @@ func (c *ApiService) PageIncomingPhoneNumberLocal(params *ListIncomingPhoneNumbe // Lists IncomingPhoneNumberLocal records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListIncomingPhoneNumberLocal(params *ListIncomingPhoneNumberLocalParams) ([]ApiV2010IncomingPhoneNumberLocal, error) { - response, errors := c.StreamIncomingPhoneNumberLocal(params) + return c.ListIncomingPhoneNumberLocalWithContext(context.TODO(), params) +} + +// Lists IncomingPhoneNumberLocal records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListIncomingPhoneNumberLocalWithContext(ctx context.Context, params *ListIncomingPhoneNumberLocalParams) ([]ApiV2010IncomingPhoneNumberLocal, error) { + response, errors := c.StreamIncomingPhoneNumberLocalWithContext(ctx, params) records := make([]ApiV2010IncomingPhoneNumberLocal, 0) for record := range response { @@ -389,6 +402,11 @@ func (c *ApiService) ListIncomingPhoneNumberLocal(params *ListIncomingPhoneNumbe // Streams IncomingPhoneNumberLocal records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamIncomingPhoneNumberLocal(params *ListIncomingPhoneNumberLocalParams) (chan ApiV2010IncomingPhoneNumberLocal, chan error) { + return c.StreamIncomingPhoneNumberLocalWithContext(context.TODO(), params) +} + +// Streams IncomingPhoneNumberLocal records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamIncomingPhoneNumberLocalWithContext(ctx context.Context, params *ListIncomingPhoneNumberLocalParams) (chan ApiV2010IncomingPhoneNumberLocal, chan error) { if params == nil { params = &ListIncomingPhoneNumberLocalParams{} } @@ -397,19 +415,19 @@ func (c *ApiService) StreamIncomingPhoneNumberLocal(params *ListIncomingPhoneNum recordChannel := make(chan ApiV2010IncomingPhoneNumberLocal, 1) errorChannel := make(chan error, 1) - response, err := c.PageIncomingPhoneNumberLocal(params, "", "") + response, err := c.PageIncomingPhoneNumberLocalWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamIncomingPhoneNumberLocal(response, params, recordChannel, errorChannel) + go c.streamIncomingPhoneNumberLocalWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamIncomingPhoneNumberLocal(response *ListIncomingPhoneNumberLocalResponse, params *ListIncomingPhoneNumberLocalParams, recordChannel chan ApiV2010IncomingPhoneNumberLocal, errorChannel chan error) { +func (c *ApiService) streamIncomingPhoneNumberLocalWithContext(ctx context.Context, response *ListIncomingPhoneNumberLocalResponse, params *ListIncomingPhoneNumberLocalParams, recordChannel chan ApiV2010IncomingPhoneNumberLocal, errorChannel chan error) { curRecord := 1 for response != nil { @@ -424,7 +442,7 @@ func (c *ApiService) streamIncomingPhoneNumberLocal(response *ListIncomingPhoneN } } - record, err := client.GetNext(c.baseURL, response, c.getNextListIncomingPhoneNumberLocalResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListIncomingPhoneNumberLocalResponseWithContext) if err != nil { errorChannel <- err break @@ -439,11 +457,11 @@ func (c *ApiService) streamIncomingPhoneNumberLocal(response *ListIncomingPhoneN close(errorChannel) } -func (c *ApiService) getNextListIncomingPhoneNumberLocalResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListIncomingPhoneNumberLocalResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_incoming_phone_numbers_mobile.go b/rest/api/v2010/accounts_incoming_phone_numbers_mobile.go index d2da86c7c..611545728 100644 --- a/rest/api/v2010/accounts_incoming_phone_numbers_mobile.go +++ b/rest/api/v2010/accounts_incoming_phone_numbers_mobile.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -172,8 +173,10 @@ func (params *CreateIncomingPhoneNumberMobileParams) SetBundleSid(BundleSid stri return params } -// func (c *ApiService) CreateIncomingPhoneNumberMobile(params *CreateIncomingPhoneNumberMobileParams) (*ApiV2010IncomingPhoneNumberMobile, error) { + return c.CreateIncomingPhoneNumberMobileWithContext(context.TODO(), params) +} +func (c *ApiService) CreateIncomingPhoneNumberMobileWithContext(ctx context.Context, params *CreateIncomingPhoneNumberMobileParams) (*ApiV2010IncomingPhoneNumberMobile, error) { path := "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/Mobile.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -256,7 +259,7 @@ func (c *ApiService) CreateIncomingPhoneNumberMobile(params *CreateIncomingPhone data.Set("BundleSid", *params.BundleSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -320,6 +323,11 @@ func (params *ListIncomingPhoneNumberMobileParams) SetLimit(Limit int) *ListInco // Retrieve a single page of IncomingPhoneNumberMobile records from the API. Request is executed immediately. func (c *ApiService) PageIncomingPhoneNumberMobile(params *ListIncomingPhoneNumberMobileParams, pageToken, pageNumber string) (*ListIncomingPhoneNumberMobileResponse, error) { + return c.PageIncomingPhoneNumberMobileWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of IncomingPhoneNumberMobile records from the API. Request is executed immediately. +func (c *ApiService) PageIncomingPhoneNumberMobileWithContext(ctx context.Context, params *ListIncomingPhoneNumberMobileParams, pageToken, pageNumber string) (*ListIncomingPhoneNumberMobileResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/Mobile.json" if params != nil && params.PathAccountSid != nil { @@ -356,7 +364,7 @@ func (c *ApiService) PageIncomingPhoneNumberMobile(params *ListIncomingPhoneNumb data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -373,7 +381,12 @@ func (c *ApiService) PageIncomingPhoneNumberMobile(params *ListIncomingPhoneNumb // Lists IncomingPhoneNumberMobile records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListIncomingPhoneNumberMobile(params *ListIncomingPhoneNumberMobileParams) ([]ApiV2010IncomingPhoneNumberMobile, error) { - response, errors := c.StreamIncomingPhoneNumberMobile(params) + return c.ListIncomingPhoneNumberMobileWithContext(context.TODO(), params) +} + +// Lists IncomingPhoneNumberMobile records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListIncomingPhoneNumberMobileWithContext(ctx context.Context, params *ListIncomingPhoneNumberMobileParams) ([]ApiV2010IncomingPhoneNumberMobile, error) { + response, errors := c.StreamIncomingPhoneNumberMobileWithContext(ctx, params) records := make([]ApiV2010IncomingPhoneNumberMobile, 0) for record := range response { @@ -389,6 +402,11 @@ func (c *ApiService) ListIncomingPhoneNumberMobile(params *ListIncomingPhoneNumb // Streams IncomingPhoneNumberMobile records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamIncomingPhoneNumberMobile(params *ListIncomingPhoneNumberMobileParams) (chan ApiV2010IncomingPhoneNumberMobile, chan error) { + return c.StreamIncomingPhoneNumberMobileWithContext(context.TODO(), params) +} + +// Streams IncomingPhoneNumberMobile records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamIncomingPhoneNumberMobileWithContext(ctx context.Context, params *ListIncomingPhoneNumberMobileParams) (chan ApiV2010IncomingPhoneNumberMobile, chan error) { if params == nil { params = &ListIncomingPhoneNumberMobileParams{} } @@ -397,19 +415,19 @@ func (c *ApiService) StreamIncomingPhoneNumberMobile(params *ListIncomingPhoneNu recordChannel := make(chan ApiV2010IncomingPhoneNumberMobile, 1) errorChannel := make(chan error, 1) - response, err := c.PageIncomingPhoneNumberMobile(params, "", "") + response, err := c.PageIncomingPhoneNumberMobileWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamIncomingPhoneNumberMobile(response, params, recordChannel, errorChannel) + go c.streamIncomingPhoneNumberMobileWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamIncomingPhoneNumberMobile(response *ListIncomingPhoneNumberMobileResponse, params *ListIncomingPhoneNumberMobileParams, recordChannel chan ApiV2010IncomingPhoneNumberMobile, errorChannel chan error) { +func (c *ApiService) streamIncomingPhoneNumberMobileWithContext(ctx context.Context, response *ListIncomingPhoneNumberMobileResponse, params *ListIncomingPhoneNumberMobileParams, recordChannel chan ApiV2010IncomingPhoneNumberMobile, errorChannel chan error) { curRecord := 1 for response != nil { @@ -424,7 +442,7 @@ func (c *ApiService) streamIncomingPhoneNumberMobile(response *ListIncomingPhone } } - record, err := client.GetNext(c.baseURL, response, c.getNextListIncomingPhoneNumberMobileResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListIncomingPhoneNumberMobileResponseWithContext) if err != nil { errorChannel <- err break @@ -439,11 +457,11 @@ func (c *ApiService) streamIncomingPhoneNumberMobile(response *ListIncomingPhone close(errorChannel) } -func (c *ApiService) getNextListIncomingPhoneNumberMobileResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListIncomingPhoneNumberMobileResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_incoming_phone_numbers_toll_free.go b/rest/api/v2010/accounts_incoming_phone_numbers_toll_free.go index a44ab524e..dcd29a5f9 100644 --- a/rest/api/v2010/accounts_incoming_phone_numbers_toll_free.go +++ b/rest/api/v2010/accounts_incoming_phone_numbers_toll_free.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -172,8 +173,10 @@ func (params *CreateIncomingPhoneNumberTollFreeParams) SetBundleSid(BundleSid st return params } -// func (c *ApiService) CreateIncomingPhoneNumberTollFree(params *CreateIncomingPhoneNumberTollFreeParams) (*ApiV2010IncomingPhoneNumberTollFree, error) { + return c.CreateIncomingPhoneNumberTollFreeWithContext(context.TODO(), params) +} +func (c *ApiService) CreateIncomingPhoneNumberTollFreeWithContext(ctx context.Context, params *CreateIncomingPhoneNumberTollFreeParams) (*ApiV2010IncomingPhoneNumberTollFree, error) { path := "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/TollFree.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -256,7 +259,7 @@ func (c *ApiService) CreateIncomingPhoneNumberTollFree(params *CreateIncomingPho data.Set("BundleSid", *params.BundleSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -320,6 +323,11 @@ func (params *ListIncomingPhoneNumberTollFreeParams) SetLimit(Limit int) *ListIn // Retrieve a single page of IncomingPhoneNumberTollFree records from the API. Request is executed immediately. func (c *ApiService) PageIncomingPhoneNumberTollFree(params *ListIncomingPhoneNumberTollFreeParams, pageToken, pageNumber string) (*ListIncomingPhoneNumberTollFreeResponse, error) { + return c.PageIncomingPhoneNumberTollFreeWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of IncomingPhoneNumberTollFree records from the API. Request is executed immediately. +func (c *ApiService) PageIncomingPhoneNumberTollFreeWithContext(ctx context.Context, params *ListIncomingPhoneNumberTollFreeParams, pageToken, pageNumber string) (*ListIncomingPhoneNumberTollFreeResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/TollFree.json" if params != nil && params.PathAccountSid != nil { @@ -356,7 +364,7 @@ func (c *ApiService) PageIncomingPhoneNumberTollFree(params *ListIncomingPhoneNu data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -373,7 +381,12 @@ func (c *ApiService) PageIncomingPhoneNumberTollFree(params *ListIncomingPhoneNu // Lists IncomingPhoneNumberTollFree records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListIncomingPhoneNumberTollFree(params *ListIncomingPhoneNumberTollFreeParams) ([]ApiV2010IncomingPhoneNumberTollFree, error) { - response, errors := c.StreamIncomingPhoneNumberTollFree(params) + return c.ListIncomingPhoneNumberTollFreeWithContext(context.TODO(), params) +} + +// Lists IncomingPhoneNumberTollFree records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListIncomingPhoneNumberTollFreeWithContext(ctx context.Context, params *ListIncomingPhoneNumberTollFreeParams) ([]ApiV2010IncomingPhoneNumberTollFree, error) { + response, errors := c.StreamIncomingPhoneNumberTollFreeWithContext(ctx, params) records := make([]ApiV2010IncomingPhoneNumberTollFree, 0) for record := range response { @@ -389,6 +402,11 @@ func (c *ApiService) ListIncomingPhoneNumberTollFree(params *ListIncomingPhoneNu // Streams IncomingPhoneNumberTollFree records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamIncomingPhoneNumberTollFree(params *ListIncomingPhoneNumberTollFreeParams) (chan ApiV2010IncomingPhoneNumberTollFree, chan error) { + return c.StreamIncomingPhoneNumberTollFreeWithContext(context.TODO(), params) +} + +// Streams IncomingPhoneNumberTollFree records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamIncomingPhoneNumberTollFreeWithContext(ctx context.Context, params *ListIncomingPhoneNumberTollFreeParams) (chan ApiV2010IncomingPhoneNumberTollFree, chan error) { if params == nil { params = &ListIncomingPhoneNumberTollFreeParams{} } @@ -397,19 +415,19 @@ func (c *ApiService) StreamIncomingPhoneNumberTollFree(params *ListIncomingPhone recordChannel := make(chan ApiV2010IncomingPhoneNumberTollFree, 1) errorChannel := make(chan error, 1) - response, err := c.PageIncomingPhoneNumberTollFree(params, "", "") + response, err := c.PageIncomingPhoneNumberTollFreeWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamIncomingPhoneNumberTollFree(response, params, recordChannel, errorChannel) + go c.streamIncomingPhoneNumberTollFreeWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamIncomingPhoneNumberTollFree(response *ListIncomingPhoneNumberTollFreeResponse, params *ListIncomingPhoneNumberTollFreeParams, recordChannel chan ApiV2010IncomingPhoneNumberTollFree, errorChannel chan error) { +func (c *ApiService) streamIncomingPhoneNumberTollFreeWithContext(ctx context.Context, response *ListIncomingPhoneNumberTollFreeResponse, params *ListIncomingPhoneNumberTollFreeParams, recordChannel chan ApiV2010IncomingPhoneNumberTollFree, errorChannel chan error) { curRecord := 1 for response != nil { @@ -424,7 +442,7 @@ func (c *ApiService) streamIncomingPhoneNumberTollFree(response *ListIncomingPho } } - record, err := client.GetNext(c.baseURL, response, c.getNextListIncomingPhoneNumberTollFreeResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListIncomingPhoneNumberTollFreeResponseWithContext) if err != nil { errorChannel <- err break @@ -439,11 +457,11 @@ func (c *ApiService) streamIncomingPhoneNumberTollFree(response *ListIncomingPho close(errorChannel) } -func (c *ApiService) getNextListIncomingPhoneNumberTollFreeResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListIncomingPhoneNumberTollFreeResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_keys.go b/rest/api/v2010/accounts_keys.go index 6d18e73ee..e9d39cdf0 100644 --- a/rest/api/v2010/accounts_keys.go +++ b/rest/api/v2010/accounts_keys.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -40,8 +41,10 @@ func (params *CreateNewKeyParams) SetFriendlyName(FriendlyName string) *CreateNe return params } -// func (c *ApiService) CreateNewKey(params *CreateNewKeyParams) (*ApiV2010NewKey, error) { + return c.CreateNewKeyWithContext(context.TODO(), params) +} +func (c *ApiService) CreateNewKeyWithContext(ctx context.Context, params *CreateNewKeyParams) (*ApiV2010NewKey, error) { path := "/2010-04-01/Accounts/{AccountSid}/Keys.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -58,7 +61,7 @@ func (c *ApiService) CreateNewKey(params *CreateNewKeyParams) (*ApiV2010NewKey, data.Set("FriendlyName", *params.FriendlyName) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -84,8 +87,10 @@ func (params *DeleteKeyParams) SetPathAccountSid(PathAccountSid string) *DeleteK return params } -// func (c *ApiService) DeleteKey(Sid string, params *DeleteKeyParams) error { + return c.DeleteKeyWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) DeleteKeyWithContext(ctx context.Context, Sid string, params *DeleteKeyParams) error { path := "/2010-04-01/Accounts/{AccountSid}/Keys/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -99,7 +104,7 @@ func (c *ApiService) DeleteKey(Sid string, params *DeleteKeyParams) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -120,8 +125,10 @@ func (params *FetchKeyParams) SetPathAccountSid(PathAccountSid string) *FetchKey return params } -// func (c *ApiService) FetchKey(Sid string, params *FetchKeyParams) (*ApiV2010Key, error) { + return c.FetchKeyWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) FetchKeyWithContext(ctx context.Context, Sid string, params *FetchKeyParams) (*ApiV2010Key, error) { path := "/2010-04-01/Accounts/{AccountSid}/Keys/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -135,7 +142,7 @@ func (c *ApiService) FetchKey(Sid string, params *FetchKeyParams) (*ApiV2010Key, "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -175,6 +182,11 @@ func (params *ListKeyParams) SetLimit(Limit int) *ListKeyParams { // Retrieve a single page of Key records from the API. Request is executed immediately. func (c *ApiService) PageKey(params *ListKeyParams, pageToken, pageNumber string) (*ListKeyResponse, error) { + return c.PageKeyWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Key records from the API. Request is executed immediately. +func (c *ApiService) PageKeyWithContext(ctx context.Context, params *ListKeyParams, pageToken, pageNumber string) (*ListKeyResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/Keys.json" if params != nil && params.PathAccountSid != nil { @@ -199,7 +211,7 @@ func (c *ApiService) PageKey(params *ListKeyParams, pageToken, pageNumber string data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -216,7 +228,12 @@ func (c *ApiService) PageKey(params *ListKeyParams, pageToken, pageNumber string // Lists Key records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListKey(params *ListKeyParams) ([]ApiV2010Key, error) { - response, errors := c.StreamKey(params) + return c.ListKeyWithContext(context.TODO(), params) +} + +// Lists Key records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListKeyWithContext(ctx context.Context, params *ListKeyParams) ([]ApiV2010Key, error) { + response, errors := c.StreamKeyWithContext(ctx, params) records := make([]ApiV2010Key, 0) for record := range response { @@ -232,6 +249,11 @@ func (c *ApiService) ListKey(params *ListKeyParams) ([]ApiV2010Key, error) { // Streams Key records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamKey(params *ListKeyParams) (chan ApiV2010Key, chan error) { + return c.StreamKeyWithContext(context.TODO(), params) +} + +// Streams Key records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamKeyWithContext(ctx context.Context, params *ListKeyParams) (chan ApiV2010Key, chan error) { if params == nil { params = &ListKeyParams{} } @@ -240,19 +262,19 @@ func (c *ApiService) StreamKey(params *ListKeyParams) (chan ApiV2010Key, chan er recordChannel := make(chan ApiV2010Key, 1) errorChannel := make(chan error, 1) - response, err := c.PageKey(params, "", "") + response, err := c.PageKeyWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamKey(response, params, recordChannel, errorChannel) + go c.streamKeyWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamKey(response *ListKeyResponse, params *ListKeyParams, recordChannel chan ApiV2010Key, errorChannel chan error) { +func (c *ApiService) streamKeyWithContext(ctx context.Context, response *ListKeyResponse, params *ListKeyParams, recordChannel chan ApiV2010Key, errorChannel chan error) { curRecord := 1 for response != nil { @@ -267,7 +289,7 @@ func (c *ApiService) streamKey(response *ListKeyResponse, params *ListKeyParams, } } - record, err := client.GetNext(c.baseURL, response, c.getNextListKeyResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListKeyResponseWithContext) if err != nil { errorChannel <- err break @@ -282,11 +304,11 @@ func (c *ApiService) streamKey(response *ListKeyResponse, params *ListKeyParams, close(errorChannel) } -func (c *ApiService) getNextListKeyResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListKeyResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -317,8 +339,10 @@ func (params *UpdateKeyParams) SetFriendlyName(FriendlyName string) *UpdateKeyPa return params } -// func (c *ApiService) UpdateKey(Sid string, params *UpdateKeyParams) (*ApiV2010Key, error) { + return c.UpdateKeyWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateKeyWithContext(ctx context.Context, Sid string, params *UpdateKeyParams) (*ApiV2010Key, error) { path := "/2010-04-01/Accounts/{AccountSid}/Keys/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -336,7 +360,7 @@ func (c *ApiService) UpdateKey(Sid string, params *UpdateKeyParams) (*ApiV2010Ke data.Set("FriendlyName", *params.FriendlyName) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_messages.go b/rest/api/v2010/accounts_messages.go index b6f8474c5..580fd084e 100644 --- a/rest/api/v2010/accounts_messages.go +++ b/rest/api/v2010/accounts_messages.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -181,6 +182,9 @@ func (params *CreateMessageParams) SetContentSid(ContentSid string) *CreateMessa // Send a message func (c *ApiService) CreateMessage(params *CreateMessageParams) (*ApiV2010Message, error) { + return c.CreateMessageWithContext(context.TODO(), params) +} +func (c *ApiService) CreateMessageWithContext(ctx context.Context, params *CreateMessageParams) (*ApiV2010Message, error) { path := "/2010-04-01/Accounts/{AccountSid}/Messages.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -270,7 +274,7 @@ func (c *ApiService) CreateMessage(params *CreateMessageParams) (*ApiV2010Messag data.Set("ContentSid", *params.ContentSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -298,6 +302,9 @@ func (params *DeleteMessageParams) SetPathAccountSid(PathAccountSid string) *Del // Deletes a Message resource from your account func (c *ApiService) DeleteMessage(Sid string, params *DeleteMessageParams) error { + return c.DeleteMessageWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) DeleteMessageWithContext(ctx context.Context, Sid string, params *DeleteMessageParams) error { path := "/2010-04-01/Accounts/{AccountSid}/Messages/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -311,7 +318,7 @@ func (c *ApiService) DeleteMessage(Sid string, params *DeleteMessageParams) erro "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -334,6 +341,9 @@ func (params *FetchMessageParams) SetPathAccountSid(PathAccountSid string) *Fetc // Fetch a specific Message func (c *ApiService) FetchMessage(Sid string, params *FetchMessageParams) (*ApiV2010Message, error) { + return c.FetchMessageWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) FetchMessageWithContext(ctx context.Context, Sid string, params *FetchMessageParams) (*ApiV2010Message, error) { path := "/2010-04-01/Accounts/{AccountSid}/Messages/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -347,7 +357,7 @@ func (c *ApiService) FetchMessage(Sid string, params *FetchMessageParams) (*ApiV "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -417,6 +427,11 @@ func (params *ListMessageParams) SetLimit(Limit int) *ListMessageParams { // Retrieve a single page of Message records from the API. Request is executed immediately. func (c *ApiService) PageMessage(params *ListMessageParams, pageToken, pageNumber string) (*ListMessageResponse, error) { + return c.PageMessageWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Message records from the API. Request is executed immediately. +func (c *ApiService) PageMessageWithContext(ctx context.Context, params *ListMessageParams, pageToken, pageNumber string) (*ListMessageResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/Messages.json" if params != nil && params.PathAccountSid != nil { @@ -456,7 +471,7 @@ func (c *ApiService) PageMessage(params *ListMessageParams, pageToken, pageNumbe data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -473,7 +488,12 @@ func (c *ApiService) PageMessage(params *ListMessageParams, pageToken, pageNumbe // Lists Message records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListMessage(params *ListMessageParams) ([]ApiV2010Message, error) { - response, errors := c.StreamMessage(params) + return c.ListMessageWithContext(context.TODO(), params) +} + +// Lists Message records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListMessageWithContext(ctx context.Context, params *ListMessageParams) ([]ApiV2010Message, error) { + response, errors := c.StreamMessageWithContext(ctx, params) records := make([]ApiV2010Message, 0) for record := range response { @@ -489,6 +509,11 @@ func (c *ApiService) ListMessage(params *ListMessageParams) ([]ApiV2010Message, // Streams Message records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamMessage(params *ListMessageParams) (chan ApiV2010Message, chan error) { + return c.StreamMessageWithContext(context.TODO(), params) +} + +// Streams Message records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamMessageWithContext(ctx context.Context, params *ListMessageParams) (chan ApiV2010Message, chan error) { if params == nil { params = &ListMessageParams{} } @@ -497,19 +522,19 @@ func (c *ApiService) StreamMessage(params *ListMessageParams) (chan ApiV2010Mess recordChannel := make(chan ApiV2010Message, 1) errorChannel := make(chan error, 1) - response, err := c.PageMessage(params, "", "") + response, err := c.PageMessageWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamMessage(response, params, recordChannel, errorChannel) + go c.streamMessageWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamMessage(response *ListMessageResponse, params *ListMessageParams, recordChannel chan ApiV2010Message, errorChannel chan error) { +func (c *ApiService) streamMessageWithContext(ctx context.Context, response *ListMessageResponse, params *ListMessageParams, recordChannel chan ApiV2010Message, errorChannel chan error) { curRecord := 1 for response != nil { @@ -524,7 +549,7 @@ func (c *ApiService) streamMessage(response *ListMessageResponse, params *ListMe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListMessageResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListMessageResponseWithContext) if err != nil { errorChannel <- err break @@ -539,11 +564,11 @@ func (c *ApiService) streamMessage(response *ListMessageResponse, params *ListMe close(errorChannel) } -func (c *ApiService) getNextListMessageResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListMessageResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -582,6 +607,9 @@ func (params *UpdateMessageParams) SetStatus(Status string) *UpdateMessageParams // Update a Message resource (used to redact Message `body` text and to cancel not-yet-sent messages) func (c *ApiService) UpdateMessage(Sid string, params *UpdateMessageParams) (*ApiV2010Message, error) { + return c.UpdateMessageWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateMessageWithContext(ctx context.Context, Sid string, params *UpdateMessageParams) (*ApiV2010Message, error) { path := "/2010-04-01/Accounts/{AccountSid}/Messages/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -602,7 +630,7 @@ func (c *ApiService) UpdateMessage(Sid string, params *UpdateMessageParams) (*Ap data.Set("Status", fmt.Sprint(*params.Status)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_messages_feedback.go b/rest/api/v2010/accounts_messages_feedback.go index 1f10d0bc1..edf9d06f2 100644 --- a/rest/api/v2010/accounts_messages_feedback.go +++ b/rest/api/v2010/accounts_messages_feedback.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -40,6 +41,9 @@ func (params *CreateMessageFeedbackParams) SetOutcome(Outcome string) *CreateMes // Create Message Feedback to confirm a tracked user action was performed by the recipient of the associated Message func (c *ApiService) CreateMessageFeedback(MessageSid string, params *CreateMessageFeedbackParams) (*ApiV2010MessageFeedback, error) { + return c.CreateMessageFeedbackWithContext(context.TODO(), MessageSid, params) +} +func (c *ApiService) CreateMessageFeedbackWithContext(ctx context.Context, MessageSid string, params *CreateMessageFeedbackParams) (*ApiV2010MessageFeedback, error) { path := "/2010-04-01/Accounts/{AccountSid}/Messages/{MessageSid}/Feedback.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -57,7 +61,7 @@ func (c *ApiService) CreateMessageFeedback(MessageSid string, params *CreateMess data.Set("Outcome", fmt.Sprint(*params.Outcome)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_messages_media.go b/rest/api/v2010/accounts_messages_media.go index c943d2944..a5ed93ee9 100644 --- a/rest/api/v2010/accounts_messages_media.go +++ b/rest/api/v2010/accounts_messages_media.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -37,6 +38,9 @@ func (params *DeleteMediaParams) SetPathAccountSid(PathAccountSid string) *Delet // Delete the Media resource. func (c *ApiService) DeleteMedia(MessageSid string, Sid string, params *DeleteMediaParams) error { + return c.DeleteMediaWithContext(context.TODO(), MessageSid, Sid, params) +} +func (c *ApiService) DeleteMediaWithContext(ctx context.Context, MessageSid string, Sid string, params *DeleteMediaParams) error { path := "/2010-04-01/Accounts/{AccountSid}/Messages/{MessageSid}/Media/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -51,7 +55,7 @@ func (c *ApiService) DeleteMedia(MessageSid string, Sid string, params *DeleteMe "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -74,6 +78,9 @@ func (params *FetchMediaParams) SetPathAccountSid(PathAccountSid string) *FetchM // Fetch a single Media resource associated with a specific Message resource func (c *ApiService) FetchMedia(MessageSid string, Sid string, params *FetchMediaParams) (*ApiV2010Media, error) { + return c.FetchMediaWithContext(context.TODO(), MessageSid, Sid, params) +} +func (c *ApiService) FetchMediaWithContext(ctx context.Context, MessageSid string, Sid string, params *FetchMediaParams) (*ApiV2010Media, error) { path := "/2010-04-01/Accounts/{AccountSid}/Messages/{MessageSid}/Media/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -88,7 +95,7 @@ func (c *ApiService) FetchMedia(MessageSid string, Sid string, params *FetchMedi "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -146,6 +153,11 @@ func (params *ListMediaParams) SetLimit(Limit int) *ListMediaParams { // Retrieve a single page of Media records from the API. Request is executed immediately. func (c *ApiService) PageMedia(MessageSid string, params *ListMediaParams, pageToken, pageNumber string) (*ListMediaResponse, error) { + return c.PageMediaWithContext(context.TODO(), MessageSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Media records from the API. Request is executed immediately. +func (c *ApiService) PageMediaWithContext(ctx context.Context, MessageSid string, params *ListMediaParams, pageToken, pageNumber string) (*ListMediaResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/Messages/{MessageSid}/Media.json" if params != nil && params.PathAccountSid != nil { @@ -180,7 +192,7 @@ func (c *ApiService) PageMedia(MessageSid string, params *ListMediaParams, pageT data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -197,7 +209,12 @@ func (c *ApiService) PageMedia(MessageSid string, params *ListMediaParams, pageT // Lists Media records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListMedia(MessageSid string, params *ListMediaParams) ([]ApiV2010Media, error) { - response, errors := c.StreamMedia(MessageSid, params) + return c.ListMediaWithContext(context.TODO(), MessageSid, params) +} + +// Lists Media records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListMediaWithContext(ctx context.Context, MessageSid string, params *ListMediaParams) ([]ApiV2010Media, error) { + response, errors := c.StreamMediaWithContext(ctx, MessageSid, params) records := make([]ApiV2010Media, 0) for record := range response { @@ -213,6 +230,11 @@ func (c *ApiService) ListMedia(MessageSid string, params *ListMediaParams) ([]Ap // Streams Media records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamMedia(MessageSid string, params *ListMediaParams) (chan ApiV2010Media, chan error) { + return c.StreamMediaWithContext(context.TODO(), MessageSid, params) +} + +// Streams Media records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamMediaWithContext(ctx context.Context, MessageSid string, params *ListMediaParams) (chan ApiV2010Media, chan error) { if params == nil { params = &ListMediaParams{} } @@ -221,19 +243,19 @@ func (c *ApiService) StreamMedia(MessageSid string, params *ListMediaParams) (ch recordChannel := make(chan ApiV2010Media, 1) errorChannel := make(chan error, 1) - response, err := c.PageMedia(MessageSid, params, "", "") + response, err := c.PageMediaWithContext(ctx, MessageSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamMedia(response, params, recordChannel, errorChannel) + go c.streamMediaWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamMedia(response *ListMediaResponse, params *ListMediaParams, recordChannel chan ApiV2010Media, errorChannel chan error) { +func (c *ApiService) streamMediaWithContext(ctx context.Context, response *ListMediaResponse, params *ListMediaParams, recordChannel chan ApiV2010Media, errorChannel chan error) { curRecord := 1 for response != nil { @@ -248,7 +270,7 @@ func (c *ApiService) streamMedia(response *ListMediaResponse, params *ListMediaP } } - record, err := client.GetNext(c.baseURL, response, c.getNextListMediaResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListMediaResponseWithContext) if err != nil { errorChannel <- err break @@ -263,11 +285,11 @@ func (c *ApiService) streamMedia(response *ListMediaResponse, params *ListMediaP close(errorChannel) } -func (c *ApiService) getNextListMediaResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListMediaResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_notifications.go b/rest/api/v2010/accounts_notifications.go index ccd566be3..74589cb8b 100644 --- a/rest/api/v2010/accounts_notifications.go +++ b/rest/api/v2010/accounts_notifications.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -36,6 +37,9 @@ func (params *FetchNotificationParams) SetPathAccountSid(PathAccountSid string) // Fetch a notification belonging to the account used to make the request func (c *ApiService) FetchNotification(Sid string, params *FetchNotificationParams) (*ApiV2010NotificationInstance, error) { + return c.FetchNotificationWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) FetchNotificationWithContext(ctx context.Context, Sid string, params *FetchNotificationParams) (*ApiV2010NotificationInstance, error) { path := "/2010-04-01/Accounts/{AccountSid}/Notifications/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -49,7 +53,7 @@ func (c *ApiService) FetchNotification(Sid string, params *FetchNotificationPara "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -113,6 +117,11 @@ func (params *ListNotificationParams) SetLimit(Limit int) *ListNotificationParam // Retrieve a single page of Notification records from the API. Request is executed immediately. func (c *ApiService) PageNotification(params *ListNotificationParams, pageToken, pageNumber string) (*ListNotificationResponse, error) { + return c.PageNotificationWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Notification records from the API. Request is executed immediately. +func (c *ApiService) PageNotificationWithContext(ctx context.Context, params *ListNotificationParams, pageToken, pageNumber string) (*ListNotificationResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/Notifications.json" if params != nil && params.PathAccountSid != nil { @@ -149,7 +158,7 @@ func (c *ApiService) PageNotification(params *ListNotificationParams, pageToken, data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -166,7 +175,12 @@ func (c *ApiService) PageNotification(params *ListNotificationParams, pageToken, // Lists Notification records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListNotification(params *ListNotificationParams) ([]ApiV2010Notification, error) { - response, errors := c.StreamNotification(params) + return c.ListNotificationWithContext(context.TODO(), params) +} + +// Lists Notification records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListNotificationWithContext(ctx context.Context, params *ListNotificationParams) ([]ApiV2010Notification, error) { + response, errors := c.StreamNotificationWithContext(ctx, params) records := make([]ApiV2010Notification, 0) for record := range response { @@ -182,6 +196,11 @@ func (c *ApiService) ListNotification(params *ListNotificationParams) ([]ApiV201 // Streams Notification records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamNotification(params *ListNotificationParams) (chan ApiV2010Notification, chan error) { + return c.StreamNotificationWithContext(context.TODO(), params) +} + +// Streams Notification records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamNotificationWithContext(ctx context.Context, params *ListNotificationParams) (chan ApiV2010Notification, chan error) { if params == nil { params = &ListNotificationParams{} } @@ -190,19 +209,19 @@ func (c *ApiService) StreamNotification(params *ListNotificationParams) (chan Ap recordChannel := make(chan ApiV2010Notification, 1) errorChannel := make(chan error, 1) - response, err := c.PageNotification(params, "", "") + response, err := c.PageNotificationWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamNotification(response, params, recordChannel, errorChannel) + go c.streamNotificationWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamNotification(response *ListNotificationResponse, params *ListNotificationParams, recordChannel chan ApiV2010Notification, errorChannel chan error) { +func (c *ApiService) streamNotificationWithContext(ctx context.Context, response *ListNotificationResponse, params *ListNotificationParams, recordChannel chan ApiV2010Notification, errorChannel chan error) { curRecord := 1 for response != nil { @@ -217,7 +236,7 @@ func (c *ApiService) streamNotification(response *ListNotificationResponse, para } } - record, err := client.GetNext(c.baseURL, response, c.getNextListNotificationResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListNotificationResponseWithContext) if err != nil { errorChannel <- err break @@ -232,11 +251,11 @@ func (c *ApiService) streamNotification(response *ListNotificationResponse, para close(errorChannel) } -func (c *ApiService) getNextListNotificationResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListNotificationResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_outgoing_caller_ids.go b/rest/api/v2010/accounts_outgoing_caller_ids.go index f098619e8..e735a3307 100644 --- a/rest/api/v2010/accounts_outgoing_caller_ids.go +++ b/rest/api/v2010/accounts_outgoing_caller_ids.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -70,8 +71,10 @@ func (params *CreateValidationRequestParams) SetStatusCallbackMethod(StatusCallb return params } -// func (c *ApiService) CreateValidationRequest(params *CreateValidationRequestParams) (*ApiV2010ValidationRequest, error) { + return c.CreateValidationRequestWithContext(context.TODO(), params) +} +func (c *ApiService) CreateValidationRequestWithContext(ctx context.Context, params *CreateValidationRequestParams) (*ApiV2010ValidationRequest, error) { path := "/2010-04-01/Accounts/{AccountSid}/OutgoingCallerIds.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -103,7 +106,7 @@ func (c *ApiService) CreateValidationRequest(params *CreateValidationRequestPara data.Set("StatusCallbackMethod", *params.StatusCallbackMethod) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -131,6 +134,9 @@ func (params *DeleteOutgoingCallerIdParams) SetPathAccountSid(PathAccountSid str // Delete the caller-id specified from the account func (c *ApiService) DeleteOutgoingCallerId(Sid string, params *DeleteOutgoingCallerIdParams) error { + return c.DeleteOutgoingCallerIdWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) DeleteOutgoingCallerIdWithContext(ctx context.Context, Sid string, params *DeleteOutgoingCallerIdParams) error { path := "/2010-04-01/Accounts/{AccountSid}/OutgoingCallerIds/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -144,7 +150,7 @@ func (c *ApiService) DeleteOutgoingCallerId(Sid string, params *DeleteOutgoingCa "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -167,6 +173,9 @@ func (params *FetchOutgoingCallerIdParams) SetPathAccountSid(PathAccountSid stri // Fetch an outgoing-caller-id belonging to the account used to make the request func (c *ApiService) FetchOutgoingCallerId(Sid string, params *FetchOutgoingCallerIdParams) (*ApiV2010OutgoingCallerId, error) { + return c.FetchOutgoingCallerIdWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) FetchOutgoingCallerIdWithContext(ctx context.Context, Sid string, params *FetchOutgoingCallerIdParams) (*ApiV2010OutgoingCallerId, error) { path := "/2010-04-01/Accounts/{AccountSid}/OutgoingCallerIds/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -180,7 +189,7 @@ func (c *ApiService) FetchOutgoingCallerId(Sid string, params *FetchOutgoingCall "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -232,6 +241,11 @@ func (params *ListOutgoingCallerIdParams) SetLimit(Limit int) *ListOutgoingCalle // Retrieve a single page of OutgoingCallerId records from the API. Request is executed immediately. func (c *ApiService) PageOutgoingCallerId(params *ListOutgoingCallerIdParams, pageToken, pageNumber string) (*ListOutgoingCallerIdResponse, error) { + return c.PageOutgoingCallerIdWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of OutgoingCallerId records from the API. Request is executed immediately. +func (c *ApiService) PageOutgoingCallerIdWithContext(ctx context.Context, params *ListOutgoingCallerIdParams, pageToken, pageNumber string) (*ListOutgoingCallerIdResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/OutgoingCallerIds.json" if params != nil && params.PathAccountSid != nil { @@ -262,7 +276,7 @@ func (c *ApiService) PageOutgoingCallerId(params *ListOutgoingCallerIdParams, pa data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -279,7 +293,12 @@ func (c *ApiService) PageOutgoingCallerId(params *ListOutgoingCallerIdParams, pa // Lists OutgoingCallerId records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListOutgoingCallerId(params *ListOutgoingCallerIdParams) ([]ApiV2010OutgoingCallerId, error) { - response, errors := c.StreamOutgoingCallerId(params) + return c.ListOutgoingCallerIdWithContext(context.TODO(), params) +} + +// Lists OutgoingCallerId records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListOutgoingCallerIdWithContext(ctx context.Context, params *ListOutgoingCallerIdParams) ([]ApiV2010OutgoingCallerId, error) { + response, errors := c.StreamOutgoingCallerIdWithContext(ctx, params) records := make([]ApiV2010OutgoingCallerId, 0) for record := range response { @@ -295,6 +314,11 @@ func (c *ApiService) ListOutgoingCallerId(params *ListOutgoingCallerIdParams) ([ // Streams OutgoingCallerId records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamOutgoingCallerId(params *ListOutgoingCallerIdParams) (chan ApiV2010OutgoingCallerId, chan error) { + return c.StreamOutgoingCallerIdWithContext(context.TODO(), params) +} + +// Streams OutgoingCallerId records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamOutgoingCallerIdWithContext(ctx context.Context, params *ListOutgoingCallerIdParams) (chan ApiV2010OutgoingCallerId, chan error) { if params == nil { params = &ListOutgoingCallerIdParams{} } @@ -303,19 +327,19 @@ func (c *ApiService) StreamOutgoingCallerId(params *ListOutgoingCallerIdParams) recordChannel := make(chan ApiV2010OutgoingCallerId, 1) errorChannel := make(chan error, 1) - response, err := c.PageOutgoingCallerId(params, "", "") + response, err := c.PageOutgoingCallerIdWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamOutgoingCallerId(response, params, recordChannel, errorChannel) + go c.streamOutgoingCallerIdWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamOutgoingCallerId(response *ListOutgoingCallerIdResponse, params *ListOutgoingCallerIdParams, recordChannel chan ApiV2010OutgoingCallerId, errorChannel chan error) { +func (c *ApiService) streamOutgoingCallerIdWithContext(ctx context.Context, response *ListOutgoingCallerIdResponse, params *ListOutgoingCallerIdParams, recordChannel chan ApiV2010OutgoingCallerId, errorChannel chan error) { curRecord := 1 for response != nil { @@ -330,7 +354,7 @@ func (c *ApiService) streamOutgoingCallerId(response *ListOutgoingCallerIdRespon } } - record, err := client.GetNext(c.baseURL, response, c.getNextListOutgoingCallerIdResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListOutgoingCallerIdResponseWithContext) if err != nil { errorChannel <- err break @@ -345,11 +369,11 @@ func (c *ApiService) streamOutgoingCallerId(response *ListOutgoingCallerIdRespon close(errorChannel) } -func (c *ApiService) getNextListOutgoingCallerIdResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListOutgoingCallerIdResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -382,6 +406,9 @@ func (params *UpdateOutgoingCallerIdParams) SetFriendlyName(FriendlyName string) // Updates the caller-id func (c *ApiService) UpdateOutgoingCallerId(Sid string, params *UpdateOutgoingCallerIdParams) (*ApiV2010OutgoingCallerId, error) { + return c.UpdateOutgoingCallerIdWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateOutgoingCallerIdWithContext(ctx context.Context, Sid string, params *UpdateOutgoingCallerIdParams) (*ApiV2010OutgoingCallerId, error) { path := "/2010-04-01/Accounts/{AccountSid}/OutgoingCallerIds/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -399,7 +426,7 @@ func (c *ApiService) UpdateOutgoingCallerId(Sid string, params *UpdateOutgoingCa data.Set("FriendlyName", *params.FriendlyName) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_queues.go b/rest/api/v2010/accounts_queues.go index 6bf8d72ad..235f0cd33 100644 --- a/rest/api/v2010/accounts_queues.go +++ b/rest/api/v2010/accounts_queues.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -48,6 +49,9 @@ func (params *CreateQueueParams) SetMaxSize(MaxSize int) *CreateQueueParams { // Create a queue func (c *ApiService) CreateQueue(params *CreateQueueParams) (*ApiV2010Queue, error) { + return c.CreateQueueWithContext(context.TODO(), params) +} +func (c *ApiService) CreateQueueWithContext(ctx context.Context, params *CreateQueueParams) (*ApiV2010Queue, error) { path := "/2010-04-01/Accounts/{AccountSid}/Queues.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -67,7 +71,7 @@ func (c *ApiService) CreateQueue(params *CreateQueueParams) (*ApiV2010Queue, err data.Set("MaxSize", fmt.Sprint(*params.MaxSize)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -95,6 +99,9 @@ func (params *DeleteQueueParams) SetPathAccountSid(PathAccountSid string) *Delet // Remove an empty queue func (c *ApiService) DeleteQueue(Sid string, params *DeleteQueueParams) error { + return c.DeleteQueueWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) DeleteQueueWithContext(ctx context.Context, Sid string, params *DeleteQueueParams) error { path := "/2010-04-01/Accounts/{AccountSid}/Queues/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -108,7 +115,7 @@ func (c *ApiService) DeleteQueue(Sid string, params *DeleteQueueParams) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -131,6 +138,9 @@ func (params *FetchQueueParams) SetPathAccountSid(PathAccountSid string) *FetchQ // Fetch an instance of a queue identified by the QueueSid func (c *ApiService) FetchQueue(Sid string, params *FetchQueueParams) (*ApiV2010Queue, error) { + return c.FetchQueueWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) FetchQueueWithContext(ctx context.Context, Sid string, params *FetchQueueParams) (*ApiV2010Queue, error) { path := "/2010-04-01/Accounts/{AccountSid}/Queues/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -144,7 +154,7 @@ func (c *ApiService) FetchQueue(Sid string, params *FetchQueueParams) (*ApiV2010 "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -184,6 +194,11 @@ func (params *ListQueueParams) SetLimit(Limit int) *ListQueueParams { // Retrieve a single page of Queue records from the API. Request is executed immediately. func (c *ApiService) PageQueue(params *ListQueueParams, pageToken, pageNumber string) (*ListQueueResponse, error) { + return c.PageQueueWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Queue records from the API. Request is executed immediately. +func (c *ApiService) PageQueueWithContext(ctx context.Context, params *ListQueueParams, pageToken, pageNumber string) (*ListQueueResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/Queues.json" if params != nil && params.PathAccountSid != nil { @@ -208,7 +223,7 @@ func (c *ApiService) PageQueue(params *ListQueueParams, pageToken, pageNumber st data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -225,7 +240,12 @@ func (c *ApiService) PageQueue(params *ListQueueParams, pageToken, pageNumber st // Lists Queue records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListQueue(params *ListQueueParams) ([]ApiV2010Queue, error) { - response, errors := c.StreamQueue(params) + return c.ListQueueWithContext(context.TODO(), params) +} + +// Lists Queue records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListQueueWithContext(ctx context.Context, params *ListQueueParams) ([]ApiV2010Queue, error) { + response, errors := c.StreamQueueWithContext(ctx, params) records := make([]ApiV2010Queue, 0) for record := range response { @@ -241,6 +261,11 @@ func (c *ApiService) ListQueue(params *ListQueueParams) ([]ApiV2010Queue, error) // Streams Queue records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamQueue(params *ListQueueParams) (chan ApiV2010Queue, chan error) { + return c.StreamQueueWithContext(context.TODO(), params) +} + +// Streams Queue records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamQueueWithContext(ctx context.Context, params *ListQueueParams) (chan ApiV2010Queue, chan error) { if params == nil { params = &ListQueueParams{} } @@ -249,19 +274,19 @@ func (c *ApiService) StreamQueue(params *ListQueueParams) (chan ApiV2010Queue, c recordChannel := make(chan ApiV2010Queue, 1) errorChannel := make(chan error, 1) - response, err := c.PageQueue(params, "", "") + response, err := c.PageQueueWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamQueue(response, params, recordChannel, errorChannel) + go c.streamQueueWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamQueue(response *ListQueueResponse, params *ListQueueParams, recordChannel chan ApiV2010Queue, errorChannel chan error) { +func (c *ApiService) streamQueueWithContext(ctx context.Context, response *ListQueueResponse, params *ListQueueParams, recordChannel chan ApiV2010Queue, errorChannel chan error) { curRecord := 1 for response != nil { @@ -276,7 +301,7 @@ func (c *ApiService) streamQueue(response *ListQueueResponse, params *ListQueueP } } - record, err := client.GetNext(c.baseURL, response, c.getNextListQueueResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListQueueResponseWithContext) if err != nil { errorChannel <- err break @@ -291,11 +316,11 @@ func (c *ApiService) streamQueue(response *ListQueueResponse, params *ListQueueP close(errorChannel) } -func (c *ApiService) getNextListQueueResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListQueueResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -334,6 +359,9 @@ func (params *UpdateQueueParams) SetMaxSize(MaxSize int) *UpdateQueueParams { // Update the queue with the new parameters func (c *ApiService) UpdateQueue(Sid string, params *UpdateQueueParams) (*ApiV2010Queue, error) { + return c.UpdateQueueWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateQueueWithContext(ctx context.Context, Sid string, params *UpdateQueueParams) (*ApiV2010Queue, error) { path := "/2010-04-01/Accounts/{AccountSid}/Queues/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -354,7 +382,7 @@ func (c *ApiService) UpdateQueue(Sid string, params *UpdateQueueParams) (*ApiV20 data.Set("MaxSize", fmt.Sprint(*params.MaxSize)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_queues_members.go b/rest/api/v2010/accounts_queues_members.go index f8fbb0b8e..760403fd9 100644 --- a/rest/api/v2010/accounts_queues_members.go +++ b/rest/api/v2010/accounts_queues_members.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -36,6 +37,9 @@ func (params *FetchMemberParams) SetPathAccountSid(PathAccountSid string) *Fetch // Fetch a specific member from the queue func (c *ApiService) FetchMember(QueueSid string, CallSid string, params *FetchMemberParams) (*ApiV2010Member, error) { + return c.FetchMemberWithContext(context.TODO(), QueueSid, CallSid, params) +} +func (c *ApiService) FetchMemberWithContext(ctx context.Context, QueueSid string, CallSid string, params *FetchMemberParams) (*ApiV2010Member, error) { path := "/2010-04-01/Accounts/{AccountSid}/Queues/{QueueSid}/Members/{CallSid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -50,7 +54,7 @@ func (c *ApiService) FetchMember(QueueSid string, CallSid string, params *FetchM "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -90,6 +94,11 @@ func (params *ListMemberParams) SetLimit(Limit int) *ListMemberParams { // Retrieve a single page of Member records from the API. Request is executed immediately. func (c *ApiService) PageMember(QueueSid string, params *ListMemberParams, pageToken, pageNumber string) (*ListMemberResponse, error) { + return c.PageMemberWithContext(context.TODO(), QueueSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Member records from the API. Request is executed immediately. +func (c *ApiService) PageMemberWithContext(ctx context.Context, QueueSid string, params *ListMemberParams, pageToken, pageNumber string) (*ListMemberResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/Queues/{QueueSid}/Members.json" if params != nil && params.PathAccountSid != nil { @@ -115,7 +124,7 @@ func (c *ApiService) PageMember(QueueSid string, params *ListMemberParams, pageT data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -132,7 +141,12 @@ func (c *ApiService) PageMember(QueueSid string, params *ListMemberParams, pageT // Lists Member records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListMember(QueueSid string, params *ListMemberParams) ([]ApiV2010Member, error) { - response, errors := c.StreamMember(QueueSid, params) + return c.ListMemberWithContext(context.TODO(), QueueSid, params) +} + +// Lists Member records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListMemberWithContext(ctx context.Context, QueueSid string, params *ListMemberParams) ([]ApiV2010Member, error) { + response, errors := c.StreamMemberWithContext(ctx, QueueSid, params) records := make([]ApiV2010Member, 0) for record := range response { @@ -148,6 +162,11 @@ func (c *ApiService) ListMember(QueueSid string, params *ListMemberParams) ([]Ap // Streams Member records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamMember(QueueSid string, params *ListMemberParams) (chan ApiV2010Member, chan error) { + return c.StreamMemberWithContext(context.TODO(), QueueSid, params) +} + +// Streams Member records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamMemberWithContext(ctx context.Context, QueueSid string, params *ListMemberParams) (chan ApiV2010Member, chan error) { if params == nil { params = &ListMemberParams{} } @@ -156,19 +175,19 @@ func (c *ApiService) StreamMember(QueueSid string, params *ListMemberParams) (ch recordChannel := make(chan ApiV2010Member, 1) errorChannel := make(chan error, 1) - response, err := c.PageMember(QueueSid, params, "", "") + response, err := c.PageMemberWithContext(ctx, QueueSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamMember(response, params, recordChannel, errorChannel) + go c.streamMemberWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamMember(response *ListMemberResponse, params *ListMemberParams, recordChannel chan ApiV2010Member, errorChannel chan error) { +func (c *ApiService) streamMemberWithContext(ctx context.Context, response *ListMemberResponse, params *ListMemberParams, recordChannel chan ApiV2010Member, errorChannel chan error) { curRecord := 1 for response != nil { @@ -183,7 +202,7 @@ func (c *ApiService) streamMember(response *ListMemberResponse, params *ListMemb } } - record, err := client.GetNext(c.baseURL, response, c.getNextListMemberResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListMemberResponseWithContext) if err != nil { errorChannel <- err break @@ -198,11 +217,11 @@ func (c *ApiService) streamMember(response *ListMemberResponse, params *ListMemb close(errorChannel) } -func (c *ApiService) getNextListMemberResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListMemberResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -241,6 +260,9 @@ func (params *UpdateMemberParams) SetMethod(Method string) *UpdateMemberParams { // Dequeue a member from a queue and have the member's call begin executing the TwiML document at that URL func (c *ApiService) UpdateMember(QueueSid string, CallSid string, params *UpdateMemberParams) (*ApiV2010Member, error) { + return c.UpdateMemberWithContext(context.TODO(), QueueSid, CallSid, params) +} +func (c *ApiService) UpdateMemberWithContext(ctx context.Context, QueueSid string, CallSid string, params *UpdateMemberParams) (*ApiV2010Member, error) { path := "/2010-04-01/Accounts/{AccountSid}/Queues/{QueueSid}/Members/{CallSid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -262,7 +284,7 @@ func (c *ApiService) UpdateMember(QueueSid string, CallSid string, params *Updat data.Set("Method", *params.Method) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_recordings.go b/rest/api/v2010/accounts_recordings.go index 6eca8877a..4f1e7d050 100644 --- a/rest/api/v2010/accounts_recordings.go +++ b/rest/api/v2010/accounts_recordings.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -37,6 +38,9 @@ func (params *DeleteRecordingParams) SetPathAccountSid(PathAccountSid string) *D // Delete a recording from your account func (c *ApiService) DeleteRecording(Sid string, params *DeleteRecordingParams) error { + return c.DeleteRecordingWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) DeleteRecordingWithContext(ctx context.Context, Sid string, params *DeleteRecordingParams) error { path := "/2010-04-01/Accounts/{AccountSid}/Recordings/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -50,7 +54,7 @@ func (c *ApiService) DeleteRecording(Sid string, params *DeleteRecordingParams) "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -79,6 +83,9 @@ func (params *FetchRecordingParams) SetIncludeSoftDeleted(IncludeSoftDeleted boo // Fetch an instance of a recording func (c *ApiService) FetchRecording(Sid string, params *FetchRecordingParams) (*ApiV2010Recording, error) { + return c.FetchRecordingWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) FetchRecordingWithContext(ctx context.Context, Sid string, params *FetchRecordingParams) (*ApiV2010Recording, error) { path := "/2010-04-01/Accounts/{AccountSid}/Recordings/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -96,7 +103,7 @@ func (c *ApiService) FetchRecording(Sid string, params *FetchRecordingParams) (* data.Set("IncludeSoftDeleted", fmt.Sprint(*params.IncludeSoftDeleted)) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -172,6 +179,11 @@ func (params *ListRecordingParams) SetLimit(Limit int) *ListRecordingParams { // Retrieve a single page of Recording records from the API. Request is executed immediately. func (c *ApiService) PageRecording(params *ListRecordingParams, pageToken, pageNumber string) (*ListRecordingResponse, error) { + return c.PageRecordingWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Recording records from the API. Request is executed immediately. +func (c *ApiService) PageRecordingWithContext(ctx context.Context, params *ListRecordingParams, pageToken, pageNumber string) (*ListRecordingResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/Recordings.json" if params != nil && params.PathAccountSid != nil { @@ -214,7 +226,7 @@ func (c *ApiService) PageRecording(params *ListRecordingParams, pageToken, pageN data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -231,7 +243,12 @@ func (c *ApiService) PageRecording(params *ListRecordingParams, pageToken, pageN // Lists Recording records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListRecording(params *ListRecordingParams) ([]ApiV2010Recording, error) { - response, errors := c.StreamRecording(params) + return c.ListRecordingWithContext(context.TODO(), params) +} + +// Lists Recording records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListRecordingWithContext(ctx context.Context, params *ListRecordingParams) ([]ApiV2010Recording, error) { + response, errors := c.StreamRecordingWithContext(ctx, params) records := make([]ApiV2010Recording, 0) for record := range response { @@ -247,6 +264,11 @@ func (c *ApiService) ListRecording(params *ListRecordingParams) ([]ApiV2010Recor // Streams Recording records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamRecording(params *ListRecordingParams) (chan ApiV2010Recording, chan error) { + return c.StreamRecordingWithContext(context.TODO(), params) +} + +// Streams Recording records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamRecordingWithContext(ctx context.Context, params *ListRecordingParams) (chan ApiV2010Recording, chan error) { if params == nil { params = &ListRecordingParams{} } @@ -255,19 +277,19 @@ func (c *ApiService) StreamRecording(params *ListRecordingParams) (chan ApiV2010 recordChannel := make(chan ApiV2010Recording, 1) errorChannel := make(chan error, 1) - response, err := c.PageRecording(params, "", "") + response, err := c.PageRecordingWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamRecording(response, params, recordChannel, errorChannel) + go c.streamRecordingWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamRecording(response *ListRecordingResponse, params *ListRecordingParams, recordChannel chan ApiV2010Recording, errorChannel chan error) { +func (c *ApiService) streamRecordingWithContext(ctx context.Context, response *ListRecordingResponse, params *ListRecordingParams, recordChannel chan ApiV2010Recording, errorChannel chan error) { curRecord := 1 for response != nil { @@ -282,7 +304,7 @@ func (c *ApiService) streamRecording(response *ListRecordingResponse, params *Li } } - record, err := client.GetNext(c.baseURL, response, c.getNextListRecordingResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListRecordingResponseWithContext) if err != nil { errorChannel <- err break @@ -297,11 +319,11 @@ func (c *ApiService) streamRecording(response *ListRecordingResponse, params *Li close(errorChannel) } -func (c *ApiService) getNextListRecordingResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListRecordingResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_recordings_add_on_results.go b/rest/api/v2010/accounts_recordings_add_on_results.go index c6c9e7760..ae35eebad 100644 --- a/rest/api/v2010/accounts_recordings_add_on_results.go +++ b/rest/api/v2010/accounts_recordings_add_on_results.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -36,6 +37,9 @@ func (params *DeleteRecordingAddOnResultParams) SetPathAccountSid(PathAccountSid // Delete a result and purge all associated Payloads func (c *ApiService) DeleteRecordingAddOnResult(ReferenceSid string, Sid string, params *DeleteRecordingAddOnResultParams) error { + return c.DeleteRecordingAddOnResultWithContext(context.TODO(), ReferenceSid, Sid, params) +} +func (c *ApiService) DeleteRecordingAddOnResultWithContext(ctx context.Context, ReferenceSid string, Sid string, params *DeleteRecordingAddOnResultParams) error { path := "/2010-04-01/Accounts/{AccountSid}/Recordings/{ReferenceSid}/AddOnResults/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -50,7 +54,7 @@ func (c *ApiService) DeleteRecordingAddOnResult(ReferenceSid string, Sid string, "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -73,6 +77,9 @@ func (params *FetchRecordingAddOnResultParams) SetPathAccountSid(PathAccountSid // Fetch an instance of an AddOnResult func (c *ApiService) FetchRecordingAddOnResult(ReferenceSid string, Sid string, params *FetchRecordingAddOnResultParams) (*ApiV2010RecordingAddOnResult, error) { + return c.FetchRecordingAddOnResultWithContext(context.TODO(), ReferenceSid, Sid, params) +} +func (c *ApiService) FetchRecordingAddOnResultWithContext(ctx context.Context, ReferenceSid string, Sid string, params *FetchRecordingAddOnResultParams) (*ApiV2010RecordingAddOnResult, error) { path := "/2010-04-01/Accounts/{AccountSid}/Recordings/{ReferenceSid}/AddOnResults/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -87,7 +94,7 @@ func (c *ApiService) FetchRecordingAddOnResult(ReferenceSid string, Sid string, "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -127,6 +134,11 @@ func (params *ListRecordingAddOnResultParams) SetLimit(Limit int) *ListRecording // Retrieve a single page of RecordingAddOnResult records from the API. Request is executed immediately. func (c *ApiService) PageRecordingAddOnResult(ReferenceSid string, params *ListRecordingAddOnResultParams, pageToken, pageNumber string) (*ListRecordingAddOnResultResponse, error) { + return c.PageRecordingAddOnResultWithContext(context.TODO(), ReferenceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of RecordingAddOnResult records from the API. Request is executed immediately. +func (c *ApiService) PageRecordingAddOnResultWithContext(ctx context.Context, ReferenceSid string, params *ListRecordingAddOnResultParams, pageToken, pageNumber string) (*ListRecordingAddOnResultResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/Recordings/{ReferenceSid}/AddOnResults.json" if params != nil && params.PathAccountSid != nil { @@ -152,7 +164,7 @@ func (c *ApiService) PageRecordingAddOnResult(ReferenceSid string, params *ListR data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -169,7 +181,12 @@ func (c *ApiService) PageRecordingAddOnResult(ReferenceSid string, params *ListR // Lists RecordingAddOnResult records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListRecordingAddOnResult(ReferenceSid string, params *ListRecordingAddOnResultParams) ([]ApiV2010RecordingAddOnResult, error) { - response, errors := c.StreamRecordingAddOnResult(ReferenceSid, params) + return c.ListRecordingAddOnResultWithContext(context.TODO(), ReferenceSid, params) +} + +// Lists RecordingAddOnResult records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListRecordingAddOnResultWithContext(ctx context.Context, ReferenceSid string, params *ListRecordingAddOnResultParams) ([]ApiV2010RecordingAddOnResult, error) { + response, errors := c.StreamRecordingAddOnResultWithContext(ctx, ReferenceSid, params) records := make([]ApiV2010RecordingAddOnResult, 0) for record := range response { @@ -185,6 +202,11 @@ func (c *ApiService) ListRecordingAddOnResult(ReferenceSid string, params *ListR // Streams RecordingAddOnResult records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamRecordingAddOnResult(ReferenceSid string, params *ListRecordingAddOnResultParams) (chan ApiV2010RecordingAddOnResult, chan error) { + return c.StreamRecordingAddOnResultWithContext(context.TODO(), ReferenceSid, params) +} + +// Streams RecordingAddOnResult records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamRecordingAddOnResultWithContext(ctx context.Context, ReferenceSid string, params *ListRecordingAddOnResultParams) (chan ApiV2010RecordingAddOnResult, chan error) { if params == nil { params = &ListRecordingAddOnResultParams{} } @@ -193,19 +215,19 @@ func (c *ApiService) StreamRecordingAddOnResult(ReferenceSid string, params *Lis recordChannel := make(chan ApiV2010RecordingAddOnResult, 1) errorChannel := make(chan error, 1) - response, err := c.PageRecordingAddOnResult(ReferenceSid, params, "", "") + response, err := c.PageRecordingAddOnResultWithContext(ctx, ReferenceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamRecordingAddOnResult(response, params, recordChannel, errorChannel) + go c.streamRecordingAddOnResultWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamRecordingAddOnResult(response *ListRecordingAddOnResultResponse, params *ListRecordingAddOnResultParams, recordChannel chan ApiV2010RecordingAddOnResult, errorChannel chan error) { +func (c *ApiService) streamRecordingAddOnResultWithContext(ctx context.Context, response *ListRecordingAddOnResultResponse, params *ListRecordingAddOnResultParams, recordChannel chan ApiV2010RecordingAddOnResult, errorChannel chan error) { curRecord := 1 for response != nil { @@ -220,7 +242,7 @@ func (c *ApiService) streamRecordingAddOnResult(response *ListRecordingAddOnResu } } - record, err := client.GetNext(c.baseURL, response, c.getNextListRecordingAddOnResultResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListRecordingAddOnResultResponseWithContext) if err != nil { errorChannel <- err break @@ -235,11 +257,11 @@ func (c *ApiService) streamRecordingAddOnResult(response *ListRecordingAddOnResu close(errorChannel) } -func (c *ApiService) getNextListRecordingAddOnResultResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListRecordingAddOnResultResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_recordings_add_on_results_payloads.go b/rest/api/v2010/accounts_recordings_add_on_results_payloads.go index 83012595d..b052346bd 100644 --- a/rest/api/v2010/accounts_recordings_add_on_results_payloads.go +++ b/rest/api/v2010/accounts_recordings_add_on_results_payloads.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -36,6 +37,9 @@ func (params *DeleteRecordingAddOnResultPayloadParams) SetPathAccountSid(PathAcc // Delete a payload from the result along with all associated Data func (c *ApiService) DeleteRecordingAddOnResultPayload(ReferenceSid string, AddOnResultSid string, Sid string, params *DeleteRecordingAddOnResultPayloadParams) error { + return c.DeleteRecordingAddOnResultPayloadWithContext(context.TODO(), ReferenceSid, AddOnResultSid, Sid, params) +} +func (c *ApiService) DeleteRecordingAddOnResultPayloadWithContext(ctx context.Context, ReferenceSid string, AddOnResultSid string, Sid string, params *DeleteRecordingAddOnResultPayloadParams) error { path := "/2010-04-01/Accounts/{AccountSid}/Recordings/{ReferenceSid}/AddOnResults/{AddOnResultSid}/Payloads/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -51,7 +55,7 @@ func (c *ApiService) DeleteRecordingAddOnResultPayload(ReferenceSid string, AddO "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -74,6 +78,9 @@ func (params *FetchRecordingAddOnResultPayloadParams) SetPathAccountSid(PathAcco // Fetch an instance of a result payload func (c *ApiService) FetchRecordingAddOnResultPayload(ReferenceSid string, AddOnResultSid string, Sid string, params *FetchRecordingAddOnResultPayloadParams) (*ApiV2010RecordingAddOnResultPayload, error) { + return c.FetchRecordingAddOnResultPayloadWithContext(context.TODO(), ReferenceSid, AddOnResultSid, Sid, params) +} +func (c *ApiService) FetchRecordingAddOnResultPayloadWithContext(ctx context.Context, ReferenceSid string, AddOnResultSid string, Sid string, params *FetchRecordingAddOnResultPayloadParams) (*ApiV2010RecordingAddOnResultPayload, error) { path := "/2010-04-01/Accounts/{AccountSid}/Recordings/{ReferenceSid}/AddOnResults/{AddOnResultSid}/Payloads/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -89,7 +96,7 @@ func (c *ApiService) FetchRecordingAddOnResultPayload(ReferenceSid string, AddOn "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -129,6 +136,11 @@ func (params *ListRecordingAddOnResultPayloadParams) SetLimit(Limit int) *ListRe // Retrieve a single page of RecordingAddOnResultPayload records from the API. Request is executed immediately. func (c *ApiService) PageRecordingAddOnResultPayload(ReferenceSid string, AddOnResultSid string, params *ListRecordingAddOnResultPayloadParams, pageToken, pageNumber string) (*ListRecordingAddOnResultPayloadResponse, error) { + return c.PageRecordingAddOnResultPayloadWithContext(context.TODO(), ReferenceSid, AddOnResultSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of RecordingAddOnResultPayload records from the API. Request is executed immediately. +func (c *ApiService) PageRecordingAddOnResultPayloadWithContext(ctx context.Context, ReferenceSid string, AddOnResultSid string, params *ListRecordingAddOnResultPayloadParams, pageToken, pageNumber string) (*ListRecordingAddOnResultPayloadResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/Recordings/{ReferenceSid}/AddOnResults/{AddOnResultSid}/Payloads.json" if params != nil && params.PathAccountSid != nil { @@ -155,7 +167,7 @@ func (c *ApiService) PageRecordingAddOnResultPayload(ReferenceSid string, AddOnR data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -172,7 +184,12 @@ func (c *ApiService) PageRecordingAddOnResultPayload(ReferenceSid string, AddOnR // Lists RecordingAddOnResultPayload records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListRecordingAddOnResultPayload(ReferenceSid string, AddOnResultSid string, params *ListRecordingAddOnResultPayloadParams) ([]ApiV2010RecordingAddOnResultPayload, error) { - response, errors := c.StreamRecordingAddOnResultPayload(ReferenceSid, AddOnResultSid, params) + return c.ListRecordingAddOnResultPayloadWithContext(context.TODO(), ReferenceSid, AddOnResultSid, params) +} + +// Lists RecordingAddOnResultPayload records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListRecordingAddOnResultPayloadWithContext(ctx context.Context, ReferenceSid string, AddOnResultSid string, params *ListRecordingAddOnResultPayloadParams) ([]ApiV2010RecordingAddOnResultPayload, error) { + response, errors := c.StreamRecordingAddOnResultPayloadWithContext(ctx, ReferenceSid, AddOnResultSid, params) records := make([]ApiV2010RecordingAddOnResultPayload, 0) for record := range response { @@ -188,6 +205,11 @@ func (c *ApiService) ListRecordingAddOnResultPayload(ReferenceSid string, AddOnR // Streams RecordingAddOnResultPayload records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamRecordingAddOnResultPayload(ReferenceSid string, AddOnResultSid string, params *ListRecordingAddOnResultPayloadParams) (chan ApiV2010RecordingAddOnResultPayload, chan error) { + return c.StreamRecordingAddOnResultPayloadWithContext(context.TODO(), ReferenceSid, AddOnResultSid, params) +} + +// Streams RecordingAddOnResultPayload records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamRecordingAddOnResultPayloadWithContext(ctx context.Context, ReferenceSid string, AddOnResultSid string, params *ListRecordingAddOnResultPayloadParams) (chan ApiV2010RecordingAddOnResultPayload, chan error) { if params == nil { params = &ListRecordingAddOnResultPayloadParams{} } @@ -196,19 +218,19 @@ func (c *ApiService) StreamRecordingAddOnResultPayload(ReferenceSid string, AddO recordChannel := make(chan ApiV2010RecordingAddOnResultPayload, 1) errorChannel := make(chan error, 1) - response, err := c.PageRecordingAddOnResultPayload(ReferenceSid, AddOnResultSid, params, "", "") + response, err := c.PageRecordingAddOnResultPayloadWithContext(ctx, ReferenceSid, AddOnResultSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamRecordingAddOnResultPayload(response, params, recordChannel, errorChannel) + go c.streamRecordingAddOnResultPayloadWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamRecordingAddOnResultPayload(response *ListRecordingAddOnResultPayloadResponse, params *ListRecordingAddOnResultPayloadParams, recordChannel chan ApiV2010RecordingAddOnResultPayload, errorChannel chan error) { +func (c *ApiService) streamRecordingAddOnResultPayloadWithContext(ctx context.Context, response *ListRecordingAddOnResultPayloadResponse, params *ListRecordingAddOnResultPayloadParams, recordChannel chan ApiV2010RecordingAddOnResultPayload, errorChannel chan error) { curRecord := 1 for response != nil { @@ -223,7 +245,7 @@ func (c *ApiService) streamRecordingAddOnResultPayload(response *ListRecordingAd } } - record, err := client.GetNext(c.baseURL, response, c.getNextListRecordingAddOnResultPayloadResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListRecordingAddOnResultPayloadResponseWithContext) if err != nil { errorChannel <- err break @@ -238,11 +260,11 @@ func (c *ApiService) streamRecordingAddOnResultPayload(response *ListRecordingAd close(errorChannel) } -func (c *ApiService) getNextListRecordingAddOnResultPayloadResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListRecordingAddOnResultPayloadResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_recordings_add_on_results_payloads_data.go b/rest/api/v2010/accounts_recordings_add_on_results_payloads_data.go index f89219e8d..7aea1f57c 100644 --- a/rest/api/v2010/accounts_recordings_add_on_results_payloads_data.go +++ b/rest/api/v2010/accounts_recordings_add_on_results_payloads_data.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -33,6 +34,9 @@ func (params *FetchRecordingAddOnResultPayloadDataParams) SetPathAccountSid(Path // Fetch an instance of a result payload func (c *ApiService) FetchRecordingAddOnResultPayloadData(ReferenceSid string, AddOnResultSid string, PayloadSid string, params *FetchRecordingAddOnResultPayloadDataParams) (*ApiV2010RecordingAddOnResultPayloadData, error) { + return c.FetchRecordingAddOnResultPayloadDataWithContext(context.TODO(), ReferenceSid, AddOnResultSid, PayloadSid, params) +} +func (c *ApiService) FetchRecordingAddOnResultPayloadDataWithContext(ctx context.Context, ReferenceSid string, AddOnResultSid string, PayloadSid string, params *FetchRecordingAddOnResultPayloadDataParams) (*ApiV2010RecordingAddOnResultPayloadData, error) { path := "/2010-04-01/Accounts/{AccountSid}/Recordings/{ReferenceSid}/AddOnResults/{AddOnResultSid}/Payloads/{PayloadSid}/Data.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -48,7 +52,7 @@ func (c *ApiService) FetchRecordingAddOnResultPayloadData(ReferenceSid string, A "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_recordings_transcriptions.go b/rest/api/v2010/accounts_recordings_transcriptions.go index 513ec233e..c810994c8 100644 --- a/rest/api/v2010/accounts_recordings_transcriptions.go +++ b/rest/api/v2010/accounts_recordings_transcriptions.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -34,8 +35,10 @@ func (params *DeleteRecordingTranscriptionParams) SetPathAccountSid(PathAccountS return params } -// func (c *ApiService) DeleteRecordingTranscription(RecordingSid string, Sid string, params *DeleteRecordingTranscriptionParams) error { + return c.DeleteRecordingTranscriptionWithContext(context.TODO(), RecordingSid, Sid, params) +} +func (c *ApiService) DeleteRecordingTranscriptionWithContext(ctx context.Context, RecordingSid string, Sid string, params *DeleteRecordingTranscriptionParams) error { path := "/2010-04-01/Accounts/{AccountSid}/Recordings/{RecordingSid}/Transcriptions/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -50,7 +53,7 @@ func (c *ApiService) DeleteRecordingTranscription(RecordingSid string, Sid strin "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -71,8 +74,10 @@ func (params *FetchRecordingTranscriptionParams) SetPathAccountSid(PathAccountSi return params } -// func (c *ApiService) FetchRecordingTranscription(RecordingSid string, Sid string, params *FetchRecordingTranscriptionParams) (*ApiV2010RecordingTranscription, error) { + return c.FetchRecordingTranscriptionWithContext(context.TODO(), RecordingSid, Sid, params) +} +func (c *ApiService) FetchRecordingTranscriptionWithContext(ctx context.Context, RecordingSid string, Sid string, params *FetchRecordingTranscriptionParams) (*ApiV2010RecordingTranscription, error) { path := "/2010-04-01/Accounts/{AccountSid}/Recordings/{RecordingSid}/Transcriptions/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -87,7 +92,7 @@ func (c *ApiService) FetchRecordingTranscription(RecordingSid string, Sid string "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -127,6 +132,11 @@ func (params *ListRecordingTranscriptionParams) SetLimit(Limit int) *ListRecordi // Retrieve a single page of RecordingTranscription records from the API. Request is executed immediately. func (c *ApiService) PageRecordingTranscription(RecordingSid string, params *ListRecordingTranscriptionParams, pageToken, pageNumber string) (*ListRecordingTranscriptionResponse, error) { + return c.PageRecordingTranscriptionWithContext(context.TODO(), RecordingSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of RecordingTranscription records from the API. Request is executed immediately. +func (c *ApiService) PageRecordingTranscriptionWithContext(ctx context.Context, RecordingSid string, params *ListRecordingTranscriptionParams, pageToken, pageNumber string) (*ListRecordingTranscriptionResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/Recordings/{RecordingSid}/Transcriptions.json" if params != nil && params.PathAccountSid != nil { @@ -152,7 +162,7 @@ func (c *ApiService) PageRecordingTranscription(RecordingSid string, params *Lis data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -169,7 +179,12 @@ func (c *ApiService) PageRecordingTranscription(RecordingSid string, params *Lis // Lists RecordingTranscription records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListRecordingTranscription(RecordingSid string, params *ListRecordingTranscriptionParams) ([]ApiV2010RecordingTranscription, error) { - response, errors := c.StreamRecordingTranscription(RecordingSid, params) + return c.ListRecordingTranscriptionWithContext(context.TODO(), RecordingSid, params) +} + +// Lists RecordingTranscription records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListRecordingTranscriptionWithContext(ctx context.Context, RecordingSid string, params *ListRecordingTranscriptionParams) ([]ApiV2010RecordingTranscription, error) { + response, errors := c.StreamRecordingTranscriptionWithContext(ctx, RecordingSid, params) records := make([]ApiV2010RecordingTranscription, 0) for record := range response { @@ -185,6 +200,11 @@ func (c *ApiService) ListRecordingTranscription(RecordingSid string, params *Lis // Streams RecordingTranscription records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamRecordingTranscription(RecordingSid string, params *ListRecordingTranscriptionParams) (chan ApiV2010RecordingTranscription, chan error) { + return c.StreamRecordingTranscriptionWithContext(context.TODO(), RecordingSid, params) +} + +// Streams RecordingTranscription records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamRecordingTranscriptionWithContext(ctx context.Context, RecordingSid string, params *ListRecordingTranscriptionParams) (chan ApiV2010RecordingTranscription, chan error) { if params == nil { params = &ListRecordingTranscriptionParams{} } @@ -193,19 +213,19 @@ func (c *ApiService) StreamRecordingTranscription(RecordingSid string, params *L recordChannel := make(chan ApiV2010RecordingTranscription, 1) errorChannel := make(chan error, 1) - response, err := c.PageRecordingTranscription(RecordingSid, params, "", "") + response, err := c.PageRecordingTranscriptionWithContext(ctx, RecordingSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamRecordingTranscription(response, params, recordChannel, errorChannel) + go c.streamRecordingTranscriptionWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamRecordingTranscription(response *ListRecordingTranscriptionResponse, params *ListRecordingTranscriptionParams, recordChannel chan ApiV2010RecordingTranscription, errorChannel chan error) { +func (c *ApiService) streamRecordingTranscriptionWithContext(ctx context.Context, response *ListRecordingTranscriptionResponse, params *ListRecordingTranscriptionParams, recordChannel chan ApiV2010RecordingTranscription, errorChannel chan error) { curRecord := 1 for response != nil { @@ -220,7 +240,7 @@ func (c *ApiService) streamRecordingTranscription(response *ListRecordingTranscr } } - record, err := client.GetNext(c.baseURL, response, c.getNextListRecordingTranscriptionResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListRecordingTranscriptionResponseWithContext) if err != nil { errorChannel <- err break @@ -235,11 +255,11 @@ func (c *ApiService) streamRecordingTranscription(response *ListRecordingTranscr close(errorChannel) } -func (c *ApiService) getNextListRecordingTranscriptionResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListRecordingTranscriptionResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_signing_keys.go b/rest/api/v2010/accounts_signing_keys.go index fa9f66dfd..0cb13d0f0 100644 --- a/rest/api/v2010/accounts_signing_keys.go +++ b/rest/api/v2010/accounts_signing_keys.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -42,6 +43,9 @@ func (params *CreateNewSigningKeyParams) SetFriendlyName(FriendlyName string) *C // Create a new Signing Key for the account making the request. func (c *ApiService) CreateNewSigningKey(params *CreateNewSigningKeyParams) (*ApiV2010NewSigningKey, error) { + return c.CreateNewSigningKeyWithContext(context.TODO(), params) +} +func (c *ApiService) CreateNewSigningKeyWithContext(ctx context.Context, params *CreateNewSigningKeyParams) (*ApiV2010NewSigningKey, error) { path := "/2010-04-01/Accounts/{AccountSid}/SigningKeys.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -58,7 +62,7 @@ func (c *ApiService) CreateNewSigningKey(params *CreateNewSigningKeyParams) (*Ap data.Set("FriendlyName", *params.FriendlyName) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -84,8 +88,10 @@ func (params *DeleteSigningKeyParams) SetPathAccountSid(PathAccountSid string) * return params } -// func (c *ApiService) DeleteSigningKey(Sid string, params *DeleteSigningKeyParams) error { + return c.DeleteSigningKeyWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) DeleteSigningKeyWithContext(ctx context.Context, Sid string, params *DeleteSigningKeyParams) error { path := "/2010-04-01/Accounts/{AccountSid}/SigningKeys/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -99,7 +105,7 @@ func (c *ApiService) DeleteSigningKey(Sid string, params *DeleteSigningKeyParams "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -120,8 +126,10 @@ func (params *FetchSigningKeyParams) SetPathAccountSid(PathAccountSid string) *F return params } -// func (c *ApiService) FetchSigningKey(Sid string, params *FetchSigningKeyParams) (*ApiV2010SigningKey, error) { + return c.FetchSigningKeyWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) FetchSigningKeyWithContext(ctx context.Context, Sid string, params *FetchSigningKeyParams) (*ApiV2010SigningKey, error) { path := "/2010-04-01/Accounts/{AccountSid}/SigningKeys/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -135,7 +143,7 @@ func (c *ApiService) FetchSigningKey(Sid string, params *FetchSigningKeyParams) "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -175,6 +183,11 @@ func (params *ListSigningKeyParams) SetLimit(Limit int) *ListSigningKeyParams { // Retrieve a single page of SigningKey records from the API. Request is executed immediately. func (c *ApiService) PageSigningKey(params *ListSigningKeyParams, pageToken, pageNumber string) (*ListSigningKeyResponse, error) { + return c.PageSigningKeyWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of SigningKey records from the API. Request is executed immediately. +func (c *ApiService) PageSigningKeyWithContext(ctx context.Context, params *ListSigningKeyParams, pageToken, pageNumber string) (*ListSigningKeyResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/SigningKeys.json" if params != nil && params.PathAccountSid != nil { @@ -199,7 +212,7 @@ func (c *ApiService) PageSigningKey(params *ListSigningKeyParams, pageToken, pag data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -216,7 +229,12 @@ func (c *ApiService) PageSigningKey(params *ListSigningKeyParams, pageToken, pag // Lists SigningKey records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListSigningKey(params *ListSigningKeyParams) ([]ApiV2010SigningKey, error) { - response, errors := c.StreamSigningKey(params) + return c.ListSigningKeyWithContext(context.TODO(), params) +} + +// Lists SigningKey records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListSigningKeyWithContext(ctx context.Context, params *ListSigningKeyParams) ([]ApiV2010SigningKey, error) { + response, errors := c.StreamSigningKeyWithContext(ctx, params) records := make([]ApiV2010SigningKey, 0) for record := range response { @@ -232,6 +250,11 @@ func (c *ApiService) ListSigningKey(params *ListSigningKeyParams) ([]ApiV2010Sig // Streams SigningKey records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamSigningKey(params *ListSigningKeyParams) (chan ApiV2010SigningKey, chan error) { + return c.StreamSigningKeyWithContext(context.TODO(), params) +} + +// Streams SigningKey records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamSigningKeyWithContext(ctx context.Context, params *ListSigningKeyParams) (chan ApiV2010SigningKey, chan error) { if params == nil { params = &ListSigningKeyParams{} } @@ -240,19 +263,19 @@ func (c *ApiService) StreamSigningKey(params *ListSigningKeyParams) (chan ApiV20 recordChannel := make(chan ApiV2010SigningKey, 1) errorChannel := make(chan error, 1) - response, err := c.PageSigningKey(params, "", "") + response, err := c.PageSigningKeyWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSigningKey(response, params, recordChannel, errorChannel) + go c.streamSigningKeyWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamSigningKey(response *ListSigningKeyResponse, params *ListSigningKeyParams, recordChannel chan ApiV2010SigningKey, errorChannel chan error) { +func (c *ApiService) streamSigningKeyWithContext(ctx context.Context, response *ListSigningKeyResponse, params *ListSigningKeyParams, recordChannel chan ApiV2010SigningKey, errorChannel chan error) { curRecord := 1 for response != nil { @@ -267,7 +290,7 @@ func (c *ApiService) streamSigningKey(response *ListSigningKeyResponse, params * } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSigningKeyResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListSigningKeyResponseWithContext) if err != nil { errorChannel <- err break @@ -282,11 +305,11 @@ func (c *ApiService) streamSigningKey(response *ListSigningKeyResponse, params * close(errorChannel) } -func (c *ApiService) getNextListSigningKeyResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSigningKeyResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -317,8 +340,10 @@ func (params *UpdateSigningKeyParams) SetFriendlyName(FriendlyName string) *Upda return params } -// func (c *ApiService) UpdateSigningKey(Sid string, params *UpdateSigningKeyParams) (*ApiV2010SigningKey, error) { + return c.UpdateSigningKeyWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateSigningKeyWithContext(ctx context.Context, Sid string, params *UpdateSigningKeyParams) (*ApiV2010SigningKey, error) { path := "/2010-04-01/Accounts/{AccountSid}/SigningKeys/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -336,7 +361,7 @@ func (c *ApiService) UpdateSigningKey(Sid string, params *UpdateSigningKeyParams data.Set("FriendlyName", *params.FriendlyName) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_sip_credential_lists.go b/rest/api/v2010/accounts_sip_credential_lists.go index ba6978691..74e4ce92f 100644 --- a/rest/api/v2010/accounts_sip_credential_lists.go +++ b/rest/api/v2010/accounts_sip_credential_lists.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -42,6 +43,9 @@ func (params *CreateSipCredentialListParams) SetFriendlyName(FriendlyName string // Create a Credential List func (c *ApiService) CreateSipCredentialList(params *CreateSipCredentialListParams) (*ApiV2010SipCredentialList, error) { + return c.CreateSipCredentialListWithContext(context.TODO(), params) +} +func (c *ApiService) CreateSipCredentialListWithContext(ctx context.Context, params *CreateSipCredentialListParams) (*ApiV2010SipCredentialList, error) { path := "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -58,7 +62,7 @@ func (c *ApiService) CreateSipCredentialList(params *CreateSipCredentialListPara data.Set("FriendlyName", *params.FriendlyName) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -86,6 +90,9 @@ func (params *DeleteSipCredentialListParams) SetPathAccountSid(PathAccountSid st // Delete a Credential List func (c *ApiService) DeleteSipCredentialList(Sid string, params *DeleteSipCredentialListParams) error { + return c.DeleteSipCredentialListWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) DeleteSipCredentialListWithContext(ctx context.Context, Sid string, params *DeleteSipCredentialListParams) error { path := "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -99,7 +106,7 @@ func (c *ApiService) DeleteSipCredentialList(Sid string, params *DeleteSipCreden "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -122,6 +129,9 @@ func (params *FetchSipCredentialListParams) SetPathAccountSid(PathAccountSid str // Get a Credential List func (c *ApiService) FetchSipCredentialList(Sid string, params *FetchSipCredentialListParams) (*ApiV2010SipCredentialList, error) { + return c.FetchSipCredentialListWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) FetchSipCredentialListWithContext(ctx context.Context, Sid string, params *FetchSipCredentialListParams) (*ApiV2010SipCredentialList, error) { path := "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -135,7 +145,7 @@ func (c *ApiService) FetchSipCredentialList(Sid string, params *FetchSipCredenti "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -175,6 +185,11 @@ func (params *ListSipCredentialListParams) SetLimit(Limit int) *ListSipCredentia // Retrieve a single page of SipCredentialList records from the API. Request is executed immediately. func (c *ApiService) PageSipCredentialList(params *ListSipCredentialListParams, pageToken, pageNumber string) (*ListSipCredentialListResponse, error) { + return c.PageSipCredentialListWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of SipCredentialList records from the API. Request is executed immediately. +func (c *ApiService) PageSipCredentialListWithContext(ctx context.Context, params *ListSipCredentialListParams, pageToken, pageNumber string) (*ListSipCredentialListResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists.json" if params != nil && params.PathAccountSid != nil { @@ -199,7 +214,7 @@ func (c *ApiService) PageSipCredentialList(params *ListSipCredentialListParams, data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -216,7 +231,12 @@ func (c *ApiService) PageSipCredentialList(params *ListSipCredentialListParams, // Lists SipCredentialList records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListSipCredentialList(params *ListSipCredentialListParams) ([]ApiV2010SipCredentialList, error) { - response, errors := c.StreamSipCredentialList(params) + return c.ListSipCredentialListWithContext(context.TODO(), params) +} + +// Lists SipCredentialList records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListSipCredentialListWithContext(ctx context.Context, params *ListSipCredentialListParams) ([]ApiV2010SipCredentialList, error) { + response, errors := c.StreamSipCredentialListWithContext(ctx, params) records := make([]ApiV2010SipCredentialList, 0) for record := range response { @@ -232,6 +252,11 @@ func (c *ApiService) ListSipCredentialList(params *ListSipCredentialListParams) // Streams SipCredentialList records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamSipCredentialList(params *ListSipCredentialListParams) (chan ApiV2010SipCredentialList, chan error) { + return c.StreamSipCredentialListWithContext(context.TODO(), params) +} + +// Streams SipCredentialList records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamSipCredentialListWithContext(ctx context.Context, params *ListSipCredentialListParams) (chan ApiV2010SipCredentialList, chan error) { if params == nil { params = &ListSipCredentialListParams{} } @@ -240,19 +265,19 @@ func (c *ApiService) StreamSipCredentialList(params *ListSipCredentialListParams recordChannel := make(chan ApiV2010SipCredentialList, 1) errorChannel := make(chan error, 1) - response, err := c.PageSipCredentialList(params, "", "") + response, err := c.PageSipCredentialListWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSipCredentialList(response, params, recordChannel, errorChannel) + go c.streamSipCredentialListWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamSipCredentialList(response *ListSipCredentialListResponse, params *ListSipCredentialListParams, recordChannel chan ApiV2010SipCredentialList, errorChannel chan error) { +func (c *ApiService) streamSipCredentialListWithContext(ctx context.Context, response *ListSipCredentialListResponse, params *ListSipCredentialListParams, recordChannel chan ApiV2010SipCredentialList, errorChannel chan error) { curRecord := 1 for response != nil { @@ -267,7 +292,7 @@ func (c *ApiService) streamSipCredentialList(response *ListSipCredentialListResp } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSipCredentialListResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListSipCredentialListResponseWithContext) if err != nil { errorChannel <- err break @@ -282,11 +307,11 @@ func (c *ApiService) streamSipCredentialList(response *ListSipCredentialListResp close(errorChannel) } -func (c *ApiService) getNextListSipCredentialListResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSipCredentialListResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -319,6 +344,9 @@ func (params *UpdateSipCredentialListParams) SetFriendlyName(FriendlyName string // Update a Credential List func (c *ApiService) UpdateSipCredentialList(Sid string, params *UpdateSipCredentialListParams) (*ApiV2010SipCredentialList, error) { + return c.UpdateSipCredentialListWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateSipCredentialListWithContext(ctx context.Context, Sid string, params *UpdateSipCredentialListParams) (*ApiV2010SipCredentialList, error) { path := "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -336,7 +364,7 @@ func (c *ApiService) UpdateSipCredentialList(Sid string, params *UpdateSipCreden data.Set("FriendlyName", *params.FriendlyName) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_sip_credential_lists_credentials.go b/rest/api/v2010/accounts_sip_credential_lists_credentials.go index c49a0b82e..036e2abff 100644 --- a/rest/api/v2010/accounts_sip_credential_lists_credentials.go +++ b/rest/api/v2010/accounts_sip_credential_lists_credentials.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -48,6 +49,9 @@ func (params *CreateSipCredentialParams) SetPassword(Password string) *CreateSip // Create a new credential resource. func (c *ApiService) CreateSipCredential(CredentialListSid string, params *CreateSipCredentialParams) (*ApiV2010SipCredential, error) { + return c.CreateSipCredentialWithContext(context.TODO(), CredentialListSid, params) +} +func (c *ApiService) CreateSipCredentialWithContext(ctx context.Context, CredentialListSid string, params *CreateSipCredentialParams) (*ApiV2010SipCredential, error) { path := "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{CredentialListSid}/Credentials.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -68,7 +72,7 @@ func (c *ApiService) CreateSipCredential(CredentialListSid string, params *Creat data.Set("Password", *params.Password) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -96,6 +100,9 @@ func (params *DeleteSipCredentialParams) SetPathAccountSid(PathAccountSid string // Delete a credential resource. func (c *ApiService) DeleteSipCredential(CredentialListSid string, Sid string, params *DeleteSipCredentialParams) error { + return c.DeleteSipCredentialWithContext(context.TODO(), CredentialListSid, Sid, params) +} +func (c *ApiService) DeleteSipCredentialWithContext(ctx context.Context, CredentialListSid string, Sid string, params *DeleteSipCredentialParams) error { path := "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{CredentialListSid}/Credentials/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -110,7 +117,7 @@ func (c *ApiService) DeleteSipCredential(CredentialListSid string, Sid string, p "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -133,6 +140,9 @@ func (params *FetchSipCredentialParams) SetPathAccountSid(PathAccountSid string) // Fetch a single credential. func (c *ApiService) FetchSipCredential(CredentialListSid string, Sid string, params *FetchSipCredentialParams) (*ApiV2010SipCredential, error) { + return c.FetchSipCredentialWithContext(context.TODO(), CredentialListSid, Sid, params) +} +func (c *ApiService) FetchSipCredentialWithContext(ctx context.Context, CredentialListSid string, Sid string, params *FetchSipCredentialParams) (*ApiV2010SipCredential, error) { path := "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{CredentialListSid}/Credentials/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -147,7 +157,7 @@ func (c *ApiService) FetchSipCredential(CredentialListSid string, Sid string, pa "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -187,6 +197,11 @@ func (params *ListSipCredentialParams) SetLimit(Limit int) *ListSipCredentialPar // Retrieve a single page of SipCredential records from the API. Request is executed immediately. func (c *ApiService) PageSipCredential(CredentialListSid string, params *ListSipCredentialParams, pageToken, pageNumber string) (*ListSipCredentialResponse, error) { + return c.PageSipCredentialWithContext(context.TODO(), CredentialListSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of SipCredential records from the API. Request is executed immediately. +func (c *ApiService) PageSipCredentialWithContext(ctx context.Context, CredentialListSid string, params *ListSipCredentialParams, pageToken, pageNumber string) (*ListSipCredentialResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{CredentialListSid}/Credentials.json" if params != nil && params.PathAccountSid != nil { @@ -212,7 +227,7 @@ func (c *ApiService) PageSipCredential(CredentialListSid string, params *ListSip data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -229,7 +244,12 @@ func (c *ApiService) PageSipCredential(CredentialListSid string, params *ListSip // Lists SipCredential records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListSipCredential(CredentialListSid string, params *ListSipCredentialParams) ([]ApiV2010SipCredential, error) { - response, errors := c.StreamSipCredential(CredentialListSid, params) + return c.ListSipCredentialWithContext(context.TODO(), CredentialListSid, params) +} + +// Lists SipCredential records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListSipCredentialWithContext(ctx context.Context, CredentialListSid string, params *ListSipCredentialParams) ([]ApiV2010SipCredential, error) { + response, errors := c.StreamSipCredentialWithContext(ctx, CredentialListSid, params) records := make([]ApiV2010SipCredential, 0) for record := range response { @@ -245,6 +265,11 @@ func (c *ApiService) ListSipCredential(CredentialListSid string, params *ListSip // Streams SipCredential records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamSipCredential(CredentialListSid string, params *ListSipCredentialParams) (chan ApiV2010SipCredential, chan error) { + return c.StreamSipCredentialWithContext(context.TODO(), CredentialListSid, params) +} + +// Streams SipCredential records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamSipCredentialWithContext(ctx context.Context, CredentialListSid string, params *ListSipCredentialParams) (chan ApiV2010SipCredential, chan error) { if params == nil { params = &ListSipCredentialParams{} } @@ -253,19 +278,19 @@ func (c *ApiService) StreamSipCredential(CredentialListSid string, params *ListS recordChannel := make(chan ApiV2010SipCredential, 1) errorChannel := make(chan error, 1) - response, err := c.PageSipCredential(CredentialListSid, params, "", "") + response, err := c.PageSipCredentialWithContext(ctx, CredentialListSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSipCredential(response, params, recordChannel, errorChannel) + go c.streamSipCredentialWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamSipCredential(response *ListSipCredentialResponse, params *ListSipCredentialParams, recordChannel chan ApiV2010SipCredential, errorChannel chan error) { +func (c *ApiService) streamSipCredentialWithContext(ctx context.Context, response *ListSipCredentialResponse, params *ListSipCredentialParams, recordChannel chan ApiV2010SipCredential, errorChannel chan error) { curRecord := 1 for response != nil { @@ -280,7 +305,7 @@ func (c *ApiService) streamSipCredential(response *ListSipCredentialResponse, pa } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSipCredentialResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListSipCredentialResponseWithContext) if err != nil { errorChannel <- err break @@ -295,11 +320,11 @@ func (c *ApiService) streamSipCredential(response *ListSipCredentialResponse, pa close(errorChannel) } -func (c *ApiService) getNextListSipCredentialResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSipCredentialResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -332,6 +357,9 @@ func (params *UpdateSipCredentialParams) SetPassword(Password string) *UpdateSip // Update a credential resource. func (c *ApiService) UpdateSipCredential(CredentialListSid string, Sid string, params *UpdateSipCredentialParams) (*ApiV2010SipCredential, error) { + return c.UpdateSipCredentialWithContext(context.TODO(), CredentialListSid, Sid, params) +} +func (c *ApiService) UpdateSipCredentialWithContext(ctx context.Context, CredentialListSid string, Sid string, params *UpdateSipCredentialParams) (*ApiV2010SipCredential, error) { path := "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{CredentialListSid}/Credentials/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -350,7 +378,7 @@ func (c *ApiService) UpdateSipCredential(CredentialListSid string, Sid string, p data.Set("Password", *params.Password) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_sip_domains.go b/rest/api/v2010/accounts_sip_domains.go index c199785fb..03d6fa12c 100644 --- a/rest/api/v2010/accounts_sip_domains.go +++ b/rest/api/v2010/accounts_sip_domains.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -114,6 +115,9 @@ func (params *CreateSipDomainParams) SetEmergencyCallerSid(EmergencyCallerSid st // Create a new Domain func (c *ApiService) CreateSipDomain(params *CreateSipDomainParams) (*ApiV2010SipDomain, error) { + return c.CreateSipDomainWithContext(context.TODO(), params) +} +func (c *ApiService) CreateSipDomainWithContext(ctx context.Context, params *CreateSipDomainParams) (*ApiV2010SipDomain, error) { path := "/2010-04-01/Accounts/{AccountSid}/SIP/Domains.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -166,7 +170,7 @@ func (c *ApiService) CreateSipDomain(params *CreateSipDomainParams) (*ApiV2010Si data.Set("EmergencyCallerSid", *params.EmergencyCallerSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -194,6 +198,9 @@ func (params *DeleteSipDomainParams) SetPathAccountSid(PathAccountSid string) *D // Delete an instance of a Domain func (c *ApiService) DeleteSipDomain(Sid string, params *DeleteSipDomainParams) error { + return c.DeleteSipDomainWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) DeleteSipDomainWithContext(ctx context.Context, Sid string, params *DeleteSipDomainParams) error { path := "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -207,7 +214,7 @@ func (c *ApiService) DeleteSipDomain(Sid string, params *DeleteSipDomainParams) "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -230,6 +237,9 @@ func (params *FetchSipDomainParams) SetPathAccountSid(PathAccountSid string) *Fe // Fetch an instance of a Domain func (c *ApiService) FetchSipDomain(Sid string, params *FetchSipDomainParams) (*ApiV2010SipDomain, error) { + return c.FetchSipDomainWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) FetchSipDomainWithContext(ctx context.Context, Sid string, params *FetchSipDomainParams) (*ApiV2010SipDomain, error) { path := "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -243,7 +253,7 @@ func (c *ApiService) FetchSipDomain(Sid string, params *FetchSipDomainParams) (* "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -283,6 +293,11 @@ func (params *ListSipDomainParams) SetLimit(Limit int) *ListSipDomainParams { // Retrieve a single page of SipDomain records from the API. Request is executed immediately. func (c *ApiService) PageSipDomain(params *ListSipDomainParams, pageToken, pageNumber string) (*ListSipDomainResponse, error) { + return c.PageSipDomainWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of SipDomain records from the API. Request is executed immediately. +func (c *ApiService) PageSipDomainWithContext(ctx context.Context, params *ListSipDomainParams, pageToken, pageNumber string) (*ListSipDomainResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/SIP/Domains.json" if params != nil && params.PathAccountSid != nil { @@ -307,7 +322,7 @@ func (c *ApiService) PageSipDomain(params *ListSipDomainParams, pageToken, pageN data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -324,7 +339,12 @@ func (c *ApiService) PageSipDomain(params *ListSipDomainParams, pageToken, pageN // Lists SipDomain records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListSipDomain(params *ListSipDomainParams) ([]ApiV2010SipDomain, error) { - response, errors := c.StreamSipDomain(params) + return c.ListSipDomainWithContext(context.TODO(), params) +} + +// Lists SipDomain records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListSipDomainWithContext(ctx context.Context, params *ListSipDomainParams) ([]ApiV2010SipDomain, error) { + response, errors := c.StreamSipDomainWithContext(ctx, params) records := make([]ApiV2010SipDomain, 0) for record := range response { @@ -340,6 +360,11 @@ func (c *ApiService) ListSipDomain(params *ListSipDomainParams) ([]ApiV2010SipDo // Streams SipDomain records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamSipDomain(params *ListSipDomainParams) (chan ApiV2010SipDomain, chan error) { + return c.StreamSipDomainWithContext(context.TODO(), params) +} + +// Streams SipDomain records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamSipDomainWithContext(ctx context.Context, params *ListSipDomainParams) (chan ApiV2010SipDomain, chan error) { if params == nil { params = &ListSipDomainParams{} } @@ -348,19 +373,19 @@ func (c *ApiService) StreamSipDomain(params *ListSipDomainParams) (chan ApiV2010 recordChannel := make(chan ApiV2010SipDomain, 1) errorChannel := make(chan error, 1) - response, err := c.PageSipDomain(params, "", "") + response, err := c.PageSipDomainWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSipDomain(response, params, recordChannel, errorChannel) + go c.streamSipDomainWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamSipDomain(response *ListSipDomainResponse, params *ListSipDomainParams, recordChannel chan ApiV2010SipDomain, errorChannel chan error) { +func (c *ApiService) streamSipDomainWithContext(ctx context.Context, response *ListSipDomainResponse, params *ListSipDomainParams, recordChannel chan ApiV2010SipDomain, errorChannel chan error) { curRecord := 1 for response != nil { @@ -375,7 +400,7 @@ func (c *ApiService) streamSipDomain(response *ListSipDomainResponse, params *Li } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSipDomainResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListSipDomainResponseWithContext) if err != nil { errorChannel <- err break @@ -390,11 +415,11 @@ func (c *ApiService) streamSipDomain(response *ListSipDomainResponse, params *Li close(errorChannel) } -func (c *ApiService) getNextListSipDomainResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSipDomainResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -499,6 +524,9 @@ func (params *UpdateSipDomainParams) SetEmergencyCallerSid(EmergencyCallerSid st // Update the attributes of a domain func (c *ApiService) UpdateSipDomain(Sid string, params *UpdateSipDomainParams) (*ApiV2010SipDomain, error) { + return c.UpdateSipDomainWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateSipDomainWithContext(ctx context.Context, Sid string, params *UpdateSipDomainParams) (*ApiV2010SipDomain, error) { path := "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -552,7 +580,7 @@ func (c *ApiService) UpdateSipDomain(Sid string, params *UpdateSipDomainParams) data.Set("EmergencyCallerSid", *params.EmergencyCallerSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_sip_domains_auth_calls_credential_list_mappings.go b/rest/api/v2010/accounts_sip_domains_auth_calls_credential_list_mappings.go index 684b9e14b..de97f63c1 100644 --- a/rest/api/v2010/accounts_sip_domains_auth_calls_credential_list_mappings.go +++ b/rest/api/v2010/accounts_sip_domains_auth_calls_credential_list_mappings.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -42,6 +43,9 @@ func (params *CreateSipAuthCallsCredentialListMappingParams) SetCredentialListSi // Create a new credential list mapping resource func (c *ApiService) CreateSipAuthCallsCredentialListMapping(DomainSid string, params *CreateSipAuthCallsCredentialListMappingParams) (*ApiV2010SipAuthCallsCredentialListMapping, error) { + return c.CreateSipAuthCallsCredentialListMappingWithContext(context.TODO(), DomainSid, params) +} +func (c *ApiService) CreateSipAuthCallsCredentialListMappingWithContext(ctx context.Context, DomainSid string, params *CreateSipAuthCallsCredentialListMappingParams) (*ApiV2010SipAuthCallsCredentialListMapping, error) { path := "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/CredentialListMappings.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -59,7 +63,7 @@ func (c *ApiService) CreateSipAuthCallsCredentialListMapping(DomainSid string, p data.Set("CredentialListSid", *params.CredentialListSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -87,6 +91,9 @@ func (params *DeleteSipAuthCallsCredentialListMappingParams) SetPathAccountSid(P // Delete a credential list mapping from the requested domain func (c *ApiService) DeleteSipAuthCallsCredentialListMapping(DomainSid string, Sid string, params *DeleteSipAuthCallsCredentialListMappingParams) error { + return c.DeleteSipAuthCallsCredentialListMappingWithContext(context.TODO(), DomainSid, Sid, params) +} +func (c *ApiService) DeleteSipAuthCallsCredentialListMappingWithContext(ctx context.Context, DomainSid string, Sid string, params *DeleteSipAuthCallsCredentialListMappingParams) error { path := "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/CredentialListMappings/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -101,7 +108,7 @@ func (c *ApiService) DeleteSipAuthCallsCredentialListMapping(DomainSid string, S "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -124,6 +131,9 @@ func (params *FetchSipAuthCallsCredentialListMappingParams) SetPathAccountSid(Pa // Fetch a specific instance of a credential list mapping func (c *ApiService) FetchSipAuthCallsCredentialListMapping(DomainSid string, Sid string, params *FetchSipAuthCallsCredentialListMappingParams) (*ApiV2010SipAuthCallsCredentialListMapping, error) { + return c.FetchSipAuthCallsCredentialListMappingWithContext(context.TODO(), DomainSid, Sid, params) +} +func (c *ApiService) FetchSipAuthCallsCredentialListMappingWithContext(ctx context.Context, DomainSid string, Sid string, params *FetchSipAuthCallsCredentialListMappingParams) (*ApiV2010SipAuthCallsCredentialListMapping, error) { path := "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/CredentialListMappings/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -138,7 +148,7 @@ func (c *ApiService) FetchSipAuthCallsCredentialListMapping(DomainSid string, Si "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -178,6 +188,11 @@ func (params *ListSipAuthCallsCredentialListMappingParams) SetLimit(Limit int) * // Retrieve a single page of SipAuthCallsCredentialListMapping records from the API. Request is executed immediately. func (c *ApiService) PageSipAuthCallsCredentialListMapping(DomainSid string, params *ListSipAuthCallsCredentialListMappingParams, pageToken, pageNumber string) (*ListSipAuthCallsCredentialListMappingResponse, error) { + return c.PageSipAuthCallsCredentialListMappingWithContext(context.TODO(), DomainSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of SipAuthCallsCredentialListMapping records from the API. Request is executed immediately. +func (c *ApiService) PageSipAuthCallsCredentialListMappingWithContext(ctx context.Context, DomainSid string, params *ListSipAuthCallsCredentialListMappingParams, pageToken, pageNumber string) (*ListSipAuthCallsCredentialListMappingResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/CredentialListMappings.json" if params != nil && params.PathAccountSid != nil { @@ -203,7 +218,7 @@ func (c *ApiService) PageSipAuthCallsCredentialListMapping(DomainSid string, par data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -220,7 +235,12 @@ func (c *ApiService) PageSipAuthCallsCredentialListMapping(DomainSid string, par // Lists SipAuthCallsCredentialListMapping records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListSipAuthCallsCredentialListMapping(DomainSid string, params *ListSipAuthCallsCredentialListMappingParams) ([]ApiV2010SipAuthCallsCredentialListMapping, error) { - response, errors := c.StreamSipAuthCallsCredentialListMapping(DomainSid, params) + return c.ListSipAuthCallsCredentialListMappingWithContext(context.TODO(), DomainSid, params) +} + +// Lists SipAuthCallsCredentialListMapping records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListSipAuthCallsCredentialListMappingWithContext(ctx context.Context, DomainSid string, params *ListSipAuthCallsCredentialListMappingParams) ([]ApiV2010SipAuthCallsCredentialListMapping, error) { + response, errors := c.StreamSipAuthCallsCredentialListMappingWithContext(ctx, DomainSid, params) records := make([]ApiV2010SipAuthCallsCredentialListMapping, 0) for record := range response { @@ -236,6 +256,11 @@ func (c *ApiService) ListSipAuthCallsCredentialListMapping(DomainSid string, par // Streams SipAuthCallsCredentialListMapping records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamSipAuthCallsCredentialListMapping(DomainSid string, params *ListSipAuthCallsCredentialListMappingParams) (chan ApiV2010SipAuthCallsCredentialListMapping, chan error) { + return c.StreamSipAuthCallsCredentialListMappingWithContext(context.TODO(), DomainSid, params) +} + +// Streams SipAuthCallsCredentialListMapping records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamSipAuthCallsCredentialListMappingWithContext(ctx context.Context, DomainSid string, params *ListSipAuthCallsCredentialListMappingParams) (chan ApiV2010SipAuthCallsCredentialListMapping, chan error) { if params == nil { params = &ListSipAuthCallsCredentialListMappingParams{} } @@ -244,19 +269,19 @@ func (c *ApiService) StreamSipAuthCallsCredentialListMapping(DomainSid string, p recordChannel := make(chan ApiV2010SipAuthCallsCredentialListMapping, 1) errorChannel := make(chan error, 1) - response, err := c.PageSipAuthCallsCredentialListMapping(DomainSid, params, "", "") + response, err := c.PageSipAuthCallsCredentialListMappingWithContext(ctx, DomainSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSipAuthCallsCredentialListMapping(response, params, recordChannel, errorChannel) + go c.streamSipAuthCallsCredentialListMappingWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamSipAuthCallsCredentialListMapping(response *ListSipAuthCallsCredentialListMappingResponse, params *ListSipAuthCallsCredentialListMappingParams, recordChannel chan ApiV2010SipAuthCallsCredentialListMapping, errorChannel chan error) { +func (c *ApiService) streamSipAuthCallsCredentialListMappingWithContext(ctx context.Context, response *ListSipAuthCallsCredentialListMappingResponse, params *ListSipAuthCallsCredentialListMappingParams, recordChannel chan ApiV2010SipAuthCallsCredentialListMapping, errorChannel chan error) { curRecord := 1 for response != nil { @@ -271,7 +296,7 @@ func (c *ApiService) streamSipAuthCallsCredentialListMapping(response *ListSipAu } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSipAuthCallsCredentialListMappingResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListSipAuthCallsCredentialListMappingResponseWithContext) if err != nil { errorChannel <- err break @@ -286,11 +311,11 @@ func (c *ApiService) streamSipAuthCallsCredentialListMapping(response *ListSipAu close(errorChannel) } -func (c *ApiService) getNextListSipAuthCallsCredentialListMappingResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSipAuthCallsCredentialListMappingResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_sip_domains_auth_calls_ip_access_control_list_mappings.go b/rest/api/v2010/accounts_sip_domains_auth_calls_ip_access_control_list_mappings.go index 6f9c61a30..55fd386ef 100644 --- a/rest/api/v2010/accounts_sip_domains_auth_calls_ip_access_control_list_mappings.go +++ b/rest/api/v2010/accounts_sip_domains_auth_calls_ip_access_control_list_mappings.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -42,6 +43,9 @@ func (params *CreateSipAuthCallsIpAccessControlListMappingParams) SetIpAccessCon // Create a new IP Access Control List mapping func (c *ApiService) CreateSipAuthCallsIpAccessControlListMapping(DomainSid string, params *CreateSipAuthCallsIpAccessControlListMappingParams) (*ApiV2010SipAuthCallsIpAccessControlListMapping, error) { + return c.CreateSipAuthCallsIpAccessControlListMappingWithContext(context.TODO(), DomainSid, params) +} +func (c *ApiService) CreateSipAuthCallsIpAccessControlListMappingWithContext(ctx context.Context, DomainSid string, params *CreateSipAuthCallsIpAccessControlListMappingParams) (*ApiV2010SipAuthCallsIpAccessControlListMapping, error) { path := "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/IpAccessControlListMappings.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -59,7 +63,7 @@ func (c *ApiService) CreateSipAuthCallsIpAccessControlListMapping(DomainSid stri data.Set("IpAccessControlListSid", *params.IpAccessControlListSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -87,6 +91,9 @@ func (params *DeleteSipAuthCallsIpAccessControlListMappingParams) SetPathAccount // Delete an IP Access Control List mapping from the requested domain func (c *ApiService) DeleteSipAuthCallsIpAccessControlListMapping(DomainSid string, Sid string, params *DeleteSipAuthCallsIpAccessControlListMappingParams) error { + return c.DeleteSipAuthCallsIpAccessControlListMappingWithContext(context.TODO(), DomainSid, Sid, params) +} +func (c *ApiService) DeleteSipAuthCallsIpAccessControlListMappingWithContext(ctx context.Context, DomainSid string, Sid string, params *DeleteSipAuthCallsIpAccessControlListMappingParams) error { path := "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/IpAccessControlListMappings/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -101,7 +108,7 @@ func (c *ApiService) DeleteSipAuthCallsIpAccessControlListMapping(DomainSid stri "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -124,6 +131,9 @@ func (params *FetchSipAuthCallsIpAccessControlListMappingParams) SetPathAccountS // Fetch a specific instance of an IP Access Control List mapping func (c *ApiService) FetchSipAuthCallsIpAccessControlListMapping(DomainSid string, Sid string, params *FetchSipAuthCallsIpAccessControlListMappingParams) (*ApiV2010SipAuthCallsIpAccessControlListMapping, error) { + return c.FetchSipAuthCallsIpAccessControlListMappingWithContext(context.TODO(), DomainSid, Sid, params) +} +func (c *ApiService) FetchSipAuthCallsIpAccessControlListMappingWithContext(ctx context.Context, DomainSid string, Sid string, params *FetchSipAuthCallsIpAccessControlListMappingParams) (*ApiV2010SipAuthCallsIpAccessControlListMapping, error) { path := "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/IpAccessControlListMappings/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -138,7 +148,7 @@ func (c *ApiService) FetchSipAuthCallsIpAccessControlListMapping(DomainSid strin "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -178,6 +188,11 @@ func (params *ListSipAuthCallsIpAccessControlListMappingParams) SetLimit(Limit i // Retrieve a single page of SipAuthCallsIpAccessControlListMapping records from the API. Request is executed immediately. func (c *ApiService) PageSipAuthCallsIpAccessControlListMapping(DomainSid string, params *ListSipAuthCallsIpAccessControlListMappingParams, pageToken, pageNumber string) (*ListSipAuthCallsIpAccessControlListMappingResponse, error) { + return c.PageSipAuthCallsIpAccessControlListMappingWithContext(context.TODO(), DomainSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of SipAuthCallsIpAccessControlListMapping records from the API. Request is executed immediately. +func (c *ApiService) PageSipAuthCallsIpAccessControlListMappingWithContext(ctx context.Context, DomainSid string, params *ListSipAuthCallsIpAccessControlListMappingParams, pageToken, pageNumber string) (*ListSipAuthCallsIpAccessControlListMappingResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/IpAccessControlListMappings.json" if params != nil && params.PathAccountSid != nil { @@ -203,7 +218,7 @@ func (c *ApiService) PageSipAuthCallsIpAccessControlListMapping(DomainSid string data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -220,7 +235,12 @@ func (c *ApiService) PageSipAuthCallsIpAccessControlListMapping(DomainSid string // Lists SipAuthCallsIpAccessControlListMapping records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListSipAuthCallsIpAccessControlListMapping(DomainSid string, params *ListSipAuthCallsIpAccessControlListMappingParams) ([]ApiV2010SipAuthCallsIpAccessControlListMapping, error) { - response, errors := c.StreamSipAuthCallsIpAccessControlListMapping(DomainSid, params) + return c.ListSipAuthCallsIpAccessControlListMappingWithContext(context.TODO(), DomainSid, params) +} + +// Lists SipAuthCallsIpAccessControlListMapping records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListSipAuthCallsIpAccessControlListMappingWithContext(ctx context.Context, DomainSid string, params *ListSipAuthCallsIpAccessControlListMappingParams) ([]ApiV2010SipAuthCallsIpAccessControlListMapping, error) { + response, errors := c.StreamSipAuthCallsIpAccessControlListMappingWithContext(ctx, DomainSid, params) records := make([]ApiV2010SipAuthCallsIpAccessControlListMapping, 0) for record := range response { @@ -236,6 +256,11 @@ func (c *ApiService) ListSipAuthCallsIpAccessControlListMapping(DomainSid string // Streams SipAuthCallsIpAccessControlListMapping records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamSipAuthCallsIpAccessControlListMapping(DomainSid string, params *ListSipAuthCallsIpAccessControlListMappingParams) (chan ApiV2010SipAuthCallsIpAccessControlListMapping, chan error) { + return c.StreamSipAuthCallsIpAccessControlListMappingWithContext(context.TODO(), DomainSid, params) +} + +// Streams SipAuthCallsIpAccessControlListMapping records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamSipAuthCallsIpAccessControlListMappingWithContext(ctx context.Context, DomainSid string, params *ListSipAuthCallsIpAccessControlListMappingParams) (chan ApiV2010SipAuthCallsIpAccessControlListMapping, chan error) { if params == nil { params = &ListSipAuthCallsIpAccessControlListMappingParams{} } @@ -244,19 +269,19 @@ func (c *ApiService) StreamSipAuthCallsIpAccessControlListMapping(DomainSid stri recordChannel := make(chan ApiV2010SipAuthCallsIpAccessControlListMapping, 1) errorChannel := make(chan error, 1) - response, err := c.PageSipAuthCallsIpAccessControlListMapping(DomainSid, params, "", "") + response, err := c.PageSipAuthCallsIpAccessControlListMappingWithContext(ctx, DomainSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSipAuthCallsIpAccessControlListMapping(response, params, recordChannel, errorChannel) + go c.streamSipAuthCallsIpAccessControlListMappingWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamSipAuthCallsIpAccessControlListMapping(response *ListSipAuthCallsIpAccessControlListMappingResponse, params *ListSipAuthCallsIpAccessControlListMappingParams, recordChannel chan ApiV2010SipAuthCallsIpAccessControlListMapping, errorChannel chan error) { +func (c *ApiService) streamSipAuthCallsIpAccessControlListMappingWithContext(ctx context.Context, response *ListSipAuthCallsIpAccessControlListMappingResponse, params *ListSipAuthCallsIpAccessControlListMappingParams, recordChannel chan ApiV2010SipAuthCallsIpAccessControlListMapping, errorChannel chan error) { curRecord := 1 for response != nil { @@ -271,7 +296,7 @@ func (c *ApiService) streamSipAuthCallsIpAccessControlListMapping(response *List } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSipAuthCallsIpAccessControlListMappingResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListSipAuthCallsIpAccessControlListMappingResponseWithContext) if err != nil { errorChannel <- err break @@ -286,11 +311,11 @@ func (c *ApiService) streamSipAuthCallsIpAccessControlListMapping(response *List close(errorChannel) } -func (c *ApiService) getNextListSipAuthCallsIpAccessControlListMappingResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSipAuthCallsIpAccessControlListMappingResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_sip_domains_auth_registrations_credential_list_mappings.go b/rest/api/v2010/accounts_sip_domains_auth_registrations_credential_list_mappings.go index 7ffac8cd7..97c842840 100644 --- a/rest/api/v2010/accounts_sip_domains_auth_registrations_credential_list_mappings.go +++ b/rest/api/v2010/accounts_sip_domains_auth_registrations_credential_list_mappings.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -42,6 +43,9 @@ func (params *CreateSipAuthRegistrationsCredentialListMappingParams) SetCredenti // Create a new credential list mapping resource func (c *ApiService) CreateSipAuthRegistrationsCredentialListMapping(DomainSid string, params *CreateSipAuthRegistrationsCredentialListMappingParams) (*ApiV2010SipAuthRegistrationsCredentialListMapping, error) { + return c.CreateSipAuthRegistrationsCredentialListMappingWithContext(context.TODO(), DomainSid, params) +} +func (c *ApiService) CreateSipAuthRegistrationsCredentialListMappingWithContext(ctx context.Context, DomainSid string, params *CreateSipAuthRegistrationsCredentialListMappingParams) (*ApiV2010SipAuthRegistrationsCredentialListMapping, error) { path := "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Registrations/CredentialListMappings.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -59,7 +63,7 @@ func (c *ApiService) CreateSipAuthRegistrationsCredentialListMapping(DomainSid s data.Set("CredentialListSid", *params.CredentialListSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -87,6 +91,9 @@ func (params *DeleteSipAuthRegistrationsCredentialListMappingParams) SetPathAcco // Delete a credential list mapping from the requested domain func (c *ApiService) DeleteSipAuthRegistrationsCredentialListMapping(DomainSid string, Sid string, params *DeleteSipAuthRegistrationsCredentialListMappingParams) error { + return c.DeleteSipAuthRegistrationsCredentialListMappingWithContext(context.TODO(), DomainSid, Sid, params) +} +func (c *ApiService) DeleteSipAuthRegistrationsCredentialListMappingWithContext(ctx context.Context, DomainSid string, Sid string, params *DeleteSipAuthRegistrationsCredentialListMappingParams) error { path := "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Registrations/CredentialListMappings/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -101,7 +108,7 @@ func (c *ApiService) DeleteSipAuthRegistrationsCredentialListMapping(DomainSid s "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -124,6 +131,9 @@ func (params *FetchSipAuthRegistrationsCredentialListMappingParams) SetPathAccou // Fetch a specific instance of a credential list mapping func (c *ApiService) FetchSipAuthRegistrationsCredentialListMapping(DomainSid string, Sid string, params *FetchSipAuthRegistrationsCredentialListMappingParams) (*ApiV2010SipAuthRegistrationsCredentialListMapping, error) { + return c.FetchSipAuthRegistrationsCredentialListMappingWithContext(context.TODO(), DomainSid, Sid, params) +} +func (c *ApiService) FetchSipAuthRegistrationsCredentialListMappingWithContext(ctx context.Context, DomainSid string, Sid string, params *FetchSipAuthRegistrationsCredentialListMappingParams) (*ApiV2010SipAuthRegistrationsCredentialListMapping, error) { path := "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Registrations/CredentialListMappings/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -138,7 +148,7 @@ func (c *ApiService) FetchSipAuthRegistrationsCredentialListMapping(DomainSid st "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -178,6 +188,11 @@ func (params *ListSipAuthRegistrationsCredentialListMappingParams) SetLimit(Limi // Retrieve a single page of SipAuthRegistrationsCredentialListMapping records from the API. Request is executed immediately. func (c *ApiService) PageSipAuthRegistrationsCredentialListMapping(DomainSid string, params *ListSipAuthRegistrationsCredentialListMappingParams, pageToken, pageNumber string) (*ListSipAuthRegistrationsCredentialListMappingResponse, error) { + return c.PageSipAuthRegistrationsCredentialListMappingWithContext(context.TODO(), DomainSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of SipAuthRegistrationsCredentialListMapping records from the API. Request is executed immediately. +func (c *ApiService) PageSipAuthRegistrationsCredentialListMappingWithContext(ctx context.Context, DomainSid string, params *ListSipAuthRegistrationsCredentialListMappingParams, pageToken, pageNumber string) (*ListSipAuthRegistrationsCredentialListMappingResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Registrations/CredentialListMappings.json" if params != nil && params.PathAccountSid != nil { @@ -203,7 +218,7 @@ func (c *ApiService) PageSipAuthRegistrationsCredentialListMapping(DomainSid str data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -220,7 +235,12 @@ func (c *ApiService) PageSipAuthRegistrationsCredentialListMapping(DomainSid str // Lists SipAuthRegistrationsCredentialListMapping records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListSipAuthRegistrationsCredentialListMapping(DomainSid string, params *ListSipAuthRegistrationsCredentialListMappingParams) ([]ApiV2010SipAuthRegistrationsCredentialListMapping, error) { - response, errors := c.StreamSipAuthRegistrationsCredentialListMapping(DomainSid, params) + return c.ListSipAuthRegistrationsCredentialListMappingWithContext(context.TODO(), DomainSid, params) +} + +// Lists SipAuthRegistrationsCredentialListMapping records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListSipAuthRegistrationsCredentialListMappingWithContext(ctx context.Context, DomainSid string, params *ListSipAuthRegistrationsCredentialListMappingParams) ([]ApiV2010SipAuthRegistrationsCredentialListMapping, error) { + response, errors := c.StreamSipAuthRegistrationsCredentialListMappingWithContext(ctx, DomainSid, params) records := make([]ApiV2010SipAuthRegistrationsCredentialListMapping, 0) for record := range response { @@ -236,6 +256,11 @@ func (c *ApiService) ListSipAuthRegistrationsCredentialListMapping(DomainSid str // Streams SipAuthRegistrationsCredentialListMapping records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamSipAuthRegistrationsCredentialListMapping(DomainSid string, params *ListSipAuthRegistrationsCredentialListMappingParams) (chan ApiV2010SipAuthRegistrationsCredentialListMapping, chan error) { + return c.StreamSipAuthRegistrationsCredentialListMappingWithContext(context.TODO(), DomainSid, params) +} + +// Streams SipAuthRegistrationsCredentialListMapping records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamSipAuthRegistrationsCredentialListMappingWithContext(ctx context.Context, DomainSid string, params *ListSipAuthRegistrationsCredentialListMappingParams) (chan ApiV2010SipAuthRegistrationsCredentialListMapping, chan error) { if params == nil { params = &ListSipAuthRegistrationsCredentialListMappingParams{} } @@ -244,19 +269,19 @@ func (c *ApiService) StreamSipAuthRegistrationsCredentialListMapping(DomainSid s recordChannel := make(chan ApiV2010SipAuthRegistrationsCredentialListMapping, 1) errorChannel := make(chan error, 1) - response, err := c.PageSipAuthRegistrationsCredentialListMapping(DomainSid, params, "", "") + response, err := c.PageSipAuthRegistrationsCredentialListMappingWithContext(ctx, DomainSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSipAuthRegistrationsCredentialListMapping(response, params, recordChannel, errorChannel) + go c.streamSipAuthRegistrationsCredentialListMappingWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamSipAuthRegistrationsCredentialListMapping(response *ListSipAuthRegistrationsCredentialListMappingResponse, params *ListSipAuthRegistrationsCredentialListMappingParams, recordChannel chan ApiV2010SipAuthRegistrationsCredentialListMapping, errorChannel chan error) { +func (c *ApiService) streamSipAuthRegistrationsCredentialListMappingWithContext(ctx context.Context, response *ListSipAuthRegistrationsCredentialListMappingResponse, params *ListSipAuthRegistrationsCredentialListMappingParams, recordChannel chan ApiV2010SipAuthRegistrationsCredentialListMapping, errorChannel chan error) { curRecord := 1 for response != nil { @@ -271,7 +296,7 @@ func (c *ApiService) streamSipAuthRegistrationsCredentialListMapping(response *L } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSipAuthRegistrationsCredentialListMappingResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListSipAuthRegistrationsCredentialListMappingResponseWithContext) if err != nil { errorChannel <- err break @@ -286,11 +311,11 @@ func (c *ApiService) streamSipAuthRegistrationsCredentialListMapping(response *L close(errorChannel) } -func (c *ApiService) getNextListSipAuthRegistrationsCredentialListMappingResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSipAuthRegistrationsCredentialListMappingResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_sip_domains_credential_list_mappings.go b/rest/api/v2010/accounts_sip_domains_credential_list_mappings.go index e5d0f12da..6d6bbce9a 100644 --- a/rest/api/v2010/accounts_sip_domains_credential_list_mappings.go +++ b/rest/api/v2010/accounts_sip_domains_credential_list_mappings.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -42,6 +43,9 @@ func (params *CreateSipCredentialListMappingParams) SetCredentialListSid(Credent // Create a CredentialListMapping resource for an account. func (c *ApiService) CreateSipCredentialListMapping(DomainSid string, params *CreateSipCredentialListMappingParams) (*ApiV2010SipCredentialListMapping, error) { + return c.CreateSipCredentialListMappingWithContext(context.TODO(), DomainSid, params) +} +func (c *ApiService) CreateSipCredentialListMappingWithContext(ctx context.Context, DomainSid string, params *CreateSipCredentialListMappingParams) (*ApiV2010SipCredentialListMapping, error) { path := "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/CredentialListMappings.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -59,7 +63,7 @@ func (c *ApiService) CreateSipCredentialListMapping(DomainSid string, params *Cr data.Set("CredentialListSid", *params.CredentialListSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -87,6 +91,9 @@ func (params *DeleteSipCredentialListMappingParams) SetPathAccountSid(PathAccoun // Delete a CredentialListMapping resource from an account. func (c *ApiService) DeleteSipCredentialListMapping(DomainSid string, Sid string, params *DeleteSipCredentialListMappingParams) error { + return c.DeleteSipCredentialListMappingWithContext(context.TODO(), DomainSid, Sid, params) +} +func (c *ApiService) DeleteSipCredentialListMappingWithContext(ctx context.Context, DomainSid string, Sid string, params *DeleteSipCredentialListMappingParams) error { path := "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/CredentialListMappings/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -101,7 +108,7 @@ func (c *ApiService) DeleteSipCredentialListMapping(DomainSid string, Sid string "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -124,6 +131,9 @@ func (params *FetchSipCredentialListMappingParams) SetPathAccountSid(PathAccount // Fetch a single CredentialListMapping resource from an account. func (c *ApiService) FetchSipCredentialListMapping(DomainSid string, Sid string, params *FetchSipCredentialListMappingParams) (*ApiV2010SipCredentialListMapping, error) { + return c.FetchSipCredentialListMappingWithContext(context.TODO(), DomainSid, Sid, params) +} +func (c *ApiService) FetchSipCredentialListMappingWithContext(ctx context.Context, DomainSid string, Sid string, params *FetchSipCredentialListMappingParams) (*ApiV2010SipCredentialListMapping, error) { path := "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/CredentialListMappings/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -138,7 +148,7 @@ func (c *ApiService) FetchSipCredentialListMapping(DomainSid string, Sid string, "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -178,6 +188,11 @@ func (params *ListSipCredentialListMappingParams) SetLimit(Limit int) *ListSipCr // Retrieve a single page of SipCredentialListMapping records from the API. Request is executed immediately. func (c *ApiService) PageSipCredentialListMapping(DomainSid string, params *ListSipCredentialListMappingParams, pageToken, pageNumber string) (*ListSipCredentialListMappingResponse, error) { + return c.PageSipCredentialListMappingWithContext(context.TODO(), DomainSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of SipCredentialListMapping records from the API. Request is executed immediately. +func (c *ApiService) PageSipCredentialListMappingWithContext(ctx context.Context, DomainSid string, params *ListSipCredentialListMappingParams, pageToken, pageNumber string) (*ListSipCredentialListMappingResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/CredentialListMappings.json" if params != nil && params.PathAccountSid != nil { @@ -203,7 +218,7 @@ func (c *ApiService) PageSipCredentialListMapping(DomainSid string, params *List data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -220,7 +235,12 @@ func (c *ApiService) PageSipCredentialListMapping(DomainSid string, params *List // Lists SipCredentialListMapping records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListSipCredentialListMapping(DomainSid string, params *ListSipCredentialListMappingParams) ([]ApiV2010SipCredentialListMapping, error) { - response, errors := c.StreamSipCredentialListMapping(DomainSid, params) + return c.ListSipCredentialListMappingWithContext(context.TODO(), DomainSid, params) +} + +// Lists SipCredentialListMapping records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListSipCredentialListMappingWithContext(ctx context.Context, DomainSid string, params *ListSipCredentialListMappingParams) ([]ApiV2010SipCredentialListMapping, error) { + response, errors := c.StreamSipCredentialListMappingWithContext(ctx, DomainSid, params) records := make([]ApiV2010SipCredentialListMapping, 0) for record := range response { @@ -236,6 +256,11 @@ func (c *ApiService) ListSipCredentialListMapping(DomainSid string, params *List // Streams SipCredentialListMapping records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamSipCredentialListMapping(DomainSid string, params *ListSipCredentialListMappingParams) (chan ApiV2010SipCredentialListMapping, chan error) { + return c.StreamSipCredentialListMappingWithContext(context.TODO(), DomainSid, params) +} + +// Streams SipCredentialListMapping records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamSipCredentialListMappingWithContext(ctx context.Context, DomainSid string, params *ListSipCredentialListMappingParams) (chan ApiV2010SipCredentialListMapping, chan error) { if params == nil { params = &ListSipCredentialListMappingParams{} } @@ -244,19 +269,19 @@ func (c *ApiService) StreamSipCredentialListMapping(DomainSid string, params *Li recordChannel := make(chan ApiV2010SipCredentialListMapping, 1) errorChannel := make(chan error, 1) - response, err := c.PageSipCredentialListMapping(DomainSid, params, "", "") + response, err := c.PageSipCredentialListMappingWithContext(ctx, DomainSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSipCredentialListMapping(response, params, recordChannel, errorChannel) + go c.streamSipCredentialListMappingWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamSipCredentialListMapping(response *ListSipCredentialListMappingResponse, params *ListSipCredentialListMappingParams, recordChannel chan ApiV2010SipCredentialListMapping, errorChannel chan error) { +func (c *ApiService) streamSipCredentialListMappingWithContext(ctx context.Context, response *ListSipCredentialListMappingResponse, params *ListSipCredentialListMappingParams, recordChannel chan ApiV2010SipCredentialListMapping, errorChannel chan error) { curRecord := 1 for response != nil { @@ -271,7 +296,7 @@ func (c *ApiService) streamSipCredentialListMapping(response *ListSipCredentialL } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSipCredentialListMappingResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListSipCredentialListMappingResponseWithContext) if err != nil { errorChannel <- err break @@ -286,11 +311,11 @@ func (c *ApiService) streamSipCredentialListMapping(response *ListSipCredentialL close(errorChannel) } -func (c *ApiService) getNextListSipCredentialListMappingResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSipCredentialListMappingResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_sip_domains_ip_access_control_list_mappings.go b/rest/api/v2010/accounts_sip_domains_ip_access_control_list_mappings.go index c675dfdaf..7f630e1d2 100644 --- a/rest/api/v2010/accounts_sip_domains_ip_access_control_list_mappings.go +++ b/rest/api/v2010/accounts_sip_domains_ip_access_control_list_mappings.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -42,6 +43,9 @@ func (params *CreateSipIpAccessControlListMappingParams) SetIpAccessControlListS // Create a new IpAccessControlListMapping resource. func (c *ApiService) CreateSipIpAccessControlListMapping(DomainSid string, params *CreateSipIpAccessControlListMappingParams) (*ApiV2010SipIpAccessControlListMapping, error) { + return c.CreateSipIpAccessControlListMappingWithContext(context.TODO(), DomainSid, params) +} +func (c *ApiService) CreateSipIpAccessControlListMappingWithContext(ctx context.Context, DomainSid string, params *CreateSipIpAccessControlListMappingParams) (*ApiV2010SipIpAccessControlListMapping, error) { path := "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/IpAccessControlListMappings.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -59,7 +63,7 @@ func (c *ApiService) CreateSipIpAccessControlListMapping(DomainSid string, param data.Set("IpAccessControlListSid", *params.IpAccessControlListSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -87,6 +91,9 @@ func (params *DeleteSipIpAccessControlListMappingParams) SetPathAccountSid(PathA // Delete an IpAccessControlListMapping resource. func (c *ApiService) DeleteSipIpAccessControlListMapping(DomainSid string, Sid string, params *DeleteSipIpAccessControlListMappingParams) error { + return c.DeleteSipIpAccessControlListMappingWithContext(context.TODO(), DomainSid, Sid, params) +} +func (c *ApiService) DeleteSipIpAccessControlListMappingWithContext(ctx context.Context, DomainSid string, Sid string, params *DeleteSipIpAccessControlListMappingParams) error { path := "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/IpAccessControlListMappings/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -101,7 +108,7 @@ func (c *ApiService) DeleteSipIpAccessControlListMapping(DomainSid string, Sid s "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -124,6 +131,9 @@ func (params *FetchSipIpAccessControlListMappingParams) SetPathAccountSid(PathAc // Fetch an IpAccessControlListMapping resource. func (c *ApiService) FetchSipIpAccessControlListMapping(DomainSid string, Sid string, params *FetchSipIpAccessControlListMappingParams) (*ApiV2010SipIpAccessControlListMapping, error) { + return c.FetchSipIpAccessControlListMappingWithContext(context.TODO(), DomainSid, Sid, params) +} +func (c *ApiService) FetchSipIpAccessControlListMappingWithContext(ctx context.Context, DomainSid string, Sid string, params *FetchSipIpAccessControlListMappingParams) (*ApiV2010SipIpAccessControlListMapping, error) { path := "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/IpAccessControlListMappings/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -138,7 +148,7 @@ func (c *ApiService) FetchSipIpAccessControlListMapping(DomainSid string, Sid st "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -178,6 +188,11 @@ func (params *ListSipIpAccessControlListMappingParams) SetLimit(Limit int) *List // Retrieve a single page of SipIpAccessControlListMapping records from the API. Request is executed immediately. func (c *ApiService) PageSipIpAccessControlListMapping(DomainSid string, params *ListSipIpAccessControlListMappingParams, pageToken, pageNumber string) (*ListSipIpAccessControlListMappingResponse, error) { + return c.PageSipIpAccessControlListMappingWithContext(context.TODO(), DomainSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of SipIpAccessControlListMapping records from the API. Request is executed immediately. +func (c *ApiService) PageSipIpAccessControlListMappingWithContext(ctx context.Context, DomainSid string, params *ListSipIpAccessControlListMappingParams, pageToken, pageNumber string) (*ListSipIpAccessControlListMappingResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/IpAccessControlListMappings.json" if params != nil && params.PathAccountSid != nil { @@ -203,7 +218,7 @@ func (c *ApiService) PageSipIpAccessControlListMapping(DomainSid string, params data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -220,7 +235,12 @@ func (c *ApiService) PageSipIpAccessControlListMapping(DomainSid string, params // Lists SipIpAccessControlListMapping records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListSipIpAccessControlListMapping(DomainSid string, params *ListSipIpAccessControlListMappingParams) ([]ApiV2010SipIpAccessControlListMapping, error) { - response, errors := c.StreamSipIpAccessControlListMapping(DomainSid, params) + return c.ListSipIpAccessControlListMappingWithContext(context.TODO(), DomainSid, params) +} + +// Lists SipIpAccessControlListMapping records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListSipIpAccessControlListMappingWithContext(ctx context.Context, DomainSid string, params *ListSipIpAccessControlListMappingParams) ([]ApiV2010SipIpAccessControlListMapping, error) { + response, errors := c.StreamSipIpAccessControlListMappingWithContext(ctx, DomainSid, params) records := make([]ApiV2010SipIpAccessControlListMapping, 0) for record := range response { @@ -236,6 +256,11 @@ func (c *ApiService) ListSipIpAccessControlListMapping(DomainSid string, params // Streams SipIpAccessControlListMapping records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamSipIpAccessControlListMapping(DomainSid string, params *ListSipIpAccessControlListMappingParams) (chan ApiV2010SipIpAccessControlListMapping, chan error) { + return c.StreamSipIpAccessControlListMappingWithContext(context.TODO(), DomainSid, params) +} + +// Streams SipIpAccessControlListMapping records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamSipIpAccessControlListMappingWithContext(ctx context.Context, DomainSid string, params *ListSipIpAccessControlListMappingParams) (chan ApiV2010SipIpAccessControlListMapping, chan error) { if params == nil { params = &ListSipIpAccessControlListMappingParams{} } @@ -244,19 +269,19 @@ func (c *ApiService) StreamSipIpAccessControlListMapping(DomainSid string, param recordChannel := make(chan ApiV2010SipIpAccessControlListMapping, 1) errorChannel := make(chan error, 1) - response, err := c.PageSipIpAccessControlListMapping(DomainSid, params, "", "") + response, err := c.PageSipIpAccessControlListMappingWithContext(ctx, DomainSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSipIpAccessControlListMapping(response, params, recordChannel, errorChannel) + go c.streamSipIpAccessControlListMappingWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamSipIpAccessControlListMapping(response *ListSipIpAccessControlListMappingResponse, params *ListSipIpAccessControlListMappingParams, recordChannel chan ApiV2010SipIpAccessControlListMapping, errorChannel chan error) { +func (c *ApiService) streamSipIpAccessControlListMappingWithContext(ctx context.Context, response *ListSipIpAccessControlListMappingResponse, params *ListSipIpAccessControlListMappingParams, recordChannel chan ApiV2010SipIpAccessControlListMapping, errorChannel chan error) { curRecord := 1 for response != nil { @@ -271,7 +296,7 @@ func (c *ApiService) streamSipIpAccessControlListMapping(response *ListSipIpAcce } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSipIpAccessControlListMappingResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListSipIpAccessControlListMappingResponseWithContext) if err != nil { errorChannel <- err break @@ -286,11 +311,11 @@ func (c *ApiService) streamSipIpAccessControlListMapping(response *ListSipIpAcce close(errorChannel) } -func (c *ApiService) getNextListSipIpAccessControlListMappingResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSipIpAccessControlListMappingResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_sipip_access_control_lists.go b/rest/api/v2010/accounts_sipip_access_control_lists.go index b6400b249..660b64968 100644 --- a/rest/api/v2010/accounts_sipip_access_control_lists.go +++ b/rest/api/v2010/accounts_sipip_access_control_lists.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -42,6 +43,9 @@ func (params *CreateSipIpAccessControlListParams) SetFriendlyName(FriendlyName s // Create a new IpAccessControlList resource func (c *ApiService) CreateSipIpAccessControlList(params *CreateSipIpAccessControlListParams) (*ApiV2010SipIpAccessControlList, error) { + return c.CreateSipIpAccessControlListWithContext(context.TODO(), params) +} +func (c *ApiService) CreateSipIpAccessControlListWithContext(ctx context.Context, params *CreateSipIpAccessControlListParams) (*ApiV2010SipIpAccessControlList, error) { path := "/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -58,7 +62,7 @@ func (c *ApiService) CreateSipIpAccessControlList(params *CreateSipIpAccessContr data.Set("FriendlyName", *params.FriendlyName) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -86,6 +90,9 @@ func (params *DeleteSipIpAccessControlListParams) SetPathAccountSid(PathAccountS // Delete an IpAccessControlList from the requested account func (c *ApiService) DeleteSipIpAccessControlList(Sid string, params *DeleteSipIpAccessControlListParams) error { + return c.DeleteSipIpAccessControlListWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) DeleteSipIpAccessControlListWithContext(ctx context.Context, Sid string, params *DeleteSipIpAccessControlListParams) error { path := "/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -99,7 +106,7 @@ func (c *ApiService) DeleteSipIpAccessControlList(Sid string, params *DeleteSipI "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -122,6 +129,9 @@ func (params *FetchSipIpAccessControlListParams) SetPathAccountSid(PathAccountSi // Fetch a specific instance of an IpAccessControlList func (c *ApiService) FetchSipIpAccessControlList(Sid string, params *FetchSipIpAccessControlListParams) (*ApiV2010SipIpAccessControlList, error) { + return c.FetchSipIpAccessControlListWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) FetchSipIpAccessControlListWithContext(ctx context.Context, Sid string, params *FetchSipIpAccessControlListParams) (*ApiV2010SipIpAccessControlList, error) { path := "/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -135,7 +145,7 @@ func (c *ApiService) FetchSipIpAccessControlList(Sid string, params *FetchSipIpA "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -175,6 +185,11 @@ func (params *ListSipIpAccessControlListParams) SetLimit(Limit int) *ListSipIpAc // Retrieve a single page of SipIpAccessControlList records from the API. Request is executed immediately. func (c *ApiService) PageSipIpAccessControlList(params *ListSipIpAccessControlListParams, pageToken, pageNumber string) (*ListSipIpAccessControlListResponse, error) { + return c.PageSipIpAccessControlListWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of SipIpAccessControlList records from the API. Request is executed immediately. +func (c *ApiService) PageSipIpAccessControlListWithContext(ctx context.Context, params *ListSipIpAccessControlListParams, pageToken, pageNumber string) (*ListSipIpAccessControlListResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists.json" if params != nil && params.PathAccountSid != nil { @@ -199,7 +214,7 @@ func (c *ApiService) PageSipIpAccessControlList(params *ListSipIpAccessControlLi data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -216,7 +231,12 @@ func (c *ApiService) PageSipIpAccessControlList(params *ListSipIpAccessControlLi // Lists SipIpAccessControlList records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListSipIpAccessControlList(params *ListSipIpAccessControlListParams) ([]ApiV2010SipIpAccessControlList, error) { - response, errors := c.StreamSipIpAccessControlList(params) + return c.ListSipIpAccessControlListWithContext(context.TODO(), params) +} + +// Lists SipIpAccessControlList records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListSipIpAccessControlListWithContext(ctx context.Context, params *ListSipIpAccessControlListParams) ([]ApiV2010SipIpAccessControlList, error) { + response, errors := c.StreamSipIpAccessControlListWithContext(ctx, params) records := make([]ApiV2010SipIpAccessControlList, 0) for record := range response { @@ -232,6 +252,11 @@ func (c *ApiService) ListSipIpAccessControlList(params *ListSipIpAccessControlLi // Streams SipIpAccessControlList records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamSipIpAccessControlList(params *ListSipIpAccessControlListParams) (chan ApiV2010SipIpAccessControlList, chan error) { + return c.StreamSipIpAccessControlListWithContext(context.TODO(), params) +} + +// Streams SipIpAccessControlList records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamSipIpAccessControlListWithContext(ctx context.Context, params *ListSipIpAccessControlListParams) (chan ApiV2010SipIpAccessControlList, chan error) { if params == nil { params = &ListSipIpAccessControlListParams{} } @@ -240,19 +265,19 @@ func (c *ApiService) StreamSipIpAccessControlList(params *ListSipIpAccessControl recordChannel := make(chan ApiV2010SipIpAccessControlList, 1) errorChannel := make(chan error, 1) - response, err := c.PageSipIpAccessControlList(params, "", "") + response, err := c.PageSipIpAccessControlListWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSipIpAccessControlList(response, params, recordChannel, errorChannel) + go c.streamSipIpAccessControlListWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamSipIpAccessControlList(response *ListSipIpAccessControlListResponse, params *ListSipIpAccessControlListParams, recordChannel chan ApiV2010SipIpAccessControlList, errorChannel chan error) { +func (c *ApiService) streamSipIpAccessControlListWithContext(ctx context.Context, response *ListSipIpAccessControlListResponse, params *ListSipIpAccessControlListParams, recordChannel chan ApiV2010SipIpAccessControlList, errorChannel chan error) { curRecord := 1 for response != nil { @@ -267,7 +292,7 @@ func (c *ApiService) streamSipIpAccessControlList(response *ListSipIpAccessContr } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSipIpAccessControlListResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListSipIpAccessControlListResponseWithContext) if err != nil { errorChannel <- err break @@ -282,11 +307,11 @@ func (c *ApiService) streamSipIpAccessControlList(response *ListSipIpAccessContr close(errorChannel) } -func (c *ApiService) getNextListSipIpAccessControlListResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSipIpAccessControlListResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -319,6 +344,9 @@ func (params *UpdateSipIpAccessControlListParams) SetFriendlyName(FriendlyName s // Rename an IpAccessControlList func (c *ApiService) UpdateSipIpAccessControlList(Sid string, params *UpdateSipIpAccessControlListParams) (*ApiV2010SipIpAccessControlList, error) { + return c.UpdateSipIpAccessControlListWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateSipIpAccessControlListWithContext(ctx context.Context, Sid string, params *UpdateSipIpAccessControlListParams) (*ApiV2010SipIpAccessControlList, error) { path := "/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -336,7 +364,7 @@ func (c *ApiService) UpdateSipIpAccessControlList(Sid string, params *UpdateSipI data.Set("FriendlyName", *params.FriendlyName) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_sipip_access_control_lists_ip_addresses.go b/rest/api/v2010/accounts_sipip_access_control_lists_ip_addresses.go index 2317e9b17..1a0119ea3 100644 --- a/rest/api/v2010/accounts_sipip_access_control_lists_ip_addresses.go +++ b/rest/api/v2010/accounts_sipip_access_control_lists_ip_addresses.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -54,6 +55,9 @@ func (params *CreateSipIpAddressParams) SetCidrPrefixLength(CidrPrefixLength int // Create a new IpAddress resource. func (c *ApiService) CreateSipIpAddress(IpAccessControlListSid string, params *CreateSipIpAddressParams) (*ApiV2010SipIpAddress, error) { + return c.CreateSipIpAddressWithContext(context.TODO(), IpAccessControlListSid, params) +} +func (c *ApiService) CreateSipIpAddressWithContext(ctx context.Context, IpAccessControlListSid string, params *CreateSipIpAddressParams) (*ApiV2010SipIpAddress, error) { path := "/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{IpAccessControlListSid}/IpAddresses.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -77,7 +81,7 @@ func (c *ApiService) CreateSipIpAddress(IpAccessControlListSid string, params *C data.Set("CidrPrefixLength", fmt.Sprint(*params.CidrPrefixLength)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -105,6 +109,9 @@ func (params *DeleteSipIpAddressParams) SetPathAccountSid(PathAccountSid string) // Delete an IpAddress resource. func (c *ApiService) DeleteSipIpAddress(IpAccessControlListSid string, Sid string, params *DeleteSipIpAddressParams) error { + return c.DeleteSipIpAddressWithContext(context.TODO(), IpAccessControlListSid, Sid, params) +} +func (c *ApiService) DeleteSipIpAddressWithContext(ctx context.Context, IpAccessControlListSid string, Sid string, params *DeleteSipIpAddressParams) error { path := "/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{IpAccessControlListSid}/IpAddresses/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -119,7 +126,7 @@ func (c *ApiService) DeleteSipIpAddress(IpAccessControlListSid string, Sid strin "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -142,6 +149,9 @@ func (params *FetchSipIpAddressParams) SetPathAccountSid(PathAccountSid string) // Read one IpAddress resource. func (c *ApiService) FetchSipIpAddress(IpAccessControlListSid string, Sid string, params *FetchSipIpAddressParams) (*ApiV2010SipIpAddress, error) { + return c.FetchSipIpAddressWithContext(context.TODO(), IpAccessControlListSid, Sid, params) +} +func (c *ApiService) FetchSipIpAddressWithContext(ctx context.Context, IpAccessControlListSid string, Sid string, params *FetchSipIpAddressParams) (*ApiV2010SipIpAddress, error) { path := "/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{IpAccessControlListSid}/IpAddresses/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -156,7 +166,7 @@ func (c *ApiService) FetchSipIpAddress(IpAccessControlListSid string, Sid string "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -196,6 +206,11 @@ func (params *ListSipIpAddressParams) SetLimit(Limit int) *ListSipIpAddressParam // Retrieve a single page of SipIpAddress records from the API. Request is executed immediately. func (c *ApiService) PageSipIpAddress(IpAccessControlListSid string, params *ListSipIpAddressParams, pageToken, pageNumber string) (*ListSipIpAddressResponse, error) { + return c.PageSipIpAddressWithContext(context.TODO(), IpAccessControlListSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of SipIpAddress records from the API. Request is executed immediately. +func (c *ApiService) PageSipIpAddressWithContext(ctx context.Context, IpAccessControlListSid string, params *ListSipIpAddressParams, pageToken, pageNumber string) (*ListSipIpAddressResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{IpAccessControlListSid}/IpAddresses.json" if params != nil && params.PathAccountSid != nil { @@ -221,7 +236,7 @@ func (c *ApiService) PageSipIpAddress(IpAccessControlListSid string, params *Lis data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -238,7 +253,12 @@ func (c *ApiService) PageSipIpAddress(IpAccessControlListSid string, params *Lis // Lists SipIpAddress records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListSipIpAddress(IpAccessControlListSid string, params *ListSipIpAddressParams) ([]ApiV2010SipIpAddress, error) { - response, errors := c.StreamSipIpAddress(IpAccessControlListSid, params) + return c.ListSipIpAddressWithContext(context.TODO(), IpAccessControlListSid, params) +} + +// Lists SipIpAddress records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListSipIpAddressWithContext(ctx context.Context, IpAccessControlListSid string, params *ListSipIpAddressParams) ([]ApiV2010SipIpAddress, error) { + response, errors := c.StreamSipIpAddressWithContext(ctx, IpAccessControlListSid, params) records := make([]ApiV2010SipIpAddress, 0) for record := range response { @@ -254,6 +274,11 @@ func (c *ApiService) ListSipIpAddress(IpAccessControlListSid string, params *Lis // Streams SipIpAddress records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamSipIpAddress(IpAccessControlListSid string, params *ListSipIpAddressParams) (chan ApiV2010SipIpAddress, chan error) { + return c.StreamSipIpAddressWithContext(context.TODO(), IpAccessControlListSid, params) +} + +// Streams SipIpAddress records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamSipIpAddressWithContext(ctx context.Context, IpAccessControlListSid string, params *ListSipIpAddressParams) (chan ApiV2010SipIpAddress, chan error) { if params == nil { params = &ListSipIpAddressParams{} } @@ -262,19 +287,19 @@ func (c *ApiService) StreamSipIpAddress(IpAccessControlListSid string, params *L recordChannel := make(chan ApiV2010SipIpAddress, 1) errorChannel := make(chan error, 1) - response, err := c.PageSipIpAddress(IpAccessControlListSid, params, "", "") + response, err := c.PageSipIpAddressWithContext(ctx, IpAccessControlListSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSipIpAddress(response, params, recordChannel, errorChannel) + go c.streamSipIpAddressWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamSipIpAddress(response *ListSipIpAddressResponse, params *ListSipIpAddressParams, recordChannel chan ApiV2010SipIpAddress, errorChannel chan error) { +func (c *ApiService) streamSipIpAddressWithContext(ctx context.Context, response *ListSipIpAddressResponse, params *ListSipIpAddressParams, recordChannel chan ApiV2010SipIpAddress, errorChannel chan error) { curRecord := 1 for response != nil { @@ -289,7 +314,7 @@ func (c *ApiService) streamSipIpAddress(response *ListSipIpAddressResponse, para } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSipIpAddressResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListSipIpAddressResponseWithContext) if err != nil { errorChannel <- err break @@ -304,11 +329,11 @@ func (c *ApiService) streamSipIpAddress(response *ListSipIpAddressResponse, para close(errorChannel) } -func (c *ApiService) getNextListSipIpAddressResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSipIpAddressResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -353,6 +378,9 @@ func (params *UpdateSipIpAddressParams) SetCidrPrefixLength(CidrPrefixLength int // Update an IpAddress resource. func (c *ApiService) UpdateSipIpAddress(IpAccessControlListSid string, Sid string, params *UpdateSipIpAddressParams) (*ApiV2010SipIpAddress, error) { + return c.UpdateSipIpAddressWithContext(context.TODO(), IpAccessControlListSid, Sid, params) +} +func (c *ApiService) UpdateSipIpAddressWithContext(ctx context.Context, IpAccessControlListSid string, Sid string, params *UpdateSipIpAddressParams) (*ApiV2010SipIpAddress, error) { path := "/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{IpAccessControlListSid}/IpAddresses/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -377,7 +405,7 @@ func (c *ApiService) UpdateSipIpAddress(IpAccessControlListSid string, Sid strin data.Set("CidrPrefixLength", fmt.Sprint(*params.CidrPrefixLength)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_sms_short_codes.go b/rest/api/v2010/accounts_sms_short_codes.go index c0dc591c9..ce44bf1dd 100644 --- a/rest/api/v2010/accounts_sms_short_codes.go +++ b/rest/api/v2010/accounts_sms_short_codes.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -36,6 +37,9 @@ func (params *FetchShortCodeParams) SetPathAccountSid(PathAccountSid string) *Fe // Fetch an instance of a short code func (c *ApiService) FetchShortCode(Sid string, params *FetchShortCodeParams) (*ApiV2010ShortCode, error) { + return c.FetchShortCodeWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) FetchShortCodeWithContext(ctx context.Context, Sid string, params *FetchShortCodeParams) (*ApiV2010ShortCode, error) { path := "/2010-04-01/Accounts/{AccountSid}/SMS/ShortCodes/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -49,7 +53,7 @@ func (c *ApiService) FetchShortCode(Sid string, params *FetchShortCodeParams) (* "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -101,6 +105,11 @@ func (params *ListShortCodeParams) SetLimit(Limit int) *ListShortCodeParams { // Retrieve a single page of ShortCode records from the API. Request is executed immediately. func (c *ApiService) PageShortCode(params *ListShortCodeParams, pageToken, pageNumber string) (*ListShortCodeResponse, error) { + return c.PageShortCodeWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of ShortCode records from the API. Request is executed immediately. +func (c *ApiService) PageShortCodeWithContext(ctx context.Context, params *ListShortCodeParams, pageToken, pageNumber string) (*ListShortCodeResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/SMS/ShortCodes.json" if params != nil && params.PathAccountSid != nil { @@ -131,7 +140,7 @@ func (c *ApiService) PageShortCode(params *ListShortCodeParams, pageToken, pageN data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -148,7 +157,12 @@ func (c *ApiService) PageShortCode(params *ListShortCodeParams, pageToken, pageN // Lists ShortCode records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListShortCode(params *ListShortCodeParams) ([]ApiV2010ShortCode, error) { - response, errors := c.StreamShortCode(params) + return c.ListShortCodeWithContext(context.TODO(), params) +} + +// Lists ShortCode records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListShortCodeWithContext(ctx context.Context, params *ListShortCodeParams) ([]ApiV2010ShortCode, error) { + response, errors := c.StreamShortCodeWithContext(ctx, params) records := make([]ApiV2010ShortCode, 0) for record := range response { @@ -164,6 +178,11 @@ func (c *ApiService) ListShortCode(params *ListShortCodeParams) ([]ApiV2010Short // Streams ShortCode records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamShortCode(params *ListShortCodeParams) (chan ApiV2010ShortCode, chan error) { + return c.StreamShortCodeWithContext(context.TODO(), params) +} + +// Streams ShortCode records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamShortCodeWithContext(ctx context.Context, params *ListShortCodeParams) (chan ApiV2010ShortCode, chan error) { if params == nil { params = &ListShortCodeParams{} } @@ -172,19 +191,19 @@ func (c *ApiService) StreamShortCode(params *ListShortCodeParams) (chan ApiV2010 recordChannel := make(chan ApiV2010ShortCode, 1) errorChannel := make(chan error, 1) - response, err := c.PageShortCode(params, "", "") + response, err := c.PageShortCodeWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamShortCode(response, params, recordChannel, errorChannel) + go c.streamShortCodeWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamShortCode(response *ListShortCodeResponse, params *ListShortCodeParams, recordChannel chan ApiV2010ShortCode, errorChannel chan error) { +func (c *ApiService) streamShortCodeWithContext(ctx context.Context, response *ListShortCodeResponse, params *ListShortCodeParams, recordChannel chan ApiV2010ShortCode, errorChannel chan error) { curRecord := 1 for response != nil { @@ -199,7 +218,7 @@ func (c *ApiService) streamShortCode(response *ListShortCodeResponse, params *Li } } - record, err := client.GetNext(c.baseURL, response, c.getNextListShortCodeResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListShortCodeResponseWithContext) if err != nil { errorChannel <- err break @@ -214,11 +233,11 @@ func (c *ApiService) streamShortCode(response *ListShortCodeResponse, params *Li close(errorChannel) } -func (c *ApiService) getNextListShortCodeResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListShortCodeResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -281,6 +300,9 @@ func (params *UpdateShortCodeParams) SetSmsFallbackMethod(SmsFallbackMethod stri // Update a short code with the following parameters func (c *ApiService) UpdateShortCode(Sid string, params *UpdateShortCodeParams) (*ApiV2010ShortCode, error) { + return c.UpdateShortCodeWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateShortCodeWithContext(ctx context.Context, Sid string, params *UpdateShortCodeParams) (*ApiV2010ShortCode, error) { path := "/2010-04-01/Accounts/{AccountSid}/SMS/ShortCodes/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -313,7 +335,7 @@ func (c *ApiService) UpdateShortCode(Sid string, params *UpdateShortCodeParams) data.Set("SmsFallbackMethod", *params.SmsFallbackMethod) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_tokens.go b/rest/api/v2010/accounts_tokens.go index e55a22fa8..aae26510f 100644 --- a/rest/api/v2010/accounts_tokens.go +++ b/rest/api/v2010/accounts_tokens.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -40,6 +41,9 @@ func (params *CreateTokenParams) SetTtl(Ttl int) *CreateTokenParams { // Create a new token for ICE servers func (c *ApiService) CreateToken(params *CreateTokenParams) (*ApiV2010Token, error) { + return c.CreateTokenWithContext(context.TODO(), params) +} +func (c *ApiService) CreateTokenWithContext(ctx context.Context, params *CreateTokenParams) (*ApiV2010Token, error) { path := "/2010-04-01/Accounts/{AccountSid}/Tokens.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -56,7 +60,7 @@ func (c *ApiService) CreateToken(params *CreateTokenParams) (*ApiV2010Token, err data.Set("Ttl", fmt.Sprint(*params.Ttl)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_transcriptions.go b/rest/api/v2010/accounts_transcriptions.go index 208a4bf2d..5bee58e1e 100644 --- a/rest/api/v2010/accounts_transcriptions.go +++ b/rest/api/v2010/accounts_transcriptions.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -36,6 +37,9 @@ func (params *DeleteTranscriptionParams) SetPathAccountSid(PathAccountSid string // Delete a transcription from the account used to make the request func (c *ApiService) DeleteTranscription(Sid string, params *DeleteTranscriptionParams) error { + return c.DeleteTranscriptionWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) DeleteTranscriptionWithContext(ctx context.Context, Sid string, params *DeleteTranscriptionParams) error { path := "/2010-04-01/Accounts/{AccountSid}/Transcriptions/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -49,7 +53,7 @@ func (c *ApiService) DeleteTranscription(Sid string, params *DeleteTranscription "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -72,6 +76,9 @@ func (params *FetchTranscriptionParams) SetPathAccountSid(PathAccountSid string) // Fetch an instance of a Transcription func (c *ApiService) FetchTranscription(Sid string, params *FetchTranscriptionParams) (*ApiV2010Transcription, error) { + return c.FetchTranscriptionWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) FetchTranscriptionWithContext(ctx context.Context, Sid string, params *FetchTranscriptionParams) (*ApiV2010Transcription, error) { path := "/2010-04-01/Accounts/{AccountSid}/Transcriptions/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -85,7 +92,7 @@ func (c *ApiService) FetchTranscription(Sid string, params *FetchTranscriptionPa "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -125,6 +132,11 @@ func (params *ListTranscriptionParams) SetLimit(Limit int) *ListTranscriptionPar // Retrieve a single page of Transcription records from the API. Request is executed immediately. func (c *ApiService) PageTranscription(params *ListTranscriptionParams, pageToken, pageNumber string) (*ListTranscriptionResponse, error) { + return c.PageTranscriptionWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Transcription records from the API. Request is executed immediately. +func (c *ApiService) PageTranscriptionWithContext(ctx context.Context, params *ListTranscriptionParams, pageToken, pageNumber string) (*ListTranscriptionResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/Transcriptions.json" if params != nil && params.PathAccountSid != nil { @@ -149,7 +161,7 @@ func (c *ApiService) PageTranscription(params *ListTranscriptionParams, pageToke data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -166,7 +178,12 @@ func (c *ApiService) PageTranscription(params *ListTranscriptionParams, pageToke // Lists Transcription records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListTranscription(params *ListTranscriptionParams) ([]ApiV2010Transcription, error) { - response, errors := c.StreamTranscription(params) + return c.ListTranscriptionWithContext(context.TODO(), params) +} + +// Lists Transcription records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListTranscriptionWithContext(ctx context.Context, params *ListTranscriptionParams) ([]ApiV2010Transcription, error) { + response, errors := c.StreamTranscriptionWithContext(ctx, params) records := make([]ApiV2010Transcription, 0) for record := range response { @@ -182,6 +199,11 @@ func (c *ApiService) ListTranscription(params *ListTranscriptionParams) ([]ApiV2 // Streams Transcription records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamTranscription(params *ListTranscriptionParams) (chan ApiV2010Transcription, chan error) { + return c.StreamTranscriptionWithContext(context.TODO(), params) +} + +// Streams Transcription records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamTranscriptionWithContext(ctx context.Context, params *ListTranscriptionParams) (chan ApiV2010Transcription, chan error) { if params == nil { params = &ListTranscriptionParams{} } @@ -190,19 +212,19 @@ func (c *ApiService) StreamTranscription(params *ListTranscriptionParams) (chan recordChannel := make(chan ApiV2010Transcription, 1) errorChannel := make(chan error, 1) - response, err := c.PageTranscription(params, "", "") + response, err := c.PageTranscriptionWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamTranscription(response, params, recordChannel, errorChannel) + go c.streamTranscriptionWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamTranscription(response *ListTranscriptionResponse, params *ListTranscriptionParams, recordChannel chan ApiV2010Transcription, errorChannel chan error) { +func (c *ApiService) streamTranscriptionWithContext(ctx context.Context, response *ListTranscriptionResponse, params *ListTranscriptionParams, recordChannel chan ApiV2010Transcription, errorChannel chan error) { curRecord := 1 for response != nil { @@ -217,7 +239,7 @@ func (c *ApiService) streamTranscription(response *ListTranscriptionResponse, pa } } - record, err := client.GetNext(c.baseURL, response, c.getNextListTranscriptionResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListTranscriptionResponseWithContext) if err != nil { errorChannel <- err break @@ -232,11 +254,11 @@ func (c *ApiService) streamTranscription(response *ListTranscriptionResponse, pa close(errorChannel) } -func (c *ApiService) getNextListTranscriptionResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListTranscriptionResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_usage_records.go b/rest/api/v2010/accounts_usage_records.go index cec0a6832..87935b8db 100644 --- a/rest/api/v2010/accounts_usage_records.go +++ b/rest/api/v2010/accounts_usage_records.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -72,6 +73,11 @@ func (params *ListUsageRecordParams) SetLimit(Limit int) *ListUsageRecordParams // Retrieve a single page of UsageRecord records from the API. Request is executed immediately. func (c *ApiService) PageUsageRecord(params *ListUsageRecordParams, pageToken, pageNumber string) (*ListUsageRecordResponse, error) { + return c.PageUsageRecordWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of UsageRecord records from the API. Request is executed immediately. +func (c *ApiService) PageUsageRecordWithContext(ctx context.Context, params *ListUsageRecordParams, pageToken, pageNumber string) (*ListUsageRecordResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/Usage/Records.json" if params != nil && params.PathAccountSid != nil { @@ -108,7 +114,7 @@ func (c *ApiService) PageUsageRecord(params *ListUsageRecordParams, pageToken, p data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -125,7 +131,12 @@ func (c *ApiService) PageUsageRecord(params *ListUsageRecordParams, pageToken, p // Lists UsageRecord records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListUsageRecord(params *ListUsageRecordParams) ([]ApiV2010UsageRecord, error) { - response, errors := c.StreamUsageRecord(params) + return c.ListUsageRecordWithContext(context.TODO(), params) +} + +// Lists UsageRecord records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListUsageRecordWithContext(ctx context.Context, params *ListUsageRecordParams) ([]ApiV2010UsageRecord, error) { + response, errors := c.StreamUsageRecordWithContext(ctx, params) records := make([]ApiV2010UsageRecord, 0) for record := range response { @@ -141,6 +152,11 @@ func (c *ApiService) ListUsageRecord(params *ListUsageRecordParams) ([]ApiV2010U // Streams UsageRecord records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamUsageRecord(params *ListUsageRecordParams) (chan ApiV2010UsageRecord, chan error) { + return c.StreamUsageRecordWithContext(context.TODO(), params) +} + +// Streams UsageRecord records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamUsageRecordWithContext(ctx context.Context, params *ListUsageRecordParams) (chan ApiV2010UsageRecord, chan error) { if params == nil { params = &ListUsageRecordParams{} } @@ -149,19 +165,19 @@ func (c *ApiService) StreamUsageRecord(params *ListUsageRecordParams) (chan ApiV recordChannel := make(chan ApiV2010UsageRecord, 1) errorChannel := make(chan error, 1) - response, err := c.PageUsageRecord(params, "", "") + response, err := c.PageUsageRecordWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUsageRecord(response, params, recordChannel, errorChannel) + go c.streamUsageRecordWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamUsageRecord(response *ListUsageRecordResponse, params *ListUsageRecordParams, recordChannel chan ApiV2010UsageRecord, errorChannel chan error) { +func (c *ApiService) streamUsageRecordWithContext(ctx context.Context, response *ListUsageRecordResponse, params *ListUsageRecordParams, recordChannel chan ApiV2010UsageRecord, errorChannel chan error) { curRecord := 1 for response != nil { @@ -176,7 +192,7 @@ func (c *ApiService) streamUsageRecord(response *ListUsageRecordResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUsageRecordResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListUsageRecordResponseWithContext) if err != nil { errorChannel <- err break @@ -191,11 +207,11 @@ func (c *ApiService) streamUsageRecord(response *ListUsageRecordResponse, params close(errorChannel) } -func (c *ApiService) getNextListUsageRecordResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUsageRecordResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_usage_records_all_time.go b/rest/api/v2010/accounts_usage_records_all_time.go index 11e4d45ba..e461428b0 100644 --- a/rest/api/v2010/accounts_usage_records_all_time.go +++ b/rest/api/v2010/accounts_usage_records_all_time.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -72,6 +73,11 @@ func (params *ListUsageRecordAllTimeParams) SetLimit(Limit int) *ListUsageRecord // Retrieve a single page of UsageRecordAllTime records from the API. Request is executed immediately. func (c *ApiService) PageUsageRecordAllTime(params *ListUsageRecordAllTimeParams, pageToken, pageNumber string) (*ListUsageRecordAllTimeResponse, error) { + return c.PageUsageRecordAllTimeWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of UsageRecordAllTime records from the API. Request is executed immediately. +func (c *ApiService) PageUsageRecordAllTimeWithContext(ctx context.Context, params *ListUsageRecordAllTimeParams, pageToken, pageNumber string) (*ListUsageRecordAllTimeResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/Usage/Records/AllTime.json" if params != nil && params.PathAccountSid != nil { @@ -108,7 +114,7 @@ func (c *ApiService) PageUsageRecordAllTime(params *ListUsageRecordAllTimeParams data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -125,7 +131,12 @@ func (c *ApiService) PageUsageRecordAllTime(params *ListUsageRecordAllTimeParams // Lists UsageRecordAllTime records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListUsageRecordAllTime(params *ListUsageRecordAllTimeParams) ([]ApiV2010UsageRecordAllTime, error) { - response, errors := c.StreamUsageRecordAllTime(params) + return c.ListUsageRecordAllTimeWithContext(context.TODO(), params) +} + +// Lists UsageRecordAllTime records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListUsageRecordAllTimeWithContext(ctx context.Context, params *ListUsageRecordAllTimeParams) ([]ApiV2010UsageRecordAllTime, error) { + response, errors := c.StreamUsageRecordAllTimeWithContext(ctx, params) records := make([]ApiV2010UsageRecordAllTime, 0) for record := range response { @@ -141,6 +152,11 @@ func (c *ApiService) ListUsageRecordAllTime(params *ListUsageRecordAllTimeParams // Streams UsageRecordAllTime records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamUsageRecordAllTime(params *ListUsageRecordAllTimeParams) (chan ApiV2010UsageRecordAllTime, chan error) { + return c.StreamUsageRecordAllTimeWithContext(context.TODO(), params) +} + +// Streams UsageRecordAllTime records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamUsageRecordAllTimeWithContext(ctx context.Context, params *ListUsageRecordAllTimeParams) (chan ApiV2010UsageRecordAllTime, chan error) { if params == nil { params = &ListUsageRecordAllTimeParams{} } @@ -149,19 +165,19 @@ func (c *ApiService) StreamUsageRecordAllTime(params *ListUsageRecordAllTimePara recordChannel := make(chan ApiV2010UsageRecordAllTime, 1) errorChannel := make(chan error, 1) - response, err := c.PageUsageRecordAllTime(params, "", "") + response, err := c.PageUsageRecordAllTimeWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUsageRecordAllTime(response, params, recordChannel, errorChannel) + go c.streamUsageRecordAllTimeWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamUsageRecordAllTime(response *ListUsageRecordAllTimeResponse, params *ListUsageRecordAllTimeParams, recordChannel chan ApiV2010UsageRecordAllTime, errorChannel chan error) { +func (c *ApiService) streamUsageRecordAllTimeWithContext(ctx context.Context, response *ListUsageRecordAllTimeResponse, params *ListUsageRecordAllTimeParams, recordChannel chan ApiV2010UsageRecordAllTime, errorChannel chan error) { curRecord := 1 for response != nil { @@ -176,7 +192,7 @@ func (c *ApiService) streamUsageRecordAllTime(response *ListUsageRecordAllTimeRe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUsageRecordAllTimeResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListUsageRecordAllTimeResponseWithContext) if err != nil { errorChannel <- err break @@ -191,11 +207,11 @@ func (c *ApiService) streamUsageRecordAllTime(response *ListUsageRecordAllTimeRe close(errorChannel) } -func (c *ApiService) getNextListUsageRecordAllTimeResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUsageRecordAllTimeResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_usage_records_daily.go b/rest/api/v2010/accounts_usage_records_daily.go index 5f6b4a78d..1b1092f38 100644 --- a/rest/api/v2010/accounts_usage_records_daily.go +++ b/rest/api/v2010/accounts_usage_records_daily.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -72,6 +73,11 @@ func (params *ListUsageRecordDailyParams) SetLimit(Limit int) *ListUsageRecordDa // Retrieve a single page of UsageRecordDaily records from the API. Request is executed immediately. func (c *ApiService) PageUsageRecordDaily(params *ListUsageRecordDailyParams, pageToken, pageNumber string) (*ListUsageRecordDailyResponse, error) { + return c.PageUsageRecordDailyWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of UsageRecordDaily records from the API. Request is executed immediately. +func (c *ApiService) PageUsageRecordDailyWithContext(ctx context.Context, params *ListUsageRecordDailyParams, pageToken, pageNumber string) (*ListUsageRecordDailyResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/Usage/Records/Daily.json" if params != nil && params.PathAccountSid != nil { @@ -108,7 +114,7 @@ func (c *ApiService) PageUsageRecordDaily(params *ListUsageRecordDailyParams, pa data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -125,7 +131,12 @@ func (c *ApiService) PageUsageRecordDaily(params *ListUsageRecordDailyParams, pa // Lists UsageRecordDaily records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListUsageRecordDaily(params *ListUsageRecordDailyParams) ([]ApiV2010UsageRecordDaily, error) { - response, errors := c.StreamUsageRecordDaily(params) + return c.ListUsageRecordDailyWithContext(context.TODO(), params) +} + +// Lists UsageRecordDaily records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListUsageRecordDailyWithContext(ctx context.Context, params *ListUsageRecordDailyParams) ([]ApiV2010UsageRecordDaily, error) { + response, errors := c.StreamUsageRecordDailyWithContext(ctx, params) records := make([]ApiV2010UsageRecordDaily, 0) for record := range response { @@ -141,6 +152,11 @@ func (c *ApiService) ListUsageRecordDaily(params *ListUsageRecordDailyParams) ([ // Streams UsageRecordDaily records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamUsageRecordDaily(params *ListUsageRecordDailyParams) (chan ApiV2010UsageRecordDaily, chan error) { + return c.StreamUsageRecordDailyWithContext(context.TODO(), params) +} + +// Streams UsageRecordDaily records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamUsageRecordDailyWithContext(ctx context.Context, params *ListUsageRecordDailyParams) (chan ApiV2010UsageRecordDaily, chan error) { if params == nil { params = &ListUsageRecordDailyParams{} } @@ -149,19 +165,19 @@ func (c *ApiService) StreamUsageRecordDaily(params *ListUsageRecordDailyParams) recordChannel := make(chan ApiV2010UsageRecordDaily, 1) errorChannel := make(chan error, 1) - response, err := c.PageUsageRecordDaily(params, "", "") + response, err := c.PageUsageRecordDailyWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUsageRecordDaily(response, params, recordChannel, errorChannel) + go c.streamUsageRecordDailyWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamUsageRecordDaily(response *ListUsageRecordDailyResponse, params *ListUsageRecordDailyParams, recordChannel chan ApiV2010UsageRecordDaily, errorChannel chan error) { +func (c *ApiService) streamUsageRecordDailyWithContext(ctx context.Context, response *ListUsageRecordDailyResponse, params *ListUsageRecordDailyParams, recordChannel chan ApiV2010UsageRecordDaily, errorChannel chan error) { curRecord := 1 for response != nil { @@ -176,7 +192,7 @@ func (c *ApiService) streamUsageRecordDaily(response *ListUsageRecordDailyRespon } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUsageRecordDailyResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListUsageRecordDailyResponseWithContext) if err != nil { errorChannel <- err break @@ -191,11 +207,11 @@ func (c *ApiService) streamUsageRecordDaily(response *ListUsageRecordDailyRespon close(errorChannel) } -func (c *ApiService) getNextListUsageRecordDailyResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUsageRecordDailyResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_usage_records_last_month.go b/rest/api/v2010/accounts_usage_records_last_month.go index cdbe23af7..a345c0b9d 100644 --- a/rest/api/v2010/accounts_usage_records_last_month.go +++ b/rest/api/v2010/accounts_usage_records_last_month.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -72,6 +73,11 @@ func (params *ListUsageRecordLastMonthParams) SetLimit(Limit int) *ListUsageReco // Retrieve a single page of UsageRecordLastMonth records from the API. Request is executed immediately. func (c *ApiService) PageUsageRecordLastMonth(params *ListUsageRecordLastMonthParams, pageToken, pageNumber string) (*ListUsageRecordLastMonthResponse, error) { + return c.PageUsageRecordLastMonthWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of UsageRecordLastMonth records from the API. Request is executed immediately. +func (c *ApiService) PageUsageRecordLastMonthWithContext(ctx context.Context, params *ListUsageRecordLastMonthParams, pageToken, pageNumber string) (*ListUsageRecordLastMonthResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/Usage/Records/LastMonth.json" if params != nil && params.PathAccountSid != nil { @@ -108,7 +114,7 @@ func (c *ApiService) PageUsageRecordLastMonth(params *ListUsageRecordLastMonthPa data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -125,7 +131,12 @@ func (c *ApiService) PageUsageRecordLastMonth(params *ListUsageRecordLastMonthPa // Lists UsageRecordLastMonth records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListUsageRecordLastMonth(params *ListUsageRecordLastMonthParams) ([]ApiV2010UsageRecordLastMonth, error) { - response, errors := c.StreamUsageRecordLastMonth(params) + return c.ListUsageRecordLastMonthWithContext(context.TODO(), params) +} + +// Lists UsageRecordLastMonth records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListUsageRecordLastMonthWithContext(ctx context.Context, params *ListUsageRecordLastMonthParams) ([]ApiV2010UsageRecordLastMonth, error) { + response, errors := c.StreamUsageRecordLastMonthWithContext(ctx, params) records := make([]ApiV2010UsageRecordLastMonth, 0) for record := range response { @@ -141,6 +152,11 @@ func (c *ApiService) ListUsageRecordLastMonth(params *ListUsageRecordLastMonthPa // Streams UsageRecordLastMonth records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamUsageRecordLastMonth(params *ListUsageRecordLastMonthParams) (chan ApiV2010UsageRecordLastMonth, chan error) { + return c.StreamUsageRecordLastMonthWithContext(context.TODO(), params) +} + +// Streams UsageRecordLastMonth records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamUsageRecordLastMonthWithContext(ctx context.Context, params *ListUsageRecordLastMonthParams) (chan ApiV2010UsageRecordLastMonth, chan error) { if params == nil { params = &ListUsageRecordLastMonthParams{} } @@ -149,19 +165,19 @@ func (c *ApiService) StreamUsageRecordLastMonth(params *ListUsageRecordLastMonth recordChannel := make(chan ApiV2010UsageRecordLastMonth, 1) errorChannel := make(chan error, 1) - response, err := c.PageUsageRecordLastMonth(params, "", "") + response, err := c.PageUsageRecordLastMonthWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUsageRecordLastMonth(response, params, recordChannel, errorChannel) + go c.streamUsageRecordLastMonthWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamUsageRecordLastMonth(response *ListUsageRecordLastMonthResponse, params *ListUsageRecordLastMonthParams, recordChannel chan ApiV2010UsageRecordLastMonth, errorChannel chan error) { +func (c *ApiService) streamUsageRecordLastMonthWithContext(ctx context.Context, response *ListUsageRecordLastMonthResponse, params *ListUsageRecordLastMonthParams, recordChannel chan ApiV2010UsageRecordLastMonth, errorChannel chan error) { curRecord := 1 for response != nil { @@ -176,7 +192,7 @@ func (c *ApiService) streamUsageRecordLastMonth(response *ListUsageRecordLastMon } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUsageRecordLastMonthResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListUsageRecordLastMonthResponseWithContext) if err != nil { errorChannel <- err break @@ -191,11 +207,11 @@ func (c *ApiService) streamUsageRecordLastMonth(response *ListUsageRecordLastMon close(errorChannel) } -func (c *ApiService) getNextListUsageRecordLastMonthResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUsageRecordLastMonthResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_usage_records_monthly.go b/rest/api/v2010/accounts_usage_records_monthly.go index 869778943..d540a628d 100644 --- a/rest/api/v2010/accounts_usage_records_monthly.go +++ b/rest/api/v2010/accounts_usage_records_monthly.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -72,6 +73,11 @@ func (params *ListUsageRecordMonthlyParams) SetLimit(Limit int) *ListUsageRecord // Retrieve a single page of UsageRecordMonthly records from the API. Request is executed immediately. func (c *ApiService) PageUsageRecordMonthly(params *ListUsageRecordMonthlyParams, pageToken, pageNumber string) (*ListUsageRecordMonthlyResponse, error) { + return c.PageUsageRecordMonthlyWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of UsageRecordMonthly records from the API. Request is executed immediately. +func (c *ApiService) PageUsageRecordMonthlyWithContext(ctx context.Context, params *ListUsageRecordMonthlyParams, pageToken, pageNumber string) (*ListUsageRecordMonthlyResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/Usage/Records/Monthly.json" if params != nil && params.PathAccountSid != nil { @@ -108,7 +114,7 @@ func (c *ApiService) PageUsageRecordMonthly(params *ListUsageRecordMonthlyParams data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -125,7 +131,12 @@ func (c *ApiService) PageUsageRecordMonthly(params *ListUsageRecordMonthlyParams // Lists UsageRecordMonthly records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListUsageRecordMonthly(params *ListUsageRecordMonthlyParams) ([]ApiV2010UsageRecordMonthly, error) { - response, errors := c.StreamUsageRecordMonthly(params) + return c.ListUsageRecordMonthlyWithContext(context.TODO(), params) +} + +// Lists UsageRecordMonthly records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListUsageRecordMonthlyWithContext(ctx context.Context, params *ListUsageRecordMonthlyParams) ([]ApiV2010UsageRecordMonthly, error) { + response, errors := c.StreamUsageRecordMonthlyWithContext(ctx, params) records := make([]ApiV2010UsageRecordMonthly, 0) for record := range response { @@ -141,6 +152,11 @@ func (c *ApiService) ListUsageRecordMonthly(params *ListUsageRecordMonthlyParams // Streams UsageRecordMonthly records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamUsageRecordMonthly(params *ListUsageRecordMonthlyParams) (chan ApiV2010UsageRecordMonthly, chan error) { + return c.StreamUsageRecordMonthlyWithContext(context.TODO(), params) +} + +// Streams UsageRecordMonthly records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamUsageRecordMonthlyWithContext(ctx context.Context, params *ListUsageRecordMonthlyParams) (chan ApiV2010UsageRecordMonthly, chan error) { if params == nil { params = &ListUsageRecordMonthlyParams{} } @@ -149,19 +165,19 @@ func (c *ApiService) StreamUsageRecordMonthly(params *ListUsageRecordMonthlyPara recordChannel := make(chan ApiV2010UsageRecordMonthly, 1) errorChannel := make(chan error, 1) - response, err := c.PageUsageRecordMonthly(params, "", "") + response, err := c.PageUsageRecordMonthlyWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUsageRecordMonthly(response, params, recordChannel, errorChannel) + go c.streamUsageRecordMonthlyWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamUsageRecordMonthly(response *ListUsageRecordMonthlyResponse, params *ListUsageRecordMonthlyParams, recordChannel chan ApiV2010UsageRecordMonthly, errorChannel chan error) { +func (c *ApiService) streamUsageRecordMonthlyWithContext(ctx context.Context, response *ListUsageRecordMonthlyResponse, params *ListUsageRecordMonthlyParams, recordChannel chan ApiV2010UsageRecordMonthly, errorChannel chan error) { curRecord := 1 for response != nil { @@ -176,7 +192,7 @@ func (c *ApiService) streamUsageRecordMonthly(response *ListUsageRecordMonthlyRe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUsageRecordMonthlyResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListUsageRecordMonthlyResponseWithContext) if err != nil { errorChannel <- err break @@ -191,11 +207,11 @@ func (c *ApiService) streamUsageRecordMonthly(response *ListUsageRecordMonthlyRe close(errorChannel) } -func (c *ApiService) getNextListUsageRecordMonthlyResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUsageRecordMonthlyResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_usage_records_this_month.go b/rest/api/v2010/accounts_usage_records_this_month.go index 4dcf3afde..8f6981944 100644 --- a/rest/api/v2010/accounts_usage_records_this_month.go +++ b/rest/api/v2010/accounts_usage_records_this_month.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -72,6 +73,11 @@ func (params *ListUsageRecordThisMonthParams) SetLimit(Limit int) *ListUsageReco // Retrieve a single page of UsageRecordThisMonth records from the API. Request is executed immediately. func (c *ApiService) PageUsageRecordThisMonth(params *ListUsageRecordThisMonthParams, pageToken, pageNumber string) (*ListUsageRecordThisMonthResponse, error) { + return c.PageUsageRecordThisMonthWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of UsageRecordThisMonth records from the API. Request is executed immediately. +func (c *ApiService) PageUsageRecordThisMonthWithContext(ctx context.Context, params *ListUsageRecordThisMonthParams, pageToken, pageNumber string) (*ListUsageRecordThisMonthResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/Usage/Records/ThisMonth.json" if params != nil && params.PathAccountSid != nil { @@ -108,7 +114,7 @@ func (c *ApiService) PageUsageRecordThisMonth(params *ListUsageRecordThisMonthPa data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -125,7 +131,12 @@ func (c *ApiService) PageUsageRecordThisMonth(params *ListUsageRecordThisMonthPa // Lists UsageRecordThisMonth records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListUsageRecordThisMonth(params *ListUsageRecordThisMonthParams) ([]ApiV2010UsageRecordThisMonth, error) { - response, errors := c.StreamUsageRecordThisMonth(params) + return c.ListUsageRecordThisMonthWithContext(context.TODO(), params) +} + +// Lists UsageRecordThisMonth records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListUsageRecordThisMonthWithContext(ctx context.Context, params *ListUsageRecordThisMonthParams) ([]ApiV2010UsageRecordThisMonth, error) { + response, errors := c.StreamUsageRecordThisMonthWithContext(ctx, params) records := make([]ApiV2010UsageRecordThisMonth, 0) for record := range response { @@ -141,6 +152,11 @@ func (c *ApiService) ListUsageRecordThisMonth(params *ListUsageRecordThisMonthPa // Streams UsageRecordThisMonth records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamUsageRecordThisMonth(params *ListUsageRecordThisMonthParams) (chan ApiV2010UsageRecordThisMonth, chan error) { + return c.StreamUsageRecordThisMonthWithContext(context.TODO(), params) +} + +// Streams UsageRecordThisMonth records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamUsageRecordThisMonthWithContext(ctx context.Context, params *ListUsageRecordThisMonthParams) (chan ApiV2010UsageRecordThisMonth, chan error) { if params == nil { params = &ListUsageRecordThisMonthParams{} } @@ -149,19 +165,19 @@ func (c *ApiService) StreamUsageRecordThisMonth(params *ListUsageRecordThisMonth recordChannel := make(chan ApiV2010UsageRecordThisMonth, 1) errorChannel := make(chan error, 1) - response, err := c.PageUsageRecordThisMonth(params, "", "") + response, err := c.PageUsageRecordThisMonthWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUsageRecordThisMonth(response, params, recordChannel, errorChannel) + go c.streamUsageRecordThisMonthWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamUsageRecordThisMonth(response *ListUsageRecordThisMonthResponse, params *ListUsageRecordThisMonthParams, recordChannel chan ApiV2010UsageRecordThisMonth, errorChannel chan error) { +func (c *ApiService) streamUsageRecordThisMonthWithContext(ctx context.Context, response *ListUsageRecordThisMonthResponse, params *ListUsageRecordThisMonthParams, recordChannel chan ApiV2010UsageRecordThisMonth, errorChannel chan error) { curRecord := 1 for response != nil { @@ -176,7 +192,7 @@ func (c *ApiService) streamUsageRecordThisMonth(response *ListUsageRecordThisMon } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUsageRecordThisMonthResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListUsageRecordThisMonthResponseWithContext) if err != nil { errorChannel <- err break @@ -191,11 +207,11 @@ func (c *ApiService) streamUsageRecordThisMonth(response *ListUsageRecordThisMon close(errorChannel) } -func (c *ApiService) getNextListUsageRecordThisMonthResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUsageRecordThisMonthResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_usage_records_today.go b/rest/api/v2010/accounts_usage_records_today.go index 332cf0489..47b3b52e8 100644 --- a/rest/api/v2010/accounts_usage_records_today.go +++ b/rest/api/v2010/accounts_usage_records_today.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -72,6 +73,11 @@ func (params *ListUsageRecordTodayParams) SetLimit(Limit int) *ListUsageRecordTo // Retrieve a single page of UsageRecordToday records from the API. Request is executed immediately. func (c *ApiService) PageUsageRecordToday(params *ListUsageRecordTodayParams, pageToken, pageNumber string) (*ListUsageRecordTodayResponse, error) { + return c.PageUsageRecordTodayWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of UsageRecordToday records from the API. Request is executed immediately. +func (c *ApiService) PageUsageRecordTodayWithContext(ctx context.Context, params *ListUsageRecordTodayParams, pageToken, pageNumber string) (*ListUsageRecordTodayResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/Usage/Records/Today.json" if params != nil && params.PathAccountSid != nil { @@ -108,7 +114,7 @@ func (c *ApiService) PageUsageRecordToday(params *ListUsageRecordTodayParams, pa data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -125,7 +131,12 @@ func (c *ApiService) PageUsageRecordToday(params *ListUsageRecordTodayParams, pa // Lists UsageRecordToday records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListUsageRecordToday(params *ListUsageRecordTodayParams) ([]ApiV2010UsageRecordToday, error) { - response, errors := c.StreamUsageRecordToday(params) + return c.ListUsageRecordTodayWithContext(context.TODO(), params) +} + +// Lists UsageRecordToday records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListUsageRecordTodayWithContext(ctx context.Context, params *ListUsageRecordTodayParams) ([]ApiV2010UsageRecordToday, error) { + response, errors := c.StreamUsageRecordTodayWithContext(ctx, params) records := make([]ApiV2010UsageRecordToday, 0) for record := range response { @@ -141,6 +152,11 @@ func (c *ApiService) ListUsageRecordToday(params *ListUsageRecordTodayParams) ([ // Streams UsageRecordToday records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamUsageRecordToday(params *ListUsageRecordTodayParams) (chan ApiV2010UsageRecordToday, chan error) { + return c.StreamUsageRecordTodayWithContext(context.TODO(), params) +} + +// Streams UsageRecordToday records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamUsageRecordTodayWithContext(ctx context.Context, params *ListUsageRecordTodayParams) (chan ApiV2010UsageRecordToday, chan error) { if params == nil { params = &ListUsageRecordTodayParams{} } @@ -149,19 +165,19 @@ func (c *ApiService) StreamUsageRecordToday(params *ListUsageRecordTodayParams) recordChannel := make(chan ApiV2010UsageRecordToday, 1) errorChannel := make(chan error, 1) - response, err := c.PageUsageRecordToday(params, "", "") + response, err := c.PageUsageRecordTodayWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUsageRecordToday(response, params, recordChannel, errorChannel) + go c.streamUsageRecordTodayWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamUsageRecordToday(response *ListUsageRecordTodayResponse, params *ListUsageRecordTodayParams, recordChannel chan ApiV2010UsageRecordToday, errorChannel chan error) { +func (c *ApiService) streamUsageRecordTodayWithContext(ctx context.Context, response *ListUsageRecordTodayResponse, params *ListUsageRecordTodayParams, recordChannel chan ApiV2010UsageRecordToday, errorChannel chan error) { curRecord := 1 for response != nil { @@ -176,7 +192,7 @@ func (c *ApiService) streamUsageRecordToday(response *ListUsageRecordTodayRespon } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUsageRecordTodayResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListUsageRecordTodayResponseWithContext) if err != nil { errorChannel <- err break @@ -191,11 +207,11 @@ func (c *ApiService) streamUsageRecordToday(response *ListUsageRecordTodayRespon close(errorChannel) } -func (c *ApiService) getNextListUsageRecordTodayResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUsageRecordTodayResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_usage_records_yearly.go b/rest/api/v2010/accounts_usage_records_yearly.go index f00d35570..fd8e36dba 100644 --- a/rest/api/v2010/accounts_usage_records_yearly.go +++ b/rest/api/v2010/accounts_usage_records_yearly.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -72,6 +73,11 @@ func (params *ListUsageRecordYearlyParams) SetLimit(Limit int) *ListUsageRecordY // Retrieve a single page of UsageRecordYearly records from the API. Request is executed immediately. func (c *ApiService) PageUsageRecordYearly(params *ListUsageRecordYearlyParams, pageToken, pageNumber string) (*ListUsageRecordYearlyResponse, error) { + return c.PageUsageRecordYearlyWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of UsageRecordYearly records from the API. Request is executed immediately. +func (c *ApiService) PageUsageRecordYearlyWithContext(ctx context.Context, params *ListUsageRecordYearlyParams, pageToken, pageNumber string) (*ListUsageRecordYearlyResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/Usage/Records/Yearly.json" if params != nil && params.PathAccountSid != nil { @@ -108,7 +114,7 @@ func (c *ApiService) PageUsageRecordYearly(params *ListUsageRecordYearlyParams, data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -125,7 +131,12 @@ func (c *ApiService) PageUsageRecordYearly(params *ListUsageRecordYearlyParams, // Lists UsageRecordYearly records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListUsageRecordYearly(params *ListUsageRecordYearlyParams) ([]ApiV2010UsageRecordYearly, error) { - response, errors := c.StreamUsageRecordYearly(params) + return c.ListUsageRecordYearlyWithContext(context.TODO(), params) +} + +// Lists UsageRecordYearly records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListUsageRecordYearlyWithContext(ctx context.Context, params *ListUsageRecordYearlyParams) ([]ApiV2010UsageRecordYearly, error) { + response, errors := c.StreamUsageRecordYearlyWithContext(ctx, params) records := make([]ApiV2010UsageRecordYearly, 0) for record := range response { @@ -141,6 +152,11 @@ func (c *ApiService) ListUsageRecordYearly(params *ListUsageRecordYearlyParams) // Streams UsageRecordYearly records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamUsageRecordYearly(params *ListUsageRecordYearlyParams) (chan ApiV2010UsageRecordYearly, chan error) { + return c.StreamUsageRecordYearlyWithContext(context.TODO(), params) +} + +// Streams UsageRecordYearly records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamUsageRecordYearlyWithContext(ctx context.Context, params *ListUsageRecordYearlyParams) (chan ApiV2010UsageRecordYearly, chan error) { if params == nil { params = &ListUsageRecordYearlyParams{} } @@ -149,19 +165,19 @@ func (c *ApiService) StreamUsageRecordYearly(params *ListUsageRecordYearlyParams recordChannel := make(chan ApiV2010UsageRecordYearly, 1) errorChannel := make(chan error, 1) - response, err := c.PageUsageRecordYearly(params, "", "") + response, err := c.PageUsageRecordYearlyWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUsageRecordYearly(response, params, recordChannel, errorChannel) + go c.streamUsageRecordYearlyWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamUsageRecordYearly(response *ListUsageRecordYearlyResponse, params *ListUsageRecordYearlyParams, recordChannel chan ApiV2010UsageRecordYearly, errorChannel chan error) { +func (c *ApiService) streamUsageRecordYearlyWithContext(ctx context.Context, response *ListUsageRecordYearlyResponse, params *ListUsageRecordYearlyParams, recordChannel chan ApiV2010UsageRecordYearly, errorChannel chan error) { curRecord := 1 for response != nil { @@ -176,7 +192,7 @@ func (c *ApiService) streamUsageRecordYearly(response *ListUsageRecordYearlyResp } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUsageRecordYearlyResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListUsageRecordYearlyResponseWithContext) if err != nil { errorChannel <- err break @@ -191,11 +207,11 @@ func (c *ApiService) streamUsageRecordYearly(response *ListUsageRecordYearlyResp close(errorChannel) } -func (c *ApiService) getNextListUsageRecordYearlyResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUsageRecordYearlyResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_usage_records_yesterday.go b/rest/api/v2010/accounts_usage_records_yesterday.go index 340ec883d..61d370544 100644 --- a/rest/api/v2010/accounts_usage_records_yesterday.go +++ b/rest/api/v2010/accounts_usage_records_yesterday.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -72,6 +73,11 @@ func (params *ListUsageRecordYesterdayParams) SetLimit(Limit int) *ListUsageReco // Retrieve a single page of UsageRecordYesterday records from the API. Request is executed immediately. func (c *ApiService) PageUsageRecordYesterday(params *ListUsageRecordYesterdayParams, pageToken, pageNumber string) (*ListUsageRecordYesterdayResponse, error) { + return c.PageUsageRecordYesterdayWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of UsageRecordYesterday records from the API. Request is executed immediately. +func (c *ApiService) PageUsageRecordYesterdayWithContext(ctx context.Context, params *ListUsageRecordYesterdayParams, pageToken, pageNumber string) (*ListUsageRecordYesterdayResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/Usage/Records/Yesterday.json" if params != nil && params.PathAccountSid != nil { @@ -108,7 +114,7 @@ func (c *ApiService) PageUsageRecordYesterday(params *ListUsageRecordYesterdayPa data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -125,7 +131,12 @@ func (c *ApiService) PageUsageRecordYesterday(params *ListUsageRecordYesterdayPa // Lists UsageRecordYesterday records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListUsageRecordYesterday(params *ListUsageRecordYesterdayParams) ([]ApiV2010UsageRecordYesterday, error) { - response, errors := c.StreamUsageRecordYesterday(params) + return c.ListUsageRecordYesterdayWithContext(context.TODO(), params) +} + +// Lists UsageRecordYesterday records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListUsageRecordYesterdayWithContext(ctx context.Context, params *ListUsageRecordYesterdayParams) ([]ApiV2010UsageRecordYesterday, error) { + response, errors := c.StreamUsageRecordYesterdayWithContext(ctx, params) records := make([]ApiV2010UsageRecordYesterday, 0) for record := range response { @@ -141,6 +152,11 @@ func (c *ApiService) ListUsageRecordYesterday(params *ListUsageRecordYesterdayPa // Streams UsageRecordYesterday records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamUsageRecordYesterday(params *ListUsageRecordYesterdayParams) (chan ApiV2010UsageRecordYesterday, chan error) { + return c.StreamUsageRecordYesterdayWithContext(context.TODO(), params) +} + +// Streams UsageRecordYesterday records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamUsageRecordYesterdayWithContext(ctx context.Context, params *ListUsageRecordYesterdayParams) (chan ApiV2010UsageRecordYesterday, chan error) { if params == nil { params = &ListUsageRecordYesterdayParams{} } @@ -149,19 +165,19 @@ func (c *ApiService) StreamUsageRecordYesterday(params *ListUsageRecordYesterday recordChannel := make(chan ApiV2010UsageRecordYesterday, 1) errorChannel := make(chan error, 1) - response, err := c.PageUsageRecordYesterday(params, "", "") + response, err := c.PageUsageRecordYesterdayWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUsageRecordYesterday(response, params, recordChannel, errorChannel) + go c.streamUsageRecordYesterdayWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamUsageRecordYesterday(response *ListUsageRecordYesterdayResponse, params *ListUsageRecordYesterdayParams, recordChannel chan ApiV2010UsageRecordYesterday, errorChannel chan error) { +func (c *ApiService) streamUsageRecordYesterdayWithContext(ctx context.Context, response *ListUsageRecordYesterdayResponse, params *ListUsageRecordYesterdayParams, recordChannel chan ApiV2010UsageRecordYesterday, errorChannel chan error) { curRecord := 1 for response != nil { @@ -176,7 +192,7 @@ func (c *ApiService) streamUsageRecordYesterday(response *ListUsageRecordYesterd } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUsageRecordYesterdayResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListUsageRecordYesterdayResponseWithContext) if err != nil { errorChannel <- err break @@ -191,11 +207,11 @@ func (c *ApiService) streamUsageRecordYesterday(response *ListUsageRecordYesterd close(errorChannel) } -func (c *ApiService) getNextListUsageRecordYesterdayResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUsageRecordYesterdayResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_usage_triggers.go b/rest/api/v2010/accounts_usage_triggers.go index 935201793..b4d531579 100644 --- a/rest/api/v2010/accounts_usage_triggers.go +++ b/rest/api/v2010/accounts_usage_triggers.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -78,6 +79,9 @@ func (params *CreateUsageTriggerParams) SetTriggerBy(TriggerBy string) *CreateUs // Create a new UsageTrigger func (c *ApiService) CreateUsageTrigger(params *CreateUsageTriggerParams) (*ApiV2010UsageTrigger, error) { + return c.CreateUsageTriggerWithContext(context.TODO(), params) +} +func (c *ApiService) CreateUsageTriggerWithContext(ctx context.Context, params *CreateUsageTriggerParams) (*ApiV2010UsageTrigger, error) { path := "/2010-04-01/Accounts/{AccountSid}/Usage/Triggers.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -112,7 +116,7 @@ func (c *ApiService) CreateUsageTrigger(params *CreateUsageTriggerParams) (*ApiV data.Set("TriggerBy", fmt.Sprint(*params.TriggerBy)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -138,8 +142,10 @@ func (params *DeleteUsageTriggerParams) SetPathAccountSid(PathAccountSid string) return params } -// func (c *ApiService) DeleteUsageTrigger(Sid string, params *DeleteUsageTriggerParams) error { + return c.DeleteUsageTriggerWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) DeleteUsageTriggerWithContext(ctx context.Context, Sid string, params *DeleteUsageTriggerParams) error { path := "/2010-04-01/Accounts/{AccountSid}/Usage/Triggers/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -153,7 +159,7 @@ func (c *ApiService) DeleteUsageTrigger(Sid string, params *DeleteUsageTriggerPa "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -176,6 +182,9 @@ func (params *FetchUsageTriggerParams) SetPathAccountSid(PathAccountSid string) // Fetch and instance of a usage-trigger func (c *ApiService) FetchUsageTrigger(Sid string, params *FetchUsageTriggerParams) (*ApiV2010UsageTrigger, error) { + return c.FetchUsageTriggerWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) FetchUsageTriggerWithContext(ctx context.Context, Sid string, params *FetchUsageTriggerParams) (*ApiV2010UsageTrigger, error) { path := "/2010-04-01/Accounts/{AccountSid}/Usage/Triggers/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -189,7 +198,7 @@ func (c *ApiService) FetchUsageTrigger(Sid string, params *FetchUsageTriggerPara "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -247,6 +256,11 @@ func (params *ListUsageTriggerParams) SetLimit(Limit int) *ListUsageTriggerParam // Retrieve a single page of UsageTrigger records from the API. Request is executed immediately. func (c *ApiService) PageUsageTrigger(params *ListUsageTriggerParams, pageToken, pageNumber string) (*ListUsageTriggerResponse, error) { + return c.PageUsageTriggerWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of UsageTrigger records from the API. Request is executed immediately. +func (c *ApiService) PageUsageTriggerWithContext(ctx context.Context, params *ListUsageTriggerParams, pageToken, pageNumber string) (*ListUsageTriggerResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/Usage/Triggers.json" if params != nil && params.PathAccountSid != nil { @@ -280,7 +294,7 @@ func (c *ApiService) PageUsageTrigger(params *ListUsageTriggerParams, pageToken, data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -297,7 +311,12 @@ func (c *ApiService) PageUsageTrigger(params *ListUsageTriggerParams, pageToken, // Lists UsageTrigger records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListUsageTrigger(params *ListUsageTriggerParams) ([]ApiV2010UsageTrigger, error) { - response, errors := c.StreamUsageTrigger(params) + return c.ListUsageTriggerWithContext(context.TODO(), params) +} + +// Lists UsageTrigger records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListUsageTriggerWithContext(ctx context.Context, params *ListUsageTriggerParams) ([]ApiV2010UsageTrigger, error) { + response, errors := c.StreamUsageTriggerWithContext(ctx, params) records := make([]ApiV2010UsageTrigger, 0) for record := range response { @@ -313,6 +332,11 @@ func (c *ApiService) ListUsageTrigger(params *ListUsageTriggerParams) ([]ApiV201 // Streams UsageTrigger records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamUsageTrigger(params *ListUsageTriggerParams) (chan ApiV2010UsageTrigger, chan error) { + return c.StreamUsageTriggerWithContext(context.TODO(), params) +} + +// Streams UsageTrigger records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamUsageTriggerWithContext(ctx context.Context, params *ListUsageTriggerParams) (chan ApiV2010UsageTrigger, chan error) { if params == nil { params = &ListUsageTriggerParams{} } @@ -321,19 +345,19 @@ func (c *ApiService) StreamUsageTrigger(params *ListUsageTriggerParams) (chan Ap recordChannel := make(chan ApiV2010UsageTrigger, 1) errorChannel := make(chan error, 1) - response, err := c.PageUsageTrigger(params, "", "") + response, err := c.PageUsageTriggerWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUsageTrigger(response, params, recordChannel, errorChannel) + go c.streamUsageTriggerWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamUsageTrigger(response *ListUsageTriggerResponse, params *ListUsageTriggerParams, recordChannel chan ApiV2010UsageTrigger, errorChannel chan error) { +func (c *ApiService) streamUsageTriggerWithContext(ctx context.Context, response *ListUsageTriggerResponse, params *ListUsageTriggerParams, recordChannel chan ApiV2010UsageTrigger, errorChannel chan error) { curRecord := 1 for response != nil { @@ -348,7 +372,7 @@ func (c *ApiService) streamUsageTrigger(response *ListUsageTriggerResponse, para } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUsageTriggerResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListUsageTriggerResponseWithContext) if err != nil { errorChannel <- err break @@ -363,11 +387,11 @@ func (c *ApiService) streamUsageTrigger(response *ListUsageTriggerResponse, para close(errorChannel) } -func (c *ApiService) getNextListUsageTriggerResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUsageTriggerResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -412,6 +436,9 @@ func (params *UpdateUsageTriggerParams) SetFriendlyName(FriendlyName string) *Up // Update an instance of a usage trigger func (c *ApiService) UpdateUsageTrigger(Sid string, params *UpdateUsageTriggerParams) (*ApiV2010UsageTrigger, error) { + return c.UpdateUsageTriggerWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateUsageTriggerWithContext(ctx context.Context, Sid string, params *UpdateUsageTriggerParams) (*ApiV2010UsageTrigger, error) { path := "/2010-04-01/Accounts/{AccountSid}/Usage/Triggers/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -435,7 +462,7 @@ func (c *ApiService) UpdateUsageTrigger(Sid string, params *UpdateUsageTriggerPa data.Set("FriendlyName", *params.FriendlyName) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/api/v2010/api_service.go b/rest/api/v2010/api_service.go index c03145e47..0d74c08bb 100644 --- a/rest/api/v2010/api_service.go +++ b/rest/api/v2010/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://api.twilio.com", + } +} diff --git a/rest/assistants/v1/api_service.go b/rest/assistants/v1/api_service.go index ebd6453e8..4ce0f9814 100644 --- a/rest/assistants/v1/api_service.go +++ b/rest/assistants/v1/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://assistants.twilio.com", + } +} diff --git a/rest/assistants/v1/assistants.go b/rest/assistants/v1/assistants.go index f1c6e7e7e..556c404b3 100644 --- a/rest/assistants/v1/assistants.go +++ b/rest/assistants/v1/assistants.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -36,6 +37,9 @@ func (params *CreateAssistantParams) SetAssistantsV1CreateAssistantRequest(Assis // create an assistant func (c *ApiService) CreateAssistant(params *CreateAssistantParams) (*AssistantsV1Assistant, error) { + return c.CreateAssistantWithContext(context.TODO(), params) +} +func (c *ApiService) CreateAssistantWithContext(ctx context.Context, params *CreateAssistantParams) (*AssistantsV1Assistant, error) { path := "/v1/Assistants" data := url.Values{} @@ -52,7 +56,7 @@ func (c *ApiService) CreateAssistant(params *CreateAssistantParams) (*Assistants body = b } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers, body...) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers, body...) if err != nil { return nil, err } @@ -69,6 +73,9 @@ func (c *ApiService) CreateAssistant(params *CreateAssistantParams) (*Assistants // delete an assistant func (c *ApiService) DeleteAssistant(Id string) error { + return c.DeleteAssistantWithContext(context.TODO(), Id) +} +func (c *ApiService) DeleteAssistantWithContext(ctx context.Context, Id string) error { path := "/v1/Assistants/{id}" path = strings.Replace(path, "{"+"id"+"}", Id, -1) @@ -77,7 +84,7 @@ func (c *ApiService) DeleteAssistant(Id string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -89,6 +96,9 @@ func (c *ApiService) DeleteAssistant(Id string) error { // get an assistant func (c *ApiService) FetchAssistant(Id string) (*AssistantsV1AssistantWithToolsAndKnowledge, error) { + return c.FetchAssistantWithContext(context.TODO(), Id) +} +func (c *ApiService) FetchAssistantWithContext(ctx context.Context, Id string) (*AssistantsV1AssistantWithToolsAndKnowledge, error) { path := "/v1/Assistants/{id}" path = strings.Replace(path, "{"+"id"+"}", Id, -1) @@ -97,7 +107,7 @@ func (c *ApiService) FetchAssistant(Id string) (*AssistantsV1AssistantWithToolsA "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -131,6 +141,11 @@ func (params *ListAssistantsParams) SetLimit(Limit int) *ListAssistantsParams { // Retrieve a single page of Assistants records from the API. Request is executed immediately. func (c *ApiService) PageAssistants(params *ListAssistantsParams, pageToken, pageNumber string) (*ListAssistantResponse, error) { + return c.PageAssistantsWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Assistants records from the API. Request is executed immediately. +func (c *ApiService) PageAssistantsWithContext(ctx context.Context, params *ListAssistantsParams, pageToken, pageNumber string) (*ListAssistantResponse, error) { path := "/v1/Assistants" data := url.Values{} @@ -149,7 +164,7 @@ func (c *ApiService) PageAssistants(params *ListAssistantsParams, pageToken, pag data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -166,7 +181,12 @@ func (c *ApiService) PageAssistants(params *ListAssistantsParams, pageToken, pag // Lists Assistants records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListAssistants(params *ListAssistantsParams) ([]AssistantsV1Assistant, error) { - response, errors := c.StreamAssistants(params) + return c.ListAssistantsWithContext(context.TODO(), params) +} + +// Lists Assistants records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListAssistantsWithContext(ctx context.Context, params *ListAssistantsParams) ([]AssistantsV1Assistant, error) { + response, errors := c.StreamAssistantsWithContext(ctx, params) records := make([]AssistantsV1Assistant, 0) for record := range response { @@ -182,6 +202,11 @@ func (c *ApiService) ListAssistants(params *ListAssistantsParams) ([]AssistantsV // Streams Assistants records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamAssistants(params *ListAssistantsParams) (chan AssistantsV1Assistant, chan error) { + return c.StreamAssistantsWithContext(context.TODO(), params) +} + +// Streams Assistants records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamAssistantsWithContext(ctx context.Context, params *ListAssistantsParams) (chan AssistantsV1Assistant, chan error) { if params == nil { params = &ListAssistantsParams{} } @@ -190,19 +215,19 @@ func (c *ApiService) StreamAssistants(params *ListAssistantsParams) (chan Assist recordChannel := make(chan AssistantsV1Assistant, 1) errorChannel := make(chan error, 1) - response, err := c.PageAssistants(params, "", "") + response, err := c.PageAssistantsWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamAssistants(response, params, recordChannel, errorChannel) + go c.streamAssistantsWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamAssistants(response *ListAssistantResponse, params *ListAssistantsParams, recordChannel chan AssistantsV1Assistant, errorChannel chan error) { +func (c *ApiService) streamAssistantsWithContext(ctx context.Context, response *ListAssistantResponse, params *ListAssistantsParams, recordChannel chan AssistantsV1Assistant, errorChannel chan error) { curRecord := 1 for response != nil { @@ -217,7 +242,7 @@ func (c *ApiService) streamAssistants(response *ListAssistantResponse, params *L } } - record, err := client.GetNext(c.baseURL, response, c.getNextListAssistantResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListAssistantResponseWithContext) if err != nil { errorChannel <- err break @@ -232,11 +257,11 @@ func (c *ApiService) streamAssistants(response *ListAssistantResponse, params *L close(errorChannel) } -func (c *ApiService) getNextListAssistantResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListAssistantResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -263,6 +288,9 @@ func (params *UpdateAssistantParams) SetAssistantsV1UpdateAssistantRequest(Assis // update an assistant func (c *ApiService) UpdateAssistant(Id string, params *UpdateAssistantParams) (*AssistantsV1Assistant, error) { + return c.UpdateAssistantWithContext(context.TODO(), Id, params) +} +func (c *ApiService) UpdateAssistantWithContext(ctx context.Context, Id string, params *UpdateAssistantParams) (*AssistantsV1Assistant, error) { path := "/v1/Assistants/{id}" path = strings.Replace(path, "{"+"id"+"}", Id, -1) @@ -280,7 +308,7 @@ func (c *ApiService) UpdateAssistant(Id string, params *UpdateAssistantParams) ( body = b } - resp, err := c.requestHandler.Put(c.baseURL+path, data, headers, body...) + resp, err := c.requestHandler.PutWithContext(ctx, c.baseURL+path, data, headers, body...) if err != nil { return nil, err } diff --git a/rest/assistants/v1/assistants_feedbacks.go b/rest/assistants/v1/assistants_feedbacks.go index 79ff4a076..0dfe6e40b 100644 --- a/rest/assistants/v1/assistants_feedbacks.go +++ b/rest/assistants/v1/assistants_feedbacks.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -36,6 +37,9 @@ func (params *CreateFeedbackParams) SetAssistantsV1CreateFeedbackRequest(Assista // Create feedback func (c *ApiService) CreateFeedback(Id string, params *CreateFeedbackParams) (*AssistantsV1Feedback, error) { + return c.CreateFeedbackWithContext(context.TODO(), Id, params) +} +func (c *ApiService) CreateFeedbackWithContext(ctx context.Context, Id string, params *CreateFeedbackParams) (*AssistantsV1Feedback, error) { path := "/v1/Assistants/{id}/Feedbacks" path = strings.Replace(path, "{"+"id"+"}", Id, -1) @@ -53,7 +57,7 @@ func (c *ApiService) CreateFeedback(Id string, params *CreateFeedbackParams) (*A body = b } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers, body...) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers, body...) if err != nil { return nil, err } @@ -87,6 +91,11 @@ func (params *ListFeedbackParams) SetLimit(Limit int) *ListFeedbackParams { // Retrieve a single page of Feedback records from the API. Request is executed immediately. func (c *ApiService) PageFeedback(Id string, params *ListFeedbackParams, pageToken, pageNumber string) (*ListFeedbacksResponse, error) { + return c.PageFeedbackWithContext(context.TODO(), Id, params, pageToken, pageNumber) +} + +// Retrieve a single page of Feedback records from the API. Request is executed immediately. +func (c *ApiService) PageFeedbackWithContext(ctx context.Context, Id string, params *ListFeedbackParams, pageToken, pageNumber string) (*ListFeedbacksResponse, error) { path := "/v1/Assistants/{id}/Feedbacks" path = strings.Replace(path, "{"+"id"+"}", Id, -1) @@ -107,7 +116,7 @@ func (c *ApiService) PageFeedback(Id string, params *ListFeedbackParams, pageTok data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -124,7 +133,12 @@ func (c *ApiService) PageFeedback(Id string, params *ListFeedbackParams, pageTok // Lists Feedback records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListFeedback(Id string, params *ListFeedbackParams) ([]AssistantsV1Feedback, error) { - response, errors := c.StreamFeedback(Id, params) + return c.ListFeedbackWithContext(context.TODO(), Id, params) +} + +// Lists Feedback records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListFeedbackWithContext(ctx context.Context, Id string, params *ListFeedbackParams) ([]AssistantsV1Feedback, error) { + response, errors := c.StreamFeedbackWithContext(ctx, Id, params) records := make([]AssistantsV1Feedback, 0) for record := range response { @@ -140,6 +154,11 @@ func (c *ApiService) ListFeedback(Id string, params *ListFeedbackParams) ([]Assi // Streams Feedback records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamFeedback(Id string, params *ListFeedbackParams) (chan AssistantsV1Feedback, chan error) { + return c.StreamFeedbackWithContext(context.TODO(), Id, params) +} + +// Streams Feedback records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamFeedbackWithContext(ctx context.Context, Id string, params *ListFeedbackParams) (chan AssistantsV1Feedback, chan error) { if params == nil { params = &ListFeedbackParams{} } @@ -148,19 +167,19 @@ func (c *ApiService) StreamFeedback(Id string, params *ListFeedbackParams) (chan recordChannel := make(chan AssistantsV1Feedback, 1) errorChannel := make(chan error, 1) - response, err := c.PageFeedback(Id, params, "", "") + response, err := c.PageFeedbackWithContext(ctx, Id, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamFeedback(response, params, recordChannel, errorChannel) + go c.streamFeedbackWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamFeedback(response *ListFeedbacksResponse, params *ListFeedbackParams, recordChannel chan AssistantsV1Feedback, errorChannel chan error) { +func (c *ApiService) streamFeedbackWithContext(ctx context.Context, response *ListFeedbacksResponse, params *ListFeedbackParams, recordChannel chan AssistantsV1Feedback, errorChannel chan error) { curRecord := 1 for response != nil { @@ -175,7 +194,7 @@ func (c *ApiService) streamFeedback(response *ListFeedbacksResponse, params *Lis } } - record, err := client.GetNext(c.baseURL, response, c.getNextListFeedbacksResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListFeedbacksResponseWithContext) if err != nil { errorChannel <- err break @@ -190,11 +209,11 @@ func (c *ApiService) streamFeedback(response *ListFeedbacksResponse, params *Lis close(errorChannel) } -func (c *ApiService) getNextListFeedbacksResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListFeedbacksResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/assistants/v1/assistants_knowledge.go b/rest/assistants/v1/assistants_knowledge.go index 3b0432ee5..5d43431af 100644 --- a/rest/assistants/v1/assistants_knowledge.go +++ b/rest/assistants/v1/assistants_knowledge.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -25,6 +26,9 @@ import ( // Attach Knowledge to Assistant func (c *ApiService) CreateAssistantKnowledgeAttachment(AssistantId string, Id string) error { + return c.CreateAssistantKnowledgeAttachmentWithContext(context.TODO(), AssistantId, Id) +} +func (c *ApiService) CreateAssistantKnowledgeAttachmentWithContext(ctx context.Context, AssistantId string, Id string) error { path := "/v1/Assistants/{assistantId}/Knowledge/{id}" path = strings.Replace(path, "{"+"assistantId"+"}", AssistantId, -1) path = strings.Replace(path, "{"+"id"+"}", Id, -1) @@ -34,7 +38,7 @@ func (c *ApiService) CreateAssistantKnowledgeAttachment(AssistantId string, Id s "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -46,6 +50,9 @@ func (c *ApiService) CreateAssistantKnowledgeAttachment(AssistantId string, Id s // Detach Knowledge to Assistant func (c *ApiService) DeleteAssistantKnowledgeAttachment(AssistantId string, Id string) error { + return c.DeleteAssistantKnowledgeAttachmentWithContext(context.TODO(), AssistantId, Id) +} +func (c *ApiService) DeleteAssistantKnowledgeAttachmentWithContext(ctx context.Context, AssistantId string, Id string) error { path := "/v1/Assistants/{assistantId}/Knowledge/{id}" path = strings.Replace(path, "{"+"assistantId"+"}", AssistantId, -1) path = strings.Replace(path, "{"+"id"+"}", Id, -1) @@ -55,7 +62,7 @@ func (c *ApiService) DeleteAssistantKnowledgeAttachment(AssistantId string, Id s "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -84,6 +91,11 @@ func (params *ListKnowledgeByAssistantParams) SetLimit(Limit int) *ListKnowledge // Retrieve a single page of KnowledgeByAssistant records from the API. Request is executed immediately. func (c *ApiService) PageKnowledgeByAssistant(AssistantId string, params *ListKnowledgeByAssistantParams, pageToken, pageNumber string) (*ListKnowledgeByAssistantResponse, error) { + return c.PageKnowledgeByAssistantWithContext(context.TODO(), AssistantId, params, pageToken, pageNumber) +} + +// Retrieve a single page of KnowledgeByAssistant records from the API. Request is executed immediately. +func (c *ApiService) PageKnowledgeByAssistantWithContext(ctx context.Context, AssistantId string, params *ListKnowledgeByAssistantParams, pageToken, pageNumber string) (*ListKnowledgeByAssistantResponse, error) { path := "/v1/Assistants/{assistantId}/Knowledge" path = strings.Replace(path, "{"+"assistantId"+"}", AssistantId, -1) @@ -104,7 +116,7 @@ func (c *ApiService) PageKnowledgeByAssistant(AssistantId string, params *ListKn data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -121,7 +133,12 @@ func (c *ApiService) PageKnowledgeByAssistant(AssistantId string, params *ListKn // Lists KnowledgeByAssistant records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListKnowledgeByAssistant(AssistantId string, params *ListKnowledgeByAssistantParams) ([]AssistantsV1Knowledge, error) { - response, errors := c.StreamKnowledgeByAssistant(AssistantId, params) + return c.ListKnowledgeByAssistantWithContext(context.TODO(), AssistantId, params) +} + +// Lists KnowledgeByAssistant records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListKnowledgeByAssistantWithContext(ctx context.Context, AssistantId string, params *ListKnowledgeByAssistantParams) ([]AssistantsV1Knowledge, error) { + response, errors := c.StreamKnowledgeByAssistantWithContext(ctx, AssistantId, params) records := make([]AssistantsV1Knowledge, 0) for record := range response { @@ -137,6 +154,11 @@ func (c *ApiService) ListKnowledgeByAssistant(AssistantId string, params *ListKn // Streams KnowledgeByAssistant records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamKnowledgeByAssistant(AssistantId string, params *ListKnowledgeByAssistantParams) (chan AssistantsV1Knowledge, chan error) { + return c.StreamKnowledgeByAssistantWithContext(context.TODO(), AssistantId, params) +} + +// Streams KnowledgeByAssistant records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamKnowledgeByAssistantWithContext(ctx context.Context, AssistantId string, params *ListKnowledgeByAssistantParams) (chan AssistantsV1Knowledge, chan error) { if params == nil { params = &ListKnowledgeByAssistantParams{} } @@ -145,19 +167,19 @@ func (c *ApiService) StreamKnowledgeByAssistant(AssistantId string, params *List recordChannel := make(chan AssistantsV1Knowledge, 1) errorChannel := make(chan error, 1) - response, err := c.PageKnowledgeByAssistant(AssistantId, params, "", "") + response, err := c.PageKnowledgeByAssistantWithContext(ctx, AssistantId, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamKnowledgeByAssistant(response, params, recordChannel, errorChannel) + go c.streamKnowledgeByAssistantWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamKnowledgeByAssistant(response *ListKnowledgeByAssistantResponse, params *ListKnowledgeByAssistantParams, recordChannel chan AssistantsV1Knowledge, errorChannel chan error) { +func (c *ApiService) streamKnowledgeByAssistantWithContext(ctx context.Context, response *ListKnowledgeByAssistantResponse, params *ListKnowledgeByAssistantParams, recordChannel chan AssistantsV1Knowledge, errorChannel chan error) { curRecord := 1 for response != nil { @@ -172,7 +194,7 @@ func (c *ApiService) streamKnowledgeByAssistant(response *ListKnowledgeByAssista } } - record, err := client.GetNext(c.baseURL, response, c.getNextListKnowledgeByAssistantResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListKnowledgeByAssistantResponseWithContext) if err != nil { errorChannel <- err break @@ -187,11 +209,11 @@ func (c *ApiService) streamKnowledgeByAssistant(response *ListKnowledgeByAssista close(errorChannel) } -func (c *ApiService) getNextListKnowledgeByAssistantResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListKnowledgeByAssistantResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/assistants/v1/assistants_messages.go b/rest/assistants/v1/assistants_messages.go index 9bc73db23..ee8cd525a 100644 --- a/rest/assistants/v1/assistants_messages.go +++ b/rest/assistants/v1/assistants_messages.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -33,6 +34,9 @@ func (params *CreateMessageParams) SetAssistantsV1AssistantSendMessageRequest(As // send a message func (c *ApiService) CreateMessage(Id string, params *CreateMessageParams) (*AssistantsV1AssistantSendMessageResponse, error) { + return c.CreateMessageWithContext(context.TODO(), Id, params) +} +func (c *ApiService) CreateMessageWithContext(ctx context.Context, Id string, params *CreateMessageParams) (*AssistantsV1AssistantSendMessageResponse, error) { path := "/v1/Assistants/{id}/Messages" path = strings.Replace(path, "{"+"id"+"}", Id, -1) @@ -50,7 +54,7 @@ func (c *ApiService) CreateMessage(Id string, params *CreateMessageParams) (*Ass body = b } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers, body...) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers, body...) if err != nil { return nil, err } diff --git a/rest/assistants/v1/assistants_tools.go b/rest/assistants/v1/assistants_tools.go index dee781660..7dffec324 100644 --- a/rest/assistants/v1/assistants_tools.go +++ b/rest/assistants/v1/assistants_tools.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -25,6 +26,9 @@ import ( // Attach Tool to Assistant func (c *ApiService) CreateAssistantToolAttachment(AssistantId string, Id string) error { + return c.CreateAssistantToolAttachmentWithContext(context.TODO(), AssistantId, Id) +} +func (c *ApiService) CreateAssistantToolAttachmentWithContext(ctx context.Context, AssistantId string, Id string) error { path := "/v1/Assistants/{assistantId}/Tools/{id}" path = strings.Replace(path, "{"+"assistantId"+"}", AssistantId, -1) path = strings.Replace(path, "{"+"id"+"}", Id, -1) @@ -34,7 +38,7 @@ func (c *ApiService) CreateAssistantToolAttachment(AssistantId string, Id string "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -46,6 +50,9 @@ func (c *ApiService) CreateAssistantToolAttachment(AssistantId string, Id string // Detach Tool to Assistant func (c *ApiService) DeleteAssistantToolAttachment(AssistantId string, Id string) error { + return c.DeleteAssistantToolAttachmentWithContext(context.TODO(), AssistantId, Id) +} +func (c *ApiService) DeleteAssistantToolAttachmentWithContext(ctx context.Context, AssistantId string, Id string) error { path := "/v1/Assistants/{assistantId}/Tools/{id}" path = strings.Replace(path, "{"+"assistantId"+"}", AssistantId, -1) path = strings.Replace(path, "{"+"id"+"}", Id, -1) @@ -55,7 +62,7 @@ func (c *ApiService) DeleteAssistantToolAttachment(AssistantId string, Id string "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -84,6 +91,11 @@ func (params *ListToolsByAssistantParams) SetLimit(Limit int) *ListToolsByAssist // Retrieve a single page of ToolsByAssistant records from the API. Request is executed immediately. func (c *ApiService) PageToolsByAssistant(AssistantId string, params *ListToolsByAssistantParams, pageToken, pageNumber string) (*ListToolsByAssistantResponse, error) { + return c.PageToolsByAssistantWithContext(context.TODO(), AssistantId, params, pageToken, pageNumber) +} + +// Retrieve a single page of ToolsByAssistant records from the API. Request is executed immediately. +func (c *ApiService) PageToolsByAssistantWithContext(ctx context.Context, AssistantId string, params *ListToolsByAssistantParams, pageToken, pageNumber string) (*ListToolsByAssistantResponse, error) { path := "/v1/Assistants/{assistantId}/Tools" path = strings.Replace(path, "{"+"assistantId"+"}", AssistantId, -1) @@ -104,7 +116,7 @@ func (c *ApiService) PageToolsByAssistant(AssistantId string, params *ListToolsB data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -121,7 +133,12 @@ func (c *ApiService) PageToolsByAssistant(AssistantId string, params *ListToolsB // Lists ToolsByAssistant records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListToolsByAssistant(AssistantId string, params *ListToolsByAssistantParams) ([]AssistantsV1Tool, error) { - response, errors := c.StreamToolsByAssistant(AssistantId, params) + return c.ListToolsByAssistantWithContext(context.TODO(), AssistantId, params) +} + +// Lists ToolsByAssistant records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListToolsByAssistantWithContext(ctx context.Context, AssistantId string, params *ListToolsByAssistantParams) ([]AssistantsV1Tool, error) { + response, errors := c.StreamToolsByAssistantWithContext(ctx, AssistantId, params) records := make([]AssistantsV1Tool, 0) for record := range response { @@ -137,6 +154,11 @@ func (c *ApiService) ListToolsByAssistant(AssistantId string, params *ListToolsB // Streams ToolsByAssistant records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamToolsByAssistant(AssistantId string, params *ListToolsByAssistantParams) (chan AssistantsV1Tool, chan error) { + return c.StreamToolsByAssistantWithContext(context.TODO(), AssistantId, params) +} + +// Streams ToolsByAssistant records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamToolsByAssistantWithContext(ctx context.Context, AssistantId string, params *ListToolsByAssistantParams) (chan AssistantsV1Tool, chan error) { if params == nil { params = &ListToolsByAssistantParams{} } @@ -145,19 +167,19 @@ func (c *ApiService) StreamToolsByAssistant(AssistantId string, params *ListTool recordChannel := make(chan AssistantsV1Tool, 1) errorChannel := make(chan error, 1) - response, err := c.PageToolsByAssistant(AssistantId, params, "", "") + response, err := c.PageToolsByAssistantWithContext(ctx, AssistantId, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamToolsByAssistant(response, params, recordChannel, errorChannel) + go c.streamToolsByAssistantWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamToolsByAssistant(response *ListToolsByAssistantResponse, params *ListToolsByAssistantParams, recordChannel chan AssistantsV1Tool, errorChannel chan error) { +func (c *ApiService) streamToolsByAssistantWithContext(ctx context.Context, response *ListToolsByAssistantResponse, params *ListToolsByAssistantParams, recordChannel chan AssistantsV1Tool, errorChannel chan error) { curRecord := 1 for response != nil { @@ -172,7 +194,7 @@ func (c *ApiService) streamToolsByAssistant(response *ListToolsByAssistantRespon } } - record, err := client.GetNext(c.baseURL, response, c.getNextListToolsByAssistantResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListToolsByAssistantResponseWithContext) if err != nil { errorChannel <- err break @@ -187,11 +209,11 @@ func (c *ApiService) streamToolsByAssistant(response *ListToolsByAssistantRespon close(errorChannel) } -func (c *ApiService) getNextListToolsByAssistantResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListToolsByAssistantResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/assistants/v1/knowledge.go b/rest/assistants/v1/knowledge.go index 162e39641..784b355fd 100644 --- a/rest/assistants/v1/knowledge.go +++ b/rest/assistants/v1/knowledge.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -36,6 +37,9 @@ func (params *CreateKnowledgeParams) SetAssistantsV1CreateKnowledgeRequest(Assis // Create knowledge func (c *ApiService) CreateKnowledge(params *CreateKnowledgeParams) (*AssistantsV1Knowledge, error) { + return c.CreateKnowledgeWithContext(context.TODO(), params) +} +func (c *ApiService) CreateKnowledgeWithContext(ctx context.Context, params *CreateKnowledgeParams) (*AssistantsV1Knowledge, error) { path := "/v1/Knowledge" data := url.Values{} @@ -52,7 +56,7 @@ func (c *ApiService) CreateKnowledge(params *CreateKnowledgeParams) (*Assistants body = b } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers, body...) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers, body...) if err != nil { return nil, err } @@ -69,6 +73,9 @@ func (c *ApiService) CreateKnowledge(params *CreateKnowledgeParams) (*Assistants // Delete knowledge func (c *ApiService) DeleteKnowledge(Id string) error { + return c.DeleteKnowledgeWithContext(context.TODO(), Id) +} +func (c *ApiService) DeleteKnowledgeWithContext(ctx context.Context, Id string) error { path := "/v1/Knowledge/{id}" path = strings.Replace(path, "{"+"id"+"}", Id, -1) @@ -77,7 +84,7 @@ func (c *ApiService) DeleteKnowledge(Id string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -89,6 +96,9 @@ func (c *ApiService) DeleteKnowledge(Id string) error { // Get knowledge func (c *ApiService) FetchKnowledge(Id string) (*AssistantsV1Knowledge, error) { + return c.FetchKnowledgeWithContext(context.TODO(), Id) +} +func (c *ApiService) FetchKnowledgeWithContext(ctx context.Context, Id string) (*AssistantsV1Knowledge, error) { path := "/v1/Knowledge/{id}" path = strings.Replace(path, "{"+"id"+"}", Id, -1) @@ -97,7 +107,7 @@ func (c *ApiService) FetchKnowledge(Id string) (*AssistantsV1Knowledge, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -137,6 +147,11 @@ func (params *ListKnowledgeParams) SetLimit(Limit int) *ListKnowledgeParams { // Retrieve a single page of Knowledge records from the API. Request is executed immediately. func (c *ApiService) PageKnowledge(params *ListKnowledgeParams, pageToken, pageNumber string) (*ListKnowledgeResponse, error) { + return c.PageKnowledgeWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Knowledge records from the API. Request is executed immediately. +func (c *ApiService) PageKnowledgeWithContext(ctx context.Context, params *ListKnowledgeParams, pageToken, pageNumber string) (*ListKnowledgeResponse, error) { path := "/v1/Knowledge" data := url.Values{} @@ -158,7 +173,7 @@ func (c *ApiService) PageKnowledge(params *ListKnowledgeParams, pageToken, pageN data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -175,7 +190,12 @@ func (c *ApiService) PageKnowledge(params *ListKnowledgeParams, pageToken, pageN // Lists Knowledge records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListKnowledge(params *ListKnowledgeParams) ([]AssistantsV1Knowledge, error) { - response, errors := c.StreamKnowledge(params) + return c.ListKnowledgeWithContext(context.TODO(), params) +} + +// Lists Knowledge records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListKnowledgeWithContext(ctx context.Context, params *ListKnowledgeParams) ([]AssistantsV1Knowledge, error) { + response, errors := c.StreamKnowledgeWithContext(ctx, params) records := make([]AssistantsV1Knowledge, 0) for record := range response { @@ -191,6 +211,11 @@ func (c *ApiService) ListKnowledge(params *ListKnowledgeParams) ([]AssistantsV1K // Streams Knowledge records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamKnowledge(params *ListKnowledgeParams) (chan AssistantsV1Knowledge, chan error) { + return c.StreamKnowledgeWithContext(context.TODO(), params) +} + +// Streams Knowledge records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamKnowledgeWithContext(ctx context.Context, params *ListKnowledgeParams) (chan AssistantsV1Knowledge, chan error) { if params == nil { params = &ListKnowledgeParams{} } @@ -199,19 +224,19 @@ func (c *ApiService) StreamKnowledge(params *ListKnowledgeParams) (chan Assistan recordChannel := make(chan AssistantsV1Knowledge, 1) errorChannel := make(chan error, 1) - response, err := c.PageKnowledge(params, "", "") + response, err := c.PageKnowledgeWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamKnowledge(response, params, recordChannel, errorChannel) + go c.streamKnowledgeWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamKnowledge(response *ListKnowledgeResponse, params *ListKnowledgeParams, recordChannel chan AssistantsV1Knowledge, errorChannel chan error) { +func (c *ApiService) streamKnowledgeWithContext(ctx context.Context, response *ListKnowledgeResponse, params *ListKnowledgeParams, recordChannel chan AssistantsV1Knowledge, errorChannel chan error) { curRecord := 1 for response != nil { @@ -226,7 +251,7 @@ func (c *ApiService) streamKnowledge(response *ListKnowledgeResponse, params *Li } } - record, err := client.GetNext(c.baseURL, response, c.getNextListKnowledgeResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListKnowledgeResponseWithContext) if err != nil { errorChannel <- err break @@ -241,11 +266,11 @@ func (c *ApiService) streamKnowledge(response *ListKnowledgeResponse, params *Li close(errorChannel) } -func (c *ApiService) getNextListKnowledgeResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListKnowledgeResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -272,6 +297,9 @@ func (params *UpdateKnowledgeParams) SetAssistantsV1UpdateKnowledgeRequest(Assis // Update knowledge func (c *ApiService) UpdateKnowledge(Id string, params *UpdateKnowledgeParams) (*AssistantsV1Knowledge, error) { + return c.UpdateKnowledgeWithContext(context.TODO(), Id, params) +} +func (c *ApiService) UpdateKnowledgeWithContext(ctx context.Context, Id string, params *UpdateKnowledgeParams) (*AssistantsV1Knowledge, error) { path := "/v1/Knowledge/{id}" path = strings.Replace(path, "{"+"id"+"}", Id, -1) @@ -289,7 +317,7 @@ func (c *ApiService) UpdateKnowledge(Id string, params *UpdateKnowledgeParams) ( body = b } - resp, err := c.requestHandler.Put(c.baseURL+path, data, headers, body...) + resp, err := c.requestHandler.PutWithContext(ctx, c.baseURL+path, data, headers, body...) if err != nil { return nil, err } diff --git a/rest/assistants/v1/knowledge_chunks.go b/rest/assistants/v1/knowledge_chunks.go index 645715415..09846b1bc 100644 --- a/rest/assistants/v1/knowledge_chunks.go +++ b/rest/assistants/v1/knowledge_chunks.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -42,6 +43,11 @@ func (params *ListKnowledgeChunksParams) SetLimit(Limit int) *ListKnowledgeChunk // Retrieve a single page of KnowledgeChunks records from the API. Request is executed immediately. func (c *ApiService) PageKnowledgeChunks(Id string, params *ListKnowledgeChunksParams, pageToken, pageNumber string) (*ListKnowledgeChunksResponse, error) { + return c.PageKnowledgeChunksWithContext(context.TODO(), Id, params, pageToken, pageNumber) +} + +// Retrieve a single page of KnowledgeChunks records from the API. Request is executed immediately. +func (c *ApiService) PageKnowledgeChunksWithContext(ctx context.Context, Id string, params *ListKnowledgeChunksParams, pageToken, pageNumber string) (*ListKnowledgeChunksResponse, error) { path := "/v1/Knowledge/{id}/Chunks" path = strings.Replace(path, "{"+"id"+"}", Id, -1) @@ -62,7 +68,7 @@ func (c *ApiService) PageKnowledgeChunks(Id string, params *ListKnowledgeChunksP data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -79,7 +85,12 @@ func (c *ApiService) PageKnowledgeChunks(Id string, params *ListKnowledgeChunksP // Lists KnowledgeChunks records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListKnowledgeChunks(Id string, params *ListKnowledgeChunksParams) ([]AssistantsV1KnowledgeChunk, error) { - response, errors := c.StreamKnowledgeChunks(Id, params) + return c.ListKnowledgeChunksWithContext(context.TODO(), Id, params) +} + +// Lists KnowledgeChunks records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListKnowledgeChunksWithContext(ctx context.Context, Id string, params *ListKnowledgeChunksParams) ([]AssistantsV1KnowledgeChunk, error) { + response, errors := c.StreamKnowledgeChunksWithContext(ctx, Id, params) records := make([]AssistantsV1KnowledgeChunk, 0) for record := range response { @@ -95,6 +106,11 @@ func (c *ApiService) ListKnowledgeChunks(Id string, params *ListKnowledgeChunksP // Streams KnowledgeChunks records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamKnowledgeChunks(Id string, params *ListKnowledgeChunksParams) (chan AssistantsV1KnowledgeChunk, chan error) { + return c.StreamKnowledgeChunksWithContext(context.TODO(), Id, params) +} + +// Streams KnowledgeChunks records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamKnowledgeChunksWithContext(ctx context.Context, Id string, params *ListKnowledgeChunksParams) (chan AssistantsV1KnowledgeChunk, chan error) { if params == nil { params = &ListKnowledgeChunksParams{} } @@ -103,19 +119,19 @@ func (c *ApiService) StreamKnowledgeChunks(Id string, params *ListKnowledgeChunk recordChannel := make(chan AssistantsV1KnowledgeChunk, 1) errorChannel := make(chan error, 1) - response, err := c.PageKnowledgeChunks(Id, params, "", "") + response, err := c.PageKnowledgeChunksWithContext(ctx, Id, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamKnowledgeChunks(response, params, recordChannel, errorChannel) + go c.streamKnowledgeChunksWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamKnowledgeChunks(response *ListKnowledgeChunksResponse, params *ListKnowledgeChunksParams, recordChannel chan AssistantsV1KnowledgeChunk, errorChannel chan error) { +func (c *ApiService) streamKnowledgeChunksWithContext(ctx context.Context, response *ListKnowledgeChunksResponse, params *ListKnowledgeChunksParams, recordChannel chan AssistantsV1KnowledgeChunk, errorChannel chan error) { curRecord := 1 for response != nil { @@ -130,7 +146,7 @@ func (c *ApiService) streamKnowledgeChunks(response *ListKnowledgeChunksResponse } } - record, err := client.GetNext(c.baseURL, response, c.getNextListKnowledgeChunksResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListKnowledgeChunksResponseWithContext) if err != nil { errorChannel <- err break @@ -145,11 +161,11 @@ func (c *ApiService) streamKnowledgeChunks(response *ListKnowledgeChunksResponse close(errorChannel) } -func (c *ApiService) getNextListKnowledgeChunksResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListKnowledgeChunksResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/assistants/v1/knowledge_status.go b/rest/assistants/v1/knowledge_status.go index 6e8947476..742668e0c 100644 --- a/rest/assistants/v1/knowledge_status.go +++ b/rest/assistants/v1/knowledge_status.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -22,6 +23,9 @@ import ( // Get knowledge status func (c *ApiService) FetchKnowledgeStatus(Id string) (*AssistantsV1KnowledgeStatus, error) { + return c.FetchKnowledgeStatusWithContext(context.TODO(), Id) +} +func (c *ApiService) FetchKnowledgeStatusWithContext(ctx context.Context, Id string) (*AssistantsV1KnowledgeStatus, error) { path := "/v1/Knowledge/{id}/Status" path = strings.Replace(path, "{"+"id"+"}", Id, -1) @@ -30,7 +34,7 @@ func (c *ApiService) FetchKnowledgeStatus(Id string) (*AssistantsV1KnowledgeStat "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/assistants/v1/policies.go b/rest/assistants/v1/policies.go index 5947ad8fc..cdbc3fe99 100644 --- a/rest/assistants/v1/policies.go +++ b/rest/assistants/v1/policies.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -53,6 +54,11 @@ func (params *ListPoliciesParams) SetLimit(Limit int) *ListPoliciesParams { // Retrieve a single page of Policies records from the API. Request is executed immediately. func (c *ApiService) PagePolicies(params *ListPoliciesParams, pageToken, pageNumber string) (*ListPoliciesResponse, error) { + return c.PagePoliciesWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Policies records from the API. Request is executed immediately. +func (c *ApiService) PagePoliciesWithContext(ctx context.Context, params *ListPoliciesParams, pageToken, pageNumber string) (*ListPoliciesResponse, error) { path := "/v1/Policies" data := url.Values{} @@ -77,7 +83,7 @@ func (c *ApiService) PagePolicies(params *ListPoliciesParams, pageToken, pageNum data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -94,7 +100,12 @@ func (c *ApiService) PagePolicies(params *ListPoliciesParams, pageToken, pageNum // Lists Policies records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListPolicies(params *ListPoliciesParams) ([]AssistantsV1Policy, error) { - response, errors := c.StreamPolicies(params) + return c.ListPoliciesWithContext(context.TODO(), params) +} + +// Lists Policies records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListPoliciesWithContext(ctx context.Context, params *ListPoliciesParams) ([]AssistantsV1Policy, error) { + response, errors := c.StreamPoliciesWithContext(ctx, params) records := make([]AssistantsV1Policy, 0) for record := range response { @@ -110,6 +121,11 @@ func (c *ApiService) ListPolicies(params *ListPoliciesParams) ([]AssistantsV1Pol // Streams Policies records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamPolicies(params *ListPoliciesParams) (chan AssistantsV1Policy, chan error) { + return c.StreamPoliciesWithContext(context.TODO(), params) +} + +// Streams Policies records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamPoliciesWithContext(ctx context.Context, params *ListPoliciesParams) (chan AssistantsV1Policy, chan error) { if params == nil { params = &ListPoliciesParams{} } @@ -118,19 +134,19 @@ func (c *ApiService) StreamPolicies(params *ListPoliciesParams) (chan Assistants recordChannel := make(chan AssistantsV1Policy, 1) errorChannel := make(chan error, 1) - response, err := c.PagePolicies(params, "", "") + response, err := c.PagePoliciesWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamPolicies(response, params, recordChannel, errorChannel) + go c.streamPoliciesWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamPolicies(response *ListPoliciesResponse, params *ListPoliciesParams, recordChannel chan AssistantsV1Policy, errorChannel chan error) { +func (c *ApiService) streamPoliciesWithContext(ctx context.Context, response *ListPoliciesResponse, params *ListPoliciesParams, recordChannel chan AssistantsV1Policy, errorChannel chan error) { curRecord := 1 for response != nil { @@ -145,7 +161,7 @@ func (c *ApiService) streamPolicies(response *ListPoliciesResponse, params *List } } - record, err := client.GetNext(c.baseURL, response, c.getNextListPoliciesResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListPoliciesResponseWithContext) if err != nil { errorChannel <- err break @@ -160,11 +176,11 @@ func (c *ApiService) streamPolicies(response *ListPoliciesResponse, params *List close(errorChannel) } -func (c *ApiService) getNextListPoliciesResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListPoliciesResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/assistants/v1/sessions.go b/rest/assistants/v1/sessions.go index 75854a9d2..5b0f9d8ae 100644 --- a/rest/assistants/v1/sessions.go +++ b/rest/assistants/v1/sessions.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -25,6 +26,9 @@ import ( // get a session func (c *ApiService) FetchSession(Id string) (*AssistantsV1Session, error) { + return c.FetchSessionWithContext(context.TODO(), Id) +} +func (c *ApiService) FetchSessionWithContext(ctx context.Context, Id string) (*AssistantsV1Session, error) { path := "/v1/Sessions/{id}" path = strings.Replace(path, "{"+"id"+"}", Id, -1) @@ -33,7 +37,7 @@ func (c *ApiService) FetchSession(Id string) (*AssistantsV1Session, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -67,6 +71,11 @@ func (params *ListSessionsParams) SetLimit(Limit int) *ListSessionsParams { // Retrieve a single page of Sessions records from the API. Request is executed immediately. func (c *ApiService) PageSessions(params *ListSessionsParams, pageToken, pageNumber string) (*ListSessionsResponse, error) { + return c.PageSessionsWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Sessions records from the API. Request is executed immediately. +func (c *ApiService) PageSessionsWithContext(ctx context.Context, params *ListSessionsParams, pageToken, pageNumber string) (*ListSessionsResponse, error) { path := "/v1/Sessions" data := url.Values{} @@ -85,7 +94,7 @@ func (c *ApiService) PageSessions(params *ListSessionsParams, pageToken, pageNum data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -102,7 +111,12 @@ func (c *ApiService) PageSessions(params *ListSessionsParams, pageToken, pageNum // Lists Sessions records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListSessions(params *ListSessionsParams) ([]AssistantsV1Session, error) { - response, errors := c.StreamSessions(params) + return c.ListSessionsWithContext(context.TODO(), params) +} + +// Lists Sessions records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListSessionsWithContext(ctx context.Context, params *ListSessionsParams) ([]AssistantsV1Session, error) { + response, errors := c.StreamSessionsWithContext(ctx, params) records := make([]AssistantsV1Session, 0) for record := range response { @@ -118,6 +132,11 @@ func (c *ApiService) ListSessions(params *ListSessionsParams) ([]AssistantsV1Ses // Streams Sessions records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamSessions(params *ListSessionsParams) (chan AssistantsV1Session, chan error) { + return c.StreamSessionsWithContext(context.TODO(), params) +} + +// Streams Sessions records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamSessionsWithContext(ctx context.Context, params *ListSessionsParams) (chan AssistantsV1Session, chan error) { if params == nil { params = &ListSessionsParams{} } @@ -126,19 +145,19 @@ func (c *ApiService) StreamSessions(params *ListSessionsParams) (chan Assistants recordChannel := make(chan AssistantsV1Session, 1) errorChannel := make(chan error, 1) - response, err := c.PageSessions(params, "", "") + response, err := c.PageSessionsWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSessions(response, params, recordChannel, errorChannel) + go c.streamSessionsWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamSessions(response *ListSessionsResponse, params *ListSessionsParams, recordChannel chan AssistantsV1Session, errorChannel chan error) { +func (c *ApiService) streamSessionsWithContext(ctx context.Context, response *ListSessionsResponse, params *ListSessionsParams, recordChannel chan AssistantsV1Session, errorChannel chan error) { curRecord := 1 for response != nil { @@ -153,7 +172,7 @@ func (c *ApiService) streamSessions(response *ListSessionsResponse, params *List } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSessionsResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListSessionsResponseWithContext) if err != nil { errorChannel <- err break @@ -168,11 +187,11 @@ func (c *ApiService) streamSessions(response *ListSessionsResponse, params *List close(errorChannel) } -func (c *ApiService) getNextListSessionsResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSessionsResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/assistants/v1/sessions_messages.go b/rest/assistants/v1/sessions_messages.go index 3963646f6..14a17717d 100644 --- a/rest/assistants/v1/sessions_messages.go +++ b/rest/assistants/v1/sessions_messages.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -42,6 +43,11 @@ func (params *ListMessagesParams) SetLimit(Limit int) *ListMessagesParams { // Retrieve a single page of Messages records from the API. Request is executed immediately. func (c *ApiService) PageMessages(SessionId string, params *ListMessagesParams, pageToken, pageNumber string) (*ListMessagesResponse, error) { + return c.PageMessagesWithContext(context.TODO(), SessionId, params, pageToken, pageNumber) +} + +// Retrieve a single page of Messages records from the API. Request is executed immediately. +func (c *ApiService) PageMessagesWithContext(ctx context.Context, SessionId string, params *ListMessagesParams, pageToken, pageNumber string) (*ListMessagesResponse, error) { path := "/v1/Sessions/{sessionId}/Messages" path = strings.Replace(path, "{"+"sessionId"+"}", SessionId, -1) @@ -62,7 +68,7 @@ func (c *ApiService) PageMessages(SessionId string, params *ListMessagesParams, data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -79,7 +85,12 @@ func (c *ApiService) PageMessages(SessionId string, params *ListMessagesParams, // Lists Messages records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListMessages(SessionId string, params *ListMessagesParams) ([]AssistantsV1Message, error) { - response, errors := c.StreamMessages(SessionId, params) + return c.ListMessagesWithContext(context.TODO(), SessionId, params) +} + +// Lists Messages records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListMessagesWithContext(ctx context.Context, SessionId string, params *ListMessagesParams) ([]AssistantsV1Message, error) { + response, errors := c.StreamMessagesWithContext(ctx, SessionId, params) records := make([]AssistantsV1Message, 0) for record := range response { @@ -95,6 +106,11 @@ func (c *ApiService) ListMessages(SessionId string, params *ListMessagesParams) // Streams Messages records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamMessages(SessionId string, params *ListMessagesParams) (chan AssistantsV1Message, chan error) { + return c.StreamMessagesWithContext(context.TODO(), SessionId, params) +} + +// Streams Messages records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamMessagesWithContext(ctx context.Context, SessionId string, params *ListMessagesParams) (chan AssistantsV1Message, chan error) { if params == nil { params = &ListMessagesParams{} } @@ -103,19 +119,19 @@ func (c *ApiService) StreamMessages(SessionId string, params *ListMessagesParams recordChannel := make(chan AssistantsV1Message, 1) errorChannel := make(chan error, 1) - response, err := c.PageMessages(SessionId, params, "", "") + response, err := c.PageMessagesWithContext(ctx, SessionId, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamMessages(response, params, recordChannel, errorChannel) + go c.streamMessagesWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamMessages(response *ListMessagesResponse, params *ListMessagesParams, recordChannel chan AssistantsV1Message, errorChannel chan error) { +func (c *ApiService) streamMessagesWithContext(ctx context.Context, response *ListMessagesResponse, params *ListMessagesParams, recordChannel chan AssistantsV1Message, errorChannel chan error) { curRecord := 1 for response != nil { @@ -130,7 +146,7 @@ func (c *ApiService) streamMessages(response *ListMessagesResponse, params *List } } - record, err := client.GetNext(c.baseURL, response, c.getNextListMessagesResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListMessagesResponseWithContext) if err != nil { errorChannel <- err break @@ -145,11 +161,11 @@ func (c *ApiService) streamMessages(response *ListMessagesResponse, params *List close(errorChannel) } -func (c *ApiService) getNextListMessagesResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListMessagesResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/assistants/v1/tools.go b/rest/assistants/v1/tools.go index 0e7a3ba83..de5767901 100644 --- a/rest/assistants/v1/tools.go +++ b/rest/assistants/v1/tools.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -36,6 +37,9 @@ func (params *CreateToolParams) SetAssistantsV1CreateToolRequest(AssistantsV1Cre // Create tool func (c *ApiService) CreateTool(params *CreateToolParams) (*AssistantsV1Tool, error) { + return c.CreateToolWithContext(context.TODO(), params) +} +func (c *ApiService) CreateToolWithContext(ctx context.Context, params *CreateToolParams) (*AssistantsV1Tool, error) { path := "/v1/Tools" data := url.Values{} @@ -52,7 +56,7 @@ func (c *ApiService) CreateTool(params *CreateToolParams) (*AssistantsV1Tool, er body = b } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers, body...) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers, body...) if err != nil { return nil, err } @@ -69,6 +73,9 @@ func (c *ApiService) CreateTool(params *CreateToolParams) (*AssistantsV1Tool, er // delete a tool func (c *ApiService) DeleteTool(Id string) error { + return c.DeleteToolWithContext(context.TODO(), Id) +} +func (c *ApiService) DeleteToolWithContext(ctx context.Context, Id string) error { path := "/v1/Tools/{id}" path = strings.Replace(path, "{"+"id"+"}", Id, -1) @@ -77,7 +84,7 @@ func (c *ApiService) DeleteTool(Id string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -89,6 +96,9 @@ func (c *ApiService) DeleteTool(Id string) error { // Get tool func (c *ApiService) FetchTool(Id string) (*AssistantsV1ToolWithPolicies, error) { + return c.FetchToolWithContext(context.TODO(), Id) +} +func (c *ApiService) FetchToolWithContext(ctx context.Context, Id string) (*AssistantsV1ToolWithPolicies, error) { path := "/v1/Tools/{id}" path = strings.Replace(path, "{"+"id"+"}", Id, -1) @@ -97,7 +107,7 @@ func (c *ApiService) FetchTool(Id string) (*AssistantsV1ToolWithPolicies, error) "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -137,6 +147,11 @@ func (params *ListToolsParams) SetLimit(Limit int) *ListToolsParams { // Retrieve a single page of Tools records from the API. Request is executed immediately. func (c *ApiService) PageTools(params *ListToolsParams, pageToken, pageNumber string) (*ListToolsResponse, error) { + return c.PageToolsWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Tools records from the API. Request is executed immediately. +func (c *ApiService) PageToolsWithContext(ctx context.Context, params *ListToolsParams, pageToken, pageNumber string) (*ListToolsResponse, error) { path := "/v1/Tools" data := url.Values{} @@ -158,7 +173,7 @@ func (c *ApiService) PageTools(params *ListToolsParams, pageToken, pageNumber st data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -175,7 +190,12 @@ func (c *ApiService) PageTools(params *ListToolsParams, pageToken, pageNumber st // Lists Tools records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListTools(params *ListToolsParams) ([]AssistantsV1Tool, error) { - response, errors := c.StreamTools(params) + return c.ListToolsWithContext(context.TODO(), params) +} + +// Lists Tools records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListToolsWithContext(ctx context.Context, params *ListToolsParams) ([]AssistantsV1Tool, error) { + response, errors := c.StreamToolsWithContext(ctx, params) records := make([]AssistantsV1Tool, 0) for record := range response { @@ -191,6 +211,11 @@ func (c *ApiService) ListTools(params *ListToolsParams) ([]AssistantsV1Tool, err // Streams Tools records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamTools(params *ListToolsParams) (chan AssistantsV1Tool, chan error) { + return c.StreamToolsWithContext(context.TODO(), params) +} + +// Streams Tools records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamToolsWithContext(ctx context.Context, params *ListToolsParams) (chan AssistantsV1Tool, chan error) { if params == nil { params = &ListToolsParams{} } @@ -199,19 +224,19 @@ func (c *ApiService) StreamTools(params *ListToolsParams) (chan AssistantsV1Tool recordChannel := make(chan AssistantsV1Tool, 1) errorChannel := make(chan error, 1) - response, err := c.PageTools(params, "", "") + response, err := c.PageToolsWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamTools(response, params, recordChannel, errorChannel) + go c.streamToolsWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamTools(response *ListToolsResponse, params *ListToolsParams, recordChannel chan AssistantsV1Tool, errorChannel chan error) { +func (c *ApiService) streamToolsWithContext(ctx context.Context, response *ListToolsResponse, params *ListToolsParams, recordChannel chan AssistantsV1Tool, errorChannel chan error) { curRecord := 1 for response != nil { @@ -226,7 +251,7 @@ func (c *ApiService) streamTools(response *ListToolsResponse, params *ListToolsP } } - record, err := client.GetNext(c.baseURL, response, c.getNextListToolsResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListToolsResponseWithContext) if err != nil { errorChannel <- err break @@ -241,11 +266,11 @@ func (c *ApiService) streamTools(response *ListToolsResponse, params *ListToolsP close(errorChannel) } -func (c *ApiService) getNextListToolsResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListToolsResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -272,6 +297,9 @@ func (params *UpdateToolParams) SetAssistantsV1UpdateToolRequest(AssistantsV1Upd // Update tool func (c *ApiService) UpdateTool(Id string, params *UpdateToolParams) (*AssistantsV1Tool, error) { + return c.UpdateToolWithContext(context.TODO(), Id, params) +} +func (c *ApiService) UpdateToolWithContext(ctx context.Context, Id string, params *UpdateToolParams) (*AssistantsV1Tool, error) { path := "/v1/Tools/{id}" path = strings.Replace(path, "{"+"id"+"}", Id, -1) @@ -289,7 +317,7 @@ func (c *ApiService) UpdateTool(Id string, params *UpdateToolParams) (*Assistant body = b } - resp, err := c.requestHandler.Put(c.baseURL+path, data, headers, body...) + resp, err := c.requestHandler.PutWithContext(ctx, c.baseURL+path, data, headers, body...) if err != nil { return nil, err } diff --git a/rest/bulkexports/v1/api_service.go b/rest/bulkexports/v1/api_service.go index 5ff5a6bc4..227706007 100644 --- a/rest/bulkexports/v1/api_service.go +++ b/rest/bulkexports/v1/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://bulkexports.twilio.com", + } +} diff --git a/rest/bulkexports/v1/exports.go b/rest/bulkexports/v1/exports.go index e12ca8460..ed07dfe31 100644 --- a/rest/bulkexports/v1/exports.go +++ b/rest/bulkexports/v1/exports.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -22,6 +23,9 @@ import ( // Fetch a specific Export. func (c *ApiService) FetchExport(ResourceType string) (*BulkexportsV1Export, error) { + return c.FetchExportWithContext(context.TODO(), ResourceType) +} +func (c *ApiService) FetchExportWithContext(ctx context.Context, ResourceType string) (*BulkexportsV1Export, error) { path := "/v1/Exports/{ResourceType}" path = strings.Replace(path, "{"+"ResourceType"+"}", ResourceType, -1) @@ -30,7 +34,7 @@ func (c *ApiService) FetchExport(ResourceType string) (*BulkexportsV1Export, err "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/bulkexports/v1/exports_configuration.go b/rest/bulkexports/v1/exports_configuration.go index 025449b0a..e5980ea02 100644 --- a/rest/bulkexports/v1/exports_configuration.go +++ b/rest/bulkexports/v1/exports_configuration.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -23,6 +24,9 @@ import ( // Fetch a specific Export Configuration. func (c *ApiService) FetchExportConfiguration(ResourceType string) (*BulkexportsV1ExportConfiguration, error) { + return c.FetchExportConfigurationWithContext(context.TODO(), ResourceType) +} +func (c *ApiService) FetchExportConfigurationWithContext(ctx context.Context, ResourceType string) (*BulkexportsV1ExportConfiguration, error) { path := "/v1/Exports/{ResourceType}/Configuration" path = strings.Replace(path, "{"+"ResourceType"+"}", ResourceType, -1) @@ -31,7 +35,7 @@ func (c *ApiService) FetchExportConfiguration(ResourceType string) (*Bulkexports "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -71,6 +75,9 @@ func (params *UpdateExportConfigurationParams) SetWebhookMethod(WebhookMethod st // Update a specific Export Configuration. func (c *ApiService) UpdateExportConfiguration(ResourceType string, params *UpdateExportConfigurationParams) (*BulkexportsV1ExportConfiguration, error) { + return c.UpdateExportConfigurationWithContext(context.TODO(), ResourceType, params) +} +func (c *ApiService) UpdateExportConfigurationWithContext(ctx context.Context, ResourceType string, params *UpdateExportConfigurationParams) (*BulkexportsV1ExportConfiguration, error) { path := "/v1/Exports/{ResourceType}/Configuration" path = strings.Replace(path, "{"+"ResourceType"+"}", ResourceType, -1) @@ -89,7 +96,7 @@ func (c *ApiService) UpdateExportConfiguration(ResourceType string, params *Upda data.Set("WebhookMethod", *params.WebhookMethod) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/bulkexports/v1/exports_days.go b/rest/bulkexports/v1/exports_days.go index 749d10adf..996ea343b 100644 --- a/rest/bulkexports/v1/exports_days.go +++ b/rest/bulkexports/v1/exports_days.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -25,6 +26,9 @@ import ( // Fetch a specific Day. func (c *ApiService) FetchDay(ResourceType string, Day string) (*BulkexportsV1DayInstance, error) { + return c.FetchDayWithContext(context.TODO(), ResourceType, Day) +} +func (c *ApiService) FetchDayWithContext(ctx context.Context, ResourceType string, Day string) (*BulkexportsV1DayInstance, error) { path := "/v1/Exports/{ResourceType}/Days/{Day}" path = strings.Replace(path, "{"+"ResourceType"+"}", ResourceType, -1) path = strings.Replace(path, "{"+"Day"+"}", Day, -1) @@ -34,7 +38,7 @@ func (c *ApiService) FetchDay(ResourceType string, Day string) (*BulkexportsV1Da "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -68,6 +72,11 @@ func (params *ListDayParams) SetLimit(Limit int) *ListDayParams { // Retrieve a single page of Day records from the API. Request is executed immediately. func (c *ApiService) PageDay(ResourceType string, params *ListDayParams, pageToken, pageNumber string) (*ListDayResponse, error) { + return c.PageDayWithContext(context.TODO(), ResourceType, params, pageToken, pageNumber) +} + +// Retrieve a single page of Day records from the API. Request is executed immediately. +func (c *ApiService) PageDayWithContext(ctx context.Context, ResourceType string, params *ListDayParams, pageToken, pageNumber string) (*ListDayResponse, error) { path := "/v1/Exports/{ResourceType}/Days" path = strings.Replace(path, "{"+"ResourceType"+"}", ResourceType, -1) @@ -88,7 +97,7 @@ func (c *ApiService) PageDay(ResourceType string, params *ListDayParams, pageTok data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -105,7 +114,12 @@ func (c *ApiService) PageDay(ResourceType string, params *ListDayParams, pageTok // Lists Day records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListDay(ResourceType string, params *ListDayParams) ([]BulkexportsV1Day, error) { - response, errors := c.StreamDay(ResourceType, params) + return c.ListDayWithContext(context.TODO(), ResourceType, params) +} + +// Lists Day records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListDayWithContext(ctx context.Context, ResourceType string, params *ListDayParams) ([]BulkexportsV1Day, error) { + response, errors := c.StreamDayWithContext(ctx, ResourceType, params) records := make([]BulkexportsV1Day, 0) for record := range response { @@ -121,6 +135,11 @@ func (c *ApiService) ListDay(ResourceType string, params *ListDayParams) ([]Bulk // Streams Day records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamDay(ResourceType string, params *ListDayParams) (chan BulkexportsV1Day, chan error) { + return c.StreamDayWithContext(context.TODO(), ResourceType, params) +} + +// Streams Day records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamDayWithContext(ctx context.Context, ResourceType string, params *ListDayParams) (chan BulkexportsV1Day, chan error) { if params == nil { params = &ListDayParams{} } @@ -129,19 +148,19 @@ func (c *ApiService) StreamDay(ResourceType string, params *ListDayParams) (chan recordChannel := make(chan BulkexportsV1Day, 1) errorChannel := make(chan error, 1) - response, err := c.PageDay(ResourceType, params, "", "") + response, err := c.PageDayWithContext(ctx, ResourceType, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamDay(response, params, recordChannel, errorChannel) + go c.streamDayWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamDay(response *ListDayResponse, params *ListDayParams, recordChannel chan BulkexportsV1Day, errorChannel chan error) { +func (c *ApiService) streamDayWithContext(ctx context.Context, response *ListDayResponse, params *ListDayParams, recordChannel chan BulkexportsV1Day, errorChannel chan error) { curRecord := 1 for response != nil { @@ -156,7 +175,7 @@ func (c *ApiService) streamDay(response *ListDayResponse, params *ListDayParams, } } - record, err := client.GetNext(c.baseURL, response, c.getNextListDayResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListDayResponseWithContext) if err != nil { errorChannel <- err break @@ -171,11 +190,11 @@ func (c *ApiService) streamDay(response *ListDayResponse, params *ListDayParams, close(errorChannel) } -func (c *ApiService) getNextListDayResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListDayResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/bulkexports/v1/exports_jobs.go b/rest/bulkexports/v1/exports_jobs.go index aa69461a0..d12a2ef83 100644 --- a/rest/bulkexports/v1/exports_jobs.go +++ b/rest/bulkexports/v1/exports_jobs.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -64,8 +65,10 @@ func (params *CreateExportCustomJobParams) SetEmail(Email string) *CreateExportC return params } -// func (c *ApiService) CreateExportCustomJob(ResourceType string, params *CreateExportCustomJobParams) (*BulkexportsV1ExportCustomJob, error) { + return c.CreateExportCustomJobWithContext(context.TODO(), ResourceType, params) +} +func (c *ApiService) CreateExportCustomJobWithContext(ctx context.Context, ResourceType string, params *CreateExportCustomJobParams) (*BulkexportsV1ExportCustomJob, error) { path := "/v1/Exports/{ResourceType}/Jobs" path = strings.Replace(path, "{"+"ResourceType"+"}", ResourceType, -1) @@ -93,7 +96,7 @@ func (c *ApiService) CreateExportCustomJob(ResourceType string, params *CreateEx data.Set("Email", *params.Email) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -108,8 +111,10 @@ func (c *ApiService) CreateExportCustomJob(ResourceType string, params *CreateEx return ps, err } -// func (c *ApiService) DeleteJob(JobSid string) error { + return c.DeleteJobWithContext(context.TODO(), JobSid) +} +func (c *ApiService) DeleteJobWithContext(ctx context.Context, JobSid string) error { path := "/v1/Exports/Jobs/{JobSid}" path = strings.Replace(path, "{"+"JobSid"+"}", JobSid, -1) @@ -118,7 +123,7 @@ func (c *ApiService) DeleteJob(JobSid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -128,8 +133,10 @@ func (c *ApiService) DeleteJob(JobSid string) error { return nil } -// func (c *ApiService) FetchJob(JobSid string) (*BulkexportsV1Job, error) { + return c.FetchJobWithContext(context.TODO(), JobSid) +} +func (c *ApiService) FetchJobWithContext(ctx context.Context, JobSid string) (*BulkexportsV1Job, error) { path := "/v1/Exports/Jobs/{JobSid}" path = strings.Replace(path, "{"+"JobSid"+"}", JobSid, -1) @@ -138,7 +145,7 @@ func (c *ApiService) FetchJob(JobSid string) (*BulkexportsV1Job, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -172,6 +179,11 @@ func (params *ListExportCustomJobParams) SetLimit(Limit int) *ListExportCustomJo // Retrieve a single page of ExportCustomJob records from the API. Request is executed immediately. func (c *ApiService) PageExportCustomJob(ResourceType string, params *ListExportCustomJobParams, pageToken, pageNumber string) (*ListExportCustomJobResponse, error) { + return c.PageExportCustomJobWithContext(context.TODO(), ResourceType, params, pageToken, pageNumber) +} + +// Retrieve a single page of ExportCustomJob records from the API. Request is executed immediately. +func (c *ApiService) PageExportCustomJobWithContext(ctx context.Context, ResourceType string, params *ListExportCustomJobParams, pageToken, pageNumber string) (*ListExportCustomJobResponse, error) { path := "/v1/Exports/{ResourceType}/Jobs" path = strings.Replace(path, "{"+"ResourceType"+"}", ResourceType, -1) @@ -192,7 +204,7 @@ func (c *ApiService) PageExportCustomJob(ResourceType string, params *ListExport data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -209,7 +221,12 @@ func (c *ApiService) PageExportCustomJob(ResourceType string, params *ListExport // Lists ExportCustomJob records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListExportCustomJob(ResourceType string, params *ListExportCustomJobParams) ([]BulkexportsV1ExportCustomJob, error) { - response, errors := c.StreamExportCustomJob(ResourceType, params) + return c.ListExportCustomJobWithContext(context.TODO(), ResourceType, params) +} + +// Lists ExportCustomJob records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListExportCustomJobWithContext(ctx context.Context, ResourceType string, params *ListExportCustomJobParams) ([]BulkexportsV1ExportCustomJob, error) { + response, errors := c.StreamExportCustomJobWithContext(ctx, ResourceType, params) records := make([]BulkexportsV1ExportCustomJob, 0) for record := range response { @@ -225,6 +242,11 @@ func (c *ApiService) ListExportCustomJob(ResourceType string, params *ListExport // Streams ExportCustomJob records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamExportCustomJob(ResourceType string, params *ListExportCustomJobParams) (chan BulkexportsV1ExportCustomJob, chan error) { + return c.StreamExportCustomJobWithContext(context.TODO(), ResourceType, params) +} + +// Streams ExportCustomJob records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamExportCustomJobWithContext(ctx context.Context, ResourceType string, params *ListExportCustomJobParams) (chan BulkexportsV1ExportCustomJob, chan error) { if params == nil { params = &ListExportCustomJobParams{} } @@ -233,19 +255,19 @@ func (c *ApiService) StreamExportCustomJob(ResourceType string, params *ListExpo recordChannel := make(chan BulkexportsV1ExportCustomJob, 1) errorChannel := make(chan error, 1) - response, err := c.PageExportCustomJob(ResourceType, params, "", "") + response, err := c.PageExportCustomJobWithContext(ctx, ResourceType, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamExportCustomJob(response, params, recordChannel, errorChannel) + go c.streamExportCustomJobWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamExportCustomJob(response *ListExportCustomJobResponse, params *ListExportCustomJobParams, recordChannel chan BulkexportsV1ExportCustomJob, errorChannel chan error) { +func (c *ApiService) streamExportCustomJobWithContext(ctx context.Context, response *ListExportCustomJobResponse, params *ListExportCustomJobParams, recordChannel chan BulkexportsV1ExportCustomJob, errorChannel chan error) { curRecord := 1 for response != nil { @@ -260,7 +282,7 @@ func (c *ApiService) streamExportCustomJob(response *ListExportCustomJobResponse } } - record, err := client.GetNext(c.baseURL, response, c.getNextListExportCustomJobResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListExportCustomJobResponseWithContext) if err != nil { errorChannel <- err break @@ -275,11 +297,11 @@ func (c *ApiService) streamExportCustomJob(response *ListExportCustomJobResponse close(errorChannel) } -func (c *ApiService) getNextListExportCustomJobResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListExportCustomJobResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/chat/v1/api_service.go b/rest/chat/v1/api_service.go index 432b78e85..56ea16150 100644 --- a/rest/chat/v1/api_service.go +++ b/rest/chat/v1/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://chat.twilio.com", + } +} diff --git a/rest/chat/v1/credentials.go b/rest/chat/v1/credentials.go index cb3d01a85..97d7b26f4 100644 --- a/rest/chat/v1/credentials.go +++ b/rest/chat/v1/credentials.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -70,8 +71,10 @@ func (params *CreateCredentialParams) SetSecret(Secret string) *CreateCredential return params } -// func (c *ApiService) CreateCredential(params *CreateCredentialParams) (*ChatV1Credential, error) { + return c.CreateCredentialWithContext(context.TODO(), params) +} +func (c *ApiService) CreateCredentialWithContext(ctx context.Context, params *CreateCredentialParams) (*ChatV1Credential, error) { path := "/v1/Credentials" data := url.Values{} @@ -101,7 +104,7 @@ func (c *ApiService) CreateCredential(params *CreateCredentialParams) (*ChatV1Cr data.Set("Secret", *params.Secret) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -116,8 +119,10 @@ func (c *ApiService) CreateCredential(params *CreateCredentialParams) (*ChatV1Cr return ps, err } -// func (c *ApiService) DeleteCredential(Sid string) error { + return c.DeleteCredentialWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteCredentialWithContext(ctx context.Context, Sid string) error { path := "/v1/Credentials/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -126,7 +131,7 @@ func (c *ApiService) DeleteCredential(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -136,8 +141,10 @@ func (c *ApiService) DeleteCredential(Sid string) error { return nil } -// func (c *ApiService) FetchCredential(Sid string) (*ChatV1Credential, error) { + return c.FetchCredentialWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchCredentialWithContext(ctx context.Context, Sid string) (*ChatV1Credential, error) { path := "/v1/Credentials/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -146,7 +153,7 @@ func (c *ApiService) FetchCredential(Sid string) (*ChatV1Credential, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -180,6 +187,11 @@ func (params *ListCredentialParams) SetLimit(Limit int) *ListCredentialParams { // Retrieve a single page of Credential records from the API. Request is executed immediately. func (c *ApiService) PageCredential(params *ListCredentialParams, pageToken, pageNumber string) (*ListCredentialResponse, error) { + return c.PageCredentialWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Credential records from the API. Request is executed immediately. +func (c *ApiService) PageCredentialWithContext(ctx context.Context, params *ListCredentialParams, pageToken, pageNumber string) (*ListCredentialResponse, error) { path := "/v1/Credentials" data := url.Values{} @@ -198,7 +210,7 @@ func (c *ApiService) PageCredential(params *ListCredentialParams, pageToken, pag data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -215,7 +227,12 @@ func (c *ApiService) PageCredential(params *ListCredentialParams, pageToken, pag // Lists Credential records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListCredential(params *ListCredentialParams) ([]ChatV1Credential, error) { - response, errors := c.StreamCredential(params) + return c.ListCredentialWithContext(context.TODO(), params) +} + +// Lists Credential records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListCredentialWithContext(ctx context.Context, params *ListCredentialParams) ([]ChatV1Credential, error) { + response, errors := c.StreamCredentialWithContext(ctx, params) records := make([]ChatV1Credential, 0) for record := range response { @@ -231,6 +248,11 @@ func (c *ApiService) ListCredential(params *ListCredentialParams) ([]ChatV1Crede // Streams Credential records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamCredential(params *ListCredentialParams) (chan ChatV1Credential, chan error) { + return c.StreamCredentialWithContext(context.TODO(), params) +} + +// Streams Credential records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamCredentialWithContext(ctx context.Context, params *ListCredentialParams) (chan ChatV1Credential, chan error) { if params == nil { params = &ListCredentialParams{} } @@ -239,19 +261,19 @@ func (c *ApiService) StreamCredential(params *ListCredentialParams) (chan ChatV1 recordChannel := make(chan ChatV1Credential, 1) errorChannel := make(chan error, 1) - response, err := c.PageCredential(params, "", "") + response, err := c.PageCredentialWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamCredential(response, params, recordChannel, errorChannel) + go c.streamCredentialWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamCredential(response *ListCredentialResponse, params *ListCredentialParams, recordChannel chan ChatV1Credential, errorChannel chan error) { +func (c *ApiService) streamCredentialWithContext(ctx context.Context, response *ListCredentialResponse, params *ListCredentialParams, recordChannel chan ChatV1Credential, errorChannel chan error) { curRecord := 1 for response != nil { @@ -266,7 +288,7 @@ func (c *ApiService) streamCredential(response *ListCredentialResponse, params * } } - record, err := client.GetNext(c.baseURL, response, c.getNextListCredentialResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListCredentialResponseWithContext) if err != nil { errorChannel <- err break @@ -281,11 +303,11 @@ func (c *ApiService) streamCredential(response *ListCredentialResponse, params * close(errorChannel) } -func (c *ApiService) getNextListCredentialResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListCredentialResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -340,8 +362,10 @@ func (params *UpdateCredentialParams) SetSecret(Secret string) *UpdateCredential return params } -// func (c *ApiService) UpdateCredential(Sid string, params *UpdateCredentialParams) (*ChatV1Credential, error) { + return c.UpdateCredentialWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateCredentialWithContext(ctx context.Context, Sid string, params *UpdateCredentialParams) (*ChatV1Credential, error) { path := "/v1/Credentials/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -369,7 +393,7 @@ func (c *ApiService) UpdateCredential(Sid string, params *UpdateCredentialParams data.Set("Secret", *params.Secret) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/chat/v1/services.go b/rest/chat/v1/services.go index 4372706ce..b1a36804c 100644 --- a/rest/chat/v1/services.go +++ b/rest/chat/v1/services.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -34,8 +35,10 @@ func (params *CreateServiceParams) SetFriendlyName(FriendlyName string) *CreateS return params } -// func (c *ApiService) CreateService(params *CreateServiceParams) (*ChatV1Service, error) { + return c.CreateServiceWithContext(context.TODO(), params) +} +func (c *ApiService) CreateServiceWithContext(ctx context.Context, params *CreateServiceParams) (*ChatV1Service, error) { path := "/v1/Services" data := url.Values{} @@ -47,7 +50,7 @@ func (c *ApiService) CreateService(params *CreateServiceParams) (*ChatV1Service, data.Set("FriendlyName", *params.FriendlyName) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -62,8 +65,10 @@ func (c *ApiService) CreateService(params *CreateServiceParams) (*ChatV1Service, return ps, err } -// func (c *ApiService) DeleteService(Sid string) error { + return c.DeleteServiceWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteServiceWithContext(ctx context.Context, Sid string) error { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -72,7 +77,7 @@ func (c *ApiService) DeleteService(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -82,8 +87,10 @@ func (c *ApiService) DeleteService(Sid string) error { return nil } -// func (c *ApiService) FetchService(Sid string) (*ChatV1Service, error) { + return c.FetchServiceWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchServiceWithContext(ctx context.Context, Sid string) (*ChatV1Service, error) { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -92,7 +99,7 @@ func (c *ApiService) FetchService(Sid string) (*ChatV1Service, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -126,6 +133,11 @@ func (params *ListServiceParams) SetLimit(Limit int) *ListServiceParams { // Retrieve a single page of Service records from the API. Request is executed immediately. func (c *ApiService) PageService(params *ListServiceParams, pageToken, pageNumber string) (*ListServiceResponse, error) { + return c.PageServiceWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Service records from the API. Request is executed immediately. +func (c *ApiService) PageServiceWithContext(ctx context.Context, params *ListServiceParams, pageToken, pageNumber string) (*ListServiceResponse, error) { path := "/v1/Services" data := url.Values{} @@ -144,7 +156,7 @@ func (c *ApiService) PageService(params *ListServiceParams, pageToken, pageNumbe data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -161,7 +173,12 @@ func (c *ApiService) PageService(params *ListServiceParams, pageToken, pageNumbe // Lists Service records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListService(params *ListServiceParams) ([]ChatV1Service, error) { - response, errors := c.StreamService(params) + return c.ListServiceWithContext(context.TODO(), params) +} + +// Lists Service records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListServiceWithContext(ctx context.Context, params *ListServiceParams) ([]ChatV1Service, error) { + response, errors := c.StreamServiceWithContext(ctx, params) records := make([]ChatV1Service, 0) for record := range response { @@ -177,6 +194,11 @@ func (c *ApiService) ListService(params *ListServiceParams) ([]ChatV1Service, er // Streams Service records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamService(params *ListServiceParams) (chan ChatV1Service, chan error) { + return c.StreamServiceWithContext(context.TODO(), params) +} + +// Streams Service records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamServiceWithContext(ctx context.Context, params *ListServiceParams) (chan ChatV1Service, chan error) { if params == nil { params = &ListServiceParams{} } @@ -185,19 +207,19 @@ func (c *ApiService) StreamService(params *ListServiceParams) (chan ChatV1Servic recordChannel := make(chan ChatV1Service, 1) errorChannel := make(chan error, 1) - response, err := c.PageService(params, "", "") + response, err := c.PageServiceWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamService(response, params, recordChannel, errorChannel) + go c.streamServiceWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamService(response *ListServiceResponse, params *ListServiceParams, recordChannel chan ChatV1Service, errorChannel chan error) { +func (c *ApiService) streamServiceWithContext(ctx context.Context, response *ListServiceResponse, params *ListServiceParams, recordChannel chan ChatV1Service, errorChannel chan error) { curRecord := 1 for response != nil { @@ -212,7 +234,7 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListServiceResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListServiceResponseWithContext) if err != nil { errorChannel <- err break @@ -227,11 +249,11 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe close(errorChannel) } -func (c *ApiService) getNextListServiceResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListServiceResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -574,8 +596,10 @@ func (params *UpdateServiceParams) SetLimitsUserChannels(LimitsUserChannels int) return params } -// func (c *ApiService) UpdateService(Sid string, params *UpdateServiceParams) (*ChatV1Service, error) { + return c.UpdateServiceWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateServiceWithContext(ctx context.Context, Sid string, params *UpdateServiceParams) (*ChatV1Service, error) { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -749,7 +773,7 @@ func (c *ApiService) UpdateService(Sid string, params *UpdateServiceParams) (*Ch data.Set("Limits.UserChannels", fmt.Sprint(*params.LimitsUserChannels)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/chat/v1/services_channels.go b/rest/chat/v1/services_channels.go index f491fb67c..cd1bfa9ba 100644 --- a/rest/chat/v1/services_channels.go +++ b/rest/chat/v1/services_channels.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -52,8 +53,10 @@ func (params *CreateChannelParams) SetType(Type string) *CreateChannelParams { return params } -// func (c *ApiService) CreateChannel(ServiceSid string, params *CreateChannelParams) (*ChatV1Channel, error) { + return c.CreateChannelWithContext(context.TODO(), ServiceSid, params) +} +func (c *ApiService) CreateChannelWithContext(ctx context.Context, ServiceSid string, params *CreateChannelParams) (*ChatV1Channel, error) { path := "/v1/Services/{ServiceSid}/Channels" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -75,7 +78,7 @@ func (c *ApiService) CreateChannel(ServiceSid string, params *CreateChannelParam data.Set("Type", fmt.Sprint(*params.Type)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -90,8 +93,10 @@ func (c *ApiService) CreateChannel(ServiceSid string, params *CreateChannelParam return ps, err } -// func (c *ApiService) DeleteChannel(ServiceSid string, Sid string) error { + return c.DeleteChannelWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) DeleteChannelWithContext(ctx context.Context, ServiceSid string, Sid string) error { path := "/v1/Services/{ServiceSid}/Channels/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -101,7 +106,7 @@ func (c *ApiService) DeleteChannel(ServiceSid string, Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -111,8 +116,10 @@ func (c *ApiService) DeleteChannel(ServiceSid string, Sid string) error { return nil } -// func (c *ApiService) FetchChannel(ServiceSid string, Sid string) (*ChatV1Channel, error) { + return c.FetchChannelWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) FetchChannelWithContext(ctx context.Context, ServiceSid string, Sid string) (*ChatV1Channel, error) { path := "/v1/Services/{ServiceSid}/Channels/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -122,7 +129,7 @@ func (c *ApiService) FetchChannel(ServiceSid string, Sid string) (*ChatV1Channel "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -162,6 +169,11 @@ func (params *ListChannelParams) SetLimit(Limit int) *ListChannelParams { // Retrieve a single page of Channel records from the API. Request is executed immediately. func (c *ApiService) PageChannel(ServiceSid string, params *ListChannelParams, pageToken, pageNumber string) (*ListChannelResponse, error) { + return c.PageChannelWithContext(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Channel records from the API. Request is executed immediately. +func (c *ApiService) PageChannelWithContext(ctx context.Context, ServiceSid string, params *ListChannelParams, pageToken, pageNumber string) (*ListChannelResponse, error) { path := "/v1/Services/{ServiceSid}/Channels" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -187,7 +199,7 @@ func (c *ApiService) PageChannel(ServiceSid string, params *ListChannelParams, p data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -204,7 +216,12 @@ func (c *ApiService) PageChannel(ServiceSid string, params *ListChannelParams, p // Lists Channel records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListChannel(ServiceSid string, params *ListChannelParams) ([]ChatV1Channel, error) { - response, errors := c.StreamChannel(ServiceSid, params) + return c.ListChannelWithContext(context.TODO(), ServiceSid, params) +} + +// Lists Channel records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListChannelWithContext(ctx context.Context, ServiceSid string, params *ListChannelParams) ([]ChatV1Channel, error) { + response, errors := c.StreamChannelWithContext(ctx, ServiceSid, params) records := make([]ChatV1Channel, 0) for record := range response { @@ -220,6 +237,11 @@ func (c *ApiService) ListChannel(ServiceSid string, params *ListChannelParams) ( // Streams Channel records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamChannel(ServiceSid string, params *ListChannelParams) (chan ChatV1Channel, chan error) { + return c.StreamChannelWithContext(context.TODO(), ServiceSid, params) +} + +// Streams Channel records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamChannelWithContext(ctx context.Context, ServiceSid string, params *ListChannelParams) (chan ChatV1Channel, chan error) { if params == nil { params = &ListChannelParams{} } @@ -228,19 +250,19 @@ func (c *ApiService) StreamChannel(ServiceSid string, params *ListChannelParams) recordChannel := make(chan ChatV1Channel, 1) errorChannel := make(chan error, 1) - response, err := c.PageChannel(ServiceSid, params, "", "") + response, err := c.PageChannelWithContext(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamChannel(response, params, recordChannel, errorChannel) + go c.streamChannelWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamChannel(response *ListChannelResponse, params *ListChannelParams, recordChannel chan ChatV1Channel, errorChannel chan error) { +func (c *ApiService) streamChannelWithContext(ctx context.Context, response *ListChannelResponse, params *ListChannelParams, recordChannel chan ChatV1Channel, errorChannel chan error) { curRecord := 1 for response != nil { @@ -255,7 +277,7 @@ func (c *ApiService) streamChannel(response *ListChannelResponse, params *ListCh } } - record, err := client.GetNext(c.baseURL, response, c.getNextListChannelResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListChannelResponseWithContext) if err != nil { errorChannel <- err break @@ -270,11 +292,11 @@ func (c *ApiService) streamChannel(response *ListChannelResponse, params *ListCh close(errorChannel) } -func (c *ApiService) getNextListChannelResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListChannelResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -311,8 +333,10 @@ func (params *UpdateChannelParams) SetAttributes(Attributes string) *UpdateChann return params } -// func (c *ApiService) UpdateChannel(ServiceSid string, Sid string, params *UpdateChannelParams) (*ChatV1Channel, error) { + return c.UpdateChannelWithContext(context.TODO(), ServiceSid, Sid, params) +} +func (c *ApiService) UpdateChannelWithContext(ctx context.Context, ServiceSid string, Sid string, params *UpdateChannelParams) (*ChatV1Channel, error) { path := "/v1/Services/{ServiceSid}/Channels/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -332,7 +356,7 @@ func (c *ApiService) UpdateChannel(ServiceSid string, Sid string, params *Update data.Set("Attributes", *params.Attributes) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/chat/v1/services_channels_invites.go b/rest/chat/v1/services_channels_invites.go index 3ae429f68..33ac38a6d 100644 --- a/rest/chat/v1/services_channels_invites.go +++ b/rest/chat/v1/services_channels_invites.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -40,8 +41,10 @@ func (params *CreateInviteParams) SetRoleSid(RoleSid string) *CreateInviteParams return params } -// func (c *ApiService) CreateInvite(ServiceSid string, ChannelSid string, params *CreateInviteParams) (*ChatV1Invite, error) { + return c.CreateInviteWithContext(context.TODO(), ServiceSid, ChannelSid, params) +} +func (c *ApiService) CreateInviteWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *CreateInviteParams) (*ChatV1Invite, error) { path := "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Invites" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -58,7 +61,7 @@ func (c *ApiService) CreateInvite(ServiceSid string, ChannelSid string, params * data.Set("RoleSid", *params.RoleSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -73,8 +76,10 @@ func (c *ApiService) CreateInvite(ServiceSid string, ChannelSid string, params * return ps, err } -// func (c *ApiService) DeleteInvite(ServiceSid string, ChannelSid string, Sid string) error { + return c.DeleteInviteWithContext(context.TODO(), ServiceSid, ChannelSid, Sid) +} +func (c *ApiService) DeleteInviteWithContext(ctx context.Context, ServiceSid string, ChannelSid string, Sid string) error { path := "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Invites/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -85,7 +90,7 @@ func (c *ApiService) DeleteInvite(ServiceSid string, ChannelSid string, Sid stri "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -95,8 +100,10 @@ func (c *ApiService) DeleteInvite(ServiceSid string, ChannelSid string, Sid stri return nil } -// func (c *ApiService) FetchInvite(ServiceSid string, ChannelSid string, Sid string) (*ChatV1Invite, error) { + return c.FetchInviteWithContext(context.TODO(), ServiceSid, ChannelSid, Sid) +} +func (c *ApiService) FetchInviteWithContext(ctx context.Context, ServiceSid string, ChannelSid string, Sid string) (*ChatV1Invite, error) { path := "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Invites/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -107,7 +114,7 @@ func (c *ApiService) FetchInvite(ServiceSid string, ChannelSid string, Sid strin "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -147,6 +154,11 @@ func (params *ListInviteParams) SetLimit(Limit int) *ListInviteParams { // Retrieve a single page of Invite records from the API. Request is executed immediately. func (c *ApiService) PageInvite(ServiceSid string, ChannelSid string, params *ListInviteParams, pageToken, pageNumber string) (*ListInviteResponse, error) { + return c.PageInviteWithContext(context.TODO(), ServiceSid, ChannelSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Invite records from the API. Request is executed immediately. +func (c *ApiService) PageInviteWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *ListInviteParams, pageToken, pageNumber string) (*ListInviteResponse, error) { path := "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Invites" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -173,7 +185,7 @@ func (c *ApiService) PageInvite(ServiceSid string, ChannelSid string, params *Li data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -190,7 +202,12 @@ func (c *ApiService) PageInvite(ServiceSid string, ChannelSid string, params *Li // Lists Invite records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListInvite(ServiceSid string, ChannelSid string, params *ListInviteParams) ([]ChatV1Invite, error) { - response, errors := c.StreamInvite(ServiceSid, ChannelSid, params) + return c.ListInviteWithContext(context.TODO(), ServiceSid, ChannelSid, params) +} + +// Lists Invite records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListInviteWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *ListInviteParams) ([]ChatV1Invite, error) { + response, errors := c.StreamInviteWithContext(ctx, ServiceSid, ChannelSid, params) records := make([]ChatV1Invite, 0) for record := range response { @@ -206,6 +223,11 @@ func (c *ApiService) ListInvite(ServiceSid string, ChannelSid string, params *Li // Streams Invite records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamInvite(ServiceSid string, ChannelSid string, params *ListInviteParams) (chan ChatV1Invite, chan error) { + return c.StreamInviteWithContext(context.TODO(), ServiceSid, ChannelSid, params) +} + +// Streams Invite records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamInviteWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *ListInviteParams) (chan ChatV1Invite, chan error) { if params == nil { params = &ListInviteParams{} } @@ -214,19 +236,19 @@ func (c *ApiService) StreamInvite(ServiceSid string, ChannelSid string, params * recordChannel := make(chan ChatV1Invite, 1) errorChannel := make(chan error, 1) - response, err := c.PageInvite(ServiceSid, ChannelSid, params, "", "") + response, err := c.PageInviteWithContext(ctx, ServiceSid, ChannelSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamInvite(response, params, recordChannel, errorChannel) + go c.streamInviteWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamInvite(response *ListInviteResponse, params *ListInviteParams, recordChannel chan ChatV1Invite, errorChannel chan error) { +func (c *ApiService) streamInviteWithContext(ctx context.Context, response *ListInviteResponse, params *ListInviteParams, recordChannel chan ChatV1Invite, errorChannel chan error) { curRecord := 1 for response != nil { @@ -241,7 +263,7 @@ func (c *ApiService) streamInvite(response *ListInviteResponse, params *ListInvi } } - record, err := client.GetNext(c.baseURL, response, c.getNextListInviteResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListInviteResponseWithContext) if err != nil { errorChannel <- err break @@ -256,11 +278,11 @@ func (c *ApiService) streamInvite(response *ListInviteResponse, params *ListInvi close(errorChannel) } -func (c *ApiService) getNextListInviteResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListInviteResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/chat/v1/services_channels_members.go b/rest/chat/v1/services_channels_members.go index a5bbb0441..b14cfa260 100644 --- a/rest/chat/v1/services_channels_members.go +++ b/rest/chat/v1/services_channels_members.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -40,8 +41,10 @@ func (params *CreateMemberParams) SetRoleSid(RoleSid string) *CreateMemberParams return params } -// func (c *ApiService) CreateMember(ServiceSid string, ChannelSid string, params *CreateMemberParams) (*ChatV1Member, error) { + return c.CreateMemberWithContext(context.TODO(), ServiceSid, ChannelSid, params) +} +func (c *ApiService) CreateMemberWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *CreateMemberParams) (*ChatV1Member, error) { path := "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Members" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -58,7 +61,7 @@ func (c *ApiService) CreateMember(ServiceSid string, ChannelSid string, params * data.Set("RoleSid", *params.RoleSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -73,8 +76,10 @@ func (c *ApiService) CreateMember(ServiceSid string, ChannelSid string, params * return ps, err } -// func (c *ApiService) DeleteMember(ServiceSid string, ChannelSid string, Sid string) error { + return c.DeleteMemberWithContext(context.TODO(), ServiceSid, ChannelSid, Sid) +} +func (c *ApiService) DeleteMemberWithContext(ctx context.Context, ServiceSid string, ChannelSid string, Sid string) error { path := "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -85,7 +90,7 @@ func (c *ApiService) DeleteMember(ServiceSid string, ChannelSid string, Sid stri "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -95,8 +100,10 @@ func (c *ApiService) DeleteMember(ServiceSid string, ChannelSid string, Sid stri return nil } -// func (c *ApiService) FetchMember(ServiceSid string, ChannelSid string, Sid string) (*ChatV1Member, error) { + return c.FetchMemberWithContext(context.TODO(), ServiceSid, ChannelSid, Sid) +} +func (c *ApiService) FetchMemberWithContext(ctx context.Context, ServiceSid string, ChannelSid string, Sid string) (*ChatV1Member, error) { path := "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -107,7 +114,7 @@ func (c *ApiService) FetchMember(ServiceSid string, ChannelSid string, Sid strin "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -147,6 +154,11 @@ func (params *ListMemberParams) SetLimit(Limit int) *ListMemberParams { // Retrieve a single page of Member records from the API. Request is executed immediately. func (c *ApiService) PageMember(ServiceSid string, ChannelSid string, params *ListMemberParams, pageToken, pageNumber string) (*ListMemberResponse, error) { + return c.PageMemberWithContext(context.TODO(), ServiceSid, ChannelSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Member records from the API. Request is executed immediately. +func (c *ApiService) PageMemberWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *ListMemberParams, pageToken, pageNumber string) (*ListMemberResponse, error) { path := "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Members" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -173,7 +185,7 @@ func (c *ApiService) PageMember(ServiceSid string, ChannelSid string, params *Li data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -190,7 +202,12 @@ func (c *ApiService) PageMember(ServiceSid string, ChannelSid string, params *Li // Lists Member records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListMember(ServiceSid string, ChannelSid string, params *ListMemberParams) ([]ChatV1Member, error) { - response, errors := c.StreamMember(ServiceSid, ChannelSid, params) + return c.ListMemberWithContext(context.TODO(), ServiceSid, ChannelSid, params) +} + +// Lists Member records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListMemberWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *ListMemberParams) ([]ChatV1Member, error) { + response, errors := c.StreamMemberWithContext(ctx, ServiceSid, ChannelSid, params) records := make([]ChatV1Member, 0) for record := range response { @@ -206,6 +223,11 @@ func (c *ApiService) ListMember(ServiceSid string, ChannelSid string, params *Li // Streams Member records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamMember(ServiceSid string, ChannelSid string, params *ListMemberParams) (chan ChatV1Member, chan error) { + return c.StreamMemberWithContext(context.TODO(), ServiceSid, ChannelSid, params) +} + +// Streams Member records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamMemberWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *ListMemberParams) (chan ChatV1Member, chan error) { if params == nil { params = &ListMemberParams{} } @@ -214,19 +236,19 @@ func (c *ApiService) StreamMember(ServiceSid string, ChannelSid string, params * recordChannel := make(chan ChatV1Member, 1) errorChannel := make(chan error, 1) - response, err := c.PageMember(ServiceSid, ChannelSid, params, "", "") + response, err := c.PageMemberWithContext(ctx, ServiceSid, ChannelSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamMember(response, params, recordChannel, errorChannel) + go c.streamMemberWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamMember(response *ListMemberResponse, params *ListMemberParams, recordChannel chan ChatV1Member, errorChannel chan error) { +func (c *ApiService) streamMemberWithContext(ctx context.Context, response *ListMemberResponse, params *ListMemberParams, recordChannel chan ChatV1Member, errorChannel chan error) { curRecord := 1 for response != nil { @@ -241,7 +263,7 @@ func (c *ApiService) streamMember(response *ListMemberResponse, params *ListMemb } } - record, err := client.GetNext(c.baseURL, response, c.getNextListMemberResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListMemberResponseWithContext) if err != nil { errorChannel <- err break @@ -256,11 +278,11 @@ func (c *ApiService) streamMember(response *ListMemberResponse, params *ListMemb close(errorChannel) } -func (c *ApiService) getNextListMemberResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListMemberResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -291,8 +313,10 @@ func (params *UpdateMemberParams) SetLastConsumedMessageIndex(LastConsumedMessag return params } -// func (c *ApiService) UpdateMember(ServiceSid string, ChannelSid string, Sid string, params *UpdateMemberParams) (*ChatV1Member, error) { + return c.UpdateMemberWithContext(context.TODO(), ServiceSid, ChannelSid, Sid, params) +} +func (c *ApiService) UpdateMemberWithContext(ctx context.Context, ServiceSid string, ChannelSid string, Sid string, params *UpdateMemberParams) (*ChatV1Member, error) { path := "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -310,7 +334,7 @@ func (c *ApiService) UpdateMember(ServiceSid string, ChannelSid string, Sid stri data.Set("LastConsumedMessageIndex", fmt.Sprint(*params.LastConsumedMessageIndex)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/chat/v1/services_channels_messages.go b/rest/chat/v1/services_channels_messages.go index 3193effe7..9071b82b8 100644 --- a/rest/chat/v1/services_channels_messages.go +++ b/rest/chat/v1/services_channels_messages.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -46,8 +47,10 @@ func (params *CreateMessageParams) SetAttributes(Attributes string) *CreateMessa return params } -// func (c *ApiService) CreateMessage(ServiceSid string, ChannelSid string, params *CreateMessageParams) (*ChatV1Message, error) { + return c.CreateMessageWithContext(context.TODO(), ServiceSid, ChannelSid, params) +} +func (c *ApiService) CreateMessageWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *CreateMessageParams) (*ChatV1Message, error) { path := "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Messages" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -67,7 +70,7 @@ func (c *ApiService) CreateMessage(ServiceSid string, ChannelSid string, params data.Set("Attributes", *params.Attributes) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -82,8 +85,10 @@ func (c *ApiService) CreateMessage(ServiceSid string, ChannelSid string, params return ps, err } -// func (c *ApiService) DeleteMessage(ServiceSid string, ChannelSid string, Sid string) error { + return c.DeleteMessageWithContext(context.TODO(), ServiceSid, ChannelSid, Sid) +} +func (c *ApiService) DeleteMessageWithContext(ctx context.Context, ServiceSid string, ChannelSid string, Sid string) error { path := "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -94,7 +99,7 @@ func (c *ApiService) DeleteMessage(ServiceSid string, ChannelSid string, Sid str "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -104,8 +109,10 @@ func (c *ApiService) DeleteMessage(ServiceSid string, ChannelSid string, Sid str return nil } -// func (c *ApiService) FetchMessage(ServiceSid string, ChannelSid string, Sid string) (*ChatV1Message, error) { + return c.FetchMessageWithContext(context.TODO(), ServiceSid, ChannelSid, Sid) +} +func (c *ApiService) FetchMessageWithContext(ctx context.Context, ServiceSid string, ChannelSid string, Sid string) (*ChatV1Message, error) { path := "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -116,7 +123,7 @@ func (c *ApiService) FetchMessage(ServiceSid string, ChannelSid string, Sid stri "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -156,6 +163,11 @@ func (params *ListMessageParams) SetLimit(Limit int) *ListMessageParams { // Retrieve a single page of Message records from the API. Request is executed immediately. func (c *ApiService) PageMessage(ServiceSid string, ChannelSid string, params *ListMessageParams, pageToken, pageNumber string) (*ListMessageResponse, error) { + return c.PageMessageWithContext(context.TODO(), ServiceSid, ChannelSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Message records from the API. Request is executed immediately. +func (c *ApiService) PageMessageWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *ListMessageParams, pageToken, pageNumber string) (*ListMessageResponse, error) { path := "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Messages" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -180,7 +192,7 @@ func (c *ApiService) PageMessage(ServiceSid string, ChannelSid string, params *L data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -197,7 +209,12 @@ func (c *ApiService) PageMessage(ServiceSid string, ChannelSid string, params *L // Lists Message records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListMessage(ServiceSid string, ChannelSid string, params *ListMessageParams) ([]ChatV1Message, error) { - response, errors := c.StreamMessage(ServiceSid, ChannelSid, params) + return c.ListMessageWithContext(context.TODO(), ServiceSid, ChannelSid, params) +} + +// Lists Message records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListMessageWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *ListMessageParams) ([]ChatV1Message, error) { + response, errors := c.StreamMessageWithContext(ctx, ServiceSid, ChannelSid, params) records := make([]ChatV1Message, 0) for record := range response { @@ -213,6 +230,11 @@ func (c *ApiService) ListMessage(ServiceSid string, ChannelSid string, params *L // Streams Message records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamMessage(ServiceSid string, ChannelSid string, params *ListMessageParams) (chan ChatV1Message, chan error) { + return c.StreamMessageWithContext(context.TODO(), ServiceSid, ChannelSid, params) +} + +// Streams Message records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamMessageWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *ListMessageParams) (chan ChatV1Message, chan error) { if params == nil { params = &ListMessageParams{} } @@ -221,19 +243,19 @@ func (c *ApiService) StreamMessage(ServiceSid string, ChannelSid string, params recordChannel := make(chan ChatV1Message, 1) errorChannel := make(chan error, 1) - response, err := c.PageMessage(ServiceSid, ChannelSid, params, "", "") + response, err := c.PageMessageWithContext(ctx, ServiceSid, ChannelSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamMessage(response, params, recordChannel, errorChannel) + go c.streamMessageWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamMessage(response *ListMessageResponse, params *ListMessageParams, recordChannel chan ChatV1Message, errorChannel chan error) { +func (c *ApiService) streamMessageWithContext(ctx context.Context, response *ListMessageResponse, params *ListMessageParams, recordChannel chan ChatV1Message, errorChannel chan error) { curRecord := 1 for response != nil { @@ -248,7 +270,7 @@ func (c *ApiService) streamMessage(response *ListMessageResponse, params *ListMe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListMessageResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListMessageResponseWithContext) if err != nil { errorChannel <- err break @@ -263,11 +285,11 @@ func (c *ApiService) streamMessage(response *ListMessageResponse, params *ListMe close(errorChannel) } -func (c *ApiService) getNextListMessageResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListMessageResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -298,8 +320,10 @@ func (params *UpdateMessageParams) SetAttributes(Attributes string) *UpdateMessa return params } -// func (c *ApiService) UpdateMessage(ServiceSid string, ChannelSid string, Sid string, params *UpdateMessageParams) (*ChatV1Message, error) { + return c.UpdateMessageWithContext(context.TODO(), ServiceSid, ChannelSid, Sid, params) +} +func (c *ApiService) UpdateMessageWithContext(ctx context.Context, ServiceSid string, ChannelSid string, Sid string, params *UpdateMessageParams) (*ChatV1Message, error) { path := "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -317,7 +341,7 @@ func (c *ApiService) UpdateMessage(ServiceSid string, ChannelSid string, Sid str data.Set("Attributes", *params.Attributes) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/chat/v1/services_roles.go b/rest/chat/v1/services_roles.go index 7826c9a45..108a7f152 100644 --- a/rest/chat/v1/services_roles.go +++ b/rest/chat/v1/services_roles.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -46,8 +47,10 @@ func (params *CreateRoleParams) SetPermission(Permission []string) *CreateRolePa return params } -// func (c *ApiService) CreateRole(ServiceSid string, params *CreateRoleParams) (*ChatV1Role, error) { + return c.CreateRoleWithContext(context.TODO(), ServiceSid, params) +} +func (c *ApiService) CreateRoleWithContext(ctx context.Context, ServiceSid string, params *CreateRoleParams) (*ChatV1Role, error) { path := "/v1/Services/{ServiceSid}/Roles" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -68,7 +71,7 @@ func (c *ApiService) CreateRole(ServiceSid string, params *CreateRoleParams) (*C } } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -83,8 +86,10 @@ func (c *ApiService) CreateRole(ServiceSid string, params *CreateRoleParams) (*C return ps, err } -// func (c *ApiService) DeleteRole(ServiceSid string, Sid string) error { + return c.DeleteRoleWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) DeleteRoleWithContext(ctx context.Context, ServiceSid string, Sid string) error { path := "/v1/Services/{ServiceSid}/Roles/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -94,7 +99,7 @@ func (c *ApiService) DeleteRole(ServiceSid string, Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -104,8 +109,10 @@ func (c *ApiService) DeleteRole(ServiceSid string, Sid string) error { return nil } -// func (c *ApiService) FetchRole(ServiceSid string, Sid string) (*ChatV1Role, error) { + return c.FetchRoleWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) FetchRoleWithContext(ctx context.Context, ServiceSid string, Sid string) (*ChatV1Role, error) { path := "/v1/Services/{ServiceSid}/Roles/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -115,7 +122,7 @@ func (c *ApiService) FetchRole(ServiceSid string, Sid string) (*ChatV1Role, erro "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -149,6 +156,11 @@ func (params *ListRoleParams) SetLimit(Limit int) *ListRoleParams { // Retrieve a single page of Role records from the API. Request is executed immediately. func (c *ApiService) PageRole(ServiceSid string, params *ListRoleParams, pageToken, pageNumber string) (*ListRoleResponse, error) { + return c.PageRoleWithContext(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Role records from the API. Request is executed immediately. +func (c *ApiService) PageRoleWithContext(ctx context.Context, ServiceSid string, params *ListRoleParams, pageToken, pageNumber string) (*ListRoleResponse, error) { path := "/v1/Services/{ServiceSid}/Roles" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -169,7 +181,7 @@ func (c *ApiService) PageRole(ServiceSid string, params *ListRoleParams, pageTok data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -186,7 +198,12 @@ func (c *ApiService) PageRole(ServiceSid string, params *ListRoleParams, pageTok // Lists Role records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListRole(ServiceSid string, params *ListRoleParams) ([]ChatV1Role, error) { - response, errors := c.StreamRole(ServiceSid, params) + return c.ListRoleWithContext(context.TODO(), ServiceSid, params) +} + +// Lists Role records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListRoleWithContext(ctx context.Context, ServiceSid string, params *ListRoleParams) ([]ChatV1Role, error) { + response, errors := c.StreamRoleWithContext(ctx, ServiceSid, params) records := make([]ChatV1Role, 0) for record := range response { @@ -202,6 +219,11 @@ func (c *ApiService) ListRole(ServiceSid string, params *ListRoleParams) ([]Chat // Streams Role records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamRole(ServiceSid string, params *ListRoleParams) (chan ChatV1Role, chan error) { + return c.StreamRoleWithContext(context.TODO(), ServiceSid, params) +} + +// Streams Role records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamRoleWithContext(ctx context.Context, ServiceSid string, params *ListRoleParams) (chan ChatV1Role, chan error) { if params == nil { params = &ListRoleParams{} } @@ -210,19 +232,19 @@ func (c *ApiService) StreamRole(ServiceSid string, params *ListRoleParams) (chan recordChannel := make(chan ChatV1Role, 1) errorChannel := make(chan error, 1) - response, err := c.PageRole(ServiceSid, params, "", "") + response, err := c.PageRoleWithContext(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamRole(response, params, recordChannel, errorChannel) + go c.streamRoleWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamRole(response *ListRoleResponse, params *ListRoleParams, recordChannel chan ChatV1Role, errorChannel chan error) { +func (c *ApiService) streamRoleWithContext(ctx context.Context, response *ListRoleResponse, params *ListRoleParams, recordChannel chan ChatV1Role, errorChannel chan error) { curRecord := 1 for response != nil { @@ -237,7 +259,7 @@ func (c *ApiService) streamRole(response *ListRoleResponse, params *ListRolePara } } - record, err := client.GetNext(c.baseURL, response, c.getNextListRoleResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListRoleResponseWithContext) if err != nil { errorChannel <- err break @@ -252,11 +274,11 @@ func (c *ApiService) streamRole(response *ListRoleResponse, params *ListRolePara close(errorChannel) } -func (c *ApiService) getNextListRoleResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListRoleResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -281,8 +303,10 @@ func (params *UpdateRoleParams) SetPermission(Permission []string) *UpdateRolePa return params } -// func (c *ApiService) UpdateRole(ServiceSid string, Sid string, params *UpdateRoleParams) (*ChatV1Role, error) { + return c.UpdateRoleWithContext(context.TODO(), ServiceSid, Sid, params) +} +func (c *ApiService) UpdateRoleWithContext(ctx context.Context, ServiceSid string, Sid string, params *UpdateRoleParams) (*ChatV1Role, error) { path := "/v1/Services/{ServiceSid}/Roles/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -298,7 +322,7 @@ func (c *ApiService) UpdateRole(ServiceSid string, Sid string, params *UpdateRol } } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/chat/v1/services_users.go b/rest/chat/v1/services_users.go index 6d21ffb4b..8f7741275 100644 --- a/rest/chat/v1/services_users.go +++ b/rest/chat/v1/services_users.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -52,8 +53,10 @@ func (params *CreateUserParams) SetFriendlyName(FriendlyName string) *CreateUser return params } -// func (c *ApiService) CreateUser(ServiceSid string, params *CreateUserParams) (*ChatV1User, error) { + return c.CreateUserWithContext(context.TODO(), ServiceSid, params) +} +func (c *ApiService) CreateUserWithContext(ctx context.Context, ServiceSid string, params *CreateUserParams) (*ChatV1User, error) { path := "/v1/Services/{ServiceSid}/Users" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -75,7 +78,7 @@ func (c *ApiService) CreateUser(ServiceSid string, params *CreateUserParams) (*C data.Set("FriendlyName", *params.FriendlyName) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -90,8 +93,10 @@ func (c *ApiService) CreateUser(ServiceSid string, params *CreateUserParams) (*C return ps, err } -// func (c *ApiService) DeleteUser(ServiceSid string, Sid string) error { + return c.DeleteUserWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) DeleteUserWithContext(ctx context.Context, ServiceSid string, Sid string) error { path := "/v1/Services/{ServiceSid}/Users/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -101,7 +106,7 @@ func (c *ApiService) DeleteUser(ServiceSid string, Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -111,8 +116,10 @@ func (c *ApiService) DeleteUser(ServiceSid string, Sid string) error { return nil } -// func (c *ApiService) FetchUser(ServiceSid string, Sid string) (*ChatV1User, error) { + return c.FetchUserWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) FetchUserWithContext(ctx context.Context, ServiceSid string, Sid string) (*ChatV1User, error) { path := "/v1/Services/{ServiceSid}/Users/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -122,7 +129,7 @@ func (c *ApiService) FetchUser(ServiceSid string, Sid string) (*ChatV1User, erro "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -156,6 +163,11 @@ func (params *ListUserParams) SetLimit(Limit int) *ListUserParams { // Retrieve a single page of User records from the API. Request is executed immediately. func (c *ApiService) PageUser(ServiceSid string, params *ListUserParams, pageToken, pageNumber string) (*ListUserResponse, error) { + return c.PageUserWithContext(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of User records from the API. Request is executed immediately. +func (c *ApiService) PageUserWithContext(ctx context.Context, ServiceSid string, params *ListUserParams, pageToken, pageNumber string) (*ListUserResponse, error) { path := "/v1/Services/{ServiceSid}/Users" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -176,7 +188,7 @@ func (c *ApiService) PageUser(ServiceSid string, params *ListUserParams, pageTok data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -193,7 +205,12 @@ func (c *ApiService) PageUser(ServiceSid string, params *ListUserParams, pageTok // Lists User records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListUser(ServiceSid string, params *ListUserParams) ([]ChatV1User, error) { - response, errors := c.StreamUser(ServiceSid, params) + return c.ListUserWithContext(context.TODO(), ServiceSid, params) +} + +// Lists User records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListUserWithContext(ctx context.Context, ServiceSid string, params *ListUserParams) ([]ChatV1User, error) { + response, errors := c.StreamUserWithContext(ctx, ServiceSid, params) records := make([]ChatV1User, 0) for record := range response { @@ -209,6 +226,11 @@ func (c *ApiService) ListUser(ServiceSid string, params *ListUserParams) ([]Chat // Streams User records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamUser(ServiceSid string, params *ListUserParams) (chan ChatV1User, chan error) { + return c.StreamUserWithContext(context.TODO(), ServiceSid, params) +} + +// Streams User records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamUserWithContext(ctx context.Context, ServiceSid string, params *ListUserParams) (chan ChatV1User, chan error) { if params == nil { params = &ListUserParams{} } @@ -217,19 +239,19 @@ func (c *ApiService) StreamUser(ServiceSid string, params *ListUserParams) (chan recordChannel := make(chan ChatV1User, 1) errorChannel := make(chan error, 1) - response, err := c.PageUser(ServiceSid, params, "", "") + response, err := c.PageUserWithContext(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUser(response, params, recordChannel, errorChannel) + go c.streamUserWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamUser(response *ListUserResponse, params *ListUserParams, recordChannel chan ChatV1User, errorChannel chan error) { +func (c *ApiService) streamUserWithContext(ctx context.Context, response *ListUserResponse, params *ListUserParams, recordChannel chan ChatV1User, errorChannel chan error) { curRecord := 1 for response != nil { @@ -244,7 +266,7 @@ func (c *ApiService) streamUser(response *ListUserResponse, params *ListUserPara } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUserResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListUserResponseWithContext) if err != nil { errorChannel <- err break @@ -259,11 +281,11 @@ func (c *ApiService) streamUser(response *ListUserResponse, params *ListUserPara close(errorChannel) } -func (c *ApiService) getNextListUserResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUserResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -300,8 +322,10 @@ func (params *UpdateUserParams) SetFriendlyName(FriendlyName string) *UpdateUser return params } -// func (c *ApiService) UpdateUser(ServiceSid string, Sid string, params *UpdateUserParams) (*ChatV1User, error) { + return c.UpdateUserWithContext(context.TODO(), ServiceSid, Sid, params) +} +func (c *ApiService) UpdateUserWithContext(ctx context.Context, ServiceSid string, Sid string, params *UpdateUserParams) (*ChatV1User, error) { path := "/v1/Services/{ServiceSid}/Users/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -321,7 +345,7 @@ func (c *ApiService) UpdateUser(ServiceSid string, Sid string, params *UpdateUse data.Set("FriendlyName", *params.FriendlyName) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/chat/v1/services_users_channels.go b/rest/chat/v1/services_users_channels.go index eb1870a23..617f28399 100644 --- a/rest/chat/v1/services_users_channels.go +++ b/rest/chat/v1/services_users_channels.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -42,6 +43,11 @@ func (params *ListUserChannelParams) SetLimit(Limit int) *ListUserChannelParams // Retrieve a single page of UserChannel records from the API. Request is executed immediately. func (c *ApiService) PageUserChannel(ServiceSid string, UserSid string, params *ListUserChannelParams, pageToken, pageNumber string) (*ListUserChannelResponse, error) { + return c.PageUserChannelWithContext(context.TODO(), ServiceSid, UserSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of UserChannel records from the API. Request is executed immediately. +func (c *ApiService) PageUserChannelWithContext(ctx context.Context, ServiceSid string, UserSid string, params *ListUserChannelParams, pageToken, pageNumber string) (*ListUserChannelResponse, error) { path := "/v1/Services/{ServiceSid}/Users/{UserSid}/Channels" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -63,7 +69,7 @@ func (c *ApiService) PageUserChannel(ServiceSid string, UserSid string, params * data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -80,7 +86,12 @@ func (c *ApiService) PageUserChannel(ServiceSid string, UserSid string, params * // Lists UserChannel records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListUserChannel(ServiceSid string, UserSid string, params *ListUserChannelParams) ([]ChatV1UserChannel, error) { - response, errors := c.StreamUserChannel(ServiceSid, UserSid, params) + return c.ListUserChannelWithContext(context.TODO(), ServiceSid, UserSid, params) +} + +// Lists UserChannel records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListUserChannelWithContext(ctx context.Context, ServiceSid string, UserSid string, params *ListUserChannelParams) ([]ChatV1UserChannel, error) { + response, errors := c.StreamUserChannelWithContext(ctx, ServiceSid, UserSid, params) records := make([]ChatV1UserChannel, 0) for record := range response { @@ -96,6 +107,11 @@ func (c *ApiService) ListUserChannel(ServiceSid string, UserSid string, params * // Streams UserChannel records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamUserChannel(ServiceSid string, UserSid string, params *ListUserChannelParams) (chan ChatV1UserChannel, chan error) { + return c.StreamUserChannelWithContext(context.TODO(), ServiceSid, UserSid, params) +} + +// Streams UserChannel records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamUserChannelWithContext(ctx context.Context, ServiceSid string, UserSid string, params *ListUserChannelParams) (chan ChatV1UserChannel, chan error) { if params == nil { params = &ListUserChannelParams{} } @@ -104,19 +120,19 @@ func (c *ApiService) StreamUserChannel(ServiceSid string, UserSid string, params recordChannel := make(chan ChatV1UserChannel, 1) errorChannel := make(chan error, 1) - response, err := c.PageUserChannel(ServiceSid, UserSid, params, "", "") + response, err := c.PageUserChannelWithContext(ctx, ServiceSid, UserSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUserChannel(response, params, recordChannel, errorChannel) + go c.streamUserChannelWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamUserChannel(response *ListUserChannelResponse, params *ListUserChannelParams, recordChannel chan ChatV1UserChannel, errorChannel chan error) { +func (c *ApiService) streamUserChannelWithContext(ctx context.Context, response *ListUserChannelResponse, params *ListUserChannelParams, recordChannel chan ChatV1UserChannel, errorChannel chan error) { curRecord := 1 for response != nil { @@ -131,7 +147,7 @@ func (c *ApiService) streamUserChannel(response *ListUserChannelResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUserChannelResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListUserChannelResponseWithContext) if err != nil { errorChannel <- err break @@ -146,11 +162,11 @@ func (c *ApiService) streamUserChannel(response *ListUserChannelResponse, params close(errorChannel) } -func (c *ApiService) getNextListUserChannelResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUserChannelResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/chat/v2/api_service.go b/rest/chat/v2/api_service.go index 432b78e85..56ea16150 100644 --- a/rest/chat/v2/api_service.go +++ b/rest/chat/v2/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://chat.twilio.com", + } +} diff --git a/rest/chat/v2/credentials.go b/rest/chat/v2/credentials.go index 4cc9bbbda..408aafda2 100644 --- a/rest/chat/v2/credentials.go +++ b/rest/chat/v2/credentials.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -70,8 +71,10 @@ func (params *CreateCredentialParams) SetSecret(Secret string) *CreateCredential return params } -// func (c *ApiService) CreateCredential(params *CreateCredentialParams) (*ChatV2Credential, error) { + return c.CreateCredentialWithContext(context.TODO(), params) +} +func (c *ApiService) CreateCredentialWithContext(ctx context.Context, params *CreateCredentialParams) (*ChatV2Credential, error) { path := "/v2/Credentials" data := url.Values{} @@ -101,7 +104,7 @@ func (c *ApiService) CreateCredential(params *CreateCredentialParams) (*ChatV2Cr data.Set("Secret", *params.Secret) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -116,8 +119,10 @@ func (c *ApiService) CreateCredential(params *CreateCredentialParams) (*ChatV2Cr return ps, err } -// func (c *ApiService) DeleteCredential(Sid string) error { + return c.DeleteCredentialWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteCredentialWithContext(ctx context.Context, Sid string) error { path := "/v2/Credentials/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -126,7 +131,7 @@ func (c *ApiService) DeleteCredential(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -136,8 +141,10 @@ func (c *ApiService) DeleteCredential(Sid string) error { return nil } -// func (c *ApiService) FetchCredential(Sid string) (*ChatV2Credential, error) { + return c.FetchCredentialWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchCredentialWithContext(ctx context.Context, Sid string) (*ChatV2Credential, error) { path := "/v2/Credentials/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -146,7 +153,7 @@ func (c *ApiService) FetchCredential(Sid string) (*ChatV2Credential, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -180,6 +187,11 @@ func (params *ListCredentialParams) SetLimit(Limit int) *ListCredentialParams { // Retrieve a single page of Credential records from the API. Request is executed immediately. func (c *ApiService) PageCredential(params *ListCredentialParams, pageToken, pageNumber string) (*ListCredentialResponse, error) { + return c.PageCredentialWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Credential records from the API. Request is executed immediately. +func (c *ApiService) PageCredentialWithContext(ctx context.Context, params *ListCredentialParams, pageToken, pageNumber string) (*ListCredentialResponse, error) { path := "/v2/Credentials" data := url.Values{} @@ -198,7 +210,7 @@ func (c *ApiService) PageCredential(params *ListCredentialParams, pageToken, pag data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -215,7 +227,12 @@ func (c *ApiService) PageCredential(params *ListCredentialParams, pageToken, pag // Lists Credential records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListCredential(params *ListCredentialParams) ([]ChatV2Credential, error) { - response, errors := c.StreamCredential(params) + return c.ListCredentialWithContext(context.TODO(), params) +} + +// Lists Credential records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListCredentialWithContext(ctx context.Context, params *ListCredentialParams) ([]ChatV2Credential, error) { + response, errors := c.StreamCredentialWithContext(ctx, params) records := make([]ChatV2Credential, 0) for record := range response { @@ -231,6 +248,11 @@ func (c *ApiService) ListCredential(params *ListCredentialParams) ([]ChatV2Crede // Streams Credential records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamCredential(params *ListCredentialParams) (chan ChatV2Credential, chan error) { + return c.StreamCredentialWithContext(context.TODO(), params) +} + +// Streams Credential records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamCredentialWithContext(ctx context.Context, params *ListCredentialParams) (chan ChatV2Credential, chan error) { if params == nil { params = &ListCredentialParams{} } @@ -239,19 +261,19 @@ func (c *ApiService) StreamCredential(params *ListCredentialParams) (chan ChatV2 recordChannel := make(chan ChatV2Credential, 1) errorChannel := make(chan error, 1) - response, err := c.PageCredential(params, "", "") + response, err := c.PageCredentialWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamCredential(response, params, recordChannel, errorChannel) + go c.streamCredentialWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamCredential(response *ListCredentialResponse, params *ListCredentialParams, recordChannel chan ChatV2Credential, errorChannel chan error) { +func (c *ApiService) streamCredentialWithContext(ctx context.Context, response *ListCredentialResponse, params *ListCredentialParams, recordChannel chan ChatV2Credential, errorChannel chan error) { curRecord := 1 for response != nil { @@ -266,7 +288,7 @@ func (c *ApiService) streamCredential(response *ListCredentialResponse, params * } } - record, err := client.GetNext(c.baseURL, response, c.getNextListCredentialResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListCredentialResponseWithContext) if err != nil { errorChannel <- err break @@ -281,11 +303,11 @@ func (c *ApiService) streamCredential(response *ListCredentialResponse, params * close(errorChannel) } -func (c *ApiService) getNextListCredentialResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListCredentialResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -340,8 +362,10 @@ func (params *UpdateCredentialParams) SetSecret(Secret string) *UpdateCredential return params } -// func (c *ApiService) UpdateCredential(Sid string, params *UpdateCredentialParams) (*ChatV2Credential, error) { + return c.UpdateCredentialWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateCredentialWithContext(ctx context.Context, Sid string, params *UpdateCredentialParams) (*ChatV2Credential, error) { path := "/v2/Credentials/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -369,7 +393,7 @@ func (c *ApiService) UpdateCredential(Sid string, params *UpdateCredentialParams data.Set("Secret", *params.Secret) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/chat/v2/services.go b/rest/chat/v2/services.go index bbd3ad3c1..12c6d08b8 100644 --- a/rest/chat/v2/services.go +++ b/rest/chat/v2/services.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -34,8 +35,10 @@ func (params *CreateServiceParams) SetFriendlyName(FriendlyName string) *CreateS return params } -// func (c *ApiService) CreateService(params *CreateServiceParams) (*ChatV2Service, error) { + return c.CreateServiceWithContext(context.TODO(), params) +} +func (c *ApiService) CreateServiceWithContext(ctx context.Context, params *CreateServiceParams) (*ChatV2Service, error) { path := "/v2/Services" data := url.Values{} @@ -47,7 +50,7 @@ func (c *ApiService) CreateService(params *CreateServiceParams) (*ChatV2Service, data.Set("FriendlyName", *params.FriendlyName) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -62,8 +65,10 @@ func (c *ApiService) CreateService(params *CreateServiceParams) (*ChatV2Service, return ps, err } -// func (c *ApiService) DeleteService(Sid string) error { + return c.DeleteServiceWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteServiceWithContext(ctx context.Context, Sid string) error { path := "/v2/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -72,7 +77,7 @@ func (c *ApiService) DeleteService(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -82,8 +87,10 @@ func (c *ApiService) DeleteService(Sid string) error { return nil } -// func (c *ApiService) FetchService(Sid string) (*ChatV2Service, error) { + return c.FetchServiceWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchServiceWithContext(ctx context.Context, Sid string) (*ChatV2Service, error) { path := "/v2/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -92,7 +99,7 @@ func (c *ApiService) FetchService(Sid string) (*ChatV2Service, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -126,6 +133,11 @@ func (params *ListServiceParams) SetLimit(Limit int) *ListServiceParams { // Retrieve a single page of Service records from the API. Request is executed immediately. func (c *ApiService) PageService(params *ListServiceParams, pageToken, pageNumber string) (*ListServiceResponse, error) { + return c.PageServiceWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Service records from the API. Request is executed immediately. +func (c *ApiService) PageServiceWithContext(ctx context.Context, params *ListServiceParams, pageToken, pageNumber string) (*ListServiceResponse, error) { path := "/v2/Services" data := url.Values{} @@ -144,7 +156,7 @@ func (c *ApiService) PageService(params *ListServiceParams, pageToken, pageNumbe data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -161,7 +173,12 @@ func (c *ApiService) PageService(params *ListServiceParams, pageToken, pageNumbe // Lists Service records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListService(params *ListServiceParams) ([]ChatV2Service, error) { - response, errors := c.StreamService(params) + return c.ListServiceWithContext(context.TODO(), params) +} + +// Lists Service records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListServiceWithContext(ctx context.Context, params *ListServiceParams) ([]ChatV2Service, error) { + response, errors := c.StreamServiceWithContext(ctx, params) records := make([]ChatV2Service, 0) for record := range response { @@ -177,6 +194,11 @@ func (c *ApiService) ListService(params *ListServiceParams) ([]ChatV2Service, er // Streams Service records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamService(params *ListServiceParams) (chan ChatV2Service, chan error) { + return c.StreamServiceWithContext(context.TODO(), params) +} + +// Streams Service records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamServiceWithContext(ctx context.Context, params *ListServiceParams) (chan ChatV2Service, chan error) { if params == nil { params = &ListServiceParams{} } @@ -185,19 +207,19 @@ func (c *ApiService) StreamService(params *ListServiceParams) (chan ChatV2Servic recordChannel := make(chan ChatV2Service, 1) errorChannel := make(chan error, 1) - response, err := c.PageService(params, "", "") + response, err := c.PageServiceWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamService(response, params, recordChannel, errorChannel) + go c.streamServiceWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamService(response *ListServiceResponse, params *ListServiceParams, recordChannel chan ChatV2Service, errorChannel chan error) { +func (c *ApiService) streamServiceWithContext(ctx context.Context, response *ListServiceResponse, params *ListServiceParams, recordChannel chan ChatV2Service, errorChannel chan error) { curRecord := 1 for response != nil { @@ -212,7 +234,7 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListServiceResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListServiceResponseWithContext) if err != nil { errorChannel <- err break @@ -227,11 +249,11 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe close(errorChannel) } -func (c *ApiService) getNextListServiceResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListServiceResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -436,8 +458,10 @@ func (params *UpdateServiceParams) SetNotificationsLogEnabled(NotificationsLogEn return params } -// func (c *ApiService) UpdateService(Sid string, params *UpdateServiceParams) (*ChatV2Service, error) { + return c.UpdateServiceWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateServiceWithContext(ctx context.Context, Sid string, params *UpdateServiceParams) (*ChatV2Service, error) { path := "/v2/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -542,7 +566,7 @@ func (c *ApiService) UpdateService(Sid string, params *UpdateServiceParams) (*Ch data.Set("Notifications.LogEnabled", fmt.Sprint(*params.NotificationsLogEnabled)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/chat/v2/services_bindings.go b/rest/chat/v2/services_bindings.go index 7e765e1f2..464933496 100644 --- a/rest/chat/v2/services_bindings.go +++ b/rest/chat/v2/services_bindings.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -23,8 +24,10 @@ import ( "github.com/twilio/twilio-go/client" ) -// func (c *ApiService) DeleteBinding(ServiceSid string, Sid string) error { + return c.DeleteBindingWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) DeleteBindingWithContext(ctx context.Context, ServiceSid string, Sid string) error { path := "/v2/Services/{ServiceSid}/Bindings/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -34,7 +37,7 @@ func (c *ApiService) DeleteBinding(ServiceSid string, Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -44,8 +47,10 @@ func (c *ApiService) DeleteBinding(ServiceSid string, Sid string) error { return nil } -// func (c *ApiService) FetchBinding(ServiceSid string, Sid string) (*ChatV2Binding, error) { + return c.FetchBindingWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) FetchBindingWithContext(ctx context.Context, ServiceSid string, Sid string) (*ChatV2Binding, error) { path := "/v2/Services/{ServiceSid}/Bindings/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -55,7 +60,7 @@ func (c *ApiService) FetchBinding(ServiceSid string, Sid string) (*ChatV2Binding "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -101,6 +106,11 @@ func (params *ListBindingParams) SetLimit(Limit int) *ListBindingParams { // Retrieve a single page of Binding records from the API. Request is executed immediately. func (c *ApiService) PageBinding(ServiceSid string, params *ListBindingParams, pageToken, pageNumber string) (*ListBindingResponse, error) { + return c.PageBindingWithContext(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Binding records from the API. Request is executed immediately. +func (c *ApiService) PageBindingWithContext(ctx context.Context, ServiceSid string, params *ListBindingParams, pageToken, pageNumber string) (*ListBindingResponse, error) { path := "/v2/Services/{ServiceSid}/Bindings" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -131,7 +141,7 @@ func (c *ApiService) PageBinding(ServiceSid string, params *ListBindingParams, p data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -148,7 +158,12 @@ func (c *ApiService) PageBinding(ServiceSid string, params *ListBindingParams, p // Lists Binding records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListBinding(ServiceSid string, params *ListBindingParams) ([]ChatV2Binding, error) { - response, errors := c.StreamBinding(ServiceSid, params) + return c.ListBindingWithContext(context.TODO(), ServiceSid, params) +} + +// Lists Binding records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListBindingWithContext(ctx context.Context, ServiceSid string, params *ListBindingParams) ([]ChatV2Binding, error) { + response, errors := c.StreamBindingWithContext(ctx, ServiceSid, params) records := make([]ChatV2Binding, 0) for record := range response { @@ -164,6 +179,11 @@ func (c *ApiService) ListBinding(ServiceSid string, params *ListBindingParams) ( // Streams Binding records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamBinding(ServiceSid string, params *ListBindingParams) (chan ChatV2Binding, chan error) { + return c.StreamBindingWithContext(context.TODO(), ServiceSid, params) +} + +// Streams Binding records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamBindingWithContext(ctx context.Context, ServiceSid string, params *ListBindingParams) (chan ChatV2Binding, chan error) { if params == nil { params = &ListBindingParams{} } @@ -172,19 +192,19 @@ func (c *ApiService) StreamBinding(ServiceSid string, params *ListBindingParams) recordChannel := make(chan ChatV2Binding, 1) errorChannel := make(chan error, 1) - response, err := c.PageBinding(ServiceSid, params, "", "") + response, err := c.PageBindingWithContext(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamBinding(response, params, recordChannel, errorChannel) + go c.streamBindingWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamBinding(response *ListBindingResponse, params *ListBindingParams, recordChannel chan ChatV2Binding, errorChannel chan error) { +func (c *ApiService) streamBindingWithContext(ctx context.Context, response *ListBindingResponse, params *ListBindingParams, recordChannel chan ChatV2Binding, errorChannel chan error) { curRecord := 1 for response != nil { @@ -199,7 +219,7 @@ func (c *ApiService) streamBinding(response *ListBindingResponse, params *ListBi } } - record, err := client.GetNext(c.baseURL, response, c.getNextListBindingResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListBindingResponseWithContext) if err != nil { errorChannel <- err break @@ -214,11 +234,11 @@ func (c *ApiService) streamBinding(response *ListBindingResponse, params *ListBi close(errorChannel) } -func (c *ApiService) getNextListBindingResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListBindingResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/chat/v2/services_channels.go b/rest/chat/v2/services_channels.go index 3bea367b2..645271ad7 100644 --- a/rest/chat/v2/services_channels.go +++ b/rest/chat/v2/services_channels.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -77,8 +78,10 @@ func (params *CreateChannelParams) SetCreatedBy(CreatedBy string) *CreateChannel return params } -// func (c *ApiService) CreateChannel(ServiceSid string, params *CreateChannelParams) (*ChatV2Channel, error) { + return c.CreateChannelWithContext(context.TODO(), ServiceSid, params) +} +func (c *ApiService) CreateChannelWithContext(ctx context.Context, ServiceSid string, params *CreateChannelParams) (*ChatV2Channel, error) { path := "/v2/Services/{ServiceSid}/Channels" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -112,7 +115,7 @@ func (c *ApiService) CreateChannel(ServiceSid string, params *CreateChannelParam if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -138,8 +141,10 @@ func (params *DeleteChannelParams) SetXTwilioWebhookEnabled(XTwilioWebhookEnable return params } -// func (c *ApiService) DeleteChannel(ServiceSid string, Sid string, params *DeleteChannelParams) error { + return c.DeleteChannelWithContext(context.TODO(), ServiceSid, Sid, params) +} +func (c *ApiService) DeleteChannelWithContext(ctx context.Context, ServiceSid string, Sid string, params *DeleteChannelParams) error { path := "/v2/Services/{ServiceSid}/Channels/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -152,7 +157,7 @@ func (c *ApiService) DeleteChannel(ServiceSid string, Sid string, params *Delete if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -162,8 +167,10 @@ func (c *ApiService) DeleteChannel(ServiceSid string, Sid string, params *Delete return nil } -// func (c *ApiService) FetchChannel(ServiceSid string, Sid string) (*ChatV2Channel, error) { + return c.FetchChannelWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) FetchChannelWithContext(ctx context.Context, ServiceSid string, Sid string) (*ChatV2Channel, error) { path := "/v2/Services/{ServiceSid}/Channels/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -173,7 +180,7 @@ func (c *ApiService) FetchChannel(ServiceSid string, Sid string) (*ChatV2Channel "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -213,6 +220,11 @@ func (params *ListChannelParams) SetLimit(Limit int) *ListChannelParams { // Retrieve a single page of Channel records from the API. Request is executed immediately. func (c *ApiService) PageChannel(ServiceSid string, params *ListChannelParams, pageToken, pageNumber string) (*ListChannelResponse, error) { + return c.PageChannelWithContext(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Channel records from the API. Request is executed immediately. +func (c *ApiService) PageChannelWithContext(ctx context.Context, ServiceSid string, params *ListChannelParams, pageToken, pageNumber string) (*ListChannelResponse, error) { path := "/v2/Services/{ServiceSid}/Channels" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -238,7 +250,7 @@ func (c *ApiService) PageChannel(ServiceSid string, params *ListChannelParams, p data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -255,7 +267,12 @@ func (c *ApiService) PageChannel(ServiceSid string, params *ListChannelParams, p // Lists Channel records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListChannel(ServiceSid string, params *ListChannelParams) ([]ChatV2Channel, error) { - response, errors := c.StreamChannel(ServiceSid, params) + return c.ListChannelWithContext(context.TODO(), ServiceSid, params) +} + +// Lists Channel records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListChannelWithContext(ctx context.Context, ServiceSid string, params *ListChannelParams) ([]ChatV2Channel, error) { + response, errors := c.StreamChannelWithContext(ctx, ServiceSid, params) records := make([]ChatV2Channel, 0) for record := range response { @@ -271,6 +288,11 @@ func (c *ApiService) ListChannel(ServiceSid string, params *ListChannelParams) ( // Streams Channel records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamChannel(ServiceSid string, params *ListChannelParams) (chan ChatV2Channel, chan error) { + return c.StreamChannelWithContext(context.TODO(), ServiceSid, params) +} + +// Streams Channel records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamChannelWithContext(ctx context.Context, ServiceSid string, params *ListChannelParams) (chan ChatV2Channel, chan error) { if params == nil { params = &ListChannelParams{} } @@ -279,19 +301,19 @@ func (c *ApiService) StreamChannel(ServiceSid string, params *ListChannelParams) recordChannel := make(chan ChatV2Channel, 1) errorChannel := make(chan error, 1) - response, err := c.PageChannel(ServiceSid, params, "", "") + response, err := c.PageChannelWithContext(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamChannel(response, params, recordChannel, errorChannel) + go c.streamChannelWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamChannel(response *ListChannelResponse, params *ListChannelParams, recordChannel chan ChatV2Channel, errorChannel chan error) { +func (c *ApiService) streamChannelWithContext(ctx context.Context, response *ListChannelResponse, params *ListChannelParams, recordChannel chan ChatV2Channel, errorChannel chan error) { curRecord := 1 for response != nil { @@ -306,7 +328,7 @@ func (c *ApiService) streamChannel(response *ListChannelResponse, params *ListCh } } - record, err := client.GetNext(c.baseURL, response, c.getNextListChannelResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListChannelResponseWithContext) if err != nil { errorChannel <- err break @@ -321,11 +343,11 @@ func (c *ApiService) streamChannel(response *ListChannelResponse, params *ListCh close(errorChannel) } -func (c *ApiService) getNextListChannelResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListChannelResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -386,8 +408,10 @@ func (params *UpdateChannelParams) SetCreatedBy(CreatedBy string) *UpdateChannel return params } -// func (c *ApiService) UpdateChannel(ServiceSid string, Sid string, params *UpdateChannelParams) (*ChatV2Channel, error) { + return c.UpdateChannelWithContext(context.TODO(), ServiceSid, Sid, params) +} +func (c *ApiService) UpdateChannelWithContext(ctx context.Context, ServiceSid string, Sid string, params *UpdateChannelParams) (*ChatV2Channel, error) { path := "/v2/Services/{ServiceSid}/Channels/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -419,7 +443,7 @@ func (c *ApiService) UpdateChannel(ServiceSid string, Sid string, params *Update if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/chat/v2/services_channels_invites.go b/rest/chat/v2/services_channels_invites.go index b34cc7a6a..7616f6584 100644 --- a/rest/chat/v2/services_channels_invites.go +++ b/rest/chat/v2/services_channels_invites.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -40,8 +41,10 @@ func (params *CreateInviteParams) SetRoleSid(RoleSid string) *CreateInviteParams return params } -// func (c *ApiService) CreateInvite(ServiceSid string, ChannelSid string, params *CreateInviteParams) (*ChatV2Invite, error) { + return c.CreateInviteWithContext(context.TODO(), ServiceSid, ChannelSid, params) +} +func (c *ApiService) CreateInviteWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *CreateInviteParams) (*ChatV2Invite, error) { path := "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Invites" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -58,7 +61,7 @@ func (c *ApiService) CreateInvite(ServiceSid string, ChannelSid string, params * data.Set("RoleSid", *params.RoleSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -73,8 +76,10 @@ func (c *ApiService) CreateInvite(ServiceSid string, ChannelSid string, params * return ps, err } -// func (c *ApiService) DeleteInvite(ServiceSid string, ChannelSid string, Sid string) error { + return c.DeleteInviteWithContext(context.TODO(), ServiceSid, ChannelSid, Sid) +} +func (c *ApiService) DeleteInviteWithContext(ctx context.Context, ServiceSid string, ChannelSid string, Sid string) error { path := "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Invites/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -85,7 +90,7 @@ func (c *ApiService) DeleteInvite(ServiceSid string, ChannelSid string, Sid stri "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -95,8 +100,10 @@ func (c *ApiService) DeleteInvite(ServiceSid string, ChannelSid string, Sid stri return nil } -// func (c *ApiService) FetchInvite(ServiceSid string, ChannelSid string, Sid string) (*ChatV2Invite, error) { + return c.FetchInviteWithContext(context.TODO(), ServiceSid, ChannelSid, Sid) +} +func (c *ApiService) FetchInviteWithContext(ctx context.Context, ServiceSid string, ChannelSid string, Sid string) (*ChatV2Invite, error) { path := "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Invites/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -107,7 +114,7 @@ func (c *ApiService) FetchInvite(ServiceSid string, ChannelSid string, Sid strin "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -147,6 +154,11 @@ func (params *ListInviteParams) SetLimit(Limit int) *ListInviteParams { // Retrieve a single page of Invite records from the API. Request is executed immediately. func (c *ApiService) PageInvite(ServiceSid string, ChannelSid string, params *ListInviteParams, pageToken, pageNumber string) (*ListInviteResponse, error) { + return c.PageInviteWithContext(context.TODO(), ServiceSid, ChannelSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Invite records from the API. Request is executed immediately. +func (c *ApiService) PageInviteWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *ListInviteParams, pageToken, pageNumber string) (*ListInviteResponse, error) { path := "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Invites" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -173,7 +185,7 @@ func (c *ApiService) PageInvite(ServiceSid string, ChannelSid string, params *Li data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -190,7 +202,12 @@ func (c *ApiService) PageInvite(ServiceSid string, ChannelSid string, params *Li // Lists Invite records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListInvite(ServiceSid string, ChannelSid string, params *ListInviteParams) ([]ChatV2Invite, error) { - response, errors := c.StreamInvite(ServiceSid, ChannelSid, params) + return c.ListInviteWithContext(context.TODO(), ServiceSid, ChannelSid, params) +} + +// Lists Invite records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListInviteWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *ListInviteParams) ([]ChatV2Invite, error) { + response, errors := c.StreamInviteWithContext(ctx, ServiceSid, ChannelSid, params) records := make([]ChatV2Invite, 0) for record := range response { @@ -206,6 +223,11 @@ func (c *ApiService) ListInvite(ServiceSid string, ChannelSid string, params *Li // Streams Invite records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamInvite(ServiceSid string, ChannelSid string, params *ListInviteParams) (chan ChatV2Invite, chan error) { + return c.StreamInviteWithContext(context.TODO(), ServiceSid, ChannelSid, params) +} + +// Streams Invite records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamInviteWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *ListInviteParams) (chan ChatV2Invite, chan error) { if params == nil { params = &ListInviteParams{} } @@ -214,19 +236,19 @@ func (c *ApiService) StreamInvite(ServiceSid string, ChannelSid string, params * recordChannel := make(chan ChatV2Invite, 1) errorChannel := make(chan error, 1) - response, err := c.PageInvite(ServiceSid, ChannelSid, params, "", "") + response, err := c.PageInviteWithContext(ctx, ServiceSid, ChannelSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamInvite(response, params, recordChannel, errorChannel) + go c.streamInviteWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamInvite(response *ListInviteResponse, params *ListInviteParams, recordChannel chan ChatV2Invite, errorChannel chan error) { +func (c *ApiService) streamInviteWithContext(ctx context.Context, response *ListInviteResponse, params *ListInviteParams, recordChannel chan ChatV2Invite, errorChannel chan error) { curRecord := 1 for response != nil { @@ -241,7 +263,7 @@ func (c *ApiService) streamInvite(response *ListInviteResponse, params *ListInvi } } - record, err := client.GetNext(c.baseURL, response, c.getNextListInviteResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListInviteResponseWithContext) if err != nil { errorChannel <- err break @@ -256,11 +278,11 @@ func (c *ApiService) streamInvite(response *ListInviteResponse, params *ListInvi close(errorChannel) } -func (c *ApiService) getNextListInviteResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListInviteResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/chat/v2/services_channels_members.go b/rest/chat/v2/services_channels_members.go index dd59be5b0..49c821486 100644 --- a/rest/chat/v2/services_channels_members.go +++ b/rest/chat/v2/services_channels_members.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -77,8 +78,10 @@ func (params *CreateMemberParams) SetAttributes(Attributes string) *CreateMember return params } -// func (c *ApiService) CreateMember(ServiceSid string, ChannelSid string, params *CreateMemberParams) (*ChatV2Member, error) { + return c.CreateMemberWithContext(context.TODO(), ServiceSid, ChannelSid, params) +} +func (c *ApiService) CreateMemberWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *CreateMemberParams) (*ChatV2Member, error) { path := "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Members" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -113,7 +116,7 @@ func (c *ApiService) CreateMember(ServiceSid string, ChannelSid string, params * if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -139,8 +142,10 @@ func (params *DeleteMemberParams) SetXTwilioWebhookEnabled(XTwilioWebhookEnabled return params } -// func (c *ApiService) DeleteMember(ServiceSid string, ChannelSid string, Sid string, params *DeleteMemberParams) error { + return c.DeleteMemberWithContext(context.TODO(), ServiceSid, ChannelSid, Sid, params) +} +func (c *ApiService) DeleteMemberWithContext(ctx context.Context, ServiceSid string, ChannelSid string, Sid string, params *DeleteMemberParams) error { path := "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -154,7 +159,7 @@ func (c *ApiService) DeleteMember(ServiceSid string, ChannelSid string, Sid stri if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -164,8 +169,10 @@ func (c *ApiService) DeleteMember(ServiceSid string, ChannelSid string, Sid stri return nil } -// func (c *ApiService) FetchMember(ServiceSid string, ChannelSid string, Sid string) (*ChatV2Member, error) { + return c.FetchMemberWithContext(context.TODO(), ServiceSid, ChannelSid, Sid) +} +func (c *ApiService) FetchMemberWithContext(ctx context.Context, ServiceSid string, ChannelSid string, Sid string) (*ChatV2Member, error) { path := "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -176,7 +183,7 @@ func (c *ApiService) FetchMember(ServiceSid string, ChannelSid string, Sid strin "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -216,6 +223,11 @@ func (params *ListMemberParams) SetLimit(Limit int) *ListMemberParams { // Retrieve a single page of Member records from the API. Request is executed immediately. func (c *ApiService) PageMember(ServiceSid string, ChannelSid string, params *ListMemberParams, pageToken, pageNumber string) (*ListMemberResponse, error) { + return c.PageMemberWithContext(context.TODO(), ServiceSid, ChannelSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Member records from the API. Request is executed immediately. +func (c *ApiService) PageMemberWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *ListMemberParams, pageToken, pageNumber string) (*ListMemberResponse, error) { path := "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Members" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -242,7 +254,7 @@ func (c *ApiService) PageMember(ServiceSid string, ChannelSid string, params *Li data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -259,7 +271,12 @@ func (c *ApiService) PageMember(ServiceSid string, ChannelSid string, params *Li // Lists Member records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListMember(ServiceSid string, ChannelSid string, params *ListMemberParams) ([]ChatV2Member, error) { - response, errors := c.StreamMember(ServiceSid, ChannelSid, params) + return c.ListMemberWithContext(context.TODO(), ServiceSid, ChannelSid, params) +} + +// Lists Member records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListMemberWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *ListMemberParams) ([]ChatV2Member, error) { + response, errors := c.StreamMemberWithContext(ctx, ServiceSid, ChannelSid, params) records := make([]ChatV2Member, 0) for record := range response { @@ -275,6 +292,11 @@ func (c *ApiService) ListMember(ServiceSid string, ChannelSid string, params *Li // Streams Member records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamMember(ServiceSid string, ChannelSid string, params *ListMemberParams) (chan ChatV2Member, chan error) { + return c.StreamMemberWithContext(context.TODO(), ServiceSid, ChannelSid, params) +} + +// Streams Member records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamMemberWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *ListMemberParams) (chan ChatV2Member, chan error) { if params == nil { params = &ListMemberParams{} } @@ -283,19 +305,19 @@ func (c *ApiService) StreamMember(ServiceSid string, ChannelSid string, params * recordChannel := make(chan ChatV2Member, 1) errorChannel := make(chan error, 1) - response, err := c.PageMember(ServiceSid, ChannelSid, params, "", "") + response, err := c.PageMemberWithContext(ctx, ServiceSid, ChannelSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamMember(response, params, recordChannel, errorChannel) + go c.streamMemberWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamMember(response *ListMemberResponse, params *ListMemberParams, recordChannel chan ChatV2Member, errorChannel chan error) { +func (c *ApiService) streamMemberWithContext(ctx context.Context, response *ListMemberResponse, params *ListMemberParams, recordChannel chan ChatV2Member, errorChannel chan error) { curRecord := 1 for response != nil { @@ -310,7 +332,7 @@ func (c *ApiService) streamMember(response *ListMemberResponse, params *ListMemb } } - record, err := client.GetNext(c.baseURL, response, c.getNextListMemberResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListMemberResponseWithContext) if err != nil { errorChannel <- err break @@ -325,11 +347,11 @@ func (c *ApiService) streamMember(response *ListMemberResponse, params *ListMemb close(errorChannel) } -func (c *ApiService) getNextListMemberResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListMemberResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -390,8 +412,10 @@ func (params *UpdateMemberParams) SetAttributes(Attributes string) *UpdateMember return params } -// func (c *ApiService) UpdateMember(ServiceSid string, ChannelSid string, Sid string, params *UpdateMemberParams) (*ChatV2Member, error) { + return c.UpdateMemberWithContext(context.TODO(), ServiceSid, ChannelSid, Sid, params) +} +func (c *ApiService) UpdateMemberWithContext(ctx context.Context, ServiceSid string, ChannelSid string, Sid string, params *UpdateMemberParams) (*ChatV2Member, error) { path := "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -424,7 +448,7 @@ func (c *ApiService) UpdateMember(ServiceSid string, ChannelSid string, Sid stri if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/chat/v2/services_channels_messages.go b/rest/chat/v2/services_channels_messages.go index 96ee19b92..e46ea3d3b 100644 --- a/rest/chat/v2/services_channels_messages.go +++ b/rest/chat/v2/services_channels_messages.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -77,8 +78,10 @@ func (params *CreateMessageParams) SetMediaSid(MediaSid string) *CreateMessagePa return params } -// func (c *ApiService) CreateMessage(ServiceSid string, ChannelSid string, params *CreateMessageParams) (*ChatV2Message, error) { + return c.CreateMessageWithContext(context.TODO(), ServiceSid, ChannelSid, params) +} +func (c *ApiService) CreateMessageWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *CreateMessageParams) (*ChatV2Message, error) { path := "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -113,7 +116,7 @@ func (c *ApiService) CreateMessage(ServiceSid string, ChannelSid string, params if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -139,8 +142,10 @@ func (params *DeleteMessageParams) SetXTwilioWebhookEnabled(XTwilioWebhookEnable return params } -// func (c *ApiService) DeleteMessage(ServiceSid string, ChannelSid string, Sid string, params *DeleteMessageParams) error { + return c.DeleteMessageWithContext(context.TODO(), ServiceSid, ChannelSid, Sid, params) +} +func (c *ApiService) DeleteMessageWithContext(ctx context.Context, ServiceSid string, ChannelSid string, Sid string, params *DeleteMessageParams) error { path := "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -154,7 +159,7 @@ func (c *ApiService) DeleteMessage(ServiceSid string, ChannelSid string, Sid str if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -164,8 +169,10 @@ func (c *ApiService) DeleteMessage(ServiceSid string, ChannelSid string, Sid str return nil } -// func (c *ApiService) FetchMessage(ServiceSid string, ChannelSid string, Sid string) (*ChatV2Message, error) { + return c.FetchMessageWithContext(context.TODO(), ServiceSid, ChannelSid, Sid) +} +func (c *ApiService) FetchMessageWithContext(ctx context.Context, ServiceSid string, ChannelSid string, Sid string) (*ChatV2Message, error) { path := "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -176,7 +183,7 @@ func (c *ApiService) FetchMessage(ServiceSid string, ChannelSid string, Sid stri "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -216,6 +223,11 @@ func (params *ListMessageParams) SetLimit(Limit int) *ListMessageParams { // Retrieve a single page of Message records from the API. Request is executed immediately. func (c *ApiService) PageMessage(ServiceSid string, ChannelSid string, params *ListMessageParams, pageToken, pageNumber string) (*ListMessageResponse, error) { + return c.PageMessageWithContext(context.TODO(), ServiceSid, ChannelSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Message records from the API. Request is executed immediately. +func (c *ApiService) PageMessageWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *ListMessageParams, pageToken, pageNumber string) (*ListMessageResponse, error) { path := "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -240,7 +252,7 @@ func (c *ApiService) PageMessage(ServiceSid string, ChannelSid string, params *L data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -257,7 +269,12 @@ func (c *ApiService) PageMessage(ServiceSid string, ChannelSid string, params *L // Lists Message records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListMessage(ServiceSid string, ChannelSid string, params *ListMessageParams) ([]ChatV2Message, error) { - response, errors := c.StreamMessage(ServiceSid, ChannelSid, params) + return c.ListMessageWithContext(context.TODO(), ServiceSid, ChannelSid, params) +} + +// Lists Message records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListMessageWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *ListMessageParams) ([]ChatV2Message, error) { + response, errors := c.StreamMessageWithContext(ctx, ServiceSid, ChannelSid, params) records := make([]ChatV2Message, 0) for record := range response { @@ -273,6 +290,11 @@ func (c *ApiService) ListMessage(ServiceSid string, ChannelSid string, params *L // Streams Message records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamMessage(ServiceSid string, ChannelSid string, params *ListMessageParams) (chan ChatV2Message, chan error) { + return c.StreamMessageWithContext(context.TODO(), ServiceSid, ChannelSid, params) +} + +// Streams Message records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamMessageWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *ListMessageParams) (chan ChatV2Message, chan error) { if params == nil { params = &ListMessageParams{} } @@ -281,19 +303,19 @@ func (c *ApiService) StreamMessage(ServiceSid string, ChannelSid string, params recordChannel := make(chan ChatV2Message, 1) errorChannel := make(chan error, 1) - response, err := c.PageMessage(ServiceSid, ChannelSid, params, "", "") + response, err := c.PageMessageWithContext(ctx, ServiceSid, ChannelSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamMessage(response, params, recordChannel, errorChannel) + go c.streamMessageWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamMessage(response *ListMessageResponse, params *ListMessageParams, recordChannel chan ChatV2Message, errorChannel chan error) { +func (c *ApiService) streamMessageWithContext(ctx context.Context, response *ListMessageResponse, params *ListMessageParams, recordChannel chan ChatV2Message, errorChannel chan error) { curRecord := 1 for response != nil { @@ -308,7 +330,7 @@ func (c *ApiService) streamMessage(response *ListMessageResponse, params *ListMe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListMessageResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListMessageResponseWithContext) if err != nil { errorChannel <- err break @@ -323,11 +345,11 @@ func (c *ApiService) streamMessage(response *ListMessageResponse, params *ListMe close(errorChannel) } -func (c *ApiService) getNextListMessageResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListMessageResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -388,8 +410,10 @@ func (params *UpdateMessageParams) SetFrom(From string) *UpdateMessageParams { return params } -// func (c *ApiService) UpdateMessage(ServiceSid string, ChannelSid string, Sid string, params *UpdateMessageParams) (*ChatV2Message, error) { + return c.UpdateMessageWithContext(context.TODO(), ServiceSid, ChannelSid, Sid, params) +} +func (c *ApiService) UpdateMessageWithContext(ctx context.Context, ServiceSid string, ChannelSid string, Sid string, params *UpdateMessageParams) (*ChatV2Message, error) { path := "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -422,7 +446,7 @@ func (c *ApiService) UpdateMessage(ServiceSid string, ChannelSid string, Sid str if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/chat/v2/services_channels_webhooks.go b/rest/chat/v2/services_channels_webhooks.go index 3106fa64b..06fe30dba 100644 --- a/rest/chat/v2/services_channels_webhooks.go +++ b/rest/chat/v2/services_channels_webhooks.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -70,8 +71,10 @@ func (params *CreateChannelWebhookParams) SetConfigurationRetryCount(Configurati return params } -// func (c *ApiService) CreateChannelWebhook(ServiceSid string, ChannelSid string, params *CreateChannelWebhookParams) (*ChatV2ChannelWebhook, error) { + return c.CreateChannelWebhookWithContext(context.TODO(), ServiceSid, ChannelSid, params) +} +func (c *ApiService) CreateChannelWebhookWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *CreateChannelWebhookParams) (*ChatV2ChannelWebhook, error) { path := "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Webhooks" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -107,7 +110,7 @@ func (c *ApiService) CreateChannelWebhook(ServiceSid string, ChannelSid string, data.Set("Configuration.RetryCount", fmt.Sprint(*params.ConfigurationRetryCount)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -122,8 +125,10 @@ func (c *ApiService) CreateChannelWebhook(ServiceSid string, ChannelSid string, return ps, err } -// func (c *ApiService) DeleteChannelWebhook(ServiceSid string, ChannelSid string, Sid string) error { + return c.DeleteChannelWebhookWithContext(context.TODO(), ServiceSid, ChannelSid, Sid) +} +func (c *ApiService) DeleteChannelWebhookWithContext(ctx context.Context, ServiceSid string, ChannelSid string, Sid string) error { path := "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Webhooks/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -134,7 +139,7 @@ func (c *ApiService) DeleteChannelWebhook(ServiceSid string, ChannelSid string, "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -144,8 +149,10 @@ func (c *ApiService) DeleteChannelWebhook(ServiceSid string, ChannelSid string, return nil } -// func (c *ApiService) FetchChannelWebhook(ServiceSid string, ChannelSid string, Sid string) (*ChatV2ChannelWebhook, error) { + return c.FetchChannelWebhookWithContext(context.TODO(), ServiceSid, ChannelSid, Sid) +} +func (c *ApiService) FetchChannelWebhookWithContext(ctx context.Context, ServiceSid string, ChannelSid string, Sid string) (*ChatV2ChannelWebhook, error) { path := "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Webhooks/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -156,7 +163,7 @@ func (c *ApiService) FetchChannelWebhook(ServiceSid string, ChannelSid string, S "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -190,6 +197,11 @@ func (params *ListChannelWebhookParams) SetLimit(Limit int) *ListChannelWebhookP // Retrieve a single page of ChannelWebhook records from the API. Request is executed immediately. func (c *ApiService) PageChannelWebhook(ServiceSid string, ChannelSid string, params *ListChannelWebhookParams, pageToken, pageNumber string) (*ListChannelWebhookResponse, error) { + return c.PageChannelWebhookWithContext(context.TODO(), ServiceSid, ChannelSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ChannelWebhook records from the API. Request is executed immediately. +func (c *ApiService) PageChannelWebhookWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *ListChannelWebhookParams, pageToken, pageNumber string) (*ListChannelWebhookResponse, error) { path := "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Webhooks" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -211,7 +223,7 @@ func (c *ApiService) PageChannelWebhook(ServiceSid string, ChannelSid string, pa data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -228,7 +240,12 @@ func (c *ApiService) PageChannelWebhook(ServiceSid string, ChannelSid string, pa // Lists ChannelWebhook records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListChannelWebhook(ServiceSid string, ChannelSid string, params *ListChannelWebhookParams) ([]ChatV2ChannelWebhook, error) { - response, errors := c.StreamChannelWebhook(ServiceSid, ChannelSid, params) + return c.ListChannelWebhookWithContext(context.TODO(), ServiceSid, ChannelSid, params) +} + +// Lists ChannelWebhook records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListChannelWebhookWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *ListChannelWebhookParams) ([]ChatV2ChannelWebhook, error) { + response, errors := c.StreamChannelWebhookWithContext(ctx, ServiceSid, ChannelSid, params) records := make([]ChatV2ChannelWebhook, 0) for record := range response { @@ -244,6 +261,11 @@ func (c *ApiService) ListChannelWebhook(ServiceSid string, ChannelSid string, pa // Streams ChannelWebhook records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamChannelWebhook(ServiceSid string, ChannelSid string, params *ListChannelWebhookParams) (chan ChatV2ChannelWebhook, chan error) { + return c.StreamChannelWebhookWithContext(context.TODO(), ServiceSid, ChannelSid, params) +} + +// Streams ChannelWebhook records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamChannelWebhookWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *ListChannelWebhookParams) (chan ChatV2ChannelWebhook, chan error) { if params == nil { params = &ListChannelWebhookParams{} } @@ -252,19 +274,19 @@ func (c *ApiService) StreamChannelWebhook(ServiceSid string, ChannelSid string, recordChannel := make(chan ChatV2ChannelWebhook, 1) errorChannel := make(chan error, 1) - response, err := c.PageChannelWebhook(ServiceSid, ChannelSid, params, "", "") + response, err := c.PageChannelWebhookWithContext(ctx, ServiceSid, ChannelSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamChannelWebhook(response, params, recordChannel, errorChannel) + go c.streamChannelWebhookWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamChannelWebhook(response *ListChannelWebhookResponse, params *ListChannelWebhookParams, recordChannel chan ChatV2ChannelWebhook, errorChannel chan error) { +func (c *ApiService) streamChannelWebhookWithContext(ctx context.Context, response *ListChannelWebhookResponse, params *ListChannelWebhookParams, recordChannel chan ChatV2ChannelWebhook, errorChannel chan error) { curRecord := 1 for response != nil { @@ -279,7 +301,7 @@ func (c *ApiService) streamChannelWebhook(response *ListChannelWebhookResponse, } } - record, err := client.GetNext(c.baseURL, response, c.getNextListChannelWebhookResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListChannelWebhookResponseWithContext) if err != nil { errorChannel <- err break @@ -294,11 +316,11 @@ func (c *ApiService) streamChannelWebhook(response *ListChannelWebhookResponse, close(errorChannel) } -func (c *ApiService) getNextListChannelWebhookResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListChannelWebhookResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -353,8 +375,10 @@ func (params *UpdateChannelWebhookParams) SetConfigurationRetryCount(Configurati return params } -// func (c *ApiService) UpdateChannelWebhook(ServiceSid string, ChannelSid string, Sid string, params *UpdateChannelWebhookParams) (*ChatV2ChannelWebhook, error) { + return c.UpdateChannelWebhookWithContext(context.TODO(), ServiceSid, ChannelSid, Sid, params) +} +func (c *ApiService) UpdateChannelWebhookWithContext(ctx context.Context, ServiceSid string, ChannelSid string, Sid string, params *UpdateChannelWebhookParams) (*ChatV2ChannelWebhook, error) { path := "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Webhooks/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -388,7 +412,7 @@ func (c *ApiService) UpdateChannelWebhook(ServiceSid string, ChannelSid string, data.Set("Configuration.RetryCount", fmt.Sprint(*params.ConfigurationRetryCount)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/chat/v2/services_roles.go b/rest/chat/v2/services_roles.go index 5d0cd884a..31e19c0bf 100644 --- a/rest/chat/v2/services_roles.go +++ b/rest/chat/v2/services_roles.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -46,8 +47,10 @@ func (params *CreateRoleParams) SetPermission(Permission []string) *CreateRolePa return params } -// func (c *ApiService) CreateRole(ServiceSid string, params *CreateRoleParams) (*ChatV2Role, error) { + return c.CreateRoleWithContext(context.TODO(), ServiceSid, params) +} +func (c *ApiService) CreateRoleWithContext(ctx context.Context, ServiceSid string, params *CreateRoleParams) (*ChatV2Role, error) { path := "/v2/Services/{ServiceSid}/Roles" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -68,7 +71,7 @@ func (c *ApiService) CreateRole(ServiceSid string, params *CreateRoleParams) (*C } } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -83,8 +86,10 @@ func (c *ApiService) CreateRole(ServiceSid string, params *CreateRoleParams) (*C return ps, err } -// func (c *ApiService) DeleteRole(ServiceSid string, Sid string) error { + return c.DeleteRoleWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) DeleteRoleWithContext(ctx context.Context, ServiceSid string, Sid string) error { path := "/v2/Services/{ServiceSid}/Roles/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -94,7 +99,7 @@ func (c *ApiService) DeleteRole(ServiceSid string, Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -104,8 +109,10 @@ func (c *ApiService) DeleteRole(ServiceSid string, Sid string) error { return nil } -// func (c *ApiService) FetchRole(ServiceSid string, Sid string) (*ChatV2Role, error) { + return c.FetchRoleWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) FetchRoleWithContext(ctx context.Context, ServiceSid string, Sid string) (*ChatV2Role, error) { path := "/v2/Services/{ServiceSid}/Roles/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -115,7 +122,7 @@ func (c *ApiService) FetchRole(ServiceSid string, Sid string) (*ChatV2Role, erro "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -149,6 +156,11 @@ func (params *ListRoleParams) SetLimit(Limit int) *ListRoleParams { // Retrieve a single page of Role records from the API. Request is executed immediately. func (c *ApiService) PageRole(ServiceSid string, params *ListRoleParams, pageToken, pageNumber string) (*ListRoleResponse, error) { + return c.PageRoleWithContext(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Role records from the API. Request is executed immediately. +func (c *ApiService) PageRoleWithContext(ctx context.Context, ServiceSid string, params *ListRoleParams, pageToken, pageNumber string) (*ListRoleResponse, error) { path := "/v2/Services/{ServiceSid}/Roles" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -169,7 +181,7 @@ func (c *ApiService) PageRole(ServiceSid string, params *ListRoleParams, pageTok data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -186,7 +198,12 @@ func (c *ApiService) PageRole(ServiceSid string, params *ListRoleParams, pageTok // Lists Role records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListRole(ServiceSid string, params *ListRoleParams) ([]ChatV2Role, error) { - response, errors := c.StreamRole(ServiceSid, params) + return c.ListRoleWithContext(context.TODO(), ServiceSid, params) +} + +// Lists Role records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListRoleWithContext(ctx context.Context, ServiceSid string, params *ListRoleParams) ([]ChatV2Role, error) { + response, errors := c.StreamRoleWithContext(ctx, ServiceSid, params) records := make([]ChatV2Role, 0) for record := range response { @@ -202,6 +219,11 @@ func (c *ApiService) ListRole(ServiceSid string, params *ListRoleParams) ([]Chat // Streams Role records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamRole(ServiceSid string, params *ListRoleParams) (chan ChatV2Role, chan error) { + return c.StreamRoleWithContext(context.TODO(), ServiceSid, params) +} + +// Streams Role records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamRoleWithContext(ctx context.Context, ServiceSid string, params *ListRoleParams) (chan ChatV2Role, chan error) { if params == nil { params = &ListRoleParams{} } @@ -210,19 +232,19 @@ func (c *ApiService) StreamRole(ServiceSid string, params *ListRoleParams) (chan recordChannel := make(chan ChatV2Role, 1) errorChannel := make(chan error, 1) - response, err := c.PageRole(ServiceSid, params, "", "") + response, err := c.PageRoleWithContext(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamRole(response, params, recordChannel, errorChannel) + go c.streamRoleWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamRole(response *ListRoleResponse, params *ListRoleParams, recordChannel chan ChatV2Role, errorChannel chan error) { +func (c *ApiService) streamRoleWithContext(ctx context.Context, response *ListRoleResponse, params *ListRoleParams, recordChannel chan ChatV2Role, errorChannel chan error) { curRecord := 1 for response != nil { @@ -237,7 +259,7 @@ func (c *ApiService) streamRole(response *ListRoleResponse, params *ListRolePara } } - record, err := client.GetNext(c.baseURL, response, c.getNextListRoleResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListRoleResponseWithContext) if err != nil { errorChannel <- err break @@ -252,11 +274,11 @@ func (c *ApiService) streamRole(response *ListRoleResponse, params *ListRolePara close(errorChannel) } -func (c *ApiService) getNextListRoleResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListRoleResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -281,8 +303,10 @@ func (params *UpdateRoleParams) SetPermission(Permission []string) *UpdateRolePa return params } -// func (c *ApiService) UpdateRole(ServiceSid string, Sid string, params *UpdateRoleParams) (*ChatV2Role, error) { + return c.UpdateRoleWithContext(context.TODO(), ServiceSid, Sid, params) +} +func (c *ApiService) UpdateRoleWithContext(ctx context.Context, ServiceSid string, Sid string, params *UpdateRoleParams) (*ChatV2Role, error) { path := "/v2/Services/{ServiceSid}/Roles/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -298,7 +322,7 @@ func (c *ApiService) UpdateRole(ServiceSid string, Sid string, params *UpdateRol } } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/chat/v2/services_users.go b/rest/chat/v2/services_users.go index 0f388a6df..2a04050a8 100644 --- a/rest/chat/v2/services_users.go +++ b/rest/chat/v2/services_users.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -58,8 +59,10 @@ func (params *CreateUserParams) SetFriendlyName(FriendlyName string) *CreateUser return params } -// func (c *ApiService) CreateUser(ServiceSid string, params *CreateUserParams) (*ChatV2User, error) { + return c.CreateUserWithContext(context.TODO(), ServiceSid, params) +} +func (c *ApiService) CreateUserWithContext(ctx context.Context, ServiceSid string, params *CreateUserParams) (*ChatV2User, error) { path := "/v2/Services/{ServiceSid}/Users" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -84,7 +87,7 @@ func (c *ApiService) CreateUser(ServiceSid string, params *CreateUserParams) (*C if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -99,8 +102,10 @@ func (c *ApiService) CreateUser(ServiceSid string, params *CreateUserParams) (*C return ps, err } -// func (c *ApiService) DeleteUser(ServiceSid string, Sid string) error { + return c.DeleteUserWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) DeleteUserWithContext(ctx context.Context, ServiceSid string, Sid string) error { path := "/v2/Services/{ServiceSid}/Users/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -110,7 +115,7 @@ func (c *ApiService) DeleteUser(ServiceSid string, Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -120,8 +125,10 @@ func (c *ApiService) DeleteUser(ServiceSid string, Sid string) error { return nil } -// func (c *ApiService) FetchUser(ServiceSid string, Sid string) (*ChatV2User, error) { + return c.FetchUserWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) FetchUserWithContext(ctx context.Context, ServiceSid string, Sid string) (*ChatV2User, error) { path := "/v2/Services/{ServiceSid}/Users/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -131,7 +138,7 @@ func (c *ApiService) FetchUser(ServiceSid string, Sid string) (*ChatV2User, erro "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -165,6 +172,11 @@ func (params *ListUserParams) SetLimit(Limit int) *ListUserParams { // Retrieve a single page of User records from the API. Request is executed immediately. func (c *ApiService) PageUser(ServiceSid string, params *ListUserParams, pageToken, pageNumber string) (*ListUserResponse, error) { + return c.PageUserWithContext(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of User records from the API. Request is executed immediately. +func (c *ApiService) PageUserWithContext(ctx context.Context, ServiceSid string, params *ListUserParams, pageToken, pageNumber string) (*ListUserResponse, error) { path := "/v2/Services/{ServiceSid}/Users" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -185,7 +197,7 @@ func (c *ApiService) PageUser(ServiceSid string, params *ListUserParams, pageTok data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -202,7 +214,12 @@ func (c *ApiService) PageUser(ServiceSid string, params *ListUserParams, pageTok // Lists User records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListUser(ServiceSid string, params *ListUserParams) ([]ChatV2User, error) { - response, errors := c.StreamUser(ServiceSid, params) + return c.ListUserWithContext(context.TODO(), ServiceSid, params) +} + +// Lists User records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListUserWithContext(ctx context.Context, ServiceSid string, params *ListUserParams) ([]ChatV2User, error) { + response, errors := c.StreamUserWithContext(ctx, ServiceSid, params) records := make([]ChatV2User, 0) for record := range response { @@ -218,6 +235,11 @@ func (c *ApiService) ListUser(ServiceSid string, params *ListUserParams) ([]Chat // Streams User records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamUser(ServiceSid string, params *ListUserParams) (chan ChatV2User, chan error) { + return c.StreamUserWithContext(context.TODO(), ServiceSid, params) +} + +// Streams User records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamUserWithContext(ctx context.Context, ServiceSid string, params *ListUserParams) (chan ChatV2User, chan error) { if params == nil { params = &ListUserParams{} } @@ -226,19 +248,19 @@ func (c *ApiService) StreamUser(ServiceSid string, params *ListUserParams) (chan recordChannel := make(chan ChatV2User, 1) errorChannel := make(chan error, 1) - response, err := c.PageUser(ServiceSid, params, "", "") + response, err := c.PageUserWithContext(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUser(response, params, recordChannel, errorChannel) + go c.streamUserWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamUser(response *ListUserResponse, params *ListUserParams, recordChannel chan ChatV2User, errorChannel chan error) { +func (c *ApiService) streamUserWithContext(ctx context.Context, response *ListUserResponse, params *ListUserParams, recordChannel chan ChatV2User, errorChannel chan error) { curRecord := 1 for response != nil { @@ -253,7 +275,7 @@ func (c *ApiService) streamUser(response *ListUserResponse, params *ListUserPara } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUserResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListUserResponseWithContext) if err != nil { errorChannel <- err break @@ -268,11 +290,11 @@ func (c *ApiService) streamUser(response *ListUserResponse, params *ListUserPara close(errorChannel) } -func (c *ApiService) getNextListUserResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUserResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -315,8 +337,10 @@ func (params *UpdateUserParams) SetFriendlyName(FriendlyName string) *UpdateUser return params } -// func (c *ApiService) UpdateUser(ServiceSid string, Sid string, params *UpdateUserParams) (*ChatV2User, error) { + return c.UpdateUserWithContext(context.TODO(), ServiceSid, Sid, params) +} +func (c *ApiService) UpdateUserWithContext(ctx context.Context, ServiceSid string, Sid string, params *UpdateUserParams) (*ChatV2User, error) { path := "/v2/Services/{ServiceSid}/Users/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -339,7 +363,7 @@ func (c *ApiService) UpdateUser(ServiceSid string, Sid string, params *UpdateUse if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/chat/v2/services_users_bindings.go b/rest/chat/v2/services_users_bindings.go index 46e61033c..5a218372f 100644 --- a/rest/chat/v2/services_users_bindings.go +++ b/rest/chat/v2/services_users_bindings.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -23,8 +24,10 @@ import ( "github.com/twilio/twilio-go/client" ) -// func (c *ApiService) DeleteUserBinding(ServiceSid string, UserSid string, Sid string) error { + return c.DeleteUserBindingWithContext(context.TODO(), ServiceSid, UserSid, Sid) +} +func (c *ApiService) DeleteUserBindingWithContext(ctx context.Context, ServiceSid string, UserSid string, Sid string) error { path := "/v2/Services/{ServiceSid}/Users/{UserSid}/Bindings/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"UserSid"+"}", UserSid, -1) @@ -35,7 +38,7 @@ func (c *ApiService) DeleteUserBinding(ServiceSid string, UserSid string, Sid st "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -45,8 +48,10 @@ func (c *ApiService) DeleteUserBinding(ServiceSid string, UserSid string, Sid st return nil } -// func (c *ApiService) FetchUserBinding(ServiceSid string, UserSid string, Sid string) (*ChatV2UserBinding, error) { + return c.FetchUserBindingWithContext(context.TODO(), ServiceSid, UserSid, Sid) +} +func (c *ApiService) FetchUserBindingWithContext(ctx context.Context, ServiceSid string, UserSid string, Sid string) (*ChatV2UserBinding, error) { path := "/v2/Services/{ServiceSid}/Users/{UserSid}/Bindings/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"UserSid"+"}", UserSid, -1) @@ -57,7 +62,7 @@ func (c *ApiService) FetchUserBinding(ServiceSid string, UserSid string, Sid str "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -97,6 +102,11 @@ func (params *ListUserBindingParams) SetLimit(Limit int) *ListUserBindingParams // Retrieve a single page of UserBinding records from the API. Request is executed immediately. func (c *ApiService) PageUserBinding(ServiceSid string, UserSid string, params *ListUserBindingParams, pageToken, pageNumber string) (*ListUserBindingResponse, error) { + return c.PageUserBindingWithContext(context.TODO(), ServiceSid, UserSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of UserBinding records from the API. Request is executed immediately. +func (c *ApiService) PageUserBindingWithContext(ctx context.Context, ServiceSid string, UserSid string, params *ListUserBindingParams, pageToken, pageNumber string) (*ListUserBindingResponse, error) { path := "/v2/Services/{ServiceSid}/Users/{UserSid}/Bindings" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -123,7 +133,7 @@ func (c *ApiService) PageUserBinding(ServiceSid string, UserSid string, params * data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -140,7 +150,12 @@ func (c *ApiService) PageUserBinding(ServiceSid string, UserSid string, params * // Lists UserBinding records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListUserBinding(ServiceSid string, UserSid string, params *ListUserBindingParams) ([]ChatV2UserBinding, error) { - response, errors := c.StreamUserBinding(ServiceSid, UserSid, params) + return c.ListUserBindingWithContext(context.TODO(), ServiceSid, UserSid, params) +} + +// Lists UserBinding records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListUserBindingWithContext(ctx context.Context, ServiceSid string, UserSid string, params *ListUserBindingParams) ([]ChatV2UserBinding, error) { + response, errors := c.StreamUserBindingWithContext(ctx, ServiceSid, UserSid, params) records := make([]ChatV2UserBinding, 0) for record := range response { @@ -156,6 +171,11 @@ func (c *ApiService) ListUserBinding(ServiceSid string, UserSid string, params * // Streams UserBinding records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamUserBinding(ServiceSid string, UserSid string, params *ListUserBindingParams) (chan ChatV2UserBinding, chan error) { + return c.StreamUserBindingWithContext(context.TODO(), ServiceSid, UserSid, params) +} + +// Streams UserBinding records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamUserBindingWithContext(ctx context.Context, ServiceSid string, UserSid string, params *ListUserBindingParams) (chan ChatV2UserBinding, chan error) { if params == nil { params = &ListUserBindingParams{} } @@ -164,19 +184,19 @@ func (c *ApiService) StreamUserBinding(ServiceSid string, UserSid string, params recordChannel := make(chan ChatV2UserBinding, 1) errorChannel := make(chan error, 1) - response, err := c.PageUserBinding(ServiceSid, UserSid, params, "", "") + response, err := c.PageUserBindingWithContext(ctx, ServiceSid, UserSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUserBinding(response, params, recordChannel, errorChannel) + go c.streamUserBindingWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamUserBinding(response *ListUserBindingResponse, params *ListUserBindingParams, recordChannel chan ChatV2UserBinding, errorChannel chan error) { +func (c *ApiService) streamUserBindingWithContext(ctx context.Context, response *ListUserBindingResponse, params *ListUserBindingParams, recordChannel chan ChatV2UserBinding, errorChannel chan error) { curRecord := 1 for response != nil { @@ -191,7 +211,7 @@ func (c *ApiService) streamUserBinding(response *ListUserBindingResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUserBindingResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListUserBindingResponseWithContext) if err != nil { errorChannel <- err break @@ -206,11 +226,11 @@ func (c *ApiService) streamUserBinding(response *ListUserBindingResponse, params close(errorChannel) } -func (c *ApiService) getNextListUserBindingResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUserBindingResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/chat/v2/services_users_channels.go b/rest/chat/v2/services_users_channels.go index 31317b73e..9c1a8f66a 100644 --- a/rest/chat/v2/services_users_channels.go +++ b/rest/chat/v2/services_users_channels.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -37,6 +38,9 @@ func (params *DeleteUserChannelParams) SetXTwilioWebhookEnabled(XTwilioWebhookEn // Removes User from selected Channel. func (c *ApiService) DeleteUserChannel(ServiceSid string, UserSid string, ChannelSid string, params *DeleteUserChannelParams) error { + return c.DeleteUserChannelWithContext(context.TODO(), ServiceSid, UserSid, ChannelSid, params) +} +func (c *ApiService) DeleteUserChannelWithContext(ctx context.Context, ServiceSid string, UserSid string, ChannelSid string, params *DeleteUserChannelParams) error { path := "/v2/Services/{ServiceSid}/Users/{UserSid}/Channels/{ChannelSid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"UserSid"+"}", UserSid, -1) @@ -50,7 +54,7 @@ func (c *ApiService) DeleteUserChannel(ServiceSid string, UserSid string, Channe if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -60,8 +64,10 @@ func (c *ApiService) DeleteUserChannel(ServiceSid string, UserSid string, Channe return nil } -// func (c *ApiService) FetchUserChannel(ServiceSid string, UserSid string, ChannelSid string) (*ChatV2UserChannel, error) { + return c.FetchUserChannelWithContext(context.TODO(), ServiceSid, UserSid, ChannelSid) +} +func (c *ApiService) FetchUserChannelWithContext(ctx context.Context, ServiceSid string, UserSid string, ChannelSid string) (*ChatV2UserChannel, error) { path := "/v2/Services/{ServiceSid}/Users/{UserSid}/Channels/{ChannelSid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"UserSid"+"}", UserSid, -1) @@ -72,7 +78,7 @@ func (c *ApiService) FetchUserChannel(ServiceSid string, UserSid string, Channel "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -106,6 +112,11 @@ func (params *ListUserChannelParams) SetLimit(Limit int) *ListUserChannelParams // Retrieve a single page of UserChannel records from the API. Request is executed immediately. func (c *ApiService) PageUserChannel(ServiceSid string, UserSid string, params *ListUserChannelParams, pageToken, pageNumber string) (*ListUserChannelResponse, error) { + return c.PageUserChannelWithContext(context.TODO(), ServiceSid, UserSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of UserChannel records from the API. Request is executed immediately. +func (c *ApiService) PageUserChannelWithContext(ctx context.Context, ServiceSid string, UserSid string, params *ListUserChannelParams, pageToken, pageNumber string) (*ListUserChannelResponse, error) { path := "/v2/Services/{ServiceSid}/Users/{UserSid}/Channels" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -127,7 +138,7 @@ func (c *ApiService) PageUserChannel(ServiceSid string, UserSid string, params * data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -144,7 +155,12 @@ func (c *ApiService) PageUserChannel(ServiceSid string, UserSid string, params * // Lists UserChannel records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListUserChannel(ServiceSid string, UserSid string, params *ListUserChannelParams) ([]ChatV2UserChannel, error) { - response, errors := c.StreamUserChannel(ServiceSid, UserSid, params) + return c.ListUserChannelWithContext(context.TODO(), ServiceSid, UserSid, params) +} + +// Lists UserChannel records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListUserChannelWithContext(ctx context.Context, ServiceSid string, UserSid string, params *ListUserChannelParams) ([]ChatV2UserChannel, error) { + response, errors := c.StreamUserChannelWithContext(ctx, ServiceSid, UserSid, params) records := make([]ChatV2UserChannel, 0) for record := range response { @@ -160,6 +176,11 @@ func (c *ApiService) ListUserChannel(ServiceSid string, UserSid string, params * // Streams UserChannel records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamUserChannel(ServiceSid string, UserSid string, params *ListUserChannelParams) (chan ChatV2UserChannel, chan error) { + return c.StreamUserChannelWithContext(context.TODO(), ServiceSid, UserSid, params) +} + +// Streams UserChannel records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamUserChannelWithContext(ctx context.Context, ServiceSid string, UserSid string, params *ListUserChannelParams) (chan ChatV2UserChannel, chan error) { if params == nil { params = &ListUserChannelParams{} } @@ -168,19 +189,19 @@ func (c *ApiService) StreamUserChannel(ServiceSid string, UserSid string, params recordChannel := make(chan ChatV2UserChannel, 1) errorChannel := make(chan error, 1) - response, err := c.PageUserChannel(ServiceSid, UserSid, params, "", "") + response, err := c.PageUserChannelWithContext(ctx, ServiceSid, UserSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUserChannel(response, params, recordChannel, errorChannel) + go c.streamUserChannelWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamUserChannel(response *ListUserChannelResponse, params *ListUserChannelParams, recordChannel chan ChatV2UserChannel, errorChannel chan error) { +func (c *ApiService) streamUserChannelWithContext(ctx context.Context, response *ListUserChannelResponse, params *ListUserChannelParams, recordChannel chan ChatV2UserChannel, errorChannel chan error) { curRecord := 1 for response != nil { @@ -195,7 +216,7 @@ func (c *ApiService) streamUserChannel(response *ListUserChannelResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUserChannelResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListUserChannelResponseWithContext) if err != nil { errorChannel <- err break @@ -210,11 +231,11 @@ func (c *ApiService) streamUserChannel(response *ListUserChannelResponse, params close(errorChannel) } -func (c *ApiService) getNextListUserChannelResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUserChannelResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -251,8 +272,10 @@ func (params *UpdateUserChannelParams) SetLastConsumptionTimestamp(LastConsumpti return params } -// func (c *ApiService) UpdateUserChannel(ServiceSid string, UserSid string, ChannelSid string, params *UpdateUserChannelParams) (*ChatV2UserChannel, error) { + return c.UpdateUserChannelWithContext(context.TODO(), ServiceSid, UserSid, ChannelSid, params) +} +func (c *ApiService) UpdateUserChannelWithContext(ctx context.Context, ServiceSid string, UserSid string, ChannelSid string, params *UpdateUserChannelParams) (*ChatV2UserChannel, error) { path := "/v2/Services/{ServiceSid}/Users/{UserSid}/Channels/{ChannelSid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"UserSid"+"}", UserSid, -1) @@ -273,7 +296,7 @@ func (c *ApiService) UpdateUserChannel(ServiceSid string, UserSid string, Channe data.Set("LastConsumptionTimestamp", fmt.Sprint((*params.LastConsumptionTimestamp).Format(time.RFC3339))) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/chat/v3/api_service.go b/rest/chat/v3/api_service.go index 432b78e85..56ea16150 100644 --- a/rest/chat/v3/api_service.go +++ b/rest/chat/v3/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://chat.twilio.com", + } +} diff --git a/rest/chat/v3/services_channels.go b/rest/chat/v3/services_channels.go index 3215a7819..94eb3209d 100644 --- a/rest/chat/v3/services_channels.go +++ b/rest/chat/v3/services_channels.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -46,6 +47,9 @@ func (params *UpdateChannelParams) SetMessagingServiceSid(MessagingServiceSid st // Update a specific Channel. func (c *ApiService) UpdateChannel(ServiceSid string, Sid string, params *UpdateChannelParams) (*ChatV3Channel, error) { + return c.UpdateChannelWithContext(context.TODO(), ServiceSid, Sid, params) +} +func (c *ApiService) UpdateChannelWithContext(ctx context.Context, ServiceSid string, Sid string, params *UpdateChannelParams) (*ChatV3Channel, error) { path := "/v3/Services/{ServiceSid}/Channels/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -65,7 +69,7 @@ func (c *ApiService) UpdateChannel(ServiceSid string, Sid string, params *Update if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/content/v1/api_service.go b/rest/content/v1/api_service.go index 1867bbec4..d0d9d2af4 100644 --- a/rest/content/v1/api_service.go +++ b/rest/content/v1/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://content.twilio.com", + } +} diff --git a/rest/content/v1/content.go b/rest/content/v1/content.go index d18e68c64..980b4004c 100644 --- a/rest/content/v1/content.go +++ b/rest/content/v1/content.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -36,6 +37,9 @@ func (params *CreateContentParams) SetContentCreateRequest(ContentCreateRequest // Create a Content resource func (c *ApiService) CreateContent(params *CreateContentParams) (*ContentV1Content, error) { + return c.CreateContentWithContext(context.TODO(), params) +} +func (c *ApiService) CreateContentWithContext(ctx context.Context, params *CreateContentParams) (*ContentV1Content, error) { path := "/v1/Content" data := url.Values{} @@ -52,7 +56,7 @@ func (c *ApiService) CreateContent(params *CreateContentParams) (*ContentV1Conte body = b } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers, body...) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers, body...) if err != nil { return nil, err } @@ -69,6 +73,9 @@ func (c *ApiService) CreateContent(params *CreateContentParams) (*ContentV1Conte // Deletes a Content resource func (c *ApiService) DeleteContent(Sid string) error { + return c.DeleteContentWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteContentWithContext(ctx context.Context, Sid string) error { path := "/v1/Content/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -77,7 +84,7 @@ func (c *ApiService) DeleteContent(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -89,6 +96,9 @@ func (c *ApiService) DeleteContent(Sid string) error { // Fetch a Content resource by its unique Content Sid func (c *ApiService) FetchContent(Sid string) (*ContentV1Content, error) { + return c.FetchContentWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchContentWithContext(ctx context.Context, Sid string) (*ContentV1Content, error) { path := "/v1/Content/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -97,7 +107,7 @@ func (c *ApiService) FetchContent(Sid string) (*ContentV1Content, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -131,6 +141,11 @@ func (params *ListContentParams) SetLimit(Limit int) *ListContentParams { // Retrieve a single page of Content records from the API. Request is executed immediately. func (c *ApiService) PageContent(params *ListContentParams, pageToken, pageNumber string) (*ListContentResponse, error) { + return c.PageContentWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Content records from the API. Request is executed immediately. +func (c *ApiService) PageContentWithContext(ctx context.Context, params *ListContentParams, pageToken, pageNumber string) (*ListContentResponse, error) { path := "/v1/Content" data := url.Values{} @@ -149,7 +164,7 @@ func (c *ApiService) PageContent(params *ListContentParams, pageToken, pageNumbe data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -166,7 +181,12 @@ func (c *ApiService) PageContent(params *ListContentParams, pageToken, pageNumbe // Lists Content records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListContent(params *ListContentParams) ([]ContentV1Content, error) { - response, errors := c.StreamContent(params) + return c.ListContentWithContext(context.TODO(), params) +} + +// Lists Content records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListContentWithContext(ctx context.Context, params *ListContentParams) ([]ContentV1Content, error) { + response, errors := c.StreamContentWithContext(ctx, params) records := make([]ContentV1Content, 0) for record := range response { @@ -182,6 +202,11 @@ func (c *ApiService) ListContent(params *ListContentParams) ([]ContentV1Content, // Streams Content records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamContent(params *ListContentParams) (chan ContentV1Content, chan error) { + return c.StreamContentWithContext(context.TODO(), params) +} + +// Streams Content records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamContentWithContext(ctx context.Context, params *ListContentParams) (chan ContentV1Content, chan error) { if params == nil { params = &ListContentParams{} } @@ -190,19 +215,19 @@ func (c *ApiService) StreamContent(params *ListContentParams) (chan ContentV1Con recordChannel := make(chan ContentV1Content, 1) errorChannel := make(chan error, 1) - response, err := c.PageContent(params, "", "") + response, err := c.PageContentWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamContent(response, params, recordChannel, errorChannel) + go c.streamContentWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamContent(response *ListContentResponse, params *ListContentParams, recordChannel chan ContentV1Content, errorChannel chan error) { +func (c *ApiService) streamContentWithContext(ctx context.Context, response *ListContentResponse, params *ListContentParams, recordChannel chan ContentV1Content, errorChannel chan error) { curRecord := 1 for response != nil { @@ -217,7 +242,7 @@ func (c *ApiService) streamContent(response *ListContentResponse, params *ListCo } } - record, err := client.GetNext(c.baseURL, response, c.getNextListContentResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListContentResponseWithContext) if err != nil { errorChannel <- err break @@ -232,11 +257,11 @@ func (c *ApiService) streamContent(response *ListContentResponse, params *ListCo close(errorChannel) } -func (c *ApiService) getNextListContentResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListContentResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/content/v1/content_and_approvals.go b/rest/content/v1/content_and_approvals.go index f8964b451..9cedfab6d 100644 --- a/rest/content/v1/content_and_approvals.go +++ b/rest/content/v1/content_and_approvals.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -41,6 +42,11 @@ func (params *ListContentAndApprovalsParams) SetLimit(Limit int) *ListContentAnd // Retrieve a single page of ContentAndApprovals records from the API. Request is executed immediately. func (c *ApiService) PageContentAndApprovals(params *ListContentAndApprovalsParams, pageToken, pageNumber string) (*ListContentAndApprovalsResponse, error) { + return c.PageContentAndApprovalsWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of ContentAndApprovals records from the API. Request is executed immediately. +func (c *ApiService) PageContentAndApprovalsWithContext(ctx context.Context, params *ListContentAndApprovalsParams, pageToken, pageNumber string) (*ListContentAndApprovalsResponse, error) { path := "/v1/ContentAndApprovals" data := url.Values{} @@ -59,7 +65,7 @@ func (c *ApiService) PageContentAndApprovals(params *ListContentAndApprovalsPara data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -76,7 +82,12 @@ func (c *ApiService) PageContentAndApprovals(params *ListContentAndApprovalsPara // Lists ContentAndApprovals records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListContentAndApprovals(params *ListContentAndApprovalsParams) ([]ContentV1ContentAndApprovals, error) { - response, errors := c.StreamContentAndApprovals(params) + return c.ListContentAndApprovalsWithContext(context.TODO(), params) +} + +// Lists ContentAndApprovals records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListContentAndApprovalsWithContext(ctx context.Context, params *ListContentAndApprovalsParams) ([]ContentV1ContentAndApprovals, error) { + response, errors := c.StreamContentAndApprovalsWithContext(ctx, params) records := make([]ContentV1ContentAndApprovals, 0) for record := range response { @@ -92,6 +103,11 @@ func (c *ApiService) ListContentAndApprovals(params *ListContentAndApprovalsPara // Streams ContentAndApprovals records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamContentAndApprovals(params *ListContentAndApprovalsParams) (chan ContentV1ContentAndApprovals, chan error) { + return c.StreamContentAndApprovalsWithContext(context.TODO(), params) +} + +// Streams ContentAndApprovals records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamContentAndApprovalsWithContext(ctx context.Context, params *ListContentAndApprovalsParams) (chan ContentV1ContentAndApprovals, chan error) { if params == nil { params = &ListContentAndApprovalsParams{} } @@ -100,19 +116,19 @@ func (c *ApiService) StreamContentAndApprovals(params *ListContentAndApprovalsPa recordChannel := make(chan ContentV1ContentAndApprovals, 1) errorChannel := make(chan error, 1) - response, err := c.PageContentAndApprovals(params, "", "") + response, err := c.PageContentAndApprovalsWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamContentAndApprovals(response, params, recordChannel, errorChannel) + go c.streamContentAndApprovalsWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamContentAndApprovals(response *ListContentAndApprovalsResponse, params *ListContentAndApprovalsParams, recordChannel chan ContentV1ContentAndApprovals, errorChannel chan error) { +func (c *ApiService) streamContentAndApprovalsWithContext(ctx context.Context, response *ListContentAndApprovalsResponse, params *ListContentAndApprovalsParams, recordChannel chan ContentV1ContentAndApprovals, errorChannel chan error) { curRecord := 1 for response != nil { @@ -127,7 +143,7 @@ func (c *ApiService) streamContentAndApprovals(response *ListContentAndApprovals } } - record, err := client.GetNext(c.baseURL, response, c.getNextListContentAndApprovalsResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListContentAndApprovalsResponseWithContext) if err != nil { errorChannel <- err break @@ -142,11 +158,11 @@ func (c *ApiService) streamContentAndApprovals(response *ListContentAndApprovals close(errorChannel) } -func (c *ApiService) getNextListContentAndApprovalsResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListContentAndApprovalsResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/content/v1/content_approval_requests.go b/rest/content/v1/content_approval_requests.go index f83e9f56c..cfeb3cf6c 100644 --- a/rest/content/v1/content_approval_requests.go +++ b/rest/content/v1/content_approval_requests.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -22,6 +23,9 @@ import ( // Fetch a Content resource's approval status by its unique Content Sid func (c *ApiService) FetchApprovalFetch(Sid string) (*ContentV1ApprovalFetch, error) { + return c.FetchApprovalFetchWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchApprovalFetchWithContext(ctx context.Context, Sid string) (*ContentV1ApprovalFetch, error) { path := "/v1/Content/{Sid}/ApprovalRequests" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -30,7 +34,7 @@ func (c *ApiService) FetchApprovalFetch(Sid string) (*ContentV1ApprovalFetch, er "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/content/v1/content_approval_requests_whatsapp.go b/rest/content/v1/content_approval_requests_whatsapp.go index f26952350..1bb346bf7 100644 --- a/rest/content/v1/content_approval_requests_whatsapp.go +++ b/rest/content/v1/content_approval_requests_whatsapp.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -31,8 +32,10 @@ func (params *CreateApprovalCreateParams) SetContentApprovalRequest(ContentAppro return params } -// func (c *ApiService) CreateApprovalCreate(ContentSid string, params *CreateApprovalCreateParams) (*ContentV1ApprovalCreate, error) { + return c.CreateApprovalCreateWithContext(context.TODO(), ContentSid, params) +} +func (c *ApiService) CreateApprovalCreateWithContext(ctx context.Context, ContentSid string, params *CreateApprovalCreateParams) (*ContentV1ApprovalCreate, error) { path := "/v1/Content/{ContentSid}/ApprovalRequests/whatsapp" path = strings.Replace(path, "{"+"ContentSid"+"}", ContentSid, -1) @@ -50,7 +53,7 @@ func (c *ApiService) CreateApprovalCreate(ContentSid string, params *CreateAppro body = b } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers, body...) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers, body...) if err != nil { return nil, err } diff --git a/rest/content/v1/legacy_content.go b/rest/content/v1/legacy_content.go index ef7c07af3..3871af9b6 100644 --- a/rest/content/v1/legacy_content.go +++ b/rest/content/v1/legacy_content.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -41,6 +42,11 @@ func (params *ListLegacyContentParams) SetLimit(Limit int) *ListLegacyContentPar // Retrieve a single page of LegacyContent records from the API. Request is executed immediately. func (c *ApiService) PageLegacyContent(params *ListLegacyContentParams, pageToken, pageNumber string) (*ListLegacyContentResponse, error) { + return c.PageLegacyContentWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of LegacyContent records from the API. Request is executed immediately. +func (c *ApiService) PageLegacyContentWithContext(ctx context.Context, params *ListLegacyContentParams, pageToken, pageNumber string) (*ListLegacyContentResponse, error) { path := "/v1/LegacyContent" data := url.Values{} @@ -59,7 +65,7 @@ func (c *ApiService) PageLegacyContent(params *ListLegacyContentParams, pageToke data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -76,7 +82,12 @@ func (c *ApiService) PageLegacyContent(params *ListLegacyContentParams, pageToke // Lists LegacyContent records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListLegacyContent(params *ListLegacyContentParams) ([]ContentV1LegacyContent, error) { - response, errors := c.StreamLegacyContent(params) + return c.ListLegacyContentWithContext(context.TODO(), params) +} + +// Lists LegacyContent records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListLegacyContentWithContext(ctx context.Context, params *ListLegacyContentParams) ([]ContentV1LegacyContent, error) { + response, errors := c.StreamLegacyContentWithContext(ctx, params) records := make([]ContentV1LegacyContent, 0) for record := range response { @@ -92,6 +103,11 @@ func (c *ApiService) ListLegacyContent(params *ListLegacyContentParams) ([]Conte // Streams LegacyContent records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamLegacyContent(params *ListLegacyContentParams) (chan ContentV1LegacyContent, chan error) { + return c.StreamLegacyContentWithContext(context.TODO(), params) +} + +// Streams LegacyContent records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamLegacyContentWithContext(ctx context.Context, params *ListLegacyContentParams) (chan ContentV1LegacyContent, chan error) { if params == nil { params = &ListLegacyContentParams{} } @@ -100,19 +116,19 @@ func (c *ApiService) StreamLegacyContent(params *ListLegacyContentParams) (chan recordChannel := make(chan ContentV1LegacyContent, 1) errorChannel := make(chan error, 1) - response, err := c.PageLegacyContent(params, "", "") + response, err := c.PageLegacyContentWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamLegacyContent(response, params, recordChannel, errorChannel) + go c.streamLegacyContentWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamLegacyContent(response *ListLegacyContentResponse, params *ListLegacyContentParams, recordChannel chan ContentV1LegacyContent, errorChannel chan error) { +func (c *ApiService) streamLegacyContentWithContext(ctx context.Context, response *ListLegacyContentResponse, params *ListLegacyContentParams, recordChannel chan ContentV1LegacyContent, errorChannel chan error) { curRecord := 1 for response != nil { @@ -127,7 +143,7 @@ func (c *ApiService) streamLegacyContent(response *ListLegacyContentResponse, pa } } - record, err := client.GetNext(c.baseURL, response, c.getNextListLegacyContentResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListLegacyContentResponseWithContext) if err != nil { errorChannel <- err break @@ -142,11 +158,11 @@ func (c *ApiService) streamLegacyContent(response *ListLegacyContentResponse, pa close(errorChannel) } -func (c *ApiService) getNextListLegacyContentResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListLegacyContentResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/content/v2/api_service.go b/rest/content/v2/api_service.go index 1867bbec4..d0d9d2af4 100644 --- a/rest/content/v2/api_service.go +++ b/rest/content/v2/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://content.twilio.com", + } +} diff --git a/rest/content/v2/content.go b/rest/content/v2/content.go index 0b5b5448e..34259150d 100644 --- a/rest/content/v2/content.go +++ b/rest/content/v2/content.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -96,6 +97,11 @@ func (params *ListContentParams) SetLimit(Limit int) *ListContentParams { // Retrieve a single page of Content records from the API. Request is executed immediately. func (c *ApiService) PageContent(params *ListContentParams, pageToken, pageNumber string) (*ListContentResponse, error) { + return c.PageContentWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Content records from the API. Request is executed immediately. +func (c *ApiService) PageContentWithContext(ctx context.Context, params *ListContentParams, pageToken, pageNumber string) (*ListContentResponse, error) { path := "/v2/Content" data := url.Values{} @@ -147,7 +153,7 @@ func (c *ApiService) PageContent(params *ListContentParams, pageToken, pageNumbe data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -164,7 +170,12 @@ func (c *ApiService) PageContent(params *ListContentParams, pageToken, pageNumbe // Lists Content records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListContent(params *ListContentParams) ([]ContentV1Content, error) { - response, errors := c.StreamContent(params) + return c.ListContentWithContext(context.TODO(), params) +} + +// Lists Content records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListContentWithContext(ctx context.Context, params *ListContentParams) ([]ContentV1Content, error) { + response, errors := c.StreamContentWithContext(ctx, params) records := make([]ContentV1Content, 0) for record := range response { @@ -180,6 +191,11 @@ func (c *ApiService) ListContent(params *ListContentParams) ([]ContentV1Content, // Streams Content records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamContent(params *ListContentParams) (chan ContentV1Content, chan error) { + return c.StreamContentWithContext(context.TODO(), params) +} + +// Streams Content records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamContentWithContext(ctx context.Context, params *ListContentParams) (chan ContentV1Content, chan error) { if params == nil { params = &ListContentParams{} } @@ -188,19 +204,19 @@ func (c *ApiService) StreamContent(params *ListContentParams) (chan ContentV1Con recordChannel := make(chan ContentV1Content, 1) errorChannel := make(chan error, 1) - response, err := c.PageContent(params, "", "") + response, err := c.PageContentWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamContent(response, params, recordChannel, errorChannel) + go c.streamContentWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamContent(response *ListContentResponse, params *ListContentParams, recordChannel chan ContentV1Content, errorChannel chan error) { +func (c *ApiService) streamContentWithContext(ctx context.Context, response *ListContentResponse, params *ListContentParams, recordChannel chan ContentV1Content, errorChannel chan error) { curRecord := 1 for response != nil { @@ -215,7 +231,7 @@ func (c *ApiService) streamContent(response *ListContentResponse, params *ListCo } } - record, err := client.GetNext(c.baseURL, response, c.getNextListContentResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListContentResponseWithContext) if err != nil { errorChannel <- err break @@ -230,11 +246,11 @@ func (c *ApiService) streamContent(response *ListContentResponse, params *ListCo close(errorChannel) } -func (c *ApiService) getNextListContentResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListContentResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/content/v2/content_and_approvals.go b/rest/content/v2/content_and_approvals.go index d296eca44..867087f75 100644 --- a/rest/content/v2/content_and_approvals.go +++ b/rest/content/v2/content_and_approvals.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -96,6 +97,11 @@ func (params *ListContentAndApprovalsParams) SetLimit(Limit int) *ListContentAnd // Retrieve a single page of ContentAndApprovals records from the API. Request is executed immediately. func (c *ApiService) PageContentAndApprovals(params *ListContentAndApprovalsParams, pageToken, pageNumber string) (*ListContentAndApprovalsResponse, error) { + return c.PageContentAndApprovalsWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of ContentAndApprovals records from the API. Request is executed immediately. +func (c *ApiService) PageContentAndApprovalsWithContext(ctx context.Context, params *ListContentAndApprovalsParams, pageToken, pageNumber string) (*ListContentAndApprovalsResponse, error) { path := "/v2/ContentAndApprovals" data := url.Values{} @@ -147,7 +153,7 @@ func (c *ApiService) PageContentAndApprovals(params *ListContentAndApprovalsPara data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -164,7 +170,12 @@ func (c *ApiService) PageContentAndApprovals(params *ListContentAndApprovalsPara // Lists ContentAndApprovals records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListContentAndApprovals(params *ListContentAndApprovalsParams) ([]ContentV1ContentAndApprovals, error) { - response, errors := c.StreamContentAndApprovals(params) + return c.ListContentAndApprovalsWithContext(context.TODO(), params) +} + +// Lists ContentAndApprovals records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListContentAndApprovalsWithContext(ctx context.Context, params *ListContentAndApprovalsParams) ([]ContentV1ContentAndApprovals, error) { + response, errors := c.StreamContentAndApprovalsWithContext(ctx, params) records := make([]ContentV1ContentAndApprovals, 0) for record := range response { @@ -180,6 +191,11 @@ func (c *ApiService) ListContentAndApprovals(params *ListContentAndApprovalsPara // Streams ContentAndApprovals records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamContentAndApprovals(params *ListContentAndApprovalsParams) (chan ContentV1ContentAndApprovals, chan error) { + return c.StreamContentAndApprovalsWithContext(context.TODO(), params) +} + +// Streams ContentAndApprovals records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamContentAndApprovalsWithContext(ctx context.Context, params *ListContentAndApprovalsParams) (chan ContentV1ContentAndApprovals, chan error) { if params == nil { params = &ListContentAndApprovalsParams{} } @@ -188,19 +204,19 @@ func (c *ApiService) StreamContentAndApprovals(params *ListContentAndApprovalsPa recordChannel := make(chan ContentV1ContentAndApprovals, 1) errorChannel := make(chan error, 1) - response, err := c.PageContentAndApprovals(params, "", "") + response, err := c.PageContentAndApprovalsWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamContentAndApprovals(response, params, recordChannel, errorChannel) + go c.streamContentAndApprovalsWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamContentAndApprovals(response *ListContentAndApprovalsResponse, params *ListContentAndApprovalsParams, recordChannel chan ContentV1ContentAndApprovals, errorChannel chan error) { +func (c *ApiService) streamContentAndApprovalsWithContext(ctx context.Context, response *ListContentAndApprovalsResponse, params *ListContentAndApprovalsParams, recordChannel chan ContentV1ContentAndApprovals, errorChannel chan error) { curRecord := 1 for response != nil { @@ -215,7 +231,7 @@ func (c *ApiService) streamContentAndApprovals(response *ListContentAndApprovals } } - record, err := client.GetNext(c.baseURL, response, c.getNextListContentAndApprovalsResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListContentAndApprovalsResponseWithContext) if err != nil { errorChannel <- err break @@ -230,11 +246,11 @@ func (c *ApiService) streamContentAndApprovals(response *ListContentAndApprovals close(errorChannel) } -func (c *ApiService) getNextListContentAndApprovalsResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListContentAndApprovalsResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/conversations/v1/api_service.go b/rest/conversations/v1/api_service.go index f123e3641..f605ee005 100644 --- a/rest/conversations/v1/api_service.go +++ b/rest/conversations/v1/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://conversations.twilio.com", + } +} diff --git a/rest/conversations/v1/configuration.go b/rest/conversations/v1/configuration.go index 253178681..722ac5a3d 100644 --- a/rest/conversations/v1/configuration.go +++ b/rest/conversations/v1/configuration.go @@ -15,12 +15,16 @@ package openapi import ( + "context" "encoding/json" "net/url" ) // Fetch the global configuration of conversations on your account func (c *ApiService) FetchConfiguration() (*ConversationsV1Configuration, error) { + return c.FetchConfigurationWithContext(context.TODO()) +} +func (c *ApiService) FetchConfigurationWithContext(ctx context.Context) (*ConversationsV1Configuration, error) { path := "/v1/Configuration" data := url.Values{} @@ -28,7 +32,7 @@ func (c *ApiService) FetchConfiguration() (*ConversationsV1Configuration, error) "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -74,6 +78,9 @@ func (params *UpdateConfigurationParams) SetDefaultClosedTimer(DefaultClosedTime // Update the global configuration of conversations on your account func (c *ApiService) UpdateConfiguration(params *UpdateConfigurationParams) (*ConversationsV1Configuration, error) { + return c.UpdateConfigurationWithContext(context.TODO(), params) +} +func (c *ApiService) UpdateConfigurationWithContext(ctx context.Context, params *UpdateConfigurationParams) (*ConversationsV1Configuration, error) { path := "/v1/Configuration" data := url.Values{} @@ -94,7 +101,7 @@ func (c *ApiService) UpdateConfiguration(params *UpdateConfigurationParams) (*Co data.Set("DefaultClosedTimer", *params.DefaultClosedTimer) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/conversations/v1/configuration_addresses.go b/rest/conversations/v1/configuration_addresses.go index 19ddce506..de8874f2d 100644 --- a/rest/conversations/v1/configuration_addresses.go +++ b/rest/conversations/v1/configuration_addresses.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -102,6 +103,9 @@ func (params *CreateConfigurationAddressParams) SetAddressCountry(AddressCountry // Create a new address configuration func (c *ApiService) CreateConfigurationAddress(params *CreateConfigurationAddressParams) (*ConversationsV1ConfigurationAddress, error) { + return c.CreateConfigurationAddressWithContext(context.TODO(), params) +} +func (c *ApiService) CreateConfigurationAddressWithContext(ctx context.Context, params *CreateConfigurationAddressParams) (*ConversationsV1ConfigurationAddress, error) { path := "/v1/Configuration/Addresses" data := url.Values{} @@ -148,7 +152,7 @@ func (c *ApiService) CreateConfigurationAddress(params *CreateConfigurationAddre data.Set("AddressCountry", *params.AddressCountry) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -165,6 +169,9 @@ func (c *ApiService) CreateConfigurationAddress(params *CreateConfigurationAddre // Remove an existing address configuration func (c *ApiService) DeleteConfigurationAddress(Sid string) error { + return c.DeleteConfigurationAddressWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteConfigurationAddressWithContext(ctx context.Context, Sid string) error { path := "/v1/Configuration/Addresses/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -173,7 +180,7 @@ func (c *ApiService) DeleteConfigurationAddress(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -185,6 +192,9 @@ func (c *ApiService) DeleteConfigurationAddress(Sid string) error { // Fetch an address configuration func (c *ApiService) FetchConfigurationAddress(Sid string) (*ConversationsV1ConfigurationAddress, error) { + return c.FetchConfigurationAddressWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchConfigurationAddressWithContext(ctx context.Context, Sid string) (*ConversationsV1ConfigurationAddress, error) { path := "/v1/Configuration/Addresses/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -193,7 +203,7 @@ func (c *ApiService) FetchConfigurationAddress(Sid string) (*ConversationsV1Conf "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -233,6 +243,11 @@ func (params *ListConfigurationAddressParams) SetLimit(Limit int) *ListConfigura // Retrieve a single page of ConfigurationAddress records from the API. Request is executed immediately. func (c *ApiService) PageConfigurationAddress(params *ListConfigurationAddressParams, pageToken, pageNumber string) (*ListConfigurationAddressResponse, error) { + return c.PageConfigurationAddressWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of ConfigurationAddress records from the API. Request is executed immediately. +func (c *ApiService) PageConfigurationAddressWithContext(ctx context.Context, params *ListConfigurationAddressParams, pageToken, pageNumber string) (*ListConfigurationAddressResponse, error) { path := "/v1/Configuration/Addresses" data := url.Values{} @@ -254,7 +269,7 @@ func (c *ApiService) PageConfigurationAddress(params *ListConfigurationAddressPa data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -271,7 +286,12 @@ func (c *ApiService) PageConfigurationAddress(params *ListConfigurationAddressPa // Lists ConfigurationAddress records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListConfigurationAddress(params *ListConfigurationAddressParams) ([]ConversationsV1ConfigurationAddress, error) { - response, errors := c.StreamConfigurationAddress(params) + return c.ListConfigurationAddressWithContext(context.TODO(), params) +} + +// Lists ConfigurationAddress records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListConfigurationAddressWithContext(ctx context.Context, params *ListConfigurationAddressParams) ([]ConversationsV1ConfigurationAddress, error) { + response, errors := c.StreamConfigurationAddressWithContext(ctx, params) records := make([]ConversationsV1ConfigurationAddress, 0) for record := range response { @@ -287,6 +307,11 @@ func (c *ApiService) ListConfigurationAddress(params *ListConfigurationAddressPa // Streams ConfigurationAddress records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamConfigurationAddress(params *ListConfigurationAddressParams) (chan ConversationsV1ConfigurationAddress, chan error) { + return c.StreamConfigurationAddressWithContext(context.TODO(), params) +} + +// Streams ConfigurationAddress records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamConfigurationAddressWithContext(ctx context.Context, params *ListConfigurationAddressParams) (chan ConversationsV1ConfigurationAddress, chan error) { if params == nil { params = &ListConfigurationAddressParams{} } @@ -295,19 +320,19 @@ func (c *ApiService) StreamConfigurationAddress(params *ListConfigurationAddress recordChannel := make(chan ConversationsV1ConfigurationAddress, 1) errorChannel := make(chan error, 1) - response, err := c.PageConfigurationAddress(params, "", "") + response, err := c.PageConfigurationAddressWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamConfigurationAddress(response, params, recordChannel, errorChannel) + go c.streamConfigurationAddressWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamConfigurationAddress(response *ListConfigurationAddressResponse, params *ListConfigurationAddressParams, recordChannel chan ConversationsV1ConfigurationAddress, errorChannel chan error) { +func (c *ApiService) streamConfigurationAddressWithContext(ctx context.Context, response *ListConfigurationAddressResponse, params *ListConfigurationAddressParams, recordChannel chan ConversationsV1ConfigurationAddress, errorChannel chan error) { curRecord := 1 for response != nil { @@ -322,7 +347,7 @@ func (c *ApiService) streamConfigurationAddress(response *ListConfigurationAddre } } - record, err := client.GetNext(c.baseURL, response, c.getNextListConfigurationAddressResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListConfigurationAddressResponseWithContext) if err != nil { errorChannel <- err break @@ -337,11 +362,11 @@ func (c *ApiService) streamConfigurationAddress(response *ListConfigurationAddre close(errorChannel) } -func (c *ApiService) getNextListConfigurationAddressResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListConfigurationAddressResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -416,6 +441,9 @@ func (params *UpdateConfigurationAddressParams) SetAutoCreationStudioRetryCount( // Update an existing address configuration func (c *ApiService) UpdateConfigurationAddress(Sid string, params *UpdateConfigurationAddressParams) (*ConversationsV1ConfigurationAddress, error) { + return c.UpdateConfigurationAddressWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateConfigurationAddressWithContext(ctx context.Context, Sid string, params *UpdateConfigurationAddressParams) (*ConversationsV1ConfigurationAddress, error) { path := "/v1/Configuration/Addresses/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -454,7 +482,7 @@ func (c *ApiService) UpdateConfigurationAddress(Sid string, params *UpdateConfig data.Set("AutoCreation.StudioRetryCount", fmt.Sprint(*params.AutoCreationStudioRetryCount)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/conversations/v1/configuration_webhooks.go b/rest/conversations/v1/configuration_webhooks.go index a8cd4f4e6..e7c3ec3cb 100644 --- a/rest/conversations/v1/configuration_webhooks.go +++ b/rest/conversations/v1/configuration_webhooks.go @@ -15,13 +15,16 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" ) -// func (c *ApiService) FetchConfigurationWebhook() (*ConversationsV1ConfigurationWebhook, error) { + return c.FetchConfigurationWebhookWithContext(context.TODO()) +} +func (c *ApiService) FetchConfigurationWebhookWithContext(ctx context.Context) (*ConversationsV1ConfigurationWebhook, error) { path := "/v1/Configuration/Webhooks" data := url.Values{} @@ -29,7 +32,7 @@ func (c *ApiService) FetchConfigurationWebhook() (*ConversationsV1ConfigurationW "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -79,8 +82,10 @@ func (params *UpdateConfigurationWebhookParams) SetTarget(Target string) *Update return params } -// func (c *ApiService) UpdateConfigurationWebhook(params *UpdateConfigurationWebhookParams) (*ConversationsV1ConfigurationWebhook, error) { + return c.UpdateConfigurationWebhookWithContext(context.TODO(), params) +} +func (c *ApiService) UpdateConfigurationWebhookWithContext(ctx context.Context, params *UpdateConfigurationWebhookParams) (*ConversationsV1ConfigurationWebhook, error) { path := "/v1/Configuration/Webhooks" data := url.Values{} @@ -106,7 +111,7 @@ func (c *ApiService) UpdateConfigurationWebhook(params *UpdateConfigurationWebho data.Set("Target", fmt.Sprint(*params.Target)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/conversations/v1/conversation_with_participants.go b/rest/conversations/v1/conversation_with_participants.go index 56059c6a2..2627ab279 100644 --- a/rest/conversations/v1/conversation_with_participants.go +++ b/rest/conversations/v1/conversation_with_participants.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -106,6 +107,9 @@ func (params *CreateConversationWithParticipantsParams) SetParticipant(Participa // Create a new conversation with the list of participants in your account's default service func (c *ApiService) CreateConversationWithParticipants(params *CreateConversationWithParticipantsParams) (*ConversationsV1ConversationWithParticipants, error) { + return c.CreateConversationWithParticipantsWithContext(context.TODO(), params) +} +func (c *ApiService) CreateConversationWithParticipantsWithContext(ctx context.Context, params *CreateConversationWithParticipantsParams) (*ConversationsV1ConversationWithParticipants, error) { path := "/v1/ConversationWithParticipants" data := url.Values{} @@ -155,7 +159,7 @@ func (c *ApiService) CreateConversationWithParticipants(params *CreateConversati if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/conversations/v1/conversations.go b/rest/conversations/v1/conversations.go index 195305033..246dc8cee 100644 --- a/rest/conversations/v1/conversations.go +++ b/rest/conversations/v1/conversations.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -103,6 +104,9 @@ func (params *CreateConversationParams) SetBindingsEmailName(BindingsEmailName s // Create a new conversation in your account's default service func (c *ApiService) CreateConversation(params *CreateConversationParams) (*ConversationsV1Conversation, error) { + return c.CreateConversationWithContext(context.TODO(), params) +} +func (c *ApiService) CreateConversationWithContext(ctx context.Context, params *CreateConversationParams) (*ConversationsV1Conversation, error) { path := "/v1/Conversations" data := url.Values{} @@ -147,7 +151,7 @@ func (c *ApiService) CreateConversation(params *CreateConversationParams) (*Conv if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -175,6 +179,9 @@ func (params *DeleteConversationParams) SetXTwilioWebhookEnabled(XTwilioWebhookE // Remove a conversation from your account's default service func (c *ApiService) DeleteConversation(Sid string, params *DeleteConversationParams) error { + return c.DeleteConversationWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) DeleteConversationWithContext(ctx context.Context, Sid string, params *DeleteConversationParams) error { path := "/v1/Conversations/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -186,7 +193,7 @@ func (c *ApiService) DeleteConversation(Sid string, params *DeleteConversationPa if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -198,6 +205,9 @@ func (c *ApiService) DeleteConversation(Sid string, params *DeleteConversationPa // Fetch a conversation from your account's default service func (c *ApiService) FetchConversation(Sid string) (*ConversationsV1Conversation, error) { + return c.FetchConversationWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchConversationWithContext(ctx context.Context, Sid string) (*ConversationsV1Conversation, error) { path := "/v1/Conversations/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -206,7 +216,7 @@ func (c *ApiService) FetchConversation(Sid string) (*ConversationsV1Conversation "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -258,6 +268,11 @@ func (params *ListConversationParams) SetLimit(Limit int) *ListConversationParam // Retrieve a single page of Conversation records from the API. Request is executed immediately. func (c *ApiService) PageConversation(params *ListConversationParams, pageToken, pageNumber string) (*ListConversationResponse, error) { + return c.PageConversationWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Conversation records from the API. Request is executed immediately. +func (c *ApiService) PageConversationWithContext(ctx context.Context, params *ListConversationParams, pageToken, pageNumber string) (*ListConversationResponse, error) { path := "/v1/Conversations" data := url.Values{} @@ -285,7 +300,7 @@ func (c *ApiService) PageConversation(params *ListConversationParams, pageToken, data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -302,7 +317,12 @@ func (c *ApiService) PageConversation(params *ListConversationParams, pageToken, // Lists Conversation records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListConversation(params *ListConversationParams) ([]ConversationsV1Conversation, error) { - response, errors := c.StreamConversation(params) + return c.ListConversationWithContext(context.TODO(), params) +} + +// Lists Conversation records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListConversationWithContext(ctx context.Context, params *ListConversationParams) ([]ConversationsV1Conversation, error) { + response, errors := c.StreamConversationWithContext(ctx, params) records := make([]ConversationsV1Conversation, 0) for record := range response { @@ -318,6 +338,11 @@ func (c *ApiService) ListConversation(params *ListConversationParams) ([]Convers // Streams Conversation records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamConversation(params *ListConversationParams) (chan ConversationsV1Conversation, chan error) { + return c.StreamConversationWithContext(context.TODO(), params) +} + +// Streams Conversation records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamConversationWithContext(ctx context.Context, params *ListConversationParams) (chan ConversationsV1Conversation, chan error) { if params == nil { params = &ListConversationParams{} } @@ -326,19 +351,19 @@ func (c *ApiService) StreamConversation(params *ListConversationParams) (chan Co recordChannel := make(chan ConversationsV1Conversation, 1) errorChannel := make(chan error, 1) - response, err := c.PageConversation(params, "", "") + response, err := c.PageConversationWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamConversation(response, params, recordChannel, errorChannel) + go c.streamConversationWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamConversation(response *ListConversationResponse, params *ListConversationParams, recordChannel chan ConversationsV1Conversation, errorChannel chan error) { +func (c *ApiService) streamConversationWithContext(ctx context.Context, response *ListConversationResponse, params *ListConversationParams, recordChannel chan ConversationsV1Conversation, errorChannel chan error) { curRecord := 1 for response != nil { @@ -353,7 +378,7 @@ func (c *ApiService) streamConversation(response *ListConversationResponse, para } } - record, err := client.GetNext(c.baseURL, response, c.getNextListConversationResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListConversationResponseWithContext) if err != nil { errorChannel <- err break @@ -368,11 +393,11 @@ func (c *ApiService) streamConversation(response *ListConversationResponse, para close(errorChannel) } -func (c *ApiService) getNextListConversationResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListConversationResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -465,6 +490,9 @@ func (params *UpdateConversationParams) SetBindingsEmailName(BindingsEmailName s // Update an existing conversation in your account's default service func (c *ApiService) UpdateConversation(Sid string, params *UpdateConversationParams) (*ConversationsV1Conversation, error) { + return c.UpdateConversationWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateConversationWithContext(ctx context.Context, Sid string, params *UpdateConversationParams) (*ConversationsV1Conversation, error) { path := "/v1/Conversations/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -510,7 +538,7 @@ func (c *ApiService) UpdateConversation(Sid string, params *UpdateConversationPa if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/conversations/v1/conversations_messages.go b/rest/conversations/v1/conversations_messages.go index 1ccaf3a20..f0010f2c0 100644 --- a/rest/conversations/v1/conversations_messages.go +++ b/rest/conversations/v1/conversations_messages.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -91,6 +92,9 @@ func (params *CreateConversationMessageParams) SetSubject(Subject string) *Creat // Add a new message to the conversation func (c *ApiService) CreateConversationMessage(ConversationSid string, params *CreateConversationMessageParams) (*ConversationsV1ConversationMessage, error) { + return c.CreateConversationMessageWithContext(context.TODO(), ConversationSid, params) +} +func (c *ApiService) CreateConversationMessageWithContext(ctx context.Context, ConversationSid string, params *CreateConversationMessageParams) (*ConversationsV1ConversationMessage, error) { path := "/v1/Conversations/{ConversationSid}/Messages" path = strings.Replace(path, "{"+"ConversationSid"+"}", ConversationSid, -1) @@ -130,7 +134,7 @@ func (c *ApiService) CreateConversationMessage(ConversationSid string, params *C if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -158,6 +162,9 @@ func (params *DeleteConversationMessageParams) SetXTwilioWebhookEnabled(XTwilioW // Remove a message from the conversation func (c *ApiService) DeleteConversationMessage(ConversationSid string, Sid string, params *DeleteConversationMessageParams) error { + return c.DeleteConversationMessageWithContext(context.TODO(), ConversationSid, Sid, params) +} +func (c *ApiService) DeleteConversationMessageWithContext(ctx context.Context, ConversationSid string, Sid string, params *DeleteConversationMessageParams) error { path := "/v1/Conversations/{ConversationSid}/Messages/{Sid}" path = strings.Replace(path, "{"+"ConversationSid"+"}", ConversationSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -170,7 +177,7 @@ func (c *ApiService) DeleteConversationMessage(ConversationSid string, Sid strin if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -182,6 +189,9 @@ func (c *ApiService) DeleteConversationMessage(ConversationSid string, Sid strin // Fetch a message from the conversation func (c *ApiService) FetchConversationMessage(ConversationSid string, Sid string) (*ConversationsV1ConversationMessage, error) { + return c.FetchConversationMessageWithContext(context.TODO(), ConversationSid, Sid) +} +func (c *ApiService) FetchConversationMessageWithContext(ctx context.Context, ConversationSid string, Sid string) (*ConversationsV1ConversationMessage, error) { path := "/v1/Conversations/{ConversationSid}/Messages/{Sid}" path = strings.Replace(path, "{"+"ConversationSid"+"}", ConversationSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -191,7 +201,7 @@ func (c *ApiService) FetchConversationMessage(ConversationSid string, Sid string "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -231,6 +241,11 @@ func (params *ListConversationMessageParams) SetLimit(Limit int) *ListConversati // Retrieve a single page of ConversationMessage records from the API. Request is executed immediately. func (c *ApiService) PageConversationMessage(ConversationSid string, params *ListConversationMessageParams, pageToken, pageNumber string) (*ListConversationMessageResponse, error) { + return c.PageConversationMessageWithContext(context.TODO(), ConversationSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ConversationMessage records from the API. Request is executed immediately. +func (c *ApiService) PageConversationMessageWithContext(ctx context.Context, ConversationSid string, params *ListConversationMessageParams, pageToken, pageNumber string) (*ListConversationMessageResponse, error) { path := "/v1/Conversations/{ConversationSid}/Messages" path = strings.Replace(path, "{"+"ConversationSid"+"}", ConversationSid, -1) @@ -254,7 +269,7 @@ func (c *ApiService) PageConversationMessage(ConversationSid string, params *Lis data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -271,7 +286,12 @@ func (c *ApiService) PageConversationMessage(ConversationSid string, params *Lis // Lists ConversationMessage records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListConversationMessage(ConversationSid string, params *ListConversationMessageParams) ([]ConversationsV1ConversationMessage, error) { - response, errors := c.StreamConversationMessage(ConversationSid, params) + return c.ListConversationMessageWithContext(context.TODO(), ConversationSid, params) +} + +// Lists ConversationMessage records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListConversationMessageWithContext(ctx context.Context, ConversationSid string, params *ListConversationMessageParams) ([]ConversationsV1ConversationMessage, error) { + response, errors := c.StreamConversationMessageWithContext(ctx, ConversationSid, params) records := make([]ConversationsV1ConversationMessage, 0) for record := range response { @@ -287,6 +307,11 @@ func (c *ApiService) ListConversationMessage(ConversationSid string, params *Lis // Streams ConversationMessage records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamConversationMessage(ConversationSid string, params *ListConversationMessageParams) (chan ConversationsV1ConversationMessage, chan error) { + return c.StreamConversationMessageWithContext(context.TODO(), ConversationSid, params) +} + +// Streams ConversationMessage records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamConversationMessageWithContext(ctx context.Context, ConversationSid string, params *ListConversationMessageParams) (chan ConversationsV1ConversationMessage, chan error) { if params == nil { params = &ListConversationMessageParams{} } @@ -295,19 +320,19 @@ func (c *ApiService) StreamConversationMessage(ConversationSid string, params *L recordChannel := make(chan ConversationsV1ConversationMessage, 1) errorChannel := make(chan error, 1) - response, err := c.PageConversationMessage(ConversationSid, params, "", "") + response, err := c.PageConversationMessageWithContext(ctx, ConversationSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamConversationMessage(response, params, recordChannel, errorChannel) + go c.streamConversationMessageWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamConversationMessage(response *ListConversationMessageResponse, params *ListConversationMessageParams, recordChannel chan ConversationsV1ConversationMessage, errorChannel chan error) { +func (c *ApiService) streamConversationMessageWithContext(ctx context.Context, response *ListConversationMessageResponse, params *ListConversationMessageParams, recordChannel chan ConversationsV1ConversationMessage, errorChannel chan error) { curRecord := 1 for response != nil { @@ -322,7 +347,7 @@ func (c *ApiService) streamConversationMessage(response *ListConversationMessage } } - record, err := client.GetNext(c.baseURL, response, c.getNextListConversationMessageResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListConversationMessageResponseWithContext) if err != nil { errorChannel <- err break @@ -337,11 +362,11 @@ func (c *ApiService) streamConversationMessage(response *ListConversationMessage close(errorChannel) } -func (c *ApiService) getNextListConversationMessageResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListConversationMessageResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -404,6 +429,9 @@ func (params *UpdateConversationMessageParams) SetSubject(Subject string) *Updat // Update an existing message in the conversation func (c *ApiService) UpdateConversationMessage(ConversationSid string, Sid string, params *UpdateConversationMessageParams) (*ConversationsV1ConversationMessage, error) { + return c.UpdateConversationMessageWithContext(context.TODO(), ConversationSid, Sid, params) +} +func (c *ApiService) UpdateConversationMessageWithContext(ctx context.Context, ConversationSid string, Sid string, params *UpdateConversationMessageParams) (*ConversationsV1ConversationMessage, error) { path := "/v1/Conversations/{ConversationSid}/Messages/{Sid}" path = strings.Replace(path, "{"+"ConversationSid"+"}", ConversationSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -435,7 +463,7 @@ func (c *ApiService) UpdateConversationMessage(ConversationSid string, Sid strin if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/conversations/v1/conversations_messages_receipts.go b/rest/conversations/v1/conversations_messages_receipts.go index cdfb3ce84..3302c530e 100644 --- a/rest/conversations/v1/conversations_messages_receipts.go +++ b/rest/conversations/v1/conversations_messages_receipts.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -25,6 +26,9 @@ import ( // Fetch the delivery and read receipts of the conversation message func (c *ApiService) FetchConversationMessageReceipt(ConversationSid string, MessageSid string, Sid string) (*ConversationsV1ConversationMessageReceipt, error) { + return c.FetchConversationMessageReceiptWithContext(context.TODO(), ConversationSid, MessageSid, Sid) +} +func (c *ApiService) FetchConversationMessageReceiptWithContext(ctx context.Context, ConversationSid string, MessageSid string, Sid string) (*ConversationsV1ConversationMessageReceipt, error) { path := "/v1/Conversations/{ConversationSid}/Messages/{MessageSid}/Receipts/{Sid}" path = strings.Replace(path, "{"+"ConversationSid"+"}", ConversationSid, -1) path = strings.Replace(path, "{"+"MessageSid"+"}", MessageSid, -1) @@ -35,7 +39,7 @@ func (c *ApiService) FetchConversationMessageReceipt(ConversationSid string, Mes "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -69,6 +73,11 @@ func (params *ListConversationMessageReceiptParams) SetLimit(Limit int) *ListCon // Retrieve a single page of ConversationMessageReceipt records from the API. Request is executed immediately. func (c *ApiService) PageConversationMessageReceipt(ConversationSid string, MessageSid string, params *ListConversationMessageReceiptParams, pageToken, pageNumber string) (*ListConversationMessageReceiptResponse, error) { + return c.PageConversationMessageReceiptWithContext(context.TODO(), ConversationSid, MessageSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ConversationMessageReceipt records from the API. Request is executed immediately. +func (c *ApiService) PageConversationMessageReceiptWithContext(ctx context.Context, ConversationSid string, MessageSid string, params *ListConversationMessageReceiptParams, pageToken, pageNumber string) (*ListConversationMessageReceiptResponse, error) { path := "/v1/Conversations/{ConversationSid}/Messages/{MessageSid}/Receipts" path = strings.Replace(path, "{"+"ConversationSid"+"}", ConversationSid, -1) @@ -90,7 +99,7 @@ func (c *ApiService) PageConversationMessageReceipt(ConversationSid string, Mess data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -107,7 +116,12 @@ func (c *ApiService) PageConversationMessageReceipt(ConversationSid string, Mess // Lists ConversationMessageReceipt records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListConversationMessageReceipt(ConversationSid string, MessageSid string, params *ListConversationMessageReceiptParams) ([]ConversationsV1ConversationMessageReceipt, error) { - response, errors := c.StreamConversationMessageReceipt(ConversationSid, MessageSid, params) + return c.ListConversationMessageReceiptWithContext(context.TODO(), ConversationSid, MessageSid, params) +} + +// Lists ConversationMessageReceipt records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListConversationMessageReceiptWithContext(ctx context.Context, ConversationSid string, MessageSid string, params *ListConversationMessageReceiptParams) ([]ConversationsV1ConversationMessageReceipt, error) { + response, errors := c.StreamConversationMessageReceiptWithContext(ctx, ConversationSid, MessageSid, params) records := make([]ConversationsV1ConversationMessageReceipt, 0) for record := range response { @@ -123,6 +137,11 @@ func (c *ApiService) ListConversationMessageReceipt(ConversationSid string, Mess // Streams ConversationMessageReceipt records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamConversationMessageReceipt(ConversationSid string, MessageSid string, params *ListConversationMessageReceiptParams) (chan ConversationsV1ConversationMessageReceipt, chan error) { + return c.StreamConversationMessageReceiptWithContext(context.TODO(), ConversationSid, MessageSid, params) +} + +// Streams ConversationMessageReceipt records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamConversationMessageReceiptWithContext(ctx context.Context, ConversationSid string, MessageSid string, params *ListConversationMessageReceiptParams) (chan ConversationsV1ConversationMessageReceipt, chan error) { if params == nil { params = &ListConversationMessageReceiptParams{} } @@ -131,19 +150,19 @@ func (c *ApiService) StreamConversationMessageReceipt(ConversationSid string, Me recordChannel := make(chan ConversationsV1ConversationMessageReceipt, 1) errorChannel := make(chan error, 1) - response, err := c.PageConversationMessageReceipt(ConversationSid, MessageSid, params, "", "") + response, err := c.PageConversationMessageReceiptWithContext(ctx, ConversationSid, MessageSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamConversationMessageReceipt(response, params, recordChannel, errorChannel) + go c.streamConversationMessageReceiptWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamConversationMessageReceipt(response *ListConversationMessageReceiptResponse, params *ListConversationMessageReceiptParams, recordChannel chan ConversationsV1ConversationMessageReceipt, errorChannel chan error) { +func (c *ApiService) streamConversationMessageReceiptWithContext(ctx context.Context, response *ListConversationMessageReceiptResponse, params *ListConversationMessageReceiptParams, recordChannel chan ConversationsV1ConversationMessageReceipt, errorChannel chan error) { curRecord := 1 for response != nil { @@ -158,7 +177,7 @@ func (c *ApiService) streamConversationMessageReceipt(response *ListConversation } } - record, err := client.GetNext(c.baseURL, response, c.getNextListConversationMessageReceiptResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListConversationMessageReceiptResponseWithContext) if err != nil { errorChannel <- err break @@ -173,11 +192,11 @@ func (c *ApiService) streamConversationMessageReceipt(response *ListConversation close(errorChannel) } -func (c *ApiService) getNextListConversationMessageReceiptResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListConversationMessageReceiptResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/conversations/v1/conversations_participants.go b/rest/conversations/v1/conversations_participants.go index 00c16e202..709715856 100644 --- a/rest/conversations/v1/conversations_participants.go +++ b/rest/conversations/v1/conversations_participants.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -85,6 +86,9 @@ func (params *CreateConversationParticipantParams) SetRoleSid(RoleSid string) *C // Add a new participant to the conversation func (c *ApiService) CreateConversationParticipant(ConversationSid string, params *CreateConversationParticipantParams) (*ConversationsV1ConversationParticipant, error) { + return c.CreateConversationParticipantWithContext(context.TODO(), ConversationSid, params) +} +func (c *ApiService) CreateConversationParticipantWithContext(ctx context.Context, ConversationSid string, params *CreateConversationParticipantParams) (*ConversationsV1ConversationParticipant, error) { path := "/v1/Conversations/{ConversationSid}/Participants" path = strings.Replace(path, "{"+"ConversationSid"+"}", ConversationSid, -1) @@ -121,7 +125,7 @@ func (c *ApiService) CreateConversationParticipant(ConversationSid string, param if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -149,6 +153,9 @@ func (params *DeleteConversationParticipantParams) SetXTwilioWebhookEnabled(XTwi // Remove a participant from the conversation func (c *ApiService) DeleteConversationParticipant(ConversationSid string, Sid string, params *DeleteConversationParticipantParams) error { + return c.DeleteConversationParticipantWithContext(context.TODO(), ConversationSid, Sid, params) +} +func (c *ApiService) DeleteConversationParticipantWithContext(ctx context.Context, ConversationSid string, Sid string, params *DeleteConversationParticipantParams) error { path := "/v1/Conversations/{ConversationSid}/Participants/{Sid}" path = strings.Replace(path, "{"+"ConversationSid"+"}", ConversationSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -161,7 +168,7 @@ func (c *ApiService) DeleteConversationParticipant(ConversationSid string, Sid s if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -173,6 +180,9 @@ func (c *ApiService) DeleteConversationParticipant(ConversationSid string, Sid s // Fetch a participant of the conversation func (c *ApiService) FetchConversationParticipant(ConversationSid string, Sid string) (*ConversationsV1ConversationParticipant, error) { + return c.FetchConversationParticipantWithContext(context.TODO(), ConversationSid, Sid) +} +func (c *ApiService) FetchConversationParticipantWithContext(ctx context.Context, ConversationSid string, Sid string) (*ConversationsV1ConversationParticipant, error) { path := "/v1/Conversations/{ConversationSid}/Participants/{Sid}" path = strings.Replace(path, "{"+"ConversationSid"+"}", ConversationSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -182,7 +192,7 @@ func (c *ApiService) FetchConversationParticipant(ConversationSid string, Sid st "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -216,6 +226,11 @@ func (params *ListConversationParticipantParams) SetLimit(Limit int) *ListConver // Retrieve a single page of ConversationParticipant records from the API. Request is executed immediately. func (c *ApiService) PageConversationParticipant(ConversationSid string, params *ListConversationParticipantParams, pageToken, pageNumber string) (*ListConversationParticipantResponse, error) { + return c.PageConversationParticipantWithContext(context.TODO(), ConversationSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ConversationParticipant records from the API. Request is executed immediately. +func (c *ApiService) PageConversationParticipantWithContext(ctx context.Context, ConversationSid string, params *ListConversationParticipantParams, pageToken, pageNumber string) (*ListConversationParticipantResponse, error) { path := "/v1/Conversations/{ConversationSid}/Participants" path = strings.Replace(path, "{"+"ConversationSid"+"}", ConversationSid, -1) @@ -236,7 +251,7 @@ func (c *ApiService) PageConversationParticipant(ConversationSid string, params data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -253,7 +268,12 @@ func (c *ApiService) PageConversationParticipant(ConversationSid string, params // Lists ConversationParticipant records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListConversationParticipant(ConversationSid string, params *ListConversationParticipantParams) ([]ConversationsV1ConversationParticipant, error) { - response, errors := c.StreamConversationParticipant(ConversationSid, params) + return c.ListConversationParticipantWithContext(context.TODO(), ConversationSid, params) +} + +// Lists ConversationParticipant records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListConversationParticipantWithContext(ctx context.Context, ConversationSid string, params *ListConversationParticipantParams) ([]ConversationsV1ConversationParticipant, error) { + response, errors := c.StreamConversationParticipantWithContext(ctx, ConversationSid, params) records := make([]ConversationsV1ConversationParticipant, 0) for record := range response { @@ -269,6 +289,11 @@ func (c *ApiService) ListConversationParticipant(ConversationSid string, params // Streams ConversationParticipant records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamConversationParticipant(ConversationSid string, params *ListConversationParticipantParams) (chan ConversationsV1ConversationParticipant, chan error) { + return c.StreamConversationParticipantWithContext(context.TODO(), ConversationSid, params) +} + +// Streams ConversationParticipant records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamConversationParticipantWithContext(ctx context.Context, ConversationSid string, params *ListConversationParticipantParams) (chan ConversationsV1ConversationParticipant, chan error) { if params == nil { params = &ListConversationParticipantParams{} } @@ -277,19 +302,19 @@ func (c *ApiService) StreamConversationParticipant(ConversationSid string, param recordChannel := make(chan ConversationsV1ConversationParticipant, 1) errorChannel := make(chan error, 1) - response, err := c.PageConversationParticipant(ConversationSid, params, "", "") + response, err := c.PageConversationParticipantWithContext(ctx, ConversationSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamConversationParticipant(response, params, recordChannel, errorChannel) + go c.streamConversationParticipantWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamConversationParticipant(response *ListConversationParticipantResponse, params *ListConversationParticipantParams, recordChannel chan ConversationsV1ConversationParticipant, errorChannel chan error) { +func (c *ApiService) streamConversationParticipantWithContext(ctx context.Context, response *ListConversationParticipantResponse, params *ListConversationParticipantParams, recordChannel chan ConversationsV1ConversationParticipant, errorChannel chan error) { curRecord := 1 for response != nil { @@ -304,7 +329,7 @@ func (c *ApiService) streamConversationParticipant(response *ListConversationPar } } - record, err := client.GetNext(c.baseURL, response, c.getNextListConversationParticipantResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListConversationParticipantResponseWithContext) if err != nil { errorChannel <- err break @@ -319,11 +344,11 @@ func (c *ApiService) streamConversationParticipant(response *ListConversationPar close(errorChannel) } -func (c *ApiService) getNextListConversationParticipantResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListConversationParticipantResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -404,6 +429,9 @@ func (params *UpdateConversationParticipantParams) SetLastReadTimestamp(LastRead // Update an existing participant in the conversation func (c *ApiService) UpdateConversationParticipant(ConversationSid string, Sid string, params *UpdateConversationParticipantParams) (*ConversationsV1ConversationParticipant, error) { + return c.UpdateConversationParticipantWithContext(context.TODO(), ConversationSid, Sid, params) +} +func (c *ApiService) UpdateConversationParticipantWithContext(ctx context.Context, ConversationSid string, Sid string, params *UpdateConversationParticipantParams) (*ConversationsV1ConversationParticipant, error) { path := "/v1/Conversations/{ConversationSid}/Participants/{Sid}" path = strings.Replace(path, "{"+"ConversationSid"+"}", ConversationSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -444,7 +472,7 @@ func (c *ApiService) UpdateConversationParticipant(ConversationSid string, Sid s if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/conversations/v1/conversations_webhooks.go b/rest/conversations/v1/conversations_webhooks.go index 20074b4f4..c217b5309 100644 --- a/rest/conversations/v1/conversations_webhooks.go +++ b/rest/conversations/v1/conversations_webhooks.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -72,6 +73,9 @@ func (params *CreateConversationScopedWebhookParams) SetConfigurationReplayAfter // Create a new webhook scoped to the conversation func (c *ApiService) CreateConversationScopedWebhook(ConversationSid string, params *CreateConversationScopedWebhookParams) (*ConversationsV1ConversationScopedWebhook, error) { + return c.CreateConversationScopedWebhookWithContext(context.TODO(), ConversationSid, params) +} +func (c *ApiService) CreateConversationScopedWebhookWithContext(ctx context.Context, ConversationSid string, params *CreateConversationScopedWebhookParams) (*ConversationsV1ConversationScopedWebhook, error) { path := "/v1/Conversations/{ConversationSid}/Webhooks" path = strings.Replace(path, "{"+"ConversationSid"+"}", ConversationSid, -1) @@ -106,7 +110,7 @@ func (c *ApiService) CreateConversationScopedWebhook(ConversationSid string, par data.Set("Configuration.ReplayAfter", fmt.Sprint(*params.ConfigurationReplayAfter)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -123,6 +127,9 @@ func (c *ApiService) CreateConversationScopedWebhook(ConversationSid string, par // Remove an existing webhook scoped to the conversation func (c *ApiService) DeleteConversationScopedWebhook(ConversationSid string, Sid string) error { + return c.DeleteConversationScopedWebhookWithContext(context.TODO(), ConversationSid, Sid) +} +func (c *ApiService) DeleteConversationScopedWebhookWithContext(ctx context.Context, ConversationSid string, Sid string) error { path := "/v1/Conversations/{ConversationSid}/Webhooks/{Sid}" path = strings.Replace(path, "{"+"ConversationSid"+"}", ConversationSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -132,7 +139,7 @@ func (c *ApiService) DeleteConversationScopedWebhook(ConversationSid string, Sid "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -144,6 +151,9 @@ func (c *ApiService) DeleteConversationScopedWebhook(ConversationSid string, Sid // Fetch the configuration of a conversation-scoped webhook func (c *ApiService) FetchConversationScopedWebhook(ConversationSid string, Sid string) (*ConversationsV1ConversationScopedWebhook, error) { + return c.FetchConversationScopedWebhookWithContext(context.TODO(), ConversationSid, Sid) +} +func (c *ApiService) FetchConversationScopedWebhookWithContext(ctx context.Context, ConversationSid string, Sid string) (*ConversationsV1ConversationScopedWebhook, error) { path := "/v1/Conversations/{ConversationSid}/Webhooks/{Sid}" path = strings.Replace(path, "{"+"ConversationSid"+"}", ConversationSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -153,7 +163,7 @@ func (c *ApiService) FetchConversationScopedWebhook(ConversationSid string, Sid "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -187,6 +197,11 @@ func (params *ListConversationScopedWebhookParams) SetLimit(Limit int) *ListConv // Retrieve a single page of ConversationScopedWebhook records from the API. Request is executed immediately. func (c *ApiService) PageConversationScopedWebhook(ConversationSid string, params *ListConversationScopedWebhookParams, pageToken, pageNumber string) (*ListConversationScopedWebhookResponse, error) { + return c.PageConversationScopedWebhookWithContext(context.TODO(), ConversationSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ConversationScopedWebhook records from the API. Request is executed immediately. +func (c *ApiService) PageConversationScopedWebhookWithContext(ctx context.Context, ConversationSid string, params *ListConversationScopedWebhookParams, pageToken, pageNumber string) (*ListConversationScopedWebhookResponse, error) { path := "/v1/Conversations/{ConversationSid}/Webhooks" path = strings.Replace(path, "{"+"ConversationSid"+"}", ConversationSid, -1) @@ -207,7 +222,7 @@ func (c *ApiService) PageConversationScopedWebhook(ConversationSid string, param data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -224,7 +239,12 @@ func (c *ApiService) PageConversationScopedWebhook(ConversationSid string, param // Lists ConversationScopedWebhook records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListConversationScopedWebhook(ConversationSid string, params *ListConversationScopedWebhookParams) ([]ConversationsV1ConversationScopedWebhook, error) { - response, errors := c.StreamConversationScopedWebhook(ConversationSid, params) + return c.ListConversationScopedWebhookWithContext(context.TODO(), ConversationSid, params) +} + +// Lists ConversationScopedWebhook records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListConversationScopedWebhookWithContext(ctx context.Context, ConversationSid string, params *ListConversationScopedWebhookParams) ([]ConversationsV1ConversationScopedWebhook, error) { + response, errors := c.StreamConversationScopedWebhookWithContext(ctx, ConversationSid, params) records := make([]ConversationsV1ConversationScopedWebhook, 0) for record := range response { @@ -240,6 +260,11 @@ func (c *ApiService) ListConversationScopedWebhook(ConversationSid string, param // Streams ConversationScopedWebhook records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamConversationScopedWebhook(ConversationSid string, params *ListConversationScopedWebhookParams) (chan ConversationsV1ConversationScopedWebhook, chan error) { + return c.StreamConversationScopedWebhookWithContext(context.TODO(), ConversationSid, params) +} + +// Streams ConversationScopedWebhook records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamConversationScopedWebhookWithContext(ctx context.Context, ConversationSid string, params *ListConversationScopedWebhookParams) (chan ConversationsV1ConversationScopedWebhook, chan error) { if params == nil { params = &ListConversationScopedWebhookParams{} } @@ -248,19 +273,19 @@ func (c *ApiService) StreamConversationScopedWebhook(ConversationSid string, par recordChannel := make(chan ConversationsV1ConversationScopedWebhook, 1) errorChannel := make(chan error, 1) - response, err := c.PageConversationScopedWebhook(ConversationSid, params, "", "") + response, err := c.PageConversationScopedWebhookWithContext(ctx, ConversationSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamConversationScopedWebhook(response, params, recordChannel, errorChannel) + go c.streamConversationScopedWebhookWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamConversationScopedWebhook(response *ListConversationScopedWebhookResponse, params *ListConversationScopedWebhookParams, recordChannel chan ConversationsV1ConversationScopedWebhook, errorChannel chan error) { +func (c *ApiService) streamConversationScopedWebhookWithContext(ctx context.Context, response *ListConversationScopedWebhookResponse, params *ListConversationScopedWebhookParams, recordChannel chan ConversationsV1ConversationScopedWebhook, errorChannel chan error) { curRecord := 1 for response != nil { @@ -275,7 +300,7 @@ func (c *ApiService) streamConversationScopedWebhook(response *ListConversationS } } - record, err := client.GetNext(c.baseURL, response, c.getNextListConversationScopedWebhookResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListConversationScopedWebhookResponseWithContext) if err != nil { errorChannel <- err break @@ -290,11 +315,11 @@ func (c *ApiService) streamConversationScopedWebhook(response *ListConversationS close(errorChannel) } -func (c *ApiService) getNextListConversationScopedWebhookResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListConversationScopedWebhookResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -345,6 +370,9 @@ func (params *UpdateConversationScopedWebhookParams) SetConfigurationFlowSid(Con // Update an existing conversation-scoped webhook func (c *ApiService) UpdateConversationScopedWebhook(ConversationSid string, Sid string, params *UpdateConversationScopedWebhookParams) (*ConversationsV1ConversationScopedWebhook, error) { + return c.UpdateConversationScopedWebhookWithContext(context.TODO(), ConversationSid, Sid, params) +} +func (c *ApiService) UpdateConversationScopedWebhookWithContext(ctx context.Context, ConversationSid string, Sid string, params *UpdateConversationScopedWebhookParams) (*ConversationsV1ConversationScopedWebhook, error) { path := "/v1/Conversations/{ConversationSid}/Webhooks/{Sid}" path = strings.Replace(path, "{"+"ConversationSid"+"}", ConversationSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -374,7 +402,7 @@ func (c *ApiService) UpdateConversationScopedWebhook(ConversationSid string, Sid data.Set("Configuration.FlowSid", *params.ConfigurationFlowSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/conversations/v1/credentials.go b/rest/conversations/v1/credentials.go index 0fa7e61ba..1f1397688 100644 --- a/rest/conversations/v1/credentials.go +++ b/rest/conversations/v1/credentials.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -72,6 +73,9 @@ func (params *CreateCredentialParams) SetSecret(Secret string) *CreateCredential // Add a new push notification credential to your account func (c *ApiService) CreateCredential(params *CreateCredentialParams) (*ConversationsV1Credential, error) { + return c.CreateCredentialWithContext(context.TODO(), params) +} +func (c *ApiService) CreateCredentialWithContext(ctx context.Context, params *CreateCredentialParams) (*ConversationsV1Credential, error) { path := "/v1/Credentials" data := url.Values{} @@ -101,7 +105,7 @@ func (c *ApiService) CreateCredential(params *CreateCredentialParams) (*Conversa data.Set("Secret", *params.Secret) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -118,6 +122,9 @@ func (c *ApiService) CreateCredential(params *CreateCredentialParams) (*Conversa // Remove a push notification credential from your account func (c *ApiService) DeleteCredential(Sid string) error { + return c.DeleteCredentialWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteCredentialWithContext(ctx context.Context, Sid string) error { path := "/v1/Credentials/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -126,7 +133,7 @@ func (c *ApiService) DeleteCredential(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -138,6 +145,9 @@ func (c *ApiService) DeleteCredential(Sid string) error { // Fetch a push notification credential from your account func (c *ApiService) FetchCredential(Sid string) (*ConversationsV1Credential, error) { + return c.FetchCredentialWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchCredentialWithContext(ctx context.Context, Sid string) (*ConversationsV1Credential, error) { path := "/v1/Credentials/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -146,7 +156,7 @@ func (c *ApiService) FetchCredential(Sid string) (*ConversationsV1Credential, er "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -180,6 +190,11 @@ func (params *ListCredentialParams) SetLimit(Limit int) *ListCredentialParams { // Retrieve a single page of Credential records from the API. Request is executed immediately. func (c *ApiService) PageCredential(params *ListCredentialParams, pageToken, pageNumber string) (*ListCredentialResponse, error) { + return c.PageCredentialWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Credential records from the API. Request is executed immediately. +func (c *ApiService) PageCredentialWithContext(ctx context.Context, params *ListCredentialParams, pageToken, pageNumber string) (*ListCredentialResponse, error) { path := "/v1/Credentials" data := url.Values{} @@ -198,7 +213,7 @@ func (c *ApiService) PageCredential(params *ListCredentialParams, pageToken, pag data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -215,7 +230,12 @@ func (c *ApiService) PageCredential(params *ListCredentialParams, pageToken, pag // Lists Credential records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListCredential(params *ListCredentialParams) ([]ConversationsV1Credential, error) { - response, errors := c.StreamCredential(params) + return c.ListCredentialWithContext(context.TODO(), params) +} + +// Lists Credential records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListCredentialWithContext(ctx context.Context, params *ListCredentialParams) ([]ConversationsV1Credential, error) { + response, errors := c.StreamCredentialWithContext(ctx, params) records := make([]ConversationsV1Credential, 0) for record := range response { @@ -231,6 +251,11 @@ func (c *ApiService) ListCredential(params *ListCredentialParams) ([]Conversatio // Streams Credential records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamCredential(params *ListCredentialParams) (chan ConversationsV1Credential, chan error) { + return c.StreamCredentialWithContext(context.TODO(), params) +} + +// Streams Credential records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamCredentialWithContext(ctx context.Context, params *ListCredentialParams) (chan ConversationsV1Credential, chan error) { if params == nil { params = &ListCredentialParams{} } @@ -239,19 +264,19 @@ func (c *ApiService) StreamCredential(params *ListCredentialParams) (chan Conver recordChannel := make(chan ConversationsV1Credential, 1) errorChannel := make(chan error, 1) - response, err := c.PageCredential(params, "", "") + response, err := c.PageCredentialWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamCredential(response, params, recordChannel, errorChannel) + go c.streamCredentialWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamCredential(response *ListCredentialResponse, params *ListCredentialParams, recordChannel chan ConversationsV1Credential, errorChannel chan error) { +func (c *ApiService) streamCredentialWithContext(ctx context.Context, response *ListCredentialResponse, params *ListCredentialParams, recordChannel chan ConversationsV1Credential, errorChannel chan error) { curRecord := 1 for response != nil { @@ -266,7 +291,7 @@ func (c *ApiService) streamCredential(response *ListCredentialResponse, params * } } - record, err := client.GetNext(c.baseURL, response, c.getNextListCredentialResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListCredentialResponseWithContext) if err != nil { errorChannel <- err break @@ -281,11 +306,11 @@ func (c *ApiService) streamCredential(response *ListCredentialResponse, params * close(errorChannel) } -func (c *ApiService) getNextListCredentialResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListCredentialResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -348,6 +373,9 @@ func (params *UpdateCredentialParams) SetSecret(Secret string) *UpdateCredential // Update an existing push notification credential on your account func (c *ApiService) UpdateCredential(Sid string, params *UpdateCredentialParams) (*ConversationsV1Credential, error) { + return c.UpdateCredentialWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateCredentialWithContext(ctx context.Context, Sid string, params *UpdateCredentialParams) (*ConversationsV1Credential, error) { path := "/v1/Credentials/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -378,7 +406,7 @@ func (c *ApiService) UpdateCredential(Sid string, params *UpdateCredentialParams data.Set("Secret", *params.Secret) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/conversations/v1/participant_conversations.go b/rest/conversations/v1/participant_conversations.go index 94d13f559..614e1f004 100644 --- a/rest/conversations/v1/participant_conversations.go +++ b/rest/conversations/v1/participant_conversations.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -53,6 +54,11 @@ func (params *ListParticipantConversationParams) SetLimit(Limit int) *ListPartic // Retrieve a single page of ParticipantConversation records from the API. Request is executed immediately. func (c *ApiService) PageParticipantConversation(params *ListParticipantConversationParams, pageToken, pageNumber string) (*ListParticipantConversationResponse, error) { + return c.PageParticipantConversationWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of ParticipantConversation records from the API. Request is executed immediately. +func (c *ApiService) PageParticipantConversationWithContext(ctx context.Context, params *ListParticipantConversationParams, pageToken, pageNumber string) (*ListParticipantConversationResponse, error) { path := "/v1/ParticipantConversations" data := url.Values{} @@ -77,7 +83,7 @@ func (c *ApiService) PageParticipantConversation(params *ListParticipantConversa data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -94,7 +100,12 @@ func (c *ApiService) PageParticipantConversation(params *ListParticipantConversa // Lists ParticipantConversation records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListParticipantConversation(params *ListParticipantConversationParams) ([]ConversationsV1ParticipantConversation, error) { - response, errors := c.StreamParticipantConversation(params) + return c.ListParticipantConversationWithContext(context.TODO(), params) +} + +// Lists ParticipantConversation records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListParticipantConversationWithContext(ctx context.Context, params *ListParticipantConversationParams) ([]ConversationsV1ParticipantConversation, error) { + response, errors := c.StreamParticipantConversationWithContext(ctx, params) records := make([]ConversationsV1ParticipantConversation, 0) for record := range response { @@ -110,6 +121,11 @@ func (c *ApiService) ListParticipantConversation(params *ListParticipantConversa // Streams ParticipantConversation records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamParticipantConversation(params *ListParticipantConversationParams) (chan ConversationsV1ParticipantConversation, chan error) { + return c.StreamParticipantConversationWithContext(context.TODO(), params) +} + +// Streams ParticipantConversation records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamParticipantConversationWithContext(ctx context.Context, params *ListParticipantConversationParams) (chan ConversationsV1ParticipantConversation, chan error) { if params == nil { params = &ListParticipantConversationParams{} } @@ -118,19 +134,19 @@ func (c *ApiService) StreamParticipantConversation(params *ListParticipantConver recordChannel := make(chan ConversationsV1ParticipantConversation, 1) errorChannel := make(chan error, 1) - response, err := c.PageParticipantConversation(params, "", "") + response, err := c.PageParticipantConversationWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamParticipantConversation(response, params, recordChannel, errorChannel) + go c.streamParticipantConversationWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamParticipantConversation(response *ListParticipantConversationResponse, params *ListParticipantConversationParams, recordChannel chan ConversationsV1ParticipantConversation, errorChannel chan error) { +func (c *ApiService) streamParticipantConversationWithContext(ctx context.Context, response *ListParticipantConversationResponse, params *ListParticipantConversationParams, recordChannel chan ConversationsV1ParticipantConversation, errorChannel chan error) { curRecord := 1 for response != nil { @@ -145,7 +161,7 @@ func (c *ApiService) streamParticipantConversation(response *ListParticipantConv } } - record, err := client.GetNext(c.baseURL, response, c.getNextListParticipantConversationResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListParticipantConversationResponseWithContext) if err != nil { errorChannel <- err break @@ -160,11 +176,11 @@ func (c *ApiService) streamParticipantConversation(response *ListParticipantConv close(errorChannel) } -func (c *ApiService) getNextListParticipantConversationResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListParticipantConversationResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/conversations/v1/roles.go b/rest/conversations/v1/roles.go index 347303a41..fc463898e 100644 --- a/rest/conversations/v1/roles.go +++ b/rest/conversations/v1/roles.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -48,6 +49,9 @@ func (params *CreateRoleParams) SetPermission(Permission []string) *CreateRolePa // Create a new user role in your account's default service func (c *ApiService) CreateRole(params *CreateRoleParams) (*ConversationsV1Role, error) { + return c.CreateRoleWithContext(context.TODO(), params) +} +func (c *ApiService) CreateRoleWithContext(ctx context.Context, params *CreateRoleParams) (*ConversationsV1Role, error) { path := "/v1/Roles" data := url.Values{} @@ -67,7 +71,7 @@ func (c *ApiService) CreateRole(params *CreateRoleParams) (*ConversationsV1Role, } } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -84,6 +88,9 @@ func (c *ApiService) CreateRole(params *CreateRoleParams) (*ConversationsV1Role, // Remove a user role from your account's default service func (c *ApiService) DeleteRole(Sid string) error { + return c.DeleteRoleWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteRoleWithContext(ctx context.Context, Sid string) error { path := "/v1/Roles/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -92,7 +99,7 @@ func (c *ApiService) DeleteRole(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -104,6 +111,9 @@ func (c *ApiService) DeleteRole(Sid string) error { // Fetch a user role from your account's default service func (c *ApiService) FetchRole(Sid string) (*ConversationsV1Role, error) { + return c.FetchRoleWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchRoleWithContext(ctx context.Context, Sid string) (*ConversationsV1Role, error) { path := "/v1/Roles/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -112,7 +122,7 @@ func (c *ApiService) FetchRole(Sid string) (*ConversationsV1Role, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -146,6 +156,11 @@ func (params *ListRoleParams) SetLimit(Limit int) *ListRoleParams { // Retrieve a single page of Role records from the API. Request is executed immediately. func (c *ApiService) PageRole(params *ListRoleParams, pageToken, pageNumber string) (*ListRoleResponse, error) { + return c.PageRoleWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Role records from the API. Request is executed immediately. +func (c *ApiService) PageRoleWithContext(ctx context.Context, params *ListRoleParams, pageToken, pageNumber string) (*ListRoleResponse, error) { path := "/v1/Roles" data := url.Values{} @@ -164,7 +179,7 @@ func (c *ApiService) PageRole(params *ListRoleParams, pageToken, pageNumber stri data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -181,7 +196,12 @@ func (c *ApiService) PageRole(params *ListRoleParams, pageToken, pageNumber stri // Lists Role records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListRole(params *ListRoleParams) ([]ConversationsV1Role, error) { - response, errors := c.StreamRole(params) + return c.ListRoleWithContext(context.TODO(), params) +} + +// Lists Role records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListRoleWithContext(ctx context.Context, params *ListRoleParams) ([]ConversationsV1Role, error) { + response, errors := c.StreamRoleWithContext(ctx, params) records := make([]ConversationsV1Role, 0) for record := range response { @@ -197,6 +217,11 @@ func (c *ApiService) ListRole(params *ListRoleParams) ([]ConversationsV1Role, er // Streams Role records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamRole(params *ListRoleParams) (chan ConversationsV1Role, chan error) { + return c.StreamRoleWithContext(context.TODO(), params) +} + +// Streams Role records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamRoleWithContext(ctx context.Context, params *ListRoleParams) (chan ConversationsV1Role, chan error) { if params == nil { params = &ListRoleParams{} } @@ -205,19 +230,19 @@ func (c *ApiService) StreamRole(params *ListRoleParams) (chan ConversationsV1Rol recordChannel := make(chan ConversationsV1Role, 1) errorChannel := make(chan error, 1) - response, err := c.PageRole(params, "", "") + response, err := c.PageRoleWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamRole(response, params, recordChannel, errorChannel) + go c.streamRoleWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamRole(response *ListRoleResponse, params *ListRoleParams, recordChannel chan ConversationsV1Role, errorChannel chan error) { +func (c *ApiService) streamRoleWithContext(ctx context.Context, response *ListRoleResponse, params *ListRoleParams, recordChannel chan ConversationsV1Role, errorChannel chan error) { curRecord := 1 for response != nil { @@ -232,7 +257,7 @@ func (c *ApiService) streamRole(response *ListRoleResponse, params *ListRolePara } } - record, err := client.GetNext(c.baseURL, response, c.getNextListRoleResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListRoleResponseWithContext) if err != nil { errorChannel <- err break @@ -247,11 +272,11 @@ func (c *ApiService) streamRole(response *ListRoleResponse, params *ListRolePara close(errorChannel) } -func (c *ApiService) getNextListRoleResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListRoleResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -278,6 +303,9 @@ func (params *UpdateRoleParams) SetPermission(Permission []string) *UpdateRolePa // Update an existing user role in your account's default service func (c *ApiService) UpdateRole(Sid string, params *UpdateRoleParams) (*ConversationsV1Role, error) { + return c.UpdateRoleWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateRoleWithContext(ctx context.Context, Sid string, params *UpdateRoleParams) (*ConversationsV1Role, error) { path := "/v1/Roles/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -292,7 +320,7 @@ func (c *ApiService) UpdateRole(Sid string, params *UpdateRoleParams) (*Conversa } } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/conversations/v1/services.go b/rest/conversations/v1/services.go index dad8368bf..a5a335aaf 100644 --- a/rest/conversations/v1/services.go +++ b/rest/conversations/v1/services.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -36,6 +37,9 @@ func (params *CreateServiceParams) SetFriendlyName(FriendlyName string) *CreateS // Create a new conversation service on your account func (c *ApiService) CreateService(params *CreateServiceParams) (*ConversationsV1Service, error) { + return c.CreateServiceWithContext(context.TODO(), params) +} +func (c *ApiService) CreateServiceWithContext(ctx context.Context, params *CreateServiceParams) (*ConversationsV1Service, error) { path := "/v1/Services" data := url.Values{} @@ -47,7 +51,7 @@ func (c *ApiService) CreateService(params *CreateServiceParams) (*ConversationsV data.Set("FriendlyName", *params.FriendlyName) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -64,6 +68,9 @@ func (c *ApiService) CreateService(params *CreateServiceParams) (*ConversationsV // Remove a conversation service with all its nested resources from your account func (c *ApiService) DeleteService(Sid string) error { + return c.DeleteServiceWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteServiceWithContext(ctx context.Context, Sid string) error { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -72,7 +79,7 @@ func (c *ApiService) DeleteService(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -84,6 +91,9 @@ func (c *ApiService) DeleteService(Sid string) error { // Fetch a conversation service from your account func (c *ApiService) FetchService(Sid string) (*ConversationsV1Service, error) { + return c.FetchServiceWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchServiceWithContext(ctx context.Context, Sid string) (*ConversationsV1Service, error) { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -92,7 +102,7 @@ func (c *ApiService) FetchService(Sid string) (*ConversationsV1Service, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -126,6 +136,11 @@ func (params *ListServiceParams) SetLimit(Limit int) *ListServiceParams { // Retrieve a single page of Service records from the API. Request is executed immediately. func (c *ApiService) PageService(params *ListServiceParams, pageToken, pageNumber string) (*ListServiceResponse, error) { + return c.PageServiceWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Service records from the API. Request is executed immediately. +func (c *ApiService) PageServiceWithContext(ctx context.Context, params *ListServiceParams, pageToken, pageNumber string) (*ListServiceResponse, error) { path := "/v1/Services" data := url.Values{} @@ -144,7 +159,7 @@ func (c *ApiService) PageService(params *ListServiceParams, pageToken, pageNumbe data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -161,7 +176,12 @@ func (c *ApiService) PageService(params *ListServiceParams, pageToken, pageNumbe // Lists Service records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListService(params *ListServiceParams) ([]ConversationsV1Service, error) { - response, errors := c.StreamService(params) + return c.ListServiceWithContext(context.TODO(), params) +} + +// Lists Service records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListServiceWithContext(ctx context.Context, params *ListServiceParams) ([]ConversationsV1Service, error) { + response, errors := c.StreamServiceWithContext(ctx, params) records := make([]ConversationsV1Service, 0) for record := range response { @@ -177,6 +197,11 @@ func (c *ApiService) ListService(params *ListServiceParams) ([]ConversationsV1Se // Streams Service records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamService(params *ListServiceParams) (chan ConversationsV1Service, chan error) { + return c.StreamServiceWithContext(context.TODO(), params) +} + +// Streams Service records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamServiceWithContext(ctx context.Context, params *ListServiceParams) (chan ConversationsV1Service, chan error) { if params == nil { params = &ListServiceParams{} } @@ -185,19 +210,19 @@ func (c *ApiService) StreamService(params *ListServiceParams) (chan Conversation recordChannel := make(chan ConversationsV1Service, 1) errorChannel := make(chan error, 1) - response, err := c.PageService(params, "", "") + response, err := c.PageServiceWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamService(response, params, recordChannel, errorChannel) + go c.streamServiceWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamService(response *ListServiceResponse, params *ListServiceParams, recordChannel chan ConversationsV1Service, errorChannel chan error) { +func (c *ApiService) streamServiceWithContext(ctx context.Context, response *ListServiceResponse, params *ListServiceParams, recordChannel chan ConversationsV1Service, errorChannel chan error) { curRecord := 1 for response != nil { @@ -212,7 +237,7 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListServiceResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListServiceResponseWithContext) if err != nil { errorChannel <- err break @@ -227,11 +252,11 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe close(errorChannel) } -func (c *ApiService) getNextListServiceResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListServiceResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/conversations/v1/services_bindings.go b/rest/conversations/v1/services_bindings.go index 5b87f3f8e..ca23cc405 100644 --- a/rest/conversations/v1/services_bindings.go +++ b/rest/conversations/v1/services_bindings.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -25,6 +26,9 @@ import ( // Remove a push notification binding from the conversation service func (c *ApiService) DeleteServiceBinding(ChatServiceSid string, Sid string) error { + return c.DeleteServiceBindingWithContext(context.TODO(), ChatServiceSid, Sid) +} +func (c *ApiService) DeleteServiceBindingWithContext(ctx context.Context, ChatServiceSid string, Sid string) error { path := "/v1/Services/{ChatServiceSid}/Bindings/{Sid}" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -34,7 +38,7 @@ func (c *ApiService) DeleteServiceBinding(ChatServiceSid string, Sid string) err "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -46,6 +50,9 @@ func (c *ApiService) DeleteServiceBinding(ChatServiceSid string, Sid string) err // Fetch a push notification binding from the conversation service func (c *ApiService) FetchServiceBinding(ChatServiceSid string, Sid string) (*ConversationsV1ServiceBinding, error) { + return c.FetchServiceBindingWithContext(context.TODO(), ChatServiceSid, Sid) +} +func (c *ApiService) FetchServiceBindingWithContext(ctx context.Context, ChatServiceSid string, Sid string) (*ConversationsV1ServiceBinding, error) { path := "/v1/Services/{ChatServiceSid}/Bindings/{Sid}" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -55,7 +62,7 @@ func (c *ApiService) FetchServiceBinding(ChatServiceSid string, Sid string) (*Co "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -101,6 +108,11 @@ func (params *ListServiceBindingParams) SetLimit(Limit int) *ListServiceBindingP // Retrieve a single page of ServiceBinding records from the API. Request is executed immediately. func (c *ApiService) PageServiceBinding(ChatServiceSid string, params *ListServiceBindingParams, pageToken, pageNumber string) (*ListServiceBindingResponse, error) { + return c.PageServiceBindingWithContext(context.TODO(), ChatServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ServiceBinding records from the API. Request is executed immediately. +func (c *ApiService) PageServiceBindingWithContext(ctx context.Context, ChatServiceSid string, params *ListServiceBindingParams, pageToken, pageNumber string) (*ListServiceBindingResponse, error) { path := "/v1/Services/{ChatServiceSid}/Bindings" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) @@ -131,7 +143,7 @@ func (c *ApiService) PageServiceBinding(ChatServiceSid string, params *ListServi data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -148,7 +160,12 @@ func (c *ApiService) PageServiceBinding(ChatServiceSid string, params *ListServi // Lists ServiceBinding records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListServiceBinding(ChatServiceSid string, params *ListServiceBindingParams) ([]ConversationsV1ServiceBinding, error) { - response, errors := c.StreamServiceBinding(ChatServiceSid, params) + return c.ListServiceBindingWithContext(context.TODO(), ChatServiceSid, params) +} + +// Lists ServiceBinding records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListServiceBindingWithContext(ctx context.Context, ChatServiceSid string, params *ListServiceBindingParams) ([]ConversationsV1ServiceBinding, error) { + response, errors := c.StreamServiceBindingWithContext(ctx, ChatServiceSid, params) records := make([]ConversationsV1ServiceBinding, 0) for record := range response { @@ -164,6 +181,11 @@ func (c *ApiService) ListServiceBinding(ChatServiceSid string, params *ListServi // Streams ServiceBinding records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamServiceBinding(ChatServiceSid string, params *ListServiceBindingParams) (chan ConversationsV1ServiceBinding, chan error) { + return c.StreamServiceBindingWithContext(context.TODO(), ChatServiceSid, params) +} + +// Streams ServiceBinding records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamServiceBindingWithContext(ctx context.Context, ChatServiceSid string, params *ListServiceBindingParams) (chan ConversationsV1ServiceBinding, chan error) { if params == nil { params = &ListServiceBindingParams{} } @@ -172,19 +194,19 @@ func (c *ApiService) StreamServiceBinding(ChatServiceSid string, params *ListSer recordChannel := make(chan ConversationsV1ServiceBinding, 1) errorChannel := make(chan error, 1) - response, err := c.PageServiceBinding(ChatServiceSid, params, "", "") + response, err := c.PageServiceBindingWithContext(ctx, ChatServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamServiceBinding(response, params, recordChannel, errorChannel) + go c.streamServiceBindingWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamServiceBinding(response *ListServiceBindingResponse, params *ListServiceBindingParams, recordChannel chan ConversationsV1ServiceBinding, errorChannel chan error) { +func (c *ApiService) streamServiceBindingWithContext(ctx context.Context, response *ListServiceBindingResponse, params *ListServiceBindingParams, recordChannel chan ConversationsV1ServiceBinding, errorChannel chan error) { curRecord := 1 for response != nil { @@ -199,7 +221,7 @@ func (c *ApiService) streamServiceBinding(response *ListServiceBindingResponse, } } - record, err := client.GetNext(c.baseURL, response, c.getNextListServiceBindingResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListServiceBindingResponseWithContext) if err != nil { errorChannel <- err break @@ -214,11 +236,11 @@ func (c *ApiService) streamServiceBinding(response *ListServiceBindingResponse, close(errorChannel) } -func (c *ApiService) getNextListServiceBindingResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListServiceBindingResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/conversations/v1/services_configuration.go b/rest/conversations/v1/services_configuration.go index 13a22e06e..573124b77 100644 --- a/rest/conversations/v1/services_configuration.go +++ b/rest/conversations/v1/services_configuration.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -23,6 +24,9 @@ import ( // Fetch the configuration of a conversation service func (c *ApiService) FetchServiceConfiguration(ChatServiceSid string) (*ConversationsV1ServiceConfiguration, error) { + return c.FetchServiceConfigurationWithContext(context.TODO(), ChatServiceSid) +} +func (c *ApiService) FetchServiceConfigurationWithContext(ctx context.Context, ChatServiceSid string) (*ConversationsV1ServiceConfiguration, error) { path := "/v1/Services/{ChatServiceSid}/Configuration" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) @@ -31,7 +35,7 @@ func (c *ApiService) FetchServiceConfiguration(ChatServiceSid string) (*Conversa "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -77,6 +81,9 @@ func (params *UpdateServiceConfigurationParams) SetReachabilityEnabled(Reachabil // Update configuration settings of a conversation service func (c *ApiService) UpdateServiceConfiguration(ChatServiceSid string, params *UpdateServiceConfigurationParams) (*ConversationsV1ServiceConfiguration, error) { + return c.UpdateServiceConfigurationWithContext(context.TODO(), ChatServiceSid, params) +} +func (c *ApiService) UpdateServiceConfigurationWithContext(ctx context.Context, ChatServiceSid string, params *UpdateServiceConfigurationParams) (*ConversationsV1ServiceConfiguration, error) { path := "/v1/Services/{ChatServiceSid}/Configuration" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) @@ -98,7 +105,7 @@ func (c *ApiService) UpdateServiceConfiguration(ChatServiceSid string, params *U data.Set("ReachabilityEnabled", fmt.Sprint(*params.ReachabilityEnabled)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/conversations/v1/services_configuration_notifications.go b/rest/conversations/v1/services_configuration_notifications.go index 1c077ce3c..bb6e35583 100644 --- a/rest/conversations/v1/services_configuration_notifications.go +++ b/rest/conversations/v1/services_configuration_notifications.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -23,6 +24,9 @@ import ( // Fetch push notification service settings func (c *ApiService) FetchServiceNotification(ChatServiceSid string) (*ConversationsV1ServiceNotification, error) { + return c.FetchServiceNotificationWithContext(context.TODO(), ChatServiceSid) +} +func (c *ApiService) FetchServiceNotificationWithContext(ctx context.Context, ChatServiceSid string) (*ConversationsV1ServiceNotification, error) { path := "/v1/Services/{ChatServiceSid}/Configuration/Notifications" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) @@ -31,7 +35,7 @@ func (c *ApiService) FetchServiceNotification(ChatServiceSid string) (*Conversat "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -131,6 +135,9 @@ func (params *UpdateServiceNotificationParams) SetNewMessageWithMediaTemplate(Ne // Update push notification service settings func (c *ApiService) UpdateServiceNotification(ChatServiceSid string, params *UpdateServiceNotificationParams) (*ConversationsV1ServiceNotification, error) { + return c.UpdateServiceNotificationWithContext(context.TODO(), ChatServiceSid, params) +} +func (c *ApiService) UpdateServiceNotificationWithContext(ctx context.Context, ChatServiceSid string, params *UpdateServiceNotificationParams) (*ConversationsV1ServiceNotification, error) { path := "/v1/Services/{ChatServiceSid}/Configuration/Notifications" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) @@ -179,7 +186,7 @@ func (c *ApiService) UpdateServiceNotification(ChatServiceSid string, params *Up data.Set("NewMessage.WithMedia.Template", *params.NewMessageWithMediaTemplate) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/conversations/v1/services_configuration_webhooks.go b/rest/conversations/v1/services_configuration_webhooks.go index 56d1434ac..0584b8976 100644 --- a/rest/conversations/v1/services_configuration_webhooks.go +++ b/rest/conversations/v1/services_configuration_webhooks.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -22,6 +23,9 @@ import ( // Fetch a specific service webhook configuration. func (c *ApiService) FetchServiceWebhookConfiguration(ChatServiceSid string) (*ConversationsV1ServiceWebhookConfiguration, error) { + return c.FetchServiceWebhookConfigurationWithContext(context.TODO(), ChatServiceSid) +} +func (c *ApiService) FetchServiceWebhookConfigurationWithContext(ctx context.Context, ChatServiceSid string) (*ConversationsV1ServiceWebhookConfiguration, error) { path := "/v1/Services/{ChatServiceSid}/Configuration/Webhooks" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) @@ -30,7 +34,7 @@ func (c *ApiService) FetchServiceWebhookConfiguration(ChatServiceSid string) (*C "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -76,6 +80,9 @@ func (params *UpdateServiceWebhookConfigurationParams) SetMethod(Method string) // Update a specific Webhook. func (c *ApiService) UpdateServiceWebhookConfiguration(ChatServiceSid string, params *UpdateServiceWebhookConfigurationParams) (*ConversationsV1ServiceWebhookConfiguration, error) { + return c.UpdateServiceWebhookConfigurationWithContext(context.TODO(), ChatServiceSid, params) +} +func (c *ApiService) UpdateServiceWebhookConfigurationWithContext(ctx context.Context, ChatServiceSid string, params *UpdateServiceWebhookConfigurationParams) (*ConversationsV1ServiceWebhookConfiguration, error) { path := "/v1/Services/{ChatServiceSid}/Configuration/Webhooks" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) @@ -99,7 +106,7 @@ func (c *ApiService) UpdateServiceWebhookConfiguration(ChatServiceSid string, pa data.Set("Method", *params.Method) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/conversations/v1/services_conversation_with_participants.go b/rest/conversations/v1/services_conversation_with_participants.go index b8d013b21..ab341842c 100644 --- a/rest/conversations/v1/services_conversation_with_participants.go +++ b/rest/conversations/v1/services_conversation_with_participants.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -107,6 +108,9 @@ func (params *CreateServiceConversationWithParticipantsParams) SetParticipant(Pa // Create a new conversation with the list of participants in your account's default service func (c *ApiService) CreateServiceConversationWithParticipants(ChatServiceSid string, params *CreateServiceConversationWithParticipantsParams) (*ConversationsV1ServiceConversationWithParticipants, error) { + return c.CreateServiceConversationWithParticipantsWithContext(context.TODO(), ChatServiceSid, params) +} +func (c *ApiService) CreateServiceConversationWithParticipantsWithContext(ctx context.Context, ChatServiceSid string, params *CreateServiceConversationWithParticipantsParams) (*ConversationsV1ServiceConversationWithParticipants, error) { path := "/v1/Services/{ChatServiceSid}/ConversationWithParticipants" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) @@ -157,7 +161,7 @@ func (c *ApiService) CreateServiceConversationWithParticipants(ChatServiceSid st if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/conversations/v1/services_conversations.go b/rest/conversations/v1/services_conversations.go index 7c5ac635a..d43434379 100644 --- a/rest/conversations/v1/services_conversations.go +++ b/rest/conversations/v1/services_conversations.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -103,6 +104,9 @@ func (params *CreateServiceConversationParams) SetBindingsEmailName(BindingsEmai // Create a new conversation in your service func (c *ApiService) CreateServiceConversation(ChatServiceSid string, params *CreateServiceConversationParams) (*ConversationsV1ServiceConversation, error) { + return c.CreateServiceConversationWithContext(context.TODO(), ChatServiceSid, params) +} +func (c *ApiService) CreateServiceConversationWithContext(ctx context.Context, ChatServiceSid string, params *CreateServiceConversationParams) (*ConversationsV1ServiceConversation, error) { path := "/v1/Services/{ChatServiceSid}/Conversations" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) @@ -148,7 +152,7 @@ func (c *ApiService) CreateServiceConversation(ChatServiceSid string, params *Cr if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -176,6 +180,9 @@ func (params *DeleteServiceConversationParams) SetXTwilioWebhookEnabled(XTwilioW // Remove a conversation from your service func (c *ApiService) DeleteServiceConversation(ChatServiceSid string, Sid string, params *DeleteServiceConversationParams) error { + return c.DeleteServiceConversationWithContext(context.TODO(), ChatServiceSid, Sid, params) +} +func (c *ApiService) DeleteServiceConversationWithContext(ctx context.Context, ChatServiceSid string, Sid string, params *DeleteServiceConversationParams) error { path := "/v1/Services/{ChatServiceSid}/Conversations/{Sid}" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -188,7 +195,7 @@ func (c *ApiService) DeleteServiceConversation(ChatServiceSid string, Sid string if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -200,6 +207,9 @@ func (c *ApiService) DeleteServiceConversation(ChatServiceSid string, Sid string // Fetch a conversation from your service func (c *ApiService) FetchServiceConversation(ChatServiceSid string, Sid string) (*ConversationsV1ServiceConversation, error) { + return c.FetchServiceConversationWithContext(context.TODO(), ChatServiceSid, Sid) +} +func (c *ApiService) FetchServiceConversationWithContext(ctx context.Context, ChatServiceSid string, Sid string) (*ConversationsV1ServiceConversation, error) { path := "/v1/Services/{ChatServiceSid}/Conversations/{Sid}" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -209,7 +219,7 @@ func (c *ApiService) FetchServiceConversation(ChatServiceSid string, Sid string) "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -261,6 +271,11 @@ func (params *ListServiceConversationParams) SetLimit(Limit int) *ListServiceCon // Retrieve a single page of ServiceConversation records from the API. Request is executed immediately. func (c *ApiService) PageServiceConversation(ChatServiceSid string, params *ListServiceConversationParams, pageToken, pageNumber string) (*ListServiceConversationResponse, error) { + return c.PageServiceConversationWithContext(context.TODO(), ChatServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ServiceConversation records from the API. Request is executed immediately. +func (c *ApiService) PageServiceConversationWithContext(ctx context.Context, ChatServiceSid string, params *ListServiceConversationParams, pageToken, pageNumber string) (*ListServiceConversationResponse, error) { path := "/v1/Services/{ChatServiceSid}/Conversations" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) @@ -290,7 +305,7 @@ func (c *ApiService) PageServiceConversation(ChatServiceSid string, params *List data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -307,7 +322,12 @@ func (c *ApiService) PageServiceConversation(ChatServiceSid string, params *List // Lists ServiceConversation records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListServiceConversation(ChatServiceSid string, params *ListServiceConversationParams) ([]ConversationsV1ServiceConversation, error) { - response, errors := c.StreamServiceConversation(ChatServiceSid, params) + return c.ListServiceConversationWithContext(context.TODO(), ChatServiceSid, params) +} + +// Lists ServiceConversation records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListServiceConversationWithContext(ctx context.Context, ChatServiceSid string, params *ListServiceConversationParams) ([]ConversationsV1ServiceConversation, error) { + response, errors := c.StreamServiceConversationWithContext(ctx, ChatServiceSid, params) records := make([]ConversationsV1ServiceConversation, 0) for record := range response { @@ -323,6 +343,11 @@ func (c *ApiService) ListServiceConversation(ChatServiceSid string, params *List // Streams ServiceConversation records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamServiceConversation(ChatServiceSid string, params *ListServiceConversationParams) (chan ConversationsV1ServiceConversation, chan error) { + return c.StreamServiceConversationWithContext(context.TODO(), ChatServiceSid, params) +} + +// Streams ServiceConversation records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamServiceConversationWithContext(ctx context.Context, ChatServiceSid string, params *ListServiceConversationParams) (chan ConversationsV1ServiceConversation, chan error) { if params == nil { params = &ListServiceConversationParams{} } @@ -331,19 +356,19 @@ func (c *ApiService) StreamServiceConversation(ChatServiceSid string, params *Li recordChannel := make(chan ConversationsV1ServiceConversation, 1) errorChannel := make(chan error, 1) - response, err := c.PageServiceConversation(ChatServiceSid, params, "", "") + response, err := c.PageServiceConversationWithContext(ctx, ChatServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamServiceConversation(response, params, recordChannel, errorChannel) + go c.streamServiceConversationWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamServiceConversation(response *ListServiceConversationResponse, params *ListServiceConversationParams, recordChannel chan ConversationsV1ServiceConversation, errorChannel chan error) { +func (c *ApiService) streamServiceConversationWithContext(ctx context.Context, response *ListServiceConversationResponse, params *ListServiceConversationParams, recordChannel chan ConversationsV1ServiceConversation, errorChannel chan error) { curRecord := 1 for response != nil { @@ -358,7 +383,7 @@ func (c *ApiService) streamServiceConversation(response *ListServiceConversation } } - record, err := client.GetNext(c.baseURL, response, c.getNextListServiceConversationResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListServiceConversationResponseWithContext) if err != nil { errorChannel <- err break @@ -373,11 +398,11 @@ func (c *ApiService) streamServiceConversation(response *ListServiceConversation close(errorChannel) } -func (c *ApiService) getNextListServiceConversationResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListServiceConversationResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -470,6 +495,9 @@ func (params *UpdateServiceConversationParams) SetBindingsEmailName(BindingsEmai // Update an existing conversation in your service func (c *ApiService) UpdateServiceConversation(ChatServiceSid string, Sid string, params *UpdateServiceConversationParams) (*ConversationsV1ServiceConversation, error) { + return c.UpdateServiceConversationWithContext(context.TODO(), ChatServiceSid, Sid, params) +} +func (c *ApiService) UpdateServiceConversationWithContext(ctx context.Context, ChatServiceSid string, Sid string, params *UpdateServiceConversationParams) (*ConversationsV1ServiceConversation, error) { path := "/v1/Services/{ChatServiceSid}/Conversations/{Sid}" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -516,7 +544,7 @@ func (c *ApiService) UpdateServiceConversation(ChatServiceSid string, Sid string if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/conversations/v1/services_conversations_messages.go b/rest/conversations/v1/services_conversations_messages.go index 0fe3af4b0..6a8002859 100644 --- a/rest/conversations/v1/services_conversations_messages.go +++ b/rest/conversations/v1/services_conversations_messages.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -91,6 +92,9 @@ func (params *CreateServiceConversationMessageParams) SetSubject(Subject string) // Add a new message to the conversation in a specific service func (c *ApiService) CreateServiceConversationMessage(ChatServiceSid string, ConversationSid string, params *CreateServiceConversationMessageParams) (*ConversationsV1ServiceConversationMessage, error) { + return c.CreateServiceConversationMessageWithContext(context.TODO(), ChatServiceSid, ConversationSid, params) +} +func (c *ApiService) CreateServiceConversationMessageWithContext(ctx context.Context, ChatServiceSid string, ConversationSid string, params *CreateServiceConversationMessageParams) (*ConversationsV1ServiceConversationMessage, error) { path := "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Messages" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) path = strings.Replace(path, "{"+"ConversationSid"+"}", ConversationSid, -1) @@ -131,7 +135,7 @@ func (c *ApiService) CreateServiceConversationMessage(ChatServiceSid string, Con if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -159,6 +163,9 @@ func (params *DeleteServiceConversationMessageParams) SetXTwilioWebhookEnabled(X // Remove a message from the conversation func (c *ApiService) DeleteServiceConversationMessage(ChatServiceSid string, ConversationSid string, Sid string, params *DeleteServiceConversationMessageParams) error { + return c.DeleteServiceConversationMessageWithContext(context.TODO(), ChatServiceSid, ConversationSid, Sid, params) +} +func (c *ApiService) DeleteServiceConversationMessageWithContext(ctx context.Context, ChatServiceSid string, ConversationSid string, Sid string, params *DeleteServiceConversationMessageParams) error { path := "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Messages/{Sid}" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) path = strings.Replace(path, "{"+"ConversationSid"+"}", ConversationSid, -1) @@ -172,7 +179,7 @@ func (c *ApiService) DeleteServiceConversationMessage(ChatServiceSid string, Con if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -184,6 +191,9 @@ func (c *ApiService) DeleteServiceConversationMessage(ChatServiceSid string, Con // Fetch a message from the conversation func (c *ApiService) FetchServiceConversationMessage(ChatServiceSid string, ConversationSid string, Sid string) (*ConversationsV1ServiceConversationMessage, error) { + return c.FetchServiceConversationMessageWithContext(context.TODO(), ChatServiceSid, ConversationSid, Sid) +} +func (c *ApiService) FetchServiceConversationMessageWithContext(ctx context.Context, ChatServiceSid string, ConversationSid string, Sid string) (*ConversationsV1ServiceConversationMessage, error) { path := "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Messages/{Sid}" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) path = strings.Replace(path, "{"+"ConversationSid"+"}", ConversationSid, -1) @@ -194,7 +204,7 @@ func (c *ApiService) FetchServiceConversationMessage(ChatServiceSid string, Conv "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -234,6 +244,11 @@ func (params *ListServiceConversationMessageParams) SetLimit(Limit int) *ListSer // Retrieve a single page of ServiceConversationMessage records from the API. Request is executed immediately. func (c *ApiService) PageServiceConversationMessage(ChatServiceSid string, ConversationSid string, params *ListServiceConversationMessageParams, pageToken, pageNumber string) (*ListServiceConversationMessageResponse, error) { + return c.PageServiceConversationMessageWithContext(context.TODO(), ChatServiceSid, ConversationSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ServiceConversationMessage records from the API. Request is executed immediately. +func (c *ApiService) PageServiceConversationMessageWithContext(ctx context.Context, ChatServiceSid string, ConversationSid string, params *ListServiceConversationMessageParams, pageToken, pageNumber string) (*ListServiceConversationMessageResponse, error) { path := "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Messages" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) @@ -258,7 +273,7 @@ func (c *ApiService) PageServiceConversationMessage(ChatServiceSid string, Conve data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -275,7 +290,12 @@ func (c *ApiService) PageServiceConversationMessage(ChatServiceSid string, Conve // Lists ServiceConversationMessage records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListServiceConversationMessage(ChatServiceSid string, ConversationSid string, params *ListServiceConversationMessageParams) ([]ConversationsV1ServiceConversationMessage, error) { - response, errors := c.StreamServiceConversationMessage(ChatServiceSid, ConversationSid, params) + return c.ListServiceConversationMessageWithContext(context.TODO(), ChatServiceSid, ConversationSid, params) +} + +// Lists ServiceConversationMessage records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListServiceConversationMessageWithContext(ctx context.Context, ChatServiceSid string, ConversationSid string, params *ListServiceConversationMessageParams) ([]ConversationsV1ServiceConversationMessage, error) { + response, errors := c.StreamServiceConversationMessageWithContext(ctx, ChatServiceSid, ConversationSid, params) records := make([]ConversationsV1ServiceConversationMessage, 0) for record := range response { @@ -291,6 +311,11 @@ func (c *ApiService) ListServiceConversationMessage(ChatServiceSid string, Conve // Streams ServiceConversationMessage records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamServiceConversationMessage(ChatServiceSid string, ConversationSid string, params *ListServiceConversationMessageParams) (chan ConversationsV1ServiceConversationMessage, chan error) { + return c.StreamServiceConversationMessageWithContext(context.TODO(), ChatServiceSid, ConversationSid, params) +} + +// Streams ServiceConversationMessage records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamServiceConversationMessageWithContext(ctx context.Context, ChatServiceSid string, ConversationSid string, params *ListServiceConversationMessageParams) (chan ConversationsV1ServiceConversationMessage, chan error) { if params == nil { params = &ListServiceConversationMessageParams{} } @@ -299,19 +324,19 @@ func (c *ApiService) StreamServiceConversationMessage(ChatServiceSid string, Con recordChannel := make(chan ConversationsV1ServiceConversationMessage, 1) errorChannel := make(chan error, 1) - response, err := c.PageServiceConversationMessage(ChatServiceSid, ConversationSid, params, "", "") + response, err := c.PageServiceConversationMessageWithContext(ctx, ChatServiceSid, ConversationSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamServiceConversationMessage(response, params, recordChannel, errorChannel) + go c.streamServiceConversationMessageWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamServiceConversationMessage(response *ListServiceConversationMessageResponse, params *ListServiceConversationMessageParams, recordChannel chan ConversationsV1ServiceConversationMessage, errorChannel chan error) { +func (c *ApiService) streamServiceConversationMessageWithContext(ctx context.Context, response *ListServiceConversationMessageResponse, params *ListServiceConversationMessageParams, recordChannel chan ConversationsV1ServiceConversationMessage, errorChannel chan error) { curRecord := 1 for response != nil { @@ -326,7 +351,7 @@ func (c *ApiService) streamServiceConversationMessage(response *ListServiceConve } } - record, err := client.GetNext(c.baseURL, response, c.getNextListServiceConversationMessageResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListServiceConversationMessageResponseWithContext) if err != nil { errorChannel <- err break @@ -341,11 +366,11 @@ func (c *ApiService) streamServiceConversationMessage(response *ListServiceConve close(errorChannel) } -func (c *ApiService) getNextListServiceConversationMessageResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListServiceConversationMessageResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -408,6 +433,9 @@ func (params *UpdateServiceConversationMessageParams) SetSubject(Subject string) // Update an existing message in the conversation func (c *ApiService) UpdateServiceConversationMessage(ChatServiceSid string, ConversationSid string, Sid string, params *UpdateServiceConversationMessageParams) (*ConversationsV1ServiceConversationMessage, error) { + return c.UpdateServiceConversationMessageWithContext(context.TODO(), ChatServiceSid, ConversationSid, Sid, params) +} +func (c *ApiService) UpdateServiceConversationMessageWithContext(ctx context.Context, ChatServiceSid string, ConversationSid string, Sid string, params *UpdateServiceConversationMessageParams) (*ConversationsV1ServiceConversationMessage, error) { path := "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Messages/{Sid}" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) path = strings.Replace(path, "{"+"ConversationSid"+"}", ConversationSid, -1) @@ -440,7 +468,7 @@ func (c *ApiService) UpdateServiceConversationMessage(ChatServiceSid string, Con if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/conversations/v1/services_conversations_messages_receipts.go b/rest/conversations/v1/services_conversations_messages_receipts.go index 0b113f2e2..e1969b427 100644 --- a/rest/conversations/v1/services_conversations_messages_receipts.go +++ b/rest/conversations/v1/services_conversations_messages_receipts.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -25,6 +26,9 @@ import ( // Fetch the delivery and read receipts of the conversation message func (c *ApiService) FetchServiceConversationMessageReceipt(ChatServiceSid string, ConversationSid string, MessageSid string, Sid string) (*ConversationsV1ServiceConversationMessageReceipt, error) { + return c.FetchServiceConversationMessageReceiptWithContext(context.TODO(), ChatServiceSid, ConversationSid, MessageSid, Sid) +} +func (c *ApiService) FetchServiceConversationMessageReceiptWithContext(ctx context.Context, ChatServiceSid string, ConversationSid string, MessageSid string, Sid string) (*ConversationsV1ServiceConversationMessageReceipt, error) { path := "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Messages/{MessageSid}/Receipts/{Sid}" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) path = strings.Replace(path, "{"+"ConversationSid"+"}", ConversationSid, -1) @@ -36,7 +40,7 @@ func (c *ApiService) FetchServiceConversationMessageReceipt(ChatServiceSid strin "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -70,6 +74,11 @@ func (params *ListServiceConversationMessageReceiptParams) SetLimit(Limit int) * // Retrieve a single page of ServiceConversationMessageReceipt records from the API. Request is executed immediately. func (c *ApiService) PageServiceConversationMessageReceipt(ChatServiceSid string, ConversationSid string, MessageSid string, params *ListServiceConversationMessageReceiptParams, pageToken, pageNumber string) (*ListServiceConversationMessageReceiptResponse, error) { + return c.PageServiceConversationMessageReceiptWithContext(context.TODO(), ChatServiceSid, ConversationSid, MessageSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ServiceConversationMessageReceipt records from the API. Request is executed immediately. +func (c *ApiService) PageServiceConversationMessageReceiptWithContext(ctx context.Context, ChatServiceSid string, ConversationSid string, MessageSid string, params *ListServiceConversationMessageReceiptParams, pageToken, pageNumber string) (*ListServiceConversationMessageReceiptResponse, error) { path := "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Messages/{MessageSid}/Receipts" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) @@ -92,7 +101,7 @@ func (c *ApiService) PageServiceConversationMessageReceipt(ChatServiceSid string data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -109,7 +118,12 @@ func (c *ApiService) PageServiceConversationMessageReceipt(ChatServiceSid string // Lists ServiceConversationMessageReceipt records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListServiceConversationMessageReceipt(ChatServiceSid string, ConversationSid string, MessageSid string, params *ListServiceConversationMessageReceiptParams) ([]ConversationsV1ServiceConversationMessageReceipt, error) { - response, errors := c.StreamServiceConversationMessageReceipt(ChatServiceSid, ConversationSid, MessageSid, params) + return c.ListServiceConversationMessageReceiptWithContext(context.TODO(), ChatServiceSid, ConversationSid, MessageSid, params) +} + +// Lists ServiceConversationMessageReceipt records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListServiceConversationMessageReceiptWithContext(ctx context.Context, ChatServiceSid string, ConversationSid string, MessageSid string, params *ListServiceConversationMessageReceiptParams) ([]ConversationsV1ServiceConversationMessageReceipt, error) { + response, errors := c.StreamServiceConversationMessageReceiptWithContext(ctx, ChatServiceSid, ConversationSid, MessageSid, params) records := make([]ConversationsV1ServiceConversationMessageReceipt, 0) for record := range response { @@ -125,6 +139,11 @@ func (c *ApiService) ListServiceConversationMessageReceipt(ChatServiceSid string // Streams ServiceConversationMessageReceipt records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamServiceConversationMessageReceipt(ChatServiceSid string, ConversationSid string, MessageSid string, params *ListServiceConversationMessageReceiptParams) (chan ConversationsV1ServiceConversationMessageReceipt, chan error) { + return c.StreamServiceConversationMessageReceiptWithContext(context.TODO(), ChatServiceSid, ConversationSid, MessageSid, params) +} + +// Streams ServiceConversationMessageReceipt records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamServiceConversationMessageReceiptWithContext(ctx context.Context, ChatServiceSid string, ConversationSid string, MessageSid string, params *ListServiceConversationMessageReceiptParams) (chan ConversationsV1ServiceConversationMessageReceipt, chan error) { if params == nil { params = &ListServiceConversationMessageReceiptParams{} } @@ -133,19 +152,19 @@ func (c *ApiService) StreamServiceConversationMessageReceipt(ChatServiceSid stri recordChannel := make(chan ConversationsV1ServiceConversationMessageReceipt, 1) errorChannel := make(chan error, 1) - response, err := c.PageServiceConversationMessageReceipt(ChatServiceSid, ConversationSid, MessageSid, params, "", "") + response, err := c.PageServiceConversationMessageReceiptWithContext(ctx, ChatServiceSid, ConversationSid, MessageSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamServiceConversationMessageReceipt(response, params, recordChannel, errorChannel) + go c.streamServiceConversationMessageReceiptWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamServiceConversationMessageReceipt(response *ListServiceConversationMessageReceiptResponse, params *ListServiceConversationMessageReceiptParams, recordChannel chan ConversationsV1ServiceConversationMessageReceipt, errorChannel chan error) { +func (c *ApiService) streamServiceConversationMessageReceiptWithContext(ctx context.Context, response *ListServiceConversationMessageReceiptResponse, params *ListServiceConversationMessageReceiptParams, recordChannel chan ConversationsV1ServiceConversationMessageReceipt, errorChannel chan error) { curRecord := 1 for response != nil { @@ -160,7 +179,7 @@ func (c *ApiService) streamServiceConversationMessageReceipt(response *ListServi } } - record, err := client.GetNext(c.baseURL, response, c.getNextListServiceConversationMessageReceiptResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListServiceConversationMessageReceiptResponseWithContext) if err != nil { errorChannel <- err break @@ -175,11 +194,11 @@ func (c *ApiService) streamServiceConversationMessageReceipt(response *ListServi close(errorChannel) } -func (c *ApiService) getNextListServiceConversationMessageReceiptResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListServiceConversationMessageReceiptResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/conversations/v1/services_conversations_participants.go b/rest/conversations/v1/services_conversations_participants.go index 30bb1b7b5..a8e8036db 100644 --- a/rest/conversations/v1/services_conversations_participants.go +++ b/rest/conversations/v1/services_conversations_participants.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -85,6 +86,9 @@ func (params *CreateServiceConversationParticipantParams) SetRoleSid(RoleSid str // Add a new participant to the conversation in a specific service func (c *ApiService) CreateServiceConversationParticipant(ChatServiceSid string, ConversationSid string, params *CreateServiceConversationParticipantParams) (*ConversationsV1ServiceConversationParticipant, error) { + return c.CreateServiceConversationParticipantWithContext(context.TODO(), ChatServiceSid, ConversationSid, params) +} +func (c *ApiService) CreateServiceConversationParticipantWithContext(ctx context.Context, ChatServiceSid string, ConversationSid string, params *CreateServiceConversationParticipantParams) (*ConversationsV1ServiceConversationParticipant, error) { path := "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Participants" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) path = strings.Replace(path, "{"+"ConversationSid"+"}", ConversationSid, -1) @@ -122,7 +126,7 @@ func (c *ApiService) CreateServiceConversationParticipant(ChatServiceSid string, if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -150,6 +154,9 @@ func (params *DeleteServiceConversationParticipantParams) SetXTwilioWebhookEnabl // Remove a participant from the conversation func (c *ApiService) DeleteServiceConversationParticipant(ChatServiceSid string, ConversationSid string, Sid string, params *DeleteServiceConversationParticipantParams) error { + return c.DeleteServiceConversationParticipantWithContext(context.TODO(), ChatServiceSid, ConversationSid, Sid, params) +} +func (c *ApiService) DeleteServiceConversationParticipantWithContext(ctx context.Context, ChatServiceSid string, ConversationSid string, Sid string, params *DeleteServiceConversationParticipantParams) error { path := "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Participants/{Sid}" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) path = strings.Replace(path, "{"+"ConversationSid"+"}", ConversationSid, -1) @@ -163,7 +170,7 @@ func (c *ApiService) DeleteServiceConversationParticipant(ChatServiceSid string, if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -175,6 +182,9 @@ func (c *ApiService) DeleteServiceConversationParticipant(ChatServiceSid string, // Fetch a participant of the conversation func (c *ApiService) FetchServiceConversationParticipant(ChatServiceSid string, ConversationSid string, Sid string) (*ConversationsV1ServiceConversationParticipant, error) { + return c.FetchServiceConversationParticipantWithContext(context.TODO(), ChatServiceSid, ConversationSid, Sid) +} +func (c *ApiService) FetchServiceConversationParticipantWithContext(ctx context.Context, ChatServiceSid string, ConversationSid string, Sid string) (*ConversationsV1ServiceConversationParticipant, error) { path := "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Participants/{Sid}" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) path = strings.Replace(path, "{"+"ConversationSid"+"}", ConversationSid, -1) @@ -185,7 +195,7 @@ func (c *ApiService) FetchServiceConversationParticipant(ChatServiceSid string, "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -219,6 +229,11 @@ func (params *ListServiceConversationParticipantParams) SetLimit(Limit int) *Lis // Retrieve a single page of ServiceConversationParticipant records from the API. Request is executed immediately. func (c *ApiService) PageServiceConversationParticipant(ChatServiceSid string, ConversationSid string, params *ListServiceConversationParticipantParams, pageToken, pageNumber string) (*ListServiceConversationParticipantResponse, error) { + return c.PageServiceConversationParticipantWithContext(context.TODO(), ChatServiceSid, ConversationSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ServiceConversationParticipant records from the API. Request is executed immediately. +func (c *ApiService) PageServiceConversationParticipantWithContext(ctx context.Context, ChatServiceSid string, ConversationSid string, params *ListServiceConversationParticipantParams, pageToken, pageNumber string) (*ListServiceConversationParticipantResponse, error) { path := "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Participants" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) @@ -240,7 +255,7 @@ func (c *ApiService) PageServiceConversationParticipant(ChatServiceSid string, C data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -257,7 +272,12 @@ func (c *ApiService) PageServiceConversationParticipant(ChatServiceSid string, C // Lists ServiceConversationParticipant records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListServiceConversationParticipant(ChatServiceSid string, ConversationSid string, params *ListServiceConversationParticipantParams) ([]ConversationsV1ServiceConversationParticipant, error) { - response, errors := c.StreamServiceConversationParticipant(ChatServiceSid, ConversationSid, params) + return c.ListServiceConversationParticipantWithContext(context.TODO(), ChatServiceSid, ConversationSid, params) +} + +// Lists ServiceConversationParticipant records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListServiceConversationParticipantWithContext(ctx context.Context, ChatServiceSid string, ConversationSid string, params *ListServiceConversationParticipantParams) ([]ConversationsV1ServiceConversationParticipant, error) { + response, errors := c.StreamServiceConversationParticipantWithContext(ctx, ChatServiceSid, ConversationSid, params) records := make([]ConversationsV1ServiceConversationParticipant, 0) for record := range response { @@ -273,6 +293,11 @@ func (c *ApiService) ListServiceConversationParticipant(ChatServiceSid string, C // Streams ServiceConversationParticipant records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamServiceConversationParticipant(ChatServiceSid string, ConversationSid string, params *ListServiceConversationParticipantParams) (chan ConversationsV1ServiceConversationParticipant, chan error) { + return c.StreamServiceConversationParticipantWithContext(context.TODO(), ChatServiceSid, ConversationSid, params) +} + +// Streams ServiceConversationParticipant records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamServiceConversationParticipantWithContext(ctx context.Context, ChatServiceSid string, ConversationSid string, params *ListServiceConversationParticipantParams) (chan ConversationsV1ServiceConversationParticipant, chan error) { if params == nil { params = &ListServiceConversationParticipantParams{} } @@ -281,19 +306,19 @@ func (c *ApiService) StreamServiceConversationParticipant(ChatServiceSid string, recordChannel := make(chan ConversationsV1ServiceConversationParticipant, 1) errorChannel := make(chan error, 1) - response, err := c.PageServiceConversationParticipant(ChatServiceSid, ConversationSid, params, "", "") + response, err := c.PageServiceConversationParticipantWithContext(ctx, ChatServiceSid, ConversationSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamServiceConversationParticipant(response, params, recordChannel, errorChannel) + go c.streamServiceConversationParticipantWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamServiceConversationParticipant(response *ListServiceConversationParticipantResponse, params *ListServiceConversationParticipantParams, recordChannel chan ConversationsV1ServiceConversationParticipant, errorChannel chan error) { +func (c *ApiService) streamServiceConversationParticipantWithContext(ctx context.Context, response *ListServiceConversationParticipantResponse, params *ListServiceConversationParticipantParams, recordChannel chan ConversationsV1ServiceConversationParticipant, errorChannel chan error) { curRecord := 1 for response != nil { @@ -308,7 +333,7 @@ func (c *ApiService) streamServiceConversationParticipant(response *ListServiceC } } - record, err := client.GetNext(c.baseURL, response, c.getNextListServiceConversationParticipantResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListServiceConversationParticipantResponseWithContext) if err != nil { errorChannel <- err break @@ -323,11 +348,11 @@ func (c *ApiService) streamServiceConversationParticipant(response *ListServiceC close(errorChannel) } -func (c *ApiService) getNextListServiceConversationParticipantResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListServiceConversationParticipantResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -408,6 +433,9 @@ func (params *UpdateServiceConversationParticipantParams) SetLastReadTimestamp(L // Update an existing participant in the conversation func (c *ApiService) UpdateServiceConversationParticipant(ChatServiceSid string, ConversationSid string, Sid string, params *UpdateServiceConversationParticipantParams) (*ConversationsV1ServiceConversationParticipant, error) { + return c.UpdateServiceConversationParticipantWithContext(context.TODO(), ChatServiceSid, ConversationSid, Sid, params) +} +func (c *ApiService) UpdateServiceConversationParticipantWithContext(ctx context.Context, ChatServiceSid string, ConversationSid string, Sid string, params *UpdateServiceConversationParticipantParams) (*ConversationsV1ServiceConversationParticipant, error) { path := "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Participants/{Sid}" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) path = strings.Replace(path, "{"+"ConversationSid"+"}", ConversationSid, -1) @@ -449,7 +477,7 @@ func (c *ApiService) UpdateServiceConversationParticipant(ChatServiceSid string, if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/conversations/v1/services_conversations_webhooks.go b/rest/conversations/v1/services_conversations_webhooks.go index 37470eb7a..4de888828 100644 --- a/rest/conversations/v1/services_conversations_webhooks.go +++ b/rest/conversations/v1/services_conversations_webhooks.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -72,6 +73,9 @@ func (params *CreateServiceConversationScopedWebhookParams) SetConfigurationRepl // Create a new webhook scoped to the conversation in a specific service func (c *ApiService) CreateServiceConversationScopedWebhook(ChatServiceSid string, ConversationSid string, params *CreateServiceConversationScopedWebhookParams) (*ConversationsV1ServiceConversationScopedWebhook, error) { + return c.CreateServiceConversationScopedWebhookWithContext(context.TODO(), ChatServiceSid, ConversationSid, params) +} +func (c *ApiService) CreateServiceConversationScopedWebhookWithContext(ctx context.Context, ChatServiceSid string, ConversationSid string, params *CreateServiceConversationScopedWebhookParams) (*ConversationsV1ServiceConversationScopedWebhook, error) { path := "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Webhooks" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) path = strings.Replace(path, "{"+"ConversationSid"+"}", ConversationSid, -1) @@ -107,7 +111,7 @@ func (c *ApiService) CreateServiceConversationScopedWebhook(ChatServiceSid strin data.Set("Configuration.ReplayAfter", fmt.Sprint(*params.ConfigurationReplayAfter)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -124,6 +128,9 @@ func (c *ApiService) CreateServiceConversationScopedWebhook(ChatServiceSid strin // Remove an existing webhook scoped to the conversation func (c *ApiService) DeleteServiceConversationScopedWebhook(ChatServiceSid string, ConversationSid string, Sid string) error { + return c.DeleteServiceConversationScopedWebhookWithContext(context.TODO(), ChatServiceSid, ConversationSid, Sid) +} +func (c *ApiService) DeleteServiceConversationScopedWebhookWithContext(ctx context.Context, ChatServiceSid string, ConversationSid string, Sid string) error { path := "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Webhooks/{Sid}" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) path = strings.Replace(path, "{"+"ConversationSid"+"}", ConversationSid, -1) @@ -134,7 +141,7 @@ func (c *ApiService) DeleteServiceConversationScopedWebhook(ChatServiceSid strin "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -146,6 +153,9 @@ func (c *ApiService) DeleteServiceConversationScopedWebhook(ChatServiceSid strin // Fetch the configuration of a conversation-scoped webhook func (c *ApiService) FetchServiceConversationScopedWebhook(ChatServiceSid string, ConversationSid string, Sid string) (*ConversationsV1ServiceConversationScopedWebhook, error) { + return c.FetchServiceConversationScopedWebhookWithContext(context.TODO(), ChatServiceSid, ConversationSid, Sid) +} +func (c *ApiService) FetchServiceConversationScopedWebhookWithContext(ctx context.Context, ChatServiceSid string, ConversationSid string, Sid string) (*ConversationsV1ServiceConversationScopedWebhook, error) { path := "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Webhooks/{Sid}" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) path = strings.Replace(path, "{"+"ConversationSid"+"}", ConversationSid, -1) @@ -156,7 +166,7 @@ func (c *ApiService) FetchServiceConversationScopedWebhook(ChatServiceSid string "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -190,6 +200,11 @@ func (params *ListServiceConversationScopedWebhookParams) SetLimit(Limit int) *L // Retrieve a single page of ServiceConversationScopedWebhook records from the API. Request is executed immediately. func (c *ApiService) PageServiceConversationScopedWebhook(ChatServiceSid string, ConversationSid string, params *ListServiceConversationScopedWebhookParams, pageToken, pageNumber string) (*ListServiceConversationScopedWebhookResponse, error) { + return c.PageServiceConversationScopedWebhookWithContext(context.TODO(), ChatServiceSid, ConversationSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ServiceConversationScopedWebhook records from the API. Request is executed immediately. +func (c *ApiService) PageServiceConversationScopedWebhookWithContext(ctx context.Context, ChatServiceSid string, ConversationSid string, params *ListServiceConversationScopedWebhookParams, pageToken, pageNumber string) (*ListServiceConversationScopedWebhookResponse, error) { path := "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Webhooks" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) @@ -211,7 +226,7 @@ func (c *ApiService) PageServiceConversationScopedWebhook(ChatServiceSid string, data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -228,7 +243,12 @@ func (c *ApiService) PageServiceConversationScopedWebhook(ChatServiceSid string, // Lists ServiceConversationScopedWebhook records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListServiceConversationScopedWebhook(ChatServiceSid string, ConversationSid string, params *ListServiceConversationScopedWebhookParams) ([]ConversationsV1ServiceConversationScopedWebhook, error) { - response, errors := c.StreamServiceConversationScopedWebhook(ChatServiceSid, ConversationSid, params) + return c.ListServiceConversationScopedWebhookWithContext(context.TODO(), ChatServiceSid, ConversationSid, params) +} + +// Lists ServiceConversationScopedWebhook records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListServiceConversationScopedWebhookWithContext(ctx context.Context, ChatServiceSid string, ConversationSid string, params *ListServiceConversationScopedWebhookParams) ([]ConversationsV1ServiceConversationScopedWebhook, error) { + response, errors := c.StreamServiceConversationScopedWebhookWithContext(ctx, ChatServiceSid, ConversationSid, params) records := make([]ConversationsV1ServiceConversationScopedWebhook, 0) for record := range response { @@ -244,6 +264,11 @@ func (c *ApiService) ListServiceConversationScopedWebhook(ChatServiceSid string, // Streams ServiceConversationScopedWebhook records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamServiceConversationScopedWebhook(ChatServiceSid string, ConversationSid string, params *ListServiceConversationScopedWebhookParams) (chan ConversationsV1ServiceConversationScopedWebhook, chan error) { + return c.StreamServiceConversationScopedWebhookWithContext(context.TODO(), ChatServiceSid, ConversationSid, params) +} + +// Streams ServiceConversationScopedWebhook records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamServiceConversationScopedWebhookWithContext(ctx context.Context, ChatServiceSid string, ConversationSid string, params *ListServiceConversationScopedWebhookParams) (chan ConversationsV1ServiceConversationScopedWebhook, chan error) { if params == nil { params = &ListServiceConversationScopedWebhookParams{} } @@ -252,19 +277,19 @@ func (c *ApiService) StreamServiceConversationScopedWebhook(ChatServiceSid strin recordChannel := make(chan ConversationsV1ServiceConversationScopedWebhook, 1) errorChannel := make(chan error, 1) - response, err := c.PageServiceConversationScopedWebhook(ChatServiceSid, ConversationSid, params, "", "") + response, err := c.PageServiceConversationScopedWebhookWithContext(ctx, ChatServiceSid, ConversationSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamServiceConversationScopedWebhook(response, params, recordChannel, errorChannel) + go c.streamServiceConversationScopedWebhookWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamServiceConversationScopedWebhook(response *ListServiceConversationScopedWebhookResponse, params *ListServiceConversationScopedWebhookParams, recordChannel chan ConversationsV1ServiceConversationScopedWebhook, errorChannel chan error) { +func (c *ApiService) streamServiceConversationScopedWebhookWithContext(ctx context.Context, response *ListServiceConversationScopedWebhookResponse, params *ListServiceConversationScopedWebhookParams, recordChannel chan ConversationsV1ServiceConversationScopedWebhook, errorChannel chan error) { curRecord := 1 for response != nil { @@ -279,7 +304,7 @@ func (c *ApiService) streamServiceConversationScopedWebhook(response *ListServic } } - record, err := client.GetNext(c.baseURL, response, c.getNextListServiceConversationScopedWebhookResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListServiceConversationScopedWebhookResponseWithContext) if err != nil { errorChannel <- err break @@ -294,11 +319,11 @@ func (c *ApiService) streamServiceConversationScopedWebhook(response *ListServic close(errorChannel) } -func (c *ApiService) getNextListServiceConversationScopedWebhookResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListServiceConversationScopedWebhookResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -349,6 +374,9 @@ func (params *UpdateServiceConversationScopedWebhookParams) SetConfigurationFlow // Update an existing conversation-scoped webhook func (c *ApiService) UpdateServiceConversationScopedWebhook(ChatServiceSid string, ConversationSid string, Sid string, params *UpdateServiceConversationScopedWebhookParams) (*ConversationsV1ServiceConversationScopedWebhook, error) { + return c.UpdateServiceConversationScopedWebhookWithContext(context.TODO(), ChatServiceSid, ConversationSid, Sid, params) +} +func (c *ApiService) UpdateServiceConversationScopedWebhookWithContext(ctx context.Context, ChatServiceSid string, ConversationSid string, Sid string, params *UpdateServiceConversationScopedWebhookParams) (*ConversationsV1ServiceConversationScopedWebhook, error) { path := "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Webhooks/{Sid}" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) path = strings.Replace(path, "{"+"ConversationSid"+"}", ConversationSid, -1) @@ -379,7 +407,7 @@ func (c *ApiService) UpdateServiceConversationScopedWebhook(ChatServiceSid strin data.Set("Configuration.FlowSid", *params.ConfigurationFlowSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/conversations/v1/services_participant_conversations.go b/rest/conversations/v1/services_participant_conversations.go index 3801747ce..7ae951029 100644 --- a/rest/conversations/v1/services_participant_conversations.go +++ b/rest/conversations/v1/services_participant_conversations.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -54,6 +55,11 @@ func (params *ListServiceParticipantConversationParams) SetLimit(Limit int) *Lis // Retrieve a single page of ServiceParticipantConversation records from the API. Request is executed immediately. func (c *ApiService) PageServiceParticipantConversation(ChatServiceSid string, params *ListServiceParticipantConversationParams, pageToken, pageNumber string) (*ListServiceParticipantConversationResponse, error) { + return c.PageServiceParticipantConversationWithContext(context.TODO(), ChatServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ServiceParticipantConversation records from the API. Request is executed immediately. +func (c *ApiService) PageServiceParticipantConversationWithContext(ctx context.Context, ChatServiceSid string, params *ListServiceParticipantConversationParams, pageToken, pageNumber string) (*ListServiceParticipantConversationResponse, error) { path := "/v1/Services/{ChatServiceSid}/ParticipantConversations" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) @@ -80,7 +86,7 @@ func (c *ApiService) PageServiceParticipantConversation(ChatServiceSid string, p data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -97,7 +103,12 @@ func (c *ApiService) PageServiceParticipantConversation(ChatServiceSid string, p // Lists ServiceParticipantConversation records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListServiceParticipantConversation(ChatServiceSid string, params *ListServiceParticipantConversationParams) ([]ConversationsV1ServiceParticipantConversation, error) { - response, errors := c.StreamServiceParticipantConversation(ChatServiceSid, params) + return c.ListServiceParticipantConversationWithContext(context.TODO(), ChatServiceSid, params) +} + +// Lists ServiceParticipantConversation records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListServiceParticipantConversationWithContext(ctx context.Context, ChatServiceSid string, params *ListServiceParticipantConversationParams) ([]ConversationsV1ServiceParticipantConversation, error) { + response, errors := c.StreamServiceParticipantConversationWithContext(ctx, ChatServiceSid, params) records := make([]ConversationsV1ServiceParticipantConversation, 0) for record := range response { @@ -113,6 +124,11 @@ func (c *ApiService) ListServiceParticipantConversation(ChatServiceSid string, p // Streams ServiceParticipantConversation records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamServiceParticipantConversation(ChatServiceSid string, params *ListServiceParticipantConversationParams) (chan ConversationsV1ServiceParticipantConversation, chan error) { + return c.StreamServiceParticipantConversationWithContext(context.TODO(), ChatServiceSid, params) +} + +// Streams ServiceParticipantConversation records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamServiceParticipantConversationWithContext(ctx context.Context, ChatServiceSid string, params *ListServiceParticipantConversationParams) (chan ConversationsV1ServiceParticipantConversation, chan error) { if params == nil { params = &ListServiceParticipantConversationParams{} } @@ -121,19 +137,19 @@ func (c *ApiService) StreamServiceParticipantConversation(ChatServiceSid string, recordChannel := make(chan ConversationsV1ServiceParticipantConversation, 1) errorChannel := make(chan error, 1) - response, err := c.PageServiceParticipantConversation(ChatServiceSid, params, "", "") + response, err := c.PageServiceParticipantConversationWithContext(ctx, ChatServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamServiceParticipantConversation(response, params, recordChannel, errorChannel) + go c.streamServiceParticipantConversationWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamServiceParticipantConversation(response *ListServiceParticipantConversationResponse, params *ListServiceParticipantConversationParams, recordChannel chan ConversationsV1ServiceParticipantConversation, errorChannel chan error) { +func (c *ApiService) streamServiceParticipantConversationWithContext(ctx context.Context, response *ListServiceParticipantConversationResponse, params *ListServiceParticipantConversationParams, recordChannel chan ConversationsV1ServiceParticipantConversation, errorChannel chan error) { curRecord := 1 for response != nil { @@ -148,7 +164,7 @@ func (c *ApiService) streamServiceParticipantConversation(response *ListServiceP } } - record, err := client.GetNext(c.baseURL, response, c.getNextListServiceParticipantConversationResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListServiceParticipantConversationResponseWithContext) if err != nil { errorChannel <- err break @@ -163,11 +179,11 @@ func (c *ApiService) streamServiceParticipantConversation(response *ListServiceP close(errorChannel) } -func (c *ApiService) getNextListServiceParticipantConversationResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListServiceParticipantConversationResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/conversations/v1/services_roles.go b/rest/conversations/v1/services_roles.go index be79b2017..cb75062b9 100644 --- a/rest/conversations/v1/services_roles.go +++ b/rest/conversations/v1/services_roles.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -48,6 +49,9 @@ func (params *CreateServiceRoleParams) SetPermission(Permission []string) *Creat // Create a new user role in your service func (c *ApiService) CreateServiceRole(ChatServiceSid string, params *CreateServiceRoleParams) (*ConversationsV1ServiceRole, error) { + return c.CreateServiceRoleWithContext(context.TODO(), ChatServiceSid, params) +} +func (c *ApiService) CreateServiceRoleWithContext(ctx context.Context, ChatServiceSid string, params *CreateServiceRoleParams) (*ConversationsV1ServiceRole, error) { path := "/v1/Services/{ChatServiceSid}/Roles" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) @@ -68,7 +72,7 @@ func (c *ApiService) CreateServiceRole(ChatServiceSid string, params *CreateServ } } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -85,6 +89,9 @@ func (c *ApiService) CreateServiceRole(ChatServiceSid string, params *CreateServ // Remove a user role from your service func (c *ApiService) DeleteServiceRole(ChatServiceSid string, Sid string) error { + return c.DeleteServiceRoleWithContext(context.TODO(), ChatServiceSid, Sid) +} +func (c *ApiService) DeleteServiceRoleWithContext(ctx context.Context, ChatServiceSid string, Sid string) error { path := "/v1/Services/{ChatServiceSid}/Roles/{Sid}" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -94,7 +101,7 @@ func (c *ApiService) DeleteServiceRole(ChatServiceSid string, Sid string) error "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -106,6 +113,9 @@ func (c *ApiService) DeleteServiceRole(ChatServiceSid string, Sid string) error // Fetch a user role from your service func (c *ApiService) FetchServiceRole(ChatServiceSid string, Sid string) (*ConversationsV1ServiceRole, error) { + return c.FetchServiceRoleWithContext(context.TODO(), ChatServiceSid, Sid) +} +func (c *ApiService) FetchServiceRoleWithContext(ctx context.Context, ChatServiceSid string, Sid string) (*ConversationsV1ServiceRole, error) { path := "/v1/Services/{ChatServiceSid}/Roles/{Sid}" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -115,7 +125,7 @@ func (c *ApiService) FetchServiceRole(ChatServiceSid string, Sid string) (*Conve "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -149,6 +159,11 @@ func (params *ListServiceRoleParams) SetLimit(Limit int) *ListServiceRoleParams // Retrieve a single page of ServiceRole records from the API. Request is executed immediately. func (c *ApiService) PageServiceRole(ChatServiceSid string, params *ListServiceRoleParams, pageToken, pageNumber string) (*ListServiceRoleResponse, error) { + return c.PageServiceRoleWithContext(context.TODO(), ChatServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ServiceRole records from the API. Request is executed immediately. +func (c *ApiService) PageServiceRoleWithContext(ctx context.Context, ChatServiceSid string, params *ListServiceRoleParams, pageToken, pageNumber string) (*ListServiceRoleResponse, error) { path := "/v1/Services/{ChatServiceSid}/Roles" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) @@ -169,7 +184,7 @@ func (c *ApiService) PageServiceRole(ChatServiceSid string, params *ListServiceR data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -186,7 +201,12 @@ func (c *ApiService) PageServiceRole(ChatServiceSid string, params *ListServiceR // Lists ServiceRole records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListServiceRole(ChatServiceSid string, params *ListServiceRoleParams) ([]ConversationsV1ServiceRole, error) { - response, errors := c.StreamServiceRole(ChatServiceSid, params) + return c.ListServiceRoleWithContext(context.TODO(), ChatServiceSid, params) +} + +// Lists ServiceRole records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListServiceRoleWithContext(ctx context.Context, ChatServiceSid string, params *ListServiceRoleParams) ([]ConversationsV1ServiceRole, error) { + response, errors := c.StreamServiceRoleWithContext(ctx, ChatServiceSid, params) records := make([]ConversationsV1ServiceRole, 0) for record := range response { @@ -202,6 +222,11 @@ func (c *ApiService) ListServiceRole(ChatServiceSid string, params *ListServiceR // Streams ServiceRole records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamServiceRole(ChatServiceSid string, params *ListServiceRoleParams) (chan ConversationsV1ServiceRole, chan error) { + return c.StreamServiceRoleWithContext(context.TODO(), ChatServiceSid, params) +} + +// Streams ServiceRole records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamServiceRoleWithContext(ctx context.Context, ChatServiceSid string, params *ListServiceRoleParams) (chan ConversationsV1ServiceRole, chan error) { if params == nil { params = &ListServiceRoleParams{} } @@ -210,19 +235,19 @@ func (c *ApiService) StreamServiceRole(ChatServiceSid string, params *ListServic recordChannel := make(chan ConversationsV1ServiceRole, 1) errorChannel := make(chan error, 1) - response, err := c.PageServiceRole(ChatServiceSid, params, "", "") + response, err := c.PageServiceRoleWithContext(ctx, ChatServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamServiceRole(response, params, recordChannel, errorChannel) + go c.streamServiceRoleWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamServiceRole(response *ListServiceRoleResponse, params *ListServiceRoleParams, recordChannel chan ConversationsV1ServiceRole, errorChannel chan error) { +func (c *ApiService) streamServiceRoleWithContext(ctx context.Context, response *ListServiceRoleResponse, params *ListServiceRoleParams, recordChannel chan ConversationsV1ServiceRole, errorChannel chan error) { curRecord := 1 for response != nil { @@ -237,7 +262,7 @@ func (c *ApiService) streamServiceRole(response *ListServiceRoleResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListServiceRoleResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListServiceRoleResponseWithContext) if err != nil { errorChannel <- err break @@ -252,11 +277,11 @@ func (c *ApiService) streamServiceRole(response *ListServiceRoleResponse, params close(errorChannel) } -func (c *ApiService) getNextListServiceRoleResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListServiceRoleResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -283,6 +308,9 @@ func (params *UpdateServiceRoleParams) SetPermission(Permission []string) *Updat // Update an existing user role in your service func (c *ApiService) UpdateServiceRole(ChatServiceSid string, Sid string, params *UpdateServiceRoleParams) (*ConversationsV1ServiceRole, error) { + return c.UpdateServiceRoleWithContext(context.TODO(), ChatServiceSid, Sid, params) +} +func (c *ApiService) UpdateServiceRoleWithContext(ctx context.Context, ChatServiceSid string, Sid string, params *UpdateServiceRoleParams) (*ConversationsV1ServiceRole, error) { path := "/v1/Services/{ChatServiceSid}/Roles/{Sid}" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -298,7 +326,7 @@ func (c *ApiService) UpdateServiceRole(ChatServiceSid string, Sid string, params } } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/conversations/v1/services_users.go b/rest/conversations/v1/services_users.go index f69423acb..54a5c8b21 100644 --- a/rest/conversations/v1/services_users.go +++ b/rest/conversations/v1/services_users.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -60,6 +61,9 @@ func (params *CreateServiceUserParams) SetRoleSid(RoleSid string) *CreateService // Add a new conversation user to your service func (c *ApiService) CreateServiceUser(ChatServiceSid string, params *CreateServiceUserParams) (*ConversationsV1ServiceUser, error) { + return c.CreateServiceUserWithContext(context.TODO(), ChatServiceSid, params) +} +func (c *ApiService) CreateServiceUserWithContext(ctx context.Context, ChatServiceSid string, params *CreateServiceUserParams) (*ConversationsV1ServiceUser, error) { path := "/v1/Services/{ChatServiceSid}/Users" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) @@ -84,7 +88,7 @@ func (c *ApiService) CreateServiceUser(ChatServiceSid string, params *CreateServ if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -112,6 +116,9 @@ func (params *DeleteServiceUserParams) SetXTwilioWebhookEnabled(XTwilioWebhookEn // Remove a conversation user from your service func (c *ApiService) DeleteServiceUser(ChatServiceSid string, Sid string, params *DeleteServiceUserParams) error { + return c.DeleteServiceUserWithContext(context.TODO(), ChatServiceSid, Sid, params) +} +func (c *ApiService) DeleteServiceUserWithContext(ctx context.Context, ChatServiceSid string, Sid string, params *DeleteServiceUserParams) error { path := "/v1/Services/{ChatServiceSid}/Users/{Sid}" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -124,7 +131,7 @@ func (c *ApiService) DeleteServiceUser(ChatServiceSid string, Sid string, params if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -136,6 +143,9 @@ func (c *ApiService) DeleteServiceUser(ChatServiceSid string, Sid string, params // Fetch a conversation user from your service func (c *ApiService) FetchServiceUser(ChatServiceSid string, Sid string) (*ConversationsV1ServiceUser, error) { + return c.FetchServiceUserWithContext(context.TODO(), ChatServiceSid, Sid) +} +func (c *ApiService) FetchServiceUserWithContext(ctx context.Context, ChatServiceSid string, Sid string) (*ConversationsV1ServiceUser, error) { path := "/v1/Services/{ChatServiceSid}/Users/{Sid}" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -145,7 +155,7 @@ func (c *ApiService) FetchServiceUser(ChatServiceSid string, Sid string) (*Conve "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -179,6 +189,11 @@ func (params *ListServiceUserParams) SetLimit(Limit int) *ListServiceUserParams // Retrieve a single page of ServiceUser records from the API. Request is executed immediately. func (c *ApiService) PageServiceUser(ChatServiceSid string, params *ListServiceUserParams, pageToken, pageNumber string) (*ListServiceUserResponse, error) { + return c.PageServiceUserWithContext(context.TODO(), ChatServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ServiceUser records from the API. Request is executed immediately. +func (c *ApiService) PageServiceUserWithContext(ctx context.Context, ChatServiceSid string, params *ListServiceUserParams, pageToken, pageNumber string) (*ListServiceUserResponse, error) { path := "/v1/Services/{ChatServiceSid}/Users" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) @@ -199,7 +214,7 @@ func (c *ApiService) PageServiceUser(ChatServiceSid string, params *ListServiceU data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -216,7 +231,12 @@ func (c *ApiService) PageServiceUser(ChatServiceSid string, params *ListServiceU // Lists ServiceUser records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListServiceUser(ChatServiceSid string, params *ListServiceUserParams) ([]ConversationsV1ServiceUser, error) { - response, errors := c.StreamServiceUser(ChatServiceSid, params) + return c.ListServiceUserWithContext(context.TODO(), ChatServiceSid, params) +} + +// Lists ServiceUser records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListServiceUserWithContext(ctx context.Context, ChatServiceSid string, params *ListServiceUserParams) ([]ConversationsV1ServiceUser, error) { + response, errors := c.StreamServiceUserWithContext(ctx, ChatServiceSid, params) records := make([]ConversationsV1ServiceUser, 0) for record := range response { @@ -232,6 +252,11 @@ func (c *ApiService) ListServiceUser(ChatServiceSid string, params *ListServiceU // Streams ServiceUser records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamServiceUser(ChatServiceSid string, params *ListServiceUserParams) (chan ConversationsV1ServiceUser, chan error) { + return c.StreamServiceUserWithContext(context.TODO(), ChatServiceSid, params) +} + +// Streams ServiceUser records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamServiceUserWithContext(ctx context.Context, ChatServiceSid string, params *ListServiceUserParams) (chan ConversationsV1ServiceUser, chan error) { if params == nil { params = &ListServiceUserParams{} } @@ -240,19 +265,19 @@ func (c *ApiService) StreamServiceUser(ChatServiceSid string, params *ListServic recordChannel := make(chan ConversationsV1ServiceUser, 1) errorChannel := make(chan error, 1) - response, err := c.PageServiceUser(ChatServiceSid, params, "", "") + response, err := c.PageServiceUserWithContext(ctx, ChatServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamServiceUser(response, params, recordChannel, errorChannel) + go c.streamServiceUserWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamServiceUser(response *ListServiceUserResponse, params *ListServiceUserParams, recordChannel chan ConversationsV1ServiceUser, errorChannel chan error) { +func (c *ApiService) streamServiceUserWithContext(ctx context.Context, response *ListServiceUserResponse, params *ListServiceUserParams, recordChannel chan ConversationsV1ServiceUser, errorChannel chan error) { curRecord := 1 for response != nil { @@ -267,7 +292,7 @@ func (c *ApiService) streamServiceUser(response *ListServiceUserResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListServiceUserResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListServiceUserResponseWithContext) if err != nil { errorChannel <- err break @@ -282,11 +307,11 @@ func (c *ApiService) streamServiceUser(response *ListServiceUserResponse, params close(errorChannel) } -func (c *ApiService) getNextListServiceUserResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListServiceUserResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -331,6 +356,9 @@ func (params *UpdateServiceUserParams) SetRoleSid(RoleSid string) *UpdateService // Update an existing conversation user in your service func (c *ApiService) UpdateServiceUser(ChatServiceSid string, Sid string, params *UpdateServiceUserParams) (*ConversationsV1ServiceUser, error) { + return c.UpdateServiceUserWithContext(context.TODO(), ChatServiceSid, Sid, params) +} +func (c *ApiService) UpdateServiceUserWithContext(ctx context.Context, ChatServiceSid string, Sid string, params *UpdateServiceUserParams) (*ConversationsV1ServiceUser, error) { path := "/v1/Services/{ChatServiceSid}/Users/{Sid}" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -353,7 +381,7 @@ func (c *ApiService) UpdateServiceUser(ChatServiceSid string, Sid string, params if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/conversations/v1/services_users_conversations.go b/rest/conversations/v1/services_users_conversations.go index 3aa59e842..f3435e4df 100644 --- a/rest/conversations/v1/services_users_conversations.go +++ b/rest/conversations/v1/services_users_conversations.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -26,6 +27,9 @@ import ( // Delete a specific User Conversation. func (c *ApiService) DeleteServiceUserConversation(ChatServiceSid string, UserSid string, ConversationSid string) error { + return c.DeleteServiceUserConversationWithContext(context.TODO(), ChatServiceSid, UserSid, ConversationSid) +} +func (c *ApiService) DeleteServiceUserConversationWithContext(ctx context.Context, ChatServiceSid string, UserSid string, ConversationSid string) error { path := "/v1/Services/{ChatServiceSid}/Users/{UserSid}/Conversations/{ConversationSid}" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) path = strings.Replace(path, "{"+"UserSid"+"}", UserSid, -1) @@ -36,7 +40,7 @@ func (c *ApiService) DeleteServiceUserConversation(ChatServiceSid string, UserSi "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -48,6 +52,9 @@ func (c *ApiService) DeleteServiceUserConversation(ChatServiceSid string, UserSi // Fetch a specific User Conversation. func (c *ApiService) FetchServiceUserConversation(ChatServiceSid string, UserSid string, ConversationSid string) (*ConversationsV1ServiceUserConversation, error) { + return c.FetchServiceUserConversationWithContext(context.TODO(), ChatServiceSid, UserSid, ConversationSid) +} +func (c *ApiService) FetchServiceUserConversationWithContext(ctx context.Context, ChatServiceSid string, UserSid string, ConversationSid string) (*ConversationsV1ServiceUserConversation, error) { path := "/v1/Services/{ChatServiceSid}/Users/{UserSid}/Conversations/{ConversationSid}" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) path = strings.Replace(path, "{"+"UserSid"+"}", UserSid, -1) @@ -58,7 +65,7 @@ func (c *ApiService) FetchServiceUserConversation(ChatServiceSid string, UserSid "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -92,6 +99,11 @@ func (params *ListServiceUserConversationParams) SetLimit(Limit int) *ListServic // Retrieve a single page of ServiceUserConversation records from the API. Request is executed immediately. func (c *ApiService) PageServiceUserConversation(ChatServiceSid string, UserSid string, params *ListServiceUserConversationParams, pageToken, pageNumber string) (*ListServiceUserConversationResponse, error) { + return c.PageServiceUserConversationWithContext(context.TODO(), ChatServiceSid, UserSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ServiceUserConversation records from the API. Request is executed immediately. +func (c *ApiService) PageServiceUserConversationWithContext(ctx context.Context, ChatServiceSid string, UserSid string, params *ListServiceUserConversationParams, pageToken, pageNumber string) (*ListServiceUserConversationResponse, error) { path := "/v1/Services/{ChatServiceSid}/Users/{UserSid}/Conversations" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) @@ -113,7 +125,7 @@ func (c *ApiService) PageServiceUserConversation(ChatServiceSid string, UserSid data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -130,7 +142,12 @@ func (c *ApiService) PageServiceUserConversation(ChatServiceSid string, UserSid // Lists ServiceUserConversation records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListServiceUserConversation(ChatServiceSid string, UserSid string, params *ListServiceUserConversationParams) ([]ConversationsV1ServiceUserConversation, error) { - response, errors := c.StreamServiceUserConversation(ChatServiceSid, UserSid, params) + return c.ListServiceUserConversationWithContext(context.TODO(), ChatServiceSid, UserSid, params) +} + +// Lists ServiceUserConversation records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListServiceUserConversationWithContext(ctx context.Context, ChatServiceSid string, UserSid string, params *ListServiceUserConversationParams) ([]ConversationsV1ServiceUserConversation, error) { + response, errors := c.StreamServiceUserConversationWithContext(ctx, ChatServiceSid, UserSid, params) records := make([]ConversationsV1ServiceUserConversation, 0) for record := range response { @@ -146,6 +163,11 @@ func (c *ApiService) ListServiceUserConversation(ChatServiceSid string, UserSid // Streams ServiceUserConversation records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamServiceUserConversation(ChatServiceSid string, UserSid string, params *ListServiceUserConversationParams) (chan ConversationsV1ServiceUserConversation, chan error) { + return c.StreamServiceUserConversationWithContext(context.TODO(), ChatServiceSid, UserSid, params) +} + +// Streams ServiceUserConversation records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamServiceUserConversationWithContext(ctx context.Context, ChatServiceSid string, UserSid string, params *ListServiceUserConversationParams) (chan ConversationsV1ServiceUserConversation, chan error) { if params == nil { params = &ListServiceUserConversationParams{} } @@ -154,19 +176,19 @@ func (c *ApiService) StreamServiceUserConversation(ChatServiceSid string, UserSi recordChannel := make(chan ConversationsV1ServiceUserConversation, 1) errorChannel := make(chan error, 1) - response, err := c.PageServiceUserConversation(ChatServiceSid, UserSid, params, "", "") + response, err := c.PageServiceUserConversationWithContext(ctx, ChatServiceSid, UserSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamServiceUserConversation(response, params, recordChannel, errorChannel) + go c.streamServiceUserConversationWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamServiceUserConversation(response *ListServiceUserConversationResponse, params *ListServiceUserConversationParams, recordChannel chan ConversationsV1ServiceUserConversation, errorChannel chan error) { +func (c *ApiService) streamServiceUserConversationWithContext(ctx context.Context, response *ListServiceUserConversationResponse, params *ListServiceUserConversationParams, recordChannel chan ConversationsV1ServiceUserConversation, errorChannel chan error) { curRecord := 1 for response != nil { @@ -181,7 +203,7 @@ func (c *ApiService) streamServiceUserConversation(response *ListServiceUserConv } } - record, err := client.GetNext(c.baseURL, response, c.getNextListServiceUserConversationResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListServiceUserConversationResponseWithContext) if err != nil { errorChannel <- err break @@ -196,11 +218,11 @@ func (c *ApiService) streamServiceUserConversation(response *ListServiceUserConv close(errorChannel) } -func (c *ApiService) getNextListServiceUserConversationResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListServiceUserConversationResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -239,6 +261,9 @@ func (params *UpdateServiceUserConversationParams) SetLastReadMessageIndex(LastR // Update a specific User Conversation. func (c *ApiService) UpdateServiceUserConversation(ChatServiceSid string, UserSid string, ConversationSid string, params *UpdateServiceUserConversationParams) (*ConversationsV1ServiceUserConversation, error) { + return c.UpdateServiceUserConversationWithContext(context.TODO(), ChatServiceSid, UserSid, ConversationSid, params) +} +func (c *ApiService) UpdateServiceUserConversationWithContext(ctx context.Context, ChatServiceSid string, UserSid string, ConversationSid string, params *UpdateServiceUserConversationParams) (*ConversationsV1ServiceUserConversation, error) { path := "/v1/Services/{ChatServiceSid}/Users/{UserSid}/Conversations/{ConversationSid}" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) path = strings.Replace(path, "{"+"UserSid"+"}", UserSid, -1) @@ -259,7 +284,7 @@ func (c *ApiService) UpdateServiceUserConversation(ChatServiceSid string, UserSi data.Set("LastReadMessageIndex", fmt.Sprint(*params.LastReadMessageIndex)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/conversations/v1/users.go b/rest/conversations/v1/users.go index 17a20e1aa..241869e3e 100644 --- a/rest/conversations/v1/users.go +++ b/rest/conversations/v1/users.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -60,6 +61,9 @@ func (params *CreateUserParams) SetRoleSid(RoleSid string) *CreateUserParams { // Add a new conversation user to your account's default service func (c *ApiService) CreateUser(params *CreateUserParams) (*ConversationsV1User, error) { + return c.CreateUserWithContext(context.TODO(), params) +} +func (c *ApiService) CreateUserWithContext(ctx context.Context, params *CreateUserParams) (*ConversationsV1User, error) { path := "/v1/Users" data := url.Values{} @@ -83,7 +87,7 @@ func (c *ApiService) CreateUser(params *CreateUserParams) (*ConversationsV1User, if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -111,6 +115,9 @@ func (params *DeleteUserParams) SetXTwilioWebhookEnabled(XTwilioWebhookEnabled s // Remove a conversation user from your account's default service func (c *ApiService) DeleteUser(Sid string, params *DeleteUserParams) error { + return c.DeleteUserWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) DeleteUserWithContext(ctx context.Context, Sid string, params *DeleteUserParams) error { path := "/v1/Users/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -122,7 +129,7 @@ func (c *ApiService) DeleteUser(Sid string, params *DeleteUserParams) error { if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -134,6 +141,9 @@ func (c *ApiService) DeleteUser(Sid string, params *DeleteUserParams) error { // Fetch a conversation user from your account's default service func (c *ApiService) FetchUser(Sid string) (*ConversationsV1User, error) { + return c.FetchUserWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchUserWithContext(ctx context.Context, Sid string) (*ConversationsV1User, error) { path := "/v1/Users/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -142,7 +152,7 @@ func (c *ApiService) FetchUser(Sid string) (*ConversationsV1User, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -176,6 +186,11 @@ func (params *ListUserParams) SetLimit(Limit int) *ListUserParams { // Retrieve a single page of User records from the API. Request is executed immediately. func (c *ApiService) PageUser(params *ListUserParams, pageToken, pageNumber string) (*ListUserResponse, error) { + return c.PageUserWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of User records from the API. Request is executed immediately. +func (c *ApiService) PageUserWithContext(ctx context.Context, params *ListUserParams, pageToken, pageNumber string) (*ListUserResponse, error) { path := "/v1/Users" data := url.Values{} @@ -194,7 +209,7 @@ func (c *ApiService) PageUser(params *ListUserParams, pageToken, pageNumber stri data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -211,7 +226,12 @@ func (c *ApiService) PageUser(params *ListUserParams, pageToken, pageNumber stri // Lists User records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListUser(params *ListUserParams) ([]ConversationsV1User, error) { - response, errors := c.StreamUser(params) + return c.ListUserWithContext(context.TODO(), params) +} + +// Lists User records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListUserWithContext(ctx context.Context, params *ListUserParams) ([]ConversationsV1User, error) { + response, errors := c.StreamUserWithContext(ctx, params) records := make([]ConversationsV1User, 0) for record := range response { @@ -227,6 +247,11 @@ func (c *ApiService) ListUser(params *ListUserParams) ([]ConversationsV1User, er // Streams User records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamUser(params *ListUserParams) (chan ConversationsV1User, chan error) { + return c.StreamUserWithContext(context.TODO(), params) +} + +// Streams User records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamUserWithContext(ctx context.Context, params *ListUserParams) (chan ConversationsV1User, chan error) { if params == nil { params = &ListUserParams{} } @@ -235,19 +260,19 @@ func (c *ApiService) StreamUser(params *ListUserParams) (chan ConversationsV1Use recordChannel := make(chan ConversationsV1User, 1) errorChannel := make(chan error, 1) - response, err := c.PageUser(params, "", "") + response, err := c.PageUserWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUser(response, params, recordChannel, errorChannel) + go c.streamUserWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamUser(response *ListUserResponse, params *ListUserParams, recordChannel chan ConversationsV1User, errorChannel chan error) { +func (c *ApiService) streamUserWithContext(ctx context.Context, response *ListUserResponse, params *ListUserParams, recordChannel chan ConversationsV1User, errorChannel chan error) { curRecord := 1 for response != nil { @@ -262,7 +287,7 @@ func (c *ApiService) streamUser(response *ListUserResponse, params *ListUserPara } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUserResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListUserResponseWithContext) if err != nil { errorChannel <- err break @@ -277,11 +302,11 @@ func (c *ApiService) streamUser(response *ListUserResponse, params *ListUserPara close(errorChannel) } -func (c *ApiService) getNextListUserResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUserResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -326,6 +351,9 @@ func (params *UpdateUserParams) SetRoleSid(RoleSid string) *UpdateUserParams { // Update an existing conversation user in your account's default service func (c *ApiService) UpdateUser(Sid string, params *UpdateUserParams) (*ConversationsV1User, error) { + return c.UpdateUserWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateUserWithContext(ctx context.Context, Sid string, params *UpdateUserParams) (*ConversationsV1User, error) { path := "/v1/Users/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -347,7 +375,7 @@ func (c *ApiService) UpdateUser(Sid string, params *UpdateUserParams) (*Conversa if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/conversations/v1/users_conversations.go b/rest/conversations/v1/users_conversations.go index fdb37395e..bb44ccf20 100644 --- a/rest/conversations/v1/users_conversations.go +++ b/rest/conversations/v1/users_conversations.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -26,6 +27,9 @@ import ( // Delete a specific User Conversation. func (c *ApiService) DeleteUserConversation(UserSid string, ConversationSid string) error { + return c.DeleteUserConversationWithContext(context.TODO(), UserSid, ConversationSid) +} +func (c *ApiService) DeleteUserConversationWithContext(ctx context.Context, UserSid string, ConversationSid string) error { path := "/v1/Users/{UserSid}/Conversations/{ConversationSid}" path = strings.Replace(path, "{"+"UserSid"+"}", UserSid, -1) path = strings.Replace(path, "{"+"ConversationSid"+"}", ConversationSid, -1) @@ -35,7 +39,7 @@ func (c *ApiService) DeleteUserConversation(UserSid string, ConversationSid stri "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -47,6 +51,9 @@ func (c *ApiService) DeleteUserConversation(UserSid string, ConversationSid stri // Fetch a specific User Conversation. func (c *ApiService) FetchUserConversation(UserSid string, ConversationSid string) (*ConversationsV1UserConversation, error) { + return c.FetchUserConversationWithContext(context.TODO(), UserSid, ConversationSid) +} +func (c *ApiService) FetchUserConversationWithContext(ctx context.Context, UserSid string, ConversationSid string) (*ConversationsV1UserConversation, error) { path := "/v1/Users/{UserSid}/Conversations/{ConversationSid}" path = strings.Replace(path, "{"+"UserSid"+"}", UserSid, -1) path = strings.Replace(path, "{"+"ConversationSid"+"}", ConversationSid, -1) @@ -56,7 +63,7 @@ func (c *ApiService) FetchUserConversation(UserSid string, ConversationSid strin "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -90,6 +97,11 @@ func (params *ListUserConversationParams) SetLimit(Limit int) *ListUserConversat // Retrieve a single page of UserConversation records from the API. Request is executed immediately. func (c *ApiService) PageUserConversation(UserSid string, params *ListUserConversationParams, pageToken, pageNumber string) (*ListUserConversationResponse, error) { + return c.PageUserConversationWithContext(context.TODO(), UserSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of UserConversation records from the API. Request is executed immediately. +func (c *ApiService) PageUserConversationWithContext(ctx context.Context, UserSid string, params *ListUserConversationParams, pageToken, pageNumber string) (*ListUserConversationResponse, error) { path := "/v1/Users/{UserSid}/Conversations" path = strings.Replace(path, "{"+"UserSid"+"}", UserSid, -1) @@ -110,7 +122,7 @@ func (c *ApiService) PageUserConversation(UserSid string, params *ListUserConver data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -127,7 +139,12 @@ func (c *ApiService) PageUserConversation(UserSid string, params *ListUserConver // Lists UserConversation records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListUserConversation(UserSid string, params *ListUserConversationParams) ([]ConversationsV1UserConversation, error) { - response, errors := c.StreamUserConversation(UserSid, params) + return c.ListUserConversationWithContext(context.TODO(), UserSid, params) +} + +// Lists UserConversation records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListUserConversationWithContext(ctx context.Context, UserSid string, params *ListUserConversationParams) ([]ConversationsV1UserConversation, error) { + response, errors := c.StreamUserConversationWithContext(ctx, UserSid, params) records := make([]ConversationsV1UserConversation, 0) for record := range response { @@ -143,6 +160,11 @@ func (c *ApiService) ListUserConversation(UserSid string, params *ListUserConver // Streams UserConversation records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamUserConversation(UserSid string, params *ListUserConversationParams) (chan ConversationsV1UserConversation, chan error) { + return c.StreamUserConversationWithContext(context.TODO(), UserSid, params) +} + +// Streams UserConversation records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamUserConversationWithContext(ctx context.Context, UserSid string, params *ListUserConversationParams) (chan ConversationsV1UserConversation, chan error) { if params == nil { params = &ListUserConversationParams{} } @@ -151,19 +173,19 @@ func (c *ApiService) StreamUserConversation(UserSid string, params *ListUserConv recordChannel := make(chan ConversationsV1UserConversation, 1) errorChannel := make(chan error, 1) - response, err := c.PageUserConversation(UserSid, params, "", "") + response, err := c.PageUserConversationWithContext(ctx, UserSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUserConversation(response, params, recordChannel, errorChannel) + go c.streamUserConversationWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamUserConversation(response *ListUserConversationResponse, params *ListUserConversationParams, recordChannel chan ConversationsV1UserConversation, errorChannel chan error) { +func (c *ApiService) streamUserConversationWithContext(ctx context.Context, response *ListUserConversationResponse, params *ListUserConversationParams, recordChannel chan ConversationsV1UserConversation, errorChannel chan error) { curRecord := 1 for response != nil { @@ -178,7 +200,7 @@ func (c *ApiService) streamUserConversation(response *ListUserConversationRespon } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUserConversationResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListUserConversationResponseWithContext) if err != nil { errorChannel <- err break @@ -193,11 +215,11 @@ func (c *ApiService) streamUserConversation(response *ListUserConversationRespon close(errorChannel) } -func (c *ApiService) getNextListUserConversationResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUserConversationResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -236,6 +258,9 @@ func (params *UpdateUserConversationParams) SetLastReadMessageIndex(LastReadMess // Update a specific User Conversation. func (c *ApiService) UpdateUserConversation(UserSid string, ConversationSid string, params *UpdateUserConversationParams) (*ConversationsV1UserConversation, error) { + return c.UpdateUserConversationWithContext(context.TODO(), UserSid, ConversationSid, params) +} +func (c *ApiService) UpdateUserConversationWithContext(ctx context.Context, UserSid string, ConversationSid string, params *UpdateUserConversationParams) (*ConversationsV1UserConversation, error) { path := "/v1/Users/{UserSid}/Conversations/{ConversationSid}" path = strings.Replace(path, "{"+"UserSid"+"}", UserSid, -1) path = strings.Replace(path, "{"+"ConversationSid"+"}", ConversationSid, -1) @@ -255,7 +280,7 @@ func (c *ApiService) UpdateUserConversation(UserSid string, ConversationSid stri data.Set("LastReadMessageIndex", fmt.Sprint(*params.LastReadMessageIndex)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/events/v1/api_service.go b/rest/events/v1/api_service.go index 1bd8a3a2c..217bbc5b7 100644 --- a/rest/events/v1/api_service.go +++ b/rest/events/v1/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://events.twilio.com", + } +} diff --git a/rest/events/v1/schemas.go b/rest/events/v1/schemas.go index eb09a74f3..172b8c0f3 100644 --- a/rest/events/v1/schemas.go +++ b/rest/events/v1/schemas.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -22,6 +23,9 @@ import ( // Fetch a specific schema with its nested versions. func (c *ApiService) FetchSchema(Id string) (*EventsV1Schema, error) { + return c.FetchSchemaWithContext(context.TODO(), Id) +} +func (c *ApiService) FetchSchemaWithContext(ctx context.Context, Id string) (*EventsV1Schema, error) { path := "/v1/Schemas/{Id}" path = strings.Replace(path, "{"+"Id"+"}", Id, -1) @@ -30,7 +34,7 @@ func (c *ApiService) FetchSchema(Id string) (*EventsV1Schema, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/events/v1/schemas_versions.go b/rest/events/v1/schemas_versions.go index 7ecdb4709..fc64df7a5 100644 --- a/rest/events/v1/schemas_versions.go +++ b/rest/events/v1/schemas_versions.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -25,6 +26,9 @@ import ( // Fetch a specific schema and version. func (c *ApiService) FetchSchemaVersion(Id string, SchemaVersion int) (*EventsV1SchemaVersion, error) { + return c.FetchSchemaVersionWithContext(context.TODO(), Id, SchemaVersion) +} +func (c *ApiService) FetchSchemaVersionWithContext(ctx context.Context, Id string, SchemaVersion int) (*EventsV1SchemaVersion, error) { path := "/v1/Schemas/{Id}/Versions/{SchemaVersion}" path = strings.Replace(path, "{"+"Id"+"}", Id, -1) path = strings.Replace(path, "{"+"SchemaVersion"+"}", fmt.Sprint(SchemaVersion), -1) @@ -34,7 +38,7 @@ func (c *ApiService) FetchSchemaVersion(Id string, SchemaVersion int) (*EventsV1 "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -68,6 +72,11 @@ func (params *ListSchemaVersionParams) SetLimit(Limit int) *ListSchemaVersionPar // Retrieve a single page of SchemaVersion records from the API. Request is executed immediately. func (c *ApiService) PageSchemaVersion(Id string, params *ListSchemaVersionParams, pageToken, pageNumber string) (*ListSchemaVersionResponse, error) { + return c.PageSchemaVersionWithContext(context.TODO(), Id, params, pageToken, pageNumber) +} + +// Retrieve a single page of SchemaVersion records from the API. Request is executed immediately. +func (c *ApiService) PageSchemaVersionWithContext(ctx context.Context, Id string, params *ListSchemaVersionParams, pageToken, pageNumber string) (*ListSchemaVersionResponse, error) { path := "/v1/Schemas/{Id}/Versions" path = strings.Replace(path, "{"+"Id"+"}", Id, -1) @@ -88,7 +97,7 @@ func (c *ApiService) PageSchemaVersion(Id string, params *ListSchemaVersionParam data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -105,7 +114,12 @@ func (c *ApiService) PageSchemaVersion(Id string, params *ListSchemaVersionParam // Lists SchemaVersion records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListSchemaVersion(Id string, params *ListSchemaVersionParams) ([]EventsV1SchemaVersion, error) { - response, errors := c.StreamSchemaVersion(Id, params) + return c.ListSchemaVersionWithContext(context.TODO(), Id, params) +} + +// Lists SchemaVersion records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListSchemaVersionWithContext(ctx context.Context, Id string, params *ListSchemaVersionParams) ([]EventsV1SchemaVersion, error) { + response, errors := c.StreamSchemaVersionWithContext(ctx, Id, params) records := make([]EventsV1SchemaVersion, 0) for record := range response { @@ -121,6 +135,11 @@ func (c *ApiService) ListSchemaVersion(Id string, params *ListSchemaVersionParam // Streams SchemaVersion records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamSchemaVersion(Id string, params *ListSchemaVersionParams) (chan EventsV1SchemaVersion, chan error) { + return c.StreamSchemaVersionWithContext(context.TODO(), Id, params) +} + +// Streams SchemaVersion records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamSchemaVersionWithContext(ctx context.Context, Id string, params *ListSchemaVersionParams) (chan EventsV1SchemaVersion, chan error) { if params == nil { params = &ListSchemaVersionParams{} } @@ -129,19 +148,19 @@ func (c *ApiService) StreamSchemaVersion(Id string, params *ListSchemaVersionPar recordChannel := make(chan EventsV1SchemaVersion, 1) errorChannel := make(chan error, 1) - response, err := c.PageSchemaVersion(Id, params, "", "") + response, err := c.PageSchemaVersionWithContext(ctx, Id, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSchemaVersion(response, params, recordChannel, errorChannel) + go c.streamSchemaVersionWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamSchemaVersion(response *ListSchemaVersionResponse, params *ListSchemaVersionParams, recordChannel chan EventsV1SchemaVersion, errorChannel chan error) { +func (c *ApiService) streamSchemaVersionWithContext(ctx context.Context, response *ListSchemaVersionResponse, params *ListSchemaVersionParams, recordChannel chan EventsV1SchemaVersion, errorChannel chan error) { curRecord := 1 for response != nil { @@ -156,7 +175,7 @@ func (c *ApiService) streamSchemaVersion(response *ListSchemaVersionResponse, pa } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSchemaVersionResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListSchemaVersionResponseWithContext) if err != nil { errorChannel <- err break @@ -171,11 +190,11 @@ func (c *ApiService) streamSchemaVersion(response *ListSchemaVersionResponse, pa close(errorChannel) } -func (c *ApiService) getNextListSchemaVersionResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSchemaVersionResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/events/v1/sinks.go b/rest/events/v1/sinks.go index dd4c157b3..7fe3da51a 100644 --- a/rest/events/v1/sinks.go +++ b/rest/events/v1/sinks.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -48,6 +49,9 @@ func (params *CreateSinkParams) SetSinkType(SinkType string) *CreateSinkParams { // Create a new Sink func (c *ApiService) CreateSink(params *CreateSinkParams) (*EventsV1Sink, error) { + return c.CreateSinkWithContext(context.TODO(), params) +} +func (c *ApiService) CreateSinkWithContext(ctx context.Context, params *CreateSinkParams) (*EventsV1Sink, error) { path := "/v1/Sinks" data := url.Values{} @@ -71,7 +75,7 @@ func (c *ApiService) CreateSink(params *CreateSinkParams) (*EventsV1Sink, error) data.Set("SinkType", fmt.Sprint(*params.SinkType)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -88,6 +92,9 @@ func (c *ApiService) CreateSink(params *CreateSinkParams) (*EventsV1Sink, error) // Delete a specific Sink. func (c *ApiService) DeleteSink(Sid string) error { + return c.DeleteSinkWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteSinkWithContext(ctx context.Context, Sid string) error { path := "/v1/Sinks/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -96,7 +103,7 @@ func (c *ApiService) DeleteSink(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -108,6 +115,9 @@ func (c *ApiService) DeleteSink(Sid string) error { // Fetch a specific Sink. func (c *ApiService) FetchSink(Sid string) (*EventsV1Sink, error) { + return c.FetchSinkWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchSinkWithContext(ctx context.Context, Sid string) (*EventsV1Sink, error) { path := "/v1/Sinks/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -116,7 +126,7 @@ func (c *ApiService) FetchSink(Sid string) (*EventsV1Sink, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -162,6 +172,11 @@ func (params *ListSinkParams) SetLimit(Limit int) *ListSinkParams { // Retrieve a single page of Sink records from the API. Request is executed immediately. func (c *ApiService) PageSink(params *ListSinkParams, pageToken, pageNumber string) (*ListSinkResponse, error) { + return c.PageSinkWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Sink records from the API. Request is executed immediately. +func (c *ApiService) PageSinkWithContext(ctx context.Context, params *ListSinkParams, pageToken, pageNumber string) (*ListSinkResponse, error) { path := "/v1/Sinks" data := url.Values{} @@ -186,7 +201,7 @@ func (c *ApiService) PageSink(params *ListSinkParams, pageToken, pageNumber stri data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -203,7 +218,12 @@ func (c *ApiService) PageSink(params *ListSinkParams, pageToken, pageNumber stri // Lists Sink records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListSink(params *ListSinkParams) ([]EventsV1Sink, error) { - response, errors := c.StreamSink(params) + return c.ListSinkWithContext(context.TODO(), params) +} + +// Lists Sink records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListSinkWithContext(ctx context.Context, params *ListSinkParams) ([]EventsV1Sink, error) { + response, errors := c.StreamSinkWithContext(ctx, params) records := make([]EventsV1Sink, 0) for record := range response { @@ -219,6 +239,11 @@ func (c *ApiService) ListSink(params *ListSinkParams) ([]EventsV1Sink, error) { // Streams Sink records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamSink(params *ListSinkParams) (chan EventsV1Sink, chan error) { + return c.StreamSinkWithContext(context.TODO(), params) +} + +// Streams Sink records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamSinkWithContext(ctx context.Context, params *ListSinkParams) (chan EventsV1Sink, chan error) { if params == nil { params = &ListSinkParams{} } @@ -227,19 +252,19 @@ func (c *ApiService) StreamSink(params *ListSinkParams) (chan EventsV1Sink, chan recordChannel := make(chan EventsV1Sink, 1) errorChannel := make(chan error, 1) - response, err := c.PageSink(params, "", "") + response, err := c.PageSinkWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSink(response, params, recordChannel, errorChannel) + go c.streamSinkWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamSink(response *ListSinkResponse, params *ListSinkParams, recordChannel chan EventsV1Sink, errorChannel chan error) { +func (c *ApiService) streamSinkWithContext(ctx context.Context, response *ListSinkResponse, params *ListSinkParams, recordChannel chan EventsV1Sink, errorChannel chan error) { curRecord := 1 for response != nil { @@ -254,7 +279,7 @@ func (c *ApiService) streamSink(response *ListSinkResponse, params *ListSinkPara } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSinkResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListSinkResponseWithContext) if err != nil { errorChannel <- err break @@ -269,11 +294,11 @@ func (c *ApiService) streamSink(response *ListSinkResponse, params *ListSinkPara close(errorChannel) } -func (c *ApiService) getNextListSinkResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSinkResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -300,6 +325,9 @@ func (params *UpdateSinkParams) SetDescription(Description string) *UpdateSinkPa // Update a specific Sink func (c *ApiService) UpdateSink(Sid string, params *UpdateSinkParams) (*EventsV1Sink, error) { + return c.UpdateSinkWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateSinkWithContext(ctx context.Context, Sid string, params *UpdateSinkParams) (*EventsV1Sink, error) { path := "/v1/Sinks/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -312,7 +340,7 @@ func (c *ApiService) UpdateSink(Sid string, params *UpdateSinkParams) (*EventsV1 data.Set("Description", *params.Description) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/events/v1/sinks_test_.go b/rest/events/v1/sinks_test_.go index 3d38524c2..e24bacdc9 100644 --- a/rest/events/v1/sinks_test_.go +++ b/rest/events/v1/sinks_test_.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -22,6 +23,9 @@ import ( // Create a new Sink Test Event for the given Sink. func (c *ApiService) CreateSinkTest(Sid string) (*EventsV1SinkTest, error) { + return c.CreateSinkTestWithContext(context.TODO(), Sid) +} +func (c *ApiService) CreateSinkTestWithContext(ctx context.Context, Sid string) (*EventsV1SinkTest, error) { path := "/v1/Sinks/{Sid}/Test" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -30,7 +34,7 @@ func (c *ApiService) CreateSinkTest(Sid string) (*EventsV1SinkTest, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/events/v1/sinks_validate.go b/rest/events/v1/sinks_validate.go index 0c89c8db1..6531a66c7 100644 --- a/rest/events/v1/sinks_validate.go +++ b/rest/events/v1/sinks_validate.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -33,6 +34,9 @@ func (params *CreateSinkValidateParams) SetTestId(TestId string) *CreateSinkVali // Validate that a test event for a Sink was received. func (c *ApiService) CreateSinkValidate(Sid string, params *CreateSinkValidateParams) (*EventsV1SinkValidate, error) { + return c.CreateSinkValidateWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) CreateSinkValidateWithContext(ctx context.Context, Sid string, params *CreateSinkValidateParams) (*EventsV1SinkValidate, error) { path := "/v1/Sinks/{Sid}/Validate" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -45,7 +49,7 @@ func (c *ApiService) CreateSinkValidate(Sid string, params *CreateSinkValidatePa data.Set("TestId", *params.TestId) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/events/v1/subscriptions.go b/rest/events/v1/subscriptions.go index 2be5fdeb7..b50e020d4 100644 --- a/rest/events/v1/subscriptions.go +++ b/rest/events/v1/subscriptions.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -48,6 +49,9 @@ func (params *CreateSubscriptionParams) SetTypes(Types []map[string]interface{}) // Create a new Subscription. func (c *ApiService) CreateSubscription(params *CreateSubscriptionParams) (*EventsV1Subscription, error) { + return c.CreateSubscriptionWithContext(context.TODO(), params) +} +func (c *ApiService) CreateSubscriptionWithContext(ctx context.Context, params *CreateSubscriptionParams) (*EventsV1Subscription, error) { path := "/v1/Subscriptions" data := url.Values{} @@ -73,7 +77,7 @@ func (c *ApiService) CreateSubscription(params *CreateSubscriptionParams) (*Even } } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -90,6 +94,9 @@ func (c *ApiService) CreateSubscription(params *CreateSubscriptionParams) (*Even // Delete a specific Subscription. func (c *ApiService) DeleteSubscription(Sid string) error { + return c.DeleteSubscriptionWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteSubscriptionWithContext(ctx context.Context, Sid string) error { path := "/v1/Subscriptions/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -98,7 +105,7 @@ func (c *ApiService) DeleteSubscription(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -110,6 +117,9 @@ func (c *ApiService) DeleteSubscription(Sid string) error { // Fetch a specific Subscription. func (c *ApiService) FetchSubscription(Sid string) (*EventsV1Subscription, error) { + return c.FetchSubscriptionWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchSubscriptionWithContext(ctx context.Context, Sid string) (*EventsV1Subscription, error) { path := "/v1/Subscriptions/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -118,7 +128,7 @@ func (c *ApiService) FetchSubscription(Sid string) (*EventsV1Subscription, error "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -158,6 +168,11 @@ func (params *ListSubscriptionParams) SetLimit(Limit int) *ListSubscriptionParam // Retrieve a single page of Subscription records from the API. Request is executed immediately. func (c *ApiService) PageSubscription(params *ListSubscriptionParams, pageToken, pageNumber string) (*ListSubscriptionResponse, error) { + return c.PageSubscriptionWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Subscription records from the API. Request is executed immediately. +func (c *ApiService) PageSubscriptionWithContext(ctx context.Context, params *ListSubscriptionParams, pageToken, pageNumber string) (*ListSubscriptionResponse, error) { path := "/v1/Subscriptions" data := url.Values{} @@ -179,7 +194,7 @@ func (c *ApiService) PageSubscription(params *ListSubscriptionParams, pageToken, data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -196,7 +211,12 @@ func (c *ApiService) PageSubscription(params *ListSubscriptionParams, pageToken, // Lists Subscription records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListSubscription(params *ListSubscriptionParams) ([]EventsV1Subscription, error) { - response, errors := c.StreamSubscription(params) + return c.ListSubscriptionWithContext(context.TODO(), params) +} + +// Lists Subscription records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListSubscriptionWithContext(ctx context.Context, params *ListSubscriptionParams) ([]EventsV1Subscription, error) { + response, errors := c.StreamSubscriptionWithContext(ctx, params) records := make([]EventsV1Subscription, 0) for record := range response { @@ -212,6 +232,11 @@ func (c *ApiService) ListSubscription(params *ListSubscriptionParams) ([]EventsV // Streams Subscription records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamSubscription(params *ListSubscriptionParams) (chan EventsV1Subscription, chan error) { + return c.StreamSubscriptionWithContext(context.TODO(), params) +} + +// Streams Subscription records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamSubscriptionWithContext(ctx context.Context, params *ListSubscriptionParams) (chan EventsV1Subscription, chan error) { if params == nil { params = &ListSubscriptionParams{} } @@ -220,19 +245,19 @@ func (c *ApiService) StreamSubscription(params *ListSubscriptionParams) (chan Ev recordChannel := make(chan EventsV1Subscription, 1) errorChannel := make(chan error, 1) - response, err := c.PageSubscription(params, "", "") + response, err := c.PageSubscriptionWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSubscription(response, params, recordChannel, errorChannel) + go c.streamSubscriptionWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamSubscription(response *ListSubscriptionResponse, params *ListSubscriptionParams, recordChannel chan EventsV1Subscription, errorChannel chan error) { +func (c *ApiService) streamSubscriptionWithContext(ctx context.Context, response *ListSubscriptionResponse, params *ListSubscriptionParams, recordChannel chan EventsV1Subscription, errorChannel chan error) { curRecord := 1 for response != nil { @@ -247,7 +272,7 @@ func (c *ApiService) streamSubscription(response *ListSubscriptionResponse, para } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSubscriptionResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListSubscriptionResponseWithContext) if err != nil { errorChannel <- err break @@ -262,11 +287,11 @@ func (c *ApiService) streamSubscription(response *ListSubscriptionResponse, para close(errorChannel) } -func (c *ApiService) getNextListSubscriptionResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSubscriptionResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -299,6 +324,9 @@ func (params *UpdateSubscriptionParams) SetSinkSid(SinkSid string) *UpdateSubscr // Update a Subscription. func (c *ApiService) UpdateSubscription(Sid string, params *UpdateSubscriptionParams) (*EventsV1Subscription, error) { + return c.UpdateSubscriptionWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateSubscriptionWithContext(ctx context.Context, Sid string, params *UpdateSubscriptionParams) (*EventsV1Subscription, error) { path := "/v1/Subscriptions/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -314,7 +342,7 @@ func (c *ApiService) UpdateSubscription(Sid string, params *UpdateSubscriptionPa data.Set("SinkSid", *params.SinkSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/events/v1/subscriptions_subscribed_events.go b/rest/events/v1/subscriptions_subscribed_events.go index e561cef6d..bb53a1fa5 100644 --- a/rest/events/v1/subscriptions_subscribed_events.go +++ b/rest/events/v1/subscriptions_subscribed_events.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -42,6 +43,9 @@ func (params *CreateSubscribedEventParams) SetSchemaVersion(SchemaVersion int) * // Add an event type to a Subscription. func (c *ApiService) CreateSubscribedEvent(SubscriptionSid string, params *CreateSubscribedEventParams) (*EventsV1SubscribedEvent, error) { + return c.CreateSubscribedEventWithContext(context.TODO(), SubscriptionSid, params) +} +func (c *ApiService) CreateSubscribedEventWithContext(ctx context.Context, SubscriptionSid string, params *CreateSubscribedEventParams) (*EventsV1SubscribedEvent, error) { path := "/v1/Subscriptions/{SubscriptionSid}/SubscribedEvents" path = strings.Replace(path, "{"+"SubscriptionSid"+"}", SubscriptionSid, -1) @@ -57,7 +61,7 @@ func (c *ApiService) CreateSubscribedEvent(SubscriptionSid string, params *Creat data.Set("SchemaVersion", fmt.Sprint(*params.SchemaVersion)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -74,6 +78,9 @@ func (c *ApiService) CreateSubscribedEvent(SubscriptionSid string, params *Creat // Remove an event type from a Subscription. func (c *ApiService) DeleteSubscribedEvent(SubscriptionSid string, Type string) error { + return c.DeleteSubscribedEventWithContext(context.TODO(), SubscriptionSid, Type) +} +func (c *ApiService) DeleteSubscribedEventWithContext(ctx context.Context, SubscriptionSid string, Type string) error { path := "/v1/Subscriptions/{SubscriptionSid}/SubscribedEvents/{Type}" path = strings.Replace(path, "{"+"SubscriptionSid"+"}", SubscriptionSid, -1) path = strings.Replace(path, "{"+"Type"+"}", Type, -1) @@ -83,7 +90,7 @@ func (c *ApiService) DeleteSubscribedEvent(SubscriptionSid string, Type string) "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -95,6 +102,9 @@ func (c *ApiService) DeleteSubscribedEvent(SubscriptionSid string, Type string) // Read an Event for a Subscription. func (c *ApiService) FetchSubscribedEvent(SubscriptionSid string, Type string) (*EventsV1SubscribedEvent, error) { + return c.FetchSubscribedEventWithContext(context.TODO(), SubscriptionSid, Type) +} +func (c *ApiService) FetchSubscribedEventWithContext(ctx context.Context, SubscriptionSid string, Type string) (*EventsV1SubscribedEvent, error) { path := "/v1/Subscriptions/{SubscriptionSid}/SubscribedEvents/{Type}" path = strings.Replace(path, "{"+"SubscriptionSid"+"}", SubscriptionSid, -1) path = strings.Replace(path, "{"+"Type"+"}", Type, -1) @@ -104,7 +114,7 @@ func (c *ApiService) FetchSubscribedEvent(SubscriptionSid string, Type string) ( "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -138,6 +148,11 @@ func (params *ListSubscribedEventParams) SetLimit(Limit int) *ListSubscribedEven // Retrieve a single page of SubscribedEvent records from the API. Request is executed immediately. func (c *ApiService) PageSubscribedEvent(SubscriptionSid string, params *ListSubscribedEventParams, pageToken, pageNumber string) (*ListSubscribedEventResponse, error) { + return c.PageSubscribedEventWithContext(context.TODO(), SubscriptionSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of SubscribedEvent records from the API. Request is executed immediately. +func (c *ApiService) PageSubscribedEventWithContext(ctx context.Context, SubscriptionSid string, params *ListSubscribedEventParams, pageToken, pageNumber string) (*ListSubscribedEventResponse, error) { path := "/v1/Subscriptions/{SubscriptionSid}/SubscribedEvents" path = strings.Replace(path, "{"+"SubscriptionSid"+"}", SubscriptionSid, -1) @@ -158,7 +173,7 @@ func (c *ApiService) PageSubscribedEvent(SubscriptionSid string, params *ListSub data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -175,7 +190,12 @@ func (c *ApiService) PageSubscribedEvent(SubscriptionSid string, params *ListSub // Lists SubscribedEvent records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListSubscribedEvent(SubscriptionSid string, params *ListSubscribedEventParams) ([]EventsV1SubscribedEvent, error) { - response, errors := c.StreamSubscribedEvent(SubscriptionSid, params) + return c.ListSubscribedEventWithContext(context.TODO(), SubscriptionSid, params) +} + +// Lists SubscribedEvent records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListSubscribedEventWithContext(ctx context.Context, SubscriptionSid string, params *ListSubscribedEventParams) ([]EventsV1SubscribedEvent, error) { + response, errors := c.StreamSubscribedEventWithContext(ctx, SubscriptionSid, params) records := make([]EventsV1SubscribedEvent, 0) for record := range response { @@ -191,6 +211,11 @@ func (c *ApiService) ListSubscribedEvent(SubscriptionSid string, params *ListSub // Streams SubscribedEvent records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamSubscribedEvent(SubscriptionSid string, params *ListSubscribedEventParams) (chan EventsV1SubscribedEvent, chan error) { + return c.StreamSubscribedEventWithContext(context.TODO(), SubscriptionSid, params) +} + +// Streams SubscribedEvent records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamSubscribedEventWithContext(ctx context.Context, SubscriptionSid string, params *ListSubscribedEventParams) (chan EventsV1SubscribedEvent, chan error) { if params == nil { params = &ListSubscribedEventParams{} } @@ -199,19 +224,19 @@ func (c *ApiService) StreamSubscribedEvent(SubscriptionSid string, params *ListS recordChannel := make(chan EventsV1SubscribedEvent, 1) errorChannel := make(chan error, 1) - response, err := c.PageSubscribedEvent(SubscriptionSid, params, "", "") + response, err := c.PageSubscribedEventWithContext(ctx, SubscriptionSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSubscribedEvent(response, params, recordChannel, errorChannel) + go c.streamSubscribedEventWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamSubscribedEvent(response *ListSubscribedEventResponse, params *ListSubscribedEventParams, recordChannel chan EventsV1SubscribedEvent, errorChannel chan error) { +func (c *ApiService) streamSubscribedEventWithContext(ctx context.Context, response *ListSubscribedEventResponse, params *ListSubscribedEventParams, recordChannel chan EventsV1SubscribedEvent, errorChannel chan error) { curRecord := 1 for response != nil { @@ -226,7 +251,7 @@ func (c *ApiService) streamSubscribedEvent(response *ListSubscribedEventResponse } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSubscribedEventResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListSubscribedEventResponseWithContext) if err != nil { errorChannel <- err break @@ -241,11 +266,11 @@ func (c *ApiService) streamSubscribedEvent(response *ListSubscribedEventResponse close(errorChannel) } -func (c *ApiService) getNextListSubscribedEventResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSubscribedEventResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -272,6 +297,9 @@ func (params *UpdateSubscribedEventParams) SetSchemaVersion(SchemaVersion int) * // Update an Event for a Subscription. func (c *ApiService) UpdateSubscribedEvent(SubscriptionSid string, Type string, params *UpdateSubscribedEventParams) (*EventsV1SubscribedEvent, error) { + return c.UpdateSubscribedEventWithContext(context.TODO(), SubscriptionSid, Type, params) +} +func (c *ApiService) UpdateSubscribedEventWithContext(ctx context.Context, SubscriptionSid string, Type string, params *UpdateSubscribedEventParams) (*EventsV1SubscribedEvent, error) { path := "/v1/Subscriptions/{SubscriptionSid}/SubscribedEvents/{Type}" path = strings.Replace(path, "{"+"SubscriptionSid"+"}", SubscriptionSid, -1) path = strings.Replace(path, "{"+"Type"+"}", Type, -1) @@ -285,7 +313,7 @@ func (c *ApiService) UpdateSubscribedEvent(SubscriptionSid string, Type string, data.Set("SchemaVersion", fmt.Sprint(*params.SchemaVersion)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/events/v1/types.go b/rest/events/v1/types.go index ee0ea459f..eaffdf3f0 100644 --- a/rest/events/v1/types.go +++ b/rest/events/v1/types.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -25,6 +26,9 @@ import ( // Fetch a specific Event Type. func (c *ApiService) FetchEventType(Type string) (*EventsV1EventType, error) { + return c.FetchEventTypeWithContext(context.TODO(), Type) +} +func (c *ApiService) FetchEventTypeWithContext(ctx context.Context, Type string) (*EventsV1EventType, error) { path := "/v1/Types/{Type}" path = strings.Replace(path, "{"+"Type"+"}", Type, -1) @@ -33,7 +37,7 @@ func (c *ApiService) FetchEventType(Type string) (*EventsV1EventType, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -73,6 +77,11 @@ func (params *ListEventTypeParams) SetLimit(Limit int) *ListEventTypeParams { // Retrieve a single page of EventType records from the API. Request is executed immediately. func (c *ApiService) PageEventType(params *ListEventTypeParams, pageToken, pageNumber string) (*ListEventTypeResponse, error) { + return c.PageEventTypeWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of EventType records from the API. Request is executed immediately. +func (c *ApiService) PageEventTypeWithContext(ctx context.Context, params *ListEventTypeParams, pageToken, pageNumber string) (*ListEventTypeResponse, error) { path := "/v1/Types" data := url.Values{} @@ -94,7 +103,7 @@ func (c *ApiService) PageEventType(params *ListEventTypeParams, pageToken, pageN data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -111,7 +120,12 @@ func (c *ApiService) PageEventType(params *ListEventTypeParams, pageToken, pageN // Lists EventType records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListEventType(params *ListEventTypeParams) ([]EventsV1EventType, error) { - response, errors := c.StreamEventType(params) + return c.ListEventTypeWithContext(context.TODO(), params) +} + +// Lists EventType records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListEventTypeWithContext(ctx context.Context, params *ListEventTypeParams) ([]EventsV1EventType, error) { + response, errors := c.StreamEventTypeWithContext(ctx, params) records := make([]EventsV1EventType, 0) for record := range response { @@ -127,6 +141,11 @@ func (c *ApiService) ListEventType(params *ListEventTypeParams) ([]EventsV1Event // Streams EventType records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamEventType(params *ListEventTypeParams) (chan EventsV1EventType, chan error) { + return c.StreamEventTypeWithContext(context.TODO(), params) +} + +// Streams EventType records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamEventTypeWithContext(ctx context.Context, params *ListEventTypeParams) (chan EventsV1EventType, chan error) { if params == nil { params = &ListEventTypeParams{} } @@ -135,19 +154,19 @@ func (c *ApiService) StreamEventType(params *ListEventTypeParams) (chan EventsV1 recordChannel := make(chan EventsV1EventType, 1) errorChannel := make(chan error, 1) - response, err := c.PageEventType(params, "", "") + response, err := c.PageEventTypeWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamEventType(response, params, recordChannel, errorChannel) + go c.streamEventTypeWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamEventType(response *ListEventTypeResponse, params *ListEventTypeParams, recordChannel chan EventsV1EventType, errorChannel chan error) { +func (c *ApiService) streamEventTypeWithContext(ctx context.Context, response *ListEventTypeResponse, params *ListEventTypeParams, recordChannel chan EventsV1EventType, errorChannel chan error) { curRecord := 1 for response != nil { @@ -162,7 +181,7 @@ func (c *ApiService) streamEventType(response *ListEventTypeResponse, params *Li } } - record, err := client.GetNext(c.baseURL, response, c.getNextListEventTypeResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListEventTypeResponseWithContext) if err != nil { errorChannel <- err break @@ -177,11 +196,11 @@ func (c *ApiService) streamEventType(response *ListEventTypeResponse, params *Li close(errorChannel) } -func (c *ApiService) getNextListEventTypeResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListEventTypeResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/flex/v1/account_provision_status.go b/rest/flex/v1/account_provision_status.go index d3ec218bb..f9f6f4f71 100644 --- a/rest/flex/v1/account_provision_status.go +++ b/rest/flex/v1/account_provision_status.go @@ -15,12 +15,15 @@ package openapi import ( + "context" "encoding/json" "net/url" ) -// func (c *ApiService) FetchProvisioningStatus() (*FlexV1ProvisioningStatus, error) { + return c.FetchProvisioningStatusWithContext(context.TODO()) +} +func (c *ApiService) FetchProvisioningStatusWithContext(ctx context.Context) (*FlexV1ProvisioningStatus, error) { path := "/v1/account/provision/status" data := url.Values{} @@ -28,7 +31,7 @@ func (c *ApiService) FetchProvisioningStatus() (*FlexV1ProvisioningStatus, error "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/flex/v1/api_service.go b/rest/flex/v1/api_service.go index b27a8c40a..0fc8478b1 100644 --- a/rest/flex/v1/api_service.go +++ b/rest/flex/v1/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://flex-api.twilio.com", + } +} diff --git a/rest/flex/v1/channels.go b/rest/flex/v1/channels.go index 4e674c50e..ead5d911e 100644 --- a/rest/flex/v1/channels.go +++ b/rest/flex/v1/channels.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -88,8 +89,10 @@ func (params *CreateChannelParams) SetLongLived(LongLived bool) *CreateChannelPa return params } -// func (c *ApiService) CreateChannel(params *CreateChannelParams) (*FlexV1Channel, error) { + return c.CreateChannelWithContext(context.TODO(), params) +} +func (c *ApiService) CreateChannelWithContext(ctx context.Context, params *CreateChannelParams) (*FlexV1Channel, error) { path := "/v1/Channels" data := url.Values{} @@ -128,7 +131,7 @@ func (c *ApiService) CreateChannel(params *CreateChannelParams) (*FlexV1Channel, data.Set("LongLived", fmt.Sprint(*params.LongLived)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -143,8 +146,10 @@ func (c *ApiService) CreateChannel(params *CreateChannelParams) (*FlexV1Channel, return ps, err } -// func (c *ApiService) DeleteChannel(Sid string) error { + return c.DeleteChannelWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteChannelWithContext(ctx context.Context, Sid string) error { path := "/v1/Channels/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -153,7 +158,7 @@ func (c *ApiService) DeleteChannel(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -163,8 +168,10 @@ func (c *ApiService) DeleteChannel(Sid string) error { return nil } -// func (c *ApiService) FetchChannel(Sid string) (*FlexV1Channel, error) { + return c.FetchChannelWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchChannelWithContext(ctx context.Context, Sid string) (*FlexV1Channel, error) { path := "/v1/Channels/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -173,7 +180,7 @@ func (c *ApiService) FetchChannel(Sid string) (*FlexV1Channel, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -207,6 +214,11 @@ func (params *ListChannelParams) SetLimit(Limit int) *ListChannelParams { // Retrieve a single page of Channel records from the API. Request is executed immediately. func (c *ApiService) PageChannel(params *ListChannelParams, pageToken, pageNumber string) (*ListChannelResponse, error) { + return c.PageChannelWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Channel records from the API. Request is executed immediately. +func (c *ApiService) PageChannelWithContext(ctx context.Context, params *ListChannelParams, pageToken, pageNumber string) (*ListChannelResponse, error) { path := "/v1/Channels" data := url.Values{} @@ -225,7 +237,7 @@ func (c *ApiService) PageChannel(params *ListChannelParams, pageToken, pageNumbe data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -242,7 +254,12 @@ func (c *ApiService) PageChannel(params *ListChannelParams, pageToken, pageNumbe // Lists Channel records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListChannel(params *ListChannelParams) ([]FlexV1Channel, error) { - response, errors := c.StreamChannel(params) + return c.ListChannelWithContext(context.TODO(), params) +} + +// Lists Channel records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListChannelWithContext(ctx context.Context, params *ListChannelParams) ([]FlexV1Channel, error) { + response, errors := c.StreamChannelWithContext(ctx, params) records := make([]FlexV1Channel, 0) for record := range response { @@ -258,6 +275,11 @@ func (c *ApiService) ListChannel(params *ListChannelParams) ([]FlexV1Channel, er // Streams Channel records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamChannel(params *ListChannelParams) (chan FlexV1Channel, chan error) { + return c.StreamChannelWithContext(context.TODO(), params) +} + +// Streams Channel records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamChannelWithContext(ctx context.Context, params *ListChannelParams) (chan FlexV1Channel, chan error) { if params == nil { params = &ListChannelParams{} } @@ -266,19 +288,19 @@ func (c *ApiService) StreamChannel(params *ListChannelParams) (chan FlexV1Channe recordChannel := make(chan FlexV1Channel, 1) errorChannel := make(chan error, 1) - response, err := c.PageChannel(params, "", "") + response, err := c.PageChannelWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamChannel(response, params, recordChannel, errorChannel) + go c.streamChannelWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamChannel(response *ListChannelResponse, params *ListChannelParams, recordChannel chan FlexV1Channel, errorChannel chan error) { +func (c *ApiService) streamChannelWithContext(ctx context.Context, response *ListChannelResponse, params *ListChannelParams, recordChannel chan FlexV1Channel, errorChannel chan error) { curRecord := 1 for response != nil { @@ -293,7 +315,7 @@ func (c *ApiService) streamChannel(response *ListChannelResponse, params *ListCh } } - record, err := client.GetNext(c.baseURL, response, c.getNextListChannelResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListChannelResponseWithContext) if err != nil { errorChannel <- err break @@ -308,11 +330,11 @@ func (c *ApiService) streamChannel(response *ListChannelResponse, params *ListCh close(errorChannel) } -func (c *ApiService) getNextListChannelResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListChannelResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/flex/v1/configuration.go b/rest/flex/v1/configuration.go index 6e3b8a775..7dc03130b 100644 --- a/rest/flex/v1/configuration.go +++ b/rest/flex/v1/configuration.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" ) @@ -30,8 +31,10 @@ func (params *FetchConfigurationParams) SetUiVersion(UiVersion string) *FetchCon return params } -// func (c *ApiService) FetchConfiguration(params *FetchConfigurationParams) (*FlexV1Configuration, error) { + return c.FetchConfigurationWithContext(context.TODO(), params) +} +func (c *ApiService) FetchConfigurationWithContext(ctx context.Context, params *FetchConfigurationParams) (*FlexV1Configuration, error) { path := "/v1/Configuration" data := url.Values{} @@ -43,7 +46,7 @@ func (c *ApiService) FetchConfiguration(params *FetchConfigurationParams) (*Flex data.Set("UiVersion", *params.UiVersion) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -69,8 +72,10 @@ func (params *UpdateConfigurationParams) SetBody(Body map[string]interface{}) *U return params } -// func (c *ApiService) UpdateConfiguration(params *UpdateConfigurationParams) (*FlexV1Configuration, error) { + return c.UpdateConfigurationWithContext(context.TODO(), params) +} +func (c *ApiService) UpdateConfigurationWithContext(ctx context.Context, params *UpdateConfigurationParams) (*FlexV1Configuration, error) { path := "/v1/Configuration" data := url.Values{} @@ -87,7 +92,7 @@ func (c *ApiService) UpdateConfiguration(params *UpdateConfigurationParams) (*Fl body = b } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers, body...) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers, body...) if err != nil { return nil, err } diff --git a/rest/flex/v1/flex_flows.go b/rest/flex/v1/flex_flows.go index d48b5948c..c1a48a455 100644 --- a/rest/flex/v1/flex_flows.go +++ b/rest/flex/v1/flex_flows.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -130,8 +131,10 @@ func (params *CreateFlexFlowParams) SetIntegrationRetryCount(IntegrationRetryCou return params } -// func (c *ApiService) CreateFlexFlow(params *CreateFlexFlowParams) (*FlexV1FlexFlow, error) { + return c.CreateFlexFlowWithContext(context.TODO(), params) +} +func (c *ApiService) CreateFlexFlowWithContext(ctx context.Context, params *CreateFlexFlowParams) (*FlexV1FlexFlow, error) { path := "/v1/FlexFlows" data := url.Values{} @@ -191,7 +194,7 @@ func (c *ApiService) CreateFlexFlow(params *CreateFlexFlowParams) (*FlexV1FlexFl data.Set("Integration.RetryCount", fmt.Sprint(*params.IntegrationRetryCount)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -206,8 +209,10 @@ func (c *ApiService) CreateFlexFlow(params *CreateFlexFlowParams) (*FlexV1FlexFl return ps, err } -// func (c *ApiService) DeleteFlexFlow(Sid string) error { + return c.DeleteFlexFlowWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteFlexFlowWithContext(ctx context.Context, Sid string) error { path := "/v1/FlexFlows/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -216,7 +221,7 @@ func (c *ApiService) DeleteFlexFlow(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -226,8 +231,10 @@ func (c *ApiService) DeleteFlexFlow(Sid string) error { return nil } -// func (c *ApiService) FetchFlexFlow(Sid string) (*FlexV1FlexFlow, error) { + return c.FetchFlexFlowWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchFlexFlowWithContext(ctx context.Context, Sid string) (*FlexV1FlexFlow, error) { path := "/v1/FlexFlows/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -236,7 +243,7 @@ func (c *ApiService) FetchFlexFlow(Sid string) (*FlexV1FlexFlow, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -276,6 +283,11 @@ func (params *ListFlexFlowParams) SetLimit(Limit int) *ListFlexFlowParams { // Retrieve a single page of FlexFlow records from the API. Request is executed immediately. func (c *ApiService) PageFlexFlow(params *ListFlexFlowParams, pageToken, pageNumber string) (*ListFlexFlowResponse, error) { + return c.PageFlexFlowWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of FlexFlow records from the API. Request is executed immediately. +func (c *ApiService) PageFlexFlowWithContext(ctx context.Context, params *ListFlexFlowParams, pageToken, pageNumber string) (*ListFlexFlowResponse, error) { path := "/v1/FlexFlows" data := url.Values{} @@ -297,7 +309,7 @@ func (c *ApiService) PageFlexFlow(params *ListFlexFlowParams, pageToken, pageNum data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -314,7 +326,12 @@ func (c *ApiService) PageFlexFlow(params *ListFlexFlowParams, pageToken, pageNum // Lists FlexFlow records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListFlexFlow(params *ListFlexFlowParams) ([]FlexV1FlexFlow, error) { - response, errors := c.StreamFlexFlow(params) + return c.ListFlexFlowWithContext(context.TODO(), params) +} + +// Lists FlexFlow records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListFlexFlowWithContext(ctx context.Context, params *ListFlexFlowParams) ([]FlexV1FlexFlow, error) { + response, errors := c.StreamFlexFlowWithContext(ctx, params) records := make([]FlexV1FlexFlow, 0) for record := range response { @@ -330,6 +347,11 @@ func (c *ApiService) ListFlexFlow(params *ListFlexFlowParams) ([]FlexV1FlexFlow, // Streams FlexFlow records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamFlexFlow(params *ListFlexFlowParams) (chan FlexV1FlexFlow, chan error) { + return c.StreamFlexFlowWithContext(context.TODO(), params) +} + +// Streams FlexFlow records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamFlexFlowWithContext(ctx context.Context, params *ListFlexFlowParams) (chan FlexV1FlexFlow, chan error) { if params == nil { params = &ListFlexFlowParams{} } @@ -338,19 +360,19 @@ func (c *ApiService) StreamFlexFlow(params *ListFlexFlowParams) (chan FlexV1Flex recordChannel := make(chan FlexV1FlexFlow, 1) errorChannel := make(chan error, 1) - response, err := c.PageFlexFlow(params, "", "") + response, err := c.PageFlexFlowWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamFlexFlow(response, params, recordChannel, errorChannel) + go c.streamFlexFlowWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamFlexFlow(response *ListFlexFlowResponse, params *ListFlexFlowParams, recordChannel chan FlexV1FlexFlow, errorChannel chan error) { +func (c *ApiService) streamFlexFlowWithContext(ctx context.Context, response *ListFlexFlowResponse, params *ListFlexFlowParams, recordChannel chan FlexV1FlexFlow, errorChannel chan error) { curRecord := 1 for response != nil { @@ -365,7 +387,7 @@ func (c *ApiService) streamFlexFlow(response *ListFlexFlowResponse, params *List } } - record, err := client.GetNext(c.baseURL, response, c.getNextListFlexFlowResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListFlexFlowResponseWithContext) if err != nil { errorChannel <- err break @@ -380,11 +402,11 @@ func (c *ApiService) streamFlexFlow(response *ListFlexFlowResponse, params *List close(errorChannel) } -func (c *ApiService) getNextListFlexFlowResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListFlexFlowResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -505,8 +527,10 @@ func (params *UpdateFlexFlowParams) SetIntegrationRetryCount(IntegrationRetryCou return params } -// func (c *ApiService) UpdateFlexFlow(Sid string, params *UpdateFlexFlowParams) (*FlexV1FlexFlow, error) { + return c.UpdateFlexFlowWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateFlexFlowWithContext(ctx context.Context, Sid string, params *UpdateFlexFlowParams) (*FlexV1FlexFlow, error) { path := "/v1/FlexFlows/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -567,7 +591,7 @@ func (c *ApiService) UpdateFlexFlow(Sid string, params *UpdateFlexFlowParams) (* data.Set("Integration.RetryCount", fmt.Sprint(*params.IntegrationRetryCount)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/flex/v1/insights_conversations.go b/rest/flex/v1/insights_conversations.go index 878b6c000..12c399751 100644 --- a/rest/flex/v1/insights_conversations.go +++ b/rest/flex/v1/insights_conversations.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -53,6 +54,11 @@ func (params *ListInsightsConversationsParams) SetLimit(Limit int) *ListInsights // Retrieve a single page of InsightsConversations records from the API. Request is executed immediately. func (c *ApiService) PageInsightsConversations(params *ListInsightsConversationsParams, pageToken, pageNumber string) (*ListInsightsConversationsResponse, error) { + return c.PageInsightsConversationsWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of InsightsConversations records from the API. Request is executed immediately. +func (c *ApiService) PageInsightsConversationsWithContext(ctx context.Context, params *ListInsightsConversationsParams, pageToken, pageNumber string) (*ListInsightsConversationsResponse, error) { path := "/v1/Insights/Conversations" data := url.Values{} @@ -74,7 +80,7 @@ func (c *ApiService) PageInsightsConversations(params *ListInsightsConversations data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -91,7 +97,12 @@ func (c *ApiService) PageInsightsConversations(params *ListInsightsConversations // Lists InsightsConversations records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListInsightsConversations(params *ListInsightsConversationsParams) ([]FlexV1InsightsConversations, error) { - response, errors := c.StreamInsightsConversations(params) + return c.ListInsightsConversationsWithContext(context.TODO(), params) +} + +// Lists InsightsConversations records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListInsightsConversationsWithContext(ctx context.Context, params *ListInsightsConversationsParams) ([]FlexV1InsightsConversations, error) { + response, errors := c.StreamInsightsConversationsWithContext(ctx, params) records := make([]FlexV1InsightsConversations, 0) for record := range response { @@ -107,6 +118,11 @@ func (c *ApiService) ListInsightsConversations(params *ListInsightsConversations // Streams InsightsConversations records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamInsightsConversations(params *ListInsightsConversationsParams) (chan FlexV1InsightsConversations, chan error) { + return c.StreamInsightsConversationsWithContext(context.TODO(), params) +} + +// Streams InsightsConversations records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamInsightsConversationsWithContext(ctx context.Context, params *ListInsightsConversationsParams) (chan FlexV1InsightsConversations, chan error) { if params == nil { params = &ListInsightsConversationsParams{} } @@ -115,19 +131,19 @@ func (c *ApiService) StreamInsightsConversations(params *ListInsightsConversatio recordChannel := make(chan FlexV1InsightsConversations, 1) errorChannel := make(chan error, 1) - response, err := c.PageInsightsConversations(params, "", "") + response, err := c.PageInsightsConversationsWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamInsightsConversations(response, params, recordChannel, errorChannel) + go c.streamInsightsConversationsWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamInsightsConversations(response *ListInsightsConversationsResponse, params *ListInsightsConversationsParams, recordChannel chan FlexV1InsightsConversations, errorChannel chan error) { +func (c *ApiService) streamInsightsConversationsWithContext(ctx context.Context, response *ListInsightsConversationsResponse, params *ListInsightsConversationsParams, recordChannel chan FlexV1InsightsConversations, errorChannel chan error) { curRecord := 1 for response != nil { @@ -142,7 +158,7 @@ func (c *ApiService) streamInsightsConversations(response *ListInsightsConversat } } - record, err := client.GetNext(c.baseURL, response, c.getNextListInsightsConversationsResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListInsightsConversationsResponseWithContext) if err != nil { errorChannel <- err break @@ -157,11 +173,11 @@ func (c *ApiService) streamInsightsConversations(response *ListInsightsConversat close(errorChannel) } -func (c *ApiService) getNextListInsightsConversationsResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListInsightsConversationsResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/flex/v1/insights_quality_management_assessments.go b/rest/flex/v1/insights_quality_management_assessments.go index 75d313c50..4868d8a6b 100644 --- a/rest/flex/v1/insights_quality_management_assessments.go +++ b/rest/flex/v1/insights_quality_management_assessments.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -96,6 +97,9 @@ func (params *CreateInsightsAssessmentsParams) SetQuestionnaireSid(Questionnaire // Add assessments against conversation to dynamo db. Used in assessments screen by user. Users can select the questionnaire and pick up answers for each and every question. func (c *ApiService) CreateInsightsAssessments(params *CreateInsightsAssessmentsParams) (*FlexV1InsightsAssessments, error) { + return c.CreateInsightsAssessmentsWithContext(context.TODO(), params) +} +func (c *ApiService) CreateInsightsAssessmentsWithContext(ctx context.Context, params *CreateInsightsAssessmentsParams) (*FlexV1InsightsAssessments, error) { path := "/v1/Insights/QualityManagement/Assessments" data := url.Values{} @@ -137,7 +141,7 @@ func (c *ApiService) CreateInsightsAssessments(params *CreateInsightsAssessments if params != nil && params.Authorization != nil { headers["Authorization"] = *params.Authorization } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -183,6 +187,11 @@ func (params *ListInsightsAssessmentsParams) SetLimit(Limit int) *ListInsightsAs // Retrieve a single page of InsightsAssessments records from the API. Request is executed immediately. func (c *ApiService) PageInsightsAssessments(params *ListInsightsAssessmentsParams, pageToken, pageNumber string) (*ListInsightsAssessmentsResponse, error) { + return c.PageInsightsAssessmentsWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of InsightsAssessments records from the API. Request is executed immediately. +func (c *ApiService) PageInsightsAssessmentsWithContext(ctx context.Context, params *ListInsightsAssessmentsParams, pageToken, pageNumber string) (*ListInsightsAssessmentsResponse, error) { path := "/v1/Insights/QualityManagement/Assessments" data := url.Values{} @@ -204,7 +213,7 @@ func (c *ApiService) PageInsightsAssessments(params *ListInsightsAssessmentsPara data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -221,7 +230,12 @@ func (c *ApiService) PageInsightsAssessments(params *ListInsightsAssessmentsPara // Lists InsightsAssessments records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListInsightsAssessments(params *ListInsightsAssessmentsParams) ([]FlexV1InsightsAssessments, error) { - response, errors := c.StreamInsightsAssessments(params) + return c.ListInsightsAssessmentsWithContext(context.TODO(), params) +} + +// Lists InsightsAssessments records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListInsightsAssessmentsWithContext(ctx context.Context, params *ListInsightsAssessmentsParams) ([]FlexV1InsightsAssessments, error) { + response, errors := c.StreamInsightsAssessmentsWithContext(ctx, params) records := make([]FlexV1InsightsAssessments, 0) for record := range response { @@ -237,6 +251,11 @@ func (c *ApiService) ListInsightsAssessments(params *ListInsightsAssessmentsPara // Streams InsightsAssessments records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamInsightsAssessments(params *ListInsightsAssessmentsParams) (chan FlexV1InsightsAssessments, chan error) { + return c.StreamInsightsAssessmentsWithContext(context.TODO(), params) +} + +// Streams InsightsAssessments records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamInsightsAssessmentsWithContext(ctx context.Context, params *ListInsightsAssessmentsParams) (chan FlexV1InsightsAssessments, chan error) { if params == nil { params = &ListInsightsAssessmentsParams{} } @@ -245,19 +264,19 @@ func (c *ApiService) StreamInsightsAssessments(params *ListInsightsAssessmentsPa recordChannel := make(chan FlexV1InsightsAssessments, 1) errorChannel := make(chan error, 1) - response, err := c.PageInsightsAssessments(params, "", "") + response, err := c.PageInsightsAssessmentsWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamInsightsAssessments(response, params, recordChannel, errorChannel) + go c.streamInsightsAssessmentsWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamInsightsAssessments(response *ListInsightsAssessmentsResponse, params *ListInsightsAssessmentsParams, recordChannel chan FlexV1InsightsAssessments, errorChannel chan error) { +func (c *ApiService) streamInsightsAssessmentsWithContext(ctx context.Context, response *ListInsightsAssessmentsResponse, params *ListInsightsAssessmentsParams, recordChannel chan FlexV1InsightsAssessments, errorChannel chan error) { curRecord := 1 for response != nil { @@ -272,7 +291,7 @@ func (c *ApiService) streamInsightsAssessments(response *ListInsightsAssessments } } - record, err := client.GetNext(c.baseURL, response, c.getNextListInsightsAssessmentsResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListInsightsAssessmentsResponseWithContext) if err != nil { errorChannel <- err break @@ -287,11 +306,11 @@ func (c *ApiService) streamInsightsAssessments(response *ListInsightsAssessments close(errorChannel) } -func (c *ApiService) getNextListInsightsAssessmentsResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListInsightsAssessmentsResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -336,6 +355,9 @@ func (params *UpdateInsightsAssessmentsParams) SetAnswerId(AnswerId string) *Upd // Update a specific Assessment assessed earlier func (c *ApiService) UpdateInsightsAssessments(AssessmentSid string, params *UpdateInsightsAssessmentsParams) (*FlexV1InsightsAssessments, error) { + return c.UpdateInsightsAssessmentsWithContext(context.TODO(), AssessmentSid, params) +} +func (c *ApiService) UpdateInsightsAssessmentsWithContext(ctx context.Context, AssessmentSid string, params *UpdateInsightsAssessmentsParams) (*FlexV1InsightsAssessments, error) { path := "/v1/Insights/QualityManagement/Assessments/{AssessmentSid}" path = strings.Replace(path, "{"+"AssessmentSid"+"}", AssessmentSid, -1) @@ -357,7 +379,7 @@ func (c *ApiService) UpdateInsightsAssessments(AssessmentSid string, params *Upd if params != nil && params.Authorization != nil { headers["Authorization"] = *params.Authorization } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/flex/v1/insights_quality_management_assessments_comments.go b/rest/flex/v1/insights_quality_management_assessments_comments.go index 1c67c672f..2f91ed782 100644 --- a/rest/flex/v1/insights_quality_management_assessments_comments.go +++ b/rest/flex/v1/insights_quality_management_assessments_comments.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -71,6 +72,9 @@ func (params *CreateInsightsAssessmentsCommentParams) SetOffset(Offset float32) // To create a comment assessment for a conversation func (c *ApiService) CreateInsightsAssessmentsComment(params *CreateInsightsAssessmentsCommentParams) (*FlexV1InsightsAssessmentsComment, error) { + return c.CreateInsightsAssessmentsCommentWithContext(context.TODO(), params) +} +func (c *ApiService) CreateInsightsAssessmentsCommentWithContext(ctx context.Context, params *CreateInsightsAssessmentsCommentParams) (*FlexV1InsightsAssessmentsComment, error) { path := "/v1/Insights/QualityManagement/Assessments/Comments" data := url.Values{} @@ -100,7 +104,7 @@ func (c *ApiService) CreateInsightsAssessmentsComment(params *CreateInsightsAsse if params != nil && params.Authorization != nil { headers["Authorization"] = *params.Authorization } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -152,6 +156,11 @@ func (params *ListInsightsAssessmentsCommentParams) SetLimit(Limit int) *ListIns // Retrieve a single page of InsightsAssessmentsComment records from the API. Request is executed immediately. func (c *ApiService) PageInsightsAssessmentsComment(params *ListInsightsAssessmentsCommentParams, pageToken, pageNumber string) (*ListInsightsAssessmentsCommentResponse, error) { + return c.PageInsightsAssessmentsCommentWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of InsightsAssessmentsComment records from the API. Request is executed immediately. +func (c *ApiService) PageInsightsAssessmentsCommentWithContext(ctx context.Context, params *ListInsightsAssessmentsCommentParams, pageToken, pageNumber string) (*ListInsightsAssessmentsCommentResponse, error) { path := "/v1/Insights/QualityManagement/Assessments/Comments" data := url.Values{} @@ -176,7 +185,7 @@ func (c *ApiService) PageInsightsAssessmentsComment(params *ListInsightsAssessme data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -193,7 +202,12 @@ func (c *ApiService) PageInsightsAssessmentsComment(params *ListInsightsAssessme // Lists InsightsAssessmentsComment records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListInsightsAssessmentsComment(params *ListInsightsAssessmentsCommentParams) ([]FlexV1InsightsAssessmentsComment, error) { - response, errors := c.StreamInsightsAssessmentsComment(params) + return c.ListInsightsAssessmentsCommentWithContext(context.TODO(), params) +} + +// Lists InsightsAssessmentsComment records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListInsightsAssessmentsCommentWithContext(ctx context.Context, params *ListInsightsAssessmentsCommentParams) ([]FlexV1InsightsAssessmentsComment, error) { + response, errors := c.StreamInsightsAssessmentsCommentWithContext(ctx, params) records := make([]FlexV1InsightsAssessmentsComment, 0) for record := range response { @@ -209,6 +223,11 @@ func (c *ApiService) ListInsightsAssessmentsComment(params *ListInsightsAssessme // Streams InsightsAssessmentsComment records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamInsightsAssessmentsComment(params *ListInsightsAssessmentsCommentParams) (chan FlexV1InsightsAssessmentsComment, chan error) { + return c.StreamInsightsAssessmentsCommentWithContext(context.TODO(), params) +} + +// Streams InsightsAssessmentsComment records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamInsightsAssessmentsCommentWithContext(ctx context.Context, params *ListInsightsAssessmentsCommentParams) (chan FlexV1InsightsAssessmentsComment, chan error) { if params == nil { params = &ListInsightsAssessmentsCommentParams{} } @@ -217,19 +236,19 @@ func (c *ApiService) StreamInsightsAssessmentsComment(params *ListInsightsAssess recordChannel := make(chan FlexV1InsightsAssessmentsComment, 1) errorChannel := make(chan error, 1) - response, err := c.PageInsightsAssessmentsComment(params, "", "") + response, err := c.PageInsightsAssessmentsCommentWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamInsightsAssessmentsComment(response, params, recordChannel, errorChannel) + go c.streamInsightsAssessmentsCommentWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamInsightsAssessmentsComment(response *ListInsightsAssessmentsCommentResponse, params *ListInsightsAssessmentsCommentParams, recordChannel chan FlexV1InsightsAssessmentsComment, errorChannel chan error) { +func (c *ApiService) streamInsightsAssessmentsCommentWithContext(ctx context.Context, response *ListInsightsAssessmentsCommentResponse, params *ListInsightsAssessmentsCommentParams, recordChannel chan FlexV1InsightsAssessmentsComment, errorChannel chan error) { curRecord := 1 for response != nil { @@ -244,7 +263,7 @@ func (c *ApiService) streamInsightsAssessmentsComment(response *ListInsightsAsse } } - record, err := client.GetNext(c.baseURL, response, c.getNextListInsightsAssessmentsCommentResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListInsightsAssessmentsCommentResponseWithContext) if err != nil { errorChannel <- err break @@ -259,11 +278,11 @@ func (c *ApiService) streamInsightsAssessmentsComment(response *ListInsightsAsse close(errorChannel) } -func (c *ApiService) getNextListInsightsAssessmentsCommentResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListInsightsAssessmentsCommentResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/flex/v1/insights_quality_management_categories.go b/rest/flex/v1/insights_quality_management_categories.go index 087b1cfff..3a589c2f3 100644 --- a/rest/flex/v1/insights_quality_management_categories.go +++ b/rest/flex/v1/insights_quality_management_categories.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -42,6 +43,9 @@ func (params *CreateInsightsQuestionnairesCategoryParams) SetName(Name string) * // To create a category for Questions func (c *ApiService) CreateInsightsQuestionnairesCategory(params *CreateInsightsQuestionnairesCategoryParams) (*FlexV1InsightsQuestionnairesCategory, error) { + return c.CreateInsightsQuestionnairesCategoryWithContext(context.TODO(), params) +} +func (c *ApiService) CreateInsightsQuestionnairesCategoryWithContext(ctx context.Context, params *CreateInsightsQuestionnairesCategoryParams) (*FlexV1InsightsQuestionnairesCategory, error) { path := "/v1/Insights/QualityManagement/Categories" data := url.Values{} @@ -56,7 +60,7 @@ func (c *ApiService) CreateInsightsQuestionnairesCategory(params *CreateInsights if params != nil && params.Authorization != nil { headers["Authorization"] = *params.Authorization } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -82,8 +86,10 @@ func (params *DeleteInsightsQuestionnairesCategoryParams) SetAuthorization(Autho return params } -// func (c *ApiService) DeleteInsightsQuestionnairesCategory(CategorySid string, params *DeleteInsightsQuestionnairesCategoryParams) error { + return c.DeleteInsightsQuestionnairesCategoryWithContext(context.TODO(), CategorySid, params) +} +func (c *ApiService) DeleteInsightsQuestionnairesCategoryWithContext(ctx context.Context, CategorySid string, params *DeleteInsightsQuestionnairesCategoryParams) error { path := "/v1/Insights/QualityManagement/Categories/{CategorySid}" path = strings.Replace(path, "{"+"CategorySid"+"}", CategorySid, -1) @@ -95,7 +101,7 @@ func (c *ApiService) DeleteInsightsQuestionnairesCategory(CategorySid string, pa if params != nil && params.Authorization != nil { headers["Authorization"] = *params.Authorization } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -130,6 +136,11 @@ func (params *ListInsightsQuestionnairesCategoryParams) SetLimit(Limit int) *Lis // Retrieve a single page of InsightsQuestionnairesCategory records from the API. Request is executed immediately. func (c *ApiService) PageInsightsQuestionnairesCategory(params *ListInsightsQuestionnairesCategoryParams, pageToken, pageNumber string) (*ListInsightsQuestionnairesCategoryResponse, error) { + return c.PageInsightsQuestionnairesCategoryWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of InsightsQuestionnairesCategory records from the API. Request is executed immediately. +func (c *ApiService) PageInsightsQuestionnairesCategoryWithContext(ctx context.Context, params *ListInsightsQuestionnairesCategoryParams, pageToken, pageNumber string) (*ListInsightsQuestionnairesCategoryResponse, error) { path := "/v1/Insights/QualityManagement/Categories" data := url.Values{} @@ -148,7 +159,7 @@ func (c *ApiService) PageInsightsQuestionnairesCategory(params *ListInsightsQues data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -165,7 +176,12 @@ func (c *ApiService) PageInsightsQuestionnairesCategory(params *ListInsightsQues // Lists InsightsQuestionnairesCategory records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListInsightsQuestionnairesCategory(params *ListInsightsQuestionnairesCategoryParams) ([]FlexV1InsightsQuestionnairesCategory, error) { - response, errors := c.StreamInsightsQuestionnairesCategory(params) + return c.ListInsightsQuestionnairesCategoryWithContext(context.TODO(), params) +} + +// Lists InsightsQuestionnairesCategory records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListInsightsQuestionnairesCategoryWithContext(ctx context.Context, params *ListInsightsQuestionnairesCategoryParams) ([]FlexV1InsightsQuestionnairesCategory, error) { + response, errors := c.StreamInsightsQuestionnairesCategoryWithContext(ctx, params) records := make([]FlexV1InsightsQuestionnairesCategory, 0) for record := range response { @@ -181,6 +197,11 @@ func (c *ApiService) ListInsightsQuestionnairesCategory(params *ListInsightsQues // Streams InsightsQuestionnairesCategory records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamInsightsQuestionnairesCategory(params *ListInsightsQuestionnairesCategoryParams) (chan FlexV1InsightsQuestionnairesCategory, chan error) { + return c.StreamInsightsQuestionnairesCategoryWithContext(context.TODO(), params) +} + +// Streams InsightsQuestionnairesCategory records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamInsightsQuestionnairesCategoryWithContext(ctx context.Context, params *ListInsightsQuestionnairesCategoryParams) (chan FlexV1InsightsQuestionnairesCategory, chan error) { if params == nil { params = &ListInsightsQuestionnairesCategoryParams{} } @@ -189,19 +210,19 @@ func (c *ApiService) StreamInsightsQuestionnairesCategory(params *ListInsightsQu recordChannel := make(chan FlexV1InsightsQuestionnairesCategory, 1) errorChannel := make(chan error, 1) - response, err := c.PageInsightsQuestionnairesCategory(params, "", "") + response, err := c.PageInsightsQuestionnairesCategoryWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamInsightsQuestionnairesCategory(response, params, recordChannel, errorChannel) + go c.streamInsightsQuestionnairesCategoryWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamInsightsQuestionnairesCategory(response *ListInsightsQuestionnairesCategoryResponse, params *ListInsightsQuestionnairesCategoryParams, recordChannel chan FlexV1InsightsQuestionnairesCategory, errorChannel chan error) { +func (c *ApiService) streamInsightsQuestionnairesCategoryWithContext(ctx context.Context, response *ListInsightsQuestionnairesCategoryResponse, params *ListInsightsQuestionnairesCategoryParams, recordChannel chan FlexV1InsightsQuestionnairesCategory, errorChannel chan error) { curRecord := 1 for response != nil { @@ -216,7 +237,7 @@ func (c *ApiService) streamInsightsQuestionnairesCategory(response *ListInsights } } - record, err := client.GetNext(c.baseURL, response, c.getNextListInsightsQuestionnairesCategoryResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListInsightsQuestionnairesCategoryResponseWithContext) if err != nil { errorChannel <- err break @@ -231,11 +252,11 @@ func (c *ApiService) streamInsightsQuestionnairesCategory(response *ListInsights close(errorChannel) } -func (c *ApiService) getNextListInsightsQuestionnairesCategoryResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListInsightsQuestionnairesCategoryResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -268,6 +289,9 @@ func (params *UpdateInsightsQuestionnairesCategoryParams) SetName(Name string) * // To update the category for Questions func (c *ApiService) UpdateInsightsQuestionnairesCategory(CategorySid string, params *UpdateInsightsQuestionnairesCategoryParams) (*FlexV1InsightsQuestionnairesCategory, error) { + return c.UpdateInsightsQuestionnairesCategoryWithContext(context.TODO(), CategorySid, params) +} +func (c *ApiService) UpdateInsightsQuestionnairesCategoryWithContext(ctx context.Context, CategorySid string, params *UpdateInsightsQuestionnairesCategoryParams) (*FlexV1InsightsQuestionnairesCategory, error) { path := "/v1/Insights/QualityManagement/Categories/{CategorySid}" path = strings.Replace(path, "{"+"CategorySid"+"}", CategorySid, -1) @@ -283,7 +307,7 @@ func (c *ApiService) UpdateInsightsQuestionnairesCategory(CategorySid string, pa if params != nil && params.Authorization != nil { headers["Authorization"] = *params.Authorization } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/flex/v1/insights_quality_management_questionnaires.go b/rest/flex/v1/insights_quality_management_questionnaires.go index 2841ae5d0..31b41facc 100644 --- a/rest/flex/v1/insights_quality_management_questionnaires.go +++ b/rest/flex/v1/insights_quality_management_questionnaires.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -60,6 +61,9 @@ func (params *CreateInsightsQuestionnairesParams) SetQuestionSids(QuestionSids [ // To create a Questionnaire func (c *ApiService) CreateInsightsQuestionnaires(params *CreateInsightsQuestionnairesParams) (*FlexV1InsightsQuestionnaires, error) { + return c.CreateInsightsQuestionnairesWithContext(context.TODO(), params) +} +func (c *ApiService) CreateInsightsQuestionnairesWithContext(ctx context.Context, params *CreateInsightsQuestionnairesParams) (*FlexV1InsightsQuestionnaires, error) { path := "/v1/Insights/QualityManagement/Questionnaires" data := url.Values{} @@ -85,7 +89,7 @@ func (c *ApiService) CreateInsightsQuestionnaires(params *CreateInsightsQuestion if params != nil && params.Authorization != nil { headers["Authorization"] = *params.Authorization } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -113,6 +117,9 @@ func (params *DeleteInsightsQuestionnairesParams) SetAuthorization(Authorization // To delete the questionnaire func (c *ApiService) DeleteInsightsQuestionnaires(QuestionnaireSid string, params *DeleteInsightsQuestionnairesParams) error { + return c.DeleteInsightsQuestionnairesWithContext(context.TODO(), QuestionnaireSid, params) +} +func (c *ApiService) DeleteInsightsQuestionnairesWithContext(ctx context.Context, QuestionnaireSid string, params *DeleteInsightsQuestionnairesParams) error { path := "/v1/Insights/QualityManagement/Questionnaires/{QuestionnaireSid}" path = strings.Replace(path, "{"+"QuestionnaireSid"+"}", QuestionnaireSid, -1) @@ -124,7 +131,7 @@ func (c *ApiService) DeleteInsightsQuestionnaires(QuestionnaireSid string, param if params != nil && params.Authorization != nil { headers["Authorization"] = *params.Authorization } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -147,6 +154,9 @@ func (params *FetchInsightsQuestionnairesParams) SetAuthorization(Authorization // To get the Questionnaire Detail func (c *ApiService) FetchInsightsQuestionnaires(QuestionnaireSid string, params *FetchInsightsQuestionnairesParams) (*FlexV1InsightsQuestionnaires, error) { + return c.FetchInsightsQuestionnairesWithContext(context.TODO(), QuestionnaireSid, params) +} +func (c *ApiService) FetchInsightsQuestionnairesWithContext(ctx context.Context, QuestionnaireSid string, params *FetchInsightsQuestionnairesParams) (*FlexV1InsightsQuestionnaires, error) { path := "/v1/Insights/QualityManagement/Questionnaires/{QuestionnaireSid}" path = strings.Replace(path, "{"+"QuestionnaireSid"+"}", QuestionnaireSid, -1) @@ -158,7 +168,7 @@ func (c *ApiService) FetchInsightsQuestionnaires(QuestionnaireSid string, params if params != nil && params.Authorization != nil { headers["Authorization"] = *params.Authorization } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -204,6 +214,11 @@ func (params *ListInsightsQuestionnairesParams) SetLimit(Limit int) *ListInsight // Retrieve a single page of InsightsQuestionnaires records from the API. Request is executed immediately. func (c *ApiService) PageInsightsQuestionnaires(params *ListInsightsQuestionnairesParams, pageToken, pageNumber string) (*ListInsightsQuestionnairesResponse, error) { + return c.PageInsightsQuestionnairesWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of InsightsQuestionnaires records from the API. Request is executed immediately. +func (c *ApiService) PageInsightsQuestionnairesWithContext(ctx context.Context, params *ListInsightsQuestionnairesParams, pageToken, pageNumber string) (*ListInsightsQuestionnairesResponse, error) { path := "/v1/Insights/QualityManagement/Questionnaires" data := url.Values{} @@ -225,7 +240,7 @@ func (c *ApiService) PageInsightsQuestionnaires(params *ListInsightsQuestionnair data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -242,7 +257,12 @@ func (c *ApiService) PageInsightsQuestionnaires(params *ListInsightsQuestionnair // Lists InsightsQuestionnaires records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListInsightsQuestionnaires(params *ListInsightsQuestionnairesParams) ([]FlexV1InsightsQuestionnaires, error) { - response, errors := c.StreamInsightsQuestionnaires(params) + return c.ListInsightsQuestionnairesWithContext(context.TODO(), params) +} + +// Lists InsightsQuestionnaires records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListInsightsQuestionnairesWithContext(ctx context.Context, params *ListInsightsQuestionnairesParams) ([]FlexV1InsightsQuestionnaires, error) { + response, errors := c.StreamInsightsQuestionnairesWithContext(ctx, params) records := make([]FlexV1InsightsQuestionnaires, 0) for record := range response { @@ -258,6 +278,11 @@ func (c *ApiService) ListInsightsQuestionnaires(params *ListInsightsQuestionnair // Streams InsightsQuestionnaires records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamInsightsQuestionnaires(params *ListInsightsQuestionnairesParams) (chan FlexV1InsightsQuestionnaires, chan error) { + return c.StreamInsightsQuestionnairesWithContext(context.TODO(), params) +} + +// Streams InsightsQuestionnaires records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamInsightsQuestionnairesWithContext(ctx context.Context, params *ListInsightsQuestionnairesParams) (chan FlexV1InsightsQuestionnaires, chan error) { if params == nil { params = &ListInsightsQuestionnairesParams{} } @@ -266,19 +291,19 @@ func (c *ApiService) StreamInsightsQuestionnaires(params *ListInsightsQuestionna recordChannel := make(chan FlexV1InsightsQuestionnaires, 1) errorChannel := make(chan error, 1) - response, err := c.PageInsightsQuestionnaires(params, "", "") + response, err := c.PageInsightsQuestionnairesWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamInsightsQuestionnaires(response, params, recordChannel, errorChannel) + go c.streamInsightsQuestionnairesWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamInsightsQuestionnaires(response *ListInsightsQuestionnairesResponse, params *ListInsightsQuestionnairesParams, recordChannel chan FlexV1InsightsQuestionnaires, errorChannel chan error) { +func (c *ApiService) streamInsightsQuestionnairesWithContext(ctx context.Context, response *ListInsightsQuestionnairesResponse, params *ListInsightsQuestionnairesParams, recordChannel chan FlexV1InsightsQuestionnaires, errorChannel chan error) { curRecord := 1 for response != nil { @@ -293,7 +318,7 @@ func (c *ApiService) streamInsightsQuestionnaires(response *ListInsightsQuestion } } - record, err := client.GetNext(c.baseURL, response, c.getNextListInsightsQuestionnairesResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListInsightsQuestionnairesResponseWithContext) if err != nil { errorChannel <- err break @@ -308,11 +333,11 @@ func (c *ApiService) streamInsightsQuestionnaires(response *ListInsightsQuestion close(errorChannel) } -func (c *ApiService) getNextListInsightsQuestionnairesResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListInsightsQuestionnairesResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -363,6 +388,9 @@ func (params *UpdateInsightsQuestionnairesParams) SetQuestionSids(QuestionSids [ // To update the questionnaire func (c *ApiService) UpdateInsightsQuestionnaires(QuestionnaireSid string, params *UpdateInsightsQuestionnairesParams) (*FlexV1InsightsQuestionnaires, error) { + return c.UpdateInsightsQuestionnairesWithContext(context.TODO(), QuestionnaireSid, params) +} +func (c *ApiService) UpdateInsightsQuestionnairesWithContext(ctx context.Context, QuestionnaireSid string, params *UpdateInsightsQuestionnairesParams) (*FlexV1InsightsQuestionnaires, error) { path := "/v1/Insights/QualityManagement/Questionnaires/{QuestionnaireSid}" path = strings.Replace(path, "{"+"QuestionnaireSid"+"}", QuestionnaireSid, -1) @@ -389,7 +417,7 @@ func (c *ApiService) UpdateInsightsQuestionnaires(QuestionnaireSid string, param if params != nil && params.Authorization != nil { headers["Authorization"] = *params.Authorization } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/flex/v1/insights_quality_management_questions.go b/rest/flex/v1/insights_quality_management_questions.go index f0ef1f3a3..994f5ca9c 100644 --- a/rest/flex/v1/insights_quality_management_questions.go +++ b/rest/flex/v1/insights_quality_management_questions.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -66,6 +67,9 @@ func (params *CreateInsightsQuestionnairesQuestionParams) SetDescription(Descrip // To create a question for a Category func (c *ApiService) CreateInsightsQuestionnairesQuestion(params *CreateInsightsQuestionnairesQuestionParams) (*FlexV1InsightsQuestionnairesQuestion, error) { + return c.CreateInsightsQuestionnairesQuestionWithContext(context.TODO(), params) +} +func (c *ApiService) CreateInsightsQuestionnairesQuestionWithContext(ctx context.Context, params *CreateInsightsQuestionnairesQuestionParams) (*FlexV1InsightsQuestionnairesQuestion, error) { path := "/v1/Insights/QualityManagement/Questions" data := url.Values{} @@ -92,7 +96,7 @@ func (c *ApiService) CreateInsightsQuestionnairesQuestion(params *CreateInsights if params != nil && params.Authorization != nil { headers["Authorization"] = *params.Authorization } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -118,8 +122,10 @@ func (params *DeleteInsightsQuestionnairesQuestionParams) SetAuthorization(Autho return params } -// func (c *ApiService) DeleteInsightsQuestionnairesQuestion(QuestionSid string, params *DeleteInsightsQuestionnairesQuestionParams) error { + return c.DeleteInsightsQuestionnairesQuestionWithContext(context.TODO(), QuestionSid, params) +} +func (c *ApiService) DeleteInsightsQuestionnairesQuestionWithContext(ctx context.Context, QuestionSid string, params *DeleteInsightsQuestionnairesQuestionParams) error { path := "/v1/Insights/QualityManagement/Questions/{QuestionSid}" path = strings.Replace(path, "{"+"QuestionSid"+"}", QuestionSid, -1) @@ -131,7 +137,7 @@ func (c *ApiService) DeleteInsightsQuestionnairesQuestion(QuestionSid string, pa if params != nil && params.Authorization != nil { headers["Authorization"] = *params.Authorization } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -172,6 +178,11 @@ func (params *ListInsightsQuestionnairesQuestionParams) SetLimit(Limit int) *Lis // Retrieve a single page of InsightsQuestionnairesQuestion records from the API. Request is executed immediately. func (c *ApiService) PageInsightsQuestionnairesQuestion(params *ListInsightsQuestionnairesQuestionParams, pageToken, pageNumber string) (*ListInsightsQuestionnairesQuestionResponse, error) { + return c.PageInsightsQuestionnairesQuestionWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of InsightsQuestionnairesQuestion records from the API. Request is executed immediately. +func (c *ApiService) PageInsightsQuestionnairesQuestionWithContext(ctx context.Context, params *ListInsightsQuestionnairesQuestionParams, pageToken, pageNumber string) (*ListInsightsQuestionnairesQuestionResponse, error) { path := "/v1/Insights/QualityManagement/Questions" data := url.Values{} @@ -195,7 +206,7 @@ func (c *ApiService) PageInsightsQuestionnairesQuestion(params *ListInsightsQues data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -212,7 +223,12 @@ func (c *ApiService) PageInsightsQuestionnairesQuestion(params *ListInsightsQues // Lists InsightsQuestionnairesQuestion records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListInsightsQuestionnairesQuestion(params *ListInsightsQuestionnairesQuestionParams) ([]FlexV1InsightsQuestionnairesQuestion, error) { - response, errors := c.StreamInsightsQuestionnairesQuestion(params) + return c.ListInsightsQuestionnairesQuestionWithContext(context.TODO(), params) +} + +// Lists InsightsQuestionnairesQuestion records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListInsightsQuestionnairesQuestionWithContext(ctx context.Context, params *ListInsightsQuestionnairesQuestionParams) ([]FlexV1InsightsQuestionnairesQuestion, error) { + response, errors := c.StreamInsightsQuestionnairesQuestionWithContext(ctx, params) records := make([]FlexV1InsightsQuestionnairesQuestion, 0) for record := range response { @@ -228,6 +244,11 @@ func (c *ApiService) ListInsightsQuestionnairesQuestion(params *ListInsightsQues // Streams InsightsQuestionnairesQuestion records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamInsightsQuestionnairesQuestion(params *ListInsightsQuestionnairesQuestionParams) (chan FlexV1InsightsQuestionnairesQuestion, chan error) { + return c.StreamInsightsQuestionnairesQuestionWithContext(context.TODO(), params) +} + +// Streams InsightsQuestionnairesQuestion records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamInsightsQuestionnairesQuestionWithContext(ctx context.Context, params *ListInsightsQuestionnairesQuestionParams) (chan FlexV1InsightsQuestionnairesQuestion, chan error) { if params == nil { params = &ListInsightsQuestionnairesQuestionParams{} } @@ -236,19 +257,19 @@ func (c *ApiService) StreamInsightsQuestionnairesQuestion(params *ListInsightsQu recordChannel := make(chan FlexV1InsightsQuestionnairesQuestion, 1) errorChannel := make(chan error, 1) - response, err := c.PageInsightsQuestionnairesQuestion(params, "", "") + response, err := c.PageInsightsQuestionnairesQuestionWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamInsightsQuestionnairesQuestion(response, params, recordChannel, errorChannel) + go c.streamInsightsQuestionnairesQuestionWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamInsightsQuestionnairesQuestion(response *ListInsightsQuestionnairesQuestionResponse, params *ListInsightsQuestionnairesQuestionParams, recordChannel chan FlexV1InsightsQuestionnairesQuestion, errorChannel chan error) { +func (c *ApiService) streamInsightsQuestionnairesQuestionWithContext(ctx context.Context, response *ListInsightsQuestionnairesQuestionResponse, params *ListInsightsQuestionnairesQuestionParams, recordChannel chan FlexV1InsightsQuestionnairesQuestion, errorChannel chan error) { curRecord := 1 for response != nil { @@ -263,7 +284,7 @@ func (c *ApiService) streamInsightsQuestionnairesQuestion(response *ListInsights } } - record, err := client.GetNext(c.baseURL, response, c.getNextListInsightsQuestionnairesQuestionResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListInsightsQuestionnairesQuestionResponseWithContext) if err != nil { errorChannel <- err break @@ -278,11 +299,11 @@ func (c *ApiService) streamInsightsQuestionnairesQuestion(response *ListInsights close(errorChannel) } -func (c *ApiService) getNextListInsightsQuestionnairesQuestionResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListInsightsQuestionnairesQuestionResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -339,6 +360,9 @@ func (params *UpdateInsightsQuestionnairesQuestionParams) SetAnswerSetId(AnswerS // To update the question func (c *ApiService) UpdateInsightsQuestionnairesQuestion(QuestionSid string, params *UpdateInsightsQuestionnairesQuestionParams) (*FlexV1InsightsQuestionnairesQuestion, error) { + return c.UpdateInsightsQuestionnairesQuestionWithContext(context.TODO(), QuestionSid, params) +} +func (c *ApiService) UpdateInsightsQuestionnairesQuestionWithContext(ctx context.Context, QuestionSid string, params *UpdateInsightsQuestionnairesQuestionParams) (*FlexV1InsightsQuestionnairesQuestion, error) { path := "/v1/Insights/QualityManagement/Questions/{QuestionSid}" path = strings.Replace(path, "{"+"QuestionSid"+"}", QuestionSid, -1) @@ -366,7 +390,7 @@ func (c *ApiService) UpdateInsightsQuestionnairesQuestion(QuestionSid string, pa if params != nil && params.Authorization != nil { headers["Authorization"] = *params.Authorization } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/flex/v1/insights_quality_management_settings_answer_sets.go b/rest/flex/v1/insights_quality_management_settings_answer_sets.go index 60714822b..7abaaf9c0 100644 --- a/rest/flex/v1/insights_quality_management_settings_answer_sets.go +++ b/rest/flex/v1/insights_quality_management_settings_answer_sets.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" ) @@ -32,6 +33,9 @@ func (params *FetchInsightsSettingsAnswersetsParams) SetAuthorization(Authorizat // To get the Answer Set Settings for an Account func (c *ApiService) FetchInsightsSettingsAnswersets(params *FetchInsightsSettingsAnswersetsParams) (*FlexV1InsightsSettingsAnswersets, error) { + return c.FetchInsightsSettingsAnswersetsWithContext(context.TODO(), params) +} +func (c *ApiService) FetchInsightsSettingsAnswersetsWithContext(ctx context.Context, params *FetchInsightsSettingsAnswersetsParams) (*FlexV1InsightsSettingsAnswersets, error) { path := "/v1/Insights/QualityManagement/Settings/AnswerSets" data := url.Values{} @@ -42,7 +46,7 @@ func (c *ApiService) FetchInsightsSettingsAnswersets(params *FetchInsightsSettin if params != nil && params.Authorization != nil { headers["Authorization"] = *params.Authorization } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/flex/v1/insights_quality_management_settings_comment_tags.go b/rest/flex/v1/insights_quality_management_settings_comment_tags.go index 2aad031e3..26ff34276 100644 --- a/rest/flex/v1/insights_quality_management_settings_comment_tags.go +++ b/rest/flex/v1/insights_quality_management_settings_comment_tags.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" ) @@ -32,6 +33,9 @@ func (params *FetchInsightsSettingsCommentParams) SetAuthorization(Authorization // To get the Comment Settings for an Account func (c *ApiService) FetchInsightsSettingsComment(params *FetchInsightsSettingsCommentParams) (*FlexV1InsightsSettingsComment, error) { + return c.FetchInsightsSettingsCommentWithContext(context.TODO(), params) +} +func (c *ApiService) FetchInsightsSettingsCommentWithContext(ctx context.Context, params *FetchInsightsSettingsCommentParams) (*FlexV1InsightsSettingsComment, error) { path := "/v1/Insights/QualityManagement/Settings/CommentTags" data := url.Values{} @@ -42,7 +46,7 @@ func (c *ApiService) FetchInsightsSettingsComment(params *FetchInsightsSettingsC if params != nil && params.Authorization != nil { headers["Authorization"] = *params.Authorization } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/flex/v1/insights_segments.go b/rest/flex/v1/insights_segments.go index 14aa8f920..6c2cc1af9 100644 --- a/rest/flex/v1/insights_segments.go +++ b/rest/flex/v1/insights_segments.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -59,6 +60,11 @@ func (params *ListInsightsSegmentsParams) SetLimit(Limit int) *ListInsightsSegme // Retrieve a single page of InsightsSegments records from the API. Request is executed immediately. func (c *ApiService) PageInsightsSegments(params *ListInsightsSegmentsParams, pageToken, pageNumber string) (*ListInsightsSegmentsResponse, error) { + return c.PageInsightsSegmentsWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of InsightsSegments records from the API. Request is executed immediately. +func (c *ApiService) PageInsightsSegmentsWithContext(ctx context.Context, params *ListInsightsSegmentsParams, pageToken, pageNumber string) (*ListInsightsSegmentsResponse, error) { path := "/v1/Insights/Segments" data := url.Values{} @@ -85,7 +91,7 @@ func (c *ApiService) PageInsightsSegments(params *ListInsightsSegmentsParams, pa data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -102,7 +108,12 @@ func (c *ApiService) PageInsightsSegments(params *ListInsightsSegmentsParams, pa // Lists InsightsSegments records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListInsightsSegments(params *ListInsightsSegmentsParams) ([]FlexV1InsightsSegments, error) { - response, errors := c.StreamInsightsSegments(params) + return c.ListInsightsSegmentsWithContext(context.TODO(), params) +} + +// Lists InsightsSegments records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListInsightsSegmentsWithContext(ctx context.Context, params *ListInsightsSegmentsParams) ([]FlexV1InsightsSegments, error) { + response, errors := c.StreamInsightsSegmentsWithContext(ctx, params) records := make([]FlexV1InsightsSegments, 0) for record := range response { @@ -118,6 +129,11 @@ func (c *ApiService) ListInsightsSegments(params *ListInsightsSegmentsParams) ([ // Streams InsightsSegments records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamInsightsSegments(params *ListInsightsSegmentsParams) (chan FlexV1InsightsSegments, chan error) { + return c.StreamInsightsSegmentsWithContext(context.TODO(), params) +} + +// Streams InsightsSegments records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamInsightsSegmentsWithContext(ctx context.Context, params *ListInsightsSegmentsParams) (chan FlexV1InsightsSegments, chan error) { if params == nil { params = &ListInsightsSegmentsParams{} } @@ -126,19 +142,19 @@ func (c *ApiService) StreamInsightsSegments(params *ListInsightsSegmentsParams) recordChannel := make(chan FlexV1InsightsSegments, 1) errorChannel := make(chan error, 1) - response, err := c.PageInsightsSegments(params, "", "") + response, err := c.PageInsightsSegmentsWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamInsightsSegments(response, params, recordChannel, errorChannel) + go c.streamInsightsSegmentsWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamInsightsSegments(response *ListInsightsSegmentsResponse, params *ListInsightsSegmentsParams, recordChannel chan FlexV1InsightsSegments, errorChannel chan error) { +func (c *ApiService) streamInsightsSegmentsWithContext(ctx context.Context, response *ListInsightsSegmentsResponse, params *ListInsightsSegmentsParams, recordChannel chan FlexV1InsightsSegments, errorChannel chan error) { curRecord := 1 for response != nil { @@ -153,7 +169,7 @@ func (c *ApiService) streamInsightsSegments(response *ListInsightsSegmentsRespon } } - record, err := client.GetNext(c.baseURL, response, c.getNextListInsightsSegmentsResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListInsightsSegmentsResponseWithContext) if err != nil { errorChannel <- err break @@ -168,11 +184,11 @@ func (c *ApiService) streamInsightsSegments(response *ListInsightsSegmentsRespon close(errorChannel) } -func (c *ApiService) getNextListInsightsSegmentsResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListInsightsSegmentsResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/flex/v1/insights_session.go b/rest/flex/v1/insights_session.go index 31bc8f887..fcd8e3324 100644 --- a/rest/flex/v1/insights_session.go +++ b/rest/flex/v1/insights_session.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" ) @@ -32,6 +33,9 @@ func (params *CreateInsightsSessionParams) SetAuthorization(Authorization string // To obtain session details for fetching reports and dashboards func (c *ApiService) CreateInsightsSession(params *CreateInsightsSessionParams) (*FlexV1InsightsSession, error) { + return c.CreateInsightsSessionWithContext(context.TODO(), params) +} +func (c *ApiService) CreateInsightsSessionWithContext(ctx context.Context, params *CreateInsightsSessionParams) (*FlexV1InsightsSession, error) { path := "/v1/Insights/Session" data := url.Values{} @@ -42,7 +46,7 @@ func (c *ApiService) CreateInsightsSession(params *CreateInsightsSessionParams) if params != nil && params.Authorization != nil { headers["Authorization"] = *params.Authorization } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/flex/v1/insights_user_roles.go b/rest/flex/v1/insights_user_roles.go index 8cadfb15e..69be9461d 100644 --- a/rest/flex/v1/insights_user_roles.go +++ b/rest/flex/v1/insights_user_roles.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" ) @@ -32,6 +33,9 @@ func (params *FetchInsightsUserRolesParams) SetAuthorization(Authorization strin // This is used by Flex UI and Quality Management to fetch the Flex Insights roles for the user func (c *ApiService) FetchInsightsUserRoles(params *FetchInsightsUserRolesParams) (*FlexV1InsightsUserRoles, error) { + return c.FetchInsightsUserRolesWithContext(context.TODO(), params) +} +func (c *ApiService) FetchInsightsUserRolesWithContext(ctx context.Context, params *FetchInsightsUserRolesParams) (*FlexV1InsightsUserRoles, error) { path := "/v1/Insights/UserRoles" data := url.Values{} @@ -42,7 +46,7 @@ func (c *ApiService) FetchInsightsUserRoles(params *FetchInsightsUserRolesParams if params != nil && params.Authorization != nil { headers["Authorization"] = *params.Authorization } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/flex/v1/interactions.go b/rest/flex/v1/interactions.go index 635e244dd..457c8803f 100644 --- a/rest/flex/v1/interactions.go +++ b/rest/flex/v1/interactions.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -51,6 +52,9 @@ func (params *CreateInteractionParams) SetWebhookTtid(WebhookTtid string) *Creat // Create a new Interaction. func (c *ApiService) CreateInteraction(params *CreateInteractionParams) (*FlexV1Interaction, error) { + return c.CreateInteractionWithContext(context.TODO(), params) +} +func (c *ApiService) CreateInteractionWithContext(ctx context.Context, params *CreateInteractionParams) (*FlexV1Interaction, error) { path := "/v1/Interactions" data := url.Values{} @@ -83,7 +87,7 @@ func (c *ApiService) CreateInteraction(params *CreateInteractionParams) (*FlexV1 data.Set("WebhookTtid", *params.WebhookTtid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -98,8 +102,10 @@ func (c *ApiService) CreateInteraction(params *CreateInteractionParams) (*FlexV1 return ps, err } -// func (c *ApiService) FetchInteraction(Sid string) (*FlexV1Interaction, error) { + return c.FetchInteractionWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchInteractionWithContext(ctx context.Context, Sid string) (*FlexV1Interaction, error) { path := "/v1/Interactions/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -108,7 +114,7 @@ func (c *ApiService) FetchInteraction(Sid string) (*FlexV1Interaction, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -136,6 +142,9 @@ func (params *UpdateInteractionParams) SetWebhookTtid(WebhookTtid string) *Updat // Updates an interaction. func (c *ApiService) UpdateInteraction(Sid string, params *UpdateInteractionParams) (*FlexV1Interaction, error) { + return c.UpdateInteractionWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateInteractionWithContext(ctx context.Context, Sid string, params *UpdateInteractionParams) (*FlexV1Interaction, error) { path := "/v1/Interactions/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -148,7 +157,7 @@ func (c *ApiService) UpdateInteraction(Sid string, params *UpdateInteractionPara data.Set("WebhookTtid", *params.WebhookTtid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/flex/v1/interactions_channels.go b/rest/flex/v1/interactions_channels.go index 8aa0e1cc8..dadf8a378 100644 --- a/rest/flex/v1/interactions_channels.go +++ b/rest/flex/v1/interactions_channels.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -25,6 +26,9 @@ import ( // Fetch a Channel for an Interaction. func (c *ApiService) FetchInteractionChannel(InteractionSid string, Sid string) (*FlexV1InteractionChannel, error) { + return c.FetchInteractionChannelWithContext(context.TODO(), InteractionSid, Sid) +} +func (c *ApiService) FetchInteractionChannelWithContext(ctx context.Context, InteractionSid string, Sid string) (*FlexV1InteractionChannel, error) { path := "/v1/Interactions/{InteractionSid}/Channels/{Sid}" path = strings.Replace(path, "{"+"InteractionSid"+"}", InteractionSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -34,7 +38,7 @@ func (c *ApiService) FetchInteractionChannel(InteractionSid string, Sid string) "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -68,6 +72,11 @@ func (params *ListInteractionChannelParams) SetLimit(Limit int) *ListInteraction // Retrieve a single page of InteractionChannel records from the API. Request is executed immediately. func (c *ApiService) PageInteractionChannel(InteractionSid string, params *ListInteractionChannelParams, pageToken, pageNumber string) (*ListInteractionChannelResponse, error) { + return c.PageInteractionChannelWithContext(context.TODO(), InteractionSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of InteractionChannel records from the API. Request is executed immediately. +func (c *ApiService) PageInteractionChannelWithContext(ctx context.Context, InteractionSid string, params *ListInteractionChannelParams, pageToken, pageNumber string) (*ListInteractionChannelResponse, error) { path := "/v1/Interactions/{InteractionSid}/Channels" path = strings.Replace(path, "{"+"InteractionSid"+"}", InteractionSid, -1) @@ -88,7 +97,7 @@ func (c *ApiService) PageInteractionChannel(InteractionSid string, params *ListI data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -105,7 +114,12 @@ func (c *ApiService) PageInteractionChannel(InteractionSid string, params *ListI // Lists InteractionChannel records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListInteractionChannel(InteractionSid string, params *ListInteractionChannelParams) ([]FlexV1InteractionChannel, error) { - response, errors := c.StreamInteractionChannel(InteractionSid, params) + return c.ListInteractionChannelWithContext(context.TODO(), InteractionSid, params) +} + +// Lists InteractionChannel records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListInteractionChannelWithContext(ctx context.Context, InteractionSid string, params *ListInteractionChannelParams) ([]FlexV1InteractionChannel, error) { + response, errors := c.StreamInteractionChannelWithContext(ctx, InteractionSid, params) records := make([]FlexV1InteractionChannel, 0) for record := range response { @@ -121,6 +135,11 @@ func (c *ApiService) ListInteractionChannel(InteractionSid string, params *ListI // Streams InteractionChannel records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamInteractionChannel(InteractionSid string, params *ListInteractionChannelParams) (chan FlexV1InteractionChannel, chan error) { + return c.StreamInteractionChannelWithContext(context.TODO(), InteractionSid, params) +} + +// Streams InteractionChannel records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamInteractionChannelWithContext(ctx context.Context, InteractionSid string, params *ListInteractionChannelParams) (chan FlexV1InteractionChannel, chan error) { if params == nil { params = &ListInteractionChannelParams{} } @@ -129,19 +148,19 @@ func (c *ApiService) StreamInteractionChannel(InteractionSid string, params *Lis recordChannel := make(chan FlexV1InteractionChannel, 1) errorChannel := make(chan error, 1) - response, err := c.PageInteractionChannel(InteractionSid, params, "", "") + response, err := c.PageInteractionChannelWithContext(ctx, InteractionSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamInteractionChannel(response, params, recordChannel, errorChannel) + go c.streamInteractionChannelWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamInteractionChannel(response *ListInteractionChannelResponse, params *ListInteractionChannelParams, recordChannel chan FlexV1InteractionChannel, errorChannel chan error) { +func (c *ApiService) streamInteractionChannelWithContext(ctx context.Context, response *ListInteractionChannelResponse, params *ListInteractionChannelParams, recordChannel chan FlexV1InteractionChannel, errorChannel chan error) { curRecord := 1 for response != nil { @@ -156,7 +175,7 @@ func (c *ApiService) streamInteractionChannel(response *ListInteractionChannelRe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListInteractionChannelResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListInteractionChannelResponseWithContext) if err != nil { errorChannel <- err break @@ -171,11 +190,11 @@ func (c *ApiService) streamInteractionChannel(response *ListInteractionChannelRe close(errorChannel) } -func (c *ApiService) getNextListInteractionChannelResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListInteractionChannelResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -208,6 +227,9 @@ func (params *UpdateInteractionChannelParams) SetRouting(Routing map[string]inte // Update an existing Interaction Channel. func (c *ApiService) UpdateInteractionChannel(InteractionSid string, Sid string, params *UpdateInteractionChannelParams) (*FlexV1InteractionChannel, error) { + return c.UpdateInteractionChannelWithContext(context.TODO(), InteractionSid, Sid, params) +} +func (c *ApiService) UpdateInteractionChannelWithContext(ctx context.Context, InteractionSid string, Sid string, params *UpdateInteractionChannelParams) (*FlexV1InteractionChannel, error) { path := "/v1/Interactions/{InteractionSid}/Channels/{Sid}" path = strings.Replace(path, "{"+"InteractionSid"+"}", InteractionSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -230,7 +252,7 @@ func (c *ApiService) UpdateInteractionChannel(InteractionSid string, Sid string, data.Set("Routing", string(v)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/flex/v1/interactions_channels_invites.go b/rest/flex/v1/interactions_channels_invites.go index 0e3291660..01ee96672 100644 --- a/rest/flex/v1/interactions_channels_invites.go +++ b/rest/flex/v1/interactions_channels_invites.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -36,6 +37,9 @@ func (params *CreateInteractionChannelInviteParams) SetRouting(Routing map[strin // Invite an Agent or a TaskQueue to a Channel. func (c *ApiService) CreateInteractionChannelInvite(InteractionSid string, ChannelSid string, params *CreateInteractionChannelInviteParams) (*FlexV1InteractionChannelInvite, error) { + return c.CreateInteractionChannelInviteWithContext(context.TODO(), InteractionSid, ChannelSid, params) +} +func (c *ApiService) CreateInteractionChannelInviteWithContext(ctx context.Context, InteractionSid string, ChannelSid string, params *CreateInteractionChannelInviteParams) (*FlexV1InteractionChannelInvite, error) { path := "/v1/Interactions/{InteractionSid}/Channels/{ChannelSid}/Invites" path = strings.Replace(path, "{"+"InteractionSid"+"}", InteractionSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -55,7 +59,7 @@ func (c *ApiService) CreateInteractionChannelInvite(InteractionSid string, Chann data.Set("Routing", string(v)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -89,6 +93,11 @@ func (params *ListInteractionChannelInviteParams) SetLimit(Limit int) *ListInter // Retrieve a single page of InteractionChannelInvite records from the API. Request is executed immediately. func (c *ApiService) PageInteractionChannelInvite(InteractionSid string, ChannelSid string, params *ListInteractionChannelInviteParams, pageToken, pageNumber string) (*ListInteractionChannelInviteResponse, error) { + return c.PageInteractionChannelInviteWithContext(context.TODO(), InteractionSid, ChannelSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of InteractionChannelInvite records from the API. Request is executed immediately. +func (c *ApiService) PageInteractionChannelInviteWithContext(ctx context.Context, InteractionSid string, ChannelSid string, params *ListInteractionChannelInviteParams, pageToken, pageNumber string) (*ListInteractionChannelInviteResponse, error) { path := "/v1/Interactions/{InteractionSid}/Channels/{ChannelSid}/Invites" path = strings.Replace(path, "{"+"InteractionSid"+"}", InteractionSid, -1) @@ -110,7 +119,7 @@ func (c *ApiService) PageInteractionChannelInvite(InteractionSid string, Channel data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -127,7 +136,12 @@ func (c *ApiService) PageInteractionChannelInvite(InteractionSid string, Channel // Lists InteractionChannelInvite records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListInteractionChannelInvite(InteractionSid string, ChannelSid string, params *ListInteractionChannelInviteParams) ([]FlexV1InteractionChannelInvite, error) { - response, errors := c.StreamInteractionChannelInvite(InteractionSid, ChannelSid, params) + return c.ListInteractionChannelInviteWithContext(context.TODO(), InteractionSid, ChannelSid, params) +} + +// Lists InteractionChannelInvite records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListInteractionChannelInviteWithContext(ctx context.Context, InteractionSid string, ChannelSid string, params *ListInteractionChannelInviteParams) ([]FlexV1InteractionChannelInvite, error) { + response, errors := c.StreamInteractionChannelInviteWithContext(ctx, InteractionSid, ChannelSid, params) records := make([]FlexV1InteractionChannelInvite, 0) for record := range response { @@ -143,6 +157,11 @@ func (c *ApiService) ListInteractionChannelInvite(InteractionSid string, Channel // Streams InteractionChannelInvite records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamInteractionChannelInvite(InteractionSid string, ChannelSid string, params *ListInteractionChannelInviteParams) (chan FlexV1InteractionChannelInvite, chan error) { + return c.StreamInteractionChannelInviteWithContext(context.TODO(), InteractionSid, ChannelSid, params) +} + +// Streams InteractionChannelInvite records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamInteractionChannelInviteWithContext(ctx context.Context, InteractionSid string, ChannelSid string, params *ListInteractionChannelInviteParams) (chan FlexV1InteractionChannelInvite, chan error) { if params == nil { params = &ListInteractionChannelInviteParams{} } @@ -151,19 +170,19 @@ func (c *ApiService) StreamInteractionChannelInvite(InteractionSid string, Chann recordChannel := make(chan FlexV1InteractionChannelInvite, 1) errorChannel := make(chan error, 1) - response, err := c.PageInteractionChannelInvite(InteractionSid, ChannelSid, params, "", "") + response, err := c.PageInteractionChannelInviteWithContext(ctx, InteractionSid, ChannelSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamInteractionChannelInvite(response, params, recordChannel, errorChannel) + go c.streamInteractionChannelInviteWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamInteractionChannelInvite(response *ListInteractionChannelInviteResponse, params *ListInteractionChannelInviteParams, recordChannel chan FlexV1InteractionChannelInvite, errorChannel chan error) { +func (c *ApiService) streamInteractionChannelInviteWithContext(ctx context.Context, response *ListInteractionChannelInviteResponse, params *ListInteractionChannelInviteParams, recordChannel chan FlexV1InteractionChannelInvite, errorChannel chan error) { curRecord := 1 for response != nil { @@ -178,7 +197,7 @@ func (c *ApiService) streamInteractionChannelInvite(response *ListInteractionCha } } - record, err := client.GetNext(c.baseURL, response, c.getNextListInteractionChannelInviteResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListInteractionChannelInviteResponseWithContext) if err != nil { errorChannel <- err break @@ -193,11 +212,11 @@ func (c *ApiService) streamInteractionChannelInvite(response *ListInteractionCha close(errorChannel) } -func (c *ApiService) getNextListInteractionChannelInviteResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListInteractionChannelInviteResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/flex/v1/interactions_channels_participants.go b/rest/flex/v1/interactions_channels_participants.go index 1f4ed231f..aa7a7d7ca 100644 --- a/rest/flex/v1/interactions_channels_participants.go +++ b/rest/flex/v1/interactions_channels_participants.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -48,6 +49,9 @@ func (params *CreateInteractionChannelParticipantParams) SetRoutingProperties(Ro // Add a Participant to a Channel. func (c *ApiService) CreateInteractionChannelParticipant(InteractionSid string, ChannelSid string, params *CreateInteractionChannelParticipantParams) (*FlexV1InteractionChannelParticipant, error) { + return c.CreateInteractionChannelParticipantWithContext(context.TODO(), InteractionSid, ChannelSid, params) +} +func (c *ApiService) CreateInteractionChannelParticipantWithContext(ctx context.Context, InteractionSid string, ChannelSid string, params *CreateInteractionChannelParticipantParams) (*FlexV1InteractionChannelParticipant, error) { path := "/v1/Interactions/{InteractionSid}/Channels/{ChannelSid}/Participants" path = strings.Replace(path, "{"+"InteractionSid"+"}", InteractionSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -79,7 +83,7 @@ func (c *ApiService) CreateInteractionChannelParticipant(InteractionSid string, data.Set("RoutingProperties", string(v)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -113,6 +117,11 @@ func (params *ListInteractionChannelParticipantParams) SetLimit(Limit int) *List // Retrieve a single page of InteractionChannelParticipant records from the API. Request is executed immediately. func (c *ApiService) PageInteractionChannelParticipant(InteractionSid string, ChannelSid string, params *ListInteractionChannelParticipantParams, pageToken, pageNumber string) (*ListInteractionChannelParticipantResponse, error) { + return c.PageInteractionChannelParticipantWithContext(context.TODO(), InteractionSid, ChannelSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of InteractionChannelParticipant records from the API. Request is executed immediately. +func (c *ApiService) PageInteractionChannelParticipantWithContext(ctx context.Context, InteractionSid string, ChannelSid string, params *ListInteractionChannelParticipantParams, pageToken, pageNumber string) (*ListInteractionChannelParticipantResponse, error) { path := "/v1/Interactions/{InteractionSid}/Channels/{ChannelSid}/Participants" path = strings.Replace(path, "{"+"InteractionSid"+"}", InteractionSid, -1) @@ -134,7 +143,7 @@ func (c *ApiService) PageInteractionChannelParticipant(InteractionSid string, Ch data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -151,7 +160,12 @@ func (c *ApiService) PageInteractionChannelParticipant(InteractionSid string, Ch // Lists InteractionChannelParticipant records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListInteractionChannelParticipant(InteractionSid string, ChannelSid string, params *ListInteractionChannelParticipantParams) ([]FlexV1InteractionChannelParticipant, error) { - response, errors := c.StreamInteractionChannelParticipant(InteractionSid, ChannelSid, params) + return c.ListInteractionChannelParticipantWithContext(context.TODO(), InteractionSid, ChannelSid, params) +} + +// Lists InteractionChannelParticipant records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListInteractionChannelParticipantWithContext(ctx context.Context, InteractionSid string, ChannelSid string, params *ListInteractionChannelParticipantParams) ([]FlexV1InteractionChannelParticipant, error) { + response, errors := c.StreamInteractionChannelParticipantWithContext(ctx, InteractionSid, ChannelSid, params) records := make([]FlexV1InteractionChannelParticipant, 0) for record := range response { @@ -167,6 +181,11 @@ func (c *ApiService) ListInteractionChannelParticipant(InteractionSid string, Ch // Streams InteractionChannelParticipant records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamInteractionChannelParticipant(InteractionSid string, ChannelSid string, params *ListInteractionChannelParticipantParams) (chan FlexV1InteractionChannelParticipant, chan error) { + return c.StreamInteractionChannelParticipantWithContext(context.TODO(), InteractionSid, ChannelSid, params) +} + +// Streams InteractionChannelParticipant records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamInteractionChannelParticipantWithContext(ctx context.Context, InteractionSid string, ChannelSid string, params *ListInteractionChannelParticipantParams) (chan FlexV1InteractionChannelParticipant, chan error) { if params == nil { params = &ListInteractionChannelParticipantParams{} } @@ -175,19 +194,19 @@ func (c *ApiService) StreamInteractionChannelParticipant(InteractionSid string, recordChannel := make(chan FlexV1InteractionChannelParticipant, 1) errorChannel := make(chan error, 1) - response, err := c.PageInteractionChannelParticipant(InteractionSid, ChannelSid, params, "", "") + response, err := c.PageInteractionChannelParticipantWithContext(ctx, InteractionSid, ChannelSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamInteractionChannelParticipant(response, params, recordChannel, errorChannel) + go c.streamInteractionChannelParticipantWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamInteractionChannelParticipant(response *ListInteractionChannelParticipantResponse, params *ListInteractionChannelParticipantParams, recordChannel chan FlexV1InteractionChannelParticipant, errorChannel chan error) { +func (c *ApiService) streamInteractionChannelParticipantWithContext(ctx context.Context, response *ListInteractionChannelParticipantResponse, params *ListInteractionChannelParticipantParams, recordChannel chan FlexV1InteractionChannelParticipant, errorChannel chan error) { curRecord := 1 for response != nil { @@ -202,7 +221,7 @@ func (c *ApiService) streamInteractionChannelParticipant(response *ListInteracti } } - record, err := client.GetNext(c.baseURL, response, c.getNextListInteractionChannelParticipantResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListInteractionChannelParticipantResponseWithContext) if err != nil { errorChannel <- err break @@ -217,11 +236,11 @@ func (c *ApiService) streamInteractionChannelParticipant(response *ListInteracti close(errorChannel) } -func (c *ApiService) getNextListInteractionChannelParticipantResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListInteractionChannelParticipantResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -248,6 +267,9 @@ func (params *UpdateInteractionChannelParticipantParams) SetStatus(Status string // Update an existing Channel Participant. func (c *ApiService) UpdateInteractionChannelParticipant(InteractionSid string, ChannelSid string, Sid string, params *UpdateInteractionChannelParticipantParams) (*FlexV1InteractionChannelParticipant, error) { + return c.UpdateInteractionChannelParticipantWithContext(context.TODO(), InteractionSid, ChannelSid, Sid, params) +} +func (c *ApiService) UpdateInteractionChannelParticipantWithContext(ctx context.Context, InteractionSid string, ChannelSid string, Sid string, params *UpdateInteractionChannelParticipantParams) (*FlexV1InteractionChannelParticipant, error) { path := "/v1/Interactions/{InteractionSid}/Channels/{ChannelSid}/Participants/{Sid}" path = strings.Replace(path, "{"+"InteractionSid"+"}", InteractionSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -262,7 +284,7 @@ func (c *ApiService) UpdateInteractionChannelParticipant(InteractionSid string, data.Set("Status", fmt.Sprint(*params.Status)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/flex/v1/interactions_channels_transfers.go b/rest/flex/v1/interactions_channels_transfers.go index 8add8df31..63da8a47e 100644 --- a/rest/flex/v1/interactions_channels_transfers.go +++ b/rest/flex/v1/interactions_channels_transfers.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -33,6 +34,9 @@ func (params *CreateInteractionTransferParams) SetBody(Body map[string]interface // Create a new Transfer. func (c *ApiService) CreateInteractionTransfer(InteractionSid string, ChannelSid string, params *CreateInteractionTransferParams) (*FlexV1InteractionTransfer, error) { + return c.CreateInteractionTransferWithContext(context.TODO(), InteractionSid, ChannelSid, params) +} +func (c *ApiService) CreateInteractionTransferWithContext(ctx context.Context, InteractionSid string, ChannelSid string, params *CreateInteractionTransferParams) (*FlexV1InteractionTransfer, error) { path := "/v1/Interactions/{InteractionSid}/Channels/{ChannelSid}/Transfers" path = strings.Replace(path, "{"+"InteractionSid"+"}", InteractionSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -51,7 +55,7 @@ func (c *ApiService) CreateInteractionTransfer(InteractionSid string, ChannelSid body = b } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers, body...) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers, body...) if err != nil { return nil, err } @@ -68,6 +72,9 @@ func (c *ApiService) CreateInteractionTransfer(InteractionSid string, ChannelSid // Fetch a specific Transfer by SID. func (c *ApiService) FetchInteractionTransfer(InteractionSid string, ChannelSid string, Sid string) (*FlexV1InteractionTransfer, error) { + return c.FetchInteractionTransferWithContext(context.TODO(), InteractionSid, ChannelSid, Sid) +} +func (c *ApiService) FetchInteractionTransferWithContext(ctx context.Context, InteractionSid string, ChannelSid string, Sid string) (*FlexV1InteractionTransfer, error) { path := "/v1/Interactions/{InteractionSid}/Channels/{ChannelSid}/Transfers/{Sid}" path = strings.Replace(path, "{"+"InteractionSid"+"}", InteractionSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -78,7 +85,7 @@ func (c *ApiService) FetchInteractionTransfer(InteractionSid string, ChannelSid "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -106,6 +113,9 @@ func (params *UpdateInteractionTransferParams) SetBody(Body map[string]interface // Update an existing Transfer. func (c *ApiService) UpdateInteractionTransfer(InteractionSid string, ChannelSid string, Sid string, params *UpdateInteractionTransferParams) (*FlexV1InteractionTransfer, error) { + return c.UpdateInteractionTransferWithContext(context.TODO(), InteractionSid, ChannelSid, Sid, params) +} +func (c *ApiService) UpdateInteractionTransferWithContext(ctx context.Context, InteractionSid string, ChannelSid string, Sid string, params *UpdateInteractionTransferParams) (*FlexV1InteractionTransfer, error) { path := "/v1/Interactions/{InteractionSid}/Channels/{ChannelSid}/Transfers/{Sid}" path = strings.Replace(path, "{"+"InteractionSid"+"}", InteractionSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -125,7 +135,7 @@ func (c *ApiService) UpdateInteractionTransfer(InteractionSid string, ChannelSid body = b } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers, body...) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers, body...) if err != nil { return nil, err } diff --git a/rest/flex/v1/plugin_service_configurations.go b/rest/flex/v1/plugin_service_configurations.go index 5753985b0..7d5d434dd 100644 --- a/rest/flex/v1/plugin_service_configurations.go +++ b/rest/flex/v1/plugin_service_configurations.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -52,8 +53,10 @@ func (params *CreatePluginConfigurationParams) SetDescription(Description string return params } -// func (c *ApiService) CreatePluginConfiguration(params *CreatePluginConfigurationParams) (*FlexV1PluginConfiguration, error) { + return c.CreatePluginConfigurationWithContext(context.TODO(), params) +} +func (c *ApiService) CreatePluginConfigurationWithContext(ctx context.Context, params *CreatePluginConfigurationParams) (*FlexV1PluginConfiguration, error) { path := "/v1/PluginService/Configurations" data := url.Values{} @@ -82,7 +85,7 @@ func (c *ApiService) CreatePluginConfiguration(params *CreatePluginConfiguration if params != nil && params.FlexMetadata != nil { headers["Flex-Metadata"] = *params.FlexMetadata } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -108,8 +111,10 @@ func (params *FetchPluginConfigurationParams) SetFlexMetadata(FlexMetadata strin return params } -// func (c *ApiService) FetchPluginConfiguration(Sid string, params *FetchPluginConfigurationParams) (*FlexV1PluginConfiguration, error) { + return c.FetchPluginConfigurationWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) FetchPluginConfigurationWithContext(ctx context.Context, Sid string, params *FetchPluginConfigurationParams) (*FlexV1PluginConfiguration, error) { path := "/v1/PluginService/Configurations/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -121,7 +126,7 @@ func (c *ApiService) FetchPluginConfiguration(Sid string, params *FetchPluginCon if params != nil && params.FlexMetadata != nil { headers["Flex-Metadata"] = *params.FlexMetadata } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -161,6 +166,11 @@ func (params *ListPluginConfigurationParams) SetLimit(Limit int) *ListPluginConf // Retrieve a single page of PluginConfiguration records from the API. Request is executed immediately. func (c *ApiService) PagePluginConfiguration(params *ListPluginConfigurationParams, pageToken, pageNumber string) (*ListPluginConfigurationResponse, error) { + return c.PagePluginConfigurationWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of PluginConfiguration records from the API. Request is executed immediately. +func (c *ApiService) PagePluginConfigurationWithContext(ctx context.Context, params *ListPluginConfigurationParams, pageToken, pageNumber string) (*ListPluginConfigurationResponse, error) { path := "/v1/PluginService/Configurations" data := url.Values{} @@ -179,7 +189,7 @@ func (c *ApiService) PagePluginConfiguration(params *ListPluginConfigurationPara data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -196,7 +206,12 @@ func (c *ApiService) PagePluginConfiguration(params *ListPluginConfigurationPara // Lists PluginConfiguration records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListPluginConfiguration(params *ListPluginConfigurationParams) ([]FlexV1PluginConfiguration, error) { - response, errors := c.StreamPluginConfiguration(params) + return c.ListPluginConfigurationWithContext(context.TODO(), params) +} + +// Lists PluginConfiguration records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListPluginConfigurationWithContext(ctx context.Context, params *ListPluginConfigurationParams) ([]FlexV1PluginConfiguration, error) { + response, errors := c.StreamPluginConfigurationWithContext(ctx, params) records := make([]FlexV1PluginConfiguration, 0) for record := range response { @@ -212,6 +227,11 @@ func (c *ApiService) ListPluginConfiguration(params *ListPluginConfigurationPara // Streams PluginConfiguration records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamPluginConfiguration(params *ListPluginConfigurationParams) (chan FlexV1PluginConfiguration, chan error) { + return c.StreamPluginConfigurationWithContext(context.TODO(), params) +} + +// Streams PluginConfiguration records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamPluginConfigurationWithContext(ctx context.Context, params *ListPluginConfigurationParams) (chan FlexV1PluginConfiguration, chan error) { if params == nil { params = &ListPluginConfigurationParams{} } @@ -220,19 +240,19 @@ func (c *ApiService) StreamPluginConfiguration(params *ListPluginConfigurationPa recordChannel := make(chan FlexV1PluginConfiguration, 1) errorChannel := make(chan error, 1) - response, err := c.PagePluginConfiguration(params, "", "") + response, err := c.PagePluginConfigurationWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamPluginConfiguration(response, params, recordChannel, errorChannel) + go c.streamPluginConfigurationWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamPluginConfiguration(response *ListPluginConfigurationResponse, params *ListPluginConfigurationParams, recordChannel chan FlexV1PluginConfiguration, errorChannel chan error) { +func (c *ApiService) streamPluginConfigurationWithContext(ctx context.Context, response *ListPluginConfigurationResponse, params *ListPluginConfigurationParams, recordChannel chan FlexV1PluginConfiguration, errorChannel chan error) { curRecord := 1 for response != nil { @@ -247,7 +267,7 @@ func (c *ApiService) streamPluginConfiguration(response *ListPluginConfiguration } } - record, err := client.GetNext(c.baseURL, response, c.getNextListPluginConfigurationResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListPluginConfigurationResponseWithContext) if err != nil { errorChannel <- err break @@ -262,11 +282,11 @@ func (c *ApiService) streamPluginConfiguration(response *ListPluginConfiguration close(errorChannel) } -func (c *ApiService) getNextListPluginConfigurationResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListPluginConfigurationResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/flex/v1/plugin_service_configurations_archive.go b/rest/flex/v1/plugin_service_configurations_archive.go index ae9f331a8..ea0c3f9c1 100644 --- a/rest/flex/v1/plugin_service_configurations_archive.go +++ b/rest/flex/v1/plugin_service_configurations_archive.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -31,8 +32,10 @@ func (params *UpdatePluginConfigurationArchiveParams) SetFlexMetadata(FlexMetada return params } -// func (c *ApiService) UpdatePluginConfigurationArchive(Sid string, params *UpdatePluginConfigurationArchiveParams) (*FlexV1PluginConfigurationArchive, error) { + return c.UpdatePluginConfigurationArchiveWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdatePluginConfigurationArchiveWithContext(ctx context.Context, Sid string, params *UpdatePluginConfigurationArchiveParams) (*FlexV1PluginConfigurationArchive, error) { path := "/v1/PluginService/Configurations/{Sid}/Archive" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -44,7 +47,7 @@ func (c *ApiService) UpdatePluginConfigurationArchive(Sid string, params *Update if params != nil && params.FlexMetadata != nil { headers["Flex-Metadata"] = *params.FlexMetadata } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/flex/v1/plugin_service_configurations_plugins.go b/rest/flex/v1/plugin_service_configurations_plugins.go index 248e1b21c..41b8be346 100644 --- a/rest/flex/v1/plugin_service_configurations_plugins.go +++ b/rest/flex/v1/plugin_service_configurations_plugins.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -34,8 +35,10 @@ func (params *FetchConfiguredPluginParams) SetFlexMetadata(FlexMetadata string) return params } -// func (c *ApiService) FetchConfiguredPlugin(ConfigurationSid string, PluginSid string, params *FetchConfiguredPluginParams) (*FlexV1ConfiguredPlugin, error) { + return c.FetchConfiguredPluginWithContext(context.TODO(), ConfigurationSid, PluginSid, params) +} +func (c *ApiService) FetchConfiguredPluginWithContext(ctx context.Context, ConfigurationSid string, PluginSid string, params *FetchConfiguredPluginParams) (*FlexV1ConfiguredPlugin, error) { path := "/v1/PluginService/Configurations/{ConfigurationSid}/Plugins/{PluginSid}" path = strings.Replace(path, "{"+"ConfigurationSid"+"}", ConfigurationSid, -1) path = strings.Replace(path, "{"+"PluginSid"+"}", PluginSid, -1) @@ -48,7 +51,7 @@ func (c *ApiService) FetchConfiguredPlugin(ConfigurationSid string, PluginSid st if params != nil && params.FlexMetadata != nil { headers["Flex-Metadata"] = *params.FlexMetadata } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -88,6 +91,11 @@ func (params *ListConfiguredPluginParams) SetLimit(Limit int) *ListConfiguredPlu // Retrieve a single page of ConfiguredPlugin records from the API. Request is executed immediately. func (c *ApiService) PageConfiguredPlugin(ConfigurationSid string, params *ListConfiguredPluginParams, pageToken, pageNumber string) (*ListConfiguredPluginResponse, error) { + return c.PageConfiguredPluginWithContext(context.TODO(), ConfigurationSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ConfiguredPlugin records from the API. Request is executed immediately. +func (c *ApiService) PageConfiguredPluginWithContext(ctx context.Context, ConfigurationSid string, params *ListConfiguredPluginParams, pageToken, pageNumber string) (*ListConfiguredPluginResponse, error) { path := "/v1/PluginService/Configurations/{ConfigurationSid}/Plugins" path = strings.Replace(path, "{"+"ConfigurationSid"+"}", ConfigurationSid, -1) @@ -108,7 +116,7 @@ func (c *ApiService) PageConfiguredPlugin(ConfigurationSid string, params *ListC data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -125,7 +133,12 @@ func (c *ApiService) PageConfiguredPlugin(ConfigurationSid string, params *ListC // Lists ConfiguredPlugin records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListConfiguredPlugin(ConfigurationSid string, params *ListConfiguredPluginParams) ([]FlexV1ConfiguredPlugin, error) { - response, errors := c.StreamConfiguredPlugin(ConfigurationSid, params) + return c.ListConfiguredPluginWithContext(context.TODO(), ConfigurationSid, params) +} + +// Lists ConfiguredPlugin records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListConfiguredPluginWithContext(ctx context.Context, ConfigurationSid string, params *ListConfiguredPluginParams) ([]FlexV1ConfiguredPlugin, error) { + response, errors := c.StreamConfiguredPluginWithContext(ctx, ConfigurationSid, params) records := make([]FlexV1ConfiguredPlugin, 0) for record := range response { @@ -141,6 +154,11 @@ func (c *ApiService) ListConfiguredPlugin(ConfigurationSid string, params *ListC // Streams ConfiguredPlugin records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamConfiguredPlugin(ConfigurationSid string, params *ListConfiguredPluginParams) (chan FlexV1ConfiguredPlugin, chan error) { + return c.StreamConfiguredPluginWithContext(context.TODO(), ConfigurationSid, params) +} + +// Streams ConfiguredPlugin records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamConfiguredPluginWithContext(ctx context.Context, ConfigurationSid string, params *ListConfiguredPluginParams) (chan FlexV1ConfiguredPlugin, chan error) { if params == nil { params = &ListConfiguredPluginParams{} } @@ -149,19 +167,19 @@ func (c *ApiService) StreamConfiguredPlugin(ConfigurationSid string, params *Lis recordChannel := make(chan FlexV1ConfiguredPlugin, 1) errorChannel := make(chan error, 1) - response, err := c.PageConfiguredPlugin(ConfigurationSid, params, "", "") + response, err := c.PageConfiguredPluginWithContext(ctx, ConfigurationSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamConfiguredPlugin(response, params, recordChannel, errorChannel) + go c.streamConfiguredPluginWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamConfiguredPlugin(response *ListConfiguredPluginResponse, params *ListConfiguredPluginParams, recordChannel chan FlexV1ConfiguredPlugin, errorChannel chan error) { +func (c *ApiService) streamConfiguredPluginWithContext(ctx context.Context, response *ListConfiguredPluginResponse, params *ListConfiguredPluginParams, recordChannel chan FlexV1ConfiguredPlugin, errorChannel chan error) { curRecord := 1 for response != nil { @@ -176,7 +194,7 @@ func (c *ApiService) streamConfiguredPlugin(response *ListConfiguredPluginRespon } } - record, err := client.GetNext(c.baseURL, response, c.getNextListConfiguredPluginResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListConfiguredPluginResponseWithContext) if err != nil { errorChannel <- err break @@ -191,11 +209,11 @@ func (c *ApiService) streamConfiguredPlugin(response *ListConfiguredPluginRespon close(errorChannel) } -func (c *ApiService) getNextListConfiguredPluginResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListConfiguredPluginResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/flex/v1/plugin_service_plugins.go b/rest/flex/v1/plugin_service_plugins.go index e42ab3347..65e4019bc 100644 --- a/rest/flex/v1/plugin_service_plugins.go +++ b/rest/flex/v1/plugin_service_plugins.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -52,8 +53,10 @@ func (params *CreatePluginParams) SetDescription(Description string) *CreatePlug return params } -// func (c *ApiService) CreatePlugin(params *CreatePluginParams) (*FlexV1Plugin, error) { + return c.CreatePluginWithContext(context.TODO(), params) +} +func (c *ApiService) CreatePluginWithContext(ctx context.Context, params *CreatePluginParams) (*FlexV1Plugin, error) { path := "/v1/PluginService/Plugins" data := url.Values{} @@ -74,7 +77,7 @@ func (c *ApiService) CreatePlugin(params *CreatePluginParams) (*FlexV1Plugin, er if params != nil && params.FlexMetadata != nil { headers["Flex-Metadata"] = *params.FlexMetadata } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -100,8 +103,10 @@ func (params *FetchPluginParams) SetFlexMetadata(FlexMetadata string) *FetchPlug return params } -// func (c *ApiService) FetchPlugin(Sid string, params *FetchPluginParams) (*FlexV1Plugin, error) { + return c.FetchPluginWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) FetchPluginWithContext(ctx context.Context, Sid string, params *FetchPluginParams) (*FlexV1Plugin, error) { path := "/v1/PluginService/Plugins/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -113,7 +118,7 @@ func (c *ApiService) FetchPlugin(Sid string, params *FetchPluginParams) (*FlexV1 if params != nil && params.FlexMetadata != nil { headers["Flex-Metadata"] = *params.FlexMetadata } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -153,6 +158,11 @@ func (params *ListPluginParams) SetLimit(Limit int) *ListPluginParams { // Retrieve a single page of Plugin records from the API. Request is executed immediately. func (c *ApiService) PagePlugin(params *ListPluginParams, pageToken, pageNumber string) (*ListPluginResponse, error) { + return c.PagePluginWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Plugin records from the API. Request is executed immediately. +func (c *ApiService) PagePluginWithContext(ctx context.Context, params *ListPluginParams, pageToken, pageNumber string) (*ListPluginResponse, error) { path := "/v1/PluginService/Plugins" data := url.Values{} @@ -171,7 +181,7 @@ func (c *ApiService) PagePlugin(params *ListPluginParams, pageToken, pageNumber data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -188,7 +198,12 @@ func (c *ApiService) PagePlugin(params *ListPluginParams, pageToken, pageNumber // Lists Plugin records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListPlugin(params *ListPluginParams) ([]FlexV1Plugin, error) { - response, errors := c.StreamPlugin(params) + return c.ListPluginWithContext(context.TODO(), params) +} + +// Lists Plugin records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListPluginWithContext(ctx context.Context, params *ListPluginParams) ([]FlexV1Plugin, error) { + response, errors := c.StreamPluginWithContext(ctx, params) records := make([]FlexV1Plugin, 0) for record := range response { @@ -204,6 +219,11 @@ func (c *ApiService) ListPlugin(params *ListPluginParams) ([]FlexV1Plugin, error // Streams Plugin records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamPlugin(params *ListPluginParams) (chan FlexV1Plugin, chan error) { + return c.StreamPluginWithContext(context.TODO(), params) +} + +// Streams Plugin records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamPluginWithContext(ctx context.Context, params *ListPluginParams) (chan FlexV1Plugin, chan error) { if params == nil { params = &ListPluginParams{} } @@ -212,19 +232,19 @@ func (c *ApiService) StreamPlugin(params *ListPluginParams) (chan FlexV1Plugin, recordChannel := make(chan FlexV1Plugin, 1) errorChannel := make(chan error, 1) - response, err := c.PagePlugin(params, "", "") + response, err := c.PagePluginWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamPlugin(response, params, recordChannel, errorChannel) + go c.streamPluginWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamPlugin(response *ListPluginResponse, params *ListPluginParams, recordChannel chan FlexV1Plugin, errorChannel chan error) { +func (c *ApiService) streamPluginWithContext(ctx context.Context, response *ListPluginResponse, params *ListPluginParams, recordChannel chan FlexV1Plugin, errorChannel chan error) { curRecord := 1 for response != nil { @@ -239,7 +259,7 @@ func (c *ApiService) streamPlugin(response *ListPluginResponse, params *ListPlug } } - record, err := client.GetNext(c.baseURL, response, c.getNextListPluginResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListPluginResponseWithContext) if err != nil { errorChannel <- err break @@ -254,11 +274,11 @@ func (c *ApiService) streamPlugin(response *ListPluginResponse, params *ListPlug close(errorChannel) } -func (c *ApiService) getNextListPluginResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListPluginResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -295,8 +315,10 @@ func (params *UpdatePluginParams) SetDescription(Description string) *UpdatePlug return params } -// func (c *ApiService) UpdatePlugin(Sid string, params *UpdatePluginParams) (*FlexV1Plugin, error) { + return c.UpdatePluginWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdatePluginWithContext(ctx context.Context, Sid string, params *UpdatePluginParams) (*FlexV1Plugin, error) { path := "/v1/PluginService/Plugins/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -315,7 +337,7 @@ func (c *ApiService) UpdatePlugin(Sid string, params *UpdatePluginParams) (*Flex if params != nil && params.FlexMetadata != nil { headers["Flex-Metadata"] = *params.FlexMetadata } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/flex/v1/plugin_service_plugins_archive.go b/rest/flex/v1/plugin_service_plugins_archive.go index cf5df8406..af6808623 100644 --- a/rest/flex/v1/plugin_service_plugins_archive.go +++ b/rest/flex/v1/plugin_service_plugins_archive.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -31,8 +32,10 @@ func (params *UpdatePluginArchiveParams) SetFlexMetadata(FlexMetadata string) *U return params } -// func (c *ApiService) UpdatePluginArchive(Sid string, params *UpdatePluginArchiveParams) (*FlexV1PluginArchive, error) { + return c.UpdatePluginArchiveWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdatePluginArchiveWithContext(ctx context.Context, Sid string, params *UpdatePluginArchiveParams) (*FlexV1PluginArchive, error) { path := "/v1/PluginService/Plugins/{Sid}/Archive" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -44,7 +47,7 @@ func (c *ApiService) UpdatePluginArchive(Sid string, params *UpdatePluginArchive if params != nil && params.FlexMetadata != nil { headers["Flex-Metadata"] = *params.FlexMetadata } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/flex/v1/plugin_service_plugins_versions.go b/rest/flex/v1/plugin_service_plugins_versions.go index 59cee1fb5..b05fb8c90 100644 --- a/rest/flex/v1/plugin_service_plugins_versions.go +++ b/rest/flex/v1/plugin_service_plugins_versions.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -70,8 +71,10 @@ func (params *CreatePluginVersionParams) SetValidateStatus(ValidateStatus string return params } -// func (c *ApiService) CreatePluginVersion(PluginSid string, params *CreatePluginVersionParams) (*FlexV1PluginVersion, error) { + return c.CreatePluginVersionWithContext(context.TODO(), PluginSid, params) +} +func (c *ApiService) CreatePluginVersionWithContext(ctx context.Context, PluginSid string, params *CreatePluginVersionParams) (*FlexV1PluginVersion, error) { path := "/v1/PluginService/Plugins/{PluginSid}/Versions" path = strings.Replace(path, "{"+"PluginSid"+"}", PluginSid, -1) @@ -102,7 +105,7 @@ func (c *ApiService) CreatePluginVersion(PluginSid string, params *CreatePluginV if params != nil && params.FlexMetadata != nil { headers["Flex-Metadata"] = *params.FlexMetadata } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -128,8 +131,10 @@ func (params *FetchPluginVersionParams) SetFlexMetadata(FlexMetadata string) *Fe return params } -// func (c *ApiService) FetchPluginVersion(PluginSid string, Sid string, params *FetchPluginVersionParams) (*FlexV1PluginVersion, error) { + return c.FetchPluginVersionWithContext(context.TODO(), PluginSid, Sid, params) +} +func (c *ApiService) FetchPluginVersionWithContext(ctx context.Context, PluginSid string, Sid string, params *FetchPluginVersionParams) (*FlexV1PluginVersion, error) { path := "/v1/PluginService/Plugins/{PluginSid}/Versions/{Sid}" path = strings.Replace(path, "{"+"PluginSid"+"}", PluginSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -142,7 +147,7 @@ func (c *ApiService) FetchPluginVersion(PluginSid string, Sid string, params *Fe if params != nil && params.FlexMetadata != nil { headers["Flex-Metadata"] = *params.FlexMetadata } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -182,6 +187,11 @@ func (params *ListPluginVersionParams) SetLimit(Limit int) *ListPluginVersionPar // Retrieve a single page of PluginVersion records from the API. Request is executed immediately. func (c *ApiService) PagePluginVersion(PluginSid string, params *ListPluginVersionParams, pageToken, pageNumber string) (*ListPluginVersionResponse, error) { + return c.PagePluginVersionWithContext(context.TODO(), PluginSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of PluginVersion records from the API. Request is executed immediately. +func (c *ApiService) PagePluginVersionWithContext(ctx context.Context, PluginSid string, params *ListPluginVersionParams, pageToken, pageNumber string) (*ListPluginVersionResponse, error) { path := "/v1/PluginService/Plugins/{PluginSid}/Versions" path = strings.Replace(path, "{"+"PluginSid"+"}", PluginSid, -1) @@ -202,7 +212,7 @@ func (c *ApiService) PagePluginVersion(PluginSid string, params *ListPluginVersi data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -219,7 +229,12 @@ func (c *ApiService) PagePluginVersion(PluginSid string, params *ListPluginVersi // Lists PluginVersion records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListPluginVersion(PluginSid string, params *ListPluginVersionParams) ([]FlexV1PluginVersion, error) { - response, errors := c.StreamPluginVersion(PluginSid, params) + return c.ListPluginVersionWithContext(context.TODO(), PluginSid, params) +} + +// Lists PluginVersion records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListPluginVersionWithContext(ctx context.Context, PluginSid string, params *ListPluginVersionParams) ([]FlexV1PluginVersion, error) { + response, errors := c.StreamPluginVersionWithContext(ctx, PluginSid, params) records := make([]FlexV1PluginVersion, 0) for record := range response { @@ -235,6 +250,11 @@ func (c *ApiService) ListPluginVersion(PluginSid string, params *ListPluginVersi // Streams PluginVersion records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamPluginVersion(PluginSid string, params *ListPluginVersionParams) (chan FlexV1PluginVersion, chan error) { + return c.StreamPluginVersionWithContext(context.TODO(), PluginSid, params) +} + +// Streams PluginVersion records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamPluginVersionWithContext(ctx context.Context, PluginSid string, params *ListPluginVersionParams) (chan FlexV1PluginVersion, chan error) { if params == nil { params = &ListPluginVersionParams{} } @@ -243,19 +263,19 @@ func (c *ApiService) StreamPluginVersion(PluginSid string, params *ListPluginVer recordChannel := make(chan FlexV1PluginVersion, 1) errorChannel := make(chan error, 1) - response, err := c.PagePluginVersion(PluginSid, params, "", "") + response, err := c.PagePluginVersionWithContext(ctx, PluginSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamPluginVersion(response, params, recordChannel, errorChannel) + go c.streamPluginVersionWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamPluginVersion(response *ListPluginVersionResponse, params *ListPluginVersionParams, recordChannel chan FlexV1PluginVersion, errorChannel chan error) { +func (c *ApiService) streamPluginVersionWithContext(ctx context.Context, response *ListPluginVersionResponse, params *ListPluginVersionParams, recordChannel chan FlexV1PluginVersion, errorChannel chan error) { curRecord := 1 for response != nil { @@ -270,7 +290,7 @@ func (c *ApiService) streamPluginVersion(response *ListPluginVersionResponse, pa } } - record, err := client.GetNext(c.baseURL, response, c.getNextListPluginVersionResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListPluginVersionResponseWithContext) if err != nil { errorChannel <- err break @@ -285,11 +305,11 @@ func (c *ApiService) streamPluginVersion(response *ListPluginVersionResponse, pa close(errorChannel) } -func (c *ApiService) getNextListPluginVersionResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListPluginVersionResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/flex/v1/plugin_service_plugins_versions_archive.go b/rest/flex/v1/plugin_service_plugins_versions_archive.go index e20cd02d0..f5ef7df0c 100644 --- a/rest/flex/v1/plugin_service_plugins_versions_archive.go +++ b/rest/flex/v1/plugin_service_plugins_versions_archive.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -31,8 +32,10 @@ func (params *UpdatePluginVersionArchiveParams) SetFlexMetadata(FlexMetadata str return params } -// func (c *ApiService) UpdatePluginVersionArchive(PluginSid string, Sid string, params *UpdatePluginVersionArchiveParams) (*FlexV1PluginVersionArchive, error) { + return c.UpdatePluginVersionArchiveWithContext(context.TODO(), PluginSid, Sid, params) +} +func (c *ApiService) UpdatePluginVersionArchiveWithContext(ctx context.Context, PluginSid string, Sid string, params *UpdatePluginVersionArchiveParams) (*FlexV1PluginVersionArchive, error) { path := "/v1/PluginService/Plugins/{PluginSid}/Versions/{Sid}/Archive" path = strings.Replace(path, "{"+"PluginSid"+"}", PluginSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -45,7 +48,7 @@ func (c *ApiService) UpdatePluginVersionArchive(PluginSid string, Sid string, pa if params != nil && params.FlexMetadata != nil { headers["Flex-Metadata"] = *params.FlexMetadata } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/flex/v1/plugin_service_releases.go b/rest/flex/v1/plugin_service_releases.go index f0695572c..a068fd7c8 100644 --- a/rest/flex/v1/plugin_service_releases.go +++ b/rest/flex/v1/plugin_service_releases.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -40,8 +41,10 @@ func (params *CreatePluginReleaseParams) SetConfigurationId(ConfigurationId stri return params } -// func (c *ApiService) CreatePluginRelease(params *CreatePluginReleaseParams) (*FlexV1PluginRelease, error) { + return c.CreatePluginReleaseWithContext(context.TODO(), params) +} +func (c *ApiService) CreatePluginReleaseWithContext(ctx context.Context, params *CreatePluginReleaseParams) (*FlexV1PluginRelease, error) { path := "/v1/PluginService/Releases" data := url.Values{} @@ -56,7 +59,7 @@ func (c *ApiService) CreatePluginRelease(params *CreatePluginReleaseParams) (*Fl if params != nil && params.FlexMetadata != nil { headers["Flex-Metadata"] = *params.FlexMetadata } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -82,8 +85,10 @@ func (params *FetchPluginReleaseParams) SetFlexMetadata(FlexMetadata string) *Fe return params } -// func (c *ApiService) FetchPluginRelease(Sid string, params *FetchPluginReleaseParams) (*FlexV1PluginRelease, error) { + return c.FetchPluginReleaseWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) FetchPluginReleaseWithContext(ctx context.Context, Sid string, params *FetchPluginReleaseParams) (*FlexV1PluginRelease, error) { path := "/v1/PluginService/Releases/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -95,7 +100,7 @@ func (c *ApiService) FetchPluginRelease(Sid string, params *FetchPluginReleasePa if params != nil && params.FlexMetadata != nil { headers["Flex-Metadata"] = *params.FlexMetadata } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -135,6 +140,11 @@ func (params *ListPluginReleaseParams) SetLimit(Limit int) *ListPluginReleasePar // Retrieve a single page of PluginRelease records from the API. Request is executed immediately. func (c *ApiService) PagePluginRelease(params *ListPluginReleaseParams, pageToken, pageNumber string) (*ListPluginReleaseResponse, error) { + return c.PagePluginReleaseWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of PluginRelease records from the API. Request is executed immediately. +func (c *ApiService) PagePluginReleaseWithContext(ctx context.Context, params *ListPluginReleaseParams, pageToken, pageNumber string) (*ListPluginReleaseResponse, error) { path := "/v1/PluginService/Releases" data := url.Values{} @@ -153,7 +163,7 @@ func (c *ApiService) PagePluginRelease(params *ListPluginReleaseParams, pageToke data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -170,7 +180,12 @@ func (c *ApiService) PagePluginRelease(params *ListPluginReleaseParams, pageToke // Lists PluginRelease records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListPluginRelease(params *ListPluginReleaseParams) ([]FlexV1PluginRelease, error) { - response, errors := c.StreamPluginRelease(params) + return c.ListPluginReleaseWithContext(context.TODO(), params) +} + +// Lists PluginRelease records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListPluginReleaseWithContext(ctx context.Context, params *ListPluginReleaseParams) ([]FlexV1PluginRelease, error) { + response, errors := c.StreamPluginReleaseWithContext(ctx, params) records := make([]FlexV1PluginRelease, 0) for record := range response { @@ -186,6 +201,11 @@ func (c *ApiService) ListPluginRelease(params *ListPluginReleaseParams) ([]FlexV // Streams PluginRelease records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamPluginRelease(params *ListPluginReleaseParams) (chan FlexV1PluginRelease, chan error) { + return c.StreamPluginReleaseWithContext(context.TODO(), params) +} + +// Streams PluginRelease records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamPluginReleaseWithContext(ctx context.Context, params *ListPluginReleaseParams) (chan FlexV1PluginRelease, chan error) { if params == nil { params = &ListPluginReleaseParams{} } @@ -194,19 +214,19 @@ func (c *ApiService) StreamPluginRelease(params *ListPluginReleaseParams) (chan recordChannel := make(chan FlexV1PluginRelease, 1) errorChannel := make(chan error, 1) - response, err := c.PagePluginRelease(params, "", "") + response, err := c.PagePluginReleaseWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamPluginRelease(response, params, recordChannel, errorChannel) + go c.streamPluginReleaseWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamPluginRelease(response *ListPluginReleaseResponse, params *ListPluginReleaseParams, recordChannel chan FlexV1PluginRelease, errorChannel chan error) { +func (c *ApiService) streamPluginReleaseWithContext(ctx context.Context, response *ListPluginReleaseResponse, params *ListPluginReleaseParams, recordChannel chan FlexV1PluginRelease, errorChannel chan error) { curRecord := 1 for response != nil { @@ -221,7 +241,7 @@ func (c *ApiService) streamPluginRelease(response *ListPluginReleaseResponse, pa } } - record, err := client.GetNext(c.baseURL, response, c.getNextListPluginReleaseResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListPluginReleaseResponseWithContext) if err != nil { errorChannel <- err break @@ -236,11 +256,11 @@ func (c *ApiService) streamPluginRelease(response *ListPluginReleaseResponse, pa close(errorChannel) } -func (c *ApiService) getNextListPluginReleaseResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListPluginReleaseResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/flex/v1/web_channels.go b/rest/flex/v1/web_channels.go index f0dae35a4..bd10980e9 100644 --- a/rest/flex/v1/web_channels.go +++ b/rest/flex/v1/web_channels.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -64,8 +65,10 @@ func (params *CreateWebChannelParams) SetPreEngagementData(PreEngagementData str return params } -// func (c *ApiService) CreateWebChannel(params *CreateWebChannelParams) (*FlexV1WebChannel, error) { + return c.CreateWebChannelWithContext(context.TODO(), params) +} +func (c *ApiService) CreateWebChannelWithContext(ctx context.Context, params *CreateWebChannelParams) (*FlexV1WebChannel, error) { path := "/v1/WebChannels" data := url.Values{} @@ -92,7 +95,7 @@ func (c *ApiService) CreateWebChannel(params *CreateWebChannelParams) (*FlexV1We data.Set("PreEngagementData", *params.PreEngagementData) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -107,8 +110,10 @@ func (c *ApiService) CreateWebChannel(params *CreateWebChannelParams) (*FlexV1We return ps, err } -// func (c *ApiService) DeleteWebChannel(Sid string) error { + return c.DeleteWebChannelWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteWebChannelWithContext(ctx context.Context, Sid string) error { path := "/v1/WebChannels/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -117,7 +122,7 @@ func (c *ApiService) DeleteWebChannel(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -127,8 +132,10 @@ func (c *ApiService) DeleteWebChannel(Sid string) error { return nil } -// func (c *ApiService) FetchWebChannel(Sid string) (*FlexV1WebChannel, error) { + return c.FetchWebChannelWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchWebChannelWithContext(ctx context.Context, Sid string) (*FlexV1WebChannel, error) { path := "/v1/WebChannels/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -137,7 +144,7 @@ func (c *ApiService) FetchWebChannel(Sid string) (*FlexV1WebChannel, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -171,6 +178,11 @@ func (params *ListWebChannelParams) SetLimit(Limit int) *ListWebChannelParams { // Retrieve a single page of WebChannel records from the API. Request is executed immediately. func (c *ApiService) PageWebChannel(params *ListWebChannelParams, pageToken, pageNumber string) (*ListWebChannelResponse, error) { + return c.PageWebChannelWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of WebChannel records from the API. Request is executed immediately. +func (c *ApiService) PageWebChannelWithContext(ctx context.Context, params *ListWebChannelParams, pageToken, pageNumber string) (*ListWebChannelResponse, error) { path := "/v1/WebChannels" data := url.Values{} @@ -189,7 +201,7 @@ func (c *ApiService) PageWebChannel(params *ListWebChannelParams, pageToken, pag data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -206,7 +218,12 @@ func (c *ApiService) PageWebChannel(params *ListWebChannelParams, pageToken, pag // Lists WebChannel records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListWebChannel(params *ListWebChannelParams) ([]FlexV1WebChannel, error) { - response, errors := c.StreamWebChannel(params) + return c.ListWebChannelWithContext(context.TODO(), params) +} + +// Lists WebChannel records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListWebChannelWithContext(ctx context.Context, params *ListWebChannelParams) ([]FlexV1WebChannel, error) { + response, errors := c.StreamWebChannelWithContext(ctx, params) records := make([]FlexV1WebChannel, 0) for record := range response { @@ -222,6 +239,11 @@ func (c *ApiService) ListWebChannel(params *ListWebChannelParams) ([]FlexV1WebCh // Streams WebChannel records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamWebChannel(params *ListWebChannelParams) (chan FlexV1WebChannel, chan error) { + return c.StreamWebChannelWithContext(context.TODO(), params) +} + +// Streams WebChannel records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamWebChannelWithContext(ctx context.Context, params *ListWebChannelParams) (chan FlexV1WebChannel, chan error) { if params == nil { params = &ListWebChannelParams{} } @@ -230,19 +252,19 @@ func (c *ApiService) StreamWebChannel(params *ListWebChannelParams) (chan FlexV1 recordChannel := make(chan FlexV1WebChannel, 1) errorChannel := make(chan error, 1) - response, err := c.PageWebChannel(params, "", "") + response, err := c.PageWebChannelWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamWebChannel(response, params, recordChannel, errorChannel) + go c.streamWebChannelWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamWebChannel(response *ListWebChannelResponse, params *ListWebChannelParams, recordChannel chan FlexV1WebChannel, errorChannel chan error) { +func (c *ApiService) streamWebChannelWithContext(ctx context.Context, response *ListWebChannelResponse, params *ListWebChannelParams, recordChannel chan FlexV1WebChannel, errorChannel chan error) { curRecord := 1 for response != nil { @@ -257,7 +279,7 @@ func (c *ApiService) streamWebChannel(response *ListWebChannelResponse, params * } } - record, err := client.GetNext(c.baseURL, response, c.getNextListWebChannelResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListWebChannelResponseWithContext) if err != nil { errorChannel <- err break @@ -272,11 +294,11 @@ func (c *ApiService) streamWebChannel(response *ListWebChannelResponse, params * close(errorChannel) } -func (c *ApiService) getNextListWebChannelResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListWebChannelResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -307,8 +329,10 @@ func (params *UpdateWebChannelParams) SetPostEngagementData(PostEngagementData s return params } -// func (c *ApiService) UpdateWebChannel(Sid string, params *UpdateWebChannelParams) (*FlexV1WebChannel, error) { + return c.UpdateWebChannelWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateWebChannelWithContext(ctx context.Context, Sid string, params *UpdateWebChannelParams) (*FlexV1WebChannel, error) { path := "/v1/WebChannels/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -324,7 +348,7 @@ func (c *ApiService) UpdateWebChannel(Sid string, params *UpdateWebChannelParams data.Set("PostEngagementData", *params.PostEngagementData) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/flex/v2/api_service.go b/rest/flex/v2/api_service.go index b27a8c40a..0fc8478b1 100644 --- a/rest/flex/v2/api_service.go +++ b/rest/flex/v2/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://flex-api.twilio.com", + } +} diff --git a/rest/flex/v2/instances_users.go b/rest/flex/v2/instances_users.go index fa0251704..a91b1527d 100644 --- a/rest/flex/v2/instances_users.go +++ b/rest/flex/v2/instances_users.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -22,6 +23,9 @@ import ( // Fetch flex user for the given flex user sid func (c *ApiService) FetchFlexUser(InstanceSid string, FlexUserSid string) (*FlexV2FlexUser, error) { + return c.FetchFlexUserWithContext(context.TODO(), InstanceSid, FlexUserSid) +} +func (c *ApiService) FetchFlexUserWithContext(ctx context.Context, InstanceSid string, FlexUserSid string) (*FlexV2FlexUser, error) { path := "/v2/Instances/{InstanceSid}/Users/{FlexUserSid}" path = strings.Replace(path, "{"+"InstanceSid"+"}", InstanceSid, -1) path = strings.Replace(path, "{"+"FlexUserSid"+"}", FlexUserSid, -1) @@ -31,7 +35,7 @@ func (c *ApiService) FetchFlexUser(InstanceSid string, FlexUserSid string) (*Fle "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -71,6 +75,9 @@ func (params *UpdateFlexUserParams) SetLocale(Locale string) *UpdateFlexUserPara // Update flex user for the given flex user sid func (c *ApiService) UpdateFlexUser(InstanceSid string, FlexUserSid string, params *UpdateFlexUserParams) (*FlexV2FlexUser, error) { + return c.UpdateFlexUserWithContext(context.TODO(), InstanceSid, FlexUserSid, params) +} +func (c *ApiService) UpdateFlexUserWithContext(ctx context.Context, InstanceSid string, FlexUserSid string, params *UpdateFlexUserParams) (*FlexV2FlexUser, error) { path := "/v2/Instances/{InstanceSid}/Users/{FlexUserSid}" path = strings.Replace(path, "{"+"InstanceSid"+"}", InstanceSid, -1) path = strings.Replace(path, "{"+"FlexUserSid"+"}", FlexUserSid, -1) @@ -90,7 +97,7 @@ func (c *ApiService) UpdateFlexUser(InstanceSid string, FlexUserSid string, para data.Set("Locale", *params.Locale) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/flex/v2/web_chats.go b/rest/flex/v2/web_chats.go index f644ff6a6..161783c54 100644 --- a/rest/flex/v2/web_chats.go +++ b/rest/flex/v2/web_chats.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" ) @@ -54,8 +55,10 @@ func (params *CreateWebChannelParams) SetPreEngagementData(PreEngagementData str return params } -// func (c *ApiService) CreateWebChannel(params *CreateWebChannelParams) (*FlexV2WebChannel, error) { + return c.CreateWebChannelWithContext(context.TODO(), params) +} +func (c *ApiService) CreateWebChannelWithContext(ctx context.Context, params *CreateWebChannelParams) (*FlexV2WebChannel, error) { path := "/v2/WebChats" data := url.Values{} @@ -79,7 +82,7 @@ func (c *ApiService) CreateWebChannel(params *CreateWebChannelParams) (*FlexV2We if params != nil && params.UiVersion != nil { headers["Ui-Version"] = *params.UiVersion } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/frontline/v1/api_service.go b/rest/frontline/v1/api_service.go index 1231f8aad..bc4e1e0d0 100644 --- a/rest/frontline/v1/api_service.go +++ b/rest/frontline/v1/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://frontline-api.twilio.com", + } +} diff --git a/rest/frontline/v1/users.go b/rest/frontline/v1/users.go index fb7285480..6268c4847 100644 --- a/rest/frontline/v1/users.go +++ b/rest/frontline/v1/users.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -23,6 +24,9 @@ import ( // Fetch a frontline user func (c *ApiService) FetchUser(Sid string) (*FrontlineV1User, error) { + return c.FetchUserWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchUserWithContext(ctx context.Context, Sid string) (*FrontlineV1User, error) { path := "/v1/Users/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -31,7 +35,7 @@ func (c *ApiService) FetchUser(Sid string) (*FrontlineV1User, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -77,6 +81,9 @@ func (params *UpdateUserParams) SetIsAvailable(IsAvailable bool) *UpdateUserPara // Update an existing frontline user func (c *ApiService) UpdateUser(Sid string, params *UpdateUserParams) (*FrontlineV1User, error) { + return c.UpdateUserWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateUserWithContext(ctx context.Context, Sid string, params *UpdateUserParams) (*FrontlineV1User, error) { path := "/v1/Users/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -98,7 +105,7 @@ func (c *ApiService) UpdateUser(Sid string, params *UpdateUserParams) (*Frontlin data.Set("IsAvailable", fmt.Sprint(*params.IsAvailable)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/iam/v1/api_service.go b/rest/iam/v1/api_service.go index a7c0f9aaa..3413c35e3 100644 --- a/rest/iam/v1/api_service.go +++ b/rest/iam/v1/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://iam.twilio.com", + } +} diff --git a/rest/iam/v1/keys.go b/rest/iam/v1/keys.go index 4f3293f36..c0e65815f 100644 --- a/rest/iam/v1/keys.go +++ b/rest/iam/v1/keys.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -54,6 +55,9 @@ func (params *CreateNewKeyParams) SetPolicy(Policy interface{}) *CreateNewKeyPar // Create a new Signing Key for the account making the request. func (c *ApiService) CreateNewKey(params *CreateNewKeyParams) (*IamV1NewKey, error) { + return c.CreateNewKeyWithContext(context.TODO(), params) +} +func (c *ApiService) CreateNewKeyWithContext(ctx context.Context, params *CreateNewKeyParams) (*IamV1NewKey, error) { path := "/v1/Keys" data := url.Values{} @@ -80,7 +84,7 @@ func (c *ApiService) CreateNewKey(params *CreateNewKeyParams) (*IamV1NewKey, err data.Set("Policy", string(v)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -97,6 +101,9 @@ func (c *ApiService) CreateNewKey(params *CreateNewKeyParams) (*IamV1NewKey, err // Delete a specific Key. func (c *ApiService) DeleteKey(Sid string) error { + return c.DeleteKeyWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteKeyWithContext(ctx context.Context, Sid string) error { path := "/v1/Keys/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -105,7 +112,7 @@ func (c *ApiService) DeleteKey(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -117,6 +124,9 @@ func (c *ApiService) DeleteKey(Sid string) error { // Fetch a specific Key. func (c *ApiService) FetchKey(Sid string) (*IamV1Key, error) { + return c.FetchKeyWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchKeyWithContext(ctx context.Context, Sid string) (*IamV1Key, error) { path := "/v1/Keys/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -125,7 +135,7 @@ func (c *ApiService) FetchKey(Sid string) (*IamV1Key, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -165,6 +175,11 @@ func (params *ListGetKeysParams) SetLimit(Limit int) *ListGetKeysParams { // Retrieve a single page of GetKeys records from the API. Request is executed immediately. func (c *ApiService) PageGetKeys(params *ListGetKeysParams, pageToken, pageNumber string) (*ListGetKeysResponse, error) { + return c.PageGetKeysWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of GetKeys records from the API. Request is executed immediately. +func (c *ApiService) PageGetKeysWithContext(ctx context.Context, params *ListGetKeysParams, pageToken, pageNumber string) (*ListGetKeysResponse, error) { path := "/v1/Keys" data := url.Values{} @@ -186,7 +201,7 @@ func (c *ApiService) PageGetKeys(params *ListGetKeysParams, pageToken, pageNumbe data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -203,7 +218,12 @@ func (c *ApiService) PageGetKeys(params *ListGetKeysParams, pageToken, pageNumbe // Lists GetKeys records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListGetKeys(params *ListGetKeysParams) ([]IamV1GetKeys, error) { - response, errors := c.StreamGetKeys(params) + return c.ListGetKeysWithContext(context.TODO(), params) +} + +// Lists GetKeys records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListGetKeysWithContext(ctx context.Context, params *ListGetKeysParams) ([]IamV1GetKeys, error) { + response, errors := c.StreamGetKeysWithContext(ctx, params) records := make([]IamV1GetKeys, 0) for record := range response { @@ -219,6 +239,11 @@ func (c *ApiService) ListGetKeys(params *ListGetKeysParams) ([]IamV1GetKeys, err // Streams GetKeys records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamGetKeys(params *ListGetKeysParams) (chan IamV1GetKeys, chan error) { + return c.StreamGetKeysWithContext(context.TODO(), params) +} + +// Streams GetKeys records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamGetKeysWithContext(ctx context.Context, params *ListGetKeysParams) (chan IamV1GetKeys, chan error) { if params == nil { params = &ListGetKeysParams{} } @@ -227,19 +252,19 @@ func (c *ApiService) StreamGetKeys(params *ListGetKeysParams) (chan IamV1GetKeys recordChannel := make(chan IamV1GetKeys, 1) errorChannel := make(chan error, 1) - response, err := c.PageGetKeys(params, "", "") + response, err := c.PageGetKeysWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamGetKeys(response, params, recordChannel, errorChannel) + go c.streamGetKeysWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamGetKeys(response *ListGetKeysResponse, params *ListGetKeysParams, recordChannel chan IamV1GetKeys, errorChannel chan error) { +func (c *ApiService) streamGetKeysWithContext(ctx context.Context, response *ListGetKeysResponse, params *ListGetKeysParams, recordChannel chan IamV1GetKeys, errorChannel chan error) { curRecord := 1 for response != nil { @@ -254,7 +279,7 @@ func (c *ApiService) streamGetKeys(response *ListGetKeysResponse, params *ListGe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListGetKeysResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListGetKeysResponseWithContext) if err != nil { errorChannel <- err break @@ -269,11 +294,11 @@ func (c *ApiService) streamGetKeys(response *ListGetKeysResponse, params *ListGe close(errorChannel) } -func (c *ApiService) getNextListGetKeysResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListGetKeysResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -306,6 +331,9 @@ func (params *UpdateKeyParams) SetPolicy(Policy interface{}) *UpdateKeyParams { // Update a specific Key. func (c *ApiService) UpdateKey(Sid string, params *UpdateKeyParams) (*IamV1Key, error) { + return c.UpdateKeyWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateKeyWithContext(ctx context.Context, Sid string, params *UpdateKeyParams) (*IamV1Key, error) { path := "/v1/Keys/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -327,7 +355,7 @@ func (c *ApiService) UpdateKey(Sid string, params *UpdateKeyParams) (*IamV1Key, data.Set("Policy", string(v)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/iam/v1/token.go b/rest/iam/v1/token.go index bea501ca2..fa4bbc29d 100644 --- a/rest/iam/v1/token.go +++ b/rest/iam/v1/token.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" ) @@ -73,6 +74,9 @@ func (params *CreateTokenParams) SetScope(Scope string) *CreateTokenParams { } func (c *ApiService) CreateToken(params *CreateTokenParams) (*OauthV1Token, error) { + return c.CreateTokenWithContext(context.TODO(), params) +} +func (c *ApiService) CreateTokenWithContext(ctx context.Context, params *CreateTokenParams) (*OauthV1Token, error) { path := "/v1/token" data := url.Values{} @@ -105,7 +109,7 @@ func (c *ApiService) CreateToken(params *CreateTokenParams) (*OauthV1Token, erro data.Set("scope", *params.Scope) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/insights/v1/api_service.go b/rest/insights/v1/api_service.go index 5221ab88c..1a65a9a3c 100644 --- a/rest/insights/v1/api_service.go +++ b/rest/insights/v1/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://insights.twilio.com", + } +} diff --git a/rest/insights/v1/conferences.go b/rest/insights/v1/conferences.go index 2be0c3889..5163eea5c 100644 --- a/rest/insights/v1/conferences.go +++ b/rest/insights/v1/conferences.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -25,6 +26,9 @@ import ( // Get a specific Conference Summary. func (c *ApiService) FetchConference(ConferenceSid string) (*InsightsV1Conference, error) { + return c.FetchConferenceWithContext(context.TODO(), ConferenceSid) +} +func (c *ApiService) FetchConferenceWithContext(ctx context.Context, ConferenceSid string) (*InsightsV1Conference, error) { path := "/v1/Conferences/{ConferenceSid}" path = strings.Replace(path, "{"+"ConferenceSid"+"}", ConferenceSid, -1) @@ -33,7 +37,7 @@ func (c *ApiService) FetchConference(ConferenceSid string) (*InsightsV1Conferenc "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -127,6 +131,11 @@ func (params *ListConferenceParams) SetLimit(Limit int) *ListConferenceParams { // Retrieve a single page of Conference records from the API. Request is executed immediately. func (c *ApiService) PageConference(params *ListConferenceParams, pageToken, pageNumber string) (*ListConferenceResponse, error) { + return c.PageConferenceWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Conference records from the API. Request is executed immediately. +func (c *ApiService) PageConferenceWithContext(ctx context.Context, params *ListConferenceParams, pageToken, pageNumber string) (*ListConferenceResponse, error) { path := "/v1/Conferences" data := url.Values{} @@ -175,7 +184,7 @@ func (c *ApiService) PageConference(params *ListConferenceParams, pageToken, pag data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -192,7 +201,12 @@ func (c *ApiService) PageConference(params *ListConferenceParams, pageToken, pag // Lists Conference records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListConference(params *ListConferenceParams) ([]InsightsV1Conference, error) { - response, errors := c.StreamConference(params) + return c.ListConferenceWithContext(context.TODO(), params) +} + +// Lists Conference records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListConferenceWithContext(ctx context.Context, params *ListConferenceParams) ([]InsightsV1Conference, error) { + response, errors := c.StreamConferenceWithContext(ctx, params) records := make([]InsightsV1Conference, 0) for record := range response { @@ -208,6 +222,11 @@ func (c *ApiService) ListConference(params *ListConferenceParams) ([]InsightsV1C // Streams Conference records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamConference(params *ListConferenceParams) (chan InsightsV1Conference, chan error) { + return c.StreamConferenceWithContext(context.TODO(), params) +} + +// Streams Conference records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamConferenceWithContext(ctx context.Context, params *ListConferenceParams) (chan InsightsV1Conference, chan error) { if params == nil { params = &ListConferenceParams{} } @@ -216,19 +235,19 @@ func (c *ApiService) StreamConference(params *ListConferenceParams) (chan Insigh recordChannel := make(chan InsightsV1Conference, 1) errorChannel := make(chan error, 1) - response, err := c.PageConference(params, "", "") + response, err := c.PageConferenceWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamConference(response, params, recordChannel, errorChannel) + go c.streamConferenceWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamConference(response *ListConferenceResponse, params *ListConferenceParams, recordChannel chan InsightsV1Conference, errorChannel chan error) { +func (c *ApiService) streamConferenceWithContext(ctx context.Context, response *ListConferenceResponse, params *ListConferenceParams, recordChannel chan InsightsV1Conference, errorChannel chan error) { curRecord := 1 for response != nil { @@ -243,7 +262,7 @@ func (c *ApiService) streamConference(response *ListConferenceResponse, params * } } - record, err := client.GetNext(c.baseURL, response, c.getNextListConferenceResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListConferenceResponseWithContext) if err != nil { errorChannel <- err break @@ -258,11 +277,11 @@ func (c *ApiService) streamConference(response *ListConferenceResponse, params * close(errorChannel) } -func (c *ApiService) getNextListConferenceResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListConferenceResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/insights/v1/conferences_participants.go b/rest/insights/v1/conferences_participants.go index 7867891fc..a5dc77a9e 100644 --- a/rest/insights/v1/conferences_participants.go +++ b/rest/insights/v1/conferences_participants.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -42,6 +43,9 @@ func (params *FetchConferenceParticipantParams) SetMetrics(Metrics string) *Fetc // Get a specific Conference Participant Summary for a Conference. func (c *ApiService) FetchConferenceParticipant(ConferenceSid string, ParticipantSid string, params *FetchConferenceParticipantParams) (*InsightsV1ConferenceParticipant, error) { + return c.FetchConferenceParticipantWithContext(context.TODO(), ConferenceSid, ParticipantSid, params) +} +func (c *ApiService) FetchConferenceParticipantWithContext(ctx context.Context, ConferenceSid string, ParticipantSid string, params *FetchConferenceParticipantParams) (*InsightsV1ConferenceParticipant, error) { path := "/v1/Conferences/{ConferenceSid}/Participants/{ParticipantSid}" path = strings.Replace(path, "{"+"ConferenceSid"+"}", ConferenceSid, -1) path = strings.Replace(path, "{"+"ParticipantSid"+"}", ParticipantSid, -1) @@ -58,7 +62,7 @@ func (c *ApiService) FetchConferenceParticipant(ConferenceSid string, Participan data.Set("Metrics", *params.Metrics) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -110,6 +114,11 @@ func (params *ListConferenceParticipantParams) SetLimit(Limit int) *ListConferen // Retrieve a single page of ConferenceParticipant records from the API. Request is executed immediately. func (c *ApiService) PageConferenceParticipant(ConferenceSid string, params *ListConferenceParticipantParams, pageToken, pageNumber string) (*ListConferenceParticipantResponse, error) { + return c.PageConferenceParticipantWithContext(context.TODO(), ConferenceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ConferenceParticipant records from the API. Request is executed immediately. +func (c *ApiService) PageConferenceParticipantWithContext(ctx context.Context, ConferenceSid string, params *ListConferenceParticipantParams, pageToken, pageNumber string) (*ListConferenceParticipantResponse, error) { path := "/v1/Conferences/{ConferenceSid}/Participants" path = strings.Replace(path, "{"+"ConferenceSid"+"}", ConferenceSid, -1) @@ -139,7 +148,7 @@ func (c *ApiService) PageConferenceParticipant(ConferenceSid string, params *Lis data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -156,7 +165,12 @@ func (c *ApiService) PageConferenceParticipant(ConferenceSid string, params *Lis // Lists ConferenceParticipant records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListConferenceParticipant(ConferenceSid string, params *ListConferenceParticipantParams) ([]InsightsV1ConferenceParticipant, error) { - response, errors := c.StreamConferenceParticipant(ConferenceSid, params) + return c.ListConferenceParticipantWithContext(context.TODO(), ConferenceSid, params) +} + +// Lists ConferenceParticipant records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListConferenceParticipantWithContext(ctx context.Context, ConferenceSid string, params *ListConferenceParticipantParams) ([]InsightsV1ConferenceParticipant, error) { + response, errors := c.StreamConferenceParticipantWithContext(ctx, ConferenceSid, params) records := make([]InsightsV1ConferenceParticipant, 0) for record := range response { @@ -172,6 +186,11 @@ func (c *ApiService) ListConferenceParticipant(ConferenceSid string, params *Lis // Streams ConferenceParticipant records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamConferenceParticipant(ConferenceSid string, params *ListConferenceParticipantParams) (chan InsightsV1ConferenceParticipant, chan error) { + return c.StreamConferenceParticipantWithContext(context.TODO(), ConferenceSid, params) +} + +// Streams ConferenceParticipant records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamConferenceParticipantWithContext(ctx context.Context, ConferenceSid string, params *ListConferenceParticipantParams) (chan InsightsV1ConferenceParticipant, chan error) { if params == nil { params = &ListConferenceParticipantParams{} } @@ -180,19 +199,19 @@ func (c *ApiService) StreamConferenceParticipant(ConferenceSid string, params *L recordChannel := make(chan InsightsV1ConferenceParticipant, 1) errorChannel := make(chan error, 1) - response, err := c.PageConferenceParticipant(ConferenceSid, params, "", "") + response, err := c.PageConferenceParticipantWithContext(ctx, ConferenceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamConferenceParticipant(response, params, recordChannel, errorChannel) + go c.streamConferenceParticipantWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamConferenceParticipant(response *ListConferenceParticipantResponse, params *ListConferenceParticipantParams, recordChannel chan InsightsV1ConferenceParticipant, errorChannel chan error) { +func (c *ApiService) streamConferenceParticipantWithContext(ctx context.Context, response *ListConferenceParticipantResponse, params *ListConferenceParticipantParams, recordChannel chan InsightsV1ConferenceParticipant, errorChannel chan error) { curRecord := 1 for response != nil { @@ -207,7 +226,7 @@ func (c *ApiService) streamConferenceParticipant(response *ListConferencePartici } } - record, err := client.GetNext(c.baseURL, response, c.getNextListConferenceParticipantResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListConferenceParticipantResponseWithContext) if err != nil { errorChannel <- err break @@ -222,11 +241,11 @@ func (c *ApiService) streamConferenceParticipant(response *ListConferencePartici close(errorChannel) } -func (c *ApiService) getNextListConferenceParticipantResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListConferenceParticipantResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/insights/v1/video_rooms.go b/rest/insights/v1/video_rooms.go index 23e3b84d4..0fdc58fe9 100644 --- a/rest/insights/v1/video_rooms.go +++ b/rest/insights/v1/video_rooms.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -26,6 +27,9 @@ import ( // Get Video Log Analyzer data for a Room. func (c *ApiService) FetchVideoRoomSummary(RoomSid string) (*InsightsV1VideoRoomSummary, error) { + return c.FetchVideoRoomSummaryWithContext(context.TODO(), RoomSid) +} +func (c *ApiService) FetchVideoRoomSummaryWithContext(ctx context.Context, RoomSid string) (*InsightsV1VideoRoomSummary, error) { path := "/v1/Video/Rooms/{RoomSid}" path = strings.Replace(path, "{"+"RoomSid"+"}", RoomSid, -1) @@ -34,7 +38,7 @@ func (c *ApiService) FetchVideoRoomSummary(RoomSid string) (*InsightsV1VideoRoom "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -98,6 +102,11 @@ func (params *ListVideoRoomSummaryParams) SetLimit(Limit int) *ListVideoRoomSumm // Retrieve a single page of VideoRoomSummary records from the API. Request is executed immediately. func (c *ApiService) PageVideoRoomSummary(params *ListVideoRoomSummaryParams, pageToken, pageNumber string) (*ListVideoRoomSummaryResponse, error) { + return c.PageVideoRoomSummaryWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of VideoRoomSummary records from the API. Request is executed immediately. +func (c *ApiService) PageVideoRoomSummaryWithContext(ctx context.Context, params *ListVideoRoomSummaryParams, pageToken, pageNumber string) (*ListVideoRoomSummaryResponse, error) { path := "/v1/Video/Rooms" data := url.Values{} @@ -135,7 +144,7 @@ func (c *ApiService) PageVideoRoomSummary(params *ListVideoRoomSummaryParams, pa data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -152,7 +161,12 @@ func (c *ApiService) PageVideoRoomSummary(params *ListVideoRoomSummaryParams, pa // Lists VideoRoomSummary records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListVideoRoomSummary(params *ListVideoRoomSummaryParams) ([]InsightsV1VideoRoomSummary, error) { - response, errors := c.StreamVideoRoomSummary(params) + return c.ListVideoRoomSummaryWithContext(context.TODO(), params) +} + +// Lists VideoRoomSummary records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListVideoRoomSummaryWithContext(ctx context.Context, params *ListVideoRoomSummaryParams) ([]InsightsV1VideoRoomSummary, error) { + response, errors := c.StreamVideoRoomSummaryWithContext(ctx, params) records := make([]InsightsV1VideoRoomSummary, 0) for record := range response { @@ -168,6 +182,11 @@ func (c *ApiService) ListVideoRoomSummary(params *ListVideoRoomSummaryParams) ([ // Streams VideoRoomSummary records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamVideoRoomSummary(params *ListVideoRoomSummaryParams) (chan InsightsV1VideoRoomSummary, chan error) { + return c.StreamVideoRoomSummaryWithContext(context.TODO(), params) +} + +// Streams VideoRoomSummary records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamVideoRoomSummaryWithContext(ctx context.Context, params *ListVideoRoomSummaryParams) (chan InsightsV1VideoRoomSummary, chan error) { if params == nil { params = &ListVideoRoomSummaryParams{} } @@ -176,19 +195,19 @@ func (c *ApiService) StreamVideoRoomSummary(params *ListVideoRoomSummaryParams) recordChannel := make(chan InsightsV1VideoRoomSummary, 1) errorChannel := make(chan error, 1) - response, err := c.PageVideoRoomSummary(params, "", "") + response, err := c.PageVideoRoomSummaryWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamVideoRoomSummary(response, params, recordChannel, errorChannel) + go c.streamVideoRoomSummaryWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamVideoRoomSummary(response *ListVideoRoomSummaryResponse, params *ListVideoRoomSummaryParams, recordChannel chan InsightsV1VideoRoomSummary, errorChannel chan error) { +func (c *ApiService) streamVideoRoomSummaryWithContext(ctx context.Context, response *ListVideoRoomSummaryResponse, params *ListVideoRoomSummaryParams, recordChannel chan InsightsV1VideoRoomSummary, errorChannel chan error) { curRecord := 1 for response != nil { @@ -203,7 +222,7 @@ func (c *ApiService) streamVideoRoomSummary(response *ListVideoRoomSummaryRespon } } - record, err := client.GetNext(c.baseURL, response, c.getNextListVideoRoomSummaryResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListVideoRoomSummaryResponseWithContext) if err != nil { errorChannel <- err break @@ -218,11 +237,11 @@ func (c *ApiService) streamVideoRoomSummary(response *ListVideoRoomSummaryRespon close(errorChannel) } -func (c *ApiService) getNextListVideoRoomSummaryResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListVideoRoomSummaryResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/insights/v1/video_rooms_participants.go b/rest/insights/v1/video_rooms_participants.go index 5f43cab63..df9ceb12e 100644 --- a/rest/insights/v1/video_rooms_participants.go +++ b/rest/insights/v1/video_rooms_participants.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -25,6 +26,9 @@ import ( // Get Video Log Analyzer data for a Room Participant. func (c *ApiService) FetchVideoParticipantSummary(RoomSid string, ParticipantSid string) (*InsightsV1VideoParticipantSummary, error) { + return c.FetchVideoParticipantSummaryWithContext(context.TODO(), RoomSid, ParticipantSid) +} +func (c *ApiService) FetchVideoParticipantSummaryWithContext(ctx context.Context, RoomSid string, ParticipantSid string) (*InsightsV1VideoParticipantSummary, error) { path := "/v1/Video/Rooms/{RoomSid}/Participants/{ParticipantSid}" path = strings.Replace(path, "{"+"RoomSid"+"}", RoomSid, -1) path = strings.Replace(path, "{"+"ParticipantSid"+"}", ParticipantSid, -1) @@ -34,7 +38,7 @@ func (c *ApiService) FetchVideoParticipantSummary(RoomSid string, ParticipantSid "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -68,6 +72,11 @@ func (params *ListVideoParticipantSummaryParams) SetLimit(Limit int) *ListVideoP // Retrieve a single page of VideoParticipantSummary records from the API. Request is executed immediately. func (c *ApiService) PageVideoParticipantSummary(RoomSid string, params *ListVideoParticipantSummaryParams, pageToken, pageNumber string) (*ListVideoParticipantSummaryResponse, error) { + return c.PageVideoParticipantSummaryWithContext(context.TODO(), RoomSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of VideoParticipantSummary records from the API. Request is executed immediately. +func (c *ApiService) PageVideoParticipantSummaryWithContext(ctx context.Context, RoomSid string, params *ListVideoParticipantSummaryParams, pageToken, pageNumber string) (*ListVideoParticipantSummaryResponse, error) { path := "/v1/Video/Rooms/{RoomSid}/Participants" path = strings.Replace(path, "{"+"RoomSid"+"}", RoomSid, -1) @@ -88,7 +97,7 @@ func (c *ApiService) PageVideoParticipantSummary(RoomSid string, params *ListVid data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -105,7 +114,12 @@ func (c *ApiService) PageVideoParticipantSummary(RoomSid string, params *ListVid // Lists VideoParticipantSummary records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListVideoParticipantSummary(RoomSid string, params *ListVideoParticipantSummaryParams) ([]InsightsV1VideoParticipantSummary, error) { - response, errors := c.StreamVideoParticipantSummary(RoomSid, params) + return c.ListVideoParticipantSummaryWithContext(context.TODO(), RoomSid, params) +} + +// Lists VideoParticipantSummary records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListVideoParticipantSummaryWithContext(ctx context.Context, RoomSid string, params *ListVideoParticipantSummaryParams) ([]InsightsV1VideoParticipantSummary, error) { + response, errors := c.StreamVideoParticipantSummaryWithContext(ctx, RoomSid, params) records := make([]InsightsV1VideoParticipantSummary, 0) for record := range response { @@ -121,6 +135,11 @@ func (c *ApiService) ListVideoParticipantSummary(RoomSid string, params *ListVid // Streams VideoParticipantSummary records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamVideoParticipantSummary(RoomSid string, params *ListVideoParticipantSummaryParams) (chan InsightsV1VideoParticipantSummary, chan error) { + return c.StreamVideoParticipantSummaryWithContext(context.TODO(), RoomSid, params) +} + +// Streams VideoParticipantSummary records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamVideoParticipantSummaryWithContext(ctx context.Context, RoomSid string, params *ListVideoParticipantSummaryParams) (chan InsightsV1VideoParticipantSummary, chan error) { if params == nil { params = &ListVideoParticipantSummaryParams{} } @@ -129,19 +148,19 @@ func (c *ApiService) StreamVideoParticipantSummary(RoomSid string, params *ListV recordChannel := make(chan InsightsV1VideoParticipantSummary, 1) errorChannel := make(chan error, 1) - response, err := c.PageVideoParticipantSummary(RoomSid, params, "", "") + response, err := c.PageVideoParticipantSummaryWithContext(ctx, RoomSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamVideoParticipantSummary(response, params, recordChannel, errorChannel) + go c.streamVideoParticipantSummaryWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamVideoParticipantSummary(response *ListVideoParticipantSummaryResponse, params *ListVideoParticipantSummaryParams, recordChannel chan InsightsV1VideoParticipantSummary, errorChannel chan error) { +func (c *ApiService) streamVideoParticipantSummaryWithContext(ctx context.Context, response *ListVideoParticipantSummaryResponse, params *ListVideoParticipantSummaryParams, recordChannel chan InsightsV1VideoParticipantSummary, errorChannel chan error) { curRecord := 1 for response != nil { @@ -156,7 +175,7 @@ func (c *ApiService) streamVideoParticipantSummary(response *ListVideoParticipan } } - record, err := client.GetNext(c.baseURL, response, c.getNextListVideoParticipantSummaryResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListVideoParticipantSummaryResponseWithContext) if err != nil { errorChannel <- err break @@ -171,11 +190,11 @@ func (c *ApiService) streamVideoParticipantSummary(response *ListVideoParticipan close(errorChannel) } -func (c *ApiService) getNextListVideoParticipantSummaryResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListVideoParticipantSummaryResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/insights/v1/voice.go b/rest/insights/v1/voice.go index 853ddb7b6..dab2c02e6 100644 --- a/rest/insights/v1/voice.go +++ b/rest/insights/v1/voice.go @@ -15,13 +15,16 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" ) -// func (c *ApiService) FetchCall(Sid string) (*InsightsV1Call, error) { + return c.FetchCallWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchCallWithContext(ctx context.Context, Sid string) (*InsightsV1Call, error) { path := "/v1/Voice/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -30,7 +33,7 @@ func (c *ApiService) FetchCall(Sid string) (*InsightsV1Call, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/insights/v1/voice_annotation.go b/rest/insights/v1/voice_annotation.go index 9fca55180..4f87766d7 100644 --- a/rest/insights/v1/voice_annotation.go +++ b/rest/insights/v1/voice_annotation.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -23,6 +24,9 @@ import ( // Get the Annotation for a specific Call. func (c *ApiService) FetchAnnotation(CallSid string) (*InsightsV1Annotation, error) { + return c.FetchAnnotationWithContext(context.TODO(), CallSid) +} +func (c *ApiService) FetchAnnotationWithContext(ctx context.Context, CallSid string) (*InsightsV1Annotation, error) { path := "/v1/Voice/{CallSid}/Annotation" path = strings.Replace(path, "{"+"CallSid"+"}", CallSid, -1) @@ -31,7 +35,7 @@ func (c *ApiService) FetchAnnotation(CallSid string) (*InsightsV1Annotation, err "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -95,6 +99,9 @@ func (params *UpdateAnnotationParams) SetIncident(Incident string) *UpdateAnnota // Update an Annotation for a specific Call. func (c *ApiService) UpdateAnnotation(CallSid string, params *UpdateAnnotationParams) (*InsightsV1Annotation, error) { + return c.UpdateAnnotationWithContext(context.TODO(), CallSid, params) +} +func (c *ApiService) UpdateAnnotationWithContext(ctx context.Context, CallSid string, params *UpdateAnnotationParams) (*InsightsV1Annotation, error) { path := "/v1/Voice/{CallSid}/Annotation" path = strings.Replace(path, "{"+"CallSid"+"}", CallSid, -1) @@ -125,7 +132,7 @@ func (c *ApiService) UpdateAnnotation(CallSid string, params *UpdateAnnotationPa data.Set("Incident", *params.Incident) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/insights/v1/voice_events.go b/rest/insights/v1/voice_events.go index 75b237bfd..3d2de4691 100644 --- a/rest/insights/v1/voice_events.go +++ b/rest/insights/v1/voice_events.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -48,6 +49,11 @@ func (params *ListEventParams) SetLimit(Limit int) *ListEventParams { // Retrieve a single page of Event records from the API. Request is executed immediately. func (c *ApiService) PageEvent(CallSid string, params *ListEventParams, pageToken, pageNumber string) (*ListEventResponse, error) { + return c.PageEventWithContext(context.TODO(), CallSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Event records from the API. Request is executed immediately. +func (c *ApiService) PageEventWithContext(ctx context.Context, CallSid string, params *ListEventParams, pageToken, pageNumber string) (*ListEventResponse, error) { path := "/v1/Voice/{CallSid}/Events" path = strings.Replace(path, "{"+"CallSid"+"}", CallSid, -1) @@ -71,7 +77,7 @@ func (c *ApiService) PageEvent(CallSid string, params *ListEventParams, pageToke data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -88,7 +94,12 @@ func (c *ApiService) PageEvent(CallSid string, params *ListEventParams, pageToke // Lists Event records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListEvent(CallSid string, params *ListEventParams) ([]InsightsV1Event, error) { - response, errors := c.StreamEvent(CallSid, params) + return c.ListEventWithContext(context.TODO(), CallSid, params) +} + +// Lists Event records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListEventWithContext(ctx context.Context, CallSid string, params *ListEventParams) ([]InsightsV1Event, error) { + response, errors := c.StreamEventWithContext(ctx, CallSid, params) records := make([]InsightsV1Event, 0) for record := range response { @@ -104,6 +115,11 @@ func (c *ApiService) ListEvent(CallSid string, params *ListEventParams) ([]Insig // Streams Event records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamEvent(CallSid string, params *ListEventParams) (chan InsightsV1Event, chan error) { + return c.StreamEventWithContext(context.TODO(), CallSid, params) +} + +// Streams Event records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamEventWithContext(ctx context.Context, CallSid string, params *ListEventParams) (chan InsightsV1Event, chan error) { if params == nil { params = &ListEventParams{} } @@ -112,19 +128,19 @@ func (c *ApiService) StreamEvent(CallSid string, params *ListEventParams) (chan recordChannel := make(chan InsightsV1Event, 1) errorChannel := make(chan error, 1) - response, err := c.PageEvent(CallSid, params, "", "") + response, err := c.PageEventWithContext(ctx, CallSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamEvent(response, params, recordChannel, errorChannel) + go c.streamEventWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamEvent(response *ListEventResponse, params *ListEventParams, recordChannel chan InsightsV1Event, errorChannel chan error) { +func (c *ApiService) streamEventWithContext(ctx context.Context, response *ListEventResponse, params *ListEventParams, recordChannel chan InsightsV1Event, errorChannel chan error) { curRecord := 1 for response != nil { @@ -139,7 +155,7 @@ func (c *ApiService) streamEvent(response *ListEventResponse, params *ListEventP } } - record, err := client.GetNext(c.baseURL, response, c.getNextListEventResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListEventResponseWithContext) if err != nil { errorChannel <- err break @@ -154,11 +170,11 @@ func (c *ApiService) streamEvent(response *ListEventResponse, params *ListEventP close(errorChannel) } -func (c *ApiService) getNextListEventResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListEventResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/insights/v1/voice_metrics.go b/rest/insights/v1/voice_metrics.go index fd3f6e032..fb6d44259 100644 --- a/rest/insights/v1/voice_metrics.go +++ b/rest/insights/v1/voice_metrics.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -54,6 +55,11 @@ func (params *ListMetricParams) SetLimit(Limit int) *ListMetricParams { // Retrieve a single page of Metric records from the API. Request is executed immediately. func (c *ApiService) PageMetric(CallSid string, params *ListMetricParams, pageToken, pageNumber string) (*ListMetricResponse, error) { + return c.PageMetricWithContext(context.TODO(), CallSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Metric records from the API. Request is executed immediately. +func (c *ApiService) PageMetricWithContext(ctx context.Context, CallSid string, params *ListMetricParams, pageToken, pageNumber string) (*ListMetricResponse, error) { path := "/v1/Voice/{CallSid}/Metrics" path = strings.Replace(path, "{"+"CallSid"+"}", CallSid, -1) @@ -80,7 +86,7 @@ func (c *ApiService) PageMetric(CallSid string, params *ListMetricParams, pageTo data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -97,7 +103,12 @@ func (c *ApiService) PageMetric(CallSid string, params *ListMetricParams, pageTo // Lists Metric records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListMetric(CallSid string, params *ListMetricParams) ([]InsightsV1Metric, error) { - response, errors := c.StreamMetric(CallSid, params) + return c.ListMetricWithContext(context.TODO(), CallSid, params) +} + +// Lists Metric records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListMetricWithContext(ctx context.Context, CallSid string, params *ListMetricParams) ([]InsightsV1Metric, error) { + response, errors := c.StreamMetricWithContext(ctx, CallSid, params) records := make([]InsightsV1Metric, 0) for record := range response { @@ -113,6 +124,11 @@ func (c *ApiService) ListMetric(CallSid string, params *ListMetricParams) ([]Ins // Streams Metric records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamMetric(CallSid string, params *ListMetricParams) (chan InsightsV1Metric, chan error) { + return c.StreamMetricWithContext(context.TODO(), CallSid, params) +} + +// Streams Metric records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamMetricWithContext(ctx context.Context, CallSid string, params *ListMetricParams) (chan InsightsV1Metric, chan error) { if params == nil { params = &ListMetricParams{} } @@ -121,19 +137,19 @@ func (c *ApiService) StreamMetric(CallSid string, params *ListMetricParams) (cha recordChannel := make(chan InsightsV1Metric, 1) errorChannel := make(chan error, 1) - response, err := c.PageMetric(CallSid, params, "", "") + response, err := c.PageMetricWithContext(ctx, CallSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamMetric(response, params, recordChannel, errorChannel) + go c.streamMetricWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamMetric(response *ListMetricResponse, params *ListMetricParams, recordChannel chan InsightsV1Metric, errorChannel chan error) { +func (c *ApiService) streamMetricWithContext(ctx context.Context, response *ListMetricResponse, params *ListMetricParams, recordChannel chan InsightsV1Metric, errorChannel chan error) { curRecord := 1 for response != nil { @@ -148,7 +164,7 @@ func (c *ApiService) streamMetric(response *ListMetricResponse, params *ListMetr } } - record, err := client.GetNext(c.baseURL, response, c.getNextListMetricResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListMetricResponseWithContext) if err != nil { errorChannel <- err break @@ -163,11 +179,11 @@ func (c *ApiService) streamMetric(response *ListMetricResponse, params *ListMetr close(errorChannel) } -func (c *ApiService) getNextListMetricResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListMetricResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/insights/v1/voice_settings.go b/rest/insights/v1/voice_settings.go index b46fa5515..da528b72e 100644 --- a/rest/insights/v1/voice_settings.go +++ b/rest/insights/v1/voice_settings.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -33,6 +34,9 @@ func (params *FetchAccountSettingsParams) SetSubaccountSid(SubaccountSid string) // Get the Voice Insights Settings. func (c *ApiService) FetchAccountSettings(params *FetchAccountSettingsParams) (*InsightsV1AccountSettings, error) { + return c.FetchAccountSettingsWithContext(context.TODO(), params) +} +func (c *ApiService) FetchAccountSettingsWithContext(ctx context.Context, params *FetchAccountSettingsParams) (*InsightsV1AccountSettings, error) { path := "/v1/Voice/Settings" data := url.Values{} @@ -44,7 +48,7 @@ func (c *ApiService) FetchAccountSettings(params *FetchAccountSettingsParams) (* data.Set("SubaccountSid", *params.SubaccountSid) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -84,6 +88,9 @@ func (params *UpdateAccountSettingsParams) SetSubaccountSid(SubaccountSid string // Update a specific Voice Insights Setting. func (c *ApiService) UpdateAccountSettings(params *UpdateAccountSettingsParams) (*InsightsV1AccountSettings, error) { + return c.UpdateAccountSettingsWithContext(context.TODO(), params) +} +func (c *ApiService) UpdateAccountSettingsWithContext(ctx context.Context, params *UpdateAccountSettingsParams) (*InsightsV1AccountSettings, error) { path := "/v1/Voice/Settings" data := url.Values{} @@ -101,7 +108,7 @@ func (c *ApiService) UpdateAccountSettings(params *UpdateAccountSettingsParams) data.Set("SubaccountSid", *params.SubaccountSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/insights/v1/voice_summaries.go b/rest/insights/v1/voice_summaries.go index d6d7468c8..93a1bf43a 100644 --- a/rest/insights/v1/voice_summaries.go +++ b/rest/insights/v1/voice_summaries.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -233,6 +234,11 @@ func (params *ListCallSummariesParams) SetLimit(Limit int) *ListCallSummariesPar // Retrieve a single page of CallSummaries records from the API. Request is executed immediately. func (c *ApiService) PageCallSummaries(params *ListCallSummariesParams, pageToken, pageNumber string) (*ListCallSummariesResponse, error) { + return c.PageCallSummariesWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of CallSummaries records from the API. Request is executed immediately. +func (c *ApiService) PageCallSummariesWithContext(ctx context.Context, params *ListCallSummariesParams, pageToken, pageNumber string) (*ListCallSummariesResponse, error) { path := "/v1/Voice/Summaries" data := url.Values{} @@ -347,7 +353,7 @@ func (c *ApiService) PageCallSummaries(params *ListCallSummariesParams, pageToke data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -364,7 +370,12 @@ func (c *ApiService) PageCallSummaries(params *ListCallSummariesParams, pageToke // Lists CallSummaries records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListCallSummaries(params *ListCallSummariesParams) ([]InsightsV1CallSummaries, error) { - response, errors := c.StreamCallSummaries(params) + return c.ListCallSummariesWithContext(context.TODO(), params) +} + +// Lists CallSummaries records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListCallSummariesWithContext(ctx context.Context, params *ListCallSummariesParams) ([]InsightsV1CallSummaries, error) { + response, errors := c.StreamCallSummariesWithContext(ctx, params) records := make([]InsightsV1CallSummaries, 0) for record := range response { @@ -380,6 +391,11 @@ func (c *ApiService) ListCallSummaries(params *ListCallSummariesParams) ([]Insig // Streams CallSummaries records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamCallSummaries(params *ListCallSummariesParams) (chan InsightsV1CallSummaries, chan error) { + return c.StreamCallSummariesWithContext(context.TODO(), params) +} + +// Streams CallSummaries records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamCallSummariesWithContext(ctx context.Context, params *ListCallSummariesParams) (chan InsightsV1CallSummaries, chan error) { if params == nil { params = &ListCallSummariesParams{} } @@ -388,19 +404,19 @@ func (c *ApiService) StreamCallSummaries(params *ListCallSummariesParams) (chan recordChannel := make(chan InsightsV1CallSummaries, 1) errorChannel := make(chan error, 1) - response, err := c.PageCallSummaries(params, "", "") + response, err := c.PageCallSummariesWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamCallSummaries(response, params, recordChannel, errorChannel) + go c.streamCallSummariesWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamCallSummaries(response *ListCallSummariesResponse, params *ListCallSummariesParams, recordChannel chan InsightsV1CallSummaries, errorChannel chan error) { +func (c *ApiService) streamCallSummariesWithContext(ctx context.Context, response *ListCallSummariesResponse, params *ListCallSummariesParams, recordChannel chan InsightsV1CallSummaries, errorChannel chan error) { curRecord := 1 for response != nil { @@ -415,7 +431,7 @@ func (c *ApiService) streamCallSummaries(response *ListCallSummariesResponse, pa } } - record, err := client.GetNext(c.baseURL, response, c.getNextListCallSummariesResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListCallSummariesResponseWithContext) if err != nil { errorChannel <- err break @@ -430,11 +446,11 @@ func (c *ApiService) streamCallSummaries(response *ListCallSummariesResponse, pa close(errorChannel) } -func (c *ApiService) getNextListCallSummariesResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListCallSummariesResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/insights/v1/voice_summary.go b/rest/insights/v1/voice_summary.go index 733a49f96..cffe55591 100644 --- a/rest/insights/v1/voice_summary.go +++ b/rest/insights/v1/voice_summary.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -33,6 +34,9 @@ func (params *FetchSummaryParams) SetProcessingState(ProcessingState string) *Fe // Get a specific Call Summary. func (c *ApiService) FetchSummary(CallSid string, params *FetchSummaryParams) (*InsightsV1Summary, error) { + return c.FetchSummaryWithContext(context.TODO(), CallSid, params) +} +func (c *ApiService) FetchSummaryWithContext(ctx context.Context, CallSid string, params *FetchSummaryParams) (*InsightsV1Summary, error) { path := "/v1/Voice/{CallSid}/Summary" path = strings.Replace(path, "{"+"CallSid"+"}", CallSid, -1) @@ -45,7 +49,7 @@ func (c *ApiService) FetchSummary(CallSid string, params *FetchSummaryParams) (* data.Set("ProcessingState", *params.ProcessingState) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/intelligence/v2/api_service.go b/rest/intelligence/v2/api_service.go index 6cd2b1058..96c1a452d 100644 --- a/rest/intelligence/v2/api_service.go +++ b/rest/intelligence/v2/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://intelligence.twilio.com", + } +} diff --git a/rest/intelligence/v2/operator_types.go b/rest/intelligence/v2/operator_types.go index 6887a831a..615c18207 100644 --- a/rest/intelligence/v2/operator_types.go +++ b/rest/intelligence/v2/operator_types.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -25,6 +26,9 @@ import ( // Fetch a specific Operator Type. func (c *ApiService) FetchOperatorType(Sid string) (*IntelligenceV2OperatorType, error) { + return c.FetchOperatorTypeWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchOperatorTypeWithContext(ctx context.Context, Sid string) (*IntelligenceV2OperatorType, error) { path := "/v2/OperatorTypes/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -33,7 +37,7 @@ func (c *ApiService) FetchOperatorType(Sid string) (*IntelligenceV2OperatorType, "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -67,6 +71,11 @@ func (params *ListOperatorTypeParams) SetLimit(Limit int) *ListOperatorTypeParam // Retrieve a single page of OperatorType records from the API. Request is executed immediately. func (c *ApiService) PageOperatorType(params *ListOperatorTypeParams, pageToken, pageNumber string) (*ListOperatorTypeResponse, error) { + return c.PageOperatorTypeWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of OperatorType records from the API. Request is executed immediately. +func (c *ApiService) PageOperatorTypeWithContext(ctx context.Context, params *ListOperatorTypeParams, pageToken, pageNumber string) (*ListOperatorTypeResponse, error) { path := "/v2/OperatorTypes" data := url.Values{} @@ -85,7 +94,7 @@ func (c *ApiService) PageOperatorType(params *ListOperatorTypeParams, pageToken, data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -102,7 +111,12 @@ func (c *ApiService) PageOperatorType(params *ListOperatorTypeParams, pageToken, // Lists OperatorType records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListOperatorType(params *ListOperatorTypeParams) ([]IntelligenceV2OperatorType, error) { - response, errors := c.StreamOperatorType(params) + return c.ListOperatorTypeWithContext(context.TODO(), params) +} + +// Lists OperatorType records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListOperatorTypeWithContext(ctx context.Context, params *ListOperatorTypeParams) ([]IntelligenceV2OperatorType, error) { + response, errors := c.StreamOperatorTypeWithContext(ctx, params) records := make([]IntelligenceV2OperatorType, 0) for record := range response { @@ -118,6 +132,11 @@ func (c *ApiService) ListOperatorType(params *ListOperatorTypeParams) ([]Intelli // Streams OperatorType records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamOperatorType(params *ListOperatorTypeParams) (chan IntelligenceV2OperatorType, chan error) { + return c.StreamOperatorTypeWithContext(context.TODO(), params) +} + +// Streams OperatorType records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamOperatorTypeWithContext(ctx context.Context, params *ListOperatorTypeParams) (chan IntelligenceV2OperatorType, chan error) { if params == nil { params = &ListOperatorTypeParams{} } @@ -126,19 +145,19 @@ func (c *ApiService) StreamOperatorType(params *ListOperatorTypeParams) (chan In recordChannel := make(chan IntelligenceV2OperatorType, 1) errorChannel := make(chan error, 1) - response, err := c.PageOperatorType(params, "", "") + response, err := c.PageOperatorTypeWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamOperatorType(response, params, recordChannel, errorChannel) + go c.streamOperatorTypeWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamOperatorType(response *ListOperatorTypeResponse, params *ListOperatorTypeParams, recordChannel chan IntelligenceV2OperatorType, errorChannel chan error) { +func (c *ApiService) streamOperatorTypeWithContext(ctx context.Context, response *ListOperatorTypeResponse, params *ListOperatorTypeParams, recordChannel chan IntelligenceV2OperatorType, errorChannel chan error) { curRecord := 1 for response != nil { @@ -153,7 +172,7 @@ func (c *ApiService) streamOperatorType(response *ListOperatorTypeResponse, para } } - record, err := client.GetNext(c.baseURL, response, c.getNextListOperatorTypeResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListOperatorTypeResponseWithContext) if err != nil { errorChannel <- err break @@ -168,11 +187,11 @@ func (c *ApiService) streamOperatorType(response *ListOperatorTypeResponse, para close(errorChannel) } -func (c *ApiService) getNextListOperatorTypeResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListOperatorTypeResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/intelligence/v2/operators.go b/rest/intelligence/v2/operators.go index ec2f4e5d6..f54a62819 100644 --- a/rest/intelligence/v2/operators.go +++ b/rest/intelligence/v2/operators.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -25,6 +26,9 @@ import ( // Fetch a specific Operator. Works for both Custom and Pre-built Operators. func (c *ApiService) FetchOperator(Sid string) (*IntelligenceV2Operator, error) { + return c.FetchOperatorWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchOperatorWithContext(ctx context.Context, Sid string) (*IntelligenceV2Operator, error) { path := "/v2/Operators/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -33,7 +37,7 @@ func (c *ApiService) FetchOperator(Sid string) (*IntelligenceV2Operator, error) "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -79,6 +83,11 @@ func (params *ListOperatorParams) SetLimit(Limit int) *ListOperatorParams { // Retrieve a single page of Operator records from the API. Request is executed immediately. func (c *ApiService) PageOperator(params *ListOperatorParams, pageToken, pageNumber string) (*ListOperatorResponse, error) { + return c.PageOperatorWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Operator records from the API. Request is executed immediately. +func (c *ApiService) PageOperatorWithContext(ctx context.Context, params *ListOperatorParams, pageToken, pageNumber string) (*ListOperatorResponse, error) { path := "/v2/Operators" data := url.Values{} @@ -103,7 +112,7 @@ func (c *ApiService) PageOperator(params *ListOperatorParams, pageToken, pageNum data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -120,7 +129,12 @@ func (c *ApiService) PageOperator(params *ListOperatorParams, pageToken, pageNum // Lists Operator records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListOperator(params *ListOperatorParams) ([]IntelligenceV2Operator, error) { - response, errors := c.StreamOperator(params) + return c.ListOperatorWithContext(context.TODO(), params) +} + +// Lists Operator records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListOperatorWithContext(ctx context.Context, params *ListOperatorParams) ([]IntelligenceV2Operator, error) { + response, errors := c.StreamOperatorWithContext(ctx, params) records := make([]IntelligenceV2Operator, 0) for record := range response { @@ -136,6 +150,11 @@ func (c *ApiService) ListOperator(params *ListOperatorParams) ([]IntelligenceV2O // Streams Operator records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamOperator(params *ListOperatorParams) (chan IntelligenceV2Operator, chan error) { + return c.StreamOperatorWithContext(context.TODO(), params) +} + +// Streams Operator records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamOperatorWithContext(ctx context.Context, params *ListOperatorParams) (chan IntelligenceV2Operator, chan error) { if params == nil { params = &ListOperatorParams{} } @@ -144,19 +163,19 @@ func (c *ApiService) StreamOperator(params *ListOperatorParams) (chan Intelligen recordChannel := make(chan IntelligenceV2Operator, 1) errorChannel := make(chan error, 1) - response, err := c.PageOperator(params, "", "") + response, err := c.PageOperatorWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamOperator(response, params, recordChannel, errorChannel) + go c.streamOperatorWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamOperator(response *ListOperatorResponse, params *ListOperatorParams, recordChannel chan IntelligenceV2Operator, errorChannel chan error) { +func (c *ApiService) streamOperatorWithContext(ctx context.Context, response *ListOperatorResponse, params *ListOperatorParams, recordChannel chan IntelligenceV2Operator, errorChannel chan error) { curRecord := 1 for response != nil { @@ -171,7 +190,7 @@ func (c *ApiService) streamOperator(response *ListOperatorResponse, params *List } } - record, err := client.GetNext(c.baseURL, response, c.getNextListOperatorResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListOperatorResponseWithContext) if err != nil { errorChannel <- err break @@ -186,11 +205,11 @@ func (c *ApiService) streamOperator(response *ListOperatorResponse, params *List close(errorChannel) } -func (c *ApiService) getNextListOperatorResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListOperatorResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/intelligence/v2/operators_custom.go b/rest/intelligence/v2/operators_custom.go index df0814356..44c13ee41 100644 --- a/rest/intelligence/v2/operators_custom.go +++ b/rest/intelligence/v2/operators_custom.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -48,6 +49,9 @@ func (params *CreateCustomOperatorParams) SetConfig(Config map[string]interface{ // Create a new Custom Operator for the given Account func (c *ApiService) CreateCustomOperator(params *CreateCustomOperatorParams) (*IntelligenceV2CustomOperator, error) { + return c.CreateCustomOperatorWithContext(context.TODO(), params) +} +func (c *ApiService) CreateCustomOperatorWithContext(ctx context.Context, params *CreateCustomOperatorParams) (*IntelligenceV2CustomOperator, error) { path := "/v2/Operators/Custom" data := url.Values{} @@ -71,7 +75,7 @@ func (c *ApiService) CreateCustomOperator(params *CreateCustomOperatorParams) (* data.Set("Config", string(v)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -88,6 +92,9 @@ func (c *ApiService) CreateCustomOperator(params *CreateCustomOperatorParams) (* // Delete a specific Custom Operator. func (c *ApiService) DeleteCustomOperator(Sid string) error { + return c.DeleteCustomOperatorWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteCustomOperatorWithContext(ctx context.Context, Sid string) error { path := "/v2/Operators/Custom/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -96,7 +103,7 @@ func (c *ApiService) DeleteCustomOperator(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -108,6 +115,9 @@ func (c *ApiService) DeleteCustomOperator(Sid string) error { // Fetch a specific Custom Operator. func (c *ApiService) FetchCustomOperator(Sid string) (*IntelligenceV2CustomOperator, error) { + return c.FetchCustomOperatorWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchCustomOperatorWithContext(ctx context.Context, Sid string) (*IntelligenceV2CustomOperator, error) { path := "/v2/Operators/Custom/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -116,7 +126,7 @@ func (c *ApiService) FetchCustomOperator(Sid string) (*IntelligenceV2CustomOpera "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -162,6 +172,11 @@ func (params *ListCustomOperatorParams) SetLimit(Limit int) *ListCustomOperatorP // Retrieve a single page of CustomOperator records from the API. Request is executed immediately. func (c *ApiService) PageCustomOperator(params *ListCustomOperatorParams, pageToken, pageNumber string) (*ListCustomOperatorResponse, error) { + return c.PageCustomOperatorWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of CustomOperator records from the API. Request is executed immediately. +func (c *ApiService) PageCustomOperatorWithContext(ctx context.Context, params *ListCustomOperatorParams, pageToken, pageNumber string) (*ListCustomOperatorResponse, error) { path := "/v2/Operators/Custom" data := url.Values{} @@ -186,7 +201,7 @@ func (c *ApiService) PageCustomOperator(params *ListCustomOperatorParams, pageTo data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -203,7 +218,12 @@ func (c *ApiService) PageCustomOperator(params *ListCustomOperatorParams, pageTo // Lists CustomOperator records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListCustomOperator(params *ListCustomOperatorParams) ([]IntelligenceV2CustomOperator, error) { - response, errors := c.StreamCustomOperator(params) + return c.ListCustomOperatorWithContext(context.TODO(), params) +} + +// Lists CustomOperator records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListCustomOperatorWithContext(ctx context.Context, params *ListCustomOperatorParams) ([]IntelligenceV2CustomOperator, error) { + response, errors := c.StreamCustomOperatorWithContext(ctx, params) records := make([]IntelligenceV2CustomOperator, 0) for record := range response { @@ -219,6 +239,11 @@ func (c *ApiService) ListCustomOperator(params *ListCustomOperatorParams) ([]Int // Streams CustomOperator records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamCustomOperator(params *ListCustomOperatorParams) (chan IntelligenceV2CustomOperator, chan error) { + return c.StreamCustomOperatorWithContext(context.TODO(), params) +} + +// Streams CustomOperator records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamCustomOperatorWithContext(ctx context.Context, params *ListCustomOperatorParams) (chan IntelligenceV2CustomOperator, chan error) { if params == nil { params = &ListCustomOperatorParams{} } @@ -227,19 +252,19 @@ func (c *ApiService) StreamCustomOperator(params *ListCustomOperatorParams) (cha recordChannel := make(chan IntelligenceV2CustomOperator, 1) errorChannel := make(chan error, 1) - response, err := c.PageCustomOperator(params, "", "") + response, err := c.PageCustomOperatorWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamCustomOperator(response, params, recordChannel, errorChannel) + go c.streamCustomOperatorWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamCustomOperator(response *ListCustomOperatorResponse, params *ListCustomOperatorParams, recordChannel chan IntelligenceV2CustomOperator, errorChannel chan error) { +func (c *ApiService) streamCustomOperatorWithContext(ctx context.Context, response *ListCustomOperatorResponse, params *ListCustomOperatorParams, recordChannel chan IntelligenceV2CustomOperator, errorChannel chan error) { curRecord := 1 for response != nil { @@ -254,7 +279,7 @@ func (c *ApiService) streamCustomOperator(response *ListCustomOperatorResponse, } } - record, err := client.GetNext(c.baseURL, response, c.getNextListCustomOperatorResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListCustomOperatorResponseWithContext) if err != nil { errorChannel <- err break @@ -269,11 +294,11 @@ func (c *ApiService) streamCustomOperator(response *ListCustomOperatorResponse, close(errorChannel) } -func (c *ApiService) getNextListCustomOperatorResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListCustomOperatorResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -312,6 +337,9 @@ func (params *UpdateCustomOperatorParams) SetConfig(Config map[string]interface{ // Update a specific Custom Operator. func (c *ApiService) UpdateCustomOperator(Sid string, params *UpdateCustomOperatorParams) (*IntelligenceV2CustomOperator, error) { + return c.UpdateCustomOperatorWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateCustomOperatorWithContext(ctx context.Context, Sid string, params *UpdateCustomOperatorParams) (*IntelligenceV2CustomOperator, error) { path := "/v2/Operators/Custom/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -336,7 +364,7 @@ func (c *ApiService) UpdateCustomOperator(Sid string, params *UpdateCustomOperat if params != nil && params.IfMatch != nil { headers["If-Match"] = *params.IfMatch } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/intelligence/v2/operators_pre_built.go b/rest/intelligence/v2/operators_pre_built.go index 8bf7e5d7b..6f006dd79 100644 --- a/rest/intelligence/v2/operators_pre_built.go +++ b/rest/intelligence/v2/operators_pre_built.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -25,6 +26,9 @@ import ( // Fetch a specific Pre-built Operator. func (c *ApiService) FetchPrebuiltOperator(Sid string) (*IntelligenceV2PrebuiltOperator, error) { + return c.FetchPrebuiltOperatorWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchPrebuiltOperatorWithContext(ctx context.Context, Sid string) (*IntelligenceV2PrebuiltOperator, error) { path := "/v2/Operators/PreBuilt/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -33,7 +37,7 @@ func (c *ApiService) FetchPrebuiltOperator(Sid string) (*IntelligenceV2PrebuiltO "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -79,6 +83,11 @@ func (params *ListPrebuiltOperatorParams) SetLimit(Limit int) *ListPrebuiltOpera // Retrieve a single page of PrebuiltOperator records from the API. Request is executed immediately. func (c *ApiService) PagePrebuiltOperator(params *ListPrebuiltOperatorParams, pageToken, pageNumber string) (*ListPrebuiltOperatorResponse, error) { + return c.PagePrebuiltOperatorWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of PrebuiltOperator records from the API. Request is executed immediately. +func (c *ApiService) PagePrebuiltOperatorWithContext(ctx context.Context, params *ListPrebuiltOperatorParams, pageToken, pageNumber string) (*ListPrebuiltOperatorResponse, error) { path := "/v2/Operators/PreBuilt" data := url.Values{} @@ -103,7 +112,7 @@ func (c *ApiService) PagePrebuiltOperator(params *ListPrebuiltOperatorParams, pa data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -120,7 +129,12 @@ func (c *ApiService) PagePrebuiltOperator(params *ListPrebuiltOperatorParams, pa // Lists PrebuiltOperator records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListPrebuiltOperator(params *ListPrebuiltOperatorParams) ([]IntelligenceV2PrebuiltOperator, error) { - response, errors := c.StreamPrebuiltOperator(params) + return c.ListPrebuiltOperatorWithContext(context.TODO(), params) +} + +// Lists PrebuiltOperator records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListPrebuiltOperatorWithContext(ctx context.Context, params *ListPrebuiltOperatorParams) ([]IntelligenceV2PrebuiltOperator, error) { + response, errors := c.StreamPrebuiltOperatorWithContext(ctx, params) records := make([]IntelligenceV2PrebuiltOperator, 0) for record := range response { @@ -136,6 +150,11 @@ func (c *ApiService) ListPrebuiltOperator(params *ListPrebuiltOperatorParams) ([ // Streams PrebuiltOperator records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamPrebuiltOperator(params *ListPrebuiltOperatorParams) (chan IntelligenceV2PrebuiltOperator, chan error) { + return c.StreamPrebuiltOperatorWithContext(context.TODO(), params) +} + +// Streams PrebuiltOperator records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamPrebuiltOperatorWithContext(ctx context.Context, params *ListPrebuiltOperatorParams) (chan IntelligenceV2PrebuiltOperator, chan error) { if params == nil { params = &ListPrebuiltOperatorParams{} } @@ -144,19 +163,19 @@ func (c *ApiService) StreamPrebuiltOperator(params *ListPrebuiltOperatorParams) recordChannel := make(chan IntelligenceV2PrebuiltOperator, 1) errorChannel := make(chan error, 1) - response, err := c.PagePrebuiltOperator(params, "", "") + response, err := c.PagePrebuiltOperatorWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamPrebuiltOperator(response, params, recordChannel, errorChannel) + go c.streamPrebuiltOperatorWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamPrebuiltOperator(response *ListPrebuiltOperatorResponse, params *ListPrebuiltOperatorParams, recordChannel chan IntelligenceV2PrebuiltOperator, errorChannel chan error) { +func (c *ApiService) streamPrebuiltOperatorWithContext(ctx context.Context, response *ListPrebuiltOperatorResponse, params *ListPrebuiltOperatorParams, recordChannel chan IntelligenceV2PrebuiltOperator, errorChannel chan error) { curRecord := 1 for response != nil { @@ -171,7 +190,7 @@ func (c *ApiService) streamPrebuiltOperator(response *ListPrebuiltOperatorRespon } } - record, err := client.GetNext(c.baseURL, response, c.getNextListPrebuiltOperatorResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListPrebuiltOperatorResponseWithContext) if err != nil { errorChannel <- err break @@ -186,11 +205,11 @@ func (c *ApiService) streamPrebuiltOperator(response *ListPrebuiltOperatorRespon close(errorChannel) } -func (c *ApiService) getNextListPrebuiltOperatorResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListPrebuiltOperatorResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/intelligence/v2/services.go b/rest/intelligence/v2/services.go index 294a15661..d8e416eb8 100644 --- a/rest/intelligence/v2/services.go +++ b/rest/intelligence/v2/services.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -84,6 +85,9 @@ func (params *CreateServiceParams) SetWebhookHttpMethod(WebhookHttpMethod string // Create a new Service for the given Account func (c *ApiService) CreateService(params *CreateServiceParams) (*IntelligenceV2Service, error) { + return c.CreateServiceWithContext(context.TODO(), params) +} +func (c *ApiService) CreateServiceWithContext(ctx context.Context, params *CreateServiceParams) (*IntelligenceV2Service, error) { path := "/v2/Services" data := url.Values{} @@ -119,7 +123,7 @@ func (c *ApiService) CreateService(params *CreateServiceParams) (*IntelligenceV2 data.Set("WebhookHttpMethod", fmt.Sprint(*params.WebhookHttpMethod)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -136,6 +140,9 @@ func (c *ApiService) CreateService(params *CreateServiceParams) (*IntelligenceV2 // Delete a specific Service. func (c *ApiService) DeleteService(Sid string) error { + return c.DeleteServiceWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteServiceWithContext(ctx context.Context, Sid string) error { path := "/v2/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -144,7 +151,7 @@ func (c *ApiService) DeleteService(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -156,6 +163,9 @@ func (c *ApiService) DeleteService(Sid string) error { // Fetch a specific Service. func (c *ApiService) FetchService(Sid string) (*IntelligenceV2Service, error) { + return c.FetchServiceWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchServiceWithContext(ctx context.Context, Sid string) (*IntelligenceV2Service, error) { path := "/v2/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -164,7 +174,7 @@ func (c *ApiService) FetchService(Sid string) (*IntelligenceV2Service, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -198,6 +208,11 @@ func (params *ListServiceParams) SetLimit(Limit int) *ListServiceParams { // Retrieve a single page of Service records from the API. Request is executed immediately. func (c *ApiService) PageService(params *ListServiceParams, pageToken, pageNumber string) (*ListServiceResponse, error) { + return c.PageServiceWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Service records from the API. Request is executed immediately. +func (c *ApiService) PageServiceWithContext(ctx context.Context, params *ListServiceParams, pageToken, pageNumber string) (*ListServiceResponse, error) { path := "/v2/Services" data := url.Values{} @@ -216,7 +231,7 @@ func (c *ApiService) PageService(params *ListServiceParams, pageToken, pageNumbe data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -233,7 +248,12 @@ func (c *ApiService) PageService(params *ListServiceParams, pageToken, pageNumbe // Lists Service records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListService(params *ListServiceParams) ([]IntelligenceV2Service, error) { - response, errors := c.StreamService(params) + return c.ListServiceWithContext(context.TODO(), params) +} + +// Lists Service records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListServiceWithContext(ctx context.Context, params *ListServiceParams) ([]IntelligenceV2Service, error) { + response, errors := c.StreamServiceWithContext(ctx, params) records := make([]IntelligenceV2Service, 0) for record := range response { @@ -249,6 +269,11 @@ func (c *ApiService) ListService(params *ListServiceParams) ([]IntelligenceV2Ser // Streams Service records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamService(params *ListServiceParams) (chan IntelligenceV2Service, chan error) { + return c.StreamServiceWithContext(context.TODO(), params) +} + +// Streams Service records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamServiceWithContext(ctx context.Context, params *ListServiceParams) (chan IntelligenceV2Service, chan error) { if params == nil { params = &ListServiceParams{} } @@ -257,19 +282,19 @@ func (c *ApiService) StreamService(params *ListServiceParams) (chan Intelligence recordChannel := make(chan IntelligenceV2Service, 1) errorChannel := make(chan error, 1) - response, err := c.PageService(params, "", "") + response, err := c.PageServiceWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamService(response, params, recordChannel, errorChannel) + go c.streamServiceWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamService(response *ListServiceResponse, params *ListServiceParams, recordChannel chan IntelligenceV2Service, errorChannel chan error) { +func (c *ApiService) streamServiceWithContext(ctx context.Context, response *ListServiceResponse, params *ListServiceParams, recordChannel chan IntelligenceV2Service, errorChannel chan error) { curRecord := 1 for response != nil { @@ -284,7 +309,7 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListServiceResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListServiceResponseWithContext) if err != nil { errorChannel <- err break @@ -299,11 +324,11 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe close(errorChannel) } -func (c *ApiService) getNextListServiceResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListServiceResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -378,6 +403,9 @@ func (params *UpdateServiceParams) SetWebhookHttpMethod(WebhookHttpMethod string // Update a specific Service. func (c *ApiService) UpdateService(Sid string, params *UpdateServiceParams) (*IntelligenceV2Service, error) { + return c.UpdateServiceWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateServiceWithContext(ctx context.Context, Sid string, params *UpdateServiceParams) (*IntelligenceV2Service, error) { path := "/v2/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -414,7 +442,7 @@ func (c *ApiService) UpdateService(Sid string, params *UpdateServiceParams) (*In if params != nil && params.IfMatch != nil { headers["If-Match"] = *params.IfMatch } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/intelligence/v2/services_operators.go b/rest/intelligence/v2/services_operators.go index 6ecfd89ea..6ef5a2381 100644 --- a/rest/intelligence/v2/services_operators.go +++ b/rest/intelligence/v2/services_operators.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -22,6 +23,9 @@ import ( // Attach an Operator to a Service. func (c *ApiService) CreateOperatorAttachment(ServiceSid string, OperatorSid string) (*IntelligenceV2OperatorAttachment, error) { + return c.CreateOperatorAttachmentWithContext(context.TODO(), ServiceSid, OperatorSid) +} +func (c *ApiService) CreateOperatorAttachmentWithContext(ctx context.Context, ServiceSid string, OperatorSid string) (*IntelligenceV2OperatorAttachment, error) { path := "/v2/Services/{ServiceSid}/Operators/{OperatorSid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"OperatorSid"+"}", OperatorSid, -1) @@ -31,7 +35,7 @@ func (c *ApiService) CreateOperatorAttachment(ServiceSid string, OperatorSid str "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -48,6 +52,9 @@ func (c *ApiService) CreateOperatorAttachment(ServiceSid string, OperatorSid str // Detach an Operator from a Service. func (c *ApiService) DeleteOperatorAttachment(ServiceSid string, OperatorSid string) error { + return c.DeleteOperatorAttachmentWithContext(context.TODO(), ServiceSid, OperatorSid) +} +func (c *ApiService) DeleteOperatorAttachmentWithContext(ctx context.Context, ServiceSid string, OperatorSid string) error { path := "/v2/Services/{ServiceSid}/Operators/{OperatorSid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"OperatorSid"+"}", OperatorSid, -1) @@ -57,7 +64,7 @@ func (c *ApiService) DeleteOperatorAttachment(ServiceSid string, OperatorSid str "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -69,6 +76,9 @@ func (c *ApiService) DeleteOperatorAttachment(ServiceSid string, OperatorSid str // Retrieve Operators attached to a Service. func (c *ApiService) FetchOperatorAttachments(ServiceSid string) (*IntelligenceV2OperatorAttachments, error) { + return c.FetchOperatorAttachmentsWithContext(context.TODO(), ServiceSid) +} +func (c *ApiService) FetchOperatorAttachmentsWithContext(ctx context.Context, ServiceSid string) (*IntelligenceV2OperatorAttachments, error) { path := "/v2/Services/{ServiceSid}/Operators" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -77,7 +87,7 @@ func (c *ApiService) FetchOperatorAttachments(ServiceSid string) (*IntelligenceV "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/intelligence/v2/transcripts.go b/rest/intelligence/v2/transcripts.go index ec8fc20fb..d09212274 100644 --- a/rest/intelligence/v2/transcripts.go +++ b/rest/intelligence/v2/transcripts.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -55,6 +56,9 @@ func (params *CreateTranscriptParams) SetMediaStartTime(MediaStartTime time.Time // Create a new Transcript for the service func (c *ApiService) CreateTranscript(params *CreateTranscriptParams) (*IntelligenceV2Transcript, error) { + return c.CreateTranscriptWithContext(context.TODO(), params) +} +func (c *ApiService) CreateTranscriptWithContext(ctx context.Context, params *CreateTranscriptParams) (*IntelligenceV2Transcript, error) { path := "/v2/Transcripts" data := url.Values{} @@ -81,7 +85,7 @@ func (c *ApiService) CreateTranscript(params *CreateTranscriptParams) (*Intellig data.Set("MediaStartTime", fmt.Sprint((*params.MediaStartTime).Format(time.RFC3339))) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -98,6 +102,9 @@ func (c *ApiService) CreateTranscript(params *CreateTranscriptParams) (*Intellig // Delete a specific Transcript. func (c *ApiService) DeleteTranscript(Sid string) error { + return c.DeleteTranscriptWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteTranscriptWithContext(ctx context.Context, Sid string) error { path := "/v2/Transcripts/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -106,7 +113,7 @@ func (c *ApiService) DeleteTranscript(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -118,6 +125,9 @@ func (c *ApiService) DeleteTranscript(Sid string) error { // Fetch a specific Transcript. func (c *ApiService) FetchTranscript(Sid string) (*IntelligenceV2Transcript, error) { + return c.FetchTranscriptWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchTranscriptWithContext(ctx context.Context, Sid string) (*IntelligenceV2Transcript, error) { path := "/v2/Transcripts/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -126,7 +136,7 @@ func (c *ApiService) FetchTranscript(Sid string) (*IntelligenceV2Transcript, err "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -208,6 +218,11 @@ func (params *ListTranscriptParams) SetLimit(Limit int) *ListTranscriptParams { // Retrieve a single page of Transcript records from the API. Request is executed immediately. func (c *ApiService) PageTranscript(params *ListTranscriptParams, pageToken, pageNumber string) (*ListTranscriptResponse, error) { + return c.PageTranscriptWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Transcript records from the API. Request is executed immediately. +func (c *ApiService) PageTranscriptWithContext(ctx context.Context, params *ListTranscriptParams, pageToken, pageNumber string) (*ListTranscriptResponse, error) { path := "/v2/Transcripts" data := url.Values{} @@ -250,7 +265,7 @@ func (c *ApiService) PageTranscript(params *ListTranscriptParams, pageToken, pag data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -267,7 +282,12 @@ func (c *ApiService) PageTranscript(params *ListTranscriptParams, pageToken, pag // Lists Transcript records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListTranscript(params *ListTranscriptParams) ([]IntelligenceV2Transcript, error) { - response, errors := c.StreamTranscript(params) + return c.ListTranscriptWithContext(context.TODO(), params) +} + +// Lists Transcript records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListTranscriptWithContext(ctx context.Context, params *ListTranscriptParams) ([]IntelligenceV2Transcript, error) { + response, errors := c.StreamTranscriptWithContext(ctx, params) records := make([]IntelligenceV2Transcript, 0) for record := range response { @@ -283,6 +303,11 @@ func (c *ApiService) ListTranscript(params *ListTranscriptParams) ([]Intelligenc // Streams Transcript records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamTranscript(params *ListTranscriptParams) (chan IntelligenceV2Transcript, chan error) { + return c.StreamTranscriptWithContext(context.TODO(), params) +} + +// Streams Transcript records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamTranscriptWithContext(ctx context.Context, params *ListTranscriptParams) (chan IntelligenceV2Transcript, chan error) { if params == nil { params = &ListTranscriptParams{} } @@ -291,19 +316,19 @@ func (c *ApiService) StreamTranscript(params *ListTranscriptParams) (chan Intell recordChannel := make(chan IntelligenceV2Transcript, 1) errorChannel := make(chan error, 1) - response, err := c.PageTranscript(params, "", "") + response, err := c.PageTranscriptWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamTranscript(response, params, recordChannel, errorChannel) + go c.streamTranscriptWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamTranscript(response *ListTranscriptResponse, params *ListTranscriptParams, recordChannel chan IntelligenceV2Transcript, errorChannel chan error) { +func (c *ApiService) streamTranscriptWithContext(ctx context.Context, response *ListTranscriptResponse, params *ListTranscriptParams, recordChannel chan IntelligenceV2Transcript, errorChannel chan error) { curRecord := 1 for response != nil { @@ -318,7 +343,7 @@ func (c *ApiService) streamTranscript(response *ListTranscriptResponse, params * } } - record, err := client.GetNext(c.baseURL, response, c.getNextListTranscriptResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListTranscriptResponseWithContext) if err != nil { errorChannel <- err break @@ -333,11 +358,11 @@ func (c *ApiService) streamTranscript(response *ListTranscriptResponse, params * close(errorChannel) } -func (c *ApiService) getNextListTranscriptResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListTranscriptResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/intelligence/v2/transcripts_media.go b/rest/intelligence/v2/transcripts_media.go index 0b7269fc7..68795114c 100644 --- a/rest/intelligence/v2/transcripts_media.go +++ b/rest/intelligence/v2/transcripts_media.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -34,6 +35,9 @@ func (params *FetchMediaParams) SetRedacted(Redacted bool) *FetchMediaParams { // Get download URLs for media if possible func (c *ApiService) FetchMedia(Sid string, params *FetchMediaParams) (*IntelligenceV2Media, error) { + return c.FetchMediaWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) FetchMediaWithContext(ctx context.Context, Sid string, params *FetchMediaParams) (*IntelligenceV2Media, error) { path := "/v2/Transcripts/{Sid}/Media" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -46,7 +50,7 @@ func (c *ApiService) FetchMedia(Sid string, params *FetchMediaParams) (*Intellig data.Set("Redacted", fmt.Sprint(*params.Redacted)) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/intelligence/v2/transcripts_operator_results.go b/rest/intelligence/v2/transcripts_operator_results.go index 26977e025..91eccd956 100644 --- a/rest/intelligence/v2/transcripts_operator_results.go +++ b/rest/intelligence/v2/transcripts_operator_results.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -36,6 +37,9 @@ func (params *FetchOperatorResultParams) SetRedacted(Redacted bool) *FetchOperat // Fetch a specific Operator Result for the given Transcript. func (c *ApiService) FetchOperatorResult(TranscriptSid string, OperatorSid string, params *FetchOperatorResultParams) (*IntelligenceV2OperatorResult, error) { + return c.FetchOperatorResultWithContext(context.TODO(), TranscriptSid, OperatorSid, params) +} +func (c *ApiService) FetchOperatorResultWithContext(ctx context.Context, TranscriptSid string, OperatorSid string, params *FetchOperatorResultParams) (*IntelligenceV2OperatorResult, error) { path := "/v2/Transcripts/{TranscriptSid}/OperatorResults/{OperatorSid}" path = strings.Replace(path, "{"+"TranscriptSid"+"}", TranscriptSid, -1) path = strings.Replace(path, "{"+"OperatorSid"+"}", OperatorSid, -1) @@ -49,7 +53,7 @@ func (c *ApiService) FetchOperatorResult(TranscriptSid string, OperatorSid strin data.Set("Redacted", fmt.Sprint(*params.Redacted)) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -89,6 +93,11 @@ func (params *ListOperatorResultParams) SetLimit(Limit int) *ListOperatorResultP // Retrieve a single page of OperatorResult records from the API. Request is executed immediately. func (c *ApiService) PageOperatorResult(TranscriptSid string, params *ListOperatorResultParams, pageToken, pageNumber string) (*ListOperatorResultResponse, error) { + return c.PageOperatorResultWithContext(context.TODO(), TranscriptSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of OperatorResult records from the API. Request is executed immediately. +func (c *ApiService) PageOperatorResultWithContext(ctx context.Context, TranscriptSid string, params *ListOperatorResultParams, pageToken, pageNumber string) (*ListOperatorResultResponse, error) { path := "/v2/Transcripts/{TranscriptSid}/OperatorResults" path = strings.Replace(path, "{"+"TranscriptSid"+"}", TranscriptSid, -1) @@ -112,7 +121,7 @@ func (c *ApiService) PageOperatorResult(TranscriptSid string, params *ListOperat data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -129,7 +138,12 @@ func (c *ApiService) PageOperatorResult(TranscriptSid string, params *ListOperat // Lists OperatorResult records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListOperatorResult(TranscriptSid string, params *ListOperatorResultParams) ([]IntelligenceV2OperatorResult, error) { - response, errors := c.StreamOperatorResult(TranscriptSid, params) + return c.ListOperatorResultWithContext(context.TODO(), TranscriptSid, params) +} + +// Lists OperatorResult records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListOperatorResultWithContext(ctx context.Context, TranscriptSid string, params *ListOperatorResultParams) ([]IntelligenceV2OperatorResult, error) { + response, errors := c.StreamOperatorResultWithContext(ctx, TranscriptSid, params) records := make([]IntelligenceV2OperatorResult, 0) for record := range response { @@ -145,6 +159,11 @@ func (c *ApiService) ListOperatorResult(TranscriptSid string, params *ListOperat // Streams OperatorResult records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamOperatorResult(TranscriptSid string, params *ListOperatorResultParams) (chan IntelligenceV2OperatorResult, chan error) { + return c.StreamOperatorResultWithContext(context.TODO(), TranscriptSid, params) +} + +// Streams OperatorResult records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamOperatorResultWithContext(ctx context.Context, TranscriptSid string, params *ListOperatorResultParams) (chan IntelligenceV2OperatorResult, chan error) { if params == nil { params = &ListOperatorResultParams{} } @@ -153,19 +172,19 @@ func (c *ApiService) StreamOperatorResult(TranscriptSid string, params *ListOper recordChannel := make(chan IntelligenceV2OperatorResult, 1) errorChannel := make(chan error, 1) - response, err := c.PageOperatorResult(TranscriptSid, params, "", "") + response, err := c.PageOperatorResultWithContext(ctx, TranscriptSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamOperatorResult(response, params, recordChannel, errorChannel) + go c.streamOperatorResultWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamOperatorResult(response *ListOperatorResultResponse, params *ListOperatorResultParams, recordChannel chan IntelligenceV2OperatorResult, errorChannel chan error) { +func (c *ApiService) streamOperatorResultWithContext(ctx context.Context, response *ListOperatorResultResponse, params *ListOperatorResultParams, recordChannel chan IntelligenceV2OperatorResult, errorChannel chan error) { curRecord := 1 for response != nil { @@ -180,7 +199,7 @@ func (c *ApiService) streamOperatorResult(response *ListOperatorResultResponse, } } - record, err := client.GetNext(c.baseURL, response, c.getNextListOperatorResultResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListOperatorResultResponseWithContext) if err != nil { errorChannel <- err break @@ -195,11 +214,11 @@ func (c *ApiService) streamOperatorResult(response *ListOperatorResultResponse, close(errorChannel) } -func (c *ApiService) getNextListOperatorResultResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListOperatorResultResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/intelligence/v2/transcripts_sentences.go b/rest/intelligence/v2/transcripts_sentences.go index 6b048ac3d..9b761c838 100644 --- a/rest/intelligence/v2/transcripts_sentences.go +++ b/rest/intelligence/v2/transcripts_sentences.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -54,6 +55,11 @@ func (params *ListSentenceParams) SetLimit(Limit int) *ListSentenceParams { // Retrieve a single page of Sentence records from the API. Request is executed immediately. func (c *ApiService) PageSentence(TranscriptSid string, params *ListSentenceParams, pageToken, pageNumber string) (*ListSentenceResponse, error) { + return c.PageSentenceWithContext(context.TODO(), TranscriptSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Sentence records from the API. Request is executed immediately. +func (c *ApiService) PageSentenceWithContext(ctx context.Context, TranscriptSid string, params *ListSentenceParams, pageToken, pageNumber string) (*ListSentenceResponse, error) { path := "/v2/Transcripts/{TranscriptSid}/Sentences" path = strings.Replace(path, "{"+"TranscriptSid"+"}", TranscriptSid, -1) @@ -80,7 +86,7 @@ func (c *ApiService) PageSentence(TranscriptSid string, params *ListSentencePara data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -97,7 +103,12 @@ func (c *ApiService) PageSentence(TranscriptSid string, params *ListSentencePara // Lists Sentence records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListSentence(TranscriptSid string, params *ListSentenceParams) ([]IntelligenceV2Sentence, error) { - response, errors := c.StreamSentence(TranscriptSid, params) + return c.ListSentenceWithContext(context.TODO(), TranscriptSid, params) +} + +// Lists Sentence records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListSentenceWithContext(ctx context.Context, TranscriptSid string, params *ListSentenceParams) ([]IntelligenceV2Sentence, error) { + response, errors := c.StreamSentenceWithContext(ctx, TranscriptSid, params) records := make([]IntelligenceV2Sentence, 0) for record := range response { @@ -113,6 +124,11 @@ func (c *ApiService) ListSentence(TranscriptSid string, params *ListSentencePara // Streams Sentence records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamSentence(TranscriptSid string, params *ListSentenceParams) (chan IntelligenceV2Sentence, chan error) { + return c.StreamSentenceWithContext(context.TODO(), TranscriptSid, params) +} + +// Streams Sentence records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamSentenceWithContext(ctx context.Context, TranscriptSid string, params *ListSentenceParams) (chan IntelligenceV2Sentence, chan error) { if params == nil { params = &ListSentenceParams{} } @@ -121,19 +137,19 @@ func (c *ApiService) StreamSentence(TranscriptSid string, params *ListSentencePa recordChannel := make(chan IntelligenceV2Sentence, 1) errorChannel := make(chan error, 1) - response, err := c.PageSentence(TranscriptSid, params, "", "") + response, err := c.PageSentenceWithContext(ctx, TranscriptSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSentence(response, params, recordChannel, errorChannel) + go c.streamSentenceWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamSentence(response *ListSentenceResponse, params *ListSentenceParams, recordChannel chan IntelligenceV2Sentence, errorChannel chan error) { +func (c *ApiService) streamSentenceWithContext(ctx context.Context, response *ListSentenceResponse, params *ListSentenceParams, recordChannel chan IntelligenceV2Sentence, errorChannel chan error) { curRecord := 1 for response != nil { @@ -148,7 +164,7 @@ func (c *ApiService) streamSentence(response *ListSentenceResponse, params *List } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSentenceResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListSentenceResponseWithContext) if err != nil { errorChannel <- err break @@ -163,11 +179,11 @@ func (c *ApiService) streamSentence(response *ListSentenceResponse, params *List close(errorChannel) } -func (c *ApiService) getNextListSentenceResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSentenceResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/ip_messaging/v1/api_service.go b/rest/ip_messaging/v1/api_service.go index e7f59ad5a..b659cfd13 100644 --- a/rest/ip_messaging/v1/api_service.go +++ b/rest/ip_messaging/v1/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://ip-messaging.twilio.com", + } +} diff --git a/rest/ip_messaging/v1/credentials.go b/rest/ip_messaging/v1/credentials.go index b17ff8c07..69cdf7886 100644 --- a/rest/ip_messaging/v1/credentials.go +++ b/rest/ip_messaging/v1/credentials.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -70,8 +71,10 @@ func (params *CreateCredentialParams) SetSecret(Secret string) *CreateCredential return params } -// func (c *ApiService) CreateCredential(params *CreateCredentialParams) (*IpMessagingV1Credential, error) { + return c.CreateCredentialWithContext(context.TODO(), params) +} +func (c *ApiService) CreateCredentialWithContext(ctx context.Context, params *CreateCredentialParams) (*IpMessagingV1Credential, error) { path := "/v1/Credentials" data := url.Values{} @@ -101,7 +104,7 @@ func (c *ApiService) CreateCredential(params *CreateCredentialParams) (*IpMessag data.Set("Secret", *params.Secret) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -116,8 +119,10 @@ func (c *ApiService) CreateCredential(params *CreateCredentialParams) (*IpMessag return ps, err } -// func (c *ApiService) DeleteCredential(Sid string) error { + return c.DeleteCredentialWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteCredentialWithContext(ctx context.Context, Sid string) error { path := "/v1/Credentials/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -126,7 +131,7 @@ func (c *ApiService) DeleteCredential(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -136,8 +141,10 @@ func (c *ApiService) DeleteCredential(Sid string) error { return nil } -// func (c *ApiService) FetchCredential(Sid string) (*IpMessagingV1Credential, error) { + return c.FetchCredentialWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchCredentialWithContext(ctx context.Context, Sid string) (*IpMessagingV1Credential, error) { path := "/v1/Credentials/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -146,7 +153,7 @@ func (c *ApiService) FetchCredential(Sid string) (*IpMessagingV1Credential, erro "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -180,6 +187,11 @@ func (params *ListCredentialParams) SetLimit(Limit int) *ListCredentialParams { // Retrieve a single page of Credential records from the API. Request is executed immediately. func (c *ApiService) PageCredential(params *ListCredentialParams, pageToken, pageNumber string) (*ListCredentialResponse, error) { + return c.PageCredentialWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Credential records from the API. Request is executed immediately. +func (c *ApiService) PageCredentialWithContext(ctx context.Context, params *ListCredentialParams, pageToken, pageNumber string) (*ListCredentialResponse, error) { path := "/v1/Credentials" data := url.Values{} @@ -198,7 +210,7 @@ func (c *ApiService) PageCredential(params *ListCredentialParams, pageToken, pag data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -215,7 +227,12 @@ func (c *ApiService) PageCredential(params *ListCredentialParams, pageToken, pag // Lists Credential records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListCredential(params *ListCredentialParams) ([]IpMessagingV1Credential, error) { - response, errors := c.StreamCredential(params) + return c.ListCredentialWithContext(context.TODO(), params) +} + +// Lists Credential records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListCredentialWithContext(ctx context.Context, params *ListCredentialParams) ([]IpMessagingV1Credential, error) { + response, errors := c.StreamCredentialWithContext(ctx, params) records := make([]IpMessagingV1Credential, 0) for record := range response { @@ -231,6 +248,11 @@ func (c *ApiService) ListCredential(params *ListCredentialParams) ([]IpMessaging // Streams Credential records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamCredential(params *ListCredentialParams) (chan IpMessagingV1Credential, chan error) { + return c.StreamCredentialWithContext(context.TODO(), params) +} + +// Streams Credential records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamCredentialWithContext(ctx context.Context, params *ListCredentialParams) (chan IpMessagingV1Credential, chan error) { if params == nil { params = &ListCredentialParams{} } @@ -239,19 +261,19 @@ func (c *ApiService) StreamCredential(params *ListCredentialParams) (chan IpMess recordChannel := make(chan IpMessagingV1Credential, 1) errorChannel := make(chan error, 1) - response, err := c.PageCredential(params, "", "") + response, err := c.PageCredentialWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamCredential(response, params, recordChannel, errorChannel) + go c.streamCredentialWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamCredential(response *ListCredentialResponse, params *ListCredentialParams, recordChannel chan IpMessagingV1Credential, errorChannel chan error) { +func (c *ApiService) streamCredentialWithContext(ctx context.Context, response *ListCredentialResponse, params *ListCredentialParams, recordChannel chan IpMessagingV1Credential, errorChannel chan error) { curRecord := 1 for response != nil { @@ -266,7 +288,7 @@ func (c *ApiService) streamCredential(response *ListCredentialResponse, params * } } - record, err := client.GetNext(c.baseURL, response, c.getNextListCredentialResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListCredentialResponseWithContext) if err != nil { errorChannel <- err break @@ -281,11 +303,11 @@ func (c *ApiService) streamCredential(response *ListCredentialResponse, params * close(errorChannel) } -func (c *ApiService) getNextListCredentialResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListCredentialResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -340,8 +362,10 @@ func (params *UpdateCredentialParams) SetSecret(Secret string) *UpdateCredential return params } -// func (c *ApiService) UpdateCredential(Sid string, params *UpdateCredentialParams) (*IpMessagingV1Credential, error) { + return c.UpdateCredentialWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateCredentialWithContext(ctx context.Context, Sid string, params *UpdateCredentialParams) (*IpMessagingV1Credential, error) { path := "/v1/Credentials/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -369,7 +393,7 @@ func (c *ApiService) UpdateCredential(Sid string, params *UpdateCredentialParams data.Set("Secret", *params.Secret) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/ip_messaging/v1/services.go b/rest/ip_messaging/v1/services.go index de3290510..f22c253cc 100644 --- a/rest/ip_messaging/v1/services.go +++ b/rest/ip_messaging/v1/services.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -34,8 +35,10 @@ func (params *CreateServiceParams) SetFriendlyName(FriendlyName string) *CreateS return params } -// func (c *ApiService) CreateService(params *CreateServiceParams) (*IpMessagingV1Service, error) { + return c.CreateServiceWithContext(context.TODO(), params) +} +func (c *ApiService) CreateServiceWithContext(ctx context.Context, params *CreateServiceParams) (*IpMessagingV1Service, error) { path := "/v1/Services" data := url.Values{} @@ -47,7 +50,7 @@ func (c *ApiService) CreateService(params *CreateServiceParams) (*IpMessagingV1S data.Set("FriendlyName", *params.FriendlyName) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -62,8 +65,10 @@ func (c *ApiService) CreateService(params *CreateServiceParams) (*IpMessagingV1S return ps, err } -// func (c *ApiService) DeleteService(Sid string) error { + return c.DeleteServiceWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteServiceWithContext(ctx context.Context, Sid string) error { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -72,7 +77,7 @@ func (c *ApiService) DeleteService(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -82,8 +87,10 @@ func (c *ApiService) DeleteService(Sid string) error { return nil } -// func (c *ApiService) FetchService(Sid string) (*IpMessagingV1Service, error) { + return c.FetchServiceWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchServiceWithContext(ctx context.Context, Sid string) (*IpMessagingV1Service, error) { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -92,7 +99,7 @@ func (c *ApiService) FetchService(Sid string) (*IpMessagingV1Service, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -126,6 +133,11 @@ func (params *ListServiceParams) SetLimit(Limit int) *ListServiceParams { // Retrieve a single page of Service records from the API. Request is executed immediately. func (c *ApiService) PageService(params *ListServiceParams, pageToken, pageNumber string) (*ListServiceResponse, error) { + return c.PageServiceWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Service records from the API. Request is executed immediately. +func (c *ApiService) PageServiceWithContext(ctx context.Context, params *ListServiceParams, pageToken, pageNumber string) (*ListServiceResponse, error) { path := "/v1/Services" data := url.Values{} @@ -144,7 +156,7 @@ func (c *ApiService) PageService(params *ListServiceParams, pageToken, pageNumbe data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -161,7 +173,12 @@ func (c *ApiService) PageService(params *ListServiceParams, pageToken, pageNumbe // Lists Service records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListService(params *ListServiceParams) ([]IpMessagingV1Service, error) { - response, errors := c.StreamService(params) + return c.ListServiceWithContext(context.TODO(), params) +} + +// Lists Service records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListServiceWithContext(ctx context.Context, params *ListServiceParams) ([]IpMessagingV1Service, error) { + response, errors := c.StreamServiceWithContext(ctx, params) records := make([]IpMessagingV1Service, 0) for record := range response { @@ -177,6 +194,11 @@ func (c *ApiService) ListService(params *ListServiceParams) ([]IpMessagingV1Serv // Streams Service records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamService(params *ListServiceParams) (chan IpMessagingV1Service, chan error) { + return c.StreamServiceWithContext(context.TODO(), params) +} + +// Streams Service records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamServiceWithContext(ctx context.Context, params *ListServiceParams) (chan IpMessagingV1Service, chan error) { if params == nil { params = &ListServiceParams{} } @@ -185,19 +207,19 @@ func (c *ApiService) StreamService(params *ListServiceParams) (chan IpMessagingV recordChannel := make(chan IpMessagingV1Service, 1) errorChannel := make(chan error, 1) - response, err := c.PageService(params, "", "") + response, err := c.PageServiceWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamService(response, params, recordChannel, errorChannel) + go c.streamServiceWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamService(response *ListServiceResponse, params *ListServiceParams, recordChannel chan IpMessagingV1Service, errorChannel chan error) { +func (c *ApiService) streamServiceWithContext(ctx context.Context, response *ListServiceResponse, params *ListServiceParams, recordChannel chan IpMessagingV1Service, errorChannel chan error) { curRecord := 1 for response != nil { @@ -212,7 +234,7 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListServiceResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListServiceResponseWithContext) if err != nil { errorChannel <- err break @@ -227,11 +249,11 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe close(errorChannel) } -func (c *ApiService) getNextListServiceResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListServiceResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -574,8 +596,10 @@ func (params *UpdateServiceParams) SetLimitsUserChannels(LimitsUserChannels int) return params } -// func (c *ApiService) UpdateService(Sid string, params *UpdateServiceParams) (*IpMessagingV1Service, error) { + return c.UpdateServiceWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateServiceWithContext(ctx context.Context, Sid string, params *UpdateServiceParams) (*IpMessagingV1Service, error) { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -749,7 +773,7 @@ func (c *ApiService) UpdateService(Sid string, params *UpdateServiceParams) (*Ip data.Set("Limits.UserChannels", fmt.Sprint(*params.LimitsUserChannels)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/ip_messaging/v1/services_channels.go b/rest/ip_messaging/v1/services_channels.go index 18b248ccb..b944c76b2 100644 --- a/rest/ip_messaging/v1/services_channels.go +++ b/rest/ip_messaging/v1/services_channels.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -52,8 +53,10 @@ func (params *CreateChannelParams) SetType(Type string) *CreateChannelParams { return params } -// func (c *ApiService) CreateChannel(ServiceSid string, params *CreateChannelParams) (*IpMessagingV1Channel, error) { + return c.CreateChannelWithContext(context.TODO(), ServiceSid, params) +} +func (c *ApiService) CreateChannelWithContext(ctx context.Context, ServiceSid string, params *CreateChannelParams) (*IpMessagingV1Channel, error) { path := "/v1/Services/{ServiceSid}/Channels" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -75,7 +78,7 @@ func (c *ApiService) CreateChannel(ServiceSid string, params *CreateChannelParam data.Set("Type", fmt.Sprint(*params.Type)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -90,8 +93,10 @@ func (c *ApiService) CreateChannel(ServiceSid string, params *CreateChannelParam return ps, err } -// func (c *ApiService) DeleteChannel(ServiceSid string, Sid string) error { + return c.DeleteChannelWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) DeleteChannelWithContext(ctx context.Context, ServiceSid string, Sid string) error { path := "/v1/Services/{ServiceSid}/Channels/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -101,7 +106,7 @@ func (c *ApiService) DeleteChannel(ServiceSid string, Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -111,8 +116,10 @@ func (c *ApiService) DeleteChannel(ServiceSid string, Sid string) error { return nil } -// func (c *ApiService) FetchChannel(ServiceSid string, Sid string) (*IpMessagingV1Channel, error) { + return c.FetchChannelWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) FetchChannelWithContext(ctx context.Context, ServiceSid string, Sid string) (*IpMessagingV1Channel, error) { path := "/v1/Services/{ServiceSid}/Channels/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -122,7 +129,7 @@ func (c *ApiService) FetchChannel(ServiceSid string, Sid string) (*IpMessagingV1 "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -162,6 +169,11 @@ func (params *ListChannelParams) SetLimit(Limit int) *ListChannelParams { // Retrieve a single page of Channel records from the API. Request is executed immediately. func (c *ApiService) PageChannel(ServiceSid string, params *ListChannelParams, pageToken, pageNumber string) (*ListChannelResponse, error) { + return c.PageChannelWithContext(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Channel records from the API. Request is executed immediately. +func (c *ApiService) PageChannelWithContext(ctx context.Context, ServiceSid string, params *ListChannelParams, pageToken, pageNumber string) (*ListChannelResponse, error) { path := "/v1/Services/{ServiceSid}/Channels" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -187,7 +199,7 @@ func (c *ApiService) PageChannel(ServiceSid string, params *ListChannelParams, p data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -204,7 +216,12 @@ func (c *ApiService) PageChannel(ServiceSid string, params *ListChannelParams, p // Lists Channel records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListChannel(ServiceSid string, params *ListChannelParams) ([]IpMessagingV1Channel, error) { - response, errors := c.StreamChannel(ServiceSid, params) + return c.ListChannelWithContext(context.TODO(), ServiceSid, params) +} + +// Lists Channel records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListChannelWithContext(ctx context.Context, ServiceSid string, params *ListChannelParams) ([]IpMessagingV1Channel, error) { + response, errors := c.StreamChannelWithContext(ctx, ServiceSid, params) records := make([]IpMessagingV1Channel, 0) for record := range response { @@ -220,6 +237,11 @@ func (c *ApiService) ListChannel(ServiceSid string, params *ListChannelParams) ( // Streams Channel records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamChannel(ServiceSid string, params *ListChannelParams) (chan IpMessagingV1Channel, chan error) { + return c.StreamChannelWithContext(context.TODO(), ServiceSid, params) +} + +// Streams Channel records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamChannelWithContext(ctx context.Context, ServiceSid string, params *ListChannelParams) (chan IpMessagingV1Channel, chan error) { if params == nil { params = &ListChannelParams{} } @@ -228,19 +250,19 @@ func (c *ApiService) StreamChannel(ServiceSid string, params *ListChannelParams) recordChannel := make(chan IpMessagingV1Channel, 1) errorChannel := make(chan error, 1) - response, err := c.PageChannel(ServiceSid, params, "", "") + response, err := c.PageChannelWithContext(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamChannel(response, params, recordChannel, errorChannel) + go c.streamChannelWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamChannel(response *ListChannelResponse, params *ListChannelParams, recordChannel chan IpMessagingV1Channel, errorChannel chan error) { +func (c *ApiService) streamChannelWithContext(ctx context.Context, response *ListChannelResponse, params *ListChannelParams, recordChannel chan IpMessagingV1Channel, errorChannel chan error) { curRecord := 1 for response != nil { @@ -255,7 +277,7 @@ func (c *ApiService) streamChannel(response *ListChannelResponse, params *ListCh } } - record, err := client.GetNext(c.baseURL, response, c.getNextListChannelResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListChannelResponseWithContext) if err != nil { errorChannel <- err break @@ -270,11 +292,11 @@ func (c *ApiService) streamChannel(response *ListChannelResponse, params *ListCh close(errorChannel) } -func (c *ApiService) getNextListChannelResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListChannelResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -311,8 +333,10 @@ func (params *UpdateChannelParams) SetAttributes(Attributes string) *UpdateChann return params } -// func (c *ApiService) UpdateChannel(ServiceSid string, Sid string, params *UpdateChannelParams) (*IpMessagingV1Channel, error) { + return c.UpdateChannelWithContext(context.TODO(), ServiceSid, Sid, params) +} +func (c *ApiService) UpdateChannelWithContext(ctx context.Context, ServiceSid string, Sid string, params *UpdateChannelParams) (*IpMessagingV1Channel, error) { path := "/v1/Services/{ServiceSid}/Channels/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -332,7 +356,7 @@ func (c *ApiService) UpdateChannel(ServiceSid string, Sid string, params *Update data.Set("Attributes", *params.Attributes) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/ip_messaging/v1/services_channels_invites.go b/rest/ip_messaging/v1/services_channels_invites.go index 3868030c9..cc8113c48 100644 --- a/rest/ip_messaging/v1/services_channels_invites.go +++ b/rest/ip_messaging/v1/services_channels_invites.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -40,8 +41,10 @@ func (params *CreateInviteParams) SetRoleSid(RoleSid string) *CreateInviteParams return params } -// func (c *ApiService) CreateInvite(ServiceSid string, ChannelSid string, params *CreateInviteParams) (*IpMessagingV1Invite, error) { + return c.CreateInviteWithContext(context.TODO(), ServiceSid, ChannelSid, params) +} +func (c *ApiService) CreateInviteWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *CreateInviteParams) (*IpMessagingV1Invite, error) { path := "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Invites" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -58,7 +61,7 @@ func (c *ApiService) CreateInvite(ServiceSid string, ChannelSid string, params * data.Set("RoleSid", *params.RoleSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -73,8 +76,10 @@ func (c *ApiService) CreateInvite(ServiceSid string, ChannelSid string, params * return ps, err } -// func (c *ApiService) DeleteInvite(ServiceSid string, ChannelSid string, Sid string) error { + return c.DeleteInviteWithContext(context.TODO(), ServiceSid, ChannelSid, Sid) +} +func (c *ApiService) DeleteInviteWithContext(ctx context.Context, ServiceSid string, ChannelSid string, Sid string) error { path := "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Invites/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -85,7 +90,7 @@ func (c *ApiService) DeleteInvite(ServiceSid string, ChannelSid string, Sid stri "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -95,8 +100,10 @@ func (c *ApiService) DeleteInvite(ServiceSid string, ChannelSid string, Sid stri return nil } -// func (c *ApiService) FetchInvite(ServiceSid string, ChannelSid string, Sid string) (*IpMessagingV1Invite, error) { + return c.FetchInviteWithContext(context.TODO(), ServiceSid, ChannelSid, Sid) +} +func (c *ApiService) FetchInviteWithContext(ctx context.Context, ServiceSid string, ChannelSid string, Sid string) (*IpMessagingV1Invite, error) { path := "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Invites/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -107,7 +114,7 @@ func (c *ApiService) FetchInvite(ServiceSid string, ChannelSid string, Sid strin "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -147,6 +154,11 @@ func (params *ListInviteParams) SetLimit(Limit int) *ListInviteParams { // Retrieve a single page of Invite records from the API. Request is executed immediately. func (c *ApiService) PageInvite(ServiceSid string, ChannelSid string, params *ListInviteParams, pageToken, pageNumber string) (*ListInviteResponse, error) { + return c.PageInviteWithContext(context.TODO(), ServiceSid, ChannelSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Invite records from the API. Request is executed immediately. +func (c *ApiService) PageInviteWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *ListInviteParams, pageToken, pageNumber string) (*ListInviteResponse, error) { path := "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Invites" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -173,7 +185,7 @@ func (c *ApiService) PageInvite(ServiceSid string, ChannelSid string, params *Li data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -190,7 +202,12 @@ func (c *ApiService) PageInvite(ServiceSid string, ChannelSid string, params *Li // Lists Invite records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListInvite(ServiceSid string, ChannelSid string, params *ListInviteParams) ([]IpMessagingV1Invite, error) { - response, errors := c.StreamInvite(ServiceSid, ChannelSid, params) + return c.ListInviteWithContext(context.TODO(), ServiceSid, ChannelSid, params) +} + +// Lists Invite records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListInviteWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *ListInviteParams) ([]IpMessagingV1Invite, error) { + response, errors := c.StreamInviteWithContext(ctx, ServiceSid, ChannelSid, params) records := make([]IpMessagingV1Invite, 0) for record := range response { @@ -206,6 +223,11 @@ func (c *ApiService) ListInvite(ServiceSid string, ChannelSid string, params *Li // Streams Invite records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamInvite(ServiceSid string, ChannelSid string, params *ListInviteParams) (chan IpMessagingV1Invite, chan error) { + return c.StreamInviteWithContext(context.TODO(), ServiceSid, ChannelSid, params) +} + +// Streams Invite records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamInviteWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *ListInviteParams) (chan IpMessagingV1Invite, chan error) { if params == nil { params = &ListInviteParams{} } @@ -214,19 +236,19 @@ func (c *ApiService) StreamInvite(ServiceSid string, ChannelSid string, params * recordChannel := make(chan IpMessagingV1Invite, 1) errorChannel := make(chan error, 1) - response, err := c.PageInvite(ServiceSid, ChannelSid, params, "", "") + response, err := c.PageInviteWithContext(ctx, ServiceSid, ChannelSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamInvite(response, params, recordChannel, errorChannel) + go c.streamInviteWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamInvite(response *ListInviteResponse, params *ListInviteParams, recordChannel chan IpMessagingV1Invite, errorChannel chan error) { +func (c *ApiService) streamInviteWithContext(ctx context.Context, response *ListInviteResponse, params *ListInviteParams, recordChannel chan IpMessagingV1Invite, errorChannel chan error) { curRecord := 1 for response != nil { @@ -241,7 +263,7 @@ func (c *ApiService) streamInvite(response *ListInviteResponse, params *ListInvi } } - record, err := client.GetNext(c.baseURL, response, c.getNextListInviteResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListInviteResponseWithContext) if err != nil { errorChannel <- err break @@ -256,11 +278,11 @@ func (c *ApiService) streamInvite(response *ListInviteResponse, params *ListInvi close(errorChannel) } -func (c *ApiService) getNextListInviteResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListInviteResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/ip_messaging/v1/services_channels_members.go b/rest/ip_messaging/v1/services_channels_members.go index a468165ff..9ecdcd27e 100644 --- a/rest/ip_messaging/v1/services_channels_members.go +++ b/rest/ip_messaging/v1/services_channels_members.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -40,8 +41,10 @@ func (params *CreateMemberParams) SetRoleSid(RoleSid string) *CreateMemberParams return params } -// func (c *ApiService) CreateMember(ServiceSid string, ChannelSid string, params *CreateMemberParams) (*IpMessagingV1Member, error) { + return c.CreateMemberWithContext(context.TODO(), ServiceSid, ChannelSid, params) +} +func (c *ApiService) CreateMemberWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *CreateMemberParams) (*IpMessagingV1Member, error) { path := "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Members" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -58,7 +61,7 @@ func (c *ApiService) CreateMember(ServiceSid string, ChannelSid string, params * data.Set("RoleSid", *params.RoleSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -73,8 +76,10 @@ func (c *ApiService) CreateMember(ServiceSid string, ChannelSid string, params * return ps, err } -// func (c *ApiService) DeleteMember(ServiceSid string, ChannelSid string, Sid string) error { + return c.DeleteMemberWithContext(context.TODO(), ServiceSid, ChannelSid, Sid) +} +func (c *ApiService) DeleteMemberWithContext(ctx context.Context, ServiceSid string, ChannelSid string, Sid string) error { path := "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -85,7 +90,7 @@ func (c *ApiService) DeleteMember(ServiceSid string, ChannelSid string, Sid stri "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -95,8 +100,10 @@ func (c *ApiService) DeleteMember(ServiceSid string, ChannelSid string, Sid stri return nil } -// func (c *ApiService) FetchMember(ServiceSid string, ChannelSid string, Sid string) (*IpMessagingV1Member, error) { + return c.FetchMemberWithContext(context.TODO(), ServiceSid, ChannelSid, Sid) +} +func (c *ApiService) FetchMemberWithContext(ctx context.Context, ServiceSid string, ChannelSid string, Sid string) (*IpMessagingV1Member, error) { path := "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -107,7 +114,7 @@ func (c *ApiService) FetchMember(ServiceSid string, ChannelSid string, Sid strin "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -147,6 +154,11 @@ func (params *ListMemberParams) SetLimit(Limit int) *ListMemberParams { // Retrieve a single page of Member records from the API. Request is executed immediately. func (c *ApiService) PageMember(ServiceSid string, ChannelSid string, params *ListMemberParams, pageToken, pageNumber string) (*ListMemberResponse, error) { + return c.PageMemberWithContext(context.TODO(), ServiceSid, ChannelSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Member records from the API. Request is executed immediately. +func (c *ApiService) PageMemberWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *ListMemberParams, pageToken, pageNumber string) (*ListMemberResponse, error) { path := "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Members" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -173,7 +185,7 @@ func (c *ApiService) PageMember(ServiceSid string, ChannelSid string, params *Li data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -190,7 +202,12 @@ func (c *ApiService) PageMember(ServiceSid string, ChannelSid string, params *Li // Lists Member records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListMember(ServiceSid string, ChannelSid string, params *ListMemberParams) ([]IpMessagingV1Member, error) { - response, errors := c.StreamMember(ServiceSid, ChannelSid, params) + return c.ListMemberWithContext(context.TODO(), ServiceSid, ChannelSid, params) +} + +// Lists Member records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListMemberWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *ListMemberParams) ([]IpMessagingV1Member, error) { + response, errors := c.StreamMemberWithContext(ctx, ServiceSid, ChannelSid, params) records := make([]IpMessagingV1Member, 0) for record := range response { @@ -206,6 +223,11 @@ func (c *ApiService) ListMember(ServiceSid string, ChannelSid string, params *Li // Streams Member records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamMember(ServiceSid string, ChannelSid string, params *ListMemberParams) (chan IpMessagingV1Member, chan error) { + return c.StreamMemberWithContext(context.TODO(), ServiceSid, ChannelSid, params) +} + +// Streams Member records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamMemberWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *ListMemberParams) (chan IpMessagingV1Member, chan error) { if params == nil { params = &ListMemberParams{} } @@ -214,19 +236,19 @@ func (c *ApiService) StreamMember(ServiceSid string, ChannelSid string, params * recordChannel := make(chan IpMessagingV1Member, 1) errorChannel := make(chan error, 1) - response, err := c.PageMember(ServiceSid, ChannelSid, params, "", "") + response, err := c.PageMemberWithContext(ctx, ServiceSid, ChannelSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamMember(response, params, recordChannel, errorChannel) + go c.streamMemberWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamMember(response *ListMemberResponse, params *ListMemberParams, recordChannel chan IpMessagingV1Member, errorChannel chan error) { +func (c *ApiService) streamMemberWithContext(ctx context.Context, response *ListMemberResponse, params *ListMemberParams, recordChannel chan IpMessagingV1Member, errorChannel chan error) { curRecord := 1 for response != nil { @@ -241,7 +263,7 @@ func (c *ApiService) streamMember(response *ListMemberResponse, params *ListMemb } } - record, err := client.GetNext(c.baseURL, response, c.getNextListMemberResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListMemberResponseWithContext) if err != nil { errorChannel <- err break @@ -256,11 +278,11 @@ func (c *ApiService) streamMember(response *ListMemberResponse, params *ListMemb close(errorChannel) } -func (c *ApiService) getNextListMemberResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListMemberResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -291,8 +313,10 @@ func (params *UpdateMemberParams) SetLastConsumedMessageIndex(LastConsumedMessag return params } -// func (c *ApiService) UpdateMember(ServiceSid string, ChannelSid string, Sid string, params *UpdateMemberParams) (*IpMessagingV1Member, error) { + return c.UpdateMemberWithContext(context.TODO(), ServiceSid, ChannelSid, Sid, params) +} +func (c *ApiService) UpdateMemberWithContext(ctx context.Context, ServiceSid string, ChannelSid string, Sid string, params *UpdateMemberParams) (*IpMessagingV1Member, error) { path := "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -310,7 +334,7 @@ func (c *ApiService) UpdateMember(ServiceSid string, ChannelSid string, Sid stri data.Set("LastConsumedMessageIndex", fmt.Sprint(*params.LastConsumedMessageIndex)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/ip_messaging/v1/services_channels_messages.go b/rest/ip_messaging/v1/services_channels_messages.go index 316d2082b..46df5bc28 100644 --- a/rest/ip_messaging/v1/services_channels_messages.go +++ b/rest/ip_messaging/v1/services_channels_messages.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -46,8 +47,10 @@ func (params *CreateMessageParams) SetAttributes(Attributes string) *CreateMessa return params } -// func (c *ApiService) CreateMessage(ServiceSid string, ChannelSid string, params *CreateMessageParams) (*IpMessagingV1Message, error) { + return c.CreateMessageWithContext(context.TODO(), ServiceSid, ChannelSid, params) +} +func (c *ApiService) CreateMessageWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *CreateMessageParams) (*IpMessagingV1Message, error) { path := "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Messages" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -67,7 +70,7 @@ func (c *ApiService) CreateMessage(ServiceSid string, ChannelSid string, params data.Set("Attributes", *params.Attributes) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -82,8 +85,10 @@ func (c *ApiService) CreateMessage(ServiceSid string, ChannelSid string, params return ps, err } -// func (c *ApiService) DeleteMessage(ServiceSid string, ChannelSid string, Sid string) error { + return c.DeleteMessageWithContext(context.TODO(), ServiceSid, ChannelSid, Sid) +} +func (c *ApiService) DeleteMessageWithContext(ctx context.Context, ServiceSid string, ChannelSid string, Sid string) error { path := "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -94,7 +99,7 @@ func (c *ApiService) DeleteMessage(ServiceSid string, ChannelSid string, Sid str "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -104,8 +109,10 @@ func (c *ApiService) DeleteMessage(ServiceSid string, ChannelSid string, Sid str return nil } -// func (c *ApiService) FetchMessage(ServiceSid string, ChannelSid string, Sid string) (*IpMessagingV1Message, error) { + return c.FetchMessageWithContext(context.TODO(), ServiceSid, ChannelSid, Sid) +} +func (c *ApiService) FetchMessageWithContext(ctx context.Context, ServiceSid string, ChannelSid string, Sid string) (*IpMessagingV1Message, error) { path := "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -116,7 +123,7 @@ func (c *ApiService) FetchMessage(ServiceSid string, ChannelSid string, Sid stri "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -156,6 +163,11 @@ func (params *ListMessageParams) SetLimit(Limit int) *ListMessageParams { // Retrieve a single page of Message records from the API. Request is executed immediately. func (c *ApiService) PageMessage(ServiceSid string, ChannelSid string, params *ListMessageParams, pageToken, pageNumber string) (*ListMessageResponse, error) { + return c.PageMessageWithContext(context.TODO(), ServiceSid, ChannelSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Message records from the API. Request is executed immediately. +func (c *ApiService) PageMessageWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *ListMessageParams, pageToken, pageNumber string) (*ListMessageResponse, error) { path := "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Messages" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -180,7 +192,7 @@ func (c *ApiService) PageMessage(ServiceSid string, ChannelSid string, params *L data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -197,7 +209,12 @@ func (c *ApiService) PageMessage(ServiceSid string, ChannelSid string, params *L // Lists Message records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListMessage(ServiceSid string, ChannelSid string, params *ListMessageParams) ([]IpMessagingV1Message, error) { - response, errors := c.StreamMessage(ServiceSid, ChannelSid, params) + return c.ListMessageWithContext(context.TODO(), ServiceSid, ChannelSid, params) +} + +// Lists Message records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListMessageWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *ListMessageParams) ([]IpMessagingV1Message, error) { + response, errors := c.StreamMessageWithContext(ctx, ServiceSid, ChannelSid, params) records := make([]IpMessagingV1Message, 0) for record := range response { @@ -213,6 +230,11 @@ func (c *ApiService) ListMessage(ServiceSid string, ChannelSid string, params *L // Streams Message records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamMessage(ServiceSid string, ChannelSid string, params *ListMessageParams) (chan IpMessagingV1Message, chan error) { + return c.StreamMessageWithContext(context.TODO(), ServiceSid, ChannelSid, params) +} + +// Streams Message records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamMessageWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *ListMessageParams) (chan IpMessagingV1Message, chan error) { if params == nil { params = &ListMessageParams{} } @@ -221,19 +243,19 @@ func (c *ApiService) StreamMessage(ServiceSid string, ChannelSid string, params recordChannel := make(chan IpMessagingV1Message, 1) errorChannel := make(chan error, 1) - response, err := c.PageMessage(ServiceSid, ChannelSid, params, "", "") + response, err := c.PageMessageWithContext(ctx, ServiceSid, ChannelSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamMessage(response, params, recordChannel, errorChannel) + go c.streamMessageWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamMessage(response *ListMessageResponse, params *ListMessageParams, recordChannel chan IpMessagingV1Message, errorChannel chan error) { +func (c *ApiService) streamMessageWithContext(ctx context.Context, response *ListMessageResponse, params *ListMessageParams, recordChannel chan IpMessagingV1Message, errorChannel chan error) { curRecord := 1 for response != nil { @@ -248,7 +270,7 @@ func (c *ApiService) streamMessage(response *ListMessageResponse, params *ListMe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListMessageResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListMessageResponseWithContext) if err != nil { errorChannel <- err break @@ -263,11 +285,11 @@ func (c *ApiService) streamMessage(response *ListMessageResponse, params *ListMe close(errorChannel) } -func (c *ApiService) getNextListMessageResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListMessageResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -298,8 +320,10 @@ func (params *UpdateMessageParams) SetAttributes(Attributes string) *UpdateMessa return params } -// func (c *ApiService) UpdateMessage(ServiceSid string, ChannelSid string, Sid string, params *UpdateMessageParams) (*IpMessagingV1Message, error) { + return c.UpdateMessageWithContext(context.TODO(), ServiceSid, ChannelSid, Sid, params) +} +func (c *ApiService) UpdateMessageWithContext(ctx context.Context, ServiceSid string, ChannelSid string, Sid string, params *UpdateMessageParams) (*IpMessagingV1Message, error) { path := "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -317,7 +341,7 @@ func (c *ApiService) UpdateMessage(ServiceSid string, ChannelSid string, Sid str data.Set("Attributes", *params.Attributes) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/ip_messaging/v1/services_roles.go b/rest/ip_messaging/v1/services_roles.go index d87b1cd08..68fc506c1 100644 --- a/rest/ip_messaging/v1/services_roles.go +++ b/rest/ip_messaging/v1/services_roles.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -46,8 +47,10 @@ func (params *CreateRoleParams) SetPermission(Permission []string) *CreateRolePa return params } -// func (c *ApiService) CreateRole(ServiceSid string, params *CreateRoleParams) (*IpMessagingV1Role, error) { + return c.CreateRoleWithContext(context.TODO(), ServiceSid, params) +} +func (c *ApiService) CreateRoleWithContext(ctx context.Context, ServiceSid string, params *CreateRoleParams) (*IpMessagingV1Role, error) { path := "/v1/Services/{ServiceSid}/Roles" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -68,7 +71,7 @@ func (c *ApiService) CreateRole(ServiceSid string, params *CreateRoleParams) (*I } } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -83,8 +86,10 @@ func (c *ApiService) CreateRole(ServiceSid string, params *CreateRoleParams) (*I return ps, err } -// func (c *ApiService) DeleteRole(ServiceSid string, Sid string) error { + return c.DeleteRoleWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) DeleteRoleWithContext(ctx context.Context, ServiceSid string, Sid string) error { path := "/v1/Services/{ServiceSid}/Roles/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -94,7 +99,7 @@ func (c *ApiService) DeleteRole(ServiceSid string, Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -104,8 +109,10 @@ func (c *ApiService) DeleteRole(ServiceSid string, Sid string) error { return nil } -// func (c *ApiService) FetchRole(ServiceSid string, Sid string) (*IpMessagingV1Role, error) { + return c.FetchRoleWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) FetchRoleWithContext(ctx context.Context, ServiceSid string, Sid string) (*IpMessagingV1Role, error) { path := "/v1/Services/{ServiceSid}/Roles/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -115,7 +122,7 @@ func (c *ApiService) FetchRole(ServiceSid string, Sid string) (*IpMessagingV1Rol "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -149,6 +156,11 @@ func (params *ListRoleParams) SetLimit(Limit int) *ListRoleParams { // Retrieve a single page of Role records from the API. Request is executed immediately. func (c *ApiService) PageRole(ServiceSid string, params *ListRoleParams, pageToken, pageNumber string) (*ListRoleResponse, error) { + return c.PageRoleWithContext(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Role records from the API. Request is executed immediately. +func (c *ApiService) PageRoleWithContext(ctx context.Context, ServiceSid string, params *ListRoleParams, pageToken, pageNumber string) (*ListRoleResponse, error) { path := "/v1/Services/{ServiceSid}/Roles" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -169,7 +181,7 @@ func (c *ApiService) PageRole(ServiceSid string, params *ListRoleParams, pageTok data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -186,7 +198,12 @@ func (c *ApiService) PageRole(ServiceSid string, params *ListRoleParams, pageTok // Lists Role records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListRole(ServiceSid string, params *ListRoleParams) ([]IpMessagingV1Role, error) { - response, errors := c.StreamRole(ServiceSid, params) + return c.ListRoleWithContext(context.TODO(), ServiceSid, params) +} + +// Lists Role records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListRoleWithContext(ctx context.Context, ServiceSid string, params *ListRoleParams) ([]IpMessagingV1Role, error) { + response, errors := c.StreamRoleWithContext(ctx, ServiceSid, params) records := make([]IpMessagingV1Role, 0) for record := range response { @@ -202,6 +219,11 @@ func (c *ApiService) ListRole(ServiceSid string, params *ListRoleParams) ([]IpMe // Streams Role records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamRole(ServiceSid string, params *ListRoleParams) (chan IpMessagingV1Role, chan error) { + return c.StreamRoleWithContext(context.TODO(), ServiceSid, params) +} + +// Streams Role records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamRoleWithContext(ctx context.Context, ServiceSid string, params *ListRoleParams) (chan IpMessagingV1Role, chan error) { if params == nil { params = &ListRoleParams{} } @@ -210,19 +232,19 @@ func (c *ApiService) StreamRole(ServiceSid string, params *ListRoleParams) (chan recordChannel := make(chan IpMessagingV1Role, 1) errorChannel := make(chan error, 1) - response, err := c.PageRole(ServiceSid, params, "", "") + response, err := c.PageRoleWithContext(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamRole(response, params, recordChannel, errorChannel) + go c.streamRoleWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamRole(response *ListRoleResponse, params *ListRoleParams, recordChannel chan IpMessagingV1Role, errorChannel chan error) { +func (c *ApiService) streamRoleWithContext(ctx context.Context, response *ListRoleResponse, params *ListRoleParams, recordChannel chan IpMessagingV1Role, errorChannel chan error) { curRecord := 1 for response != nil { @@ -237,7 +259,7 @@ func (c *ApiService) streamRole(response *ListRoleResponse, params *ListRolePara } } - record, err := client.GetNext(c.baseURL, response, c.getNextListRoleResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListRoleResponseWithContext) if err != nil { errorChannel <- err break @@ -252,11 +274,11 @@ func (c *ApiService) streamRole(response *ListRoleResponse, params *ListRolePara close(errorChannel) } -func (c *ApiService) getNextListRoleResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListRoleResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -281,8 +303,10 @@ func (params *UpdateRoleParams) SetPermission(Permission []string) *UpdateRolePa return params } -// func (c *ApiService) UpdateRole(ServiceSid string, Sid string, params *UpdateRoleParams) (*IpMessagingV1Role, error) { + return c.UpdateRoleWithContext(context.TODO(), ServiceSid, Sid, params) +} +func (c *ApiService) UpdateRoleWithContext(ctx context.Context, ServiceSid string, Sid string, params *UpdateRoleParams) (*IpMessagingV1Role, error) { path := "/v1/Services/{ServiceSid}/Roles/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -298,7 +322,7 @@ func (c *ApiService) UpdateRole(ServiceSid string, Sid string, params *UpdateRol } } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/ip_messaging/v1/services_users.go b/rest/ip_messaging/v1/services_users.go index 5fc0f3ed4..4efc0288f 100644 --- a/rest/ip_messaging/v1/services_users.go +++ b/rest/ip_messaging/v1/services_users.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -52,8 +53,10 @@ func (params *CreateUserParams) SetFriendlyName(FriendlyName string) *CreateUser return params } -// func (c *ApiService) CreateUser(ServiceSid string, params *CreateUserParams) (*IpMessagingV1User, error) { + return c.CreateUserWithContext(context.TODO(), ServiceSid, params) +} +func (c *ApiService) CreateUserWithContext(ctx context.Context, ServiceSid string, params *CreateUserParams) (*IpMessagingV1User, error) { path := "/v1/Services/{ServiceSid}/Users" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -75,7 +78,7 @@ func (c *ApiService) CreateUser(ServiceSid string, params *CreateUserParams) (*I data.Set("FriendlyName", *params.FriendlyName) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -90,8 +93,10 @@ func (c *ApiService) CreateUser(ServiceSid string, params *CreateUserParams) (*I return ps, err } -// func (c *ApiService) DeleteUser(ServiceSid string, Sid string) error { + return c.DeleteUserWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) DeleteUserWithContext(ctx context.Context, ServiceSid string, Sid string) error { path := "/v1/Services/{ServiceSid}/Users/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -101,7 +106,7 @@ func (c *ApiService) DeleteUser(ServiceSid string, Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -111,8 +116,10 @@ func (c *ApiService) DeleteUser(ServiceSid string, Sid string) error { return nil } -// func (c *ApiService) FetchUser(ServiceSid string, Sid string) (*IpMessagingV1User, error) { + return c.FetchUserWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) FetchUserWithContext(ctx context.Context, ServiceSid string, Sid string) (*IpMessagingV1User, error) { path := "/v1/Services/{ServiceSid}/Users/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -122,7 +129,7 @@ func (c *ApiService) FetchUser(ServiceSid string, Sid string) (*IpMessagingV1Use "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -156,6 +163,11 @@ func (params *ListUserParams) SetLimit(Limit int) *ListUserParams { // Retrieve a single page of User records from the API. Request is executed immediately. func (c *ApiService) PageUser(ServiceSid string, params *ListUserParams, pageToken, pageNumber string) (*ListUserResponse, error) { + return c.PageUserWithContext(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of User records from the API. Request is executed immediately. +func (c *ApiService) PageUserWithContext(ctx context.Context, ServiceSid string, params *ListUserParams, pageToken, pageNumber string) (*ListUserResponse, error) { path := "/v1/Services/{ServiceSid}/Users" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -176,7 +188,7 @@ func (c *ApiService) PageUser(ServiceSid string, params *ListUserParams, pageTok data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -193,7 +205,12 @@ func (c *ApiService) PageUser(ServiceSid string, params *ListUserParams, pageTok // Lists User records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListUser(ServiceSid string, params *ListUserParams) ([]IpMessagingV1User, error) { - response, errors := c.StreamUser(ServiceSid, params) + return c.ListUserWithContext(context.TODO(), ServiceSid, params) +} + +// Lists User records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListUserWithContext(ctx context.Context, ServiceSid string, params *ListUserParams) ([]IpMessagingV1User, error) { + response, errors := c.StreamUserWithContext(ctx, ServiceSid, params) records := make([]IpMessagingV1User, 0) for record := range response { @@ -209,6 +226,11 @@ func (c *ApiService) ListUser(ServiceSid string, params *ListUserParams) ([]IpMe // Streams User records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamUser(ServiceSid string, params *ListUserParams) (chan IpMessagingV1User, chan error) { + return c.StreamUserWithContext(context.TODO(), ServiceSid, params) +} + +// Streams User records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamUserWithContext(ctx context.Context, ServiceSid string, params *ListUserParams) (chan IpMessagingV1User, chan error) { if params == nil { params = &ListUserParams{} } @@ -217,19 +239,19 @@ func (c *ApiService) StreamUser(ServiceSid string, params *ListUserParams) (chan recordChannel := make(chan IpMessagingV1User, 1) errorChannel := make(chan error, 1) - response, err := c.PageUser(ServiceSid, params, "", "") + response, err := c.PageUserWithContext(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUser(response, params, recordChannel, errorChannel) + go c.streamUserWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamUser(response *ListUserResponse, params *ListUserParams, recordChannel chan IpMessagingV1User, errorChannel chan error) { +func (c *ApiService) streamUserWithContext(ctx context.Context, response *ListUserResponse, params *ListUserParams, recordChannel chan IpMessagingV1User, errorChannel chan error) { curRecord := 1 for response != nil { @@ -244,7 +266,7 @@ func (c *ApiService) streamUser(response *ListUserResponse, params *ListUserPara } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUserResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListUserResponseWithContext) if err != nil { errorChannel <- err break @@ -259,11 +281,11 @@ func (c *ApiService) streamUser(response *ListUserResponse, params *ListUserPara close(errorChannel) } -func (c *ApiService) getNextListUserResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUserResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -300,8 +322,10 @@ func (params *UpdateUserParams) SetFriendlyName(FriendlyName string) *UpdateUser return params } -// func (c *ApiService) UpdateUser(ServiceSid string, Sid string, params *UpdateUserParams) (*IpMessagingV1User, error) { + return c.UpdateUserWithContext(context.TODO(), ServiceSid, Sid, params) +} +func (c *ApiService) UpdateUserWithContext(ctx context.Context, ServiceSid string, Sid string, params *UpdateUserParams) (*IpMessagingV1User, error) { path := "/v1/Services/{ServiceSid}/Users/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -321,7 +345,7 @@ func (c *ApiService) UpdateUser(ServiceSid string, Sid string, params *UpdateUse data.Set("FriendlyName", *params.FriendlyName) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/ip_messaging/v1/services_users_channels.go b/rest/ip_messaging/v1/services_users_channels.go index 801fcf96d..e53125f2c 100644 --- a/rest/ip_messaging/v1/services_users_channels.go +++ b/rest/ip_messaging/v1/services_users_channels.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -42,6 +43,11 @@ func (params *ListUserChannelParams) SetLimit(Limit int) *ListUserChannelParams // Retrieve a single page of UserChannel records from the API. Request is executed immediately. func (c *ApiService) PageUserChannel(ServiceSid string, UserSid string, params *ListUserChannelParams, pageToken, pageNumber string) (*ListUserChannelResponse, error) { + return c.PageUserChannelWithContext(context.TODO(), ServiceSid, UserSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of UserChannel records from the API. Request is executed immediately. +func (c *ApiService) PageUserChannelWithContext(ctx context.Context, ServiceSid string, UserSid string, params *ListUserChannelParams, pageToken, pageNumber string) (*ListUserChannelResponse, error) { path := "/v1/Services/{ServiceSid}/Users/{UserSid}/Channels" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -63,7 +69,7 @@ func (c *ApiService) PageUserChannel(ServiceSid string, UserSid string, params * data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -80,7 +86,12 @@ func (c *ApiService) PageUserChannel(ServiceSid string, UserSid string, params * // Lists UserChannel records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListUserChannel(ServiceSid string, UserSid string, params *ListUserChannelParams) ([]IpMessagingV1UserChannel, error) { - response, errors := c.StreamUserChannel(ServiceSid, UserSid, params) + return c.ListUserChannelWithContext(context.TODO(), ServiceSid, UserSid, params) +} + +// Lists UserChannel records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListUserChannelWithContext(ctx context.Context, ServiceSid string, UserSid string, params *ListUserChannelParams) ([]IpMessagingV1UserChannel, error) { + response, errors := c.StreamUserChannelWithContext(ctx, ServiceSid, UserSid, params) records := make([]IpMessagingV1UserChannel, 0) for record := range response { @@ -96,6 +107,11 @@ func (c *ApiService) ListUserChannel(ServiceSid string, UserSid string, params * // Streams UserChannel records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamUserChannel(ServiceSid string, UserSid string, params *ListUserChannelParams) (chan IpMessagingV1UserChannel, chan error) { + return c.StreamUserChannelWithContext(context.TODO(), ServiceSid, UserSid, params) +} + +// Streams UserChannel records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamUserChannelWithContext(ctx context.Context, ServiceSid string, UserSid string, params *ListUserChannelParams) (chan IpMessagingV1UserChannel, chan error) { if params == nil { params = &ListUserChannelParams{} } @@ -104,19 +120,19 @@ func (c *ApiService) StreamUserChannel(ServiceSid string, UserSid string, params recordChannel := make(chan IpMessagingV1UserChannel, 1) errorChannel := make(chan error, 1) - response, err := c.PageUserChannel(ServiceSid, UserSid, params, "", "") + response, err := c.PageUserChannelWithContext(ctx, ServiceSid, UserSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUserChannel(response, params, recordChannel, errorChannel) + go c.streamUserChannelWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamUserChannel(response *ListUserChannelResponse, params *ListUserChannelParams, recordChannel chan IpMessagingV1UserChannel, errorChannel chan error) { +func (c *ApiService) streamUserChannelWithContext(ctx context.Context, response *ListUserChannelResponse, params *ListUserChannelParams, recordChannel chan IpMessagingV1UserChannel, errorChannel chan error) { curRecord := 1 for response != nil { @@ -131,7 +147,7 @@ func (c *ApiService) streamUserChannel(response *ListUserChannelResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUserChannelResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListUserChannelResponseWithContext) if err != nil { errorChannel <- err break @@ -146,11 +162,11 @@ func (c *ApiService) streamUserChannel(response *ListUserChannelResponse, params close(errorChannel) } -func (c *ApiService) getNextListUserChannelResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUserChannelResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/ip_messaging/v2/api_service.go b/rest/ip_messaging/v2/api_service.go index e7f59ad5a..b659cfd13 100644 --- a/rest/ip_messaging/v2/api_service.go +++ b/rest/ip_messaging/v2/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://ip-messaging.twilio.com", + } +} diff --git a/rest/ip_messaging/v2/credentials.go b/rest/ip_messaging/v2/credentials.go index b9c956a30..2283889ac 100644 --- a/rest/ip_messaging/v2/credentials.go +++ b/rest/ip_messaging/v2/credentials.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -70,8 +71,10 @@ func (params *CreateCredentialParams) SetSecret(Secret string) *CreateCredential return params } -// func (c *ApiService) CreateCredential(params *CreateCredentialParams) (*IpMessagingV2Credential, error) { + return c.CreateCredentialWithContext(context.TODO(), params) +} +func (c *ApiService) CreateCredentialWithContext(ctx context.Context, params *CreateCredentialParams) (*IpMessagingV2Credential, error) { path := "/v2/Credentials" data := url.Values{} @@ -101,7 +104,7 @@ func (c *ApiService) CreateCredential(params *CreateCredentialParams) (*IpMessag data.Set("Secret", *params.Secret) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -116,8 +119,10 @@ func (c *ApiService) CreateCredential(params *CreateCredentialParams) (*IpMessag return ps, err } -// func (c *ApiService) DeleteCredential(Sid string) error { + return c.DeleteCredentialWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteCredentialWithContext(ctx context.Context, Sid string) error { path := "/v2/Credentials/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -126,7 +131,7 @@ func (c *ApiService) DeleteCredential(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -136,8 +141,10 @@ func (c *ApiService) DeleteCredential(Sid string) error { return nil } -// func (c *ApiService) FetchCredential(Sid string) (*IpMessagingV2Credential, error) { + return c.FetchCredentialWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchCredentialWithContext(ctx context.Context, Sid string) (*IpMessagingV2Credential, error) { path := "/v2/Credentials/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -146,7 +153,7 @@ func (c *ApiService) FetchCredential(Sid string) (*IpMessagingV2Credential, erro "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -180,6 +187,11 @@ func (params *ListCredentialParams) SetLimit(Limit int) *ListCredentialParams { // Retrieve a single page of Credential records from the API. Request is executed immediately. func (c *ApiService) PageCredential(params *ListCredentialParams, pageToken, pageNumber string) (*ListCredentialResponse, error) { + return c.PageCredentialWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Credential records from the API. Request is executed immediately. +func (c *ApiService) PageCredentialWithContext(ctx context.Context, params *ListCredentialParams, pageToken, pageNumber string) (*ListCredentialResponse, error) { path := "/v2/Credentials" data := url.Values{} @@ -198,7 +210,7 @@ func (c *ApiService) PageCredential(params *ListCredentialParams, pageToken, pag data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -215,7 +227,12 @@ func (c *ApiService) PageCredential(params *ListCredentialParams, pageToken, pag // Lists Credential records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListCredential(params *ListCredentialParams) ([]IpMessagingV2Credential, error) { - response, errors := c.StreamCredential(params) + return c.ListCredentialWithContext(context.TODO(), params) +} + +// Lists Credential records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListCredentialWithContext(ctx context.Context, params *ListCredentialParams) ([]IpMessagingV2Credential, error) { + response, errors := c.StreamCredentialWithContext(ctx, params) records := make([]IpMessagingV2Credential, 0) for record := range response { @@ -231,6 +248,11 @@ func (c *ApiService) ListCredential(params *ListCredentialParams) ([]IpMessaging // Streams Credential records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamCredential(params *ListCredentialParams) (chan IpMessagingV2Credential, chan error) { + return c.StreamCredentialWithContext(context.TODO(), params) +} + +// Streams Credential records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamCredentialWithContext(ctx context.Context, params *ListCredentialParams) (chan IpMessagingV2Credential, chan error) { if params == nil { params = &ListCredentialParams{} } @@ -239,19 +261,19 @@ func (c *ApiService) StreamCredential(params *ListCredentialParams) (chan IpMess recordChannel := make(chan IpMessagingV2Credential, 1) errorChannel := make(chan error, 1) - response, err := c.PageCredential(params, "", "") + response, err := c.PageCredentialWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamCredential(response, params, recordChannel, errorChannel) + go c.streamCredentialWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamCredential(response *ListCredentialResponse, params *ListCredentialParams, recordChannel chan IpMessagingV2Credential, errorChannel chan error) { +func (c *ApiService) streamCredentialWithContext(ctx context.Context, response *ListCredentialResponse, params *ListCredentialParams, recordChannel chan IpMessagingV2Credential, errorChannel chan error) { curRecord := 1 for response != nil { @@ -266,7 +288,7 @@ func (c *ApiService) streamCredential(response *ListCredentialResponse, params * } } - record, err := client.GetNext(c.baseURL, response, c.getNextListCredentialResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListCredentialResponseWithContext) if err != nil { errorChannel <- err break @@ -281,11 +303,11 @@ func (c *ApiService) streamCredential(response *ListCredentialResponse, params * close(errorChannel) } -func (c *ApiService) getNextListCredentialResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListCredentialResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -340,8 +362,10 @@ func (params *UpdateCredentialParams) SetSecret(Secret string) *UpdateCredential return params } -// func (c *ApiService) UpdateCredential(Sid string, params *UpdateCredentialParams) (*IpMessagingV2Credential, error) { + return c.UpdateCredentialWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateCredentialWithContext(ctx context.Context, Sid string, params *UpdateCredentialParams) (*IpMessagingV2Credential, error) { path := "/v2/Credentials/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -369,7 +393,7 @@ func (c *ApiService) UpdateCredential(Sid string, params *UpdateCredentialParams data.Set("Secret", *params.Secret) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/ip_messaging/v2/services.go b/rest/ip_messaging/v2/services.go index df3740ea4..e90774bc3 100644 --- a/rest/ip_messaging/v2/services.go +++ b/rest/ip_messaging/v2/services.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -34,8 +35,10 @@ func (params *CreateServiceParams) SetFriendlyName(FriendlyName string) *CreateS return params } -// func (c *ApiService) CreateService(params *CreateServiceParams) (*IpMessagingV2Service, error) { + return c.CreateServiceWithContext(context.TODO(), params) +} +func (c *ApiService) CreateServiceWithContext(ctx context.Context, params *CreateServiceParams) (*IpMessagingV2Service, error) { path := "/v2/Services" data := url.Values{} @@ -47,7 +50,7 @@ func (c *ApiService) CreateService(params *CreateServiceParams) (*IpMessagingV2S data.Set("FriendlyName", *params.FriendlyName) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -62,8 +65,10 @@ func (c *ApiService) CreateService(params *CreateServiceParams) (*IpMessagingV2S return ps, err } -// func (c *ApiService) DeleteService(Sid string) error { + return c.DeleteServiceWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteServiceWithContext(ctx context.Context, Sid string) error { path := "/v2/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -72,7 +77,7 @@ func (c *ApiService) DeleteService(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -82,8 +87,10 @@ func (c *ApiService) DeleteService(Sid string) error { return nil } -// func (c *ApiService) FetchService(Sid string) (*IpMessagingV2Service, error) { + return c.FetchServiceWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchServiceWithContext(ctx context.Context, Sid string) (*IpMessagingV2Service, error) { path := "/v2/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -92,7 +99,7 @@ func (c *ApiService) FetchService(Sid string) (*IpMessagingV2Service, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -126,6 +133,11 @@ func (params *ListServiceParams) SetLimit(Limit int) *ListServiceParams { // Retrieve a single page of Service records from the API. Request is executed immediately. func (c *ApiService) PageService(params *ListServiceParams, pageToken, pageNumber string) (*ListServiceResponse, error) { + return c.PageServiceWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Service records from the API. Request is executed immediately. +func (c *ApiService) PageServiceWithContext(ctx context.Context, params *ListServiceParams, pageToken, pageNumber string) (*ListServiceResponse, error) { path := "/v2/Services" data := url.Values{} @@ -144,7 +156,7 @@ func (c *ApiService) PageService(params *ListServiceParams, pageToken, pageNumbe data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -161,7 +173,12 @@ func (c *ApiService) PageService(params *ListServiceParams, pageToken, pageNumbe // Lists Service records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListService(params *ListServiceParams) ([]IpMessagingV2Service, error) { - response, errors := c.StreamService(params) + return c.ListServiceWithContext(context.TODO(), params) +} + +// Lists Service records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListServiceWithContext(ctx context.Context, params *ListServiceParams) ([]IpMessagingV2Service, error) { + response, errors := c.StreamServiceWithContext(ctx, params) records := make([]IpMessagingV2Service, 0) for record := range response { @@ -177,6 +194,11 @@ func (c *ApiService) ListService(params *ListServiceParams) ([]IpMessagingV2Serv // Streams Service records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamService(params *ListServiceParams) (chan IpMessagingV2Service, chan error) { + return c.StreamServiceWithContext(context.TODO(), params) +} + +// Streams Service records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamServiceWithContext(ctx context.Context, params *ListServiceParams) (chan IpMessagingV2Service, chan error) { if params == nil { params = &ListServiceParams{} } @@ -185,19 +207,19 @@ func (c *ApiService) StreamService(params *ListServiceParams) (chan IpMessagingV recordChannel := make(chan IpMessagingV2Service, 1) errorChannel := make(chan error, 1) - response, err := c.PageService(params, "", "") + response, err := c.PageServiceWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamService(response, params, recordChannel, errorChannel) + go c.streamServiceWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamService(response *ListServiceResponse, params *ListServiceParams, recordChannel chan IpMessagingV2Service, errorChannel chan error) { +func (c *ApiService) streamServiceWithContext(ctx context.Context, response *ListServiceResponse, params *ListServiceParams, recordChannel chan IpMessagingV2Service, errorChannel chan error) { curRecord := 1 for response != nil { @@ -212,7 +234,7 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListServiceResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListServiceResponseWithContext) if err != nil { errorChannel <- err break @@ -227,11 +249,11 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe close(errorChannel) } -func (c *ApiService) getNextListServiceResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListServiceResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -436,8 +458,10 @@ func (params *UpdateServiceParams) SetNotificationsLogEnabled(NotificationsLogEn return params } -// func (c *ApiService) UpdateService(Sid string, params *UpdateServiceParams) (*IpMessagingV2Service, error) { + return c.UpdateServiceWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateServiceWithContext(ctx context.Context, Sid string, params *UpdateServiceParams) (*IpMessagingV2Service, error) { path := "/v2/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -542,7 +566,7 @@ func (c *ApiService) UpdateService(Sid string, params *UpdateServiceParams) (*Ip data.Set("Notifications.LogEnabled", fmt.Sprint(*params.NotificationsLogEnabled)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/ip_messaging/v2/services_bindings.go b/rest/ip_messaging/v2/services_bindings.go index 66eba541d..c822c57f1 100644 --- a/rest/ip_messaging/v2/services_bindings.go +++ b/rest/ip_messaging/v2/services_bindings.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -23,8 +24,10 @@ import ( "github.com/twilio/twilio-go/client" ) -// func (c *ApiService) DeleteBinding(ServiceSid string, Sid string) error { + return c.DeleteBindingWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) DeleteBindingWithContext(ctx context.Context, ServiceSid string, Sid string) error { path := "/v2/Services/{ServiceSid}/Bindings/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -34,7 +37,7 @@ func (c *ApiService) DeleteBinding(ServiceSid string, Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -44,8 +47,10 @@ func (c *ApiService) DeleteBinding(ServiceSid string, Sid string) error { return nil } -// func (c *ApiService) FetchBinding(ServiceSid string, Sid string) (*IpMessagingV2Binding, error) { + return c.FetchBindingWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) FetchBindingWithContext(ctx context.Context, ServiceSid string, Sid string) (*IpMessagingV2Binding, error) { path := "/v2/Services/{ServiceSid}/Bindings/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -55,7 +60,7 @@ func (c *ApiService) FetchBinding(ServiceSid string, Sid string) (*IpMessagingV2 "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -101,6 +106,11 @@ func (params *ListBindingParams) SetLimit(Limit int) *ListBindingParams { // Retrieve a single page of Binding records from the API. Request is executed immediately. func (c *ApiService) PageBinding(ServiceSid string, params *ListBindingParams, pageToken, pageNumber string) (*ListBindingResponse, error) { + return c.PageBindingWithContext(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Binding records from the API. Request is executed immediately. +func (c *ApiService) PageBindingWithContext(ctx context.Context, ServiceSid string, params *ListBindingParams, pageToken, pageNumber string) (*ListBindingResponse, error) { path := "/v2/Services/{ServiceSid}/Bindings" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -131,7 +141,7 @@ func (c *ApiService) PageBinding(ServiceSid string, params *ListBindingParams, p data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -148,7 +158,12 @@ func (c *ApiService) PageBinding(ServiceSid string, params *ListBindingParams, p // Lists Binding records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListBinding(ServiceSid string, params *ListBindingParams) ([]IpMessagingV2Binding, error) { - response, errors := c.StreamBinding(ServiceSid, params) + return c.ListBindingWithContext(context.TODO(), ServiceSid, params) +} + +// Lists Binding records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListBindingWithContext(ctx context.Context, ServiceSid string, params *ListBindingParams) ([]IpMessagingV2Binding, error) { + response, errors := c.StreamBindingWithContext(ctx, ServiceSid, params) records := make([]IpMessagingV2Binding, 0) for record := range response { @@ -164,6 +179,11 @@ func (c *ApiService) ListBinding(ServiceSid string, params *ListBindingParams) ( // Streams Binding records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamBinding(ServiceSid string, params *ListBindingParams) (chan IpMessagingV2Binding, chan error) { + return c.StreamBindingWithContext(context.TODO(), ServiceSid, params) +} + +// Streams Binding records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamBindingWithContext(ctx context.Context, ServiceSid string, params *ListBindingParams) (chan IpMessagingV2Binding, chan error) { if params == nil { params = &ListBindingParams{} } @@ -172,19 +192,19 @@ func (c *ApiService) StreamBinding(ServiceSid string, params *ListBindingParams) recordChannel := make(chan IpMessagingV2Binding, 1) errorChannel := make(chan error, 1) - response, err := c.PageBinding(ServiceSid, params, "", "") + response, err := c.PageBindingWithContext(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamBinding(response, params, recordChannel, errorChannel) + go c.streamBindingWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamBinding(response *ListBindingResponse, params *ListBindingParams, recordChannel chan IpMessagingV2Binding, errorChannel chan error) { +func (c *ApiService) streamBindingWithContext(ctx context.Context, response *ListBindingResponse, params *ListBindingParams, recordChannel chan IpMessagingV2Binding, errorChannel chan error) { curRecord := 1 for response != nil { @@ -199,7 +219,7 @@ func (c *ApiService) streamBinding(response *ListBindingResponse, params *ListBi } } - record, err := client.GetNext(c.baseURL, response, c.getNextListBindingResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListBindingResponseWithContext) if err != nil { errorChannel <- err break @@ -214,11 +234,11 @@ func (c *ApiService) streamBinding(response *ListBindingResponse, params *ListBi close(errorChannel) } -func (c *ApiService) getNextListBindingResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListBindingResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/ip_messaging/v2/services_channels.go b/rest/ip_messaging/v2/services_channels.go index f0fbbcd75..bcb5d0af9 100644 --- a/rest/ip_messaging/v2/services_channels.go +++ b/rest/ip_messaging/v2/services_channels.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -77,8 +78,10 @@ func (params *CreateChannelParams) SetCreatedBy(CreatedBy string) *CreateChannel return params } -// func (c *ApiService) CreateChannel(ServiceSid string, params *CreateChannelParams) (*IpMessagingV2Channel, error) { + return c.CreateChannelWithContext(context.TODO(), ServiceSid, params) +} +func (c *ApiService) CreateChannelWithContext(ctx context.Context, ServiceSid string, params *CreateChannelParams) (*IpMessagingV2Channel, error) { path := "/v2/Services/{ServiceSid}/Channels" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -112,7 +115,7 @@ func (c *ApiService) CreateChannel(ServiceSid string, params *CreateChannelParam if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -138,8 +141,10 @@ func (params *DeleteChannelParams) SetXTwilioWebhookEnabled(XTwilioWebhookEnable return params } -// func (c *ApiService) DeleteChannel(ServiceSid string, Sid string, params *DeleteChannelParams) error { + return c.DeleteChannelWithContext(context.TODO(), ServiceSid, Sid, params) +} +func (c *ApiService) DeleteChannelWithContext(ctx context.Context, ServiceSid string, Sid string, params *DeleteChannelParams) error { path := "/v2/Services/{ServiceSid}/Channels/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -152,7 +157,7 @@ func (c *ApiService) DeleteChannel(ServiceSid string, Sid string, params *Delete if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -162,8 +167,10 @@ func (c *ApiService) DeleteChannel(ServiceSid string, Sid string, params *Delete return nil } -// func (c *ApiService) FetchChannel(ServiceSid string, Sid string) (*IpMessagingV2Channel, error) { + return c.FetchChannelWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) FetchChannelWithContext(ctx context.Context, ServiceSid string, Sid string) (*IpMessagingV2Channel, error) { path := "/v2/Services/{ServiceSid}/Channels/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -173,7 +180,7 @@ func (c *ApiService) FetchChannel(ServiceSid string, Sid string) (*IpMessagingV2 "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -213,6 +220,11 @@ func (params *ListChannelParams) SetLimit(Limit int) *ListChannelParams { // Retrieve a single page of Channel records from the API. Request is executed immediately. func (c *ApiService) PageChannel(ServiceSid string, params *ListChannelParams, pageToken, pageNumber string) (*ListChannelResponse, error) { + return c.PageChannelWithContext(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Channel records from the API. Request is executed immediately. +func (c *ApiService) PageChannelWithContext(ctx context.Context, ServiceSid string, params *ListChannelParams, pageToken, pageNumber string) (*ListChannelResponse, error) { path := "/v2/Services/{ServiceSid}/Channels" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -238,7 +250,7 @@ func (c *ApiService) PageChannel(ServiceSid string, params *ListChannelParams, p data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -255,7 +267,12 @@ func (c *ApiService) PageChannel(ServiceSid string, params *ListChannelParams, p // Lists Channel records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListChannel(ServiceSid string, params *ListChannelParams) ([]IpMessagingV2Channel, error) { - response, errors := c.StreamChannel(ServiceSid, params) + return c.ListChannelWithContext(context.TODO(), ServiceSid, params) +} + +// Lists Channel records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListChannelWithContext(ctx context.Context, ServiceSid string, params *ListChannelParams) ([]IpMessagingV2Channel, error) { + response, errors := c.StreamChannelWithContext(ctx, ServiceSid, params) records := make([]IpMessagingV2Channel, 0) for record := range response { @@ -271,6 +288,11 @@ func (c *ApiService) ListChannel(ServiceSid string, params *ListChannelParams) ( // Streams Channel records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamChannel(ServiceSid string, params *ListChannelParams) (chan IpMessagingV2Channel, chan error) { + return c.StreamChannelWithContext(context.TODO(), ServiceSid, params) +} + +// Streams Channel records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamChannelWithContext(ctx context.Context, ServiceSid string, params *ListChannelParams) (chan IpMessagingV2Channel, chan error) { if params == nil { params = &ListChannelParams{} } @@ -279,19 +301,19 @@ func (c *ApiService) StreamChannel(ServiceSid string, params *ListChannelParams) recordChannel := make(chan IpMessagingV2Channel, 1) errorChannel := make(chan error, 1) - response, err := c.PageChannel(ServiceSid, params, "", "") + response, err := c.PageChannelWithContext(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamChannel(response, params, recordChannel, errorChannel) + go c.streamChannelWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamChannel(response *ListChannelResponse, params *ListChannelParams, recordChannel chan IpMessagingV2Channel, errorChannel chan error) { +func (c *ApiService) streamChannelWithContext(ctx context.Context, response *ListChannelResponse, params *ListChannelParams, recordChannel chan IpMessagingV2Channel, errorChannel chan error) { curRecord := 1 for response != nil { @@ -306,7 +328,7 @@ func (c *ApiService) streamChannel(response *ListChannelResponse, params *ListCh } } - record, err := client.GetNext(c.baseURL, response, c.getNextListChannelResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListChannelResponseWithContext) if err != nil { errorChannel <- err break @@ -321,11 +343,11 @@ func (c *ApiService) streamChannel(response *ListChannelResponse, params *ListCh close(errorChannel) } -func (c *ApiService) getNextListChannelResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListChannelResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -386,8 +408,10 @@ func (params *UpdateChannelParams) SetCreatedBy(CreatedBy string) *UpdateChannel return params } -// func (c *ApiService) UpdateChannel(ServiceSid string, Sid string, params *UpdateChannelParams) (*IpMessagingV2Channel, error) { + return c.UpdateChannelWithContext(context.TODO(), ServiceSid, Sid, params) +} +func (c *ApiService) UpdateChannelWithContext(ctx context.Context, ServiceSid string, Sid string, params *UpdateChannelParams) (*IpMessagingV2Channel, error) { path := "/v2/Services/{ServiceSid}/Channels/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -419,7 +443,7 @@ func (c *ApiService) UpdateChannel(ServiceSid string, Sid string, params *Update if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/ip_messaging/v2/services_channels_invites.go b/rest/ip_messaging/v2/services_channels_invites.go index 2a84dd9af..ad17f7f65 100644 --- a/rest/ip_messaging/v2/services_channels_invites.go +++ b/rest/ip_messaging/v2/services_channels_invites.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -40,8 +41,10 @@ func (params *CreateInviteParams) SetRoleSid(RoleSid string) *CreateInviteParams return params } -// func (c *ApiService) CreateInvite(ServiceSid string, ChannelSid string, params *CreateInviteParams) (*IpMessagingV2Invite, error) { + return c.CreateInviteWithContext(context.TODO(), ServiceSid, ChannelSid, params) +} +func (c *ApiService) CreateInviteWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *CreateInviteParams) (*IpMessagingV2Invite, error) { path := "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Invites" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -58,7 +61,7 @@ func (c *ApiService) CreateInvite(ServiceSid string, ChannelSid string, params * data.Set("RoleSid", *params.RoleSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -73,8 +76,10 @@ func (c *ApiService) CreateInvite(ServiceSid string, ChannelSid string, params * return ps, err } -// func (c *ApiService) DeleteInvite(ServiceSid string, ChannelSid string, Sid string) error { + return c.DeleteInviteWithContext(context.TODO(), ServiceSid, ChannelSid, Sid) +} +func (c *ApiService) DeleteInviteWithContext(ctx context.Context, ServiceSid string, ChannelSid string, Sid string) error { path := "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Invites/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -85,7 +90,7 @@ func (c *ApiService) DeleteInvite(ServiceSid string, ChannelSid string, Sid stri "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -95,8 +100,10 @@ func (c *ApiService) DeleteInvite(ServiceSid string, ChannelSid string, Sid stri return nil } -// func (c *ApiService) FetchInvite(ServiceSid string, ChannelSid string, Sid string) (*IpMessagingV2Invite, error) { + return c.FetchInviteWithContext(context.TODO(), ServiceSid, ChannelSid, Sid) +} +func (c *ApiService) FetchInviteWithContext(ctx context.Context, ServiceSid string, ChannelSid string, Sid string) (*IpMessagingV2Invite, error) { path := "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Invites/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -107,7 +114,7 @@ func (c *ApiService) FetchInvite(ServiceSid string, ChannelSid string, Sid strin "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -147,6 +154,11 @@ func (params *ListInviteParams) SetLimit(Limit int) *ListInviteParams { // Retrieve a single page of Invite records from the API. Request is executed immediately. func (c *ApiService) PageInvite(ServiceSid string, ChannelSid string, params *ListInviteParams, pageToken, pageNumber string) (*ListInviteResponse, error) { + return c.PageInviteWithContext(context.TODO(), ServiceSid, ChannelSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Invite records from the API. Request is executed immediately. +func (c *ApiService) PageInviteWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *ListInviteParams, pageToken, pageNumber string) (*ListInviteResponse, error) { path := "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Invites" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -173,7 +185,7 @@ func (c *ApiService) PageInvite(ServiceSid string, ChannelSid string, params *Li data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -190,7 +202,12 @@ func (c *ApiService) PageInvite(ServiceSid string, ChannelSid string, params *Li // Lists Invite records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListInvite(ServiceSid string, ChannelSid string, params *ListInviteParams) ([]IpMessagingV2Invite, error) { - response, errors := c.StreamInvite(ServiceSid, ChannelSid, params) + return c.ListInviteWithContext(context.TODO(), ServiceSid, ChannelSid, params) +} + +// Lists Invite records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListInviteWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *ListInviteParams) ([]IpMessagingV2Invite, error) { + response, errors := c.StreamInviteWithContext(ctx, ServiceSid, ChannelSid, params) records := make([]IpMessagingV2Invite, 0) for record := range response { @@ -206,6 +223,11 @@ func (c *ApiService) ListInvite(ServiceSid string, ChannelSid string, params *Li // Streams Invite records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamInvite(ServiceSid string, ChannelSid string, params *ListInviteParams) (chan IpMessagingV2Invite, chan error) { + return c.StreamInviteWithContext(context.TODO(), ServiceSid, ChannelSid, params) +} + +// Streams Invite records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamInviteWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *ListInviteParams) (chan IpMessagingV2Invite, chan error) { if params == nil { params = &ListInviteParams{} } @@ -214,19 +236,19 @@ func (c *ApiService) StreamInvite(ServiceSid string, ChannelSid string, params * recordChannel := make(chan IpMessagingV2Invite, 1) errorChannel := make(chan error, 1) - response, err := c.PageInvite(ServiceSid, ChannelSid, params, "", "") + response, err := c.PageInviteWithContext(ctx, ServiceSid, ChannelSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamInvite(response, params, recordChannel, errorChannel) + go c.streamInviteWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamInvite(response *ListInviteResponse, params *ListInviteParams, recordChannel chan IpMessagingV2Invite, errorChannel chan error) { +func (c *ApiService) streamInviteWithContext(ctx context.Context, response *ListInviteResponse, params *ListInviteParams, recordChannel chan IpMessagingV2Invite, errorChannel chan error) { curRecord := 1 for response != nil { @@ -241,7 +263,7 @@ func (c *ApiService) streamInvite(response *ListInviteResponse, params *ListInvi } } - record, err := client.GetNext(c.baseURL, response, c.getNextListInviteResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListInviteResponseWithContext) if err != nil { errorChannel <- err break @@ -256,11 +278,11 @@ func (c *ApiService) streamInvite(response *ListInviteResponse, params *ListInvi close(errorChannel) } -func (c *ApiService) getNextListInviteResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListInviteResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/ip_messaging/v2/services_channels_members.go b/rest/ip_messaging/v2/services_channels_members.go index f33396ada..f64b0c776 100644 --- a/rest/ip_messaging/v2/services_channels_members.go +++ b/rest/ip_messaging/v2/services_channels_members.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -77,8 +78,10 @@ func (params *CreateMemberParams) SetAttributes(Attributes string) *CreateMember return params } -// func (c *ApiService) CreateMember(ServiceSid string, ChannelSid string, params *CreateMemberParams) (*IpMessagingV2Member, error) { + return c.CreateMemberWithContext(context.TODO(), ServiceSid, ChannelSid, params) +} +func (c *ApiService) CreateMemberWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *CreateMemberParams) (*IpMessagingV2Member, error) { path := "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Members" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -113,7 +116,7 @@ func (c *ApiService) CreateMember(ServiceSid string, ChannelSid string, params * if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -139,8 +142,10 @@ func (params *DeleteMemberParams) SetXTwilioWebhookEnabled(XTwilioWebhookEnabled return params } -// func (c *ApiService) DeleteMember(ServiceSid string, ChannelSid string, Sid string, params *DeleteMemberParams) error { + return c.DeleteMemberWithContext(context.TODO(), ServiceSid, ChannelSid, Sid, params) +} +func (c *ApiService) DeleteMemberWithContext(ctx context.Context, ServiceSid string, ChannelSid string, Sid string, params *DeleteMemberParams) error { path := "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -154,7 +159,7 @@ func (c *ApiService) DeleteMember(ServiceSid string, ChannelSid string, Sid stri if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -164,8 +169,10 @@ func (c *ApiService) DeleteMember(ServiceSid string, ChannelSid string, Sid stri return nil } -// func (c *ApiService) FetchMember(ServiceSid string, ChannelSid string, Sid string) (*IpMessagingV2Member, error) { + return c.FetchMemberWithContext(context.TODO(), ServiceSid, ChannelSid, Sid) +} +func (c *ApiService) FetchMemberWithContext(ctx context.Context, ServiceSid string, ChannelSid string, Sid string) (*IpMessagingV2Member, error) { path := "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -176,7 +183,7 @@ func (c *ApiService) FetchMember(ServiceSid string, ChannelSid string, Sid strin "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -216,6 +223,11 @@ func (params *ListMemberParams) SetLimit(Limit int) *ListMemberParams { // Retrieve a single page of Member records from the API. Request is executed immediately. func (c *ApiService) PageMember(ServiceSid string, ChannelSid string, params *ListMemberParams, pageToken, pageNumber string) (*ListMemberResponse, error) { + return c.PageMemberWithContext(context.TODO(), ServiceSid, ChannelSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Member records from the API. Request is executed immediately. +func (c *ApiService) PageMemberWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *ListMemberParams, pageToken, pageNumber string) (*ListMemberResponse, error) { path := "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Members" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -242,7 +254,7 @@ func (c *ApiService) PageMember(ServiceSid string, ChannelSid string, params *Li data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -259,7 +271,12 @@ func (c *ApiService) PageMember(ServiceSid string, ChannelSid string, params *Li // Lists Member records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListMember(ServiceSid string, ChannelSid string, params *ListMemberParams) ([]IpMessagingV2Member, error) { - response, errors := c.StreamMember(ServiceSid, ChannelSid, params) + return c.ListMemberWithContext(context.TODO(), ServiceSid, ChannelSid, params) +} + +// Lists Member records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListMemberWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *ListMemberParams) ([]IpMessagingV2Member, error) { + response, errors := c.StreamMemberWithContext(ctx, ServiceSid, ChannelSid, params) records := make([]IpMessagingV2Member, 0) for record := range response { @@ -275,6 +292,11 @@ func (c *ApiService) ListMember(ServiceSid string, ChannelSid string, params *Li // Streams Member records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamMember(ServiceSid string, ChannelSid string, params *ListMemberParams) (chan IpMessagingV2Member, chan error) { + return c.StreamMemberWithContext(context.TODO(), ServiceSid, ChannelSid, params) +} + +// Streams Member records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamMemberWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *ListMemberParams) (chan IpMessagingV2Member, chan error) { if params == nil { params = &ListMemberParams{} } @@ -283,19 +305,19 @@ func (c *ApiService) StreamMember(ServiceSid string, ChannelSid string, params * recordChannel := make(chan IpMessagingV2Member, 1) errorChannel := make(chan error, 1) - response, err := c.PageMember(ServiceSid, ChannelSid, params, "", "") + response, err := c.PageMemberWithContext(ctx, ServiceSid, ChannelSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamMember(response, params, recordChannel, errorChannel) + go c.streamMemberWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamMember(response *ListMemberResponse, params *ListMemberParams, recordChannel chan IpMessagingV2Member, errorChannel chan error) { +func (c *ApiService) streamMemberWithContext(ctx context.Context, response *ListMemberResponse, params *ListMemberParams, recordChannel chan IpMessagingV2Member, errorChannel chan error) { curRecord := 1 for response != nil { @@ -310,7 +332,7 @@ func (c *ApiService) streamMember(response *ListMemberResponse, params *ListMemb } } - record, err := client.GetNext(c.baseURL, response, c.getNextListMemberResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListMemberResponseWithContext) if err != nil { errorChannel <- err break @@ -325,11 +347,11 @@ func (c *ApiService) streamMember(response *ListMemberResponse, params *ListMemb close(errorChannel) } -func (c *ApiService) getNextListMemberResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListMemberResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -390,8 +412,10 @@ func (params *UpdateMemberParams) SetAttributes(Attributes string) *UpdateMember return params } -// func (c *ApiService) UpdateMember(ServiceSid string, ChannelSid string, Sid string, params *UpdateMemberParams) (*IpMessagingV2Member, error) { + return c.UpdateMemberWithContext(context.TODO(), ServiceSid, ChannelSid, Sid, params) +} +func (c *ApiService) UpdateMemberWithContext(ctx context.Context, ServiceSid string, ChannelSid string, Sid string, params *UpdateMemberParams) (*IpMessagingV2Member, error) { path := "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -424,7 +448,7 @@ func (c *ApiService) UpdateMember(ServiceSid string, ChannelSid string, Sid stri if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/ip_messaging/v2/services_channels_messages.go b/rest/ip_messaging/v2/services_channels_messages.go index e24552ee7..2d7ada21f 100644 --- a/rest/ip_messaging/v2/services_channels_messages.go +++ b/rest/ip_messaging/v2/services_channels_messages.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -77,8 +78,10 @@ func (params *CreateMessageParams) SetMediaSid(MediaSid string) *CreateMessagePa return params } -// func (c *ApiService) CreateMessage(ServiceSid string, ChannelSid string, params *CreateMessageParams) (*IpMessagingV2Message, error) { + return c.CreateMessageWithContext(context.TODO(), ServiceSid, ChannelSid, params) +} +func (c *ApiService) CreateMessageWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *CreateMessageParams) (*IpMessagingV2Message, error) { path := "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -113,7 +116,7 @@ func (c *ApiService) CreateMessage(ServiceSid string, ChannelSid string, params if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -139,8 +142,10 @@ func (params *DeleteMessageParams) SetXTwilioWebhookEnabled(XTwilioWebhookEnable return params } -// func (c *ApiService) DeleteMessage(ServiceSid string, ChannelSid string, Sid string, params *DeleteMessageParams) error { + return c.DeleteMessageWithContext(context.TODO(), ServiceSid, ChannelSid, Sid, params) +} +func (c *ApiService) DeleteMessageWithContext(ctx context.Context, ServiceSid string, ChannelSid string, Sid string, params *DeleteMessageParams) error { path := "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -154,7 +159,7 @@ func (c *ApiService) DeleteMessage(ServiceSid string, ChannelSid string, Sid str if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -164,8 +169,10 @@ func (c *ApiService) DeleteMessage(ServiceSid string, ChannelSid string, Sid str return nil } -// func (c *ApiService) FetchMessage(ServiceSid string, ChannelSid string, Sid string) (*IpMessagingV2Message, error) { + return c.FetchMessageWithContext(context.TODO(), ServiceSid, ChannelSid, Sid) +} +func (c *ApiService) FetchMessageWithContext(ctx context.Context, ServiceSid string, ChannelSid string, Sid string) (*IpMessagingV2Message, error) { path := "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -176,7 +183,7 @@ func (c *ApiService) FetchMessage(ServiceSid string, ChannelSid string, Sid stri "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -216,6 +223,11 @@ func (params *ListMessageParams) SetLimit(Limit int) *ListMessageParams { // Retrieve a single page of Message records from the API. Request is executed immediately. func (c *ApiService) PageMessage(ServiceSid string, ChannelSid string, params *ListMessageParams, pageToken, pageNumber string) (*ListMessageResponse, error) { + return c.PageMessageWithContext(context.TODO(), ServiceSid, ChannelSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Message records from the API. Request is executed immediately. +func (c *ApiService) PageMessageWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *ListMessageParams, pageToken, pageNumber string) (*ListMessageResponse, error) { path := "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -240,7 +252,7 @@ func (c *ApiService) PageMessage(ServiceSid string, ChannelSid string, params *L data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -257,7 +269,12 @@ func (c *ApiService) PageMessage(ServiceSid string, ChannelSid string, params *L // Lists Message records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListMessage(ServiceSid string, ChannelSid string, params *ListMessageParams) ([]IpMessagingV2Message, error) { - response, errors := c.StreamMessage(ServiceSid, ChannelSid, params) + return c.ListMessageWithContext(context.TODO(), ServiceSid, ChannelSid, params) +} + +// Lists Message records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListMessageWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *ListMessageParams) ([]IpMessagingV2Message, error) { + response, errors := c.StreamMessageWithContext(ctx, ServiceSid, ChannelSid, params) records := make([]IpMessagingV2Message, 0) for record := range response { @@ -273,6 +290,11 @@ func (c *ApiService) ListMessage(ServiceSid string, ChannelSid string, params *L // Streams Message records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamMessage(ServiceSid string, ChannelSid string, params *ListMessageParams) (chan IpMessagingV2Message, chan error) { + return c.StreamMessageWithContext(context.TODO(), ServiceSid, ChannelSid, params) +} + +// Streams Message records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamMessageWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *ListMessageParams) (chan IpMessagingV2Message, chan error) { if params == nil { params = &ListMessageParams{} } @@ -281,19 +303,19 @@ func (c *ApiService) StreamMessage(ServiceSid string, ChannelSid string, params recordChannel := make(chan IpMessagingV2Message, 1) errorChannel := make(chan error, 1) - response, err := c.PageMessage(ServiceSid, ChannelSid, params, "", "") + response, err := c.PageMessageWithContext(ctx, ServiceSid, ChannelSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamMessage(response, params, recordChannel, errorChannel) + go c.streamMessageWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamMessage(response *ListMessageResponse, params *ListMessageParams, recordChannel chan IpMessagingV2Message, errorChannel chan error) { +func (c *ApiService) streamMessageWithContext(ctx context.Context, response *ListMessageResponse, params *ListMessageParams, recordChannel chan IpMessagingV2Message, errorChannel chan error) { curRecord := 1 for response != nil { @@ -308,7 +330,7 @@ func (c *ApiService) streamMessage(response *ListMessageResponse, params *ListMe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListMessageResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListMessageResponseWithContext) if err != nil { errorChannel <- err break @@ -323,11 +345,11 @@ func (c *ApiService) streamMessage(response *ListMessageResponse, params *ListMe close(errorChannel) } -func (c *ApiService) getNextListMessageResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListMessageResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -388,8 +410,10 @@ func (params *UpdateMessageParams) SetFrom(From string) *UpdateMessageParams { return params } -// func (c *ApiService) UpdateMessage(ServiceSid string, ChannelSid string, Sid string, params *UpdateMessageParams) (*IpMessagingV2Message, error) { + return c.UpdateMessageWithContext(context.TODO(), ServiceSid, ChannelSid, Sid, params) +} +func (c *ApiService) UpdateMessageWithContext(ctx context.Context, ServiceSid string, ChannelSid string, Sid string, params *UpdateMessageParams) (*IpMessagingV2Message, error) { path := "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -422,7 +446,7 @@ func (c *ApiService) UpdateMessage(ServiceSid string, ChannelSid string, Sid str if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/ip_messaging/v2/services_channels_webhooks.go b/rest/ip_messaging/v2/services_channels_webhooks.go index ceee589a0..a34abb666 100644 --- a/rest/ip_messaging/v2/services_channels_webhooks.go +++ b/rest/ip_messaging/v2/services_channels_webhooks.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -70,8 +71,10 @@ func (params *CreateChannelWebhookParams) SetConfigurationRetryCount(Configurati return params } -// func (c *ApiService) CreateChannelWebhook(ServiceSid string, ChannelSid string, params *CreateChannelWebhookParams) (*IpMessagingV2ChannelWebhook, error) { + return c.CreateChannelWebhookWithContext(context.TODO(), ServiceSid, ChannelSid, params) +} +func (c *ApiService) CreateChannelWebhookWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *CreateChannelWebhookParams) (*IpMessagingV2ChannelWebhook, error) { path := "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Webhooks" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -107,7 +110,7 @@ func (c *ApiService) CreateChannelWebhook(ServiceSid string, ChannelSid string, data.Set("Configuration.RetryCount", fmt.Sprint(*params.ConfigurationRetryCount)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -122,8 +125,10 @@ func (c *ApiService) CreateChannelWebhook(ServiceSid string, ChannelSid string, return ps, err } -// func (c *ApiService) DeleteChannelWebhook(ServiceSid string, ChannelSid string, Sid string) error { + return c.DeleteChannelWebhookWithContext(context.TODO(), ServiceSid, ChannelSid, Sid) +} +func (c *ApiService) DeleteChannelWebhookWithContext(ctx context.Context, ServiceSid string, ChannelSid string, Sid string) error { path := "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Webhooks/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -134,7 +139,7 @@ func (c *ApiService) DeleteChannelWebhook(ServiceSid string, ChannelSid string, "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -144,8 +149,10 @@ func (c *ApiService) DeleteChannelWebhook(ServiceSid string, ChannelSid string, return nil } -// func (c *ApiService) FetchChannelWebhook(ServiceSid string, ChannelSid string, Sid string) (*IpMessagingV2ChannelWebhook, error) { + return c.FetchChannelWebhookWithContext(context.TODO(), ServiceSid, ChannelSid, Sid) +} +func (c *ApiService) FetchChannelWebhookWithContext(ctx context.Context, ServiceSid string, ChannelSid string, Sid string) (*IpMessagingV2ChannelWebhook, error) { path := "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Webhooks/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -156,7 +163,7 @@ func (c *ApiService) FetchChannelWebhook(ServiceSid string, ChannelSid string, S "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -190,6 +197,11 @@ func (params *ListChannelWebhookParams) SetLimit(Limit int) *ListChannelWebhookP // Retrieve a single page of ChannelWebhook records from the API. Request is executed immediately. func (c *ApiService) PageChannelWebhook(ServiceSid string, ChannelSid string, params *ListChannelWebhookParams, pageToken, pageNumber string) (*ListChannelWebhookResponse, error) { + return c.PageChannelWebhookWithContext(context.TODO(), ServiceSid, ChannelSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ChannelWebhook records from the API. Request is executed immediately. +func (c *ApiService) PageChannelWebhookWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *ListChannelWebhookParams, pageToken, pageNumber string) (*ListChannelWebhookResponse, error) { path := "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Webhooks" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -211,7 +223,7 @@ func (c *ApiService) PageChannelWebhook(ServiceSid string, ChannelSid string, pa data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -228,7 +240,12 @@ func (c *ApiService) PageChannelWebhook(ServiceSid string, ChannelSid string, pa // Lists ChannelWebhook records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListChannelWebhook(ServiceSid string, ChannelSid string, params *ListChannelWebhookParams) ([]IpMessagingV2ChannelWebhook, error) { - response, errors := c.StreamChannelWebhook(ServiceSid, ChannelSid, params) + return c.ListChannelWebhookWithContext(context.TODO(), ServiceSid, ChannelSid, params) +} + +// Lists ChannelWebhook records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListChannelWebhookWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *ListChannelWebhookParams) ([]IpMessagingV2ChannelWebhook, error) { + response, errors := c.StreamChannelWebhookWithContext(ctx, ServiceSid, ChannelSid, params) records := make([]IpMessagingV2ChannelWebhook, 0) for record := range response { @@ -244,6 +261,11 @@ func (c *ApiService) ListChannelWebhook(ServiceSid string, ChannelSid string, pa // Streams ChannelWebhook records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamChannelWebhook(ServiceSid string, ChannelSid string, params *ListChannelWebhookParams) (chan IpMessagingV2ChannelWebhook, chan error) { + return c.StreamChannelWebhookWithContext(context.TODO(), ServiceSid, ChannelSid, params) +} + +// Streams ChannelWebhook records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamChannelWebhookWithContext(ctx context.Context, ServiceSid string, ChannelSid string, params *ListChannelWebhookParams) (chan IpMessagingV2ChannelWebhook, chan error) { if params == nil { params = &ListChannelWebhookParams{} } @@ -252,19 +274,19 @@ func (c *ApiService) StreamChannelWebhook(ServiceSid string, ChannelSid string, recordChannel := make(chan IpMessagingV2ChannelWebhook, 1) errorChannel := make(chan error, 1) - response, err := c.PageChannelWebhook(ServiceSid, ChannelSid, params, "", "") + response, err := c.PageChannelWebhookWithContext(ctx, ServiceSid, ChannelSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamChannelWebhook(response, params, recordChannel, errorChannel) + go c.streamChannelWebhookWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamChannelWebhook(response *ListChannelWebhookResponse, params *ListChannelWebhookParams, recordChannel chan IpMessagingV2ChannelWebhook, errorChannel chan error) { +func (c *ApiService) streamChannelWebhookWithContext(ctx context.Context, response *ListChannelWebhookResponse, params *ListChannelWebhookParams, recordChannel chan IpMessagingV2ChannelWebhook, errorChannel chan error) { curRecord := 1 for response != nil { @@ -279,7 +301,7 @@ func (c *ApiService) streamChannelWebhook(response *ListChannelWebhookResponse, } } - record, err := client.GetNext(c.baseURL, response, c.getNextListChannelWebhookResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListChannelWebhookResponseWithContext) if err != nil { errorChannel <- err break @@ -294,11 +316,11 @@ func (c *ApiService) streamChannelWebhook(response *ListChannelWebhookResponse, close(errorChannel) } -func (c *ApiService) getNextListChannelWebhookResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListChannelWebhookResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -353,8 +375,10 @@ func (params *UpdateChannelWebhookParams) SetConfigurationRetryCount(Configurati return params } -// func (c *ApiService) UpdateChannelWebhook(ServiceSid string, ChannelSid string, Sid string, params *UpdateChannelWebhookParams) (*IpMessagingV2ChannelWebhook, error) { + return c.UpdateChannelWebhookWithContext(context.TODO(), ServiceSid, ChannelSid, Sid, params) +} +func (c *ApiService) UpdateChannelWebhookWithContext(ctx context.Context, ServiceSid string, ChannelSid string, Sid string, params *UpdateChannelWebhookParams) (*IpMessagingV2ChannelWebhook, error) { path := "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Webhooks/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ChannelSid"+"}", ChannelSid, -1) @@ -388,7 +412,7 @@ func (c *ApiService) UpdateChannelWebhook(ServiceSid string, ChannelSid string, data.Set("Configuration.RetryCount", fmt.Sprint(*params.ConfigurationRetryCount)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/ip_messaging/v2/services_roles.go b/rest/ip_messaging/v2/services_roles.go index 160f32bb2..360ad7390 100644 --- a/rest/ip_messaging/v2/services_roles.go +++ b/rest/ip_messaging/v2/services_roles.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -46,8 +47,10 @@ func (params *CreateRoleParams) SetPermission(Permission []string) *CreateRolePa return params } -// func (c *ApiService) CreateRole(ServiceSid string, params *CreateRoleParams) (*IpMessagingV2Role, error) { + return c.CreateRoleWithContext(context.TODO(), ServiceSid, params) +} +func (c *ApiService) CreateRoleWithContext(ctx context.Context, ServiceSid string, params *CreateRoleParams) (*IpMessagingV2Role, error) { path := "/v2/Services/{ServiceSid}/Roles" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -68,7 +71,7 @@ func (c *ApiService) CreateRole(ServiceSid string, params *CreateRoleParams) (*I } } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -83,8 +86,10 @@ func (c *ApiService) CreateRole(ServiceSid string, params *CreateRoleParams) (*I return ps, err } -// func (c *ApiService) DeleteRole(ServiceSid string, Sid string) error { + return c.DeleteRoleWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) DeleteRoleWithContext(ctx context.Context, ServiceSid string, Sid string) error { path := "/v2/Services/{ServiceSid}/Roles/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -94,7 +99,7 @@ func (c *ApiService) DeleteRole(ServiceSid string, Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -104,8 +109,10 @@ func (c *ApiService) DeleteRole(ServiceSid string, Sid string) error { return nil } -// func (c *ApiService) FetchRole(ServiceSid string, Sid string) (*IpMessagingV2Role, error) { + return c.FetchRoleWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) FetchRoleWithContext(ctx context.Context, ServiceSid string, Sid string) (*IpMessagingV2Role, error) { path := "/v2/Services/{ServiceSid}/Roles/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -115,7 +122,7 @@ func (c *ApiService) FetchRole(ServiceSid string, Sid string) (*IpMessagingV2Rol "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -149,6 +156,11 @@ func (params *ListRoleParams) SetLimit(Limit int) *ListRoleParams { // Retrieve a single page of Role records from the API. Request is executed immediately. func (c *ApiService) PageRole(ServiceSid string, params *ListRoleParams, pageToken, pageNumber string) (*ListRoleResponse, error) { + return c.PageRoleWithContext(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Role records from the API. Request is executed immediately. +func (c *ApiService) PageRoleWithContext(ctx context.Context, ServiceSid string, params *ListRoleParams, pageToken, pageNumber string) (*ListRoleResponse, error) { path := "/v2/Services/{ServiceSid}/Roles" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -169,7 +181,7 @@ func (c *ApiService) PageRole(ServiceSid string, params *ListRoleParams, pageTok data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -186,7 +198,12 @@ func (c *ApiService) PageRole(ServiceSid string, params *ListRoleParams, pageTok // Lists Role records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListRole(ServiceSid string, params *ListRoleParams) ([]IpMessagingV2Role, error) { - response, errors := c.StreamRole(ServiceSid, params) + return c.ListRoleWithContext(context.TODO(), ServiceSid, params) +} + +// Lists Role records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListRoleWithContext(ctx context.Context, ServiceSid string, params *ListRoleParams) ([]IpMessagingV2Role, error) { + response, errors := c.StreamRoleWithContext(ctx, ServiceSid, params) records := make([]IpMessagingV2Role, 0) for record := range response { @@ -202,6 +219,11 @@ func (c *ApiService) ListRole(ServiceSid string, params *ListRoleParams) ([]IpMe // Streams Role records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamRole(ServiceSid string, params *ListRoleParams) (chan IpMessagingV2Role, chan error) { + return c.StreamRoleWithContext(context.TODO(), ServiceSid, params) +} + +// Streams Role records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamRoleWithContext(ctx context.Context, ServiceSid string, params *ListRoleParams) (chan IpMessagingV2Role, chan error) { if params == nil { params = &ListRoleParams{} } @@ -210,19 +232,19 @@ func (c *ApiService) StreamRole(ServiceSid string, params *ListRoleParams) (chan recordChannel := make(chan IpMessagingV2Role, 1) errorChannel := make(chan error, 1) - response, err := c.PageRole(ServiceSid, params, "", "") + response, err := c.PageRoleWithContext(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamRole(response, params, recordChannel, errorChannel) + go c.streamRoleWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamRole(response *ListRoleResponse, params *ListRoleParams, recordChannel chan IpMessagingV2Role, errorChannel chan error) { +func (c *ApiService) streamRoleWithContext(ctx context.Context, response *ListRoleResponse, params *ListRoleParams, recordChannel chan IpMessagingV2Role, errorChannel chan error) { curRecord := 1 for response != nil { @@ -237,7 +259,7 @@ func (c *ApiService) streamRole(response *ListRoleResponse, params *ListRolePara } } - record, err := client.GetNext(c.baseURL, response, c.getNextListRoleResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListRoleResponseWithContext) if err != nil { errorChannel <- err break @@ -252,11 +274,11 @@ func (c *ApiService) streamRole(response *ListRoleResponse, params *ListRolePara close(errorChannel) } -func (c *ApiService) getNextListRoleResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListRoleResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -281,8 +303,10 @@ func (params *UpdateRoleParams) SetPermission(Permission []string) *UpdateRolePa return params } -// func (c *ApiService) UpdateRole(ServiceSid string, Sid string, params *UpdateRoleParams) (*IpMessagingV2Role, error) { + return c.UpdateRoleWithContext(context.TODO(), ServiceSid, Sid, params) +} +func (c *ApiService) UpdateRoleWithContext(ctx context.Context, ServiceSid string, Sid string, params *UpdateRoleParams) (*IpMessagingV2Role, error) { path := "/v2/Services/{ServiceSid}/Roles/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -298,7 +322,7 @@ func (c *ApiService) UpdateRole(ServiceSid string, Sid string, params *UpdateRol } } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/ip_messaging/v2/services_users.go b/rest/ip_messaging/v2/services_users.go index 879f15e56..5c546c111 100644 --- a/rest/ip_messaging/v2/services_users.go +++ b/rest/ip_messaging/v2/services_users.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -58,8 +59,10 @@ func (params *CreateUserParams) SetFriendlyName(FriendlyName string) *CreateUser return params } -// func (c *ApiService) CreateUser(ServiceSid string, params *CreateUserParams) (*IpMessagingV2User, error) { + return c.CreateUserWithContext(context.TODO(), ServiceSid, params) +} +func (c *ApiService) CreateUserWithContext(ctx context.Context, ServiceSid string, params *CreateUserParams) (*IpMessagingV2User, error) { path := "/v2/Services/{ServiceSid}/Users" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -84,7 +87,7 @@ func (c *ApiService) CreateUser(ServiceSid string, params *CreateUserParams) (*I if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -99,8 +102,10 @@ func (c *ApiService) CreateUser(ServiceSid string, params *CreateUserParams) (*I return ps, err } -// func (c *ApiService) DeleteUser(ServiceSid string, Sid string) error { + return c.DeleteUserWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) DeleteUserWithContext(ctx context.Context, ServiceSid string, Sid string) error { path := "/v2/Services/{ServiceSid}/Users/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -110,7 +115,7 @@ func (c *ApiService) DeleteUser(ServiceSid string, Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -120,8 +125,10 @@ func (c *ApiService) DeleteUser(ServiceSid string, Sid string) error { return nil } -// func (c *ApiService) FetchUser(ServiceSid string, Sid string) (*IpMessagingV2User, error) { + return c.FetchUserWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) FetchUserWithContext(ctx context.Context, ServiceSid string, Sid string) (*IpMessagingV2User, error) { path := "/v2/Services/{ServiceSid}/Users/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -131,7 +138,7 @@ func (c *ApiService) FetchUser(ServiceSid string, Sid string) (*IpMessagingV2Use "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -165,6 +172,11 @@ func (params *ListUserParams) SetLimit(Limit int) *ListUserParams { // Retrieve a single page of User records from the API. Request is executed immediately. func (c *ApiService) PageUser(ServiceSid string, params *ListUserParams, pageToken, pageNumber string) (*ListUserResponse, error) { + return c.PageUserWithContext(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of User records from the API. Request is executed immediately. +func (c *ApiService) PageUserWithContext(ctx context.Context, ServiceSid string, params *ListUserParams, pageToken, pageNumber string) (*ListUserResponse, error) { path := "/v2/Services/{ServiceSid}/Users" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -185,7 +197,7 @@ func (c *ApiService) PageUser(ServiceSid string, params *ListUserParams, pageTok data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -202,7 +214,12 @@ func (c *ApiService) PageUser(ServiceSid string, params *ListUserParams, pageTok // Lists User records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListUser(ServiceSid string, params *ListUserParams) ([]IpMessagingV2User, error) { - response, errors := c.StreamUser(ServiceSid, params) + return c.ListUserWithContext(context.TODO(), ServiceSid, params) +} + +// Lists User records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListUserWithContext(ctx context.Context, ServiceSid string, params *ListUserParams) ([]IpMessagingV2User, error) { + response, errors := c.StreamUserWithContext(ctx, ServiceSid, params) records := make([]IpMessagingV2User, 0) for record := range response { @@ -218,6 +235,11 @@ func (c *ApiService) ListUser(ServiceSid string, params *ListUserParams) ([]IpMe // Streams User records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamUser(ServiceSid string, params *ListUserParams) (chan IpMessagingV2User, chan error) { + return c.StreamUserWithContext(context.TODO(), ServiceSid, params) +} + +// Streams User records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamUserWithContext(ctx context.Context, ServiceSid string, params *ListUserParams) (chan IpMessagingV2User, chan error) { if params == nil { params = &ListUserParams{} } @@ -226,19 +248,19 @@ func (c *ApiService) StreamUser(ServiceSid string, params *ListUserParams) (chan recordChannel := make(chan IpMessagingV2User, 1) errorChannel := make(chan error, 1) - response, err := c.PageUser(ServiceSid, params, "", "") + response, err := c.PageUserWithContext(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUser(response, params, recordChannel, errorChannel) + go c.streamUserWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamUser(response *ListUserResponse, params *ListUserParams, recordChannel chan IpMessagingV2User, errorChannel chan error) { +func (c *ApiService) streamUserWithContext(ctx context.Context, response *ListUserResponse, params *ListUserParams, recordChannel chan IpMessagingV2User, errorChannel chan error) { curRecord := 1 for response != nil { @@ -253,7 +275,7 @@ func (c *ApiService) streamUser(response *ListUserResponse, params *ListUserPara } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUserResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListUserResponseWithContext) if err != nil { errorChannel <- err break @@ -268,11 +290,11 @@ func (c *ApiService) streamUser(response *ListUserResponse, params *ListUserPara close(errorChannel) } -func (c *ApiService) getNextListUserResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUserResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -315,8 +337,10 @@ func (params *UpdateUserParams) SetFriendlyName(FriendlyName string) *UpdateUser return params } -// func (c *ApiService) UpdateUser(ServiceSid string, Sid string, params *UpdateUserParams) (*IpMessagingV2User, error) { + return c.UpdateUserWithContext(context.TODO(), ServiceSid, Sid, params) +} +func (c *ApiService) UpdateUserWithContext(ctx context.Context, ServiceSid string, Sid string, params *UpdateUserParams) (*IpMessagingV2User, error) { path := "/v2/Services/{ServiceSid}/Users/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -339,7 +363,7 @@ func (c *ApiService) UpdateUser(ServiceSid string, Sid string, params *UpdateUse if params != nil && params.XTwilioWebhookEnabled != nil { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/ip_messaging/v2/services_users_bindings.go b/rest/ip_messaging/v2/services_users_bindings.go index fab6679a7..beee3397a 100644 --- a/rest/ip_messaging/v2/services_users_bindings.go +++ b/rest/ip_messaging/v2/services_users_bindings.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -23,8 +24,10 @@ import ( "github.com/twilio/twilio-go/client" ) -// func (c *ApiService) DeleteUserBinding(ServiceSid string, UserSid string, Sid string) error { + return c.DeleteUserBindingWithContext(context.TODO(), ServiceSid, UserSid, Sid) +} +func (c *ApiService) DeleteUserBindingWithContext(ctx context.Context, ServiceSid string, UserSid string, Sid string) error { path := "/v2/Services/{ServiceSid}/Users/{UserSid}/Bindings/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"UserSid"+"}", UserSid, -1) @@ -35,7 +38,7 @@ func (c *ApiService) DeleteUserBinding(ServiceSid string, UserSid string, Sid st "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -45,8 +48,10 @@ func (c *ApiService) DeleteUserBinding(ServiceSid string, UserSid string, Sid st return nil } -// func (c *ApiService) FetchUserBinding(ServiceSid string, UserSid string, Sid string) (*IpMessagingV2UserBinding, error) { + return c.FetchUserBindingWithContext(context.TODO(), ServiceSid, UserSid, Sid) +} +func (c *ApiService) FetchUserBindingWithContext(ctx context.Context, ServiceSid string, UserSid string, Sid string) (*IpMessagingV2UserBinding, error) { path := "/v2/Services/{ServiceSid}/Users/{UserSid}/Bindings/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"UserSid"+"}", UserSid, -1) @@ -57,7 +62,7 @@ func (c *ApiService) FetchUserBinding(ServiceSid string, UserSid string, Sid str "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -97,6 +102,11 @@ func (params *ListUserBindingParams) SetLimit(Limit int) *ListUserBindingParams // Retrieve a single page of UserBinding records from the API. Request is executed immediately. func (c *ApiService) PageUserBinding(ServiceSid string, UserSid string, params *ListUserBindingParams, pageToken, pageNumber string) (*ListUserBindingResponse, error) { + return c.PageUserBindingWithContext(context.TODO(), ServiceSid, UserSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of UserBinding records from the API. Request is executed immediately. +func (c *ApiService) PageUserBindingWithContext(ctx context.Context, ServiceSid string, UserSid string, params *ListUserBindingParams, pageToken, pageNumber string) (*ListUserBindingResponse, error) { path := "/v2/Services/{ServiceSid}/Users/{UserSid}/Bindings" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -123,7 +133,7 @@ func (c *ApiService) PageUserBinding(ServiceSid string, UserSid string, params * data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -140,7 +150,12 @@ func (c *ApiService) PageUserBinding(ServiceSid string, UserSid string, params * // Lists UserBinding records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListUserBinding(ServiceSid string, UserSid string, params *ListUserBindingParams) ([]IpMessagingV2UserBinding, error) { - response, errors := c.StreamUserBinding(ServiceSid, UserSid, params) + return c.ListUserBindingWithContext(context.TODO(), ServiceSid, UserSid, params) +} + +// Lists UserBinding records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListUserBindingWithContext(ctx context.Context, ServiceSid string, UserSid string, params *ListUserBindingParams) ([]IpMessagingV2UserBinding, error) { + response, errors := c.StreamUserBindingWithContext(ctx, ServiceSid, UserSid, params) records := make([]IpMessagingV2UserBinding, 0) for record := range response { @@ -156,6 +171,11 @@ func (c *ApiService) ListUserBinding(ServiceSid string, UserSid string, params * // Streams UserBinding records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamUserBinding(ServiceSid string, UserSid string, params *ListUserBindingParams) (chan IpMessagingV2UserBinding, chan error) { + return c.StreamUserBindingWithContext(context.TODO(), ServiceSid, UserSid, params) +} + +// Streams UserBinding records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamUserBindingWithContext(ctx context.Context, ServiceSid string, UserSid string, params *ListUserBindingParams) (chan IpMessagingV2UserBinding, chan error) { if params == nil { params = &ListUserBindingParams{} } @@ -164,19 +184,19 @@ func (c *ApiService) StreamUserBinding(ServiceSid string, UserSid string, params recordChannel := make(chan IpMessagingV2UserBinding, 1) errorChannel := make(chan error, 1) - response, err := c.PageUserBinding(ServiceSid, UserSid, params, "", "") + response, err := c.PageUserBindingWithContext(ctx, ServiceSid, UserSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUserBinding(response, params, recordChannel, errorChannel) + go c.streamUserBindingWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamUserBinding(response *ListUserBindingResponse, params *ListUserBindingParams, recordChannel chan IpMessagingV2UserBinding, errorChannel chan error) { +func (c *ApiService) streamUserBindingWithContext(ctx context.Context, response *ListUserBindingResponse, params *ListUserBindingParams, recordChannel chan IpMessagingV2UserBinding, errorChannel chan error) { curRecord := 1 for response != nil { @@ -191,7 +211,7 @@ func (c *ApiService) streamUserBinding(response *ListUserBindingResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUserBindingResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListUserBindingResponseWithContext) if err != nil { errorChannel <- err break @@ -206,11 +226,11 @@ func (c *ApiService) streamUserBinding(response *ListUserBindingResponse, params close(errorChannel) } -func (c *ApiService) getNextListUserBindingResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUserBindingResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/ip_messaging/v2/services_users_channels.go b/rest/ip_messaging/v2/services_users_channels.go index 918b3e38c..2f0623a09 100644 --- a/rest/ip_messaging/v2/services_users_channels.go +++ b/rest/ip_messaging/v2/services_users_channels.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -24,8 +25,10 @@ import ( "github.com/twilio/twilio-go/client" ) -// func (c *ApiService) DeleteUserChannel(ServiceSid string, UserSid string, ChannelSid string) error { + return c.DeleteUserChannelWithContext(context.TODO(), ServiceSid, UserSid, ChannelSid) +} +func (c *ApiService) DeleteUserChannelWithContext(ctx context.Context, ServiceSid string, UserSid string, ChannelSid string) error { path := "/v2/Services/{ServiceSid}/Users/{UserSid}/Channels/{ChannelSid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"UserSid"+"}", UserSid, -1) @@ -36,7 +39,7 @@ func (c *ApiService) DeleteUserChannel(ServiceSid string, UserSid string, Channe "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -46,8 +49,10 @@ func (c *ApiService) DeleteUserChannel(ServiceSid string, UserSid string, Channe return nil } -// func (c *ApiService) FetchUserChannel(ServiceSid string, UserSid string, ChannelSid string) (*IpMessagingV2UserChannel, error) { + return c.FetchUserChannelWithContext(context.TODO(), ServiceSid, UserSid, ChannelSid) +} +func (c *ApiService) FetchUserChannelWithContext(ctx context.Context, ServiceSid string, UserSid string, ChannelSid string) (*IpMessagingV2UserChannel, error) { path := "/v2/Services/{ServiceSid}/Users/{UserSid}/Channels/{ChannelSid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"UserSid"+"}", UserSid, -1) @@ -58,7 +63,7 @@ func (c *ApiService) FetchUserChannel(ServiceSid string, UserSid string, Channel "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -92,6 +97,11 @@ func (params *ListUserChannelParams) SetLimit(Limit int) *ListUserChannelParams // Retrieve a single page of UserChannel records from the API. Request is executed immediately. func (c *ApiService) PageUserChannel(ServiceSid string, UserSid string, params *ListUserChannelParams, pageToken, pageNumber string) (*ListUserChannelResponse, error) { + return c.PageUserChannelWithContext(context.TODO(), ServiceSid, UserSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of UserChannel records from the API. Request is executed immediately. +func (c *ApiService) PageUserChannelWithContext(ctx context.Context, ServiceSid string, UserSid string, params *ListUserChannelParams, pageToken, pageNumber string) (*ListUserChannelResponse, error) { path := "/v2/Services/{ServiceSid}/Users/{UserSid}/Channels" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -113,7 +123,7 @@ func (c *ApiService) PageUserChannel(ServiceSid string, UserSid string, params * data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -130,7 +140,12 @@ func (c *ApiService) PageUserChannel(ServiceSid string, UserSid string, params * // Lists UserChannel records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListUserChannel(ServiceSid string, UserSid string, params *ListUserChannelParams) ([]IpMessagingV2UserChannel, error) { - response, errors := c.StreamUserChannel(ServiceSid, UserSid, params) + return c.ListUserChannelWithContext(context.TODO(), ServiceSid, UserSid, params) +} + +// Lists UserChannel records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListUserChannelWithContext(ctx context.Context, ServiceSid string, UserSid string, params *ListUserChannelParams) ([]IpMessagingV2UserChannel, error) { + response, errors := c.StreamUserChannelWithContext(ctx, ServiceSid, UserSid, params) records := make([]IpMessagingV2UserChannel, 0) for record := range response { @@ -146,6 +161,11 @@ func (c *ApiService) ListUserChannel(ServiceSid string, UserSid string, params * // Streams UserChannel records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamUserChannel(ServiceSid string, UserSid string, params *ListUserChannelParams) (chan IpMessagingV2UserChannel, chan error) { + return c.StreamUserChannelWithContext(context.TODO(), ServiceSid, UserSid, params) +} + +// Streams UserChannel records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamUserChannelWithContext(ctx context.Context, ServiceSid string, UserSid string, params *ListUserChannelParams) (chan IpMessagingV2UserChannel, chan error) { if params == nil { params = &ListUserChannelParams{} } @@ -154,19 +174,19 @@ func (c *ApiService) StreamUserChannel(ServiceSid string, UserSid string, params recordChannel := make(chan IpMessagingV2UserChannel, 1) errorChannel := make(chan error, 1) - response, err := c.PageUserChannel(ServiceSid, UserSid, params, "", "") + response, err := c.PageUserChannelWithContext(ctx, ServiceSid, UserSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUserChannel(response, params, recordChannel, errorChannel) + go c.streamUserChannelWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamUserChannel(response *ListUserChannelResponse, params *ListUserChannelParams, recordChannel chan IpMessagingV2UserChannel, errorChannel chan error) { +func (c *ApiService) streamUserChannelWithContext(ctx context.Context, response *ListUserChannelResponse, params *ListUserChannelParams, recordChannel chan IpMessagingV2UserChannel, errorChannel chan error) { curRecord := 1 for response != nil { @@ -181,7 +201,7 @@ func (c *ApiService) streamUserChannel(response *ListUserChannelResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUserChannelResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListUserChannelResponseWithContext) if err != nil { errorChannel <- err break @@ -196,11 +216,11 @@ func (c *ApiService) streamUserChannel(response *ListUserChannelResponse, params close(errorChannel) } -func (c *ApiService) getNextListUserChannelResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUserChannelResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -237,8 +257,10 @@ func (params *UpdateUserChannelParams) SetLastConsumptionTimestamp(LastConsumpti return params } -// func (c *ApiService) UpdateUserChannel(ServiceSid string, UserSid string, ChannelSid string, params *UpdateUserChannelParams) (*IpMessagingV2UserChannel, error) { + return c.UpdateUserChannelWithContext(context.TODO(), ServiceSid, UserSid, ChannelSid, params) +} +func (c *ApiService) UpdateUserChannelWithContext(ctx context.Context, ServiceSid string, UserSid string, ChannelSid string, params *UpdateUserChannelParams) (*IpMessagingV2UserChannel, error) { path := "/v2/Services/{ServiceSid}/Users/{UserSid}/Channels/{ChannelSid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"UserSid"+"}", UserSid, -1) @@ -259,7 +281,7 @@ func (c *ApiService) UpdateUserChannel(ServiceSid string, UserSid string, Channe data.Set("LastConsumptionTimestamp", fmt.Sprint((*params.LastConsumptionTimestamp).Format(time.RFC3339))) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/knowledge/v1/api_service.go b/rest/knowledge/v1/api_service.go index 3b100a92d..afa997a9a 100644 --- a/rest/knowledge/v1/api_service.go +++ b/rest/knowledge/v1/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://knowledge.twilio.com", + } +} diff --git a/rest/knowledge/v1/knowledge.go b/rest/knowledge/v1/knowledge.go index 6bf4b7007..d1ef7c4a5 100644 --- a/rest/knowledge/v1/knowledge.go +++ b/rest/knowledge/v1/knowledge.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -36,6 +37,9 @@ func (params *CreateKnowledgeParams) SetKnowledgeV1CreateKnowledgeRequest(Knowle // Create knowledge func (c *ApiService) CreateKnowledge(params *CreateKnowledgeParams) (*KnowledgeV1Knowledge, error) { + return c.CreateKnowledgeWithContext(context.TODO(), params) +} +func (c *ApiService) CreateKnowledgeWithContext(ctx context.Context, params *CreateKnowledgeParams) (*KnowledgeV1Knowledge, error) { path := "/v1/Knowledge" data := url.Values{} @@ -52,7 +56,7 @@ func (c *ApiService) CreateKnowledge(params *CreateKnowledgeParams) (*KnowledgeV body = b } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers, body...) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers, body...) if err != nil { return nil, err } @@ -69,6 +73,9 @@ func (c *ApiService) CreateKnowledge(params *CreateKnowledgeParams) (*KnowledgeV // Delete knowledge func (c *ApiService) DeleteKnowledge(Id string) error { + return c.DeleteKnowledgeWithContext(context.TODO(), Id) +} +func (c *ApiService) DeleteKnowledgeWithContext(ctx context.Context, Id string) error { path := "/v1/Knowledge/{id}" path = strings.Replace(path, "{"+"id"+"}", Id, -1) @@ -77,7 +84,7 @@ func (c *ApiService) DeleteKnowledge(Id string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -89,6 +96,9 @@ func (c *ApiService) DeleteKnowledge(Id string) error { // Get knowledge func (c *ApiService) FetchKnowledge(Id string) (*KnowledgeV1Knowledge, error) { + return c.FetchKnowledgeWithContext(context.TODO(), Id) +} +func (c *ApiService) FetchKnowledgeWithContext(ctx context.Context, Id string) (*KnowledgeV1Knowledge, error) { path := "/v1/Knowledge/{id}" path = strings.Replace(path, "{"+"id"+"}", Id, -1) @@ -97,7 +107,7 @@ func (c *ApiService) FetchKnowledge(Id string) (*KnowledgeV1Knowledge, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -131,6 +141,11 @@ func (params *ListKnowledgeParams) SetLimit(Limit int) *ListKnowledgeParams { // Retrieve a single page of Knowledge records from the API. Request is executed immediately. func (c *ApiService) PageKnowledge(params *ListKnowledgeParams, pageToken, pageNumber string) (*ListKnowledgeResponse, error) { + return c.PageKnowledgeWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Knowledge records from the API. Request is executed immediately. +func (c *ApiService) PageKnowledgeWithContext(ctx context.Context, params *ListKnowledgeParams, pageToken, pageNumber string) (*ListKnowledgeResponse, error) { path := "/v1/Knowledge" data := url.Values{} @@ -149,7 +164,7 @@ func (c *ApiService) PageKnowledge(params *ListKnowledgeParams, pageToken, pageN data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -166,7 +181,12 @@ func (c *ApiService) PageKnowledge(params *ListKnowledgeParams, pageToken, pageN // Lists Knowledge records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListKnowledge(params *ListKnowledgeParams) ([]ListKnowledgeResponseKnowledge, error) { - response, errors := c.StreamKnowledge(params) + return c.ListKnowledgeWithContext(context.TODO(), params) +} + +// Lists Knowledge records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListKnowledgeWithContext(ctx context.Context, params *ListKnowledgeParams) ([]ListKnowledgeResponseKnowledge, error) { + response, errors := c.StreamKnowledgeWithContext(ctx, params) records := make([]ListKnowledgeResponseKnowledge, 0) for record := range response { @@ -182,6 +202,11 @@ func (c *ApiService) ListKnowledge(params *ListKnowledgeParams) ([]ListKnowledge // Streams Knowledge records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamKnowledge(params *ListKnowledgeParams) (chan ListKnowledgeResponseKnowledge, chan error) { + return c.StreamKnowledgeWithContext(context.TODO(), params) +} + +// Streams Knowledge records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamKnowledgeWithContext(ctx context.Context, params *ListKnowledgeParams) (chan ListKnowledgeResponseKnowledge, chan error) { if params == nil { params = &ListKnowledgeParams{} } @@ -190,19 +215,19 @@ func (c *ApiService) StreamKnowledge(params *ListKnowledgeParams) (chan ListKnow recordChannel := make(chan ListKnowledgeResponseKnowledge, 1) errorChannel := make(chan error, 1) - response, err := c.PageKnowledge(params, "", "") + response, err := c.PageKnowledgeWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamKnowledge(response, params, recordChannel, errorChannel) + go c.streamKnowledgeWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamKnowledge(response *ListKnowledgeResponse, params *ListKnowledgeParams, recordChannel chan ListKnowledgeResponseKnowledge, errorChannel chan error) { +func (c *ApiService) streamKnowledgeWithContext(ctx context.Context, response *ListKnowledgeResponse, params *ListKnowledgeParams, recordChannel chan ListKnowledgeResponseKnowledge, errorChannel chan error) { curRecord := 1 for response != nil { @@ -217,7 +242,7 @@ func (c *ApiService) streamKnowledge(response *ListKnowledgeResponse, params *Li } } - record, err := client.GetNext(c.baseURL, response, c.getNextListKnowledgeResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListKnowledgeResponseWithContext) if err != nil { errorChannel <- err break @@ -232,11 +257,11 @@ func (c *ApiService) streamKnowledge(response *ListKnowledgeResponse, params *Li close(errorChannel) } -func (c *ApiService) getNextListKnowledgeResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListKnowledgeResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -263,6 +288,9 @@ func (params *UpdateKnowledgeParams) SetKnowledgeV1UpdateKnowledgeRequest(Knowle // Update knowledge func (c *ApiService) UpdateKnowledge(Id string, params *UpdateKnowledgeParams) (*KnowledgeV1Knowledge, error) { + return c.UpdateKnowledgeWithContext(context.TODO(), Id, params) +} +func (c *ApiService) UpdateKnowledgeWithContext(ctx context.Context, Id string, params *UpdateKnowledgeParams) (*KnowledgeV1Knowledge, error) { path := "/v1/Knowledge/{id}" path = strings.Replace(path, "{"+"id"+"}", Id, -1) @@ -280,7 +308,7 @@ func (c *ApiService) UpdateKnowledge(Id string, params *UpdateKnowledgeParams) ( body = b } - resp, err := c.requestHandler.Put(c.baseURL+path, data, headers, body...) + resp, err := c.requestHandler.PutWithContext(ctx, c.baseURL+path, data, headers, body...) if err != nil { return nil, err } diff --git a/rest/knowledge/v1/knowledge_chunks.go b/rest/knowledge/v1/knowledge_chunks.go index 3573b091b..9b1fd344c 100644 --- a/rest/knowledge/v1/knowledge_chunks.go +++ b/rest/knowledge/v1/knowledge_chunks.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -42,6 +43,11 @@ func (params *ListKnowledgeChunksParams) SetLimit(Limit int) *ListKnowledgeChunk // Retrieve a single page of KnowledgeChunks records from the API. Request is executed immediately. func (c *ApiService) PageKnowledgeChunks(Id string, params *ListKnowledgeChunksParams, pageToken, pageNumber string) (*ListKnowledgeChunksResponse, error) { + return c.PageKnowledgeChunksWithContext(context.TODO(), Id, params, pageToken, pageNumber) +} + +// Retrieve a single page of KnowledgeChunks records from the API. Request is executed immediately. +func (c *ApiService) PageKnowledgeChunksWithContext(ctx context.Context, Id string, params *ListKnowledgeChunksParams, pageToken, pageNumber string) (*ListKnowledgeChunksResponse, error) { path := "/v1/Knowledge/{id}/Chunks" path = strings.Replace(path, "{"+"id"+"}", Id, -1) @@ -62,7 +68,7 @@ func (c *ApiService) PageKnowledgeChunks(Id string, params *ListKnowledgeChunksP data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -79,7 +85,12 @@ func (c *ApiService) PageKnowledgeChunks(Id string, params *ListKnowledgeChunksP // Lists KnowledgeChunks records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListKnowledgeChunks(Id string, params *ListKnowledgeChunksParams) ([]KnowledgeV1KnowledgeChunk, error) { - response, errors := c.StreamKnowledgeChunks(Id, params) + return c.ListKnowledgeChunksWithContext(context.TODO(), Id, params) +} + +// Lists KnowledgeChunks records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListKnowledgeChunksWithContext(ctx context.Context, Id string, params *ListKnowledgeChunksParams) ([]KnowledgeV1KnowledgeChunk, error) { + response, errors := c.StreamKnowledgeChunksWithContext(ctx, Id, params) records := make([]KnowledgeV1KnowledgeChunk, 0) for record := range response { @@ -95,6 +106,11 @@ func (c *ApiService) ListKnowledgeChunks(Id string, params *ListKnowledgeChunksP // Streams KnowledgeChunks records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamKnowledgeChunks(Id string, params *ListKnowledgeChunksParams) (chan KnowledgeV1KnowledgeChunk, chan error) { + return c.StreamKnowledgeChunksWithContext(context.TODO(), Id, params) +} + +// Streams KnowledgeChunks records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamKnowledgeChunksWithContext(ctx context.Context, Id string, params *ListKnowledgeChunksParams) (chan KnowledgeV1KnowledgeChunk, chan error) { if params == nil { params = &ListKnowledgeChunksParams{} } @@ -103,19 +119,19 @@ func (c *ApiService) StreamKnowledgeChunks(Id string, params *ListKnowledgeChunk recordChannel := make(chan KnowledgeV1KnowledgeChunk, 1) errorChannel := make(chan error, 1) - response, err := c.PageKnowledgeChunks(Id, params, "", "") + response, err := c.PageKnowledgeChunksWithContext(ctx, Id, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamKnowledgeChunks(response, params, recordChannel, errorChannel) + go c.streamKnowledgeChunksWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamKnowledgeChunks(response *ListKnowledgeChunksResponse, params *ListKnowledgeChunksParams, recordChannel chan KnowledgeV1KnowledgeChunk, errorChannel chan error) { +func (c *ApiService) streamKnowledgeChunksWithContext(ctx context.Context, response *ListKnowledgeChunksResponse, params *ListKnowledgeChunksParams, recordChannel chan KnowledgeV1KnowledgeChunk, errorChannel chan error) { curRecord := 1 for response != nil { @@ -130,7 +146,7 @@ func (c *ApiService) streamKnowledgeChunks(response *ListKnowledgeChunksResponse } } - record, err := client.GetNext(c.baseURL, response, c.getNextListKnowledgeChunksResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListKnowledgeChunksResponseWithContext) if err != nil { errorChannel <- err break @@ -145,11 +161,11 @@ func (c *ApiService) streamKnowledgeChunks(response *ListKnowledgeChunksResponse close(errorChannel) } -func (c *ApiService) getNextListKnowledgeChunksResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListKnowledgeChunksResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/knowledge/v1/knowledge_status.go b/rest/knowledge/v1/knowledge_status.go index 4c2dcba08..5257ad200 100644 --- a/rest/knowledge/v1/knowledge_status.go +++ b/rest/knowledge/v1/knowledge_status.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -22,6 +23,9 @@ import ( // Get knowledge status func (c *ApiService) FetchKnowledgeStatus(Id string) (*KnowledgeV1KnowledgeStatus, error) { + return c.FetchKnowledgeStatusWithContext(context.TODO(), Id) +} +func (c *ApiService) FetchKnowledgeStatusWithContext(ctx context.Context, Id string) (*KnowledgeV1KnowledgeStatus, error) { path := "/v1/Knowledge/{id}/Status" path = strings.Replace(path, "{"+"id"+"}", Id, -1) @@ -30,7 +34,7 @@ func (c *ApiService) FetchKnowledgeStatus(Id string) (*KnowledgeV1KnowledgeStatu "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/lookups/v1/api_service.go b/rest/lookups/v1/api_service.go index 89f681c71..adfa291a9 100644 --- a/rest/lookups/v1/api_service.go +++ b/rest/lookups/v1/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://lookups.twilio.com", + } +} diff --git a/rest/lookups/v1/phone_numbers.go b/rest/lookups/v1/phone_numbers.go index 46e7c4fec..78d372467 100644 --- a/rest/lookups/v1/phone_numbers.go +++ b/rest/lookups/v1/phone_numbers.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -49,8 +50,10 @@ func (params *FetchPhoneNumberParams) SetAddOnsData(AddOnsData map[string]interf return params } -// func (c *ApiService) FetchPhoneNumber(PhoneNumber string, params *FetchPhoneNumberParams) (*LookupsV1PhoneNumber, error) { + return c.FetchPhoneNumberWithContext(context.TODO(), PhoneNumber, params) +} +func (c *ApiService) FetchPhoneNumberWithContext(ctx context.Context, PhoneNumber string, params *FetchPhoneNumberParams) (*LookupsV1PhoneNumber, error) { path := "/v1/PhoneNumbers/{PhoneNumber}" path = strings.Replace(path, "{"+"PhoneNumber"+"}", PhoneNumber, -1) @@ -82,7 +85,7 @@ func (c *ApiService) FetchPhoneNumber(PhoneNumber string, params *FetchPhoneNumb data.Set("AddOnsData", string(v)) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/lookups/v2/api_service.go b/rest/lookups/v2/api_service.go index 89f681c71..adfa291a9 100644 --- a/rest/lookups/v2/api_service.go +++ b/rest/lookups/v2/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://lookups.twilio.com", + } +} diff --git a/rest/lookups/v2/phone_numbers.go b/rest/lookups/v2/phone_numbers.go index f563d17e7..b3160d119 100644 --- a/rest/lookups/v2/phone_numbers.go +++ b/rest/lookups/v2/phone_numbers.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -115,8 +116,10 @@ func (params *FetchPhoneNumberParams) SetPartnerSubId(PartnerSubId string) *Fetc return params } -// func (c *ApiService) FetchPhoneNumber(PhoneNumber string, params *FetchPhoneNumberParams) (*LookupsV2PhoneNumber, error) { + return c.FetchPhoneNumberWithContext(context.TODO(), PhoneNumber, params) +} +func (c *ApiService) FetchPhoneNumberWithContext(ctx context.Context, PhoneNumber string, params *FetchPhoneNumberParams) (*LookupsV2PhoneNumber, error) { path := "/v2/PhoneNumbers/{PhoneNumber}" path = strings.Replace(path, "{"+"PhoneNumber"+"}", PhoneNumber, -1) @@ -171,7 +174,7 @@ func (c *ApiService) FetchPhoneNumber(PhoneNumber string, params *FetchPhoneNumb data.Set("PartnerSubId", *params.PartnerSubId) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/marketplace/v1/api_service.go b/rest/marketplace/v1/api_service.go index 1c48fb7a2..6793f2d2b 100644 --- a/rest/marketplace/v1/api_service.go +++ b/rest/marketplace/v1/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://marketplace.twilio.com", + } +} diff --git a/rest/marketplace/v1/available_add_ons.go b/rest/marketplace/v1/available_add_ons.go index cfbae759d..9237d0799 100644 --- a/rest/marketplace/v1/available_add_ons.go +++ b/rest/marketplace/v1/available_add_ons.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -25,6 +26,9 @@ import ( // Fetch an instance of an Add-on currently available to be installed. func (c *ApiService) FetchAvailableAddOn(Sid string) (*MarketplaceV1AvailableAddOn, error) { + return c.FetchAvailableAddOnWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchAvailableAddOnWithContext(ctx context.Context, Sid string) (*MarketplaceV1AvailableAddOn, error) { path := "/v1/AvailableAddOns/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -33,7 +37,7 @@ func (c *ApiService) FetchAvailableAddOn(Sid string) (*MarketplaceV1AvailableAdd "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -67,6 +71,11 @@ func (params *ListAvailableAddOnParams) SetLimit(Limit int) *ListAvailableAddOnP // Retrieve a single page of AvailableAddOn records from the API. Request is executed immediately. func (c *ApiService) PageAvailableAddOn(params *ListAvailableAddOnParams, pageToken, pageNumber string) (*ListAvailableAddOnResponse, error) { + return c.PageAvailableAddOnWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of AvailableAddOn records from the API. Request is executed immediately. +func (c *ApiService) PageAvailableAddOnWithContext(ctx context.Context, params *ListAvailableAddOnParams, pageToken, pageNumber string) (*ListAvailableAddOnResponse, error) { path := "/v1/AvailableAddOns" data := url.Values{} @@ -85,7 +94,7 @@ func (c *ApiService) PageAvailableAddOn(params *ListAvailableAddOnParams, pageTo data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -102,7 +111,12 @@ func (c *ApiService) PageAvailableAddOn(params *ListAvailableAddOnParams, pageTo // Lists AvailableAddOn records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListAvailableAddOn(params *ListAvailableAddOnParams) ([]MarketplaceV1AvailableAddOn, error) { - response, errors := c.StreamAvailableAddOn(params) + return c.ListAvailableAddOnWithContext(context.TODO(), params) +} + +// Lists AvailableAddOn records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListAvailableAddOnWithContext(ctx context.Context, params *ListAvailableAddOnParams) ([]MarketplaceV1AvailableAddOn, error) { + response, errors := c.StreamAvailableAddOnWithContext(ctx, params) records := make([]MarketplaceV1AvailableAddOn, 0) for record := range response { @@ -118,6 +132,11 @@ func (c *ApiService) ListAvailableAddOn(params *ListAvailableAddOnParams) ([]Mar // Streams AvailableAddOn records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamAvailableAddOn(params *ListAvailableAddOnParams) (chan MarketplaceV1AvailableAddOn, chan error) { + return c.StreamAvailableAddOnWithContext(context.TODO(), params) +} + +// Streams AvailableAddOn records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamAvailableAddOnWithContext(ctx context.Context, params *ListAvailableAddOnParams) (chan MarketplaceV1AvailableAddOn, chan error) { if params == nil { params = &ListAvailableAddOnParams{} } @@ -126,19 +145,19 @@ func (c *ApiService) StreamAvailableAddOn(params *ListAvailableAddOnParams) (cha recordChannel := make(chan MarketplaceV1AvailableAddOn, 1) errorChannel := make(chan error, 1) - response, err := c.PageAvailableAddOn(params, "", "") + response, err := c.PageAvailableAddOnWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamAvailableAddOn(response, params, recordChannel, errorChannel) + go c.streamAvailableAddOnWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamAvailableAddOn(response *ListAvailableAddOnResponse, params *ListAvailableAddOnParams, recordChannel chan MarketplaceV1AvailableAddOn, errorChannel chan error) { +func (c *ApiService) streamAvailableAddOnWithContext(ctx context.Context, response *ListAvailableAddOnResponse, params *ListAvailableAddOnParams, recordChannel chan MarketplaceV1AvailableAddOn, errorChannel chan error) { curRecord := 1 for response != nil { @@ -153,7 +172,7 @@ func (c *ApiService) streamAvailableAddOn(response *ListAvailableAddOnResponse, } } - record, err := client.GetNext(c.baseURL, response, c.getNextListAvailableAddOnResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListAvailableAddOnResponseWithContext) if err != nil { errorChannel <- err break @@ -168,11 +187,11 @@ func (c *ApiService) streamAvailableAddOn(response *ListAvailableAddOnResponse, close(errorChannel) } -func (c *ApiService) getNextListAvailableAddOnResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListAvailableAddOnResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/marketplace/v1/available_add_ons_extensions.go b/rest/marketplace/v1/available_add_ons_extensions.go index 2936202e4..e760a0ffa 100644 --- a/rest/marketplace/v1/available_add_ons_extensions.go +++ b/rest/marketplace/v1/available_add_ons_extensions.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -25,6 +26,9 @@ import ( // Fetch an instance of an Extension for the Available Add-on. func (c *ApiService) FetchAvailableAddOnExtension(AvailableAddOnSid string, Sid string) (*MarketplaceV1AvailableAddOnExtension, error) { + return c.FetchAvailableAddOnExtensionWithContext(context.TODO(), AvailableAddOnSid, Sid) +} +func (c *ApiService) FetchAvailableAddOnExtensionWithContext(ctx context.Context, AvailableAddOnSid string, Sid string) (*MarketplaceV1AvailableAddOnExtension, error) { path := "/v1/AvailableAddOns/{AvailableAddOnSid}/Extensions/{Sid}" path = strings.Replace(path, "{"+"AvailableAddOnSid"+"}", AvailableAddOnSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -34,7 +38,7 @@ func (c *ApiService) FetchAvailableAddOnExtension(AvailableAddOnSid string, Sid "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -68,6 +72,11 @@ func (params *ListAvailableAddOnExtensionParams) SetLimit(Limit int) *ListAvaila // Retrieve a single page of AvailableAddOnExtension records from the API. Request is executed immediately. func (c *ApiService) PageAvailableAddOnExtension(AvailableAddOnSid string, params *ListAvailableAddOnExtensionParams, pageToken, pageNumber string) (*ListAvailableAddOnExtensionResponse, error) { + return c.PageAvailableAddOnExtensionWithContext(context.TODO(), AvailableAddOnSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of AvailableAddOnExtension records from the API. Request is executed immediately. +func (c *ApiService) PageAvailableAddOnExtensionWithContext(ctx context.Context, AvailableAddOnSid string, params *ListAvailableAddOnExtensionParams, pageToken, pageNumber string) (*ListAvailableAddOnExtensionResponse, error) { path := "/v1/AvailableAddOns/{AvailableAddOnSid}/Extensions" path = strings.Replace(path, "{"+"AvailableAddOnSid"+"}", AvailableAddOnSid, -1) @@ -88,7 +97,7 @@ func (c *ApiService) PageAvailableAddOnExtension(AvailableAddOnSid string, param data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -105,7 +114,12 @@ func (c *ApiService) PageAvailableAddOnExtension(AvailableAddOnSid string, param // Lists AvailableAddOnExtension records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListAvailableAddOnExtension(AvailableAddOnSid string, params *ListAvailableAddOnExtensionParams) ([]MarketplaceV1AvailableAddOnExtension, error) { - response, errors := c.StreamAvailableAddOnExtension(AvailableAddOnSid, params) + return c.ListAvailableAddOnExtensionWithContext(context.TODO(), AvailableAddOnSid, params) +} + +// Lists AvailableAddOnExtension records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListAvailableAddOnExtensionWithContext(ctx context.Context, AvailableAddOnSid string, params *ListAvailableAddOnExtensionParams) ([]MarketplaceV1AvailableAddOnExtension, error) { + response, errors := c.StreamAvailableAddOnExtensionWithContext(ctx, AvailableAddOnSid, params) records := make([]MarketplaceV1AvailableAddOnExtension, 0) for record := range response { @@ -121,6 +135,11 @@ func (c *ApiService) ListAvailableAddOnExtension(AvailableAddOnSid string, param // Streams AvailableAddOnExtension records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamAvailableAddOnExtension(AvailableAddOnSid string, params *ListAvailableAddOnExtensionParams) (chan MarketplaceV1AvailableAddOnExtension, chan error) { + return c.StreamAvailableAddOnExtensionWithContext(context.TODO(), AvailableAddOnSid, params) +} + +// Streams AvailableAddOnExtension records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamAvailableAddOnExtensionWithContext(ctx context.Context, AvailableAddOnSid string, params *ListAvailableAddOnExtensionParams) (chan MarketplaceV1AvailableAddOnExtension, chan error) { if params == nil { params = &ListAvailableAddOnExtensionParams{} } @@ -129,19 +148,19 @@ func (c *ApiService) StreamAvailableAddOnExtension(AvailableAddOnSid string, par recordChannel := make(chan MarketplaceV1AvailableAddOnExtension, 1) errorChannel := make(chan error, 1) - response, err := c.PageAvailableAddOnExtension(AvailableAddOnSid, params, "", "") + response, err := c.PageAvailableAddOnExtensionWithContext(ctx, AvailableAddOnSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamAvailableAddOnExtension(response, params, recordChannel, errorChannel) + go c.streamAvailableAddOnExtensionWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamAvailableAddOnExtension(response *ListAvailableAddOnExtensionResponse, params *ListAvailableAddOnExtensionParams, recordChannel chan MarketplaceV1AvailableAddOnExtension, errorChannel chan error) { +func (c *ApiService) streamAvailableAddOnExtensionWithContext(ctx context.Context, response *ListAvailableAddOnExtensionResponse, params *ListAvailableAddOnExtensionParams, recordChannel chan MarketplaceV1AvailableAddOnExtension, errorChannel chan error) { curRecord := 1 for response != nil { @@ -156,7 +175,7 @@ func (c *ApiService) streamAvailableAddOnExtension(response *ListAvailableAddOnE } } - record, err := client.GetNext(c.baseURL, response, c.getNextListAvailableAddOnExtensionResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListAvailableAddOnExtensionResponseWithContext) if err != nil { errorChannel <- err break @@ -171,11 +190,11 @@ func (c *ApiService) streamAvailableAddOnExtension(response *ListAvailableAddOnE close(errorChannel) } -func (c *ApiService) getNextListAvailableAddOnExtensionResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListAvailableAddOnExtensionResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/marketplace/v1/installed_add_ons.go b/rest/marketplace/v1/installed_add_ons.go index 054a7f8dc..d391310f0 100644 --- a/rest/marketplace/v1/installed_add_ons.go +++ b/rest/marketplace/v1/installed_add_ons.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -54,6 +55,9 @@ func (params *CreateInstalledAddOnParams) SetUniqueName(UniqueName string) *Crea // Install an Add-on for the Account specified. func (c *ApiService) CreateInstalledAddOn(params *CreateInstalledAddOnParams) (*MarketplaceV1InstalledAddOn, error) { + return c.CreateInstalledAddOnWithContext(context.TODO(), params) +} +func (c *ApiService) CreateInstalledAddOnWithContext(ctx context.Context, params *CreateInstalledAddOnParams) (*MarketplaceV1InstalledAddOn, error) { path := "/v1/InstalledAddOns" data := url.Values{} @@ -80,7 +84,7 @@ func (c *ApiService) CreateInstalledAddOn(params *CreateInstalledAddOnParams) (* data.Set("UniqueName", *params.UniqueName) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -97,6 +101,9 @@ func (c *ApiService) CreateInstalledAddOn(params *CreateInstalledAddOnParams) (* // Remove an Add-on installation from your account func (c *ApiService) DeleteInstalledAddOn(Sid string) error { + return c.DeleteInstalledAddOnWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteInstalledAddOnWithContext(ctx context.Context, Sid string) error { path := "/v1/InstalledAddOns/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -105,7 +112,7 @@ func (c *ApiService) DeleteInstalledAddOn(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -117,6 +124,9 @@ func (c *ApiService) DeleteInstalledAddOn(Sid string) error { // Fetch an instance of an Add-on currently installed on this Account. func (c *ApiService) FetchInstalledAddOn(Sid string) (*MarketplaceV1InstalledAddOn, error) { + return c.FetchInstalledAddOnWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchInstalledAddOnWithContext(ctx context.Context, Sid string) (*MarketplaceV1InstalledAddOn, error) { path := "/v1/InstalledAddOns/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -125,7 +135,7 @@ func (c *ApiService) FetchInstalledAddOn(Sid string) (*MarketplaceV1InstalledAdd "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -159,6 +169,11 @@ func (params *ListInstalledAddOnParams) SetLimit(Limit int) *ListInstalledAddOnP // Retrieve a single page of InstalledAddOn records from the API. Request is executed immediately. func (c *ApiService) PageInstalledAddOn(params *ListInstalledAddOnParams, pageToken, pageNumber string) (*ListInstalledAddOnResponse, error) { + return c.PageInstalledAddOnWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of InstalledAddOn records from the API. Request is executed immediately. +func (c *ApiService) PageInstalledAddOnWithContext(ctx context.Context, params *ListInstalledAddOnParams, pageToken, pageNumber string) (*ListInstalledAddOnResponse, error) { path := "/v1/InstalledAddOns" data := url.Values{} @@ -177,7 +192,7 @@ func (c *ApiService) PageInstalledAddOn(params *ListInstalledAddOnParams, pageTo data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -194,7 +209,12 @@ func (c *ApiService) PageInstalledAddOn(params *ListInstalledAddOnParams, pageTo // Lists InstalledAddOn records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListInstalledAddOn(params *ListInstalledAddOnParams) ([]MarketplaceV1InstalledAddOn, error) { - response, errors := c.StreamInstalledAddOn(params) + return c.ListInstalledAddOnWithContext(context.TODO(), params) +} + +// Lists InstalledAddOn records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListInstalledAddOnWithContext(ctx context.Context, params *ListInstalledAddOnParams) ([]MarketplaceV1InstalledAddOn, error) { + response, errors := c.StreamInstalledAddOnWithContext(ctx, params) records := make([]MarketplaceV1InstalledAddOn, 0) for record := range response { @@ -210,6 +230,11 @@ func (c *ApiService) ListInstalledAddOn(params *ListInstalledAddOnParams) ([]Mar // Streams InstalledAddOn records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamInstalledAddOn(params *ListInstalledAddOnParams) (chan MarketplaceV1InstalledAddOn, chan error) { + return c.StreamInstalledAddOnWithContext(context.TODO(), params) +} + +// Streams InstalledAddOn records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamInstalledAddOnWithContext(ctx context.Context, params *ListInstalledAddOnParams) (chan MarketplaceV1InstalledAddOn, chan error) { if params == nil { params = &ListInstalledAddOnParams{} } @@ -218,19 +243,19 @@ func (c *ApiService) StreamInstalledAddOn(params *ListInstalledAddOnParams) (cha recordChannel := make(chan MarketplaceV1InstalledAddOn, 1) errorChannel := make(chan error, 1) - response, err := c.PageInstalledAddOn(params, "", "") + response, err := c.PageInstalledAddOnWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamInstalledAddOn(response, params, recordChannel, errorChannel) + go c.streamInstalledAddOnWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamInstalledAddOn(response *ListInstalledAddOnResponse, params *ListInstalledAddOnParams, recordChannel chan MarketplaceV1InstalledAddOn, errorChannel chan error) { +func (c *ApiService) streamInstalledAddOnWithContext(ctx context.Context, response *ListInstalledAddOnResponse, params *ListInstalledAddOnParams, recordChannel chan MarketplaceV1InstalledAddOn, errorChannel chan error) { curRecord := 1 for response != nil { @@ -245,7 +270,7 @@ func (c *ApiService) streamInstalledAddOn(response *ListInstalledAddOnResponse, } } - record, err := client.GetNext(c.baseURL, response, c.getNextListInstalledAddOnResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListInstalledAddOnResponseWithContext) if err != nil { errorChannel <- err break @@ -260,11 +285,11 @@ func (c *ApiService) streamInstalledAddOn(response *ListInstalledAddOnResponse, close(errorChannel) } -func (c *ApiService) getNextListInstalledAddOnResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListInstalledAddOnResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -297,6 +322,9 @@ func (params *UpdateInstalledAddOnParams) SetUniqueName(UniqueName string) *Upda // Update an Add-on installation for the Account specified. func (c *ApiService) UpdateInstalledAddOn(Sid string, params *UpdateInstalledAddOnParams) (*MarketplaceV1InstalledAddOn, error) { + return c.UpdateInstalledAddOnWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateInstalledAddOnWithContext(ctx context.Context, Sid string, params *UpdateInstalledAddOnParams) (*MarketplaceV1InstalledAddOn, error) { path := "/v1/InstalledAddOns/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -318,7 +346,7 @@ func (c *ApiService) UpdateInstalledAddOn(Sid string, params *UpdateInstalledAdd data.Set("UniqueName", *params.UniqueName) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/marketplace/v1/installed_add_ons_extensions.go b/rest/marketplace/v1/installed_add_ons_extensions.go index c31263dec..a41e5ed21 100644 --- a/rest/marketplace/v1/installed_add_ons_extensions.go +++ b/rest/marketplace/v1/installed_add_ons_extensions.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -25,6 +26,9 @@ import ( // Fetch an instance of an Extension for the Installed Add-on. func (c *ApiService) FetchInstalledAddOnExtension(InstalledAddOnSid string, Sid string) (*MarketplaceV1InstalledAddOnExtension, error) { + return c.FetchInstalledAddOnExtensionWithContext(context.TODO(), InstalledAddOnSid, Sid) +} +func (c *ApiService) FetchInstalledAddOnExtensionWithContext(ctx context.Context, InstalledAddOnSid string, Sid string) (*MarketplaceV1InstalledAddOnExtension, error) { path := "/v1/InstalledAddOns/{InstalledAddOnSid}/Extensions/{Sid}" path = strings.Replace(path, "{"+"InstalledAddOnSid"+"}", InstalledAddOnSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -34,7 +38,7 @@ func (c *ApiService) FetchInstalledAddOnExtension(InstalledAddOnSid string, Sid "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -68,6 +72,11 @@ func (params *ListInstalledAddOnExtensionParams) SetLimit(Limit int) *ListInstal // Retrieve a single page of InstalledAddOnExtension records from the API. Request is executed immediately. func (c *ApiService) PageInstalledAddOnExtension(InstalledAddOnSid string, params *ListInstalledAddOnExtensionParams, pageToken, pageNumber string) (*ListInstalledAddOnExtensionResponse, error) { + return c.PageInstalledAddOnExtensionWithContext(context.TODO(), InstalledAddOnSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of InstalledAddOnExtension records from the API. Request is executed immediately. +func (c *ApiService) PageInstalledAddOnExtensionWithContext(ctx context.Context, InstalledAddOnSid string, params *ListInstalledAddOnExtensionParams, pageToken, pageNumber string) (*ListInstalledAddOnExtensionResponse, error) { path := "/v1/InstalledAddOns/{InstalledAddOnSid}/Extensions" path = strings.Replace(path, "{"+"InstalledAddOnSid"+"}", InstalledAddOnSid, -1) @@ -88,7 +97,7 @@ func (c *ApiService) PageInstalledAddOnExtension(InstalledAddOnSid string, param data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -105,7 +114,12 @@ func (c *ApiService) PageInstalledAddOnExtension(InstalledAddOnSid string, param // Lists InstalledAddOnExtension records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListInstalledAddOnExtension(InstalledAddOnSid string, params *ListInstalledAddOnExtensionParams) ([]MarketplaceV1InstalledAddOnExtension, error) { - response, errors := c.StreamInstalledAddOnExtension(InstalledAddOnSid, params) + return c.ListInstalledAddOnExtensionWithContext(context.TODO(), InstalledAddOnSid, params) +} + +// Lists InstalledAddOnExtension records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListInstalledAddOnExtensionWithContext(ctx context.Context, InstalledAddOnSid string, params *ListInstalledAddOnExtensionParams) ([]MarketplaceV1InstalledAddOnExtension, error) { + response, errors := c.StreamInstalledAddOnExtensionWithContext(ctx, InstalledAddOnSid, params) records := make([]MarketplaceV1InstalledAddOnExtension, 0) for record := range response { @@ -121,6 +135,11 @@ func (c *ApiService) ListInstalledAddOnExtension(InstalledAddOnSid string, param // Streams InstalledAddOnExtension records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamInstalledAddOnExtension(InstalledAddOnSid string, params *ListInstalledAddOnExtensionParams) (chan MarketplaceV1InstalledAddOnExtension, chan error) { + return c.StreamInstalledAddOnExtensionWithContext(context.TODO(), InstalledAddOnSid, params) +} + +// Streams InstalledAddOnExtension records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamInstalledAddOnExtensionWithContext(ctx context.Context, InstalledAddOnSid string, params *ListInstalledAddOnExtensionParams) (chan MarketplaceV1InstalledAddOnExtension, chan error) { if params == nil { params = &ListInstalledAddOnExtensionParams{} } @@ -129,19 +148,19 @@ func (c *ApiService) StreamInstalledAddOnExtension(InstalledAddOnSid string, par recordChannel := make(chan MarketplaceV1InstalledAddOnExtension, 1) errorChannel := make(chan error, 1) - response, err := c.PageInstalledAddOnExtension(InstalledAddOnSid, params, "", "") + response, err := c.PageInstalledAddOnExtensionWithContext(ctx, InstalledAddOnSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamInstalledAddOnExtension(response, params, recordChannel, errorChannel) + go c.streamInstalledAddOnExtensionWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamInstalledAddOnExtension(response *ListInstalledAddOnExtensionResponse, params *ListInstalledAddOnExtensionParams, recordChannel chan MarketplaceV1InstalledAddOnExtension, errorChannel chan error) { +func (c *ApiService) streamInstalledAddOnExtensionWithContext(ctx context.Context, response *ListInstalledAddOnExtensionResponse, params *ListInstalledAddOnExtensionParams, recordChannel chan MarketplaceV1InstalledAddOnExtension, errorChannel chan error) { curRecord := 1 for response != nil { @@ -156,7 +175,7 @@ func (c *ApiService) streamInstalledAddOnExtension(response *ListInstalledAddOnE } } - record, err := client.GetNext(c.baseURL, response, c.getNextListInstalledAddOnExtensionResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListInstalledAddOnExtensionResponseWithContext) if err != nil { errorChannel <- err break @@ -171,11 +190,11 @@ func (c *ApiService) streamInstalledAddOnExtension(response *ListInstalledAddOnE close(errorChannel) } -func (c *ApiService) getNextListInstalledAddOnExtensionResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListInstalledAddOnExtensionResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -202,6 +221,9 @@ func (params *UpdateInstalledAddOnExtensionParams) SetEnabled(Enabled bool) *Upd // Update an Extension for an Add-on installation. func (c *ApiService) UpdateInstalledAddOnExtension(InstalledAddOnSid string, Sid string, params *UpdateInstalledAddOnExtensionParams) (*MarketplaceV1InstalledAddOnExtension, error) { + return c.UpdateInstalledAddOnExtensionWithContext(context.TODO(), InstalledAddOnSid, Sid, params) +} +func (c *ApiService) UpdateInstalledAddOnExtensionWithContext(ctx context.Context, InstalledAddOnSid string, Sid string, params *UpdateInstalledAddOnExtensionParams) (*MarketplaceV1InstalledAddOnExtension, error) { path := "/v1/InstalledAddOns/{InstalledAddOnSid}/Extensions/{Sid}" path = strings.Replace(path, "{"+"InstalledAddOnSid"+"}", InstalledAddOnSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -215,7 +237,7 @@ func (c *ApiService) UpdateInstalledAddOnExtension(InstalledAddOnSid string, Sid data.Set("Enabled", fmt.Sprint(*params.Enabled)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/marketplace/v1/installed_add_ons_usage.go b/rest/marketplace/v1/installed_add_ons_usage.go index 847fd6970..f2b624752 100644 --- a/rest/marketplace/v1/installed_add_ons_usage.go +++ b/rest/marketplace/v1/installed_add_ons_usage.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -33,6 +34,9 @@ func (params *CreateBillingUsageParams) SetMarketplaceV1InstalledAddOnUsage(Mark // Allows Twilio Marketplace publishers to manually report customer usage on No-code Partner Listings that they own. func (c *ApiService) CreateBillingUsage(InstalledAddOnSid string, params *CreateBillingUsageParams) (*MarketplaceV1InstalledAddOnUsage, error) { + return c.CreateBillingUsageWithContext(context.TODO(), InstalledAddOnSid, params) +} +func (c *ApiService) CreateBillingUsageWithContext(ctx context.Context, InstalledAddOnSid string, params *CreateBillingUsageParams) (*MarketplaceV1InstalledAddOnUsage, error) { path := "/v1/InstalledAddOns/{InstalledAddOnSid}/Usage" path = strings.Replace(path, "{"+"InstalledAddOnSid"+"}", InstalledAddOnSid, -1) @@ -50,7 +54,7 @@ func (c *ApiService) CreateBillingUsage(InstalledAddOnSid string, params *Create body = b } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers, body...) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers, body...) if err != nil { return nil, err } diff --git a/rest/marketplace/v1/listing.go b/rest/marketplace/v1/listing.go index b70cbe334..3697367ba 100644 --- a/rest/marketplace/v1/listing.go +++ b/rest/marketplace/v1/listing.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -22,6 +23,9 @@ import ( // This endpoint returns the data of a given Listing. To find a Listing's SID, use the [Available Add-ons resource](/docs/marketplace/api/available-add-ons) or view its Listing details page in the Console by visiting the [Catalog](https://console.twilio.com/us1/develop/add-ons/catalog) or the [My Listings tab](https://console.twilio.com/us1/develop/add-ons/publish/my-listings) and selecting the Listing. func (c *ApiService) FetchModuleDataManagement(Sid string) (*MarketplaceV1ModuleDataManagement, error) { + return c.FetchModuleDataManagementWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchModuleDataManagementWithContext(ctx context.Context, Sid string) (*MarketplaceV1ModuleDataManagement, error) { path := "/v1/Listing/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -30,7 +34,7 @@ func (c *ApiService) FetchModuleDataManagement(Sid string) (*MarketplaceV1Module "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -94,6 +98,9 @@ func (params *UpdateModuleDataManagementParams) SetPricing(Pricing string) *Upda // This endpoint updates the data of a given Listing. To find a Listing's SID, use the [Available Add-ons resource](https://www.twilio.com/docs/marketplace/api/available-add-ons) or view its Listing details page in the Console by visiting the [Catalog](https://console.twilio.com/us1/develop/add-ons/catalog) or the [My Listings tab](https://console.twilio.com/us1/develop/add-ons/publish/my-listings) and selecting the Listing. Only Listing owners are allowed to update the Listing. func (c *ApiService) UpdateModuleDataManagement(Sid string, params *UpdateModuleDataManagementParams) (*MarketplaceV1ModuleDataManagement, error) { + return c.UpdateModuleDataManagementWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateModuleDataManagementWithContext(ctx context.Context, Sid string, params *UpdateModuleDataManagementParams) (*MarketplaceV1ModuleDataManagement, error) { path := "/v1/Listing/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -124,7 +131,7 @@ func (c *ApiService) UpdateModuleDataManagement(Sid string, params *UpdateModule data.Set("Pricing", *params.Pricing) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/marketplace/v1/listings.go b/rest/marketplace/v1/listings.go index b4f6f8dc6..a339af866 100644 --- a/rest/marketplace/v1/listings.go +++ b/rest/marketplace/v1/listings.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" ) @@ -38,6 +39,9 @@ func (params *CreateModuleDataParams) SetConfiguration(Configuration string) *Cr // This endpoint creates a Listing based on the given data. func (c *ApiService) CreateModuleData(params *CreateModuleDataParams) (*MarketplaceV1ModuleDataManagement, error) { + return c.CreateModuleDataWithContext(context.TODO(), params) +} +func (c *ApiService) CreateModuleDataWithContext(ctx context.Context, params *CreateModuleDataParams) (*MarketplaceV1ModuleDataManagement, error) { path := "/v1/Listings" data := url.Values{} @@ -52,7 +56,7 @@ func (c *ApiService) CreateModuleData(params *CreateModuleDataParams) (*Marketpl data.Set("Configuration", *params.Configuration) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -69,6 +73,9 @@ func (c *ApiService) CreateModuleData(params *CreateModuleDataParams) (*Marketpl // This endpoint returns the Listings owned by the authenticated Account. func (c *ApiService) FetchModuleDataForListingOwner() (*FetchModuleDataForListingOwnerResponse, error) { + return c.FetchModuleDataForListingOwnerWithContext(context.TODO()) +} +func (c *ApiService) FetchModuleDataForListingOwnerWithContext(ctx context.Context) (*FetchModuleDataForListingOwnerResponse, error) { path := "/v1/Listings" data := url.Values{} @@ -76,7 +83,7 @@ func (c *ApiService) FetchModuleDataForListingOwner() (*FetchModuleDataForListin "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/marketplace/v1/referral_conversion.go b/rest/marketplace/v1/referral_conversion.go index 60cd43175..6b65389b1 100644 --- a/rest/marketplace/v1/referral_conversion.go +++ b/rest/marketplace/v1/referral_conversion.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" ) @@ -30,8 +31,10 @@ func (params *CreateReferralConversionParams) SetCreateReferralConversionRequest return params } -// func (c *ApiService) CreateReferralConversion(params *CreateReferralConversionParams) (*MarketplaceV1ReferralConversion, error) { + return c.CreateReferralConversionWithContext(context.TODO(), params) +} +func (c *ApiService) CreateReferralConversionWithContext(ctx context.Context, params *CreateReferralConversionParams) (*MarketplaceV1ReferralConversion, error) { path := "/v1/ReferralConversion" data := url.Values{} @@ -48,7 +51,7 @@ func (c *ApiService) CreateReferralConversion(params *CreateReferralConversionPa body = b } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers, body...) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers, body...) if err != nil { return nil, err } diff --git a/rest/messaging/v1/a2p_brand_registrations.go b/rest/messaging/v1/a2p_brand_registrations.go index 9c2a3bc7e..d0942d82e 100644 --- a/rest/messaging/v1/a2p_brand_registrations.go +++ b/rest/messaging/v1/a2p_brand_registrations.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -58,8 +59,10 @@ func (params *CreateBrandRegistrationsParams) SetSkipAutomaticSecVet(SkipAutomat return params } -// func (c *ApiService) CreateBrandRegistrations(params *CreateBrandRegistrationsParams) (*MessagingV1BrandRegistrations, error) { + return c.CreateBrandRegistrationsWithContext(context.TODO(), params) +} +func (c *ApiService) CreateBrandRegistrationsWithContext(ctx context.Context, params *CreateBrandRegistrationsParams) (*MessagingV1BrandRegistrations, error) { path := "/v1/a2p/BrandRegistrations" data := url.Values{} @@ -83,7 +86,7 @@ func (c *ApiService) CreateBrandRegistrations(params *CreateBrandRegistrationsPa data.Set("SkipAutomaticSecVet", fmt.Sprint(*params.SkipAutomaticSecVet)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -98,8 +101,10 @@ func (c *ApiService) CreateBrandRegistrations(params *CreateBrandRegistrationsPa return ps, err } -// func (c *ApiService) FetchBrandRegistrations(Sid string) (*MessagingV1BrandRegistrations, error) { + return c.FetchBrandRegistrationsWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchBrandRegistrationsWithContext(ctx context.Context, Sid string) (*MessagingV1BrandRegistrations, error) { path := "/v1/a2p/BrandRegistrations/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -108,7 +113,7 @@ func (c *ApiService) FetchBrandRegistrations(Sid string) (*MessagingV1BrandRegis "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -142,6 +147,11 @@ func (params *ListBrandRegistrationsParams) SetLimit(Limit int) *ListBrandRegist // Retrieve a single page of BrandRegistrations records from the API. Request is executed immediately. func (c *ApiService) PageBrandRegistrations(params *ListBrandRegistrationsParams, pageToken, pageNumber string) (*ListBrandRegistrationsResponse, error) { + return c.PageBrandRegistrationsWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of BrandRegistrations records from the API. Request is executed immediately. +func (c *ApiService) PageBrandRegistrationsWithContext(ctx context.Context, params *ListBrandRegistrationsParams, pageToken, pageNumber string) (*ListBrandRegistrationsResponse, error) { path := "/v1/a2p/BrandRegistrations" data := url.Values{} @@ -160,7 +170,7 @@ func (c *ApiService) PageBrandRegistrations(params *ListBrandRegistrationsParams data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -177,7 +187,12 @@ func (c *ApiService) PageBrandRegistrations(params *ListBrandRegistrationsParams // Lists BrandRegistrations records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListBrandRegistrations(params *ListBrandRegistrationsParams) ([]MessagingV1BrandRegistrations, error) { - response, errors := c.StreamBrandRegistrations(params) + return c.ListBrandRegistrationsWithContext(context.TODO(), params) +} + +// Lists BrandRegistrations records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListBrandRegistrationsWithContext(ctx context.Context, params *ListBrandRegistrationsParams) ([]MessagingV1BrandRegistrations, error) { + response, errors := c.StreamBrandRegistrationsWithContext(ctx, params) records := make([]MessagingV1BrandRegistrations, 0) for record := range response { @@ -193,6 +208,11 @@ func (c *ApiService) ListBrandRegistrations(params *ListBrandRegistrationsParams // Streams BrandRegistrations records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamBrandRegistrations(params *ListBrandRegistrationsParams) (chan MessagingV1BrandRegistrations, chan error) { + return c.StreamBrandRegistrationsWithContext(context.TODO(), params) +} + +// Streams BrandRegistrations records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamBrandRegistrationsWithContext(ctx context.Context, params *ListBrandRegistrationsParams) (chan MessagingV1BrandRegistrations, chan error) { if params == nil { params = &ListBrandRegistrationsParams{} } @@ -201,19 +221,19 @@ func (c *ApiService) StreamBrandRegistrations(params *ListBrandRegistrationsPara recordChannel := make(chan MessagingV1BrandRegistrations, 1) errorChannel := make(chan error, 1) - response, err := c.PageBrandRegistrations(params, "", "") + response, err := c.PageBrandRegistrationsWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamBrandRegistrations(response, params, recordChannel, errorChannel) + go c.streamBrandRegistrationsWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamBrandRegistrations(response *ListBrandRegistrationsResponse, params *ListBrandRegistrationsParams, recordChannel chan MessagingV1BrandRegistrations, errorChannel chan error) { +func (c *ApiService) streamBrandRegistrationsWithContext(ctx context.Context, response *ListBrandRegistrationsResponse, params *ListBrandRegistrationsParams, recordChannel chan MessagingV1BrandRegistrations, errorChannel chan error) { curRecord := 1 for response != nil { @@ -228,7 +248,7 @@ func (c *ApiService) streamBrandRegistrations(response *ListBrandRegistrationsRe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListBrandRegistrationsResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListBrandRegistrationsResponseWithContext) if err != nil { errorChannel <- err break @@ -243,11 +263,11 @@ func (c *ApiService) streamBrandRegistrations(response *ListBrandRegistrationsRe close(errorChannel) } -func (c *ApiService) getNextListBrandRegistrationsResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListBrandRegistrationsResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -261,8 +281,10 @@ func (c *ApiService) getNextListBrandRegistrationsResponse(nextPageUrl string) ( return ps, nil } -// func (c *ApiService) UpdateBrandRegistrations(Sid string) (*MessagingV1BrandRegistrations, error) { + return c.UpdateBrandRegistrationsWithContext(context.TODO(), Sid) +} +func (c *ApiService) UpdateBrandRegistrationsWithContext(ctx context.Context, Sid string) (*MessagingV1BrandRegistrations, error) { path := "/v1/a2p/BrandRegistrations/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -271,7 +293,7 @@ func (c *ApiService) UpdateBrandRegistrations(Sid string) (*MessagingV1BrandRegi "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/messaging/v1/a2p_brand_registrations_sms_otp.go b/rest/messaging/v1/a2p_brand_registrations_sms_otp.go index e50d6ace6..f51b2e97c 100644 --- a/rest/messaging/v1/a2p_brand_registrations_sms_otp.go +++ b/rest/messaging/v1/a2p_brand_registrations_sms_otp.go @@ -15,13 +15,16 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" ) -// func (c *ApiService) CreateBrandRegistrationOtp(BrandRegistrationSid string) (*MessagingV1BrandRegistrationOtp, error) { + return c.CreateBrandRegistrationOtpWithContext(context.TODO(), BrandRegistrationSid) +} +func (c *ApiService) CreateBrandRegistrationOtpWithContext(ctx context.Context, BrandRegistrationSid string) (*MessagingV1BrandRegistrationOtp, error) { path := "/v1/a2p/BrandRegistrations/{BrandRegistrationSid}/SmsOtp" path = strings.Replace(path, "{"+"BrandRegistrationSid"+"}", BrandRegistrationSid, -1) @@ -30,7 +33,7 @@ func (c *ApiService) CreateBrandRegistrationOtp(BrandRegistrationSid string) (*M "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/messaging/v1/a2p_brand_registrations_vettings.go b/rest/messaging/v1/a2p_brand_registrations_vettings.go index df8a862f4..dda37ea00 100644 --- a/rest/messaging/v1/a2p_brand_registrations_vettings.go +++ b/rest/messaging/v1/a2p_brand_registrations_vettings.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -40,8 +41,10 @@ func (params *CreateBrandVettingParams) SetVettingId(VettingId string) *CreateBr return params } -// func (c *ApiService) CreateBrandVetting(BrandSid string, params *CreateBrandVettingParams) (*MessagingV1BrandVetting, error) { + return c.CreateBrandVettingWithContext(context.TODO(), BrandSid, params) +} +func (c *ApiService) CreateBrandVettingWithContext(ctx context.Context, BrandSid string, params *CreateBrandVettingParams) (*MessagingV1BrandVetting, error) { path := "/v1/a2p/BrandRegistrations/{BrandSid}/Vettings" path = strings.Replace(path, "{"+"BrandSid"+"}", BrandSid, -1) @@ -57,7 +60,7 @@ func (c *ApiService) CreateBrandVetting(BrandSid string, params *CreateBrandVett data.Set("VettingId", *params.VettingId) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -72,8 +75,10 @@ func (c *ApiService) CreateBrandVetting(BrandSid string, params *CreateBrandVett return ps, err } -// func (c *ApiService) FetchBrandVetting(BrandSid string, BrandVettingSid string) (*MessagingV1BrandVetting, error) { + return c.FetchBrandVettingWithContext(context.TODO(), BrandSid, BrandVettingSid) +} +func (c *ApiService) FetchBrandVettingWithContext(ctx context.Context, BrandSid string, BrandVettingSid string) (*MessagingV1BrandVetting, error) { path := "/v1/a2p/BrandRegistrations/{BrandSid}/Vettings/{BrandVettingSid}" path = strings.Replace(path, "{"+"BrandSid"+"}", BrandSid, -1) path = strings.Replace(path, "{"+"BrandVettingSid"+"}", BrandVettingSid, -1) @@ -83,7 +88,7 @@ func (c *ApiService) FetchBrandVetting(BrandSid string, BrandVettingSid string) "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -123,6 +128,11 @@ func (params *ListBrandVettingParams) SetPageSize(PageSize int) *ListBrandVettin // Retrieve a single page of BrandVetting records from the API. Request is executed immediately. func (c *ApiService) PageBrandVetting(BrandSid string, params *ListBrandVettingParams, pageToken, pageNumber string) (*ListBrandVettingResponse, error) { + return c.PageBrandVettingWithContext(context.TODO(), BrandSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of BrandVetting records from the API. Request is executed immediately. +func (c *ApiService) PageBrandVettingWithContext(ctx context.Context, BrandSid string, params *ListBrandVettingParams, pageToken, pageNumber string) (*ListBrandVettingResponse, error) { path := "/v1/a2p/BrandRegistrations/{BrandSid}/Vettings" path = strings.Replace(path, "{"+"BrandSid"+"}", BrandSid, -1) @@ -146,7 +156,7 @@ func (c *ApiService) PageBrandVetting(BrandSid string, params *ListBrandVettingP data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -163,7 +173,12 @@ func (c *ApiService) PageBrandVetting(BrandSid string, params *ListBrandVettingP // Lists BrandVetting records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListBrandVetting(BrandSid string, params *ListBrandVettingParams) ([]MessagingV1BrandVetting, error) { - response, errors := c.StreamBrandVetting(BrandSid, params) + return c.ListBrandVettingWithContext(context.TODO(), BrandSid, params) +} + +// Lists BrandVetting records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListBrandVettingWithContext(ctx context.Context, BrandSid string, params *ListBrandVettingParams) ([]MessagingV1BrandVetting, error) { + response, errors := c.StreamBrandVettingWithContext(ctx, BrandSid, params) records := make([]MessagingV1BrandVetting, 0) for record := range response { @@ -179,6 +194,11 @@ func (c *ApiService) ListBrandVetting(BrandSid string, params *ListBrandVettingP // Streams BrandVetting records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamBrandVetting(BrandSid string, params *ListBrandVettingParams) (chan MessagingV1BrandVetting, chan error) { + return c.StreamBrandVettingWithContext(context.TODO(), BrandSid, params) +} + +// Streams BrandVetting records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamBrandVettingWithContext(ctx context.Context, BrandSid string, params *ListBrandVettingParams) (chan MessagingV1BrandVetting, chan error) { if params == nil { params = &ListBrandVettingParams{} } @@ -187,19 +207,19 @@ func (c *ApiService) StreamBrandVetting(BrandSid string, params *ListBrandVettin recordChannel := make(chan MessagingV1BrandVetting, 1) errorChannel := make(chan error, 1) - response, err := c.PageBrandVetting(BrandSid, params, "", "") + response, err := c.PageBrandVettingWithContext(ctx, BrandSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamBrandVetting(response, params, recordChannel, errorChannel) + go c.streamBrandVettingWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamBrandVetting(response *ListBrandVettingResponse, params *ListBrandVettingParams, recordChannel chan MessagingV1BrandVetting, errorChannel chan error) { +func (c *ApiService) streamBrandVettingWithContext(ctx context.Context, response *ListBrandVettingResponse, params *ListBrandVettingParams, recordChannel chan MessagingV1BrandVetting, errorChannel chan error) { curRecord := 1 for response != nil { @@ -214,7 +234,7 @@ func (c *ApiService) streamBrandVetting(response *ListBrandVettingResponse, para } } - record, err := client.GetNext(c.baseURL, response, c.getNextListBrandVettingResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListBrandVettingResponseWithContext) if err != nil { errorChannel <- err break @@ -229,11 +249,11 @@ func (c *ApiService) streamBrandVetting(response *ListBrandVettingResponse, para close(errorChannel) } -func (c *ApiService) getNextListBrandVettingResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListBrandVettingResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/messaging/v1/api_service.go b/rest/messaging/v1/api_service.go index 2233a7d5a..3b7519452 100644 --- a/rest/messaging/v1/api_service.go +++ b/rest/messaging/v1/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://messaging.twilio.com", + } +} diff --git a/rest/messaging/v1/deactivations.go b/rest/messaging/v1/deactivations.go index 534aea74c..3f4b24df7 100644 --- a/rest/messaging/v1/deactivations.go +++ b/rest/messaging/v1/deactivations.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -33,6 +34,9 @@ func (params *FetchDeactivationParams) SetDate(Date string) *FetchDeactivationPa // Fetch a list of all United States numbers that have been deactivated on a specific date. func (c *ApiService) FetchDeactivation(params *FetchDeactivationParams) (*MessagingV1Deactivation, error) { + return c.FetchDeactivationWithContext(context.TODO(), params) +} +func (c *ApiService) FetchDeactivationWithContext(ctx context.Context, params *FetchDeactivationParams) (*MessagingV1Deactivation, error) { path := "/v1/Deactivations" data := url.Values{} @@ -44,7 +48,7 @@ func (c *ApiService) FetchDeactivation(params *FetchDeactivationParams) (*Messag data.Set("Date", fmt.Sprint(*params.Date)) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/messaging/v1/link_shortening_domains_certificate.go b/rest/messaging/v1/link_shortening_domains_certificate.go index 18da54871..9d5a6e0d4 100644 --- a/rest/messaging/v1/link_shortening_domains_certificate.go +++ b/rest/messaging/v1/link_shortening_domains_certificate.go @@ -15,13 +15,16 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" ) -// func (c *ApiService) DeleteDomainCertV4(DomainSid string) error { + return c.DeleteDomainCertV4WithContext(context.TODO(), DomainSid) +} +func (c *ApiService) DeleteDomainCertV4WithContext(ctx context.Context, DomainSid string) error { path := "/v1/LinkShortening/Domains/{DomainSid}/Certificate" path = strings.Replace(path, "{"+"DomainSid"+"}", DomainSid, -1) @@ -30,7 +33,7 @@ func (c *ApiService) DeleteDomainCertV4(DomainSid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -40,8 +43,10 @@ func (c *ApiService) DeleteDomainCertV4(DomainSid string) error { return nil } -// func (c *ApiService) FetchDomainCertV4(DomainSid string) (*MessagingV1DomainCertV4, error) { + return c.FetchDomainCertV4WithContext(context.TODO(), DomainSid) +} +func (c *ApiService) FetchDomainCertV4WithContext(ctx context.Context, DomainSid string) (*MessagingV1DomainCertV4, error) { path := "/v1/LinkShortening/Domains/{DomainSid}/Certificate" path = strings.Replace(path, "{"+"DomainSid"+"}", DomainSid, -1) @@ -50,7 +55,7 @@ func (c *ApiService) FetchDomainCertV4(DomainSid string) (*MessagingV1DomainCert "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -76,8 +81,10 @@ func (params *UpdateDomainCertV4Params) SetTlsCert(TlsCert string) *UpdateDomain return params } -// func (c *ApiService) UpdateDomainCertV4(DomainSid string, params *UpdateDomainCertV4Params) (*MessagingV1DomainCertV4, error) { + return c.UpdateDomainCertV4WithContext(context.TODO(), DomainSid, params) +} +func (c *ApiService) UpdateDomainCertV4WithContext(ctx context.Context, DomainSid string, params *UpdateDomainCertV4Params) (*MessagingV1DomainCertV4, error) { path := "/v1/LinkShortening/Domains/{DomainSid}/Certificate" path = strings.Replace(path, "{"+"DomainSid"+"}", DomainSid, -1) @@ -90,7 +97,7 @@ func (c *ApiService) UpdateDomainCertV4(DomainSid string, params *UpdateDomainCe data.Set("TlsCert", *params.TlsCert) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/messaging/v1/link_shortening_domains_config.go b/rest/messaging/v1/link_shortening_domains_config.go index 4640b96c5..dc6e83d29 100644 --- a/rest/messaging/v1/link_shortening_domains_config.go +++ b/rest/messaging/v1/link_shortening_domains_config.go @@ -15,14 +15,17 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" "strings" ) -// func (c *ApiService) FetchDomainConfig(DomainSid string) (*MessagingV1DomainConfig, error) { + return c.FetchDomainConfigWithContext(context.TODO(), DomainSid) +} +func (c *ApiService) FetchDomainConfigWithContext(ctx context.Context, DomainSid string) (*MessagingV1DomainConfig, error) { path := "/v1/LinkShortening/Domains/{DomainSid}/Config" path = strings.Replace(path, "{"+"DomainSid"+"}", DomainSid, -1) @@ -31,7 +34,7 @@ func (c *ApiService) FetchDomainConfig(DomainSid string) (*MessagingV1DomainConf "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -75,8 +78,10 @@ func (params *UpdateDomainConfigParams) SetDisableHttps(DisableHttps bool) *Upda return params } -// func (c *ApiService) UpdateDomainConfig(DomainSid string, params *UpdateDomainConfigParams) (*MessagingV1DomainConfig, error) { + return c.UpdateDomainConfigWithContext(context.TODO(), DomainSid, params) +} +func (c *ApiService) UpdateDomainConfigWithContext(ctx context.Context, DomainSid string, params *UpdateDomainConfigParams) (*MessagingV1DomainConfig, error) { path := "/v1/LinkShortening/Domains/{DomainSid}/Config" path = strings.Replace(path, "{"+"DomainSid"+"}", DomainSid, -1) @@ -98,7 +103,7 @@ func (c *ApiService) UpdateDomainConfig(DomainSid string, params *UpdateDomainCo data.Set("DisableHttps", fmt.Sprint(*params.DisableHttps)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/messaging/v1/link_shortening_domains_messaging_services.go b/rest/messaging/v1/link_shortening_domains_messaging_services.go index c855ac7e4..d34bf09bb 100644 --- a/rest/messaging/v1/link_shortening_domains_messaging_services.go +++ b/rest/messaging/v1/link_shortening_domains_messaging_services.go @@ -15,13 +15,16 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" ) -// func (c *ApiService) CreateLinkshorteningMessagingService(DomainSid string, MessagingServiceSid string) (*MessagingV1LinkshorteningMessagingService, error) { + return c.CreateLinkshorteningMessagingServiceWithContext(context.TODO(), DomainSid, MessagingServiceSid) +} +func (c *ApiService) CreateLinkshorteningMessagingServiceWithContext(ctx context.Context, DomainSid string, MessagingServiceSid string) (*MessagingV1LinkshorteningMessagingService, error) { path := "/v1/LinkShortening/Domains/{DomainSid}/MessagingServices/{MessagingServiceSid}" path = strings.Replace(path, "{"+"DomainSid"+"}", DomainSid, -1) path = strings.Replace(path, "{"+"MessagingServiceSid"+"}", MessagingServiceSid, -1) @@ -31,7 +34,7 @@ func (c *ApiService) CreateLinkshorteningMessagingService(DomainSid string, Mess "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -46,8 +49,10 @@ func (c *ApiService) CreateLinkshorteningMessagingService(DomainSid string, Mess return ps, err } -// func (c *ApiService) DeleteLinkshorteningMessagingService(DomainSid string, MessagingServiceSid string) error { + return c.DeleteLinkshorteningMessagingServiceWithContext(context.TODO(), DomainSid, MessagingServiceSid) +} +func (c *ApiService) DeleteLinkshorteningMessagingServiceWithContext(ctx context.Context, DomainSid string, MessagingServiceSid string) error { path := "/v1/LinkShortening/Domains/{DomainSid}/MessagingServices/{MessagingServiceSid}" path = strings.Replace(path, "{"+"DomainSid"+"}", DomainSid, -1) path = strings.Replace(path, "{"+"MessagingServiceSid"+"}", MessagingServiceSid, -1) @@ -57,7 +62,7 @@ func (c *ApiService) DeleteLinkshorteningMessagingService(DomainSid string, Mess "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } diff --git a/rest/messaging/v1/link_shortening_domains_request_managed_cert.go b/rest/messaging/v1/link_shortening_domains_request_managed_cert.go index 78c888b7c..995a64fbc 100644 --- a/rest/messaging/v1/link_shortening_domains_request_managed_cert.go +++ b/rest/messaging/v1/link_shortening_domains_request_managed_cert.go @@ -15,13 +15,16 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" ) -// func (c *ApiService) UpdateRequestManagedCert(DomainSid string) (*MessagingV1RequestManagedCert, error) { + return c.UpdateRequestManagedCertWithContext(context.TODO(), DomainSid) +} +func (c *ApiService) UpdateRequestManagedCertWithContext(ctx context.Context, DomainSid string) (*MessagingV1RequestManagedCert, error) { path := "/v1/LinkShortening/Domains/{DomainSid}/RequestManagedCert" path = strings.Replace(path, "{"+"DomainSid"+"}", DomainSid, -1) @@ -30,7 +33,7 @@ func (c *ApiService) UpdateRequestManagedCert(DomainSid string) (*MessagingV1Req "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/messaging/v1/link_shortening_messaging_service_domain_config.go b/rest/messaging/v1/link_shortening_messaging_service_domain_config.go index eccc21461..127345e9c 100644 --- a/rest/messaging/v1/link_shortening_messaging_service_domain_config.go +++ b/rest/messaging/v1/link_shortening_messaging_service_domain_config.go @@ -15,13 +15,16 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" ) -// func (c *ApiService) FetchDomainConfigMessagingService(MessagingServiceSid string) (*MessagingV1DomainConfigMessagingService, error) { + return c.FetchDomainConfigMessagingServiceWithContext(context.TODO(), MessagingServiceSid) +} +func (c *ApiService) FetchDomainConfigMessagingServiceWithContext(ctx context.Context, MessagingServiceSid string) (*MessagingV1DomainConfigMessagingService, error) { path := "/v1/LinkShortening/MessagingService/{MessagingServiceSid}/DomainConfig" path = strings.Replace(path, "{"+"MessagingServiceSid"+"}", MessagingServiceSid, -1) @@ -30,7 +33,7 @@ func (c *ApiService) FetchDomainConfigMessagingService(MessagingServiceSid strin "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/messaging/v1/link_shortening_messaging_services_domain.go b/rest/messaging/v1/link_shortening_messaging_services_domain.go index 959612813..25a66d68f 100644 --- a/rest/messaging/v1/link_shortening_messaging_services_domain.go +++ b/rest/messaging/v1/link_shortening_messaging_services_domain.go @@ -15,13 +15,16 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" ) -// func (c *ApiService) FetchLinkshorteningMessagingServiceDomainAssociation(MessagingServiceSid string) (*MessagingV1LinkshorteningMessagingServiceDomainAssociation, error) { + return c.FetchLinkshorteningMessagingServiceDomainAssociationWithContext(context.TODO(), MessagingServiceSid) +} +func (c *ApiService) FetchLinkshorteningMessagingServiceDomainAssociationWithContext(ctx context.Context, MessagingServiceSid string) (*MessagingV1LinkshorteningMessagingServiceDomainAssociation, error) { path := "/v1/LinkShortening/MessagingServices/{MessagingServiceSid}/Domain" path = strings.Replace(path, "{"+"MessagingServiceSid"+"}", MessagingServiceSid, -1) @@ -30,7 +33,7 @@ func (c *ApiService) FetchLinkshorteningMessagingServiceDomainAssociation(Messag "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/messaging/v1/services.go b/rest/messaging/v1/services.go index 6c4bbcf2b..492a8dc45 100644 --- a/rest/messaging/v1/services.go +++ b/rest/messaging/v1/services.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -124,8 +125,10 @@ func (params *CreateServiceParams) SetUseInboundWebhookOnNumber(UseInboundWebhoo return params } -// func (c *ApiService) CreateService(params *CreateServiceParams) (*MessagingV1Service, error) { + return c.CreateServiceWithContext(context.TODO(), params) +} +func (c *ApiService) CreateServiceWithContext(ctx context.Context, params *CreateServiceParams) (*MessagingV1Service, error) { path := "/v1/Services" data := url.Values{} @@ -182,7 +185,7 @@ func (c *ApiService) CreateService(params *CreateServiceParams) (*MessagingV1Ser data.Set("UseInboundWebhookOnNumber", fmt.Sprint(*params.UseInboundWebhookOnNumber)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -197,8 +200,10 @@ func (c *ApiService) CreateService(params *CreateServiceParams) (*MessagingV1Ser return ps, err } -// func (c *ApiService) DeleteService(Sid string) error { + return c.DeleteServiceWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteServiceWithContext(ctx context.Context, Sid string) error { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -207,7 +212,7 @@ func (c *ApiService) DeleteService(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -217,8 +222,10 @@ func (c *ApiService) DeleteService(Sid string) error { return nil } -// func (c *ApiService) FetchService(Sid string) (*MessagingV1Service, error) { + return c.FetchServiceWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchServiceWithContext(ctx context.Context, Sid string) (*MessagingV1Service, error) { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -227,7 +234,7 @@ func (c *ApiService) FetchService(Sid string) (*MessagingV1Service, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -261,6 +268,11 @@ func (params *ListServiceParams) SetLimit(Limit int) *ListServiceParams { // Retrieve a single page of Service records from the API. Request is executed immediately. func (c *ApiService) PageService(params *ListServiceParams, pageToken, pageNumber string) (*ListServiceResponse, error) { + return c.PageServiceWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Service records from the API. Request is executed immediately. +func (c *ApiService) PageServiceWithContext(ctx context.Context, params *ListServiceParams, pageToken, pageNumber string) (*ListServiceResponse, error) { path := "/v1/Services" data := url.Values{} @@ -279,7 +291,7 @@ func (c *ApiService) PageService(params *ListServiceParams, pageToken, pageNumbe data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -296,7 +308,12 @@ func (c *ApiService) PageService(params *ListServiceParams, pageToken, pageNumbe // Lists Service records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListService(params *ListServiceParams) ([]MessagingV1Service, error) { - response, errors := c.StreamService(params) + return c.ListServiceWithContext(context.TODO(), params) +} + +// Lists Service records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListServiceWithContext(ctx context.Context, params *ListServiceParams) ([]MessagingV1Service, error) { + response, errors := c.StreamServiceWithContext(ctx, params) records := make([]MessagingV1Service, 0) for record := range response { @@ -312,6 +329,11 @@ func (c *ApiService) ListService(params *ListServiceParams) ([]MessagingV1Servic // Streams Service records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamService(params *ListServiceParams) (chan MessagingV1Service, chan error) { + return c.StreamServiceWithContext(context.TODO(), params) +} + +// Streams Service records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamServiceWithContext(ctx context.Context, params *ListServiceParams) (chan MessagingV1Service, chan error) { if params == nil { params = &ListServiceParams{} } @@ -320,19 +342,19 @@ func (c *ApiService) StreamService(params *ListServiceParams) (chan MessagingV1S recordChannel := make(chan MessagingV1Service, 1) errorChannel := make(chan error, 1) - response, err := c.PageService(params, "", "") + response, err := c.PageServiceWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamService(response, params, recordChannel, errorChannel) + go c.streamServiceWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamService(response *ListServiceResponse, params *ListServiceParams, recordChannel chan MessagingV1Service, errorChannel chan error) { +func (c *ApiService) streamServiceWithContext(ctx context.Context, response *ListServiceResponse, params *ListServiceParams, recordChannel chan MessagingV1Service, errorChannel chan error) { curRecord := 1 for response != nil { @@ -347,7 +369,7 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListServiceResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListServiceResponseWithContext) if err != nil { errorChannel <- err break @@ -362,11 +384,11 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe close(errorChannel) } -func (c *ApiService) getNextListServiceResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListServiceResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -481,8 +503,10 @@ func (params *UpdateServiceParams) SetUseInboundWebhookOnNumber(UseInboundWebhoo return params } -// func (c *ApiService) UpdateService(Sid string, params *UpdateServiceParams) (*MessagingV1Service, error) { + return c.UpdateServiceWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateServiceWithContext(ctx context.Context, Sid string, params *UpdateServiceParams) (*MessagingV1Service, error) { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -540,7 +564,7 @@ func (c *ApiService) UpdateService(Sid string, params *UpdateServiceParams) (*Me data.Set("UseInboundWebhookOnNumber", fmt.Sprint(*params.UseInboundWebhookOnNumber)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/messaging/v1/services_alpha_senders.go b/rest/messaging/v1/services_alpha_senders.go index 469d8cec6..3633091c5 100644 --- a/rest/messaging/v1/services_alpha_senders.go +++ b/rest/messaging/v1/services_alpha_senders.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -34,8 +35,10 @@ func (params *CreateAlphaSenderParams) SetAlphaSender(AlphaSender string) *Creat return params } -// func (c *ApiService) CreateAlphaSender(ServiceSid string, params *CreateAlphaSenderParams) (*MessagingV1AlphaSender, error) { + return c.CreateAlphaSenderWithContext(context.TODO(), ServiceSid, params) +} +func (c *ApiService) CreateAlphaSenderWithContext(ctx context.Context, ServiceSid string, params *CreateAlphaSenderParams) (*MessagingV1AlphaSender, error) { path := "/v1/Services/{ServiceSid}/AlphaSenders" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -48,7 +51,7 @@ func (c *ApiService) CreateAlphaSender(ServiceSid string, params *CreateAlphaSen data.Set("AlphaSender", *params.AlphaSender) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -63,8 +66,10 @@ func (c *ApiService) CreateAlphaSender(ServiceSid string, params *CreateAlphaSen return ps, err } -// func (c *ApiService) DeleteAlphaSender(ServiceSid string, Sid string) error { + return c.DeleteAlphaSenderWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) DeleteAlphaSenderWithContext(ctx context.Context, ServiceSid string, Sid string) error { path := "/v1/Services/{ServiceSid}/AlphaSenders/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -74,7 +79,7 @@ func (c *ApiService) DeleteAlphaSender(ServiceSid string, Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -84,8 +89,10 @@ func (c *ApiService) DeleteAlphaSender(ServiceSid string, Sid string) error { return nil } -// func (c *ApiService) FetchAlphaSender(ServiceSid string, Sid string) (*MessagingV1AlphaSender, error) { + return c.FetchAlphaSenderWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) FetchAlphaSenderWithContext(ctx context.Context, ServiceSid string, Sid string) (*MessagingV1AlphaSender, error) { path := "/v1/Services/{ServiceSid}/AlphaSenders/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -95,7 +102,7 @@ func (c *ApiService) FetchAlphaSender(ServiceSid string, Sid string) (*Messaging "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -129,6 +136,11 @@ func (params *ListAlphaSenderParams) SetLimit(Limit int) *ListAlphaSenderParams // Retrieve a single page of AlphaSender records from the API. Request is executed immediately. func (c *ApiService) PageAlphaSender(ServiceSid string, params *ListAlphaSenderParams, pageToken, pageNumber string) (*ListAlphaSenderResponse, error) { + return c.PageAlphaSenderWithContext(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of AlphaSender records from the API. Request is executed immediately. +func (c *ApiService) PageAlphaSenderWithContext(ctx context.Context, ServiceSid string, params *ListAlphaSenderParams, pageToken, pageNumber string) (*ListAlphaSenderResponse, error) { path := "/v1/Services/{ServiceSid}/AlphaSenders" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -149,7 +161,7 @@ func (c *ApiService) PageAlphaSender(ServiceSid string, params *ListAlphaSenderP data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -166,7 +178,12 @@ func (c *ApiService) PageAlphaSender(ServiceSid string, params *ListAlphaSenderP // Lists AlphaSender records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListAlphaSender(ServiceSid string, params *ListAlphaSenderParams) ([]MessagingV1AlphaSender, error) { - response, errors := c.StreamAlphaSender(ServiceSid, params) + return c.ListAlphaSenderWithContext(context.TODO(), ServiceSid, params) +} + +// Lists AlphaSender records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListAlphaSenderWithContext(ctx context.Context, ServiceSid string, params *ListAlphaSenderParams) ([]MessagingV1AlphaSender, error) { + response, errors := c.StreamAlphaSenderWithContext(ctx, ServiceSid, params) records := make([]MessagingV1AlphaSender, 0) for record := range response { @@ -182,6 +199,11 @@ func (c *ApiService) ListAlphaSender(ServiceSid string, params *ListAlphaSenderP // Streams AlphaSender records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamAlphaSender(ServiceSid string, params *ListAlphaSenderParams) (chan MessagingV1AlphaSender, chan error) { + return c.StreamAlphaSenderWithContext(context.TODO(), ServiceSid, params) +} + +// Streams AlphaSender records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamAlphaSenderWithContext(ctx context.Context, ServiceSid string, params *ListAlphaSenderParams) (chan MessagingV1AlphaSender, chan error) { if params == nil { params = &ListAlphaSenderParams{} } @@ -190,19 +212,19 @@ func (c *ApiService) StreamAlphaSender(ServiceSid string, params *ListAlphaSende recordChannel := make(chan MessagingV1AlphaSender, 1) errorChannel := make(chan error, 1) - response, err := c.PageAlphaSender(ServiceSid, params, "", "") + response, err := c.PageAlphaSenderWithContext(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamAlphaSender(response, params, recordChannel, errorChannel) + go c.streamAlphaSenderWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamAlphaSender(response *ListAlphaSenderResponse, params *ListAlphaSenderParams, recordChannel chan MessagingV1AlphaSender, errorChannel chan error) { +func (c *ApiService) streamAlphaSenderWithContext(ctx context.Context, response *ListAlphaSenderResponse, params *ListAlphaSenderParams, recordChannel chan MessagingV1AlphaSender, errorChannel chan error) { curRecord := 1 for response != nil { @@ -217,7 +239,7 @@ func (c *ApiService) streamAlphaSender(response *ListAlphaSenderResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListAlphaSenderResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListAlphaSenderResponseWithContext) if err != nil { errorChannel <- err break @@ -232,11 +254,11 @@ func (c *ApiService) streamAlphaSender(response *ListAlphaSenderResponse, params close(errorChannel) } -func (c *ApiService) getNextListAlphaSenderResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListAlphaSenderResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/messaging/v1/services_channel_senders.go b/rest/messaging/v1/services_channel_senders.go index 8a00c8a5e..7ad176eee 100644 --- a/rest/messaging/v1/services_channel_senders.go +++ b/rest/messaging/v1/services_channel_senders.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -34,8 +35,10 @@ func (params *CreateChannelSenderParams) SetSid(Sid string) *CreateChannelSender return params } -// func (c *ApiService) CreateChannelSender(MessagingServiceSid string, params *CreateChannelSenderParams) (*MessagingV1ChannelSender, error) { + return c.CreateChannelSenderWithContext(context.TODO(), MessagingServiceSid, params) +} +func (c *ApiService) CreateChannelSenderWithContext(ctx context.Context, MessagingServiceSid string, params *CreateChannelSenderParams) (*MessagingV1ChannelSender, error) { path := "/v1/Services/{MessagingServiceSid}/ChannelSenders" path = strings.Replace(path, "{"+"MessagingServiceSid"+"}", MessagingServiceSid, -1) @@ -48,7 +51,7 @@ func (c *ApiService) CreateChannelSender(MessagingServiceSid string, params *Cre data.Set("Sid", *params.Sid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -63,8 +66,10 @@ func (c *ApiService) CreateChannelSender(MessagingServiceSid string, params *Cre return ps, err } -// func (c *ApiService) DeleteChannelSender(MessagingServiceSid string, Sid string) error { + return c.DeleteChannelSenderWithContext(context.TODO(), MessagingServiceSid, Sid) +} +func (c *ApiService) DeleteChannelSenderWithContext(ctx context.Context, MessagingServiceSid string, Sid string) error { path := "/v1/Services/{MessagingServiceSid}/ChannelSenders/{Sid}" path = strings.Replace(path, "{"+"MessagingServiceSid"+"}", MessagingServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -74,7 +79,7 @@ func (c *ApiService) DeleteChannelSender(MessagingServiceSid string, Sid string) "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -84,8 +89,10 @@ func (c *ApiService) DeleteChannelSender(MessagingServiceSid string, Sid string) return nil } -// func (c *ApiService) FetchChannelSender(MessagingServiceSid string, Sid string) (*MessagingV1ChannelSender, error) { + return c.FetchChannelSenderWithContext(context.TODO(), MessagingServiceSid, Sid) +} +func (c *ApiService) FetchChannelSenderWithContext(ctx context.Context, MessagingServiceSid string, Sid string) (*MessagingV1ChannelSender, error) { path := "/v1/Services/{MessagingServiceSid}/ChannelSenders/{Sid}" path = strings.Replace(path, "{"+"MessagingServiceSid"+"}", MessagingServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -95,7 +102,7 @@ func (c *ApiService) FetchChannelSender(MessagingServiceSid string, Sid string) "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -129,6 +136,11 @@ func (params *ListChannelSenderParams) SetLimit(Limit int) *ListChannelSenderPar // Retrieve a single page of ChannelSender records from the API. Request is executed immediately. func (c *ApiService) PageChannelSender(MessagingServiceSid string, params *ListChannelSenderParams, pageToken, pageNumber string) (*ListChannelSenderResponse, error) { + return c.PageChannelSenderWithContext(context.TODO(), MessagingServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ChannelSender records from the API. Request is executed immediately. +func (c *ApiService) PageChannelSenderWithContext(ctx context.Context, MessagingServiceSid string, params *ListChannelSenderParams, pageToken, pageNumber string) (*ListChannelSenderResponse, error) { path := "/v1/Services/{MessagingServiceSid}/ChannelSenders" path = strings.Replace(path, "{"+"MessagingServiceSid"+"}", MessagingServiceSid, -1) @@ -149,7 +161,7 @@ func (c *ApiService) PageChannelSender(MessagingServiceSid string, params *ListC data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -166,7 +178,12 @@ func (c *ApiService) PageChannelSender(MessagingServiceSid string, params *ListC // Lists ChannelSender records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListChannelSender(MessagingServiceSid string, params *ListChannelSenderParams) ([]MessagingV1ChannelSender, error) { - response, errors := c.StreamChannelSender(MessagingServiceSid, params) + return c.ListChannelSenderWithContext(context.TODO(), MessagingServiceSid, params) +} + +// Lists ChannelSender records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListChannelSenderWithContext(ctx context.Context, MessagingServiceSid string, params *ListChannelSenderParams) ([]MessagingV1ChannelSender, error) { + response, errors := c.StreamChannelSenderWithContext(ctx, MessagingServiceSid, params) records := make([]MessagingV1ChannelSender, 0) for record := range response { @@ -182,6 +199,11 @@ func (c *ApiService) ListChannelSender(MessagingServiceSid string, params *ListC // Streams ChannelSender records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamChannelSender(MessagingServiceSid string, params *ListChannelSenderParams) (chan MessagingV1ChannelSender, chan error) { + return c.StreamChannelSenderWithContext(context.TODO(), MessagingServiceSid, params) +} + +// Streams ChannelSender records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamChannelSenderWithContext(ctx context.Context, MessagingServiceSid string, params *ListChannelSenderParams) (chan MessagingV1ChannelSender, chan error) { if params == nil { params = &ListChannelSenderParams{} } @@ -190,19 +212,19 @@ func (c *ApiService) StreamChannelSender(MessagingServiceSid string, params *Lis recordChannel := make(chan MessagingV1ChannelSender, 1) errorChannel := make(chan error, 1) - response, err := c.PageChannelSender(MessagingServiceSid, params, "", "") + response, err := c.PageChannelSenderWithContext(ctx, MessagingServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamChannelSender(response, params, recordChannel, errorChannel) + go c.streamChannelSenderWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamChannelSender(response *ListChannelSenderResponse, params *ListChannelSenderParams, recordChannel chan MessagingV1ChannelSender, errorChannel chan error) { +func (c *ApiService) streamChannelSenderWithContext(ctx context.Context, response *ListChannelSenderResponse, params *ListChannelSenderParams, recordChannel chan MessagingV1ChannelSender, errorChannel chan error) { curRecord := 1 for response != nil { @@ -217,7 +239,7 @@ func (c *ApiService) streamChannelSender(response *ListChannelSenderResponse, pa } } - record, err := client.GetNext(c.baseURL, response, c.getNextListChannelSenderResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListChannelSenderResponseWithContext) if err != nil { errorChannel <- err break @@ -232,11 +254,11 @@ func (c *ApiService) streamChannelSender(response *ListChannelSenderResponse, pa close(errorChannel) } -func (c *ApiService) getNextListChannelSenderResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListChannelSenderResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/messaging/v1/services_compliance_usa2p.go b/rest/messaging/v1/services_compliance_usa2p.go index 8cd2f9492..d6f4a977d 100644 --- a/rest/messaging/v1/services_compliance_usa2p.go +++ b/rest/messaging/v1/services_compliance_usa2p.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -124,8 +125,10 @@ func (params *CreateUsAppToPersonParams) SetDirectLending(DirectLending bool) *C return params } -// func (c *ApiService) CreateUsAppToPerson(MessagingServiceSid string, params *CreateUsAppToPersonParams) (*MessagingV1UsAppToPerson, error) { + return c.CreateUsAppToPersonWithContext(context.TODO(), MessagingServiceSid, params) +} +func (c *ApiService) CreateUsAppToPersonWithContext(ctx context.Context, MessagingServiceSid string, params *CreateUsAppToPersonParams) (*MessagingV1UsAppToPerson, error) { path := "/v1/Services/{MessagingServiceSid}/Compliance/Usa2p" path = strings.Replace(path, "{"+"MessagingServiceSid"+"}", MessagingServiceSid, -1) @@ -191,7 +194,7 @@ func (c *ApiService) CreateUsAppToPerson(MessagingServiceSid string, params *Cre data.Set("DirectLending", fmt.Sprint(*params.DirectLending)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -206,8 +209,10 @@ func (c *ApiService) CreateUsAppToPerson(MessagingServiceSid string, params *Cre return ps, err } -// func (c *ApiService) DeleteUsAppToPerson(MessagingServiceSid string, Sid string) error { + return c.DeleteUsAppToPersonWithContext(context.TODO(), MessagingServiceSid, Sid) +} +func (c *ApiService) DeleteUsAppToPersonWithContext(ctx context.Context, MessagingServiceSid string, Sid string) error { path := "/v1/Services/{MessagingServiceSid}/Compliance/Usa2p/{Sid}" path = strings.Replace(path, "{"+"MessagingServiceSid"+"}", MessagingServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -217,7 +222,7 @@ func (c *ApiService) DeleteUsAppToPerson(MessagingServiceSid string, Sid string) "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -227,8 +232,10 @@ func (c *ApiService) DeleteUsAppToPerson(MessagingServiceSid string, Sid string) return nil } -// func (c *ApiService) FetchUsAppToPerson(MessagingServiceSid string, Sid string) (*MessagingV1UsAppToPerson, error) { + return c.FetchUsAppToPersonWithContext(context.TODO(), MessagingServiceSid, Sid) +} +func (c *ApiService) FetchUsAppToPersonWithContext(ctx context.Context, MessagingServiceSid string, Sid string) (*MessagingV1UsAppToPerson, error) { path := "/v1/Services/{MessagingServiceSid}/Compliance/Usa2p/{Sid}" path = strings.Replace(path, "{"+"MessagingServiceSid"+"}", MessagingServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -238,7 +245,7 @@ func (c *ApiService) FetchUsAppToPerson(MessagingServiceSid string, Sid string) "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -272,6 +279,11 @@ func (params *ListUsAppToPersonParams) SetLimit(Limit int) *ListUsAppToPersonPar // Retrieve a single page of UsAppToPerson records from the API. Request is executed immediately. func (c *ApiService) PageUsAppToPerson(MessagingServiceSid string, params *ListUsAppToPersonParams, pageToken, pageNumber string) (*ListUsAppToPersonResponse, error) { + return c.PageUsAppToPersonWithContext(context.TODO(), MessagingServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of UsAppToPerson records from the API. Request is executed immediately. +func (c *ApiService) PageUsAppToPersonWithContext(ctx context.Context, MessagingServiceSid string, params *ListUsAppToPersonParams, pageToken, pageNumber string) (*ListUsAppToPersonResponse, error) { path := "/v1/Services/{MessagingServiceSid}/Compliance/Usa2p" path = strings.Replace(path, "{"+"MessagingServiceSid"+"}", MessagingServiceSid, -1) @@ -292,7 +304,7 @@ func (c *ApiService) PageUsAppToPerson(MessagingServiceSid string, params *ListU data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -309,7 +321,12 @@ func (c *ApiService) PageUsAppToPerson(MessagingServiceSid string, params *ListU // Lists UsAppToPerson records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListUsAppToPerson(MessagingServiceSid string, params *ListUsAppToPersonParams) ([]MessagingV1UsAppToPerson, error) { - response, errors := c.StreamUsAppToPerson(MessagingServiceSid, params) + return c.ListUsAppToPersonWithContext(context.TODO(), MessagingServiceSid, params) +} + +// Lists UsAppToPerson records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListUsAppToPersonWithContext(ctx context.Context, MessagingServiceSid string, params *ListUsAppToPersonParams) ([]MessagingV1UsAppToPerson, error) { + response, errors := c.StreamUsAppToPersonWithContext(ctx, MessagingServiceSid, params) records := make([]MessagingV1UsAppToPerson, 0) for record := range response { @@ -325,6 +342,11 @@ func (c *ApiService) ListUsAppToPerson(MessagingServiceSid string, params *ListU // Streams UsAppToPerson records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamUsAppToPerson(MessagingServiceSid string, params *ListUsAppToPersonParams) (chan MessagingV1UsAppToPerson, chan error) { + return c.StreamUsAppToPersonWithContext(context.TODO(), MessagingServiceSid, params) +} + +// Streams UsAppToPerson records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamUsAppToPersonWithContext(ctx context.Context, MessagingServiceSid string, params *ListUsAppToPersonParams) (chan MessagingV1UsAppToPerson, chan error) { if params == nil { params = &ListUsAppToPersonParams{} } @@ -333,19 +355,19 @@ func (c *ApiService) StreamUsAppToPerson(MessagingServiceSid string, params *Lis recordChannel := make(chan MessagingV1UsAppToPerson, 1) errorChannel := make(chan error, 1) - response, err := c.PageUsAppToPerson(MessagingServiceSid, params, "", "") + response, err := c.PageUsAppToPersonWithContext(ctx, MessagingServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUsAppToPerson(response, params, recordChannel, errorChannel) + go c.streamUsAppToPersonWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamUsAppToPerson(response *ListUsAppToPersonResponse, params *ListUsAppToPersonParams, recordChannel chan MessagingV1UsAppToPerson, errorChannel chan error) { +func (c *ApiService) streamUsAppToPersonWithContext(ctx context.Context, response *ListUsAppToPersonResponse, params *ListUsAppToPersonParams, recordChannel chan MessagingV1UsAppToPerson, errorChannel chan error) { curRecord := 1 for response != nil { @@ -360,7 +382,7 @@ func (c *ApiService) streamUsAppToPerson(response *ListUsAppToPersonResponse, pa } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUsAppToPersonResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListUsAppToPersonResponseWithContext) if err != nil { errorChannel <- err break @@ -375,11 +397,11 @@ func (c *ApiService) streamUsAppToPerson(response *ListUsAppToPersonResponse, pa close(errorChannel) } -func (c *ApiService) getNextListUsAppToPersonResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUsAppToPersonResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -440,8 +462,10 @@ func (params *UpdateUsAppToPersonParams) SetDirectLending(DirectLending bool) *U return params } -// func (c *ApiService) UpdateUsAppToPerson(MessagingServiceSid string, Sid string, params *UpdateUsAppToPersonParams) (*MessagingV1UsAppToPerson, error) { + return c.UpdateUsAppToPersonWithContext(context.TODO(), MessagingServiceSid, Sid, params) +} +func (c *ApiService) UpdateUsAppToPersonWithContext(ctx context.Context, MessagingServiceSid string, Sid string, params *UpdateUsAppToPersonParams) (*MessagingV1UsAppToPerson, error) { path := "/v1/Services/{MessagingServiceSid}/Compliance/Usa2p/{Sid}" path = strings.Replace(path, "{"+"MessagingServiceSid"+"}", MessagingServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -475,7 +499,7 @@ func (c *ApiService) UpdateUsAppToPerson(MessagingServiceSid string, Sid string, data.Set("DirectLending", fmt.Sprint(*params.DirectLending)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/messaging/v1/services_compliance_usa2p_usecases.go b/rest/messaging/v1/services_compliance_usa2p_usecases.go index 34f6527a0..8b545a5db 100644 --- a/rest/messaging/v1/services_compliance_usa2p_usecases.go +++ b/rest/messaging/v1/services_compliance_usa2p_usecases.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -31,8 +32,10 @@ func (params *FetchUsAppToPersonUsecaseParams) SetBrandRegistrationSid(BrandRegi return params } -// func (c *ApiService) FetchUsAppToPersonUsecase(MessagingServiceSid string, params *FetchUsAppToPersonUsecaseParams) (*MessagingV1UsAppToPersonUsecase, error) { + return c.FetchUsAppToPersonUsecaseWithContext(context.TODO(), MessagingServiceSid, params) +} +func (c *ApiService) FetchUsAppToPersonUsecaseWithContext(ctx context.Context, MessagingServiceSid string, params *FetchUsAppToPersonUsecaseParams) (*MessagingV1UsAppToPersonUsecase, error) { path := "/v1/Services/{MessagingServiceSid}/Compliance/Usa2p/Usecases" path = strings.Replace(path, "{"+"MessagingServiceSid"+"}", MessagingServiceSid, -1) @@ -45,7 +48,7 @@ func (c *ApiService) FetchUsAppToPersonUsecase(MessagingServiceSid string, param data.Set("BrandRegistrationSid", *params.BrandRegistrationSid) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/messaging/v1/services_destination_alpha_senders.go b/rest/messaging/v1/services_destination_alpha_senders.go index afc92ec76..dea35e8ac 100644 --- a/rest/messaging/v1/services_destination_alpha_senders.go +++ b/rest/messaging/v1/services_destination_alpha_senders.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -40,8 +41,10 @@ func (params *CreateDestinationAlphaSenderParams) SetIsoCountryCode(IsoCountryCo return params } -// func (c *ApiService) CreateDestinationAlphaSender(ServiceSid string, params *CreateDestinationAlphaSenderParams) (*MessagingV1DestinationAlphaSender, error) { + return c.CreateDestinationAlphaSenderWithContext(context.TODO(), ServiceSid, params) +} +func (c *ApiService) CreateDestinationAlphaSenderWithContext(ctx context.Context, ServiceSid string, params *CreateDestinationAlphaSenderParams) (*MessagingV1DestinationAlphaSender, error) { path := "/v1/Services/{ServiceSid}/DestinationAlphaSenders" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -57,7 +60,7 @@ func (c *ApiService) CreateDestinationAlphaSender(ServiceSid string, params *Cre data.Set("IsoCountryCode", *params.IsoCountryCode) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -72,8 +75,10 @@ func (c *ApiService) CreateDestinationAlphaSender(ServiceSid string, params *Cre return ps, err } -// func (c *ApiService) DeleteDestinationAlphaSender(ServiceSid string, Sid string) error { + return c.DeleteDestinationAlphaSenderWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) DeleteDestinationAlphaSenderWithContext(ctx context.Context, ServiceSid string, Sid string) error { path := "/v1/Services/{ServiceSid}/DestinationAlphaSenders/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -83,7 +88,7 @@ func (c *ApiService) DeleteDestinationAlphaSender(ServiceSid string, Sid string) "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -93,8 +98,10 @@ func (c *ApiService) DeleteDestinationAlphaSender(ServiceSid string, Sid string) return nil } -// func (c *ApiService) FetchDestinationAlphaSender(ServiceSid string, Sid string) (*MessagingV1DestinationAlphaSender, error) { + return c.FetchDestinationAlphaSenderWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) FetchDestinationAlphaSenderWithContext(ctx context.Context, ServiceSid string, Sid string) (*MessagingV1DestinationAlphaSender, error) { path := "/v1/Services/{ServiceSid}/DestinationAlphaSenders/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -104,7 +111,7 @@ func (c *ApiService) FetchDestinationAlphaSender(ServiceSid string, Sid string) "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -138,6 +145,11 @@ func (params *ListDestinationAlphaSenderParams) SetLimit(Limit int) *ListDestina // Retrieve a single page of DestinationAlphaSender records from the API. Request is executed immediately. func (c *ApiService) PageDestinationAlphaSender(ServiceSid string, params *ListDestinationAlphaSenderParams, pageToken, pageNumber string) (*ListDestinationAlphaSenderResponse, error) { + return c.PageDestinationAlphaSenderWithContext(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of DestinationAlphaSender records from the API. Request is executed immediately. +func (c *ApiService) PageDestinationAlphaSenderWithContext(ctx context.Context, ServiceSid string, params *ListDestinationAlphaSenderParams, pageToken, pageNumber string) (*ListDestinationAlphaSenderResponse, error) { path := "/v1/Services/{ServiceSid}/DestinationAlphaSenders" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -158,7 +170,7 @@ func (c *ApiService) PageDestinationAlphaSender(ServiceSid string, params *ListD data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -175,7 +187,12 @@ func (c *ApiService) PageDestinationAlphaSender(ServiceSid string, params *ListD // Lists DestinationAlphaSender records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListDestinationAlphaSender(ServiceSid string, params *ListDestinationAlphaSenderParams) ([]MessagingV1DestinationAlphaSender, error) { - response, errors := c.StreamDestinationAlphaSender(ServiceSid, params) + return c.ListDestinationAlphaSenderWithContext(context.TODO(), ServiceSid, params) +} + +// Lists DestinationAlphaSender records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListDestinationAlphaSenderWithContext(ctx context.Context, ServiceSid string, params *ListDestinationAlphaSenderParams) ([]MessagingV1DestinationAlphaSender, error) { + response, errors := c.StreamDestinationAlphaSenderWithContext(ctx, ServiceSid, params) records := make([]MessagingV1DestinationAlphaSender, 0) for record := range response { @@ -191,6 +208,11 @@ func (c *ApiService) ListDestinationAlphaSender(ServiceSid string, params *ListD // Streams DestinationAlphaSender records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamDestinationAlphaSender(ServiceSid string, params *ListDestinationAlphaSenderParams) (chan MessagingV1DestinationAlphaSender, chan error) { + return c.StreamDestinationAlphaSenderWithContext(context.TODO(), ServiceSid, params) +} + +// Streams DestinationAlphaSender records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamDestinationAlphaSenderWithContext(ctx context.Context, ServiceSid string, params *ListDestinationAlphaSenderParams) (chan MessagingV1DestinationAlphaSender, chan error) { if params == nil { params = &ListDestinationAlphaSenderParams{} } @@ -199,19 +221,19 @@ func (c *ApiService) StreamDestinationAlphaSender(ServiceSid string, params *Lis recordChannel := make(chan MessagingV1DestinationAlphaSender, 1) errorChannel := make(chan error, 1) - response, err := c.PageDestinationAlphaSender(ServiceSid, params, "", "") + response, err := c.PageDestinationAlphaSenderWithContext(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamDestinationAlphaSender(response, params, recordChannel, errorChannel) + go c.streamDestinationAlphaSenderWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamDestinationAlphaSender(response *ListDestinationAlphaSenderResponse, params *ListDestinationAlphaSenderParams, recordChannel chan MessagingV1DestinationAlphaSender, errorChannel chan error) { +func (c *ApiService) streamDestinationAlphaSenderWithContext(ctx context.Context, response *ListDestinationAlphaSenderResponse, params *ListDestinationAlphaSenderParams, recordChannel chan MessagingV1DestinationAlphaSender, errorChannel chan error) { curRecord := 1 for response != nil { @@ -226,7 +248,7 @@ func (c *ApiService) streamDestinationAlphaSender(response *ListDestinationAlpha } } - record, err := client.GetNext(c.baseURL, response, c.getNextListDestinationAlphaSenderResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListDestinationAlphaSenderResponseWithContext) if err != nil { errorChannel <- err break @@ -241,11 +263,11 @@ func (c *ApiService) streamDestinationAlphaSender(response *ListDestinationAlpha close(errorChannel) } -func (c *ApiService) getNextListDestinationAlphaSenderResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListDestinationAlphaSenderResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/messaging/v1/services_phone_numbers.go b/rest/messaging/v1/services_phone_numbers.go index 644f38e34..fdcf86a0a 100644 --- a/rest/messaging/v1/services_phone_numbers.go +++ b/rest/messaging/v1/services_phone_numbers.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -34,8 +35,10 @@ func (params *CreatePhoneNumberParams) SetPhoneNumberSid(PhoneNumberSid string) return params } -// func (c *ApiService) CreatePhoneNumber(ServiceSid string, params *CreatePhoneNumberParams) (*MessagingV1PhoneNumber, error) { + return c.CreatePhoneNumberWithContext(context.TODO(), ServiceSid, params) +} +func (c *ApiService) CreatePhoneNumberWithContext(ctx context.Context, ServiceSid string, params *CreatePhoneNumberParams) (*MessagingV1PhoneNumber, error) { path := "/v1/Services/{ServiceSid}/PhoneNumbers" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -48,7 +51,7 @@ func (c *ApiService) CreatePhoneNumber(ServiceSid string, params *CreatePhoneNum data.Set("PhoneNumberSid", *params.PhoneNumberSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -63,8 +66,10 @@ func (c *ApiService) CreatePhoneNumber(ServiceSid string, params *CreatePhoneNum return ps, err } -// func (c *ApiService) DeletePhoneNumber(ServiceSid string, Sid string) error { + return c.DeletePhoneNumberWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) DeletePhoneNumberWithContext(ctx context.Context, ServiceSid string, Sid string) error { path := "/v1/Services/{ServiceSid}/PhoneNumbers/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -74,7 +79,7 @@ func (c *ApiService) DeletePhoneNumber(ServiceSid string, Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -84,8 +89,10 @@ func (c *ApiService) DeletePhoneNumber(ServiceSid string, Sid string) error { return nil } -// func (c *ApiService) FetchPhoneNumber(ServiceSid string, Sid string) (*MessagingV1PhoneNumber, error) { + return c.FetchPhoneNumberWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) FetchPhoneNumberWithContext(ctx context.Context, ServiceSid string, Sid string) (*MessagingV1PhoneNumber, error) { path := "/v1/Services/{ServiceSid}/PhoneNumbers/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -95,7 +102,7 @@ func (c *ApiService) FetchPhoneNumber(ServiceSid string, Sid string) (*Messaging "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -129,6 +136,11 @@ func (params *ListPhoneNumberParams) SetLimit(Limit int) *ListPhoneNumberParams // Retrieve a single page of PhoneNumber records from the API. Request is executed immediately. func (c *ApiService) PagePhoneNumber(ServiceSid string, params *ListPhoneNumberParams, pageToken, pageNumber string) (*ListPhoneNumberResponse, error) { + return c.PagePhoneNumberWithContext(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of PhoneNumber records from the API. Request is executed immediately. +func (c *ApiService) PagePhoneNumberWithContext(ctx context.Context, ServiceSid string, params *ListPhoneNumberParams, pageToken, pageNumber string) (*ListPhoneNumberResponse, error) { path := "/v1/Services/{ServiceSid}/PhoneNumbers" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -149,7 +161,7 @@ func (c *ApiService) PagePhoneNumber(ServiceSid string, params *ListPhoneNumberP data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -166,7 +178,12 @@ func (c *ApiService) PagePhoneNumber(ServiceSid string, params *ListPhoneNumberP // Lists PhoneNumber records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListPhoneNumber(ServiceSid string, params *ListPhoneNumberParams) ([]MessagingV1PhoneNumber, error) { - response, errors := c.StreamPhoneNumber(ServiceSid, params) + return c.ListPhoneNumberWithContext(context.TODO(), ServiceSid, params) +} + +// Lists PhoneNumber records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListPhoneNumberWithContext(ctx context.Context, ServiceSid string, params *ListPhoneNumberParams) ([]MessagingV1PhoneNumber, error) { + response, errors := c.StreamPhoneNumberWithContext(ctx, ServiceSid, params) records := make([]MessagingV1PhoneNumber, 0) for record := range response { @@ -182,6 +199,11 @@ func (c *ApiService) ListPhoneNumber(ServiceSid string, params *ListPhoneNumberP // Streams PhoneNumber records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamPhoneNumber(ServiceSid string, params *ListPhoneNumberParams) (chan MessagingV1PhoneNumber, chan error) { + return c.StreamPhoneNumberWithContext(context.TODO(), ServiceSid, params) +} + +// Streams PhoneNumber records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamPhoneNumberWithContext(ctx context.Context, ServiceSid string, params *ListPhoneNumberParams) (chan MessagingV1PhoneNumber, chan error) { if params == nil { params = &ListPhoneNumberParams{} } @@ -190,19 +212,19 @@ func (c *ApiService) StreamPhoneNumber(ServiceSid string, params *ListPhoneNumbe recordChannel := make(chan MessagingV1PhoneNumber, 1) errorChannel := make(chan error, 1) - response, err := c.PagePhoneNumber(ServiceSid, params, "", "") + response, err := c.PagePhoneNumberWithContext(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamPhoneNumber(response, params, recordChannel, errorChannel) + go c.streamPhoneNumberWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamPhoneNumber(response *ListPhoneNumberResponse, params *ListPhoneNumberParams, recordChannel chan MessagingV1PhoneNumber, errorChannel chan error) { +func (c *ApiService) streamPhoneNumberWithContext(ctx context.Context, response *ListPhoneNumberResponse, params *ListPhoneNumberParams, recordChannel chan MessagingV1PhoneNumber, errorChannel chan error) { curRecord := 1 for response != nil { @@ -217,7 +239,7 @@ func (c *ApiService) streamPhoneNumber(response *ListPhoneNumberResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListPhoneNumberResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListPhoneNumberResponseWithContext) if err != nil { errorChannel <- err break @@ -232,11 +254,11 @@ func (c *ApiService) streamPhoneNumber(response *ListPhoneNumberResponse, params close(errorChannel) } -func (c *ApiService) getNextListPhoneNumberResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListPhoneNumberResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/messaging/v1/services_preregistered_usa2p.go b/rest/messaging/v1/services_preregistered_usa2p.go index 548aa0733..ca9c4b362 100644 --- a/rest/messaging/v1/services_preregistered_usa2p.go +++ b/rest/messaging/v1/services_preregistered_usa2p.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -43,8 +44,10 @@ func (params *CreateExternalCampaignParams) SetCnpMigration(CnpMigration bool) * return params } -// func (c *ApiService) CreateExternalCampaign(params *CreateExternalCampaignParams) (*MessagingV1ExternalCampaign, error) { + return c.CreateExternalCampaignWithContext(context.TODO(), params) +} +func (c *ApiService) CreateExternalCampaignWithContext(ctx context.Context, params *CreateExternalCampaignParams) (*MessagingV1ExternalCampaign, error) { path := "/v1/Services/PreregisteredUsa2p" data := url.Values{} @@ -62,7 +65,7 @@ func (c *ApiService) CreateExternalCampaign(params *CreateExternalCampaignParams data.Set("CnpMigration", fmt.Sprint(*params.CnpMigration)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/messaging/v1/services_short_codes.go b/rest/messaging/v1/services_short_codes.go index a776f509f..7530c946f 100644 --- a/rest/messaging/v1/services_short_codes.go +++ b/rest/messaging/v1/services_short_codes.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -34,8 +35,10 @@ func (params *CreateShortCodeParams) SetShortCodeSid(ShortCodeSid string) *Creat return params } -// func (c *ApiService) CreateShortCode(ServiceSid string, params *CreateShortCodeParams) (*MessagingV1ShortCode, error) { + return c.CreateShortCodeWithContext(context.TODO(), ServiceSid, params) +} +func (c *ApiService) CreateShortCodeWithContext(ctx context.Context, ServiceSid string, params *CreateShortCodeParams) (*MessagingV1ShortCode, error) { path := "/v1/Services/{ServiceSid}/ShortCodes" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -48,7 +51,7 @@ func (c *ApiService) CreateShortCode(ServiceSid string, params *CreateShortCodeP data.Set("ShortCodeSid", *params.ShortCodeSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -63,8 +66,10 @@ func (c *ApiService) CreateShortCode(ServiceSid string, params *CreateShortCodeP return ps, err } -// func (c *ApiService) DeleteShortCode(ServiceSid string, Sid string) error { + return c.DeleteShortCodeWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) DeleteShortCodeWithContext(ctx context.Context, ServiceSid string, Sid string) error { path := "/v1/Services/{ServiceSid}/ShortCodes/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -74,7 +79,7 @@ func (c *ApiService) DeleteShortCode(ServiceSid string, Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -84,8 +89,10 @@ func (c *ApiService) DeleteShortCode(ServiceSid string, Sid string) error { return nil } -// func (c *ApiService) FetchShortCode(ServiceSid string, Sid string) (*MessagingV1ShortCode, error) { + return c.FetchShortCodeWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) FetchShortCodeWithContext(ctx context.Context, ServiceSid string, Sid string) (*MessagingV1ShortCode, error) { path := "/v1/Services/{ServiceSid}/ShortCodes/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -95,7 +102,7 @@ func (c *ApiService) FetchShortCode(ServiceSid string, Sid string) (*MessagingV1 "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -129,6 +136,11 @@ func (params *ListShortCodeParams) SetLimit(Limit int) *ListShortCodeParams { // Retrieve a single page of ShortCode records from the API. Request is executed immediately. func (c *ApiService) PageShortCode(ServiceSid string, params *ListShortCodeParams, pageToken, pageNumber string) (*ListShortCodeResponse, error) { + return c.PageShortCodeWithContext(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ShortCode records from the API. Request is executed immediately. +func (c *ApiService) PageShortCodeWithContext(ctx context.Context, ServiceSid string, params *ListShortCodeParams, pageToken, pageNumber string) (*ListShortCodeResponse, error) { path := "/v1/Services/{ServiceSid}/ShortCodes" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -149,7 +161,7 @@ func (c *ApiService) PageShortCode(ServiceSid string, params *ListShortCodeParam data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -166,7 +178,12 @@ func (c *ApiService) PageShortCode(ServiceSid string, params *ListShortCodeParam // Lists ShortCode records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListShortCode(ServiceSid string, params *ListShortCodeParams) ([]MessagingV1ShortCode, error) { - response, errors := c.StreamShortCode(ServiceSid, params) + return c.ListShortCodeWithContext(context.TODO(), ServiceSid, params) +} + +// Lists ShortCode records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListShortCodeWithContext(ctx context.Context, ServiceSid string, params *ListShortCodeParams) ([]MessagingV1ShortCode, error) { + response, errors := c.StreamShortCodeWithContext(ctx, ServiceSid, params) records := make([]MessagingV1ShortCode, 0) for record := range response { @@ -182,6 +199,11 @@ func (c *ApiService) ListShortCode(ServiceSid string, params *ListShortCodeParam // Streams ShortCode records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamShortCode(ServiceSid string, params *ListShortCodeParams) (chan MessagingV1ShortCode, chan error) { + return c.StreamShortCodeWithContext(context.TODO(), ServiceSid, params) +} + +// Streams ShortCode records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamShortCodeWithContext(ctx context.Context, ServiceSid string, params *ListShortCodeParams) (chan MessagingV1ShortCode, chan error) { if params == nil { params = &ListShortCodeParams{} } @@ -190,19 +212,19 @@ func (c *ApiService) StreamShortCode(ServiceSid string, params *ListShortCodePar recordChannel := make(chan MessagingV1ShortCode, 1) errorChannel := make(chan error, 1) - response, err := c.PageShortCode(ServiceSid, params, "", "") + response, err := c.PageShortCodeWithContext(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamShortCode(response, params, recordChannel, errorChannel) + go c.streamShortCodeWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamShortCode(response *ListShortCodeResponse, params *ListShortCodeParams, recordChannel chan MessagingV1ShortCode, errorChannel chan error) { +func (c *ApiService) streamShortCodeWithContext(ctx context.Context, response *ListShortCodeResponse, params *ListShortCodeParams, recordChannel chan MessagingV1ShortCode, errorChannel chan error) { curRecord := 1 for response != nil { @@ -217,7 +239,7 @@ func (c *ApiService) streamShortCode(response *ListShortCodeResponse, params *Li } } - record, err := client.GetNext(c.baseURL, response, c.getNextListShortCodeResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListShortCodeResponseWithContext) if err != nil { errorChannel <- err break @@ -232,11 +254,11 @@ func (c *ApiService) streamShortCode(response *ListShortCodeResponse, params *Li close(errorChannel) } -func (c *ApiService) getNextListShortCodeResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListShortCodeResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/messaging/v1/services_usecases.go b/rest/messaging/v1/services_usecases.go index af836ab9a..46b1babe9 100644 --- a/rest/messaging/v1/services_usecases.go +++ b/rest/messaging/v1/services_usecases.go @@ -15,12 +15,15 @@ package openapi import ( + "context" "encoding/json" "net/url" ) -// func (c *ApiService) FetchUsecase() (*MessagingV1Usecase, error) { + return c.FetchUsecaseWithContext(context.TODO()) +} +func (c *ApiService) FetchUsecaseWithContext(ctx context.Context) (*MessagingV1Usecase, error) { path := "/v1/Services/Usecases" data := url.Values{} @@ -28,7 +31,7 @@ func (c *ApiService) FetchUsecase() (*MessagingV1Usecase, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/messaging/v1/tollfree_verifications.go b/rest/messaging/v1/tollfree_verifications.go index 88632039e..de1358ee1 100644 --- a/rest/messaging/v1/tollfree_verifications.go +++ b/rest/messaging/v1/tollfree_verifications.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -166,8 +167,10 @@ func (params *CreateTollfreeVerificationParams) SetExternalReferenceId(ExternalR return params } -// func (c *ApiService) CreateTollfreeVerification(params *CreateTollfreeVerificationParams) (*MessagingV1TollfreeVerification, error) { + return c.CreateTollfreeVerificationWithContext(context.TODO(), params) +} +func (c *ApiService) CreateTollfreeVerificationWithContext(ctx context.Context, params *CreateTollfreeVerificationParams) (*MessagingV1TollfreeVerification, error) { path := "/v1/Tollfree/Verifications" data := url.Values{} @@ -249,7 +252,7 @@ func (c *ApiService) CreateTollfreeVerification(params *CreateTollfreeVerificati data.Set("ExternalReferenceId", *params.ExternalReferenceId) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -264,8 +267,10 @@ func (c *ApiService) CreateTollfreeVerification(params *CreateTollfreeVerificati return ps, err } -// func (c *ApiService) DeleteTollfreeVerification(Sid string) error { + return c.DeleteTollfreeVerificationWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteTollfreeVerificationWithContext(ctx context.Context, Sid string) error { path := "/v1/Tollfree/Verifications/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -274,7 +279,7 @@ func (c *ApiService) DeleteTollfreeVerification(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -284,8 +289,10 @@ func (c *ApiService) DeleteTollfreeVerification(Sid string) error { return nil } -// func (c *ApiService) FetchTollfreeVerification(Sid string) (*MessagingV1TollfreeVerification, error) { + return c.FetchTollfreeVerificationWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchTollfreeVerificationWithContext(ctx context.Context, Sid string) (*MessagingV1TollfreeVerification, error) { path := "/v1/Tollfree/Verifications/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -294,7 +301,7 @@ func (c *ApiService) FetchTollfreeVerification(Sid string) (*MessagingV1Tollfree "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -352,6 +359,11 @@ func (params *ListTollfreeVerificationParams) SetLimit(Limit int) *ListTollfreeV // Retrieve a single page of TollfreeVerification records from the API. Request is executed immediately. func (c *ApiService) PageTollfreeVerification(params *ListTollfreeVerificationParams, pageToken, pageNumber string) (*ListTollfreeVerificationResponse, error) { + return c.PageTollfreeVerificationWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of TollfreeVerification records from the API. Request is executed immediately. +func (c *ApiService) PageTollfreeVerificationWithContext(ctx context.Context, params *ListTollfreeVerificationParams, pageToken, pageNumber string) (*ListTollfreeVerificationResponse, error) { path := "/v1/Tollfree/Verifications" data := url.Values{} @@ -382,7 +394,7 @@ func (c *ApiService) PageTollfreeVerification(params *ListTollfreeVerificationPa data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -399,7 +411,12 @@ func (c *ApiService) PageTollfreeVerification(params *ListTollfreeVerificationPa // Lists TollfreeVerification records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListTollfreeVerification(params *ListTollfreeVerificationParams) ([]MessagingV1TollfreeVerification, error) { - response, errors := c.StreamTollfreeVerification(params) + return c.ListTollfreeVerificationWithContext(context.TODO(), params) +} + +// Lists TollfreeVerification records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListTollfreeVerificationWithContext(ctx context.Context, params *ListTollfreeVerificationParams) ([]MessagingV1TollfreeVerification, error) { + response, errors := c.StreamTollfreeVerificationWithContext(ctx, params) records := make([]MessagingV1TollfreeVerification, 0) for record := range response { @@ -415,6 +432,11 @@ func (c *ApiService) ListTollfreeVerification(params *ListTollfreeVerificationPa // Streams TollfreeVerification records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamTollfreeVerification(params *ListTollfreeVerificationParams) (chan MessagingV1TollfreeVerification, chan error) { + return c.StreamTollfreeVerificationWithContext(context.TODO(), params) +} + +// Streams TollfreeVerification records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamTollfreeVerificationWithContext(ctx context.Context, params *ListTollfreeVerificationParams) (chan MessagingV1TollfreeVerification, chan error) { if params == nil { params = &ListTollfreeVerificationParams{} } @@ -423,19 +445,19 @@ func (c *ApiService) StreamTollfreeVerification(params *ListTollfreeVerification recordChannel := make(chan MessagingV1TollfreeVerification, 1) errorChannel := make(chan error, 1) - response, err := c.PageTollfreeVerification(params, "", "") + response, err := c.PageTollfreeVerificationWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamTollfreeVerification(response, params, recordChannel, errorChannel) + go c.streamTollfreeVerificationWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamTollfreeVerification(response *ListTollfreeVerificationResponse, params *ListTollfreeVerificationParams, recordChannel chan MessagingV1TollfreeVerification, errorChannel chan error) { +func (c *ApiService) streamTollfreeVerificationWithContext(ctx context.Context, response *ListTollfreeVerificationResponse, params *ListTollfreeVerificationParams, recordChannel chan MessagingV1TollfreeVerification, errorChannel chan error) { curRecord := 1 for response != nil { @@ -450,7 +472,7 @@ func (c *ApiService) streamTollfreeVerification(response *ListTollfreeVerificati } } - record, err := client.GetNext(c.baseURL, response, c.getNextListTollfreeVerificationResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListTollfreeVerificationResponseWithContext) if err != nil { errorChannel <- err break @@ -465,11 +487,11 @@ func (c *ApiService) streamTollfreeVerification(response *ListTollfreeVerificati close(errorChannel) } -func (c *ApiService) getNextListTollfreeVerificationResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListTollfreeVerificationResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -614,8 +636,10 @@ func (params *UpdateTollfreeVerificationParams) SetEditReason(EditReason string) return params } -// func (c *ApiService) UpdateTollfreeVerification(Sid string, params *UpdateTollfreeVerificationParams) (*MessagingV1TollfreeVerification, error) { + return c.UpdateTollfreeVerificationWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateTollfreeVerificationWithContext(ctx context.Context, Sid string, params *UpdateTollfreeVerificationParams) (*MessagingV1TollfreeVerification, error) { path := "/v1/Tollfree/Verifications/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -692,7 +716,7 @@ func (c *ApiService) UpdateTollfreeVerification(Sid string, params *UpdateTollfr data.Set("EditReason", *params.EditReason) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/messaging/v2/README.md b/rest/messaging/v2/README.md index 8c0f7db5c..8522446b6 100644 --- a/rest/messaging/v2/README.md +++ b/rest/messaging/v2/README.md @@ -41,15 +41,17 @@ Class | Method | HTTP request | Description ## Documentation For Models - [ListChannelsSenderResponse](docs/ListChannelsSenderResponse.md) - - [MessagingV2ChannelsSender](docs/MessagingV2ChannelsSender.md) - [MessagingV2Configuration](docs/MessagingV2Configuration.md) - [MessagingV2Items](docs/MessagingV2Items.md) - - [ListChannelsSenderResponseMeta](docs/ListChannelsSenderResponseMeta.md) - [MessagingV2Webhook](docs/MessagingV2Webhook.md) - [MessagingV2Create](docs/MessagingV2Create.md) - - [MessagingV2Properties](docs/MessagingV2Properties.md) - [MessagingV2Update](docs/MessagingV2Update.md) - [MessagingV2Profile](docs/MessagingV2Profile.md) + - [MessagingV2ChannelsSender](docs/MessagingV2ChannelsSender.md) + - [ListChannelsSenderResponseMeta](docs/ListChannelsSenderResponseMeta.md) + - [MessagingV2ChannelsSenderProfileEmails](docs/MessagingV2ChannelsSenderProfileEmails.md) + - [MessagingV2Properties](docs/MessagingV2Properties.md) + - [MessagingV2ChannelsSenderProfileWebsites](docs/MessagingV2ChannelsSenderProfileWebsites.md) ## Documentation For Authorization diff --git a/rest/messaging/v2/api_service.go b/rest/messaging/v2/api_service.go index 2233a7d5a..3b7519452 100644 --- a/rest/messaging/v2/api_service.go +++ b/rest/messaging/v2/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://messaging.twilio.com", + } +} diff --git a/rest/messaging/v2/channels_senders.go b/rest/messaging/v2/channels_senders.go index 32a12e86e..628d30a06 100644 --- a/rest/messaging/v2/channels_senders.go +++ b/rest/messaging/v2/channels_senders.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -36,6 +37,9 @@ func (params *CreateChannelsSenderParams) SetMessagingV2Create(MessagingV2Create // Create a new sender of WhatsApp. func (c *ApiService) CreateChannelsSender(params *CreateChannelsSenderParams) (*MessagingV2ChannelsSender, error) { + return c.CreateChannelsSenderWithContext(context.TODO(), params) +} +func (c *ApiService) CreateChannelsSenderWithContext(ctx context.Context, params *CreateChannelsSenderParams) (*MessagingV2ChannelsSender, error) { path := "/v2/Channels/Senders" data := url.Values{} @@ -52,7 +56,7 @@ func (c *ApiService) CreateChannelsSender(params *CreateChannelsSenderParams) (* body = b } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers, body...) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers, body...) if err != nil { return nil, err } @@ -69,6 +73,9 @@ func (c *ApiService) CreateChannelsSender(params *CreateChannelsSenderParams) (* // Delete a specific sender by its unique identifier. func (c *ApiService) DeleteChannelsSender(Sid string) error { + return c.DeleteChannelsSenderWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteChannelsSenderWithContext(ctx context.Context, Sid string) error { path := "/v2/Channels/Senders/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -77,7 +84,7 @@ func (c *ApiService) DeleteChannelsSender(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -89,6 +96,9 @@ func (c *ApiService) DeleteChannelsSender(Sid string) error { // Retrieve details of a specific sender by its unique identifier. func (c *ApiService) FetchChannelsSender(Sid string) (*MessagingV2ChannelsSender, error) { + return c.FetchChannelsSenderWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchChannelsSenderWithContext(ctx context.Context, Sid string) (*MessagingV2ChannelsSender, error) { path := "/v2/Channels/Senders/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -97,7 +107,7 @@ func (c *ApiService) FetchChannelsSender(Sid string) (*MessagingV2ChannelsSender "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -137,6 +147,11 @@ func (params *ListChannelsSenderParams) SetLimit(Limit int) *ListChannelsSenderP // Retrieve a single page of ChannelsSender records from the API. Request is executed immediately. func (c *ApiService) PageChannelsSender(params *ListChannelsSenderParams, pageToken, pageNumber string) (*ListChannelsSenderResponse, error) { + return c.PageChannelsSenderWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of ChannelsSender records from the API. Request is executed immediately. +func (c *ApiService) PageChannelsSenderWithContext(ctx context.Context, params *ListChannelsSenderParams, pageToken, pageNumber string) (*ListChannelsSenderResponse, error) { path := "/v2/Channels/Senders" data := url.Values{} @@ -158,7 +173,7 @@ func (c *ApiService) PageChannelsSender(params *ListChannelsSenderParams, pageTo data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -175,7 +190,12 @@ func (c *ApiService) PageChannelsSender(params *ListChannelsSenderParams, pageTo // Lists ChannelsSender records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListChannelsSender(params *ListChannelsSenderParams) ([]MessagingV2ChannelsSender, error) { - response, errors := c.StreamChannelsSender(params) + return c.ListChannelsSenderWithContext(context.TODO(), params) +} + +// Lists ChannelsSender records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListChannelsSenderWithContext(ctx context.Context, params *ListChannelsSenderParams) ([]MessagingV2ChannelsSender, error) { + response, errors := c.StreamChannelsSenderWithContext(ctx, params) records := make([]MessagingV2ChannelsSender, 0) for record := range response { @@ -191,6 +211,11 @@ func (c *ApiService) ListChannelsSender(params *ListChannelsSenderParams) ([]Mes // Streams ChannelsSender records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamChannelsSender(params *ListChannelsSenderParams) (chan MessagingV2ChannelsSender, chan error) { + return c.StreamChannelsSenderWithContext(context.TODO(), params) +} + +// Streams ChannelsSender records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamChannelsSenderWithContext(ctx context.Context, params *ListChannelsSenderParams) (chan MessagingV2ChannelsSender, chan error) { if params == nil { params = &ListChannelsSenderParams{} } @@ -199,19 +224,19 @@ func (c *ApiService) StreamChannelsSender(params *ListChannelsSenderParams) (cha recordChannel := make(chan MessagingV2ChannelsSender, 1) errorChannel := make(chan error, 1) - response, err := c.PageChannelsSender(params, "", "") + response, err := c.PageChannelsSenderWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamChannelsSender(response, params, recordChannel, errorChannel) + go c.streamChannelsSenderWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamChannelsSender(response *ListChannelsSenderResponse, params *ListChannelsSenderParams, recordChannel chan MessagingV2ChannelsSender, errorChannel chan error) { +func (c *ApiService) streamChannelsSenderWithContext(ctx context.Context, response *ListChannelsSenderResponse, params *ListChannelsSenderParams, recordChannel chan MessagingV2ChannelsSender, errorChannel chan error) { curRecord := 1 for response != nil { @@ -226,7 +251,7 @@ func (c *ApiService) streamChannelsSender(response *ListChannelsSenderResponse, } } - record, err := client.GetNext(c.baseURL, response, c.getNextListChannelsSenderResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListChannelsSenderResponseWithContext) if err != nil { errorChannel <- err break @@ -241,11 +266,11 @@ func (c *ApiService) streamChannelsSender(response *ListChannelsSenderResponse, close(errorChannel) } -func (c *ApiService) getNextListChannelsSenderResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListChannelsSenderResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -272,6 +297,9 @@ func (params *UpdateChannelsSenderParams) SetMessagingV2Update(MessagingV2Update // Update a specific sender information like OTP Code, Webhook, Profile information. func (c *ApiService) UpdateChannelsSender(Sid string, params *UpdateChannelsSenderParams) (*MessagingV2ChannelsSender, error) { + return c.UpdateChannelsSenderWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateChannelsSenderWithContext(ctx context.Context, Sid string, params *UpdateChannelsSenderParams) (*MessagingV2ChannelsSender, error) { path := "/v2/Channels/Senders/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -289,7 +317,7 @@ func (c *ApiService) UpdateChannelsSender(Sid string, params *UpdateChannelsSend body = b } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers, body...) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers, body...) if err != nil { return nil, err } diff --git a/rest/messaging/v2/docs/MessagingV2ChannelsSenderProfileEmails.md b/rest/messaging/v2/docs/MessagingV2ChannelsSenderProfileEmails.md new file mode 100644 index 000000000..3b600b4ac --- /dev/null +++ b/rest/messaging/v2/docs/MessagingV2ChannelsSenderProfileEmails.md @@ -0,0 +1,12 @@ +# MessagingV2ChannelsSenderProfileEmails + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**Email** | Pointer to **string** | The email of the sender. | +**Label** | Pointer to **string** | The label of the sender. | + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/rest/messaging/v2/docs/MessagingV2ChannelsSenderProfileWebsites.md b/rest/messaging/v2/docs/MessagingV2ChannelsSenderProfileWebsites.md new file mode 100644 index 000000000..77dfa884b --- /dev/null +++ b/rest/messaging/v2/docs/MessagingV2ChannelsSenderProfileWebsites.md @@ -0,0 +1,12 @@ +# MessagingV2ChannelsSenderProfileWebsites + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**Label** | Pointer to **string** | The label of the sender. | +**Website** | Pointer to **string** | The website of the sender. | + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/rest/messaging/v2/docs/MessagingV2Profile.md b/rest/messaging/v2/docs/MessagingV2Profile.md index 7e6ef1650..7ccdae953 100644 --- a/rest/messaging/v2/docs/MessagingV2Profile.md +++ b/rest/messaging/v2/docs/MessagingV2Profile.md @@ -8,10 +8,10 @@ Name | Type | Description | Notes **About** | Pointer to **string** | The about text of the sender. | **Address** | Pointer to **string** | The address of the sender. | **Description** | Pointer to **string** | The description of the sender. | -**Emails** | Pointer to **interface{}** | The emails of the sender. | +**Emails** | Pointer to [**[]MessagingV2ChannelsSenderProfileEmails**](MessagingV2ChannelsSenderProfileEmails.md) | The emails of the sender. | **LogoUrl** | Pointer to **string** | The logo URL of the sender. | **Vertical** | Pointer to **string** | The vertical of the sender. Allowed values are: - \"Automotive\" - \"Beauty, Spa and Salon\" - \"Clothing and Apparel\" - \"Education\" - \"Entertainment\" - \"Event Planning and Service\" - \"Finance and Banking\" - \"Food and Grocery\" - \"Public Service\" - \"Hotel and Lodging\" - \"Medical and Health\" - \"Non-profit\" - \"Professional Services\" - \"Shopping and Retail\" - \"Travel and Transportation\" - \"Restaurant\" - \"Other\" | -**Websites** | Pointer to **interface{}** | The websites of the sender. | +**Websites** | Pointer to [**[]MessagingV2ChannelsSenderProfileWebsites**](MessagingV2ChannelsSenderProfileWebsites.md) | The websites of the sender. | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/rest/messaging/v2/model_messaging_v2_channels_sender_profile_emails.go b/rest/messaging/v2/model_messaging_v2_channels_sender_profile_emails.go new file mode 100644 index 000000000..3339ee4c5 --- /dev/null +++ b/rest/messaging/v2/model_messaging_v2_channels_sender_profile_emails.go @@ -0,0 +1,23 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package openapi + +// MessagingV2ChannelsSenderProfileEmails struct for MessagingV2ChannelsSenderProfileEmails +type MessagingV2ChannelsSenderProfileEmails struct { + // The email of the sender. + Email *string `json:"email,omitempty"` + // The label of the sender. + Label *string `json:"label,omitempty"` +} diff --git a/rest/messaging/v2/model_messaging_v2_channels_sender_profile_websites.go b/rest/messaging/v2/model_messaging_v2_channels_sender_profile_websites.go new file mode 100644 index 000000000..0bba6d086 --- /dev/null +++ b/rest/messaging/v2/model_messaging_v2_channels_sender_profile_websites.go @@ -0,0 +1,23 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package openapi + +// MessagingV2ChannelsSenderProfileWebsites struct for MessagingV2ChannelsSenderProfileWebsites +type MessagingV2ChannelsSenderProfileWebsites struct { + // The label of the sender. + Label *string `json:"label,omitempty"` + // The website of the sender. + Website *string `json:"website,omitempty"` +} diff --git a/rest/messaging/v2/model_messaging_v2_profile.go b/rest/messaging/v2/model_messaging_v2_profile.go index 8dde6f92e..3e7f8eac2 100644 --- a/rest/messaging/v2/model_messaging_v2_profile.go +++ b/rest/messaging/v2/model_messaging_v2_profile.go @@ -25,11 +25,11 @@ type MessagingV2Profile struct { // The description of the sender. Description *string `json:"description,omitempty"` // The emails of the sender. - Emails *interface{} `json:"emails,omitempty"` + Emails *[]MessagingV2ChannelsSenderProfileEmails `json:"emails,omitempty"` // The logo URL of the sender. LogoUrl *string `json:"logo_url,omitempty"` // The vertical of the sender. Allowed values are: - \"Automotive\" - \"Beauty, Spa and Salon\" - \"Clothing and Apparel\" - \"Education\" - \"Entertainment\" - \"Event Planning and Service\" - \"Finance and Banking\" - \"Food and Grocery\" - \"Public Service\" - \"Hotel and Lodging\" - \"Medical and Health\" - \"Non-profit\" - \"Professional Services\" - \"Shopping and Retail\" - \"Travel and Transportation\" - \"Restaurant\" - \"Other\" Vertical *string `json:"vertical,omitempty"` // The websites of the sender. - Websites *interface{} `json:"websites,omitempty"` + Websites *[]MessagingV2ChannelsSenderProfileWebsites `json:"websites,omitempty"` } diff --git a/rest/microvisor/v1/api_service.go b/rest/microvisor/v1/api_service.go index b769e9e26..dc0b9f2b5 100644 --- a/rest/microvisor/v1/api_service.go +++ b/rest/microvisor/v1/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://microvisor.twilio.com", + } +} diff --git a/rest/microvisor/v1/apps.go b/rest/microvisor/v1/apps.go index b1a9a7594..5c29c0021 100644 --- a/rest/microvisor/v1/apps.go +++ b/rest/microvisor/v1/apps.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -25,6 +26,9 @@ import ( // Delete a specific App. func (c *ApiService) DeleteApp(Sid string) error { + return c.DeleteAppWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteAppWithContext(ctx context.Context, Sid string) error { path := "/v1/Apps/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -33,7 +37,7 @@ func (c *ApiService) DeleteApp(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -45,6 +49,9 @@ func (c *ApiService) DeleteApp(Sid string) error { // Fetch a specific App. func (c *ApiService) FetchApp(Sid string) (*MicrovisorV1App, error) { + return c.FetchAppWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchAppWithContext(ctx context.Context, Sid string) (*MicrovisorV1App, error) { path := "/v1/Apps/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -53,7 +60,7 @@ func (c *ApiService) FetchApp(Sid string) (*MicrovisorV1App, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -87,6 +94,11 @@ func (params *ListAppParams) SetLimit(Limit int) *ListAppParams { // Retrieve a single page of App records from the API. Request is executed immediately. func (c *ApiService) PageApp(params *ListAppParams, pageToken, pageNumber string) (*ListAppResponse, error) { + return c.PageAppWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of App records from the API. Request is executed immediately. +func (c *ApiService) PageAppWithContext(ctx context.Context, params *ListAppParams, pageToken, pageNumber string) (*ListAppResponse, error) { path := "/v1/Apps" data := url.Values{} @@ -105,7 +117,7 @@ func (c *ApiService) PageApp(params *ListAppParams, pageToken, pageNumber string data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -122,7 +134,12 @@ func (c *ApiService) PageApp(params *ListAppParams, pageToken, pageNumber string // Lists App records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListApp(params *ListAppParams) ([]MicrovisorV1App, error) { - response, errors := c.StreamApp(params) + return c.ListAppWithContext(context.TODO(), params) +} + +// Lists App records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListAppWithContext(ctx context.Context, params *ListAppParams) ([]MicrovisorV1App, error) { + response, errors := c.StreamAppWithContext(ctx, params) records := make([]MicrovisorV1App, 0) for record := range response { @@ -138,6 +155,11 @@ func (c *ApiService) ListApp(params *ListAppParams) ([]MicrovisorV1App, error) { // Streams App records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamApp(params *ListAppParams) (chan MicrovisorV1App, chan error) { + return c.StreamAppWithContext(context.TODO(), params) +} + +// Streams App records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamAppWithContext(ctx context.Context, params *ListAppParams) (chan MicrovisorV1App, chan error) { if params == nil { params = &ListAppParams{} } @@ -146,19 +168,19 @@ func (c *ApiService) StreamApp(params *ListAppParams) (chan MicrovisorV1App, cha recordChannel := make(chan MicrovisorV1App, 1) errorChannel := make(chan error, 1) - response, err := c.PageApp(params, "", "") + response, err := c.PageAppWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamApp(response, params, recordChannel, errorChannel) + go c.streamAppWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamApp(response *ListAppResponse, params *ListAppParams, recordChannel chan MicrovisorV1App, errorChannel chan error) { +func (c *ApiService) streamAppWithContext(ctx context.Context, response *ListAppResponse, params *ListAppParams, recordChannel chan MicrovisorV1App, errorChannel chan error) { curRecord := 1 for response != nil { @@ -173,7 +195,7 @@ func (c *ApiService) streamApp(response *ListAppResponse, params *ListAppParams, } } - record, err := client.GetNext(c.baseURL, response, c.getNextListAppResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListAppResponseWithContext) if err != nil { errorChannel <- err break @@ -188,11 +210,11 @@ func (c *ApiService) streamApp(response *ListAppResponse, params *ListAppParams, close(errorChannel) } -func (c *ApiService) getNextListAppResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListAppResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/microvisor/v1/apps_manifest.go b/rest/microvisor/v1/apps_manifest.go index 141766393..015b4d4ea 100644 --- a/rest/microvisor/v1/apps_manifest.go +++ b/rest/microvisor/v1/apps_manifest.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -22,6 +23,9 @@ import ( // Retrieve the Manifest for an App. func (c *ApiService) FetchAppManifest(AppSid string) (*MicrovisorV1AppManifest, error) { + return c.FetchAppManifestWithContext(context.TODO(), AppSid) +} +func (c *ApiService) FetchAppManifestWithContext(ctx context.Context, AppSid string) (*MicrovisorV1AppManifest, error) { path := "/v1/Apps/{AppSid}/Manifest" path = strings.Replace(path, "{"+"AppSid"+"}", AppSid, -1) @@ -30,7 +34,7 @@ func (c *ApiService) FetchAppManifest(AppSid string) (*MicrovisorV1AppManifest, "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/microvisor/v1/configs.go b/rest/microvisor/v1/configs.go index 5690f138b..a8a1d668b 100644 --- a/rest/microvisor/v1/configs.go +++ b/rest/microvisor/v1/configs.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -42,6 +43,9 @@ func (params *CreateAccountConfigParams) SetValue(Value string) *CreateAccountCo // Create a config for an Account. func (c *ApiService) CreateAccountConfig(params *CreateAccountConfigParams) (*MicrovisorV1AccountConfig, error) { + return c.CreateAccountConfigWithContext(context.TODO(), params) +} +func (c *ApiService) CreateAccountConfigWithContext(ctx context.Context, params *CreateAccountConfigParams) (*MicrovisorV1AccountConfig, error) { path := "/v1/Configs" data := url.Values{} @@ -56,7 +60,7 @@ func (c *ApiService) CreateAccountConfig(params *CreateAccountConfigParams) (*Mi data.Set("Value", *params.Value) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -73,6 +77,9 @@ func (c *ApiService) CreateAccountConfig(params *CreateAccountConfigParams) (*Mi // Delete a config for an Account. func (c *ApiService) DeleteAccountConfig(Key string) error { + return c.DeleteAccountConfigWithContext(context.TODO(), Key) +} +func (c *ApiService) DeleteAccountConfigWithContext(ctx context.Context, Key string) error { path := "/v1/Configs/{Key}" path = strings.Replace(path, "{"+"Key"+"}", Key, -1) @@ -81,7 +88,7 @@ func (c *ApiService) DeleteAccountConfig(Key string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -93,6 +100,9 @@ func (c *ApiService) DeleteAccountConfig(Key string) error { // Retrieve a Config for an Account. func (c *ApiService) FetchAccountConfig(Key string) (*MicrovisorV1AccountConfig, error) { + return c.FetchAccountConfigWithContext(context.TODO(), Key) +} +func (c *ApiService) FetchAccountConfigWithContext(ctx context.Context, Key string) (*MicrovisorV1AccountConfig, error) { path := "/v1/Configs/{Key}" path = strings.Replace(path, "{"+"Key"+"}", Key, -1) @@ -101,7 +111,7 @@ func (c *ApiService) FetchAccountConfig(Key string) (*MicrovisorV1AccountConfig, "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -135,6 +145,11 @@ func (params *ListAccountConfigParams) SetLimit(Limit int) *ListAccountConfigPar // Retrieve a single page of AccountConfig records from the API. Request is executed immediately. func (c *ApiService) PageAccountConfig(params *ListAccountConfigParams, pageToken, pageNumber string) (*ListAccountConfigResponse, error) { + return c.PageAccountConfigWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of AccountConfig records from the API. Request is executed immediately. +func (c *ApiService) PageAccountConfigWithContext(ctx context.Context, params *ListAccountConfigParams, pageToken, pageNumber string) (*ListAccountConfigResponse, error) { path := "/v1/Configs" data := url.Values{} @@ -153,7 +168,7 @@ func (c *ApiService) PageAccountConfig(params *ListAccountConfigParams, pageToke data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -170,7 +185,12 @@ func (c *ApiService) PageAccountConfig(params *ListAccountConfigParams, pageToke // Lists AccountConfig records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListAccountConfig(params *ListAccountConfigParams) ([]MicrovisorV1AccountConfig, error) { - response, errors := c.StreamAccountConfig(params) + return c.ListAccountConfigWithContext(context.TODO(), params) +} + +// Lists AccountConfig records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListAccountConfigWithContext(ctx context.Context, params *ListAccountConfigParams) ([]MicrovisorV1AccountConfig, error) { + response, errors := c.StreamAccountConfigWithContext(ctx, params) records := make([]MicrovisorV1AccountConfig, 0) for record := range response { @@ -186,6 +206,11 @@ func (c *ApiService) ListAccountConfig(params *ListAccountConfigParams) ([]Micro // Streams AccountConfig records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamAccountConfig(params *ListAccountConfigParams) (chan MicrovisorV1AccountConfig, chan error) { + return c.StreamAccountConfigWithContext(context.TODO(), params) +} + +// Streams AccountConfig records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamAccountConfigWithContext(ctx context.Context, params *ListAccountConfigParams) (chan MicrovisorV1AccountConfig, chan error) { if params == nil { params = &ListAccountConfigParams{} } @@ -194,19 +219,19 @@ func (c *ApiService) StreamAccountConfig(params *ListAccountConfigParams) (chan recordChannel := make(chan MicrovisorV1AccountConfig, 1) errorChannel := make(chan error, 1) - response, err := c.PageAccountConfig(params, "", "") + response, err := c.PageAccountConfigWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamAccountConfig(response, params, recordChannel, errorChannel) + go c.streamAccountConfigWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamAccountConfig(response *ListAccountConfigResponse, params *ListAccountConfigParams, recordChannel chan MicrovisorV1AccountConfig, errorChannel chan error) { +func (c *ApiService) streamAccountConfigWithContext(ctx context.Context, response *ListAccountConfigResponse, params *ListAccountConfigParams, recordChannel chan MicrovisorV1AccountConfig, errorChannel chan error) { curRecord := 1 for response != nil { @@ -221,7 +246,7 @@ func (c *ApiService) streamAccountConfig(response *ListAccountConfigResponse, pa } } - record, err := client.GetNext(c.baseURL, response, c.getNextListAccountConfigResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListAccountConfigResponseWithContext) if err != nil { errorChannel <- err break @@ -236,11 +261,11 @@ func (c *ApiService) streamAccountConfig(response *ListAccountConfigResponse, pa close(errorChannel) } -func (c *ApiService) getNextListAccountConfigResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListAccountConfigResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -267,6 +292,9 @@ func (params *UpdateAccountConfigParams) SetValue(Value string) *UpdateAccountCo // Update a config for an Account. func (c *ApiService) UpdateAccountConfig(Key string, params *UpdateAccountConfigParams) (*MicrovisorV1AccountConfig, error) { + return c.UpdateAccountConfigWithContext(context.TODO(), Key, params) +} +func (c *ApiService) UpdateAccountConfigWithContext(ctx context.Context, Key string, params *UpdateAccountConfigParams) (*MicrovisorV1AccountConfig, error) { path := "/v1/Configs/{Key}" path = strings.Replace(path, "{"+"Key"+"}", Key, -1) @@ -279,7 +307,7 @@ func (c *ApiService) UpdateAccountConfig(Key string, params *UpdateAccountConfig data.Set("Value", *params.Value) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/microvisor/v1/devices.go b/rest/microvisor/v1/devices.go index 99499a5d6..b8825e91a 100644 --- a/rest/microvisor/v1/devices.go +++ b/rest/microvisor/v1/devices.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -25,6 +26,9 @@ import ( // Fetch a specific Device. func (c *ApiService) FetchDevice(Sid string) (*MicrovisorV1Device, error) { + return c.FetchDeviceWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchDeviceWithContext(ctx context.Context, Sid string) (*MicrovisorV1Device, error) { path := "/v1/Devices/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -33,7 +37,7 @@ func (c *ApiService) FetchDevice(Sid string) (*MicrovisorV1Device, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -67,6 +71,11 @@ func (params *ListDeviceParams) SetLimit(Limit int) *ListDeviceParams { // Retrieve a single page of Device records from the API. Request is executed immediately. func (c *ApiService) PageDevice(params *ListDeviceParams, pageToken, pageNumber string) (*ListDeviceResponse, error) { + return c.PageDeviceWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Device records from the API. Request is executed immediately. +func (c *ApiService) PageDeviceWithContext(ctx context.Context, params *ListDeviceParams, pageToken, pageNumber string) (*ListDeviceResponse, error) { path := "/v1/Devices" data := url.Values{} @@ -85,7 +94,7 @@ func (c *ApiService) PageDevice(params *ListDeviceParams, pageToken, pageNumber data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -102,7 +111,12 @@ func (c *ApiService) PageDevice(params *ListDeviceParams, pageToken, pageNumber // Lists Device records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListDevice(params *ListDeviceParams) ([]MicrovisorV1Device, error) { - response, errors := c.StreamDevice(params) + return c.ListDeviceWithContext(context.TODO(), params) +} + +// Lists Device records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListDeviceWithContext(ctx context.Context, params *ListDeviceParams) ([]MicrovisorV1Device, error) { + response, errors := c.StreamDeviceWithContext(ctx, params) records := make([]MicrovisorV1Device, 0) for record := range response { @@ -118,6 +132,11 @@ func (c *ApiService) ListDevice(params *ListDeviceParams) ([]MicrovisorV1Device, // Streams Device records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamDevice(params *ListDeviceParams) (chan MicrovisorV1Device, chan error) { + return c.StreamDeviceWithContext(context.TODO(), params) +} + +// Streams Device records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamDeviceWithContext(ctx context.Context, params *ListDeviceParams) (chan MicrovisorV1Device, chan error) { if params == nil { params = &ListDeviceParams{} } @@ -126,19 +145,19 @@ func (c *ApiService) StreamDevice(params *ListDeviceParams) (chan MicrovisorV1De recordChannel := make(chan MicrovisorV1Device, 1) errorChannel := make(chan error, 1) - response, err := c.PageDevice(params, "", "") + response, err := c.PageDeviceWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamDevice(response, params, recordChannel, errorChannel) + go c.streamDeviceWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamDevice(response *ListDeviceResponse, params *ListDeviceParams, recordChannel chan MicrovisorV1Device, errorChannel chan error) { +func (c *ApiService) streamDeviceWithContext(ctx context.Context, response *ListDeviceResponse, params *ListDeviceParams, recordChannel chan MicrovisorV1Device, errorChannel chan error) { curRecord := 1 for response != nil { @@ -153,7 +172,7 @@ func (c *ApiService) streamDevice(response *ListDeviceResponse, params *ListDevi } } - record, err := client.GetNext(c.baseURL, response, c.getNextListDeviceResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListDeviceResponseWithContext) if err != nil { errorChannel <- err break @@ -168,11 +187,11 @@ func (c *ApiService) streamDevice(response *ListDeviceResponse, params *ListDevi close(errorChannel) } -func (c *ApiService) getNextListDeviceResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListDeviceResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -217,6 +236,9 @@ func (params *UpdateDeviceParams) SetRestartApp(RestartApp bool) *UpdateDevicePa // Update a specific Device. func (c *ApiService) UpdateDevice(Sid string, params *UpdateDeviceParams) (*MicrovisorV1Device, error) { + return c.UpdateDeviceWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateDeviceWithContext(ctx context.Context, Sid string, params *UpdateDeviceParams) (*MicrovisorV1Device, error) { path := "/v1/Devices/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -238,7 +260,7 @@ func (c *ApiService) UpdateDevice(Sid string, params *UpdateDeviceParams) (*Micr data.Set("RestartApp", fmt.Sprint(*params.RestartApp)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/microvisor/v1/devices_configs.go b/rest/microvisor/v1/devices_configs.go index 46dd40e0d..aad8709e0 100644 --- a/rest/microvisor/v1/devices_configs.go +++ b/rest/microvisor/v1/devices_configs.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -42,6 +43,9 @@ func (params *CreateDeviceConfigParams) SetValue(Value string) *CreateDeviceConf // Create a config for a Microvisor Device. func (c *ApiService) CreateDeviceConfig(DeviceSid string, params *CreateDeviceConfigParams) (*MicrovisorV1DeviceConfig, error) { + return c.CreateDeviceConfigWithContext(context.TODO(), DeviceSid, params) +} +func (c *ApiService) CreateDeviceConfigWithContext(ctx context.Context, DeviceSid string, params *CreateDeviceConfigParams) (*MicrovisorV1DeviceConfig, error) { path := "/v1/Devices/{DeviceSid}/Configs" path = strings.Replace(path, "{"+"DeviceSid"+"}", DeviceSid, -1) @@ -57,7 +61,7 @@ func (c *ApiService) CreateDeviceConfig(DeviceSid string, params *CreateDeviceCo data.Set("Value", *params.Value) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -74,6 +78,9 @@ func (c *ApiService) CreateDeviceConfig(DeviceSid string, params *CreateDeviceCo // Delete a config for a Microvisor Device. func (c *ApiService) DeleteDeviceConfig(DeviceSid string, Key string) error { + return c.DeleteDeviceConfigWithContext(context.TODO(), DeviceSid, Key) +} +func (c *ApiService) DeleteDeviceConfigWithContext(ctx context.Context, DeviceSid string, Key string) error { path := "/v1/Devices/{DeviceSid}/Configs/{Key}" path = strings.Replace(path, "{"+"DeviceSid"+"}", DeviceSid, -1) path = strings.Replace(path, "{"+"Key"+"}", Key, -1) @@ -83,7 +90,7 @@ func (c *ApiService) DeleteDeviceConfig(DeviceSid string, Key string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -95,6 +102,9 @@ func (c *ApiService) DeleteDeviceConfig(DeviceSid string, Key string) error { // Retrieve a Config for a Device. func (c *ApiService) FetchDeviceConfig(DeviceSid string, Key string) (*MicrovisorV1DeviceConfig, error) { + return c.FetchDeviceConfigWithContext(context.TODO(), DeviceSid, Key) +} +func (c *ApiService) FetchDeviceConfigWithContext(ctx context.Context, DeviceSid string, Key string) (*MicrovisorV1DeviceConfig, error) { path := "/v1/Devices/{DeviceSid}/Configs/{Key}" path = strings.Replace(path, "{"+"DeviceSid"+"}", DeviceSid, -1) path = strings.Replace(path, "{"+"Key"+"}", Key, -1) @@ -104,7 +114,7 @@ func (c *ApiService) FetchDeviceConfig(DeviceSid string, Key string) (*Microviso "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -138,6 +148,11 @@ func (params *ListDeviceConfigParams) SetLimit(Limit int) *ListDeviceConfigParam // Retrieve a single page of DeviceConfig records from the API. Request is executed immediately. func (c *ApiService) PageDeviceConfig(DeviceSid string, params *ListDeviceConfigParams, pageToken, pageNumber string) (*ListDeviceConfigResponse, error) { + return c.PageDeviceConfigWithContext(context.TODO(), DeviceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of DeviceConfig records from the API. Request is executed immediately. +func (c *ApiService) PageDeviceConfigWithContext(ctx context.Context, DeviceSid string, params *ListDeviceConfigParams, pageToken, pageNumber string) (*ListDeviceConfigResponse, error) { path := "/v1/Devices/{DeviceSid}/Configs" path = strings.Replace(path, "{"+"DeviceSid"+"}", DeviceSid, -1) @@ -158,7 +173,7 @@ func (c *ApiService) PageDeviceConfig(DeviceSid string, params *ListDeviceConfig data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -175,7 +190,12 @@ func (c *ApiService) PageDeviceConfig(DeviceSid string, params *ListDeviceConfig // Lists DeviceConfig records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListDeviceConfig(DeviceSid string, params *ListDeviceConfigParams) ([]MicrovisorV1DeviceConfig, error) { - response, errors := c.StreamDeviceConfig(DeviceSid, params) + return c.ListDeviceConfigWithContext(context.TODO(), DeviceSid, params) +} + +// Lists DeviceConfig records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListDeviceConfigWithContext(ctx context.Context, DeviceSid string, params *ListDeviceConfigParams) ([]MicrovisorV1DeviceConfig, error) { + response, errors := c.StreamDeviceConfigWithContext(ctx, DeviceSid, params) records := make([]MicrovisorV1DeviceConfig, 0) for record := range response { @@ -191,6 +211,11 @@ func (c *ApiService) ListDeviceConfig(DeviceSid string, params *ListDeviceConfig // Streams DeviceConfig records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamDeviceConfig(DeviceSid string, params *ListDeviceConfigParams) (chan MicrovisorV1DeviceConfig, chan error) { + return c.StreamDeviceConfigWithContext(context.TODO(), DeviceSid, params) +} + +// Streams DeviceConfig records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamDeviceConfigWithContext(ctx context.Context, DeviceSid string, params *ListDeviceConfigParams) (chan MicrovisorV1DeviceConfig, chan error) { if params == nil { params = &ListDeviceConfigParams{} } @@ -199,19 +224,19 @@ func (c *ApiService) StreamDeviceConfig(DeviceSid string, params *ListDeviceConf recordChannel := make(chan MicrovisorV1DeviceConfig, 1) errorChannel := make(chan error, 1) - response, err := c.PageDeviceConfig(DeviceSid, params, "", "") + response, err := c.PageDeviceConfigWithContext(ctx, DeviceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamDeviceConfig(response, params, recordChannel, errorChannel) + go c.streamDeviceConfigWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamDeviceConfig(response *ListDeviceConfigResponse, params *ListDeviceConfigParams, recordChannel chan MicrovisorV1DeviceConfig, errorChannel chan error) { +func (c *ApiService) streamDeviceConfigWithContext(ctx context.Context, response *ListDeviceConfigResponse, params *ListDeviceConfigParams, recordChannel chan MicrovisorV1DeviceConfig, errorChannel chan error) { curRecord := 1 for response != nil { @@ -226,7 +251,7 @@ func (c *ApiService) streamDeviceConfig(response *ListDeviceConfigResponse, para } } - record, err := client.GetNext(c.baseURL, response, c.getNextListDeviceConfigResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListDeviceConfigResponseWithContext) if err != nil { errorChannel <- err break @@ -241,11 +266,11 @@ func (c *ApiService) streamDeviceConfig(response *ListDeviceConfigResponse, para close(errorChannel) } -func (c *ApiService) getNextListDeviceConfigResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListDeviceConfigResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -272,6 +297,9 @@ func (params *UpdateDeviceConfigParams) SetValue(Value string) *UpdateDeviceConf // Update a config for a Microvisor Device. func (c *ApiService) UpdateDeviceConfig(DeviceSid string, Key string, params *UpdateDeviceConfigParams) (*MicrovisorV1DeviceConfig, error) { + return c.UpdateDeviceConfigWithContext(context.TODO(), DeviceSid, Key, params) +} +func (c *ApiService) UpdateDeviceConfigWithContext(ctx context.Context, DeviceSid string, Key string, params *UpdateDeviceConfigParams) (*MicrovisorV1DeviceConfig, error) { path := "/v1/Devices/{DeviceSid}/Configs/{Key}" path = strings.Replace(path, "{"+"DeviceSid"+"}", DeviceSid, -1) path = strings.Replace(path, "{"+"Key"+"}", Key, -1) @@ -285,7 +313,7 @@ func (c *ApiService) UpdateDeviceConfig(DeviceSid string, Key string, params *Up data.Set("Value", *params.Value) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/microvisor/v1/devices_secrets.go b/rest/microvisor/v1/devices_secrets.go index 9558333f7..526252a97 100644 --- a/rest/microvisor/v1/devices_secrets.go +++ b/rest/microvisor/v1/devices_secrets.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -42,6 +43,9 @@ func (params *CreateDeviceSecretParams) SetValue(Value string) *CreateDeviceSecr // Create a secret for a Microvisor Device. func (c *ApiService) CreateDeviceSecret(DeviceSid string, params *CreateDeviceSecretParams) (*MicrovisorV1DeviceSecret, error) { + return c.CreateDeviceSecretWithContext(context.TODO(), DeviceSid, params) +} +func (c *ApiService) CreateDeviceSecretWithContext(ctx context.Context, DeviceSid string, params *CreateDeviceSecretParams) (*MicrovisorV1DeviceSecret, error) { path := "/v1/Devices/{DeviceSid}/Secrets" path = strings.Replace(path, "{"+"DeviceSid"+"}", DeviceSid, -1) @@ -57,7 +61,7 @@ func (c *ApiService) CreateDeviceSecret(DeviceSid string, params *CreateDeviceSe data.Set("Value", *params.Value) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -74,6 +78,9 @@ func (c *ApiService) CreateDeviceSecret(DeviceSid string, params *CreateDeviceSe // Delete a secret for a Microvisor Device. func (c *ApiService) DeleteDeviceSecret(DeviceSid string, Key string) error { + return c.DeleteDeviceSecretWithContext(context.TODO(), DeviceSid, Key) +} +func (c *ApiService) DeleteDeviceSecretWithContext(ctx context.Context, DeviceSid string, Key string) error { path := "/v1/Devices/{DeviceSid}/Secrets/{Key}" path = strings.Replace(path, "{"+"DeviceSid"+"}", DeviceSid, -1) path = strings.Replace(path, "{"+"Key"+"}", Key, -1) @@ -83,7 +90,7 @@ func (c *ApiService) DeleteDeviceSecret(DeviceSid string, Key string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -95,6 +102,9 @@ func (c *ApiService) DeleteDeviceSecret(DeviceSid string, Key string) error { // Retrieve a Secret for a Device. func (c *ApiService) FetchDeviceSecret(DeviceSid string, Key string) (*MicrovisorV1DeviceSecret, error) { + return c.FetchDeviceSecretWithContext(context.TODO(), DeviceSid, Key) +} +func (c *ApiService) FetchDeviceSecretWithContext(ctx context.Context, DeviceSid string, Key string) (*MicrovisorV1DeviceSecret, error) { path := "/v1/Devices/{DeviceSid}/Secrets/{Key}" path = strings.Replace(path, "{"+"DeviceSid"+"}", DeviceSid, -1) path = strings.Replace(path, "{"+"Key"+"}", Key, -1) @@ -104,7 +114,7 @@ func (c *ApiService) FetchDeviceSecret(DeviceSid string, Key string) (*Microviso "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -138,6 +148,11 @@ func (params *ListDeviceSecretParams) SetLimit(Limit int) *ListDeviceSecretParam // Retrieve a single page of DeviceSecret records from the API. Request is executed immediately. func (c *ApiService) PageDeviceSecret(DeviceSid string, params *ListDeviceSecretParams, pageToken, pageNumber string) (*ListDeviceSecretResponse, error) { + return c.PageDeviceSecretWithContext(context.TODO(), DeviceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of DeviceSecret records from the API. Request is executed immediately. +func (c *ApiService) PageDeviceSecretWithContext(ctx context.Context, DeviceSid string, params *ListDeviceSecretParams, pageToken, pageNumber string) (*ListDeviceSecretResponse, error) { path := "/v1/Devices/{DeviceSid}/Secrets" path = strings.Replace(path, "{"+"DeviceSid"+"}", DeviceSid, -1) @@ -158,7 +173,7 @@ func (c *ApiService) PageDeviceSecret(DeviceSid string, params *ListDeviceSecret data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -175,7 +190,12 @@ func (c *ApiService) PageDeviceSecret(DeviceSid string, params *ListDeviceSecret // Lists DeviceSecret records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListDeviceSecret(DeviceSid string, params *ListDeviceSecretParams) ([]MicrovisorV1DeviceSecret, error) { - response, errors := c.StreamDeviceSecret(DeviceSid, params) + return c.ListDeviceSecretWithContext(context.TODO(), DeviceSid, params) +} + +// Lists DeviceSecret records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListDeviceSecretWithContext(ctx context.Context, DeviceSid string, params *ListDeviceSecretParams) ([]MicrovisorV1DeviceSecret, error) { + response, errors := c.StreamDeviceSecretWithContext(ctx, DeviceSid, params) records := make([]MicrovisorV1DeviceSecret, 0) for record := range response { @@ -191,6 +211,11 @@ func (c *ApiService) ListDeviceSecret(DeviceSid string, params *ListDeviceSecret // Streams DeviceSecret records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamDeviceSecret(DeviceSid string, params *ListDeviceSecretParams) (chan MicrovisorV1DeviceSecret, chan error) { + return c.StreamDeviceSecretWithContext(context.TODO(), DeviceSid, params) +} + +// Streams DeviceSecret records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamDeviceSecretWithContext(ctx context.Context, DeviceSid string, params *ListDeviceSecretParams) (chan MicrovisorV1DeviceSecret, chan error) { if params == nil { params = &ListDeviceSecretParams{} } @@ -199,19 +224,19 @@ func (c *ApiService) StreamDeviceSecret(DeviceSid string, params *ListDeviceSecr recordChannel := make(chan MicrovisorV1DeviceSecret, 1) errorChannel := make(chan error, 1) - response, err := c.PageDeviceSecret(DeviceSid, params, "", "") + response, err := c.PageDeviceSecretWithContext(ctx, DeviceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamDeviceSecret(response, params, recordChannel, errorChannel) + go c.streamDeviceSecretWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamDeviceSecret(response *ListDeviceSecretResponse, params *ListDeviceSecretParams, recordChannel chan MicrovisorV1DeviceSecret, errorChannel chan error) { +func (c *ApiService) streamDeviceSecretWithContext(ctx context.Context, response *ListDeviceSecretResponse, params *ListDeviceSecretParams, recordChannel chan MicrovisorV1DeviceSecret, errorChannel chan error) { curRecord := 1 for response != nil { @@ -226,7 +251,7 @@ func (c *ApiService) streamDeviceSecret(response *ListDeviceSecretResponse, para } } - record, err := client.GetNext(c.baseURL, response, c.getNextListDeviceSecretResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListDeviceSecretResponseWithContext) if err != nil { errorChannel <- err break @@ -241,11 +266,11 @@ func (c *ApiService) streamDeviceSecret(response *ListDeviceSecretResponse, para close(errorChannel) } -func (c *ApiService) getNextListDeviceSecretResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListDeviceSecretResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -272,6 +297,9 @@ func (params *UpdateDeviceSecretParams) SetValue(Value string) *UpdateDeviceSecr // Update a secret for a Microvisor Device. func (c *ApiService) UpdateDeviceSecret(DeviceSid string, Key string, params *UpdateDeviceSecretParams) (*MicrovisorV1DeviceSecret, error) { + return c.UpdateDeviceSecretWithContext(context.TODO(), DeviceSid, Key, params) +} +func (c *ApiService) UpdateDeviceSecretWithContext(ctx context.Context, DeviceSid string, Key string, params *UpdateDeviceSecretParams) (*MicrovisorV1DeviceSecret, error) { path := "/v1/Devices/{DeviceSid}/Secrets/{Key}" path = strings.Replace(path, "{"+"DeviceSid"+"}", DeviceSid, -1) path = strings.Replace(path, "{"+"Key"+"}", Key, -1) @@ -285,7 +313,7 @@ func (c *ApiService) UpdateDeviceSecret(DeviceSid string, Key string, params *Up data.Set("Value", *params.Value) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/microvisor/v1/secrets.go b/rest/microvisor/v1/secrets.go index 39a5f8064..dd2ff72ae 100644 --- a/rest/microvisor/v1/secrets.go +++ b/rest/microvisor/v1/secrets.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -42,6 +43,9 @@ func (params *CreateAccountSecretParams) SetValue(Value string) *CreateAccountSe // Create a secret for an Account. func (c *ApiService) CreateAccountSecret(params *CreateAccountSecretParams) (*MicrovisorV1AccountSecret, error) { + return c.CreateAccountSecretWithContext(context.TODO(), params) +} +func (c *ApiService) CreateAccountSecretWithContext(ctx context.Context, params *CreateAccountSecretParams) (*MicrovisorV1AccountSecret, error) { path := "/v1/Secrets" data := url.Values{} @@ -56,7 +60,7 @@ func (c *ApiService) CreateAccountSecret(params *CreateAccountSecretParams) (*Mi data.Set("Value", *params.Value) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -73,6 +77,9 @@ func (c *ApiService) CreateAccountSecret(params *CreateAccountSecretParams) (*Mi // Delete a secret for an Account. func (c *ApiService) DeleteAccountSecret(Key string) error { + return c.DeleteAccountSecretWithContext(context.TODO(), Key) +} +func (c *ApiService) DeleteAccountSecretWithContext(ctx context.Context, Key string) error { path := "/v1/Secrets/{Key}" path = strings.Replace(path, "{"+"Key"+"}", Key, -1) @@ -81,7 +88,7 @@ func (c *ApiService) DeleteAccountSecret(Key string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -93,6 +100,9 @@ func (c *ApiService) DeleteAccountSecret(Key string) error { // Retrieve a Secret for an Account. func (c *ApiService) FetchAccountSecret(Key string) (*MicrovisorV1AccountSecret, error) { + return c.FetchAccountSecretWithContext(context.TODO(), Key) +} +func (c *ApiService) FetchAccountSecretWithContext(ctx context.Context, Key string) (*MicrovisorV1AccountSecret, error) { path := "/v1/Secrets/{Key}" path = strings.Replace(path, "{"+"Key"+"}", Key, -1) @@ -101,7 +111,7 @@ func (c *ApiService) FetchAccountSecret(Key string) (*MicrovisorV1AccountSecret, "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -135,6 +145,11 @@ func (params *ListAccountSecretParams) SetLimit(Limit int) *ListAccountSecretPar // Retrieve a single page of AccountSecret records from the API. Request is executed immediately. func (c *ApiService) PageAccountSecret(params *ListAccountSecretParams, pageToken, pageNumber string) (*ListAccountSecretResponse, error) { + return c.PageAccountSecretWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of AccountSecret records from the API. Request is executed immediately. +func (c *ApiService) PageAccountSecretWithContext(ctx context.Context, params *ListAccountSecretParams, pageToken, pageNumber string) (*ListAccountSecretResponse, error) { path := "/v1/Secrets" data := url.Values{} @@ -153,7 +168,7 @@ func (c *ApiService) PageAccountSecret(params *ListAccountSecretParams, pageToke data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -170,7 +185,12 @@ func (c *ApiService) PageAccountSecret(params *ListAccountSecretParams, pageToke // Lists AccountSecret records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListAccountSecret(params *ListAccountSecretParams) ([]MicrovisorV1AccountSecret, error) { - response, errors := c.StreamAccountSecret(params) + return c.ListAccountSecretWithContext(context.TODO(), params) +} + +// Lists AccountSecret records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListAccountSecretWithContext(ctx context.Context, params *ListAccountSecretParams) ([]MicrovisorV1AccountSecret, error) { + response, errors := c.StreamAccountSecretWithContext(ctx, params) records := make([]MicrovisorV1AccountSecret, 0) for record := range response { @@ -186,6 +206,11 @@ func (c *ApiService) ListAccountSecret(params *ListAccountSecretParams) ([]Micro // Streams AccountSecret records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamAccountSecret(params *ListAccountSecretParams) (chan MicrovisorV1AccountSecret, chan error) { + return c.StreamAccountSecretWithContext(context.TODO(), params) +} + +// Streams AccountSecret records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamAccountSecretWithContext(ctx context.Context, params *ListAccountSecretParams) (chan MicrovisorV1AccountSecret, chan error) { if params == nil { params = &ListAccountSecretParams{} } @@ -194,19 +219,19 @@ func (c *ApiService) StreamAccountSecret(params *ListAccountSecretParams) (chan recordChannel := make(chan MicrovisorV1AccountSecret, 1) errorChannel := make(chan error, 1) - response, err := c.PageAccountSecret(params, "", "") + response, err := c.PageAccountSecretWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamAccountSecret(response, params, recordChannel, errorChannel) + go c.streamAccountSecretWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamAccountSecret(response *ListAccountSecretResponse, params *ListAccountSecretParams, recordChannel chan MicrovisorV1AccountSecret, errorChannel chan error) { +func (c *ApiService) streamAccountSecretWithContext(ctx context.Context, response *ListAccountSecretResponse, params *ListAccountSecretParams, recordChannel chan MicrovisorV1AccountSecret, errorChannel chan error) { curRecord := 1 for response != nil { @@ -221,7 +246,7 @@ func (c *ApiService) streamAccountSecret(response *ListAccountSecretResponse, pa } } - record, err := client.GetNext(c.baseURL, response, c.getNextListAccountSecretResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListAccountSecretResponseWithContext) if err != nil { errorChannel <- err break @@ -236,11 +261,11 @@ func (c *ApiService) streamAccountSecret(response *ListAccountSecretResponse, pa close(errorChannel) } -func (c *ApiService) getNextListAccountSecretResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListAccountSecretResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -267,6 +292,9 @@ func (params *UpdateAccountSecretParams) SetValue(Value string) *UpdateAccountSe // Update a secret for an Account. func (c *ApiService) UpdateAccountSecret(Key string, params *UpdateAccountSecretParams) (*MicrovisorV1AccountSecret, error) { + return c.UpdateAccountSecretWithContext(context.TODO(), Key, params) +} +func (c *ApiService) UpdateAccountSecretWithContext(ctx context.Context, Key string, params *UpdateAccountSecretParams) (*MicrovisorV1AccountSecret, error) { path := "/v1/Secrets/{Key}" path = strings.Replace(path, "{"+"Key"+"}", Key, -1) @@ -279,7 +307,7 @@ func (c *ApiService) UpdateAccountSecret(Key string, params *UpdateAccountSecret data.Set("Value", *params.Value) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/monitor/v1/alerts.go b/rest/monitor/v1/alerts.go index 6421e3004..ab056cd1e 100644 --- a/rest/monitor/v1/alerts.go +++ b/rest/monitor/v1/alerts.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -24,8 +25,10 @@ import ( "github.com/twilio/twilio-go/client" ) -// func (c *ApiService) FetchAlert(Sid string) (*MonitorV1AlertInstance, error) { + return c.FetchAlertWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchAlertWithContext(ctx context.Context, Sid string) (*MonitorV1AlertInstance, error) { path := "/v1/Alerts/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -34,7 +37,7 @@ func (c *ApiService) FetchAlert(Sid string) (*MonitorV1AlertInstance, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -86,6 +89,11 @@ func (params *ListAlertParams) SetLimit(Limit int) *ListAlertParams { // Retrieve a single page of Alert records from the API. Request is executed immediately. func (c *ApiService) PageAlert(params *ListAlertParams, pageToken, pageNumber string) (*ListAlertResponse, error) { + return c.PageAlertWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Alert records from the API. Request is executed immediately. +func (c *ApiService) PageAlertWithContext(ctx context.Context, params *ListAlertParams, pageToken, pageNumber string) (*ListAlertResponse, error) { path := "/v1/Alerts" data := url.Values{} @@ -113,7 +121,7 @@ func (c *ApiService) PageAlert(params *ListAlertParams, pageToken, pageNumber st data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -130,7 +138,12 @@ func (c *ApiService) PageAlert(params *ListAlertParams, pageToken, pageNumber st // Lists Alert records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListAlert(params *ListAlertParams) ([]MonitorV1Alert, error) { - response, errors := c.StreamAlert(params) + return c.ListAlertWithContext(context.TODO(), params) +} + +// Lists Alert records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListAlertWithContext(ctx context.Context, params *ListAlertParams) ([]MonitorV1Alert, error) { + response, errors := c.StreamAlertWithContext(ctx, params) records := make([]MonitorV1Alert, 0) for record := range response { @@ -146,6 +159,11 @@ func (c *ApiService) ListAlert(params *ListAlertParams) ([]MonitorV1Alert, error // Streams Alert records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamAlert(params *ListAlertParams) (chan MonitorV1Alert, chan error) { + return c.StreamAlertWithContext(context.TODO(), params) +} + +// Streams Alert records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamAlertWithContext(ctx context.Context, params *ListAlertParams) (chan MonitorV1Alert, chan error) { if params == nil { params = &ListAlertParams{} } @@ -154,19 +172,19 @@ func (c *ApiService) StreamAlert(params *ListAlertParams) (chan MonitorV1Alert, recordChannel := make(chan MonitorV1Alert, 1) errorChannel := make(chan error, 1) - response, err := c.PageAlert(params, "", "") + response, err := c.PageAlertWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamAlert(response, params, recordChannel, errorChannel) + go c.streamAlertWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamAlert(response *ListAlertResponse, params *ListAlertParams, recordChannel chan MonitorV1Alert, errorChannel chan error) { +func (c *ApiService) streamAlertWithContext(ctx context.Context, response *ListAlertResponse, params *ListAlertParams, recordChannel chan MonitorV1Alert, errorChannel chan error) { curRecord := 1 for response != nil { @@ -181,7 +199,7 @@ func (c *ApiService) streamAlert(response *ListAlertResponse, params *ListAlertP } } - record, err := client.GetNext(c.baseURL, response, c.getNextListAlertResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListAlertResponseWithContext) if err != nil { errorChannel <- err break @@ -196,11 +214,11 @@ func (c *ApiService) streamAlert(response *ListAlertResponse, params *ListAlertP close(errorChannel) } -func (c *ApiService) getNextListAlertResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListAlertResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/monitor/v1/api_service.go b/rest/monitor/v1/api_service.go index 1f56b1fdf..8c343d992 100644 --- a/rest/monitor/v1/api_service.go +++ b/rest/monitor/v1/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://monitor.twilio.com", + } +} diff --git a/rest/monitor/v1/events.go b/rest/monitor/v1/events.go index 7c778aa07..ae4bb1c62 100644 --- a/rest/monitor/v1/events.go +++ b/rest/monitor/v1/events.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -24,8 +25,10 @@ import ( "github.com/twilio/twilio-go/client" ) -// func (c *ApiService) FetchEvent(Sid string) (*MonitorV1Event, error) { + return c.FetchEventWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchEventWithContext(ctx context.Context, Sid string) (*MonitorV1Event, error) { path := "/v1/Events/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -34,7 +37,7 @@ func (c *ApiService) FetchEvent(Sid string) (*MonitorV1Event, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -104,6 +107,11 @@ func (params *ListEventParams) SetLimit(Limit int) *ListEventParams { // Retrieve a single page of Event records from the API. Request is executed immediately. func (c *ApiService) PageEvent(params *ListEventParams, pageToken, pageNumber string) (*ListEventResponse, error) { + return c.PageEventWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Event records from the API. Request is executed immediately. +func (c *ApiService) PageEventWithContext(ctx context.Context, params *ListEventParams, pageToken, pageNumber string) (*ListEventResponse, error) { path := "/v1/Events" data := url.Values{} @@ -140,7 +148,7 @@ func (c *ApiService) PageEvent(params *ListEventParams, pageToken, pageNumber st data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -157,7 +165,12 @@ func (c *ApiService) PageEvent(params *ListEventParams, pageToken, pageNumber st // Lists Event records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListEvent(params *ListEventParams) ([]MonitorV1Event, error) { - response, errors := c.StreamEvent(params) + return c.ListEventWithContext(context.TODO(), params) +} + +// Lists Event records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListEventWithContext(ctx context.Context, params *ListEventParams) ([]MonitorV1Event, error) { + response, errors := c.StreamEventWithContext(ctx, params) records := make([]MonitorV1Event, 0) for record := range response { @@ -173,6 +186,11 @@ func (c *ApiService) ListEvent(params *ListEventParams) ([]MonitorV1Event, error // Streams Event records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamEvent(params *ListEventParams) (chan MonitorV1Event, chan error) { + return c.StreamEventWithContext(context.TODO(), params) +} + +// Streams Event records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamEventWithContext(ctx context.Context, params *ListEventParams) (chan MonitorV1Event, chan error) { if params == nil { params = &ListEventParams{} } @@ -181,19 +199,19 @@ func (c *ApiService) StreamEvent(params *ListEventParams) (chan MonitorV1Event, recordChannel := make(chan MonitorV1Event, 1) errorChannel := make(chan error, 1) - response, err := c.PageEvent(params, "", "") + response, err := c.PageEventWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamEvent(response, params, recordChannel, errorChannel) + go c.streamEventWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamEvent(response *ListEventResponse, params *ListEventParams, recordChannel chan MonitorV1Event, errorChannel chan error) { +func (c *ApiService) streamEventWithContext(ctx context.Context, response *ListEventResponse, params *ListEventParams, recordChannel chan MonitorV1Event, errorChannel chan error) { curRecord := 1 for response != nil { @@ -208,7 +226,7 @@ func (c *ApiService) streamEvent(response *ListEventResponse, params *ListEventP } } - record, err := client.GetNext(c.baseURL, response, c.getNextListEventResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListEventResponseWithContext) if err != nil { errorChannel <- err break @@ -223,11 +241,11 @@ func (c *ApiService) streamEvent(response *ListEventResponse, params *ListEventP close(errorChannel) } -func (c *ApiService) getNextListEventResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListEventResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/notify/v1/api_service.go b/rest/notify/v1/api_service.go index 3145d6fc5..b50c0f80f 100644 --- a/rest/notify/v1/api_service.go +++ b/rest/notify/v1/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://notify.twilio.com", + } +} diff --git a/rest/notify/v1/credentials.go b/rest/notify/v1/credentials.go index be7f79ca2..80ea74bd6 100644 --- a/rest/notify/v1/credentials.go +++ b/rest/notify/v1/credentials.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -70,8 +71,10 @@ func (params *CreateCredentialParams) SetSecret(Secret string) *CreateCredential return params } -// func (c *ApiService) CreateCredential(params *CreateCredentialParams) (*NotifyV1Credential, error) { + return c.CreateCredentialWithContext(context.TODO(), params) +} +func (c *ApiService) CreateCredentialWithContext(ctx context.Context, params *CreateCredentialParams) (*NotifyV1Credential, error) { path := "/v1/Credentials" data := url.Values{} @@ -101,7 +104,7 @@ func (c *ApiService) CreateCredential(params *CreateCredentialParams) (*NotifyV1 data.Set("Secret", *params.Secret) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -116,8 +119,10 @@ func (c *ApiService) CreateCredential(params *CreateCredentialParams) (*NotifyV1 return ps, err } -// func (c *ApiService) DeleteCredential(Sid string) error { + return c.DeleteCredentialWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteCredentialWithContext(ctx context.Context, Sid string) error { path := "/v1/Credentials/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -126,7 +131,7 @@ func (c *ApiService) DeleteCredential(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -136,8 +141,10 @@ func (c *ApiService) DeleteCredential(Sid string) error { return nil } -// func (c *ApiService) FetchCredential(Sid string) (*NotifyV1Credential, error) { + return c.FetchCredentialWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchCredentialWithContext(ctx context.Context, Sid string) (*NotifyV1Credential, error) { path := "/v1/Credentials/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -146,7 +153,7 @@ func (c *ApiService) FetchCredential(Sid string) (*NotifyV1Credential, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -180,6 +187,11 @@ func (params *ListCredentialParams) SetLimit(Limit int) *ListCredentialParams { // Retrieve a single page of Credential records from the API. Request is executed immediately. func (c *ApiService) PageCredential(params *ListCredentialParams, pageToken, pageNumber string) (*ListCredentialResponse, error) { + return c.PageCredentialWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Credential records from the API. Request is executed immediately. +func (c *ApiService) PageCredentialWithContext(ctx context.Context, params *ListCredentialParams, pageToken, pageNumber string) (*ListCredentialResponse, error) { path := "/v1/Credentials" data := url.Values{} @@ -198,7 +210,7 @@ func (c *ApiService) PageCredential(params *ListCredentialParams, pageToken, pag data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -215,7 +227,12 @@ func (c *ApiService) PageCredential(params *ListCredentialParams, pageToken, pag // Lists Credential records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListCredential(params *ListCredentialParams) ([]NotifyV1Credential, error) { - response, errors := c.StreamCredential(params) + return c.ListCredentialWithContext(context.TODO(), params) +} + +// Lists Credential records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListCredentialWithContext(ctx context.Context, params *ListCredentialParams) ([]NotifyV1Credential, error) { + response, errors := c.StreamCredentialWithContext(ctx, params) records := make([]NotifyV1Credential, 0) for record := range response { @@ -231,6 +248,11 @@ func (c *ApiService) ListCredential(params *ListCredentialParams) ([]NotifyV1Cre // Streams Credential records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamCredential(params *ListCredentialParams) (chan NotifyV1Credential, chan error) { + return c.StreamCredentialWithContext(context.TODO(), params) +} + +// Streams Credential records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamCredentialWithContext(ctx context.Context, params *ListCredentialParams) (chan NotifyV1Credential, chan error) { if params == nil { params = &ListCredentialParams{} } @@ -239,19 +261,19 @@ func (c *ApiService) StreamCredential(params *ListCredentialParams) (chan Notify recordChannel := make(chan NotifyV1Credential, 1) errorChannel := make(chan error, 1) - response, err := c.PageCredential(params, "", "") + response, err := c.PageCredentialWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamCredential(response, params, recordChannel, errorChannel) + go c.streamCredentialWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamCredential(response *ListCredentialResponse, params *ListCredentialParams, recordChannel chan NotifyV1Credential, errorChannel chan error) { +func (c *ApiService) streamCredentialWithContext(ctx context.Context, response *ListCredentialResponse, params *ListCredentialParams, recordChannel chan NotifyV1Credential, errorChannel chan error) { curRecord := 1 for response != nil { @@ -266,7 +288,7 @@ func (c *ApiService) streamCredential(response *ListCredentialResponse, params * } } - record, err := client.GetNext(c.baseURL, response, c.getNextListCredentialResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListCredentialResponseWithContext) if err != nil { errorChannel <- err break @@ -281,11 +303,11 @@ func (c *ApiService) streamCredential(response *ListCredentialResponse, params * close(errorChannel) } -func (c *ApiService) getNextListCredentialResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListCredentialResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -340,8 +362,10 @@ func (params *UpdateCredentialParams) SetSecret(Secret string) *UpdateCredential return params } -// func (c *ApiService) UpdateCredential(Sid string, params *UpdateCredentialParams) (*NotifyV1Credential, error) { + return c.UpdateCredentialWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateCredentialWithContext(ctx context.Context, Sid string, params *UpdateCredentialParams) (*NotifyV1Credential, error) { path := "/v1/Credentials/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -369,7 +393,7 @@ func (c *ApiService) UpdateCredential(Sid string, params *UpdateCredentialParams data.Set("Secret", *params.Secret) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/notify/v1/services.go b/rest/notify/v1/services.go index ea47b0e2e..ed394f008 100644 --- a/rest/notify/v1/services.go +++ b/rest/notify/v1/services.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -112,8 +113,10 @@ func (params *CreateServiceParams) SetDeliveryCallbackEnabled(DeliveryCallbackEn return params } -// func (c *ApiService) CreateService(params *CreateServiceParams) (*NotifyV1Service, error) { + return c.CreateServiceWithContext(context.TODO(), params) +} +func (c *ApiService) CreateServiceWithContext(ctx context.Context, params *CreateServiceParams) (*NotifyV1Service, error) { path := "/v1/Services" data := url.Values{} @@ -164,7 +167,7 @@ func (c *ApiService) CreateService(params *CreateServiceParams) (*NotifyV1Servic data.Set("DeliveryCallbackEnabled", fmt.Sprint(*params.DeliveryCallbackEnabled)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -179,8 +182,10 @@ func (c *ApiService) CreateService(params *CreateServiceParams) (*NotifyV1Servic return ps, err } -// func (c *ApiService) DeleteService(Sid string) error { + return c.DeleteServiceWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteServiceWithContext(ctx context.Context, Sid string) error { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -189,7 +194,7 @@ func (c *ApiService) DeleteService(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -199,8 +204,10 @@ func (c *ApiService) DeleteService(Sid string) error { return nil } -// func (c *ApiService) FetchService(Sid string) (*NotifyV1Service, error) { + return c.FetchServiceWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchServiceWithContext(ctx context.Context, Sid string) (*NotifyV1Service, error) { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -209,7 +216,7 @@ func (c *ApiService) FetchService(Sid string) (*NotifyV1Service, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -249,6 +256,11 @@ func (params *ListServiceParams) SetLimit(Limit int) *ListServiceParams { // Retrieve a single page of Service records from the API. Request is executed immediately. func (c *ApiService) PageService(params *ListServiceParams, pageToken, pageNumber string) (*ListServiceResponse, error) { + return c.PageServiceWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Service records from the API. Request is executed immediately. +func (c *ApiService) PageServiceWithContext(ctx context.Context, params *ListServiceParams, pageToken, pageNumber string) (*ListServiceResponse, error) { path := "/v1/Services" data := url.Values{} @@ -270,7 +282,7 @@ func (c *ApiService) PageService(params *ListServiceParams, pageToken, pageNumbe data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -287,7 +299,12 @@ func (c *ApiService) PageService(params *ListServiceParams, pageToken, pageNumbe // Lists Service records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListService(params *ListServiceParams) ([]NotifyV1Service, error) { - response, errors := c.StreamService(params) + return c.ListServiceWithContext(context.TODO(), params) +} + +// Lists Service records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListServiceWithContext(ctx context.Context, params *ListServiceParams) ([]NotifyV1Service, error) { + response, errors := c.StreamServiceWithContext(ctx, params) records := make([]NotifyV1Service, 0) for record := range response { @@ -303,6 +320,11 @@ func (c *ApiService) ListService(params *ListServiceParams) ([]NotifyV1Service, // Streams Service records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamService(params *ListServiceParams) (chan NotifyV1Service, chan error) { + return c.StreamServiceWithContext(context.TODO(), params) +} + +// Streams Service records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamServiceWithContext(ctx context.Context, params *ListServiceParams) (chan NotifyV1Service, chan error) { if params == nil { params = &ListServiceParams{} } @@ -311,19 +333,19 @@ func (c *ApiService) StreamService(params *ListServiceParams) (chan NotifyV1Serv recordChannel := make(chan NotifyV1Service, 1) errorChannel := make(chan error, 1) - response, err := c.PageService(params, "", "") + response, err := c.PageServiceWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamService(response, params, recordChannel, errorChannel) + go c.streamServiceWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamService(response *ListServiceResponse, params *ListServiceParams, recordChannel chan NotifyV1Service, errorChannel chan error) { +func (c *ApiService) streamServiceWithContext(ctx context.Context, response *ListServiceResponse, params *ListServiceParams, recordChannel chan NotifyV1Service, errorChannel chan error) { curRecord := 1 for response != nil { @@ -338,7 +360,7 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListServiceResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListServiceResponseWithContext) if err != nil { errorChannel <- err break @@ -353,11 +375,11 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe close(errorChannel) } -func (c *ApiService) getNextListServiceResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListServiceResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -460,8 +482,10 @@ func (params *UpdateServiceParams) SetDeliveryCallbackEnabled(DeliveryCallbackEn return params } -// func (c *ApiService) UpdateService(Sid string, params *UpdateServiceParams) (*NotifyV1Service, error) { + return c.UpdateServiceWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateServiceWithContext(ctx context.Context, Sid string, params *UpdateServiceParams) (*NotifyV1Service, error) { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -513,7 +537,7 @@ func (c *ApiService) UpdateService(Sid string, params *UpdateServiceParams) (*No data.Set("DeliveryCallbackEnabled", fmt.Sprint(*params.DeliveryCallbackEnabled)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/notify/v1/services_bindings.go b/rest/notify/v1/services_bindings.go index 4d6652302..3a28ed8a8 100644 --- a/rest/notify/v1/services_bindings.go +++ b/rest/notify/v1/services_bindings.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -70,8 +71,10 @@ func (params *CreateBindingParams) SetEndpoint(Endpoint string) *CreateBindingPa return params } -// func (c *ApiService) CreateBinding(ServiceSid string, params *CreateBindingParams) (*NotifyV1Binding, error) { + return c.CreateBindingWithContext(context.TODO(), ServiceSid, params) +} +func (c *ApiService) CreateBindingWithContext(ctx context.Context, ServiceSid string, params *CreateBindingParams) (*NotifyV1Binding, error) { path := "/v1/Services/{ServiceSid}/Bindings" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -104,7 +107,7 @@ func (c *ApiService) CreateBinding(ServiceSid string, params *CreateBindingParam data.Set("Endpoint", *params.Endpoint) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -119,8 +122,10 @@ func (c *ApiService) CreateBinding(ServiceSid string, params *CreateBindingParam return ps, err } -// func (c *ApiService) DeleteBinding(ServiceSid string, Sid string) error { + return c.DeleteBindingWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) DeleteBindingWithContext(ctx context.Context, ServiceSid string, Sid string) error { path := "/v1/Services/{ServiceSid}/Bindings/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -130,7 +135,7 @@ func (c *ApiService) DeleteBinding(ServiceSid string, Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -140,8 +145,10 @@ func (c *ApiService) DeleteBinding(ServiceSid string, Sid string) error { return nil } -// func (c *ApiService) FetchBinding(ServiceSid string, Sid string) (*NotifyV1Binding, error) { + return c.FetchBindingWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) FetchBindingWithContext(ctx context.Context, ServiceSid string, Sid string) (*NotifyV1Binding, error) { path := "/v1/Services/{ServiceSid}/Bindings/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -151,7 +158,7 @@ func (c *ApiService) FetchBinding(ServiceSid string, Sid string) (*NotifyV1Bindi "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -209,6 +216,11 @@ func (params *ListBindingParams) SetLimit(Limit int) *ListBindingParams { // Retrieve a single page of Binding records from the API. Request is executed immediately. func (c *ApiService) PageBinding(ServiceSid string, params *ListBindingParams, pageToken, pageNumber string) (*ListBindingResponse, error) { + return c.PageBindingWithContext(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Binding records from the API. Request is executed immediately. +func (c *ApiService) PageBindingWithContext(ctx context.Context, ServiceSid string, params *ListBindingParams, pageToken, pageNumber string) (*ListBindingResponse, error) { path := "/v1/Services/{ServiceSid}/Bindings" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -245,7 +257,7 @@ func (c *ApiService) PageBinding(ServiceSid string, params *ListBindingParams, p data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -262,7 +274,12 @@ func (c *ApiService) PageBinding(ServiceSid string, params *ListBindingParams, p // Lists Binding records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListBinding(ServiceSid string, params *ListBindingParams) ([]NotifyV1Binding, error) { - response, errors := c.StreamBinding(ServiceSid, params) + return c.ListBindingWithContext(context.TODO(), ServiceSid, params) +} + +// Lists Binding records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListBindingWithContext(ctx context.Context, ServiceSid string, params *ListBindingParams) ([]NotifyV1Binding, error) { + response, errors := c.StreamBindingWithContext(ctx, ServiceSid, params) records := make([]NotifyV1Binding, 0) for record := range response { @@ -278,6 +295,11 @@ func (c *ApiService) ListBinding(ServiceSid string, params *ListBindingParams) ( // Streams Binding records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamBinding(ServiceSid string, params *ListBindingParams) (chan NotifyV1Binding, chan error) { + return c.StreamBindingWithContext(context.TODO(), ServiceSid, params) +} + +// Streams Binding records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamBindingWithContext(ctx context.Context, ServiceSid string, params *ListBindingParams) (chan NotifyV1Binding, chan error) { if params == nil { params = &ListBindingParams{} } @@ -286,19 +308,19 @@ func (c *ApiService) StreamBinding(ServiceSid string, params *ListBindingParams) recordChannel := make(chan NotifyV1Binding, 1) errorChannel := make(chan error, 1) - response, err := c.PageBinding(ServiceSid, params, "", "") + response, err := c.PageBindingWithContext(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamBinding(response, params, recordChannel, errorChannel) + go c.streamBindingWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamBinding(response *ListBindingResponse, params *ListBindingParams, recordChannel chan NotifyV1Binding, errorChannel chan error) { +func (c *ApiService) streamBindingWithContext(ctx context.Context, response *ListBindingResponse, params *ListBindingParams, recordChannel chan NotifyV1Binding, errorChannel chan error) { curRecord := 1 for response != nil { @@ -313,7 +335,7 @@ func (c *ApiService) streamBinding(response *ListBindingResponse, params *ListBi } } - record, err := client.GetNext(c.baseURL, response, c.getNextListBindingResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListBindingResponseWithContext) if err != nil { errorChannel <- err break @@ -328,11 +350,11 @@ func (c *ApiService) streamBinding(response *ListBindingResponse, params *ListBi close(errorChannel) } -func (c *ApiService) getNextListBindingResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListBindingResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/notify/v1/services_notifications.go b/rest/notify/v1/services_notifications.go index f843012a2..746f032d1 100644 --- a/rest/notify/v1/services_notifications.go +++ b/rest/notify/v1/services_notifications.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -134,8 +135,10 @@ func (params *CreateNotificationParams) SetTag(Tag []string) *CreateNotification return params } -// func (c *ApiService) CreateNotification(ServiceSid string, params *CreateNotificationParams) (*NotifyV1Notification, error) { + return c.CreateNotificationWithContext(context.TODO(), ServiceSid, params) +} +func (c *ApiService) CreateNotificationWithContext(ctx context.Context, ServiceSid string, params *CreateNotificationParams) (*NotifyV1Notification, error) { path := "/v1/Services/{ServiceSid}/Notifications" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -249,7 +252,7 @@ func (c *ApiService) CreateNotification(ServiceSid string, params *CreateNotific } } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/numbers/v1/api_service.go b/rest/numbers/v1/api_service.go index ab3fa279e..5dfccd6f4 100644 --- a/rest/numbers/v1/api_service.go +++ b/rest/numbers/v1/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://numbers.twilio.com", + } +} diff --git a/rest/numbers/v1/docs/NumbersV1PortingPortIn.md b/rest/numbers/v1/docs/NumbersV1PortingPortIn.md index 95f8f3044..d277652e1 100644 --- a/rest/numbers/v1/docs/NumbersV1PortingPortIn.md +++ b/rest/numbers/v1/docs/NumbersV1PortingPortIn.md @@ -8,9 +8,9 @@ Name | Type | Description | Notes **Url** | Pointer to **string** | The URL of this Port In request | **AccountSid** | Pointer to **string** | Account Sid or subaccount where the phone number(s) will be Ported | **NotificationEmails** | Pointer to **[]string** | Additional emails to send a copy of the signed LOA to. | -**TargetPortInDate** | Pointer to **string** | Target date to port the number. We cannot guarantee that this date will be honored by the other carriers, please work with Ops to get a confirmation of the firm order commitment (FOC) date. Expected format is ISO Local Date, example: ‘2011-12-03`. This date must be at least 7 days in the future for US ports and 10 days in the future for Japanese ports. We can't guarantee the exact date and time, as this depends on the losing carrier | -**TargetPortInTimeRangeStart** | Pointer to **string** | The earliest time that the port should occur on the target port in date. Expected format is ISO Offset Time, example: ‘10:15:00-08:00'. We can't guarantee the exact date and time, as this depends on the losing carrier | -**TargetPortInTimeRangeEnd** | Pointer to **string** | The latest time that the port should occur on the target port in date. Expected format is ISO Offset Time, example: ‘10:15:00-08:00'. We can't guarantee the exact date and time, as this depends on the losing carrier | +**TargetPortInDate** | Pointer to **string** | Target date to port the number. We cannot guarantee that this date will be honored by the other carriers, please work with Ops to get a confirmation of the firm order commitment (FOC) date. Expected format is ISO Local Date, example: ‘2011-12-03`. This date must be at least 7 days in the future for US ports and 10 days in the future for Japanese ports. (This value is only available for custom porting customers.) | +**TargetPortInTimeRangeStart** | Pointer to **string** | The earliest time that the port should occur on the target port in date. Expected format is ISO Offset Time, example: ‘10:15:00-08:00'. (This value is only available for custom porting customers.) | +**TargetPortInTimeRangeEnd** | Pointer to **string** | The latest time that the port should occur on the target port in date. Expected format is ISO Offset Time, example: ‘10:15:00-08:00'. (This value is only available for custom porting customers.) | **PortInRequestStatus** | Pointer to **string** | The status of the port in request. The possible values are: In progress, Completed, Expired, In review, Waiting for Signature, Action Required, and Canceled. | **LosingCarrierInformation** | Pointer to **map[string]interface{}** | Details regarding the customer’s information with the losing carrier. These values will be used to generate the letter of authorization and should match the losing carrier’s data as closely as possible to ensure the port is accepted. | **PhoneNumbers** | Pointer to **[]map[string]interface{}** | | diff --git a/rest/numbers/v1/hosted_number_eligibility.go b/rest/numbers/v1/hosted_number_eligibility.go index 98a13f849..77c697889 100644 --- a/rest/numbers/v1/hosted_number_eligibility.go +++ b/rest/numbers/v1/hosted_number_eligibility.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" ) @@ -32,6 +33,9 @@ func (params *CreateEligibilityParams) SetBody(Body map[string]interface{}) *Cre // Create an eligibility check for a number that you want to host in Twilio. func (c *ApiService) CreateEligibility(params *CreateEligibilityParams) (*NumbersV1Eligibility, error) { + return c.CreateEligibilityWithContext(context.TODO(), params) +} +func (c *ApiService) CreateEligibilityWithContext(ctx context.Context, params *CreateEligibilityParams) (*NumbersV1Eligibility, error) { path := "/v1/HostedNumber/Eligibility" data := url.Values{} @@ -48,7 +52,7 @@ func (c *ApiService) CreateEligibility(params *CreateEligibilityParams) (*Number body = b } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers, body...) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers, body...) if err != nil { return nil, err } diff --git a/rest/numbers/v1/hosted_number_eligibility_bulk.go b/rest/numbers/v1/hosted_number_eligibility_bulk.go index 80a3dcab4..9f7b420da 100644 --- a/rest/numbers/v1/hosted_number_eligibility_bulk.go +++ b/rest/numbers/v1/hosted_number_eligibility_bulk.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -33,6 +34,9 @@ func (params *CreateBulkEligibilityParams) SetBody(Body map[string]interface{}) // Create a bulk eligibility check for a set of numbers that you want to host in Twilio. func (c *ApiService) CreateBulkEligibility(params *CreateBulkEligibilityParams) (*NumbersV1BulkEligibility, error) { + return c.CreateBulkEligibilityWithContext(context.TODO(), params) +} +func (c *ApiService) CreateBulkEligibilityWithContext(ctx context.Context, params *CreateBulkEligibilityParams) (*NumbersV1BulkEligibility, error) { path := "/v1/HostedNumber/Eligibility/Bulk" data := url.Values{} @@ -49,7 +53,7 @@ func (c *ApiService) CreateBulkEligibility(params *CreateBulkEligibilityParams) body = b } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers, body...) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers, body...) if err != nil { return nil, err } @@ -66,6 +70,9 @@ func (c *ApiService) CreateBulkEligibility(params *CreateBulkEligibilityParams) // Fetch an eligibility bulk check that you requested to host in Twilio. func (c *ApiService) FetchBulkEligibility(RequestId string) (*NumbersV1BulkEligibility, error) { + return c.FetchBulkEligibilityWithContext(context.TODO(), RequestId) +} +func (c *ApiService) FetchBulkEligibilityWithContext(ctx context.Context, RequestId string) (*NumbersV1BulkEligibility, error) { path := "/v1/HostedNumber/Eligibility/Bulk/{RequestId}" path = strings.Replace(path, "{"+"RequestId"+"}", RequestId, -1) @@ -74,7 +81,7 @@ func (c *ApiService) FetchBulkEligibility(RequestId string) (*NumbersV1BulkEligi "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/numbers/v1/model_numbers_v1_porting_port_in.go b/rest/numbers/v1/model_numbers_v1_porting_port_in.go index 39529fd3b..9935e8620 100644 --- a/rest/numbers/v1/model_numbers_v1_porting_port_in.go +++ b/rest/numbers/v1/model_numbers_v1_porting_port_in.go @@ -28,11 +28,11 @@ type NumbersV1PortingPortIn struct { AccountSid *string `json:"account_sid,omitempty"` // Additional emails to send a copy of the signed LOA to. NotificationEmails *[]string `json:"notification_emails,omitempty"` - // Target date to port the number. We cannot guarantee that this date will be honored by the other carriers, please work with Ops to get a confirmation of the firm order commitment (FOC) date. Expected format is ISO Local Date, example: ‘2011-12-03`. This date must be at least 7 days in the future for US ports and 10 days in the future for Japanese ports. We can't guarantee the exact date and time, as this depends on the losing carrier + // Target date to port the number. We cannot guarantee that this date will be honored by the other carriers, please work with Ops to get a confirmation of the firm order commitment (FOC) date. Expected format is ISO Local Date, example: ‘2011-12-03`. This date must be at least 7 days in the future for US ports and 10 days in the future for Japanese ports. (This value is only available for custom porting customers.) TargetPortInDate *string `json:"target_port_in_date,omitempty"` - // The earliest time that the port should occur on the target port in date. Expected format is ISO Offset Time, example: ‘10:15:00-08:00'. We can't guarantee the exact date and time, as this depends on the losing carrier + // The earliest time that the port should occur on the target port in date. Expected format is ISO Offset Time, example: ‘10:15:00-08:00'. (This value is only available for custom porting customers.) TargetPortInTimeRangeStart *string `json:"target_port_in_time_range_start,omitempty"` - // The latest time that the port should occur on the target port in date. Expected format is ISO Offset Time, example: ‘10:15:00-08:00'. We can't guarantee the exact date and time, as this depends on the losing carrier + // The latest time that the port should occur on the target port in date. Expected format is ISO Offset Time, example: ‘10:15:00-08:00'. (This value is only available for custom porting customers.) TargetPortInTimeRangeEnd *string `json:"target_port_in_time_range_end,omitempty"` // The status of the port in request. The possible values are: In progress, Completed, Expired, In review, Waiting for Signature, Action Required, and Canceled. PortInRequestStatus *string `json:"port_in_request_status,omitempty"` diff --git a/rest/numbers/v1/porting_configuration_webhook.go b/rest/numbers/v1/porting_configuration_webhook.go index 3fea09d91..207158a49 100644 --- a/rest/numbers/v1/porting_configuration_webhook.go +++ b/rest/numbers/v1/porting_configuration_webhook.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -34,6 +35,9 @@ func (params *CreatePortingWebhookConfigurationParams) SetBody(Body map[string]i // Create a Webhook Configuration func (c *ApiService) CreatePortingWebhookConfiguration(params *CreatePortingWebhookConfigurationParams) (*NumbersV1PortingWebhookConfiguration, error) { + return c.CreatePortingWebhookConfigurationWithContext(context.TODO(), params) +} +func (c *ApiService) CreatePortingWebhookConfigurationWithContext(ctx context.Context, params *CreatePortingWebhookConfigurationParams) (*NumbersV1PortingWebhookConfiguration, error) { path := "/v1/Porting/Configuration/Webhook" data := url.Values{} @@ -50,7 +54,7 @@ func (c *ApiService) CreatePortingWebhookConfiguration(params *CreatePortingWebh body = b } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers, body...) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers, body...) if err != nil { return nil, err } @@ -67,6 +71,9 @@ func (c *ApiService) CreatePortingWebhookConfiguration(params *CreatePortingWebh // Allows the client to delete a webhook configuration. func (c *ApiService) DeletePortingWebhookConfigurationDelete(WebhookType string) error { + return c.DeletePortingWebhookConfigurationDeleteWithContext(context.TODO(), WebhookType) +} +func (c *ApiService) DeletePortingWebhookConfigurationDeleteWithContext(ctx context.Context, WebhookType string) error { path := "/v1/Porting/Configuration/Webhook/{WebhookType}" path = strings.Replace(path, "{"+"WebhookType"+"}", fmt.Sprint(WebhookType), -1) @@ -75,7 +82,7 @@ func (c *ApiService) DeletePortingWebhookConfigurationDelete(WebhookType string) "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -87,6 +94,9 @@ func (c *ApiService) DeletePortingWebhookConfigurationDelete(WebhookType string) // Allows to fetch the webhook configuration func (c *ApiService) FetchPortingWebhookConfigurationFetch() (*NumbersV1PortingWebhookConfigurationFetch, error) { + return c.FetchPortingWebhookConfigurationFetchWithContext(context.TODO()) +} +func (c *ApiService) FetchPortingWebhookConfigurationFetchWithContext(ctx context.Context) (*NumbersV1PortingWebhookConfigurationFetch, error) { path := "/v1/Porting/Configuration/Webhook" data := url.Values{} @@ -94,7 +104,7 @@ func (c *ApiService) FetchPortingWebhookConfigurationFetch() (*NumbersV1PortingW "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/numbers/v1/porting_port_in.go b/rest/numbers/v1/porting_port_in.go index 7b026458a..c8f614c62 100644 --- a/rest/numbers/v1/porting_port_in.go +++ b/rest/numbers/v1/porting_port_in.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -33,6 +34,9 @@ func (params *CreatePortingPortInParams) SetBody(Body map[string]interface{}) *C // Allows to create a new port in request func (c *ApiService) CreatePortingPortIn(params *CreatePortingPortInParams) (*NumbersV1PortingPortIn, error) { + return c.CreatePortingPortInWithContext(context.TODO(), params) +} +func (c *ApiService) CreatePortingPortInWithContext(ctx context.Context, params *CreatePortingPortInParams) (*NumbersV1PortingPortIn, error) { path := "/v1/Porting/PortIn" data := url.Values{} @@ -49,7 +53,7 @@ func (c *ApiService) CreatePortingPortIn(params *CreatePortingPortInParams) (*Nu body = b } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers, body...) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers, body...) if err != nil { return nil, err } @@ -66,6 +70,9 @@ func (c *ApiService) CreatePortingPortIn(params *CreatePortingPortInParams) (*Nu // Allows to cancel a port in request by SID func (c *ApiService) DeletePortingPortIn(PortInRequestSid string) error { + return c.DeletePortingPortInWithContext(context.TODO(), PortInRequestSid) +} +func (c *ApiService) DeletePortingPortInWithContext(ctx context.Context, PortInRequestSid string) error { path := "/v1/Porting/PortIn/{PortInRequestSid}" path = strings.Replace(path, "{"+"PortInRequestSid"+"}", PortInRequestSid, -1) @@ -74,7 +81,7 @@ func (c *ApiService) DeletePortingPortIn(PortInRequestSid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -86,6 +93,9 @@ func (c *ApiService) DeletePortingPortIn(PortInRequestSid string) error { // Fetch a port in request by SID func (c *ApiService) FetchPortingPortIn(PortInRequestSid string) (*NumbersV1PortingPortIn, error) { + return c.FetchPortingPortInWithContext(context.TODO(), PortInRequestSid) +} +func (c *ApiService) FetchPortingPortInWithContext(ctx context.Context, PortInRequestSid string) (*NumbersV1PortingPortIn, error) { path := "/v1/Porting/PortIn/{PortInRequestSid}" path = strings.Replace(path, "{"+"PortInRequestSid"+"}", PortInRequestSid, -1) @@ -94,7 +104,7 @@ func (c *ApiService) FetchPortingPortIn(PortInRequestSid string) (*NumbersV1Port "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/numbers/v1/porting_port_in_phone_number.go b/rest/numbers/v1/porting_port_in_phone_number.go index 6e7b2f633..c1d44ef1b 100644 --- a/rest/numbers/v1/porting_port_in_phone_number.go +++ b/rest/numbers/v1/porting_port_in_phone_number.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -22,6 +23,9 @@ import ( // Allows to cancel a port in request phone number by SID func (c *ApiService) DeletePortingPortInPhoneNumber(PortInRequestSid string, PhoneNumberSid string) error { + return c.DeletePortingPortInPhoneNumberWithContext(context.TODO(), PortInRequestSid, PhoneNumberSid) +} +func (c *ApiService) DeletePortingPortInPhoneNumberWithContext(ctx context.Context, PortInRequestSid string, PhoneNumberSid string) error { path := "/v1/Porting/PortIn/{PortInRequestSid}/PhoneNumber/{PhoneNumberSid}" path = strings.Replace(path, "{"+"PortInRequestSid"+"}", PortInRequestSid, -1) path = strings.Replace(path, "{"+"PhoneNumberSid"+"}", PhoneNumberSid, -1) @@ -31,7 +35,7 @@ func (c *ApiService) DeletePortingPortInPhoneNumber(PortInRequestSid string, Pho "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -43,6 +47,9 @@ func (c *ApiService) DeletePortingPortInPhoneNumber(PortInRequestSid string, Pho // Fetch a phone number by port in request SID and phone number SID func (c *ApiService) FetchPortingPortInPhoneNumber(PortInRequestSid string, PhoneNumberSid string) (*NumbersV1PortingPortInPhoneNumber, error) { + return c.FetchPortingPortInPhoneNumberWithContext(context.TODO(), PortInRequestSid, PhoneNumberSid) +} +func (c *ApiService) FetchPortingPortInPhoneNumberWithContext(ctx context.Context, PortInRequestSid string, PhoneNumberSid string) (*NumbersV1PortingPortInPhoneNumber, error) { path := "/v1/Porting/PortIn/{PortInRequestSid}/PhoneNumber/{PhoneNumberSid}" path = strings.Replace(path, "{"+"PortInRequestSid"+"}", PortInRequestSid, -1) path = strings.Replace(path, "{"+"PhoneNumberSid"+"}", PhoneNumberSid, -1) @@ -52,7 +59,7 @@ func (c *ApiService) FetchPortingPortInPhoneNumber(PortInRequestSid string, Phon "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/numbers/v1/porting_portability_phone_number.go b/rest/numbers/v1/porting_portability_phone_number.go index 3d549986a..47e0036c3 100644 --- a/rest/numbers/v1/porting_portability_phone_number.go +++ b/rest/numbers/v1/porting_portability_phone_number.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -39,6 +40,9 @@ func (params *FetchPortingPortabilityParams) SetAddressSid(AddressSid string) *F // Check if a single phone number can be ported to Twilio func (c *ApiService) FetchPortingPortability(PhoneNumber string, params *FetchPortingPortabilityParams) (*NumbersV1PortingPortability, error) { + return c.FetchPortingPortabilityWithContext(context.TODO(), PhoneNumber, params) +} +func (c *ApiService) FetchPortingPortabilityWithContext(ctx context.Context, PhoneNumber string, params *FetchPortingPortabilityParams) (*NumbersV1PortingPortability, error) { path := "/v1/Porting/Portability/PhoneNumber/{PhoneNumber}" path = strings.Replace(path, "{"+"PhoneNumber"+"}", PhoneNumber, -1) @@ -54,7 +58,7 @@ func (c *ApiService) FetchPortingPortability(PhoneNumber string, params *FetchPo data.Set("AddressSid", *params.AddressSid) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/numbers/v1/signing_request_configuration.go b/rest/numbers/v1/signing_request_configuration.go index bc1530b29..5a130f834 100644 --- a/rest/numbers/v1/signing_request_configuration.go +++ b/rest/numbers/v1/signing_request_configuration.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -35,6 +36,9 @@ func (params *CreateSigningRequestConfigurationParams) SetBody(Body map[string]i // Synchronous operation to insert or update a configuration for the customer. func (c *ApiService) CreateSigningRequestConfiguration(params *CreateSigningRequestConfigurationParams) (*NumbersV1SigningRequestConfiguration, error) { + return c.CreateSigningRequestConfigurationWithContext(context.TODO(), params) +} +func (c *ApiService) CreateSigningRequestConfigurationWithContext(ctx context.Context, params *CreateSigningRequestConfigurationParams) (*NumbersV1SigningRequestConfiguration, error) { path := "/v1/SigningRequest/Configuration" data := url.Values{} @@ -51,7 +55,7 @@ func (c *ApiService) CreateSigningRequestConfiguration(params *CreateSigningRequ body = b } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers, body...) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers, body...) if err != nil { return nil, err } @@ -97,6 +101,11 @@ func (params *ListSigningRequestConfigurationParams) SetLimit(Limit int) *ListSi // Retrieve a single page of SigningRequestConfiguration records from the API. Request is executed immediately. func (c *ApiService) PageSigningRequestConfiguration(params *ListSigningRequestConfigurationParams, pageToken, pageNumber string) (*ListSigningRequestConfigurationResponse, error) { + return c.PageSigningRequestConfigurationWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of SigningRequestConfiguration records from the API. Request is executed immediately. +func (c *ApiService) PageSigningRequestConfigurationWithContext(ctx context.Context, params *ListSigningRequestConfigurationParams, pageToken, pageNumber string) (*ListSigningRequestConfigurationResponse, error) { path := "/v1/SigningRequest/Configuration" data := url.Values{} @@ -121,7 +130,7 @@ func (c *ApiService) PageSigningRequestConfiguration(params *ListSigningRequestC data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -138,7 +147,12 @@ func (c *ApiService) PageSigningRequestConfiguration(params *ListSigningRequestC // Lists SigningRequestConfiguration records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListSigningRequestConfiguration(params *ListSigningRequestConfigurationParams) ([]NumbersV1SigningRequestConfiguration, error) { - response, errors := c.StreamSigningRequestConfiguration(params) + return c.ListSigningRequestConfigurationWithContext(context.TODO(), params) +} + +// Lists SigningRequestConfiguration records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListSigningRequestConfigurationWithContext(ctx context.Context, params *ListSigningRequestConfigurationParams) ([]NumbersV1SigningRequestConfiguration, error) { + response, errors := c.StreamSigningRequestConfigurationWithContext(ctx, params) records := make([]NumbersV1SigningRequestConfiguration, 0) for record := range response { @@ -154,6 +168,11 @@ func (c *ApiService) ListSigningRequestConfiguration(params *ListSigningRequestC // Streams SigningRequestConfiguration records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamSigningRequestConfiguration(params *ListSigningRequestConfigurationParams) (chan NumbersV1SigningRequestConfiguration, chan error) { + return c.StreamSigningRequestConfigurationWithContext(context.TODO(), params) +} + +// Streams SigningRequestConfiguration records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamSigningRequestConfigurationWithContext(ctx context.Context, params *ListSigningRequestConfigurationParams) (chan NumbersV1SigningRequestConfiguration, chan error) { if params == nil { params = &ListSigningRequestConfigurationParams{} } @@ -162,19 +181,19 @@ func (c *ApiService) StreamSigningRequestConfiguration(params *ListSigningReques recordChannel := make(chan NumbersV1SigningRequestConfiguration, 1) errorChannel := make(chan error, 1) - response, err := c.PageSigningRequestConfiguration(params, "", "") + response, err := c.PageSigningRequestConfigurationWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSigningRequestConfiguration(response, params, recordChannel, errorChannel) + go c.streamSigningRequestConfigurationWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamSigningRequestConfiguration(response *ListSigningRequestConfigurationResponse, params *ListSigningRequestConfigurationParams, recordChannel chan NumbersV1SigningRequestConfiguration, errorChannel chan error) { +func (c *ApiService) streamSigningRequestConfigurationWithContext(ctx context.Context, response *ListSigningRequestConfigurationResponse, params *ListSigningRequestConfigurationParams, recordChannel chan NumbersV1SigningRequestConfiguration, errorChannel chan error) { curRecord := 1 for response != nil { @@ -189,7 +208,7 @@ func (c *ApiService) streamSigningRequestConfiguration(response *ListSigningRequ } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSigningRequestConfigurationResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListSigningRequestConfigurationResponseWithContext) if err != nil { errorChannel <- err break @@ -204,11 +223,11 @@ func (c *ApiService) streamSigningRequestConfiguration(response *ListSigningRequ close(errorChannel) } -func (c *ApiService) getNextListSigningRequestConfigurationResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSigningRequestConfigurationResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/numbers/v2/api_service.go b/rest/numbers/v2/api_service.go index ab3fa279e..5dfccd6f4 100644 --- a/rest/numbers/v2/api_service.go +++ b/rest/numbers/v2/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://numbers.twilio.com", + } +} diff --git a/rest/numbers/v2/hosted_number_authorization_documents.go b/rest/numbers/v2/hosted_number_authorization_documents.go index 11593b450..a7c951f5a 100644 --- a/rest/numbers/v2/hosted_number_authorization_documents.go +++ b/rest/numbers/v2/hosted_number_authorization_documents.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -66,6 +67,9 @@ func (params *CreateAuthorizationDocumentParams) SetCcEmails(CcEmails []string) // Create an AuthorizationDocument for authorizing the hosting of phone number capabilities on Twilio's platform. func (c *ApiService) CreateAuthorizationDocument(params *CreateAuthorizationDocumentParams) (*NumbersV2AuthorizationDocument, error) { + return c.CreateAuthorizationDocumentWithContext(context.TODO(), params) +} +func (c *ApiService) CreateAuthorizationDocumentWithContext(ctx context.Context, params *CreateAuthorizationDocumentParams) (*NumbersV2AuthorizationDocument, error) { path := "/v2/HostedNumber/AuthorizationDocuments" data := url.Values{} @@ -96,7 +100,7 @@ func (c *ApiService) CreateAuthorizationDocument(params *CreateAuthorizationDocu } } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -113,6 +117,9 @@ func (c *ApiService) CreateAuthorizationDocument(params *CreateAuthorizationDocu // Cancel the AuthorizationDocument request. func (c *ApiService) DeleteAuthorizationDocument(Sid string) error { + return c.DeleteAuthorizationDocumentWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteAuthorizationDocumentWithContext(ctx context.Context, Sid string) error { path := "/v2/HostedNumber/AuthorizationDocuments/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -121,7 +128,7 @@ func (c *ApiService) DeleteAuthorizationDocument(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -133,6 +140,9 @@ func (c *ApiService) DeleteAuthorizationDocument(Sid string) error { // Fetch a specific AuthorizationDocument. func (c *ApiService) FetchAuthorizationDocument(Sid string) (*NumbersV2AuthorizationDocument, error) { + return c.FetchAuthorizationDocumentWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchAuthorizationDocumentWithContext(ctx context.Context, Sid string) (*NumbersV2AuthorizationDocument, error) { path := "/v2/HostedNumber/AuthorizationDocuments/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -141,7 +151,7 @@ func (c *ApiService) FetchAuthorizationDocument(Sid string) (*NumbersV2Authoriza "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -187,6 +197,11 @@ func (params *ListAuthorizationDocumentParams) SetLimit(Limit int) *ListAuthoriz // Retrieve a single page of AuthorizationDocument records from the API. Request is executed immediately. func (c *ApiService) PageAuthorizationDocument(params *ListAuthorizationDocumentParams, pageToken, pageNumber string) (*ListAuthorizationDocumentResponse, error) { + return c.PageAuthorizationDocumentWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of AuthorizationDocument records from the API. Request is executed immediately. +func (c *ApiService) PageAuthorizationDocumentWithContext(ctx context.Context, params *ListAuthorizationDocumentParams, pageToken, pageNumber string) (*ListAuthorizationDocumentResponse, error) { path := "/v2/HostedNumber/AuthorizationDocuments" data := url.Values{} @@ -211,7 +226,7 @@ func (c *ApiService) PageAuthorizationDocument(params *ListAuthorizationDocument data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -228,7 +243,12 @@ func (c *ApiService) PageAuthorizationDocument(params *ListAuthorizationDocument // Lists AuthorizationDocument records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListAuthorizationDocument(params *ListAuthorizationDocumentParams) ([]NumbersV2AuthorizationDocument, error) { - response, errors := c.StreamAuthorizationDocument(params) + return c.ListAuthorizationDocumentWithContext(context.TODO(), params) +} + +// Lists AuthorizationDocument records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListAuthorizationDocumentWithContext(ctx context.Context, params *ListAuthorizationDocumentParams) ([]NumbersV2AuthorizationDocument, error) { + response, errors := c.StreamAuthorizationDocumentWithContext(ctx, params) records := make([]NumbersV2AuthorizationDocument, 0) for record := range response { @@ -244,6 +264,11 @@ func (c *ApiService) ListAuthorizationDocument(params *ListAuthorizationDocument // Streams AuthorizationDocument records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamAuthorizationDocument(params *ListAuthorizationDocumentParams) (chan NumbersV2AuthorizationDocument, chan error) { + return c.StreamAuthorizationDocumentWithContext(context.TODO(), params) +} + +// Streams AuthorizationDocument records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamAuthorizationDocumentWithContext(ctx context.Context, params *ListAuthorizationDocumentParams) (chan NumbersV2AuthorizationDocument, chan error) { if params == nil { params = &ListAuthorizationDocumentParams{} } @@ -252,19 +277,19 @@ func (c *ApiService) StreamAuthorizationDocument(params *ListAuthorizationDocume recordChannel := make(chan NumbersV2AuthorizationDocument, 1) errorChannel := make(chan error, 1) - response, err := c.PageAuthorizationDocument(params, "", "") + response, err := c.PageAuthorizationDocumentWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamAuthorizationDocument(response, params, recordChannel, errorChannel) + go c.streamAuthorizationDocumentWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamAuthorizationDocument(response *ListAuthorizationDocumentResponse, params *ListAuthorizationDocumentParams, recordChannel chan NumbersV2AuthorizationDocument, errorChannel chan error) { +func (c *ApiService) streamAuthorizationDocumentWithContext(ctx context.Context, response *ListAuthorizationDocumentResponse, params *ListAuthorizationDocumentParams, recordChannel chan NumbersV2AuthorizationDocument, errorChannel chan error) { curRecord := 1 for response != nil { @@ -279,7 +304,7 @@ func (c *ApiService) streamAuthorizationDocument(response *ListAuthorizationDocu } } - record, err := client.GetNext(c.baseURL, response, c.getNextListAuthorizationDocumentResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListAuthorizationDocumentResponseWithContext) if err != nil { errorChannel <- err break @@ -294,11 +319,11 @@ func (c *ApiService) streamAuthorizationDocument(response *ListAuthorizationDocu close(errorChannel) } -func (c *ApiService) getNextListAuthorizationDocumentResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListAuthorizationDocumentResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/numbers/v2/hosted_number_authorization_documents_dependent_hosted_number_orders.go b/rest/numbers/v2/hosted_number_authorization_documents_dependent_hosted_number_orders.go index 04673c166..d454a7813 100644 --- a/rest/numbers/v2/hosted_number_authorization_documents_dependent_hosted_number_orders.go +++ b/rest/numbers/v2/hosted_number_authorization_documents_dependent_hosted_number_orders.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -66,6 +67,11 @@ func (params *ListDependentHostedNumberOrderParams) SetLimit(Limit int) *ListDep // Retrieve a single page of DependentHostedNumberOrder records from the API. Request is executed immediately. func (c *ApiService) PageDependentHostedNumberOrder(SigningDocumentSid string, params *ListDependentHostedNumberOrderParams, pageToken, pageNumber string) (*ListDependentHostedNumberOrderResponse, error) { + return c.PageDependentHostedNumberOrderWithContext(context.TODO(), SigningDocumentSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of DependentHostedNumberOrder records from the API. Request is executed immediately. +func (c *ApiService) PageDependentHostedNumberOrderWithContext(ctx context.Context, SigningDocumentSid string, params *ListDependentHostedNumberOrderParams, pageToken, pageNumber string) (*ListDependentHostedNumberOrderResponse, error) { path := "/v2/HostedNumber/AuthorizationDocuments/{SigningDocumentSid}/DependentHostedNumberOrders" path = strings.Replace(path, "{"+"SigningDocumentSid"+"}", SigningDocumentSid, -1) @@ -98,7 +104,7 @@ func (c *ApiService) PageDependentHostedNumberOrder(SigningDocumentSid string, p data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -115,7 +121,12 @@ func (c *ApiService) PageDependentHostedNumberOrder(SigningDocumentSid string, p // Lists DependentHostedNumberOrder records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListDependentHostedNumberOrder(SigningDocumentSid string, params *ListDependentHostedNumberOrderParams) ([]NumbersV2DependentHostedNumberOrder, error) { - response, errors := c.StreamDependentHostedNumberOrder(SigningDocumentSid, params) + return c.ListDependentHostedNumberOrderWithContext(context.TODO(), SigningDocumentSid, params) +} + +// Lists DependentHostedNumberOrder records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListDependentHostedNumberOrderWithContext(ctx context.Context, SigningDocumentSid string, params *ListDependentHostedNumberOrderParams) ([]NumbersV2DependentHostedNumberOrder, error) { + response, errors := c.StreamDependentHostedNumberOrderWithContext(ctx, SigningDocumentSid, params) records := make([]NumbersV2DependentHostedNumberOrder, 0) for record := range response { @@ -131,6 +142,11 @@ func (c *ApiService) ListDependentHostedNumberOrder(SigningDocumentSid string, p // Streams DependentHostedNumberOrder records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamDependentHostedNumberOrder(SigningDocumentSid string, params *ListDependentHostedNumberOrderParams) (chan NumbersV2DependentHostedNumberOrder, chan error) { + return c.StreamDependentHostedNumberOrderWithContext(context.TODO(), SigningDocumentSid, params) +} + +// Streams DependentHostedNumberOrder records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamDependentHostedNumberOrderWithContext(ctx context.Context, SigningDocumentSid string, params *ListDependentHostedNumberOrderParams) (chan NumbersV2DependentHostedNumberOrder, chan error) { if params == nil { params = &ListDependentHostedNumberOrderParams{} } @@ -139,19 +155,19 @@ func (c *ApiService) StreamDependentHostedNumberOrder(SigningDocumentSid string, recordChannel := make(chan NumbersV2DependentHostedNumberOrder, 1) errorChannel := make(chan error, 1) - response, err := c.PageDependentHostedNumberOrder(SigningDocumentSid, params, "", "") + response, err := c.PageDependentHostedNumberOrderWithContext(ctx, SigningDocumentSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamDependentHostedNumberOrder(response, params, recordChannel, errorChannel) + go c.streamDependentHostedNumberOrderWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamDependentHostedNumberOrder(response *ListDependentHostedNumberOrderResponse, params *ListDependentHostedNumberOrderParams, recordChannel chan NumbersV2DependentHostedNumberOrder, errorChannel chan error) { +func (c *ApiService) streamDependentHostedNumberOrderWithContext(ctx context.Context, response *ListDependentHostedNumberOrderResponse, params *ListDependentHostedNumberOrderParams, recordChannel chan NumbersV2DependentHostedNumberOrder, errorChannel chan error) { curRecord := 1 for response != nil { @@ -166,7 +182,7 @@ func (c *ApiService) streamDependentHostedNumberOrder(response *ListDependentHos } } - record, err := client.GetNext(c.baseURL, response, c.getNextListDependentHostedNumberOrderResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListDependentHostedNumberOrderResponseWithContext) if err != nil { errorChannel <- err break @@ -181,11 +197,11 @@ func (c *ApiService) streamDependentHostedNumberOrder(response *ListDependentHos close(errorChannel) } -func (c *ApiService) getNextListDependentHostedNumberOrderResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListDependentHostedNumberOrderResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/numbers/v2/hosted_number_orders.go b/rest/numbers/v2/hosted_number_orders.go index 2412a6792..50568999b 100644 --- a/rest/numbers/v2/hosted_number_orders.go +++ b/rest/numbers/v2/hosted_number_orders.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -126,6 +127,9 @@ func (params *CreateHostedNumberOrderParams) SetContactTitle(ContactTitle string // Host a phone number's capability on Twilio's platform. func (c *ApiService) CreateHostedNumberOrder(params *CreateHostedNumberOrderParams) (*NumbersV2HostedNumberOrder, error) { + return c.CreateHostedNumberOrderWithContext(context.TODO(), params) +} +func (c *ApiService) CreateHostedNumberOrderWithContext(ctx context.Context, params *CreateHostedNumberOrderParams) (*NumbersV2HostedNumberOrder, error) { path := "/v2/HostedNumber/Orders" data := url.Values{} @@ -184,7 +188,7 @@ func (c *ApiService) CreateHostedNumberOrder(params *CreateHostedNumberOrderPara data.Set("ContactTitle", *params.ContactTitle) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -201,6 +205,9 @@ func (c *ApiService) CreateHostedNumberOrder(params *CreateHostedNumberOrderPara // Cancel the HostedNumberOrder (only available when the status is in `received`). func (c *ApiService) DeleteHostedNumberOrder(Sid string) error { + return c.DeleteHostedNumberOrderWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteHostedNumberOrderWithContext(ctx context.Context, Sid string) error { path := "/v2/HostedNumber/Orders/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -209,7 +216,7 @@ func (c *ApiService) DeleteHostedNumberOrder(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -221,6 +228,9 @@ func (c *ApiService) DeleteHostedNumberOrder(Sid string) error { // Fetch a specific HostedNumberOrder. func (c *ApiService) FetchHostedNumberOrder(Sid string) (*NumbersV2HostedNumberOrder, error) { + return c.FetchHostedNumberOrderWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchHostedNumberOrderWithContext(ctx context.Context, Sid string) (*NumbersV2HostedNumberOrder, error) { path := "/v2/HostedNumber/Orders/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -229,7 +239,7 @@ func (c *ApiService) FetchHostedNumberOrder(Sid string) (*NumbersV2HostedNumberO "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -293,6 +303,11 @@ func (params *ListHostedNumberOrderParams) SetLimit(Limit int) *ListHostedNumber // Retrieve a single page of HostedNumberOrder records from the API. Request is executed immediately. func (c *ApiService) PageHostedNumberOrder(params *ListHostedNumberOrderParams, pageToken, pageNumber string) (*ListHostedNumberOrderResponse, error) { + return c.PageHostedNumberOrderWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of HostedNumberOrder records from the API. Request is executed immediately. +func (c *ApiService) PageHostedNumberOrderWithContext(ctx context.Context, params *ListHostedNumberOrderParams, pageToken, pageNumber string) (*ListHostedNumberOrderResponse, error) { path := "/v2/HostedNumber/Orders" data := url.Values{} @@ -326,7 +341,7 @@ func (c *ApiService) PageHostedNumberOrder(params *ListHostedNumberOrderParams, data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -343,7 +358,12 @@ func (c *ApiService) PageHostedNumberOrder(params *ListHostedNumberOrderParams, // Lists HostedNumberOrder records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListHostedNumberOrder(params *ListHostedNumberOrderParams) ([]NumbersV2HostedNumberOrder, error) { - response, errors := c.StreamHostedNumberOrder(params) + return c.ListHostedNumberOrderWithContext(context.TODO(), params) +} + +// Lists HostedNumberOrder records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListHostedNumberOrderWithContext(ctx context.Context, params *ListHostedNumberOrderParams) ([]NumbersV2HostedNumberOrder, error) { + response, errors := c.StreamHostedNumberOrderWithContext(ctx, params) records := make([]NumbersV2HostedNumberOrder, 0) for record := range response { @@ -359,6 +379,11 @@ func (c *ApiService) ListHostedNumberOrder(params *ListHostedNumberOrderParams) // Streams HostedNumberOrder records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamHostedNumberOrder(params *ListHostedNumberOrderParams) (chan NumbersV2HostedNumberOrder, chan error) { + return c.StreamHostedNumberOrderWithContext(context.TODO(), params) +} + +// Streams HostedNumberOrder records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamHostedNumberOrderWithContext(ctx context.Context, params *ListHostedNumberOrderParams) (chan NumbersV2HostedNumberOrder, chan error) { if params == nil { params = &ListHostedNumberOrderParams{} } @@ -367,19 +392,19 @@ func (c *ApiService) StreamHostedNumberOrder(params *ListHostedNumberOrderParams recordChannel := make(chan NumbersV2HostedNumberOrder, 1) errorChannel := make(chan error, 1) - response, err := c.PageHostedNumberOrder(params, "", "") + response, err := c.PageHostedNumberOrderWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamHostedNumberOrder(response, params, recordChannel, errorChannel) + go c.streamHostedNumberOrderWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamHostedNumberOrder(response *ListHostedNumberOrderResponse, params *ListHostedNumberOrderParams, recordChannel chan NumbersV2HostedNumberOrder, errorChannel chan error) { +func (c *ApiService) streamHostedNumberOrderWithContext(ctx context.Context, response *ListHostedNumberOrderResponse, params *ListHostedNumberOrderParams, recordChannel chan NumbersV2HostedNumberOrder, errorChannel chan error) { curRecord := 1 for response != nil { @@ -394,7 +419,7 @@ func (c *ApiService) streamHostedNumberOrder(response *ListHostedNumberOrderResp } } - record, err := client.GetNext(c.baseURL, response, c.getNextListHostedNumberOrderResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListHostedNumberOrderResponseWithContext) if err != nil { errorChannel <- err break @@ -409,11 +434,11 @@ func (c *ApiService) streamHostedNumberOrder(response *ListHostedNumberOrderResp close(errorChannel) } -func (c *ApiService) getNextListHostedNumberOrderResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListHostedNumberOrderResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -452,6 +477,9 @@ func (params *UpdateHostedNumberOrderParams) SetVerificationCallExtension(Verifi // Updates a specific HostedNumberOrder. func (c *ApiService) UpdateHostedNumberOrder(Sid string, params *UpdateHostedNumberOrderParams) (*NumbersV2HostedNumberOrder, error) { + return c.UpdateHostedNumberOrderWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateHostedNumberOrderWithContext(ctx context.Context, Sid string, params *UpdateHostedNumberOrderParams) (*NumbersV2HostedNumberOrder, error) { path := "/v2/HostedNumber/Orders/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -470,7 +498,7 @@ func (c *ApiService) UpdateHostedNumberOrder(Sid string, params *UpdateHostedNum data.Set("VerificationCallExtension", *params.VerificationCallExtension) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/numbers/v2/hosted_number_orders_bulk.go b/rest/numbers/v2/hosted_number_orders_bulk.go index 61abc2457..94fa1121d 100644 --- a/rest/numbers/v2/hosted_number_orders_bulk.go +++ b/rest/numbers/v2/hosted_number_orders_bulk.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -33,6 +34,9 @@ func (params *CreateBulkHostedNumberOrderParams) SetBody(Body map[string]interfa // Host multiple phone numbers on Twilio's platform. func (c *ApiService) CreateBulkHostedNumberOrder(params *CreateBulkHostedNumberOrderParams) (*NumbersV2BulkHostedNumberOrder, error) { + return c.CreateBulkHostedNumberOrderWithContext(context.TODO(), params) +} +func (c *ApiService) CreateBulkHostedNumberOrderWithContext(ctx context.Context, params *CreateBulkHostedNumberOrderParams) (*NumbersV2BulkHostedNumberOrder, error) { path := "/v2/HostedNumber/Orders/Bulk" data := url.Values{} @@ -49,7 +53,7 @@ func (c *ApiService) CreateBulkHostedNumberOrder(params *CreateBulkHostedNumberO body = b } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers, body...) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers, body...) if err != nil { return nil, err } @@ -77,6 +81,9 @@ func (params *FetchBulkHostedNumberOrderParams) SetOrderStatus(OrderStatus strin // Fetch a specific BulkHostedNumberOrder. func (c *ApiService) FetchBulkHostedNumberOrder(BulkHostingSid string, params *FetchBulkHostedNumberOrderParams) (*NumbersV2BulkHostedNumberOrder, error) { + return c.FetchBulkHostedNumberOrderWithContext(context.TODO(), BulkHostingSid, params) +} +func (c *ApiService) FetchBulkHostedNumberOrderWithContext(ctx context.Context, BulkHostingSid string, params *FetchBulkHostedNumberOrderParams) (*NumbersV2BulkHostedNumberOrder, error) { path := "/v2/HostedNumber/Orders/Bulk/{BulkHostingSid}" path = strings.Replace(path, "{"+"BulkHostingSid"+"}", BulkHostingSid, -1) @@ -89,7 +96,7 @@ func (c *ApiService) FetchBulkHostedNumberOrder(BulkHostingSid string, params *F data.Set("OrderStatus", *params.OrderStatus) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/numbers/v2/regulatory_compliance_bundles.go b/rest/numbers/v2/regulatory_compliance_bundles.go index 5159fff2c..a504ee589 100644 --- a/rest/numbers/v2/regulatory_compliance_bundles.go +++ b/rest/numbers/v2/regulatory_compliance_bundles.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -79,6 +80,9 @@ func (params *CreateBundleParams) SetIsTest(IsTest bool) *CreateBundleParams { // Create a new Bundle. func (c *ApiService) CreateBundle(params *CreateBundleParams) (*NumbersV2Bundle, error) { + return c.CreateBundleWithContext(context.TODO(), params) +} +func (c *ApiService) CreateBundleWithContext(ctx context.Context, params *CreateBundleParams) (*NumbersV2Bundle, error) { path := "/v2/RegulatoryCompliance/Bundles" data := url.Values{} @@ -111,7 +115,7 @@ func (c *ApiService) CreateBundle(params *CreateBundleParams) (*NumbersV2Bundle, data.Set("IsTest", fmt.Sprint(*params.IsTest)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -128,6 +132,9 @@ func (c *ApiService) CreateBundle(params *CreateBundleParams) (*NumbersV2Bundle, // Delete a specific Bundle. func (c *ApiService) DeleteBundle(Sid string) error { + return c.DeleteBundleWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteBundleWithContext(ctx context.Context, Sid string) error { path := "/v2/RegulatoryCompliance/Bundles/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -136,7 +143,7 @@ func (c *ApiService) DeleteBundle(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -148,6 +155,9 @@ func (c *ApiService) DeleteBundle(Sid string) error { // Fetch a specific Bundle instance. func (c *ApiService) FetchBundle(Sid string) (*NumbersV2Bundle, error) { + return c.FetchBundleWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchBundleWithContext(ctx context.Context, Sid string) (*NumbersV2Bundle, error) { path := "/v2/RegulatoryCompliance/Bundles/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -156,7 +166,7 @@ func (c *ApiService) FetchBundle(Sid string) (*NumbersV2Bundle, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -256,6 +266,11 @@ func (params *ListBundleParams) SetLimit(Limit int) *ListBundleParams { // Retrieve a single page of Bundle records from the API. Request is executed immediately. func (c *ApiService) PageBundle(params *ListBundleParams, pageToken, pageNumber string) (*ListBundleResponse, error) { + return c.PageBundleWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Bundle records from the API. Request is executed immediately. +func (c *ApiService) PageBundleWithContext(ctx context.Context, params *ListBundleParams, pageToken, pageNumber string) (*ListBundleResponse, error) { path := "/v2/RegulatoryCompliance/Bundles" data := url.Values{} @@ -307,7 +322,7 @@ func (c *ApiService) PageBundle(params *ListBundleParams, pageToken, pageNumber data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -324,7 +339,12 @@ func (c *ApiService) PageBundle(params *ListBundleParams, pageToken, pageNumber // Lists Bundle records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListBundle(params *ListBundleParams) ([]NumbersV2Bundle, error) { - response, errors := c.StreamBundle(params) + return c.ListBundleWithContext(context.TODO(), params) +} + +// Lists Bundle records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListBundleWithContext(ctx context.Context, params *ListBundleParams) ([]NumbersV2Bundle, error) { + response, errors := c.StreamBundleWithContext(ctx, params) records := make([]NumbersV2Bundle, 0) for record := range response { @@ -340,6 +360,11 @@ func (c *ApiService) ListBundle(params *ListBundleParams) ([]NumbersV2Bundle, er // Streams Bundle records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamBundle(params *ListBundleParams) (chan NumbersV2Bundle, chan error) { + return c.StreamBundleWithContext(context.TODO(), params) +} + +// Streams Bundle records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamBundleWithContext(ctx context.Context, params *ListBundleParams) (chan NumbersV2Bundle, chan error) { if params == nil { params = &ListBundleParams{} } @@ -348,19 +373,19 @@ func (c *ApiService) StreamBundle(params *ListBundleParams) (chan NumbersV2Bundl recordChannel := make(chan NumbersV2Bundle, 1) errorChannel := make(chan error, 1) - response, err := c.PageBundle(params, "", "") + response, err := c.PageBundleWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamBundle(response, params, recordChannel, errorChannel) + go c.streamBundleWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamBundle(response *ListBundleResponse, params *ListBundleParams, recordChannel chan NumbersV2Bundle, errorChannel chan error) { +func (c *ApiService) streamBundleWithContext(ctx context.Context, response *ListBundleResponse, params *ListBundleParams, recordChannel chan NumbersV2Bundle, errorChannel chan error) { curRecord := 1 for response != nil { @@ -375,7 +400,7 @@ func (c *ApiService) streamBundle(response *ListBundleResponse, params *ListBund } } - record, err := client.GetNext(c.baseURL, response, c.getNextListBundleResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListBundleResponseWithContext) if err != nil { errorChannel <- err break @@ -390,11 +415,11 @@ func (c *ApiService) streamBundle(response *ListBundleResponse, params *ListBund close(errorChannel) } -func (c *ApiService) getNextListBundleResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListBundleResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -439,6 +464,9 @@ func (params *UpdateBundleParams) SetEmail(Email string) *UpdateBundleParams { // Updates a Bundle in an account. func (c *ApiService) UpdateBundle(Sid string, params *UpdateBundleParams) (*NumbersV2Bundle, error) { + return c.UpdateBundleWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateBundleWithContext(ctx context.Context, Sid string, params *UpdateBundleParams) (*NumbersV2Bundle, error) { path := "/v2/RegulatoryCompliance/Bundles/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -460,7 +488,7 @@ func (c *ApiService) UpdateBundle(Sid string, params *UpdateBundleParams) (*Numb data.Set("Email", *params.Email) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/numbers/v2/regulatory_compliance_bundles_clones.go b/rest/numbers/v2/regulatory_compliance_bundles_clones.go index 684585dd0..0c40ee69c 100644 --- a/rest/numbers/v2/regulatory_compliance_bundles_clones.go +++ b/rest/numbers/v2/regulatory_compliance_bundles_clones.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -46,6 +47,9 @@ func (params *CreateBundleCloneParams) SetFriendlyName(FriendlyName string) *Cre // Creates a new clone of the Bundle in target Account. It will internally create clones of all the bundle items (identities and documents) of the original bundle func (c *ApiService) CreateBundleClone(BundleSid string, params *CreateBundleCloneParams) (*NumbersV2BundleClone, error) { + return c.CreateBundleCloneWithContext(context.TODO(), BundleSid, params) +} +func (c *ApiService) CreateBundleCloneWithContext(ctx context.Context, BundleSid string, params *CreateBundleCloneParams) (*NumbersV2BundleClone, error) { path := "/v2/RegulatoryCompliance/Bundles/{BundleSid}/Clones" path = strings.Replace(path, "{"+"BundleSid"+"}", BundleSid, -1) @@ -64,7 +68,7 @@ func (c *ApiService) CreateBundleClone(BundleSid string, params *CreateBundleClo data.Set("FriendlyName", *params.FriendlyName) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/numbers/v2/regulatory_compliance_bundles_copies.go b/rest/numbers/v2/regulatory_compliance_bundles_copies.go index 69835a3cb..cfb214032 100644 --- a/rest/numbers/v2/regulatory_compliance_bundles_copies.go +++ b/rest/numbers/v2/regulatory_compliance_bundles_copies.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -36,6 +37,9 @@ func (params *CreateBundleCopyParams) SetFriendlyName(FriendlyName string) *Crea // Creates a new copy of a Bundle. It will internally create copies of all the bundle items (identities and documents) of the original bundle func (c *ApiService) CreateBundleCopy(BundleSid string, params *CreateBundleCopyParams) (*NumbersV2BundleCopy, error) { + return c.CreateBundleCopyWithContext(context.TODO(), BundleSid, params) +} +func (c *ApiService) CreateBundleCopyWithContext(ctx context.Context, BundleSid string, params *CreateBundleCopyParams) (*NumbersV2BundleCopy, error) { path := "/v2/RegulatoryCompliance/Bundles/{BundleSid}/Copies" path = strings.Replace(path, "{"+"BundleSid"+"}", BundleSid, -1) @@ -48,7 +52,7 @@ func (c *ApiService) CreateBundleCopy(BundleSid string, params *CreateBundleCopy data.Set("FriendlyName", *params.FriendlyName) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -82,6 +86,11 @@ func (params *ListBundleCopyParams) SetLimit(Limit int) *ListBundleCopyParams { // Retrieve a single page of BundleCopy records from the API. Request is executed immediately. func (c *ApiService) PageBundleCopy(BundleSid string, params *ListBundleCopyParams, pageToken, pageNumber string) (*ListBundleCopyResponse, error) { + return c.PageBundleCopyWithContext(context.TODO(), BundleSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of BundleCopy records from the API. Request is executed immediately. +func (c *ApiService) PageBundleCopyWithContext(ctx context.Context, BundleSid string, params *ListBundleCopyParams, pageToken, pageNumber string) (*ListBundleCopyResponse, error) { path := "/v2/RegulatoryCompliance/Bundles/{BundleSid}/Copies" path = strings.Replace(path, "{"+"BundleSid"+"}", BundleSid, -1) @@ -102,7 +111,7 @@ func (c *ApiService) PageBundleCopy(BundleSid string, params *ListBundleCopyPara data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -119,7 +128,12 @@ func (c *ApiService) PageBundleCopy(BundleSid string, params *ListBundleCopyPara // Lists BundleCopy records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListBundleCopy(BundleSid string, params *ListBundleCopyParams) ([]NumbersV2BundleCopy, error) { - response, errors := c.StreamBundleCopy(BundleSid, params) + return c.ListBundleCopyWithContext(context.TODO(), BundleSid, params) +} + +// Lists BundleCopy records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListBundleCopyWithContext(ctx context.Context, BundleSid string, params *ListBundleCopyParams) ([]NumbersV2BundleCopy, error) { + response, errors := c.StreamBundleCopyWithContext(ctx, BundleSid, params) records := make([]NumbersV2BundleCopy, 0) for record := range response { @@ -135,6 +149,11 @@ func (c *ApiService) ListBundleCopy(BundleSid string, params *ListBundleCopyPara // Streams BundleCopy records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamBundleCopy(BundleSid string, params *ListBundleCopyParams) (chan NumbersV2BundleCopy, chan error) { + return c.StreamBundleCopyWithContext(context.TODO(), BundleSid, params) +} + +// Streams BundleCopy records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamBundleCopyWithContext(ctx context.Context, BundleSid string, params *ListBundleCopyParams) (chan NumbersV2BundleCopy, chan error) { if params == nil { params = &ListBundleCopyParams{} } @@ -143,19 +162,19 @@ func (c *ApiService) StreamBundleCopy(BundleSid string, params *ListBundleCopyPa recordChannel := make(chan NumbersV2BundleCopy, 1) errorChannel := make(chan error, 1) - response, err := c.PageBundleCopy(BundleSid, params, "", "") + response, err := c.PageBundleCopyWithContext(ctx, BundleSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamBundleCopy(response, params, recordChannel, errorChannel) + go c.streamBundleCopyWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamBundleCopy(response *ListBundleCopyResponse, params *ListBundleCopyParams, recordChannel chan NumbersV2BundleCopy, errorChannel chan error) { +func (c *ApiService) streamBundleCopyWithContext(ctx context.Context, response *ListBundleCopyResponse, params *ListBundleCopyParams, recordChannel chan NumbersV2BundleCopy, errorChannel chan error) { curRecord := 1 for response != nil { @@ -170,7 +189,7 @@ func (c *ApiService) streamBundleCopy(response *ListBundleCopyResponse, params * } } - record, err := client.GetNext(c.baseURL, response, c.getNextListBundleCopyResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListBundleCopyResponseWithContext) if err != nil { errorChannel <- err break @@ -185,11 +204,11 @@ func (c *ApiService) streamBundleCopy(response *ListBundleCopyResponse, params * close(errorChannel) } -func (c *ApiService) getNextListBundleCopyResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListBundleCopyResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/numbers/v2/regulatory_compliance_bundles_evaluations.go b/rest/numbers/v2/regulatory_compliance_bundles_evaluations.go index 2b69e24ec..2e6a03289 100644 --- a/rest/numbers/v2/regulatory_compliance_bundles_evaluations.go +++ b/rest/numbers/v2/regulatory_compliance_bundles_evaluations.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -25,6 +26,9 @@ import ( // Creates an evaluation for a bundle func (c *ApiService) CreateEvaluation(BundleSid string) (*NumbersV2Evaluation, error) { + return c.CreateEvaluationWithContext(context.TODO(), BundleSid) +} +func (c *ApiService) CreateEvaluationWithContext(ctx context.Context, BundleSid string) (*NumbersV2Evaluation, error) { path := "/v2/RegulatoryCompliance/Bundles/{BundleSid}/Evaluations" path = strings.Replace(path, "{"+"BundleSid"+"}", BundleSid, -1) @@ -33,7 +37,7 @@ func (c *ApiService) CreateEvaluation(BundleSid string) (*NumbersV2Evaluation, e "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -50,6 +54,9 @@ func (c *ApiService) CreateEvaluation(BundleSid string) (*NumbersV2Evaluation, e // Fetch specific Evaluation Instance. func (c *ApiService) FetchEvaluation(BundleSid string, Sid string) (*NumbersV2Evaluation, error) { + return c.FetchEvaluationWithContext(context.TODO(), BundleSid, Sid) +} +func (c *ApiService) FetchEvaluationWithContext(ctx context.Context, BundleSid string, Sid string) (*NumbersV2Evaluation, error) { path := "/v2/RegulatoryCompliance/Bundles/{BundleSid}/Evaluations/{Sid}" path = strings.Replace(path, "{"+"BundleSid"+"}", BundleSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -59,7 +66,7 @@ func (c *ApiService) FetchEvaluation(BundleSid string, Sid string) (*NumbersV2Ev "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -93,6 +100,11 @@ func (params *ListEvaluationParams) SetLimit(Limit int) *ListEvaluationParams { // Retrieve a single page of Evaluation records from the API. Request is executed immediately. func (c *ApiService) PageEvaluation(BundleSid string, params *ListEvaluationParams, pageToken, pageNumber string) (*ListEvaluationResponse, error) { + return c.PageEvaluationWithContext(context.TODO(), BundleSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Evaluation records from the API. Request is executed immediately. +func (c *ApiService) PageEvaluationWithContext(ctx context.Context, BundleSid string, params *ListEvaluationParams, pageToken, pageNumber string) (*ListEvaluationResponse, error) { path := "/v2/RegulatoryCompliance/Bundles/{BundleSid}/Evaluations" path = strings.Replace(path, "{"+"BundleSid"+"}", BundleSid, -1) @@ -113,7 +125,7 @@ func (c *ApiService) PageEvaluation(BundleSid string, params *ListEvaluationPara data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -130,7 +142,12 @@ func (c *ApiService) PageEvaluation(BundleSid string, params *ListEvaluationPara // Lists Evaluation records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListEvaluation(BundleSid string, params *ListEvaluationParams) ([]NumbersV2Evaluation, error) { - response, errors := c.StreamEvaluation(BundleSid, params) + return c.ListEvaluationWithContext(context.TODO(), BundleSid, params) +} + +// Lists Evaluation records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListEvaluationWithContext(ctx context.Context, BundleSid string, params *ListEvaluationParams) ([]NumbersV2Evaluation, error) { + response, errors := c.StreamEvaluationWithContext(ctx, BundleSid, params) records := make([]NumbersV2Evaluation, 0) for record := range response { @@ -146,6 +163,11 @@ func (c *ApiService) ListEvaluation(BundleSid string, params *ListEvaluationPara // Streams Evaluation records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamEvaluation(BundleSid string, params *ListEvaluationParams) (chan NumbersV2Evaluation, chan error) { + return c.StreamEvaluationWithContext(context.TODO(), BundleSid, params) +} + +// Streams Evaluation records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamEvaluationWithContext(ctx context.Context, BundleSid string, params *ListEvaluationParams) (chan NumbersV2Evaluation, chan error) { if params == nil { params = &ListEvaluationParams{} } @@ -154,19 +176,19 @@ func (c *ApiService) StreamEvaluation(BundleSid string, params *ListEvaluationPa recordChannel := make(chan NumbersV2Evaluation, 1) errorChannel := make(chan error, 1) - response, err := c.PageEvaluation(BundleSid, params, "", "") + response, err := c.PageEvaluationWithContext(ctx, BundleSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamEvaluation(response, params, recordChannel, errorChannel) + go c.streamEvaluationWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamEvaluation(response *ListEvaluationResponse, params *ListEvaluationParams, recordChannel chan NumbersV2Evaluation, errorChannel chan error) { +func (c *ApiService) streamEvaluationWithContext(ctx context.Context, response *ListEvaluationResponse, params *ListEvaluationParams, recordChannel chan NumbersV2Evaluation, errorChannel chan error) { curRecord := 1 for response != nil { @@ -181,7 +203,7 @@ func (c *ApiService) streamEvaluation(response *ListEvaluationResponse, params * } } - record, err := client.GetNext(c.baseURL, response, c.getNextListEvaluationResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListEvaluationResponseWithContext) if err != nil { errorChannel <- err break @@ -196,11 +218,11 @@ func (c *ApiService) streamEvaluation(response *ListEvaluationResponse, params * close(errorChannel) } -func (c *ApiService) getNextListEvaluationResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListEvaluationResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/numbers/v2/regulatory_compliance_bundles_item_assignments.go b/rest/numbers/v2/regulatory_compliance_bundles_item_assignments.go index d22ac33e1..2f81eb37b 100644 --- a/rest/numbers/v2/regulatory_compliance_bundles_item_assignments.go +++ b/rest/numbers/v2/regulatory_compliance_bundles_item_assignments.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -36,6 +37,9 @@ func (params *CreateItemAssignmentParams) SetObjectSid(ObjectSid string) *Create // Create a new Assigned Item. func (c *ApiService) CreateItemAssignment(BundleSid string, params *CreateItemAssignmentParams) (*NumbersV2ItemAssignment, error) { + return c.CreateItemAssignmentWithContext(context.TODO(), BundleSid, params) +} +func (c *ApiService) CreateItemAssignmentWithContext(ctx context.Context, BundleSid string, params *CreateItemAssignmentParams) (*NumbersV2ItemAssignment, error) { path := "/v2/RegulatoryCompliance/Bundles/{BundleSid}/ItemAssignments" path = strings.Replace(path, "{"+"BundleSid"+"}", BundleSid, -1) @@ -48,7 +52,7 @@ func (c *ApiService) CreateItemAssignment(BundleSid string, params *CreateItemAs data.Set("ObjectSid", *params.ObjectSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -65,6 +69,9 @@ func (c *ApiService) CreateItemAssignment(BundleSid string, params *CreateItemAs // Remove an Assignment Item Instance. func (c *ApiService) DeleteItemAssignment(BundleSid string, Sid string) error { + return c.DeleteItemAssignmentWithContext(context.TODO(), BundleSid, Sid) +} +func (c *ApiService) DeleteItemAssignmentWithContext(ctx context.Context, BundleSid string, Sid string) error { path := "/v2/RegulatoryCompliance/Bundles/{BundleSid}/ItemAssignments/{Sid}" path = strings.Replace(path, "{"+"BundleSid"+"}", BundleSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -74,7 +81,7 @@ func (c *ApiService) DeleteItemAssignment(BundleSid string, Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -86,6 +93,9 @@ func (c *ApiService) DeleteItemAssignment(BundleSid string, Sid string) error { // Fetch specific Assigned Item Instance. func (c *ApiService) FetchItemAssignment(BundleSid string, Sid string) (*NumbersV2ItemAssignment, error) { + return c.FetchItemAssignmentWithContext(context.TODO(), BundleSid, Sid) +} +func (c *ApiService) FetchItemAssignmentWithContext(ctx context.Context, BundleSid string, Sid string) (*NumbersV2ItemAssignment, error) { path := "/v2/RegulatoryCompliance/Bundles/{BundleSid}/ItemAssignments/{Sid}" path = strings.Replace(path, "{"+"BundleSid"+"}", BundleSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -95,7 +105,7 @@ func (c *ApiService) FetchItemAssignment(BundleSid string, Sid string) (*Numbers "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -129,6 +139,11 @@ func (params *ListItemAssignmentParams) SetLimit(Limit int) *ListItemAssignmentP // Retrieve a single page of ItemAssignment records from the API. Request is executed immediately. func (c *ApiService) PageItemAssignment(BundleSid string, params *ListItemAssignmentParams, pageToken, pageNumber string) (*ListItemAssignmentResponse, error) { + return c.PageItemAssignmentWithContext(context.TODO(), BundleSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ItemAssignment records from the API. Request is executed immediately. +func (c *ApiService) PageItemAssignmentWithContext(ctx context.Context, BundleSid string, params *ListItemAssignmentParams, pageToken, pageNumber string) (*ListItemAssignmentResponse, error) { path := "/v2/RegulatoryCompliance/Bundles/{BundleSid}/ItemAssignments" path = strings.Replace(path, "{"+"BundleSid"+"}", BundleSid, -1) @@ -149,7 +164,7 @@ func (c *ApiService) PageItemAssignment(BundleSid string, params *ListItemAssign data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -166,7 +181,12 @@ func (c *ApiService) PageItemAssignment(BundleSid string, params *ListItemAssign // Lists ItemAssignment records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListItemAssignment(BundleSid string, params *ListItemAssignmentParams) ([]NumbersV2ItemAssignment, error) { - response, errors := c.StreamItemAssignment(BundleSid, params) + return c.ListItemAssignmentWithContext(context.TODO(), BundleSid, params) +} + +// Lists ItemAssignment records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListItemAssignmentWithContext(ctx context.Context, BundleSid string, params *ListItemAssignmentParams) ([]NumbersV2ItemAssignment, error) { + response, errors := c.StreamItemAssignmentWithContext(ctx, BundleSid, params) records := make([]NumbersV2ItemAssignment, 0) for record := range response { @@ -182,6 +202,11 @@ func (c *ApiService) ListItemAssignment(BundleSid string, params *ListItemAssign // Streams ItemAssignment records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamItemAssignment(BundleSid string, params *ListItemAssignmentParams) (chan NumbersV2ItemAssignment, chan error) { + return c.StreamItemAssignmentWithContext(context.TODO(), BundleSid, params) +} + +// Streams ItemAssignment records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamItemAssignmentWithContext(ctx context.Context, BundleSid string, params *ListItemAssignmentParams) (chan NumbersV2ItemAssignment, chan error) { if params == nil { params = &ListItemAssignmentParams{} } @@ -190,19 +215,19 @@ func (c *ApiService) StreamItemAssignment(BundleSid string, params *ListItemAssi recordChannel := make(chan NumbersV2ItemAssignment, 1) errorChannel := make(chan error, 1) - response, err := c.PageItemAssignment(BundleSid, params, "", "") + response, err := c.PageItemAssignmentWithContext(ctx, BundleSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamItemAssignment(response, params, recordChannel, errorChannel) + go c.streamItemAssignmentWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamItemAssignment(response *ListItemAssignmentResponse, params *ListItemAssignmentParams, recordChannel chan NumbersV2ItemAssignment, errorChannel chan error) { +func (c *ApiService) streamItemAssignmentWithContext(ctx context.Context, response *ListItemAssignmentResponse, params *ListItemAssignmentParams, recordChannel chan NumbersV2ItemAssignment, errorChannel chan error) { curRecord := 1 for response != nil { @@ -217,7 +242,7 @@ func (c *ApiService) streamItemAssignment(response *ListItemAssignmentResponse, } } - record, err := client.GetNext(c.baseURL, response, c.getNextListItemAssignmentResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListItemAssignmentResponseWithContext) if err != nil { errorChannel <- err break @@ -232,11 +257,11 @@ func (c *ApiService) streamItemAssignment(response *ListItemAssignmentResponse, close(errorChannel) } -func (c *ApiService) getNextListItemAssignmentResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListItemAssignmentResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/numbers/v2/regulatory_compliance_bundles_replace_items.go b/rest/numbers/v2/regulatory_compliance_bundles_replace_items.go index b74c5c917..214fa1169 100644 --- a/rest/numbers/v2/regulatory_compliance_bundles_replace_items.go +++ b/rest/numbers/v2/regulatory_compliance_bundles_replace_items.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -33,6 +34,9 @@ func (params *CreateReplaceItemsParams) SetFromBundleSid(FromBundleSid string) * // Replaces all bundle items in the target bundle (specified in the path) with all the bundle items of the source bundle (specified by the from_bundle_sid body param) func (c *ApiService) CreateReplaceItems(BundleSid string, params *CreateReplaceItemsParams) (*NumbersV2ReplaceItems, error) { + return c.CreateReplaceItemsWithContext(context.TODO(), BundleSid, params) +} +func (c *ApiService) CreateReplaceItemsWithContext(ctx context.Context, BundleSid string, params *CreateReplaceItemsParams) (*NumbersV2ReplaceItems, error) { path := "/v2/RegulatoryCompliance/Bundles/{BundleSid}/ReplaceItems" path = strings.Replace(path, "{"+"BundleSid"+"}", BundleSid, -1) @@ -45,7 +49,7 @@ func (c *ApiService) CreateReplaceItems(BundleSid string, params *CreateReplaceI data.Set("FromBundleSid", *params.FromBundleSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/numbers/v2/regulatory_compliance_end_user_types.go b/rest/numbers/v2/regulatory_compliance_end_user_types.go index feb306891..502e3c804 100644 --- a/rest/numbers/v2/regulatory_compliance_end_user_types.go +++ b/rest/numbers/v2/regulatory_compliance_end_user_types.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -25,6 +26,9 @@ import ( // Fetch a specific End-User Type Instance. func (c *ApiService) FetchEndUserType(Sid string) (*NumbersV2EndUserType, error) { + return c.FetchEndUserTypeWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchEndUserTypeWithContext(ctx context.Context, Sid string) (*NumbersV2EndUserType, error) { path := "/v2/RegulatoryCompliance/EndUserTypes/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -33,7 +37,7 @@ func (c *ApiService) FetchEndUserType(Sid string) (*NumbersV2EndUserType, error) "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -67,6 +71,11 @@ func (params *ListEndUserTypeParams) SetLimit(Limit int) *ListEndUserTypeParams // Retrieve a single page of EndUserType records from the API. Request is executed immediately. func (c *ApiService) PageEndUserType(params *ListEndUserTypeParams, pageToken, pageNumber string) (*ListEndUserTypeResponse, error) { + return c.PageEndUserTypeWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of EndUserType records from the API. Request is executed immediately. +func (c *ApiService) PageEndUserTypeWithContext(ctx context.Context, params *ListEndUserTypeParams, pageToken, pageNumber string) (*ListEndUserTypeResponse, error) { path := "/v2/RegulatoryCompliance/EndUserTypes" data := url.Values{} @@ -85,7 +94,7 @@ func (c *ApiService) PageEndUserType(params *ListEndUserTypeParams, pageToken, p data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -102,7 +111,12 @@ func (c *ApiService) PageEndUserType(params *ListEndUserTypeParams, pageToken, p // Lists EndUserType records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListEndUserType(params *ListEndUserTypeParams) ([]NumbersV2EndUserType, error) { - response, errors := c.StreamEndUserType(params) + return c.ListEndUserTypeWithContext(context.TODO(), params) +} + +// Lists EndUserType records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListEndUserTypeWithContext(ctx context.Context, params *ListEndUserTypeParams) ([]NumbersV2EndUserType, error) { + response, errors := c.StreamEndUserTypeWithContext(ctx, params) records := make([]NumbersV2EndUserType, 0) for record := range response { @@ -118,6 +132,11 @@ func (c *ApiService) ListEndUserType(params *ListEndUserTypeParams) ([]NumbersV2 // Streams EndUserType records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamEndUserType(params *ListEndUserTypeParams) (chan NumbersV2EndUserType, chan error) { + return c.StreamEndUserTypeWithContext(context.TODO(), params) +} + +// Streams EndUserType records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamEndUserTypeWithContext(ctx context.Context, params *ListEndUserTypeParams) (chan NumbersV2EndUserType, chan error) { if params == nil { params = &ListEndUserTypeParams{} } @@ -126,19 +145,19 @@ func (c *ApiService) StreamEndUserType(params *ListEndUserTypeParams) (chan Numb recordChannel := make(chan NumbersV2EndUserType, 1) errorChannel := make(chan error, 1) - response, err := c.PageEndUserType(params, "", "") + response, err := c.PageEndUserTypeWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamEndUserType(response, params, recordChannel, errorChannel) + go c.streamEndUserTypeWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamEndUserType(response *ListEndUserTypeResponse, params *ListEndUserTypeParams, recordChannel chan NumbersV2EndUserType, errorChannel chan error) { +func (c *ApiService) streamEndUserTypeWithContext(ctx context.Context, response *ListEndUserTypeResponse, params *ListEndUserTypeParams, recordChannel chan NumbersV2EndUserType, errorChannel chan error) { curRecord := 1 for response != nil { @@ -153,7 +172,7 @@ func (c *ApiService) streamEndUserType(response *ListEndUserTypeResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListEndUserTypeResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListEndUserTypeResponseWithContext) if err != nil { errorChannel <- err break @@ -168,11 +187,11 @@ func (c *ApiService) streamEndUserType(response *ListEndUserTypeResponse, params close(errorChannel) } -func (c *ApiService) getNextListEndUserTypeResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListEndUserTypeResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/numbers/v2/regulatory_compliance_end_users.go b/rest/numbers/v2/regulatory_compliance_end_users.go index 564185595..182b386fe 100644 --- a/rest/numbers/v2/regulatory_compliance_end_users.go +++ b/rest/numbers/v2/regulatory_compliance_end_users.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -48,6 +49,9 @@ func (params *CreateEndUserParams) SetAttributes(Attributes map[string]interface // Create a new End User. func (c *ApiService) CreateEndUser(params *CreateEndUserParams) (*NumbersV2EndUser, error) { + return c.CreateEndUserWithContext(context.TODO(), params) +} +func (c *ApiService) CreateEndUserWithContext(ctx context.Context, params *CreateEndUserParams) (*NumbersV2EndUser, error) { path := "/v2/RegulatoryCompliance/EndUsers" data := url.Values{} @@ -71,7 +75,7 @@ func (c *ApiService) CreateEndUser(params *CreateEndUserParams) (*NumbersV2EndUs data.Set("Attributes", string(v)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -88,6 +92,9 @@ func (c *ApiService) CreateEndUser(params *CreateEndUserParams) (*NumbersV2EndUs // Delete a specific End User. func (c *ApiService) DeleteEndUser(Sid string) error { + return c.DeleteEndUserWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteEndUserWithContext(ctx context.Context, Sid string) error { path := "/v2/RegulatoryCompliance/EndUsers/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -96,7 +103,7 @@ func (c *ApiService) DeleteEndUser(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -108,6 +115,9 @@ func (c *ApiService) DeleteEndUser(Sid string) error { // Fetch specific End User Instance. func (c *ApiService) FetchEndUser(Sid string) (*NumbersV2EndUser, error) { + return c.FetchEndUserWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchEndUserWithContext(ctx context.Context, Sid string) (*NumbersV2EndUser, error) { path := "/v2/RegulatoryCompliance/EndUsers/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -116,7 +126,7 @@ func (c *ApiService) FetchEndUser(Sid string) (*NumbersV2EndUser, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -150,6 +160,11 @@ func (params *ListEndUserParams) SetLimit(Limit int) *ListEndUserParams { // Retrieve a single page of EndUser records from the API. Request is executed immediately. func (c *ApiService) PageEndUser(params *ListEndUserParams, pageToken, pageNumber string) (*ListEndUserResponse, error) { + return c.PageEndUserWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of EndUser records from the API. Request is executed immediately. +func (c *ApiService) PageEndUserWithContext(ctx context.Context, params *ListEndUserParams, pageToken, pageNumber string) (*ListEndUserResponse, error) { path := "/v2/RegulatoryCompliance/EndUsers" data := url.Values{} @@ -168,7 +183,7 @@ func (c *ApiService) PageEndUser(params *ListEndUserParams, pageToken, pageNumbe data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -185,7 +200,12 @@ func (c *ApiService) PageEndUser(params *ListEndUserParams, pageToken, pageNumbe // Lists EndUser records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListEndUser(params *ListEndUserParams) ([]NumbersV2EndUser, error) { - response, errors := c.StreamEndUser(params) + return c.ListEndUserWithContext(context.TODO(), params) +} + +// Lists EndUser records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListEndUserWithContext(ctx context.Context, params *ListEndUserParams) ([]NumbersV2EndUser, error) { + response, errors := c.StreamEndUserWithContext(ctx, params) records := make([]NumbersV2EndUser, 0) for record := range response { @@ -201,6 +221,11 @@ func (c *ApiService) ListEndUser(params *ListEndUserParams) ([]NumbersV2EndUser, // Streams EndUser records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamEndUser(params *ListEndUserParams) (chan NumbersV2EndUser, chan error) { + return c.StreamEndUserWithContext(context.TODO(), params) +} + +// Streams EndUser records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamEndUserWithContext(ctx context.Context, params *ListEndUserParams) (chan NumbersV2EndUser, chan error) { if params == nil { params = &ListEndUserParams{} } @@ -209,19 +234,19 @@ func (c *ApiService) StreamEndUser(params *ListEndUserParams) (chan NumbersV2End recordChannel := make(chan NumbersV2EndUser, 1) errorChannel := make(chan error, 1) - response, err := c.PageEndUser(params, "", "") + response, err := c.PageEndUserWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamEndUser(response, params, recordChannel, errorChannel) + go c.streamEndUserWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamEndUser(response *ListEndUserResponse, params *ListEndUserParams, recordChannel chan NumbersV2EndUser, errorChannel chan error) { +func (c *ApiService) streamEndUserWithContext(ctx context.Context, response *ListEndUserResponse, params *ListEndUserParams, recordChannel chan NumbersV2EndUser, errorChannel chan error) { curRecord := 1 for response != nil { @@ -236,7 +261,7 @@ func (c *ApiService) streamEndUser(response *ListEndUserResponse, params *ListEn } } - record, err := client.GetNext(c.baseURL, response, c.getNextListEndUserResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListEndUserResponseWithContext) if err != nil { errorChannel <- err break @@ -251,11 +276,11 @@ func (c *ApiService) streamEndUser(response *ListEndUserResponse, params *ListEn close(errorChannel) } -func (c *ApiService) getNextListEndUserResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListEndUserResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -288,6 +313,9 @@ func (params *UpdateEndUserParams) SetAttributes(Attributes map[string]interface // Update an existing End User. func (c *ApiService) UpdateEndUser(Sid string, params *UpdateEndUserParams) (*NumbersV2EndUser, error) { + return c.UpdateEndUserWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateEndUserWithContext(ctx context.Context, Sid string, params *UpdateEndUserParams) (*NumbersV2EndUser, error) { path := "/v2/RegulatoryCompliance/EndUsers/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -309,7 +337,7 @@ func (c *ApiService) UpdateEndUser(Sid string, params *UpdateEndUserParams) (*Nu data.Set("Attributes", string(v)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/numbers/v2/regulatory_compliance_regulations.go b/rest/numbers/v2/regulatory_compliance_regulations.go index e060cc4ca..f7b03ca49 100644 --- a/rest/numbers/v2/regulatory_compliance_regulations.go +++ b/rest/numbers/v2/regulatory_compliance_regulations.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -36,6 +37,9 @@ func (params *FetchRegulationParams) SetIncludeConstraints(IncludeConstraints bo // Fetch specific Regulation Instance. func (c *ApiService) FetchRegulation(Sid string, params *FetchRegulationParams) (*NumbersV2Regulation, error) { + return c.FetchRegulationWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) FetchRegulationWithContext(ctx context.Context, Sid string, params *FetchRegulationParams) (*NumbersV2Regulation, error) { path := "/v2/RegulatoryCompliance/Regulations/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -48,7 +52,7 @@ func (c *ApiService) FetchRegulation(Sid string, params *FetchRegulationParams) data.Set("IncludeConstraints", fmt.Sprint(*params.IncludeConstraints)) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -106,6 +110,11 @@ func (params *ListRegulationParams) SetLimit(Limit int) *ListRegulationParams { // Retrieve a single page of Regulation records from the API. Request is executed immediately. func (c *ApiService) PageRegulation(params *ListRegulationParams, pageToken, pageNumber string) (*ListRegulationResponse, error) { + return c.PageRegulationWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Regulation records from the API. Request is executed immediately. +func (c *ApiService) PageRegulationWithContext(ctx context.Context, params *ListRegulationParams, pageToken, pageNumber string) (*ListRegulationResponse, error) { path := "/v2/RegulatoryCompliance/Regulations" data := url.Values{} @@ -136,7 +145,7 @@ func (c *ApiService) PageRegulation(params *ListRegulationParams, pageToken, pag data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -153,7 +162,12 @@ func (c *ApiService) PageRegulation(params *ListRegulationParams, pageToken, pag // Lists Regulation records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListRegulation(params *ListRegulationParams) ([]NumbersV2Regulation, error) { - response, errors := c.StreamRegulation(params) + return c.ListRegulationWithContext(context.TODO(), params) +} + +// Lists Regulation records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListRegulationWithContext(ctx context.Context, params *ListRegulationParams) ([]NumbersV2Regulation, error) { + response, errors := c.StreamRegulationWithContext(ctx, params) records := make([]NumbersV2Regulation, 0) for record := range response { @@ -169,6 +183,11 @@ func (c *ApiService) ListRegulation(params *ListRegulationParams) ([]NumbersV2Re // Streams Regulation records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamRegulation(params *ListRegulationParams) (chan NumbersV2Regulation, chan error) { + return c.StreamRegulationWithContext(context.TODO(), params) +} + +// Streams Regulation records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamRegulationWithContext(ctx context.Context, params *ListRegulationParams) (chan NumbersV2Regulation, chan error) { if params == nil { params = &ListRegulationParams{} } @@ -177,19 +196,19 @@ func (c *ApiService) StreamRegulation(params *ListRegulationParams) (chan Number recordChannel := make(chan NumbersV2Regulation, 1) errorChannel := make(chan error, 1) - response, err := c.PageRegulation(params, "", "") + response, err := c.PageRegulationWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamRegulation(response, params, recordChannel, errorChannel) + go c.streamRegulationWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamRegulation(response *ListRegulationResponse, params *ListRegulationParams, recordChannel chan NumbersV2Regulation, errorChannel chan error) { +func (c *ApiService) streamRegulationWithContext(ctx context.Context, response *ListRegulationResponse, params *ListRegulationParams, recordChannel chan NumbersV2Regulation, errorChannel chan error) { curRecord := 1 for response != nil { @@ -204,7 +223,7 @@ func (c *ApiService) streamRegulation(response *ListRegulationResponse, params * } } - record, err := client.GetNext(c.baseURL, response, c.getNextListRegulationResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListRegulationResponseWithContext) if err != nil { errorChannel <- err break @@ -219,11 +238,11 @@ func (c *ApiService) streamRegulation(response *ListRegulationResponse, params * close(errorChannel) } -func (c *ApiService) getNextListRegulationResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListRegulationResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/numbers/v2/regulatory_compliance_supporting_document_types.go b/rest/numbers/v2/regulatory_compliance_supporting_document_types.go index 7c6653ce8..90b2a272b 100644 --- a/rest/numbers/v2/regulatory_compliance_supporting_document_types.go +++ b/rest/numbers/v2/regulatory_compliance_supporting_document_types.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -25,6 +26,9 @@ import ( // Fetch a specific Supporting Document Type Instance. func (c *ApiService) FetchSupportingDocumentType(Sid string) (*NumbersV2SupportingDocumentType, error) { + return c.FetchSupportingDocumentTypeWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchSupportingDocumentTypeWithContext(ctx context.Context, Sid string) (*NumbersV2SupportingDocumentType, error) { path := "/v2/RegulatoryCompliance/SupportingDocumentTypes/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -33,7 +37,7 @@ func (c *ApiService) FetchSupportingDocumentType(Sid string) (*NumbersV2Supporti "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -67,6 +71,11 @@ func (params *ListSupportingDocumentTypeParams) SetLimit(Limit int) *ListSupport // Retrieve a single page of SupportingDocumentType records from the API. Request is executed immediately. func (c *ApiService) PageSupportingDocumentType(params *ListSupportingDocumentTypeParams, pageToken, pageNumber string) (*ListSupportingDocumentTypeResponse, error) { + return c.PageSupportingDocumentTypeWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of SupportingDocumentType records from the API. Request is executed immediately. +func (c *ApiService) PageSupportingDocumentTypeWithContext(ctx context.Context, params *ListSupportingDocumentTypeParams, pageToken, pageNumber string) (*ListSupportingDocumentTypeResponse, error) { path := "/v2/RegulatoryCompliance/SupportingDocumentTypes" data := url.Values{} @@ -85,7 +94,7 @@ func (c *ApiService) PageSupportingDocumentType(params *ListSupportingDocumentTy data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -102,7 +111,12 @@ func (c *ApiService) PageSupportingDocumentType(params *ListSupportingDocumentTy // Lists SupportingDocumentType records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListSupportingDocumentType(params *ListSupportingDocumentTypeParams) ([]NumbersV2SupportingDocumentType, error) { - response, errors := c.StreamSupportingDocumentType(params) + return c.ListSupportingDocumentTypeWithContext(context.TODO(), params) +} + +// Lists SupportingDocumentType records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListSupportingDocumentTypeWithContext(ctx context.Context, params *ListSupportingDocumentTypeParams) ([]NumbersV2SupportingDocumentType, error) { + response, errors := c.StreamSupportingDocumentTypeWithContext(ctx, params) records := make([]NumbersV2SupportingDocumentType, 0) for record := range response { @@ -118,6 +132,11 @@ func (c *ApiService) ListSupportingDocumentType(params *ListSupportingDocumentTy // Streams SupportingDocumentType records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamSupportingDocumentType(params *ListSupportingDocumentTypeParams) (chan NumbersV2SupportingDocumentType, chan error) { + return c.StreamSupportingDocumentTypeWithContext(context.TODO(), params) +} + +// Streams SupportingDocumentType records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamSupportingDocumentTypeWithContext(ctx context.Context, params *ListSupportingDocumentTypeParams) (chan NumbersV2SupportingDocumentType, chan error) { if params == nil { params = &ListSupportingDocumentTypeParams{} } @@ -126,19 +145,19 @@ func (c *ApiService) StreamSupportingDocumentType(params *ListSupportingDocument recordChannel := make(chan NumbersV2SupportingDocumentType, 1) errorChannel := make(chan error, 1) - response, err := c.PageSupportingDocumentType(params, "", "") + response, err := c.PageSupportingDocumentTypeWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSupportingDocumentType(response, params, recordChannel, errorChannel) + go c.streamSupportingDocumentTypeWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamSupportingDocumentType(response *ListSupportingDocumentTypeResponse, params *ListSupportingDocumentTypeParams, recordChannel chan NumbersV2SupportingDocumentType, errorChannel chan error) { +func (c *ApiService) streamSupportingDocumentTypeWithContext(ctx context.Context, response *ListSupportingDocumentTypeResponse, params *ListSupportingDocumentTypeParams, recordChannel chan NumbersV2SupportingDocumentType, errorChannel chan error) { curRecord := 1 for response != nil { @@ -153,7 +172,7 @@ func (c *ApiService) streamSupportingDocumentType(response *ListSupportingDocume } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSupportingDocumentTypeResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListSupportingDocumentTypeResponseWithContext) if err != nil { errorChannel <- err break @@ -168,11 +187,11 @@ func (c *ApiService) streamSupportingDocumentType(response *ListSupportingDocume close(errorChannel) } -func (c *ApiService) getNextListSupportingDocumentTypeResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSupportingDocumentTypeResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/numbers/v2/regulatory_compliance_supporting_documents.go b/rest/numbers/v2/regulatory_compliance_supporting_documents.go index 6bb364cd5..655c3a363 100644 --- a/rest/numbers/v2/regulatory_compliance_supporting_documents.go +++ b/rest/numbers/v2/regulatory_compliance_supporting_documents.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -48,6 +49,9 @@ func (params *CreateSupportingDocumentParams) SetAttributes(Attributes map[strin // Create a new Supporting Document. func (c *ApiService) CreateSupportingDocument(params *CreateSupportingDocumentParams) (*NumbersV2SupportingDocument, error) { + return c.CreateSupportingDocumentWithContext(context.TODO(), params) +} +func (c *ApiService) CreateSupportingDocumentWithContext(ctx context.Context, params *CreateSupportingDocumentParams) (*NumbersV2SupportingDocument, error) { path := "/v2/RegulatoryCompliance/SupportingDocuments" data := url.Values{} @@ -71,7 +75,7 @@ func (c *ApiService) CreateSupportingDocument(params *CreateSupportingDocumentPa data.Set("Attributes", string(v)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -88,6 +92,9 @@ func (c *ApiService) CreateSupportingDocument(params *CreateSupportingDocumentPa // Delete a specific Supporting Document. func (c *ApiService) DeleteSupportingDocument(Sid string) error { + return c.DeleteSupportingDocumentWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteSupportingDocumentWithContext(ctx context.Context, Sid string) error { path := "/v2/RegulatoryCompliance/SupportingDocuments/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -96,7 +103,7 @@ func (c *ApiService) DeleteSupportingDocument(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -108,6 +115,9 @@ func (c *ApiService) DeleteSupportingDocument(Sid string) error { // Fetch specific Supporting Document Instance. func (c *ApiService) FetchSupportingDocument(Sid string) (*NumbersV2SupportingDocument, error) { + return c.FetchSupportingDocumentWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchSupportingDocumentWithContext(ctx context.Context, Sid string) (*NumbersV2SupportingDocument, error) { path := "/v2/RegulatoryCompliance/SupportingDocuments/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -116,7 +126,7 @@ func (c *ApiService) FetchSupportingDocument(Sid string) (*NumbersV2SupportingDo "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -150,6 +160,11 @@ func (params *ListSupportingDocumentParams) SetLimit(Limit int) *ListSupportingD // Retrieve a single page of SupportingDocument records from the API. Request is executed immediately. func (c *ApiService) PageSupportingDocument(params *ListSupportingDocumentParams, pageToken, pageNumber string) (*ListSupportingDocumentResponse, error) { + return c.PageSupportingDocumentWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of SupportingDocument records from the API. Request is executed immediately. +func (c *ApiService) PageSupportingDocumentWithContext(ctx context.Context, params *ListSupportingDocumentParams, pageToken, pageNumber string) (*ListSupportingDocumentResponse, error) { path := "/v2/RegulatoryCompliance/SupportingDocuments" data := url.Values{} @@ -168,7 +183,7 @@ func (c *ApiService) PageSupportingDocument(params *ListSupportingDocumentParams data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -185,7 +200,12 @@ func (c *ApiService) PageSupportingDocument(params *ListSupportingDocumentParams // Lists SupportingDocument records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListSupportingDocument(params *ListSupportingDocumentParams) ([]NumbersV2SupportingDocument, error) { - response, errors := c.StreamSupportingDocument(params) + return c.ListSupportingDocumentWithContext(context.TODO(), params) +} + +// Lists SupportingDocument records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListSupportingDocumentWithContext(ctx context.Context, params *ListSupportingDocumentParams) ([]NumbersV2SupportingDocument, error) { + response, errors := c.StreamSupportingDocumentWithContext(ctx, params) records := make([]NumbersV2SupportingDocument, 0) for record := range response { @@ -201,6 +221,11 @@ func (c *ApiService) ListSupportingDocument(params *ListSupportingDocumentParams // Streams SupportingDocument records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamSupportingDocument(params *ListSupportingDocumentParams) (chan NumbersV2SupportingDocument, chan error) { + return c.StreamSupportingDocumentWithContext(context.TODO(), params) +} + +// Streams SupportingDocument records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamSupportingDocumentWithContext(ctx context.Context, params *ListSupportingDocumentParams) (chan NumbersV2SupportingDocument, chan error) { if params == nil { params = &ListSupportingDocumentParams{} } @@ -209,19 +234,19 @@ func (c *ApiService) StreamSupportingDocument(params *ListSupportingDocumentPara recordChannel := make(chan NumbersV2SupportingDocument, 1) errorChannel := make(chan error, 1) - response, err := c.PageSupportingDocument(params, "", "") + response, err := c.PageSupportingDocumentWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSupportingDocument(response, params, recordChannel, errorChannel) + go c.streamSupportingDocumentWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamSupportingDocument(response *ListSupportingDocumentResponse, params *ListSupportingDocumentParams, recordChannel chan NumbersV2SupportingDocument, errorChannel chan error) { +func (c *ApiService) streamSupportingDocumentWithContext(ctx context.Context, response *ListSupportingDocumentResponse, params *ListSupportingDocumentParams, recordChannel chan NumbersV2SupportingDocument, errorChannel chan error) { curRecord := 1 for response != nil { @@ -236,7 +261,7 @@ func (c *ApiService) streamSupportingDocument(response *ListSupportingDocumentRe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSupportingDocumentResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListSupportingDocumentResponseWithContext) if err != nil { errorChannel <- err break @@ -251,11 +276,11 @@ func (c *ApiService) streamSupportingDocument(response *ListSupportingDocumentRe close(errorChannel) } -func (c *ApiService) getNextListSupportingDocumentResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSupportingDocumentResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -288,6 +313,9 @@ func (params *UpdateSupportingDocumentParams) SetAttributes(Attributes map[strin // Update an existing Supporting Document. func (c *ApiService) UpdateSupportingDocument(Sid string, params *UpdateSupportingDocumentParams) (*NumbersV2SupportingDocument, error) { + return c.UpdateSupportingDocumentWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateSupportingDocumentWithContext(ctx context.Context, Sid string, params *UpdateSupportingDocumentParams) (*NumbersV2SupportingDocument, error) { path := "/v2/RegulatoryCompliance/SupportingDocuments/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -309,7 +337,7 @@ func (c *ApiService) UpdateSupportingDocument(Sid string, params *UpdateSupporti data.Set("Attributes", string(v)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/oauth/v1/api_service.go b/rest/oauth/v1/api_service.go index e452822bd..bd05e6128 100644 --- a/rest/oauth/v1/api_service.go +++ b/rest/oauth/v1/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://oauth.twilio.com", + } +} diff --git a/rest/oauth/v1/authorize.go b/rest/oauth/v1/authorize.go index ac809f114..59d21693f 100644 --- a/rest/oauth/v1/authorize.go +++ b/rest/oauth/v1/authorize.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" ) @@ -56,6 +57,9 @@ func (params *FetchAuthorizeParams) SetState(State string) *FetchAuthorizeParams // Retrieves authorize uri func (c *ApiService) FetchAuthorize(params *FetchAuthorizeParams) (*OauthV1Authorize, error) { + return c.FetchAuthorizeWithContext(context.TODO(), params) +} +func (c *ApiService) FetchAuthorizeWithContext(ctx context.Context, params *FetchAuthorizeParams) (*OauthV1Authorize, error) { path := "/v1/authorize" data := url.Values{} @@ -79,7 +83,7 @@ func (c *ApiService) FetchAuthorize(params *FetchAuthorizeParams) (*OauthV1Autho data.Set("State", *params.State) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/oauth/v1/token.go b/rest/oauth/v1/token.go index 14b540781..31452b653 100644 --- a/rest/oauth/v1/token.go +++ b/rest/oauth/v1/token.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" ) @@ -74,6 +75,9 @@ func (params *CreateTokenParams) SetScope(Scope string) *CreateTokenParams { // Issues a new Access token (optionally identity_token & refresh_token) in exchange of Oauth grant func (c *ApiService) CreateToken(params *CreateTokenParams) (*OauthV1Token, error) { + return c.CreateTokenWithContext(context.TODO(), params) +} +func (c *ApiService) CreateTokenWithContext(ctx context.Context, params *CreateTokenParams) (*OauthV1Token, error) { path := "/v1/token" data := url.Values{} @@ -106,7 +110,7 @@ func (c *ApiService) CreateToken(params *CreateTokenParams) (*OauthV1Token, erro data.Set("Scope", *params.Scope) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/preview_iam/organization/accounts.go b/rest/preview_iam/organization/accounts.go index c5056fc72..f26139d8f 100644 --- a/rest/preview_iam/organization/accounts.go +++ b/rest/preview_iam/organization/accounts.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -35,6 +36,9 @@ func (params *FetchOrganizationAccountParams) SetPathAccountSid(PathAccountSid s } func (c *ApiService) FetchOrganizationAccount(OrganizationSid string, params *FetchOrganizationAccountParams) (*PublicApiAccountResponse, error) { + return c.FetchOrganizationAccountWithContext(context.TODO(), OrganizationSid, params) +} +func (c *ApiService) FetchOrganizationAccountWithContext(ctx context.Context, OrganizationSid string, params *FetchOrganizationAccountParams) (*PublicApiAccountResponse, error) { path := "/Organizations/{OrganizationSid}/Accounts/{AccountSid}" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -48,7 +52,7 @@ func (c *ApiService) FetchOrganizationAccount(OrganizationSid string, params *Fe "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -82,6 +86,11 @@ func (params *ListOrganizationAccountsParams) SetLimit(Limit int) *ListOrganizat // Retrieve a single page of OrganizationAccounts records from the API. Request is executed immediately. func (c *ApiService) PageOrganizationAccounts(OrganizationSid string, params *ListOrganizationAccountsParams, pageToken, pageNumber string) (*PublicApiAccountResponsePage, error) { + return c.PageOrganizationAccountsWithContext(context.TODO(), OrganizationSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of OrganizationAccounts records from the API. Request is executed immediately. +func (c *ApiService) PageOrganizationAccountsWithContext(ctx context.Context, OrganizationSid string, params *ListOrganizationAccountsParams, pageToken, pageNumber string) (*PublicApiAccountResponsePage, error) { path := "/Organizations/{OrganizationSid}/Accounts" path = strings.Replace(path, "{"+"OrganizationSid"+"}", OrganizationSid, -1) @@ -102,7 +111,7 @@ func (c *ApiService) PageOrganizationAccounts(OrganizationSid string, params *Li data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -119,7 +128,12 @@ func (c *ApiService) PageOrganizationAccounts(OrganizationSid string, params *Li // Lists OrganizationAccounts records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListOrganizationAccounts(OrganizationSid string, params *ListOrganizationAccountsParams) ([]PublicApiAccountResponse, error) { - response, errors := c.StreamOrganizationAccounts(OrganizationSid, params) + return c.ListOrganizationAccountsWithContext(context.TODO(), OrganizationSid, params) +} + +// Lists OrganizationAccounts records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListOrganizationAccountsWithContext(ctx context.Context, OrganizationSid string, params *ListOrganizationAccountsParams) ([]PublicApiAccountResponse, error) { + response, errors := c.StreamOrganizationAccountsWithContext(ctx, OrganizationSid, params) records := make([]PublicApiAccountResponse, 0) for record := range response { @@ -135,6 +149,11 @@ func (c *ApiService) ListOrganizationAccounts(OrganizationSid string, params *Li // Streams OrganizationAccounts records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamOrganizationAccounts(OrganizationSid string, params *ListOrganizationAccountsParams) (chan PublicApiAccountResponse, chan error) { + return c.StreamOrganizationAccountsWithContext(context.TODO(), OrganizationSid, params) +} + +// Streams OrganizationAccounts records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamOrganizationAccountsWithContext(ctx context.Context, OrganizationSid string, params *ListOrganizationAccountsParams) (chan PublicApiAccountResponse, chan error) { if params == nil { params = &ListOrganizationAccountsParams{} } @@ -143,19 +162,19 @@ func (c *ApiService) StreamOrganizationAccounts(OrganizationSid string, params * recordChannel := make(chan PublicApiAccountResponse, 1) errorChannel := make(chan error, 1) - response, err := c.PageOrganizationAccounts(OrganizationSid, params, "", "") + response, err := c.PageOrganizationAccountsWithContext(ctx, OrganizationSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamOrganizationAccounts(response, params, recordChannel, errorChannel) + go c.streamOrganizationAccountsWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamOrganizationAccounts(response *PublicApiAccountResponsePage, params *ListOrganizationAccountsParams, recordChannel chan PublicApiAccountResponse, errorChannel chan error) { +func (c *ApiService) streamOrganizationAccountsWithContext(ctx context.Context, response *PublicApiAccountResponsePage, params *ListOrganizationAccountsParams, recordChannel chan PublicApiAccountResponse, errorChannel chan error) { curRecord := 1 for response != nil { @@ -170,7 +189,7 @@ func (c *ApiService) streamOrganizationAccounts(response *PublicApiAccountRespon } } - record, err := client.GetNext(c.baseURL, response, c.getNextPublicApiAccountResponsePage) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextPublicApiAccountResponsePageWithContext) if err != nil { errorChannel <- err break @@ -185,11 +204,11 @@ func (c *ApiService) streamOrganizationAccounts(response *PublicApiAccountRespon close(errorChannel) } -func (c *ApiService) getNextPublicApiAccountResponsePage(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextPublicApiAccountResponsePageWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/preview_iam/organization/api_service.go b/rest/preview_iam/organization/api_service.go index 1bc0d62b4..3bb97633d 100644 --- a/rest/preview_iam/organization/api_service.go +++ b/rest/preview_iam/organization/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://preview-iam.twilio.com", + } +} diff --git a/rest/preview_iam/organization/organization.go b/rest/preview_iam/organization/organization.go index 8f9191fda..11d0f9d79 100644 --- a/rest/preview_iam/organization/organization.go +++ b/rest/preview_iam/organization/organization.go @@ -15,11 +15,15 @@ package openapi import ( + "context" "net/url" "strings" ) func (c *ApiService) FetchOrganization(OrganizationSid string) error { + return c.FetchOrganizationWithContext(context.TODO(), OrganizationSid) +} +func (c *ApiService) FetchOrganizationWithContext(ctx context.Context, OrganizationSid string) error { path := "/Organizations/{OrganizationSid}" path = strings.Replace(path, "{"+"OrganizationSid"+"}", OrganizationSid, -1) @@ -28,7 +32,7 @@ func (c *ApiService) FetchOrganization(OrganizationSid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } diff --git a/rest/preview_iam/organization/role_assignments.go b/rest/preview_iam/organization/role_assignments.go index 689da651a..f3e8d64b8 100644 --- a/rest/preview_iam/organization/role_assignments.go +++ b/rest/preview_iam/organization/role_assignments.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -36,6 +37,9 @@ func (params *CreateRoleAssignmentParams) SetPublicApiCreateRoleAssignmentReques // Create a role assignment for the given organization func (c *ApiService) CreateRoleAssignment(OrganizationSid string, params *CreateRoleAssignmentParams) (*PublicApiRoleAssignmentResponse, error) { + return c.CreateRoleAssignmentWithContext(context.TODO(), OrganizationSid, params) +} +func (c *ApiService) CreateRoleAssignmentWithContext(ctx context.Context, OrganizationSid string, params *CreateRoleAssignmentParams) (*PublicApiRoleAssignmentResponse, error) { path := "/Organizations/{OrganizationSid}/RoleAssignments" path = strings.Replace(path, "{"+"OrganizationSid"+"}", OrganizationSid, -1) @@ -53,7 +57,7 @@ func (c *ApiService) CreateRoleAssignment(OrganizationSid string, params *Create body = b } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers, body...) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers, body...) if err != nil { return nil, err } @@ -70,6 +74,9 @@ func (c *ApiService) CreateRoleAssignment(OrganizationSid string, params *Create // Delete a role assignment for the given organization func (c *ApiService) DeleteRoleAssignment(OrganizationSid string, Sid string) error { + return c.DeleteRoleAssignmentWithContext(context.TODO(), OrganizationSid, Sid) +} +func (c *ApiService) DeleteRoleAssignmentWithContext(ctx context.Context, OrganizationSid string, Sid string) error { path := "/Organizations/{OrganizationSid}/RoleAssignments/{Sid}" path = strings.Replace(path, "{"+"OrganizationSid"+"}", OrganizationSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -79,7 +86,7 @@ func (c *ApiService) DeleteRoleAssignment(OrganizationSid string, Sid string) er "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -120,6 +127,11 @@ func (params *ListRoleAssignmentsParams) SetLimit(Limit int) *ListRoleAssignment // Retrieve a single page of RoleAssignments records from the API. Request is executed immediately. func (c *ApiService) PageRoleAssignments(OrganizationSid string, params *ListRoleAssignmentsParams, pageToken, pageNumber string) (*PublicApiCreateRoleAssignmentResponsePage, error) { + return c.PageRoleAssignmentsWithContext(context.TODO(), OrganizationSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of RoleAssignments records from the API. Request is executed immediately. +func (c *ApiService) PageRoleAssignmentsWithContext(ctx context.Context, OrganizationSid string, params *ListRoleAssignmentsParams, pageToken, pageNumber string) (*PublicApiCreateRoleAssignmentResponsePage, error) { path := "/Organizations/{OrganizationSid}/RoleAssignments" path = strings.Replace(path, "{"+"OrganizationSid"+"}", OrganizationSid, -1) @@ -146,7 +158,7 @@ func (c *ApiService) PageRoleAssignments(OrganizationSid string, params *ListRol data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -163,7 +175,12 @@ func (c *ApiService) PageRoleAssignments(OrganizationSid string, params *ListRol // Lists RoleAssignments records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListRoleAssignments(OrganizationSid string, params *ListRoleAssignmentsParams) ([]PublicApiRoleAssignmentResponse, error) { - response, errors := c.StreamRoleAssignments(OrganizationSid, params) + return c.ListRoleAssignmentsWithContext(context.TODO(), OrganizationSid, params) +} + +// Lists RoleAssignments records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListRoleAssignmentsWithContext(ctx context.Context, OrganizationSid string, params *ListRoleAssignmentsParams) ([]PublicApiRoleAssignmentResponse, error) { + response, errors := c.StreamRoleAssignmentsWithContext(ctx, OrganizationSid, params) records := make([]PublicApiRoleAssignmentResponse, 0) for record := range response { @@ -179,6 +196,11 @@ func (c *ApiService) ListRoleAssignments(OrganizationSid string, params *ListRol // Streams RoleAssignments records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamRoleAssignments(OrganizationSid string, params *ListRoleAssignmentsParams) (chan PublicApiRoleAssignmentResponse, chan error) { + return c.StreamRoleAssignmentsWithContext(context.TODO(), OrganizationSid, params) +} + +// Streams RoleAssignments records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamRoleAssignmentsWithContext(ctx context.Context, OrganizationSid string, params *ListRoleAssignmentsParams) (chan PublicApiRoleAssignmentResponse, chan error) { if params == nil { params = &ListRoleAssignmentsParams{} } @@ -187,19 +209,19 @@ func (c *ApiService) StreamRoleAssignments(OrganizationSid string, params *ListR recordChannel := make(chan PublicApiRoleAssignmentResponse, 1) errorChannel := make(chan error, 1) - response, err := c.PageRoleAssignments(OrganizationSid, params, "", "") + response, err := c.PageRoleAssignmentsWithContext(ctx, OrganizationSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamRoleAssignments(response, params, recordChannel, errorChannel) + go c.streamRoleAssignmentsWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamRoleAssignments(response *PublicApiCreateRoleAssignmentResponsePage, params *ListRoleAssignmentsParams, recordChannel chan PublicApiRoleAssignmentResponse, errorChannel chan error) { +func (c *ApiService) streamRoleAssignmentsWithContext(ctx context.Context, response *PublicApiCreateRoleAssignmentResponsePage, params *ListRoleAssignmentsParams, recordChannel chan PublicApiRoleAssignmentResponse, errorChannel chan error) { curRecord := 1 for response != nil { @@ -214,7 +236,7 @@ func (c *ApiService) streamRoleAssignments(response *PublicApiCreateRoleAssignme } } - record, err := client.GetNext(c.baseURL, response, c.getNextPublicApiCreateRoleAssignmentResponsePage) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextPublicApiCreateRoleAssignmentResponsePageWithContext) if err != nil { errorChannel <- err break @@ -229,11 +251,11 @@ func (c *ApiService) streamRoleAssignments(response *PublicApiCreateRoleAssignme close(errorChannel) } -func (c *ApiService) getNextPublicApiCreateRoleAssignmentResponsePage(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextPublicApiCreateRoleAssignmentResponsePageWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/preview_iam/organization/scim_users.go b/rest/preview_iam/organization/scim_users.go index 6cff19371..503892fd2 100644 --- a/rest/preview_iam/organization/scim_users.go +++ b/rest/preview_iam/organization/scim_users.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -35,6 +36,9 @@ func (params *CreateOrganizationUserParams) SetScimUser(ScimUser ScimUser) *Crea } func (c *ApiService) CreateOrganizationUser(OrganizationSid string, params *CreateOrganizationUserParams) (*ScimUser, error) { + return c.CreateOrganizationUserWithContext(context.TODO(), OrganizationSid, params) +} +func (c *ApiService) CreateOrganizationUserWithContext(ctx context.Context, OrganizationSid string, params *CreateOrganizationUserParams) (*ScimUser, error) { path := "/Organizations/{OrganizationSid}/scim/Users" path = strings.Replace(path, "{"+"OrganizationSid"+"}", OrganizationSid, -1) @@ -52,7 +56,7 @@ func (c *ApiService) CreateOrganizationUser(OrganizationSid string, params *Crea body = b } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers, body...) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers, body...) if err != nil { return nil, err } @@ -68,6 +72,9 @@ func (c *ApiService) CreateOrganizationUser(OrganizationSid string, params *Crea } func (c *ApiService) DeleteOrganizationUser(OrganizationSid string, Id string) error { + return c.DeleteOrganizationUserWithContext(context.TODO(), OrganizationSid, Id) +} +func (c *ApiService) DeleteOrganizationUserWithContext(ctx context.Context, OrganizationSid string, Id string) error { path := "/Organizations/{OrganizationSid}/scim/Users/{Id}" path = strings.Replace(path, "{"+"OrganizationSid"+"}", OrganizationSid, -1) path = strings.Replace(path, "{"+"Id"+"}", Id, -1) @@ -77,7 +84,7 @@ func (c *ApiService) DeleteOrganizationUser(OrganizationSid string, Id string) e "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -88,6 +95,9 @@ func (c *ApiService) DeleteOrganizationUser(OrganizationSid string, Id string) e } func (c *ApiService) FetchOrganizationUser(OrganizationSid string, Id string) (*ScimUser, error) { + return c.FetchOrganizationUserWithContext(context.TODO(), OrganizationSid, Id) +} +func (c *ApiService) FetchOrganizationUserWithContext(ctx context.Context, OrganizationSid string, Id string) (*ScimUser, error) { path := "/Organizations/{OrganizationSid}/scim/Users/{Id}" path = strings.Replace(path, "{"+"OrganizationSid"+"}", OrganizationSid, -1) path = strings.Replace(path, "{"+"Id"+"}", Id, -1) @@ -97,7 +107,7 @@ func (c *ApiService) FetchOrganizationUser(OrganizationSid string, Id string) (* "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -137,6 +147,11 @@ func (params *ListOrganizationUsersParams) SetPageSize(PageSize int) *ListOrgani // Retrieve a single page of OrganizationUsers records from the API. Request is executed immediately. func (c *ApiService) PageOrganizationUsers(OrganizationSid string, params *ListOrganizationUsersParams, pageToken, pageNumber string) (*ScimUserPage, error) { + return c.PageOrganizationUsersWithContext(context.TODO(), OrganizationSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of OrganizationUsers records from the API. Request is executed immediately. +func (c *ApiService) PageOrganizationUsersWithContext(ctx context.Context, OrganizationSid string, params *ListOrganizationUsersParams, pageToken, pageNumber string) (*ScimUserPage, error) { path := "/Organizations/{OrganizationSid}/scim/Users" path = strings.Replace(path, "{"+"OrganizationSid"+"}", OrganizationSid, -1) @@ -160,7 +175,7 @@ func (c *ApiService) PageOrganizationUsers(OrganizationSid string, params *ListO data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -177,7 +192,12 @@ func (c *ApiService) PageOrganizationUsers(OrganizationSid string, params *ListO // Lists OrganizationUsers records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListOrganizationUsers(OrganizationSid string, params *ListOrganizationUsersParams) ([]ScimUser, error) { - response, errors := c.StreamOrganizationUsers(OrganizationSid, params) + return c.ListOrganizationUsersWithContext(context.TODO(), OrganizationSid, params) +} + +// Lists OrganizationUsers records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListOrganizationUsersWithContext(ctx context.Context, OrganizationSid string, params *ListOrganizationUsersParams) ([]ScimUser, error) { + response, errors := c.StreamOrganizationUsersWithContext(ctx, OrganizationSid, params) records := make([]ScimUser, 0) for record := range response { @@ -193,6 +213,11 @@ func (c *ApiService) ListOrganizationUsers(OrganizationSid string, params *ListO // Streams OrganizationUsers records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamOrganizationUsers(OrganizationSid string, params *ListOrganizationUsersParams) (chan ScimUser, chan error) { + return c.StreamOrganizationUsersWithContext(context.TODO(), OrganizationSid, params) +} + +// Streams OrganizationUsers records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamOrganizationUsersWithContext(ctx context.Context, OrganizationSid string, params *ListOrganizationUsersParams) (chan ScimUser, chan error) { if params == nil { params = &ListOrganizationUsersParams{} } @@ -201,19 +226,19 @@ func (c *ApiService) StreamOrganizationUsers(OrganizationSid string, params *Lis recordChannel := make(chan ScimUser, 1) errorChannel := make(chan error, 1) - response, err := c.PageOrganizationUsers(OrganizationSid, params, "", "") + response, err := c.PageOrganizationUsersWithContext(ctx, OrganizationSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamOrganizationUsers(response, params, recordChannel, errorChannel) + go c.streamOrganizationUsersWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamOrganizationUsers(response *ScimUserPage, params *ListOrganizationUsersParams, recordChannel chan ScimUser, errorChannel chan error) { +func (c *ApiService) streamOrganizationUsersWithContext(ctx context.Context, response *ScimUserPage, params *ListOrganizationUsersParams, recordChannel chan ScimUser, errorChannel chan error) { curRecord := 1 for response != nil { @@ -228,7 +253,7 @@ func (c *ApiService) streamOrganizationUsers(response *ScimUserPage, params *Lis } } - record, err := client.GetNext(c.baseURL, response, c.getNextScimUserPage) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextScimUserPageWithContext) if err != nil { errorChannel <- err break @@ -243,11 +268,11 @@ func (c *ApiService) streamOrganizationUsers(response *ScimUserPage, params *Lis close(errorChannel) } -func (c *ApiService) getNextScimUserPage(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextScimUserPageWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -279,6 +304,9 @@ func (params *UpdateOrganizationUserParams) SetScimUser(ScimUser ScimUser) *Upda } func (c *ApiService) UpdateOrganizationUser(OrganizationSid string, Id string, params *UpdateOrganizationUserParams) (*ScimUser, error) { + return c.UpdateOrganizationUserWithContext(context.TODO(), OrganizationSid, Id, params) +} +func (c *ApiService) UpdateOrganizationUserWithContext(ctx context.Context, OrganizationSid string, Id string, params *UpdateOrganizationUserParams) (*ScimUser, error) { path := "/Organizations/{OrganizationSid}/scim/Users/{Id}" path = strings.Replace(path, "{"+"OrganizationSid"+"}", OrganizationSid, -1) path = strings.Replace(path, "{"+"Id"+"}", Id, -1) @@ -300,7 +328,7 @@ func (c *ApiService) UpdateOrganizationUser(OrganizationSid string, Id string, p if params != nil && params.IfMatch != nil { headers["If-Match"] = *params.IfMatch } - resp, err := c.requestHandler.Put(c.baseURL+path, data, headers, body...) + resp, err := c.requestHandler.PutWithContext(ctx, c.baseURL+path, data, headers, body...) if err != nil { return nil, err } diff --git a/rest/preview_iam/v1/api_service.go b/rest/preview_iam/v1/api_service.go index 1bc0d62b4..3bb97633d 100644 --- a/rest/preview_iam/v1/api_service.go +++ b/rest/preview_iam/v1/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://preview-iam.twilio.com", + } +} diff --git a/rest/preview_iam/v1/authorize.go b/rest/preview_iam/v1/authorize.go index bddba9103..9acaf5713 100644 --- a/rest/preview_iam/v1/authorize.go +++ b/rest/preview_iam/v1/authorize.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" ) @@ -55,6 +56,9 @@ func (params *FetchAuthorizeParams) SetState(State string) *FetchAuthorizeParams } func (c *ApiService) FetchAuthorize(params *FetchAuthorizeParams) (*OauthV1Authorize, error) { + return c.FetchAuthorizeWithContext(context.TODO(), params) +} +func (c *ApiService) FetchAuthorizeWithContext(ctx context.Context, params *FetchAuthorizeParams) (*OauthV1Authorize, error) { path := "/v1/authorize" data := url.Values{} @@ -78,7 +82,7 @@ func (c *ApiService) FetchAuthorize(params *FetchAuthorizeParams) (*OauthV1Autho data.Set("state", *params.State) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/preview_iam/v1/token.go b/rest/preview_iam/v1/token.go index 22d93f839..5111578ca 100644 --- a/rest/preview_iam/v1/token.go +++ b/rest/preview_iam/v1/token.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" ) @@ -73,6 +74,9 @@ func (params *CreateTokenParams) SetScope(Scope string) *CreateTokenParams { } func (c *ApiService) CreateToken(params *CreateTokenParams) (*OauthV1Token, error) { + return c.CreateTokenWithContext(context.TODO(), params) +} +func (c *ApiService) CreateTokenWithContext(ctx context.Context, params *CreateTokenParams) (*OauthV1Token, error) { path := "/v1/token" data := url.Values{} @@ -105,7 +109,7 @@ func (c *ApiService) CreateToken(params *CreateTokenParams) (*OauthV1Token, erro data.Set("scope", *params.Scope) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/pricing/v1/api_service.go b/rest/pricing/v1/api_service.go index 6f1c4551a..43756bf04 100644 --- a/rest/pricing/v1/api_service.go +++ b/rest/pricing/v1/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://pricing.twilio.com", + } +} diff --git a/rest/pricing/v1/messaging_countries.go b/rest/pricing/v1/messaging_countries.go index 623db10b8..c11242612 100644 --- a/rest/pricing/v1/messaging_countries.go +++ b/rest/pricing/v1/messaging_countries.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -23,8 +24,10 @@ import ( "github.com/twilio/twilio-go/client" ) -// func (c *ApiService) FetchMessagingCountry(IsoCountry string) (*PricingV1MessagingCountryInstance, error) { + return c.FetchMessagingCountryWithContext(context.TODO(), IsoCountry) +} +func (c *ApiService) FetchMessagingCountryWithContext(ctx context.Context, IsoCountry string) (*PricingV1MessagingCountryInstance, error) { path := "/v1/Messaging/Countries/{IsoCountry}" path = strings.Replace(path, "{"+"IsoCountry"+"}", IsoCountry, -1) @@ -33,7 +36,7 @@ func (c *ApiService) FetchMessagingCountry(IsoCountry string) (*PricingV1Messagi "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -67,6 +70,11 @@ func (params *ListMessagingCountryParams) SetLimit(Limit int) *ListMessagingCoun // Retrieve a single page of MessagingCountry records from the API. Request is executed immediately. func (c *ApiService) PageMessagingCountry(params *ListMessagingCountryParams, pageToken, pageNumber string) (*ListMessagingCountryResponse, error) { + return c.PageMessagingCountryWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of MessagingCountry records from the API. Request is executed immediately. +func (c *ApiService) PageMessagingCountryWithContext(ctx context.Context, params *ListMessagingCountryParams, pageToken, pageNumber string) (*ListMessagingCountryResponse, error) { path := "/v1/Messaging/Countries" data := url.Values{} @@ -85,7 +93,7 @@ func (c *ApiService) PageMessagingCountry(params *ListMessagingCountryParams, pa data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -102,7 +110,12 @@ func (c *ApiService) PageMessagingCountry(params *ListMessagingCountryParams, pa // Lists MessagingCountry records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListMessagingCountry(params *ListMessagingCountryParams) ([]PricingV1MessagingCountry, error) { - response, errors := c.StreamMessagingCountry(params) + return c.ListMessagingCountryWithContext(context.TODO(), params) +} + +// Lists MessagingCountry records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListMessagingCountryWithContext(ctx context.Context, params *ListMessagingCountryParams) ([]PricingV1MessagingCountry, error) { + response, errors := c.StreamMessagingCountryWithContext(ctx, params) records := make([]PricingV1MessagingCountry, 0) for record := range response { @@ -118,6 +131,11 @@ func (c *ApiService) ListMessagingCountry(params *ListMessagingCountryParams) ([ // Streams MessagingCountry records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamMessagingCountry(params *ListMessagingCountryParams) (chan PricingV1MessagingCountry, chan error) { + return c.StreamMessagingCountryWithContext(context.TODO(), params) +} + +// Streams MessagingCountry records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamMessagingCountryWithContext(ctx context.Context, params *ListMessagingCountryParams) (chan PricingV1MessagingCountry, chan error) { if params == nil { params = &ListMessagingCountryParams{} } @@ -126,19 +144,19 @@ func (c *ApiService) StreamMessagingCountry(params *ListMessagingCountryParams) recordChannel := make(chan PricingV1MessagingCountry, 1) errorChannel := make(chan error, 1) - response, err := c.PageMessagingCountry(params, "", "") + response, err := c.PageMessagingCountryWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamMessagingCountry(response, params, recordChannel, errorChannel) + go c.streamMessagingCountryWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamMessagingCountry(response *ListMessagingCountryResponse, params *ListMessagingCountryParams, recordChannel chan PricingV1MessagingCountry, errorChannel chan error) { +func (c *ApiService) streamMessagingCountryWithContext(ctx context.Context, response *ListMessagingCountryResponse, params *ListMessagingCountryParams, recordChannel chan PricingV1MessagingCountry, errorChannel chan error) { curRecord := 1 for response != nil { @@ -153,7 +171,7 @@ func (c *ApiService) streamMessagingCountry(response *ListMessagingCountryRespon } } - record, err := client.GetNext(c.baseURL, response, c.getNextListMessagingCountryResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListMessagingCountryResponseWithContext) if err != nil { errorChannel <- err break @@ -168,11 +186,11 @@ func (c *ApiService) streamMessagingCountry(response *ListMessagingCountryRespon close(errorChannel) } -func (c *ApiService) getNextListMessagingCountryResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListMessagingCountryResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/pricing/v1/phone_numbers_countries.go b/rest/pricing/v1/phone_numbers_countries.go index ee3b5cba1..925153b00 100644 --- a/rest/pricing/v1/phone_numbers_countries.go +++ b/rest/pricing/v1/phone_numbers_countries.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -23,8 +24,10 @@ import ( "github.com/twilio/twilio-go/client" ) -// func (c *ApiService) FetchPhoneNumberCountry(IsoCountry string) (*PricingV1PhoneNumberCountryInstance, error) { + return c.FetchPhoneNumberCountryWithContext(context.TODO(), IsoCountry) +} +func (c *ApiService) FetchPhoneNumberCountryWithContext(ctx context.Context, IsoCountry string) (*PricingV1PhoneNumberCountryInstance, error) { path := "/v1/PhoneNumbers/Countries/{IsoCountry}" path = strings.Replace(path, "{"+"IsoCountry"+"}", IsoCountry, -1) @@ -33,7 +36,7 @@ func (c *ApiService) FetchPhoneNumberCountry(IsoCountry string) (*PricingV1Phone "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -67,6 +70,11 @@ func (params *ListPhoneNumberCountryParams) SetLimit(Limit int) *ListPhoneNumber // Retrieve a single page of PhoneNumberCountry records from the API. Request is executed immediately. func (c *ApiService) PagePhoneNumberCountry(params *ListPhoneNumberCountryParams, pageToken, pageNumber string) (*ListPhoneNumberCountryResponse, error) { + return c.PagePhoneNumberCountryWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of PhoneNumberCountry records from the API. Request is executed immediately. +func (c *ApiService) PagePhoneNumberCountryWithContext(ctx context.Context, params *ListPhoneNumberCountryParams, pageToken, pageNumber string) (*ListPhoneNumberCountryResponse, error) { path := "/v1/PhoneNumbers/Countries" data := url.Values{} @@ -85,7 +93,7 @@ func (c *ApiService) PagePhoneNumberCountry(params *ListPhoneNumberCountryParams data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -102,7 +110,12 @@ func (c *ApiService) PagePhoneNumberCountry(params *ListPhoneNumberCountryParams // Lists PhoneNumberCountry records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListPhoneNumberCountry(params *ListPhoneNumberCountryParams) ([]PricingV1PhoneNumberCountry, error) { - response, errors := c.StreamPhoneNumberCountry(params) + return c.ListPhoneNumberCountryWithContext(context.TODO(), params) +} + +// Lists PhoneNumberCountry records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListPhoneNumberCountryWithContext(ctx context.Context, params *ListPhoneNumberCountryParams) ([]PricingV1PhoneNumberCountry, error) { + response, errors := c.StreamPhoneNumberCountryWithContext(ctx, params) records := make([]PricingV1PhoneNumberCountry, 0) for record := range response { @@ -118,6 +131,11 @@ func (c *ApiService) ListPhoneNumberCountry(params *ListPhoneNumberCountryParams // Streams PhoneNumberCountry records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamPhoneNumberCountry(params *ListPhoneNumberCountryParams) (chan PricingV1PhoneNumberCountry, chan error) { + return c.StreamPhoneNumberCountryWithContext(context.TODO(), params) +} + +// Streams PhoneNumberCountry records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamPhoneNumberCountryWithContext(ctx context.Context, params *ListPhoneNumberCountryParams) (chan PricingV1PhoneNumberCountry, chan error) { if params == nil { params = &ListPhoneNumberCountryParams{} } @@ -126,19 +144,19 @@ func (c *ApiService) StreamPhoneNumberCountry(params *ListPhoneNumberCountryPara recordChannel := make(chan PricingV1PhoneNumberCountry, 1) errorChannel := make(chan error, 1) - response, err := c.PagePhoneNumberCountry(params, "", "") + response, err := c.PagePhoneNumberCountryWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamPhoneNumberCountry(response, params, recordChannel, errorChannel) + go c.streamPhoneNumberCountryWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamPhoneNumberCountry(response *ListPhoneNumberCountryResponse, params *ListPhoneNumberCountryParams, recordChannel chan PricingV1PhoneNumberCountry, errorChannel chan error) { +func (c *ApiService) streamPhoneNumberCountryWithContext(ctx context.Context, response *ListPhoneNumberCountryResponse, params *ListPhoneNumberCountryParams, recordChannel chan PricingV1PhoneNumberCountry, errorChannel chan error) { curRecord := 1 for response != nil { @@ -153,7 +171,7 @@ func (c *ApiService) streamPhoneNumberCountry(response *ListPhoneNumberCountryRe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListPhoneNumberCountryResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListPhoneNumberCountryResponseWithContext) if err != nil { errorChannel <- err break @@ -168,11 +186,11 @@ func (c *ApiService) streamPhoneNumberCountry(response *ListPhoneNumberCountryRe close(errorChannel) } -func (c *ApiService) getNextListPhoneNumberCountryResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListPhoneNumberCountryResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/pricing/v1/voice_countries.go b/rest/pricing/v1/voice_countries.go index 48bd17bfc..094fdc2de 100644 --- a/rest/pricing/v1/voice_countries.go +++ b/rest/pricing/v1/voice_countries.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -23,8 +24,10 @@ import ( "github.com/twilio/twilio-go/client" ) -// func (c *ApiService) FetchVoiceCountry(IsoCountry string) (*PricingV1VoiceCountryInstance, error) { + return c.FetchVoiceCountryWithContext(context.TODO(), IsoCountry) +} +func (c *ApiService) FetchVoiceCountryWithContext(ctx context.Context, IsoCountry string) (*PricingV1VoiceCountryInstance, error) { path := "/v1/Voice/Countries/{IsoCountry}" path = strings.Replace(path, "{"+"IsoCountry"+"}", IsoCountry, -1) @@ -33,7 +36,7 @@ func (c *ApiService) FetchVoiceCountry(IsoCountry string) (*PricingV1VoiceCountr "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -67,6 +70,11 @@ func (params *ListVoiceCountryParams) SetLimit(Limit int) *ListVoiceCountryParam // Retrieve a single page of VoiceCountry records from the API. Request is executed immediately. func (c *ApiService) PageVoiceCountry(params *ListVoiceCountryParams, pageToken, pageNumber string) (*ListVoiceCountryResponse, error) { + return c.PageVoiceCountryWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of VoiceCountry records from the API. Request is executed immediately. +func (c *ApiService) PageVoiceCountryWithContext(ctx context.Context, params *ListVoiceCountryParams, pageToken, pageNumber string) (*ListVoiceCountryResponse, error) { path := "/v1/Voice/Countries" data := url.Values{} @@ -85,7 +93,7 @@ func (c *ApiService) PageVoiceCountry(params *ListVoiceCountryParams, pageToken, data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -102,7 +110,12 @@ func (c *ApiService) PageVoiceCountry(params *ListVoiceCountryParams, pageToken, // Lists VoiceCountry records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListVoiceCountry(params *ListVoiceCountryParams) ([]PricingV1VoiceCountry, error) { - response, errors := c.StreamVoiceCountry(params) + return c.ListVoiceCountryWithContext(context.TODO(), params) +} + +// Lists VoiceCountry records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListVoiceCountryWithContext(ctx context.Context, params *ListVoiceCountryParams) ([]PricingV1VoiceCountry, error) { + response, errors := c.StreamVoiceCountryWithContext(ctx, params) records := make([]PricingV1VoiceCountry, 0) for record := range response { @@ -118,6 +131,11 @@ func (c *ApiService) ListVoiceCountry(params *ListVoiceCountryParams) ([]Pricing // Streams VoiceCountry records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamVoiceCountry(params *ListVoiceCountryParams) (chan PricingV1VoiceCountry, chan error) { + return c.StreamVoiceCountryWithContext(context.TODO(), params) +} + +// Streams VoiceCountry records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamVoiceCountryWithContext(ctx context.Context, params *ListVoiceCountryParams) (chan PricingV1VoiceCountry, chan error) { if params == nil { params = &ListVoiceCountryParams{} } @@ -126,19 +144,19 @@ func (c *ApiService) StreamVoiceCountry(params *ListVoiceCountryParams) (chan Pr recordChannel := make(chan PricingV1VoiceCountry, 1) errorChannel := make(chan error, 1) - response, err := c.PageVoiceCountry(params, "", "") + response, err := c.PageVoiceCountryWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamVoiceCountry(response, params, recordChannel, errorChannel) + go c.streamVoiceCountryWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamVoiceCountry(response *ListVoiceCountryResponse, params *ListVoiceCountryParams, recordChannel chan PricingV1VoiceCountry, errorChannel chan error) { +func (c *ApiService) streamVoiceCountryWithContext(ctx context.Context, response *ListVoiceCountryResponse, params *ListVoiceCountryParams, recordChannel chan PricingV1VoiceCountry, errorChannel chan error) { curRecord := 1 for response != nil { @@ -153,7 +171,7 @@ func (c *ApiService) streamVoiceCountry(response *ListVoiceCountryResponse, para } } - record, err := client.GetNext(c.baseURL, response, c.getNextListVoiceCountryResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListVoiceCountryResponseWithContext) if err != nil { errorChannel <- err break @@ -168,11 +186,11 @@ func (c *ApiService) streamVoiceCountry(response *ListVoiceCountryResponse, para close(errorChannel) } -func (c *ApiService) getNextListVoiceCountryResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListVoiceCountryResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/pricing/v1/voice_numbers.go b/rest/pricing/v1/voice_numbers.go index b4cdf9750..42cddcde6 100644 --- a/rest/pricing/v1/voice_numbers.go +++ b/rest/pricing/v1/voice_numbers.go @@ -15,13 +15,16 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" ) -// func (c *ApiService) FetchVoiceNumber(Number string) (*PricingV1VoiceNumber, error) { + return c.FetchVoiceNumberWithContext(context.TODO(), Number) +} +func (c *ApiService) FetchVoiceNumberWithContext(ctx context.Context, Number string) (*PricingV1VoiceNumber, error) { path := "/v1/Voice/Numbers/{Number}" path = strings.Replace(path, "{"+"Number"+"}", Number, -1) @@ -30,7 +33,7 @@ func (c *ApiService) FetchVoiceNumber(Number string) (*PricingV1VoiceNumber, err "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/pricing/v2/api_service.go b/rest/pricing/v2/api_service.go index 6f1c4551a..43756bf04 100644 --- a/rest/pricing/v2/api_service.go +++ b/rest/pricing/v2/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://pricing.twilio.com", + } +} diff --git a/rest/pricing/v2/trunking_countries.go b/rest/pricing/v2/trunking_countries.go index 94c1d3395..a6a0bcf3d 100644 --- a/rest/pricing/v2/trunking_countries.go +++ b/rest/pricing/v2/trunking_countries.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -25,6 +26,9 @@ import ( // Fetch a specific Country. func (c *ApiService) FetchTrunkingCountry(IsoCountry string) (*PricingV2TrunkingCountryInstance, error) { + return c.FetchTrunkingCountryWithContext(context.TODO(), IsoCountry) +} +func (c *ApiService) FetchTrunkingCountryWithContext(ctx context.Context, IsoCountry string) (*PricingV2TrunkingCountryInstance, error) { path := "/v2/Trunking/Countries/{IsoCountry}" path = strings.Replace(path, "{"+"IsoCountry"+"}", IsoCountry, -1) @@ -33,7 +37,7 @@ func (c *ApiService) FetchTrunkingCountry(IsoCountry string) (*PricingV2Trunking "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -67,6 +71,11 @@ func (params *ListTrunkingCountryParams) SetLimit(Limit int) *ListTrunkingCountr // Retrieve a single page of TrunkingCountry records from the API. Request is executed immediately. func (c *ApiService) PageTrunkingCountry(params *ListTrunkingCountryParams, pageToken, pageNumber string) (*ListTrunkingCountryResponse, error) { + return c.PageTrunkingCountryWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of TrunkingCountry records from the API. Request is executed immediately. +func (c *ApiService) PageTrunkingCountryWithContext(ctx context.Context, params *ListTrunkingCountryParams, pageToken, pageNumber string) (*ListTrunkingCountryResponse, error) { path := "/v2/Trunking/Countries" data := url.Values{} @@ -85,7 +94,7 @@ func (c *ApiService) PageTrunkingCountry(params *ListTrunkingCountryParams, page data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -102,7 +111,12 @@ func (c *ApiService) PageTrunkingCountry(params *ListTrunkingCountryParams, page // Lists TrunkingCountry records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListTrunkingCountry(params *ListTrunkingCountryParams) ([]PricingV2TrunkingCountry, error) { - response, errors := c.StreamTrunkingCountry(params) + return c.ListTrunkingCountryWithContext(context.TODO(), params) +} + +// Lists TrunkingCountry records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListTrunkingCountryWithContext(ctx context.Context, params *ListTrunkingCountryParams) ([]PricingV2TrunkingCountry, error) { + response, errors := c.StreamTrunkingCountryWithContext(ctx, params) records := make([]PricingV2TrunkingCountry, 0) for record := range response { @@ -118,6 +132,11 @@ func (c *ApiService) ListTrunkingCountry(params *ListTrunkingCountryParams) ([]P // Streams TrunkingCountry records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamTrunkingCountry(params *ListTrunkingCountryParams) (chan PricingV2TrunkingCountry, chan error) { + return c.StreamTrunkingCountryWithContext(context.TODO(), params) +} + +// Streams TrunkingCountry records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamTrunkingCountryWithContext(ctx context.Context, params *ListTrunkingCountryParams) (chan PricingV2TrunkingCountry, chan error) { if params == nil { params = &ListTrunkingCountryParams{} } @@ -126,19 +145,19 @@ func (c *ApiService) StreamTrunkingCountry(params *ListTrunkingCountryParams) (c recordChannel := make(chan PricingV2TrunkingCountry, 1) errorChannel := make(chan error, 1) - response, err := c.PageTrunkingCountry(params, "", "") + response, err := c.PageTrunkingCountryWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamTrunkingCountry(response, params, recordChannel, errorChannel) + go c.streamTrunkingCountryWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamTrunkingCountry(response *ListTrunkingCountryResponse, params *ListTrunkingCountryParams, recordChannel chan PricingV2TrunkingCountry, errorChannel chan error) { +func (c *ApiService) streamTrunkingCountryWithContext(ctx context.Context, response *ListTrunkingCountryResponse, params *ListTrunkingCountryParams, recordChannel chan PricingV2TrunkingCountry, errorChannel chan error) { curRecord := 1 for response != nil { @@ -153,7 +172,7 @@ func (c *ApiService) streamTrunkingCountry(response *ListTrunkingCountryResponse } } - record, err := client.GetNext(c.baseURL, response, c.getNextListTrunkingCountryResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListTrunkingCountryResponseWithContext) if err != nil { errorChannel <- err break @@ -168,11 +187,11 @@ func (c *ApiService) streamTrunkingCountry(response *ListTrunkingCountryResponse close(errorChannel) } -func (c *ApiService) getNextListTrunkingCountryResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListTrunkingCountryResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/pricing/v2/trunking_numbers.go b/rest/pricing/v2/trunking_numbers.go index 5e17e51af..98d5c91a3 100644 --- a/rest/pricing/v2/trunking_numbers.go +++ b/rest/pricing/v2/trunking_numbers.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -33,6 +34,9 @@ func (params *FetchTrunkingNumberParams) SetOriginationNumber(OriginationNumber // Fetch pricing information for a specific destination and, optionally, origination phone number. func (c *ApiService) FetchTrunkingNumber(DestinationNumber string, params *FetchTrunkingNumberParams) (*PricingV2TrunkingNumber, error) { + return c.FetchTrunkingNumberWithContext(context.TODO(), DestinationNumber, params) +} +func (c *ApiService) FetchTrunkingNumberWithContext(ctx context.Context, DestinationNumber string, params *FetchTrunkingNumberParams) (*PricingV2TrunkingNumber, error) { path := "/v2/Trunking/Numbers/{DestinationNumber}" path = strings.Replace(path, "{"+"DestinationNumber"+"}", DestinationNumber, -1) @@ -45,7 +49,7 @@ func (c *ApiService) FetchTrunkingNumber(DestinationNumber string, params *Fetch data.Set("OriginationNumber", *params.OriginationNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/pricing/v2/voice_countries.go b/rest/pricing/v2/voice_countries.go index 5b68817be..2e1ad16b0 100644 --- a/rest/pricing/v2/voice_countries.go +++ b/rest/pricing/v2/voice_countries.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -25,6 +26,9 @@ import ( // Fetch a specific Country. func (c *ApiService) FetchVoiceCountry(IsoCountry string) (*PricingV2VoiceCountryInstance, error) { + return c.FetchVoiceCountryWithContext(context.TODO(), IsoCountry) +} +func (c *ApiService) FetchVoiceCountryWithContext(ctx context.Context, IsoCountry string) (*PricingV2VoiceCountryInstance, error) { path := "/v2/Voice/Countries/{IsoCountry}" path = strings.Replace(path, "{"+"IsoCountry"+"}", IsoCountry, -1) @@ -33,7 +37,7 @@ func (c *ApiService) FetchVoiceCountry(IsoCountry string) (*PricingV2VoiceCountr "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -67,6 +71,11 @@ func (params *ListVoiceCountryParams) SetLimit(Limit int) *ListVoiceCountryParam // Retrieve a single page of VoiceCountry records from the API. Request is executed immediately. func (c *ApiService) PageVoiceCountry(params *ListVoiceCountryParams, pageToken, pageNumber string) (*ListVoiceCountryResponse, error) { + return c.PageVoiceCountryWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of VoiceCountry records from the API. Request is executed immediately. +func (c *ApiService) PageVoiceCountryWithContext(ctx context.Context, params *ListVoiceCountryParams, pageToken, pageNumber string) (*ListVoiceCountryResponse, error) { path := "/v2/Voice/Countries" data := url.Values{} @@ -85,7 +94,7 @@ func (c *ApiService) PageVoiceCountry(params *ListVoiceCountryParams, pageToken, data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -102,7 +111,12 @@ func (c *ApiService) PageVoiceCountry(params *ListVoiceCountryParams, pageToken, // Lists VoiceCountry records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListVoiceCountry(params *ListVoiceCountryParams) ([]PricingV2VoiceCountry, error) { - response, errors := c.StreamVoiceCountry(params) + return c.ListVoiceCountryWithContext(context.TODO(), params) +} + +// Lists VoiceCountry records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListVoiceCountryWithContext(ctx context.Context, params *ListVoiceCountryParams) ([]PricingV2VoiceCountry, error) { + response, errors := c.StreamVoiceCountryWithContext(ctx, params) records := make([]PricingV2VoiceCountry, 0) for record := range response { @@ -118,6 +132,11 @@ func (c *ApiService) ListVoiceCountry(params *ListVoiceCountryParams) ([]Pricing // Streams VoiceCountry records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamVoiceCountry(params *ListVoiceCountryParams) (chan PricingV2VoiceCountry, chan error) { + return c.StreamVoiceCountryWithContext(context.TODO(), params) +} + +// Streams VoiceCountry records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamVoiceCountryWithContext(ctx context.Context, params *ListVoiceCountryParams) (chan PricingV2VoiceCountry, chan error) { if params == nil { params = &ListVoiceCountryParams{} } @@ -126,19 +145,19 @@ func (c *ApiService) StreamVoiceCountry(params *ListVoiceCountryParams) (chan Pr recordChannel := make(chan PricingV2VoiceCountry, 1) errorChannel := make(chan error, 1) - response, err := c.PageVoiceCountry(params, "", "") + response, err := c.PageVoiceCountryWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamVoiceCountry(response, params, recordChannel, errorChannel) + go c.streamVoiceCountryWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamVoiceCountry(response *ListVoiceCountryResponse, params *ListVoiceCountryParams, recordChannel chan PricingV2VoiceCountry, errorChannel chan error) { +func (c *ApiService) streamVoiceCountryWithContext(ctx context.Context, response *ListVoiceCountryResponse, params *ListVoiceCountryParams, recordChannel chan PricingV2VoiceCountry, errorChannel chan error) { curRecord := 1 for response != nil { @@ -153,7 +172,7 @@ func (c *ApiService) streamVoiceCountry(response *ListVoiceCountryResponse, para } } - record, err := client.GetNext(c.baseURL, response, c.getNextListVoiceCountryResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListVoiceCountryResponseWithContext) if err != nil { errorChannel <- err break @@ -168,11 +187,11 @@ func (c *ApiService) streamVoiceCountry(response *ListVoiceCountryResponse, para close(errorChannel) } -func (c *ApiService) getNextListVoiceCountryResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListVoiceCountryResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/pricing/v2/voice_numbers.go b/rest/pricing/v2/voice_numbers.go index 96ba0bc66..59ddc4ea0 100644 --- a/rest/pricing/v2/voice_numbers.go +++ b/rest/pricing/v2/voice_numbers.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -33,6 +34,9 @@ func (params *FetchVoiceNumberParams) SetOriginationNumber(OriginationNumber str // Fetch pricing information for a specific destination and, optionally, origination phone number. func (c *ApiService) FetchVoiceNumber(DestinationNumber string, params *FetchVoiceNumberParams) (*PricingV2VoiceNumber, error) { + return c.FetchVoiceNumberWithContext(context.TODO(), DestinationNumber, params) +} +func (c *ApiService) FetchVoiceNumberWithContext(ctx context.Context, DestinationNumber string, params *FetchVoiceNumberParams) (*PricingV2VoiceNumber, error) { path := "/v2/Voice/Numbers/{DestinationNumber}" path = strings.Replace(path, "{"+"DestinationNumber"+"}", DestinationNumber, -1) @@ -45,7 +49,7 @@ func (c *ApiService) FetchVoiceNumber(DestinationNumber string, params *FetchVoi data.Set("OriginationNumber", *params.OriginationNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/proxy/v1/api_service.go b/rest/proxy/v1/api_service.go index 8bba2625b..39e348d11 100644 --- a/rest/proxy/v1/api_service.go +++ b/rest/proxy/v1/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://proxy.twilio.com", + } +} diff --git a/rest/proxy/v1/services.go b/rest/proxy/v1/services.go index 837e4f590..47fefc0c2 100644 --- a/rest/proxy/v1/services.go +++ b/rest/proxy/v1/services.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -78,6 +79,9 @@ func (params *CreateServiceParams) SetChatInstanceSid(ChatInstanceSid string) *C // Create a new Service for Twilio Proxy func (c *ApiService) CreateService(params *CreateServiceParams) (*ProxyV1Service, error) { + return c.CreateServiceWithContext(context.TODO(), params) +} +func (c *ApiService) CreateServiceWithContext(ctx context.Context, params *CreateServiceParams) (*ProxyV1Service, error) { path := "/v1/Services" data := url.Values{} @@ -110,7 +114,7 @@ func (c *ApiService) CreateService(params *CreateServiceParams) (*ProxyV1Service data.Set("ChatInstanceSid", *params.ChatInstanceSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -127,6 +131,9 @@ func (c *ApiService) CreateService(params *CreateServiceParams) (*ProxyV1Service // Delete a specific Service. func (c *ApiService) DeleteService(Sid string) error { + return c.DeleteServiceWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteServiceWithContext(ctx context.Context, Sid string) error { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -135,7 +142,7 @@ func (c *ApiService) DeleteService(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -147,6 +154,9 @@ func (c *ApiService) DeleteService(Sid string) error { // Fetch a specific Service. func (c *ApiService) FetchService(Sid string) (*ProxyV1Service, error) { + return c.FetchServiceWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchServiceWithContext(ctx context.Context, Sid string) (*ProxyV1Service, error) { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -155,7 +165,7 @@ func (c *ApiService) FetchService(Sid string) (*ProxyV1Service, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -189,6 +199,11 @@ func (params *ListServiceParams) SetLimit(Limit int) *ListServiceParams { // Retrieve a single page of Service records from the API. Request is executed immediately. func (c *ApiService) PageService(params *ListServiceParams, pageToken, pageNumber string) (*ListServiceResponse, error) { + return c.PageServiceWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Service records from the API. Request is executed immediately. +func (c *ApiService) PageServiceWithContext(ctx context.Context, params *ListServiceParams, pageToken, pageNumber string) (*ListServiceResponse, error) { path := "/v1/Services" data := url.Values{} @@ -207,7 +222,7 @@ func (c *ApiService) PageService(params *ListServiceParams, pageToken, pageNumbe data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -224,7 +239,12 @@ func (c *ApiService) PageService(params *ListServiceParams, pageToken, pageNumbe // Lists Service records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListService(params *ListServiceParams) ([]ProxyV1Service, error) { - response, errors := c.StreamService(params) + return c.ListServiceWithContext(context.TODO(), params) +} + +// Lists Service records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListServiceWithContext(ctx context.Context, params *ListServiceParams) ([]ProxyV1Service, error) { + response, errors := c.StreamServiceWithContext(ctx, params) records := make([]ProxyV1Service, 0) for record := range response { @@ -240,6 +260,11 @@ func (c *ApiService) ListService(params *ListServiceParams) ([]ProxyV1Service, e // Streams Service records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamService(params *ListServiceParams) (chan ProxyV1Service, chan error) { + return c.StreamServiceWithContext(context.TODO(), params) +} + +// Streams Service records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamServiceWithContext(ctx context.Context, params *ListServiceParams) (chan ProxyV1Service, chan error) { if params == nil { params = &ListServiceParams{} } @@ -248,19 +273,19 @@ func (c *ApiService) StreamService(params *ListServiceParams) (chan ProxyV1Servi recordChannel := make(chan ProxyV1Service, 1) errorChannel := make(chan error, 1) - response, err := c.PageService(params, "", "") + response, err := c.PageServiceWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamService(response, params, recordChannel, errorChannel) + go c.streamServiceWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamService(response *ListServiceResponse, params *ListServiceParams, recordChannel chan ProxyV1Service, errorChannel chan error) { +func (c *ApiService) streamServiceWithContext(ctx context.Context, response *ListServiceResponse, params *ListServiceParams, recordChannel chan ProxyV1Service, errorChannel chan error) { curRecord := 1 for response != nil { @@ -275,7 +300,7 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListServiceResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListServiceResponseWithContext) if err != nil { errorChannel <- err break @@ -290,11 +315,11 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe close(errorChannel) } -func (c *ApiService) getNextListServiceResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListServiceResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -363,6 +388,9 @@ func (params *UpdateServiceParams) SetChatInstanceSid(ChatInstanceSid string) *U // Update a specific Service. func (c *ApiService) UpdateService(Sid string, params *UpdateServiceParams) (*ProxyV1Service, error) { + return c.UpdateServiceWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateServiceWithContext(ctx context.Context, Sid string, params *UpdateServiceParams) (*ProxyV1Service, error) { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -396,7 +424,7 @@ func (c *ApiService) UpdateService(Sid string, params *UpdateServiceParams) (*Pr data.Set("ChatInstanceSid", *params.ChatInstanceSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/proxy/v1/services_phone_numbers.go b/rest/proxy/v1/services_phone_numbers.go index 1f6af5057..4e57bffa8 100644 --- a/rest/proxy/v1/services_phone_numbers.go +++ b/rest/proxy/v1/services_phone_numbers.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -48,6 +49,9 @@ func (params *CreatePhoneNumberParams) SetIsReserved(IsReserved bool) *CreatePho // Add a Phone Number to a Service's Proxy Number Pool. func (c *ApiService) CreatePhoneNumber(ServiceSid string, params *CreatePhoneNumberParams) (*ProxyV1PhoneNumber, error) { + return c.CreatePhoneNumberWithContext(context.TODO(), ServiceSid, params) +} +func (c *ApiService) CreatePhoneNumberWithContext(ctx context.Context, ServiceSid string, params *CreatePhoneNumberParams) (*ProxyV1PhoneNumber, error) { path := "/v1/Services/{ServiceSid}/PhoneNumbers" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -66,7 +70,7 @@ func (c *ApiService) CreatePhoneNumber(ServiceSid string, params *CreatePhoneNum data.Set("IsReserved", fmt.Sprint(*params.IsReserved)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -83,6 +87,9 @@ func (c *ApiService) CreatePhoneNumber(ServiceSid string, params *CreatePhoneNum // Delete a specific Phone Number from a Service. func (c *ApiService) DeletePhoneNumber(ServiceSid string, Sid string) error { + return c.DeletePhoneNumberWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) DeletePhoneNumberWithContext(ctx context.Context, ServiceSid string, Sid string) error { path := "/v1/Services/{ServiceSid}/PhoneNumbers/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -92,7 +99,7 @@ func (c *ApiService) DeletePhoneNumber(ServiceSid string, Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -104,6 +111,9 @@ func (c *ApiService) DeletePhoneNumber(ServiceSid string, Sid string) error { // Fetch a specific Phone Number. func (c *ApiService) FetchPhoneNumber(ServiceSid string, Sid string) (*ProxyV1PhoneNumber, error) { + return c.FetchPhoneNumberWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) FetchPhoneNumberWithContext(ctx context.Context, ServiceSid string, Sid string) (*ProxyV1PhoneNumber, error) { path := "/v1/Services/{ServiceSid}/PhoneNumbers/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -113,7 +123,7 @@ func (c *ApiService) FetchPhoneNumber(ServiceSid string, Sid string) (*ProxyV1Ph "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -147,6 +157,11 @@ func (params *ListPhoneNumberParams) SetLimit(Limit int) *ListPhoneNumberParams // Retrieve a single page of PhoneNumber records from the API. Request is executed immediately. func (c *ApiService) PagePhoneNumber(ServiceSid string, params *ListPhoneNumberParams, pageToken, pageNumber string) (*ListPhoneNumberResponse, error) { + return c.PagePhoneNumberWithContext(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of PhoneNumber records from the API. Request is executed immediately. +func (c *ApiService) PagePhoneNumberWithContext(ctx context.Context, ServiceSid string, params *ListPhoneNumberParams, pageToken, pageNumber string) (*ListPhoneNumberResponse, error) { path := "/v1/Services/{ServiceSid}/PhoneNumbers" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -167,7 +182,7 @@ func (c *ApiService) PagePhoneNumber(ServiceSid string, params *ListPhoneNumberP data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -184,7 +199,12 @@ func (c *ApiService) PagePhoneNumber(ServiceSid string, params *ListPhoneNumberP // Lists PhoneNumber records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListPhoneNumber(ServiceSid string, params *ListPhoneNumberParams) ([]ProxyV1PhoneNumber, error) { - response, errors := c.StreamPhoneNumber(ServiceSid, params) + return c.ListPhoneNumberWithContext(context.TODO(), ServiceSid, params) +} + +// Lists PhoneNumber records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListPhoneNumberWithContext(ctx context.Context, ServiceSid string, params *ListPhoneNumberParams) ([]ProxyV1PhoneNumber, error) { + response, errors := c.StreamPhoneNumberWithContext(ctx, ServiceSid, params) records := make([]ProxyV1PhoneNumber, 0) for record := range response { @@ -200,6 +220,11 @@ func (c *ApiService) ListPhoneNumber(ServiceSid string, params *ListPhoneNumberP // Streams PhoneNumber records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamPhoneNumber(ServiceSid string, params *ListPhoneNumberParams) (chan ProxyV1PhoneNumber, chan error) { + return c.StreamPhoneNumberWithContext(context.TODO(), ServiceSid, params) +} + +// Streams PhoneNumber records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamPhoneNumberWithContext(ctx context.Context, ServiceSid string, params *ListPhoneNumberParams) (chan ProxyV1PhoneNumber, chan error) { if params == nil { params = &ListPhoneNumberParams{} } @@ -208,19 +233,19 @@ func (c *ApiService) StreamPhoneNumber(ServiceSid string, params *ListPhoneNumbe recordChannel := make(chan ProxyV1PhoneNumber, 1) errorChannel := make(chan error, 1) - response, err := c.PagePhoneNumber(ServiceSid, params, "", "") + response, err := c.PagePhoneNumberWithContext(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamPhoneNumber(response, params, recordChannel, errorChannel) + go c.streamPhoneNumberWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamPhoneNumber(response *ListPhoneNumberResponse, params *ListPhoneNumberParams, recordChannel chan ProxyV1PhoneNumber, errorChannel chan error) { +func (c *ApiService) streamPhoneNumberWithContext(ctx context.Context, response *ListPhoneNumberResponse, params *ListPhoneNumberParams, recordChannel chan ProxyV1PhoneNumber, errorChannel chan error) { curRecord := 1 for response != nil { @@ -235,7 +260,7 @@ func (c *ApiService) streamPhoneNumber(response *ListPhoneNumberResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListPhoneNumberResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListPhoneNumberResponseWithContext) if err != nil { errorChannel <- err break @@ -250,11 +275,11 @@ func (c *ApiService) streamPhoneNumber(response *ListPhoneNumberResponse, params close(errorChannel) } -func (c *ApiService) getNextListPhoneNumberResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListPhoneNumberResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -281,6 +306,9 @@ func (params *UpdatePhoneNumberParams) SetIsReserved(IsReserved bool) *UpdatePho // Update a specific Proxy Number. func (c *ApiService) UpdatePhoneNumber(ServiceSid string, Sid string, params *UpdatePhoneNumberParams) (*ProxyV1PhoneNumber, error) { + return c.UpdatePhoneNumberWithContext(context.TODO(), ServiceSid, Sid, params) +} +func (c *ApiService) UpdatePhoneNumberWithContext(ctx context.Context, ServiceSid string, Sid string, params *UpdatePhoneNumberParams) (*ProxyV1PhoneNumber, error) { path := "/v1/Services/{ServiceSid}/PhoneNumbers/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -294,7 +322,7 @@ func (c *ApiService) UpdatePhoneNumber(ServiceSid string, Sid string, params *Up data.Set("IsReserved", fmt.Sprint(*params.IsReserved)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/proxy/v1/services_sessions.go b/rest/proxy/v1/services_sessions.go index 2a5b04535..d75dc3484 100644 --- a/rest/proxy/v1/services_sessions.go +++ b/rest/proxy/v1/services_sessions.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -67,6 +68,9 @@ func (params *CreateSessionParams) SetParticipants(Participants []map[string]int // Create a new Session func (c *ApiService) CreateSession(ServiceSid string, params *CreateSessionParams) (*ProxyV1Session, error) { + return c.CreateSessionWithContext(context.TODO(), ServiceSid, params) +} +func (c *ApiService) CreateSessionWithContext(ctx context.Context, ServiceSid string, params *CreateSessionParams) (*ProxyV1Session, error) { path := "/v1/Services/{ServiceSid}/Sessions" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -102,7 +106,7 @@ func (c *ApiService) CreateSession(ServiceSid string, params *CreateSessionParam } } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -119,6 +123,9 @@ func (c *ApiService) CreateSession(ServiceSid string, params *CreateSessionParam // Delete a specific Session. func (c *ApiService) DeleteSession(ServiceSid string, Sid string) error { + return c.DeleteSessionWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) DeleteSessionWithContext(ctx context.Context, ServiceSid string, Sid string) error { path := "/v1/Services/{ServiceSid}/Sessions/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -128,7 +135,7 @@ func (c *ApiService) DeleteSession(ServiceSid string, Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -140,6 +147,9 @@ func (c *ApiService) DeleteSession(ServiceSid string, Sid string) error { // Fetch a specific Session. func (c *ApiService) FetchSession(ServiceSid string, Sid string) (*ProxyV1Session, error) { + return c.FetchSessionWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) FetchSessionWithContext(ctx context.Context, ServiceSid string, Sid string) (*ProxyV1Session, error) { path := "/v1/Services/{ServiceSid}/Sessions/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -149,7 +159,7 @@ func (c *ApiService) FetchSession(ServiceSid string, Sid string) (*ProxyV1Sessio "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -183,6 +193,11 @@ func (params *ListSessionParams) SetLimit(Limit int) *ListSessionParams { // Retrieve a single page of Session records from the API. Request is executed immediately. func (c *ApiService) PageSession(ServiceSid string, params *ListSessionParams, pageToken, pageNumber string) (*ListSessionResponse, error) { + return c.PageSessionWithContext(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Session records from the API. Request is executed immediately. +func (c *ApiService) PageSessionWithContext(ctx context.Context, ServiceSid string, params *ListSessionParams, pageToken, pageNumber string) (*ListSessionResponse, error) { path := "/v1/Services/{ServiceSid}/Sessions" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -203,7 +218,7 @@ func (c *ApiService) PageSession(ServiceSid string, params *ListSessionParams, p data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -220,7 +235,12 @@ func (c *ApiService) PageSession(ServiceSid string, params *ListSessionParams, p // Lists Session records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListSession(ServiceSid string, params *ListSessionParams) ([]ProxyV1Session, error) { - response, errors := c.StreamSession(ServiceSid, params) + return c.ListSessionWithContext(context.TODO(), ServiceSid, params) +} + +// Lists Session records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListSessionWithContext(ctx context.Context, ServiceSid string, params *ListSessionParams) ([]ProxyV1Session, error) { + response, errors := c.StreamSessionWithContext(ctx, ServiceSid, params) records := make([]ProxyV1Session, 0) for record := range response { @@ -236,6 +256,11 @@ func (c *ApiService) ListSession(ServiceSid string, params *ListSessionParams) ( // Streams Session records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamSession(ServiceSid string, params *ListSessionParams) (chan ProxyV1Session, chan error) { + return c.StreamSessionWithContext(context.TODO(), ServiceSid, params) +} + +// Streams Session records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamSessionWithContext(ctx context.Context, ServiceSid string, params *ListSessionParams) (chan ProxyV1Session, chan error) { if params == nil { params = &ListSessionParams{} } @@ -244,19 +269,19 @@ func (c *ApiService) StreamSession(ServiceSid string, params *ListSessionParams) recordChannel := make(chan ProxyV1Session, 1) errorChannel := make(chan error, 1) - response, err := c.PageSession(ServiceSid, params, "", "") + response, err := c.PageSessionWithContext(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSession(response, params, recordChannel, errorChannel) + go c.streamSessionWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamSession(response *ListSessionResponse, params *ListSessionParams, recordChannel chan ProxyV1Session, errorChannel chan error) { +func (c *ApiService) streamSessionWithContext(ctx context.Context, response *ListSessionResponse, params *ListSessionParams, recordChannel chan ProxyV1Session, errorChannel chan error) { curRecord := 1 for response != nil { @@ -271,7 +296,7 @@ func (c *ApiService) streamSession(response *ListSessionResponse, params *ListSe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSessionResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListSessionResponseWithContext) if err != nil { errorChannel <- err break @@ -286,11 +311,11 @@ func (c *ApiService) streamSession(response *ListSessionResponse, params *ListSe close(errorChannel) } -func (c *ApiService) getNextListSessionResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSessionResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -329,6 +354,9 @@ func (params *UpdateSessionParams) SetStatus(Status string) *UpdateSessionParams // Update a specific Session. func (c *ApiService) UpdateSession(ServiceSid string, Sid string, params *UpdateSessionParams) (*ProxyV1Session, error) { + return c.UpdateSessionWithContext(context.TODO(), ServiceSid, Sid, params) +} +func (c *ApiService) UpdateSessionWithContext(ctx context.Context, ServiceSid string, Sid string, params *UpdateSessionParams) (*ProxyV1Session, error) { path := "/v1/Services/{ServiceSid}/Sessions/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -348,7 +376,7 @@ func (c *ApiService) UpdateSession(ServiceSid string, Sid string, params *Update data.Set("Status", fmt.Sprint(*params.Status)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/proxy/v1/services_sessions_interactions.go b/rest/proxy/v1/services_sessions_interactions.go index 5fd3884be..db12d97e0 100644 --- a/rest/proxy/v1/services_sessions_interactions.go +++ b/rest/proxy/v1/services_sessions_interactions.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -25,6 +26,9 @@ import ( // Delete a specific Interaction. func (c *ApiService) DeleteInteraction(ServiceSid string, SessionSid string, Sid string) error { + return c.DeleteInteractionWithContext(context.TODO(), ServiceSid, SessionSid, Sid) +} +func (c *ApiService) DeleteInteractionWithContext(ctx context.Context, ServiceSid string, SessionSid string, Sid string) error { path := "/v1/Services/{ServiceSid}/Sessions/{SessionSid}/Interactions/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"SessionSid"+"}", SessionSid, -1) @@ -35,7 +39,7 @@ func (c *ApiService) DeleteInteraction(ServiceSid string, SessionSid string, Sid "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -47,6 +51,9 @@ func (c *ApiService) DeleteInteraction(ServiceSid string, SessionSid string, Sid // Retrieve a list of Interactions for a given [Session](https://www.twilio.com/docs/proxy/api/session). func (c *ApiService) FetchInteraction(ServiceSid string, SessionSid string, Sid string) (*ProxyV1Interaction, error) { + return c.FetchInteractionWithContext(context.TODO(), ServiceSid, SessionSid, Sid) +} +func (c *ApiService) FetchInteractionWithContext(ctx context.Context, ServiceSid string, SessionSid string, Sid string) (*ProxyV1Interaction, error) { path := "/v1/Services/{ServiceSid}/Sessions/{SessionSid}/Interactions/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"SessionSid"+"}", SessionSid, -1) @@ -57,7 +64,7 @@ func (c *ApiService) FetchInteraction(ServiceSid string, SessionSid string, Sid "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -91,6 +98,11 @@ func (params *ListInteractionParams) SetLimit(Limit int) *ListInteractionParams // Retrieve a single page of Interaction records from the API. Request is executed immediately. func (c *ApiService) PageInteraction(ServiceSid string, SessionSid string, params *ListInteractionParams, pageToken, pageNumber string) (*ListInteractionResponse, error) { + return c.PageInteractionWithContext(context.TODO(), ServiceSid, SessionSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Interaction records from the API. Request is executed immediately. +func (c *ApiService) PageInteractionWithContext(ctx context.Context, ServiceSid string, SessionSid string, params *ListInteractionParams, pageToken, pageNumber string) (*ListInteractionResponse, error) { path := "/v1/Services/{ServiceSid}/Sessions/{SessionSid}/Interactions" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -112,7 +124,7 @@ func (c *ApiService) PageInteraction(ServiceSid string, SessionSid string, param data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -129,7 +141,12 @@ func (c *ApiService) PageInteraction(ServiceSid string, SessionSid string, param // Lists Interaction records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListInteraction(ServiceSid string, SessionSid string, params *ListInteractionParams) ([]ProxyV1Interaction, error) { - response, errors := c.StreamInteraction(ServiceSid, SessionSid, params) + return c.ListInteractionWithContext(context.TODO(), ServiceSid, SessionSid, params) +} + +// Lists Interaction records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListInteractionWithContext(ctx context.Context, ServiceSid string, SessionSid string, params *ListInteractionParams) ([]ProxyV1Interaction, error) { + response, errors := c.StreamInteractionWithContext(ctx, ServiceSid, SessionSid, params) records := make([]ProxyV1Interaction, 0) for record := range response { @@ -145,6 +162,11 @@ func (c *ApiService) ListInteraction(ServiceSid string, SessionSid string, param // Streams Interaction records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamInteraction(ServiceSid string, SessionSid string, params *ListInteractionParams) (chan ProxyV1Interaction, chan error) { + return c.StreamInteractionWithContext(context.TODO(), ServiceSid, SessionSid, params) +} + +// Streams Interaction records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamInteractionWithContext(ctx context.Context, ServiceSid string, SessionSid string, params *ListInteractionParams) (chan ProxyV1Interaction, chan error) { if params == nil { params = &ListInteractionParams{} } @@ -153,19 +175,19 @@ func (c *ApiService) StreamInteraction(ServiceSid string, SessionSid string, par recordChannel := make(chan ProxyV1Interaction, 1) errorChannel := make(chan error, 1) - response, err := c.PageInteraction(ServiceSid, SessionSid, params, "", "") + response, err := c.PageInteractionWithContext(ctx, ServiceSid, SessionSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamInteraction(response, params, recordChannel, errorChannel) + go c.streamInteractionWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamInteraction(response *ListInteractionResponse, params *ListInteractionParams, recordChannel chan ProxyV1Interaction, errorChannel chan error) { +func (c *ApiService) streamInteractionWithContext(ctx context.Context, response *ListInteractionResponse, params *ListInteractionParams, recordChannel chan ProxyV1Interaction, errorChannel chan error) { curRecord := 1 for response != nil { @@ -180,7 +202,7 @@ func (c *ApiService) streamInteraction(response *ListInteractionResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListInteractionResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListInteractionResponseWithContext) if err != nil { errorChannel <- err break @@ -195,11 +217,11 @@ func (c *ApiService) streamInteraction(response *ListInteractionResponse, params close(errorChannel) } -func (c *ApiService) getNextListInteractionResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListInteractionResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/proxy/v1/services_sessions_participants.go b/rest/proxy/v1/services_sessions_participants.go index 6638e11c1..29a401d0a 100644 --- a/rest/proxy/v1/services_sessions_participants.go +++ b/rest/proxy/v1/services_sessions_participants.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -54,6 +55,9 @@ func (params *CreateParticipantParams) SetProxyIdentifierSid(ProxyIdentifierSid // Add a new Participant to the Session func (c *ApiService) CreateParticipant(ServiceSid string, SessionSid string, params *CreateParticipantParams) (*ProxyV1Participant, error) { + return c.CreateParticipantWithContext(context.TODO(), ServiceSid, SessionSid, params) +} +func (c *ApiService) CreateParticipantWithContext(ctx context.Context, ServiceSid string, SessionSid string, params *CreateParticipantParams) (*ProxyV1Participant, error) { path := "/v1/Services/{ServiceSid}/Sessions/{SessionSid}/Participants" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"SessionSid"+"}", SessionSid, -1) @@ -76,7 +80,7 @@ func (c *ApiService) CreateParticipant(ServiceSid string, SessionSid string, par data.Set("ProxyIdentifierSid", *params.ProxyIdentifierSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -93,6 +97,9 @@ func (c *ApiService) CreateParticipant(ServiceSid string, SessionSid string, par // Delete a specific Participant. This is a soft-delete. The participant remains associated with the session and cannot be re-added. Participants are only permanently deleted when the [Session](https://www.twilio.com/docs/proxy/api/session) is deleted. func (c *ApiService) DeleteParticipant(ServiceSid string, SessionSid string, Sid string) error { + return c.DeleteParticipantWithContext(context.TODO(), ServiceSid, SessionSid, Sid) +} +func (c *ApiService) DeleteParticipantWithContext(ctx context.Context, ServiceSid string, SessionSid string, Sid string) error { path := "/v1/Services/{ServiceSid}/Sessions/{SessionSid}/Participants/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"SessionSid"+"}", SessionSid, -1) @@ -103,7 +110,7 @@ func (c *ApiService) DeleteParticipant(ServiceSid string, SessionSid string, Sid "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -115,6 +122,9 @@ func (c *ApiService) DeleteParticipant(ServiceSid string, SessionSid string, Sid // Fetch a specific Participant. func (c *ApiService) FetchParticipant(ServiceSid string, SessionSid string, Sid string) (*ProxyV1Participant, error) { + return c.FetchParticipantWithContext(context.TODO(), ServiceSid, SessionSid, Sid) +} +func (c *ApiService) FetchParticipantWithContext(ctx context.Context, ServiceSid string, SessionSid string, Sid string) (*ProxyV1Participant, error) { path := "/v1/Services/{ServiceSid}/Sessions/{SessionSid}/Participants/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"SessionSid"+"}", SessionSid, -1) @@ -125,7 +135,7 @@ func (c *ApiService) FetchParticipant(ServiceSid string, SessionSid string, Sid "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -159,6 +169,11 @@ func (params *ListParticipantParams) SetLimit(Limit int) *ListParticipantParams // Retrieve a single page of Participant records from the API. Request is executed immediately. func (c *ApiService) PageParticipant(ServiceSid string, SessionSid string, params *ListParticipantParams, pageToken, pageNumber string) (*ListParticipantResponse, error) { + return c.PageParticipantWithContext(context.TODO(), ServiceSid, SessionSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Participant records from the API. Request is executed immediately. +func (c *ApiService) PageParticipantWithContext(ctx context.Context, ServiceSid string, SessionSid string, params *ListParticipantParams, pageToken, pageNumber string) (*ListParticipantResponse, error) { path := "/v1/Services/{ServiceSid}/Sessions/{SessionSid}/Participants" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -180,7 +195,7 @@ func (c *ApiService) PageParticipant(ServiceSid string, SessionSid string, param data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -197,7 +212,12 @@ func (c *ApiService) PageParticipant(ServiceSid string, SessionSid string, param // Lists Participant records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListParticipant(ServiceSid string, SessionSid string, params *ListParticipantParams) ([]ProxyV1Participant, error) { - response, errors := c.StreamParticipant(ServiceSid, SessionSid, params) + return c.ListParticipantWithContext(context.TODO(), ServiceSid, SessionSid, params) +} + +// Lists Participant records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListParticipantWithContext(ctx context.Context, ServiceSid string, SessionSid string, params *ListParticipantParams) ([]ProxyV1Participant, error) { + response, errors := c.StreamParticipantWithContext(ctx, ServiceSid, SessionSid, params) records := make([]ProxyV1Participant, 0) for record := range response { @@ -213,6 +233,11 @@ func (c *ApiService) ListParticipant(ServiceSid string, SessionSid string, param // Streams Participant records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamParticipant(ServiceSid string, SessionSid string, params *ListParticipantParams) (chan ProxyV1Participant, chan error) { + return c.StreamParticipantWithContext(context.TODO(), ServiceSid, SessionSid, params) +} + +// Streams Participant records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamParticipantWithContext(ctx context.Context, ServiceSid string, SessionSid string, params *ListParticipantParams) (chan ProxyV1Participant, chan error) { if params == nil { params = &ListParticipantParams{} } @@ -221,19 +246,19 @@ func (c *ApiService) StreamParticipant(ServiceSid string, SessionSid string, par recordChannel := make(chan ProxyV1Participant, 1) errorChannel := make(chan error, 1) - response, err := c.PageParticipant(ServiceSid, SessionSid, params, "", "") + response, err := c.PageParticipantWithContext(ctx, ServiceSid, SessionSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamParticipant(response, params, recordChannel, errorChannel) + go c.streamParticipantWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamParticipant(response *ListParticipantResponse, params *ListParticipantParams, recordChannel chan ProxyV1Participant, errorChannel chan error) { +func (c *ApiService) streamParticipantWithContext(ctx context.Context, response *ListParticipantResponse, params *ListParticipantParams, recordChannel chan ProxyV1Participant, errorChannel chan error) { curRecord := 1 for response != nil { @@ -248,7 +273,7 @@ func (c *ApiService) streamParticipant(response *ListParticipantResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListParticipantResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListParticipantResponseWithContext) if err != nil { errorChannel <- err break @@ -263,11 +288,11 @@ func (c *ApiService) streamParticipant(response *ListParticipantResponse, params close(errorChannel) } -func (c *ApiService) getNextListParticipantResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListParticipantResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/proxy/v1/services_sessions_participants_message_interactions.go b/rest/proxy/v1/services_sessions_participants_message_interactions.go index c492c1fc1..6ca8a00cd 100644 --- a/rest/proxy/v1/services_sessions_participants_message_interactions.go +++ b/rest/proxy/v1/services_sessions_participants_message_interactions.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -42,6 +43,9 @@ func (params *CreateMessageInteractionParams) SetMediaUrl(MediaUrl []string) *Cr // Create a new message Interaction to send directly from your system to one [Participant](https://www.twilio.com/docs/proxy/api/participant). The `inbound` properties for the Interaction will always be empty. func (c *ApiService) CreateMessageInteraction(ServiceSid string, SessionSid string, ParticipantSid string, params *CreateMessageInteractionParams) (*ProxyV1MessageInteraction, error) { + return c.CreateMessageInteractionWithContext(context.TODO(), ServiceSid, SessionSid, ParticipantSid, params) +} +func (c *ApiService) CreateMessageInteractionWithContext(ctx context.Context, ServiceSid string, SessionSid string, ParticipantSid string, params *CreateMessageInteractionParams) (*ProxyV1MessageInteraction, error) { path := "/v1/Services/{ServiceSid}/Sessions/{SessionSid}/Participants/{ParticipantSid}/MessageInteractions" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"SessionSid"+"}", SessionSid, -1) @@ -61,7 +65,7 @@ func (c *ApiService) CreateMessageInteraction(ServiceSid string, SessionSid stri } } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -76,8 +80,10 @@ func (c *ApiService) CreateMessageInteraction(ServiceSid string, SessionSid stri return ps, err } -// func (c *ApiService) FetchMessageInteraction(ServiceSid string, SessionSid string, ParticipantSid string, Sid string) (*ProxyV1MessageInteraction, error) { + return c.FetchMessageInteractionWithContext(context.TODO(), ServiceSid, SessionSid, ParticipantSid, Sid) +} +func (c *ApiService) FetchMessageInteractionWithContext(ctx context.Context, ServiceSid string, SessionSid string, ParticipantSid string, Sid string) (*ProxyV1MessageInteraction, error) { path := "/v1/Services/{ServiceSid}/Sessions/{SessionSid}/Participants/{ParticipantSid}/MessageInteractions/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"SessionSid"+"}", SessionSid, -1) @@ -89,7 +95,7 @@ func (c *ApiService) FetchMessageInteraction(ServiceSid string, SessionSid strin "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -123,6 +129,11 @@ func (params *ListMessageInteractionParams) SetLimit(Limit int) *ListMessageInte // Retrieve a single page of MessageInteraction records from the API. Request is executed immediately. func (c *ApiService) PageMessageInteraction(ServiceSid string, SessionSid string, ParticipantSid string, params *ListMessageInteractionParams, pageToken, pageNumber string) (*ListMessageInteractionResponse, error) { + return c.PageMessageInteractionWithContext(context.TODO(), ServiceSid, SessionSid, ParticipantSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of MessageInteraction records from the API. Request is executed immediately. +func (c *ApiService) PageMessageInteractionWithContext(ctx context.Context, ServiceSid string, SessionSid string, ParticipantSid string, params *ListMessageInteractionParams, pageToken, pageNumber string) (*ListMessageInteractionResponse, error) { path := "/v1/Services/{ServiceSid}/Sessions/{SessionSid}/Participants/{ParticipantSid}/MessageInteractions" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -145,7 +156,7 @@ func (c *ApiService) PageMessageInteraction(ServiceSid string, SessionSid string data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -162,7 +173,12 @@ func (c *ApiService) PageMessageInteraction(ServiceSid string, SessionSid string // Lists MessageInteraction records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListMessageInteraction(ServiceSid string, SessionSid string, ParticipantSid string, params *ListMessageInteractionParams) ([]ProxyV1MessageInteraction, error) { - response, errors := c.StreamMessageInteraction(ServiceSid, SessionSid, ParticipantSid, params) + return c.ListMessageInteractionWithContext(context.TODO(), ServiceSid, SessionSid, ParticipantSid, params) +} + +// Lists MessageInteraction records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListMessageInteractionWithContext(ctx context.Context, ServiceSid string, SessionSid string, ParticipantSid string, params *ListMessageInteractionParams) ([]ProxyV1MessageInteraction, error) { + response, errors := c.StreamMessageInteractionWithContext(ctx, ServiceSid, SessionSid, ParticipantSid, params) records := make([]ProxyV1MessageInteraction, 0) for record := range response { @@ -178,6 +194,11 @@ func (c *ApiService) ListMessageInteraction(ServiceSid string, SessionSid string // Streams MessageInteraction records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamMessageInteraction(ServiceSid string, SessionSid string, ParticipantSid string, params *ListMessageInteractionParams) (chan ProxyV1MessageInteraction, chan error) { + return c.StreamMessageInteractionWithContext(context.TODO(), ServiceSid, SessionSid, ParticipantSid, params) +} + +// Streams MessageInteraction records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamMessageInteractionWithContext(ctx context.Context, ServiceSid string, SessionSid string, ParticipantSid string, params *ListMessageInteractionParams) (chan ProxyV1MessageInteraction, chan error) { if params == nil { params = &ListMessageInteractionParams{} } @@ -186,19 +207,19 @@ func (c *ApiService) StreamMessageInteraction(ServiceSid string, SessionSid stri recordChannel := make(chan ProxyV1MessageInteraction, 1) errorChannel := make(chan error, 1) - response, err := c.PageMessageInteraction(ServiceSid, SessionSid, ParticipantSid, params, "", "") + response, err := c.PageMessageInteractionWithContext(ctx, ServiceSid, SessionSid, ParticipantSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamMessageInteraction(response, params, recordChannel, errorChannel) + go c.streamMessageInteractionWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamMessageInteraction(response *ListMessageInteractionResponse, params *ListMessageInteractionParams, recordChannel chan ProxyV1MessageInteraction, errorChannel chan error) { +func (c *ApiService) streamMessageInteractionWithContext(ctx context.Context, response *ListMessageInteractionResponse, params *ListMessageInteractionParams, recordChannel chan ProxyV1MessageInteraction, errorChannel chan error) { curRecord := 1 for response != nil { @@ -213,7 +234,7 @@ func (c *ApiService) streamMessageInteraction(response *ListMessageInteractionRe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListMessageInteractionResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListMessageInteractionResponseWithContext) if err != nil { errorChannel <- err break @@ -228,11 +249,11 @@ func (c *ApiService) streamMessageInteraction(response *ListMessageInteractionRe close(errorChannel) } -func (c *ApiService) getNextListMessageInteractionResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListMessageInteractionResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/proxy/v1/services_short_codes.go b/rest/proxy/v1/services_short_codes.go index 74cb6541e..3ccfd2e40 100644 --- a/rest/proxy/v1/services_short_codes.go +++ b/rest/proxy/v1/services_short_codes.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -36,6 +37,9 @@ func (params *CreateShortCodeParams) SetSid(Sid string) *CreateShortCodeParams { // Add a Short Code to the Proxy Number Pool for the Service. func (c *ApiService) CreateShortCode(ServiceSid string, params *CreateShortCodeParams) (*ProxyV1ShortCode, error) { + return c.CreateShortCodeWithContext(context.TODO(), ServiceSid, params) +} +func (c *ApiService) CreateShortCodeWithContext(ctx context.Context, ServiceSid string, params *CreateShortCodeParams) (*ProxyV1ShortCode, error) { path := "/v1/Services/{ServiceSid}/ShortCodes" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -48,7 +52,7 @@ func (c *ApiService) CreateShortCode(ServiceSid string, params *CreateShortCodeP data.Set("Sid", *params.Sid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -65,6 +69,9 @@ func (c *ApiService) CreateShortCode(ServiceSid string, params *CreateShortCodeP // Delete a specific Short Code from a Service. func (c *ApiService) DeleteShortCode(ServiceSid string, Sid string) error { + return c.DeleteShortCodeWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) DeleteShortCodeWithContext(ctx context.Context, ServiceSid string, Sid string) error { path := "/v1/Services/{ServiceSid}/ShortCodes/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -74,7 +81,7 @@ func (c *ApiService) DeleteShortCode(ServiceSid string, Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -86,6 +93,9 @@ func (c *ApiService) DeleteShortCode(ServiceSid string, Sid string) error { // Fetch a specific Short Code. func (c *ApiService) FetchShortCode(ServiceSid string, Sid string) (*ProxyV1ShortCode, error) { + return c.FetchShortCodeWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) FetchShortCodeWithContext(ctx context.Context, ServiceSid string, Sid string) (*ProxyV1ShortCode, error) { path := "/v1/Services/{ServiceSid}/ShortCodes/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -95,7 +105,7 @@ func (c *ApiService) FetchShortCode(ServiceSid string, Sid string) (*ProxyV1Shor "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -129,6 +139,11 @@ func (params *ListShortCodeParams) SetLimit(Limit int) *ListShortCodeParams { // Retrieve a single page of ShortCode records from the API. Request is executed immediately. func (c *ApiService) PageShortCode(ServiceSid string, params *ListShortCodeParams, pageToken, pageNumber string) (*ListShortCodeResponse, error) { + return c.PageShortCodeWithContext(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ShortCode records from the API. Request is executed immediately. +func (c *ApiService) PageShortCodeWithContext(ctx context.Context, ServiceSid string, params *ListShortCodeParams, pageToken, pageNumber string) (*ListShortCodeResponse, error) { path := "/v1/Services/{ServiceSid}/ShortCodes" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -149,7 +164,7 @@ func (c *ApiService) PageShortCode(ServiceSid string, params *ListShortCodeParam data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -166,7 +181,12 @@ func (c *ApiService) PageShortCode(ServiceSid string, params *ListShortCodeParam // Lists ShortCode records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListShortCode(ServiceSid string, params *ListShortCodeParams) ([]ProxyV1ShortCode, error) { - response, errors := c.StreamShortCode(ServiceSid, params) + return c.ListShortCodeWithContext(context.TODO(), ServiceSid, params) +} + +// Lists ShortCode records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListShortCodeWithContext(ctx context.Context, ServiceSid string, params *ListShortCodeParams) ([]ProxyV1ShortCode, error) { + response, errors := c.StreamShortCodeWithContext(ctx, ServiceSid, params) records := make([]ProxyV1ShortCode, 0) for record := range response { @@ -182,6 +202,11 @@ func (c *ApiService) ListShortCode(ServiceSid string, params *ListShortCodeParam // Streams ShortCode records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamShortCode(ServiceSid string, params *ListShortCodeParams) (chan ProxyV1ShortCode, chan error) { + return c.StreamShortCodeWithContext(context.TODO(), ServiceSid, params) +} + +// Streams ShortCode records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamShortCodeWithContext(ctx context.Context, ServiceSid string, params *ListShortCodeParams) (chan ProxyV1ShortCode, chan error) { if params == nil { params = &ListShortCodeParams{} } @@ -190,19 +215,19 @@ func (c *ApiService) StreamShortCode(ServiceSid string, params *ListShortCodePar recordChannel := make(chan ProxyV1ShortCode, 1) errorChannel := make(chan error, 1) - response, err := c.PageShortCode(ServiceSid, params, "", "") + response, err := c.PageShortCodeWithContext(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamShortCode(response, params, recordChannel, errorChannel) + go c.streamShortCodeWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamShortCode(response *ListShortCodeResponse, params *ListShortCodeParams, recordChannel chan ProxyV1ShortCode, errorChannel chan error) { +func (c *ApiService) streamShortCodeWithContext(ctx context.Context, response *ListShortCodeResponse, params *ListShortCodeParams, recordChannel chan ProxyV1ShortCode, errorChannel chan error) { curRecord := 1 for response != nil { @@ -217,7 +242,7 @@ func (c *ApiService) streamShortCode(response *ListShortCodeResponse, params *Li } } - record, err := client.GetNext(c.baseURL, response, c.getNextListShortCodeResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListShortCodeResponseWithContext) if err != nil { errorChannel <- err break @@ -232,11 +257,11 @@ func (c *ApiService) streamShortCode(response *ListShortCodeResponse, params *Li close(errorChannel) } -func (c *ApiService) getNextListShortCodeResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListShortCodeResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -263,6 +288,9 @@ func (params *UpdateShortCodeParams) SetIsReserved(IsReserved bool) *UpdateShort // Update a specific Short Code. func (c *ApiService) UpdateShortCode(ServiceSid string, Sid string, params *UpdateShortCodeParams) (*ProxyV1ShortCode, error) { + return c.UpdateShortCodeWithContext(context.TODO(), ServiceSid, Sid, params) +} +func (c *ApiService) UpdateShortCodeWithContext(ctx context.Context, ServiceSid string, Sid string, params *UpdateShortCodeParams) (*ProxyV1ShortCode, error) { path := "/v1/Services/{ServiceSid}/ShortCodes/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -276,7 +304,7 @@ func (c *ApiService) UpdateShortCode(ServiceSid string, Sid string, params *Upda data.Set("IsReserved", fmt.Sprint(*params.IsReserved)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/routes/v2/api_service.go b/rest/routes/v2/api_service.go index 5b829d4d0..1a5922c16 100644 --- a/rest/routes/v2/api_service.go +++ b/rest/routes/v2/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://routes.twilio.com", + } +} diff --git a/rest/routes/v2/phone_numbers.go b/rest/routes/v2/phone_numbers.go index 41df081fd..13e9849c3 100644 --- a/rest/routes/v2/phone_numbers.go +++ b/rest/routes/v2/phone_numbers.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -22,6 +23,9 @@ import ( // Fetch the Inbound Processing Region assigned to a phone number. func (c *ApiService) FetchPhoneNumber(PhoneNumber string) (*RoutesV2PhoneNumber, error) { + return c.FetchPhoneNumberWithContext(context.TODO(), PhoneNumber) +} +func (c *ApiService) FetchPhoneNumberWithContext(ctx context.Context, PhoneNumber string) (*RoutesV2PhoneNumber, error) { path := "/v2/PhoneNumbers/{PhoneNumber}" path = strings.Replace(path, "{"+"PhoneNumber"+"}", PhoneNumber, -1) @@ -30,7 +34,7 @@ func (c *ApiService) FetchPhoneNumber(PhoneNumber string) (*RoutesV2PhoneNumber, "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -64,6 +68,9 @@ func (params *UpdatePhoneNumberParams) SetFriendlyName(FriendlyName string) *Upd // Assign an Inbound Processing Region to a phone number. func (c *ApiService) UpdatePhoneNumber(PhoneNumber string, params *UpdatePhoneNumberParams) (*RoutesV2PhoneNumber, error) { + return c.UpdatePhoneNumberWithContext(context.TODO(), PhoneNumber, params) +} +func (c *ApiService) UpdatePhoneNumberWithContext(ctx context.Context, PhoneNumber string, params *UpdatePhoneNumberParams) (*RoutesV2PhoneNumber, error) { path := "/v2/PhoneNumbers/{PhoneNumber}" path = strings.Replace(path, "{"+"PhoneNumber"+"}", PhoneNumber, -1) @@ -79,7 +86,7 @@ func (c *ApiService) UpdatePhoneNumber(PhoneNumber string, params *UpdatePhoneNu data.Set("FriendlyName", *params.FriendlyName) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/routes/v2/sip_domains.go b/rest/routes/v2/sip_domains.go index e9f4deacd..d6a7ea743 100644 --- a/rest/routes/v2/sip_domains.go +++ b/rest/routes/v2/sip_domains.go @@ -15,13 +15,16 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" ) -// func (c *ApiService) FetchSipDomain(SipDomain string) (*RoutesV2SipDomain, error) { + return c.FetchSipDomainWithContext(context.TODO(), SipDomain) +} +func (c *ApiService) FetchSipDomainWithContext(ctx context.Context, SipDomain string) (*RoutesV2SipDomain, error) { path := "/v2/SipDomains/{SipDomain}" path = strings.Replace(path, "{"+"SipDomain"+"}", SipDomain, -1) @@ -30,7 +33,7 @@ func (c *ApiService) FetchSipDomain(SipDomain string) (*RoutesV2SipDomain, error "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -62,8 +65,10 @@ func (params *UpdateSipDomainParams) SetFriendlyName(FriendlyName string) *Updat return params } -// func (c *ApiService) UpdateSipDomain(SipDomain string, params *UpdateSipDomainParams) (*RoutesV2SipDomain, error) { + return c.UpdateSipDomainWithContext(context.TODO(), SipDomain, params) +} +func (c *ApiService) UpdateSipDomainWithContext(ctx context.Context, SipDomain string, params *UpdateSipDomainParams) (*RoutesV2SipDomain, error) { path := "/v2/SipDomains/{SipDomain}" path = strings.Replace(path, "{"+"SipDomain"+"}", SipDomain, -1) @@ -79,7 +84,7 @@ func (c *ApiService) UpdateSipDomain(SipDomain string, params *UpdateSipDomainPa data.Set("FriendlyName", *params.FriendlyName) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/routes/v2/trunks.go b/rest/routes/v2/trunks.go index 5d2c1c0bc..2700cebd1 100644 --- a/rest/routes/v2/trunks.go +++ b/rest/routes/v2/trunks.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -22,6 +23,9 @@ import ( // Fetch the Inbound Processing Region assigned to a SIP Trunk. func (c *ApiService) FetchTrunks(SipTrunkDomain string) (*RoutesV2Trunks, error) { + return c.FetchTrunksWithContext(context.TODO(), SipTrunkDomain) +} +func (c *ApiService) FetchTrunksWithContext(ctx context.Context, SipTrunkDomain string) (*RoutesV2Trunks, error) { path := "/v2/Trunks/{SipTrunkDomain}" path = strings.Replace(path, "{"+"SipTrunkDomain"+"}", SipTrunkDomain, -1) @@ -30,7 +34,7 @@ func (c *ApiService) FetchTrunks(SipTrunkDomain string) (*RoutesV2Trunks, error) "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -64,6 +68,9 @@ func (params *UpdateTrunksParams) SetFriendlyName(FriendlyName string) *UpdateTr // Assign an Inbound Processing Region to a SIP Trunk func (c *ApiService) UpdateTrunks(SipTrunkDomain string, params *UpdateTrunksParams) (*RoutesV2Trunks, error) { + return c.UpdateTrunksWithContext(context.TODO(), SipTrunkDomain, params) +} +func (c *ApiService) UpdateTrunksWithContext(ctx context.Context, SipTrunkDomain string, params *UpdateTrunksParams) (*RoutesV2Trunks, error) { path := "/v2/Trunks/{SipTrunkDomain}" path = strings.Replace(path, "{"+"SipTrunkDomain"+"}", SipTrunkDomain, -1) @@ -79,7 +86,7 @@ func (c *ApiService) UpdateTrunks(SipTrunkDomain string, params *UpdateTrunksPar data.Set("FriendlyName", *params.FriendlyName) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/serverless/v1/api_service.go b/rest/serverless/v1/api_service.go index 133adbdb0..95f05c422 100644 --- a/rest/serverless/v1/api_service.go +++ b/rest/serverless/v1/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://serverless.twilio.com", + } +} diff --git a/rest/serverless/v1/services.go b/rest/serverless/v1/services.go index ead2cb99c..5c9dbf2e3 100644 --- a/rest/serverless/v1/services.go +++ b/rest/serverless/v1/services.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -54,6 +55,9 @@ func (params *CreateServiceParams) SetUiEditable(UiEditable bool) *CreateService // Create a new Service resource. func (c *ApiService) CreateService(params *CreateServiceParams) (*ServerlessV1Service, error) { + return c.CreateServiceWithContext(context.TODO(), params) +} +func (c *ApiService) CreateServiceWithContext(ctx context.Context, params *CreateServiceParams) (*ServerlessV1Service, error) { path := "/v1/Services" data := url.Values{} @@ -74,7 +78,7 @@ func (c *ApiService) CreateService(params *CreateServiceParams) (*ServerlessV1Se data.Set("UiEditable", fmt.Sprint(*params.UiEditable)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -91,6 +95,9 @@ func (c *ApiService) CreateService(params *CreateServiceParams) (*ServerlessV1Se // Delete a Service resource. func (c *ApiService) DeleteService(Sid string) error { + return c.DeleteServiceWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteServiceWithContext(ctx context.Context, Sid string) error { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -99,7 +106,7 @@ func (c *ApiService) DeleteService(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -111,6 +118,9 @@ func (c *ApiService) DeleteService(Sid string) error { // Retrieve a specific Service resource. func (c *ApiService) FetchService(Sid string) (*ServerlessV1Service, error) { + return c.FetchServiceWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchServiceWithContext(ctx context.Context, Sid string) (*ServerlessV1Service, error) { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -119,7 +129,7 @@ func (c *ApiService) FetchService(Sid string) (*ServerlessV1Service, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -153,6 +163,11 @@ func (params *ListServiceParams) SetLimit(Limit int) *ListServiceParams { // Retrieve a single page of Service records from the API. Request is executed immediately. func (c *ApiService) PageService(params *ListServiceParams, pageToken, pageNumber string) (*ListServiceResponse, error) { + return c.PageServiceWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Service records from the API. Request is executed immediately. +func (c *ApiService) PageServiceWithContext(ctx context.Context, params *ListServiceParams, pageToken, pageNumber string) (*ListServiceResponse, error) { path := "/v1/Services" data := url.Values{} @@ -171,7 +186,7 @@ func (c *ApiService) PageService(params *ListServiceParams, pageToken, pageNumbe data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -188,7 +203,12 @@ func (c *ApiService) PageService(params *ListServiceParams, pageToken, pageNumbe // Lists Service records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListService(params *ListServiceParams) ([]ServerlessV1Service, error) { - response, errors := c.StreamService(params) + return c.ListServiceWithContext(context.TODO(), params) +} + +// Lists Service records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListServiceWithContext(ctx context.Context, params *ListServiceParams) ([]ServerlessV1Service, error) { + response, errors := c.StreamServiceWithContext(ctx, params) records := make([]ServerlessV1Service, 0) for record := range response { @@ -204,6 +224,11 @@ func (c *ApiService) ListService(params *ListServiceParams) ([]ServerlessV1Servi // Streams Service records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamService(params *ListServiceParams) (chan ServerlessV1Service, chan error) { + return c.StreamServiceWithContext(context.TODO(), params) +} + +// Streams Service records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamServiceWithContext(ctx context.Context, params *ListServiceParams) (chan ServerlessV1Service, chan error) { if params == nil { params = &ListServiceParams{} } @@ -212,19 +237,19 @@ func (c *ApiService) StreamService(params *ListServiceParams) (chan ServerlessV1 recordChannel := make(chan ServerlessV1Service, 1) errorChannel := make(chan error, 1) - response, err := c.PageService(params, "", "") + response, err := c.PageServiceWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamService(response, params, recordChannel, errorChannel) + go c.streamServiceWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamService(response *ListServiceResponse, params *ListServiceParams, recordChannel chan ServerlessV1Service, errorChannel chan error) { +func (c *ApiService) streamServiceWithContext(ctx context.Context, response *ListServiceResponse, params *ListServiceParams, recordChannel chan ServerlessV1Service, errorChannel chan error) { curRecord := 1 for response != nil { @@ -239,7 +264,7 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListServiceResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListServiceResponseWithContext) if err != nil { errorChannel <- err break @@ -254,11 +279,11 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe close(errorChannel) } -func (c *ApiService) getNextListServiceResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListServiceResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -297,6 +322,9 @@ func (params *UpdateServiceParams) SetUiEditable(UiEditable bool) *UpdateService // Update a specific Service resource. func (c *ApiService) UpdateService(Sid string, params *UpdateServiceParams) (*ServerlessV1Service, error) { + return c.UpdateServiceWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateServiceWithContext(ctx context.Context, Sid string, params *UpdateServiceParams) (*ServerlessV1Service, error) { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -315,7 +343,7 @@ func (c *ApiService) UpdateService(Sid string, params *UpdateServiceParams) (*Se data.Set("UiEditable", fmt.Sprint(*params.UiEditable)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/serverless/v1/services_assets.go b/rest/serverless/v1/services_assets.go index c39c6ade4..c79216263 100644 --- a/rest/serverless/v1/services_assets.go +++ b/rest/serverless/v1/services_assets.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -36,6 +37,9 @@ func (params *CreateAssetParams) SetFriendlyName(FriendlyName string) *CreateAss // Create a new Asset resource. func (c *ApiService) CreateAsset(ServiceSid string, params *CreateAssetParams) (*ServerlessV1Asset, error) { + return c.CreateAssetWithContext(context.TODO(), ServiceSid, params) +} +func (c *ApiService) CreateAssetWithContext(ctx context.Context, ServiceSid string, params *CreateAssetParams) (*ServerlessV1Asset, error) { path := "/v1/Services/{ServiceSid}/Assets" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -48,7 +52,7 @@ func (c *ApiService) CreateAsset(ServiceSid string, params *CreateAssetParams) ( data.Set("FriendlyName", *params.FriendlyName) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -65,6 +69,9 @@ func (c *ApiService) CreateAsset(ServiceSid string, params *CreateAssetParams) ( // Delete an Asset resource. func (c *ApiService) DeleteAsset(ServiceSid string, Sid string) error { + return c.DeleteAssetWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) DeleteAssetWithContext(ctx context.Context, ServiceSid string, Sid string) error { path := "/v1/Services/{ServiceSid}/Assets/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -74,7 +81,7 @@ func (c *ApiService) DeleteAsset(ServiceSid string, Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -86,6 +93,9 @@ func (c *ApiService) DeleteAsset(ServiceSid string, Sid string) error { // Retrieve a specific Asset resource. func (c *ApiService) FetchAsset(ServiceSid string, Sid string) (*ServerlessV1Asset, error) { + return c.FetchAssetWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) FetchAssetWithContext(ctx context.Context, ServiceSid string, Sid string) (*ServerlessV1Asset, error) { path := "/v1/Services/{ServiceSid}/Assets/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -95,7 +105,7 @@ func (c *ApiService) FetchAsset(ServiceSid string, Sid string) (*ServerlessV1Ass "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -129,6 +139,11 @@ func (params *ListAssetParams) SetLimit(Limit int) *ListAssetParams { // Retrieve a single page of Asset records from the API. Request is executed immediately. func (c *ApiService) PageAsset(ServiceSid string, params *ListAssetParams, pageToken, pageNumber string) (*ListAssetResponse, error) { + return c.PageAssetWithContext(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Asset records from the API. Request is executed immediately. +func (c *ApiService) PageAssetWithContext(ctx context.Context, ServiceSid string, params *ListAssetParams, pageToken, pageNumber string) (*ListAssetResponse, error) { path := "/v1/Services/{ServiceSid}/Assets" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -149,7 +164,7 @@ func (c *ApiService) PageAsset(ServiceSid string, params *ListAssetParams, pageT data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -166,7 +181,12 @@ func (c *ApiService) PageAsset(ServiceSid string, params *ListAssetParams, pageT // Lists Asset records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListAsset(ServiceSid string, params *ListAssetParams) ([]ServerlessV1Asset, error) { - response, errors := c.StreamAsset(ServiceSid, params) + return c.ListAssetWithContext(context.TODO(), ServiceSid, params) +} + +// Lists Asset records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListAssetWithContext(ctx context.Context, ServiceSid string, params *ListAssetParams) ([]ServerlessV1Asset, error) { + response, errors := c.StreamAssetWithContext(ctx, ServiceSid, params) records := make([]ServerlessV1Asset, 0) for record := range response { @@ -182,6 +202,11 @@ func (c *ApiService) ListAsset(ServiceSid string, params *ListAssetParams) ([]Se // Streams Asset records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamAsset(ServiceSid string, params *ListAssetParams) (chan ServerlessV1Asset, chan error) { + return c.StreamAssetWithContext(context.TODO(), ServiceSid, params) +} + +// Streams Asset records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamAssetWithContext(ctx context.Context, ServiceSid string, params *ListAssetParams) (chan ServerlessV1Asset, chan error) { if params == nil { params = &ListAssetParams{} } @@ -190,19 +215,19 @@ func (c *ApiService) StreamAsset(ServiceSid string, params *ListAssetParams) (ch recordChannel := make(chan ServerlessV1Asset, 1) errorChannel := make(chan error, 1) - response, err := c.PageAsset(ServiceSid, params, "", "") + response, err := c.PageAssetWithContext(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamAsset(response, params, recordChannel, errorChannel) + go c.streamAssetWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamAsset(response *ListAssetResponse, params *ListAssetParams, recordChannel chan ServerlessV1Asset, errorChannel chan error) { +func (c *ApiService) streamAssetWithContext(ctx context.Context, response *ListAssetResponse, params *ListAssetParams, recordChannel chan ServerlessV1Asset, errorChannel chan error) { curRecord := 1 for response != nil { @@ -217,7 +242,7 @@ func (c *ApiService) streamAsset(response *ListAssetResponse, params *ListAssetP } } - record, err := client.GetNext(c.baseURL, response, c.getNextListAssetResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListAssetResponseWithContext) if err != nil { errorChannel <- err break @@ -232,11 +257,11 @@ func (c *ApiService) streamAsset(response *ListAssetResponse, params *ListAssetP close(errorChannel) } -func (c *ApiService) getNextListAssetResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListAssetResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -263,6 +288,9 @@ func (params *UpdateAssetParams) SetFriendlyName(FriendlyName string) *UpdateAss // Update a specific Asset resource. func (c *ApiService) UpdateAsset(ServiceSid string, Sid string, params *UpdateAssetParams) (*ServerlessV1Asset, error) { + return c.UpdateAssetWithContext(context.TODO(), ServiceSid, Sid, params) +} +func (c *ApiService) UpdateAssetWithContext(ctx context.Context, ServiceSid string, Sid string, params *UpdateAssetParams) (*ServerlessV1Asset, error) { path := "/v1/Services/{ServiceSid}/Assets/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -276,7 +304,7 @@ func (c *ApiService) UpdateAsset(ServiceSid string, Sid string, params *UpdateAs data.Set("FriendlyName", *params.FriendlyName) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/serverless/v1/services_assets_versions.go b/rest/serverless/v1/services_assets_versions.go index 9974c7fb0..0508879cb 100644 --- a/rest/serverless/v1/services_assets_versions.go +++ b/rest/serverless/v1/services_assets_versions.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -25,6 +26,9 @@ import ( // Retrieve a specific Asset Version. func (c *ApiService) FetchAssetVersion(ServiceSid string, AssetSid string, Sid string) (*ServerlessV1AssetVersion, error) { + return c.FetchAssetVersionWithContext(context.TODO(), ServiceSid, AssetSid, Sid) +} +func (c *ApiService) FetchAssetVersionWithContext(ctx context.Context, ServiceSid string, AssetSid string, Sid string) (*ServerlessV1AssetVersion, error) { path := "/v1/Services/{ServiceSid}/Assets/{AssetSid}/Versions/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"AssetSid"+"}", AssetSid, -1) @@ -35,7 +39,7 @@ func (c *ApiService) FetchAssetVersion(ServiceSid string, AssetSid string, Sid s "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -69,6 +73,11 @@ func (params *ListAssetVersionParams) SetLimit(Limit int) *ListAssetVersionParam // Retrieve a single page of AssetVersion records from the API. Request is executed immediately. func (c *ApiService) PageAssetVersion(ServiceSid string, AssetSid string, params *ListAssetVersionParams, pageToken, pageNumber string) (*ListAssetVersionResponse, error) { + return c.PageAssetVersionWithContext(context.TODO(), ServiceSid, AssetSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of AssetVersion records from the API. Request is executed immediately. +func (c *ApiService) PageAssetVersionWithContext(ctx context.Context, ServiceSid string, AssetSid string, params *ListAssetVersionParams, pageToken, pageNumber string) (*ListAssetVersionResponse, error) { path := "/v1/Services/{ServiceSid}/Assets/{AssetSid}/Versions" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -90,7 +99,7 @@ func (c *ApiService) PageAssetVersion(ServiceSid string, AssetSid string, params data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -107,7 +116,12 @@ func (c *ApiService) PageAssetVersion(ServiceSid string, AssetSid string, params // Lists AssetVersion records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListAssetVersion(ServiceSid string, AssetSid string, params *ListAssetVersionParams) ([]ServerlessV1AssetVersion, error) { - response, errors := c.StreamAssetVersion(ServiceSid, AssetSid, params) + return c.ListAssetVersionWithContext(context.TODO(), ServiceSid, AssetSid, params) +} + +// Lists AssetVersion records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListAssetVersionWithContext(ctx context.Context, ServiceSid string, AssetSid string, params *ListAssetVersionParams) ([]ServerlessV1AssetVersion, error) { + response, errors := c.StreamAssetVersionWithContext(ctx, ServiceSid, AssetSid, params) records := make([]ServerlessV1AssetVersion, 0) for record := range response { @@ -123,6 +137,11 @@ func (c *ApiService) ListAssetVersion(ServiceSid string, AssetSid string, params // Streams AssetVersion records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamAssetVersion(ServiceSid string, AssetSid string, params *ListAssetVersionParams) (chan ServerlessV1AssetVersion, chan error) { + return c.StreamAssetVersionWithContext(context.TODO(), ServiceSid, AssetSid, params) +} + +// Streams AssetVersion records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamAssetVersionWithContext(ctx context.Context, ServiceSid string, AssetSid string, params *ListAssetVersionParams) (chan ServerlessV1AssetVersion, chan error) { if params == nil { params = &ListAssetVersionParams{} } @@ -131,19 +150,19 @@ func (c *ApiService) StreamAssetVersion(ServiceSid string, AssetSid string, para recordChannel := make(chan ServerlessV1AssetVersion, 1) errorChannel := make(chan error, 1) - response, err := c.PageAssetVersion(ServiceSid, AssetSid, params, "", "") + response, err := c.PageAssetVersionWithContext(ctx, ServiceSid, AssetSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamAssetVersion(response, params, recordChannel, errorChannel) + go c.streamAssetVersionWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamAssetVersion(response *ListAssetVersionResponse, params *ListAssetVersionParams, recordChannel chan ServerlessV1AssetVersion, errorChannel chan error) { +func (c *ApiService) streamAssetVersionWithContext(ctx context.Context, response *ListAssetVersionResponse, params *ListAssetVersionParams, recordChannel chan ServerlessV1AssetVersion, errorChannel chan error) { curRecord := 1 for response != nil { @@ -158,7 +177,7 @@ func (c *ApiService) streamAssetVersion(response *ListAssetVersionResponse, para } } - record, err := client.GetNext(c.baseURL, response, c.getNextListAssetVersionResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListAssetVersionResponseWithContext) if err != nil { errorChannel <- err break @@ -173,11 +192,11 @@ func (c *ApiService) streamAssetVersion(response *ListAssetVersionResponse, para close(errorChannel) } -func (c *ApiService) getNextListAssetVersionResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListAssetVersionResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/serverless/v1/services_builds.go b/rest/serverless/v1/services_builds.go index 27b2fe423..b5e7902dd 100644 --- a/rest/serverless/v1/services_builds.go +++ b/rest/serverless/v1/services_builds.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -54,6 +55,9 @@ func (params *CreateBuildParams) SetRuntime(Runtime string) *CreateBuildParams { // Create a new Build resource. At least one function version or asset version is required. func (c *ApiService) CreateBuild(ServiceSid string, params *CreateBuildParams) (*ServerlessV1Build, error) { + return c.CreateBuildWithContext(context.TODO(), ServiceSid, params) +} +func (c *ApiService) CreateBuildWithContext(ctx context.Context, ServiceSid string, params *CreateBuildParams) (*ServerlessV1Build, error) { path := "/v1/Services/{ServiceSid}/Builds" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -79,7 +83,7 @@ func (c *ApiService) CreateBuild(ServiceSid string, params *CreateBuildParams) ( data.Set("Runtime", *params.Runtime) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -96,6 +100,9 @@ func (c *ApiService) CreateBuild(ServiceSid string, params *CreateBuildParams) ( // Delete a Build resource. func (c *ApiService) DeleteBuild(ServiceSid string, Sid string) error { + return c.DeleteBuildWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) DeleteBuildWithContext(ctx context.Context, ServiceSid string, Sid string) error { path := "/v1/Services/{ServiceSid}/Builds/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -105,7 +112,7 @@ func (c *ApiService) DeleteBuild(ServiceSid string, Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -117,6 +124,9 @@ func (c *ApiService) DeleteBuild(ServiceSid string, Sid string) error { // Retrieve a specific Build resource. func (c *ApiService) FetchBuild(ServiceSid string, Sid string) (*ServerlessV1Build, error) { + return c.FetchBuildWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) FetchBuildWithContext(ctx context.Context, ServiceSid string, Sid string) (*ServerlessV1Build, error) { path := "/v1/Services/{ServiceSid}/Builds/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -126,7 +136,7 @@ func (c *ApiService) FetchBuild(ServiceSid string, Sid string) (*ServerlessV1Bui "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -160,6 +170,11 @@ func (params *ListBuildParams) SetLimit(Limit int) *ListBuildParams { // Retrieve a single page of Build records from the API. Request is executed immediately. func (c *ApiService) PageBuild(ServiceSid string, params *ListBuildParams, pageToken, pageNumber string) (*ListBuildResponse, error) { + return c.PageBuildWithContext(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Build records from the API. Request is executed immediately. +func (c *ApiService) PageBuildWithContext(ctx context.Context, ServiceSid string, params *ListBuildParams, pageToken, pageNumber string) (*ListBuildResponse, error) { path := "/v1/Services/{ServiceSid}/Builds" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -180,7 +195,7 @@ func (c *ApiService) PageBuild(ServiceSid string, params *ListBuildParams, pageT data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -197,7 +212,12 @@ func (c *ApiService) PageBuild(ServiceSid string, params *ListBuildParams, pageT // Lists Build records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListBuild(ServiceSid string, params *ListBuildParams) ([]ServerlessV1Build, error) { - response, errors := c.StreamBuild(ServiceSid, params) + return c.ListBuildWithContext(context.TODO(), ServiceSid, params) +} + +// Lists Build records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListBuildWithContext(ctx context.Context, ServiceSid string, params *ListBuildParams) ([]ServerlessV1Build, error) { + response, errors := c.StreamBuildWithContext(ctx, ServiceSid, params) records := make([]ServerlessV1Build, 0) for record := range response { @@ -213,6 +233,11 @@ func (c *ApiService) ListBuild(ServiceSid string, params *ListBuildParams) ([]Se // Streams Build records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamBuild(ServiceSid string, params *ListBuildParams) (chan ServerlessV1Build, chan error) { + return c.StreamBuildWithContext(context.TODO(), ServiceSid, params) +} + +// Streams Build records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamBuildWithContext(ctx context.Context, ServiceSid string, params *ListBuildParams) (chan ServerlessV1Build, chan error) { if params == nil { params = &ListBuildParams{} } @@ -221,19 +246,19 @@ func (c *ApiService) StreamBuild(ServiceSid string, params *ListBuildParams) (ch recordChannel := make(chan ServerlessV1Build, 1) errorChannel := make(chan error, 1) - response, err := c.PageBuild(ServiceSid, params, "", "") + response, err := c.PageBuildWithContext(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamBuild(response, params, recordChannel, errorChannel) + go c.streamBuildWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamBuild(response *ListBuildResponse, params *ListBuildParams, recordChannel chan ServerlessV1Build, errorChannel chan error) { +func (c *ApiService) streamBuildWithContext(ctx context.Context, response *ListBuildResponse, params *ListBuildParams, recordChannel chan ServerlessV1Build, errorChannel chan error) { curRecord := 1 for response != nil { @@ -248,7 +273,7 @@ func (c *ApiService) streamBuild(response *ListBuildResponse, params *ListBuildP } } - record, err := client.GetNext(c.baseURL, response, c.getNextListBuildResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListBuildResponseWithContext) if err != nil { errorChannel <- err break @@ -263,11 +288,11 @@ func (c *ApiService) streamBuild(response *ListBuildResponse, params *ListBuildP close(errorChannel) } -func (c *ApiService) getNextListBuildResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListBuildResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/serverless/v1/services_builds_status.go b/rest/serverless/v1/services_builds_status.go index 17e6b0a0b..c83fac5d7 100644 --- a/rest/serverless/v1/services_builds_status.go +++ b/rest/serverless/v1/services_builds_status.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -22,6 +23,9 @@ import ( // Retrieve a specific Build resource. func (c *ApiService) FetchBuildStatus(ServiceSid string, Sid string) (*ServerlessV1BuildStatus, error) { + return c.FetchBuildStatusWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) FetchBuildStatusWithContext(ctx context.Context, ServiceSid string, Sid string) (*ServerlessV1BuildStatus, error) { path := "/v1/Services/{ServiceSid}/Builds/{Sid}/Status" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -31,7 +35,7 @@ func (c *ApiService) FetchBuildStatus(ServiceSid string, Sid string) (*Serverles "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/serverless/v1/services_environments.go b/rest/serverless/v1/services_environments.go index 5711e31d7..fe35764cf 100644 --- a/rest/serverless/v1/services_environments.go +++ b/rest/serverless/v1/services_environments.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -42,6 +43,9 @@ func (params *CreateEnvironmentParams) SetDomainSuffix(DomainSuffix string) *Cre // Create a new environment. func (c *ApiService) CreateEnvironment(ServiceSid string, params *CreateEnvironmentParams) (*ServerlessV1Environment, error) { + return c.CreateEnvironmentWithContext(context.TODO(), ServiceSid, params) +} +func (c *ApiService) CreateEnvironmentWithContext(ctx context.Context, ServiceSid string, params *CreateEnvironmentParams) (*ServerlessV1Environment, error) { path := "/v1/Services/{ServiceSid}/Environments" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -57,7 +61,7 @@ func (c *ApiService) CreateEnvironment(ServiceSid string, params *CreateEnvironm data.Set("DomainSuffix", *params.DomainSuffix) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -74,6 +78,9 @@ func (c *ApiService) CreateEnvironment(ServiceSid string, params *CreateEnvironm // Delete a specific environment. func (c *ApiService) DeleteEnvironment(ServiceSid string, Sid string) error { + return c.DeleteEnvironmentWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) DeleteEnvironmentWithContext(ctx context.Context, ServiceSid string, Sid string) error { path := "/v1/Services/{ServiceSid}/Environments/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -83,7 +90,7 @@ func (c *ApiService) DeleteEnvironment(ServiceSid string, Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -95,6 +102,9 @@ func (c *ApiService) DeleteEnvironment(ServiceSid string, Sid string) error { // Retrieve a specific environment. func (c *ApiService) FetchEnvironment(ServiceSid string, Sid string) (*ServerlessV1Environment, error) { + return c.FetchEnvironmentWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) FetchEnvironmentWithContext(ctx context.Context, ServiceSid string, Sid string) (*ServerlessV1Environment, error) { path := "/v1/Services/{ServiceSid}/Environments/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -104,7 +114,7 @@ func (c *ApiService) FetchEnvironment(ServiceSid string, Sid string) (*Serverles "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -138,6 +148,11 @@ func (params *ListEnvironmentParams) SetLimit(Limit int) *ListEnvironmentParams // Retrieve a single page of Environment records from the API. Request is executed immediately. func (c *ApiService) PageEnvironment(ServiceSid string, params *ListEnvironmentParams, pageToken, pageNumber string) (*ListEnvironmentResponse, error) { + return c.PageEnvironmentWithContext(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Environment records from the API. Request is executed immediately. +func (c *ApiService) PageEnvironmentWithContext(ctx context.Context, ServiceSid string, params *ListEnvironmentParams, pageToken, pageNumber string) (*ListEnvironmentResponse, error) { path := "/v1/Services/{ServiceSid}/Environments" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -158,7 +173,7 @@ func (c *ApiService) PageEnvironment(ServiceSid string, params *ListEnvironmentP data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -175,7 +190,12 @@ func (c *ApiService) PageEnvironment(ServiceSid string, params *ListEnvironmentP // Lists Environment records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListEnvironment(ServiceSid string, params *ListEnvironmentParams) ([]ServerlessV1Environment, error) { - response, errors := c.StreamEnvironment(ServiceSid, params) + return c.ListEnvironmentWithContext(context.TODO(), ServiceSid, params) +} + +// Lists Environment records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListEnvironmentWithContext(ctx context.Context, ServiceSid string, params *ListEnvironmentParams) ([]ServerlessV1Environment, error) { + response, errors := c.StreamEnvironmentWithContext(ctx, ServiceSid, params) records := make([]ServerlessV1Environment, 0) for record := range response { @@ -191,6 +211,11 @@ func (c *ApiService) ListEnvironment(ServiceSid string, params *ListEnvironmentP // Streams Environment records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamEnvironment(ServiceSid string, params *ListEnvironmentParams) (chan ServerlessV1Environment, chan error) { + return c.StreamEnvironmentWithContext(context.TODO(), ServiceSid, params) +} + +// Streams Environment records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamEnvironmentWithContext(ctx context.Context, ServiceSid string, params *ListEnvironmentParams) (chan ServerlessV1Environment, chan error) { if params == nil { params = &ListEnvironmentParams{} } @@ -199,19 +224,19 @@ func (c *ApiService) StreamEnvironment(ServiceSid string, params *ListEnvironmen recordChannel := make(chan ServerlessV1Environment, 1) errorChannel := make(chan error, 1) - response, err := c.PageEnvironment(ServiceSid, params, "", "") + response, err := c.PageEnvironmentWithContext(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamEnvironment(response, params, recordChannel, errorChannel) + go c.streamEnvironmentWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamEnvironment(response *ListEnvironmentResponse, params *ListEnvironmentParams, recordChannel chan ServerlessV1Environment, errorChannel chan error) { +func (c *ApiService) streamEnvironmentWithContext(ctx context.Context, response *ListEnvironmentResponse, params *ListEnvironmentParams, recordChannel chan ServerlessV1Environment, errorChannel chan error) { curRecord := 1 for response != nil { @@ -226,7 +251,7 @@ func (c *ApiService) streamEnvironment(response *ListEnvironmentResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListEnvironmentResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListEnvironmentResponseWithContext) if err != nil { errorChannel <- err break @@ -241,11 +266,11 @@ func (c *ApiService) streamEnvironment(response *ListEnvironmentResponse, params close(errorChannel) } -func (c *ApiService) getNextListEnvironmentResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListEnvironmentResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/serverless/v1/services_environments_deployments.go b/rest/serverless/v1/services_environments_deployments.go index da5816e6e..e4d3b9657 100644 --- a/rest/serverless/v1/services_environments_deployments.go +++ b/rest/serverless/v1/services_environments_deployments.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -42,6 +43,9 @@ func (params *CreateDeploymentParams) SetIsPlugin(IsPlugin bool) *CreateDeployme // Create a new Deployment. func (c *ApiService) CreateDeployment(ServiceSid string, EnvironmentSid string, params *CreateDeploymentParams) (*ServerlessV1Deployment, error) { + return c.CreateDeploymentWithContext(context.TODO(), ServiceSid, EnvironmentSid, params) +} +func (c *ApiService) CreateDeploymentWithContext(ctx context.Context, ServiceSid string, EnvironmentSid string, params *CreateDeploymentParams) (*ServerlessV1Deployment, error) { path := "/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Deployments" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"EnvironmentSid"+"}", EnvironmentSid, -1) @@ -58,7 +62,7 @@ func (c *ApiService) CreateDeployment(ServiceSid string, EnvironmentSid string, data.Set("IsPlugin", fmt.Sprint(*params.IsPlugin)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -75,6 +79,9 @@ func (c *ApiService) CreateDeployment(ServiceSid string, EnvironmentSid string, // Retrieve a specific Deployment. func (c *ApiService) FetchDeployment(ServiceSid string, EnvironmentSid string, Sid string) (*ServerlessV1Deployment, error) { + return c.FetchDeploymentWithContext(context.TODO(), ServiceSid, EnvironmentSid, Sid) +} +func (c *ApiService) FetchDeploymentWithContext(ctx context.Context, ServiceSid string, EnvironmentSid string, Sid string) (*ServerlessV1Deployment, error) { path := "/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Deployments/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"EnvironmentSid"+"}", EnvironmentSid, -1) @@ -85,7 +92,7 @@ func (c *ApiService) FetchDeployment(ServiceSid string, EnvironmentSid string, S "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -119,6 +126,11 @@ func (params *ListDeploymentParams) SetLimit(Limit int) *ListDeploymentParams { // Retrieve a single page of Deployment records from the API. Request is executed immediately. func (c *ApiService) PageDeployment(ServiceSid string, EnvironmentSid string, params *ListDeploymentParams, pageToken, pageNumber string) (*ListDeploymentResponse, error) { + return c.PageDeploymentWithContext(context.TODO(), ServiceSid, EnvironmentSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Deployment records from the API. Request is executed immediately. +func (c *ApiService) PageDeploymentWithContext(ctx context.Context, ServiceSid string, EnvironmentSid string, params *ListDeploymentParams, pageToken, pageNumber string) (*ListDeploymentResponse, error) { path := "/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Deployments" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -140,7 +152,7 @@ func (c *ApiService) PageDeployment(ServiceSid string, EnvironmentSid string, pa data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -157,7 +169,12 @@ func (c *ApiService) PageDeployment(ServiceSid string, EnvironmentSid string, pa // Lists Deployment records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListDeployment(ServiceSid string, EnvironmentSid string, params *ListDeploymentParams) ([]ServerlessV1Deployment, error) { - response, errors := c.StreamDeployment(ServiceSid, EnvironmentSid, params) + return c.ListDeploymentWithContext(context.TODO(), ServiceSid, EnvironmentSid, params) +} + +// Lists Deployment records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListDeploymentWithContext(ctx context.Context, ServiceSid string, EnvironmentSid string, params *ListDeploymentParams) ([]ServerlessV1Deployment, error) { + response, errors := c.StreamDeploymentWithContext(ctx, ServiceSid, EnvironmentSid, params) records := make([]ServerlessV1Deployment, 0) for record := range response { @@ -173,6 +190,11 @@ func (c *ApiService) ListDeployment(ServiceSid string, EnvironmentSid string, pa // Streams Deployment records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamDeployment(ServiceSid string, EnvironmentSid string, params *ListDeploymentParams) (chan ServerlessV1Deployment, chan error) { + return c.StreamDeploymentWithContext(context.TODO(), ServiceSid, EnvironmentSid, params) +} + +// Streams Deployment records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamDeploymentWithContext(ctx context.Context, ServiceSid string, EnvironmentSid string, params *ListDeploymentParams) (chan ServerlessV1Deployment, chan error) { if params == nil { params = &ListDeploymentParams{} } @@ -181,19 +203,19 @@ func (c *ApiService) StreamDeployment(ServiceSid string, EnvironmentSid string, recordChannel := make(chan ServerlessV1Deployment, 1) errorChannel := make(chan error, 1) - response, err := c.PageDeployment(ServiceSid, EnvironmentSid, params, "", "") + response, err := c.PageDeploymentWithContext(ctx, ServiceSid, EnvironmentSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamDeployment(response, params, recordChannel, errorChannel) + go c.streamDeploymentWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamDeployment(response *ListDeploymentResponse, params *ListDeploymentParams, recordChannel chan ServerlessV1Deployment, errorChannel chan error) { +func (c *ApiService) streamDeploymentWithContext(ctx context.Context, response *ListDeploymentResponse, params *ListDeploymentParams, recordChannel chan ServerlessV1Deployment, errorChannel chan error) { curRecord := 1 for response != nil { @@ -208,7 +230,7 @@ func (c *ApiService) streamDeployment(response *ListDeploymentResponse, params * } } - record, err := client.GetNext(c.baseURL, response, c.getNextListDeploymentResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListDeploymentResponseWithContext) if err != nil { errorChannel <- err break @@ -223,11 +245,11 @@ func (c *ApiService) streamDeployment(response *ListDeploymentResponse, params * close(errorChannel) } -func (c *ApiService) getNextListDeploymentResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListDeploymentResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/serverless/v1/services_environments_logs.go b/rest/serverless/v1/services_environments_logs.go index f37c3663d..f799026be 100644 --- a/rest/serverless/v1/services_environments_logs.go +++ b/rest/serverless/v1/services_environments_logs.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -26,6 +27,9 @@ import ( // Retrieve a specific log. func (c *ApiService) FetchLog(ServiceSid string, EnvironmentSid string, Sid string) (*ServerlessV1Log, error) { + return c.FetchLogWithContext(context.TODO(), ServiceSid, EnvironmentSid, Sid) +} +func (c *ApiService) FetchLogWithContext(ctx context.Context, ServiceSid string, EnvironmentSid string, Sid string) (*ServerlessV1Log, error) { path := "/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Logs/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"EnvironmentSid"+"}", EnvironmentSid, -1) @@ -36,7 +40,7 @@ func (c *ApiService) FetchLog(ServiceSid string, EnvironmentSid string, Sid stri "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -88,6 +92,11 @@ func (params *ListLogParams) SetLimit(Limit int) *ListLogParams { // Retrieve a single page of Log records from the API. Request is executed immediately. func (c *ApiService) PageLog(ServiceSid string, EnvironmentSid string, params *ListLogParams, pageToken, pageNumber string) (*ListLogResponse, error) { + return c.PageLogWithContext(context.TODO(), ServiceSid, EnvironmentSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Log records from the API. Request is executed immediately. +func (c *ApiService) PageLogWithContext(ctx context.Context, ServiceSid string, EnvironmentSid string, params *ListLogParams, pageToken, pageNumber string) (*ListLogResponse, error) { path := "/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Logs" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -118,7 +127,7 @@ func (c *ApiService) PageLog(ServiceSid string, EnvironmentSid string, params *L data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -135,7 +144,12 @@ func (c *ApiService) PageLog(ServiceSid string, EnvironmentSid string, params *L // Lists Log records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListLog(ServiceSid string, EnvironmentSid string, params *ListLogParams) ([]ServerlessV1Log, error) { - response, errors := c.StreamLog(ServiceSid, EnvironmentSid, params) + return c.ListLogWithContext(context.TODO(), ServiceSid, EnvironmentSid, params) +} + +// Lists Log records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListLogWithContext(ctx context.Context, ServiceSid string, EnvironmentSid string, params *ListLogParams) ([]ServerlessV1Log, error) { + response, errors := c.StreamLogWithContext(ctx, ServiceSid, EnvironmentSid, params) records := make([]ServerlessV1Log, 0) for record := range response { @@ -151,6 +165,11 @@ func (c *ApiService) ListLog(ServiceSid string, EnvironmentSid string, params *L // Streams Log records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamLog(ServiceSid string, EnvironmentSid string, params *ListLogParams) (chan ServerlessV1Log, chan error) { + return c.StreamLogWithContext(context.TODO(), ServiceSid, EnvironmentSid, params) +} + +// Streams Log records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamLogWithContext(ctx context.Context, ServiceSid string, EnvironmentSid string, params *ListLogParams) (chan ServerlessV1Log, chan error) { if params == nil { params = &ListLogParams{} } @@ -159,19 +178,19 @@ func (c *ApiService) StreamLog(ServiceSid string, EnvironmentSid string, params recordChannel := make(chan ServerlessV1Log, 1) errorChannel := make(chan error, 1) - response, err := c.PageLog(ServiceSid, EnvironmentSid, params, "", "") + response, err := c.PageLogWithContext(ctx, ServiceSid, EnvironmentSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamLog(response, params, recordChannel, errorChannel) + go c.streamLogWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamLog(response *ListLogResponse, params *ListLogParams, recordChannel chan ServerlessV1Log, errorChannel chan error) { +func (c *ApiService) streamLogWithContext(ctx context.Context, response *ListLogResponse, params *ListLogParams, recordChannel chan ServerlessV1Log, errorChannel chan error) { curRecord := 1 for response != nil { @@ -186,7 +205,7 @@ func (c *ApiService) streamLog(response *ListLogResponse, params *ListLogParams, } } - record, err := client.GetNext(c.baseURL, response, c.getNextListLogResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListLogResponseWithContext) if err != nil { errorChannel <- err break @@ -201,11 +220,11 @@ func (c *ApiService) streamLog(response *ListLogResponse, params *ListLogParams, close(errorChannel) } -func (c *ApiService) getNextListLogResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListLogResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/serverless/v1/services_environments_variables.go b/rest/serverless/v1/services_environments_variables.go index 13d4db41a..4395f4e1b 100644 --- a/rest/serverless/v1/services_environments_variables.go +++ b/rest/serverless/v1/services_environments_variables.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -42,6 +43,9 @@ func (params *CreateVariableParams) SetValue(Value string) *CreateVariableParams // Create a new Variable. func (c *ApiService) CreateVariable(ServiceSid string, EnvironmentSid string, params *CreateVariableParams) (*ServerlessV1Variable, error) { + return c.CreateVariableWithContext(context.TODO(), ServiceSid, EnvironmentSid, params) +} +func (c *ApiService) CreateVariableWithContext(ctx context.Context, ServiceSid string, EnvironmentSid string, params *CreateVariableParams) (*ServerlessV1Variable, error) { path := "/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Variables" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"EnvironmentSid"+"}", EnvironmentSid, -1) @@ -58,7 +62,7 @@ func (c *ApiService) CreateVariable(ServiceSid string, EnvironmentSid string, pa data.Set("Value", *params.Value) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -75,6 +79,9 @@ func (c *ApiService) CreateVariable(ServiceSid string, EnvironmentSid string, pa // Delete a specific Variable. func (c *ApiService) DeleteVariable(ServiceSid string, EnvironmentSid string, Sid string) error { + return c.DeleteVariableWithContext(context.TODO(), ServiceSid, EnvironmentSid, Sid) +} +func (c *ApiService) DeleteVariableWithContext(ctx context.Context, ServiceSid string, EnvironmentSid string, Sid string) error { path := "/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Variables/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"EnvironmentSid"+"}", EnvironmentSid, -1) @@ -85,7 +92,7 @@ func (c *ApiService) DeleteVariable(ServiceSid string, EnvironmentSid string, Si "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -97,6 +104,9 @@ func (c *ApiService) DeleteVariable(ServiceSid string, EnvironmentSid string, Si // Retrieve a specific Variable. func (c *ApiService) FetchVariable(ServiceSid string, EnvironmentSid string, Sid string) (*ServerlessV1Variable, error) { + return c.FetchVariableWithContext(context.TODO(), ServiceSid, EnvironmentSid, Sid) +} +func (c *ApiService) FetchVariableWithContext(ctx context.Context, ServiceSid string, EnvironmentSid string, Sid string) (*ServerlessV1Variable, error) { path := "/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Variables/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"EnvironmentSid"+"}", EnvironmentSid, -1) @@ -107,7 +117,7 @@ func (c *ApiService) FetchVariable(ServiceSid string, EnvironmentSid string, Sid "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -141,6 +151,11 @@ func (params *ListVariableParams) SetLimit(Limit int) *ListVariableParams { // Retrieve a single page of Variable records from the API. Request is executed immediately. func (c *ApiService) PageVariable(ServiceSid string, EnvironmentSid string, params *ListVariableParams, pageToken, pageNumber string) (*ListVariableResponse, error) { + return c.PageVariableWithContext(context.TODO(), ServiceSid, EnvironmentSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Variable records from the API. Request is executed immediately. +func (c *ApiService) PageVariableWithContext(ctx context.Context, ServiceSid string, EnvironmentSid string, params *ListVariableParams, pageToken, pageNumber string) (*ListVariableResponse, error) { path := "/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Variables" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -162,7 +177,7 @@ func (c *ApiService) PageVariable(ServiceSid string, EnvironmentSid string, para data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -179,7 +194,12 @@ func (c *ApiService) PageVariable(ServiceSid string, EnvironmentSid string, para // Lists Variable records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListVariable(ServiceSid string, EnvironmentSid string, params *ListVariableParams) ([]ServerlessV1Variable, error) { - response, errors := c.StreamVariable(ServiceSid, EnvironmentSid, params) + return c.ListVariableWithContext(context.TODO(), ServiceSid, EnvironmentSid, params) +} + +// Lists Variable records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListVariableWithContext(ctx context.Context, ServiceSid string, EnvironmentSid string, params *ListVariableParams) ([]ServerlessV1Variable, error) { + response, errors := c.StreamVariableWithContext(ctx, ServiceSid, EnvironmentSid, params) records := make([]ServerlessV1Variable, 0) for record := range response { @@ -195,6 +215,11 @@ func (c *ApiService) ListVariable(ServiceSid string, EnvironmentSid string, para // Streams Variable records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamVariable(ServiceSid string, EnvironmentSid string, params *ListVariableParams) (chan ServerlessV1Variable, chan error) { + return c.StreamVariableWithContext(context.TODO(), ServiceSid, EnvironmentSid, params) +} + +// Streams Variable records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamVariableWithContext(ctx context.Context, ServiceSid string, EnvironmentSid string, params *ListVariableParams) (chan ServerlessV1Variable, chan error) { if params == nil { params = &ListVariableParams{} } @@ -203,19 +228,19 @@ func (c *ApiService) StreamVariable(ServiceSid string, EnvironmentSid string, pa recordChannel := make(chan ServerlessV1Variable, 1) errorChannel := make(chan error, 1) - response, err := c.PageVariable(ServiceSid, EnvironmentSid, params, "", "") + response, err := c.PageVariableWithContext(ctx, ServiceSid, EnvironmentSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamVariable(response, params, recordChannel, errorChannel) + go c.streamVariableWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamVariable(response *ListVariableResponse, params *ListVariableParams, recordChannel chan ServerlessV1Variable, errorChannel chan error) { +func (c *ApiService) streamVariableWithContext(ctx context.Context, response *ListVariableResponse, params *ListVariableParams, recordChannel chan ServerlessV1Variable, errorChannel chan error) { curRecord := 1 for response != nil { @@ -230,7 +255,7 @@ func (c *ApiService) streamVariable(response *ListVariableResponse, params *List } } - record, err := client.GetNext(c.baseURL, response, c.getNextListVariableResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListVariableResponseWithContext) if err != nil { errorChannel <- err break @@ -245,11 +270,11 @@ func (c *ApiService) streamVariable(response *ListVariableResponse, params *List close(errorChannel) } -func (c *ApiService) getNextListVariableResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListVariableResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -282,6 +307,9 @@ func (params *UpdateVariableParams) SetValue(Value string) *UpdateVariableParams // Update a specific Variable. func (c *ApiService) UpdateVariable(ServiceSid string, EnvironmentSid string, Sid string, params *UpdateVariableParams) (*ServerlessV1Variable, error) { + return c.UpdateVariableWithContext(context.TODO(), ServiceSid, EnvironmentSid, Sid, params) +} +func (c *ApiService) UpdateVariableWithContext(ctx context.Context, ServiceSid string, EnvironmentSid string, Sid string, params *UpdateVariableParams) (*ServerlessV1Variable, error) { path := "/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Variables/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"EnvironmentSid"+"}", EnvironmentSid, -1) @@ -299,7 +327,7 @@ func (c *ApiService) UpdateVariable(ServiceSid string, EnvironmentSid string, Si data.Set("Value", *params.Value) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/serverless/v1/services_functions.go b/rest/serverless/v1/services_functions.go index 57201123d..87c128892 100644 --- a/rest/serverless/v1/services_functions.go +++ b/rest/serverless/v1/services_functions.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -36,6 +37,9 @@ func (params *CreateFunctionParams) SetFriendlyName(FriendlyName string) *Create // Create a new Function resource. func (c *ApiService) CreateFunction(ServiceSid string, params *CreateFunctionParams) (*ServerlessV1Function, error) { + return c.CreateFunctionWithContext(context.TODO(), ServiceSid, params) +} +func (c *ApiService) CreateFunctionWithContext(ctx context.Context, ServiceSid string, params *CreateFunctionParams) (*ServerlessV1Function, error) { path := "/v1/Services/{ServiceSid}/Functions" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -48,7 +52,7 @@ func (c *ApiService) CreateFunction(ServiceSid string, params *CreateFunctionPar data.Set("FriendlyName", *params.FriendlyName) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -65,6 +69,9 @@ func (c *ApiService) CreateFunction(ServiceSid string, params *CreateFunctionPar // Delete a Function resource. func (c *ApiService) DeleteFunction(ServiceSid string, Sid string) error { + return c.DeleteFunctionWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) DeleteFunctionWithContext(ctx context.Context, ServiceSid string, Sid string) error { path := "/v1/Services/{ServiceSid}/Functions/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -74,7 +81,7 @@ func (c *ApiService) DeleteFunction(ServiceSid string, Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -86,6 +93,9 @@ func (c *ApiService) DeleteFunction(ServiceSid string, Sid string) error { // Retrieve a specific Function resource. func (c *ApiService) FetchFunction(ServiceSid string, Sid string) (*ServerlessV1Function, error) { + return c.FetchFunctionWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) FetchFunctionWithContext(ctx context.Context, ServiceSid string, Sid string) (*ServerlessV1Function, error) { path := "/v1/Services/{ServiceSid}/Functions/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -95,7 +105,7 @@ func (c *ApiService) FetchFunction(ServiceSid string, Sid string) (*ServerlessV1 "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -129,6 +139,11 @@ func (params *ListFunctionParams) SetLimit(Limit int) *ListFunctionParams { // Retrieve a single page of Function records from the API. Request is executed immediately. func (c *ApiService) PageFunction(ServiceSid string, params *ListFunctionParams, pageToken, pageNumber string) (*ListFunctionResponse, error) { + return c.PageFunctionWithContext(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Function records from the API. Request is executed immediately. +func (c *ApiService) PageFunctionWithContext(ctx context.Context, ServiceSid string, params *ListFunctionParams, pageToken, pageNumber string) (*ListFunctionResponse, error) { path := "/v1/Services/{ServiceSid}/Functions" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -149,7 +164,7 @@ func (c *ApiService) PageFunction(ServiceSid string, params *ListFunctionParams, data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -166,7 +181,12 @@ func (c *ApiService) PageFunction(ServiceSid string, params *ListFunctionParams, // Lists Function records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListFunction(ServiceSid string, params *ListFunctionParams) ([]ServerlessV1Function, error) { - response, errors := c.StreamFunction(ServiceSid, params) + return c.ListFunctionWithContext(context.TODO(), ServiceSid, params) +} + +// Lists Function records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListFunctionWithContext(ctx context.Context, ServiceSid string, params *ListFunctionParams) ([]ServerlessV1Function, error) { + response, errors := c.StreamFunctionWithContext(ctx, ServiceSid, params) records := make([]ServerlessV1Function, 0) for record := range response { @@ -182,6 +202,11 @@ func (c *ApiService) ListFunction(ServiceSid string, params *ListFunctionParams) // Streams Function records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamFunction(ServiceSid string, params *ListFunctionParams) (chan ServerlessV1Function, chan error) { + return c.StreamFunctionWithContext(context.TODO(), ServiceSid, params) +} + +// Streams Function records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamFunctionWithContext(ctx context.Context, ServiceSid string, params *ListFunctionParams) (chan ServerlessV1Function, chan error) { if params == nil { params = &ListFunctionParams{} } @@ -190,19 +215,19 @@ func (c *ApiService) StreamFunction(ServiceSid string, params *ListFunctionParam recordChannel := make(chan ServerlessV1Function, 1) errorChannel := make(chan error, 1) - response, err := c.PageFunction(ServiceSid, params, "", "") + response, err := c.PageFunctionWithContext(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamFunction(response, params, recordChannel, errorChannel) + go c.streamFunctionWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamFunction(response *ListFunctionResponse, params *ListFunctionParams, recordChannel chan ServerlessV1Function, errorChannel chan error) { +func (c *ApiService) streamFunctionWithContext(ctx context.Context, response *ListFunctionResponse, params *ListFunctionParams, recordChannel chan ServerlessV1Function, errorChannel chan error) { curRecord := 1 for response != nil { @@ -217,7 +242,7 @@ func (c *ApiService) streamFunction(response *ListFunctionResponse, params *List } } - record, err := client.GetNext(c.baseURL, response, c.getNextListFunctionResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListFunctionResponseWithContext) if err != nil { errorChannel <- err break @@ -232,11 +257,11 @@ func (c *ApiService) streamFunction(response *ListFunctionResponse, params *List close(errorChannel) } -func (c *ApiService) getNextListFunctionResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListFunctionResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -263,6 +288,9 @@ func (params *UpdateFunctionParams) SetFriendlyName(FriendlyName string) *Update // Update a specific Function resource. func (c *ApiService) UpdateFunction(ServiceSid string, Sid string, params *UpdateFunctionParams) (*ServerlessV1Function, error) { + return c.UpdateFunctionWithContext(context.TODO(), ServiceSid, Sid, params) +} +func (c *ApiService) UpdateFunctionWithContext(ctx context.Context, ServiceSid string, Sid string, params *UpdateFunctionParams) (*ServerlessV1Function, error) { path := "/v1/Services/{ServiceSid}/Functions/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -276,7 +304,7 @@ func (c *ApiService) UpdateFunction(ServiceSid string, Sid string, params *Updat data.Set("FriendlyName", *params.FriendlyName) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/serverless/v1/services_functions_versions.go b/rest/serverless/v1/services_functions_versions.go index 4a74b8d46..ccbee329e 100644 --- a/rest/serverless/v1/services_functions_versions.go +++ b/rest/serverless/v1/services_functions_versions.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -25,6 +26,9 @@ import ( // Retrieve a specific Function Version resource. func (c *ApiService) FetchFunctionVersion(ServiceSid string, FunctionSid string, Sid string) (*ServerlessV1FunctionVersion, error) { + return c.FetchFunctionVersionWithContext(context.TODO(), ServiceSid, FunctionSid, Sid) +} +func (c *ApiService) FetchFunctionVersionWithContext(ctx context.Context, ServiceSid string, FunctionSid string, Sid string) (*ServerlessV1FunctionVersion, error) { path := "/v1/Services/{ServiceSid}/Functions/{FunctionSid}/Versions/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"FunctionSid"+"}", FunctionSid, -1) @@ -35,7 +39,7 @@ func (c *ApiService) FetchFunctionVersion(ServiceSid string, FunctionSid string, "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -69,6 +73,11 @@ func (params *ListFunctionVersionParams) SetLimit(Limit int) *ListFunctionVersio // Retrieve a single page of FunctionVersion records from the API. Request is executed immediately. func (c *ApiService) PageFunctionVersion(ServiceSid string, FunctionSid string, params *ListFunctionVersionParams, pageToken, pageNumber string) (*ListFunctionVersionResponse, error) { + return c.PageFunctionVersionWithContext(context.TODO(), ServiceSid, FunctionSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of FunctionVersion records from the API. Request is executed immediately. +func (c *ApiService) PageFunctionVersionWithContext(ctx context.Context, ServiceSid string, FunctionSid string, params *ListFunctionVersionParams, pageToken, pageNumber string) (*ListFunctionVersionResponse, error) { path := "/v1/Services/{ServiceSid}/Functions/{FunctionSid}/Versions" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -90,7 +99,7 @@ func (c *ApiService) PageFunctionVersion(ServiceSid string, FunctionSid string, data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -107,7 +116,12 @@ func (c *ApiService) PageFunctionVersion(ServiceSid string, FunctionSid string, // Lists FunctionVersion records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListFunctionVersion(ServiceSid string, FunctionSid string, params *ListFunctionVersionParams) ([]ServerlessV1FunctionVersion, error) { - response, errors := c.StreamFunctionVersion(ServiceSid, FunctionSid, params) + return c.ListFunctionVersionWithContext(context.TODO(), ServiceSid, FunctionSid, params) +} + +// Lists FunctionVersion records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListFunctionVersionWithContext(ctx context.Context, ServiceSid string, FunctionSid string, params *ListFunctionVersionParams) ([]ServerlessV1FunctionVersion, error) { + response, errors := c.StreamFunctionVersionWithContext(ctx, ServiceSid, FunctionSid, params) records := make([]ServerlessV1FunctionVersion, 0) for record := range response { @@ -123,6 +137,11 @@ func (c *ApiService) ListFunctionVersion(ServiceSid string, FunctionSid string, // Streams FunctionVersion records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamFunctionVersion(ServiceSid string, FunctionSid string, params *ListFunctionVersionParams) (chan ServerlessV1FunctionVersion, chan error) { + return c.StreamFunctionVersionWithContext(context.TODO(), ServiceSid, FunctionSid, params) +} + +// Streams FunctionVersion records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamFunctionVersionWithContext(ctx context.Context, ServiceSid string, FunctionSid string, params *ListFunctionVersionParams) (chan ServerlessV1FunctionVersion, chan error) { if params == nil { params = &ListFunctionVersionParams{} } @@ -131,19 +150,19 @@ func (c *ApiService) StreamFunctionVersion(ServiceSid string, FunctionSid string recordChannel := make(chan ServerlessV1FunctionVersion, 1) errorChannel := make(chan error, 1) - response, err := c.PageFunctionVersion(ServiceSid, FunctionSid, params, "", "") + response, err := c.PageFunctionVersionWithContext(ctx, ServiceSid, FunctionSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamFunctionVersion(response, params, recordChannel, errorChannel) + go c.streamFunctionVersionWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamFunctionVersion(response *ListFunctionVersionResponse, params *ListFunctionVersionParams, recordChannel chan ServerlessV1FunctionVersion, errorChannel chan error) { +func (c *ApiService) streamFunctionVersionWithContext(ctx context.Context, response *ListFunctionVersionResponse, params *ListFunctionVersionParams, recordChannel chan ServerlessV1FunctionVersion, errorChannel chan error) { curRecord := 1 for response != nil { @@ -158,7 +177,7 @@ func (c *ApiService) streamFunctionVersion(response *ListFunctionVersionResponse } } - record, err := client.GetNext(c.baseURL, response, c.getNextListFunctionVersionResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListFunctionVersionResponseWithContext) if err != nil { errorChannel <- err break @@ -173,11 +192,11 @@ func (c *ApiService) streamFunctionVersion(response *ListFunctionVersionResponse close(errorChannel) } -func (c *ApiService) getNextListFunctionVersionResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListFunctionVersionResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/serverless/v1/services_functions_versions_content.go b/rest/serverless/v1/services_functions_versions_content.go index b7fc05d0a..de9a2eef8 100644 --- a/rest/serverless/v1/services_functions_versions_content.go +++ b/rest/serverless/v1/services_functions_versions_content.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -22,6 +23,9 @@ import ( // Retrieve a the content of a specific Function Version resource. func (c *ApiService) FetchFunctionVersionContent(ServiceSid string, FunctionSid string, Sid string) (*ServerlessV1FunctionVersionContent, error) { + return c.FetchFunctionVersionContentWithContext(context.TODO(), ServiceSid, FunctionSid, Sid) +} +func (c *ApiService) FetchFunctionVersionContentWithContext(ctx context.Context, ServiceSid string, FunctionSid string, Sid string) (*ServerlessV1FunctionVersionContent, error) { path := "/v1/Services/{ServiceSid}/Functions/{FunctionSid}/Versions/{Sid}/Content" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"FunctionSid"+"}", FunctionSid, -1) @@ -32,7 +36,7 @@ func (c *ApiService) FetchFunctionVersionContent(ServiceSid string, FunctionSid "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/studio/v1/api_service.go b/rest/studio/v1/api_service.go index 8cdd0d27f..2f927fffa 100644 --- a/rest/studio/v1/api_service.go +++ b/rest/studio/v1/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://studio.twilio.com", + } +} diff --git a/rest/studio/v1/flows.go b/rest/studio/v1/flows.go index ee82119fc..8889955d0 100644 --- a/rest/studio/v1/flows.go +++ b/rest/studio/v1/flows.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -25,6 +26,9 @@ import ( // Delete a specific Flow. func (c *ApiService) DeleteFlow(Sid string) error { + return c.DeleteFlowWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteFlowWithContext(ctx context.Context, Sid string) error { path := "/v1/Flows/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -33,7 +37,7 @@ func (c *ApiService) DeleteFlow(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -45,6 +49,9 @@ func (c *ApiService) DeleteFlow(Sid string) error { // Retrieve a specific Flow. func (c *ApiService) FetchFlow(Sid string) (*StudioV1Flow, error) { + return c.FetchFlowWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchFlowWithContext(ctx context.Context, Sid string) (*StudioV1Flow, error) { path := "/v1/Flows/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -53,7 +60,7 @@ func (c *ApiService) FetchFlow(Sid string) (*StudioV1Flow, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -87,6 +94,11 @@ func (params *ListFlowParams) SetLimit(Limit int) *ListFlowParams { // Retrieve a single page of Flow records from the API. Request is executed immediately. func (c *ApiService) PageFlow(params *ListFlowParams, pageToken, pageNumber string) (*ListFlowResponse, error) { + return c.PageFlowWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Flow records from the API. Request is executed immediately. +func (c *ApiService) PageFlowWithContext(ctx context.Context, params *ListFlowParams, pageToken, pageNumber string) (*ListFlowResponse, error) { path := "/v1/Flows" data := url.Values{} @@ -105,7 +117,7 @@ func (c *ApiService) PageFlow(params *ListFlowParams, pageToken, pageNumber stri data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -122,7 +134,12 @@ func (c *ApiService) PageFlow(params *ListFlowParams, pageToken, pageNumber stri // Lists Flow records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListFlow(params *ListFlowParams) ([]StudioV1Flow, error) { - response, errors := c.StreamFlow(params) + return c.ListFlowWithContext(context.TODO(), params) +} + +// Lists Flow records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListFlowWithContext(ctx context.Context, params *ListFlowParams) ([]StudioV1Flow, error) { + response, errors := c.StreamFlowWithContext(ctx, params) records := make([]StudioV1Flow, 0) for record := range response { @@ -138,6 +155,11 @@ func (c *ApiService) ListFlow(params *ListFlowParams) ([]StudioV1Flow, error) { // Streams Flow records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamFlow(params *ListFlowParams) (chan StudioV1Flow, chan error) { + return c.StreamFlowWithContext(context.TODO(), params) +} + +// Streams Flow records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamFlowWithContext(ctx context.Context, params *ListFlowParams) (chan StudioV1Flow, chan error) { if params == nil { params = &ListFlowParams{} } @@ -146,19 +168,19 @@ func (c *ApiService) StreamFlow(params *ListFlowParams) (chan StudioV1Flow, chan recordChannel := make(chan StudioV1Flow, 1) errorChannel := make(chan error, 1) - response, err := c.PageFlow(params, "", "") + response, err := c.PageFlowWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamFlow(response, params, recordChannel, errorChannel) + go c.streamFlowWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamFlow(response *ListFlowResponse, params *ListFlowParams, recordChannel chan StudioV1Flow, errorChannel chan error) { +func (c *ApiService) streamFlowWithContext(ctx context.Context, response *ListFlowResponse, params *ListFlowParams, recordChannel chan StudioV1Flow, errorChannel chan error) { curRecord := 1 for response != nil { @@ -173,7 +195,7 @@ func (c *ApiService) streamFlow(response *ListFlowResponse, params *ListFlowPara } } - record, err := client.GetNext(c.baseURL, response, c.getNextListFlowResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListFlowResponseWithContext) if err != nil { errorChannel <- err break @@ -188,11 +210,11 @@ func (c *ApiService) streamFlow(response *ListFlowResponse, params *ListFlowPara close(errorChannel) } -func (c *ApiService) getNextListFlowResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListFlowResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/studio/v1/flows_engagements.go b/rest/studio/v1/flows_engagements.go index 8e6f93498..eaa039d27 100644 --- a/rest/studio/v1/flows_engagements.go +++ b/rest/studio/v1/flows_engagements.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -48,6 +49,9 @@ func (params *CreateEngagementParams) SetParameters(Parameters map[string]interf // Triggers a new Engagement for the Flow func (c *ApiService) CreateEngagement(FlowSid string, params *CreateEngagementParams) (*StudioV1Engagement, error) { + return c.CreateEngagementWithContext(context.TODO(), FlowSid, params) +} +func (c *ApiService) CreateEngagementWithContext(ctx context.Context, FlowSid string, params *CreateEngagementParams) (*StudioV1Engagement, error) { path := "/v1/Flows/{FlowSid}/Engagements" path = strings.Replace(path, "{"+"FlowSid"+"}", FlowSid, -1) @@ -72,7 +76,7 @@ func (c *ApiService) CreateEngagement(FlowSid string, params *CreateEngagementPa data.Set("Parameters", string(v)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -89,6 +93,9 @@ func (c *ApiService) CreateEngagement(FlowSid string, params *CreateEngagementPa // Delete this Engagement and all Steps relating to it. func (c *ApiService) DeleteEngagement(FlowSid string, Sid string) error { + return c.DeleteEngagementWithContext(context.TODO(), FlowSid, Sid) +} +func (c *ApiService) DeleteEngagementWithContext(ctx context.Context, FlowSid string, Sid string) error { path := "/v1/Flows/{FlowSid}/Engagements/{Sid}" path = strings.Replace(path, "{"+"FlowSid"+"}", FlowSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -98,7 +105,7 @@ func (c *ApiService) DeleteEngagement(FlowSid string, Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -110,6 +117,9 @@ func (c *ApiService) DeleteEngagement(FlowSid string, Sid string) error { // Retrieve an Engagement func (c *ApiService) FetchEngagement(FlowSid string, Sid string) (*StudioV1Engagement, error) { + return c.FetchEngagementWithContext(context.TODO(), FlowSid, Sid) +} +func (c *ApiService) FetchEngagementWithContext(ctx context.Context, FlowSid string, Sid string) (*StudioV1Engagement, error) { path := "/v1/Flows/{FlowSid}/Engagements/{Sid}" path = strings.Replace(path, "{"+"FlowSid"+"}", FlowSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -119,7 +129,7 @@ func (c *ApiService) FetchEngagement(FlowSid string, Sid string) (*StudioV1Engag "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -153,6 +163,11 @@ func (params *ListEngagementParams) SetLimit(Limit int) *ListEngagementParams { // Retrieve a single page of Engagement records from the API. Request is executed immediately. func (c *ApiService) PageEngagement(FlowSid string, params *ListEngagementParams, pageToken, pageNumber string) (*ListEngagementResponse, error) { + return c.PageEngagementWithContext(context.TODO(), FlowSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Engagement records from the API. Request is executed immediately. +func (c *ApiService) PageEngagementWithContext(ctx context.Context, FlowSid string, params *ListEngagementParams, pageToken, pageNumber string) (*ListEngagementResponse, error) { path := "/v1/Flows/{FlowSid}/Engagements" path = strings.Replace(path, "{"+"FlowSid"+"}", FlowSid, -1) @@ -173,7 +188,7 @@ func (c *ApiService) PageEngagement(FlowSid string, params *ListEngagementParams data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -190,7 +205,12 @@ func (c *ApiService) PageEngagement(FlowSid string, params *ListEngagementParams // Lists Engagement records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListEngagement(FlowSid string, params *ListEngagementParams) ([]StudioV1Engagement, error) { - response, errors := c.StreamEngagement(FlowSid, params) + return c.ListEngagementWithContext(context.TODO(), FlowSid, params) +} + +// Lists Engagement records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListEngagementWithContext(ctx context.Context, FlowSid string, params *ListEngagementParams) ([]StudioV1Engagement, error) { + response, errors := c.StreamEngagementWithContext(ctx, FlowSid, params) records := make([]StudioV1Engagement, 0) for record := range response { @@ -206,6 +226,11 @@ func (c *ApiService) ListEngagement(FlowSid string, params *ListEngagementParams // Streams Engagement records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamEngagement(FlowSid string, params *ListEngagementParams) (chan StudioV1Engagement, chan error) { + return c.StreamEngagementWithContext(context.TODO(), FlowSid, params) +} + +// Streams Engagement records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamEngagementWithContext(ctx context.Context, FlowSid string, params *ListEngagementParams) (chan StudioV1Engagement, chan error) { if params == nil { params = &ListEngagementParams{} } @@ -214,19 +239,19 @@ func (c *ApiService) StreamEngagement(FlowSid string, params *ListEngagementPara recordChannel := make(chan StudioV1Engagement, 1) errorChannel := make(chan error, 1) - response, err := c.PageEngagement(FlowSid, params, "", "") + response, err := c.PageEngagementWithContext(ctx, FlowSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamEngagement(response, params, recordChannel, errorChannel) + go c.streamEngagementWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamEngagement(response *ListEngagementResponse, params *ListEngagementParams, recordChannel chan StudioV1Engagement, errorChannel chan error) { +func (c *ApiService) streamEngagementWithContext(ctx context.Context, response *ListEngagementResponse, params *ListEngagementParams, recordChannel chan StudioV1Engagement, errorChannel chan error) { curRecord := 1 for response != nil { @@ -241,7 +266,7 @@ func (c *ApiService) streamEngagement(response *ListEngagementResponse, params * } } - record, err := client.GetNext(c.baseURL, response, c.getNextListEngagementResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListEngagementResponseWithContext) if err != nil { errorChannel <- err break @@ -256,11 +281,11 @@ func (c *ApiService) streamEngagement(response *ListEngagementResponse, params * close(errorChannel) } -func (c *ApiService) getNextListEngagementResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListEngagementResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/studio/v1/flows_engagements_context.go b/rest/studio/v1/flows_engagements_context.go index 6ee6a8020..c52c0a919 100644 --- a/rest/studio/v1/flows_engagements_context.go +++ b/rest/studio/v1/flows_engagements_context.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -22,6 +23,9 @@ import ( // Retrieve the most recent context for an Engagement. func (c *ApiService) FetchEngagementContext(FlowSid string, EngagementSid string) (*StudioV1EngagementContext, error) { + return c.FetchEngagementContextWithContext(context.TODO(), FlowSid, EngagementSid) +} +func (c *ApiService) FetchEngagementContextWithContext(ctx context.Context, FlowSid string, EngagementSid string) (*StudioV1EngagementContext, error) { path := "/v1/Flows/{FlowSid}/Engagements/{EngagementSid}/Context" path = strings.Replace(path, "{"+"FlowSid"+"}", FlowSid, -1) path = strings.Replace(path, "{"+"EngagementSid"+"}", EngagementSid, -1) @@ -31,7 +35,7 @@ func (c *ApiService) FetchEngagementContext(FlowSid string, EngagementSid string "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/studio/v1/flows_engagements_steps.go b/rest/studio/v1/flows_engagements_steps.go index c3e6eb33a..715da5644 100644 --- a/rest/studio/v1/flows_engagements_steps.go +++ b/rest/studio/v1/flows_engagements_steps.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -25,6 +26,9 @@ import ( // Retrieve a Step. func (c *ApiService) FetchStep(FlowSid string, EngagementSid string, Sid string) (*StudioV1Step, error) { + return c.FetchStepWithContext(context.TODO(), FlowSid, EngagementSid, Sid) +} +func (c *ApiService) FetchStepWithContext(ctx context.Context, FlowSid string, EngagementSid string, Sid string) (*StudioV1Step, error) { path := "/v1/Flows/{FlowSid}/Engagements/{EngagementSid}/Steps/{Sid}" path = strings.Replace(path, "{"+"FlowSid"+"}", FlowSid, -1) path = strings.Replace(path, "{"+"EngagementSid"+"}", EngagementSid, -1) @@ -35,7 +39,7 @@ func (c *ApiService) FetchStep(FlowSid string, EngagementSid string, Sid string) "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -69,6 +73,11 @@ func (params *ListStepParams) SetLimit(Limit int) *ListStepParams { // Retrieve a single page of Step records from the API. Request is executed immediately. func (c *ApiService) PageStep(FlowSid string, EngagementSid string, params *ListStepParams, pageToken, pageNumber string) (*ListStepResponse, error) { + return c.PageStepWithContext(context.TODO(), FlowSid, EngagementSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Step records from the API. Request is executed immediately. +func (c *ApiService) PageStepWithContext(ctx context.Context, FlowSid string, EngagementSid string, params *ListStepParams, pageToken, pageNumber string) (*ListStepResponse, error) { path := "/v1/Flows/{FlowSid}/Engagements/{EngagementSid}/Steps" path = strings.Replace(path, "{"+"FlowSid"+"}", FlowSid, -1) @@ -90,7 +99,7 @@ func (c *ApiService) PageStep(FlowSid string, EngagementSid string, params *List data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -107,7 +116,12 @@ func (c *ApiService) PageStep(FlowSid string, EngagementSid string, params *List // Lists Step records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListStep(FlowSid string, EngagementSid string, params *ListStepParams) ([]StudioV1Step, error) { - response, errors := c.StreamStep(FlowSid, EngagementSid, params) + return c.ListStepWithContext(context.TODO(), FlowSid, EngagementSid, params) +} + +// Lists Step records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListStepWithContext(ctx context.Context, FlowSid string, EngagementSid string, params *ListStepParams) ([]StudioV1Step, error) { + response, errors := c.StreamStepWithContext(ctx, FlowSid, EngagementSid, params) records := make([]StudioV1Step, 0) for record := range response { @@ -123,6 +137,11 @@ func (c *ApiService) ListStep(FlowSid string, EngagementSid string, params *List // Streams Step records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamStep(FlowSid string, EngagementSid string, params *ListStepParams) (chan StudioV1Step, chan error) { + return c.StreamStepWithContext(context.TODO(), FlowSid, EngagementSid, params) +} + +// Streams Step records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamStepWithContext(ctx context.Context, FlowSid string, EngagementSid string, params *ListStepParams) (chan StudioV1Step, chan error) { if params == nil { params = &ListStepParams{} } @@ -131,19 +150,19 @@ func (c *ApiService) StreamStep(FlowSid string, EngagementSid string, params *Li recordChannel := make(chan StudioV1Step, 1) errorChannel := make(chan error, 1) - response, err := c.PageStep(FlowSid, EngagementSid, params, "", "") + response, err := c.PageStepWithContext(ctx, FlowSid, EngagementSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamStep(response, params, recordChannel, errorChannel) + go c.streamStepWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamStep(response *ListStepResponse, params *ListStepParams, recordChannel chan StudioV1Step, errorChannel chan error) { +func (c *ApiService) streamStepWithContext(ctx context.Context, response *ListStepResponse, params *ListStepParams, recordChannel chan StudioV1Step, errorChannel chan error) { curRecord := 1 for response != nil { @@ -158,7 +177,7 @@ func (c *ApiService) streamStep(response *ListStepResponse, params *ListStepPara } } - record, err := client.GetNext(c.baseURL, response, c.getNextListStepResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListStepResponseWithContext) if err != nil { errorChannel <- err break @@ -173,11 +192,11 @@ func (c *ApiService) streamStep(response *ListStepResponse, params *ListStepPara close(errorChannel) } -func (c *ApiService) getNextListStepResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListStepResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/studio/v1/flows_engagements_steps_context.go b/rest/studio/v1/flows_engagements_steps_context.go index 7b6c08838..2ba4b67a7 100644 --- a/rest/studio/v1/flows_engagements_steps_context.go +++ b/rest/studio/v1/flows_engagements_steps_context.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -22,6 +23,9 @@ import ( // Retrieve the context for an Engagement Step. func (c *ApiService) FetchStepContext(FlowSid string, EngagementSid string, StepSid string) (*StudioV1StepContext, error) { + return c.FetchStepContextWithContext(context.TODO(), FlowSid, EngagementSid, StepSid) +} +func (c *ApiService) FetchStepContextWithContext(ctx context.Context, FlowSid string, EngagementSid string, StepSid string) (*StudioV1StepContext, error) { path := "/v1/Flows/{FlowSid}/Engagements/{EngagementSid}/Steps/{StepSid}/Context" path = strings.Replace(path, "{"+"FlowSid"+"}", FlowSid, -1) path = strings.Replace(path, "{"+"EngagementSid"+"}", EngagementSid, -1) @@ -32,7 +36,7 @@ func (c *ApiService) FetchStepContext(FlowSid string, EngagementSid string, Step "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/studio/v1/flows_executions.go b/rest/studio/v1/flows_executions.go index f6e123275..c589714ca 100644 --- a/rest/studio/v1/flows_executions.go +++ b/rest/studio/v1/flows_executions.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -49,6 +50,9 @@ func (params *CreateExecutionParams) SetParameters(Parameters map[string]interfa // Triggers a new Execution for the Flow func (c *ApiService) CreateExecution(FlowSid string, params *CreateExecutionParams) (*StudioV1Execution, error) { + return c.CreateExecutionWithContext(context.TODO(), FlowSid, params) +} +func (c *ApiService) CreateExecutionWithContext(ctx context.Context, FlowSid string, params *CreateExecutionParams) (*StudioV1Execution, error) { path := "/v1/Flows/{FlowSid}/Executions" path = strings.Replace(path, "{"+"FlowSid"+"}", FlowSid, -1) @@ -73,7 +77,7 @@ func (c *ApiService) CreateExecution(FlowSid string, params *CreateExecutionPara data.Set("Parameters", string(v)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -90,6 +94,9 @@ func (c *ApiService) CreateExecution(FlowSid string, params *CreateExecutionPara // Delete the Execution and all Steps relating to it. func (c *ApiService) DeleteExecution(FlowSid string, Sid string) error { + return c.DeleteExecutionWithContext(context.TODO(), FlowSid, Sid) +} +func (c *ApiService) DeleteExecutionWithContext(ctx context.Context, FlowSid string, Sid string) error { path := "/v1/Flows/{FlowSid}/Executions/{Sid}" path = strings.Replace(path, "{"+"FlowSid"+"}", FlowSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -99,7 +106,7 @@ func (c *ApiService) DeleteExecution(FlowSid string, Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -111,6 +118,9 @@ func (c *ApiService) DeleteExecution(FlowSid string, Sid string) error { // Retrieve an Execution func (c *ApiService) FetchExecution(FlowSid string, Sid string) (*StudioV1Execution, error) { + return c.FetchExecutionWithContext(context.TODO(), FlowSid, Sid) +} +func (c *ApiService) FetchExecutionWithContext(ctx context.Context, FlowSid string, Sid string) (*StudioV1Execution, error) { path := "/v1/Flows/{FlowSid}/Executions/{Sid}" path = strings.Replace(path, "{"+"FlowSid"+"}", FlowSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -120,7 +130,7 @@ func (c *ApiService) FetchExecution(FlowSid string, Sid string) (*StudioV1Execut "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -166,6 +176,11 @@ func (params *ListExecutionParams) SetLimit(Limit int) *ListExecutionParams { // Retrieve a single page of Execution records from the API. Request is executed immediately. func (c *ApiService) PageExecution(FlowSid string, params *ListExecutionParams, pageToken, pageNumber string) (*ListExecutionResponse, error) { + return c.PageExecutionWithContext(context.TODO(), FlowSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Execution records from the API. Request is executed immediately. +func (c *ApiService) PageExecutionWithContext(ctx context.Context, FlowSid string, params *ListExecutionParams, pageToken, pageNumber string) (*ListExecutionResponse, error) { path := "/v1/Flows/{FlowSid}/Executions" path = strings.Replace(path, "{"+"FlowSid"+"}", FlowSid, -1) @@ -192,7 +207,7 @@ func (c *ApiService) PageExecution(FlowSid string, params *ListExecutionParams, data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -209,7 +224,12 @@ func (c *ApiService) PageExecution(FlowSid string, params *ListExecutionParams, // Lists Execution records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListExecution(FlowSid string, params *ListExecutionParams) ([]StudioV1Execution, error) { - response, errors := c.StreamExecution(FlowSid, params) + return c.ListExecutionWithContext(context.TODO(), FlowSid, params) +} + +// Lists Execution records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListExecutionWithContext(ctx context.Context, FlowSid string, params *ListExecutionParams) ([]StudioV1Execution, error) { + response, errors := c.StreamExecutionWithContext(ctx, FlowSid, params) records := make([]StudioV1Execution, 0) for record := range response { @@ -225,6 +245,11 @@ func (c *ApiService) ListExecution(FlowSid string, params *ListExecutionParams) // Streams Execution records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamExecution(FlowSid string, params *ListExecutionParams) (chan StudioV1Execution, chan error) { + return c.StreamExecutionWithContext(context.TODO(), FlowSid, params) +} + +// Streams Execution records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamExecutionWithContext(ctx context.Context, FlowSid string, params *ListExecutionParams) (chan StudioV1Execution, chan error) { if params == nil { params = &ListExecutionParams{} } @@ -233,19 +258,19 @@ func (c *ApiService) StreamExecution(FlowSid string, params *ListExecutionParams recordChannel := make(chan StudioV1Execution, 1) errorChannel := make(chan error, 1) - response, err := c.PageExecution(FlowSid, params, "", "") + response, err := c.PageExecutionWithContext(ctx, FlowSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamExecution(response, params, recordChannel, errorChannel) + go c.streamExecutionWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamExecution(response *ListExecutionResponse, params *ListExecutionParams, recordChannel chan StudioV1Execution, errorChannel chan error) { +func (c *ApiService) streamExecutionWithContext(ctx context.Context, response *ListExecutionResponse, params *ListExecutionParams, recordChannel chan StudioV1Execution, errorChannel chan error) { curRecord := 1 for response != nil { @@ -260,7 +285,7 @@ func (c *ApiService) streamExecution(response *ListExecutionResponse, params *Li } } - record, err := client.GetNext(c.baseURL, response, c.getNextListExecutionResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListExecutionResponseWithContext) if err != nil { errorChannel <- err break @@ -275,11 +300,11 @@ func (c *ApiService) streamExecution(response *ListExecutionResponse, params *Li close(errorChannel) } -func (c *ApiService) getNextListExecutionResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListExecutionResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -306,6 +331,9 @@ func (params *UpdateExecutionParams) SetStatus(Status string) *UpdateExecutionPa // Update the status of an Execution to `ended`. func (c *ApiService) UpdateExecution(FlowSid string, Sid string, params *UpdateExecutionParams) (*StudioV1Execution, error) { + return c.UpdateExecutionWithContext(context.TODO(), FlowSid, Sid, params) +} +func (c *ApiService) UpdateExecutionWithContext(ctx context.Context, FlowSid string, Sid string, params *UpdateExecutionParams) (*StudioV1Execution, error) { path := "/v1/Flows/{FlowSid}/Executions/{Sid}" path = strings.Replace(path, "{"+"FlowSid"+"}", FlowSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -319,7 +347,7 @@ func (c *ApiService) UpdateExecution(FlowSid string, Sid string, params *UpdateE data.Set("Status", fmt.Sprint(*params.Status)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/studio/v1/flows_executions_context.go b/rest/studio/v1/flows_executions_context.go index 6a6e483f3..8e3de4b89 100644 --- a/rest/studio/v1/flows_executions_context.go +++ b/rest/studio/v1/flows_executions_context.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -22,6 +23,9 @@ import ( // Retrieve the most recent context for an Execution. func (c *ApiService) FetchExecutionContext(FlowSid string, ExecutionSid string) (*StudioV1ExecutionContext, error) { + return c.FetchExecutionContextWithContext(context.TODO(), FlowSid, ExecutionSid) +} +func (c *ApiService) FetchExecutionContextWithContext(ctx context.Context, FlowSid string, ExecutionSid string) (*StudioV1ExecutionContext, error) { path := "/v1/Flows/{FlowSid}/Executions/{ExecutionSid}/Context" path = strings.Replace(path, "{"+"FlowSid"+"}", FlowSid, -1) path = strings.Replace(path, "{"+"ExecutionSid"+"}", ExecutionSid, -1) @@ -31,7 +35,7 @@ func (c *ApiService) FetchExecutionContext(FlowSid string, ExecutionSid string) "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/studio/v1/flows_executions_steps.go b/rest/studio/v1/flows_executions_steps.go index 4b52b4910..a0b9fe424 100644 --- a/rest/studio/v1/flows_executions_steps.go +++ b/rest/studio/v1/flows_executions_steps.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -25,6 +26,9 @@ import ( // Retrieve a Step. func (c *ApiService) FetchExecutionStep(FlowSid string, ExecutionSid string, Sid string) (*StudioV1ExecutionStep, error) { + return c.FetchExecutionStepWithContext(context.TODO(), FlowSid, ExecutionSid, Sid) +} +func (c *ApiService) FetchExecutionStepWithContext(ctx context.Context, FlowSid string, ExecutionSid string, Sid string) (*StudioV1ExecutionStep, error) { path := "/v1/Flows/{FlowSid}/Executions/{ExecutionSid}/Steps/{Sid}" path = strings.Replace(path, "{"+"FlowSid"+"}", FlowSid, -1) path = strings.Replace(path, "{"+"ExecutionSid"+"}", ExecutionSid, -1) @@ -35,7 +39,7 @@ func (c *ApiService) FetchExecutionStep(FlowSid string, ExecutionSid string, Sid "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -69,6 +73,11 @@ func (params *ListExecutionStepParams) SetLimit(Limit int) *ListExecutionStepPar // Retrieve a single page of ExecutionStep records from the API. Request is executed immediately. func (c *ApiService) PageExecutionStep(FlowSid string, ExecutionSid string, params *ListExecutionStepParams, pageToken, pageNumber string) (*ListExecutionStepResponse, error) { + return c.PageExecutionStepWithContext(context.TODO(), FlowSid, ExecutionSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ExecutionStep records from the API. Request is executed immediately. +func (c *ApiService) PageExecutionStepWithContext(ctx context.Context, FlowSid string, ExecutionSid string, params *ListExecutionStepParams, pageToken, pageNumber string) (*ListExecutionStepResponse, error) { path := "/v1/Flows/{FlowSid}/Executions/{ExecutionSid}/Steps" path = strings.Replace(path, "{"+"FlowSid"+"}", FlowSid, -1) @@ -90,7 +99,7 @@ func (c *ApiService) PageExecutionStep(FlowSid string, ExecutionSid string, para data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -107,7 +116,12 @@ func (c *ApiService) PageExecutionStep(FlowSid string, ExecutionSid string, para // Lists ExecutionStep records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListExecutionStep(FlowSid string, ExecutionSid string, params *ListExecutionStepParams) ([]StudioV1ExecutionStep, error) { - response, errors := c.StreamExecutionStep(FlowSid, ExecutionSid, params) + return c.ListExecutionStepWithContext(context.TODO(), FlowSid, ExecutionSid, params) +} + +// Lists ExecutionStep records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListExecutionStepWithContext(ctx context.Context, FlowSid string, ExecutionSid string, params *ListExecutionStepParams) ([]StudioV1ExecutionStep, error) { + response, errors := c.StreamExecutionStepWithContext(ctx, FlowSid, ExecutionSid, params) records := make([]StudioV1ExecutionStep, 0) for record := range response { @@ -123,6 +137,11 @@ func (c *ApiService) ListExecutionStep(FlowSid string, ExecutionSid string, para // Streams ExecutionStep records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamExecutionStep(FlowSid string, ExecutionSid string, params *ListExecutionStepParams) (chan StudioV1ExecutionStep, chan error) { + return c.StreamExecutionStepWithContext(context.TODO(), FlowSid, ExecutionSid, params) +} + +// Streams ExecutionStep records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamExecutionStepWithContext(ctx context.Context, FlowSid string, ExecutionSid string, params *ListExecutionStepParams) (chan StudioV1ExecutionStep, chan error) { if params == nil { params = &ListExecutionStepParams{} } @@ -131,19 +150,19 @@ func (c *ApiService) StreamExecutionStep(FlowSid string, ExecutionSid string, pa recordChannel := make(chan StudioV1ExecutionStep, 1) errorChannel := make(chan error, 1) - response, err := c.PageExecutionStep(FlowSid, ExecutionSid, params, "", "") + response, err := c.PageExecutionStepWithContext(ctx, FlowSid, ExecutionSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamExecutionStep(response, params, recordChannel, errorChannel) + go c.streamExecutionStepWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamExecutionStep(response *ListExecutionStepResponse, params *ListExecutionStepParams, recordChannel chan StudioV1ExecutionStep, errorChannel chan error) { +func (c *ApiService) streamExecutionStepWithContext(ctx context.Context, response *ListExecutionStepResponse, params *ListExecutionStepParams, recordChannel chan StudioV1ExecutionStep, errorChannel chan error) { curRecord := 1 for response != nil { @@ -158,7 +177,7 @@ func (c *ApiService) streamExecutionStep(response *ListExecutionStepResponse, pa } } - record, err := client.GetNext(c.baseURL, response, c.getNextListExecutionStepResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListExecutionStepResponseWithContext) if err != nil { errorChannel <- err break @@ -173,11 +192,11 @@ func (c *ApiService) streamExecutionStep(response *ListExecutionStepResponse, pa close(errorChannel) } -func (c *ApiService) getNextListExecutionStepResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListExecutionStepResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/studio/v1/flows_executions_steps_context.go b/rest/studio/v1/flows_executions_steps_context.go index f3866ad56..c34f56731 100644 --- a/rest/studio/v1/flows_executions_steps_context.go +++ b/rest/studio/v1/flows_executions_steps_context.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -22,6 +23,9 @@ import ( // Retrieve the context for an Execution Step. func (c *ApiService) FetchExecutionStepContext(FlowSid string, ExecutionSid string, StepSid string) (*StudioV1ExecutionStepContext, error) { + return c.FetchExecutionStepContextWithContext(context.TODO(), FlowSid, ExecutionSid, StepSid) +} +func (c *ApiService) FetchExecutionStepContextWithContext(ctx context.Context, FlowSid string, ExecutionSid string, StepSid string) (*StudioV1ExecutionStepContext, error) { path := "/v1/Flows/{FlowSid}/Executions/{ExecutionSid}/Steps/{StepSid}/Context" path = strings.Replace(path, "{"+"FlowSid"+"}", FlowSid, -1) path = strings.Replace(path, "{"+"ExecutionSid"+"}", ExecutionSid, -1) @@ -32,7 +36,7 @@ func (c *ApiService) FetchExecutionStepContext(FlowSid string, ExecutionSid stri "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/studio/v2/api_service.go b/rest/studio/v2/api_service.go index 8cdd0d27f..2f927fffa 100644 --- a/rest/studio/v2/api_service.go +++ b/rest/studio/v2/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://studio.twilio.com", + } +} diff --git a/rest/studio/v2/flows.go b/rest/studio/v2/flows.go index 826399d0d..0c9c2e080 100644 --- a/rest/studio/v2/flows.go +++ b/rest/studio/v2/flows.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -54,6 +55,9 @@ func (params *CreateFlowParams) SetCommitMessage(CommitMessage string) *CreateFl // Create a Flow. func (c *ApiService) CreateFlow(params *CreateFlowParams) (*StudioV2Flow, error) { + return c.CreateFlowWithContext(context.TODO(), params) +} +func (c *ApiService) CreateFlowWithContext(ctx context.Context, params *CreateFlowParams) (*StudioV2Flow, error) { path := "/v2/Flows" data := url.Values{} @@ -80,7 +84,7 @@ func (c *ApiService) CreateFlow(params *CreateFlowParams) (*StudioV2Flow, error) data.Set("CommitMessage", *params.CommitMessage) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -97,6 +101,9 @@ func (c *ApiService) CreateFlow(params *CreateFlowParams) (*StudioV2Flow, error) // Delete a specific Flow. func (c *ApiService) DeleteFlow(Sid string) error { + return c.DeleteFlowWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteFlowWithContext(ctx context.Context, Sid string) error { path := "/v2/Flows/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -105,7 +112,7 @@ func (c *ApiService) DeleteFlow(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -117,6 +124,9 @@ func (c *ApiService) DeleteFlow(Sid string) error { // Retrieve a specific Flow. func (c *ApiService) FetchFlow(Sid string) (*StudioV2Flow, error) { + return c.FetchFlowWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchFlowWithContext(ctx context.Context, Sid string) (*StudioV2Flow, error) { path := "/v2/Flows/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -125,7 +135,7 @@ func (c *ApiService) FetchFlow(Sid string) (*StudioV2Flow, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -159,6 +169,11 @@ func (params *ListFlowParams) SetLimit(Limit int) *ListFlowParams { // Retrieve a single page of Flow records from the API. Request is executed immediately. func (c *ApiService) PageFlow(params *ListFlowParams, pageToken, pageNumber string) (*ListFlowResponse, error) { + return c.PageFlowWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Flow records from the API. Request is executed immediately. +func (c *ApiService) PageFlowWithContext(ctx context.Context, params *ListFlowParams, pageToken, pageNumber string) (*ListFlowResponse, error) { path := "/v2/Flows" data := url.Values{} @@ -177,7 +192,7 @@ func (c *ApiService) PageFlow(params *ListFlowParams, pageToken, pageNumber stri data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -194,7 +209,12 @@ func (c *ApiService) PageFlow(params *ListFlowParams, pageToken, pageNumber stri // Lists Flow records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListFlow(params *ListFlowParams) ([]StudioV2Flow, error) { - response, errors := c.StreamFlow(params) + return c.ListFlowWithContext(context.TODO(), params) +} + +// Lists Flow records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListFlowWithContext(ctx context.Context, params *ListFlowParams) ([]StudioV2Flow, error) { + response, errors := c.StreamFlowWithContext(ctx, params) records := make([]StudioV2Flow, 0) for record := range response { @@ -210,6 +230,11 @@ func (c *ApiService) ListFlow(params *ListFlowParams) ([]StudioV2Flow, error) { // Streams Flow records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamFlow(params *ListFlowParams) (chan StudioV2Flow, chan error) { + return c.StreamFlowWithContext(context.TODO(), params) +} + +// Streams Flow records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamFlowWithContext(ctx context.Context, params *ListFlowParams) (chan StudioV2Flow, chan error) { if params == nil { params = &ListFlowParams{} } @@ -218,19 +243,19 @@ func (c *ApiService) StreamFlow(params *ListFlowParams) (chan StudioV2Flow, chan recordChannel := make(chan StudioV2Flow, 1) errorChannel := make(chan error, 1) - response, err := c.PageFlow(params, "", "") + response, err := c.PageFlowWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamFlow(response, params, recordChannel, errorChannel) + go c.streamFlowWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamFlow(response *ListFlowResponse, params *ListFlowParams, recordChannel chan StudioV2Flow, errorChannel chan error) { +func (c *ApiService) streamFlowWithContext(ctx context.Context, response *ListFlowResponse, params *ListFlowParams, recordChannel chan StudioV2Flow, errorChannel chan error) { curRecord := 1 for response != nil { @@ -245,7 +270,7 @@ func (c *ApiService) streamFlow(response *ListFlowResponse, params *ListFlowPara } } - record, err := client.GetNext(c.baseURL, response, c.getNextListFlowResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListFlowResponseWithContext) if err != nil { errorChannel <- err break @@ -260,11 +285,11 @@ func (c *ApiService) streamFlow(response *ListFlowResponse, params *ListFlowPara close(errorChannel) } -func (c *ApiService) getNextListFlowResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListFlowResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -309,6 +334,9 @@ func (params *UpdateFlowParams) SetCommitMessage(CommitMessage string) *UpdateFl // Update a Flow. func (c *ApiService) UpdateFlow(Sid string, params *UpdateFlowParams) (*StudioV2Flow, error) { + return c.UpdateFlowWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateFlowWithContext(ctx context.Context, Sid string, params *UpdateFlowParams) (*StudioV2Flow, error) { path := "/v2/Flows/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -336,7 +364,7 @@ func (c *ApiService) UpdateFlow(Sid string, params *UpdateFlowParams) (*StudioV2 data.Set("CommitMessage", *params.CommitMessage) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/studio/v2/flows_executions.go b/rest/studio/v2/flows_executions.go index 79feff882..a9b3c57fa 100644 --- a/rest/studio/v2/flows_executions.go +++ b/rest/studio/v2/flows_executions.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -49,6 +50,9 @@ func (params *CreateExecutionParams) SetParameters(Parameters map[string]interfa // Triggers a new Execution for the Flow func (c *ApiService) CreateExecution(FlowSid string, params *CreateExecutionParams) (*StudioV2Execution, error) { + return c.CreateExecutionWithContext(context.TODO(), FlowSid, params) +} +func (c *ApiService) CreateExecutionWithContext(ctx context.Context, FlowSid string, params *CreateExecutionParams) (*StudioV2Execution, error) { path := "/v2/Flows/{FlowSid}/Executions" path = strings.Replace(path, "{"+"FlowSid"+"}", FlowSid, -1) @@ -73,7 +77,7 @@ func (c *ApiService) CreateExecution(FlowSid string, params *CreateExecutionPara data.Set("Parameters", string(v)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -90,6 +94,9 @@ func (c *ApiService) CreateExecution(FlowSid string, params *CreateExecutionPara // Delete the Execution and all Steps relating to it. func (c *ApiService) DeleteExecution(FlowSid string, Sid string) error { + return c.DeleteExecutionWithContext(context.TODO(), FlowSid, Sid) +} +func (c *ApiService) DeleteExecutionWithContext(ctx context.Context, FlowSid string, Sid string) error { path := "/v2/Flows/{FlowSid}/Executions/{Sid}" path = strings.Replace(path, "{"+"FlowSid"+"}", FlowSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -99,7 +106,7 @@ func (c *ApiService) DeleteExecution(FlowSid string, Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -111,6 +118,9 @@ func (c *ApiService) DeleteExecution(FlowSid string, Sid string) error { // Retrieve an Execution func (c *ApiService) FetchExecution(FlowSid string, Sid string) (*StudioV2Execution, error) { + return c.FetchExecutionWithContext(context.TODO(), FlowSid, Sid) +} +func (c *ApiService) FetchExecutionWithContext(ctx context.Context, FlowSid string, Sid string) (*StudioV2Execution, error) { path := "/v2/Flows/{FlowSid}/Executions/{Sid}" path = strings.Replace(path, "{"+"FlowSid"+"}", FlowSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -120,7 +130,7 @@ func (c *ApiService) FetchExecution(FlowSid string, Sid string) (*StudioV2Execut "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -166,6 +176,11 @@ func (params *ListExecutionParams) SetLimit(Limit int) *ListExecutionParams { // Retrieve a single page of Execution records from the API. Request is executed immediately. func (c *ApiService) PageExecution(FlowSid string, params *ListExecutionParams, pageToken, pageNumber string) (*ListExecutionResponse, error) { + return c.PageExecutionWithContext(context.TODO(), FlowSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Execution records from the API. Request is executed immediately. +func (c *ApiService) PageExecutionWithContext(ctx context.Context, FlowSid string, params *ListExecutionParams, pageToken, pageNumber string) (*ListExecutionResponse, error) { path := "/v2/Flows/{FlowSid}/Executions" path = strings.Replace(path, "{"+"FlowSid"+"}", FlowSid, -1) @@ -192,7 +207,7 @@ func (c *ApiService) PageExecution(FlowSid string, params *ListExecutionParams, data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -209,7 +224,12 @@ func (c *ApiService) PageExecution(FlowSid string, params *ListExecutionParams, // Lists Execution records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListExecution(FlowSid string, params *ListExecutionParams) ([]StudioV2Execution, error) { - response, errors := c.StreamExecution(FlowSid, params) + return c.ListExecutionWithContext(context.TODO(), FlowSid, params) +} + +// Lists Execution records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListExecutionWithContext(ctx context.Context, FlowSid string, params *ListExecutionParams) ([]StudioV2Execution, error) { + response, errors := c.StreamExecutionWithContext(ctx, FlowSid, params) records := make([]StudioV2Execution, 0) for record := range response { @@ -225,6 +245,11 @@ func (c *ApiService) ListExecution(FlowSid string, params *ListExecutionParams) // Streams Execution records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamExecution(FlowSid string, params *ListExecutionParams) (chan StudioV2Execution, chan error) { + return c.StreamExecutionWithContext(context.TODO(), FlowSid, params) +} + +// Streams Execution records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamExecutionWithContext(ctx context.Context, FlowSid string, params *ListExecutionParams) (chan StudioV2Execution, chan error) { if params == nil { params = &ListExecutionParams{} } @@ -233,19 +258,19 @@ func (c *ApiService) StreamExecution(FlowSid string, params *ListExecutionParams recordChannel := make(chan StudioV2Execution, 1) errorChannel := make(chan error, 1) - response, err := c.PageExecution(FlowSid, params, "", "") + response, err := c.PageExecutionWithContext(ctx, FlowSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamExecution(response, params, recordChannel, errorChannel) + go c.streamExecutionWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamExecution(response *ListExecutionResponse, params *ListExecutionParams, recordChannel chan StudioV2Execution, errorChannel chan error) { +func (c *ApiService) streamExecutionWithContext(ctx context.Context, response *ListExecutionResponse, params *ListExecutionParams, recordChannel chan StudioV2Execution, errorChannel chan error) { curRecord := 1 for response != nil { @@ -260,7 +285,7 @@ func (c *ApiService) streamExecution(response *ListExecutionResponse, params *Li } } - record, err := client.GetNext(c.baseURL, response, c.getNextListExecutionResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListExecutionResponseWithContext) if err != nil { errorChannel <- err break @@ -275,11 +300,11 @@ func (c *ApiService) streamExecution(response *ListExecutionResponse, params *Li close(errorChannel) } -func (c *ApiService) getNextListExecutionResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListExecutionResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -306,6 +331,9 @@ func (params *UpdateExecutionParams) SetStatus(Status string) *UpdateExecutionPa // Update the status of an Execution to `ended`. func (c *ApiService) UpdateExecution(FlowSid string, Sid string, params *UpdateExecutionParams) (*StudioV2Execution, error) { + return c.UpdateExecutionWithContext(context.TODO(), FlowSid, Sid, params) +} +func (c *ApiService) UpdateExecutionWithContext(ctx context.Context, FlowSid string, Sid string, params *UpdateExecutionParams) (*StudioV2Execution, error) { path := "/v2/Flows/{FlowSid}/Executions/{Sid}" path = strings.Replace(path, "{"+"FlowSid"+"}", FlowSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -319,7 +347,7 @@ func (c *ApiService) UpdateExecution(FlowSid string, Sid string, params *UpdateE data.Set("Status", fmt.Sprint(*params.Status)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/studio/v2/flows_executions_context.go b/rest/studio/v2/flows_executions_context.go index 9133eea45..14f306405 100644 --- a/rest/studio/v2/flows_executions_context.go +++ b/rest/studio/v2/flows_executions_context.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -22,6 +23,9 @@ import ( // Retrieve the most recent context for an Execution. func (c *ApiService) FetchExecutionContext(FlowSid string, ExecutionSid string) (*StudioV2ExecutionContext, error) { + return c.FetchExecutionContextWithContext(context.TODO(), FlowSid, ExecutionSid) +} +func (c *ApiService) FetchExecutionContextWithContext(ctx context.Context, FlowSid string, ExecutionSid string) (*StudioV2ExecutionContext, error) { path := "/v2/Flows/{FlowSid}/Executions/{ExecutionSid}/Context" path = strings.Replace(path, "{"+"FlowSid"+"}", FlowSid, -1) path = strings.Replace(path, "{"+"ExecutionSid"+"}", ExecutionSid, -1) @@ -31,7 +35,7 @@ func (c *ApiService) FetchExecutionContext(FlowSid string, ExecutionSid string) "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/studio/v2/flows_executions_steps.go b/rest/studio/v2/flows_executions_steps.go index 9b190ad3d..d4fc90e95 100644 --- a/rest/studio/v2/flows_executions_steps.go +++ b/rest/studio/v2/flows_executions_steps.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -25,6 +26,9 @@ import ( // Retrieve a Step. func (c *ApiService) FetchExecutionStep(FlowSid string, ExecutionSid string, Sid string) (*StudioV2ExecutionStep, error) { + return c.FetchExecutionStepWithContext(context.TODO(), FlowSid, ExecutionSid, Sid) +} +func (c *ApiService) FetchExecutionStepWithContext(ctx context.Context, FlowSid string, ExecutionSid string, Sid string) (*StudioV2ExecutionStep, error) { path := "/v2/Flows/{FlowSid}/Executions/{ExecutionSid}/Steps/{Sid}" path = strings.Replace(path, "{"+"FlowSid"+"}", FlowSid, -1) path = strings.Replace(path, "{"+"ExecutionSid"+"}", ExecutionSid, -1) @@ -35,7 +39,7 @@ func (c *ApiService) FetchExecutionStep(FlowSid string, ExecutionSid string, Sid "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -69,6 +73,11 @@ func (params *ListExecutionStepParams) SetLimit(Limit int) *ListExecutionStepPar // Retrieve a single page of ExecutionStep records from the API. Request is executed immediately. func (c *ApiService) PageExecutionStep(FlowSid string, ExecutionSid string, params *ListExecutionStepParams, pageToken, pageNumber string) (*ListExecutionStepResponse, error) { + return c.PageExecutionStepWithContext(context.TODO(), FlowSid, ExecutionSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ExecutionStep records from the API. Request is executed immediately. +func (c *ApiService) PageExecutionStepWithContext(ctx context.Context, FlowSid string, ExecutionSid string, params *ListExecutionStepParams, pageToken, pageNumber string) (*ListExecutionStepResponse, error) { path := "/v2/Flows/{FlowSid}/Executions/{ExecutionSid}/Steps" path = strings.Replace(path, "{"+"FlowSid"+"}", FlowSid, -1) @@ -90,7 +99,7 @@ func (c *ApiService) PageExecutionStep(FlowSid string, ExecutionSid string, para data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -107,7 +116,12 @@ func (c *ApiService) PageExecutionStep(FlowSid string, ExecutionSid string, para // Lists ExecutionStep records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListExecutionStep(FlowSid string, ExecutionSid string, params *ListExecutionStepParams) ([]StudioV2ExecutionStep, error) { - response, errors := c.StreamExecutionStep(FlowSid, ExecutionSid, params) + return c.ListExecutionStepWithContext(context.TODO(), FlowSid, ExecutionSid, params) +} + +// Lists ExecutionStep records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListExecutionStepWithContext(ctx context.Context, FlowSid string, ExecutionSid string, params *ListExecutionStepParams) ([]StudioV2ExecutionStep, error) { + response, errors := c.StreamExecutionStepWithContext(ctx, FlowSid, ExecutionSid, params) records := make([]StudioV2ExecutionStep, 0) for record := range response { @@ -123,6 +137,11 @@ func (c *ApiService) ListExecutionStep(FlowSid string, ExecutionSid string, para // Streams ExecutionStep records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamExecutionStep(FlowSid string, ExecutionSid string, params *ListExecutionStepParams) (chan StudioV2ExecutionStep, chan error) { + return c.StreamExecutionStepWithContext(context.TODO(), FlowSid, ExecutionSid, params) +} + +// Streams ExecutionStep records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamExecutionStepWithContext(ctx context.Context, FlowSid string, ExecutionSid string, params *ListExecutionStepParams) (chan StudioV2ExecutionStep, chan error) { if params == nil { params = &ListExecutionStepParams{} } @@ -131,19 +150,19 @@ func (c *ApiService) StreamExecutionStep(FlowSid string, ExecutionSid string, pa recordChannel := make(chan StudioV2ExecutionStep, 1) errorChannel := make(chan error, 1) - response, err := c.PageExecutionStep(FlowSid, ExecutionSid, params, "", "") + response, err := c.PageExecutionStepWithContext(ctx, FlowSid, ExecutionSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamExecutionStep(response, params, recordChannel, errorChannel) + go c.streamExecutionStepWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamExecutionStep(response *ListExecutionStepResponse, params *ListExecutionStepParams, recordChannel chan StudioV2ExecutionStep, errorChannel chan error) { +func (c *ApiService) streamExecutionStepWithContext(ctx context.Context, response *ListExecutionStepResponse, params *ListExecutionStepParams, recordChannel chan StudioV2ExecutionStep, errorChannel chan error) { curRecord := 1 for response != nil { @@ -158,7 +177,7 @@ func (c *ApiService) streamExecutionStep(response *ListExecutionStepResponse, pa } } - record, err := client.GetNext(c.baseURL, response, c.getNextListExecutionStepResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListExecutionStepResponseWithContext) if err != nil { errorChannel <- err break @@ -173,11 +192,11 @@ func (c *ApiService) streamExecutionStep(response *ListExecutionStepResponse, pa close(errorChannel) } -func (c *ApiService) getNextListExecutionStepResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListExecutionStepResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/studio/v2/flows_executions_steps_context.go b/rest/studio/v2/flows_executions_steps_context.go index fb1ea0a32..940808d47 100644 --- a/rest/studio/v2/flows_executions_steps_context.go +++ b/rest/studio/v2/flows_executions_steps_context.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -22,6 +23,9 @@ import ( // Retrieve the context for an Execution Step. func (c *ApiService) FetchExecutionStepContext(FlowSid string, ExecutionSid string, StepSid string) (*StudioV2ExecutionStepContext, error) { + return c.FetchExecutionStepContextWithContext(context.TODO(), FlowSid, ExecutionSid, StepSid) +} +func (c *ApiService) FetchExecutionStepContextWithContext(ctx context.Context, FlowSid string, ExecutionSid string, StepSid string) (*StudioV2ExecutionStepContext, error) { path := "/v2/Flows/{FlowSid}/Executions/{ExecutionSid}/Steps/{StepSid}/Context" path = strings.Replace(path, "{"+"FlowSid"+"}", FlowSid, -1) path = strings.Replace(path, "{"+"ExecutionSid"+"}", ExecutionSid, -1) @@ -32,7 +36,7 @@ func (c *ApiService) FetchExecutionStepContext(FlowSid string, ExecutionSid stri "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/studio/v2/flows_revisions.go b/rest/studio/v2/flows_revisions.go index b7471d5f1..f3d7a650e 100644 --- a/rest/studio/v2/flows_revisions.go +++ b/rest/studio/v2/flows_revisions.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -25,6 +26,9 @@ import ( // Retrieve a specific Flow revision. func (c *ApiService) FetchFlowRevision(Sid string, Revision string) (*StudioV2FlowRevision, error) { + return c.FetchFlowRevisionWithContext(context.TODO(), Sid, Revision) +} +func (c *ApiService) FetchFlowRevisionWithContext(ctx context.Context, Sid string, Revision string) (*StudioV2FlowRevision, error) { path := "/v2/Flows/{Sid}/Revisions/{Revision}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) path = strings.Replace(path, "{"+"Revision"+"}", Revision, -1) @@ -34,7 +38,7 @@ func (c *ApiService) FetchFlowRevision(Sid string, Revision string) (*StudioV2Fl "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -68,6 +72,11 @@ func (params *ListFlowRevisionParams) SetLimit(Limit int) *ListFlowRevisionParam // Retrieve a single page of FlowRevision records from the API. Request is executed immediately. func (c *ApiService) PageFlowRevision(Sid string, params *ListFlowRevisionParams, pageToken, pageNumber string) (*ListFlowRevisionResponse, error) { + return c.PageFlowRevisionWithContext(context.TODO(), Sid, params, pageToken, pageNumber) +} + +// Retrieve a single page of FlowRevision records from the API. Request is executed immediately. +func (c *ApiService) PageFlowRevisionWithContext(ctx context.Context, Sid string, params *ListFlowRevisionParams, pageToken, pageNumber string) (*ListFlowRevisionResponse, error) { path := "/v2/Flows/{Sid}/Revisions" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -88,7 +97,7 @@ func (c *ApiService) PageFlowRevision(Sid string, params *ListFlowRevisionParams data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -105,7 +114,12 @@ func (c *ApiService) PageFlowRevision(Sid string, params *ListFlowRevisionParams // Lists FlowRevision records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListFlowRevision(Sid string, params *ListFlowRevisionParams) ([]StudioV2FlowRevision, error) { - response, errors := c.StreamFlowRevision(Sid, params) + return c.ListFlowRevisionWithContext(context.TODO(), Sid, params) +} + +// Lists FlowRevision records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListFlowRevisionWithContext(ctx context.Context, Sid string, params *ListFlowRevisionParams) ([]StudioV2FlowRevision, error) { + response, errors := c.StreamFlowRevisionWithContext(ctx, Sid, params) records := make([]StudioV2FlowRevision, 0) for record := range response { @@ -121,6 +135,11 @@ func (c *ApiService) ListFlowRevision(Sid string, params *ListFlowRevisionParams // Streams FlowRevision records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamFlowRevision(Sid string, params *ListFlowRevisionParams) (chan StudioV2FlowRevision, chan error) { + return c.StreamFlowRevisionWithContext(context.TODO(), Sid, params) +} + +// Streams FlowRevision records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamFlowRevisionWithContext(ctx context.Context, Sid string, params *ListFlowRevisionParams) (chan StudioV2FlowRevision, chan error) { if params == nil { params = &ListFlowRevisionParams{} } @@ -129,19 +148,19 @@ func (c *ApiService) StreamFlowRevision(Sid string, params *ListFlowRevisionPara recordChannel := make(chan StudioV2FlowRevision, 1) errorChannel := make(chan error, 1) - response, err := c.PageFlowRevision(Sid, params, "", "") + response, err := c.PageFlowRevisionWithContext(ctx, Sid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamFlowRevision(response, params, recordChannel, errorChannel) + go c.streamFlowRevisionWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamFlowRevision(response *ListFlowRevisionResponse, params *ListFlowRevisionParams, recordChannel chan StudioV2FlowRevision, errorChannel chan error) { +func (c *ApiService) streamFlowRevisionWithContext(ctx context.Context, response *ListFlowRevisionResponse, params *ListFlowRevisionParams, recordChannel chan StudioV2FlowRevision, errorChannel chan error) { curRecord := 1 for response != nil { @@ -156,7 +175,7 @@ func (c *ApiService) streamFlowRevision(response *ListFlowRevisionResponse, para } } - record, err := client.GetNext(c.baseURL, response, c.getNextListFlowRevisionResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListFlowRevisionResponseWithContext) if err != nil { errorChannel <- err break @@ -171,11 +190,11 @@ func (c *ApiService) streamFlowRevision(response *ListFlowRevisionResponse, para close(errorChannel) } -func (c *ApiService) getNextListFlowRevisionResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListFlowRevisionResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/studio/v2/flows_test_users.go b/rest/studio/v2/flows_test_users.go index ff348b378..0645851c5 100644 --- a/rest/studio/v2/flows_test_users.go +++ b/rest/studio/v2/flows_test_users.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -22,6 +23,9 @@ import ( // Fetch flow test users func (c *ApiService) FetchTestUser(Sid string) (*StudioV2TestUser, error) { + return c.FetchTestUserWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchTestUserWithContext(ctx context.Context, Sid string) (*StudioV2TestUser, error) { path := "/v2/Flows/{Sid}/TestUsers" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -30,7 +34,7 @@ func (c *ApiService) FetchTestUser(Sid string) (*StudioV2TestUser, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -58,6 +62,9 @@ func (params *UpdateTestUserParams) SetTestUsers(TestUsers []string) *UpdateTest // Update flow test users func (c *ApiService) UpdateTestUser(Sid string, params *UpdateTestUserParams) (*StudioV2TestUser, error) { + return c.UpdateTestUserWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateTestUserWithContext(ctx context.Context, Sid string, params *UpdateTestUserParams) (*StudioV2TestUser, error) { path := "/v2/Flows/{Sid}/TestUsers" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -72,7 +79,7 @@ func (c *ApiService) UpdateTestUser(Sid string, params *UpdateTestUserParams) (* } } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/studio/v2/flows_validate.go b/rest/studio/v2/flows_validate.go index 254dbe029..f9225670e 100644 --- a/rest/studio/v2/flows_validate.go +++ b/rest/studio/v2/flows_validate.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -51,6 +52,9 @@ func (params *UpdateFlowValidateParams) SetCommitMessage(CommitMessage string) * // Validate flow JSON definition func (c *ApiService) UpdateFlowValidate(params *UpdateFlowValidateParams) (*StudioV2FlowValidate, error) { + return c.UpdateFlowValidateWithContext(context.TODO(), params) +} +func (c *ApiService) UpdateFlowValidateWithContext(ctx context.Context, params *UpdateFlowValidateParams) (*StudioV2FlowValidate, error) { path := "/v2/Flows/Validate" data := url.Values{} @@ -77,7 +81,7 @@ func (c *ApiService) UpdateFlowValidate(params *UpdateFlowValidateParams) (*Stud data.Set("CommitMessage", *params.CommitMessage) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/supersim/v1/api_service.go b/rest/supersim/v1/api_service.go index ce3bad411..68c8c356f 100644 --- a/rest/supersim/v1/api_service.go +++ b/rest/supersim/v1/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://supersim.twilio.com", + } +} diff --git a/rest/supersim/v1/e_sim_profiles.go b/rest/supersim/v1/e_sim_profiles.go index 7845fe966..2fa51199e 100644 --- a/rest/supersim/v1/e_sim_profiles.go +++ b/rest/supersim/v1/e_sim_profiles.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -54,6 +55,9 @@ func (params *CreateEsimProfileParams) SetEid(Eid string) *CreateEsimProfilePara // Order an eSIM Profile. func (c *ApiService) CreateEsimProfile(params *CreateEsimProfileParams) (*SupersimV1EsimProfile, error) { + return c.CreateEsimProfileWithContext(context.TODO(), params) +} +func (c *ApiService) CreateEsimProfileWithContext(ctx context.Context, params *CreateEsimProfileParams) (*SupersimV1EsimProfile, error) { path := "/v1/ESimProfiles" data := url.Values{} @@ -74,7 +78,7 @@ func (c *ApiService) CreateEsimProfile(params *CreateEsimProfileParams) (*Supers data.Set("Eid", *params.Eid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -91,6 +95,9 @@ func (c *ApiService) CreateEsimProfile(params *CreateEsimProfileParams) (*Supers // Fetch an eSIM Profile. func (c *ApiService) FetchEsimProfile(Sid string) (*SupersimV1EsimProfile, error) { + return c.FetchEsimProfileWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchEsimProfileWithContext(ctx context.Context, Sid string) (*SupersimV1EsimProfile, error) { path := "/v1/ESimProfiles/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -99,7 +106,7 @@ func (c *ApiService) FetchEsimProfile(Sid string) (*SupersimV1EsimProfile, error "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -151,6 +158,11 @@ func (params *ListEsimProfileParams) SetLimit(Limit int) *ListEsimProfileParams // Retrieve a single page of EsimProfile records from the API. Request is executed immediately. func (c *ApiService) PageEsimProfile(params *ListEsimProfileParams, pageToken, pageNumber string) (*ListEsimProfileResponse, error) { + return c.PageEsimProfileWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of EsimProfile records from the API. Request is executed immediately. +func (c *ApiService) PageEsimProfileWithContext(ctx context.Context, params *ListEsimProfileParams, pageToken, pageNumber string) (*ListEsimProfileResponse, error) { path := "/v1/ESimProfiles" data := url.Values{} @@ -178,7 +190,7 @@ func (c *ApiService) PageEsimProfile(params *ListEsimProfileParams, pageToken, p data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -195,7 +207,12 @@ func (c *ApiService) PageEsimProfile(params *ListEsimProfileParams, pageToken, p // Lists EsimProfile records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListEsimProfile(params *ListEsimProfileParams) ([]SupersimV1EsimProfile, error) { - response, errors := c.StreamEsimProfile(params) + return c.ListEsimProfileWithContext(context.TODO(), params) +} + +// Lists EsimProfile records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListEsimProfileWithContext(ctx context.Context, params *ListEsimProfileParams) ([]SupersimV1EsimProfile, error) { + response, errors := c.StreamEsimProfileWithContext(ctx, params) records := make([]SupersimV1EsimProfile, 0) for record := range response { @@ -211,6 +228,11 @@ func (c *ApiService) ListEsimProfile(params *ListEsimProfileParams) ([]SupersimV // Streams EsimProfile records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamEsimProfile(params *ListEsimProfileParams) (chan SupersimV1EsimProfile, chan error) { + return c.StreamEsimProfileWithContext(context.TODO(), params) +} + +// Streams EsimProfile records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamEsimProfileWithContext(ctx context.Context, params *ListEsimProfileParams) (chan SupersimV1EsimProfile, chan error) { if params == nil { params = &ListEsimProfileParams{} } @@ -219,19 +241,19 @@ func (c *ApiService) StreamEsimProfile(params *ListEsimProfileParams) (chan Supe recordChannel := make(chan SupersimV1EsimProfile, 1) errorChannel := make(chan error, 1) - response, err := c.PageEsimProfile(params, "", "") + response, err := c.PageEsimProfileWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamEsimProfile(response, params, recordChannel, errorChannel) + go c.streamEsimProfileWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamEsimProfile(response *ListEsimProfileResponse, params *ListEsimProfileParams, recordChannel chan SupersimV1EsimProfile, errorChannel chan error) { +func (c *ApiService) streamEsimProfileWithContext(ctx context.Context, response *ListEsimProfileResponse, params *ListEsimProfileParams, recordChannel chan SupersimV1EsimProfile, errorChannel chan error) { curRecord := 1 for response != nil { @@ -246,7 +268,7 @@ func (c *ApiService) streamEsimProfile(response *ListEsimProfileResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListEsimProfileResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListEsimProfileResponseWithContext) if err != nil { errorChannel <- err break @@ -261,11 +283,11 @@ func (c *ApiService) streamEsimProfile(response *ListEsimProfileResponse, params close(errorChannel) } -func (c *ApiService) getNextListEsimProfileResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListEsimProfileResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/supersim/v1/fleets.go b/rest/supersim/v1/fleets.go index ce99486a8..78bfcabe3 100644 --- a/rest/supersim/v1/fleets.go +++ b/rest/supersim/v1/fleets.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -84,6 +85,9 @@ func (params *CreateFleetParams) SetSmsCommandsMethod(SmsCommandsMethod string) // Create a Fleet func (c *ApiService) CreateFleet(params *CreateFleetParams) (*SupersimV1Fleet, error) { + return c.CreateFleetWithContext(context.TODO(), params) +} +func (c *ApiService) CreateFleetWithContext(ctx context.Context, params *CreateFleetParams) (*SupersimV1Fleet, error) { path := "/v1/Fleets" data := url.Values{} @@ -119,7 +123,7 @@ func (c *ApiService) CreateFleet(params *CreateFleetParams) (*SupersimV1Fleet, e data.Set("SmsCommandsMethod", *params.SmsCommandsMethod) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -136,6 +140,9 @@ func (c *ApiService) CreateFleet(params *CreateFleetParams) (*SupersimV1Fleet, e // Fetch a Fleet instance from your account. func (c *ApiService) FetchFleet(Sid string) (*SupersimV1Fleet, error) { + return c.FetchFleetWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchFleetWithContext(ctx context.Context, Sid string) (*SupersimV1Fleet, error) { path := "/v1/Fleets/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -144,7 +151,7 @@ func (c *ApiService) FetchFleet(Sid string) (*SupersimV1Fleet, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -184,6 +191,11 @@ func (params *ListFleetParams) SetLimit(Limit int) *ListFleetParams { // Retrieve a single page of Fleet records from the API. Request is executed immediately. func (c *ApiService) PageFleet(params *ListFleetParams, pageToken, pageNumber string) (*ListFleetResponse, error) { + return c.PageFleetWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Fleet records from the API. Request is executed immediately. +func (c *ApiService) PageFleetWithContext(ctx context.Context, params *ListFleetParams, pageToken, pageNumber string) (*ListFleetResponse, error) { path := "/v1/Fleets" data := url.Values{} @@ -205,7 +217,7 @@ func (c *ApiService) PageFleet(params *ListFleetParams, pageToken, pageNumber st data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -222,7 +234,12 @@ func (c *ApiService) PageFleet(params *ListFleetParams, pageToken, pageNumber st // Lists Fleet records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListFleet(params *ListFleetParams) ([]SupersimV1Fleet, error) { - response, errors := c.StreamFleet(params) + return c.ListFleetWithContext(context.TODO(), params) +} + +// Lists Fleet records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListFleetWithContext(ctx context.Context, params *ListFleetParams) ([]SupersimV1Fleet, error) { + response, errors := c.StreamFleetWithContext(ctx, params) records := make([]SupersimV1Fleet, 0) for record := range response { @@ -238,6 +255,11 @@ func (c *ApiService) ListFleet(params *ListFleetParams) ([]SupersimV1Fleet, erro // Streams Fleet records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamFleet(params *ListFleetParams) (chan SupersimV1Fleet, chan error) { + return c.StreamFleetWithContext(context.TODO(), params) +} + +// Streams Fleet records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamFleetWithContext(ctx context.Context, params *ListFleetParams) (chan SupersimV1Fleet, chan error) { if params == nil { params = &ListFleetParams{} } @@ -246,19 +268,19 @@ func (c *ApiService) StreamFleet(params *ListFleetParams) (chan SupersimV1Fleet, recordChannel := make(chan SupersimV1Fleet, 1) errorChannel := make(chan error, 1) - response, err := c.PageFleet(params, "", "") + response, err := c.PageFleetWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamFleet(response, params, recordChannel, errorChannel) + go c.streamFleetWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamFleet(response *ListFleetResponse, params *ListFleetParams, recordChannel chan SupersimV1Fleet, errorChannel chan error) { +func (c *ApiService) streamFleetWithContext(ctx context.Context, response *ListFleetResponse, params *ListFleetParams, recordChannel chan SupersimV1Fleet, errorChannel chan error) { curRecord := 1 for response != nil { @@ -273,7 +295,7 @@ func (c *ApiService) streamFleet(response *ListFleetResponse, params *ListFleetP } } - record, err := client.GetNext(c.baseURL, response, c.getNextListFleetResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListFleetResponseWithContext) if err != nil { errorChannel <- err break @@ -288,11 +310,11 @@ func (c *ApiService) streamFleet(response *ListFleetResponse, params *ListFleetP close(errorChannel) } -func (c *ApiService) getNextListFleetResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListFleetResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -355,6 +377,9 @@ func (params *UpdateFleetParams) SetDataLimit(DataLimit int) *UpdateFleetParams // Updates the given properties of a Super SIM Fleet instance from your account. func (c *ApiService) UpdateFleet(Sid string, params *UpdateFleetParams) (*SupersimV1Fleet, error) { + return c.UpdateFleetWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateFleetWithContext(ctx context.Context, Sid string, params *UpdateFleetParams) (*SupersimV1Fleet, error) { path := "/v1/Fleets/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -385,7 +410,7 @@ func (c *ApiService) UpdateFleet(Sid string, params *UpdateFleetParams) (*Supers data.Set("DataLimit", fmt.Sprint(*params.DataLimit)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/supersim/v1/ip_commands.go b/rest/supersim/v1/ip_commands.go index d05aa497b..716c463c3 100644 --- a/rest/supersim/v1/ip_commands.go +++ b/rest/supersim/v1/ip_commands.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -66,6 +67,9 @@ func (params *CreateIpCommandParams) SetCallbackMethod(CallbackMethod string) *C // Send an IP Command to a Super SIM. func (c *ApiService) CreateIpCommand(params *CreateIpCommandParams) (*SupersimV1IpCommand, error) { + return c.CreateIpCommandWithContext(context.TODO(), params) +} +func (c *ApiService) CreateIpCommandWithContext(ctx context.Context, params *CreateIpCommandParams) (*SupersimV1IpCommand, error) { path := "/v1/IpCommands" data := url.Values{} @@ -92,7 +96,7 @@ func (c *ApiService) CreateIpCommand(params *CreateIpCommandParams) (*SupersimV1 data.Set("CallbackMethod", *params.CallbackMethod) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -109,6 +113,9 @@ func (c *ApiService) CreateIpCommand(params *CreateIpCommandParams) (*SupersimV1 // Fetch IP Command instance from your account. func (c *ApiService) FetchIpCommand(Sid string) (*SupersimV1IpCommand, error) { + return c.FetchIpCommandWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchIpCommandWithContext(ctx context.Context, Sid string) (*SupersimV1IpCommand, error) { path := "/v1/IpCommands/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -117,7 +124,7 @@ func (c *ApiService) FetchIpCommand(Sid string) (*SupersimV1IpCommand, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -175,6 +182,11 @@ func (params *ListIpCommandParams) SetLimit(Limit int) *ListIpCommandParams { // Retrieve a single page of IpCommand records from the API. Request is executed immediately. func (c *ApiService) PageIpCommand(params *ListIpCommandParams, pageToken, pageNumber string) (*ListIpCommandResponse, error) { + return c.PageIpCommandWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of IpCommand records from the API. Request is executed immediately. +func (c *ApiService) PageIpCommandWithContext(ctx context.Context, params *ListIpCommandParams, pageToken, pageNumber string) (*ListIpCommandResponse, error) { path := "/v1/IpCommands" data := url.Values{} @@ -205,7 +217,7 @@ func (c *ApiService) PageIpCommand(params *ListIpCommandParams, pageToken, pageN data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -222,7 +234,12 @@ func (c *ApiService) PageIpCommand(params *ListIpCommandParams, pageToken, pageN // Lists IpCommand records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListIpCommand(params *ListIpCommandParams) ([]SupersimV1IpCommand, error) { - response, errors := c.StreamIpCommand(params) + return c.ListIpCommandWithContext(context.TODO(), params) +} + +// Lists IpCommand records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListIpCommandWithContext(ctx context.Context, params *ListIpCommandParams) ([]SupersimV1IpCommand, error) { + response, errors := c.StreamIpCommandWithContext(ctx, params) records := make([]SupersimV1IpCommand, 0) for record := range response { @@ -238,6 +255,11 @@ func (c *ApiService) ListIpCommand(params *ListIpCommandParams) ([]SupersimV1IpC // Streams IpCommand records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamIpCommand(params *ListIpCommandParams) (chan SupersimV1IpCommand, chan error) { + return c.StreamIpCommandWithContext(context.TODO(), params) +} + +// Streams IpCommand records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamIpCommandWithContext(ctx context.Context, params *ListIpCommandParams) (chan SupersimV1IpCommand, chan error) { if params == nil { params = &ListIpCommandParams{} } @@ -246,19 +268,19 @@ func (c *ApiService) StreamIpCommand(params *ListIpCommandParams) (chan Supersim recordChannel := make(chan SupersimV1IpCommand, 1) errorChannel := make(chan error, 1) - response, err := c.PageIpCommand(params, "", "") + response, err := c.PageIpCommandWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamIpCommand(response, params, recordChannel, errorChannel) + go c.streamIpCommandWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamIpCommand(response *ListIpCommandResponse, params *ListIpCommandParams, recordChannel chan SupersimV1IpCommand, errorChannel chan error) { +func (c *ApiService) streamIpCommandWithContext(ctx context.Context, response *ListIpCommandResponse, params *ListIpCommandParams, recordChannel chan SupersimV1IpCommand, errorChannel chan error) { curRecord := 1 for response != nil { @@ -273,7 +295,7 @@ func (c *ApiService) streamIpCommand(response *ListIpCommandResponse, params *Li } } - record, err := client.GetNext(c.baseURL, response, c.getNextListIpCommandResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListIpCommandResponseWithContext) if err != nil { errorChannel <- err break @@ -288,11 +310,11 @@ func (c *ApiService) streamIpCommand(response *ListIpCommandResponse, params *Li close(errorChannel) } -func (c *ApiService) getNextListIpCommandResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListIpCommandResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/supersim/v1/network_access_profiles.go b/rest/supersim/v1/network_access_profiles.go index 245af52ec..ea67dadb2 100644 --- a/rest/supersim/v1/network_access_profiles.go +++ b/rest/supersim/v1/network_access_profiles.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -42,6 +43,9 @@ func (params *CreateNetworkAccessProfileParams) SetNetworks(Networks []string) * // Create a new Network Access Profile func (c *ApiService) CreateNetworkAccessProfile(params *CreateNetworkAccessProfileParams) (*SupersimV1NetworkAccessProfile, error) { + return c.CreateNetworkAccessProfileWithContext(context.TODO(), params) +} +func (c *ApiService) CreateNetworkAccessProfileWithContext(ctx context.Context, params *CreateNetworkAccessProfileParams) (*SupersimV1NetworkAccessProfile, error) { path := "/v1/NetworkAccessProfiles" data := url.Values{} @@ -58,7 +62,7 @@ func (c *ApiService) CreateNetworkAccessProfile(params *CreateNetworkAccessProfi } } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -75,6 +79,9 @@ func (c *ApiService) CreateNetworkAccessProfile(params *CreateNetworkAccessProfi // Fetch a Network Access Profile instance from your account. func (c *ApiService) FetchNetworkAccessProfile(Sid string) (*SupersimV1NetworkAccessProfile, error) { + return c.FetchNetworkAccessProfileWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchNetworkAccessProfileWithContext(ctx context.Context, Sid string) (*SupersimV1NetworkAccessProfile, error) { path := "/v1/NetworkAccessProfiles/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -83,7 +90,7 @@ func (c *ApiService) FetchNetworkAccessProfile(Sid string) (*SupersimV1NetworkAc "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -117,6 +124,11 @@ func (params *ListNetworkAccessProfileParams) SetLimit(Limit int) *ListNetworkAc // Retrieve a single page of NetworkAccessProfile records from the API. Request is executed immediately. func (c *ApiService) PageNetworkAccessProfile(params *ListNetworkAccessProfileParams, pageToken, pageNumber string) (*ListNetworkAccessProfileResponse, error) { + return c.PageNetworkAccessProfileWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of NetworkAccessProfile records from the API. Request is executed immediately. +func (c *ApiService) PageNetworkAccessProfileWithContext(ctx context.Context, params *ListNetworkAccessProfileParams, pageToken, pageNumber string) (*ListNetworkAccessProfileResponse, error) { path := "/v1/NetworkAccessProfiles" data := url.Values{} @@ -135,7 +147,7 @@ func (c *ApiService) PageNetworkAccessProfile(params *ListNetworkAccessProfilePa data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -152,7 +164,12 @@ func (c *ApiService) PageNetworkAccessProfile(params *ListNetworkAccessProfilePa // Lists NetworkAccessProfile records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListNetworkAccessProfile(params *ListNetworkAccessProfileParams) ([]SupersimV1NetworkAccessProfile, error) { - response, errors := c.StreamNetworkAccessProfile(params) + return c.ListNetworkAccessProfileWithContext(context.TODO(), params) +} + +// Lists NetworkAccessProfile records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListNetworkAccessProfileWithContext(ctx context.Context, params *ListNetworkAccessProfileParams) ([]SupersimV1NetworkAccessProfile, error) { + response, errors := c.StreamNetworkAccessProfileWithContext(ctx, params) records := make([]SupersimV1NetworkAccessProfile, 0) for record := range response { @@ -168,6 +185,11 @@ func (c *ApiService) ListNetworkAccessProfile(params *ListNetworkAccessProfilePa // Streams NetworkAccessProfile records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamNetworkAccessProfile(params *ListNetworkAccessProfileParams) (chan SupersimV1NetworkAccessProfile, chan error) { + return c.StreamNetworkAccessProfileWithContext(context.TODO(), params) +} + +// Streams NetworkAccessProfile records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamNetworkAccessProfileWithContext(ctx context.Context, params *ListNetworkAccessProfileParams) (chan SupersimV1NetworkAccessProfile, chan error) { if params == nil { params = &ListNetworkAccessProfileParams{} } @@ -176,19 +198,19 @@ func (c *ApiService) StreamNetworkAccessProfile(params *ListNetworkAccessProfile recordChannel := make(chan SupersimV1NetworkAccessProfile, 1) errorChannel := make(chan error, 1) - response, err := c.PageNetworkAccessProfile(params, "", "") + response, err := c.PageNetworkAccessProfileWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamNetworkAccessProfile(response, params, recordChannel, errorChannel) + go c.streamNetworkAccessProfileWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamNetworkAccessProfile(response *ListNetworkAccessProfileResponse, params *ListNetworkAccessProfileParams, recordChannel chan SupersimV1NetworkAccessProfile, errorChannel chan error) { +func (c *ApiService) streamNetworkAccessProfileWithContext(ctx context.Context, response *ListNetworkAccessProfileResponse, params *ListNetworkAccessProfileParams, recordChannel chan SupersimV1NetworkAccessProfile, errorChannel chan error) { curRecord := 1 for response != nil { @@ -203,7 +225,7 @@ func (c *ApiService) streamNetworkAccessProfile(response *ListNetworkAccessProfi } } - record, err := client.GetNext(c.baseURL, response, c.getNextListNetworkAccessProfileResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListNetworkAccessProfileResponseWithContext) if err != nil { errorChannel <- err break @@ -218,11 +240,11 @@ func (c *ApiService) streamNetworkAccessProfile(response *ListNetworkAccessProfi close(errorChannel) } -func (c *ApiService) getNextListNetworkAccessProfileResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListNetworkAccessProfileResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -249,6 +271,9 @@ func (params *UpdateNetworkAccessProfileParams) SetUniqueName(UniqueName string) // Updates the given properties of a Network Access Profile in your account. func (c *ApiService) UpdateNetworkAccessProfile(Sid string, params *UpdateNetworkAccessProfileParams) (*SupersimV1NetworkAccessProfile, error) { + return c.UpdateNetworkAccessProfileWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateNetworkAccessProfileWithContext(ctx context.Context, Sid string, params *UpdateNetworkAccessProfileParams) (*SupersimV1NetworkAccessProfile, error) { path := "/v1/NetworkAccessProfiles/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -261,7 +286,7 @@ func (c *ApiService) UpdateNetworkAccessProfile(Sid string, params *UpdateNetwor data.Set("UniqueName", *params.UniqueName) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/supersim/v1/network_access_profiles_networks.go b/rest/supersim/v1/network_access_profiles_networks.go index b79c2d583..89e2422b8 100644 --- a/rest/supersim/v1/network_access_profiles_networks.go +++ b/rest/supersim/v1/network_access_profiles_networks.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -36,6 +37,9 @@ func (params *CreateNetworkAccessProfileNetworkParams) SetNetwork(Network string // Add a Network resource to the Network Access Profile resource. func (c *ApiService) CreateNetworkAccessProfileNetwork(NetworkAccessProfileSid string, params *CreateNetworkAccessProfileNetworkParams) (*SupersimV1NetworkAccessProfileNetwork, error) { + return c.CreateNetworkAccessProfileNetworkWithContext(context.TODO(), NetworkAccessProfileSid, params) +} +func (c *ApiService) CreateNetworkAccessProfileNetworkWithContext(ctx context.Context, NetworkAccessProfileSid string, params *CreateNetworkAccessProfileNetworkParams) (*SupersimV1NetworkAccessProfileNetwork, error) { path := "/v1/NetworkAccessProfiles/{NetworkAccessProfileSid}/Networks" path = strings.Replace(path, "{"+"NetworkAccessProfileSid"+"}", NetworkAccessProfileSid, -1) @@ -48,7 +52,7 @@ func (c *ApiService) CreateNetworkAccessProfileNetwork(NetworkAccessProfileSid s data.Set("Network", *params.Network) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -65,6 +69,9 @@ func (c *ApiService) CreateNetworkAccessProfileNetwork(NetworkAccessProfileSid s // Remove a Network resource from the Network Access Profile resource's. func (c *ApiService) DeleteNetworkAccessProfileNetwork(NetworkAccessProfileSid string, Sid string) error { + return c.DeleteNetworkAccessProfileNetworkWithContext(context.TODO(), NetworkAccessProfileSid, Sid) +} +func (c *ApiService) DeleteNetworkAccessProfileNetworkWithContext(ctx context.Context, NetworkAccessProfileSid string, Sid string) error { path := "/v1/NetworkAccessProfiles/{NetworkAccessProfileSid}/Networks/{Sid}" path = strings.Replace(path, "{"+"NetworkAccessProfileSid"+"}", NetworkAccessProfileSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -74,7 +81,7 @@ func (c *ApiService) DeleteNetworkAccessProfileNetwork(NetworkAccessProfileSid s "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -86,6 +93,9 @@ func (c *ApiService) DeleteNetworkAccessProfileNetwork(NetworkAccessProfileSid s // Fetch a Network Access Profile resource's Network resource. func (c *ApiService) FetchNetworkAccessProfileNetwork(NetworkAccessProfileSid string, Sid string) (*SupersimV1NetworkAccessProfileNetwork, error) { + return c.FetchNetworkAccessProfileNetworkWithContext(context.TODO(), NetworkAccessProfileSid, Sid) +} +func (c *ApiService) FetchNetworkAccessProfileNetworkWithContext(ctx context.Context, NetworkAccessProfileSid string, Sid string) (*SupersimV1NetworkAccessProfileNetwork, error) { path := "/v1/NetworkAccessProfiles/{NetworkAccessProfileSid}/Networks/{Sid}" path = strings.Replace(path, "{"+"NetworkAccessProfileSid"+"}", NetworkAccessProfileSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -95,7 +105,7 @@ func (c *ApiService) FetchNetworkAccessProfileNetwork(NetworkAccessProfileSid st "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -129,6 +139,11 @@ func (params *ListNetworkAccessProfileNetworkParams) SetLimit(Limit int) *ListNe // Retrieve a single page of NetworkAccessProfileNetwork records from the API. Request is executed immediately. func (c *ApiService) PageNetworkAccessProfileNetwork(NetworkAccessProfileSid string, params *ListNetworkAccessProfileNetworkParams, pageToken, pageNumber string) (*ListNetworkAccessProfileNetworkResponse, error) { + return c.PageNetworkAccessProfileNetworkWithContext(context.TODO(), NetworkAccessProfileSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of NetworkAccessProfileNetwork records from the API. Request is executed immediately. +func (c *ApiService) PageNetworkAccessProfileNetworkWithContext(ctx context.Context, NetworkAccessProfileSid string, params *ListNetworkAccessProfileNetworkParams, pageToken, pageNumber string) (*ListNetworkAccessProfileNetworkResponse, error) { path := "/v1/NetworkAccessProfiles/{NetworkAccessProfileSid}/Networks" path = strings.Replace(path, "{"+"NetworkAccessProfileSid"+"}", NetworkAccessProfileSid, -1) @@ -149,7 +164,7 @@ func (c *ApiService) PageNetworkAccessProfileNetwork(NetworkAccessProfileSid str data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -166,7 +181,12 @@ func (c *ApiService) PageNetworkAccessProfileNetwork(NetworkAccessProfileSid str // Lists NetworkAccessProfileNetwork records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListNetworkAccessProfileNetwork(NetworkAccessProfileSid string, params *ListNetworkAccessProfileNetworkParams) ([]SupersimV1NetworkAccessProfileNetwork, error) { - response, errors := c.StreamNetworkAccessProfileNetwork(NetworkAccessProfileSid, params) + return c.ListNetworkAccessProfileNetworkWithContext(context.TODO(), NetworkAccessProfileSid, params) +} + +// Lists NetworkAccessProfileNetwork records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListNetworkAccessProfileNetworkWithContext(ctx context.Context, NetworkAccessProfileSid string, params *ListNetworkAccessProfileNetworkParams) ([]SupersimV1NetworkAccessProfileNetwork, error) { + response, errors := c.StreamNetworkAccessProfileNetworkWithContext(ctx, NetworkAccessProfileSid, params) records := make([]SupersimV1NetworkAccessProfileNetwork, 0) for record := range response { @@ -182,6 +202,11 @@ func (c *ApiService) ListNetworkAccessProfileNetwork(NetworkAccessProfileSid str // Streams NetworkAccessProfileNetwork records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamNetworkAccessProfileNetwork(NetworkAccessProfileSid string, params *ListNetworkAccessProfileNetworkParams) (chan SupersimV1NetworkAccessProfileNetwork, chan error) { + return c.StreamNetworkAccessProfileNetworkWithContext(context.TODO(), NetworkAccessProfileSid, params) +} + +// Streams NetworkAccessProfileNetwork records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamNetworkAccessProfileNetworkWithContext(ctx context.Context, NetworkAccessProfileSid string, params *ListNetworkAccessProfileNetworkParams) (chan SupersimV1NetworkAccessProfileNetwork, chan error) { if params == nil { params = &ListNetworkAccessProfileNetworkParams{} } @@ -190,19 +215,19 @@ func (c *ApiService) StreamNetworkAccessProfileNetwork(NetworkAccessProfileSid s recordChannel := make(chan SupersimV1NetworkAccessProfileNetwork, 1) errorChannel := make(chan error, 1) - response, err := c.PageNetworkAccessProfileNetwork(NetworkAccessProfileSid, params, "", "") + response, err := c.PageNetworkAccessProfileNetworkWithContext(ctx, NetworkAccessProfileSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamNetworkAccessProfileNetwork(response, params, recordChannel, errorChannel) + go c.streamNetworkAccessProfileNetworkWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamNetworkAccessProfileNetwork(response *ListNetworkAccessProfileNetworkResponse, params *ListNetworkAccessProfileNetworkParams, recordChannel chan SupersimV1NetworkAccessProfileNetwork, errorChannel chan error) { +func (c *ApiService) streamNetworkAccessProfileNetworkWithContext(ctx context.Context, response *ListNetworkAccessProfileNetworkResponse, params *ListNetworkAccessProfileNetworkParams, recordChannel chan SupersimV1NetworkAccessProfileNetwork, errorChannel chan error) { curRecord := 1 for response != nil { @@ -217,7 +242,7 @@ func (c *ApiService) streamNetworkAccessProfileNetwork(response *ListNetworkAcce } } - record, err := client.GetNext(c.baseURL, response, c.getNextListNetworkAccessProfileNetworkResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListNetworkAccessProfileNetworkResponseWithContext) if err != nil { errorChannel <- err break @@ -232,11 +257,11 @@ func (c *ApiService) streamNetworkAccessProfileNetwork(response *ListNetworkAcce close(errorChannel) } -func (c *ApiService) getNextListNetworkAccessProfileNetworkResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListNetworkAccessProfileNetworkResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/supersim/v1/networks.go b/rest/supersim/v1/networks.go index 84db1d32c..127c2a42e 100644 --- a/rest/supersim/v1/networks.go +++ b/rest/supersim/v1/networks.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -25,6 +26,9 @@ import ( // Fetch a Network resource. func (c *ApiService) FetchNetwork(Sid string) (*SupersimV1Network, error) { + return c.FetchNetworkWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchNetworkWithContext(ctx context.Context, Sid string) (*SupersimV1Network, error) { path := "/v1/Networks/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -33,7 +37,7 @@ func (c *ApiService) FetchNetwork(Sid string) (*SupersimV1Network, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -85,6 +89,11 @@ func (params *ListNetworkParams) SetLimit(Limit int) *ListNetworkParams { // Retrieve a single page of Network records from the API. Request is executed immediately. func (c *ApiService) PageNetwork(params *ListNetworkParams, pageToken, pageNumber string) (*ListNetworkResponse, error) { + return c.PageNetworkWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Network records from the API. Request is executed immediately. +func (c *ApiService) PageNetworkWithContext(ctx context.Context, params *ListNetworkParams, pageToken, pageNumber string) (*ListNetworkResponse, error) { path := "/v1/Networks" data := url.Values{} @@ -112,7 +121,7 @@ func (c *ApiService) PageNetwork(params *ListNetworkParams, pageToken, pageNumbe data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -129,7 +138,12 @@ func (c *ApiService) PageNetwork(params *ListNetworkParams, pageToken, pageNumbe // Lists Network records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListNetwork(params *ListNetworkParams) ([]SupersimV1Network, error) { - response, errors := c.StreamNetwork(params) + return c.ListNetworkWithContext(context.TODO(), params) +} + +// Lists Network records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListNetworkWithContext(ctx context.Context, params *ListNetworkParams) ([]SupersimV1Network, error) { + response, errors := c.StreamNetworkWithContext(ctx, params) records := make([]SupersimV1Network, 0) for record := range response { @@ -145,6 +159,11 @@ func (c *ApiService) ListNetwork(params *ListNetworkParams) ([]SupersimV1Network // Streams Network records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamNetwork(params *ListNetworkParams) (chan SupersimV1Network, chan error) { + return c.StreamNetworkWithContext(context.TODO(), params) +} + +// Streams Network records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamNetworkWithContext(ctx context.Context, params *ListNetworkParams) (chan SupersimV1Network, chan error) { if params == nil { params = &ListNetworkParams{} } @@ -153,19 +172,19 @@ func (c *ApiService) StreamNetwork(params *ListNetworkParams) (chan SupersimV1Ne recordChannel := make(chan SupersimV1Network, 1) errorChannel := make(chan error, 1) - response, err := c.PageNetwork(params, "", "") + response, err := c.PageNetworkWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamNetwork(response, params, recordChannel, errorChannel) + go c.streamNetworkWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamNetwork(response *ListNetworkResponse, params *ListNetworkParams, recordChannel chan SupersimV1Network, errorChannel chan error) { +func (c *ApiService) streamNetworkWithContext(ctx context.Context, response *ListNetworkResponse, params *ListNetworkParams, recordChannel chan SupersimV1Network, errorChannel chan error) { curRecord := 1 for response != nil { @@ -180,7 +199,7 @@ func (c *ApiService) streamNetwork(response *ListNetworkResponse, params *ListNe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListNetworkResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListNetworkResponseWithContext) if err != nil { errorChannel <- err break @@ -195,11 +214,11 @@ func (c *ApiService) streamNetwork(response *ListNetworkResponse, params *ListNe close(errorChannel) } -func (c *ApiService) getNextListNetworkResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListNetworkResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/supersim/v1/settings_updates.go b/rest/supersim/v1/settings_updates.go index 3c3c0622c..d8eb55260 100644 --- a/rest/supersim/v1/settings_updates.go +++ b/rest/supersim/v1/settings_updates.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -53,6 +54,11 @@ func (params *ListSettingsUpdateParams) SetLimit(Limit int) *ListSettingsUpdateP // Retrieve a single page of SettingsUpdate records from the API. Request is executed immediately. func (c *ApiService) PageSettingsUpdate(params *ListSettingsUpdateParams, pageToken, pageNumber string) (*ListSettingsUpdateResponse, error) { + return c.PageSettingsUpdateWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of SettingsUpdate records from the API. Request is executed immediately. +func (c *ApiService) PageSettingsUpdateWithContext(ctx context.Context, params *ListSettingsUpdateParams, pageToken, pageNumber string) (*ListSettingsUpdateResponse, error) { path := "/v1/SettingsUpdates" data := url.Values{} @@ -77,7 +83,7 @@ func (c *ApiService) PageSettingsUpdate(params *ListSettingsUpdateParams, pageTo data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -94,7 +100,12 @@ func (c *ApiService) PageSettingsUpdate(params *ListSettingsUpdateParams, pageTo // Lists SettingsUpdate records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListSettingsUpdate(params *ListSettingsUpdateParams) ([]SupersimV1SettingsUpdate, error) { - response, errors := c.StreamSettingsUpdate(params) + return c.ListSettingsUpdateWithContext(context.TODO(), params) +} + +// Lists SettingsUpdate records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListSettingsUpdateWithContext(ctx context.Context, params *ListSettingsUpdateParams) ([]SupersimV1SettingsUpdate, error) { + response, errors := c.StreamSettingsUpdateWithContext(ctx, params) records := make([]SupersimV1SettingsUpdate, 0) for record := range response { @@ -110,6 +121,11 @@ func (c *ApiService) ListSettingsUpdate(params *ListSettingsUpdateParams) ([]Sup // Streams SettingsUpdate records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamSettingsUpdate(params *ListSettingsUpdateParams) (chan SupersimV1SettingsUpdate, chan error) { + return c.StreamSettingsUpdateWithContext(context.TODO(), params) +} + +// Streams SettingsUpdate records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamSettingsUpdateWithContext(ctx context.Context, params *ListSettingsUpdateParams) (chan SupersimV1SettingsUpdate, chan error) { if params == nil { params = &ListSettingsUpdateParams{} } @@ -118,19 +134,19 @@ func (c *ApiService) StreamSettingsUpdate(params *ListSettingsUpdateParams) (cha recordChannel := make(chan SupersimV1SettingsUpdate, 1) errorChannel := make(chan error, 1) - response, err := c.PageSettingsUpdate(params, "", "") + response, err := c.PageSettingsUpdateWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSettingsUpdate(response, params, recordChannel, errorChannel) + go c.streamSettingsUpdateWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamSettingsUpdate(response *ListSettingsUpdateResponse, params *ListSettingsUpdateParams, recordChannel chan SupersimV1SettingsUpdate, errorChannel chan error) { +func (c *ApiService) streamSettingsUpdateWithContext(ctx context.Context, response *ListSettingsUpdateResponse, params *ListSettingsUpdateParams, recordChannel chan SupersimV1SettingsUpdate, errorChannel chan error) { curRecord := 1 for response != nil { @@ -145,7 +161,7 @@ func (c *ApiService) streamSettingsUpdate(response *ListSettingsUpdateResponse, } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSettingsUpdateResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListSettingsUpdateResponseWithContext) if err != nil { errorChannel <- err break @@ -160,11 +176,11 @@ func (c *ApiService) streamSettingsUpdate(response *ListSettingsUpdateResponse, close(errorChannel) } -func (c *ApiService) getNextListSettingsUpdateResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSettingsUpdateResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/supersim/v1/sims.go b/rest/supersim/v1/sims.go index 3750c3733..a2aa01c44 100644 --- a/rest/supersim/v1/sims.go +++ b/rest/supersim/v1/sims.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -42,6 +43,9 @@ func (params *CreateSimParams) SetRegistrationCode(RegistrationCode string) *Cre // Register a Super SIM to your Account func (c *ApiService) CreateSim(params *CreateSimParams) (*SupersimV1Sim, error) { + return c.CreateSimWithContext(context.TODO(), params) +} +func (c *ApiService) CreateSimWithContext(ctx context.Context, params *CreateSimParams) (*SupersimV1Sim, error) { path := "/v1/Sims" data := url.Values{} @@ -56,7 +60,7 @@ func (c *ApiService) CreateSim(params *CreateSimParams) (*SupersimV1Sim, error) data.Set("RegistrationCode", *params.RegistrationCode) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -73,6 +77,9 @@ func (c *ApiService) CreateSim(params *CreateSimParams) (*SupersimV1Sim, error) // Fetch a Super SIM instance from your account. func (c *ApiService) FetchSim(Sid string) (*SupersimV1Sim, error) { + return c.FetchSimWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchSimWithContext(ctx context.Context, Sid string) (*SupersimV1Sim, error) { path := "/v1/Sims/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -81,7 +88,7 @@ func (c *ApiService) FetchSim(Sid string) (*SupersimV1Sim, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -133,6 +140,11 @@ func (params *ListSimParams) SetLimit(Limit int) *ListSimParams { // Retrieve a single page of Sim records from the API. Request is executed immediately. func (c *ApiService) PageSim(params *ListSimParams, pageToken, pageNumber string) (*ListSimResponse, error) { + return c.PageSimWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Sim records from the API. Request is executed immediately. +func (c *ApiService) PageSimWithContext(ctx context.Context, params *ListSimParams, pageToken, pageNumber string) (*ListSimResponse, error) { path := "/v1/Sims" data := url.Values{} @@ -160,7 +172,7 @@ func (c *ApiService) PageSim(params *ListSimParams, pageToken, pageNumber string data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -177,7 +189,12 @@ func (c *ApiService) PageSim(params *ListSimParams, pageToken, pageNumber string // Lists Sim records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListSim(params *ListSimParams) ([]SupersimV1Sim, error) { - response, errors := c.StreamSim(params) + return c.ListSimWithContext(context.TODO(), params) +} + +// Lists Sim records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListSimWithContext(ctx context.Context, params *ListSimParams) ([]SupersimV1Sim, error) { + response, errors := c.StreamSimWithContext(ctx, params) records := make([]SupersimV1Sim, 0) for record := range response { @@ -193,6 +210,11 @@ func (c *ApiService) ListSim(params *ListSimParams) ([]SupersimV1Sim, error) { // Streams Sim records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamSim(params *ListSimParams) (chan SupersimV1Sim, chan error) { + return c.StreamSimWithContext(context.TODO(), params) +} + +// Streams Sim records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamSimWithContext(ctx context.Context, params *ListSimParams) (chan SupersimV1Sim, chan error) { if params == nil { params = &ListSimParams{} } @@ -201,19 +223,19 @@ func (c *ApiService) StreamSim(params *ListSimParams) (chan SupersimV1Sim, chan recordChannel := make(chan SupersimV1Sim, 1) errorChannel := make(chan error, 1) - response, err := c.PageSim(params, "", "") + response, err := c.PageSimWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSim(response, params, recordChannel, errorChannel) + go c.streamSimWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamSim(response *ListSimResponse, params *ListSimParams, recordChannel chan SupersimV1Sim, errorChannel chan error) { +func (c *ApiService) streamSimWithContext(ctx context.Context, response *ListSimResponse, params *ListSimParams, recordChannel chan SupersimV1Sim, errorChannel chan error) { curRecord := 1 for response != nil { @@ -228,7 +250,7 @@ func (c *ApiService) streamSim(response *ListSimResponse, params *ListSimParams, } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSimResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListSimResponseWithContext) if err != nil { errorChannel <- err break @@ -243,11 +265,11 @@ func (c *ApiService) streamSim(response *ListSimResponse, params *ListSimParams, close(errorChannel) } -func (c *ApiService) getNextListSimResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSimResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -304,6 +326,9 @@ func (params *UpdateSimParams) SetAccountSid(AccountSid string) *UpdateSimParams // Updates the given properties of a Super SIM instance from your account. func (c *ApiService) UpdateSim(Sid string, params *UpdateSimParams) (*SupersimV1Sim, error) { + return c.UpdateSimWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateSimWithContext(ctx context.Context, Sid string, params *UpdateSimParams) (*SupersimV1Sim, error) { path := "/v1/Sims/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -331,7 +356,7 @@ func (c *ApiService) UpdateSim(Sid string, params *UpdateSimParams) (*SupersimV1 data.Set("AccountSid", *params.AccountSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/supersim/v1/sims_billing_periods.go b/rest/supersim/v1/sims_billing_periods.go index 727e8bbdd..3a008d9b4 100644 --- a/rest/supersim/v1/sims_billing_periods.go +++ b/rest/supersim/v1/sims_billing_periods.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -42,6 +43,11 @@ func (params *ListBillingPeriodParams) SetLimit(Limit int) *ListBillingPeriodPar // Retrieve a single page of BillingPeriod records from the API. Request is executed immediately. func (c *ApiService) PageBillingPeriod(SimSid string, params *ListBillingPeriodParams, pageToken, pageNumber string) (*ListBillingPeriodResponse, error) { + return c.PageBillingPeriodWithContext(context.TODO(), SimSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of BillingPeriod records from the API. Request is executed immediately. +func (c *ApiService) PageBillingPeriodWithContext(ctx context.Context, SimSid string, params *ListBillingPeriodParams, pageToken, pageNumber string) (*ListBillingPeriodResponse, error) { path := "/v1/Sims/{SimSid}/BillingPeriods" path = strings.Replace(path, "{"+"SimSid"+"}", SimSid, -1) @@ -62,7 +68,7 @@ func (c *ApiService) PageBillingPeriod(SimSid string, params *ListBillingPeriodP data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -79,7 +85,12 @@ func (c *ApiService) PageBillingPeriod(SimSid string, params *ListBillingPeriodP // Lists BillingPeriod records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListBillingPeriod(SimSid string, params *ListBillingPeriodParams) ([]SupersimV1BillingPeriod, error) { - response, errors := c.StreamBillingPeriod(SimSid, params) + return c.ListBillingPeriodWithContext(context.TODO(), SimSid, params) +} + +// Lists BillingPeriod records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListBillingPeriodWithContext(ctx context.Context, SimSid string, params *ListBillingPeriodParams) ([]SupersimV1BillingPeriod, error) { + response, errors := c.StreamBillingPeriodWithContext(ctx, SimSid, params) records := make([]SupersimV1BillingPeriod, 0) for record := range response { @@ -95,6 +106,11 @@ func (c *ApiService) ListBillingPeriod(SimSid string, params *ListBillingPeriodP // Streams BillingPeriod records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamBillingPeriod(SimSid string, params *ListBillingPeriodParams) (chan SupersimV1BillingPeriod, chan error) { + return c.StreamBillingPeriodWithContext(context.TODO(), SimSid, params) +} + +// Streams BillingPeriod records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamBillingPeriodWithContext(ctx context.Context, SimSid string, params *ListBillingPeriodParams) (chan SupersimV1BillingPeriod, chan error) { if params == nil { params = &ListBillingPeriodParams{} } @@ -103,19 +119,19 @@ func (c *ApiService) StreamBillingPeriod(SimSid string, params *ListBillingPerio recordChannel := make(chan SupersimV1BillingPeriod, 1) errorChannel := make(chan error, 1) - response, err := c.PageBillingPeriod(SimSid, params, "", "") + response, err := c.PageBillingPeriodWithContext(ctx, SimSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamBillingPeriod(response, params, recordChannel, errorChannel) + go c.streamBillingPeriodWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamBillingPeriod(response *ListBillingPeriodResponse, params *ListBillingPeriodParams, recordChannel chan SupersimV1BillingPeriod, errorChannel chan error) { +func (c *ApiService) streamBillingPeriodWithContext(ctx context.Context, response *ListBillingPeriodResponse, params *ListBillingPeriodParams, recordChannel chan SupersimV1BillingPeriod, errorChannel chan error) { curRecord := 1 for response != nil { @@ -130,7 +146,7 @@ func (c *ApiService) streamBillingPeriod(response *ListBillingPeriodResponse, pa } } - record, err := client.GetNext(c.baseURL, response, c.getNextListBillingPeriodResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListBillingPeriodResponseWithContext) if err != nil { errorChannel <- err break @@ -145,11 +161,11 @@ func (c *ApiService) streamBillingPeriod(response *ListBillingPeriodResponse, pa close(errorChannel) } -func (c *ApiService) getNextListBillingPeriodResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListBillingPeriodResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/supersim/v1/sims_ip_addresses.go b/rest/supersim/v1/sims_ip_addresses.go index 0c3793923..2edc8efcb 100644 --- a/rest/supersim/v1/sims_ip_addresses.go +++ b/rest/supersim/v1/sims_ip_addresses.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -42,6 +43,11 @@ func (params *ListSimIpAddressParams) SetLimit(Limit int) *ListSimIpAddressParam // Retrieve a single page of SimIpAddress records from the API. Request is executed immediately. func (c *ApiService) PageSimIpAddress(SimSid string, params *ListSimIpAddressParams, pageToken, pageNumber string) (*ListSimIpAddressResponse, error) { + return c.PageSimIpAddressWithContext(context.TODO(), SimSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of SimIpAddress records from the API. Request is executed immediately. +func (c *ApiService) PageSimIpAddressWithContext(ctx context.Context, SimSid string, params *ListSimIpAddressParams, pageToken, pageNumber string) (*ListSimIpAddressResponse, error) { path := "/v1/Sims/{SimSid}/IpAddresses" path = strings.Replace(path, "{"+"SimSid"+"}", SimSid, -1) @@ -62,7 +68,7 @@ func (c *ApiService) PageSimIpAddress(SimSid string, params *ListSimIpAddressPar data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -79,7 +85,12 @@ func (c *ApiService) PageSimIpAddress(SimSid string, params *ListSimIpAddressPar // Lists SimIpAddress records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListSimIpAddress(SimSid string, params *ListSimIpAddressParams) ([]SupersimV1SimIpAddress, error) { - response, errors := c.StreamSimIpAddress(SimSid, params) + return c.ListSimIpAddressWithContext(context.TODO(), SimSid, params) +} + +// Lists SimIpAddress records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListSimIpAddressWithContext(ctx context.Context, SimSid string, params *ListSimIpAddressParams) ([]SupersimV1SimIpAddress, error) { + response, errors := c.StreamSimIpAddressWithContext(ctx, SimSid, params) records := make([]SupersimV1SimIpAddress, 0) for record := range response { @@ -95,6 +106,11 @@ func (c *ApiService) ListSimIpAddress(SimSid string, params *ListSimIpAddressPar // Streams SimIpAddress records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamSimIpAddress(SimSid string, params *ListSimIpAddressParams) (chan SupersimV1SimIpAddress, chan error) { + return c.StreamSimIpAddressWithContext(context.TODO(), SimSid, params) +} + +// Streams SimIpAddress records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamSimIpAddressWithContext(ctx context.Context, SimSid string, params *ListSimIpAddressParams) (chan SupersimV1SimIpAddress, chan error) { if params == nil { params = &ListSimIpAddressParams{} } @@ -103,19 +119,19 @@ func (c *ApiService) StreamSimIpAddress(SimSid string, params *ListSimIpAddressP recordChannel := make(chan SupersimV1SimIpAddress, 1) errorChannel := make(chan error, 1) - response, err := c.PageSimIpAddress(SimSid, params, "", "") + response, err := c.PageSimIpAddressWithContext(ctx, SimSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSimIpAddress(response, params, recordChannel, errorChannel) + go c.streamSimIpAddressWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamSimIpAddress(response *ListSimIpAddressResponse, params *ListSimIpAddressParams, recordChannel chan SupersimV1SimIpAddress, errorChannel chan error) { +func (c *ApiService) streamSimIpAddressWithContext(ctx context.Context, response *ListSimIpAddressResponse, params *ListSimIpAddressParams, recordChannel chan SupersimV1SimIpAddress, errorChannel chan error) { curRecord := 1 for response != nil { @@ -130,7 +146,7 @@ func (c *ApiService) streamSimIpAddress(response *ListSimIpAddressResponse, para } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSimIpAddressResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListSimIpAddressResponseWithContext) if err != nil { errorChannel <- err break @@ -145,11 +161,11 @@ func (c *ApiService) streamSimIpAddress(response *ListSimIpAddressResponse, para close(errorChannel) } -func (c *ApiService) getNextListSimIpAddressResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSimIpAddressResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/supersim/v1/sms_commands.go b/rest/supersim/v1/sms_commands.go index 9a8389338..8c78bf0fb 100644 --- a/rest/supersim/v1/sms_commands.go +++ b/rest/supersim/v1/sms_commands.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -54,6 +55,9 @@ func (params *CreateSmsCommandParams) SetCallbackUrl(CallbackUrl string) *Create // Send SMS Command to a Sim. func (c *ApiService) CreateSmsCommand(params *CreateSmsCommandParams) (*SupersimV1SmsCommand, error) { + return c.CreateSmsCommandWithContext(context.TODO(), params) +} +func (c *ApiService) CreateSmsCommandWithContext(ctx context.Context, params *CreateSmsCommandParams) (*SupersimV1SmsCommand, error) { path := "/v1/SmsCommands" data := url.Values{} @@ -74,7 +78,7 @@ func (c *ApiService) CreateSmsCommand(params *CreateSmsCommandParams) (*Supersim data.Set("CallbackUrl", *params.CallbackUrl) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -91,6 +95,9 @@ func (c *ApiService) CreateSmsCommand(params *CreateSmsCommandParams) (*Supersim // Fetch SMS Command instance from your account. func (c *ApiService) FetchSmsCommand(Sid string) (*SupersimV1SmsCommand, error) { + return c.FetchSmsCommandWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchSmsCommandWithContext(ctx context.Context, Sid string) (*SupersimV1SmsCommand, error) { path := "/v1/SmsCommands/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -99,7 +106,7 @@ func (c *ApiService) FetchSmsCommand(Sid string) (*SupersimV1SmsCommand, error) "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -151,6 +158,11 @@ func (params *ListSmsCommandParams) SetLimit(Limit int) *ListSmsCommandParams { // Retrieve a single page of SmsCommand records from the API. Request is executed immediately. func (c *ApiService) PageSmsCommand(params *ListSmsCommandParams, pageToken, pageNumber string) (*ListSmsCommandResponse, error) { + return c.PageSmsCommandWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of SmsCommand records from the API. Request is executed immediately. +func (c *ApiService) PageSmsCommandWithContext(ctx context.Context, params *ListSmsCommandParams, pageToken, pageNumber string) (*ListSmsCommandResponse, error) { path := "/v1/SmsCommands" data := url.Values{} @@ -178,7 +190,7 @@ func (c *ApiService) PageSmsCommand(params *ListSmsCommandParams, pageToken, pag data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -195,7 +207,12 @@ func (c *ApiService) PageSmsCommand(params *ListSmsCommandParams, pageToken, pag // Lists SmsCommand records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListSmsCommand(params *ListSmsCommandParams) ([]SupersimV1SmsCommand, error) { - response, errors := c.StreamSmsCommand(params) + return c.ListSmsCommandWithContext(context.TODO(), params) +} + +// Lists SmsCommand records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListSmsCommandWithContext(ctx context.Context, params *ListSmsCommandParams) ([]SupersimV1SmsCommand, error) { + response, errors := c.StreamSmsCommandWithContext(ctx, params) records := make([]SupersimV1SmsCommand, 0) for record := range response { @@ -211,6 +228,11 @@ func (c *ApiService) ListSmsCommand(params *ListSmsCommandParams) ([]SupersimV1S // Streams SmsCommand records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamSmsCommand(params *ListSmsCommandParams) (chan SupersimV1SmsCommand, chan error) { + return c.StreamSmsCommandWithContext(context.TODO(), params) +} + +// Streams SmsCommand records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamSmsCommandWithContext(ctx context.Context, params *ListSmsCommandParams) (chan SupersimV1SmsCommand, chan error) { if params == nil { params = &ListSmsCommandParams{} } @@ -219,19 +241,19 @@ func (c *ApiService) StreamSmsCommand(params *ListSmsCommandParams) (chan Supers recordChannel := make(chan SupersimV1SmsCommand, 1) errorChannel := make(chan error, 1) - response, err := c.PageSmsCommand(params, "", "") + response, err := c.PageSmsCommandWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSmsCommand(response, params, recordChannel, errorChannel) + go c.streamSmsCommandWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamSmsCommand(response *ListSmsCommandResponse, params *ListSmsCommandParams, recordChannel chan SupersimV1SmsCommand, errorChannel chan error) { +func (c *ApiService) streamSmsCommandWithContext(ctx context.Context, response *ListSmsCommandResponse, params *ListSmsCommandParams, recordChannel chan SupersimV1SmsCommand, errorChannel chan error) { curRecord := 1 for response != nil { @@ -246,7 +268,7 @@ func (c *ApiService) streamSmsCommand(response *ListSmsCommandResponse, params * } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSmsCommandResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListSmsCommandResponseWithContext) if err != nil { errorChannel <- err break @@ -261,11 +283,11 @@ func (c *ApiService) streamSmsCommand(response *ListSmsCommandResponse, params * close(errorChannel) } -func (c *ApiService) getNextListSmsCommandResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSmsCommandResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/supersim/v1/usage_records.go b/rest/supersim/v1/usage_records.go index 7a92cfe18..27dfa0a7f 100644 --- a/rest/supersim/v1/usage_records.go +++ b/rest/supersim/v1/usage_records.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -90,6 +91,11 @@ func (params *ListUsageRecordParams) SetLimit(Limit int) *ListUsageRecordParams // Retrieve a single page of UsageRecord records from the API. Request is executed immediately. func (c *ApiService) PageUsageRecord(params *ListUsageRecordParams, pageToken, pageNumber string) (*ListUsageRecordResponse, error) { + return c.PageUsageRecordWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of UsageRecord records from the API. Request is executed immediately. +func (c *ApiService) PageUsageRecordWithContext(ctx context.Context, params *ListUsageRecordParams, pageToken, pageNumber string) (*ListUsageRecordResponse, error) { path := "/v1/UsageRecords" data := url.Values{} @@ -132,7 +138,7 @@ func (c *ApiService) PageUsageRecord(params *ListUsageRecordParams, pageToken, p data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -149,7 +155,12 @@ func (c *ApiService) PageUsageRecord(params *ListUsageRecordParams, pageToken, p // Lists UsageRecord records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListUsageRecord(params *ListUsageRecordParams) ([]SupersimV1UsageRecord, error) { - response, errors := c.StreamUsageRecord(params) + return c.ListUsageRecordWithContext(context.TODO(), params) +} + +// Lists UsageRecord records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListUsageRecordWithContext(ctx context.Context, params *ListUsageRecordParams) ([]SupersimV1UsageRecord, error) { + response, errors := c.StreamUsageRecordWithContext(ctx, params) records := make([]SupersimV1UsageRecord, 0) for record := range response { @@ -165,6 +176,11 @@ func (c *ApiService) ListUsageRecord(params *ListUsageRecordParams) ([]SupersimV // Streams UsageRecord records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamUsageRecord(params *ListUsageRecordParams) (chan SupersimV1UsageRecord, chan error) { + return c.StreamUsageRecordWithContext(context.TODO(), params) +} + +// Streams UsageRecord records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamUsageRecordWithContext(ctx context.Context, params *ListUsageRecordParams) (chan SupersimV1UsageRecord, chan error) { if params == nil { params = &ListUsageRecordParams{} } @@ -173,19 +189,19 @@ func (c *ApiService) StreamUsageRecord(params *ListUsageRecordParams) (chan Supe recordChannel := make(chan SupersimV1UsageRecord, 1) errorChannel := make(chan error, 1) - response, err := c.PageUsageRecord(params, "", "") + response, err := c.PageUsageRecordWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUsageRecord(response, params, recordChannel, errorChannel) + go c.streamUsageRecordWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamUsageRecord(response *ListUsageRecordResponse, params *ListUsageRecordParams, recordChannel chan SupersimV1UsageRecord, errorChannel chan error) { +func (c *ApiService) streamUsageRecordWithContext(ctx context.Context, response *ListUsageRecordResponse, params *ListUsageRecordParams, recordChannel chan SupersimV1UsageRecord, errorChannel chan error) { curRecord := 1 for response != nil { @@ -200,7 +216,7 @@ func (c *ApiService) streamUsageRecord(response *ListUsageRecordResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUsageRecordResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListUsageRecordResponseWithContext) if err != nil { errorChannel <- err break @@ -215,11 +231,11 @@ func (c *ApiService) streamUsageRecord(response *ListUsageRecordResponse, params close(errorChannel) } -func (c *ApiService) getNextListUsageRecordResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUsageRecordResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/sync/v1/api_service.go b/rest/sync/v1/api_service.go index e0c486707..add078ab5 100644 --- a/rest/sync/v1/api_service.go +++ b/rest/sync/v1/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://sync.twilio.com", + } +} diff --git a/rest/sync/v1/services.go b/rest/sync/v1/services.go index c720651f5..8708b964c 100644 --- a/rest/sync/v1/services.go +++ b/rest/sync/v1/services.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -70,8 +71,10 @@ func (params *CreateServiceParams) SetWebhooksFromRestEnabled(WebhooksFromRestEn return params } -// func (c *ApiService) CreateService(params *CreateServiceParams) (*SyncV1Service, error) { + return c.CreateServiceWithContext(context.TODO(), params) +} +func (c *ApiService) CreateServiceWithContext(ctx context.Context, params *CreateServiceParams) (*SyncV1Service, error) { path := "/v1/Services" data := url.Values{} @@ -101,7 +104,7 @@ func (c *ApiService) CreateService(params *CreateServiceParams) (*SyncV1Service, data.Set("WebhooksFromRestEnabled", fmt.Sprint(*params.WebhooksFromRestEnabled)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -116,8 +119,10 @@ func (c *ApiService) CreateService(params *CreateServiceParams) (*SyncV1Service, return ps, err } -// func (c *ApiService) DeleteService(Sid string) error { + return c.DeleteServiceWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteServiceWithContext(ctx context.Context, Sid string) error { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -126,7 +131,7 @@ func (c *ApiService) DeleteService(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -136,8 +141,10 @@ func (c *ApiService) DeleteService(Sid string) error { return nil } -// func (c *ApiService) FetchService(Sid string) (*SyncV1Service, error) { + return c.FetchServiceWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchServiceWithContext(ctx context.Context, Sid string) (*SyncV1Service, error) { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -146,7 +153,7 @@ func (c *ApiService) FetchService(Sid string) (*SyncV1Service, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -180,6 +187,11 @@ func (params *ListServiceParams) SetLimit(Limit int) *ListServiceParams { // Retrieve a single page of Service records from the API. Request is executed immediately. func (c *ApiService) PageService(params *ListServiceParams, pageToken, pageNumber string) (*ListServiceResponse, error) { + return c.PageServiceWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Service records from the API. Request is executed immediately. +func (c *ApiService) PageServiceWithContext(ctx context.Context, params *ListServiceParams, pageToken, pageNumber string) (*ListServiceResponse, error) { path := "/v1/Services" data := url.Values{} @@ -198,7 +210,7 @@ func (c *ApiService) PageService(params *ListServiceParams, pageToken, pageNumbe data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -215,7 +227,12 @@ func (c *ApiService) PageService(params *ListServiceParams, pageToken, pageNumbe // Lists Service records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListService(params *ListServiceParams) ([]SyncV1Service, error) { - response, errors := c.StreamService(params) + return c.ListServiceWithContext(context.TODO(), params) +} + +// Lists Service records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListServiceWithContext(ctx context.Context, params *ListServiceParams) ([]SyncV1Service, error) { + response, errors := c.StreamServiceWithContext(ctx, params) records := make([]SyncV1Service, 0) for record := range response { @@ -231,6 +248,11 @@ func (c *ApiService) ListService(params *ListServiceParams) ([]SyncV1Service, er // Streams Service records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamService(params *ListServiceParams) (chan SyncV1Service, chan error) { + return c.StreamServiceWithContext(context.TODO(), params) +} + +// Streams Service records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamServiceWithContext(ctx context.Context, params *ListServiceParams) (chan SyncV1Service, chan error) { if params == nil { params = &ListServiceParams{} } @@ -239,19 +261,19 @@ func (c *ApiService) StreamService(params *ListServiceParams) (chan SyncV1Servic recordChannel := make(chan SyncV1Service, 1) errorChannel := make(chan error, 1) - response, err := c.PageService(params, "", "") + response, err := c.PageServiceWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamService(response, params, recordChannel, errorChannel) + go c.streamServiceWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamService(response *ListServiceResponse, params *ListServiceParams, recordChannel chan SyncV1Service, errorChannel chan error) { +func (c *ApiService) streamServiceWithContext(ctx context.Context, response *ListServiceResponse, params *ListServiceParams, recordChannel chan SyncV1Service, errorChannel chan error) { curRecord := 1 for response != nil { @@ -266,7 +288,7 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListServiceResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListServiceResponseWithContext) if err != nil { errorChannel <- err break @@ -281,11 +303,11 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe close(errorChannel) } -func (c *ApiService) getNextListServiceResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListServiceResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -346,8 +368,10 @@ func (params *UpdateServiceParams) SetWebhooksFromRestEnabled(WebhooksFromRestEn return params } -// func (c *ApiService) UpdateService(Sid string, params *UpdateServiceParams) (*SyncV1Service, error) { + return c.UpdateServiceWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateServiceWithContext(ctx context.Context, Sid string, params *UpdateServiceParams) (*SyncV1Service, error) { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -378,7 +402,7 @@ func (c *ApiService) UpdateService(Sid string, params *UpdateServiceParams) (*Sy data.Set("WebhooksFromRestEnabled", fmt.Sprint(*params.WebhooksFromRestEnabled)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/sync/v1/services_documents.go b/rest/sync/v1/services_documents.go index 41d52dd28..1637b9b9a 100644 --- a/rest/sync/v1/services_documents.go +++ b/rest/sync/v1/services_documents.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -46,8 +47,10 @@ func (params *CreateDocumentParams) SetTtl(Ttl int) *CreateDocumentParams { return params } -// func (c *ApiService) CreateDocument(ServiceSid string, params *CreateDocumentParams) (*SyncV1Document, error) { + return c.CreateDocumentWithContext(context.TODO(), ServiceSid, params) +} +func (c *ApiService) CreateDocumentWithContext(ctx context.Context, ServiceSid string, params *CreateDocumentParams) (*SyncV1Document, error) { path := "/v1/Services/{ServiceSid}/Documents" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -72,7 +75,7 @@ func (c *ApiService) CreateDocument(ServiceSid string, params *CreateDocumentPar data.Set("Ttl", fmt.Sprint(*params.Ttl)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -87,8 +90,10 @@ func (c *ApiService) CreateDocument(ServiceSid string, params *CreateDocumentPar return ps, err } -// func (c *ApiService) DeleteDocument(ServiceSid string, Sid string) error { + return c.DeleteDocumentWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) DeleteDocumentWithContext(ctx context.Context, ServiceSid string, Sid string) error { path := "/v1/Services/{ServiceSid}/Documents/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -98,7 +103,7 @@ func (c *ApiService) DeleteDocument(ServiceSid string, Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -108,8 +113,10 @@ func (c *ApiService) DeleteDocument(ServiceSid string, Sid string) error { return nil } -// func (c *ApiService) FetchDocument(ServiceSid string, Sid string) (*SyncV1Document, error) { + return c.FetchDocumentWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) FetchDocumentWithContext(ctx context.Context, ServiceSid string, Sid string) (*SyncV1Document, error) { path := "/v1/Services/{ServiceSid}/Documents/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -119,7 +126,7 @@ func (c *ApiService) FetchDocument(ServiceSid string, Sid string) (*SyncV1Docume "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -153,6 +160,11 @@ func (params *ListDocumentParams) SetLimit(Limit int) *ListDocumentParams { // Retrieve a single page of Document records from the API. Request is executed immediately. func (c *ApiService) PageDocument(ServiceSid string, params *ListDocumentParams, pageToken, pageNumber string) (*ListDocumentResponse, error) { + return c.PageDocumentWithContext(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Document records from the API. Request is executed immediately. +func (c *ApiService) PageDocumentWithContext(ctx context.Context, ServiceSid string, params *ListDocumentParams, pageToken, pageNumber string) (*ListDocumentResponse, error) { path := "/v1/Services/{ServiceSid}/Documents" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -173,7 +185,7 @@ func (c *ApiService) PageDocument(ServiceSid string, params *ListDocumentParams, data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -190,7 +202,12 @@ func (c *ApiService) PageDocument(ServiceSid string, params *ListDocumentParams, // Lists Document records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListDocument(ServiceSid string, params *ListDocumentParams) ([]SyncV1Document, error) { - response, errors := c.StreamDocument(ServiceSid, params) + return c.ListDocumentWithContext(context.TODO(), ServiceSid, params) +} + +// Lists Document records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListDocumentWithContext(ctx context.Context, ServiceSid string, params *ListDocumentParams) ([]SyncV1Document, error) { + response, errors := c.StreamDocumentWithContext(ctx, ServiceSid, params) records := make([]SyncV1Document, 0) for record := range response { @@ -206,6 +223,11 @@ func (c *ApiService) ListDocument(ServiceSid string, params *ListDocumentParams) // Streams Document records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamDocument(ServiceSid string, params *ListDocumentParams) (chan SyncV1Document, chan error) { + return c.StreamDocumentWithContext(context.TODO(), ServiceSid, params) +} + +// Streams Document records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamDocumentWithContext(ctx context.Context, ServiceSid string, params *ListDocumentParams) (chan SyncV1Document, chan error) { if params == nil { params = &ListDocumentParams{} } @@ -214,19 +236,19 @@ func (c *ApiService) StreamDocument(ServiceSid string, params *ListDocumentParam recordChannel := make(chan SyncV1Document, 1) errorChannel := make(chan error, 1) - response, err := c.PageDocument(ServiceSid, params, "", "") + response, err := c.PageDocumentWithContext(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamDocument(response, params, recordChannel, errorChannel) + go c.streamDocumentWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamDocument(response *ListDocumentResponse, params *ListDocumentParams, recordChannel chan SyncV1Document, errorChannel chan error) { +func (c *ApiService) streamDocumentWithContext(ctx context.Context, response *ListDocumentResponse, params *ListDocumentParams, recordChannel chan SyncV1Document, errorChannel chan error) { curRecord := 1 for response != nil { @@ -241,7 +263,7 @@ func (c *ApiService) streamDocument(response *ListDocumentResponse, params *List } } - record, err := client.GetNext(c.baseURL, response, c.getNextListDocumentResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListDocumentResponseWithContext) if err != nil { errorChannel <- err break @@ -256,11 +278,11 @@ func (c *ApiService) streamDocument(response *ListDocumentResponse, params *List close(errorChannel) } -func (c *ApiService) getNextListDocumentResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListDocumentResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -297,8 +319,10 @@ func (params *UpdateDocumentParams) SetTtl(Ttl int) *UpdateDocumentParams { return params } -// func (c *ApiService) UpdateDocument(ServiceSid string, Sid string, params *UpdateDocumentParams) (*SyncV1Document, error) { + return c.UpdateDocumentWithContext(context.TODO(), ServiceSid, Sid, params) +} +func (c *ApiService) UpdateDocumentWithContext(ctx context.Context, ServiceSid string, Sid string, params *UpdateDocumentParams) (*SyncV1Document, error) { path := "/v1/Services/{ServiceSid}/Documents/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -324,7 +348,7 @@ func (c *ApiService) UpdateDocument(ServiceSid string, Sid string, params *Updat if params != nil && params.IfMatch != nil { headers["If-Match"] = *params.IfMatch } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/sync/v1/services_documents_permissions.go b/rest/sync/v1/services_documents_permissions.go index 4b9ae9253..a98d7e4b7 100644 --- a/rest/sync/v1/services_documents_permissions.go +++ b/rest/sync/v1/services_documents_permissions.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -25,6 +26,9 @@ import ( // Delete a specific Sync Document Permission. func (c *ApiService) DeleteDocumentPermission(ServiceSid string, DocumentSid string, Identity string) error { + return c.DeleteDocumentPermissionWithContext(context.TODO(), ServiceSid, DocumentSid, Identity) +} +func (c *ApiService) DeleteDocumentPermissionWithContext(ctx context.Context, ServiceSid string, DocumentSid string, Identity string) error { path := "/v1/Services/{ServiceSid}/Documents/{DocumentSid}/Permissions/{Identity}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"DocumentSid"+"}", DocumentSid, -1) @@ -35,7 +39,7 @@ func (c *ApiService) DeleteDocumentPermission(ServiceSid string, DocumentSid str "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -47,6 +51,9 @@ func (c *ApiService) DeleteDocumentPermission(ServiceSid string, DocumentSid str // Fetch a specific Sync Document Permission. func (c *ApiService) FetchDocumentPermission(ServiceSid string, DocumentSid string, Identity string) (*SyncV1DocumentPermission, error) { + return c.FetchDocumentPermissionWithContext(context.TODO(), ServiceSid, DocumentSid, Identity) +} +func (c *ApiService) FetchDocumentPermissionWithContext(ctx context.Context, ServiceSid string, DocumentSid string, Identity string) (*SyncV1DocumentPermission, error) { path := "/v1/Services/{ServiceSid}/Documents/{DocumentSid}/Permissions/{Identity}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"DocumentSid"+"}", DocumentSid, -1) @@ -57,7 +64,7 @@ func (c *ApiService) FetchDocumentPermission(ServiceSid string, DocumentSid stri "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -91,6 +98,11 @@ func (params *ListDocumentPermissionParams) SetLimit(Limit int) *ListDocumentPer // Retrieve a single page of DocumentPermission records from the API. Request is executed immediately. func (c *ApiService) PageDocumentPermission(ServiceSid string, DocumentSid string, params *ListDocumentPermissionParams, pageToken, pageNumber string) (*ListDocumentPermissionResponse, error) { + return c.PageDocumentPermissionWithContext(context.TODO(), ServiceSid, DocumentSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of DocumentPermission records from the API. Request is executed immediately. +func (c *ApiService) PageDocumentPermissionWithContext(ctx context.Context, ServiceSid string, DocumentSid string, params *ListDocumentPermissionParams, pageToken, pageNumber string) (*ListDocumentPermissionResponse, error) { path := "/v1/Services/{ServiceSid}/Documents/{DocumentSid}/Permissions" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -112,7 +124,7 @@ func (c *ApiService) PageDocumentPermission(ServiceSid string, DocumentSid strin data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -129,7 +141,12 @@ func (c *ApiService) PageDocumentPermission(ServiceSid string, DocumentSid strin // Lists DocumentPermission records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListDocumentPermission(ServiceSid string, DocumentSid string, params *ListDocumentPermissionParams) ([]SyncV1DocumentPermission, error) { - response, errors := c.StreamDocumentPermission(ServiceSid, DocumentSid, params) + return c.ListDocumentPermissionWithContext(context.TODO(), ServiceSid, DocumentSid, params) +} + +// Lists DocumentPermission records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListDocumentPermissionWithContext(ctx context.Context, ServiceSid string, DocumentSid string, params *ListDocumentPermissionParams) ([]SyncV1DocumentPermission, error) { + response, errors := c.StreamDocumentPermissionWithContext(ctx, ServiceSid, DocumentSid, params) records := make([]SyncV1DocumentPermission, 0) for record := range response { @@ -145,6 +162,11 @@ func (c *ApiService) ListDocumentPermission(ServiceSid string, DocumentSid strin // Streams DocumentPermission records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamDocumentPermission(ServiceSid string, DocumentSid string, params *ListDocumentPermissionParams) (chan SyncV1DocumentPermission, chan error) { + return c.StreamDocumentPermissionWithContext(context.TODO(), ServiceSid, DocumentSid, params) +} + +// Streams DocumentPermission records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamDocumentPermissionWithContext(ctx context.Context, ServiceSid string, DocumentSid string, params *ListDocumentPermissionParams) (chan SyncV1DocumentPermission, chan error) { if params == nil { params = &ListDocumentPermissionParams{} } @@ -153,19 +175,19 @@ func (c *ApiService) StreamDocumentPermission(ServiceSid string, DocumentSid str recordChannel := make(chan SyncV1DocumentPermission, 1) errorChannel := make(chan error, 1) - response, err := c.PageDocumentPermission(ServiceSid, DocumentSid, params, "", "") + response, err := c.PageDocumentPermissionWithContext(ctx, ServiceSid, DocumentSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamDocumentPermission(response, params, recordChannel, errorChannel) + go c.streamDocumentPermissionWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamDocumentPermission(response *ListDocumentPermissionResponse, params *ListDocumentPermissionParams, recordChannel chan SyncV1DocumentPermission, errorChannel chan error) { +func (c *ApiService) streamDocumentPermissionWithContext(ctx context.Context, response *ListDocumentPermissionResponse, params *ListDocumentPermissionParams, recordChannel chan SyncV1DocumentPermission, errorChannel chan error) { curRecord := 1 for response != nil { @@ -180,7 +202,7 @@ func (c *ApiService) streamDocumentPermission(response *ListDocumentPermissionRe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListDocumentPermissionResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListDocumentPermissionResponseWithContext) if err != nil { errorChannel <- err break @@ -195,11 +217,11 @@ func (c *ApiService) streamDocumentPermission(response *ListDocumentPermissionRe close(errorChannel) } -func (c *ApiService) getNextListDocumentPermissionResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListDocumentPermissionResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -238,6 +260,9 @@ func (params *UpdateDocumentPermissionParams) SetManage(Manage bool) *UpdateDocu // Update an identity's access to a specific Sync Document. func (c *ApiService) UpdateDocumentPermission(ServiceSid string, DocumentSid string, Identity string, params *UpdateDocumentPermissionParams) (*SyncV1DocumentPermission, error) { + return c.UpdateDocumentPermissionWithContext(context.TODO(), ServiceSid, DocumentSid, Identity, params) +} +func (c *ApiService) UpdateDocumentPermissionWithContext(ctx context.Context, ServiceSid string, DocumentSid string, Identity string, params *UpdateDocumentPermissionParams) (*SyncV1DocumentPermission, error) { path := "/v1/Services/{ServiceSid}/Documents/{DocumentSid}/Permissions/{Identity}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"DocumentSid"+"}", DocumentSid, -1) @@ -258,7 +283,7 @@ func (c *ApiService) UpdateDocumentPermission(ServiceSid string, DocumentSid str data.Set("Manage", fmt.Sprint(*params.Manage)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/sync/v1/services_lists.go b/rest/sync/v1/services_lists.go index e9a1977ce..b327957ce 100644 --- a/rest/sync/v1/services_lists.go +++ b/rest/sync/v1/services_lists.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -46,8 +47,10 @@ func (params *CreateSyncListParams) SetCollectionTtl(CollectionTtl int) *CreateS return params } -// func (c *ApiService) CreateSyncList(ServiceSid string, params *CreateSyncListParams) (*SyncV1SyncList, error) { + return c.CreateSyncListWithContext(context.TODO(), ServiceSid, params) +} +func (c *ApiService) CreateSyncListWithContext(ctx context.Context, ServiceSid string, params *CreateSyncListParams) (*SyncV1SyncList, error) { path := "/v1/Services/{ServiceSid}/Lists" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -66,7 +69,7 @@ func (c *ApiService) CreateSyncList(ServiceSid string, params *CreateSyncListPar data.Set("CollectionTtl", fmt.Sprint(*params.CollectionTtl)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -81,8 +84,10 @@ func (c *ApiService) CreateSyncList(ServiceSid string, params *CreateSyncListPar return ps, err } -// func (c *ApiService) DeleteSyncList(ServiceSid string, Sid string) error { + return c.DeleteSyncListWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) DeleteSyncListWithContext(ctx context.Context, ServiceSid string, Sid string) error { path := "/v1/Services/{ServiceSid}/Lists/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -92,7 +97,7 @@ func (c *ApiService) DeleteSyncList(ServiceSid string, Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -102,8 +107,10 @@ func (c *ApiService) DeleteSyncList(ServiceSid string, Sid string) error { return nil } -// func (c *ApiService) FetchSyncList(ServiceSid string, Sid string) (*SyncV1SyncList, error) { + return c.FetchSyncListWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) FetchSyncListWithContext(ctx context.Context, ServiceSid string, Sid string) (*SyncV1SyncList, error) { path := "/v1/Services/{ServiceSid}/Lists/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -113,7 +120,7 @@ func (c *ApiService) FetchSyncList(ServiceSid string, Sid string) (*SyncV1SyncLi "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -147,6 +154,11 @@ func (params *ListSyncListParams) SetLimit(Limit int) *ListSyncListParams { // Retrieve a single page of SyncList records from the API. Request is executed immediately. func (c *ApiService) PageSyncList(ServiceSid string, params *ListSyncListParams, pageToken, pageNumber string) (*ListSyncListResponse, error) { + return c.PageSyncListWithContext(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of SyncList records from the API. Request is executed immediately. +func (c *ApiService) PageSyncListWithContext(ctx context.Context, ServiceSid string, params *ListSyncListParams, pageToken, pageNumber string) (*ListSyncListResponse, error) { path := "/v1/Services/{ServiceSid}/Lists" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -167,7 +179,7 @@ func (c *ApiService) PageSyncList(ServiceSid string, params *ListSyncListParams, data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -184,7 +196,12 @@ func (c *ApiService) PageSyncList(ServiceSid string, params *ListSyncListParams, // Lists SyncList records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListSyncList(ServiceSid string, params *ListSyncListParams) ([]SyncV1SyncList, error) { - response, errors := c.StreamSyncList(ServiceSid, params) + return c.ListSyncListWithContext(context.TODO(), ServiceSid, params) +} + +// Lists SyncList records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListSyncListWithContext(ctx context.Context, ServiceSid string, params *ListSyncListParams) ([]SyncV1SyncList, error) { + response, errors := c.StreamSyncListWithContext(ctx, ServiceSid, params) records := make([]SyncV1SyncList, 0) for record := range response { @@ -200,6 +217,11 @@ func (c *ApiService) ListSyncList(ServiceSid string, params *ListSyncListParams) // Streams SyncList records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamSyncList(ServiceSid string, params *ListSyncListParams) (chan SyncV1SyncList, chan error) { + return c.StreamSyncListWithContext(context.TODO(), ServiceSid, params) +} + +// Streams SyncList records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamSyncListWithContext(ctx context.Context, ServiceSid string, params *ListSyncListParams) (chan SyncV1SyncList, chan error) { if params == nil { params = &ListSyncListParams{} } @@ -208,19 +230,19 @@ func (c *ApiService) StreamSyncList(ServiceSid string, params *ListSyncListParam recordChannel := make(chan SyncV1SyncList, 1) errorChannel := make(chan error, 1) - response, err := c.PageSyncList(ServiceSid, params, "", "") + response, err := c.PageSyncListWithContext(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSyncList(response, params, recordChannel, errorChannel) + go c.streamSyncListWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamSyncList(response *ListSyncListResponse, params *ListSyncListParams, recordChannel chan SyncV1SyncList, errorChannel chan error) { +func (c *ApiService) streamSyncListWithContext(ctx context.Context, response *ListSyncListResponse, params *ListSyncListParams, recordChannel chan SyncV1SyncList, errorChannel chan error) { curRecord := 1 for response != nil { @@ -235,7 +257,7 @@ func (c *ApiService) streamSyncList(response *ListSyncListResponse, params *List } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSyncListResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListSyncListResponseWithContext) if err != nil { errorChannel <- err break @@ -250,11 +272,11 @@ func (c *ApiService) streamSyncList(response *ListSyncListResponse, params *List close(errorChannel) } -func (c *ApiService) getNextListSyncListResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSyncListResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -285,8 +307,10 @@ func (params *UpdateSyncListParams) SetCollectionTtl(CollectionTtl int) *UpdateS return params } -// func (c *ApiService) UpdateSyncList(ServiceSid string, Sid string, params *UpdateSyncListParams) (*SyncV1SyncList, error) { + return c.UpdateSyncListWithContext(context.TODO(), ServiceSid, Sid, params) +} +func (c *ApiService) UpdateSyncListWithContext(ctx context.Context, ServiceSid string, Sid string, params *UpdateSyncListParams) (*SyncV1SyncList, error) { path := "/v1/Services/{ServiceSid}/Lists/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -303,7 +327,7 @@ func (c *ApiService) UpdateSyncList(ServiceSid string, Sid string, params *Updat data.Set("CollectionTtl", fmt.Sprint(*params.CollectionTtl)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/sync/v1/services_lists_items.go b/rest/sync/v1/services_lists_items.go index 8178a1d24..647651b7a 100644 --- a/rest/sync/v1/services_lists_items.go +++ b/rest/sync/v1/services_lists_items.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -52,8 +53,10 @@ func (params *CreateSyncListItemParams) SetCollectionTtl(CollectionTtl int) *Cre return params } -// func (c *ApiService) CreateSyncListItem(ServiceSid string, ListSid string, params *CreateSyncListItemParams) (*SyncV1SyncListItem, error) { + return c.CreateSyncListItemWithContext(context.TODO(), ServiceSid, ListSid, params) +} +func (c *ApiService) CreateSyncListItemWithContext(ctx context.Context, ServiceSid string, ListSid string, params *CreateSyncListItemParams) (*SyncV1SyncListItem, error) { path := "/v1/Services/{ServiceSid}/Lists/{ListSid}/Items" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ListSid"+"}", ListSid, -1) @@ -82,7 +85,7 @@ func (c *ApiService) CreateSyncListItem(ServiceSid string, ListSid string, param data.Set("CollectionTtl", fmt.Sprint(*params.CollectionTtl)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -108,8 +111,10 @@ func (params *DeleteSyncListItemParams) SetIfMatch(IfMatch string) *DeleteSyncLi return params } -// func (c *ApiService) DeleteSyncListItem(ServiceSid string, ListSid string, Index int, params *DeleteSyncListItemParams) error { + return c.DeleteSyncListItemWithContext(context.TODO(), ServiceSid, ListSid, Index, params) +} +func (c *ApiService) DeleteSyncListItemWithContext(ctx context.Context, ServiceSid string, ListSid string, Index int, params *DeleteSyncListItemParams) error { path := "/v1/Services/{ServiceSid}/Lists/{ListSid}/Items/{Index}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ListSid"+"}", ListSid, -1) @@ -123,7 +128,7 @@ func (c *ApiService) DeleteSyncListItem(ServiceSid string, ListSid string, Index if params != nil && params.IfMatch != nil { headers["If-Match"] = *params.IfMatch } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -133,8 +138,10 @@ func (c *ApiService) DeleteSyncListItem(ServiceSid string, ListSid string, Index return nil } -// func (c *ApiService) FetchSyncListItem(ServiceSid string, ListSid string, Index int) (*SyncV1SyncListItem, error) { + return c.FetchSyncListItemWithContext(context.TODO(), ServiceSid, ListSid, Index) +} +func (c *ApiService) FetchSyncListItemWithContext(ctx context.Context, ServiceSid string, ListSid string, Index int) (*SyncV1SyncListItem, error) { path := "/v1/Services/{ServiceSid}/Lists/{ListSid}/Items/{Index}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ListSid"+"}", ListSid, -1) @@ -145,7 +152,7 @@ func (c *ApiService) FetchSyncListItem(ServiceSid string, ListSid string, Index "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -197,6 +204,11 @@ func (params *ListSyncListItemParams) SetLimit(Limit int) *ListSyncListItemParam // Retrieve a single page of SyncListItem records from the API. Request is executed immediately. func (c *ApiService) PageSyncListItem(ServiceSid string, ListSid string, params *ListSyncListItemParams, pageToken, pageNumber string) (*ListSyncListItemResponse, error) { + return c.PageSyncListItemWithContext(context.TODO(), ServiceSid, ListSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of SyncListItem records from the API. Request is executed immediately. +func (c *ApiService) PageSyncListItemWithContext(ctx context.Context, ServiceSid string, ListSid string, params *ListSyncListItemParams, pageToken, pageNumber string) (*ListSyncListItemResponse, error) { path := "/v1/Services/{ServiceSid}/Lists/{ListSid}/Items" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -227,7 +239,7 @@ func (c *ApiService) PageSyncListItem(ServiceSid string, ListSid string, params data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -244,7 +256,12 @@ func (c *ApiService) PageSyncListItem(ServiceSid string, ListSid string, params // Lists SyncListItem records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListSyncListItem(ServiceSid string, ListSid string, params *ListSyncListItemParams) ([]SyncV1SyncListItem, error) { - response, errors := c.StreamSyncListItem(ServiceSid, ListSid, params) + return c.ListSyncListItemWithContext(context.TODO(), ServiceSid, ListSid, params) +} + +// Lists SyncListItem records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListSyncListItemWithContext(ctx context.Context, ServiceSid string, ListSid string, params *ListSyncListItemParams) ([]SyncV1SyncListItem, error) { + response, errors := c.StreamSyncListItemWithContext(ctx, ServiceSid, ListSid, params) records := make([]SyncV1SyncListItem, 0) for record := range response { @@ -260,6 +277,11 @@ func (c *ApiService) ListSyncListItem(ServiceSid string, ListSid string, params // Streams SyncListItem records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamSyncListItem(ServiceSid string, ListSid string, params *ListSyncListItemParams) (chan SyncV1SyncListItem, chan error) { + return c.StreamSyncListItemWithContext(context.TODO(), ServiceSid, ListSid, params) +} + +// Streams SyncListItem records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamSyncListItemWithContext(ctx context.Context, ServiceSid string, ListSid string, params *ListSyncListItemParams) (chan SyncV1SyncListItem, chan error) { if params == nil { params = &ListSyncListItemParams{} } @@ -268,19 +290,19 @@ func (c *ApiService) StreamSyncListItem(ServiceSid string, ListSid string, param recordChannel := make(chan SyncV1SyncListItem, 1) errorChannel := make(chan error, 1) - response, err := c.PageSyncListItem(ServiceSid, ListSid, params, "", "") + response, err := c.PageSyncListItemWithContext(ctx, ServiceSid, ListSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSyncListItem(response, params, recordChannel, errorChannel) + go c.streamSyncListItemWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamSyncListItem(response *ListSyncListItemResponse, params *ListSyncListItemParams, recordChannel chan SyncV1SyncListItem, errorChannel chan error) { +func (c *ApiService) streamSyncListItemWithContext(ctx context.Context, response *ListSyncListItemResponse, params *ListSyncListItemParams, recordChannel chan SyncV1SyncListItem, errorChannel chan error) { curRecord := 1 for response != nil { @@ -295,7 +317,7 @@ func (c *ApiService) streamSyncListItem(response *ListSyncListItemResponse, para } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSyncListItemResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListSyncListItemResponseWithContext) if err != nil { errorChannel <- err break @@ -310,11 +332,11 @@ func (c *ApiService) streamSyncListItem(response *ListSyncListItemResponse, para close(errorChannel) } -func (c *ApiService) getNextListSyncListItemResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSyncListItemResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -363,8 +385,10 @@ func (params *UpdateSyncListItemParams) SetCollectionTtl(CollectionTtl int) *Upd return params } -// func (c *ApiService) UpdateSyncListItem(ServiceSid string, ListSid string, Index int, params *UpdateSyncListItemParams) (*SyncV1SyncListItem, error) { + return c.UpdateSyncListItemWithContext(context.TODO(), ServiceSid, ListSid, Index, params) +} +func (c *ApiService) UpdateSyncListItemWithContext(ctx context.Context, ServiceSid string, ListSid string, Index int, params *UpdateSyncListItemParams) (*SyncV1SyncListItem, error) { path := "/v1/Services/{ServiceSid}/Lists/{ListSid}/Items/{Index}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ListSid"+"}", ListSid, -1) @@ -397,7 +421,7 @@ func (c *ApiService) UpdateSyncListItem(ServiceSid string, ListSid string, Index if params != nil && params.IfMatch != nil { headers["If-Match"] = *params.IfMatch } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/sync/v1/services_lists_permissions.go b/rest/sync/v1/services_lists_permissions.go index abb29c592..80e311393 100644 --- a/rest/sync/v1/services_lists_permissions.go +++ b/rest/sync/v1/services_lists_permissions.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -25,6 +26,9 @@ import ( // Delete a specific Sync List Permission. func (c *ApiService) DeleteSyncListPermission(ServiceSid string, ListSid string, Identity string) error { + return c.DeleteSyncListPermissionWithContext(context.TODO(), ServiceSid, ListSid, Identity) +} +func (c *ApiService) DeleteSyncListPermissionWithContext(ctx context.Context, ServiceSid string, ListSid string, Identity string) error { path := "/v1/Services/{ServiceSid}/Lists/{ListSid}/Permissions/{Identity}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ListSid"+"}", ListSid, -1) @@ -35,7 +39,7 @@ func (c *ApiService) DeleteSyncListPermission(ServiceSid string, ListSid string, "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -47,6 +51,9 @@ func (c *ApiService) DeleteSyncListPermission(ServiceSid string, ListSid string, // Fetch a specific Sync List Permission. func (c *ApiService) FetchSyncListPermission(ServiceSid string, ListSid string, Identity string) (*SyncV1SyncListPermission, error) { + return c.FetchSyncListPermissionWithContext(context.TODO(), ServiceSid, ListSid, Identity) +} +func (c *ApiService) FetchSyncListPermissionWithContext(ctx context.Context, ServiceSid string, ListSid string, Identity string) (*SyncV1SyncListPermission, error) { path := "/v1/Services/{ServiceSid}/Lists/{ListSid}/Permissions/{Identity}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ListSid"+"}", ListSid, -1) @@ -57,7 +64,7 @@ func (c *ApiService) FetchSyncListPermission(ServiceSid string, ListSid string, "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -91,6 +98,11 @@ func (params *ListSyncListPermissionParams) SetLimit(Limit int) *ListSyncListPer // Retrieve a single page of SyncListPermission records from the API. Request is executed immediately. func (c *ApiService) PageSyncListPermission(ServiceSid string, ListSid string, params *ListSyncListPermissionParams, pageToken, pageNumber string) (*ListSyncListPermissionResponse, error) { + return c.PageSyncListPermissionWithContext(context.TODO(), ServiceSid, ListSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of SyncListPermission records from the API. Request is executed immediately. +func (c *ApiService) PageSyncListPermissionWithContext(ctx context.Context, ServiceSid string, ListSid string, params *ListSyncListPermissionParams, pageToken, pageNumber string) (*ListSyncListPermissionResponse, error) { path := "/v1/Services/{ServiceSid}/Lists/{ListSid}/Permissions" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -112,7 +124,7 @@ func (c *ApiService) PageSyncListPermission(ServiceSid string, ListSid string, p data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -129,7 +141,12 @@ func (c *ApiService) PageSyncListPermission(ServiceSid string, ListSid string, p // Lists SyncListPermission records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListSyncListPermission(ServiceSid string, ListSid string, params *ListSyncListPermissionParams) ([]SyncV1SyncListPermission, error) { - response, errors := c.StreamSyncListPermission(ServiceSid, ListSid, params) + return c.ListSyncListPermissionWithContext(context.TODO(), ServiceSid, ListSid, params) +} + +// Lists SyncListPermission records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListSyncListPermissionWithContext(ctx context.Context, ServiceSid string, ListSid string, params *ListSyncListPermissionParams) ([]SyncV1SyncListPermission, error) { + response, errors := c.StreamSyncListPermissionWithContext(ctx, ServiceSid, ListSid, params) records := make([]SyncV1SyncListPermission, 0) for record := range response { @@ -145,6 +162,11 @@ func (c *ApiService) ListSyncListPermission(ServiceSid string, ListSid string, p // Streams SyncListPermission records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamSyncListPermission(ServiceSid string, ListSid string, params *ListSyncListPermissionParams) (chan SyncV1SyncListPermission, chan error) { + return c.StreamSyncListPermissionWithContext(context.TODO(), ServiceSid, ListSid, params) +} + +// Streams SyncListPermission records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamSyncListPermissionWithContext(ctx context.Context, ServiceSid string, ListSid string, params *ListSyncListPermissionParams) (chan SyncV1SyncListPermission, chan error) { if params == nil { params = &ListSyncListPermissionParams{} } @@ -153,19 +175,19 @@ func (c *ApiService) StreamSyncListPermission(ServiceSid string, ListSid string, recordChannel := make(chan SyncV1SyncListPermission, 1) errorChannel := make(chan error, 1) - response, err := c.PageSyncListPermission(ServiceSid, ListSid, params, "", "") + response, err := c.PageSyncListPermissionWithContext(ctx, ServiceSid, ListSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSyncListPermission(response, params, recordChannel, errorChannel) + go c.streamSyncListPermissionWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamSyncListPermission(response *ListSyncListPermissionResponse, params *ListSyncListPermissionParams, recordChannel chan SyncV1SyncListPermission, errorChannel chan error) { +func (c *ApiService) streamSyncListPermissionWithContext(ctx context.Context, response *ListSyncListPermissionResponse, params *ListSyncListPermissionParams, recordChannel chan SyncV1SyncListPermission, errorChannel chan error) { curRecord := 1 for response != nil { @@ -180,7 +202,7 @@ func (c *ApiService) streamSyncListPermission(response *ListSyncListPermissionRe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSyncListPermissionResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListSyncListPermissionResponseWithContext) if err != nil { errorChannel <- err break @@ -195,11 +217,11 @@ func (c *ApiService) streamSyncListPermission(response *ListSyncListPermissionRe close(errorChannel) } -func (c *ApiService) getNextListSyncListPermissionResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSyncListPermissionResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -238,6 +260,9 @@ func (params *UpdateSyncListPermissionParams) SetManage(Manage bool) *UpdateSync // Update an identity's access to a specific Sync List. func (c *ApiService) UpdateSyncListPermission(ServiceSid string, ListSid string, Identity string, params *UpdateSyncListPermissionParams) (*SyncV1SyncListPermission, error) { + return c.UpdateSyncListPermissionWithContext(context.TODO(), ServiceSid, ListSid, Identity, params) +} +func (c *ApiService) UpdateSyncListPermissionWithContext(ctx context.Context, ServiceSid string, ListSid string, Identity string, params *UpdateSyncListPermissionParams) (*SyncV1SyncListPermission, error) { path := "/v1/Services/{ServiceSid}/Lists/{ListSid}/Permissions/{Identity}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"ListSid"+"}", ListSid, -1) @@ -258,7 +283,7 @@ func (c *ApiService) UpdateSyncListPermission(ServiceSid string, ListSid string, data.Set("Manage", fmt.Sprint(*params.Manage)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/sync/v1/services_maps.go b/rest/sync/v1/services_maps.go index 2b4c4897d..55aa62f39 100644 --- a/rest/sync/v1/services_maps.go +++ b/rest/sync/v1/services_maps.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -46,8 +47,10 @@ func (params *CreateSyncMapParams) SetCollectionTtl(CollectionTtl int) *CreateSy return params } -// func (c *ApiService) CreateSyncMap(ServiceSid string, params *CreateSyncMapParams) (*SyncV1SyncMap, error) { + return c.CreateSyncMapWithContext(context.TODO(), ServiceSid, params) +} +func (c *ApiService) CreateSyncMapWithContext(ctx context.Context, ServiceSid string, params *CreateSyncMapParams) (*SyncV1SyncMap, error) { path := "/v1/Services/{ServiceSid}/Maps" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -66,7 +69,7 @@ func (c *ApiService) CreateSyncMap(ServiceSid string, params *CreateSyncMapParam data.Set("CollectionTtl", fmt.Sprint(*params.CollectionTtl)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -81,8 +84,10 @@ func (c *ApiService) CreateSyncMap(ServiceSid string, params *CreateSyncMapParam return ps, err } -// func (c *ApiService) DeleteSyncMap(ServiceSid string, Sid string) error { + return c.DeleteSyncMapWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) DeleteSyncMapWithContext(ctx context.Context, ServiceSid string, Sid string) error { path := "/v1/Services/{ServiceSid}/Maps/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -92,7 +97,7 @@ func (c *ApiService) DeleteSyncMap(ServiceSid string, Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -102,8 +107,10 @@ func (c *ApiService) DeleteSyncMap(ServiceSid string, Sid string) error { return nil } -// func (c *ApiService) FetchSyncMap(ServiceSid string, Sid string) (*SyncV1SyncMap, error) { + return c.FetchSyncMapWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) FetchSyncMapWithContext(ctx context.Context, ServiceSid string, Sid string) (*SyncV1SyncMap, error) { path := "/v1/Services/{ServiceSid}/Maps/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -113,7 +120,7 @@ func (c *ApiService) FetchSyncMap(ServiceSid string, Sid string) (*SyncV1SyncMap "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -147,6 +154,11 @@ func (params *ListSyncMapParams) SetLimit(Limit int) *ListSyncMapParams { // Retrieve a single page of SyncMap records from the API. Request is executed immediately. func (c *ApiService) PageSyncMap(ServiceSid string, params *ListSyncMapParams, pageToken, pageNumber string) (*ListSyncMapResponse, error) { + return c.PageSyncMapWithContext(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of SyncMap records from the API. Request is executed immediately. +func (c *ApiService) PageSyncMapWithContext(ctx context.Context, ServiceSid string, params *ListSyncMapParams, pageToken, pageNumber string) (*ListSyncMapResponse, error) { path := "/v1/Services/{ServiceSid}/Maps" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -167,7 +179,7 @@ func (c *ApiService) PageSyncMap(ServiceSid string, params *ListSyncMapParams, p data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -184,7 +196,12 @@ func (c *ApiService) PageSyncMap(ServiceSid string, params *ListSyncMapParams, p // Lists SyncMap records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListSyncMap(ServiceSid string, params *ListSyncMapParams) ([]SyncV1SyncMap, error) { - response, errors := c.StreamSyncMap(ServiceSid, params) + return c.ListSyncMapWithContext(context.TODO(), ServiceSid, params) +} + +// Lists SyncMap records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListSyncMapWithContext(ctx context.Context, ServiceSid string, params *ListSyncMapParams) ([]SyncV1SyncMap, error) { + response, errors := c.StreamSyncMapWithContext(ctx, ServiceSid, params) records := make([]SyncV1SyncMap, 0) for record := range response { @@ -200,6 +217,11 @@ func (c *ApiService) ListSyncMap(ServiceSid string, params *ListSyncMapParams) ( // Streams SyncMap records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamSyncMap(ServiceSid string, params *ListSyncMapParams) (chan SyncV1SyncMap, chan error) { + return c.StreamSyncMapWithContext(context.TODO(), ServiceSid, params) +} + +// Streams SyncMap records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamSyncMapWithContext(ctx context.Context, ServiceSid string, params *ListSyncMapParams) (chan SyncV1SyncMap, chan error) { if params == nil { params = &ListSyncMapParams{} } @@ -208,19 +230,19 @@ func (c *ApiService) StreamSyncMap(ServiceSid string, params *ListSyncMapParams) recordChannel := make(chan SyncV1SyncMap, 1) errorChannel := make(chan error, 1) - response, err := c.PageSyncMap(ServiceSid, params, "", "") + response, err := c.PageSyncMapWithContext(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSyncMap(response, params, recordChannel, errorChannel) + go c.streamSyncMapWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamSyncMap(response *ListSyncMapResponse, params *ListSyncMapParams, recordChannel chan SyncV1SyncMap, errorChannel chan error) { +func (c *ApiService) streamSyncMapWithContext(ctx context.Context, response *ListSyncMapResponse, params *ListSyncMapParams, recordChannel chan SyncV1SyncMap, errorChannel chan error) { curRecord := 1 for response != nil { @@ -235,7 +257,7 @@ func (c *ApiService) streamSyncMap(response *ListSyncMapResponse, params *ListSy } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSyncMapResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListSyncMapResponseWithContext) if err != nil { errorChannel <- err break @@ -250,11 +272,11 @@ func (c *ApiService) streamSyncMap(response *ListSyncMapResponse, params *ListSy close(errorChannel) } -func (c *ApiService) getNextListSyncMapResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSyncMapResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -285,8 +307,10 @@ func (params *UpdateSyncMapParams) SetCollectionTtl(CollectionTtl int) *UpdateSy return params } -// func (c *ApiService) UpdateSyncMap(ServiceSid string, Sid string, params *UpdateSyncMapParams) (*SyncV1SyncMap, error) { + return c.UpdateSyncMapWithContext(context.TODO(), ServiceSid, Sid, params) +} +func (c *ApiService) UpdateSyncMapWithContext(ctx context.Context, ServiceSid string, Sid string, params *UpdateSyncMapParams) (*SyncV1SyncMap, error) { path := "/v1/Services/{ServiceSid}/Maps/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -303,7 +327,7 @@ func (c *ApiService) UpdateSyncMap(ServiceSid string, Sid string, params *Update data.Set("CollectionTtl", fmt.Sprint(*params.CollectionTtl)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/sync/v1/services_maps_items.go b/rest/sync/v1/services_maps_items.go index 69a8a7dc9..b057a01b9 100644 --- a/rest/sync/v1/services_maps_items.go +++ b/rest/sync/v1/services_maps_items.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -58,8 +59,10 @@ func (params *CreateSyncMapItemParams) SetCollectionTtl(CollectionTtl int) *Crea return params } -// func (c *ApiService) CreateSyncMapItem(ServiceSid string, MapSid string, params *CreateSyncMapItemParams) (*SyncV1SyncMapItem, error) { + return c.CreateSyncMapItemWithContext(context.TODO(), ServiceSid, MapSid, params) +} +func (c *ApiService) CreateSyncMapItemWithContext(ctx context.Context, ServiceSid string, MapSid string, params *CreateSyncMapItemParams) (*SyncV1SyncMapItem, error) { path := "/v1/Services/{ServiceSid}/Maps/{MapSid}/Items" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"MapSid"+"}", MapSid, -1) @@ -91,7 +94,7 @@ func (c *ApiService) CreateSyncMapItem(ServiceSid string, MapSid string, params data.Set("CollectionTtl", fmt.Sprint(*params.CollectionTtl)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -117,8 +120,10 @@ func (params *DeleteSyncMapItemParams) SetIfMatch(IfMatch string) *DeleteSyncMap return params } -// func (c *ApiService) DeleteSyncMapItem(ServiceSid string, MapSid string, Key string, params *DeleteSyncMapItemParams) error { + return c.DeleteSyncMapItemWithContext(context.TODO(), ServiceSid, MapSid, Key, params) +} +func (c *ApiService) DeleteSyncMapItemWithContext(ctx context.Context, ServiceSid string, MapSid string, Key string, params *DeleteSyncMapItemParams) error { path := "/v1/Services/{ServiceSid}/Maps/{MapSid}/Items/{Key}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"MapSid"+"}", MapSid, -1) @@ -132,7 +137,7 @@ func (c *ApiService) DeleteSyncMapItem(ServiceSid string, MapSid string, Key str if params != nil && params.IfMatch != nil { headers["If-Match"] = *params.IfMatch } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -142,8 +147,10 @@ func (c *ApiService) DeleteSyncMapItem(ServiceSid string, MapSid string, Key str return nil } -// func (c *ApiService) FetchSyncMapItem(ServiceSid string, MapSid string, Key string) (*SyncV1SyncMapItem, error) { + return c.FetchSyncMapItemWithContext(context.TODO(), ServiceSid, MapSid, Key) +} +func (c *ApiService) FetchSyncMapItemWithContext(ctx context.Context, ServiceSid string, MapSid string, Key string) (*SyncV1SyncMapItem, error) { path := "/v1/Services/{ServiceSid}/Maps/{MapSid}/Items/{Key}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"MapSid"+"}", MapSid, -1) @@ -154,7 +161,7 @@ func (c *ApiService) FetchSyncMapItem(ServiceSid string, MapSid string, Key stri "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -206,6 +213,11 @@ func (params *ListSyncMapItemParams) SetLimit(Limit int) *ListSyncMapItemParams // Retrieve a single page of SyncMapItem records from the API. Request is executed immediately. func (c *ApiService) PageSyncMapItem(ServiceSid string, MapSid string, params *ListSyncMapItemParams, pageToken, pageNumber string) (*ListSyncMapItemResponse, error) { + return c.PageSyncMapItemWithContext(context.TODO(), ServiceSid, MapSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of SyncMapItem records from the API. Request is executed immediately. +func (c *ApiService) PageSyncMapItemWithContext(ctx context.Context, ServiceSid string, MapSid string, params *ListSyncMapItemParams, pageToken, pageNumber string) (*ListSyncMapItemResponse, error) { path := "/v1/Services/{ServiceSid}/Maps/{MapSid}/Items" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -236,7 +248,7 @@ func (c *ApiService) PageSyncMapItem(ServiceSid string, MapSid string, params *L data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -253,7 +265,12 @@ func (c *ApiService) PageSyncMapItem(ServiceSid string, MapSid string, params *L // Lists SyncMapItem records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListSyncMapItem(ServiceSid string, MapSid string, params *ListSyncMapItemParams) ([]SyncV1SyncMapItem, error) { - response, errors := c.StreamSyncMapItem(ServiceSid, MapSid, params) + return c.ListSyncMapItemWithContext(context.TODO(), ServiceSid, MapSid, params) +} + +// Lists SyncMapItem records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListSyncMapItemWithContext(ctx context.Context, ServiceSid string, MapSid string, params *ListSyncMapItemParams) ([]SyncV1SyncMapItem, error) { + response, errors := c.StreamSyncMapItemWithContext(ctx, ServiceSid, MapSid, params) records := make([]SyncV1SyncMapItem, 0) for record := range response { @@ -269,6 +286,11 @@ func (c *ApiService) ListSyncMapItem(ServiceSid string, MapSid string, params *L // Streams SyncMapItem records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamSyncMapItem(ServiceSid string, MapSid string, params *ListSyncMapItemParams) (chan SyncV1SyncMapItem, chan error) { + return c.StreamSyncMapItemWithContext(context.TODO(), ServiceSid, MapSid, params) +} + +// Streams SyncMapItem records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamSyncMapItemWithContext(ctx context.Context, ServiceSid string, MapSid string, params *ListSyncMapItemParams) (chan SyncV1SyncMapItem, chan error) { if params == nil { params = &ListSyncMapItemParams{} } @@ -277,19 +299,19 @@ func (c *ApiService) StreamSyncMapItem(ServiceSid string, MapSid string, params recordChannel := make(chan SyncV1SyncMapItem, 1) errorChannel := make(chan error, 1) - response, err := c.PageSyncMapItem(ServiceSid, MapSid, params, "", "") + response, err := c.PageSyncMapItemWithContext(ctx, ServiceSid, MapSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSyncMapItem(response, params, recordChannel, errorChannel) + go c.streamSyncMapItemWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamSyncMapItem(response *ListSyncMapItemResponse, params *ListSyncMapItemParams, recordChannel chan SyncV1SyncMapItem, errorChannel chan error) { +func (c *ApiService) streamSyncMapItemWithContext(ctx context.Context, response *ListSyncMapItemResponse, params *ListSyncMapItemParams, recordChannel chan SyncV1SyncMapItem, errorChannel chan error) { curRecord := 1 for response != nil { @@ -304,7 +326,7 @@ func (c *ApiService) streamSyncMapItem(response *ListSyncMapItemResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSyncMapItemResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListSyncMapItemResponseWithContext) if err != nil { errorChannel <- err break @@ -319,11 +341,11 @@ func (c *ApiService) streamSyncMapItem(response *ListSyncMapItemResponse, params close(errorChannel) } -func (c *ApiService) getNextListSyncMapItemResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSyncMapItemResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -372,8 +394,10 @@ func (params *UpdateSyncMapItemParams) SetCollectionTtl(CollectionTtl int) *Upda return params } -// func (c *ApiService) UpdateSyncMapItem(ServiceSid string, MapSid string, Key string, params *UpdateSyncMapItemParams) (*SyncV1SyncMapItem, error) { + return c.UpdateSyncMapItemWithContext(context.TODO(), ServiceSid, MapSid, Key, params) +} +func (c *ApiService) UpdateSyncMapItemWithContext(ctx context.Context, ServiceSid string, MapSid string, Key string, params *UpdateSyncMapItemParams) (*SyncV1SyncMapItem, error) { path := "/v1/Services/{ServiceSid}/Maps/{MapSid}/Items/{Key}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"MapSid"+"}", MapSid, -1) @@ -406,7 +430,7 @@ func (c *ApiService) UpdateSyncMapItem(ServiceSid string, MapSid string, Key str if params != nil && params.IfMatch != nil { headers["If-Match"] = *params.IfMatch } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/sync/v1/services_maps_permissions.go b/rest/sync/v1/services_maps_permissions.go index 6668be3a2..8f104ce7e 100644 --- a/rest/sync/v1/services_maps_permissions.go +++ b/rest/sync/v1/services_maps_permissions.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -25,6 +26,9 @@ import ( // Delete a specific Sync Map Permission. func (c *ApiService) DeleteSyncMapPermission(ServiceSid string, MapSid string, Identity string) error { + return c.DeleteSyncMapPermissionWithContext(context.TODO(), ServiceSid, MapSid, Identity) +} +func (c *ApiService) DeleteSyncMapPermissionWithContext(ctx context.Context, ServiceSid string, MapSid string, Identity string) error { path := "/v1/Services/{ServiceSid}/Maps/{MapSid}/Permissions/{Identity}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"MapSid"+"}", MapSid, -1) @@ -35,7 +39,7 @@ func (c *ApiService) DeleteSyncMapPermission(ServiceSid string, MapSid string, I "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -47,6 +51,9 @@ func (c *ApiService) DeleteSyncMapPermission(ServiceSid string, MapSid string, I // Fetch a specific Sync Map Permission. func (c *ApiService) FetchSyncMapPermission(ServiceSid string, MapSid string, Identity string) (*SyncV1SyncMapPermission, error) { + return c.FetchSyncMapPermissionWithContext(context.TODO(), ServiceSid, MapSid, Identity) +} +func (c *ApiService) FetchSyncMapPermissionWithContext(ctx context.Context, ServiceSid string, MapSid string, Identity string) (*SyncV1SyncMapPermission, error) { path := "/v1/Services/{ServiceSid}/Maps/{MapSid}/Permissions/{Identity}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"MapSid"+"}", MapSid, -1) @@ -57,7 +64,7 @@ func (c *ApiService) FetchSyncMapPermission(ServiceSid string, MapSid string, Id "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -91,6 +98,11 @@ func (params *ListSyncMapPermissionParams) SetLimit(Limit int) *ListSyncMapPermi // Retrieve a single page of SyncMapPermission records from the API. Request is executed immediately. func (c *ApiService) PageSyncMapPermission(ServiceSid string, MapSid string, params *ListSyncMapPermissionParams, pageToken, pageNumber string) (*ListSyncMapPermissionResponse, error) { + return c.PageSyncMapPermissionWithContext(context.TODO(), ServiceSid, MapSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of SyncMapPermission records from the API. Request is executed immediately. +func (c *ApiService) PageSyncMapPermissionWithContext(ctx context.Context, ServiceSid string, MapSid string, params *ListSyncMapPermissionParams, pageToken, pageNumber string) (*ListSyncMapPermissionResponse, error) { path := "/v1/Services/{ServiceSid}/Maps/{MapSid}/Permissions" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -112,7 +124,7 @@ func (c *ApiService) PageSyncMapPermission(ServiceSid string, MapSid string, par data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -129,7 +141,12 @@ func (c *ApiService) PageSyncMapPermission(ServiceSid string, MapSid string, par // Lists SyncMapPermission records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListSyncMapPermission(ServiceSid string, MapSid string, params *ListSyncMapPermissionParams) ([]SyncV1SyncMapPermission, error) { - response, errors := c.StreamSyncMapPermission(ServiceSid, MapSid, params) + return c.ListSyncMapPermissionWithContext(context.TODO(), ServiceSid, MapSid, params) +} + +// Lists SyncMapPermission records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListSyncMapPermissionWithContext(ctx context.Context, ServiceSid string, MapSid string, params *ListSyncMapPermissionParams) ([]SyncV1SyncMapPermission, error) { + response, errors := c.StreamSyncMapPermissionWithContext(ctx, ServiceSid, MapSid, params) records := make([]SyncV1SyncMapPermission, 0) for record := range response { @@ -145,6 +162,11 @@ func (c *ApiService) ListSyncMapPermission(ServiceSid string, MapSid string, par // Streams SyncMapPermission records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamSyncMapPermission(ServiceSid string, MapSid string, params *ListSyncMapPermissionParams) (chan SyncV1SyncMapPermission, chan error) { + return c.StreamSyncMapPermissionWithContext(context.TODO(), ServiceSid, MapSid, params) +} + +// Streams SyncMapPermission records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamSyncMapPermissionWithContext(ctx context.Context, ServiceSid string, MapSid string, params *ListSyncMapPermissionParams) (chan SyncV1SyncMapPermission, chan error) { if params == nil { params = &ListSyncMapPermissionParams{} } @@ -153,19 +175,19 @@ func (c *ApiService) StreamSyncMapPermission(ServiceSid string, MapSid string, p recordChannel := make(chan SyncV1SyncMapPermission, 1) errorChannel := make(chan error, 1) - response, err := c.PageSyncMapPermission(ServiceSid, MapSid, params, "", "") + response, err := c.PageSyncMapPermissionWithContext(ctx, ServiceSid, MapSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSyncMapPermission(response, params, recordChannel, errorChannel) + go c.streamSyncMapPermissionWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamSyncMapPermission(response *ListSyncMapPermissionResponse, params *ListSyncMapPermissionParams, recordChannel chan SyncV1SyncMapPermission, errorChannel chan error) { +func (c *ApiService) streamSyncMapPermissionWithContext(ctx context.Context, response *ListSyncMapPermissionResponse, params *ListSyncMapPermissionParams, recordChannel chan SyncV1SyncMapPermission, errorChannel chan error) { curRecord := 1 for response != nil { @@ -180,7 +202,7 @@ func (c *ApiService) streamSyncMapPermission(response *ListSyncMapPermissionResp } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSyncMapPermissionResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListSyncMapPermissionResponseWithContext) if err != nil { errorChannel <- err break @@ -195,11 +217,11 @@ func (c *ApiService) streamSyncMapPermission(response *ListSyncMapPermissionResp close(errorChannel) } -func (c *ApiService) getNextListSyncMapPermissionResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSyncMapPermissionResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -238,6 +260,9 @@ func (params *UpdateSyncMapPermissionParams) SetManage(Manage bool) *UpdateSyncM // Update an identity's access to a specific Sync Map. func (c *ApiService) UpdateSyncMapPermission(ServiceSid string, MapSid string, Identity string, params *UpdateSyncMapPermissionParams) (*SyncV1SyncMapPermission, error) { + return c.UpdateSyncMapPermissionWithContext(context.TODO(), ServiceSid, MapSid, Identity, params) +} +func (c *ApiService) UpdateSyncMapPermissionWithContext(ctx context.Context, ServiceSid string, MapSid string, Identity string, params *UpdateSyncMapPermissionParams) (*SyncV1SyncMapPermission, error) { path := "/v1/Services/{ServiceSid}/Maps/{MapSid}/Permissions/{Identity}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"MapSid"+"}", MapSid, -1) @@ -258,7 +283,7 @@ func (c *ApiService) UpdateSyncMapPermission(ServiceSid string, MapSid string, I data.Set("Manage", fmt.Sprint(*params.Manage)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/sync/v1/services_streams.go b/rest/sync/v1/services_streams.go index 1a187324a..f70657c07 100644 --- a/rest/sync/v1/services_streams.go +++ b/rest/sync/v1/services_streams.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -42,6 +43,9 @@ func (params *CreateSyncStreamParams) SetTtl(Ttl int) *CreateSyncStreamParams { // Create a new Stream. func (c *ApiService) CreateSyncStream(ServiceSid string, params *CreateSyncStreamParams) (*SyncV1SyncStream, error) { + return c.CreateSyncStreamWithContext(context.TODO(), ServiceSid, params) +} +func (c *ApiService) CreateSyncStreamWithContext(ctx context.Context, ServiceSid string, params *CreateSyncStreamParams) (*SyncV1SyncStream, error) { path := "/v1/Services/{ServiceSid}/Streams" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -57,7 +61,7 @@ func (c *ApiService) CreateSyncStream(ServiceSid string, params *CreateSyncStrea data.Set("Ttl", fmt.Sprint(*params.Ttl)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -74,6 +78,9 @@ func (c *ApiService) CreateSyncStream(ServiceSid string, params *CreateSyncStrea // Delete a specific Stream. func (c *ApiService) DeleteSyncStream(ServiceSid string, Sid string) error { + return c.DeleteSyncStreamWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) DeleteSyncStreamWithContext(ctx context.Context, ServiceSid string, Sid string) error { path := "/v1/Services/{ServiceSid}/Streams/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -83,7 +90,7 @@ func (c *ApiService) DeleteSyncStream(ServiceSid string, Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -95,6 +102,9 @@ func (c *ApiService) DeleteSyncStream(ServiceSid string, Sid string) error { // Fetch a specific Stream. func (c *ApiService) FetchSyncStream(ServiceSid string, Sid string) (*SyncV1SyncStream, error) { + return c.FetchSyncStreamWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) FetchSyncStreamWithContext(ctx context.Context, ServiceSid string, Sid string) (*SyncV1SyncStream, error) { path := "/v1/Services/{ServiceSid}/Streams/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -104,7 +114,7 @@ func (c *ApiService) FetchSyncStream(ServiceSid string, Sid string) (*SyncV1Sync "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -138,6 +148,11 @@ func (params *ListSyncStreamParams) SetLimit(Limit int) *ListSyncStreamParams { // Retrieve a single page of SyncStream records from the API. Request is executed immediately. func (c *ApiService) PageSyncStream(ServiceSid string, params *ListSyncStreamParams, pageToken, pageNumber string) (*ListSyncStreamResponse, error) { + return c.PageSyncStreamWithContext(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of SyncStream records from the API. Request is executed immediately. +func (c *ApiService) PageSyncStreamWithContext(ctx context.Context, ServiceSid string, params *ListSyncStreamParams, pageToken, pageNumber string) (*ListSyncStreamResponse, error) { path := "/v1/Services/{ServiceSid}/Streams" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -158,7 +173,7 @@ func (c *ApiService) PageSyncStream(ServiceSid string, params *ListSyncStreamPar data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -175,7 +190,12 @@ func (c *ApiService) PageSyncStream(ServiceSid string, params *ListSyncStreamPar // Lists SyncStream records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListSyncStream(ServiceSid string, params *ListSyncStreamParams) ([]SyncV1SyncStream, error) { - response, errors := c.StreamSyncStream(ServiceSid, params) + return c.ListSyncStreamWithContext(context.TODO(), ServiceSid, params) +} + +// Lists SyncStream records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListSyncStreamWithContext(ctx context.Context, ServiceSid string, params *ListSyncStreamParams) ([]SyncV1SyncStream, error) { + response, errors := c.StreamSyncStreamWithContext(ctx, ServiceSid, params) records := make([]SyncV1SyncStream, 0) for record := range response { @@ -191,6 +211,11 @@ func (c *ApiService) ListSyncStream(ServiceSid string, params *ListSyncStreamPar // Streams SyncStream records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamSyncStream(ServiceSid string, params *ListSyncStreamParams) (chan SyncV1SyncStream, chan error) { + return c.StreamSyncStreamWithContext(context.TODO(), ServiceSid, params) +} + +// Streams SyncStream records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamSyncStreamWithContext(ctx context.Context, ServiceSid string, params *ListSyncStreamParams) (chan SyncV1SyncStream, chan error) { if params == nil { params = &ListSyncStreamParams{} } @@ -199,19 +224,19 @@ func (c *ApiService) StreamSyncStream(ServiceSid string, params *ListSyncStreamP recordChannel := make(chan SyncV1SyncStream, 1) errorChannel := make(chan error, 1) - response, err := c.PageSyncStream(ServiceSid, params, "", "") + response, err := c.PageSyncStreamWithContext(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSyncStream(response, params, recordChannel, errorChannel) + go c.streamSyncStreamWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamSyncStream(response *ListSyncStreamResponse, params *ListSyncStreamParams, recordChannel chan SyncV1SyncStream, errorChannel chan error) { +func (c *ApiService) streamSyncStreamWithContext(ctx context.Context, response *ListSyncStreamResponse, params *ListSyncStreamParams, recordChannel chan SyncV1SyncStream, errorChannel chan error) { curRecord := 1 for response != nil { @@ -226,7 +251,7 @@ func (c *ApiService) streamSyncStream(response *ListSyncStreamResponse, params * } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSyncStreamResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListSyncStreamResponseWithContext) if err != nil { errorChannel <- err break @@ -241,11 +266,11 @@ func (c *ApiService) streamSyncStream(response *ListSyncStreamResponse, params * close(errorChannel) } -func (c *ApiService) getNextListSyncStreamResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSyncStreamResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -272,6 +297,9 @@ func (params *UpdateSyncStreamParams) SetTtl(Ttl int) *UpdateSyncStreamParams { // Update a specific Stream. func (c *ApiService) UpdateSyncStream(ServiceSid string, Sid string, params *UpdateSyncStreamParams) (*SyncV1SyncStream, error) { + return c.UpdateSyncStreamWithContext(context.TODO(), ServiceSid, Sid, params) +} +func (c *ApiService) UpdateSyncStreamWithContext(ctx context.Context, ServiceSid string, Sid string, params *UpdateSyncStreamParams) (*SyncV1SyncStream, error) { path := "/v1/Services/{ServiceSid}/Streams/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -285,7 +313,7 @@ func (c *ApiService) UpdateSyncStream(ServiceSid string, Sid string, params *Upd data.Set("Ttl", fmt.Sprint(*params.Ttl)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/sync/v1/services_streams_messages.go b/rest/sync/v1/services_streams_messages.go index a4c0cfa83..371520812 100644 --- a/rest/sync/v1/services_streams_messages.go +++ b/rest/sync/v1/services_streams_messages.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -33,6 +34,9 @@ func (params *CreateStreamMessageParams) SetData(Data map[string]interface{}) *C // Create a new Stream Message. func (c *ApiService) CreateStreamMessage(ServiceSid string, StreamSid string, params *CreateStreamMessageParams) (*SyncV1StreamMessage, error) { + return c.CreateStreamMessageWithContext(context.TODO(), ServiceSid, StreamSid, params) +} +func (c *ApiService) CreateStreamMessageWithContext(ctx context.Context, ServiceSid string, StreamSid string, params *CreateStreamMessageParams) (*SyncV1StreamMessage, error) { path := "/v1/Services/{ServiceSid}/Streams/{StreamSid}/Messages" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"StreamSid"+"}", StreamSid, -1) @@ -52,7 +56,7 @@ func (c *ApiService) CreateStreamMessage(ServiceSid string, StreamSid string, pa data.Set("Data", string(v)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/taskrouter/v1/api_service.go b/rest/taskrouter/v1/api_service.go index f4b51acdf..70a8d6400 100644 --- a/rest/taskrouter/v1/api_service.go +++ b/rest/taskrouter/v1/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://taskrouter.twilio.com", + } +} diff --git a/rest/taskrouter/v1/workspaces.go b/rest/taskrouter/v1/workspaces.go index 10455b47b..1d0528075 100644 --- a/rest/taskrouter/v1/workspaces.go +++ b/rest/taskrouter/v1/workspaces.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -64,8 +65,10 @@ func (params *CreateWorkspaceParams) SetPrioritizeQueueOrder(PrioritizeQueueOrde return params } -// func (c *ApiService) CreateWorkspace(params *CreateWorkspaceParams) (*TaskrouterV1Workspace, error) { + return c.CreateWorkspaceWithContext(context.TODO(), params) +} +func (c *ApiService) CreateWorkspaceWithContext(ctx context.Context, params *CreateWorkspaceParams) (*TaskrouterV1Workspace, error) { path := "/v1/Workspaces" data := url.Values{} @@ -92,7 +95,7 @@ func (c *ApiService) CreateWorkspace(params *CreateWorkspaceParams) (*Taskrouter data.Set("PrioritizeQueueOrder", fmt.Sprint(*params.PrioritizeQueueOrder)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -107,8 +110,10 @@ func (c *ApiService) CreateWorkspace(params *CreateWorkspaceParams) (*Taskrouter return ps, err } -// func (c *ApiService) DeleteWorkspace(Sid string) error { + return c.DeleteWorkspaceWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteWorkspaceWithContext(ctx context.Context, Sid string) error { path := "/v1/Workspaces/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -117,7 +122,7 @@ func (c *ApiService) DeleteWorkspace(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -127,8 +132,10 @@ func (c *ApiService) DeleteWorkspace(Sid string) error { return nil } -// func (c *ApiService) FetchWorkspace(Sid string) (*TaskrouterV1Workspace, error) { + return c.FetchWorkspaceWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchWorkspaceWithContext(ctx context.Context, Sid string) (*TaskrouterV1Workspace, error) { path := "/v1/Workspaces/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -137,7 +144,7 @@ func (c *ApiService) FetchWorkspace(Sid string) (*TaskrouterV1Workspace, error) "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -177,6 +184,11 @@ func (params *ListWorkspaceParams) SetLimit(Limit int) *ListWorkspaceParams { // Retrieve a single page of Workspace records from the API. Request is executed immediately. func (c *ApiService) PageWorkspace(params *ListWorkspaceParams, pageToken, pageNumber string) (*ListWorkspaceResponse, error) { + return c.PageWorkspaceWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Workspace records from the API. Request is executed immediately. +func (c *ApiService) PageWorkspaceWithContext(ctx context.Context, params *ListWorkspaceParams, pageToken, pageNumber string) (*ListWorkspaceResponse, error) { path := "/v1/Workspaces" data := url.Values{} @@ -198,7 +210,7 @@ func (c *ApiService) PageWorkspace(params *ListWorkspaceParams, pageToken, pageN data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -215,7 +227,12 @@ func (c *ApiService) PageWorkspace(params *ListWorkspaceParams, pageToken, pageN // Lists Workspace records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListWorkspace(params *ListWorkspaceParams) ([]TaskrouterV1Workspace, error) { - response, errors := c.StreamWorkspace(params) + return c.ListWorkspaceWithContext(context.TODO(), params) +} + +// Lists Workspace records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListWorkspaceWithContext(ctx context.Context, params *ListWorkspaceParams) ([]TaskrouterV1Workspace, error) { + response, errors := c.StreamWorkspaceWithContext(ctx, params) records := make([]TaskrouterV1Workspace, 0) for record := range response { @@ -231,6 +248,11 @@ func (c *ApiService) ListWorkspace(params *ListWorkspaceParams) ([]TaskrouterV1W // Streams Workspace records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamWorkspace(params *ListWorkspaceParams) (chan TaskrouterV1Workspace, chan error) { + return c.StreamWorkspaceWithContext(context.TODO(), params) +} + +// Streams Workspace records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamWorkspaceWithContext(ctx context.Context, params *ListWorkspaceParams) (chan TaskrouterV1Workspace, chan error) { if params == nil { params = &ListWorkspaceParams{} } @@ -239,19 +261,19 @@ func (c *ApiService) StreamWorkspace(params *ListWorkspaceParams) (chan Taskrout recordChannel := make(chan TaskrouterV1Workspace, 1) errorChannel := make(chan error, 1) - response, err := c.PageWorkspace(params, "", "") + response, err := c.PageWorkspaceWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamWorkspace(response, params, recordChannel, errorChannel) + go c.streamWorkspaceWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamWorkspace(response *ListWorkspaceResponse, params *ListWorkspaceParams, recordChannel chan TaskrouterV1Workspace, errorChannel chan error) { +func (c *ApiService) streamWorkspaceWithContext(ctx context.Context, response *ListWorkspaceResponse, params *ListWorkspaceParams, recordChannel chan TaskrouterV1Workspace, errorChannel chan error) { curRecord := 1 for response != nil { @@ -266,7 +288,7 @@ func (c *ApiService) streamWorkspace(response *ListWorkspaceResponse, params *Li } } - record, err := client.GetNext(c.baseURL, response, c.getNextListWorkspaceResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListWorkspaceResponseWithContext) if err != nil { errorChannel <- err break @@ -281,11 +303,11 @@ func (c *ApiService) streamWorkspace(response *ListWorkspaceResponse, params *Li close(errorChannel) } -func (c *ApiService) getNextListWorkspaceResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListWorkspaceResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -346,8 +368,10 @@ func (params *UpdateWorkspaceParams) SetPrioritizeQueueOrder(PrioritizeQueueOrde return params } -// func (c *ApiService) UpdateWorkspace(Sid string, params *UpdateWorkspaceParams) (*TaskrouterV1Workspace, error) { + return c.UpdateWorkspaceWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateWorkspaceWithContext(ctx context.Context, Sid string, params *UpdateWorkspaceParams) (*TaskrouterV1Workspace, error) { path := "/v1/Workspaces/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -378,7 +402,7 @@ func (c *ApiService) UpdateWorkspace(Sid string, params *UpdateWorkspaceParams) data.Set("PrioritizeQueueOrder", fmt.Sprint(*params.PrioritizeQueueOrder)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/taskrouter/v1/workspaces_activities.go b/rest/taskrouter/v1/workspaces_activities.go index e056d5e47..e2a515e41 100644 --- a/rest/taskrouter/v1/workspaces_activities.go +++ b/rest/taskrouter/v1/workspaces_activities.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -40,8 +41,10 @@ func (params *CreateActivityParams) SetAvailable(Available bool) *CreateActivity return params } -// func (c *ApiService) CreateActivity(WorkspaceSid string, params *CreateActivityParams) (*TaskrouterV1Activity, error) { + return c.CreateActivityWithContext(context.TODO(), WorkspaceSid, params) +} +func (c *ApiService) CreateActivityWithContext(ctx context.Context, WorkspaceSid string, params *CreateActivityParams) (*TaskrouterV1Activity, error) { path := "/v1/Workspaces/{WorkspaceSid}/Activities" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) @@ -57,7 +60,7 @@ func (c *ApiService) CreateActivity(WorkspaceSid string, params *CreateActivityP data.Set("Available", fmt.Sprint(*params.Available)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -72,8 +75,10 @@ func (c *ApiService) CreateActivity(WorkspaceSid string, params *CreateActivityP return ps, err } -// func (c *ApiService) DeleteActivity(WorkspaceSid string, Sid string) error { + return c.DeleteActivityWithContext(context.TODO(), WorkspaceSid, Sid) +} +func (c *ApiService) DeleteActivityWithContext(ctx context.Context, WorkspaceSid string, Sid string) error { path := "/v1/Workspaces/{WorkspaceSid}/Activities/{Sid}" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -83,7 +88,7 @@ func (c *ApiService) DeleteActivity(WorkspaceSid string, Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -93,8 +98,10 @@ func (c *ApiService) DeleteActivity(WorkspaceSid string, Sid string) error { return nil } -// func (c *ApiService) FetchActivity(WorkspaceSid string, Sid string) (*TaskrouterV1Activity, error) { + return c.FetchActivityWithContext(context.TODO(), WorkspaceSid, Sid) +} +func (c *ApiService) FetchActivityWithContext(ctx context.Context, WorkspaceSid string, Sid string) (*TaskrouterV1Activity, error) { path := "/v1/Workspaces/{WorkspaceSid}/Activities/{Sid}" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -104,7 +111,7 @@ func (c *ApiService) FetchActivity(WorkspaceSid string, Sid string) (*Taskrouter "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -150,6 +157,11 @@ func (params *ListActivityParams) SetLimit(Limit int) *ListActivityParams { // Retrieve a single page of Activity records from the API. Request is executed immediately. func (c *ApiService) PageActivity(WorkspaceSid string, params *ListActivityParams, pageToken, pageNumber string) (*ListActivityResponse, error) { + return c.PageActivityWithContext(context.TODO(), WorkspaceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Activity records from the API. Request is executed immediately. +func (c *ApiService) PageActivityWithContext(ctx context.Context, WorkspaceSid string, params *ListActivityParams, pageToken, pageNumber string) (*ListActivityResponse, error) { path := "/v1/Workspaces/{WorkspaceSid}/Activities" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) @@ -176,7 +188,7 @@ func (c *ApiService) PageActivity(WorkspaceSid string, params *ListActivityParam data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -193,7 +205,12 @@ func (c *ApiService) PageActivity(WorkspaceSid string, params *ListActivityParam // Lists Activity records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListActivity(WorkspaceSid string, params *ListActivityParams) ([]TaskrouterV1Activity, error) { - response, errors := c.StreamActivity(WorkspaceSid, params) + return c.ListActivityWithContext(context.TODO(), WorkspaceSid, params) +} + +// Lists Activity records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListActivityWithContext(ctx context.Context, WorkspaceSid string, params *ListActivityParams) ([]TaskrouterV1Activity, error) { + response, errors := c.StreamActivityWithContext(ctx, WorkspaceSid, params) records := make([]TaskrouterV1Activity, 0) for record := range response { @@ -209,6 +226,11 @@ func (c *ApiService) ListActivity(WorkspaceSid string, params *ListActivityParam // Streams Activity records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamActivity(WorkspaceSid string, params *ListActivityParams) (chan TaskrouterV1Activity, chan error) { + return c.StreamActivityWithContext(context.TODO(), WorkspaceSid, params) +} + +// Streams Activity records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamActivityWithContext(ctx context.Context, WorkspaceSid string, params *ListActivityParams) (chan TaskrouterV1Activity, chan error) { if params == nil { params = &ListActivityParams{} } @@ -217,19 +239,19 @@ func (c *ApiService) StreamActivity(WorkspaceSid string, params *ListActivityPar recordChannel := make(chan TaskrouterV1Activity, 1) errorChannel := make(chan error, 1) - response, err := c.PageActivity(WorkspaceSid, params, "", "") + response, err := c.PageActivityWithContext(ctx, WorkspaceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamActivity(response, params, recordChannel, errorChannel) + go c.streamActivityWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamActivity(response *ListActivityResponse, params *ListActivityParams, recordChannel chan TaskrouterV1Activity, errorChannel chan error) { +func (c *ApiService) streamActivityWithContext(ctx context.Context, response *ListActivityResponse, params *ListActivityParams, recordChannel chan TaskrouterV1Activity, errorChannel chan error) { curRecord := 1 for response != nil { @@ -244,7 +266,7 @@ func (c *ApiService) streamActivity(response *ListActivityResponse, params *List } } - record, err := client.GetNext(c.baseURL, response, c.getNextListActivityResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListActivityResponseWithContext) if err != nil { errorChannel <- err break @@ -259,11 +281,11 @@ func (c *ApiService) streamActivity(response *ListActivityResponse, params *List close(errorChannel) } -func (c *ApiService) getNextListActivityResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListActivityResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -288,8 +310,10 @@ func (params *UpdateActivityParams) SetFriendlyName(FriendlyName string) *Update return params } -// func (c *ApiService) UpdateActivity(WorkspaceSid string, Sid string, params *UpdateActivityParams) (*TaskrouterV1Activity, error) { + return c.UpdateActivityWithContext(context.TODO(), WorkspaceSid, Sid, params) +} +func (c *ApiService) UpdateActivityWithContext(ctx context.Context, WorkspaceSid string, Sid string, params *UpdateActivityParams) (*TaskrouterV1Activity, error) { path := "/v1/Workspaces/{WorkspaceSid}/Activities/{Sid}" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -303,7 +327,7 @@ func (c *ApiService) UpdateActivity(WorkspaceSid string, Sid string, params *Upd data.Set("FriendlyName", *params.FriendlyName) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/taskrouter/v1/workspaces_cumulative_statistics.go b/rest/taskrouter/v1/workspaces_cumulative_statistics.go index 2ebf39d3a..9e3c9761d 100644 --- a/rest/taskrouter/v1/workspaces_cumulative_statistics.go +++ b/rest/taskrouter/v1/workspaces_cumulative_statistics.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -57,8 +58,10 @@ func (params *FetchWorkspaceCumulativeStatisticsParams) SetSplitByWaitTime(Split return params } -// func (c *ApiService) FetchWorkspaceCumulativeStatistics(WorkspaceSid string, params *FetchWorkspaceCumulativeStatisticsParams) (*TaskrouterV1WorkspaceCumulativeStatistics, error) { + return c.FetchWorkspaceCumulativeStatisticsWithContext(context.TODO(), WorkspaceSid, params) +} +func (c *ApiService) FetchWorkspaceCumulativeStatisticsWithContext(ctx context.Context, WorkspaceSid string, params *FetchWorkspaceCumulativeStatisticsParams) (*TaskrouterV1WorkspaceCumulativeStatistics, error) { path := "/v1/Workspaces/{WorkspaceSid}/CumulativeStatistics" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) @@ -83,7 +86,7 @@ func (c *ApiService) FetchWorkspaceCumulativeStatistics(WorkspaceSid string, par data.Set("SplitByWaitTime", *params.SplitByWaitTime) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/taskrouter/v1/workspaces_events.go b/rest/taskrouter/v1/workspaces_events.go index c66a5bb0f..a837d61b0 100644 --- a/rest/taskrouter/v1/workspaces_events.go +++ b/rest/taskrouter/v1/workspaces_events.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -24,8 +25,10 @@ import ( "github.com/twilio/twilio-go/client" ) -// func (c *ApiService) FetchEvent(WorkspaceSid string, Sid string) (*TaskrouterV1Event, error) { + return c.FetchEventWithContext(context.TODO(), WorkspaceSid, Sid) +} +func (c *ApiService) FetchEventWithContext(ctx context.Context, WorkspaceSid string, Sid string) (*TaskrouterV1Event, error) { path := "/v1/Workspaces/{WorkspaceSid}/Events/{Sid}" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -35,7 +38,7 @@ func (c *ApiService) FetchEvent(WorkspaceSid string, Sid string) (*TaskrouterV1E "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -135,6 +138,11 @@ func (params *ListEventParams) SetLimit(Limit int) *ListEventParams { // Retrieve a single page of Event records from the API. Request is executed immediately. func (c *ApiService) PageEvent(WorkspaceSid string, params *ListEventParams, pageToken, pageNumber string) (*ListEventResponse, error) { + return c.PageEventWithContext(context.TODO(), WorkspaceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Event records from the API. Request is executed immediately. +func (c *ApiService) PageEventWithContext(ctx context.Context, WorkspaceSid string, params *ListEventParams, pageToken, pageNumber string) (*ListEventResponse, error) { path := "/v1/Workspaces/{WorkspaceSid}/Events" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) @@ -188,7 +196,7 @@ func (c *ApiService) PageEvent(WorkspaceSid string, params *ListEventParams, pag data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -205,7 +213,12 @@ func (c *ApiService) PageEvent(WorkspaceSid string, params *ListEventParams, pag // Lists Event records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListEvent(WorkspaceSid string, params *ListEventParams) ([]TaskrouterV1Event, error) { - response, errors := c.StreamEvent(WorkspaceSid, params) + return c.ListEventWithContext(context.TODO(), WorkspaceSid, params) +} + +// Lists Event records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListEventWithContext(ctx context.Context, WorkspaceSid string, params *ListEventParams) ([]TaskrouterV1Event, error) { + response, errors := c.StreamEventWithContext(ctx, WorkspaceSid, params) records := make([]TaskrouterV1Event, 0) for record := range response { @@ -221,6 +234,11 @@ func (c *ApiService) ListEvent(WorkspaceSid string, params *ListEventParams) ([] // Streams Event records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamEvent(WorkspaceSid string, params *ListEventParams) (chan TaskrouterV1Event, chan error) { + return c.StreamEventWithContext(context.TODO(), WorkspaceSid, params) +} + +// Streams Event records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamEventWithContext(ctx context.Context, WorkspaceSid string, params *ListEventParams) (chan TaskrouterV1Event, chan error) { if params == nil { params = &ListEventParams{} } @@ -229,19 +247,19 @@ func (c *ApiService) StreamEvent(WorkspaceSid string, params *ListEventParams) ( recordChannel := make(chan TaskrouterV1Event, 1) errorChannel := make(chan error, 1) - response, err := c.PageEvent(WorkspaceSid, params, "", "") + response, err := c.PageEventWithContext(ctx, WorkspaceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamEvent(response, params, recordChannel, errorChannel) + go c.streamEventWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamEvent(response *ListEventResponse, params *ListEventParams, recordChannel chan TaskrouterV1Event, errorChannel chan error) { +func (c *ApiService) streamEventWithContext(ctx context.Context, response *ListEventResponse, params *ListEventParams, recordChannel chan TaskrouterV1Event, errorChannel chan error) { curRecord := 1 for response != nil { @@ -256,7 +274,7 @@ func (c *ApiService) streamEvent(response *ListEventResponse, params *ListEventP } } - record, err := client.GetNext(c.baseURL, response, c.getNextListEventResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListEventResponseWithContext) if err != nil { errorChannel <- err break @@ -271,11 +289,11 @@ func (c *ApiService) streamEvent(response *ListEventResponse, params *ListEventP close(errorChannel) } -func (c *ApiService) getNextListEventResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListEventResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/taskrouter/v1/workspaces_real_time_statistics.go b/rest/taskrouter/v1/workspaces_real_time_statistics.go index e4de938fc..82043c492 100644 --- a/rest/taskrouter/v1/workspaces_real_time_statistics.go +++ b/rest/taskrouter/v1/workspaces_real_time_statistics.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -31,8 +32,10 @@ func (params *FetchWorkspaceRealTimeStatisticsParams) SetTaskChannel(TaskChannel return params } -// func (c *ApiService) FetchWorkspaceRealTimeStatistics(WorkspaceSid string, params *FetchWorkspaceRealTimeStatisticsParams) (*TaskrouterV1WorkspaceRealTimeStatistics, error) { + return c.FetchWorkspaceRealTimeStatisticsWithContext(context.TODO(), WorkspaceSid, params) +} +func (c *ApiService) FetchWorkspaceRealTimeStatisticsWithContext(ctx context.Context, WorkspaceSid string, params *FetchWorkspaceRealTimeStatisticsParams) (*TaskrouterV1WorkspaceRealTimeStatistics, error) { path := "/v1/Workspaces/{WorkspaceSid}/RealTimeStatistics" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) @@ -45,7 +48,7 @@ func (c *ApiService) FetchWorkspaceRealTimeStatistics(WorkspaceSid string, param data.Set("TaskChannel", *params.TaskChannel) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/taskrouter/v1/workspaces_statistics.go b/rest/taskrouter/v1/workspaces_statistics.go index c1df80e2a..a3ff54a85 100644 --- a/rest/taskrouter/v1/workspaces_statistics.go +++ b/rest/taskrouter/v1/workspaces_statistics.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -57,8 +58,10 @@ func (params *FetchWorkspaceStatisticsParams) SetSplitByWaitTime(SplitByWaitTime return params } -// func (c *ApiService) FetchWorkspaceStatistics(WorkspaceSid string, params *FetchWorkspaceStatisticsParams) (*TaskrouterV1WorkspaceStatistics, error) { + return c.FetchWorkspaceStatisticsWithContext(context.TODO(), WorkspaceSid, params) +} +func (c *ApiService) FetchWorkspaceStatisticsWithContext(ctx context.Context, WorkspaceSid string, params *FetchWorkspaceStatisticsParams) (*TaskrouterV1WorkspaceStatistics, error) { path := "/v1/Workspaces/{WorkspaceSid}/Statistics" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) @@ -83,7 +86,7 @@ func (c *ApiService) FetchWorkspaceStatistics(WorkspaceSid string, params *Fetch data.Set("SplitByWaitTime", *params.SplitByWaitTime) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/taskrouter/v1/workspaces_task_channels.go b/rest/taskrouter/v1/workspaces_task_channels.go index 10ee10e27..cc7c58640 100644 --- a/rest/taskrouter/v1/workspaces_task_channels.go +++ b/rest/taskrouter/v1/workspaces_task_channels.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -46,8 +47,10 @@ func (params *CreateTaskChannelParams) SetChannelOptimizedRouting(ChannelOptimiz return params } -// func (c *ApiService) CreateTaskChannel(WorkspaceSid string, params *CreateTaskChannelParams) (*TaskrouterV1TaskChannel, error) { + return c.CreateTaskChannelWithContext(context.TODO(), WorkspaceSid, params) +} +func (c *ApiService) CreateTaskChannelWithContext(ctx context.Context, WorkspaceSid string, params *CreateTaskChannelParams) (*TaskrouterV1TaskChannel, error) { path := "/v1/Workspaces/{WorkspaceSid}/TaskChannels" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) @@ -66,7 +69,7 @@ func (c *ApiService) CreateTaskChannel(WorkspaceSid string, params *CreateTaskCh data.Set("ChannelOptimizedRouting", fmt.Sprint(*params.ChannelOptimizedRouting)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -81,8 +84,10 @@ func (c *ApiService) CreateTaskChannel(WorkspaceSid string, params *CreateTaskCh return ps, err } -// func (c *ApiService) DeleteTaskChannel(WorkspaceSid string, Sid string) error { + return c.DeleteTaskChannelWithContext(context.TODO(), WorkspaceSid, Sid) +} +func (c *ApiService) DeleteTaskChannelWithContext(ctx context.Context, WorkspaceSid string, Sid string) error { path := "/v1/Workspaces/{WorkspaceSid}/TaskChannels/{Sid}" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -92,7 +97,7 @@ func (c *ApiService) DeleteTaskChannel(WorkspaceSid string, Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -102,8 +107,10 @@ func (c *ApiService) DeleteTaskChannel(WorkspaceSid string, Sid string) error { return nil } -// func (c *ApiService) FetchTaskChannel(WorkspaceSid string, Sid string) (*TaskrouterV1TaskChannel, error) { + return c.FetchTaskChannelWithContext(context.TODO(), WorkspaceSid, Sid) +} +func (c *ApiService) FetchTaskChannelWithContext(ctx context.Context, WorkspaceSid string, Sid string) (*TaskrouterV1TaskChannel, error) { path := "/v1/Workspaces/{WorkspaceSid}/TaskChannels/{Sid}" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -113,7 +120,7 @@ func (c *ApiService) FetchTaskChannel(WorkspaceSid string, Sid string) (*Taskrou "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -147,6 +154,11 @@ func (params *ListTaskChannelParams) SetLimit(Limit int) *ListTaskChannelParams // Retrieve a single page of TaskChannel records from the API. Request is executed immediately. func (c *ApiService) PageTaskChannel(WorkspaceSid string, params *ListTaskChannelParams, pageToken, pageNumber string) (*ListTaskChannelResponse, error) { + return c.PageTaskChannelWithContext(context.TODO(), WorkspaceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of TaskChannel records from the API. Request is executed immediately. +func (c *ApiService) PageTaskChannelWithContext(ctx context.Context, WorkspaceSid string, params *ListTaskChannelParams, pageToken, pageNumber string) (*ListTaskChannelResponse, error) { path := "/v1/Workspaces/{WorkspaceSid}/TaskChannels" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) @@ -167,7 +179,7 @@ func (c *ApiService) PageTaskChannel(WorkspaceSid string, params *ListTaskChanne data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -184,7 +196,12 @@ func (c *ApiService) PageTaskChannel(WorkspaceSid string, params *ListTaskChanne // Lists TaskChannel records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListTaskChannel(WorkspaceSid string, params *ListTaskChannelParams) ([]TaskrouterV1TaskChannel, error) { - response, errors := c.StreamTaskChannel(WorkspaceSid, params) + return c.ListTaskChannelWithContext(context.TODO(), WorkspaceSid, params) +} + +// Lists TaskChannel records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListTaskChannelWithContext(ctx context.Context, WorkspaceSid string, params *ListTaskChannelParams) ([]TaskrouterV1TaskChannel, error) { + response, errors := c.StreamTaskChannelWithContext(ctx, WorkspaceSid, params) records := make([]TaskrouterV1TaskChannel, 0) for record := range response { @@ -200,6 +217,11 @@ func (c *ApiService) ListTaskChannel(WorkspaceSid string, params *ListTaskChanne // Streams TaskChannel records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamTaskChannel(WorkspaceSid string, params *ListTaskChannelParams) (chan TaskrouterV1TaskChannel, chan error) { + return c.StreamTaskChannelWithContext(context.TODO(), WorkspaceSid, params) +} + +// Streams TaskChannel records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamTaskChannelWithContext(ctx context.Context, WorkspaceSid string, params *ListTaskChannelParams) (chan TaskrouterV1TaskChannel, chan error) { if params == nil { params = &ListTaskChannelParams{} } @@ -208,19 +230,19 @@ func (c *ApiService) StreamTaskChannel(WorkspaceSid string, params *ListTaskChan recordChannel := make(chan TaskrouterV1TaskChannel, 1) errorChannel := make(chan error, 1) - response, err := c.PageTaskChannel(WorkspaceSid, params, "", "") + response, err := c.PageTaskChannelWithContext(ctx, WorkspaceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamTaskChannel(response, params, recordChannel, errorChannel) + go c.streamTaskChannelWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamTaskChannel(response *ListTaskChannelResponse, params *ListTaskChannelParams, recordChannel chan TaskrouterV1TaskChannel, errorChannel chan error) { +func (c *ApiService) streamTaskChannelWithContext(ctx context.Context, response *ListTaskChannelResponse, params *ListTaskChannelParams, recordChannel chan TaskrouterV1TaskChannel, errorChannel chan error) { curRecord := 1 for response != nil { @@ -235,7 +257,7 @@ func (c *ApiService) streamTaskChannel(response *ListTaskChannelResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListTaskChannelResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListTaskChannelResponseWithContext) if err != nil { errorChannel <- err break @@ -250,11 +272,11 @@ func (c *ApiService) streamTaskChannel(response *ListTaskChannelResponse, params close(errorChannel) } -func (c *ApiService) getNextListTaskChannelResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListTaskChannelResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -285,8 +307,10 @@ func (params *UpdateTaskChannelParams) SetChannelOptimizedRouting(ChannelOptimiz return params } -// func (c *ApiService) UpdateTaskChannel(WorkspaceSid string, Sid string, params *UpdateTaskChannelParams) (*TaskrouterV1TaskChannel, error) { + return c.UpdateTaskChannelWithContext(context.TODO(), WorkspaceSid, Sid, params) +} +func (c *ApiService) UpdateTaskChannelWithContext(ctx context.Context, WorkspaceSid string, Sid string, params *UpdateTaskChannelParams) (*TaskrouterV1TaskChannel, error) { path := "/v1/Workspaces/{WorkspaceSid}/TaskChannels/{Sid}" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -303,7 +327,7 @@ func (c *ApiService) UpdateTaskChannel(WorkspaceSid string, Sid string, params * data.Set("ChannelOptimizedRouting", fmt.Sprint(*params.ChannelOptimizedRouting)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/taskrouter/v1/workspaces_task_queues.go b/rest/taskrouter/v1/workspaces_task_queues.go index 7e1fae8df..51ac706ab 100644 --- a/rest/taskrouter/v1/workspaces_task_queues.go +++ b/rest/taskrouter/v1/workspaces_task_queues.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -64,8 +65,10 @@ func (params *CreateTaskQueueParams) SetAssignmentActivitySid(AssignmentActivity return params } -// func (c *ApiService) CreateTaskQueue(WorkspaceSid string, params *CreateTaskQueueParams) (*TaskrouterV1TaskQueue, error) { + return c.CreateTaskQueueWithContext(context.TODO(), WorkspaceSid, params) +} +func (c *ApiService) CreateTaskQueueWithContext(ctx context.Context, WorkspaceSid string, params *CreateTaskQueueParams) (*TaskrouterV1TaskQueue, error) { path := "/v1/Workspaces/{WorkspaceSid}/TaskQueues" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) @@ -93,7 +96,7 @@ func (c *ApiService) CreateTaskQueue(WorkspaceSid string, params *CreateTaskQueu data.Set("AssignmentActivitySid", *params.AssignmentActivitySid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -108,8 +111,10 @@ func (c *ApiService) CreateTaskQueue(WorkspaceSid string, params *CreateTaskQueu return ps, err } -// func (c *ApiService) DeleteTaskQueue(WorkspaceSid string, Sid string) error { + return c.DeleteTaskQueueWithContext(context.TODO(), WorkspaceSid, Sid) +} +func (c *ApiService) DeleteTaskQueueWithContext(ctx context.Context, WorkspaceSid string, Sid string) error { path := "/v1/Workspaces/{WorkspaceSid}/TaskQueues/{Sid}" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -119,7 +124,7 @@ func (c *ApiService) DeleteTaskQueue(WorkspaceSid string, Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -129,8 +134,10 @@ func (c *ApiService) DeleteTaskQueue(WorkspaceSid string, Sid string) error { return nil } -// func (c *ApiService) FetchTaskQueue(WorkspaceSid string, Sid string) (*TaskrouterV1TaskQueue, error) { + return c.FetchTaskQueueWithContext(context.TODO(), WorkspaceSid, Sid) +} +func (c *ApiService) FetchTaskQueueWithContext(ctx context.Context, WorkspaceSid string, Sid string) (*TaskrouterV1TaskQueue, error) { path := "/v1/Workspaces/{WorkspaceSid}/TaskQueues/{Sid}" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -140,7 +147,7 @@ func (c *ApiService) FetchTaskQueue(WorkspaceSid string, Sid string) (*Taskroute "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -198,6 +205,11 @@ func (params *ListTaskQueueParams) SetLimit(Limit int) *ListTaskQueueParams { // Retrieve a single page of TaskQueue records from the API. Request is executed immediately. func (c *ApiService) PageTaskQueue(WorkspaceSid string, params *ListTaskQueueParams, pageToken, pageNumber string) (*ListTaskQueueResponse, error) { + return c.PageTaskQueueWithContext(context.TODO(), WorkspaceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of TaskQueue records from the API. Request is executed immediately. +func (c *ApiService) PageTaskQueueWithContext(ctx context.Context, WorkspaceSid string, params *ListTaskQueueParams, pageToken, pageNumber string) (*ListTaskQueueResponse, error) { path := "/v1/Workspaces/{WorkspaceSid}/TaskQueues" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) @@ -230,7 +242,7 @@ func (c *ApiService) PageTaskQueue(WorkspaceSid string, params *ListTaskQueuePar data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -247,7 +259,12 @@ func (c *ApiService) PageTaskQueue(WorkspaceSid string, params *ListTaskQueuePar // Lists TaskQueue records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListTaskQueue(WorkspaceSid string, params *ListTaskQueueParams) ([]TaskrouterV1TaskQueue, error) { - response, errors := c.StreamTaskQueue(WorkspaceSid, params) + return c.ListTaskQueueWithContext(context.TODO(), WorkspaceSid, params) +} + +// Lists TaskQueue records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListTaskQueueWithContext(ctx context.Context, WorkspaceSid string, params *ListTaskQueueParams) ([]TaskrouterV1TaskQueue, error) { + response, errors := c.StreamTaskQueueWithContext(ctx, WorkspaceSid, params) records := make([]TaskrouterV1TaskQueue, 0) for record := range response { @@ -263,6 +280,11 @@ func (c *ApiService) ListTaskQueue(WorkspaceSid string, params *ListTaskQueuePar // Streams TaskQueue records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamTaskQueue(WorkspaceSid string, params *ListTaskQueueParams) (chan TaskrouterV1TaskQueue, chan error) { + return c.StreamTaskQueueWithContext(context.TODO(), WorkspaceSid, params) +} + +// Streams TaskQueue records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamTaskQueueWithContext(ctx context.Context, WorkspaceSid string, params *ListTaskQueueParams) (chan TaskrouterV1TaskQueue, chan error) { if params == nil { params = &ListTaskQueueParams{} } @@ -271,19 +293,19 @@ func (c *ApiService) StreamTaskQueue(WorkspaceSid string, params *ListTaskQueueP recordChannel := make(chan TaskrouterV1TaskQueue, 1) errorChannel := make(chan error, 1) - response, err := c.PageTaskQueue(WorkspaceSid, params, "", "") + response, err := c.PageTaskQueueWithContext(ctx, WorkspaceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamTaskQueue(response, params, recordChannel, errorChannel) + go c.streamTaskQueueWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamTaskQueue(response *ListTaskQueueResponse, params *ListTaskQueueParams, recordChannel chan TaskrouterV1TaskQueue, errorChannel chan error) { +func (c *ApiService) streamTaskQueueWithContext(ctx context.Context, response *ListTaskQueueResponse, params *ListTaskQueueParams, recordChannel chan TaskrouterV1TaskQueue, errorChannel chan error) { curRecord := 1 for response != nil { @@ -298,7 +320,7 @@ func (c *ApiService) streamTaskQueue(response *ListTaskQueueResponse, params *Li } } - record, err := client.GetNext(c.baseURL, response, c.getNextListTaskQueueResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListTaskQueueResponseWithContext) if err != nil { errorChannel <- err break @@ -313,11 +335,11 @@ func (c *ApiService) streamTaskQueue(response *ListTaskQueueResponse, params *Li close(errorChannel) } -func (c *ApiService) getNextListTaskQueueResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListTaskQueueResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -372,8 +394,10 @@ func (params *UpdateTaskQueueParams) SetTaskOrder(TaskOrder string) *UpdateTaskQ return params } -// func (c *ApiService) UpdateTaskQueue(WorkspaceSid string, Sid string, params *UpdateTaskQueueParams) (*TaskrouterV1TaskQueue, error) { + return c.UpdateTaskQueueWithContext(context.TODO(), WorkspaceSid, Sid, params) +} +func (c *ApiService) UpdateTaskQueueWithContext(ctx context.Context, WorkspaceSid string, Sid string, params *UpdateTaskQueueParams) (*TaskrouterV1TaskQueue, error) { path := "/v1/Workspaces/{WorkspaceSid}/TaskQueues/{Sid}" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -402,7 +426,7 @@ func (c *ApiService) UpdateTaskQueue(WorkspaceSid string, Sid string, params *Up data.Set("TaskOrder", fmt.Sprint(*params.TaskOrder)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/taskrouter/v1/workspaces_task_queues_cumulative_statistics.go b/rest/taskrouter/v1/workspaces_task_queues_cumulative_statistics.go index cf9b44f7c..9e1290e2e 100644 --- a/rest/taskrouter/v1/workspaces_task_queues_cumulative_statistics.go +++ b/rest/taskrouter/v1/workspaces_task_queues_cumulative_statistics.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -57,8 +58,10 @@ func (params *FetchTaskQueueCumulativeStatisticsParams) SetSplitByWaitTime(Split return params } -// func (c *ApiService) FetchTaskQueueCumulativeStatistics(WorkspaceSid string, TaskQueueSid string, params *FetchTaskQueueCumulativeStatisticsParams) (*TaskrouterV1TaskQueueCumulativeStatistics, error) { + return c.FetchTaskQueueCumulativeStatisticsWithContext(context.TODO(), WorkspaceSid, TaskQueueSid, params) +} +func (c *ApiService) FetchTaskQueueCumulativeStatisticsWithContext(ctx context.Context, WorkspaceSid string, TaskQueueSid string, params *FetchTaskQueueCumulativeStatisticsParams) (*TaskrouterV1TaskQueueCumulativeStatistics, error) { path := "/v1/Workspaces/{WorkspaceSid}/TaskQueues/{TaskQueueSid}/CumulativeStatistics" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) path = strings.Replace(path, "{"+"TaskQueueSid"+"}", TaskQueueSid, -1) @@ -84,7 +87,7 @@ func (c *ApiService) FetchTaskQueueCumulativeStatistics(WorkspaceSid string, Tas data.Set("SplitByWaitTime", *params.SplitByWaitTime) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/taskrouter/v1/workspaces_task_queues_real_time_statistics.go b/rest/taskrouter/v1/workspaces_task_queues_real_time_statistics.go index f024b24e3..ed92cf658 100644 --- a/rest/taskrouter/v1/workspaces_task_queues_real_time_statistics.go +++ b/rest/taskrouter/v1/workspaces_task_queues_real_time_statistics.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -33,6 +34,9 @@ func (params *CreateTaskQueueBulkRealTimeStatisticsParams) SetBody(Body map[stri // Fetch a Task Queue Real Time Statistics in bulk for the array of TaskQueue SIDs, support upto 50 in a request. func (c *ApiService) CreateTaskQueueBulkRealTimeStatistics(WorkspaceSid string, params *CreateTaskQueueBulkRealTimeStatisticsParams) (*TaskrouterV1TaskQueueBulkRealTimeStatistics, error) { + return c.CreateTaskQueueBulkRealTimeStatisticsWithContext(context.TODO(), WorkspaceSid, params) +} +func (c *ApiService) CreateTaskQueueBulkRealTimeStatisticsWithContext(ctx context.Context, WorkspaceSid string, params *CreateTaskQueueBulkRealTimeStatisticsParams) (*TaskrouterV1TaskQueueBulkRealTimeStatistics, error) { path := "/v1/Workspaces/{WorkspaceSid}/TaskQueues/RealTimeStatistics" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) @@ -50,7 +54,7 @@ func (c *ApiService) CreateTaskQueueBulkRealTimeStatistics(WorkspaceSid string, body = b } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers, body...) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers, body...) if err != nil { return nil, err } @@ -76,8 +80,10 @@ func (params *FetchTaskQueueRealTimeStatisticsParams) SetTaskChannel(TaskChannel return params } -// func (c *ApiService) FetchTaskQueueRealTimeStatistics(WorkspaceSid string, TaskQueueSid string, params *FetchTaskQueueRealTimeStatisticsParams) (*TaskrouterV1TaskQueueRealTimeStatistics, error) { + return c.FetchTaskQueueRealTimeStatisticsWithContext(context.TODO(), WorkspaceSid, TaskQueueSid, params) +} +func (c *ApiService) FetchTaskQueueRealTimeStatisticsWithContext(ctx context.Context, WorkspaceSid string, TaskQueueSid string, params *FetchTaskQueueRealTimeStatisticsParams) (*TaskrouterV1TaskQueueRealTimeStatistics, error) { path := "/v1/Workspaces/{WorkspaceSid}/TaskQueues/{TaskQueueSid}/RealTimeStatistics" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) path = strings.Replace(path, "{"+"TaskQueueSid"+"}", TaskQueueSid, -1) @@ -91,7 +97,7 @@ func (c *ApiService) FetchTaskQueueRealTimeStatistics(WorkspaceSid string, TaskQ data.Set("TaskChannel", *params.TaskChannel) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/taskrouter/v1/workspaces_task_queues_statistics.go b/rest/taskrouter/v1/workspaces_task_queues_statistics.go index c70d5f854..694c832ce 100644 --- a/rest/taskrouter/v1/workspaces_task_queues_statistics.go +++ b/rest/taskrouter/v1/workspaces_task_queues_statistics.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -59,8 +60,10 @@ func (params *FetchTaskQueueStatisticsParams) SetSplitByWaitTime(SplitByWaitTime return params } -// func (c *ApiService) FetchTaskQueueStatistics(WorkspaceSid string, TaskQueueSid string, params *FetchTaskQueueStatisticsParams) (*TaskrouterV1TaskQueueStatistics, error) { + return c.FetchTaskQueueStatisticsWithContext(context.TODO(), WorkspaceSid, TaskQueueSid, params) +} +func (c *ApiService) FetchTaskQueueStatisticsWithContext(ctx context.Context, WorkspaceSid string, TaskQueueSid string, params *FetchTaskQueueStatisticsParams) (*TaskrouterV1TaskQueueStatistics, error) { path := "/v1/Workspaces/{WorkspaceSid}/TaskQueues/{TaskQueueSid}/Statistics" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) path = strings.Replace(path, "{"+"TaskQueueSid"+"}", TaskQueueSid, -1) @@ -86,7 +89,7 @@ func (c *ApiService) FetchTaskQueueStatistics(WorkspaceSid string, TaskQueueSid data.Set("SplitByWaitTime", *params.SplitByWaitTime) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -156,6 +159,11 @@ func (params *ListTaskQueuesStatisticsParams) SetLimit(Limit int) *ListTaskQueue // Retrieve a single page of TaskQueuesStatistics records from the API. Request is executed immediately. func (c *ApiService) PageTaskQueuesStatistics(WorkspaceSid string, params *ListTaskQueuesStatisticsParams, pageToken, pageNumber string) (*ListTaskQueuesStatisticsResponse, error) { + return c.PageTaskQueuesStatisticsWithContext(context.TODO(), WorkspaceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of TaskQueuesStatistics records from the API. Request is executed immediately. +func (c *ApiService) PageTaskQueuesStatisticsWithContext(ctx context.Context, WorkspaceSid string, params *ListTaskQueuesStatisticsParams, pageToken, pageNumber string) (*ListTaskQueuesStatisticsResponse, error) { path := "/v1/Workspaces/{WorkspaceSid}/TaskQueues/Statistics" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) @@ -194,7 +202,7 @@ func (c *ApiService) PageTaskQueuesStatistics(WorkspaceSid string, params *ListT data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -211,7 +219,12 @@ func (c *ApiService) PageTaskQueuesStatistics(WorkspaceSid string, params *ListT // Lists TaskQueuesStatistics records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListTaskQueuesStatistics(WorkspaceSid string, params *ListTaskQueuesStatisticsParams) ([]TaskrouterV1TaskQueuesStatistics, error) { - response, errors := c.StreamTaskQueuesStatistics(WorkspaceSid, params) + return c.ListTaskQueuesStatisticsWithContext(context.TODO(), WorkspaceSid, params) +} + +// Lists TaskQueuesStatistics records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListTaskQueuesStatisticsWithContext(ctx context.Context, WorkspaceSid string, params *ListTaskQueuesStatisticsParams) ([]TaskrouterV1TaskQueuesStatistics, error) { + response, errors := c.StreamTaskQueuesStatisticsWithContext(ctx, WorkspaceSid, params) records := make([]TaskrouterV1TaskQueuesStatistics, 0) for record := range response { @@ -227,6 +240,11 @@ func (c *ApiService) ListTaskQueuesStatistics(WorkspaceSid string, params *ListT // Streams TaskQueuesStatistics records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamTaskQueuesStatistics(WorkspaceSid string, params *ListTaskQueuesStatisticsParams) (chan TaskrouterV1TaskQueuesStatistics, chan error) { + return c.StreamTaskQueuesStatisticsWithContext(context.TODO(), WorkspaceSid, params) +} + +// Streams TaskQueuesStatistics records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamTaskQueuesStatisticsWithContext(ctx context.Context, WorkspaceSid string, params *ListTaskQueuesStatisticsParams) (chan TaskrouterV1TaskQueuesStatistics, chan error) { if params == nil { params = &ListTaskQueuesStatisticsParams{} } @@ -235,19 +253,19 @@ func (c *ApiService) StreamTaskQueuesStatistics(WorkspaceSid string, params *Lis recordChannel := make(chan TaskrouterV1TaskQueuesStatistics, 1) errorChannel := make(chan error, 1) - response, err := c.PageTaskQueuesStatistics(WorkspaceSid, params, "", "") + response, err := c.PageTaskQueuesStatisticsWithContext(ctx, WorkspaceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamTaskQueuesStatistics(response, params, recordChannel, errorChannel) + go c.streamTaskQueuesStatisticsWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamTaskQueuesStatistics(response *ListTaskQueuesStatisticsResponse, params *ListTaskQueuesStatisticsParams, recordChannel chan TaskrouterV1TaskQueuesStatistics, errorChannel chan error) { +func (c *ApiService) streamTaskQueuesStatisticsWithContext(ctx context.Context, response *ListTaskQueuesStatisticsResponse, params *ListTaskQueuesStatisticsParams, recordChannel chan TaskrouterV1TaskQueuesStatistics, errorChannel chan error) { curRecord := 1 for response != nil { @@ -262,7 +280,7 @@ func (c *ApiService) streamTaskQueuesStatistics(response *ListTaskQueuesStatisti } } - record, err := client.GetNext(c.baseURL, response, c.getNextListTaskQueuesStatisticsResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListTaskQueuesStatisticsResponseWithContext) if err != nil { errorChannel <- err break @@ -277,11 +295,11 @@ func (c *ApiService) streamTaskQueuesStatistics(response *ListTaskQueuesStatisti close(errorChannel) } -func (c *ApiService) getNextListTaskQueuesStatisticsResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListTaskQueuesStatisticsResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/taskrouter/v1/workspaces_tasks.go b/rest/taskrouter/v1/workspaces_tasks.go index 589b7b927..afc25143a 100644 --- a/rest/taskrouter/v1/workspaces_tasks.go +++ b/rest/taskrouter/v1/workspaces_tasks.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -83,8 +84,10 @@ func (params *CreateTaskParams) SetTaskQueueSid(TaskQueueSid string) *CreateTask return params } -// func (c *ApiService) CreateTask(WorkspaceSid string, params *CreateTaskParams) (*TaskrouterV1Task, error) { + return c.CreateTaskWithContext(context.TODO(), WorkspaceSid, params) +} +func (c *ApiService) CreateTaskWithContext(ctx context.Context, WorkspaceSid string, params *CreateTaskParams) (*TaskrouterV1Task, error) { path := "/v1/Workspaces/{WorkspaceSid}/Tasks" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) @@ -121,7 +124,7 @@ func (c *ApiService) CreateTask(WorkspaceSid string, params *CreateTaskParams) ( data.Set("TaskQueueSid", *params.TaskQueueSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -147,8 +150,10 @@ func (params *DeleteTaskParams) SetIfMatch(IfMatch string) *DeleteTaskParams { return params } -// func (c *ApiService) DeleteTask(WorkspaceSid string, Sid string, params *DeleteTaskParams) error { + return c.DeleteTaskWithContext(context.TODO(), WorkspaceSid, Sid, params) +} +func (c *ApiService) DeleteTaskWithContext(ctx context.Context, WorkspaceSid string, Sid string, params *DeleteTaskParams) error { path := "/v1/Workspaces/{WorkspaceSid}/Tasks/{Sid}" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -161,7 +166,7 @@ func (c *ApiService) DeleteTask(WorkspaceSid string, Sid string, params *DeleteT if params != nil && params.IfMatch != nil { headers["If-Match"] = *params.IfMatch } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -171,8 +176,10 @@ func (c *ApiService) DeleteTask(WorkspaceSid string, Sid string, params *DeleteT return nil } -// func (c *ApiService) FetchTask(WorkspaceSid string, Sid string) (*TaskrouterV1Task, error) { + return c.FetchTaskWithContext(context.TODO(), WorkspaceSid, Sid) +} +func (c *ApiService) FetchTaskWithContext(ctx context.Context, WorkspaceSid string, Sid string) (*TaskrouterV1Task, error) { path := "/v1/Workspaces/{WorkspaceSid}/Tasks/{Sid}" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -182,7 +189,7 @@ func (c *ApiService) FetchTask(WorkspaceSid string, Sid string) (*TaskrouterV1Ta "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -276,6 +283,11 @@ func (params *ListTaskParams) SetLimit(Limit int) *ListTaskParams { // Retrieve a single page of Task records from the API. Request is executed immediately. func (c *ApiService) PageTask(WorkspaceSid string, params *ListTaskParams, pageToken, pageNumber string) (*ListTaskResponse, error) { + return c.PageTaskWithContext(context.TODO(), WorkspaceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Task records from the API. Request is executed immediately. +func (c *ApiService) PageTaskWithContext(ctx context.Context, WorkspaceSid string, params *ListTaskParams, pageToken, pageNumber string) (*ListTaskResponse, error) { path := "/v1/Workspaces/{WorkspaceSid}/Tasks" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) @@ -328,7 +340,7 @@ func (c *ApiService) PageTask(WorkspaceSid string, params *ListTaskParams, pageT data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -345,7 +357,12 @@ func (c *ApiService) PageTask(WorkspaceSid string, params *ListTaskParams, pageT // Lists Task records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListTask(WorkspaceSid string, params *ListTaskParams) ([]TaskrouterV1Task, error) { - response, errors := c.StreamTask(WorkspaceSid, params) + return c.ListTaskWithContext(context.TODO(), WorkspaceSid, params) +} + +// Lists Task records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListTaskWithContext(ctx context.Context, WorkspaceSid string, params *ListTaskParams) ([]TaskrouterV1Task, error) { + response, errors := c.StreamTaskWithContext(ctx, WorkspaceSid, params) records := make([]TaskrouterV1Task, 0) for record := range response { @@ -361,6 +378,11 @@ func (c *ApiService) ListTask(WorkspaceSid string, params *ListTaskParams) ([]Ta // Streams Task records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamTask(WorkspaceSid string, params *ListTaskParams) (chan TaskrouterV1Task, chan error) { + return c.StreamTaskWithContext(context.TODO(), WorkspaceSid, params) +} + +// Streams Task records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamTaskWithContext(ctx context.Context, WorkspaceSid string, params *ListTaskParams) (chan TaskrouterV1Task, chan error) { if params == nil { params = &ListTaskParams{} } @@ -369,19 +391,19 @@ func (c *ApiService) StreamTask(WorkspaceSid string, params *ListTaskParams) (ch recordChannel := make(chan TaskrouterV1Task, 1) errorChannel := make(chan error, 1) - response, err := c.PageTask(WorkspaceSid, params, "", "") + response, err := c.PageTaskWithContext(ctx, WorkspaceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamTask(response, params, recordChannel, errorChannel) + go c.streamTaskWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamTask(response *ListTaskResponse, params *ListTaskParams, recordChannel chan TaskrouterV1Task, errorChannel chan error) { +func (c *ApiService) streamTaskWithContext(ctx context.Context, response *ListTaskResponse, params *ListTaskParams, recordChannel chan TaskrouterV1Task, errorChannel chan error) { curRecord := 1 for response != nil { @@ -396,7 +418,7 @@ func (c *ApiService) streamTask(response *ListTaskResponse, params *ListTaskPara } } - record, err := client.GetNext(c.baseURL, response, c.getNextListTaskResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListTaskResponseWithContext) if err != nil { errorChannel <- err break @@ -411,11 +433,11 @@ func (c *ApiService) streamTask(response *ListTaskResponse, params *ListTaskPara close(errorChannel) } -func (c *ApiService) getNextListTaskResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListTaskResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -476,8 +498,10 @@ func (params *UpdateTaskParams) SetVirtualStartTime(VirtualStartTime time.Time) return params } -// func (c *ApiService) UpdateTask(WorkspaceSid string, Sid string, params *UpdateTaskParams) (*TaskrouterV1Task, error) { + return c.UpdateTaskWithContext(context.TODO(), WorkspaceSid, Sid, params) +} +func (c *ApiService) UpdateTaskWithContext(ctx context.Context, WorkspaceSid string, Sid string, params *UpdateTaskParams) (*TaskrouterV1Task, error) { path := "/v1/Workspaces/{WorkspaceSid}/Tasks/{Sid}" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -509,7 +533,7 @@ func (c *ApiService) UpdateTask(WorkspaceSid string, Sid string, params *UpdateT if params != nil && params.IfMatch != nil { headers["If-Match"] = *params.IfMatch } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/taskrouter/v1/workspaces_tasks_reservations.go b/rest/taskrouter/v1/workspaces_tasks_reservations.go index 4fec72da5..ecdbf8d47 100644 --- a/rest/taskrouter/v1/workspaces_tasks_reservations.go +++ b/rest/taskrouter/v1/workspaces_tasks_reservations.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -23,8 +24,10 @@ import ( "github.com/twilio/twilio-go/client" ) -// func (c *ApiService) FetchTaskReservation(WorkspaceSid string, TaskSid string, Sid string) (*TaskrouterV1TaskReservation, error) { + return c.FetchTaskReservationWithContext(context.TODO(), WorkspaceSid, TaskSid, Sid) +} +func (c *ApiService) FetchTaskReservationWithContext(ctx context.Context, WorkspaceSid string, TaskSid string, Sid string) (*TaskrouterV1TaskReservation, error) { path := "/v1/Workspaces/{WorkspaceSid}/Tasks/{TaskSid}/Reservations/{Sid}" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) path = strings.Replace(path, "{"+"TaskSid"+"}", TaskSid, -1) @@ -35,7 +38,7 @@ func (c *ApiService) FetchTaskReservation(WorkspaceSid string, TaskSid string, S "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -81,6 +84,11 @@ func (params *ListTaskReservationParams) SetLimit(Limit int) *ListTaskReservatio // Retrieve a single page of TaskReservation records from the API. Request is executed immediately. func (c *ApiService) PageTaskReservation(WorkspaceSid string, TaskSid string, params *ListTaskReservationParams, pageToken, pageNumber string) (*ListTaskReservationResponse, error) { + return c.PageTaskReservationWithContext(context.TODO(), WorkspaceSid, TaskSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of TaskReservation records from the API. Request is executed immediately. +func (c *ApiService) PageTaskReservationWithContext(ctx context.Context, WorkspaceSid string, TaskSid string, params *ListTaskReservationParams, pageToken, pageNumber string) (*ListTaskReservationResponse, error) { path := "/v1/Workspaces/{WorkspaceSid}/Tasks/{TaskSid}/Reservations" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) @@ -108,7 +116,7 @@ func (c *ApiService) PageTaskReservation(WorkspaceSid string, TaskSid string, pa data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -125,7 +133,12 @@ func (c *ApiService) PageTaskReservation(WorkspaceSid string, TaskSid string, pa // Lists TaskReservation records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListTaskReservation(WorkspaceSid string, TaskSid string, params *ListTaskReservationParams) ([]TaskrouterV1TaskReservation, error) { - response, errors := c.StreamTaskReservation(WorkspaceSid, TaskSid, params) + return c.ListTaskReservationWithContext(context.TODO(), WorkspaceSid, TaskSid, params) +} + +// Lists TaskReservation records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListTaskReservationWithContext(ctx context.Context, WorkspaceSid string, TaskSid string, params *ListTaskReservationParams) ([]TaskrouterV1TaskReservation, error) { + response, errors := c.StreamTaskReservationWithContext(ctx, WorkspaceSid, TaskSid, params) records := make([]TaskrouterV1TaskReservation, 0) for record := range response { @@ -141,6 +154,11 @@ func (c *ApiService) ListTaskReservation(WorkspaceSid string, TaskSid string, pa // Streams TaskReservation records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamTaskReservation(WorkspaceSid string, TaskSid string, params *ListTaskReservationParams) (chan TaskrouterV1TaskReservation, chan error) { + return c.StreamTaskReservationWithContext(context.TODO(), WorkspaceSid, TaskSid, params) +} + +// Streams TaskReservation records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamTaskReservationWithContext(ctx context.Context, WorkspaceSid string, TaskSid string, params *ListTaskReservationParams) (chan TaskrouterV1TaskReservation, chan error) { if params == nil { params = &ListTaskReservationParams{} } @@ -149,19 +167,19 @@ func (c *ApiService) StreamTaskReservation(WorkspaceSid string, TaskSid string, recordChannel := make(chan TaskrouterV1TaskReservation, 1) errorChannel := make(chan error, 1) - response, err := c.PageTaskReservation(WorkspaceSid, TaskSid, params, "", "") + response, err := c.PageTaskReservationWithContext(ctx, WorkspaceSid, TaskSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamTaskReservation(response, params, recordChannel, errorChannel) + go c.streamTaskReservationWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamTaskReservation(response *ListTaskReservationResponse, params *ListTaskReservationParams, recordChannel chan TaskrouterV1TaskReservation, errorChannel chan error) { +func (c *ApiService) streamTaskReservationWithContext(ctx context.Context, response *ListTaskReservationResponse, params *ListTaskReservationParams, recordChannel chan TaskrouterV1TaskReservation, errorChannel chan error) { curRecord := 1 for response != nil { @@ -176,7 +194,7 @@ func (c *ApiService) streamTaskReservation(response *ListTaskReservationResponse } } - record, err := client.GetNext(c.baseURL, response, c.getNextListTaskReservationResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListTaskReservationResponseWithContext) if err != nil { errorChannel <- err break @@ -191,11 +209,11 @@ func (c *ApiService) streamTaskReservation(response *ListTaskReservationResponse close(errorChannel) } -func (c *ApiService) getNextListTaskReservationResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListTaskReservationResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -544,8 +562,10 @@ func (params *UpdateTaskReservationParams) SetJitterBufferSize(JitterBufferSize return params } -// func (c *ApiService) UpdateTaskReservation(WorkspaceSid string, TaskSid string, Sid string, params *UpdateTaskReservationParams) (*TaskrouterV1TaskReservation, error) { + return c.UpdateTaskReservationWithContext(context.TODO(), WorkspaceSid, TaskSid, Sid, params) +} +func (c *ApiService) UpdateTaskReservationWithContext(ctx context.Context, WorkspaceSid string, TaskSid string, Sid string, params *UpdateTaskReservationParams) (*TaskrouterV1TaskReservation, error) { path := "/v1/Workspaces/{WorkspaceSid}/Tasks/{TaskSid}/Reservations/{Sid}" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) path = strings.Replace(path, "{"+"TaskSid"+"}", TaskSid, -1) @@ -728,7 +748,7 @@ func (c *ApiService) UpdateTaskReservation(WorkspaceSid string, TaskSid string, if params != nil && params.IfMatch != nil { headers["If-Match"] = *params.IfMatch } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/taskrouter/v1/workspaces_workers.go b/rest/taskrouter/v1/workspaces_workers.go index f4971390d..ac099fabd 100644 --- a/rest/taskrouter/v1/workspaces_workers.go +++ b/rest/taskrouter/v1/workspaces_workers.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -46,8 +47,10 @@ func (params *CreateWorkerParams) SetAttributes(Attributes string) *CreateWorker return params } -// func (c *ApiService) CreateWorker(WorkspaceSid string, params *CreateWorkerParams) (*TaskrouterV1Worker, error) { + return c.CreateWorkerWithContext(context.TODO(), WorkspaceSid, params) +} +func (c *ApiService) CreateWorkerWithContext(ctx context.Context, WorkspaceSid string, params *CreateWorkerParams) (*TaskrouterV1Worker, error) { path := "/v1/Workspaces/{WorkspaceSid}/Workers" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) @@ -66,7 +69,7 @@ func (c *ApiService) CreateWorker(WorkspaceSid string, params *CreateWorkerParam data.Set("Attributes", *params.Attributes) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -92,8 +95,10 @@ func (params *DeleteWorkerParams) SetIfMatch(IfMatch string) *DeleteWorkerParams return params } -// func (c *ApiService) DeleteWorker(WorkspaceSid string, Sid string, params *DeleteWorkerParams) error { + return c.DeleteWorkerWithContext(context.TODO(), WorkspaceSid, Sid, params) +} +func (c *ApiService) DeleteWorkerWithContext(ctx context.Context, WorkspaceSid string, Sid string, params *DeleteWorkerParams) error { path := "/v1/Workspaces/{WorkspaceSid}/Workers/{Sid}" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -106,7 +111,7 @@ func (c *ApiService) DeleteWorker(WorkspaceSid string, Sid string, params *Delet if params != nil && params.IfMatch != nil { headers["If-Match"] = *params.IfMatch } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -116,8 +121,10 @@ func (c *ApiService) DeleteWorker(WorkspaceSid string, Sid string, params *Delet return nil } -// func (c *ApiService) FetchWorker(WorkspaceSid string, Sid string) (*TaskrouterV1Worker, error) { + return c.FetchWorkerWithContext(context.TODO(), WorkspaceSid, Sid) +} +func (c *ApiService) FetchWorkerWithContext(ctx context.Context, WorkspaceSid string, Sid string) (*TaskrouterV1Worker, error) { path := "/v1/Workspaces/{WorkspaceSid}/Workers/{Sid}" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -127,7 +134,7 @@ func (c *ApiService) FetchWorker(WorkspaceSid string, Sid string) (*TaskrouterV1 "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -209,6 +216,11 @@ func (params *ListWorkerParams) SetLimit(Limit int) *ListWorkerParams { // Retrieve a single page of Worker records from the API. Request is executed immediately. func (c *ApiService) PageWorker(WorkspaceSid string, params *ListWorkerParams, pageToken, pageNumber string) (*ListWorkerResponse, error) { + return c.PageWorkerWithContext(context.TODO(), WorkspaceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Worker records from the API. Request is executed immediately. +func (c *ApiService) PageWorkerWithContext(ctx context.Context, WorkspaceSid string, params *ListWorkerParams, pageToken, pageNumber string) (*ListWorkerResponse, error) { path := "/v1/Workspaces/{WorkspaceSid}/Workers" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) @@ -253,7 +265,7 @@ func (c *ApiService) PageWorker(WorkspaceSid string, params *ListWorkerParams, p data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -270,7 +282,12 @@ func (c *ApiService) PageWorker(WorkspaceSid string, params *ListWorkerParams, p // Lists Worker records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListWorker(WorkspaceSid string, params *ListWorkerParams) ([]TaskrouterV1Worker, error) { - response, errors := c.StreamWorker(WorkspaceSid, params) + return c.ListWorkerWithContext(context.TODO(), WorkspaceSid, params) +} + +// Lists Worker records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListWorkerWithContext(ctx context.Context, WorkspaceSid string, params *ListWorkerParams) ([]TaskrouterV1Worker, error) { + response, errors := c.StreamWorkerWithContext(ctx, WorkspaceSid, params) records := make([]TaskrouterV1Worker, 0) for record := range response { @@ -286,6 +303,11 @@ func (c *ApiService) ListWorker(WorkspaceSid string, params *ListWorkerParams) ( // Streams Worker records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamWorker(WorkspaceSid string, params *ListWorkerParams) (chan TaskrouterV1Worker, chan error) { + return c.StreamWorkerWithContext(context.TODO(), WorkspaceSid, params) +} + +// Streams Worker records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamWorkerWithContext(ctx context.Context, WorkspaceSid string, params *ListWorkerParams) (chan TaskrouterV1Worker, chan error) { if params == nil { params = &ListWorkerParams{} } @@ -294,19 +316,19 @@ func (c *ApiService) StreamWorker(WorkspaceSid string, params *ListWorkerParams) recordChannel := make(chan TaskrouterV1Worker, 1) errorChannel := make(chan error, 1) - response, err := c.PageWorker(WorkspaceSid, params, "", "") + response, err := c.PageWorkerWithContext(ctx, WorkspaceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamWorker(response, params, recordChannel, errorChannel) + go c.streamWorkerWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamWorker(response *ListWorkerResponse, params *ListWorkerParams, recordChannel chan TaskrouterV1Worker, errorChannel chan error) { +func (c *ApiService) streamWorkerWithContext(ctx context.Context, response *ListWorkerResponse, params *ListWorkerParams, recordChannel chan TaskrouterV1Worker, errorChannel chan error) { curRecord := 1 for response != nil { @@ -321,7 +343,7 @@ func (c *ApiService) streamWorker(response *ListWorkerResponse, params *ListWork } } - record, err := client.GetNext(c.baseURL, response, c.getNextListWorkerResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListWorkerResponseWithContext) if err != nil { errorChannel <- err break @@ -336,11 +358,11 @@ func (c *ApiService) streamWorker(response *ListWorkerResponse, params *ListWork close(errorChannel) } -func (c *ApiService) getNextListWorkerResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListWorkerResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -389,8 +411,10 @@ func (params *UpdateWorkerParams) SetRejectPendingReservations(RejectPendingRese return params } -// func (c *ApiService) UpdateWorker(WorkspaceSid string, Sid string, params *UpdateWorkerParams) (*TaskrouterV1Worker, error) { + return c.UpdateWorkerWithContext(context.TODO(), WorkspaceSid, Sid, params) +} +func (c *ApiService) UpdateWorkerWithContext(ctx context.Context, WorkspaceSid string, Sid string, params *UpdateWorkerParams) (*TaskrouterV1Worker, error) { path := "/v1/Workspaces/{WorkspaceSid}/Workers/{Sid}" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -416,7 +440,7 @@ func (c *ApiService) UpdateWorker(WorkspaceSid string, Sid string, params *Updat if params != nil && params.IfMatch != nil { headers["If-Match"] = *params.IfMatch } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/taskrouter/v1/workspaces_workers_channels.go b/rest/taskrouter/v1/workspaces_workers_channels.go index 00676b248..a7f2edd0d 100644 --- a/rest/taskrouter/v1/workspaces_workers_channels.go +++ b/rest/taskrouter/v1/workspaces_workers_channels.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -23,8 +24,10 @@ import ( "github.com/twilio/twilio-go/client" ) -// func (c *ApiService) FetchWorkerChannel(WorkspaceSid string, WorkerSid string, Sid string) (*TaskrouterV1WorkerChannel, error) { + return c.FetchWorkerChannelWithContext(context.TODO(), WorkspaceSid, WorkerSid, Sid) +} +func (c *ApiService) FetchWorkerChannelWithContext(ctx context.Context, WorkspaceSid string, WorkerSid string, Sid string) (*TaskrouterV1WorkerChannel, error) { path := "/v1/Workspaces/{WorkspaceSid}/Workers/{WorkerSid}/Channels/{Sid}" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) path = strings.Replace(path, "{"+"WorkerSid"+"}", WorkerSid, -1) @@ -35,7 +38,7 @@ func (c *ApiService) FetchWorkerChannel(WorkspaceSid string, WorkerSid string, S "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -69,6 +72,11 @@ func (params *ListWorkerChannelParams) SetLimit(Limit int) *ListWorkerChannelPar // Retrieve a single page of WorkerChannel records from the API. Request is executed immediately. func (c *ApiService) PageWorkerChannel(WorkspaceSid string, WorkerSid string, params *ListWorkerChannelParams, pageToken, pageNumber string) (*ListWorkerChannelResponse, error) { + return c.PageWorkerChannelWithContext(context.TODO(), WorkspaceSid, WorkerSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of WorkerChannel records from the API. Request is executed immediately. +func (c *ApiService) PageWorkerChannelWithContext(ctx context.Context, WorkspaceSid string, WorkerSid string, params *ListWorkerChannelParams, pageToken, pageNumber string) (*ListWorkerChannelResponse, error) { path := "/v1/Workspaces/{WorkspaceSid}/Workers/{WorkerSid}/Channels" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) @@ -90,7 +98,7 @@ func (c *ApiService) PageWorkerChannel(WorkspaceSid string, WorkerSid string, pa data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -107,7 +115,12 @@ func (c *ApiService) PageWorkerChannel(WorkspaceSid string, WorkerSid string, pa // Lists WorkerChannel records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListWorkerChannel(WorkspaceSid string, WorkerSid string, params *ListWorkerChannelParams) ([]TaskrouterV1WorkerChannel, error) { - response, errors := c.StreamWorkerChannel(WorkspaceSid, WorkerSid, params) + return c.ListWorkerChannelWithContext(context.TODO(), WorkspaceSid, WorkerSid, params) +} + +// Lists WorkerChannel records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListWorkerChannelWithContext(ctx context.Context, WorkspaceSid string, WorkerSid string, params *ListWorkerChannelParams) ([]TaskrouterV1WorkerChannel, error) { + response, errors := c.StreamWorkerChannelWithContext(ctx, WorkspaceSid, WorkerSid, params) records := make([]TaskrouterV1WorkerChannel, 0) for record := range response { @@ -123,6 +136,11 @@ func (c *ApiService) ListWorkerChannel(WorkspaceSid string, WorkerSid string, pa // Streams WorkerChannel records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamWorkerChannel(WorkspaceSid string, WorkerSid string, params *ListWorkerChannelParams) (chan TaskrouterV1WorkerChannel, chan error) { + return c.StreamWorkerChannelWithContext(context.TODO(), WorkspaceSid, WorkerSid, params) +} + +// Streams WorkerChannel records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamWorkerChannelWithContext(ctx context.Context, WorkspaceSid string, WorkerSid string, params *ListWorkerChannelParams) (chan TaskrouterV1WorkerChannel, chan error) { if params == nil { params = &ListWorkerChannelParams{} } @@ -131,19 +149,19 @@ func (c *ApiService) StreamWorkerChannel(WorkspaceSid string, WorkerSid string, recordChannel := make(chan TaskrouterV1WorkerChannel, 1) errorChannel := make(chan error, 1) - response, err := c.PageWorkerChannel(WorkspaceSid, WorkerSid, params, "", "") + response, err := c.PageWorkerChannelWithContext(ctx, WorkspaceSid, WorkerSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamWorkerChannel(response, params, recordChannel, errorChannel) + go c.streamWorkerChannelWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamWorkerChannel(response *ListWorkerChannelResponse, params *ListWorkerChannelParams, recordChannel chan TaskrouterV1WorkerChannel, errorChannel chan error) { +func (c *ApiService) streamWorkerChannelWithContext(ctx context.Context, response *ListWorkerChannelResponse, params *ListWorkerChannelParams, recordChannel chan TaskrouterV1WorkerChannel, errorChannel chan error) { curRecord := 1 for response != nil { @@ -158,7 +176,7 @@ func (c *ApiService) streamWorkerChannel(response *ListWorkerChannelResponse, pa } } - record, err := client.GetNext(c.baseURL, response, c.getNextListWorkerChannelResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListWorkerChannelResponseWithContext) if err != nil { errorChannel <- err break @@ -173,11 +191,11 @@ func (c *ApiService) streamWorkerChannel(response *ListWorkerChannelResponse, pa close(errorChannel) } -func (c *ApiService) getNextListWorkerChannelResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListWorkerChannelResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -208,8 +226,10 @@ func (params *UpdateWorkerChannelParams) SetAvailable(Available bool) *UpdateWor return params } -// func (c *ApiService) UpdateWorkerChannel(WorkspaceSid string, WorkerSid string, Sid string, params *UpdateWorkerChannelParams) (*TaskrouterV1WorkerChannel, error) { + return c.UpdateWorkerChannelWithContext(context.TODO(), WorkspaceSid, WorkerSid, Sid, params) +} +func (c *ApiService) UpdateWorkerChannelWithContext(ctx context.Context, WorkspaceSid string, WorkerSid string, Sid string, params *UpdateWorkerChannelParams) (*TaskrouterV1WorkerChannel, error) { path := "/v1/Workspaces/{WorkspaceSid}/Workers/{WorkerSid}/Channels/{Sid}" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) path = strings.Replace(path, "{"+"WorkerSid"+"}", WorkerSid, -1) @@ -227,7 +247,7 @@ func (c *ApiService) UpdateWorkerChannel(WorkspaceSid string, WorkerSid string, data.Set("Available", fmt.Sprint(*params.Available)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/taskrouter/v1/workspaces_workers_cumulative_statistics.go b/rest/taskrouter/v1/workspaces_workers_cumulative_statistics.go index 62e0d6845..b30ad2602 100644 --- a/rest/taskrouter/v1/workspaces_workers_cumulative_statistics.go +++ b/rest/taskrouter/v1/workspaces_workers_cumulative_statistics.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -51,8 +52,10 @@ func (params *FetchWorkersCumulativeStatisticsParams) SetTaskChannel(TaskChannel return params } -// func (c *ApiService) FetchWorkersCumulativeStatistics(WorkspaceSid string, params *FetchWorkersCumulativeStatisticsParams) (*TaskrouterV1WorkersCumulativeStatistics, error) { + return c.FetchWorkersCumulativeStatisticsWithContext(context.TODO(), WorkspaceSid, params) +} +func (c *ApiService) FetchWorkersCumulativeStatisticsWithContext(ctx context.Context, WorkspaceSid string, params *FetchWorkersCumulativeStatisticsParams) (*TaskrouterV1WorkersCumulativeStatistics, error) { path := "/v1/Workspaces/{WorkspaceSid}/Workers/CumulativeStatistics" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) @@ -74,7 +77,7 @@ func (c *ApiService) FetchWorkersCumulativeStatistics(WorkspaceSid string, param data.Set("TaskChannel", *params.TaskChannel) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/taskrouter/v1/workspaces_workers_real_time_statistics.go b/rest/taskrouter/v1/workspaces_workers_real_time_statistics.go index c7500bb80..88578db44 100644 --- a/rest/taskrouter/v1/workspaces_workers_real_time_statistics.go +++ b/rest/taskrouter/v1/workspaces_workers_real_time_statistics.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -31,8 +32,10 @@ func (params *FetchWorkersRealTimeStatisticsParams) SetTaskChannel(TaskChannel s return params } -// func (c *ApiService) FetchWorkersRealTimeStatistics(WorkspaceSid string, params *FetchWorkersRealTimeStatisticsParams) (*TaskrouterV1WorkersRealTimeStatistics, error) { + return c.FetchWorkersRealTimeStatisticsWithContext(context.TODO(), WorkspaceSid, params) +} +func (c *ApiService) FetchWorkersRealTimeStatisticsWithContext(ctx context.Context, WorkspaceSid string, params *FetchWorkersRealTimeStatisticsParams) (*TaskrouterV1WorkersRealTimeStatistics, error) { path := "/v1/Workspaces/{WorkspaceSid}/Workers/RealTimeStatistics" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) @@ -45,7 +48,7 @@ func (c *ApiService) FetchWorkersRealTimeStatistics(WorkspaceSid string, params data.Set("TaskChannel", *params.TaskChannel) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/taskrouter/v1/workspaces_workers_reservations.go b/rest/taskrouter/v1/workspaces_workers_reservations.go index 4a99ce003..4729cb653 100644 --- a/rest/taskrouter/v1/workspaces_workers_reservations.go +++ b/rest/taskrouter/v1/workspaces_workers_reservations.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -23,8 +24,10 @@ import ( "github.com/twilio/twilio-go/client" ) -// func (c *ApiService) FetchWorkerReservation(WorkspaceSid string, WorkerSid string, Sid string) (*TaskrouterV1WorkerReservation, error) { + return c.FetchWorkerReservationWithContext(context.TODO(), WorkspaceSid, WorkerSid, Sid) +} +func (c *ApiService) FetchWorkerReservationWithContext(ctx context.Context, WorkspaceSid string, WorkerSid string, Sid string) (*TaskrouterV1WorkerReservation, error) { path := "/v1/Workspaces/{WorkspaceSid}/Workers/{WorkerSid}/Reservations/{Sid}" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) path = strings.Replace(path, "{"+"WorkerSid"+"}", WorkerSid, -1) @@ -35,7 +38,7 @@ func (c *ApiService) FetchWorkerReservation(WorkspaceSid string, WorkerSid strin "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -75,6 +78,11 @@ func (params *ListWorkerReservationParams) SetLimit(Limit int) *ListWorkerReserv // Retrieve a single page of WorkerReservation records from the API. Request is executed immediately. func (c *ApiService) PageWorkerReservation(WorkspaceSid string, WorkerSid string, params *ListWorkerReservationParams, pageToken, pageNumber string) (*ListWorkerReservationResponse, error) { + return c.PageWorkerReservationWithContext(context.TODO(), WorkspaceSid, WorkerSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of WorkerReservation records from the API. Request is executed immediately. +func (c *ApiService) PageWorkerReservationWithContext(ctx context.Context, WorkspaceSid string, WorkerSid string, params *ListWorkerReservationParams, pageToken, pageNumber string) (*ListWorkerReservationResponse, error) { path := "/v1/Workspaces/{WorkspaceSid}/Workers/{WorkerSid}/Reservations" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) @@ -99,7 +107,7 @@ func (c *ApiService) PageWorkerReservation(WorkspaceSid string, WorkerSid string data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -116,7 +124,12 @@ func (c *ApiService) PageWorkerReservation(WorkspaceSid string, WorkerSid string // Lists WorkerReservation records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListWorkerReservation(WorkspaceSid string, WorkerSid string, params *ListWorkerReservationParams) ([]TaskrouterV1WorkerReservation, error) { - response, errors := c.StreamWorkerReservation(WorkspaceSid, WorkerSid, params) + return c.ListWorkerReservationWithContext(context.TODO(), WorkspaceSid, WorkerSid, params) +} + +// Lists WorkerReservation records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListWorkerReservationWithContext(ctx context.Context, WorkspaceSid string, WorkerSid string, params *ListWorkerReservationParams) ([]TaskrouterV1WorkerReservation, error) { + response, errors := c.StreamWorkerReservationWithContext(ctx, WorkspaceSid, WorkerSid, params) records := make([]TaskrouterV1WorkerReservation, 0) for record := range response { @@ -132,6 +145,11 @@ func (c *ApiService) ListWorkerReservation(WorkspaceSid string, WorkerSid string // Streams WorkerReservation records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamWorkerReservation(WorkspaceSid string, WorkerSid string, params *ListWorkerReservationParams) (chan TaskrouterV1WorkerReservation, chan error) { + return c.StreamWorkerReservationWithContext(context.TODO(), WorkspaceSid, WorkerSid, params) +} + +// Streams WorkerReservation records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamWorkerReservationWithContext(ctx context.Context, WorkspaceSid string, WorkerSid string, params *ListWorkerReservationParams) (chan TaskrouterV1WorkerReservation, chan error) { if params == nil { params = &ListWorkerReservationParams{} } @@ -140,19 +158,19 @@ func (c *ApiService) StreamWorkerReservation(WorkspaceSid string, WorkerSid stri recordChannel := make(chan TaskrouterV1WorkerReservation, 1) errorChannel := make(chan error, 1) - response, err := c.PageWorkerReservation(WorkspaceSid, WorkerSid, params, "", "") + response, err := c.PageWorkerReservationWithContext(ctx, WorkspaceSid, WorkerSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamWorkerReservation(response, params, recordChannel, errorChannel) + go c.streamWorkerReservationWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamWorkerReservation(response *ListWorkerReservationResponse, params *ListWorkerReservationParams, recordChannel chan TaskrouterV1WorkerReservation, errorChannel chan error) { +func (c *ApiService) streamWorkerReservationWithContext(ctx context.Context, response *ListWorkerReservationResponse, params *ListWorkerReservationParams, recordChannel chan TaskrouterV1WorkerReservation, errorChannel chan error) { curRecord := 1 for response != nil { @@ -167,7 +185,7 @@ func (c *ApiService) streamWorkerReservation(response *ListWorkerReservationResp } } - record, err := client.GetNext(c.baseURL, response, c.getNextListWorkerReservationResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListWorkerReservationResponseWithContext) if err != nil { errorChannel <- err break @@ -182,11 +200,11 @@ func (c *ApiService) streamWorkerReservation(response *ListWorkerReservationResp close(errorChannel) } -func (c *ApiService) getNextListWorkerReservationResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListWorkerReservationResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -523,8 +541,10 @@ func (params *UpdateWorkerReservationParams) SetJitterBufferSize(JitterBufferSiz return params } -// func (c *ApiService) UpdateWorkerReservation(WorkspaceSid string, WorkerSid string, Sid string, params *UpdateWorkerReservationParams) (*TaskrouterV1WorkerReservation, error) { + return c.UpdateWorkerReservationWithContext(context.TODO(), WorkspaceSid, WorkerSid, Sid, params) +} +func (c *ApiService) UpdateWorkerReservationWithContext(ctx context.Context, WorkspaceSid string, WorkerSid string, Sid string, params *UpdateWorkerReservationParams) (*TaskrouterV1WorkerReservation, error) { path := "/v1/Workspaces/{WorkspaceSid}/Workers/{WorkerSid}/Reservations/{Sid}" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) path = strings.Replace(path, "{"+"WorkerSid"+"}", WorkerSid, -1) @@ -701,7 +721,7 @@ func (c *ApiService) UpdateWorkerReservation(WorkspaceSid string, WorkerSid stri if params != nil && params.IfMatch != nil { headers["If-Match"] = *params.IfMatch } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/taskrouter/v1/workspaces_workers_statistics.go b/rest/taskrouter/v1/workspaces_workers_statistics.go index c7f1e2a08..538770662 100644 --- a/rest/taskrouter/v1/workspaces_workers_statistics.go +++ b/rest/taskrouter/v1/workspaces_workers_statistics.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -51,8 +52,10 @@ func (params *FetchWorkerInstanceStatisticsParams) SetTaskChannel(TaskChannel st return params } -// func (c *ApiService) FetchWorkerInstanceStatistics(WorkspaceSid string, WorkerSid string, params *FetchWorkerInstanceStatisticsParams) (*TaskrouterV1WorkerInstanceStatistics, error) { + return c.FetchWorkerInstanceStatisticsWithContext(context.TODO(), WorkspaceSid, WorkerSid, params) +} +func (c *ApiService) FetchWorkerInstanceStatisticsWithContext(ctx context.Context, WorkspaceSid string, WorkerSid string, params *FetchWorkerInstanceStatisticsParams) (*TaskrouterV1WorkerInstanceStatistics, error) { path := "/v1/Workspaces/{WorkspaceSid}/Workers/{WorkerSid}/Statistics" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) path = strings.Replace(path, "{"+"WorkerSid"+"}", WorkerSid, -1) @@ -75,7 +78,7 @@ func (c *ApiService) FetchWorkerInstanceStatistics(WorkspaceSid string, WorkerSi data.Set("TaskChannel", *params.TaskChannel) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -137,8 +140,10 @@ func (params *FetchWorkerStatisticsParams) SetTaskChannel(TaskChannel string) *F return params } -// func (c *ApiService) FetchWorkerStatistics(WorkspaceSid string, params *FetchWorkerStatisticsParams) (*TaskrouterV1WorkerStatistics, error) { + return c.FetchWorkerStatisticsWithContext(context.TODO(), WorkspaceSid, params) +} +func (c *ApiService) FetchWorkerStatisticsWithContext(ctx context.Context, WorkspaceSid string, params *FetchWorkerStatisticsParams) (*TaskrouterV1WorkerStatistics, error) { path := "/v1/Workspaces/{WorkspaceSid}/Workers/Statistics" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) @@ -169,7 +174,7 @@ func (c *ApiService) FetchWorkerStatistics(WorkspaceSid string, params *FetchWor data.Set("TaskChannel", *params.TaskChannel) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/taskrouter/v1/workspaces_workflows.go b/rest/taskrouter/v1/workspaces_workflows.go index 43b1e2d90..681a95757 100644 --- a/rest/taskrouter/v1/workspaces_workflows.go +++ b/rest/taskrouter/v1/workspaces_workflows.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -58,8 +59,10 @@ func (params *CreateWorkflowParams) SetTaskReservationTimeout(TaskReservationTim return params } -// func (c *ApiService) CreateWorkflow(WorkspaceSid string, params *CreateWorkflowParams) (*TaskrouterV1Workflow, error) { + return c.CreateWorkflowWithContext(context.TODO(), WorkspaceSid, params) +} +func (c *ApiService) CreateWorkflowWithContext(ctx context.Context, WorkspaceSid string, params *CreateWorkflowParams) (*TaskrouterV1Workflow, error) { path := "/v1/Workspaces/{WorkspaceSid}/Workflows" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) @@ -84,7 +87,7 @@ func (c *ApiService) CreateWorkflow(WorkspaceSid string, params *CreateWorkflowP data.Set("TaskReservationTimeout", fmt.Sprint(*params.TaskReservationTimeout)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -99,8 +102,10 @@ func (c *ApiService) CreateWorkflow(WorkspaceSid string, params *CreateWorkflowP return ps, err } -// func (c *ApiService) DeleteWorkflow(WorkspaceSid string, Sid string) error { + return c.DeleteWorkflowWithContext(context.TODO(), WorkspaceSid, Sid) +} +func (c *ApiService) DeleteWorkflowWithContext(ctx context.Context, WorkspaceSid string, Sid string) error { path := "/v1/Workspaces/{WorkspaceSid}/Workflows/{Sid}" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -110,7 +115,7 @@ func (c *ApiService) DeleteWorkflow(WorkspaceSid string, Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -120,8 +125,10 @@ func (c *ApiService) DeleteWorkflow(WorkspaceSid string, Sid string) error { return nil } -// func (c *ApiService) FetchWorkflow(WorkspaceSid string, Sid string) (*TaskrouterV1Workflow, error) { + return c.FetchWorkflowWithContext(context.TODO(), WorkspaceSid, Sid) +} +func (c *ApiService) FetchWorkflowWithContext(ctx context.Context, WorkspaceSid string, Sid string) (*TaskrouterV1Workflow, error) { path := "/v1/Workspaces/{WorkspaceSid}/Workflows/{Sid}" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -131,7 +138,7 @@ func (c *ApiService) FetchWorkflow(WorkspaceSid string, Sid string) (*Taskrouter "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -171,6 +178,11 @@ func (params *ListWorkflowParams) SetLimit(Limit int) *ListWorkflowParams { // Retrieve a single page of Workflow records from the API. Request is executed immediately. func (c *ApiService) PageWorkflow(WorkspaceSid string, params *ListWorkflowParams, pageToken, pageNumber string) (*ListWorkflowResponse, error) { + return c.PageWorkflowWithContext(context.TODO(), WorkspaceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Workflow records from the API. Request is executed immediately. +func (c *ApiService) PageWorkflowWithContext(ctx context.Context, WorkspaceSid string, params *ListWorkflowParams, pageToken, pageNumber string) (*ListWorkflowResponse, error) { path := "/v1/Workspaces/{WorkspaceSid}/Workflows" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) @@ -194,7 +206,7 @@ func (c *ApiService) PageWorkflow(WorkspaceSid string, params *ListWorkflowParam data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -211,7 +223,12 @@ func (c *ApiService) PageWorkflow(WorkspaceSid string, params *ListWorkflowParam // Lists Workflow records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListWorkflow(WorkspaceSid string, params *ListWorkflowParams) ([]TaskrouterV1Workflow, error) { - response, errors := c.StreamWorkflow(WorkspaceSid, params) + return c.ListWorkflowWithContext(context.TODO(), WorkspaceSid, params) +} + +// Lists Workflow records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListWorkflowWithContext(ctx context.Context, WorkspaceSid string, params *ListWorkflowParams) ([]TaskrouterV1Workflow, error) { + response, errors := c.StreamWorkflowWithContext(ctx, WorkspaceSid, params) records := make([]TaskrouterV1Workflow, 0) for record := range response { @@ -227,6 +244,11 @@ func (c *ApiService) ListWorkflow(WorkspaceSid string, params *ListWorkflowParam // Streams Workflow records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamWorkflow(WorkspaceSid string, params *ListWorkflowParams) (chan TaskrouterV1Workflow, chan error) { + return c.StreamWorkflowWithContext(context.TODO(), WorkspaceSid, params) +} + +// Streams Workflow records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamWorkflowWithContext(ctx context.Context, WorkspaceSid string, params *ListWorkflowParams) (chan TaskrouterV1Workflow, chan error) { if params == nil { params = &ListWorkflowParams{} } @@ -235,19 +257,19 @@ func (c *ApiService) StreamWorkflow(WorkspaceSid string, params *ListWorkflowPar recordChannel := make(chan TaskrouterV1Workflow, 1) errorChannel := make(chan error, 1) - response, err := c.PageWorkflow(WorkspaceSid, params, "", "") + response, err := c.PageWorkflowWithContext(ctx, WorkspaceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamWorkflow(response, params, recordChannel, errorChannel) + go c.streamWorkflowWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamWorkflow(response *ListWorkflowResponse, params *ListWorkflowParams, recordChannel chan TaskrouterV1Workflow, errorChannel chan error) { +func (c *ApiService) streamWorkflowWithContext(ctx context.Context, response *ListWorkflowResponse, params *ListWorkflowParams, recordChannel chan TaskrouterV1Workflow, errorChannel chan error) { curRecord := 1 for response != nil { @@ -262,7 +284,7 @@ func (c *ApiService) streamWorkflow(response *ListWorkflowResponse, params *List } } - record, err := client.GetNext(c.baseURL, response, c.getNextListWorkflowResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListWorkflowResponseWithContext) if err != nil { errorChannel <- err break @@ -277,11 +299,11 @@ func (c *ApiService) streamWorkflow(response *ListWorkflowResponse, params *List close(errorChannel) } -func (c *ApiService) getNextListWorkflowResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListWorkflowResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -336,8 +358,10 @@ func (params *UpdateWorkflowParams) SetReEvaluateTasks(ReEvaluateTasks string) * return params } -// func (c *ApiService) UpdateWorkflow(WorkspaceSid string, Sid string, params *UpdateWorkflowParams) (*TaskrouterV1Workflow, error) { + return c.UpdateWorkflowWithContext(context.TODO(), WorkspaceSid, Sid, params) +} +func (c *ApiService) UpdateWorkflowWithContext(ctx context.Context, WorkspaceSid string, Sid string, params *UpdateWorkflowParams) (*TaskrouterV1Workflow, error) { path := "/v1/Workspaces/{WorkspaceSid}/Workflows/{Sid}" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -366,7 +390,7 @@ func (c *ApiService) UpdateWorkflow(WorkspaceSid string, Sid string, params *Upd data.Set("ReEvaluateTasks", *params.ReEvaluateTasks) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/taskrouter/v1/workspaces_workflows_cumulative_statistics.go b/rest/taskrouter/v1/workspaces_workflows_cumulative_statistics.go index 295411579..66bbe08ef 100644 --- a/rest/taskrouter/v1/workspaces_workflows_cumulative_statistics.go +++ b/rest/taskrouter/v1/workspaces_workflows_cumulative_statistics.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -57,8 +58,10 @@ func (params *FetchWorkflowCumulativeStatisticsParams) SetSplitByWaitTime(SplitB return params } -// func (c *ApiService) FetchWorkflowCumulativeStatistics(WorkspaceSid string, WorkflowSid string, params *FetchWorkflowCumulativeStatisticsParams) (*TaskrouterV1WorkflowCumulativeStatistics, error) { + return c.FetchWorkflowCumulativeStatisticsWithContext(context.TODO(), WorkspaceSid, WorkflowSid, params) +} +func (c *ApiService) FetchWorkflowCumulativeStatisticsWithContext(ctx context.Context, WorkspaceSid string, WorkflowSid string, params *FetchWorkflowCumulativeStatisticsParams) (*TaskrouterV1WorkflowCumulativeStatistics, error) { path := "/v1/Workspaces/{WorkspaceSid}/Workflows/{WorkflowSid}/CumulativeStatistics" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) path = strings.Replace(path, "{"+"WorkflowSid"+"}", WorkflowSid, -1) @@ -84,7 +87,7 @@ func (c *ApiService) FetchWorkflowCumulativeStatistics(WorkspaceSid string, Work data.Set("SplitByWaitTime", *params.SplitByWaitTime) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/taskrouter/v1/workspaces_workflows_real_time_statistics.go b/rest/taskrouter/v1/workspaces_workflows_real_time_statistics.go index f0aeb9656..c5eabce73 100644 --- a/rest/taskrouter/v1/workspaces_workflows_real_time_statistics.go +++ b/rest/taskrouter/v1/workspaces_workflows_real_time_statistics.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -31,8 +32,10 @@ func (params *FetchWorkflowRealTimeStatisticsParams) SetTaskChannel(TaskChannel return params } -// func (c *ApiService) FetchWorkflowRealTimeStatistics(WorkspaceSid string, WorkflowSid string, params *FetchWorkflowRealTimeStatisticsParams) (*TaskrouterV1WorkflowRealTimeStatistics, error) { + return c.FetchWorkflowRealTimeStatisticsWithContext(context.TODO(), WorkspaceSid, WorkflowSid, params) +} +func (c *ApiService) FetchWorkflowRealTimeStatisticsWithContext(ctx context.Context, WorkspaceSid string, WorkflowSid string, params *FetchWorkflowRealTimeStatisticsParams) (*TaskrouterV1WorkflowRealTimeStatistics, error) { path := "/v1/Workspaces/{WorkspaceSid}/Workflows/{WorkflowSid}/RealTimeStatistics" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) path = strings.Replace(path, "{"+"WorkflowSid"+"}", WorkflowSid, -1) @@ -46,7 +49,7 @@ func (c *ApiService) FetchWorkflowRealTimeStatistics(WorkspaceSid string, Workfl data.Set("TaskChannel", *params.TaskChannel) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/taskrouter/v1/workspaces_workflows_statistics.go b/rest/taskrouter/v1/workspaces_workflows_statistics.go index 123d3b981..18cceee99 100644 --- a/rest/taskrouter/v1/workspaces_workflows_statistics.go +++ b/rest/taskrouter/v1/workspaces_workflows_statistics.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -57,8 +58,10 @@ func (params *FetchWorkflowStatisticsParams) SetSplitByWaitTime(SplitByWaitTime return params } -// func (c *ApiService) FetchWorkflowStatistics(WorkspaceSid string, WorkflowSid string, params *FetchWorkflowStatisticsParams) (*TaskrouterV1WorkflowStatistics, error) { + return c.FetchWorkflowStatisticsWithContext(context.TODO(), WorkspaceSid, WorkflowSid, params) +} +func (c *ApiService) FetchWorkflowStatisticsWithContext(ctx context.Context, WorkspaceSid string, WorkflowSid string, params *FetchWorkflowStatisticsParams) (*TaskrouterV1WorkflowStatistics, error) { path := "/v1/Workspaces/{WorkspaceSid}/Workflows/{WorkflowSid}/Statistics" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) path = strings.Replace(path, "{"+"WorkflowSid"+"}", WorkflowSid, -1) @@ -84,7 +87,7 @@ func (c *ApiService) FetchWorkflowStatistics(WorkspaceSid string, WorkflowSid st data.Set("SplitByWaitTime", *params.SplitByWaitTime) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/trunking/v1/api_service.go b/rest/trunking/v1/api_service.go index b4f5afcd6..097120774 100644 --- a/rest/trunking/v1/api_service.go +++ b/rest/trunking/v1/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://trunking.twilio.com", + } +} diff --git a/rest/trunking/v1/trunks.go b/rest/trunking/v1/trunks.go index e136127f7..9168e8da1 100644 --- a/rest/trunking/v1/trunks.go +++ b/rest/trunking/v1/trunks.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -76,8 +77,10 @@ func (params *CreateTrunkParams) SetTransferCallerId(TransferCallerId string) *C return params } -// func (c *ApiService) CreateTrunk(params *CreateTrunkParams) (*TrunkingV1Trunk, error) { + return c.CreateTrunkWithContext(context.TODO(), params) +} +func (c *ApiService) CreateTrunkWithContext(ctx context.Context, params *CreateTrunkParams) (*TrunkingV1Trunk, error) { path := "/v1/Trunks" data := url.Values{} @@ -110,7 +113,7 @@ func (c *ApiService) CreateTrunk(params *CreateTrunkParams) (*TrunkingV1Trunk, e data.Set("TransferCallerId", fmt.Sprint(*params.TransferCallerId)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -125,8 +128,10 @@ func (c *ApiService) CreateTrunk(params *CreateTrunkParams) (*TrunkingV1Trunk, e return ps, err } -// func (c *ApiService) DeleteTrunk(Sid string) error { + return c.DeleteTrunkWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteTrunkWithContext(ctx context.Context, Sid string) error { path := "/v1/Trunks/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -135,7 +140,7 @@ func (c *ApiService) DeleteTrunk(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -145,8 +150,10 @@ func (c *ApiService) DeleteTrunk(Sid string) error { return nil } -// func (c *ApiService) FetchTrunk(Sid string) (*TrunkingV1Trunk, error) { + return c.FetchTrunkWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchTrunkWithContext(ctx context.Context, Sid string) (*TrunkingV1Trunk, error) { path := "/v1/Trunks/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -155,7 +162,7 @@ func (c *ApiService) FetchTrunk(Sid string) (*TrunkingV1Trunk, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -189,6 +196,11 @@ func (params *ListTrunkParams) SetLimit(Limit int) *ListTrunkParams { // Retrieve a single page of Trunk records from the API. Request is executed immediately. func (c *ApiService) PageTrunk(params *ListTrunkParams, pageToken, pageNumber string) (*ListTrunkResponse, error) { + return c.PageTrunkWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Trunk records from the API. Request is executed immediately. +func (c *ApiService) PageTrunkWithContext(ctx context.Context, params *ListTrunkParams, pageToken, pageNumber string) (*ListTrunkResponse, error) { path := "/v1/Trunks" data := url.Values{} @@ -207,7 +219,7 @@ func (c *ApiService) PageTrunk(params *ListTrunkParams, pageToken, pageNumber st data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -224,7 +236,12 @@ func (c *ApiService) PageTrunk(params *ListTrunkParams, pageToken, pageNumber st // Lists Trunk records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListTrunk(params *ListTrunkParams) ([]TrunkingV1Trunk, error) { - response, errors := c.StreamTrunk(params) + return c.ListTrunkWithContext(context.TODO(), params) +} + +// Lists Trunk records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListTrunkWithContext(ctx context.Context, params *ListTrunkParams) ([]TrunkingV1Trunk, error) { + response, errors := c.StreamTrunkWithContext(ctx, params) records := make([]TrunkingV1Trunk, 0) for record := range response { @@ -240,6 +257,11 @@ func (c *ApiService) ListTrunk(params *ListTrunkParams) ([]TrunkingV1Trunk, erro // Streams Trunk records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamTrunk(params *ListTrunkParams) (chan TrunkingV1Trunk, chan error) { + return c.StreamTrunkWithContext(context.TODO(), params) +} + +// Streams Trunk records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamTrunkWithContext(ctx context.Context, params *ListTrunkParams) (chan TrunkingV1Trunk, chan error) { if params == nil { params = &ListTrunkParams{} } @@ -248,19 +270,19 @@ func (c *ApiService) StreamTrunk(params *ListTrunkParams) (chan TrunkingV1Trunk, recordChannel := make(chan TrunkingV1Trunk, 1) errorChannel := make(chan error, 1) - response, err := c.PageTrunk(params, "", "") + response, err := c.PageTrunkWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamTrunk(response, params, recordChannel, errorChannel) + go c.streamTrunkWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamTrunk(response *ListTrunkResponse, params *ListTrunkParams, recordChannel chan TrunkingV1Trunk, errorChannel chan error) { +func (c *ApiService) streamTrunkWithContext(ctx context.Context, response *ListTrunkResponse, params *ListTrunkParams, recordChannel chan TrunkingV1Trunk, errorChannel chan error) { curRecord := 1 for response != nil { @@ -275,7 +297,7 @@ func (c *ApiService) streamTrunk(response *ListTrunkResponse, params *ListTrunkP } } - record, err := client.GetNext(c.baseURL, response, c.getNextListTrunkResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListTrunkResponseWithContext) if err != nil { errorChannel <- err break @@ -290,11 +312,11 @@ func (c *ApiService) streamTrunk(response *ListTrunkResponse, params *ListTrunkP close(errorChannel) } -func (c *ApiService) getNextListTrunkResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListTrunkResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -361,8 +383,10 @@ func (params *UpdateTrunkParams) SetTransferCallerId(TransferCallerId string) *U return params } -// func (c *ApiService) UpdateTrunk(Sid string, params *UpdateTrunkParams) (*TrunkingV1Trunk, error) { + return c.UpdateTrunkWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateTrunkWithContext(ctx context.Context, Sid string, params *UpdateTrunkParams) (*TrunkingV1Trunk, error) { path := "/v1/Trunks/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -396,7 +420,7 @@ func (c *ApiService) UpdateTrunk(Sid string, params *UpdateTrunkParams) (*Trunki data.Set("TransferCallerId", fmt.Sprint(*params.TransferCallerId)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/trunking/v1/trunks_credential_lists.go b/rest/trunking/v1/trunks_credential_lists.go index d7d1042d8..297dbc732 100644 --- a/rest/trunking/v1/trunks_credential_lists.go +++ b/rest/trunking/v1/trunks_credential_lists.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -34,8 +35,10 @@ func (params *CreateCredentialListParams) SetCredentialListSid(CredentialListSid return params } -// func (c *ApiService) CreateCredentialList(TrunkSid string, params *CreateCredentialListParams) (*TrunkingV1CredentialList, error) { + return c.CreateCredentialListWithContext(context.TODO(), TrunkSid, params) +} +func (c *ApiService) CreateCredentialListWithContext(ctx context.Context, TrunkSid string, params *CreateCredentialListParams) (*TrunkingV1CredentialList, error) { path := "/v1/Trunks/{TrunkSid}/CredentialLists" path = strings.Replace(path, "{"+"TrunkSid"+"}", TrunkSid, -1) @@ -48,7 +51,7 @@ func (c *ApiService) CreateCredentialList(TrunkSid string, params *CreateCredent data.Set("CredentialListSid", *params.CredentialListSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -63,8 +66,10 @@ func (c *ApiService) CreateCredentialList(TrunkSid string, params *CreateCredent return ps, err } -// func (c *ApiService) DeleteCredentialList(TrunkSid string, Sid string) error { + return c.DeleteCredentialListWithContext(context.TODO(), TrunkSid, Sid) +} +func (c *ApiService) DeleteCredentialListWithContext(ctx context.Context, TrunkSid string, Sid string) error { path := "/v1/Trunks/{TrunkSid}/CredentialLists/{Sid}" path = strings.Replace(path, "{"+"TrunkSid"+"}", TrunkSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -74,7 +79,7 @@ func (c *ApiService) DeleteCredentialList(TrunkSid string, Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -84,8 +89,10 @@ func (c *ApiService) DeleteCredentialList(TrunkSid string, Sid string) error { return nil } -// func (c *ApiService) FetchCredentialList(TrunkSid string, Sid string) (*TrunkingV1CredentialList, error) { + return c.FetchCredentialListWithContext(context.TODO(), TrunkSid, Sid) +} +func (c *ApiService) FetchCredentialListWithContext(ctx context.Context, TrunkSid string, Sid string) (*TrunkingV1CredentialList, error) { path := "/v1/Trunks/{TrunkSid}/CredentialLists/{Sid}" path = strings.Replace(path, "{"+"TrunkSid"+"}", TrunkSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -95,7 +102,7 @@ func (c *ApiService) FetchCredentialList(TrunkSid string, Sid string) (*Trunking "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -129,6 +136,11 @@ func (params *ListCredentialListParams) SetLimit(Limit int) *ListCredentialListP // Retrieve a single page of CredentialList records from the API. Request is executed immediately. func (c *ApiService) PageCredentialList(TrunkSid string, params *ListCredentialListParams, pageToken, pageNumber string) (*ListCredentialListResponse, error) { + return c.PageCredentialListWithContext(context.TODO(), TrunkSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of CredentialList records from the API. Request is executed immediately. +func (c *ApiService) PageCredentialListWithContext(ctx context.Context, TrunkSid string, params *ListCredentialListParams, pageToken, pageNumber string) (*ListCredentialListResponse, error) { path := "/v1/Trunks/{TrunkSid}/CredentialLists" path = strings.Replace(path, "{"+"TrunkSid"+"}", TrunkSid, -1) @@ -149,7 +161,7 @@ func (c *ApiService) PageCredentialList(TrunkSid string, params *ListCredentialL data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -166,7 +178,12 @@ func (c *ApiService) PageCredentialList(TrunkSid string, params *ListCredentialL // Lists CredentialList records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListCredentialList(TrunkSid string, params *ListCredentialListParams) ([]TrunkingV1CredentialList, error) { - response, errors := c.StreamCredentialList(TrunkSid, params) + return c.ListCredentialListWithContext(context.TODO(), TrunkSid, params) +} + +// Lists CredentialList records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListCredentialListWithContext(ctx context.Context, TrunkSid string, params *ListCredentialListParams) ([]TrunkingV1CredentialList, error) { + response, errors := c.StreamCredentialListWithContext(ctx, TrunkSid, params) records := make([]TrunkingV1CredentialList, 0) for record := range response { @@ -182,6 +199,11 @@ func (c *ApiService) ListCredentialList(TrunkSid string, params *ListCredentialL // Streams CredentialList records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamCredentialList(TrunkSid string, params *ListCredentialListParams) (chan TrunkingV1CredentialList, chan error) { + return c.StreamCredentialListWithContext(context.TODO(), TrunkSid, params) +} + +// Streams CredentialList records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamCredentialListWithContext(ctx context.Context, TrunkSid string, params *ListCredentialListParams) (chan TrunkingV1CredentialList, chan error) { if params == nil { params = &ListCredentialListParams{} } @@ -190,19 +212,19 @@ func (c *ApiService) StreamCredentialList(TrunkSid string, params *ListCredentia recordChannel := make(chan TrunkingV1CredentialList, 1) errorChannel := make(chan error, 1) - response, err := c.PageCredentialList(TrunkSid, params, "", "") + response, err := c.PageCredentialListWithContext(ctx, TrunkSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamCredentialList(response, params, recordChannel, errorChannel) + go c.streamCredentialListWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamCredentialList(response *ListCredentialListResponse, params *ListCredentialListParams, recordChannel chan TrunkingV1CredentialList, errorChannel chan error) { +func (c *ApiService) streamCredentialListWithContext(ctx context.Context, response *ListCredentialListResponse, params *ListCredentialListParams, recordChannel chan TrunkingV1CredentialList, errorChannel chan error) { curRecord := 1 for response != nil { @@ -217,7 +239,7 @@ func (c *ApiService) streamCredentialList(response *ListCredentialListResponse, } } - record, err := client.GetNext(c.baseURL, response, c.getNextListCredentialListResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListCredentialListResponseWithContext) if err != nil { errorChannel <- err break @@ -232,11 +254,11 @@ func (c *ApiService) streamCredentialList(response *ListCredentialListResponse, close(errorChannel) } -func (c *ApiService) getNextListCredentialListResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListCredentialListResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/trunking/v1/trunks_ip_access_control_lists.go b/rest/trunking/v1/trunks_ip_access_control_lists.go index 87fa47ae2..e54f2ea86 100644 --- a/rest/trunking/v1/trunks_ip_access_control_lists.go +++ b/rest/trunking/v1/trunks_ip_access_control_lists.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -36,6 +37,9 @@ func (params *CreateIpAccessControlListParams) SetIpAccessControlListSid(IpAcces // Associate an IP Access Control List with a Trunk func (c *ApiService) CreateIpAccessControlList(TrunkSid string, params *CreateIpAccessControlListParams) (*TrunkingV1IpAccessControlList, error) { + return c.CreateIpAccessControlListWithContext(context.TODO(), TrunkSid, params) +} +func (c *ApiService) CreateIpAccessControlListWithContext(ctx context.Context, TrunkSid string, params *CreateIpAccessControlListParams) (*TrunkingV1IpAccessControlList, error) { path := "/v1/Trunks/{TrunkSid}/IpAccessControlLists" path = strings.Replace(path, "{"+"TrunkSid"+"}", TrunkSid, -1) @@ -48,7 +52,7 @@ func (c *ApiService) CreateIpAccessControlList(TrunkSid string, params *CreateIp data.Set("IpAccessControlListSid", *params.IpAccessControlListSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -65,6 +69,9 @@ func (c *ApiService) CreateIpAccessControlList(TrunkSid string, params *CreateIp // Remove an associated IP Access Control List from a Trunk func (c *ApiService) DeleteIpAccessControlList(TrunkSid string, Sid string) error { + return c.DeleteIpAccessControlListWithContext(context.TODO(), TrunkSid, Sid) +} +func (c *ApiService) DeleteIpAccessControlListWithContext(ctx context.Context, TrunkSid string, Sid string) error { path := "/v1/Trunks/{TrunkSid}/IpAccessControlLists/{Sid}" path = strings.Replace(path, "{"+"TrunkSid"+"}", TrunkSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -74,7 +81,7 @@ func (c *ApiService) DeleteIpAccessControlList(TrunkSid string, Sid string) erro "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -84,8 +91,10 @@ func (c *ApiService) DeleteIpAccessControlList(TrunkSid string, Sid string) erro return nil } -// func (c *ApiService) FetchIpAccessControlList(TrunkSid string, Sid string) (*TrunkingV1IpAccessControlList, error) { + return c.FetchIpAccessControlListWithContext(context.TODO(), TrunkSid, Sid) +} +func (c *ApiService) FetchIpAccessControlListWithContext(ctx context.Context, TrunkSid string, Sid string) (*TrunkingV1IpAccessControlList, error) { path := "/v1/Trunks/{TrunkSid}/IpAccessControlLists/{Sid}" path = strings.Replace(path, "{"+"TrunkSid"+"}", TrunkSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -95,7 +104,7 @@ func (c *ApiService) FetchIpAccessControlList(TrunkSid string, Sid string) (*Tru "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -129,6 +138,11 @@ func (params *ListIpAccessControlListParams) SetLimit(Limit int) *ListIpAccessCo // Retrieve a single page of IpAccessControlList records from the API. Request is executed immediately. func (c *ApiService) PageIpAccessControlList(TrunkSid string, params *ListIpAccessControlListParams, pageToken, pageNumber string) (*ListIpAccessControlListResponse, error) { + return c.PageIpAccessControlListWithContext(context.TODO(), TrunkSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of IpAccessControlList records from the API. Request is executed immediately. +func (c *ApiService) PageIpAccessControlListWithContext(ctx context.Context, TrunkSid string, params *ListIpAccessControlListParams, pageToken, pageNumber string) (*ListIpAccessControlListResponse, error) { path := "/v1/Trunks/{TrunkSid}/IpAccessControlLists" path = strings.Replace(path, "{"+"TrunkSid"+"}", TrunkSid, -1) @@ -149,7 +163,7 @@ func (c *ApiService) PageIpAccessControlList(TrunkSid string, params *ListIpAcce data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -166,7 +180,12 @@ func (c *ApiService) PageIpAccessControlList(TrunkSid string, params *ListIpAcce // Lists IpAccessControlList records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListIpAccessControlList(TrunkSid string, params *ListIpAccessControlListParams) ([]TrunkingV1IpAccessControlList, error) { - response, errors := c.StreamIpAccessControlList(TrunkSid, params) + return c.ListIpAccessControlListWithContext(context.TODO(), TrunkSid, params) +} + +// Lists IpAccessControlList records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListIpAccessControlListWithContext(ctx context.Context, TrunkSid string, params *ListIpAccessControlListParams) ([]TrunkingV1IpAccessControlList, error) { + response, errors := c.StreamIpAccessControlListWithContext(ctx, TrunkSid, params) records := make([]TrunkingV1IpAccessControlList, 0) for record := range response { @@ -182,6 +201,11 @@ func (c *ApiService) ListIpAccessControlList(TrunkSid string, params *ListIpAcce // Streams IpAccessControlList records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamIpAccessControlList(TrunkSid string, params *ListIpAccessControlListParams) (chan TrunkingV1IpAccessControlList, chan error) { + return c.StreamIpAccessControlListWithContext(context.TODO(), TrunkSid, params) +} + +// Streams IpAccessControlList records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamIpAccessControlListWithContext(ctx context.Context, TrunkSid string, params *ListIpAccessControlListParams) (chan TrunkingV1IpAccessControlList, chan error) { if params == nil { params = &ListIpAccessControlListParams{} } @@ -190,19 +214,19 @@ func (c *ApiService) StreamIpAccessControlList(TrunkSid string, params *ListIpAc recordChannel := make(chan TrunkingV1IpAccessControlList, 1) errorChannel := make(chan error, 1) - response, err := c.PageIpAccessControlList(TrunkSid, params, "", "") + response, err := c.PageIpAccessControlListWithContext(ctx, TrunkSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamIpAccessControlList(response, params, recordChannel, errorChannel) + go c.streamIpAccessControlListWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamIpAccessControlList(response *ListIpAccessControlListResponse, params *ListIpAccessControlListParams, recordChannel chan TrunkingV1IpAccessControlList, errorChannel chan error) { +func (c *ApiService) streamIpAccessControlListWithContext(ctx context.Context, response *ListIpAccessControlListResponse, params *ListIpAccessControlListParams, recordChannel chan TrunkingV1IpAccessControlList, errorChannel chan error) { curRecord := 1 for response != nil { @@ -217,7 +241,7 @@ func (c *ApiService) streamIpAccessControlList(response *ListIpAccessControlList } } - record, err := client.GetNext(c.baseURL, response, c.getNextListIpAccessControlListResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListIpAccessControlListResponseWithContext) if err != nil { errorChannel <- err break @@ -232,11 +256,11 @@ func (c *ApiService) streamIpAccessControlList(response *ListIpAccessControlList close(errorChannel) } -func (c *ApiService) getNextListIpAccessControlListResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListIpAccessControlListResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/trunking/v1/trunks_origination_urls.go b/rest/trunking/v1/trunks_origination_urls.go index 135109c9c..1244a3787 100644 --- a/rest/trunking/v1/trunks_origination_urls.go +++ b/rest/trunking/v1/trunks_origination_urls.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -58,8 +59,10 @@ func (params *CreateOriginationUrlParams) SetSipUrl(SipUrl string) *CreateOrigin return params } -// func (c *ApiService) CreateOriginationUrl(TrunkSid string, params *CreateOriginationUrlParams) (*TrunkingV1OriginationUrl, error) { + return c.CreateOriginationUrlWithContext(context.TODO(), TrunkSid, params) +} +func (c *ApiService) CreateOriginationUrlWithContext(ctx context.Context, TrunkSid string, params *CreateOriginationUrlParams) (*TrunkingV1OriginationUrl, error) { path := "/v1/Trunks/{TrunkSid}/OriginationUrls" path = strings.Replace(path, "{"+"TrunkSid"+"}", TrunkSid, -1) @@ -84,7 +87,7 @@ func (c *ApiService) CreateOriginationUrl(TrunkSid string, params *CreateOrigina data.Set("SipUrl", *params.SipUrl) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -99,8 +102,10 @@ func (c *ApiService) CreateOriginationUrl(TrunkSid string, params *CreateOrigina return ps, err } -// func (c *ApiService) DeleteOriginationUrl(TrunkSid string, Sid string) error { + return c.DeleteOriginationUrlWithContext(context.TODO(), TrunkSid, Sid) +} +func (c *ApiService) DeleteOriginationUrlWithContext(ctx context.Context, TrunkSid string, Sid string) error { path := "/v1/Trunks/{TrunkSid}/OriginationUrls/{Sid}" path = strings.Replace(path, "{"+"TrunkSid"+"}", TrunkSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -110,7 +115,7 @@ func (c *ApiService) DeleteOriginationUrl(TrunkSid string, Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -120,8 +125,10 @@ func (c *ApiService) DeleteOriginationUrl(TrunkSid string, Sid string) error { return nil } -// func (c *ApiService) FetchOriginationUrl(TrunkSid string, Sid string) (*TrunkingV1OriginationUrl, error) { + return c.FetchOriginationUrlWithContext(context.TODO(), TrunkSid, Sid) +} +func (c *ApiService) FetchOriginationUrlWithContext(ctx context.Context, TrunkSid string, Sid string) (*TrunkingV1OriginationUrl, error) { path := "/v1/Trunks/{TrunkSid}/OriginationUrls/{Sid}" path = strings.Replace(path, "{"+"TrunkSid"+"}", TrunkSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -131,7 +138,7 @@ func (c *ApiService) FetchOriginationUrl(TrunkSid string, Sid string) (*Trunking "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -165,6 +172,11 @@ func (params *ListOriginationUrlParams) SetLimit(Limit int) *ListOriginationUrlP // Retrieve a single page of OriginationUrl records from the API. Request is executed immediately. func (c *ApiService) PageOriginationUrl(TrunkSid string, params *ListOriginationUrlParams, pageToken, pageNumber string) (*ListOriginationUrlResponse, error) { + return c.PageOriginationUrlWithContext(context.TODO(), TrunkSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of OriginationUrl records from the API. Request is executed immediately. +func (c *ApiService) PageOriginationUrlWithContext(ctx context.Context, TrunkSid string, params *ListOriginationUrlParams, pageToken, pageNumber string) (*ListOriginationUrlResponse, error) { path := "/v1/Trunks/{TrunkSid}/OriginationUrls" path = strings.Replace(path, "{"+"TrunkSid"+"}", TrunkSid, -1) @@ -185,7 +197,7 @@ func (c *ApiService) PageOriginationUrl(TrunkSid string, params *ListOrigination data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -202,7 +214,12 @@ func (c *ApiService) PageOriginationUrl(TrunkSid string, params *ListOrigination // Lists OriginationUrl records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListOriginationUrl(TrunkSid string, params *ListOriginationUrlParams) ([]TrunkingV1OriginationUrl, error) { - response, errors := c.StreamOriginationUrl(TrunkSid, params) + return c.ListOriginationUrlWithContext(context.TODO(), TrunkSid, params) +} + +// Lists OriginationUrl records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListOriginationUrlWithContext(ctx context.Context, TrunkSid string, params *ListOriginationUrlParams) ([]TrunkingV1OriginationUrl, error) { + response, errors := c.StreamOriginationUrlWithContext(ctx, TrunkSid, params) records := make([]TrunkingV1OriginationUrl, 0) for record := range response { @@ -218,6 +235,11 @@ func (c *ApiService) ListOriginationUrl(TrunkSid string, params *ListOrigination // Streams OriginationUrl records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamOriginationUrl(TrunkSid string, params *ListOriginationUrlParams) (chan TrunkingV1OriginationUrl, chan error) { + return c.StreamOriginationUrlWithContext(context.TODO(), TrunkSid, params) +} + +// Streams OriginationUrl records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamOriginationUrlWithContext(ctx context.Context, TrunkSid string, params *ListOriginationUrlParams) (chan TrunkingV1OriginationUrl, chan error) { if params == nil { params = &ListOriginationUrlParams{} } @@ -226,19 +248,19 @@ func (c *ApiService) StreamOriginationUrl(TrunkSid string, params *ListOriginati recordChannel := make(chan TrunkingV1OriginationUrl, 1) errorChannel := make(chan error, 1) - response, err := c.PageOriginationUrl(TrunkSid, params, "", "") + response, err := c.PageOriginationUrlWithContext(ctx, TrunkSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamOriginationUrl(response, params, recordChannel, errorChannel) + go c.streamOriginationUrlWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamOriginationUrl(response *ListOriginationUrlResponse, params *ListOriginationUrlParams, recordChannel chan TrunkingV1OriginationUrl, errorChannel chan error) { +func (c *ApiService) streamOriginationUrlWithContext(ctx context.Context, response *ListOriginationUrlResponse, params *ListOriginationUrlParams, recordChannel chan TrunkingV1OriginationUrl, errorChannel chan error) { curRecord := 1 for response != nil { @@ -253,7 +275,7 @@ func (c *ApiService) streamOriginationUrl(response *ListOriginationUrlResponse, } } - record, err := client.GetNext(c.baseURL, response, c.getNextListOriginationUrlResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListOriginationUrlResponseWithContext) if err != nil { errorChannel <- err break @@ -268,11 +290,11 @@ func (c *ApiService) streamOriginationUrl(response *ListOriginationUrlResponse, close(errorChannel) } -func (c *ApiService) getNextListOriginationUrlResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListOriginationUrlResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -321,8 +343,10 @@ func (params *UpdateOriginationUrlParams) SetSipUrl(SipUrl string) *UpdateOrigin return params } -// func (c *ApiService) UpdateOriginationUrl(TrunkSid string, Sid string, params *UpdateOriginationUrlParams) (*TrunkingV1OriginationUrl, error) { + return c.UpdateOriginationUrlWithContext(context.TODO(), TrunkSid, Sid, params) +} +func (c *ApiService) UpdateOriginationUrlWithContext(ctx context.Context, TrunkSid string, Sid string, params *UpdateOriginationUrlParams) (*TrunkingV1OriginationUrl, error) { path := "/v1/Trunks/{TrunkSid}/OriginationUrls/{Sid}" path = strings.Replace(path, "{"+"TrunkSid"+"}", TrunkSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -348,7 +372,7 @@ func (c *ApiService) UpdateOriginationUrl(TrunkSid string, Sid string, params *U data.Set("SipUrl", *params.SipUrl) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/trunking/v1/trunks_phone_numbers.go b/rest/trunking/v1/trunks_phone_numbers.go index 4f83a2672..6ed0e4ff6 100644 --- a/rest/trunking/v1/trunks_phone_numbers.go +++ b/rest/trunking/v1/trunks_phone_numbers.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -34,8 +35,10 @@ func (params *CreatePhoneNumberParams) SetPhoneNumberSid(PhoneNumberSid string) return params } -// func (c *ApiService) CreatePhoneNumber(TrunkSid string, params *CreatePhoneNumberParams) (*TrunkingV1PhoneNumber, error) { + return c.CreatePhoneNumberWithContext(context.TODO(), TrunkSid, params) +} +func (c *ApiService) CreatePhoneNumberWithContext(ctx context.Context, TrunkSid string, params *CreatePhoneNumberParams) (*TrunkingV1PhoneNumber, error) { path := "/v1/Trunks/{TrunkSid}/PhoneNumbers" path = strings.Replace(path, "{"+"TrunkSid"+"}", TrunkSid, -1) @@ -48,7 +51,7 @@ func (c *ApiService) CreatePhoneNumber(TrunkSid string, params *CreatePhoneNumbe data.Set("PhoneNumberSid", *params.PhoneNumberSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -63,8 +66,10 @@ func (c *ApiService) CreatePhoneNumber(TrunkSid string, params *CreatePhoneNumbe return ps, err } -// func (c *ApiService) DeletePhoneNumber(TrunkSid string, Sid string) error { + return c.DeletePhoneNumberWithContext(context.TODO(), TrunkSid, Sid) +} +func (c *ApiService) DeletePhoneNumberWithContext(ctx context.Context, TrunkSid string, Sid string) error { path := "/v1/Trunks/{TrunkSid}/PhoneNumbers/{Sid}" path = strings.Replace(path, "{"+"TrunkSid"+"}", TrunkSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -74,7 +79,7 @@ func (c *ApiService) DeletePhoneNumber(TrunkSid string, Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -84,8 +89,10 @@ func (c *ApiService) DeletePhoneNumber(TrunkSid string, Sid string) error { return nil } -// func (c *ApiService) FetchPhoneNumber(TrunkSid string, Sid string) (*TrunkingV1PhoneNumber, error) { + return c.FetchPhoneNumberWithContext(context.TODO(), TrunkSid, Sid) +} +func (c *ApiService) FetchPhoneNumberWithContext(ctx context.Context, TrunkSid string, Sid string) (*TrunkingV1PhoneNumber, error) { path := "/v1/Trunks/{TrunkSid}/PhoneNumbers/{Sid}" path = strings.Replace(path, "{"+"TrunkSid"+"}", TrunkSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -95,7 +102,7 @@ func (c *ApiService) FetchPhoneNumber(TrunkSid string, Sid string) (*TrunkingV1P "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -129,6 +136,11 @@ func (params *ListPhoneNumberParams) SetLimit(Limit int) *ListPhoneNumberParams // Retrieve a single page of PhoneNumber records from the API. Request is executed immediately. func (c *ApiService) PagePhoneNumber(TrunkSid string, params *ListPhoneNumberParams, pageToken, pageNumber string) (*ListPhoneNumberResponse, error) { + return c.PagePhoneNumberWithContext(context.TODO(), TrunkSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of PhoneNumber records from the API. Request is executed immediately. +func (c *ApiService) PagePhoneNumberWithContext(ctx context.Context, TrunkSid string, params *ListPhoneNumberParams, pageToken, pageNumber string) (*ListPhoneNumberResponse, error) { path := "/v1/Trunks/{TrunkSid}/PhoneNumbers" path = strings.Replace(path, "{"+"TrunkSid"+"}", TrunkSid, -1) @@ -149,7 +161,7 @@ func (c *ApiService) PagePhoneNumber(TrunkSid string, params *ListPhoneNumberPar data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -166,7 +178,12 @@ func (c *ApiService) PagePhoneNumber(TrunkSid string, params *ListPhoneNumberPar // Lists PhoneNumber records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListPhoneNumber(TrunkSid string, params *ListPhoneNumberParams) ([]TrunkingV1PhoneNumber, error) { - response, errors := c.StreamPhoneNumber(TrunkSid, params) + return c.ListPhoneNumberWithContext(context.TODO(), TrunkSid, params) +} + +// Lists PhoneNumber records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListPhoneNumberWithContext(ctx context.Context, TrunkSid string, params *ListPhoneNumberParams) ([]TrunkingV1PhoneNumber, error) { + response, errors := c.StreamPhoneNumberWithContext(ctx, TrunkSid, params) records := make([]TrunkingV1PhoneNumber, 0) for record := range response { @@ -182,6 +199,11 @@ func (c *ApiService) ListPhoneNumber(TrunkSid string, params *ListPhoneNumberPar // Streams PhoneNumber records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamPhoneNumber(TrunkSid string, params *ListPhoneNumberParams) (chan TrunkingV1PhoneNumber, chan error) { + return c.StreamPhoneNumberWithContext(context.TODO(), TrunkSid, params) +} + +// Streams PhoneNumber records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamPhoneNumberWithContext(ctx context.Context, TrunkSid string, params *ListPhoneNumberParams) (chan TrunkingV1PhoneNumber, chan error) { if params == nil { params = &ListPhoneNumberParams{} } @@ -190,19 +212,19 @@ func (c *ApiService) StreamPhoneNumber(TrunkSid string, params *ListPhoneNumberP recordChannel := make(chan TrunkingV1PhoneNumber, 1) errorChannel := make(chan error, 1) - response, err := c.PagePhoneNumber(TrunkSid, params, "", "") + response, err := c.PagePhoneNumberWithContext(ctx, TrunkSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamPhoneNumber(response, params, recordChannel, errorChannel) + go c.streamPhoneNumberWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamPhoneNumber(response *ListPhoneNumberResponse, params *ListPhoneNumberParams, recordChannel chan TrunkingV1PhoneNumber, errorChannel chan error) { +func (c *ApiService) streamPhoneNumberWithContext(ctx context.Context, response *ListPhoneNumberResponse, params *ListPhoneNumberParams, recordChannel chan TrunkingV1PhoneNumber, errorChannel chan error) { curRecord := 1 for response != nil { @@ -217,7 +239,7 @@ func (c *ApiService) streamPhoneNumber(response *ListPhoneNumberResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListPhoneNumberResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListPhoneNumberResponseWithContext) if err != nil { errorChannel <- err break @@ -232,11 +254,11 @@ func (c *ApiService) streamPhoneNumber(response *ListPhoneNumberResponse, params close(errorChannel) } -func (c *ApiService) getNextListPhoneNumberResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListPhoneNumberResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/trunking/v1/trunks_recording.go b/rest/trunking/v1/trunks_recording.go index 2386f48b1..0d688e210 100644 --- a/rest/trunking/v1/trunks_recording.go +++ b/rest/trunking/v1/trunks_recording.go @@ -15,14 +15,17 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" "strings" ) -// func (c *ApiService) FetchRecording(TrunkSid string) (*TrunkingV1Recording, error) { + return c.FetchRecordingWithContext(context.TODO(), TrunkSid) +} +func (c *ApiService) FetchRecordingWithContext(ctx context.Context, TrunkSid string) (*TrunkingV1Recording, error) { path := "/v1/Trunks/{TrunkSid}/Recording" path = strings.Replace(path, "{"+"TrunkSid"+"}", TrunkSid, -1) @@ -31,7 +34,7 @@ func (c *ApiService) FetchRecording(TrunkSid string) (*TrunkingV1Recording, erro "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -63,8 +66,10 @@ func (params *UpdateRecordingParams) SetTrim(Trim string) *UpdateRecordingParams return params } -// func (c *ApiService) UpdateRecording(TrunkSid string, params *UpdateRecordingParams) (*TrunkingV1Recording, error) { + return c.UpdateRecordingWithContext(context.TODO(), TrunkSid, params) +} +func (c *ApiService) UpdateRecordingWithContext(ctx context.Context, TrunkSid string, params *UpdateRecordingParams) (*TrunkingV1Recording, error) { path := "/v1/Trunks/{TrunkSid}/Recording" path = strings.Replace(path, "{"+"TrunkSid"+"}", TrunkSid, -1) @@ -80,7 +85,7 @@ func (c *ApiService) UpdateRecording(TrunkSid string, params *UpdateRecordingPar data.Set("Trim", fmt.Sprint(*params.Trim)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/trusthub/v1/api_service.go b/rest/trusthub/v1/api_service.go index 7adabd338..c307e8f3c 100644 --- a/rest/trusthub/v1/api_service.go +++ b/rest/trusthub/v1/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://trusthub.twilio.com", + } +} diff --git a/rest/trusthub/v1/compliance_inquiries_customers_initialize.go b/rest/trusthub/v1/compliance_inquiries_customers_initialize.go index 8c4265aa3..10ab756eb 100644 --- a/rest/trusthub/v1/compliance_inquiries_customers_initialize.go +++ b/rest/trusthub/v1/compliance_inquiries_customers_initialize.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -45,6 +46,9 @@ func (params *CreateComplianceInquiryParams) SetThemeSetId(ThemeSetId string) *C // Create a new Compliance Inquiry for the authenticated account. This is necessary to start a new embedded session. func (c *ApiService) CreateComplianceInquiry(params *CreateComplianceInquiryParams) (*TrusthubV1ComplianceInquiry, error) { + return c.CreateComplianceInquiryWithContext(context.TODO(), params) +} +func (c *ApiService) CreateComplianceInquiryWithContext(ctx context.Context, params *CreateComplianceInquiryParams) (*TrusthubV1ComplianceInquiry, error) { path := "/v1/ComplianceInquiries/Customers/Initialize" data := url.Values{} @@ -62,7 +66,7 @@ func (c *ApiService) CreateComplianceInquiry(params *CreateComplianceInquiryPara data.Set("ThemeSetId", *params.ThemeSetId) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -96,6 +100,9 @@ func (params *UpdateComplianceInquiryParams) SetThemeSetId(ThemeSetId string) *U // Resume a specific Compliance Inquiry that has expired, or re-open a rejected Compliance Inquiry for editing. func (c *ApiService) UpdateComplianceInquiry(CustomerId string, params *UpdateComplianceInquiryParams) (*TrusthubV1ComplianceInquiry, error) { + return c.UpdateComplianceInquiryWithContext(context.TODO(), CustomerId, params) +} +func (c *ApiService) UpdateComplianceInquiryWithContext(ctx context.Context, CustomerId string, params *UpdateComplianceInquiryParams) (*TrusthubV1ComplianceInquiry, error) { path := "/v1/ComplianceInquiries/Customers/{CustomerId}/Initialize" path = strings.Replace(path, "{"+"CustomerId"+"}", CustomerId, -1) @@ -111,7 +118,7 @@ func (c *ApiService) UpdateComplianceInquiry(CustomerId string, params *UpdateCo data.Set("ThemeSetId", *params.ThemeSetId) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/trusthub/v1/compliance_inquiries_registration_regulatory_compliance_gb_initialize.go b/rest/trusthub/v1/compliance_inquiries_registration_regulatory_compliance_gb_initialize.go index fb4dee719..dfb97d0cf 100644 --- a/rest/trusthub/v1/compliance_inquiries_registration_regulatory_compliance_gb_initialize.go +++ b/rest/trusthub/v1/compliance_inquiries_registration_regulatory_compliance_gb_initialize.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -262,6 +263,9 @@ func (params *CreateComplianceRegistrationParams) SetThemeSetId(ThemeSetId strin // Create a new Compliance Registration Inquiry for the authenticated account. This is necessary to start a new embedded session. func (c *ApiService) CreateComplianceRegistration(params *CreateComplianceRegistrationParams) (*TrusthubV1ComplianceRegistration, error) { + return c.CreateComplianceRegistrationWithContext(context.TODO(), params) +} +func (c *ApiService) CreateComplianceRegistrationWithContext(ctx context.Context, params *CreateComplianceRegistrationParams) (*TrusthubV1ComplianceRegistration, error) { path := "/v1/ComplianceInquiries/Registration/RegulatoryCompliance/GB/Initialize" data := url.Values{} @@ -387,7 +391,7 @@ func (c *ApiService) CreateComplianceRegistration(params *CreateComplianceRegist data.Set("ThemeSetId", *params.ThemeSetId) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -421,6 +425,9 @@ func (params *UpdateComplianceRegistrationParams) SetThemeSetId(ThemeSetId strin // Resume a specific Regulatory Compliance Inquiry that has expired, or re-open a rejected Compliance Inquiry for editing. func (c *ApiService) UpdateComplianceRegistration(RegistrationId string, params *UpdateComplianceRegistrationParams) (*TrusthubV1ComplianceRegistration, error) { + return c.UpdateComplianceRegistrationWithContext(context.TODO(), RegistrationId, params) +} +func (c *ApiService) UpdateComplianceRegistrationWithContext(ctx context.Context, RegistrationId string, params *UpdateComplianceRegistrationParams) (*TrusthubV1ComplianceRegistration, error) { path := "/v1/ComplianceInquiries/Registration/{RegistrationId}/RegulatoryCompliance/GB/Initialize" path = strings.Replace(path, "{"+"RegistrationId"+"}", RegistrationId, -1) @@ -436,7 +443,7 @@ func (c *ApiService) UpdateComplianceRegistration(RegistrationId string, params data.Set("ThemeSetId", *params.ThemeSetId) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/trusthub/v1/compliance_inquiries_tollfree_initialize.go b/rest/trusthub/v1/compliance_inquiries_tollfree_initialize.go index 2923ca9c0..e64cc4568 100644 --- a/rest/trusthub/v1/compliance_inquiries_tollfree_initialize.go +++ b/rest/trusthub/v1/compliance_inquiries_tollfree_initialize.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -165,6 +166,9 @@ func (params *CreateComplianceTollfreeInquiryParams) SetSkipMessagingUseCase(Ski // Create a new Compliance Tollfree Verification Inquiry for the authenticated account. This is necessary to start a new embedded session. func (c *ApiService) CreateComplianceTollfreeInquiry(params *CreateComplianceTollfreeInquiryParams) (*TrusthubV1ComplianceTollfreeInquiry, error) { + return c.CreateComplianceTollfreeInquiryWithContext(context.TODO(), params) +} +func (c *ApiService) CreateComplianceTollfreeInquiryWithContext(ctx context.Context, params *CreateComplianceTollfreeInquiryParams) (*TrusthubV1ComplianceTollfreeInquiry, error) { path := "/v1/ComplianceInquiries/Tollfree/Initialize" data := url.Values{} @@ -246,7 +250,7 @@ func (c *ApiService) CreateComplianceTollfreeInquiry(params *CreateComplianceTol data.Set("SkipMessagingUseCase", fmt.Sprint(*params.SkipMessagingUseCase)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/trusthub/v1/customer_profiles.go b/rest/trusthub/v1/customer_profiles.go index 2fbc7141d..b25df3816 100644 --- a/rest/trusthub/v1/customer_profiles.go +++ b/rest/trusthub/v1/customer_profiles.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -54,6 +55,9 @@ func (params *CreateCustomerProfileParams) SetStatusCallback(StatusCallback stri // Create a new Customer-Profile. func (c *ApiService) CreateCustomerProfile(params *CreateCustomerProfileParams) (*TrusthubV1CustomerProfile, error) { + return c.CreateCustomerProfileWithContext(context.TODO(), params) +} +func (c *ApiService) CreateCustomerProfileWithContext(ctx context.Context, params *CreateCustomerProfileParams) (*TrusthubV1CustomerProfile, error) { path := "/v1/CustomerProfiles" data := url.Values{} @@ -74,7 +78,7 @@ func (c *ApiService) CreateCustomerProfile(params *CreateCustomerProfileParams) data.Set("StatusCallback", *params.StatusCallback) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -91,6 +95,9 @@ func (c *ApiService) CreateCustomerProfile(params *CreateCustomerProfileParams) // Delete a specific Customer-Profile. func (c *ApiService) DeleteCustomerProfile(Sid string) error { + return c.DeleteCustomerProfileWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteCustomerProfileWithContext(ctx context.Context, Sid string) error { path := "/v1/CustomerProfiles/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -99,7 +106,7 @@ func (c *ApiService) DeleteCustomerProfile(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -111,6 +118,9 @@ func (c *ApiService) DeleteCustomerProfile(Sid string) error { // Fetch a specific Customer-Profile instance. func (c *ApiService) FetchCustomerProfile(Sid string) (*TrusthubV1CustomerProfile, error) { + return c.FetchCustomerProfileWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchCustomerProfileWithContext(ctx context.Context, Sid string) (*TrusthubV1CustomerProfile, error) { path := "/v1/CustomerProfiles/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -119,7 +129,7 @@ func (c *ApiService) FetchCustomerProfile(Sid string) (*TrusthubV1CustomerProfil "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -171,6 +181,11 @@ func (params *ListCustomerProfileParams) SetLimit(Limit int) *ListCustomerProfil // Retrieve a single page of CustomerProfile records from the API. Request is executed immediately. func (c *ApiService) PageCustomerProfile(params *ListCustomerProfileParams, pageToken, pageNumber string) (*ListCustomerProfileResponse, error) { + return c.PageCustomerProfileWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of CustomerProfile records from the API. Request is executed immediately. +func (c *ApiService) PageCustomerProfileWithContext(ctx context.Context, params *ListCustomerProfileParams, pageToken, pageNumber string) (*ListCustomerProfileResponse, error) { path := "/v1/CustomerProfiles" data := url.Values{} @@ -198,7 +213,7 @@ func (c *ApiService) PageCustomerProfile(params *ListCustomerProfileParams, page data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -215,7 +230,12 @@ func (c *ApiService) PageCustomerProfile(params *ListCustomerProfileParams, page // Lists CustomerProfile records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListCustomerProfile(params *ListCustomerProfileParams) ([]TrusthubV1CustomerProfile, error) { - response, errors := c.StreamCustomerProfile(params) + return c.ListCustomerProfileWithContext(context.TODO(), params) +} + +// Lists CustomerProfile records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListCustomerProfileWithContext(ctx context.Context, params *ListCustomerProfileParams) ([]TrusthubV1CustomerProfile, error) { + response, errors := c.StreamCustomerProfileWithContext(ctx, params) records := make([]TrusthubV1CustomerProfile, 0) for record := range response { @@ -231,6 +251,11 @@ func (c *ApiService) ListCustomerProfile(params *ListCustomerProfileParams) ([]T // Streams CustomerProfile records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamCustomerProfile(params *ListCustomerProfileParams) (chan TrusthubV1CustomerProfile, chan error) { + return c.StreamCustomerProfileWithContext(context.TODO(), params) +} + +// Streams CustomerProfile records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamCustomerProfileWithContext(ctx context.Context, params *ListCustomerProfileParams) (chan TrusthubV1CustomerProfile, chan error) { if params == nil { params = &ListCustomerProfileParams{} } @@ -239,19 +264,19 @@ func (c *ApiService) StreamCustomerProfile(params *ListCustomerProfileParams) (c recordChannel := make(chan TrusthubV1CustomerProfile, 1) errorChannel := make(chan error, 1) - response, err := c.PageCustomerProfile(params, "", "") + response, err := c.PageCustomerProfileWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamCustomerProfile(response, params, recordChannel, errorChannel) + go c.streamCustomerProfileWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamCustomerProfile(response *ListCustomerProfileResponse, params *ListCustomerProfileParams, recordChannel chan TrusthubV1CustomerProfile, errorChannel chan error) { +func (c *ApiService) streamCustomerProfileWithContext(ctx context.Context, response *ListCustomerProfileResponse, params *ListCustomerProfileParams, recordChannel chan TrusthubV1CustomerProfile, errorChannel chan error) { curRecord := 1 for response != nil { @@ -266,7 +291,7 @@ func (c *ApiService) streamCustomerProfile(response *ListCustomerProfileResponse } } - record, err := client.GetNext(c.baseURL, response, c.getNextListCustomerProfileResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListCustomerProfileResponseWithContext) if err != nil { errorChannel <- err break @@ -281,11 +306,11 @@ func (c *ApiService) streamCustomerProfile(response *ListCustomerProfileResponse close(errorChannel) } -func (c *ApiService) getNextListCustomerProfileResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListCustomerProfileResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -330,6 +355,9 @@ func (params *UpdateCustomerProfileParams) SetEmail(Email string) *UpdateCustome // Updates a Customer-Profile in an account. func (c *ApiService) UpdateCustomerProfile(Sid string, params *UpdateCustomerProfileParams) (*TrusthubV1CustomerProfile, error) { + return c.UpdateCustomerProfileWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateCustomerProfileWithContext(ctx context.Context, Sid string, params *UpdateCustomerProfileParams) (*TrusthubV1CustomerProfile, error) { path := "/v1/CustomerProfiles/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -351,7 +379,7 @@ func (c *ApiService) UpdateCustomerProfile(Sid string, params *UpdateCustomerPro data.Set("Email", *params.Email) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/trusthub/v1/customer_profiles_channel_endpoint_assignments.go b/rest/trusthub/v1/customer_profiles_channel_endpoint_assignments.go index ce70ae79a..6cb81aba4 100644 --- a/rest/trusthub/v1/customer_profiles_channel_endpoint_assignments.go +++ b/rest/trusthub/v1/customer_profiles_channel_endpoint_assignments.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -42,6 +43,9 @@ func (params *CreateCustomerProfileChannelEndpointAssignmentParams) SetChannelEn // Create a new Assigned Item. func (c *ApiService) CreateCustomerProfileChannelEndpointAssignment(CustomerProfileSid string, params *CreateCustomerProfileChannelEndpointAssignmentParams) (*TrusthubV1CustomerProfileChannelEndpointAssignment, error) { + return c.CreateCustomerProfileChannelEndpointAssignmentWithContext(context.TODO(), CustomerProfileSid, params) +} +func (c *ApiService) CreateCustomerProfileChannelEndpointAssignmentWithContext(ctx context.Context, CustomerProfileSid string, params *CreateCustomerProfileChannelEndpointAssignmentParams) (*TrusthubV1CustomerProfileChannelEndpointAssignment, error) { path := "/v1/CustomerProfiles/{CustomerProfileSid}/ChannelEndpointAssignments" path = strings.Replace(path, "{"+"CustomerProfileSid"+"}", CustomerProfileSid, -1) @@ -57,7 +61,7 @@ func (c *ApiService) CreateCustomerProfileChannelEndpointAssignment(CustomerProf data.Set("ChannelEndpointSid", *params.ChannelEndpointSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -74,6 +78,9 @@ func (c *ApiService) CreateCustomerProfileChannelEndpointAssignment(CustomerProf // Remove an Assignment Item Instance. func (c *ApiService) DeleteCustomerProfileChannelEndpointAssignment(CustomerProfileSid string, Sid string) error { + return c.DeleteCustomerProfileChannelEndpointAssignmentWithContext(context.TODO(), CustomerProfileSid, Sid) +} +func (c *ApiService) DeleteCustomerProfileChannelEndpointAssignmentWithContext(ctx context.Context, CustomerProfileSid string, Sid string) error { path := "/v1/CustomerProfiles/{CustomerProfileSid}/ChannelEndpointAssignments/{Sid}" path = strings.Replace(path, "{"+"CustomerProfileSid"+"}", CustomerProfileSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -83,7 +90,7 @@ func (c *ApiService) DeleteCustomerProfileChannelEndpointAssignment(CustomerProf "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -95,6 +102,9 @@ func (c *ApiService) DeleteCustomerProfileChannelEndpointAssignment(CustomerProf // Fetch specific Assigned Item Instance. func (c *ApiService) FetchCustomerProfileChannelEndpointAssignment(CustomerProfileSid string, Sid string) (*TrusthubV1CustomerProfileChannelEndpointAssignment, error) { + return c.FetchCustomerProfileChannelEndpointAssignmentWithContext(context.TODO(), CustomerProfileSid, Sid) +} +func (c *ApiService) FetchCustomerProfileChannelEndpointAssignmentWithContext(ctx context.Context, CustomerProfileSid string, Sid string) (*TrusthubV1CustomerProfileChannelEndpointAssignment, error) { path := "/v1/CustomerProfiles/{CustomerProfileSid}/ChannelEndpointAssignments/{Sid}" path = strings.Replace(path, "{"+"CustomerProfileSid"+"}", CustomerProfileSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -104,7 +114,7 @@ func (c *ApiService) FetchCustomerProfileChannelEndpointAssignment(CustomerProfi "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -150,6 +160,11 @@ func (params *ListCustomerProfileChannelEndpointAssignmentParams) SetLimit(Limit // Retrieve a single page of CustomerProfileChannelEndpointAssignment records from the API. Request is executed immediately. func (c *ApiService) PageCustomerProfileChannelEndpointAssignment(CustomerProfileSid string, params *ListCustomerProfileChannelEndpointAssignmentParams, pageToken, pageNumber string) (*ListCustomerProfileChannelEndpointAssignmentResponse, error) { + return c.PageCustomerProfileChannelEndpointAssignmentWithContext(context.TODO(), CustomerProfileSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of CustomerProfileChannelEndpointAssignment records from the API. Request is executed immediately. +func (c *ApiService) PageCustomerProfileChannelEndpointAssignmentWithContext(ctx context.Context, CustomerProfileSid string, params *ListCustomerProfileChannelEndpointAssignmentParams, pageToken, pageNumber string) (*ListCustomerProfileChannelEndpointAssignmentResponse, error) { path := "/v1/CustomerProfiles/{CustomerProfileSid}/ChannelEndpointAssignments" path = strings.Replace(path, "{"+"CustomerProfileSid"+"}", CustomerProfileSid, -1) @@ -176,7 +191,7 @@ func (c *ApiService) PageCustomerProfileChannelEndpointAssignment(CustomerProfil data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -193,7 +208,12 @@ func (c *ApiService) PageCustomerProfileChannelEndpointAssignment(CustomerProfil // Lists CustomerProfileChannelEndpointAssignment records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListCustomerProfileChannelEndpointAssignment(CustomerProfileSid string, params *ListCustomerProfileChannelEndpointAssignmentParams) ([]TrusthubV1CustomerProfileChannelEndpointAssignment, error) { - response, errors := c.StreamCustomerProfileChannelEndpointAssignment(CustomerProfileSid, params) + return c.ListCustomerProfileChannelEndpointAssignmentWithContext(context.TODO(), CustomerProfileSid, params) +} + +// Lists CustomerProfileChannelEndpointAssignment records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListCustomerProfileChannelEndpointAssignmentWithContext(ctx context.Context, CustomerProfileSid string, params *ListCustomerProfileChannelEndpointAssignmentParams) ([]TrusthubV1CustomerProfileChannelEndpointAssignment, error) { + response, errors := c.StreamCustomerProfileChannelEndpointAssignmentWithContext(ctx, CustomerProfileSid, params) records := make([]TrusthubV1CustomerProfileChannelEndpointAssignment, 0) for record := range response { @@ -209,6 +229,11 @@ func (c *ApiService) ListCustomerProfileChannelEndpointAssignment(CustomerProfil // Streams CustomerProfileChannelEndpointAssignment records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamCustomerProfileChannelEndpointAssignment(CustomerProfileSid string, params *ListCustomerProfileChannelEndpointAssignmentParams) (chan TrusthubV1CustomerProfileChannelEndpointAssignment, chan error) { + return c.StreamCustomerProfileChannelEndpointAssignmentWithContext(context.TODO(), CustomerProfileSid, params) +} + +// Streams CustomerProfileChannelEndpointAssignment records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamCustomerProfileChannelEndpointAssignmentWithContext(ctx context.Context, CustomerProfileSid string, params *ListCustomerProfileChannelEndpointAssignmentParams) (chan TrusthubV1CustomerProfileChannelEndpointAssignment, chan error) { if params == nil { params = &ListCustomerProfileChannelEndpointAssignmentParams{} } @@ -217,19 +242,19 @@ func (c *ApiService) StreamCustomerProfileChannelEndpointAssignment(CustomerProf recordChannel := make(chan TrusthubV1CustomerProfileChannelEndpointAssignment, 1) errorChannel := make(chan error, 1) - response, err := c.PageCustomerProfileChannelEndpointAssignment(CustomerProfileSid, params, "", "") + response, err := c.PageCustomerProfileChannelEndpointAssignmentWithContext(ctx, CustomerProfileSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamCustomerProfileChannelEndpointAssignment(response, params, recordChannel, errorChannel) + go c.streamCustomerProfileChannelEndpointAssignmentWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamCustomerProfileChannelEndpointAssignment(response *ListCustomerProfileChannelEndpointAssignmentResponse, params *ListCustomerProfileChannelEndpointAssignmentParams, recordChannel chan TrusthubV1CustomerProfileChannelEndpointAssignment, errorChannel chan error) { +func (c *ApiService) streamCustomerProfileChannelEndpointAssignmentWithContext(ctx context.Context, response *ListCustomerProfileChannelEndpointAssignmentResponse, params *ListCustomerProfileChannelEndpointAssignmentParams, recordChannel chan TrusthubV1CustomerProfileChannelEndpointAssignment, errorChannel chan error) { curRecord := 1 for response != nil { @@ -244,7 +269,7 @@ func (c *ApiService) streamCustomerProfileChannelEndpointAssignment(response *Li } } - record, err := client.GetNext(c.baseURL, response, c.getNextListCustomerProfileChannelEndpointAssignmentResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListCustomerProfileChannelEndpointAssignmentResponseWithContext) if err != nil { errorChannel <- err break @@ -259,11 +284,11 @@ func (c *ApiService) streamCustomerProfileChannelEndpointAssignment(response *Li close(errorChannel) } -func (c *ApiService) getNextListCustomerProfileChannelEndpointAssignmentResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListCustomerProfileChannelEndpointAssignmentResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/trusthub/v1/customer_profiles_entity_assignments.go b/rest/trusthub/v1/customer_profiles_entity_assignments.go index 4c02e6bff..2c5fbb482 100644 --- a/rest/trusthub/v1/customer_profiles_entity_assignments.go +++ b/rest/trusthub/v1/customer_profiles_entity_assignments.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -36,6 +37,9 @@ func (params *CreateCustomerProfileEntityAssignmentParams) SetObjectSid(ObjectSi // Create a new Assigned Item. func (c *ApiService) CreateCustomerProfileEntityAssignment(CustomerProfileSid string, params *CreateCustomerProfileEntityAssignmentParams) (*TrusthubV1CustomerProfileEntityAssignment, error) { + return c.CreateCustomerProfileEntityAssignmentWithContext(context.TODO(), CustomerProfileSid, params) +} +func (c *ApiService) CreateCustomerProfileEntityAssignmentWithContext(ctx context.Context, CustomerProfileSid string, params *CreateCustomerProfileEntityAssignmentParams) (*TrusthubV1CustomerProfileEntityAssignment, error) { path := "/v1/CustomerProfiles/{CustomerProfileSid}/EntityAssignments" path = strings.Replace(path, "{"+"CustomerProfileSid"+"}", CustomerProfileSid, -1) @@ -48,7 +52,7 @@ func (c *ApiService) CreateCustomerProfileEntityAssignment(CustomerProfileSid st data.Set("ObjectSid", *params.ObjectSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -65,6 +69,9 @@ func (c *ApiService) CreateCustomerProfileEntityAssignment(CustomerProfileSid st // Remove an Assignment Item Instance. func (c *ApiService) DeleteCustomerProfileEntityAssignment(CustomerProfileSid string, Sid string) error { + return c.DeleteCustomerProfileEntityAssignmentWithContext(context.TODO(), CustomerProfileSid, Sid) +} +func (c *ApiService) DeleteCustomerProfileEntityAssignmentWithContext(ctx context.Context, CustomerProfileSid string, Sid string) error { path := "/v1/CustomerProfiles/{CustomerProfileSid}/EntityAssignments/{Sid}" path = strings.Replace(path, "{"+"CustomerProfileSid"+"}", CustomerProfileSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -74,7 +81,7 @@ func (c *ApiService) DeleteCustomerProfileEntityAssignment(CustomerProfileSid st "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -86,6 +93,9 @@ func (c *ApiService) DeleteCustomerProfileEntityAssignment(CustomerProfileSid st // Fetch specific Assigned Item Instance. func (c *ApiService) FetchCustomerProfileEntityAssignment(CustomerProfileSid string, Sid string) (*TrusthubV1CustomerProfileEntityAssignment, error) { + return c.FetchCustomerProfileEntityAssignmentWithContext(context.TODO(), CustomerProfileSid, Sid) +} +func (c *ApiService) FetchCustomerProfileEntityAssignmentWithContext(ctx context.Context, CustomerProfileSid string, Sid string) (*TrusthubV1CustomerProfileEntityAssignment, error) { path := "/v1/CustomerProfiles/{CustomerProfileSid}/EntityAssignments/{Sid}" path = strings.Replace(path, "{"+"CustomerProfileSid"+"}", CustomerProfileSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -95,7 +105,7 @@ func (c *ApiService) FetchCustomerProfileEntityAssignment(CustomerProfileSid str "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -135,6 +145,11 @@ func (params *ListCustomerProfileEntityAssignmentParams) SetLimit(Limit int) *Li // Retrieve a single page of CustomerProfileEntityAssignment records from the API. Request is executed immediately. func (c *ApiService) PageCustomerProfileEntityAssignment(CustomerProfileSid string, params *ListCustomerProfileEntityAssignmentParams, pageToken, pageNumber string) (*ListCustomerProfileEntityAssignmentResponse, error) { + return c.PageCustomerProfileEntityAssignmentWithContext(context.TODO(), CustomerProfileSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of CustomerProfileEntityAssignment records from the API. Request is executed immediately. +func (c *ApiService) PageCustomerProfileEntityAssignmentWithContext(ctx context.Context, CustomerProfileSid string, params *ListCustomerProfileEntityAssignmentParams, pageToken, pageNumber string) (*ListCustomerProfileEntityAssignmentResponse, error) { path := "/v1/CustomerProfiles/{CustomerProfileSid}/EntityAssignments" path = strings.Replace(path, "{"+"CustomerProfileSid"+"}", CustomerProfileSid, -1) @@ -158,7 +173,7 @@ func (c *ApiService) PageCustomerProfileEntityAssignment(CustomerProfileSid stri data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -175,7 +190,12 @@ func (c *ApiService) PageCustomerProfileEntityAssignment(CustomerProfileSid stri // Lists CustomerProfileEntityAssignment records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListCustomerProfileEntityAssignment(CustomerProfileSid string, params *ListCustomerProfileEntityAssignmentParams) ([]TrusthubV1CustomerProfileEntityAssignment, error) { - response, errors := c.StreamCustomerProfileEntityAssignment(CustomerProfileSid, params) + return c.ListCustomerProfileEntityAssignmentWithContext(context.TODO(), CustomerProfileSid, params) +} + +// Lists CustomerProfileEntityAssignment records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListCustomerProfileEntityAssignmentWithContext(ctx context.Context, CustomerProfileSid string, params *ListCustomerProfileEntityAssignmentParams) ([]TrusthubV1CustomerProfileEntityAssignment, error) { + response, errors := c.StreamCustomerProfileEntityAssignmentWithContext(ctx, CustomerProfileSid, params) records := make([]TrusthubV1CustomerProfileEntityAssignment, 0) for record := range response { @@ -191,6 +211,11 @@ func (c *ApiService) ListCustomerProfileEntityAssignment(CustomerProfileSid stri // Streams CustomerProfileEntityAssignment records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamCustomerProfileEntityAssignment(CustomerProfileSid string, params *ListCustomerProfileEntityAssignmentParams) (chan TrusthubV1CustomerProfileEntityAssignment, chan error) { + return c.StreamCustomerProfileEntityAssignmentWithContext(context.TODO(), CustomerProfileSid, params) +} + +// Streams CustomerProfileEntityAssignment records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamCustomerProfileEntityAssignmentWithContext(ctx context.Context, CustomerProfileSid string, params *ListCustomerProfileEntityAssignmentParams) (chan TrusthubV1CustomerProfileEntityAssignment, chan error) { if params == nil { params = &ListCustomerProfileEntityAssignmentParams{} } @@ -199,19 +224,19 @@ func (c *ApiService) StreamCustomerProfileEntityAssignment(CustomerProfileSid st recordChannel := make(chan TrusthubV1CustomerProfileEntityAssignment, 1) errorChannel := make(chan error, 1) - response, err := c.PageCustomerProfileEntityAssignment(CustomerProfileSid, params, "", "") + response, err := c.PageCustomerProfileEntityAssignmentWithContext(ctx, CustomerProfileSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamCustomerProfileEntityAssignment(response, params, recordChannel, errorChannel) + go c.streamCustomerProfileEntityAssignmentWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamCustomerProfileEntityAssignment(response *ListCustomerProfileEntityAssignmentResponse, params *ListCustomerProfileEntityAssignmentParams, recordChannel chan TrusthubV1CustomerProfileEntityAssignment, errorChannel chan error) { +func (c *ApiService) streamCustomerProfileEntityAssignmentWithContext(ctx context.Context, response *ListCustomerProfileEntityAssignmentResponse, params *ListCustomerProfileEntityAssignmentParams, recordChannel chan TrusthubV1CustomerProfileEntityAssignment, errorChannel chan error) { curRecord := 1 for response != nil { @@ -226,7 +251,7 @@ func (c *ApiService) streamCustomerProfileEntityAssignment(response *ListCustome } } - record, err := client.GetNext(c.baseURL, response, c.getNextListCustomerProfileEntityAssignmentResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListCustomerProfileEntityAssignmentResponseWithContext) if err != nil { errorChannel <- err break @@ -241,11 +266,11 @@ func (c *ApiService) streamCustomerProfileEntityAssignment(response *ListCustome close(errorChannel) } -func (c *ApiService) getNextListCustomerProfileEntityAssignmentResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListCustomerProfileEntityAssignmentResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/trusthub/v1/customer_profiles_evaluations.go b/rest/trusthub/v1/customer_profiles_evaluations.go index 5ac4aca2d..86e8343a9 100644 --- a/rest/trusthub/v1/customer_profiles_evaluations.go +++ b/rest/trusthub/v1/customer_profiles_evaluations.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -36,6 +37,9 @@ func (params *CreateCustomerProfileEvaluationParams) SetPolicySid(PolicySid stri // Create a new Evaluation func (c *ApiService) CreateCustomerProfileEvaluation(CustomerProfileSid string, params *CreateCustomerProfileEvaluationParams) (*TrusthubV1CustomerProfileEvaluation, error) { + return c.CreateCustomerProfileEvaluationWithContext(context.TODO(), CustomerProfileSid, params) +} +func (c *ApiService) CreateCustomerProfileEvaluationWithContext(ctx context.Context, CustomerProfileSid string, params *CreateCustomerProfileEvaluationParams) (*TrusthubV1CustomerProfileEvaluation, error) { path := "/v1/CustomerProfiles/{CustomerProfileSid}/Evaluations" path = strings.Replace(path, "{"+"CustomerProfileSid"+"}", CustomerProfileSid, -1) @@ -48,7 +52,7 @@ func (c *ApiService) CreateCustomerProfileEvaluation(CustomerProfileSid string, data.Set("PolicySid", *params.PolicySid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -65,6 +69,9 @@ func (c *ApiService) CreateCustomerProfileEvaluation(CustomerProfileSid string, // Fetch specific Evaluation Instance. func (c *ApiService) FetchCustomerProfileEvaluation(CustomerProfileSid string, Sid string) (*TrusthubV1CustomerProfileEvaluation, error) { + return c.FetchCustomerProfileEvaluationWithContext(context.TODO(), CustomerProfileSid, Sid) +} +func (c *ApiService) FetchCustomerProfileEvaluationWithContext(ctx context.Context, CustomerProfileSid string, Sid string) (*TrusthubV1CustomerProfileEvaluation, error) { path := "/v1/CustomerProfiles/{CustomerProfileSid}/Evaluations/{Sid}" path = strings.Replace(path, "{"+"CustomerProfileSid"+"}", CustomerProfileSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -74,7 +81,7 @@ func (c *ApiService) FetchCustomerProfileEvaluation(CustomerProfileSid string, S "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -108,6 +115,11 @@ func (params *ListCustomerProfileEvaluationParams) SetLimit(Limit int) *ListCust // Retrieve a single page of CustomerProfileEvaluation records from the API. Request is executed immediately. func (c *ApiService) PageCustomerProfileEvaluation(CustomerProfileSid string, params *ListCustomerProfileEvaluationParams, pageToken, pageNumber string) (*ListCustomerProfileEvaluationResponse, error) { + return c.PageCustomerProfileEvaluationWithContext(context.TODO(), CustomerProfileSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of CustomerProfileEvaluation records from the API. Request is executed immediately. +func (c *ApiService) PageCustomerProfileEvaluationWithContext(ctx context.Context, CustomerProfileSid string, params *ListCustomerProfileEvaluationParams, pageToken, pageNumber string) (*ListCustomerProfileEvaluationResponse, error) { path := "/v1/CustomerProfiles/{CustomerProfileSid}/Evaluations" path = strings.Replace(path, "{"+"CustomerProfileSid"+"}", CustomerProfileSid, -1) @@ -128,7 +140,7 @@ func (c *ApiService) PageCustomerProfileEvaluation(CustomerProfileSid string, pa data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -145,7 +157,12 @@ func (c *ApiService) PageCustomerProfileEvaluation(CustomerProfileSid string, pa // Lists CustomerProfileEvaluation records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListCustomerProfileEvaluation(CustomerProfileSid string, params *ListCustomerProfileEvaluationParams) ([]TrusthubV1CustomerProfileEvaluation, error) { - response, errors := c.StreamCustomerProfileEvaluation(CustomerProfileSid, params) + return c.ListCustomerProfileEvaluationWithContext(context.TODO(), CustomerProfileSid, params) +} + +// Lists CustomerProfileEvaluation records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListCustomerProfileEvaluationWithContext(ctx context.Context, CustomerProfileSid string, params *ListCustomerProfileEvaluationParams) ([]TrusthubV1CustomerProfileEvaluation, error) { + response, errors := c.StreamCustomerProfileEvaluationWithContext(ctx, CustomerProfileSid, params) records := make([]TrusthubV1CustomerProfileEvaluation, 0) for record := range response { @@ -161,6 +178,11 @@ func (c *ApiService) ListCustomerProfileEvaluation(CustomerProfileSid string, pa // Streams CustomerProfileEvaluation records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamCustomerProfileEvaluation(CustomerProfileSid string, params *ListCustomerProfileEvaluationParams) (chan TrusthubV1CustomerProfileEvaluation, chan error) { + return c.StreamCustomerProfileEvaluationWithContext(context.TODO(), CustomerProfileSid, params) +} + +// Streams CustomerProfileEvaluation records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamCustomerProfileEvaluationWithContext(ctx context.Context, CustomerProfileSid string, params *ListCustomerProfileEvaluationParams) (chan TrusthubV1CustomerProfileEvaluation, chan error) { if params == nil { params = &ListCustomerProfileEvaluationParams{} } @@ -169,19 +191,19 @@ func (c *ApiService) StreamCustomerProfileEvaluation(CustomerProfileSid string, recordChannel := make(chan TrusthubV1CustomerProfileEvaluation, 1) errorChannel := make(chan error, 1) - response, err := c.PageCustomerProfileEvaluation(CustomerProfileSid, params, "", "") + response, err := c.PageCustomerProfileEvaluationWithContext(ctx, CustomerProfileSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamCustomerProfileEvaluation(response, params, recordChannel, errorChannel) + go c.streamCustomerProfileEvaluationWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamCustomerProfileEvaluation(response *ListCustomerProfileEvaluationResponse, params *ListCustomerProfileEvaluationParams, recordChannel chan TrusthubV1CustomerProfileEvaluation, errorChannel chan error) { +func (c *ApiService) streamCustomerProfileEvaluationWithContext(ctx context.Context, response *ListCustomerProfileEvaluationResponse, params *ListCustomerProfileEvaluationParams, recordChannel chan TrusthubV1CustomerProfileEvaluation, errorChannel chan error) { curRecord := 1 for response != nil { @@ -196,7 +218,7 @@ func (c *ApiService) streamCustomerProfileEvaluation(response *ListCustomerProfi } } - record, err := client.GetNext(c.baseURL, response, c.getNextListCustomerProfileEvaluationResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListCustomerProfileEvaluationResponseWithContext) if err != nil { errorChannel <- err break @@ -211,11 +233,11 @@ func (c *ApiService) streamCustomerProfileEvaluation(response *ListCustomerProfi close(errorChannel) } -func (c *ApiService) getNextListCustomerProfileEvaluationResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListCustomerProfileEvaluationResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/trusthub/v1/end_user_types.go b/rest/trusthub/v1/end_user_types.go index 2a3462963..86b433740 100644 --- a/rest/trusthub/v1/end_user_types.go +++ b/rest/trusthub/v1/end_user_types.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -25,6 +26,9 @@ import ( // Fetch a specific End-User Type Instance. func (c *ApiService) FetchEndUserType(Sid string) (*TrusthubV1EndUserType, error) { + return c.FetchEndUserTypeWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchEndUserTypeWithContext(ctx context.Context, Sid string) (*TrusthubV1EndUserType, error) { path := "/v1/EndUserTypes/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -33,7 +37,7 @@ func (c *ApiService) FetchEndUserType(Sid string) (*TrusthubV1EndUserType, error "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -67,6 +71,11 @@ func (params *ListEndUserTypeParams) SetLimit(Limit int) *ListEndUserTypeParams // Retrieve a single page of EndUserType records from the API. Request is executed immediately. func (c *ApiService) PageEndUserType(params *ListEndUserTypeParams, pageToken, pageNumber string) (*ListEndUserTypeResponse, error) { + return c.PageEndUserTypeWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of EndUserType records from the API. Request is executed immediately. +func (c *ApiService) PageEndUserTypeWithContext(ctx context.Context, params *ListEndUserTypeParams, pageToken, pageNumber string) (*ListEndUserTypeResponse, error) { path := "/v1/EndUserTypes" data := url.Values{} @@ -85,7 +94,7 @@ func (c *ApiService) PageEndUserType(params *ListEndUserTypeParams, pageToken, p data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -102,7 +111,12 @@ func (c *ApiService) PageEndUserType(params *ListEndUserTypeParams, pageToken, p // Lists EndUserType records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListEndUserType(params *ListEndUserTypeParams) ([]TrusthubV1EndUserType, error) { - response, errors := c.StreamEndUserType(params) + return c.ListEndUserTypeWithContext(context.TODO(), params) +} + +// Lists EndUserType records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListEndUserTypeWithContext(ctx context.Context, params *ListEndUserTypeParams) ([]TrusthubV1EndUserType, error) { + response, errors := c.StreamEndUserTypeWithContext(ctx, params) records := make([]TrusthubV1EndUserType, 0) for record := range response { @@ -118,6 +132,11 @@ func (c *ApiService) ListEndUserType(params *ListEndUserTypeParams) ([]TrusthubV // Streams EndUserType records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamEndUserType(params *ListEndUserTypeParams) (chan TrusthubV1EndUserType, chan error) { + return c.StreamEndUserTypeWithContext(context.TODO(), params) +} + +// Streams EndUserType records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamEndUserTypeWithContext(ctx context.Context, params *ListEndUserTypeParams) (chan TrusthubV1EndUserType, chan error) { if params == nil { params = &ListEndUserTypeParams{} } @@ -126,19 +145,19 @@ func (c *ApiService) StreamEndUserType(params *ListEndUserTypeParams) (chan Trus recordChannel := make(chan TrusthubV1EndUserType, 1) errorChannel := make(chan error, 1) - response, err := c.PageEndUserType(params, "", "") + response, err := c.PageEndUserTypeWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamEndUserType(response, params, recordChannel, errorChannel) + go c.streamEndUserTypeWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamEndUserType(response *ListEndUserTypeResponse, params *ListEndUserTypeParams, recordChannel chan TrusthubV1EndUserType, errorChannel chan error) { +func (c *ApiService) streamEndUserTypeWithContext(ctx context.Context, response *ListEndUserTypeResponse, params *ListEndUserTypeParams, recordChannel chan TrusthubV1EndUserType, errorChannel chan error) { curRecord := 1 for response != nil { @@ -153,7 +172,7 @@ func (c *ApiService) streamEndUserType(response *ListEndUserTypeResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListEndUserTypeResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListEndUserTypeResponseWithContext) if err != nil { errorChannel <- err break @@ -168,11 +187,11 @@ func (c *ApiService) streamEndUserType(response *ListEndUserTypeResponse, params close(errorChannel) } -func (c *ApiService) getNextListEndUserTypeResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListEndUserTypeResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/trusthub/v1/end_users.go b/rest/trusthub/v1/end_users.go index c9f4e8f7e..6490ab797 100644 --- a/rest/trusthub/v1/end_users.go +++ b/rest/trusthub/v1/end_users.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -48,6 +49,9 @@ func (params *CreateEndUserParams) SetAttributes(Attributes map[string]interface // Create a new End User. func (c *ApiService) CreateEndUser(params *CreateEndUserParams) (*TrusthubV1EndUser, error) { + return c.CreateEndUserWithContext(context.TODO(), params) +} +func (c *ApiService) CreateEndUserWithContext(ctx context.Context, params *CreateEndUserParams) (*TrusthubV1EndUser, error) { path := "/v1/EndUsers" data := url.Values{} @@ -71,7 +75,7 @@ func (c *ApiService) CreateEndUser(params *CreateEndUserParams) (*TrusthubV1EndU data.Set("Attributes", string(v)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -88,6 +92,9 @@ func (c *ApiService) CreateEndUser(params *CreateEndUserParams) (*TrusthubV1EndU // Delete a specific End User. func (c *ApiService) DeleteEndUser(Sid string) error { + return c.DeleteEndUserWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteEndUserWithContext(ctx context.Context, Sid string) error { path := "/v1/EndUsers/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -96,7 +103,7 @@ func (c *ApiService) DeleteEndUser(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -108,6 +115,9 @@ func (c *ApiService) DeleteEndUser(Sid string) error { // Fetch specific End User Instance. func (c *ApiService) FetchEndUser(Sid string) (*TrusthubV1EndUser, error) { + return c.FetchEndUserWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchEndUserWithContext(ctx context.Context, Sid string) (*TrusthubV1EndUser, error) { path := "/v1/EndUsers/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -116,7 +126,7 @@ func (c *ApiService) FetchEndUser(Sid string) (*TrusthubV1EndUser, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -150,6 +160,11 @@ func (params *ListEndUserParams) SetLimit(Limit int) *ListEndUserParams { // Retrieve a single page of EndUser records from the API. Request is executed immediately. func (c *ApiService) PageEndUser(params *ListEndUserParams, pageToken, pageNumber string) (*ListEndUserResponse, error) { + return c.PageEndUserWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of EndUser records from the API. Request is executed immediately. +func (c *ApiService) PageEndUserWithContext(ctx context.Context, params *ListEndUserParams, pageToken, pageNumber string) (*ListEndUserResponse, error) { path := "/v1/EndUsers" data := url.Values{} @@ -168,7 +183,7 @@ func (c *ApiService) PageEndUser(params *ListEndUserParams, pageToken, pageNumbe data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -185,7 +200,12 @@ func (c *ApiService) PageEndUser(params *ListEndUserParams, pageToken, pageNumbe // Lists EndUser records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListEndUser(params *ListEndUserParams) ([]TrusthubV1EndUser, error) { - response, errors := c.StreamEndUser(params) + return c.ListEndUserWithContext(context.TODO(), params) +} + +// Lists EndUser records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListEndUserWithContext(ctx context.Context, params *ListEndUserParams) ([]TrusthubV1EndUser, error) { + response, errors := c.StreamEndUserWithContext(ctx, params) records := make([]TrusthubV1EndUser, 0) for record := range response { @@ -201,6 +221,11 @@ func (c *ApiService) ListEndUser(params *ListEndUserParams) ([]TrusthubV1EndUser // Streams EndUser records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamEndUser(params *ListEndUserParams) (chan TrusthubV1EndUser, chan error) { + return c.StreamEndUserWithContext(context.TODO(), params) +} + +// Streams EndUser records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamEndUserWithContext(ctx context.Context, params *ListEndUserParams) (chan TrusthubV1EndUser, chan error) { if params == nil { params = &ListEndUserParams{} } @@ -209,19 +234,19 @@ func (c *ApiService) StreamEndUser(params *ListEndUserParams) (chan TrusthubV1En recordChannel := make(chan TrusthubV1EndUser, 1) errorChannel := make(chan error, 1) - response, err := c.PageEndUser(params, "", "") + response, err := c.PageEndUserWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamEndUser(response, params, recordChannel, errorChannel) + go c.streamEndUserWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamEndUser(response *ListEndUserResponse, params *ListEndUserParams, recordChannel chan TrusthubV1EndUser, errorChannel chan error) { +func (c *ApiService) streamEndUserWithContext(ctx context.Context, response *ListEndUserResponse, params *ListEndUserParams, recordChannel chan TrusthubV1EndUser, errorChannel chan error) { curRecord := 1 for response != nil { @@ -236,7 +261,7 @@ func (c *ApiService) streamEndUser(response *ListEndUserResponse, params *ListEn } } - record, err := client.GetNext(c.baseURL, response, c.getNextListEndUserResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListEndUserResponseWithContext) if err != nil { errorChannel <- err break @@ -251,11 +276,11 @@ func (c *ApiService) streamEndUser(response *ListEndUserResponse, params *ListEn close(errorChannel) } -func (c *ApiService) getNextListEndUserResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListEndUserResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -288,6 +313,9 @@ func (params *UpdateEndUserParams) SetAttributes(Attributes map[string]interface // Update an existing End User. func (c *ApiService) UpdateEndUser(Sid string, params *UpdateEndUserParams) (*TrusthubV1EndUser, error) { + return c.UpdateEndUserWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateEndUserWithContext(ctx context.Context, Sid string, params *UpdateEndUserParams) (*TrusthubV1EndUser, error) { path := "/v1/EndUsers/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -309,7 +337,7 @@ func (c *ApiService) UpdateEndUser(Sid string, params *UpdateEndUserParams) (*Tr data.Set("Attributes", string(v)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/trusthub/v1/policies.go b/rest/trusthub/v1/policies.go index b518ba0da..30ee2ce71 100644 --- a/rest/trusthub/v1/policies.go +++ b/rest/trusthub/v1/policies.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -25,6 +26,9 @@ import ( // Fetch specific Policy Instance. func (c *ApiService) FetchPolicies(Sid string) (*TrusthubV1Policies, error) { + return c.FetchPoliciesWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchPoliciesWithContext(ctx context.Context, Sid string) (*TrusthubV1Policies, error) { path := "/v1/Policies/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -33,7 +37,7 @@ func (c *ApiService) FetchPolicies(Sid string) (*TrusthubV1Policies, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -67,6 +71,11 @@ func (params *ListPoliciesParams) SetLimit(Limit int) *ListPoliciesParams { // Retrieve a single page of Policies records from the API. Request is executed immediately. func (c *ApiService) PagePolicies(params *ListPoliciesParams, pageToken, pageNumber string) (*ListPoliciesResponse, error) { + return c.PagePoliciesWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Policies records from the API. Request is executed immediately. +func (c *ApiService) PagePoliciesWithContext(ctx context.Context, params *ListPoliciesParams, pageToken, pageNumber string) (*ListPoliciesResponse, error) { path := "/v1/Policies" data := url.Values{} @@ -85,7 +94,7 @@ func (c *ApiService) PagePolicies(params *ListPoliciesParams, pageToken, pageNum data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -102,7 +111,12 @@ func (c *ApiService) PagePolicies(params *ListPoliciesParams, pageToken, pageNum // Lists Policies records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListPolicies(params *ListPoliciesParams) ([]TrusthubV1Policies, error) { - response, errors := c.StreamPolicies(params) + return c.ListPoliciesWithContext(context.TODO(), params) +} + +// Lists Policies records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListPoliciesWithContext(ctx context.Context, params *ListPoliciesParams) ([]TrusthubV1Policies, error) { + response, errors := c.StreamPoliciesWithContext(ctx, params) records := make([]TrusthubV1Policies, 0) for record := range response { @@ -118,6 +132,11 @@ func (c *ApiService) ListPolicies(params *ListPoliciesParams) ([]TrusthubV1Polic // Streams Policies records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamPolicies(params *ListPoliciesParams) (chan TrusthubV1Policies, chan error) { + return c.StreamPoliciesWithContext(context.TODO(), params) +} + +// Streams Policies records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamPoliciesWithContext(ctx context.Context, params *ListPoliciesParams) (chan TrusthubV1Policies, chan error) { if params == nil { params = &ListPoliciesParams{} } @@ -126,19 +145,19 @@ func (c *ApiService) StreamPolicies(params *ListPoliciesParams) (chan TrusthubV1 recordChannel := make(chan TrusthubV1Policies, 1) errorChannel := make(chan error, 1) - response, err := c.PagePolicies(params, "", "") + response, err := c.PagePoliciesWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamPolicies(response, params, recordChannel, errorChannel) + go c.streamPoliciesWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamPolicies(response *ListPoliciesResponse, params *ListPoliciesParams, recordChannel chan TrusthubV1Policies, errorChannel chan error) { +func (c *ApiService) streamPoliciesWithContext(ctx context.Context, response *ListPoliciesResponse, params *ListPoliciesParams, recordChannel chan TrusthubV1Policies, errorChannel chan error) { curRecord := 1 for response != nil { @@ -153,7 +172,7 @@ func (c *ApiService) streamPolicies(response *ListPoliciesResponse, params *List } } - record, err := client.GetNext(c.baseURL, response, c.getNextListPoliciesResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListPoliciesResponseWithContext) if err != nil { errorChannel <- err break @@ -168,11 +187,11 @@ func (c *ApiService) streamPolicies(response *ListPoliciesResponse, params *List close(errorChannel) } -func (c *ApiService) getNextListPoliciesResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListPoliciesResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/trusthub/v1/supporting_document_types.go b/rest/trusthub/v1/supporting_document_types.go index 2edfa91be..8983ac6bb 100644 --- a/rest/trusthub/v1/supporting_document_types.go +++ b/rest/trusthub/v1/supporting_document_types.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -25,6 +26,9 @@ import ( // Fetch a specific Supporting Document Type Instance. func (c *ApiService) FetchSupportingDocumentType(Sid string) (*TrusthubV1SupportingDocumentType, error) { + return c.FetchSupportingDocumentTypeWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchSupportingDocumentTypeWithContext(ctx context.Context, Sid string) (*TrusthubV1SupportingDocumentType, error) { path := "/v1/SupportingDocumentTypes/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -33,7 +37,7 @@ func (c *ApiService) FetchSupportingDocumentType(Sid string) (*TrusthubV1Support "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -67,6 +71,11 @@ func (params *ListSupportingDocumentTypeParams) SetLimit(Limit int) *ListSupport // Retrieve a single page of SupportingDocumentType records from the API. Request is executed immediately. func (c *ApiService) PageSupportingDocumentType(params *ListSupportingDocumentTypeParams, pageToken, pageNumber string) (*ListSupportingDocumentTypeResponse, error) { + return c.PageSupportingDocumentTypeWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of SupportingDocumentType records from the API. Request is executed immediately. +func (c *ApiService) PageSupportingDocumentTypeWithContext(ctx context.Context, params *ListSupportingDocumentTypeParams, pageToken, pageNumber string) (*ListSupportingDocumentTypeResponse, error) { path := "/v1/SupportingDocumentTypes" data := url.Values{} @@ -85,7 +94,7 @@ func (c *ApiService) PageSupportingDocumentType(params *ListSupportingDocumentTy data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -102,7 +111,12 @@ func (c *ApiService) PageSupportingDocumentType(params *ListSupportingDocumentTy // Lists SupportingDocumentType records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListSupportingDocumentType(params *ListSupportingDocumentTypeParams) ([]TrusthubV1SupportingDocumentType, error) { - response, errors := c.StreamSupportingDocumentType(params) + return c.ListSupportingDocumentTypeWithContext(context.TODO(), params) +} + +// Lists SupportingDocumentType records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListSupportingDocumentTypeWithContext(ctx context.Context, params *ListSupportingDocumentTypeParams) ([]TrusthubV1SupportingDocumentType, error) { + response, errors := c.StreamSupportingDocumentTypeWithContext(ctx, params) records := make([]TrusthubV1SupportingDocumentType, 0) for record := range response { @@ -118,6 +132,11 @@ func (c *ApiService) ListSupportingDocumentType(params *ListSupportingDocumentTy // Streams SupportingDocumentType records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamSupportingDocumentType(params *ListSupportingDocumentTypeParams) (chan TrusthubV1SupportingDocumentType, chan error) { + return c.StreamSupportingDocumentTypeWithContext(context.TODO(), params) +} + +// Streams SupportingDocumentType records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamSupportingDocumentTypeWithContext(ctx context.Context, params *ListSupportingDocumentTypeParams) (chan TrusthubV1SupportingDocumentType, chan error) { if params == nil { params = &ListSupportingDocumentTypeParams{} } @@ -126,19 +145,19 @@ func (c *ApiService) StreamSupportingDocumentType(params *ListSupportingDocument recordChannel := make(chan TrusthubV1SupportingDocumentType, 1) errorChannel := make(chan error, 1) - response, err := c.PageSupportingDocumentType(params, "", "") + response, err := c.PageSupportingDocumentTypeWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSupportingDocumentType(response, params, recordChannel, errorChannel) + go c.streamSupportingDocumentTypeWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamSupportingDocumentType(response *ListSupportingDocumentTypeResponse, params *ListSupportingDocumentTypeParams, recordChannel chan TrusthubV1SupportingDocumentType, errorChannel chan error) { +func (c *ApiService) streamSupportingDocumentTypeWithContext(ctx context.Context, response *ListSupportingDocumentTypeResponse, params *ListSupportingDocumentTypeParams, recordChannel chan TrusthubV1SupportingDocumentType, errorChannel chan error) { curRecord := 1 for response != nil { @@ -153,7 +172,7 @@ func (c *ApiService) streamSupportingDocumentType(response *ListSupportingDocume } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSupportingDocumentTypeResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListSupportingDocumentTypeResponseWithContext) if err != nil { errorChannel <- err break @@ -168,11 +187,11 @@ func (c *ApiService) streamSupportingDocumentType(response *ListSupportingDocume close(errorChannel) } -func (c *ApiService) getNextListSupportingDocumentTypeResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSupportingDocumentTypeResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/trusthub/v1/supporting_documents.go b/rest/trusthub/v1/supporting_documents.go index cdfd9976c..7f427c658 100644 --- a/rest/trusthub/v1/supporting_documents.go +++ b/rest/trusthub/v1/supporting_documents.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -48,6 +49,9 @@ func (params *CreateSupportingDocumentParams) SetAttributes(Attributes map[strin // Create a new Supporting Document. func (c *ApiService) CreateSupportingDocument(params *CreateSupportingDocumentParams) (*TrusthubV1SupportingDocument, error) { + return c.CreateSupportingDocumentWithContext(context.TODO(), params) +} +func (c *ApiService) CreateSupportingDocumentWithContext(ctx context.Context, params *CreateSupportingDocumentParams) (*TrusthubV1SupportingDocument, error) { path := "/v1/SupportingDocuments" data := url.Values{} @@ -71,7 +75,7 @@ func (c *ApiService) CreateSupportingDocument(params *CreateSupportingDocumentPa data.Set("Attributes", string(v)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -88,6 +92,9 @@ func (c *ApiService) CreateSupportingDocument(params *CreateSupportingDocumentPa // Delete a specific Supporting Document. func (c *ApiService) DeleteSupportingDocument(Sid string) error { + return c.DeleteSupportingDocumentWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteSupportingDocumentWithContext(ctx context.Context, Sid string) error { path := "/v1/SupportingDocuments/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -96,7 +103,7 @@ func (c *ApiService) DeleteSupportingDocument(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -108,6 +115,9 @@ func (c *ApiService) DeleteSupportingDocument(Sid string) error { // Fetch specific Supporting Document Instance. func (c *ApiService) FetchSupportingDocument(Sid string) (*TrusthubV1SupportingDocument, error) { + return c.FetchSupportingDocumentWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchSupportingDocumentWithContext(ctx context.Context, Sid string) (*TrusthubV1SupportingDocument, error) { path := "/v1/SupportingDocuments/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -116,7 +126,7 @@ func (c *ApiService) FetchSupportingDocument(Sid string) (*TrusthubV1SupportingD "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -150,6 +160,11 @@ func (params *ListSupportingDocumentParams) SetLimit(Limit int) *ListSupportingD // Retrieve a single page of SupportingDocument records from the API. Request is executed immediately. func (c *ApiService) PageSupportingDocument(params *ListSupportingDocumentParams, pageToken, pageNumber string) (*ListSupportingDocumentResponse, error) { + return c.PageSupportingDocumentWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of SupportingDocument records from the API. Request is executed immediately. +func (c *ApiService) PageSupportingDocumentWithContext(ctx context.Context, params *ListSupportingDocumentParams, pageToken, pageNumber string) (*ListSupportingDocumentResponse, error) { path := "/v1/SupportingDocuments" data := url.Values{} @@ -168,7 +183,7 @@ func (c *ApiService) PageSupportingDocument(params *ListSupportingDocumentParams data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -185,7 +200,12 @@ func (c *ApiService) PageSupportingDocument(params *ListSupportingDocumentParams // Lists SupportingDocument records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListSupportingDocument(params *ListSupportingDocumentParams) ([]TrusthubV1SupportingDocument, error) { - response, errors := c.StreamSupportingDocument(params) + return c.ListSupportingDocumentWithContext(context.TODO(), params) +} + +// Lists SupportingDocument records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListSupportingDocumentWithContext(ctx context.Context, params *ListSupportingDocumentParams) ([]TrusthubV1SupportingDocument, error) { + response, errors := c.StreamSupportingDocumentWithContext(ctx, params) records := make([]TrusthubV1SupportingDocument, 0) for record := range response { @@ -201,6 +221,11 @@ func (c *ApiService) ListSupportingDocument(params *ListSupportingDocumentParams // Streams SupportingDocument records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamSupportingDocument(params *ListSupportingDocumentParams) (chan TrusthubV1SupportingDocument, chan error) { + return c.StreamSupportingDocumentWithContext(context.TODO(), params) +} + +// Streams SupportingDocument records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamSupportingDocumentWithContext(ctx context.Context, params *ListSupportingDocumentParams) (chan TrusthubV1SupportingDocument, chan error) { if params == nil { params = &ListSupportingDocumentParams{} } @@ -209,19 +234,19 @@ func (c *ApiService) StreamSupportingDocument(params *ListSupportingDocumentPara recordChannel := make(chan TrusthubV1SupportingDocument, 1) errorChannel := make(chan error, 1) - response, err := c.PageSupportingDocument(params, "", "") + response, err := c.PageSupportingDocumentWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSupportingDocument(response, params, recordChannel, errorChannel) + go c.streamSupportingDocumentWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamSupportingDocument(response *ListSupportingDocumentResponse, params *ListSupportingDocumentParams, recordChannel chan TrusthubV1SupportingDocument, errorChannel chan error) { +func (c *ApiService) streamSupportingDocumentWithContext(ctx context.Context, response *ListSupportingDocumentResponse, params *ListSupportingDocumentParams, recordChannel chan TrusthubV1SupportingDocument, errorChannel chan error) { curRecord := 1 for response != nil { @@ -236,7 +261,7 @@ func (c *ApiService) streamSupportingDocument(response *ListSupportingDocumentRe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSupportingDocumentResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListSupportingDocumentResponseWithContext) if err != nil { errorChannel <- err break @@ -251,11 +276,11 @@ func (c *ApiService) streamSupportingDocument(response *ListSupportingDocumentRe close(errorChannel) } -func (c *ApiService) getNextListSupportingDocumentResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSupportingDocumentResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -288,6 +313,9 @@ func (params *UpdateSupportingDocumentParams) SetAttributes(Attributes map[strin // Update an existing Supporting Document. func (c *ApiService) UpdateSupportingDocument(Sid string, params *UpdateSupportingDocumentParams) (*TrusthubV1SupportingDocument, error) { + return c.UpdateSupportingDocumentWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateSupportingDocumentWithContext(ctx context.Context, Sid string, params *UpdateSupportingDocumentParams) (*TrusthubV1SupportingDocument, error) { path := "/v1/SupportingDocuments/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -309,7 +337,7 @@ func (c *ApiService) UpdateSupportingDocument(Sid string, params *UpdateSupporti data.Set("Attributes", string(v)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/trusthub/v1/trust_products.go b/rest/trusthub/v1/trust_products.go index 627f73953..a9bf3d9a3 100644 --- a/rest/trusthub/v1/trust_products.go +++ b/rest/trusthub/v1/trust_products.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -54,6 +55,9 @@ func (params *CreateTrustProductParams) SetStatusCallback(StatusCallback string) // Create a new Trust Product. func (c *ApiService) CreateTrustProduct(params *CreateTrustProductParams) (*TrusthubV1TrustProduct, error) { + return c.CreateTrustProductWithContext(context.TODO(), params) +} +func (c *ApiService) CreateTrustProductWithContext(ctx context.Context, params *CreateTrustProductParams) (*TrusthubV1TrustProduct, error) { path := "/v1/TrustProducts" data := url.Values{} @@ -74,7 +78,7 @@ func (c *ApiService) CreateTrustProduct(params *CreateTrustProductParams) (*Trus data.Set("StatusCallback", *params.StatusCallback) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -91,6 +95,9 @@ func (c *ApiService) CreateTrustProduct(params *CreateTrustProductParams) (*Trus // Delete a specific Trust Product. func (c *ApiService) DeleteTrustProduct(Sid string) error { + return c.DeleteTrustProductWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteTrustProductWithContext(ctx context.Context, Sid string) error { path := "/v1/TrustProducts/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -99,7 +106,7 @@ func (c *ApiService) DeleteTrustProduct(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -111,6 +118,9 @@ func (c *ApiService) DeleteTrustProduct(Sid string) error { // Fetch a specific Trust Product instance. func (c *ApiService) FetchTrustProduct(Sid string) (*TrusthubV1TrustProduct, error) { + return c.FetchTrustProductWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchTrustProductWithContext(ctx context.Context, Sid string) (*TrusthubV1TrustProduct, error) { path := "/v1/TrustProducts/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -119,7 +129,7 @@ func (c *ApiService) FetchTrustProduct(Sid string) (*TrusthubV1TrustProduct, err "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -171,6 +181,11 @@ func (params *ListTrustProductParams) SetLimit(Limit int) *ListTrustProductParam // Retrieve a single page of TrustProduct records from the API. Request is executed immediately. func (c *ApiService) PageTrustProduct(params *ListTrustProductParams, pageToken, pageNumber string) (*ListTrustProductResponse, error) { + return c.PageTrustProductWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of TrustProduct records from the API. Request is executed immediately. +func (c *ApiService) PageTrustProductWithContext(ctx context.Context, params *ListTrustProductParams, pageToken, pageNumber string) (*ListTrustProductResponse, error) { path := "/v1/TrustProducts" data := url.Values{} @@ -198,7 +213,7 @@ func (c *ApiService) PageTrustProduct(params *ListTrustProductParams, pageToken, data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -215,7 +230,12 @@ func (c *ApiService) PageTrustProduct(params *ListTrustProductParams, pageToken, // Lists TrustProduct records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListTrustProduct(params *ListTrustProductParams) ([]TrusthubV1TrustProduct, error) { - response, errors := c.StreamTrustProduct(params) + return c.ListTrustProductWithContext(context.TODO(), params) +} + +// Lists TrustProduct records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListTrustProductWithContext(ctx context.Context, params *ListTrustProductParams) ([]TrusthubV1TrustProduct, error) { + response, errors := c.StreamTrustProductWithContext(ctx, params) records := make([]TrusthubV1TrustProduct, 0) for record := range response { @@ -231,6 +251,11 @@ func (c *ApiService) ListTrustProduct(params *ListTrustProductParams) ([]Trusthu // Streams TrustProduct records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamTrustProduct(params *ListTrustProductParams) (chan TrusthubV1TrustProduct, chan error) { + return c.StreamTrustProductWithContext(context.TODO(), params) +} + +// Streams TrustProduct records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamTrustProductWithContext(ctx context.Context, params *ListTrustProductParams) (chan TrusthubV1TrustProduct, chan error) { if params == nil { params = &ListTrustProductParams{} } @@ -239,19 +264,19 @@ func (c *ApiService) StreamTrustProduct(params *ListTrustProductParams) (chan Tr recordChannel := make(chan TrusthubV1TrustProduct, 1) errorChannel := make(chan error, 1) - response, err := c.PageTrustProduct(params, "", "") + response, err := c.PageTrustProductWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamTrustProduct(response, params, recordChannel, errorChannel) + go c.streamTrustProductWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamTrustProduct(response *ListTrustProductResponse, params *ListTrustProductParams, recordChannel chan TrusthubV1TrustProduct, errorChannel chan error) { +func (c *ApiService) streamTrustProductWithContext(ctx context.Context, response *ListTrustProductResponse, params *ListTrustProductParams, recordChannel chan TrusthubV1TrustProduct, errorChannel chan error) { curRecord := 1 for response != nil { @@ -266,7 +291,7 @@ func (c *ApiService) streamTrustProduct(response *ListTrustProductResponse, para } } - record, err := client.GetNext(c.baseURL, response, c.getNextListTrustProductResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListTrustProductResponseWithContext) if err != nil { errorChannel <- err break @@ -281,11 +306,11 @@ func (c *ApiService) streamTrustProduct(response *ListTrustProductResponse, para close(errorChannel) } -func (c *ApiService) getNextListTrustProductResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListTrustProductResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -330,6 +355,9 @@ func (params *UpdateTrustProductParams) SetEmail(Email string) *UpdateTrustProdu // Updates a Trust Product in an account. func (c *ApiService) UpdateTrustProduct(Sid string, params *UpdateTrustProductParams) (*TrusthubV1TrustProduct, error) { + return c.UpdateTrustProductWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateTrustProductWithContext(ctx context.Context, Sid string, params *UpdateTrustProductParams) (*TrusthubV1TrustProduct, error) { path := "/v1/TrustProducts/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -351,7 +379,7 @@ func (c *ApiService) UpdateTrustProduct(Sid string, params *UpdateTrustProductPa data.Set("Email", *params.Email) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/trusthub/v1/trust_products_channel_endpoint_assignments.go b/rest/trusthub/v1/trust_products_channel_endpoint_assignments.go index 2f25823d1..5aa0eabf4 100644 --- a/rest/trusthub/v1/trust_products_channel_endpoint_assignments.go +++ b/rest/trusthub/v1/trust_products_channel_endpoint_assignments.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -42,6 +43,9 @@ func (params *CreateTrustProductChannelEndpointAssignmentParams) SetChannelEndpo // Create a new Assigned Item. func (c *ApiService) CreateTrustProductChannelEndpointAssignment(TrustProductSid string, params *CreateTrustProductChannelEndpointAssignmentParams) (*TrusthubV1TrustProductChannelEndpointAssignment, error) { + return c.CreateTrustProductChannelEndpointAssignmentWithContext(context.TODO(), TrustProductSid, params) +} +func (c *ApiService) CreateTrustProductChannelEndpointAssignmentWithContext(ctx context.Context, TrustProductSid string, params *CreateTrustProductChannelEndpointAssignmentParams) (*TrusthubV1TrustProductChannelEndpointAssignment, error) { path := "/v1/TrustProducts/{TrustProductSid}/ChannelEndpointAssignments" path = strings.Replace(path, "{"+"TrustProductSid"+"}", TrustProductSid, -1) @@ -57,7 +61,7 @@ func (c *ApiService) CreateTrustProductChannelEndpointAssignment(TrustProductSid data.Set("ChannelEndpointSid", *params.ChannelEndpointSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -74,6 +78,9 @@ func (c *ApiService) CreateTrustProductChannelEndpointAssignment(TrustProductSid // Remove an Assignment Item Instance. func (c *ApiService) DeleteTrustProductChannelEndpointAssignment(TrustProductSid string, Sid string) error { + return c.DeleteTrustProductChannelEndpointAssignmentWithContext(context.TODO(), TrustProductSid, Sid) +} +func (c *ApiService) DeleteTrustProductChannelEndpointAssignmentWithContext(ctx context.Context, TrustProductSid string, Sid string) error { path := "/v1/TrustProducts/{TrustProductSid}/ChannelEndpointAssignments/{Sid}" path = strings.Replace(path, "{"+"TrustProductSid"+"}", TrustProductSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -83,7 +90,7 @@ func (c *ApiService) DeleteTrustProductChannelEndpointAssignment(TrustProductSid "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -95,6 +102,9 @@ func (c *ApiService) DeleteTrustProductChannelEndpointAssignment(TrustProductSid // Fetch specific Assigned Item Instance. func (c *ApiService) FetchTrustProductChannelEndpointAssignment(TrustProductSid string, Sid string) (*TrusthubV1TrustProductChannelEndpointAssignment, error) { + return c.FetchTrustProductChannelEndpointAssignmentWithContext(context.TODO(), TrustProductSid, Sid) +} +func (c *ApiService) FetchTrustProductChannelEndpointAssignmentWithContext(ctx context.Context, TrustProductSid string, Sid string) (*TrusthubV1TrustProductChannelEndpointAssignment, error) { path := "/v1/TrustProducts/{TrustProductSid}/ChannelEndpointAssignments/{Sid}" path = strings.Replace(path, "{"+"TrustProductSid"+"}", TrustProductSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -104,7 +114,7 @@ func (c *ApiService) FetchTrustProductChannelEndpointAssignment(TrustProductSid "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -150,6 +160,11 @@ func (params *ListTrustProductChannelEndpointAssignmentParams) SetLimit(Limit in // Retrieve a single page of TrustProductChannelEndpointAssignment records from the API. Request is executed immediately. func (c *ApiService) PageTrustProductChannelEndpointAssignment(TrustProductSid string, params *ListTrustProductChannelEndpointAssignmentParams, pageToken, pageNumber string) (*ListTrustProductChannelEndpointAssignmentResponse, error) { + return c.PageTrustProductChannelEndpointAssignmentWithContext(context.TODO(), TrustProductSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of TrustProductChannelEndpointAssignment records from the API. Request is executed immediately. +func (c *ApiService) PageTrustProductChannelEndpointAssignmentWithContext(ctx context.Context, TrustProductSid string, params *ListTrustProductChannelEndpointAssignmentParams, pageToken, pageNumber string) (*ListTrustProductChannelEndpointAssignmentResponse, error) { path := "/v1/TrustProducts/{TrustProductSid}/ChannelEndpointAssignments" path = strings.Replace(path, "{"+"TrustProductSid"+"}", TrustProductSid, -1) @@ -176,7 +191,7 @@ func (c *ApiService) PageTrustProductChannelEndpointAssignment(TrustProductSid s data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -193,7 +208,12 @@ func (c *ApiService) PageTrustProductChannelEndpointAssignment(TrustProductSid s // Lists TrustProductChannelEndpointAssignment records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListTrustProductChannelEndpointAssignment(TrustProductSid string, params *ListTrustProductChannelEndpointAssignmentParams) ([]TrusthubV1TrustProductChannelEndpointAssignment, error) { - response, errors := c.StreamTrustProductChannelEndpointAssignment(TrustProductSid, params) + return c.ListTrustProductChannelEndpointAssignmentWithContext(context.TODO(), TrustProductSid, params) +} + +// Lists TrustProductChannelEndpointAssignment records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListTrustProductChannelEndpointAssignmentWithContext(ctx context.Context, TrustProductSid string, params *ListTrustProductChannelEndpointAssignmentParams) ([]TrusthubV1TrustProductChannelEndpointAssignment, error) { + response, errors := c.StreamTrustProductChannelEndpointAssignmentWithContext(ctx, TrustProductSid, params) records := make([]TrusthubV1TrustProductChannelEndpointAssignment, 0) for record := range response { @@ -209,6 +229,11 @@ func (c *ApiService) ListTrustProductChannelEndpointAssignment(TrustProductSid s // Streams TrustProductChannelEndpointAssignment records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamTrustProductChannelEndpointAssignment(TrustProductSid string, params *ListTrustProductChannelEndpointAssignmentParams) (chan TrusthubV1TrustProductChannelEndpointAssignment, chan error) { + return c.StreamTrustProductChannelEndpointAssignmentWithContext(context.TODO(), TrustProductSid, params) +} + +// Streams TrustProductChannelEndpointAssignment records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamTrustProductChannelEndpointAssignmentWithContext(ctx context.Context, TrustProductSid string, params *ListTrustProductChannelEndpointAssignmentParams) (chan TrusthubV1TrustProductChannelEndpointAssignment, chan error) { if params == nil { params = &ListTrustProductChannelEndpointAssignmentParams{} } @@ -217,19 +242,19 @@ func (c *ApiService) StreamTrustProductChannelEndpointAssignment(TrustProductSid recordChannel := make(chan TrusthubV1TrustProductChannelEndpointAssignment, 1) errorChannel := make(chan error, 1) - response, err := c.PageTrustProductChannelEndpointAssignment(TrustProductSid, params, "", "") + response, err := c.PageTrustProductChannelEndpointAssignmentWithContext(ctx, TrustProductSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamTrustProductChannelEndpointAssignment(response, params, recordChannel, errorChannel) + go c.streamTrustProductChannelEndpointAssignmentWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamTrustProductChannelEndpointAssignment(response *ListTrustProductChannelEndpointAssignmentResponse, params *ListTrustProductChannelEndpointAssignmentParams, recordChannel chan TrusthubV1TrustProductChannelEndpointAssignment, errorChannel chan error) { +func (c *ApiService) streamTrustProductChannelEndpointAssignmentWithContext(ctx context.Context, response *ListTrustProductChannelEndpointAssignmentResponse, params *ListTrustProductChannelEndpointAssignmentParams, recordChannel chan TrusthubV1TrustProductChannelEndpointAssignment, errorChannel chan error) { curRecord := 1 for response != nil { @@ -244,7 +269,7 @@ func (c *ApiService) streamTrustProductChannelEndpointAssignment(response *ListT } } - record, err := client.GetNext(c.baseURL, response, c.getNextListTrustProductChannelEndpointAssignmentResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListTrustProductChannelEndpointAssignmentResponseWithContext) if err != nil { errorChannel <- err break @@ -259,11 +284,11 @@ func (c *ApiService) streamTrustProductChannelEndpointAssignment(response *ListT close(errorChannel) } -func (c *ApiService) getNextListTrustProductChannelEndpointAssignmentResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListTrustProductChannelEndpointAssignmentResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/trusthub/v1/trust_products_entity_assignments.go b/rest/trusthub/v1/trust_products_entity_assignments.go index d8accdc65..dbb4c957b 100644 --- a/rest/trusthub/v1/trust_products_entity_assignments.go +++ b/rest/trusthub/v1/trust_products_entity_assignments.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -36,6 +37,9 @@ func (params *CreateTrustProductEntityAssignmentParams) SetObjectSid(ObjectSid s // Create a new Assigned Item. func (c *ApiService) CreateTrustProductEntityAssignment(TrustProductSid string, params *CreateTrustProductEntityAssignmentParams) (*TrusthubV1TrustProductEntityAssignment, error) { + return c.CreateTrustProductEntityAssignmentWithContext(context.TODO(), TrustProductSid, params) +} +func (c *ApiService) CreateTrustProductEntityAssignmentWithContext(ctx context.Context, TrustProductSid string, params *CreateTrustProductEntityAssignmentParams) (*TrusthubV1TrustProductEntityAssignment, error) { path := "/v1/TrustProducts/{TrustProductSid}/EntityAssignments" path = strings.Replace(path, "{"+"TrustProductSid"+"}", TrustProductSid, -1) @@ -48,7 +52,7 @@ func (c *ApiService) CreateTrustProductEntityAssignment(TrustProductSid string, data.Set("ObjectSid", *params.ObjectSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -65,6 +69,9 @@ func (c *ApiService) CreateTrustProductEntityAssignment(TrustProductSid string, // Remove an Assignment Item Instance. func (c *ApiService) DeleteTrustProductEntityAssignment(TrustProductSid string, Sid string) error { + return c.DeleteTrustProductEntityAssignmentWithContext(context.TODO(), TrustProductSid, Sid) +} +func (c *ApiService) DeleteTrustProductEntityAssignmentWithContext(ctx context.Context, TrustProductSid string, Sid string) error { path := "/v1/TrustProducts/{TrustProductSid}/EntityAssignments/{Sid}" path = strings.Replace(path, "{"+"TrustProductSid"+"}", TrustProductSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -74,7 +81,7 @@ func (c *ApiService) DeleteTrustProductEntityAssignment(TrustProductSid string, "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -86,6 +93,9 @@ func (c *ApiService) DeleteTrustProductEntityAssignment(TrustProductSid string, // Fetch specific Assigned Item Instance. func (c *ApiService) FetchTrustProductEntityAssignment(TrustProductSid string, Sid string) (*TrusthubV1TrustProductEntityAssignment, error) { + return c.FetchTrustProductEntityAssignmentWithContext(context.TODO(), TrustProductSid, Sid) +} +func (c *ApiService) FetchTrustProductEntityAssignmentWithContext(ctx context.Context, TrustProductSid string, Sid string) (*TrusthubV1TrustProductEntityAssignment, error) { path := "/v1/TrustProducts/{TrustProductSid}/EntityAssignments/{Sid}" path = strings.Replace(path, "{"+"TrustProductSid"+"}", TrustProductSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -95,7 +105,7 @@ func (c *ApiService) FetchTrustProductEntityAssignment(TrustProductSid string, S "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -135,6 +145,11 @@ func (params *ListTrustProductEntityAssignmentParams) SetLimit(Limit int) *ListT // Retrieve a single page of TrustProductEntityAssignment records from the API. Request is executed immediately. func (c *ApiService) PageTrustProductEntityAssignment(TrustProductSid string, params *ListTrustProductEntityAssignmentParams, pageToken, pageNumber string) (*ListTrustProductEntityAssignmentResponse, error) { + return c.PageTrustProductEntityAssignmentWithContext(context.TODO(), TrustProductSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of TrustProductEntityAssignment records from the API. Request is executed immediately. +func (c *ApiService) PageTrustProductEntityAssignmentWithContext(ctx context.Context, TrustProductSid string, params *ListTrustProductEntityAssignmentParams, pageToken, pageNumber string) (*ListTrustProductEntityAssignmentResponse, error) { path := "/v1/TrustProducts/{TrustProductSid}/EntityAssignments" path = strings.Replace(path, "{"+"TrustProductSid"+"}", TrustProductSid, -1) @@ -158,7 +173,7 @@ func (c *ApiService) PageTrustProductEntityAssignment(TrustProductSid string, pa data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -175,7 +190,12 @@ func (c *ApiService) PageTrustProductEntityAssignment(TrustProductSid string, pa // Lists TrustProductEntityAssignment records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListTrustProductEntityAssignment(TrustProductSid string, params *ListTrustProductEntityAssignmentParams) ([]TrusthubV1TrustProductEntityAssignment, error) { - response, errors := c.StreamTrustProductEntityAssignment(TrustProductSid, params) + return c.ListTrustProductEntityAssignmentWithContext(context.TODO(), TrustProductSid, params) +} + +// Lists TrustProductEntityAssignment records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListTrustProductEntityAssignmentWithContext(ctx context.Context, TrustProductSid string, params *ListTrustProductEntityAssignmentParams) ([]TrusthubV1TrustProductEntityAssignment, error) { + response, errors := c.StreamTrustProductEntityAssignmentWithContext(ctx, TrustProductSid, params) records := make([]TrusthubV1TrustProductEntityAssignment, 0) for record := range response { @@ -191,6 +211,11 @@ func (c *ApiService) ListTrustProductEntityAssignment(TrustProductSid string, pa // Streams TrustProductEntityAssignment records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamTrustProductEntityAssignment(TrustProductSid string, params *ListTrustProductEntityAssignmentParams) (chan TrusthubV1TrustProductEntityAssignment, chan error) { + return c.StreamTrustProductEntityAssignmentWithContext(context.TODO(), TrustProductSid, params) +} + +// Streams TrustProductEntityAssignment records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamTrustProductEntityAssignmentWithContext(ctx context.Context, TrustProductSid string, params *ListTrustProductEntityAssignmentParams) (chan TrusthubV1TrustProductEntityAssignment, chan error) { if params == nil { params = &ListTrustProductEntityAssignmentParams{} } @@ -199,19 +224,19 @@ func (c *ApiService) StreamTrustProductEntityAssignment(TrustProductSid string, recordChannel := make(chan TrusthubV1TrustProductEntityAssignment, 1) errorChannel := make(chan error, 1) - response, err := c.PageTrustProductEntityAssignment(TrustProductSid, params, "", "") + response, err := c.PageTrustProductEntityAssignmentWithContext(ctx, TrustProductSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamTrustProductEntityAssignment(response, params, recordChannel, errorChannel) + go c.streamTrustProductEntityAssignmentWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamTrustProductEntityAssignment(response *ListTrustProductEntityAssignmentResponse, params *ListTrustProductEntityAssignmentParams, recordChannel chan TrusthubV1TrustProductEntityAssignment, errorChannel chan error) { +func (c *ApiService) streamTrustProductEntityAssignmentWithContext(ctx context.Context, response *ListTrustProductEntityAssignmentResponse, params *ListTrustProductEntityAssignmentParams, recordChannel chan TrusthubV1TrustProductEntityAssignment, errorChannel chan error) { curRecord := 1 for response != nil { @@ -226,7 +251,7 @@ func (c *ApiService) streamTrustProductEntityAssignment(response *ListTrustProdu } } - record, err := client.GetNext(c.baseURL, response, c.getNextListTrustProductEntityAssignmentResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListTrustProductEntityAssignmentResponseWithContext) if err != nil { errorChannel <- err break @@ -241,11 +266,11 @@ func (c *ApiService) streamTrustProductEntityAssignment(response *ListTrustProdu close(errorChannel) } -func (c *ApiService) getNextListTrustProductEntityAssignmentResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListTrustProductEntityAssignmentResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/trusthub/v1/trust_products_evaluations.go b/rest/trusthub/v1/trust_products_evaluations.go index 3799fca77..a3e1bab0a 100644 --- a/rest/trusthub/v1/trust_products_evaluations.go +++ b/rest/trusthub/v1/trust_products_evaluations.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -36,6 +37,9 @@ func (params *CreateTrustProductEvaluationParams) SetPolicySid(PolicySid string) // Create a new Evaluation func (c *ApiService) CreateTrustProductEvaluation(TrustProductSid string, params *CreateTrustProductEvaluationParams) (*TrusthubV1TrustProductEvaluation, error) { + return c.CreateTrustProductEvaluationWithContext(context.TODO(), TrustProductSid, params) +} +func (c *ApiService) CreateTrustProductEvaluationWithContext(ctx context.Context, TrustProductSid string, params *CreateTrustProductEvaluationParams) (*TrusthubV1TrustProductEvaluation, error) { path := "/v1/TrustProducts/{TrustProductSid}/Evaluations" path = strings.Replace(path, "{"+"TrustProductSid"+"}", TrustProductSid, -1) @@ -48,7 +52,7 @@ func (c *ApiService) CreateTrustProductEvaluation(TrustProductSid string, params data.Set("PolicySid", *params.PolicySid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -65,6 +69,9 @@ func (c *ApiService) CreateTrustProductEvaluation(TrustProductSid string, params // Fetch specific Evaluation Instance. func (c *ApiService) FetchTrustProductEvaluation(TrustProductSid string, Sid string) (*TrusthubV1TrustProductEvaluation, error) { + return c.FetchTrustProductEvaluationWithContext(context.TODO(), TrustProductSid, Sid) +} +func (c *ApiService) FetchTrustProductEvaluationWithContext(ctx context.Context, TrustProductSid string, Sid string) (*TrusthubV1TrustProductEvaluation, error) { path := "/v1/TrustProducts/{TrustProductSid}/Evaluations/{Sid}" path = strings.Replace(path, "{"+"TrustProductSid"+"}", TrustProductSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -74,7 +81,7 @@ func (c *ApiService) FetchTrustProductEvaluation(TrustProductSid string, Sid str "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -108,6 +115,11 @@ func (params *ListTrustProductEvaluationParams) SetLimit(Limit int) *ListTrustPr // Retrieve a single page of TrustProductEvaluation records from the API. Request is executed immediately. func (c *ApiService) PageTrustProductEvaluation(TrustProductSid string, params *ListTrustProductEvaluationParams, pageToken, pageNumber string) (*ListTrustProductEvaluationResponse, error) { + return c.PageTrustProductEvaluationWithContext(context.TODO(), TrustProductSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of TrustProductEvaluation records from the API. Request is executed immediately. +func (c *ApiService) PageTrustProductEvaluationWithContext(ctx context.Context, TrustProductSid string, params *ListTrustProductEvaluationParams, pageToken, pageNumber string) (*ListTrustProductEvaluationResponse, error) { path := "/v1/TrustProducts/{TrustProductSid}/Evaluations" path = strings.Replace(path, "{"+"TrustProductSid"+"}", TrustProductSid, -1) @@ -128,7 +140,7 @@ func (c *ApiService) PageTrustProductEvaluation(TrustProductSid string, params * data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -145,7 +157,12 @@ func (c *ApiService) PageTrustProductEvaluation(TrustProductSid string, params * // Lists TrustProductEvaluation records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListTrustProductEvaluation(TrustProductSid string, params *ListTrustProductEvaluationParams) ([]TrusthubV1TrustProductEvaluation, error) { - response, errors := c.StreamTrustProductEvaluation(TrustProductSid, params) + return c.ListTrustProductEvaluationWithContext(context.TODO(), TrustProductSid, params) +} + +// Lists TrustProductEvaluation records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListTrustProductEvaluationWithContext(ctx context.Context, TrustProductSid string, params *ListTrustProductEvaluationParams) ([]TrusthubV1TrustProductEvaluation, error) { + response, errors := c.StreamTrustProductEvaluationWithContext(ctx, TrustProductSid, params) records := make([]TrusthubV1TrustProductEvaluation, 0) for record := range response { @@ -161,6 +178,11 @@ func (c *ApiService) ListTrustProductEvaluation(TrustProductSid string, params * // Streams TrustProductEvaluation records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamTrustProductEvaluation(TrustProductSid string, params *ListTrustProductEvaluationParams) (chan TrusthubV1TrustProductEvaluation, chan error) { + return c.StreamTrustProductEvaluationWithContext(context.TODO(), TrustProductSid, params) +} + +// Streams TrustProductEvaluation records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamTrustProductEvaluationWithContext(ctx context.Context, TrustProductSid string, params *ListTrustProductEvaluationParams) (chan TrusthubV1TrustProductEvaluation, chan error) { if params == nil { params = &ListTrustProductEvaluationParams{} } @@ -169,19 +191,19 @@ func (c *ApiService) StreamTrustProductEvaluation(TrustProductSid string, params recordChannel := make(chan TrusthubV1TrustProductEvaluation, 1) errorChannel := make(chan error, 1) - response, err := c.PageTrustProductEvaluation(TrustProductSid, params, "", "") + response, err := c.PageTrustProductEvaluationWithContext(ctx, TrustProductSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamTrustProductEvaluation(response, params, recordChannel, errorChannel) + go c.streamTrustProductEvaluationWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamTrustProductEvaluation(response *ListTrustProductEvaluationResponse, params *ListTrustProductEvaluationParams, recordChannel chan TrusthubV1TrustProductEvaluation, errorChannel chan error) { +func (c *ApiService) streamTrustProductEvaluationWithContext(ctx context.Context, response *ListTrustProductEvaluationResponse, params *ListTrustProductEvaluationParams, recordChannel chan TrusthubV1TrustProductEvaluation, errorChannel chan error) { curRecord := 1 for response != nil { @@ -196,7 +218,7 @@ func (c *ApiService) streamTrustProductEvaluation(response *ListTrustProductEval } } - record, err := client.GetNext(c.baseURL, response, c.getNextListTrustProductEvaluationResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListTrustProductEvaluationResponseWithContext) if err != nil { errorChannel <- err break @@ -211,11 +233,11 @@ func (c *ApiService) streamTrustProductEvaluation(response *ListTrustProductEval close(errorChannel) } -func (c *ApiService) getNextListTrustProductEvaluationResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListTrustProductEvaluationResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/verify/v2/api_service.go b/rest/verify/v2/api_service.go index 05d7252f6..7cb878c65 100644 --- a/rest/verify/v2/api_service.go +++ b/rest/verify/v2/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://verify.twilio.com", + } +} diff --git a/rest/verify/v2/attempts.go b/rest/verify/v2/attempts.go index b81443a90..dde7e56a3 100644 --- a/rest/verify/v2/attempts.go +++ b/rest/verify/v2/attempts.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -26,6 +27,9 @@ import ( // Fetch a specific verification attempt. func (c *ApiService) FetchVerificationAttempt(Sid string) (*VerifyV2VerificationAttempt, error) { + return c.FetchVerificationAttemptWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchVerificationAttemptWithContext(ctx context.Context, Sid string) (*VerifyV2VerificationAttempt, error) { path := "/v2/Attempts/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -34,7 +38,7 @@ func (c *ApiService) FetchVerificationAttempt(Sid string) (*VerifyV2Verification "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -116,6 +120,11 @@ func (params *ListVerificationAttemptParams) SetLimit(Limit int) *ListVerificati // Retrieve a single page of VerificationAttempt records from the API. Request is executed immediately. func (c *ApiService) PageVerificationAttempt(params *ListVerificationAttemptParams, pageToken, pageNumber string) (*ListVerificationAttemptResponse, error) { + return c.PageVerificationAttemptWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of VerificationAttempt records from the API. Request is executed immediately. +func (c *ApiService) PageVerificationAttemptWithContext(ctx context.Context, params *ListVerificationAttemptParams, pageToken, pageNumber string) (*ListVerificationAttemptResponse, error) { path := "/v2/Attempts" data := url.Values{} @@ -158,7 +167,7 @@ func (c *ApiService) PageVerificationAttempt(params *ListVerificationAttemptPara data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -175,7 +184,12 @@ func (c *ApiService) PageVerificationAttempt(params *ListVerificationAttemptPara // Lists VerificationAttempt records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListVerificationAttempt(params *ListVerificationAttemptParams) ([]VerifyV2VerificationAttempt, error) { - response, errors := c.StreamVerificationAttempt(params) + return c.ListVerificationAttemptWithContext(context.TODO(), params) +} + +// Lists VerificationAttempt records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListVerificationAttemptWithContext(ctx context.Context, params *ListVerificationAttemptParams) ([]VerifyV2VerificationAttempt, error) { + response, errors := c.StreamVerificationAttemptWithContext(ctx, params) records := make([]VerifyV2VerificationAttempt, 0) for record := range response { @@ -191,6 +205,11 @@ func (c *ApiService) ListVerificationAttempt(params *ListVerificationAttemptPara // Streams VerificationAttempt records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamVerificationAttempt(params *ListVerificationAttemptParams) (chan VerifyV2VerificationAttempt, chan error) { + return c.StreamVerificationAttemptWithContext(context.TODO(), params) +} + +// Streams VerificationAttempt records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamVerificationAttemptWithContext(ctx context.Context, params *ListVerificationAttemptParams) (chan VerifyV2VerificationAttempt, chan error) { if params == nil { params = &ListVerificationAttemptParams{} } @@ -199,19 +218,19 @@ func (c *ApiService) StreamVerificationAttempt(params *ListVerificationAttemptPa recordChannel := make(chan VerifyV2VerificationAttempt, 1) errorChannel := make(chan error, 1) - response, err := c.PageVerificationAttempt(params, "", "") + response, err := c.PageVerificationAttemptWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamVerificationAttempt(response, params, recordChannel, errorChannel) + go c.streamVerificationAttemptWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamVerificationAttempt(response *ListVerificationAttemptResponse, params *ListVerificationAttemptParams, recordChannel chan VerifyV2VerificationAttempt, errorChannel chan error) { +func (c *ApiService) streamVerificationAttemptWithContext(ctx context.Context, response *ListVerificationAttemptResponse, params *ListVerificationAttemptParams, recordChannel chan VerifyV2VerificationAttempt, errorChannel chan error) { curRecord := 1 for response != nil { @@ -226,7 +245,7 @@ func (c *ApiService) streamVerificationAttempt(response *ListVerificationAttempt } } - record, err := client.GetNext(c.baseURL, response, c.getNextListVerificationAttemptResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListVerificationAttemptResponseWithContext) if err != nil { errorChannel <- err break @@ -241,11 +260,11 @@ func (c *ApiService) streamVerificationAttempt(response *ListVerificationAttempt close(errorChannel) } -func (c *ApiService) getNextListVerificationAttemptResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListVerificationAttemptResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/verify/v2/attempts_summary.go b/rest/verify/v2/attempts_summary.go index ec5834f12..12f51e9ac 100644 --- a/rest/verify/v2/attempts_summary.go +++ b/rest/verify/v2/attempts_summary.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -64,6 +65,9 @@ func (params *FetchVerificationAttemptsSummaryParams) SetDestinationPrefix(Desti // Get a summary of how many attempts were made and how many were converted. func (c *ApiService) FetchVerificationAttemptsSummary(params *FetchVerificationAttemptsSummaryParams) (*VerifyV2VerificationAttemptsSummary, error) { + return c.FetchVerificationAttemptsSummaryWithContext(context.TODO(), params) +} +func (c *ApiService) FetchVerificationAttemptsSummaryWithContext(ctx context.Context, params *FetchVerificationAttemptsSummaryParams) (*VerifyV2VerificationAttemptsSummary, error) { path := "/v2/Attempts/Summary" data := url.Values{} @@ -90,7 +94,7 @@ func (c *ApiService) FetchVerificationAttemptsSummary(params *FetchVerificationA data.Set("DestinationPrefix", *params.DestinationPrefix) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/verify/v2/docs/VerifyV2Service.md b/rest/verify/v2/docs/VerifyV2Service.md index d979aa7b6..91da450d2 100644 --- a/rest/verify/v2/docs/VerifyV2Service.md +++ b/rest/verify/v2/docs/VerifyV2Service.md @@ -6,7 +6,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **Sid** | Pointer to **string** | The unique string that we created to identify the Service resource. | **AccountSid** | Pointer to **string** | The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Service resource. | -**FriendlyName** | Pointer to **string** | The name that appears in the body of your verification messages. It can be up to 30 characters long and can include letters, numbers, spaces, dashes, underscores. Phone numbers, special characters or links are NOT allowed. It cannot contain more than 4 (consecutive or non-consecutive) digits. **This value should not contain PII.** | +**FriendlyName** | Pointer to **string** | The name that appears in the body of your verification messages. It can be up to 30 characters long and can include letters, numbers, spaces, dashes, underscores. Phone numbers, special characters or links are NOT allowed. **This value should not contain PII.** | **CodeLength** | **int** | The length of the verification code to generate. |[optional] [default to 0] **LookupEnabled** | Pointer to **bool** | Whether to perform a lookup with each verification started and return info about the phone number. | **Psd2Enabled** | Pointer to **bool** | Whether to pass PSD2 transaction parameters when starting a verification. | diff --git a/rest/verify/v2/forms.go b/rest/verify/v2/forms.go index 3dfcceaf3..9ee75a9a2 100644 --- a/rest/verify/v2/forms.go +++ b/rest/verify/v2/forms.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -23,6 +24,9 @@ import ( // Fetch the forms for a specific Form Type. func (c *ApiService) FetchForm(FormType string) (*VerifyV2Form, error) { + return c.FetchFormWithContext(context.TODO(), FormType) +} +func (c *ApiService) FetchFormWithContext(ctx context.Context, FormType string) (*VerifyV2Form, error) { path := "/v2/Forms/{FormType}" path = strings.Replace(path, "{"+"FormType"+"}", fmt.Sprint(FormType), -1) @@ -31,7 +35,7 @@ func (c *ApiService) FetchForm(FormType string) (*VerifyV2Form, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/verify/v2/model_verify_v2_service.go b/rest/verify/v2/model_verify_v2_service.go index 3ec7a5199..b0f5fd717 100644 --- a/rest/verify/v2/model_verify_v2_service.go +++ b/rest/verify/v2/model_verify_v2_service.go @@ -24,7 +24,7 @@ type VerifyV2Service struct { Sid *string `json:"sid,omitempty"` // The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Service resource. AccountSid *string `json:"account_sid,omitempty"` - // The name that appears in the body of your verification messages. It can be up to 30 characters long and can include letters, numbers, spaces, dashes, underscores. Phone numbers, special characters or links are NOT allowed. It cannot contain more than 4 (consecutive or non-consecutive) digits. **This value should not contain PII.** + // The name that appears in the body of your verification messages. It can be up to 30 characters long and can include letters, numbers, spaces, dashes, underscores. Phone numbers, special characters or links are NOT allowed. **This value should not contain PII.** FriendlyName *string `json:"friendly_name,omitempty"` // The length of the verification code to generate. CodeLength int `json:"code_length,omitempty"` diff --git a/rest/verify/v2/safe_list_numbers.go b/rest/verify/v2/safe_list_numbers.go index 098d83ce5..9b3c16677 100644 --- a/rest/verify/v2/safe_list_numbers.go +++ b/rest/verify/v2/safe_list_numbers.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -33,6 +34,9 @@ func (params *CreateSafelistParams) SetPhoneNumber(PhoneNumber string) *CreateSa // Add a new phone number to SafeList. func (c *ApiService) CreateSafelist(params *CreateSafelistParams) (*VerifyV2Safelist, error) { + return c.CreateSafelistWithContext(context.TODO(), params) +} +func (c *ApiService) CreateSafelistWithContext(ctx context.Context, params *CreateSafelistParams) (*VerifyV2Safelist, error) { path := "/v2/SafeList/Numbers" data := url.Values{} @@ -44,7 +48,7 @@ func (c *ApiService) CreateSafelist(params *CreateSafelistParams) (*VerifyV2Safe data.Set("PhoneNumber", *params.PhoneNumber) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -61,6 +65,9 @@ func (c *ApiService) CreateSafelist(params *CreateSafelistParams) (*VerifyV2Safe // Remove a phone number from SafeList. func (c *ApiService) DeleteSafelist(PhoneNumber string) error { + return c.DeleteSafelistWithContext(context.TODO(), PhoneNumber) +} +func (c *ApiService) DeleteSafelistWithContext(ctx context.Context, PhoneNumber string) error { path := "/v2/SafeList/Numbers/{PhoneNumber}" path = strings.Replace(path, "{"+"PhoneNumber"+"}", PhoneNumber, -1) @@ -69,7 +76,7 @@ func (c *ApiService) DeleteSafelist(PhoneNumber string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -81,6 +88,9 @@ func (c *ApiService) DeleteSafelist(PhoneNumber string) error { // Check if a phone number exists in SafeList. func (c *ApiService) FetchSafelist(PhoneNumber string) (*VerifyV2Safelist, error) { + return c.FetchSafelistWithContext(context.TODO(), PhoneNumber) +} +func (c *ApiService) FetchSafelistWithContext(ctx context.Context, PhoneNumber string) (*VerifyV2Safelist, error) { path := "/v2/SafeList/Numbers/{PhoneNumber}" path = strings.Replace(path, "{"+"PhoneNumber"+"}", PhoneNumber, -1) @@ -89,7 +99,7 @@ func (c *ApiService) FetchSafelist(PhoneNumber string) (*VerifyV2Safelist, error "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/verify/v2/services.go b/rest/verify/v2/services.go index 3e0c13f9d..9edd68b5c 100644 --- a/rest/verify/v2/services.go +++ b/rest/verify/v2/services.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -150,6 +151,9 @@ func (params *CreateServiceParams) SetVerifyEventSubscriptionEnabled(VerifyEvent // Create a new Verification Service. func (c *ApiService) CreateService(params *CreateServiceParams) (*VerifyV2Service, error) { + return c.CreateServiceWithContext(context.TODO(), params) +} +func (c *ApiService) CreateServiceWithContext(ctx context.Context, params *CreateServiceParams) (*VerifyV2Service, error) { path := "/v2/Services" data := url.Values{} @@ -218,7 +222,7 @@ func (c *ApiService) CreateService(params *CreateServiceParams) (*VerifyV2Servic data.Set("VerifyEventSubscriptionEnabled", fmt.Sprint(*params.VerifyEventSubscriptionEnabled)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -235,6 +239,9 @@ func (c *ApiService) CreateService(params *CreateServiceParams) (*VerifyV2Servic // Delete a specific Verification Service Instance. func (c *ApiService) DeleteService(Sid string) error { + return c.DeleteServiceWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteServiceWithContext(ctx context.Context, Sid string) error { path := "/v2/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -243,7 +250,7 @@ func (c *ApiService) DeleteService(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -255,6 +262,9 @@ func (c *ApiService) DeleteService(Sid string) error { // Fetch specific Verification Service Instance. func (c *ApiService) FetchService(Sid string) (*VerifyV2Service, error) { + return c.FetchServiceWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchServiceWithContext(ctx context.Context, Sid string) (*VerifyV2Service, error) { path := "/v2/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -263,7 +273,7 @@ func (c *ApiService) FetchService(Sid string) (*VerifyV2Service, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -297,6 +307,11 @@ func (params *ListServiceParams) SetLimit(Limit int) *ListServiceParams { // Retrieve a single page of Service records from the API. Request is executed immediately. func (c *ApiService) PageService(params *ListServiceParams, pageToken, pageNumber string) (*ListServiceResponse, error) { + return c.PageServiceWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Service records from the API. Request is executed immediately. +func (c *ApiService) PageServiceWithContext(ctx context.Context, params *ListServiceParams, pageToken, pageNumber string) (*ListServiceResponse, error) { path := "/v2/Services" data := url.Values{} @@ -315,7 +330,7 @@ func (c *ApiService) PageService(params *ListServiceParams, pageToken, pageNumbe data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -332,7 +347,12 @@ func (c *ApiService) PageService(params *ListServiceParams, pageToken, pageNumbe // Lists Service records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListService(params *ListServiceParams) ([]VerifyV2Service, error) { - response, errors := c.StreamService(params) + return c.ListServiceWithContext(context.TODO(), params) +} + +// Lists Service records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListServiceWithContext(ctx context.Context, params *ListServiceParams) ([]VerifyV2Service, error) { + response, errors := c.StreamServiceWithContext(ctx, params) records := make([]VerifyV2Service, 0) for record := range response { @@ -348,6 +368,11 @@ func (c *ApiService) ListService(params *ListServiceParams) ([]VerifyV2Service, // Streams Service records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamService(params *ListServiceParams) (chan VerifyV2Service, chan error) { + return c.StreamServiceWithContext(context.TODO(), params) +} + +// Streams Service records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamServiceWithContext(ctx context.Context, params *ListServiceParams) (chan VerifyV2Service, chan error) { if params == nil { params = &ListServiceParams{} } @@ -356,19 +381,19 @@ func (c *ApiService) StreamService(params *ListServiceParams) (chan VerifyV2Serv recordChannel := make(chan VerifyV2Service, 1) errorChannel := make(chan error, 1) - response, err := c.PageService(params, "", "") + response, err := c.PageServiceWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamService(response, params, recordChannel, errorChannel) + go c.streamServiceWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamService(response *ListServiceResponse, params *ListServiceParams, recordChannel chan VerifyV2Service, errorChannel chan error) { +func (c *ApiService) streamServiceWithContext(ctx context.Context, response *ListServiceResponse, params *ListServiceParams, recordChannel chan VerifyV2Service, errorChannel chan error) { curRecord := 1 for response != nil { @@ -383,7 +408,7 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListServiceResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListServiceResponseWithContext) if err != nil { errorChannel <- err break @@ -398,11 +423,11 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe close(errorChannel) } -func (c *ApiService) getNextListServiceResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListServiceResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -543,6 +568,9 @@ func (params *UpdateServiceParams) SetVerifyEventSubscriptionEnabled(VerifyEvent // Update a specific Verification Service. func (c *ApiService) UpdateService(Sid string, params *UpdateServiceParams) (*VerifyV2Service, error) { + return c.UpdateServiceWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateServiceWithContext(ctx context.Context, Sid string, params *UpdateServiceParams) (*VerifyV2Service, error) { path := "/v2/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -612,7 +640,7 @@ func (c *ApiService) UpdateService(Sid string, params *UpdateServiceParams) (*Ve data.Set("VerifyEventSubscriptionEnabled", fmt.Sprint(*params.VerifyEventSubscriptionEnabled)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/verify/v2/services_access_tokens.go b/rest/verify/v2/services_access_tokens.go index 0c029f7b5..0988ac912 100644 --- a/rest/verify/v2/services_access_tokens.go +++ b/rest/verify/v2/services_access_tokens.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -52,6 +53,9 @@ func (params *CreateAccessTokenParams) SetTtl(Ttl int) *CreateAccessTokenParams // Create a new enrollment Access Token for the Entity func (c *ApiService) CreateAccessToken(ServiceSid string, params *CreateAccessTokenParams) (*VerifyV2AccessToken, error) { + return c.CreateAccessTokenWithContext(context.TODO(), ServiceSid, params) +} +func (c *ApiService) CreateAccessTokenWithContext(ctx context.Context, ServiceSid string, params *CreateAccessTokenParams) (*VerifyV2AccessToken, error) { path := "/v2/Services/{ServiceSid}/AccessTokens" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -73,7 +77,7 @@ func (c *ApiService) CreateAccessToken(ServiceSid string, params *CreateAccessTo data.Set("Ttl", fmt.Sprint(*params.Ttl)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -90,6 +94,9 @@ func (c *ApiService) CreateAccessToken(ServiceSid string, params *CreateAccessTo // Fetch an Access Token for the Entity func (c *ApiService) FetchAccessToken(ServiceSid string, Sid string) (*VerifyV2AccessToken, error) { + return c.FetchAccessTokenWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) FetchAccessTokenWithContext(ctx context.Context, ServiceSid string, Sid string) (*VerifyV2AccessToken, error) { path := "/v2/Services/{ServiceSid}/AccessTokens/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -99,7 +106,7 @@ func (c *ApiService) FetchAccessToken(ServiceSid string, Sid string) (*VerifyV2A "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/verify/v2/services_entities.go b/rest/verify/v2/services_entities.go index c3b52698c..05e943552 100644 --- a/rest/verify/v2/services_entities.go +++ b/rest/verify/v2/services_entities.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -36,6 +37,9 @@ func (params *CreateEntityParams) SetIdentity(Identity string) *CreateEntityPara // Create a new Entity for the Service func (c *ApiService) CreateEntity(ServiceSid string, params *CreateEntityParams) (*VerifyV2Entity, error) { + return c.CreateEntityWithContext(context.TODO(), ServiceSid, params) +} +func (c *ApiService) CreateEntityWithContext(ctx context.Context, ServiceSid string, params *CreateEntityParams) (*VerifyV2Entity, error) { path := "/v2/Services/{ServiceSid}/Entities" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -48,7 +52,7 @@ func (c *ApiService) CreateEntity(ServiceSid string, params *CreateEntityParams) data.Set("Identity", *params.Identity) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -65,6 +69,9 @@ func (c *ApiService) CreateEntity(ServiceSid string, params *CreateEntityParams) // Delete a specific Entity. func (c *ApiService) DeleteEntity(ServiceSid string, Identity string) error { + return c.DeleteEntityWithContext(context.TODO(), ServiceSid, Identity) +} +func (c *ApiService) DeleteEntityWithContext(ctx context.Context, ServiceSid string, Identity string) error { path := "/v2/Services/{ServiceSid}/Entities/{Identity}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Identity"+"}", Identity, -1) @@ -74,7 +81,7 @@ func (c *ApiService) DeleteEntity(ServiceSid string, Identity string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -86,6 +93,9 @@ func (c *ApiService) DeleteEntity(ServiceSid string, Identity string) error { // Fetch a specific Entity. func (c *ApiService) FetchEntity(ServiceSid string, Identity string) (*VerifyV2Entity, error) { + return c.FetchEntityWithContext(context.TODO(), ServiceSid, Identity) +} +func (c *ApiService) FetchEntityWithContext(ctx context.Context, ServiceSid string, Identity string) (*VerifyV2Entity, error) { path := "/v2/Services/{ServiceSid}/Entities/{Identity}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Identity"+"}", Identity, -1) @@ -95,7 +105,7 @@ func (c *ApiService) FetchEntity(ServiceSid string, Identity string) (*VerifyV2E "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -129,6 +139,11 @@ func (params *ListEntityParams) SetLimit(Limit int) *ListEntityParams { // Retrieve a single page of Entity records from the API. Request is executed immediately. func (c *ApiService) PageEntity(ServiceSid string, params *ListEntityParams, pageToken, pageNumber string) (*ListEntityResponse, error) { + return c.PageEntityWithContext(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Entity records from the API. Request is executed immediately. +func (c *ApiService) PageEntityWithContext(ctx context.Context, ServiceSid string, params *ListEntityParams, pageToken, pageNumber string) (*ListEntityResponse, error) { path := "/v2/Services/{ServiceSid}/Entities" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -149,7 +164,7 @@ func (c *ApiService) PageEntity(ServiceSid string, params *ListEntityParams, pag data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -166,7 +181,12 @@ func (c *ApiService) PageEntity(ServiceSid string, params *ListEntityParams, pag // Lists Entity records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListEntity(ServiceSid string, params *ListEntityParams) ([]VerifyV2Entity, error) { - response, errors := c.StreamEntity(ServiceSid, params) + return c.ListEntityWithContext(context.TODO(), ServiceSid, params) +} + +// Lists Entity records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListEntityWithContext(ctx context.Context, ServiceSid string, params *ListEntityParams) ([]VerifyV2Entity, error) { + response, errors := c.StreamEntityWithContext(ctx, ServiceSid, params) records := make([]VerifyV2Entity, 0) for record := range response { @@ -182,6 +202,11 @@ func (c *ApiService) ListEntity(ServiceSid string, params *ListEntityParams) ([] // Streams Entity records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamEntity(ServiceSid string, params *ListEntityParams) (chan VerifyV2Entity, chan error) { + return c.StreamEntityWithContext(context.TODO(), ServiceSid, params) +} + +// Streams Entity records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamEntityWithContext(ctx context.Context, ServiceSid string, params *ListEntityParams) (chan VerifyV2Entity, chan error) { if params == nil { params = &ListEntityParams{} } @@ -190,19 +215,19 @@ func (c *ApiService) StreamEntity(ServiceSid string, params *ListEntityParams) ( recordChannel := make(chan VerifyV2Entity, 1) errorChannel := make(chan error, 1) - response, err := c.PageEntity(ServiceSid, params, "", "") + response, err := c.PageEntityWithContext(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamEntity(response, params, recordChannel, errorChannel) + go c.streamEntityWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamEntity(response *ListEntityResponse, params *ListEntityParams, recordChannel chan VerifyV2Entity, errorChannel chan error) { +func (c *ApiService) streamEntityWithContext(ctx context.Context, response *ListEntityResponse, params *ListEntityParams, recordChannel chan VerifyV2Entity, errorChannel chan error) { curRecord := 1 for response != nil { @@ -217,7 +242,7 @@ func (c *ApiService) streamEntity(response *ListEntityResponse, params *ListEnti } } - record, err := client.GetNext(c.baseURL, response, c.getNextListEntityResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListEntityResponseWithContext) if err != nil { errorChannel <- err break @@ -232,11 +257,11 @@ func (c *ApiService) streamEntity(response *ListEntityResponse, params *ListEnti close(errorChannel) } -func (c *ApiService) getNextListEntityResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListEntityResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/verify/v2/services_entities_challenges.go b/rest/verify/v2/services_entities_challenges.go index 2f476b3fc..1147834e7 100644 --- a/rest/verify/v2/services_entities_challenges.go +++ b/rest/verify/v2/services_entities_challenges.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -67,6 +68,9 @@ func (params *CreateChallengeParams) SetAuthPayload(AuthPayload string) *CreateC // Create a new Challenge for the Factor func (c *ApiService) CreateChallenge(ServiceSid string, Identity string, params *CreateChallengeParams) (*VerifyV2Challenge, error) { + return c.CreateChallengeWithContext(context.TODO(), ServiceSid, Identity, params) +} +func (c *ApiService) CreateChallengeWithContext(ctx context.Context, ServiceSid string, Identity string, params *CreateChallengeParams) (*VerifyV2Challenge, error) { path := "/v2/Services/{ServiceSid}/Entities/{Identity}/Challenges" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Identity"+"}", Identity, -1) @@ -109,7 +113,7 @@ func (c *ApiService) CreateChallenge(ServiceSid string, Identity string, params data.Set("AuthPayload", *params.AuthPayload) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -126,6 +130,9 @@ func (c *ApiService) CreateChallenge(ServiceSid string, Identity string, params // Fetch a specific Challenge. func (c *ApiService) FetchChallenge(ServiceSid string, Identity string, Sid string) (*VerifyV2Challenge, error) { + return c.FetchChallengeWithContext(context.TODO(), ServiceSid, Identity, Sid) +} +func (c *ApiService) FetchChallengeWithContext(ctx context.Context, ServiceSid string, Identity string, Sid string) (*VerifyV2Challenge, error) { path := "/v2/Services/{ServiceSid}/Entities/{Identity}/Challenges/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Identity"+"}", Identity, -1) @@ -136,7 +143,7 @@ func (c *ApiService) FetchChallenge(ServiceSid string, Identity string, Sid stri "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -188,6 +195,11 @@ func (params *ListChallengeParams) SetLimit(Limit int) *ListChallengeParams { // Retrieve a single page of Challenge records from the API. Request is executed immediately. func (c *ApiService) PageChallenge(ServiceSid string, Identity string, params *ListChallengeParams, pageToken, pageNumber string) (*ListChallengeResponse, error) { + return c.PageChallengeWithContext(context.TODO(), ServiceSid, Identity, params, pageToken, pageNumber) +} + +// Retrieve a single page of Challenge records from the API. Request is executed immediately. +func (c *ApiService) PageChallengeWithContext(ctx context.Context, ServiceSid string, Identity string, params *ListChallengeParams, pageToken, pageNumber string) (*ListChallengeResponse, error) { path := "/v2/Services/{ServiceSid}/Entities/{Identity}/Challenges" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -218,7 +230,7 @@ func (c *ApiService) PageChallenge(ServiceSid string, Identity string, params *L data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -235,7 +247,12 @@ func (c *ApiService) PageChallenge(ServiceSid string, Identity string, params *L // Lists Challenge records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListChallenge(ServiceSid string, Identity string, params *ListChallengeParams) ([]VerifyV2Challenge, error) { - response, errors := c.StreamChallenge(ServiceSid, Identity, params) + return c.ListChallengeWithContext(context.TODO(), ServiceSid, Identity, params) +} + +// Lists Challenge records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListChallengeWithContext(ctx context.Context, ServiceSid string, Identity string, params *ListChallengeParams) ([]VerifyV2Challenge, error) { + response, errors := c.StreamChallengeWithContext(ctx, ServiceSid, Identity, params) records := make([]VerifyV2Challenge, 0) for record := range response { @@ -251,6 +268,11 @@ func (c *ApiService) ListChallenge(ServiceSid string, Identity string, params *L // Streams Challenge records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamChallenge(ServiceSid string, Identity string, params *ListChallengeParams) (chan VerifyV2Challenge, chan error) { + return c.StreamChallengeWithContext(context.TODO(), ServiceSid, Identity, params) +} + +// Streams Challenge records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamChallengeWithContext(ctx context.Context, ServiceSid string, Identity string, params *ListChallengeParams) (chan VerifyV2Challenge, chan error) { if params == nil { params = &ListChallengeParams{} } @@ -259,19 +281,19 @@ func (c *ApiService) StreamChallenge(ServiceSid string, Identity string, params recordChannel := make(chan VerifyV2Challenge, 1) errorChannel := make(chan error, 1) - response, err := c.PageChallenge(ServiceSid, Identity, params, "", "") + response, err := c.PageChallengeWithContext(ctx, ServiceSid, Identity, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamChallenge(response, params, recordChannel, errorChannel) + go c.streamChallengeWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamChallenge(response *ListChallengeResponse, params *ListChallengeParams, recordChannel chan VerifyV2Challenge, errorChannel chan error) { +func (c *ApiService) streamChallengeWithContext(ctx context.Context, response *ListChallengeResponse, params *ListChallengeParams, recordChannel chan VerifyV2Challenge, errorChannel chan error) { curRecord := 1 for response != nil { @@ -286,7 +308,7 @@ func (c *ApiService) streamChallenge(response *ListChallengeResponse, params *Li } } - record, err := client.GetNext(c.baseURL, response, c.getNextListChallengeResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListChallengeResponseWithContext) if err != nil { errorChannel <- err break @@ -301,11 +323,11 @@ func (c *ApiService) streamChallenge(response *ListChallengeResponse, params *Li close(errorChannel) } -func (c *ApiService) getNextListChallengeResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListChallengeResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -338,6 +360,9 @@ func (params *UpdateChallengeParams) SetMetadata(Metadata map[string]interface{} // Verify a specific Challenge. func (c *ApiService) UpdateChallenge(ServiceSid string, Identity string, Sid string, params *UpdateChallengeParams) (*VerifyV2Challenge, error) { + return c.UpdateChallengeWithContext(context.TODO(), ServiceSid, Identity, Sid, params) +} +func (c *ApiService) UpdateChallengeWithContext(ctx context.Context, ServiceSid string, Identity string, Sid string, params *UpdateChallengeParams) (*VerifyV2Challenge, error) { path := "/v2/Services/{ServiceSid}/Entities/{Identity}/Challenges/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Identity"+"}", Identity, -1) @@ -361,7 +386,7 @@ func (c *ApiService) UpdateChallenge(ServiceSid string, Identity string, Sid str data.Set("Metadata", string(v)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/verify/v2/services_entities_challenges_notifications.go b/rest/verify/v2/services_entities_challenges_notifications.go index 2fbd0d9b7..72c60ca36 100644 --- a/rest/verify/v2/services_entities_challenges_notifications.go +++ b/rest/verify/v2/services_entities_challenges_notifications.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -34,6 +35,9 @@ func (params *CreateNotificationParams) SetTtl(Ttl int) *CreateNotificationParam // Create a new Notification for the corresponding Challenge func (c *ApiService) CreateNotification(ServiceSid string, Identity string, ChallengeSid string, params *CreateNotificationParams) (*VerifyV2Notification, error) { + return c.CreateNotificationWithContext(context.TODO(), ServiceSid, Identity, ChallengeSid, params) +} +func (c *ApiService) CreateNotificationWithContext(ctx context.Context, ServiceSid string, Identity string, ChallengeSid string, params *CreateNotificationParams) (*VerifyV2Notification, error) { path := "/v2/Services/{ServiceSid}/Entities/{Identity}/Challenges/{ChallengeSid}/Notifications" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Identity"+"}", Identity, -1) @@ -48,7 +52,7 @@ func (c *ApiService) CreateNotification(ServiceSid string, Identity string, Chal data.Set("Ttl", fmt.Sprint(*params.Ttl)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/verify/v2/services_entities_factors.go b/rest/verify/v2/services_entities_factors.go index f8684a80f..bb56f771a 100644 --- a/rest/verify/v2/services_entities_factors.go +++ b/rest/verify/v2/services_entities_factors.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -114,6 +115,9 @@ func (params *CreateNewFactorParams) SetMetadata(Metadata map[string]interface{} // Create a new Factor for the Entity func (c *ApiService) CreateNewFactor(ServiceSid string, Identity string, params *CreateNewFactorParams) (*VerifyV2NewFactor, error) { + return c.CreateNewFactorWithContext(context.TODO(), ServiceSid, Identity, params) +} +func (c *ApiService) CreateNewFactorWithContext(ctx context.Context, ServiceSid string, Identity string, params *CreateNewFactorParams) (*VerifyV2NewFactor, error) { path := "/v2/Services/{ServiceSid}/Entities/{Identity}/Factors" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Identity"+"}", Identity, -1) @@ -172,7 +176,7 @@ func (c *ApiService) CreateNewFactor(ServiceSid string, Identity string, params data.Set("Metadata", string(v)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -189,6 +193,9 @@ func (c *ApiService) CreateNewFactor(ServiceSid string, Identity string, params // Delete a specific Factor. func (c *ApiService) DeleteFactor(ServiceSid string, Identity string, Sid string) error { + return c.DeleteFactorWithContext(context.TODO(), ServiceSid, Identity, Sid) +} +func (c *ApiService) DeleteFactorWithContext(ctx context.Context, ServiceSid string, Identity string, Sid string) error { path := "/v2/Services/{ServiceSid}/Entities/{Identity}/Factors/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Identity"+"}", Identity, -1) @@ -199,7 +206,7 @@ func (c *ApiService) DeleteFactor(ServiceSid string, Identity string, Sid string "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -211,6 +218,9 @@ func (c *ApiService) DeleteFactor(ServiceSid string, Identity string, Sid string // Fetch a specific Factor. func (c *ApiService) FetchFactor(ServiceSid string, Identity string, Sid string) (*VerifyV2Factor, error) { + return c.FetchFactorWithContext(context.TODO(), ServiceSid, Identity, Sid) +} +func (c *ApiService) FetchFactorWithContext(ctx context.Context, ServiceSid string, Identity string, Sid string) (*VerifyV2Factor, error) { path := "/v2/Services/{ServiceSid}/Entities/{Identity}/Factors/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Identity"+"}", Identity, -1) @@ -221,7 +231,7 @@ func (c *ApiService) FetchFactor(ServiceSid string, Identity string, Sid string) "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -255,6 +265,11 @@ func (params *ListFactorParams) SetLimit(Limit int) *ListFactorParams { // Retrieve a single page of Factor records from the API. Request is executed immediately. func (c *ApiService) PageFactor(ServiceSid string, Identity string, params *ListFactorParams, pageToken, pageNumber string) (*ListFactorResponse, error) { + return c.PageFactorWithContext(context.TODO(), ServiceSid, Identity, params, pageToken, pageNumber) +} + +// Retrieve a single page of Factor records from the API. Request is executed immediately. +func (c *ApiService) PageFactorWithContext(ctx context.Context, ServiceSid string, Identity string, params *ListFactorParams, pageToken, pageNumber string) (*ListFactorResponse, error) { path := "/v2/Services/{ServiceSid}/Entities/{Identity}/Factors" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -276,7 +291,7 @@ func (c *ApiService) PageFactor(ServiceSid string, Identity string, params *List data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -293,7 +308,12 @@ func (c *ApiService) PageFactor(ServiceSid string, Identity string, params *List // Lists Factor records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListFactor(ServiceSid string, Identity string, params *ListFactorParams) ([]VerifyV2Factor, error) { - response, errors := c.StreamFactor(ServiceSid, Identity, params) + return c.ListFactorWithContext(context.TODO(), ServiceSid, Identity, params) +} + +// Lists Factor records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListFactorWithContext(ctx context.Context, ServiceSid string, Identity string, params *ListFactorParams) ([]VerifyV2Factor, error) { + response, errors := c.StreamFactorWithContext(ctx, ServiceSid, Identity, params) records := make([]VerifyV2Factor, 0) for record := range response { @@ -309,6 +329,11 @@ func (c *ApiService) ListFactor(ServiceSid string, Identity string, params *List // Streams Factor records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamFactor(ServiceSid string, Identity string, params *ListFactorParams) (chan VerifyV2Factor, chan error) { + return c.StreamFactorWithContext(context.TODO(), ServiceSid, Identity, params) +} + +// Streams Factor records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamFactorWithContext(ctx context.Context, ServiceSid string, Identity string, params *ListFactorParams) (chan VerifyV2Factor, chan error) { if params == nil { params = &ListFactorParams{} } @@ -317,19 +342,19 @@ func (c *ApiService) StreamFactor(ServiceSid string, Identity string, params *Li recordChannel := make(chan VerifyV2Factor, 1) errorChannel := make(chan error, 1) - response, err := c.PageFactor(ServiceSid, Identity, params, "", "") + response, err := c.PageFactorWithContext(ctx, ServiceSid, Identity, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamFactor(response, params, recordChannel, errorChannel) + go c.streamFactorWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamFactor(response *ListFactorResponse, params *ListFactorParams, recordChannel chan VerifyV2Factor, errorChannel chan error) { +func (c *ApiService) streamFactorWithContext(ctx context.Context, response *ListFactorResponse, params *ListFactorParams, recordChannel chan VerifyV2Factor, errorChannel chan error) { curRecord := 1 for response != nil { @@ -344,7 +369,7 @@ func (c *ApiService) streamFactor(response *ListFactorResponse, params *ListFact } } - record, err := client.GetNext(c.baseURL, response, c.getNextListFactorResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListFactorResponseWithContext) if err != nil { errorChannel <- err break @@ -359,11 +384,11 @@ func (c *ApiService) streamFactor(response *ListFactorResponse, params *ListFact close(errorChannel) } -func (c *ApiService) getNextListFactorResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListFactorResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -438,6 +463,9 @@ func (params *UpdateFactorParams) SetConfigNotificationPlatform(ConfigNotificati // Update a specific Factor. This endpoint can be used to Verify a Factor if passed an `AuthPayload` param. func (c *ApiService) UpdateFactor(ServiceSid string, Identity string, Sid string, params *UpdateFactorParams) (*VerifyV2Factor, error) { + return c.UpdateFactorWithContext(context.TODO(), ServiceSid, Identity, Sid, params) +} +func (c *ApiService) UpdateFactorWithContext(ctx context.Context, ServiceSid string, Identity string, Sid string, params *UpdateFactorParams) (*VerifyV2Factor, error) { path := "/v2/Services/{ServiceSid}/Entities/{Identity}/Factors/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Identity"+"}", Identity, -1) @@ -476,7 +504,7 @@ func (c *ApiService) UpdateFactor(ServiceSid string, Identity string, Sid string data.Set("Config.NotificationPlatform", *params.ConfigNotificationPlatform) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/verify/v2/services_messaging_configurations.go b/rest/verify/v2/services_messaging_configurations.go index 011021fe6..c3db11a1c 100644 --- a/rest/verify/v2/services_messaging_configurations.go +++ b/rest/verify/v2/services_messaging_configurations.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -42,6 +43,9 @@ func (params *CreateMessagingConfigurationParams) SetMessagingServiceSid(Messagi // Create a new MessagingConfiguration for a service. func (c *ApiService) CreateMessagingConfiguration(ServiceSid string, params *CreateMessagingConfigurationParams) (*VerifyV2MessagingConfiguration, error) { + return c.CreateMessagingConfigurationWithContext(context.TODO(), ServiceSid, params) +} +func (c *ApiService) CreateMessagingConfigurationWithContext(ctx context.Context, ServiceSid string, params *CreateMessagingConfigurationParams) (*VerifyV2MessagingConfiguration, error) { path := "/v2/Services/{ServiceSid}/MessagingConfigurations" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -57,7 +61,7 @@ func (c *ApiService) CreateMessagingConfiguration(ServiceSid string, params *Cre data.Set("MessagingServiceSid", *params.MessagingServiceSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -74,6 +78,9 @@ func (c *ApiService) CreateMessagingConfiguration(ServiceSid string, params *Cre // Delete a specific MessagingConfiguration. func (c *ApiService) DeleteMessagingConfiguration(ServiceSid string, Country string) error { + return c.DeleteMessagingConfigurationWithContext(context.TODO(), ServiceSid, Country) +} +func (c *ApiService) DeleteMessagingConfigurationWithContext(ctx context.Context, ServiceSid string, Country string) error { path := "/v2/Services/{ServiceSid}/MessagingConfigurations/{Country}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Country"+"}", Country, -1) @@ -83,7 +90,7 @@ func (c *ApiService) DeleteMessagingConfiguration(ServiceSid string, Country str "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -95,6 +102,9 @@ func (c *ApiService) DeleteMessagingConfiguration(ServiceSid string, Country str // Fetch a specific MessagingConfiguration. func (c *ApiService) FetchMessagingConfiguration(ServiceSid string, Country string) (*VerifyV2MessagingConfiguration, error) { + return c.FetchMessagingConfigurationWithContext(context.TODO(), ServiceSid, Country) +} +func (c *ApiService) FetchMessagingConfigurationWithContext(ctx context.Context, ServiceSid string, Country string) (*VerifyV2MessagingConfiguration, error) { path := "/v2/Services/{ServiceSid}/MessagingConfigurations/{Country}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Country"+"}", Country, -1) @@ -104,7 +114,7 @@ func (c *ApiService) FetchMessagingConfiguration(ServiceSid string, Country stri "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -138,6 +148,11 @@ func (params *ListMessagingConfigurationParams) SetLimit(Limit int) *ListMessagi // Retrieve a single page of MessagingConfiguration records from the API. Request is executed immediately. func (c *ApiService) PageMessagingConfiguration(ServiceSid string, params *ListMessagingConfigurationParams, pageToken, pageNumber string) (*ListMessagingConfigurationResponse, error) { + return c.PageMessagingConfigurationWithContext(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of MessagingConfiguration records from the API. Request is executed immediately. +func (c *ApiService) PageMessagingConfigurationWithContext(ctx context.Context, ServiceSid string, params *ListMessagingConfigurationParams, pageToken, pageNumber string) (*ListMessagingConfigurationResponse, error) { path := "/v2/Services/{ServiceSid}/MessagingConfigurations" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -158,7 +173,7 @@ func (c *ApiService) PageMessagingConfiguration(ServiceSid string, params *ListM data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -175,7 +190,12 @@ func (c *ApiService) PageMessagingConfiguration(ServiceSid string, params *ListM // Lists MessagingConfiguration records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListMessagingConfiguration(ServiceSid string, params *ListMessagingConfigurationParams) ([]VerifyV2MessagingConfiguration, error) { - response, errors := c.StreamMessagingConfiguration(ServiceSid, params) + return c.ListMessagingConfigurationWithContext(context.TODO(), ServiceSid, params) +} + +// Lists MessagingConfiguration records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListMessagingConfigurationWithContext(ctx context.Context, ServiceSid string, params *ListMessagingConfigurationParams) ([]VerifyV2MessagingConfiguration, error) { + response, errors := c.StreamMessagingConfigurationWithContext(ctx, ServiceSid, params) records := make([]VerifyV2MessagingConfiguration, 0) for record := range response { @@ -191,6 +211,11 @@ func (c *ApiService) ListMessagingConfiguration(ServiceSid string, params *ListM // Streams MessagingConfiguration records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamMessagingConfiguration(ServiceSid string, params *ListMessagingConfigurationParams) (chan VerifyV2MessagingConfiguration, chan error) { + return c.StreamMessagingConfigurationWithContext(context.TODO(), ServiceSid, params) +} + +// Streams MessagingConfiguration records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamMessagingConfigurationWithContext(ctx context.Context, ServiceSid string, params *ListMessagingConfigurationParams) (chan VerifyV2MessagingConfiguration, chan error) { if params == nil { params = &ListMessagingConfigurationParams{} } @@ -199,19 +224,19 @@ func (c *ApiService) StreamMessagingConfiguration(ServiceSid string, params *Lis recordChannel := make(chan VerifyV2MessagingConfiguration, 1) errorChannel := make(chan error, 1) - response, err := c.PageMessagingConfiguration(ServiceSid, params, "", "") + response, err := c.PageMessagingConfigurationWithContext(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamMessagingConfiguration(response, params, recordChannel, errorChannel) + go c.streamMessagingConfigurationWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamMessagingConfiguration(response *ListMessagingConfigurationResponse, params *ListMessagingConfigurationParams, recordChannel chan VerifyV2MessagingConfiguration, errorChannel chan error) { +func (c *ApiService) streamMessagingConfigurationWithContext(ctx context.Context, response *ListMessagingConfigurationResponse, params *ListMessagingConfigurationParams, recordChannel chan VerifyV2MessagingConfiguration, errorChannel chan error) { curRecord := 1 for response != nil { @@ -226,7 +251,7 @@ func (c *ApiService) streamMessagingConfiguration(response *ListMessagingConfigu } } - record, err := client.GetNext(c.baseURL, response, c.getNextListMessagingConfigurationResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListMessagingConfigurationResponseWithContext) if err != nil { errorChannel <- err break @@ -241,11 +266,11 @@ func (c *ApiService) streamMessagingConfiguration(response *ListMessagingConfigu close(errorChannel) } -func (c *ApiService) getNextListMessagingConfigurationResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListMessagingConfigurationResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -272,6 +297,9 @@ func (params *UpdateMessagingConfigurationParams) SetMessagingServiceSid(Messagi // Update a specific MessagingConfiguration func (c *ApiService) UpdateMessagingConfiguration(ServiceSid string, Country string, params *UpdateMessagingConfigurationParams) (*VerifyV2MessagingConfiguration, error) { + return c.UpdateMessagingConfigurationWithContext(context.TODO(), ServiceSid, Country, params) +} +func (c *ApiService) UpdateMessagingConfigurationWithContext(ctx context.Context, ServiceSid string, Country string, params *UpdateMessagingConfigurationParams) (*VerifyV2MessagingConfiguration, error) { path := "/v2/Services/{ServiceSid}/MessagingConfigurations/{Country}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Country"+"}", Country, -1) @@ -285,7 +313,7 @@ func (c *ApiService) UpdateMessagingConfiguration(ServiceSid string, Country str data.Set("MessagingServiceSid", *params.MessagingServiceSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/verify/v2/services_rate_limits.go b/rest/verify/v2/services_rate_limits.go index 4e29bc55d..226694274 100644 --- a/rest/verify/v2/services_rate_limits.go +++ b/rest/verify/v2/services_rate_limits.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -42,6 +43,9 @@ func (params *CreateRateLimitParams) SetDescription(Description string) *CreateR // Create a new Rate Limit for a Service func (c *ApiService) CreateRateLimit(ServiceSid string, params *CreateRateLimitParams) (*VerifyV2RateLimit, error) { + return c.CreateRateLimitWithContext(context.TODO(), ServiceSid, params) +} +func (c *ApiService) CreateRateLimitWithContext(ctx context.Context, ServiceSid string, params *CreateRateLimitParams) (*VerifyV2RateLimit, error) { path := "/v2/Services/{ServiceSid}/RateLimits" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -57,7 +61,7 @@ func (c *ApiService) CreateRateLimit(ServiceSid string, params *CreateRateLimitP data.Set("Description", *params.Description) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -74,6 +78,9 @@ func (c *ApiService) CreateRateLimit(ServiceSid string, params *CreateRateLimitP // Delete a specific Rate Limit. func (c *ApiService) DeleteRateLimit(ServiceSid string, Sid string) error { + return c.DeleteRateLimitWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) DeleteRateLimitWithContext(ctx context.Context, ServiceSid string, Sid string) error { path := "/v2/Services/{ServiceSid}/RateLimits/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -83,7 +90,7 @@ func (c *ApiService) DeleteRateLimit(ServiceSid string, Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -95,6 +102,9 @@ func (c *ApiService) DeleteRateLimit(ServiceSid string, Sid string) error { // Fetch a specific Rate Limit. func (c *ApiService) FetchRateLimit(ServiceSid string, Sid string) (*VerifyV2RateLimit, error) { + return c.FetchRateLimitWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) FetchRateLimitWithContext(ctx context.Context, ServiceSid string, Sid string) (*VerifyV2RateLimit, error) { path := "/v2/Services/{ServiceSid}/RateLimits/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -104,7 +114,7 @@ func (c *ApiService) FetchRateLimit(ServiceSid string, Sid string) (*VerifyV2Rat "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -138,6 +148,11 @@ func (params *ListRateLimitParams) SetLimit(Limit int) *ListRateLimitParams { // Retrieve a single page of RateLimit records from the API. Request is executed immediately. func (c *ApiService) PageRateLimit(ServiceSid string, params *ListRateLimitParams, pageToken, pageNumber string) (*ListRateLimitResponse, error) { + return c.PageRateLimitWithContext(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of RateLimit records from the API. Request is executed immediately. +func (c *ApiService) PageRateLimitWithContext(ctx context.Context, ServiceSid string, params *ListRateLimitParams, pageToken, pageNumber string) (*ListRateLimitResponse, error) { path := "/v2/Services/{ServiceSid}/RateLimits" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -158,7 +173,7 @@ func (c *ApiService) PageRateLimit(ServiceSid string, params *ListRateLimitParam data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -175,7 +190,12 @@ func (c *ApiService) PageRateLimit(ServiceSid string, params *ListRateLimitParam // Lists RateLimit records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListRateLimit(ServiceSid string, params *ListRateLimitParams) ([]VerifyV2RateLimit, error) { - response, errors := c.StreamRateLimit(ServiceSid, params) + return c.ListRateLimitWithContext(context.TODO(), ServiceSid, params) +} + +// Lists RateLimit records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListRateLimitWithContext(ctx context.Context, ServiceSid string, params *ListRateLimitParams) ([]VerifyV2RateLimit, error) { + response, errors := c.StreamRateLimitWithContext(ctx, ServiceSid, params) records := make([]VerifyV2RateLimit, 0) for record := range response { @@ -191,6 +211,11 @@ func (c *ApiService) ListRateLimit(ServiceSid string, params *ListRateLimitParam // Streams RateLimit records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamRateLimit(ServiceSid string, params *ListRateLimitParams) (chan VerifyV2RateLimit, chan error) { + return c.StreamRateLimitWithContext(context.TODO(), ServiceSid, params) +} + +// Streams RateLimit records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamRateLimitWithContext(ctx context.Context, ServiceSid string, params *ListRateLimitParams) (chan VerifyV2RateLimit, chan error) { if params == nil { params = &ListRateLimitParams{} } @@ -199,19 +224,19 @@ func (c *ApiService) StreamRateLimit(ServiceSid string, params *ListRateLimitPar recordChannel := make(chan VerifyV2RateLimit, 1) errorChannel := make(chan error, 1) - response, err := c.PageRateLimit(ServiceSid, params, "", "") + response, err := c.PageRateLimitWithContext(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamRateLimit(response, params, recordChannel, errorChannel) + go c.streamRateLimitWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamRateLimit(response *ListRateLimitResponse, params *ListRateLimitParams, recordChannel chan VerifyV2RateLimit, errorChannel chan error) { +func (c *ApiService) streamRateLimitWithContext(ctx context.Context, response *ListRateLimitResponse, params *ListRateLimitParams, recordChannel chan VerifyV2RateLimit, errorChannel chan error) { curRecord := 1 for response != nil { @@ -226,7 +251,7 @@ func (c *ApiService) streamRateLimit(response *ListRateLimitResponse, params *Li } } - record, err := client.GetNext(c.baseURL, response, c.getNextListRateLimitResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListRateLimitResponseWithContext) if err != nil { errorChannel <- err break @@ -241,11 +266,11 @@ func (c *ApiService) streamRateLimit(response *ListRateLimitResponse, params *Li close(errorChannel) } -func (c *ApiService) getNextListRateLimitResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListRateLimitResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -272,6 +297,9 @@ func (params *UpdateRateLimitParams) SetDescription(Description string) *UpdateR // Update a specific Rate Limit. func (c *ApiService) UpdateRateLimit(ServiceSid string, Sid string, params *UpdateRateLimitParams) (*VerifyV2RateLimit, error) { + return c.UpdateRateLimitWithContext(context.TODO(), ServiceSid, Sid, params) +} +func (c *ApiService) UpdateRateLimitWithContext(ctx context.Context, ServiceSid string, Sid string, params *UpdateRateLimitParams) (*VerifyV2RateLimit, error) { path := "/v2/Services/{ServiceSid}/RateLimits/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -285,7 +313,7 @@ func (c *ApiService) UpdateRateLimit(ServiceSid string, Sid string, params *Upda data.Set("Description", *params.Description) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/verify/v2/services_rate_limits_buckets.go b/rest/verify/v2/services_rate_limits_buckets.go index c835b280e..49e35ef23 100644 --- a/rest/verify/v2/services_rate_limits_buckets.go +++ b/rest/verify/v2/services_rate_limits_buckets.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -42,6 +43,9 @@ func (params *CreateBucketParams) SetInterval(Interval int) *CreateBucketParams // Create a new Bucket for a Rate Limit func (c *ApiService) CreateBucket(ServiceSid string, RateLimitSid string, params *CreateBucketParams) (*VerifyV2Bucket, error) { + return c.CreateBucketWithContext(context.TODO(), ServiceSid, RateLimitSid, params) +} +func (c *ApiService) CreateBucketWithContext(ctx context.Context, ServiceSid string, RateLimitSid string, params *CreateBucketParams) (*VerifyV2Bucket, error) { path := "/v2/Services/{ServiceSid}/RateLimits/{RateLimitSid}/Buckets" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"RateLimitSid"+"}", RateLimitSid, -1) @@ -58,7 +62,7 @@ func (c *ApiService) CreateBucket(ServiceSid string, RateLimitSid string, params data.Set("Interval", fmt.Sprint(*params.Interval)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -75,6 +79,9 @@ func (c *ApiService) CreateBucket(ServiceSid string, RateLimitSid string, params // Delete a specific Bucket. func (c *ApiService) DeleteBucket(ServiceSid string, RateLimitSid string, Sid string) error { + return c.DeleteBucketWithContext(context.TODO(), ServiceSid, RateLimitSid, Sid) +} +func (c *ApiService) DeleteBucketWithContext(ctx context.Context, ServiceSid string, RateLimitSid string, Sid string) error { path := "/v2/Services/{ServiceSid}/RateLimits/{RateLimitSid}/Buckets/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"RateLimitSid"+"}", RateLimitSid, -1) @@ -85,7 +92,7 @@ func (c *ApiService) DeleteBucket(ServiceSid string, RateLimitSid string, Sid st "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -97,6 +104,9 @@ func (c *ApiService) DeleteBucket(ServiceSid string, RateLimitSid string, Sid st // Fetch a specific Bucket. func (c *ApiService) FetchBucket(ServiceSid string, RateLimitSid string, Sid string) (*VerifyV2Bucket, error) { + return c.FetchBucketWithContext(context.TODO(), ServiceSid, RateLimitSid, Sid) +} +func (c *ApiService) FetchBucketWithContext(ctx context.Context, ServiceSid string, RateLimitSid string, Sid string) (*VerifyV2Bucket, error) { path := "/v2/Services/{ServiceSid}/RateLimits/{RateLimitSid}/Buckets/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"RateLimitSid"+"}", RateLimitSid, -1) @@ -107,7 +117,7 @@ func (c *ApiService) FetchBucket(ServiceSid string, RateLimitSid string, Sid str "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -141,6 +151,11 @@ func (params *ListBucketParams) SetLimit(Limit int) *ListBucketParams { // Retrieve a single page of Bucket records from the API. Request is executed immediately. func (c *ApiService) PageBucket(ServiceSid string, RateLimitSid string, params *ListBucketParams, pageToken, pageNumber string) (*ListBucketResponse, error) { + return c.PageBucketWithContext(context.TODO(), ServiceSid, RateLimitSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Bucket records from the API. Request is executed immediately. +func (c *ApiService) PageBucketWithContext(ctx context.Context, ServiceSid string, RateLimitSid string, params *ListBucketParams, pageToken, pageNumber string) (*ListBucketResponse, error) { path := "/v2/Services/{ServiceSid}/RateLimits/{RateLimitSid}/Buckets" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -162,7 +177,7 @@ func (c *ApiService) PageBucket(ServiceSid string, RateLimitSid string, params * data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -179,7 +194,12 @@ func (c *ApiService) PageBucket(ServiceSid string, RateLimitSid string, params * // Lists Bucket records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListBucket(ServiceSid string, RateLimitSid string, params *ListBucketParams) ([]VerifyV2Bucket, error) { - response, errors := c.StreamBucket(ServiceSid, RateLimitSid, params) + return c.ListBucketWithContext(context.TODO(), ServiceSid, RateLimitSid, params) +} + +// Lists Bucket records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListBucketWithContext(ctx context.Context, ServiceSid string, RateLimitSid string, params *ListBucketParams) ([]VerifyV2Bucket, error) { + response, errors := c.StreamBucketWithContext(ctx, ServiceSid, RateLimitSid, params) records := make([]VerifyV2Bucket, 0) for record := range response { @@ -195,6 +215,11 @@ func (c *ApiService) ListBucket(ServiceSid string, RateLimitSid string, params * // Streams Bucket records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamBucket(ServiceSid string, RateLimitSid string, params *ListBucketParams) (chan VerifyV2Bucket, chan error) { + return c.StreamBucketWithContext(context.TODO(), ServiceSid, RateLimitSid, params) +} + +// Streams Bucket records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamBucketWithContext(ctx context.Context, ServiceSid string, RateLimitSid string, params *ListBucketParams) (chan VerifyV2Bucket, chan error) { if params == nil { params = &ListBucketParams{} } @@ -203,19 +228,19 @@ func (c *ApiService) StreamBucket(ServiceSid string, RateLimitSid string, params recordChannel := make(chan VerifyV2Bucket, 1) errorChannel := make(chan error, 1) - response, err := c.PageBucket(ServiceSid, RateLimitSid, params, "", "") + response, err := c.PageBucketWithContext(ctx, ServiceSid, RateLimitSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamBucket(response, params, recordChannel, errorChannel) + go c.streamBucketWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamBucket(response *ListBucketResponse, params *ListBucketParams, recordChannel chan VerifyV2Bucket, errorChannel chan error) { +func (c *ApiService) streamBucketWithContext(ctx context.Context, response *ListBucketResponse, params *ListBucketParams, recordChannel chan VerifyV2Bucket, errorChannel chan error) { curRecord := 1 for response != nil { @@ -230,7 +255,7 @@ func (c *ApiService) streamBucket(response *ListBucketResponse, params *ListBuck } } - record, err := client.GetNext(c.baseURL, response, c.getNextListBucketResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListBucketResponseWithContext) if err != nil { errorChannel <- err break @@ -245,11 +270,11 @@ func (c *ApiService) streamBucket(response *ListBucketResponse, params *ListBuck close(errorChannel) } -func (c *ApiService) getNextListBucketResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListBucketResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -282,6 +307,9 @@ func (params *UpdateBucketParams) SetInterval(Interval int) *UpdateBucketParams // Update a specific Bucket. func (c *ApiService) UpdateBucket(ServiceSid string, RateLimitSid string, Sid string, params *UpdateBucketParams) (*VerifyV2Bucket, error) { + return c.UpdateBucketWithContext(context.TODO(), ServiceSid, RateLimitSid, Sid, params) +} +func (c *ApiService) UpdateBucketWithContext(ctx context.Context, ServiceSid string, RateLimitSid string, Sid string, params *UpdateBucketParams) (*VerifyV2Bucket, error) { path := "/v2/Services/{ServiceSid}/RateLimits/{RateLimitSid}/Buckets/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"RateLimitSid"+"}", RateLimitSid, -1) @@ -299,7 +327,7 @@ func (c *ApiService) UpdateBucket(ServiceSid string, RateLimitSid string, Sid st data.Set("Interval", fmt.Sprint(*params.Interval)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/verify/v2/services_verification_check.go b/rest/verify/v2/services_verification_check.go index 6549cc554..3ca5b7e56 100644 --- a/rest/verify/v2/services_verification_check.go +++ b/rest/verify/v2/services_verification_check.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -63,6 +64,9 @@ func (params *CreateVerificationCheckParams) SetSnaClientToken(SnaClientToken st // challenge a specific Verification Check. func (c *ApiService) CreateVerificationCheck(ServiceSid string, params *CreateVerificationCheckParams) (*VerifyV2VerificationCheck, error) { + return c.CreateVerificationCheckWithContext(context.TODO(), ServiceSid, params) +} +func (c *ApiService) CreateVerificationCheckWithContext(ctx context.Context, ServiceSid string, params *CreateVerificationCheckParams) (*VerifyV2VerificationCheck, error) { path := "/v2/Services/{ServiceSid}/VerificationCheck" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -90,7 +94,7 @@ func (c *ApiService) CreateVerificationCheck(ServiceSid string, params *CreateVe data.Set("SnaClientToken", *params.SnaClientToken) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/verify/v2/services_verifications.go b/rest/verify/v2/services_verifications.go index 3984f819f..d8050d879 100644 --- a/rest/verify/v2/services_verifications.go +++ b/rest/verify/v2/services_verifications.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -136,6 +137,9 @@ func (params *CreateVerificationParams) SetTags(Tags string) *CreateVerification // Create a new Verification using a Service func (c *ApiService) CreateVerification(ServiceSid string, params *CreateVerificationParams) (*VerifyV2Verification, error) { + return c.CreateVerificationWithContext(context.TODO(), ServiceSid, params) +} +func (c *ApiService) CreateVerificationWithContext(ctx context.Context, ServiceSid string, params *CreateVerificationParams) (*VerifyV2Verification, error) { path := "/v2/Services/{ServiceSid}/Verifications" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -211,7 +215,7 @@ func (c *ApiService) CreateVerification(ServiceSid string, params *CreateVerific data.Set("Tags", *params.Tags) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -228,6 +232,9 @@ func (c *ApiService) CreateVerification(ServiceSid string, params *CreateVerific // Fetch a specific Verification func (c *ApiService) FetchVerification(ServiceSid string, Sid string) (*VerifyV2Verification, error) { + return c.FetchVerificationWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) FetchVerificationWithContext(ctx context.Context, ServiceSid string, Sid string) (*VerifyV2Verification, error) { path := "/v2/Services/{ServiceSid}/Verifications/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -237,7 +244,7 @@ func (c *ApiService) FetchVerification(ServiceSid string, Sid string) (*VerifyV2 "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -265,6 +272,9 @@ func (params *UpdateVerificationParams) SetStatus(Status string) *UpdateVerifica // Update a Verification status func (c *ApiService) UpdateVerification(ServiceSid string, Sid string, params *UpdateVerificationParams) (*VerifyV2Verification, error) { + return c.UpdateVerificationWithContext(context.TODO(), ServiceSid, Sid, params) +} +func (c *ApiService) UpdateVerificationWithContext(ctx context.Context, ServiceSid string, Sid string, params *UpdateVerificationParams) (*VerifyV2Verification, error) { path := "/v2/Services/{ServiceSid}/Verifications/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -278,7 +288,7 @@ func (c *ApiService) UpdateVerification(ServiceSid string, Sid string, params *U data.Set("Status", fmt.Sprint(*params.Status)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/verify/v2/services_webhooks.go b/rest/verify/v2/services_webhooks.go index 5b0d0f274..8c3226ef2 100644 --- a/rest/verify/v2/services_webhooks.go +++ b/rest/verify/v2/services_webhooks.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -60,6 +61,9 @@ func (params *CreateWebhookParams) SetVersion(Version string) *CreateWebhookPara // Create a new Webhook for the Service func (c *ApiService) CreateWebhook(ServiceSid string, params *CreateWebhookParams) (*VerifyV2Webhook, error) { + return c.CreateWebhookWithContext(context.TODO(), ServiceSid, params) +} +func (c *ApiService) CreateWebhookWithContext(ctx context.Context, ServiceSid string, params *CreateWebhookParams) (*VerifyV2Webhook, error) { path := "/v2/Services/{ServiceSid}/Webhooks" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -86,7 +90,7 @@ func (c *ApiService) CreateWebhook(ServiceSid string, params *CreateWebhookParam data.Set("Version", fmt.Sprint(*params.Version)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -103,6 +107,9 @@ func (c *ApiService) CreateWebhook(ServiceSid string, params *CreateWebhookParam // Delete a specific Webhook. func (c *ApiService) DeleteWebhook(ServiceSid string, Sid string) error { + return c.DeleteWebhookWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) DeleteWebhookWithContext(ctx context.Context, ServiceSid string, Sid string) error { path := "/v2/Services/{ServiceSid}/Webhooks/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -112,7 +119,7 @@ func (c *ApiService) DeleteWebhook(ServiceSid string, Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -124,6 +131,9 @@ func (c *ApiService) DeleteWebhook(ServiceSid string, Sid string) error { // Fetch a specific Webhook. func (c *ApiService) FetchWebhook(ServiceSid string, Sid string) (*VerifyV2Webhook, error) { + return c.FetchWebhookWithContext(context.TODO(), ServiceSid, Sid) +} +func (c *ApiService) FetchWebhookWithContext(ctx context.Context, ServiceSid string, Sid string) (*VerifyV2Webhook, error) { path := "/v2/Services/{ServiceSid}/Webhooks/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -133,7 +143,7 @@ func (c *ApiService) FetchWebhook(ServiceSid string, Sid string) (*VerifyV2Webho "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -167,6 +177,11 @@ func (params *ListWebhookParams) SetLimit(Limit int) *ListWebhookParams { // Retrieve a single page of Webhook records from the API. Request is executed immediately. func (c *ApiService) PageWebhook(ServiceSid string, params *ListWebhookParams, pageToken, pageNumber string) (*ListWebhookResponse, error) { + return c.PageWebhookWithContext(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Webhook records from the API. Request is executed immediately. +func (c *ApiService) PageWebhookWithContext(ctx context.Context, ServiceSid string, params *ListWebhookParams, pageToken, pageNumber string) (*ListWebhookResponse, error) { path := "/v2/Services/{ServiceSid}/Webhooks" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -187,7 +202,7 @@ func (c *ApiService) PageWebhook(ServiceSid string, params *ListWebhookParams, p data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -204,7 +219,12 @@ func (c *ApiService) PageWebhook(ServiceSid string, params *ListWebhookParams, p // Lists Webhook records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListWebhook(ServiceSid string, params *ListWebhookParams) ([]VerifyV2Webhook, error) { - response, errors := c.StreamWebhook(ServiceSid, params) + return c.ListWebhookWithContext(context.TODO(), ServiceSid, params) +} + +// Lists Webhook records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListWebhookWithContext(ctx context.Context, ServiceSid string, params *ListWebhookParams) ([]VerifyV2Webhook, error) { + response, errors := c.StreamWebhookWithContext(ctx, ServiceSid, params) records := make([]VerifyV2Webhook, 0) for record := range response { @@ -220,6 +240,11 @@ func (c *ApiService) ListWebhook(ServiceSid string, params *ListWebhookParams) ( // Streams Webhook records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamWebhook(ServiceSid string, params *ListWebhookParams) (chan VerifyV2Webhook, chan error) { + return c.StreamWebhookWithContext(context.TODO(), ServiceSid, params) +} + +// Streams Webhook records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamWebhookWithContext(ctx context.Context, ServiceSid string, params *ListWebhookParams) (chan VerifyV2Webhook, chan error) { if params == nil { params = &ListWebhookParams{} } @@ -228,19 +253,19 @@ func (c *ApiService) StreamWebhook(ServiceSid string, params *ListWebhookParams) recordChannel := make(chan VerifyV2Webhook, 1) errorChannel := make(chan error, 1) - response, err := c.PageWebhook(ServiceSid, params, "", "") + response, err := c.PageWebhookWithContext(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamWebhook(response, params, recordChannel, errorChannel) + go c.streamWebhookWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamWebhook(response *ListWebhookResponse, params *ListWebhookParams, recordChannel chan VerifyV2Webhook, errorChannel chan error) { +func (c *ApiService) streamWebhookWithContext(ctx context.Context, response *ListWebhookResponse, params *ListWebhookParams, recordChannel chan VerifyV2Webhook, errorChannel chan error) { curRecord := 1 for response != nil { @@ -255,7 +280,7 @@ func (c *ApiService) streamWebhook(response *ListWebhookResponse, params *ListWe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListWebhookResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListWebhookResponseWithContext) if err != nil { errorChannel <- err break @@ -270,11 +295,11 @@ func (c *ApiService) streamWebhook(response *ListWebhookResponse, params *ListWe close(errorChannel) } -func (c *ApiService) getNextListWebhookResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListWebhookResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -323,8 +348,10 @@ func (params *UpdateWebhookParams) SetVersion(Version string) *UpdateWebhookPara return params } -// func (c *ApiService) UpdateWebhook(ServiceSid string, Sid string, params *UpdateWebhookParams) (*VerifyV2Webhook, error) { + return c.UpdateWebhookWithContext(context.TODO(), ServiceSid, Sid, params) +} +func (c *ApiService) UpdateWebhookWithContext(ctx context.Context, ServiceSid string, Sid string, params *UpdateWebhookParams) (*VerifyV2Webhook, error) { path := "/v2/Services/{ServiceSid}/Webhooks/{Sid}" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -352,7 +379,7 @@ func (c *ApiService) UpdateWebhook(ServiceSid string, Sid string, params *Update data.Set("Version", fmt.Sprint(*params.Version)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/verify/v2/templates.go b/rest/verify/v2/templates.go index ac664378d..56d2d94c1 100644 --- a/rest/verify/v2/templates.go +++ b/rest/verify/v2/templates.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -47,6 +48,11 @@ func (params *ListVerificationTemplateParams) SetLimit(Limit int) *ListVerificat // Retrieve a single page of VerificationTemplate records from the API. Request is executed immediately. func (c *ApiService) PageVerificationTemplate(params *ListVerificationTemplateParams, pageToken, pageNumber string) (*ListVerificationTemplateResponse, error) { + return c.PageVerificationTemplateWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of VerificationTemplate records from the API. Request is executed immediately. +func (c *ApiService) PageVerificationTemplateWithContext(ctx context.Context, params *ListVerificationTemplateParams, pageToken, pageNumber string) (*ListVerificationTemplateResponse, error) { path := "/v2/Templates" data := url.Values{} @@ -68,7 +74,7 @@ func (c *ApiService) PageVerificationTemplate(params *ListVerificationTemplatePa data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -85,7 +91,12 @@ func (c *ApiService) PageVerificationTemplate(params *ListVerificationTemplatePa // Lists VerificationTemplate records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListVerificationTemplate(params *ListVerificationTemplateParams) ([]VerifyV2VerificationTemplate, error) { - response, errors := c.StreamVerificationTemplate(params) + return c.ListVerificationTemplateWithContext(context.TODO(), params) +} + +// Lists VerificationTemplate records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListVerificationTemplateWithContext(ctx context.Context, params *ListVerificationTemplateParams) ([]VerifyV2VerificationTemplate, error) { + response, errors := c.StreamVerificationTemplateWithContext(ctx, params) records := make([]VerifyV2VerificationTemplate, 0) for record := range response { @@ -101,6 +112,11 @@ func (c *ApiService) ListVerificationTemplate(params *ListVerificationTemplatePa // Streams VerificationTemplate records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamVerificationTemplate(params *ListVerificationTemplateParams) (chan VerifyV2VerificationTemplate, chan error) { + return c.StreamVerificationTemplateWithContext(context.TODO(), params) +} + +// Streams VerificationTemplate records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamVerificationTemplateWithContext(ctx context.Context, params *ListVerificationTemplateParams) (chan VerifyV2VerificationTemplate, chan error) { if params == nil { params = &ListVerificationTemplateParams{} } @@ -109,19 +125,19 @@ func (c *ApiService) StreamVerificationTemplate(params *ListVerificationTemplate recordChannel := make(chan VerifyV2VerificationTemplate, 1) errorChannel := make(chan error, 1) - response, err := c.PageVerificationTemplate(params, "", "") + response, err := c.PageVerificationTemplateWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamVerificationTemplate(response, params, recordChannel, errorChannel) + go c.streamVerificationTemplateWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamVerificationTemplate(response *ListVerificationTemplateResponse, params *ListVerificationTemplateParams, recordChannel chan VerifyV2VerificationTemplate, errorChannel chan error) { +func (c *ApiService) streamVerificationTemplateWithContext(ctx context.Context, response *ListVerificationTemplateResponse, params *ListVerificationTemplateParams, recordChannel chan VerifyV2VerificationTemplate, errorChannel chan error) { curRecord := 1 for response != nil { @@ -136,7 +152,7 @@ func (c *ApiService) streamVerificationTemplate(response *ListVerificationTempla } } - record, err := client.GetNext(c.baseURL, response, c.getNextListVerificationTemplateResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListVerificationTemplateResponseWithContext) if err != nil { errorChannel <- err break @@ -151,11 +167,11 @@ func (c *ApiService) streamVerificationTemplate(response *ListVerificationTempla close(errorChannel) } -func (c *ApiService) getNextListVerificationTemplateResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListVerificationTemplateResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/video/v1/api_service.go b/rest/video/v1/api_service.go index 34ed1c782..83e8663c9 100644 --- a/rest/video/v1/api_service.go +++ b/rest/video/v1/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://video.twilio.com", + } +} diff --git a/rest/video/v1/composition_hooks.go b/rest/video/v1/composition_hooks.go index 5ebdcd527..c8e89c8ec 100644 --- a/rest/video/v1/composition_hooks.go +++ b/rest/video/v1/composition_hooks.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -89,8 +90,10 @@ func (params *CreateCompositionHookParams) SetTrim(Trim bool) *CreateComposition return params } -// func (c *ApiService) CreateCompositionHook(params *CreateCompositionHookParams) (*VideoV1CompositionHook, error) { + return c.CreateCompositionHookWithContext(context.TODO(), params) +} +func (c *ApiService) CreateCompositionHookWithContext(ctx context.Context, params *CreateCompositionHookParams) (*VideoV1CompositionHook, error) { path := "/v1/CompositionHooks" data := url.Values{} @@ -139,7 +142,7 @@ func (c *ApiService) CreateCompositionHook(params *CreateCompositionHookParams) data.Set("Trim", fmt.Sprint(*params.Trim)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -156,6 +159,9 @@ func (c *ApiService) CreateCompositionHook(params *CreateCompositionHookParams) // Delete a Recording CompositionHook resource identified by a `CompositionHook SID`. func (c *ApiService) DeleteCompositionHook(Sid string) error { + return c.DeleteCompositionHookWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteCompositionHookWithContext(ctx context.Context, Sid string) error { path := "/v1/CompositionHooks/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -164,7 +170,7 @@ func (c *ApiService) DeleteCompositionHook(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -176,6 +182,9 @@ func (c *ApiService) DeleteCompositionHook(Sid string) error { // Returns a single CompositionHook resource identified by a CompositionHook SID. func (c *ApiService) FetchCompositionHook(Sid string) (*VideoV1CompositionHook, error) { + return c.FetchCompositionHookWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchCompositionHookWithContext(ctx context.Context, Sid string) (*VideoV1CompositionHook, error) { path := "/v1/CompositionHooks/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -184,7 +193,7 @@ func (c *ApiService) FetchCompositionHook(Sid string) (*VideoV1CompositionHook, "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -242,6 +251,11 @@ func (params *ListCompositionHookParams) SetLimit(Limit int) *ListCompositionHoo // Retrieve a single page of CompositionHook records from the API. Request is executed immediately. func (c *ApiService) PageCompositionHook(params *ListCompositionHookParams, pageToken, pageNumber string) (*ListCompositionHookResponse, error) { + return c.PageCompositionHookWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of CompositionHook records from the API. Request is executed immediately. +func (c *ApiService) PageCompositionHookWithContext(ctx context.Context, params *ListCompositionHookParams, pageToken, pageNumber string) (*ListCompositionHookResponse, error) { path := "/v1/CompositionHooks" data := url.Values{} @@ -272,7 +286,7 @@ func (c *ApiService) PageCompositionHook(params *ListCompositionHookParams, page data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -289,7 +303,12 @@ func (c *ApiService) PageCompositionHook(params *ListCompositionHookParams, page // Lists CompositionHook records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListCompositionHook(params *ListCompositionHookParams) ([]VideoV1CompositionHook, error) { - response, errors := c.StreamCompositionHook(params) + return c.ListCompositionHookWithContext(context.TODO(), params) +} + +// Lists CompositionHook records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListCompositionHookWithContext(ctx context.Context, params *ListCompositionHookParams) ([]VideoV1CompositionHook, error) { + response, errors := c.StreamCompositionHookWithContext(ctx, params) records := make([]VideoV1CompositionHook, 0) for record := range response { @@ -305,6 +324,11 @@ func (c *ApiService) ListCompositionHook(params *ListCompositionHookParams) ([]V // Streams CompositionHook records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamCompositionHook(params *ListCompositionHookParams) (chan VideoV1CompositionHook, chan error) { + return c.StreamCompositionHookWithContext(context.TODO(), params) +} + +// Streams CompositionHook records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamCompositionHookWithContext(ctx context.Context, params *ListCompositionHookParams) (chan VideoV1CompositionHook, chan error) { if params == nil { params = &ListCompositionHookParams{} } @@ -313,19 +337,19 @@ func (c *ApiService) StreamCompositionHook(params *ListCompositionHookParams) (c recordChannel := make(chan VideoV1CompositionHook, 1) errorChannel := make(chan error, 1) - response, err := c.PageCompositionHook(params, "", "") + response, err := c.PageCompositionHookWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamCompositionHook(response, params, recordChannel, errorChannel) + go c.streamCompositionHookWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamCompositionHook(response *ListCompositionHookResponse, params *ListCompositionHookParams, recordChannel chan VideoV1CompositionHook, errorChannel chan error) { +func (c *ApiService) streamCompositionHookWithContext(ctx context.Context, response *ListCompositionHookResponse, params *ListCompositionHookParams, recordChannel chan VideoV1CompositionHook, errorChannel chan error) { curRecord := 1 for response != nil { @@ -340,7 +364,7 @@ func (c *ApiService) streamCompositionHook(response *ListCompositionHookResponse } } - record, err := client.GetNext(c.baseURL, response, c.getNextListCompositionHookResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListCompositionHookResponseWithContext) if err != nil { errorChannel <- err break @@ -355,11 +379,11 @@ func (c *ApiService) streamCompositionHook(response *ListCompositionHookResponse close(errorChannel) } -func (c *ApiService) getNextListCompositionHookResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListCompositionHookResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -438,8 +462,10 @@ func (params *UpdateCompositionHookParams) SetStatusCallbackMethod(StatusCallbac return params } -// func (c *ApiService) UpdateCompositionHook(Sid string, params *UpdateCompositionHookParams) (*VideoV1CompositionHook, error) { + return c.UpdateCompositionHookWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateCompositionHookWithContext(ctx context.Context, Sid string, params *UpdateCompositionHookParams) (*VideoV1CompositionHook, error) { path := "/v1/CompositionHooks/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -489,7 +515,7 @@ func (c *ApiService) UpdateCompositionHook(Sid string, params *UpdateComposition data.Set("StatusCallbackMethod", *params.StatusCallbackMethod) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/video/v1/composition_settings_default.go b/rest/video/v1/composition_settings_default.go index 11e12253e..70f252ae3 100644 --- a/rest/video/v1/composition_settings_default.go +++ b/rest/video/v1/composition_settings_default.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -61,8 +62,10 @@ func (params *CreateCompositionSettingsParams) SetEncryptionEnabled(EncryptionEn return params } -// func (c *ApiService) CreateCompositionSettings(params *CreateCompositionSettingsParams) (*VideoV1CompositionSettings, error) { + return c.CreateCompositionSettingsWithContext(context.TODO(), params) +} +func (c *ApiService) CreateCompositionSettingsWithContext(ctx context.Context, params *CreateCompositionSettingsParams) (*VideoV1CompositionSettings, error) { path := "/v1/CompositionSettings/Default" data := url.Values{} @@ -89,7 +92,7 @@ func (c *ApiService) CreateCompositionSettings(params *CreateCompositionSettings data.Set("EncryptionEnabled", fmt.Sprint(*params.EncryptionEnabled)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -104,8 +107,10 @@ func (c *ApiService) CreateCompositionSettings(params *CreateCompositionSettings return ps, err } -// func (c *ApiService) FetchCompositionSettings() (*VideoV1CompositionSettings, error) { + return c.FetchCompositionSettingsWithContext(context.TODO()) +} +func (c *ApiService) FetchCompositionSettingsWithContext(ctx context.Context) (*VideoV1CompositionSettings, error) { path := "/v1/CompositionSettings/Default" data := url.Values{} @@ -113,7 +118,7 @@ func (c *ApiService) FetchCompositionSettings() (*VideoV1CompositionSettings, er "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/video/v1/compositions.go b/rest/video/v1/compositions.go index 6891d3468..641eeddd7 100644 --- a/rest/video/v1/compositions.go +++ b/rest/video/v1/compositions.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -83,8 +84,10 @@ func (params *CreateCompositionParams) SetTrim(Trim bool) *CreateCompositionPara return params } -// func (c *ApiService) CreateComposition(params *CreateCompositionParams) (*VideoV1Composition, error) { + return c.CreateCompositionWithContext(context.TODO(), params) +} +func (c *ApiService) CreateCompositionWithContext(ctx context.Context, params *CreateCompositionParams) (*VideoV1Composition, error) { path := "/v1/Compositions" data := url.Values{} @@ -130,7 +133,7 @@ func (c *ApiService) CreateComposition(params *CreateCompositionParams) (*VideoV data.Set("Trim", fmt.Sprint(*params.Trim)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -147,6 +150,9 @@ func (c *ApiService) CreateComposition(params *CreateCompositionParams) (*VideoV // Delete a Recording Composition resource identified by a Composition SID. func (c *ApiService) DeleteComposition(Sid string) error { + return c.DeleteCompositionWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteCompositionWithContext(ctx context.Context, Sid string) error { path := "/v1/Compositions/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -155,7 +161,7 @@ func (c *ApiService) DeleteComposition(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -167,6 +173,9 @@ func (c *ApiService) DeleteComposition(Sid string) error { // Returns a single Composition resource identified by a Composition SID. func (c *ApiService) FetchComposition(Sid string) (*VideoV1Composition, error) { + return c.FetchCompositionWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchCompositionWithContext(ctx context.Context, Sid string) (*VideoV1Composition, error) { path := "/v1/Compositions/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -175,7 +184,7 @@ func (c *ApiService) FetchComposition(Sid string) (*VideoV1Composition, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -233,6 +242,11 @@ func (params *ListCompositionParams) SetLimit(Limit int) *ListCompositionParams // Retrieve a single page of Composition records from the API. Request is executed immediately. func (c *ApiService) PageComposition(params *ListCompositionParams, pageToken, pageNumber string) (*ListCompositionResponse, error) { + return c.PageCompositionWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Composition records from the API. Request is executed immediately. +func (c *ApiService) PageCompositionWithContext(ctx context.Context, params *ListCompositionParams, pageToken, pageNumber string) (*ListCompositionResponse, error) { path := "/v1/Compositions" data := url.Values{} @@ -263,7 +277,7 @@ func (c *ApiService) PageComposition(params *ListCompositionParams, pageToken, p data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -280,7 +294,12 @@ func (c *ApiService) PageComposition(params *ListCompositionParams, pageToken, p // Lists Composition records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListComposition(params *ListCompositionParams) ([]VideoV1Composition, error) { - response, errors := c.StreamComposition(params) + return c.ListCompositionWithContext(context.TODO(), params) +} + +// Lists Composition records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListCompositionWithContext(ctx context.Context, params *ListCompositionParams) ([]VideoV1Composition, error) { + response, errors := c.StreamCompositionWithContext(ctx, params) records := make([]VideoV1Composition, 0) for record := range response { @@ -296,6 +315,11 @@ func (c *ApiService) ListComposition(params *ListCompositionParams) ([]VideoV1Co // Streams Composition records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamComposition(params *ListCompositionParams) (chan VideoV1Composition, chan error) { + return c.StreamCompositionWithContext(context.TODO(), params) +} + +// Streams Composition records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamCompositionWithContext(ctx context.Context, params *ListCompositionParams) (chan VideoV1Composition, chan error) { if params == nil { params = &ListCompositionParams{} } @@ -304,19 +328,19 @@ func (c *ApiService) StreamComposition(params *ListCompositionParams) (chan Vide recordChannel := make(chan VideoV1Composition, 1) errorChannel := make(chan error, 1) - response, err := c.PageComposition(params, "", "") + response, err := c.PageCompositionWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamComposition(response, params, recordChannel, errorChannel) + go c.streamCompositionWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamComposition(response *ListCompositionResponse, params *ListCompositionParams, recordChannel chan VideoV1Composition, errorChannel chan error) { +func (c *ApiService) streamCompositionWithContext(ctx context.Context, response *ListCompositionResponse, params *ListCompositionParams, recordChannel chan VideoV1Composition, errorChannel chan error) { curRecord := 1 for response != nil { @@ -331,7 +355,7 @@ func (c *ApiService) streamComposition(response *ListCompositionResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListCompositionResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListCompositionResponseWithContext) if err != nil { errorChannel <- err break @@ -346,11 +370,11 @@ func (c *ApiService) streamComposition(response *ListCompositionResponse, params close(errorChannel) } -func (c *ApiService) getNextListCompositionResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListCompositionResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/video/v1/recording_settings_default.go b/rest/video/v1/recording_settings_default.go index 6c590d55f..3aa36e1c4 100644 --- a/rest/video/v1/recording_settings_default.go +++ b/rest/video/v1/recording_settings_default.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -61,8 +62,10 @@ func (params *CreateRecordingSettingsParams) SetEncryptionEnabled(EncryptionEnab return params } -// func (c *ApiService) CreateRecordingSettings(params *CreateRecordingSettingsParams) (*VideoV1RecordingSettings, error) { + return c.CreateRecordingSettingsWithContext(context.TODO(), params) +} +func (c *ApiService) CreateRecordingSettingsWithContext(ctx context.Context, params *CreateRecordingSettingsParams) (*VideoV1RecordingSettings, error) { path := "/v1/RecordingSettings/Default" data := url.Values{} @@ -89,7 +92,7 @@ func (c *ApiService) CreateRecordingSettings(params *CreateRecordingSettingsPara data.Set("EncryptionEnabled", fmt.Sprint(*params.EncryptionEnabled)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -104,8 +107,10 @@ func (c *ApiService) CreateRecordingSettings(params *CreateRecordingSettingsPara return ps, err } -// func (c *ApiService) FetchRecordingSettings() (*VideoV1RecordingSettings, error) { + return c.FetchRecordingSettingsWithContext(context.TODO()) +} +func (c *ApiService) FetchRecordingSettingsWithContext(ctx context.Context) (*VideoV1RecordingSettings, error) { path := "/v1/RecordingSettings/Default" data := url.Values{} @@ -113,7 +118,7 @@ func (c *ApiService) FetchRecordingSettings() (*VideoV1RecordingSettings, error) "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/video/v1/recordings.go b/rest/video/v1/recordings.go index d5f4425c1..083e54985 100644 --- a/rest/video/v1/recordings.go +++ b/rest/video/v1/recordings.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -26,6 +27,9 @@ import ( // Delete a Recording resource identified by a Recording SID. func (c *ApiService) DeleteRecording(Sid string) error { + return c.DeleteRecordingWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteRecordingWithContext(ctx context.Context, Sid string) error { path := "/v1/Recordings/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -34,7 +38,7 @@ func (c *ApiService) DeleteRecording(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -46,6 +50,9 @@ func (c *ApiService) DeleteRecording(Sid string) error { // Returns a single Recording resource identified by a Recording SID. func (c *ApiService) FetchRecording(Sid string) (*VideoV1Recording, error) { + return c.FetchRecordingWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchRecordingWithContext(ctx context.Context, Sid string) (*VideoV1Recording, error) { path := "/v1/Recordings/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -54,7 +61,7 @@ func (c *ApiService) FetchRecording(Sid string) (*VideoV1Recording, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -124,6 +131,11 @@ func (params *ListRecordingParams) SetLimit(Limit int) *ListRecordingParams { // Retrieve a single page of Recording records from the API. Request is executed immediately. func (c *ApiService) PageRecording(params *ListRecordingParams, pageToken, pageNumber string) (*ListRecordingResponse, error) { + return c.PageRecordingWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Recording records from the API. Request is executed immediately. +func (c *ApiService) PageRecordingWithContext(ctx context.Context, params *ListRecordingParams, pageToken, pageNumber string) (*ListRecordingResponse, error) { path := "/v1/Recordings" data := url.Values{} @@ -162,7 +174,7 @@ func (c *ApiService) PageRecording(params *ListRecordingParams, pageToken, pageN data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -179,7 +191,12 @@ func (c *ApiService) PageRecording(params *ListRecordingParams, pageToken, pageN // Lists Recording records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListRecording(params *ListRecordingParams) ([]VideoV1Recording, error) { - response, errors := c.StreamRecording(params) + return c.ListRecordingWithContext(context.TODO(), params) +} + +// Lists Recording records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListRecordingWithContext(ctx context.Context, params *ListRecordingParams) ([]VideoV1Recording, error) { + response, errors := c.StreamRecordingWithContext(ctx, params) records := make([]VideoV1Recording, 0) for record := range response { @@ -195,6 +212,11 @@ func (c *ApiService) ListRecording(params *ListRecordingParams) ([]VideoV1Record // Streams Recording records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamRecording(params *ListRecordingParams) (chan VideoV1Recording, chan error) { + return c.StreamRecordingWithContext(context.TODO(), params) +} + +// Streams Recording records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamRecordingWithContext(ctx context.Context, params *ListRecordingParams) (chan VideoV1Recording, chan error) { if params == nil { params = &ListRecordingParams{} } @@ -203,19 +225,19 @@ func (c *ApiService) StreamRecording(params *ListRecordingParams) (chan VideoV1R recordChannel := make(chan VideoV1Recording, 1) errorChannel := make(chan error, 1) - response, err := c.PageRecording(params, "", "") + response, err := c.PageRecordingWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamRecording(response, params, recordChannel, errorChannel) + go c.streamRecordingWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamRecording(response *ListRecordingResponse, params *ListRecordingParams, recordChannel chan VideoV1Recording, errorChannel chan error) { +func (c *ApiService) streamRecordingWithContext(ctx context.Context, response *ListRecordingResponse, params *ListRecordingParams, recordChannel chan VideoV1Recording, errorChannel chan error) { curRecord := 1 for response != nil { @@ -230,7 +252,7 @@ func (c *ApiService) streamRecording(response *ListRecordingResponse, params *Li } } - record, err := client.GetNext(c.baseURL, response, c.getNextListRecordingResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListRecordingResponseWithContext) if err != nil { errorChannel <- err break @@ -245,11 +267,11 @@ func (c *ApiService) streamRecording(response *ListRecordingResponse, params *Li close(errorChannel) } -func (c *ApiService) getNextListRecordingResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListRecordingResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/video/v1/rooms.go b/rest/video/v1/rooms.go index 7537cfa7b..74995a9c0 100644 --- a/rest/video/v1/rooms.go +++ b/rest/video/v1/rooms.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -131,8 +132,10 @@ func (params *CreateRoomParams) SetLargeRoom(LargeRoom bool) *CreateRoomParams { return params } -// func (c *ApiService) CreateRoom(params *CreateRoomParams) (*VideoV1Room, error) { + return c.CreateRoomWithContext(context.TODO(), params) +} +func (c *ApiService) CreateRoomWithContext(ctx context.Context, params *CreateRoomParams) (*VideoV1Room, error) { path := "/v1/Rooms" data := url.Values{} @@ -206,7 +209,7 @@ func (c *ApiService) CreateRoom(params *CreateRoomParams) (*VideoV1Room, error) data.Set("LargeRoom", fmt.Sprint(*params.LargeRoom)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -221,8 +224,10 @@ func (c *ApiService) CreateRoom(params *CreateRoomParams) (*VideoV1Room, error) return ps, err } -// func (c *ApiService) FetchRoom(Sid string) (*VideoV1Room, error) { + return c.FetchRoomWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchRoomWithContext(ctx context.Context, Sid string) (*VideoV1Room, error) { path := "/v1/Rooms/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -231,7 +236,7 @@ func (c *ApiService) FetchRoom(Sid string) (*VideoV1Room, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -289,6 +294,11 @@ func (params *ListRoomParams) SetLimit(Limit int) *ListRoomParams { // Retrieve a single page of Room records from the API. Request is executed immediately. func (c *ApiService) PageRoom(params *ListRoomParams, pageToken, pageNumber string) (*ListRoomResponse, error) { + return c.PageRoomWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Room records from the API. Request is executed immediately. +func (c *ApiService) PageRoomWithContext(ctx context.Context, params *ListRoomParams, pageToken, pageNumber string) (*ListRoomResponse, error) { path := "/v1/Rooms" data := url.Values{} @@ -319,7 +329,7 @@ func (c *ApiService) PageRoom(params *ListRoomParams, pageToken, pageNumber stri data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -336,7 +346,12 @@ func (c *ApiService) PageRoom(params *ListRoomParams, pageToken, pageNumber stri // Lists Room records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListRoom(params *ListRoomParams) ([]VideoV1Room, error) { - response, errors := c.StreamRoom(params) + return c.ListRoomWithContext(context.TODO(), params) +} + +// Lists Room records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListRoomWithContext(ctx context.Context, params *ListRoomParams) ([]VideoV1Room, error) { + response, errors := c.StreamRoomWithContext(ctx, params) records := make([]VideoV1Room, 0) for record := range response { @@ -352,6 +367,11 @@ func (c *ApiService) ListRoom(params *ListRoomParams) ([]VideoV1Room, error) { // Streams Room records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamRoom(params *ListRoomParams) (chan VideoV1Room, chan error) { + return c.StreamRoomWithContext(context.TODO(), params) +} + +// Streams Room records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamRoomWithContext(ctx context.Context, params *ListRoomParams) (chan VideoV1Room, chan error) { if params == nil { params = &ListRoomParams{} } @@ -360,19 +380,19 @@ func (c *ApiService) StreamRoom(params *ListRoomParams) (chan VideoV1Room, chan recordChannel := make(chan VideoV1Room, 1) errorChannel := make(chan error, 1) - response, err := c.PageRoom(params, "", "") + response, err := c.PageRoomWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamRoom(response, params, recordChannel, errorChannel) + go c.streamRoomWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamRoom(response *ListRoomResponse, params *ListRoomParams, recordChannel chan VideoV1Room, errorChannel chan error) { +func (c *ApiService) streamRoomWithContext(ctx context.Context, response *ListRoomResponse, params *ListRoomParams, recordChannel chan VideoV1Room, errorChannel chan error) { curRecord := 1 for response != nil { @@ -387,7 +407,7 @@ func (c *ApiService) streamRoom(response *ListRoomResponse, params *ListRoomPara } } - record, err := client.GetNext(c.baseURL, response, c.getNextListRoomResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListRoomResponseWithContext) if err != nil { errorChannel <- err break @@ -402,11 +422,11 @@ func (c *ApiService) streamRoom(response *ListRoomResponse, params *ListRoomPara close(errorChannel) } -func (c *ApiService) getNextListRoomResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListRoomResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -431,8 +451,10 @@ func (params *UpdateRoomParams) SetStatus(Status string) *UpdateRoomParams { return params } -// func (c *ApiService) UpdateRoom(Sid string, params *UpdateRoomParams) (*VideoV1Room, error) { + return c.UpdateRoomWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateRoomWithContext(ctx context.Context, Sid string, params *UpdateRoomParams) (*VideoV1Room, error) { path := "/v1/Rooms/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -445,7 +467,7 @@ func (c *ApiService) UpdateRoom(Sid string, params *UpdateRoomParams) (*VideoV1R data.Set("Status", fmt.Sprint(*params.Status)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/video/v1/rooms_participants.go b/rest/video/v1/rooms_participants.go index f0dc02f27..3fc27fa35 100644 --- a/rest/video/v1/rooms_participants.go +++ b/rest/video/v1/rooms_participants.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -24,8 +25,10 @@ import ( "github.com/twilio/twilio-go/client" ) -// func (c *ApiService) FetchRoomParticipant(RoomSid string, Sid string) (*VideoV1RoomParticipant, error) { + return c.FetchRoomParticipantWithContext(context.TODO(), RoomSid, Sid) +} +func (c *ApiService) FetchRoomParticipantWithContext(ctx context.Context, RoomSid string, Sid string) (*VideoV1RoomParticipant, error) { path := "/v1/Rooms/{RoomSid}/Participants/{Sid}" path = strings.Replace(path, "{"+"RoomSid"+"}", RoomSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -35,7 +38,7 @@ func (c *ApiService) FetchRoomParticipant(RoomSid string, Sid string) (*VideoV1R "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -93,6 +96,11 @@ func (params *ListRoomParticipantParams) SetLimit(Limit int) *ListRoomParticipan // Retrieve a single page of RoomParticipant records from the API. Request is executed immediately. func (c *ApiService) PageRoomParticipant(RoomSid string, params *ListRoomParticipantParams, pageToken, pageNumber string) (*ListRoomParticipantResponse, error) { + return c.PageRoomParticipantWithContext(context.TODO(), RoomSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of RoomParticipant records from the API. Request is executed immediately. +func (c *ApiService) PageRoomParticipantWithContext(ctx context.Context, RoomSid string, params *ListRoomParticipantParams, pageToken, pageNumber string) (*ListRoomParticipantResponse, error) { path := "/v1/Rooms/{RoomSid}/Participants" path = strings.Replace(path, "{"+"RoomSid"+"}", RoomSid, -1) @@ -125,7 +133,7 @@ func (c *ApiService) PageRoomParticipant(RoomSid string, params *ListRoomPartici data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -142,7 +150,12 @@ func (c *ApiService) PageRoomParticipant(RoomSid string, params *ListRoomPartici // Lists RoomParticipant records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListRoomParticipant(RoomSid string, params *ListRoomParticipantParams) ([]VideoV1RoomParticipant, error) { - response, errors := c.StreamRoomParticipant(RoomSid, params) + return c.ListRoomParticipantWithContext(context.TODO(), RoomSid, params) +} + +// Lists RoomParticipant records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListRoomParticipantWithContext(ctx context.Context, RoomSid string, params *ListRoomParticipantParams) ([]VideoV1RoomParticipant, error) { + response, errors := c.StreamRoomParticipantWithContext(ctx, RoomSid, params) records := make([]VideoV1RoomParticipant, 0) for record := range response { @@ -158,6 +171,11 @@ func (c *ApiService) ListRoomParticipant(RoomSid string, params *ListRoomPartici // Streams RoomParticipant records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamRoomParticipant(RoomSid string, params *ListRoomParticipantParams) (chan VideoV1RoomParticipant, chan error) { + return c.StreamRoomParticipantWithContext(context.TODO(), RoomSid, params) +} + +// Streams RoomParticipant records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamRoomParticipantWithContext(ctx context.Context, RoomSid string, params *ListRoomParticipantParams) (chan VideoV1RoomParticipant, chan error) { if params == nil { params = &ListRoomParticipantParams{} } @@ -166,19 +184,19 @@ func (c *ApiService) StreamRoomParticipant(RoomSid string, params *ListRoomParti recordChannel := make(chan VideoV1RoomParticipant, 1) errorChannel := make(chan error, 1) - response, err := c.PageRoomParticipant(RoomSid, params, "", "") + response, err := c.PageRoomParticipantWithContext(ctx, RoomSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamRoomParticipant(response, params, recordChannel, errorChannel) + go c.streamRoomParticipantWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamRoomParticipant(response *ListRoomParticipantResponse, params *ListRoomParticipantParams, recordChannel chan VideoV1RoomParticipant, errorChannel chan error) { +func (c *ApiService) streamRoomParticipantWithContext(ctx context.Context, response *ListRoomParticipantResponse, params *ListRoomParticipantParams, recordChannel chan VideoV1RoomParticipant, errorChannel chan error) { curRecord := 1 for response != nil { @@ -193,7 +211,7 @@ func (c *ApiService) streamRoomParticipant(response *ListRoomParticipantResponse } } - record, err := client.GetNext(c.baseURL, response, c.getNextListRoomParticipantResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListRoomParticipantResponseWithContext) if err != nil { errorChannel <- err break @@ -208,11 +226,11 @@ func (c *ApiService) streamRoomParticipant(response *ListRoomParticipantResponse close(errorChannel) } -func (c *ApiService) getNextListRoomParticipantResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListRoomParticipantResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -237,8 +255,10 @@ func (params *UpdateRoomParticipantParams) SetStatus(Status string) *UpdateRoomP return params } -// func (c *ApiService) UpdateRoomParticipant(RoomSid string, Sid string, params *UpdateRoomParticipantParams) (*VideoV1RoomParticipant, error) { + return c.UpdateRoomParticipantWithContext(context.TODO(), RoomSid, Sid, params) +} +func (c *ApiService) UpdateRoomParticipantWithContext(ctx context.Context, RoomSid string, Sid string, params *UpdateRoomParticipantParams) (*VideoV1RoomParticipant, error) { path := "/v1/Rooms/{RoomSid}/Participants/{Sid}" path = strings.Replace(path, "{"+"RoomSid"+"}", RoomSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -252,7 +272,7 @@ func (c *ApiService) UpdateRoomParticipant(RoomSid string, Sid string, params *U data.Set("Status", fmt.Sprint(*params.Status)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/video/v1/rooms_participants_anonymize.go b/rest/video/v1/rooms_participants_anonymize.go index bee96b1c9..c21529995 100644 --- a/rest/video/v1/rooms_participants_anonymize.go +++ b/rest/video/v1/rooms_participants_anonymize.go @@ -15,13 +15,16 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" ) -// func (c *ApiService) UpdateRoomParticipantAnonymize(RoomSid string, Sid string) (*VideoV1RoomParticipantAnonymize, error) { + return c.UpdateRoomParticipantAnonymizeWithContext(context.TODO(), RoomSid, Sid) +} +func (c *ApiService) UpdateRoomParticipantAnonymizeWithContext(ctx context.Context, RoomSid string, Sid string) (*VideoV1RoomParticipantAnonymize, error) { path := "/v1/Rooms/{RoomSid}/Participants/{Sid}/Anonymize" path = strings.Replace(path, "{"+"RoomSid"+"}", RoomSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -31,7 +34,7 @@ func (c *ApiService) UpdateRoomParticipantAnonymize(RoomSid string, Sid string) "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/video/v1/rooms_participants_published_tracks.go b/rest/video/v1/rooms_participants_published_tracks.go index a0bf1f669..c130e64b9 100644 --- a/rest/video/v1/rooms_participants_published_tracks.go +++ b/rest/video/v1/rooms_participants_published_tracks.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -25,6 +26,9 @@ import ( // Returns a single Track resource represented by TrackName or SID. func (c *ApiService) FetchRoomParticipantPublishedTrack(RoomSid string, ParticipantSid string, Sid string) (*VideoV1RoomParticipantPublishedTrack, error) { + return c.FetchRoomParticipantPublishedTrackWithContext(context.TODO(), RoomSid, ParticipantSid, Sid) +} +func (c *ApiService) FetchRoomParticipantPublishedTrackWithContext(ctx context.Context, RoomSid string, ParticipantSid string, Sid string) (*VideoV1RoomParticipantPublishedTrack, error) { path := "/v1/Rooms/{RoomSid}/Participants/{ParticipantSid}/PublishedTracks/{Sid}" path = strings.Replace(path, "{"+"RoomSid"+"}", RoomSid, -1) path = strings.Replace(path, "{"+"ParticipantSid"+"}", ParticipantSid, -1) @@ -35,7 +39,7 @@ func (c *ApiService) FetchRoomParticipantPublishedTrack(RoomSid string, Particip "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -69,6 +73,11 @@ func (params *ListRoomParticipantPublishedTrackParams) SetLimit(Limit int) *List // Retrieve a single page of RoomParticipantPublishedTrack records from the API. Request is executed immediately. func (c *ApiService) PageRoomParticipantPublishedTrack(RoomSid string, ParticipantSid string, params *ListRoomParticipantPublishedTrackParams, pageToken, pageNumber string) (*ListRoomParticipantPublishedTrackResponse, error) { + return c.PageRoomParticipantPublishedTrackWithContext(context.TODO(), RoomSid, ParticipantSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of RoomParticipantPublishedTrack records from the API. Request is executed immediately. +func (c *ApiService) PageRoomParticipantPublishedTrackWithContext(ctx context.Context, RoomSid string, ParticipantSid string, params *ListRoomParticipantPublishedTrackParams, pageToken, pageNumber string) (*ListRoomParticipantPublishedTrackResponse, error) { path := "/v1/Rooms/{RoomSid}/Participants/{ParticipantSid}/PublishedTracks" path = strings.Replace(path, "{"+"RoomSid"+"}", RoomSid, -1) @@ -90,7 +99,7 @@ func (c *ApiService) PageRoomParticipantPublishedTrack(RoomSid string, Participa data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -107,7 +116,12 @@ func (c *ApiService) PageRoomParticipantPublishedTrack(RoomSid string, Participa // Lists RoomParticipantPublishedTrack records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListRoomParticipantPublishedTrack(RoomSid string, ParticipantSid string, params *ListRoomParticipantPublishedTrackParams) ([]VideoV1RoomParticipantPublishedTrack, error) { - response, errors := c.StreamRoomParticipantPublishedTrack(RoomSid, ParticipantSid, params) + return c.ListRoomParticipantPublishedTrackWithContext(context.TODO(), RoomSid, ParticipantSid, params) +} + +// Lists RoomParticipantPublishedTrack records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListRoomParticipantPublishedTrackWithContext(ctx context.Context, RoomSid string, ParticipantSid string, params *ListRoomParticipantPublishedTrackParams) ([]VideoV1RoomParticipantPublishedTrack, error) { + response, errors := c.StreamRoomParticipantPublishedTrackWithContext(ctx, RoomSid, ParticipantSid, params) records := make([]VideoV1RoomParticipantPublishedTrack, 0) for record := range response { @@ -123,6 +137,11 @@ func (c *ApiService) ListRoomParticipantPublishedTrack(RoomSid string, Participa // Streams RoomParticipantPublishedTrack records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamRoomParticipantPublishedTrack(RoomSid string, ParticipantSid string, params *ListRoomParticipantPublishedTrackParams) (chan VideoV1RoomParticipantPublishedTrack, chan error) { + return c.StreamRoomParticipantPublishedTrackWithContext(context.TODO(), RoomSid, ParticipantSid, params) +} + +// Streams RoomParticipantPublishedTrack records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamRoomParticipantPublishedTrackWithContext(ctx context.Context, RoomSid string, ParticipantSid string, params *ListRoomParticipantPublishedTrackParams) (chan VideoV1RoomParticipantPublishedTrack, chan error) { if params == nil { params = &ListRoomParticipantPublishedTrackParams{} } @@ -131,19 +150,19 @@ func (c *ApiService) StreamRoomParticipantPublishedTrack(RoomSid string, Partici recordChannel := make(chan VideoV1RoomParticipantPublishedTrack, 1) errorChannel := make(chan error, 1) - response, err := c.PageRoomParticipantPublishedTrack(RoomSid, ParticipantSid, params, "", "") + response, err := c.PageRoomParticipantPublishedTrackWithContext(ctx, RoomSid, ParticipantSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamRoomParticipantPublishedTrack(response, params, recordChannel, errorChannel) + go c.streamRoomParticipantPublishedTrackWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamRoomParticipantPublishedTrack(response *ListRoomParticipantPublishedTrackResponse, params *ListRoomParticipantPublishedTrackParams, recordChannel chan VideoV1RoomParticipantPublishedTrack, errorChannel chan error) { +func (c *ApiService) streamRoomParticipantPublishedTrackWithContext(ctx context.Context, response *ListRoomParticipantPublishedTrackResponse, params *ListRoomParticipantPublishedTrackParams, recordChannel chan VideoV1RoomParticipantPublishedTrack, errorChannel chan error) { curRecord := 1 for response != nil { @@ -158,7 +177,7 @@ func (c *ApiService) streamRoomParticipantPublishedTrack(response *ListRoomParti } } - record, err := client.GetNext(c.baseURL, response, c.getNextListRoomParticipantPublishedTrackResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListRoomParticipantPublishedTrackResponseWithContext) if err != nil { errorChannel <- err break @@ -173,11 +192,11 @@ func (c *ApiService) streamRoomParticipantPublishedTrack(response *ListRoomParti close(errorChannel) } -func (c *ApiService) getNextListRoomParticipantPublishedTrackResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListRoomParticipantPublishedTrackResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/video/v1/rooms_participants_subscribe_rules.go b/rest/video/v1/rooms_participants_subscribe_rules.go index f7ec08211..f983c8920 100644 --- a/rest/video/v1/rooms_participants_subscribe_rules.go +++ b/rest/video/v1/rooms_participants_subscribe_rules.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -22,6 +23,9 @@ import ( // Returns a list of Subscribe Rules for the Participant. func (c *ApiService) FetchRoomParticipantSubscribeRule(RoomSid string, ParticipantSid string) (*VideoV1RoomParticipantSubscribeRule, error) { + return c.FetchRoomParticipantSubscribeRuleWithContext(context.TODO(), RoomSid, ParticipantSid) +} +func (c *ApiService) FetchRoomParticipantSubscribeRuleWithContext(ctx context.Context, RoomSid string, ParticipantSid string) (*VideoV1RoomParticipantSubscribeRule, error) { path := "/v1/Rooms/{RoomSid}/Participants/{ParticipantSid}/SubscribeRules" path = strings.Replace(path, "{"+"RoomSid"+"}", RoomSid, -1) path = strings.Replace(path, "{"+"ParticipantSid"+"}", ParticipantSid, -1) @@ -31,7 +35,7 @@ func (c *ApiService) FetchRoomParticipantSubscribeRule(RoomSid string, Participa "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -59,6 +63,9 @@ func (params *UpdateRoomParticipantSubscribeRuleParams) SetRules(Rules map[strin // Update the Subscribe Rules for the Participant func (c *ApiService) UpdateRoomParticipantSubscribeRule(RoomSid string, ParticipantSid string, params *UpdateRoomParticipantSubscribeRuleParams) (*VideoV1RoomParticipantSubscribeRule, error) { + return c.UpdateRoomParticipantSubscribeRuleWithContext(context.TODO(), RoomSid, ParticipantSid, params) +} +func (c *ApiService) UpdateRoomParticipantSubscribeRuleWithContext(ctx context.Context, RoomSid string, ParticipantSid string, params *UpdateRoomParticipantSubscribeRuleParams) (*VideoV1RoomParticipantSubscribeRule, error) { path := "/v1/Rooms/{RoomSid}/Participants/{ParticipantSid}/SubscribeRules" path = strings.Replace(path, "{"+"RoomSid"+"}", RoomSid, -1) path = strings.Replace(path, "{"+"ParticipantSid"+"}", ParticipantSid, -1) @@ -78,7 +85,7 @@ func (c *ApiService) UpdateRoomParticipantSubscribeRule(RoomSid string, Particip data.Set("Rules", string(v)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/video/v1/rooms_participants_subscribed_tracks.go b/rest/video/v1/rooms_participants_subscribed_tracks.go index 5419a1f90..4e527f1a4 100644 --- a/rest/video/v1/rooms_participants_subscribed_tracks.go +++ b/rest/video/v1/rooms_participants_subscribed_tracks.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -25,6 +26,9 @@ import ( // Returns a single Track resource represented by `track_sid`. Note: This is one resource with the Video API that requires a SID, be Track Name on the subscriber side is not guaranteed to be unique. func (c *ApiService) FetchRoomParticipantSubscribedTrack(RoomSid string, ParticipantSid string, Sid string) (*VideoV1RoomParticipantSubscribedTrack, error) { + return c.FetchRoomParticipantSubscribedTrackWithContext(context.TODO(), RoomSid, ParticipantSid, Sid) +} +func (c *ApiService) FetchRoomParticipantSubscribedTrackWithContext(ctx context.Context, RoomSid string, ParticipantSid string, Sid string) (*VideoV1RoomParticipantSubscribedTrack, error) { path := "/v1/Rooms/{RoomSid}/Participants/{ParticipantSid}/SubscribedTracks/{Sid}" path = strings.Replace(path, "{"+"RoomSid"+"}", RoomSid, -1) path = strings.Replace(path, "{"+"ParticipantSid"+"}", ParticipantSid, -1) @@ -35,7 +39,7 @@ func (c *ApiService) FetchRoomParticipantSubscribedTrack(RoomSid string, Partici "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -69,6 +73,11 @@ func (params *ListRoomParticipantSubscribedTrackParams) SetLimit(Limit int) *Lis // Retrieve a single page of RoomParticipantSubscribedTrack records from the API. Request is executed immediately. func (c *ApiService) PageRoomParticipantSubscribedTrack(RoomSid string, ParticipantSid string, params *ListRoomParticipantSubscribedTrackParams, pageToken, pageNumber string) (*ListRoomParticipantSubscribedTrackResponse, error) { + return c.PageRoomParticipantSubscribedTrackWithContext(context.TODO(), RoomSid, ParticipantSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of RoomParticipantSubscribedTrack records from the API. Request is executed immediately. +func (c *ApiService) PageRoomParticipantSubscribedTrackWithContext(ctx context.Context, RoomSid string, ParticipantSid string, params *ListRoomParticipantSubscribedTrackParams, pageToken, pageNumber string) (*ListRoomParticipantSubscribedTrackResponse, error) { path := "/v1/Rooms/{RoomSid}/Participants/{ParticipantSid}/SubscribedTracks" path = strings.Replace(path, "{"+"RoomSid"+"}", RoomSid, -1) @@ -90,7 +99,7 @@ func (c *ApiService) PageRoomParticipantSubscribedTrack(RoomSid string, Particip data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -107,7 +116,12 @@ func (c *ApiService) PageRoomParticipantSubscribedTrack(RoomSid string, Particip // Lists RoomParticipantSubscribedTrack records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListRoomParticipantSubscribedTrack(RoomSid string, ParticipantSid string, params *ListRoomParticipantSubscribedTrackParams) ([]VideoV1RoomParticipantSubscribedTrack, error) { - response, errors := c.StreamRoomParticipantSubscribedTrack(RoomSid, ParticipantSid, params) + return c.ListRoomParticipantSubscribedTrackWithContext(context.TODO(), RoomSid, ParticipantSid, params) +} + +// Lists RoomParticipantSubscribedTrack records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListRoomParticipantSubscribedTrackWithContext(ctx context.Context, RoomSid string, ParticipantSid string, params *ListRoomParticipantSubscribedTrackParams) ([]VideoV1RoomParticipantSubscribedTrack, error) { + response, errors := c.StreamRoomParticipantSubscribedTrackWithContext(ctx, RoomSid, ParticipantSid, params) records := make([]VideoV1RoomParticipantSubscribedTrack, 0) for record := range response { @@ -123,6 +137,11 @@ func (c *ApiService) ListRoomParticipantSubscribedTrack(RoomSid string, Particip // Streams RoomParticipantSubscribedTrack records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamRoomParticipantSubscribedTrack(RoomSid string, ParticipantSid string, params *ListRoomParticipantSubscribedTrackParams) (chan VideoV1RoomParticipantSubscribedTrack, chan error) { + return c.StreamRoomParticipantSubscribedTrackWithContext(context.TODO(), RoomSid, ParticipantSid, params) +} + +// Streams RoomParticipantSubscribedTrack records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamRoomParticipantSubscribedTrackWithContext(ctx context.Context, RoomSid string, ParticipantSid string, params *ListRoomParticipantSubscribedTrackParams) (chan VideoV1RoomParticipantSubscribedTrack, chan error) { if params == nil { params = &ListRoomParticipantSubscribedTrackParams{} } @@ -131,19 +150,19 @@ func (c *ApiService) StreamRoomParticipantSubscribedTrack(RoomSid string, Partic recordChannel := make(chan VideoV1RoomParticipantSubscribedTrack, 1) errorChannel := make(chan error, 1) - response, err := c.PageRoomParticipantSubscribedTrack(RoomSid, ParticipantSid, params, "", "") + response, err := c.PageRoomParticipantSubscribedTrackWithContext(ctx, RoomSid, ParticipantSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamRoomParticipantSubscribedTrack(response, params, recordChannel, errorChannel) + go c.streamRoomParticipantSubscribedTrackWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamRoomParticipantSubscribedTrack(response *ListRoomParticipantSubscribedTrackResponse, params *ListRoomParticipantSubscribedTrackParams, recordChannel chan VideoV1RoomParticipantSubscribedTrack, errorChannel chan error) { +func (c *ApiService) streamRoomParticipantSubscribedTrackWithContext(ctx context.Context, response *ListRoomParticipantSubscribedTrackResponse, params *ListRoomParticipantSubscribedTrackParams, recordChannel chan VideoV1RoomParticipantSubscribedTrack, errorChannel chan error) { curRecord := 1 for response != nil { @@ -158,7 +177,7 @@ func (c *ApiService) streamRoomParticipantSubscribedTrack(response *ListRoomPart } } - record, err := client.GetNext(c.baseURL, response, c.getNextListRoomParticipantSubscribedTrackResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListRoomParticipantSubscribedTrackResponseWithContext) if err != nil { errorChannel <- err break @@ -173,11 +192,11 @@ func (c *ApiService) streamRoomParticipantSubscribedTrack(response *ListRoomPart close(errorChannel) } -func (c *ApiService) getNextListRoomParticipantSubscribedTrackResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListRoomParticipantSubscribedTrackResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/video/v1/rooms_recording_rules.go b/rest/video/v1/rooms_recording_rules.go index f3a636815..ae5728dc0 100644 --- a/rest/video/v1/rooms_recording_rules.go +++ b/rest/video/v1/rooms_recording_rules.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -22,6 +23,9 @@ import ( // Returns a list of Recording Rules for the Room. func (c *ApiService) FetchRoomRecordingRule(RoomSid string) (*VideoV1RoomRecordingRule, error) { + return c.FetchRoomRecordingRuleWithContext(context.TODO(), RoomSid) +} +func (c *ApiService) FetchRoomRecordingRuleWithContext(ctx context.Context, RoomSid string) (*VideoV1RoomRecordingRule, error) { path := "/v1/Rooms/{RoomSid}/RecordingRules" path = strings.Replace(path, "{"+"RoomSid"+"}", RoomSid, -1) @@ -30,7 +34,7 @@ func (c *ApiService) FetchRoomRecordingRule(RoomSid string) (*VideoV1RoomRecordi "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -58,6 +62,9 @@ func (params *UpdateRoomRecordingRuleParams) SetRules(Rules map[string]interface // Update the Recording Rules for the Room func (c *ApiService) UpdateRoomRecordingRule(RoomSid string, params *UpdateRoomRecordingRuleParams) (*VideoV1RoomRecordingRule, error) { + return c.UpdateRoomRecordingRuleWithContext(context.TODO(), RoomSid, params) +} +func (c *ApiService) UpdateRoomRecordingRuleWithContext(ctx context.Context, RoomSid string, params *UpdateRoomRecordingRuleParams) (*VideoV1RoomRecordingRule, error) { path := "/v1/Rooms/{RoomSid}/RecordingRules" path = strings.Replace(path, "{"+"RoomSid"+"}", RoomSid, -1) @@ -76,7 +83,7 @@ func (c *ApiService) UpdateRoomRecordingRule(RoomSid string, params *UpdateRoomR data.Set("Rules", string(v)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/video/v1/rooms_recordings.go b/rest/video/v1/rooms_recordings.go index a28cf7cba..5876d188e 100644 --- a/rest/video/v1/rooms_recordings.go +++ b/rest/video/v1/rooms_recordings.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -24,8 +25,10 @@ import ( "github.com/twilio/twilio-go/client" ) -// func (c *ApiService) DeleteRoomRecording(RoomSid string, Sid string) error { + return c.DeleteRoomRecordingWithContext(context.TODO(), RoomSid, Sid) +} +func (c *ApiService) DeleteRoomRecordingWithContext(ctx context.Context, RoomSid string, Sid string) error { path := "/v1/Rooms/{RoomSid}/Recordings/{Sid}" path = strings.Replace(path, "{"+"RoomSid"+"}", RoomSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -35,7 +38,7 @@ func (c *ApiService) DeleteRoomRecording(RoomSid string, Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -45,8 +48,10 @@ func (c *ApiService) DeleteRoomRecording(RoomSid string, Sid string) error { return nil } -// func (c *ApiService) FetchRoomRecording(RoomSid string, Sid string) (*VideoV1RoomRecording, error) { + return c.FetchRoomRecordingWithContext(context.TODO(), RoomSid, Sid) +} +func (c *ApiService) FetchRoomRecordingWithContext(ctx context.Context, RoomSid string, Sid string) (*VideoV1RoomRecording, error) { path := "/v1/Rooms/{RoomSid}/Recordings/{Sid}" path = strings.Replace(path, "{"+"RoomSid"+"}", RoomSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -56,7 +61,7 @@ func (c *ApiService) FetchRoomRecording(RoomSid string, Sid string) (*VideoV1Roo "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -114,6 +119,11 @@ func (params *ListRoomRecordingParams) SetLimit(Limit int) *ListRoomRecordingPar // Retrieve a single page of RoomRecording records from the API. Request is executed immediately. func (c *ApiService) PageRoomRecording(RoomSid string, params *ListRoomRecordingParams, pageToken, pageNumber string) (*ListRoomRecordingResponse, error) { + return c.PageRoomRecordingWithContext(context.TODO(), RoomSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of RoomRecording records from the API. Request is executed immediately. +func (c *ApiService) PageRoomRecordingWithContext(ctx context.Context, RoomSid string, params *ListRoomRecordingParams, pageToken, pageNumber string) (*ListRoomRecordingResponse, error) { path := "/v1/Rooms/{RoomSid}/Recordings" path = strings.Replace(path, "{"+"RoomSid"+"}", RoomSid, -1) @@ -146,7 +156,7 @@ func (c *ApiService) PageRoomRecording(RoomSid string, params *ListRoomRecording data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -163,7 +173,12 @@ func (c *ApiService) PageRoomRecording(RoomSid string, params *ListRoomRecording // Lists RoomRecording records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListRoomRecording(RoomSid string, params *ListRoomRecordingParams) ([]VideoV1RoomRecording, error) { - response, errors := c.StreamRoomRecording(RoomSid, params) + return c.ListRoomRecordingWithContext(context.TODO(), RoomSid, params) +} + +// Lists RoomRecording records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListRoomRecordingWithContext(ctx context.Context, RoomSid string, params *ListRoomRecordingParams) ([]VideoV1RoomRecording, error) { + response, errors := c.StreamRoomRecordingWithContext(ctx, RoomSid, params) records := make([]VideoV1RoomRecording, 0) for record := range response { @@ -179,6 +194,11 @@ func (c *ApiService) ListRoomRecording(RoomSid string, params *ListRoomRecording // Streams RoomRecording records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamRoomRecording(RoomSid string, params *ListRoomRecordingParams) (chan VideoV1RoomRecording, chan error) { + return c.StreamRoomRecordingWithContext(context.TODO(), RoomSid, params) +} + +// Streams RoomRecording records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamRoomRecordingWithContext(ctx context.Context, RoomSid string, params *ListRoomRecordingParams) (chan VideoV1RoomRecording, chan error) { if params == nil { params = &ListRoomRecordingParams{} } @@ -187,19 +207,19 @@ func (c *ApiService) StreamRoomRecording(RoomSid string, params *ListRoomRecordi recordChannel := make(chan VideoV1RoomRecording, 1) errorChannel := make(chan error, 1) - response, err := c.PageRoomRecording(RoomSid, params, "", "") + response, err := c.PageRoomRecordingWithContext(ctx, RoomSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamRoomRecording(response, params, recordChannel, errorChannel) + go c.streamRoomRecordingWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamRoomRecording(response *ListRoomRecordingResponse, params *ListRoomRecordingParams, recordChannel chan VideoV1RoomRecording, errorChannel chan error) { +func (c *ApiService) streamRoomRecordingWithContext(ctx context.Context, response *ListRoomRecordingResponse, params *ListRoomRecordingParams, recordChannel chan VideoV1RoomRecording, errorChannel chan error) { curRecord := 1 for response != nil { @@ -214,7 +234,7 @@ func (c *ApiService) streamRoomRecording(response *ListRoomRecordingResponse, pa } } - record, err := client.GetNext(c.baseURL, response, c.getNextListRoomRecordingResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListRoomRecordingResponseWithContext) if err != nil { errorChannel <- err break @@ -229,11 +249,11 @@ func (c *ApiService) streamRoomRecording(response *ListRoomRecordingResponse, pa close(errorChannel) } -func (c *ApiService) getNextListRoomRecordingResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListRoomRecordingResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/voice/v1/api_service.go b/rest/voice/v1/api_service.go index 9252a957d..518606460 100644 --- a/rest/voice/v1/api_service.go +++ b/rest/voice/v1/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://voice.twilio.com", + } +} diff --git a/rest/voice/v1/archives_calls.go b/rest/voice/v1/archives_calls.go index 10f90d0b9..0acb8336e 100644 --- a/rest/voice/v1/archives_calls.go +++ b/rest/voice/v1/archives_calls.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "fmt" "net/url" "strings" @@ -22,6 +23,9 @@ import ( // Delete an archived call record from Bulk Export. Note: this does not also delete the record from the Voice API. func (c *ApiService) DeleteArchivedCall(Date string, Sid string) error { + return c.DeleteArchivedCallWithContext(context.TODO(), Date, Sid) +} +func (c *ApiService) DeleteArchivedCallWithContext(ctx context.Context, Date string, Sid string) error { path := "/v1/Archives/{Date}/Calls/{Sid}" path = strings.Replace(path, "{"+"Date"+"}", fmt.Sprint(Date), -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -31,7 +35,7 @@ func (c *ApiService) DeleteArchivedCall(Date string, Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } diff --git a/rest/voice/v1/byoc_trunks.go b/rest/voice/v1/byoc_trunks.go index f3c72996f..283f09f8e 100644 --- a/rest/voice/v1/byoc_trunks.go +++ b/rest/voice/v1/byoc_trunks.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -88,8 +89,10 @@ func (params *CreateByocTrunkParams) SetFromDomainSid(FromDomainSid string) *Cre return params } -// func (c *ApiService) CreateByocTrunk(params *CreateByocTrunkParams) (*VoiceV1ByocTrunk, error) { + return c.CreateByocTrunkWithContext(context.TODO(), params) +} +func (c *ApiService) CreateByocTrunkWithContext(ctx context.Context, params *CreateByocTrunkParams) (*VoiceV1ByocTrunk, error) { path := "/v1/ByocTrunks" data := url.Values{} @@ -128,7 +131,7 @@ func (c *ApiService) CreateByocTrunk(params *CreateByocTrunkParams) (*VoiceV1Byo data.Set("FromDomainSid", *params.FromDomainSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -143,8 +146,10 @@ func (c *ApiService) CreateByocTrunk(params *CreateByocTrunkParams) (*VoiceV1Byo return ps, err } -// func (c *ApiService) DeleteByocTrunk(Sid string) error { + return c.DeleteByocTrunkWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteByocTrunkWithContext(ctx context.Context, Sid string) error { path := "/v1/ByocTrunks/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -153,7 +158,7 @@ func (c *ApiService) DeleteByocTrunk(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -163,8 +168,10 @@ func (c *ApiService) DeleteByocTrunk(Sid string) error { return nil } -// func (c *ApiService) FetchByocTrunk(Sid string) (*VoiceV1ByocTrunk, error) { + return c.FetchByocTrunkWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchByocTrunkWithContext(ctx context.Context, Sid string) (*VoiceV1ByocTrunk, error) { path := "/v1/ByocTrunks/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -173,7 +180,7 @@ func (c *ApiService) FetchByocTrunk(Sid string) (*VoiceV1ByocTrunk, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -207,6 +214,11 @@ func (params *ListByocTrunkParams) SetLimit(Limit int) *ListByocTrunkParams { // Retrieve a single page of ByocTrunk records from the API. Request is executed immediately. func (c *ApiService) PageByocTrunk(params *ListByocTrunkParams, pageToken, pageNumber string) (*ListByocTrunkResponse, error) { + return c.PageByocTrunkWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of ByocTrunk records from the API. Request is executed immediately. +func (c *ApiService) PageByocTrunkWithContext(ctx context.Context, params *ListByocTrunkParams, pageToken, pageNumber string) (*ListByocTrunkResponse, error) { path := "/v1/ByocTrunks" data := url.Values{} @@ -225,7 +237,7 @@ func (c *ApiService) PageByocTrunk(params *ListByocTrunkParams, pageToken, pageN data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -242,7 +254,12 @@ func (c *ApiService) PageByocTrunk(params *ListByocTrunkParams, pageToken, pageN // Lists ByocTrunk records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListByocTrunk(params *ListByocTrunkParams) ([]VoiceV1ByocTrunk, error) { - response, errors := c.StreamByocTrunk(params) + return c.ListByocTrunkWithContext(context.TODO(), params) +} + +// Lists ByocTrunk records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListByocTrunkWithContext(ctx context.Context, params *ListByocTrunkParams) ([]VoiceV1ByocTrunk, error) { + response, errors := c.StreamByocTrunkWithContext(ctx, params) records := make([]VoiceV1ByocTrunk, 0) for record := range response { @@ -258,6 +275,11 @@ func (c *ApiService) ListByocTrunk(params *ListByocTrunkParams) ([]VoiceV1ByocTr // Streams ByocTrunk records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamByocTrunk(params *ListByocTrunkParams) (chan VoiceV1ByocTrunk, chan error) { + return c.StreamByocTrunkWithContext(context.TODO(), params) +} + +// Streams ByocTrunk records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamByocTrunkWithContext(ctx context.Context, params *ListByocTrunkParams) (chan VoiceV1ByocTrunk, chan error) { if params == nil { params = &ListByocTrunkParams{} } @@ -266,19 +288,19 @@ func (c *ApiService) StreamByocTrunk(params *ListByocTrunkParams) (chan VoiceV1B recordChannel := make(chan VoiceV1ByocTrunk, 1) errorChannel := make(chan error, 1) - response, err := c.PageByocTrunk(params, "", "") + response, err := c.PageByocTrunkWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamByocTrunk(response, params, recordChannel, errorChannel) + go c.streamByocTrunkWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamByocTrunk(response *ListByocTrunkResponse, params *ListByocTrunkParams, recordChannel chan VoiceV1ByocTrunk, errorChannel chan error) { +func (c *ApiService) streamByocTrunkWithContext(ctx context.Context, response *ListByocTrunkResponse, params *ListByocTrunkParams, recordChannel chan VoiceV1ByocTrunk, errorChannel chan error) { curRecord := 1 for response != nil { @@ -293,7 +315,7 @@ func (c *ApiService) streamByocTrunk(response *ListByocTrunkResponse, params *Li } } - record, err := client.GetNext(c.baseURL, response, c.getNextListByocTrunkResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListByocTrunkResponseWithContext) if err != nil { errorChannel <- err break @@ -308,11 +330,11 @@ func (c *ApiService) streamByocTrunk(response *ListByocTrunkResponse, params *Li close(errorChannel) } -func (c *ApiService) getNextListByocTrunkResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListByocTrunkResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -391,8 +413,10 @@ func (params *UpdateByocTrunkParams) SetFromDomainSid(FromDomainSid string) *Upd return params } -// func (c *ApiService) UpdateByocTrunk(Sid string, params *UpdateByocTrunkParams) (*VoiceV1ByocTrunk, error) { + return c.UpdateByocTrunkWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateByocTrunkWithContext(ctx context.Context, Sid string, params *UpdateByocTrunkParams) (*VoiceV1ByocTrunk, error) { path := "/v1/ByocTrunks/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -432,7 +456,7 @@ func (c *ApiService) UpdateByocTrunk(Sid string, params *UpdateByocTrunkParams) data.Set("FromDomainSid", *params.FromDomainSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/voice/v1/connection_policies.go b/rest/voice/v1/connection_policies.go index 667161f4c..898179181 100644 --- a/rest/voice/v1/connection_policies.go +++ b/rest/voice/v1/connection_policies.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -34,8 +35,10 @@ func (params *CreateConnectionPolicyParams) SetFriendlyName(FriendlyName string) return params } -// func (c *ApiService) CreateConnectionPolicy(params *CreateConnectionPolicyParams) (*VoiceV1ConnectionPolicy, error) { + return c.CreateConnectionPolicyWithContext(context.TODO(), params) +} +func (c *ApiService) CreateConnectionPolicyWithContext(ctx context.Context, params *CreateConnectionPolicyParams) (*VoiceV1ConnectionPolicy, error) { path := "/v1/ConnectionPolicies" data := url.Values{} @@ -47,7 +50,7 @@ func (c *ApiService) CreateConnectionPolicy(params *CreateConnectionPolicyParams data.Set("FriendlyName", *params.FriendlyName) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -62,8 +65,10 @@ func (c *ApiService) CreateConnectionPolicy(params *CreateConnectionPolicyParams return ps, err } -// func (c *ApiService) DeleteConnectionPolicy(Sid string) error { + return c.DeleteConnectionPolicyWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteConnectionPolicyWithContext(ctx context.Context, Sid string) error { path := "/v1/ConnectionPolicies/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -72,7 +77,7 @@ func (c *ApiService) DeleteConnectionPolicy(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -82,8 +87,10 @@ func (c *ApiService) DeleteConnectionPolicy(Sid string) error { return nil } -// func (c *ApiService) FetchConnectionPolicy(Sid string) (*VoiceV1ConnectionPolicy, error) { + return c.FetchConnectionPolicyWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchConnectionPolicyWithContext(ctx context.Context, Sid string) (*VoiceV1ConnectionPolicy, error) { path := "/v1/ConnectionPolicies/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -92,7 +99,7 @@ func (c *ApiService) FetchConnectionPolicy(Sid string) (*VoiceV1ConnectionPolicy "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -126,6 +133,11 @@ func (params *ListConnectionPolicyParams) SetLimit(Limit int) *ListConnectionPol // Retrieve a single page of ConnectionPolicy records from the API. Request is executed immediately. func (c *ApiService) PageConnectionPolicy(params *ListConnectionPolicyParams, pageToken, pageNumber string) (*ListConnectionPolicyResponse, error) { + return c.PageConnectionPolicyWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of ConnectionPolicy records from the API. Request is executed immediately. +func (c *ApiService) PageConnectionPolicyWithContext(ctx context.Context, params *ListConnectionPolicyParams, pageToken, pageNumber string) (*ListConnectionPolicyResponse, error) { path := "/v1/ConnectionPolicies" data := url.Values{} @@ -144,7 +156,7 @@ func (c *ApiService) PageConnectionPolicy(params *ListConnectionPolicyParams, pa data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -161,7 +173,12 @@ func (c *ApiService) PageConnectionPolicy(params *ListConnectionPolicyParams, pa // Lists ConnectionPolicy records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListConnectionPolicy(params *ListConnectionPolicyParams) ([]VoiceV1ConnectionPolicy, error) { - response, errors := c.StreamConnectionPolicy(params) + return c.ListConnectionPolicyWithContext(context.TODO(), params) +} + +// Lists ConnectionPolicy records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListConnectionPolicyWithContext(ctx context.Context, params *ListConnectionPolicyParams) ([]VoiceV1ConnectionPolicy, error) { + response, errors := c.StreamConnectionPolicyWithContext(ctx, params) records := make([]VoiceV1ConnectionPolicy, 0) for record := range response { @@ -177,6 +194,11 @@ func (c *ApiService) ListConnectionPolicy(params *ListConnectionPolicyParams) ([ // Streams ConnectionPolicy records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamConnectionPolicy(params *ListConnectionPolicyParams) (chan VoiceV1ConnectionPolicy, chan error) { + return c.StreamConnectionPolicyWithContext(context.TODO(), params) +} + +// Streams ConnectionPolicy records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamConnectionPolicyWithContext(ctx context.Context, params *ListConnectionPolicyParams) (chan VoiceV1ConnectionPolicy, chan error) { if params == nil { params = &ListConnectionPolicyParams{} } @@ -185,19 +207,19 @@ func (c *ApiService) StreamConnectionPolicy(params *ListConnectionPolicyParams) recordChannel := make(chan VoiceV1ConnectionPolicy, 1) errorChannel := make(chan error, 1) - response, err := c.PageConnectionPolicy(params, "", "") + response, err := c.PageConnectionPolicyWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamConnectionPolicy(response, params, recordChannel, errorChannel) + go c.streamConnectionPolicyWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamConnectionPolicy(response *ListConnectionPolicyResponse, params *ListConnectionPolicyParams, recordChannel chan VoiceV1ConnectionPolicy, errorChannel chan error) { +func (c *ApiService) streamConnectionPolicyWithContext(ctx context.Context, response *ListConnectionPolicyResponse, params *ListConnectionPolicyParams, recordChannel chan VoiceV1ConnectionPolicy, errorChannel chan error) { curRecord := 1 for response != nil { @@ -212,7 +234,7 @@ func (c *ApiService) streamConnectionPolicy(response *ListConnectionPolicyRespon } } - record, err := client.GetNext(c.baseURL, response, c.getNextListConnectionPolicyResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListConnectionPolicyResponseWithContext) if err != nil { errorChannel <- err break @@ -227,11 +249,11 @@ func (c *ApiService) streamConnectionPolicy(response *ListConnectionPolicyRespon close(errorChannel) } -func (c *ApiService) getNextListConnectionPolicyResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListConnectionPolicyResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -256,8 +278,10 @@ func (params *UpdateConnectionPolicyParams) SetFriendlyName(FriendlyName string) return params } -// func (c *ApiService) UpdateConnectionPolicy(Sid string, params *UpdateConnectionPolicyParams) (*VoiceV1ConnectionPolicy, error) { + return c.UpdateConnectionPolicyWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateConnectionPolicyWithContext(ctx context.Context, Sid string, params *UpdateConnectionPolicyParams) (*VoiceV1ConnectionPolicy, error) { path := "/v1/ConnectionPolicies/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -270,7 +294,7 @@ func (c *ApiService) UpdateConnectionPolicy(Sid string, params *UpdateConnection data.Set("FriendlyName", *params.FriendlyName) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/voice/v1/connection_policies_targets.go b/rest/voice/v1/connection_policies_targets.go index 1bc98a8e5..98c37e0be 100644 --- a/rest/voice/v1/connection_policies_targets.go +++ b/rest/voice/v1/connection_policies_targets.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -58,8 +59,10 @@ func (params *CreateConnectionPolicyTargetParams) SetEnabled(Enabled bool) *Crea return params } -// func (c *ApiService) CreateConnectionPolicyTarget(ConnectionPolicySid string, params *CreateConnectionPolicyTargetParams) (*VoiceV1ConnectionPolicyTarget, error) { + return c.CreateConnectionPolicyTargetWithContext(context.TODO(), ConnectionPolicySid, params) +} +func (c *ApiService) CreateConnectionPolicyTargetWithContext(ctx context.Context, ConnectionPolicySid string, params *CreateConnectionPolicyTargetParams) (*VoiceV1ConnectionPolicyTarget, error) { path := "/v1/ConnectionPolicies/{ConnectionPolicySid}/Targets" path = strings.Replace(path, "{"+"ConnectionPolicySid"+"}", ConnectionPolicySid, -1) @@ -84,7 +87,7 @@ func (c *ApiService) CreateConnectionPolicyTarget(ConnectionPolicySid string, pa data.Set("Enabled", fmt.Sprint(*params.Enabled)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -99,8 +102,10 @@ func (c *ApiService) CreateConnectionPolicyTarget(ConnectionPolicySid string, pa return ps, err } -// func (c *ApiService) DeleteConnectionPolicyTarget(ConnectionPolicySid string, Sid string) error { + return c.DeleteConnectionPolicyTargetWithContext(context.TODO(), ConnectionPolicySid, Sid) +} +func (c *ApiService) DeleteConnectionPolicyTargetWithContext(ctx context.Context, ConnectionPolicySid string, Sid string) error { path := "/v1/ConnectionPolicies/{ConnectionPolicySid}/Targets/{Sid}" path = strings.Replace(path, "{"+"ConnectionPolicySid"+"}", ConnectionPolicySid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -110,7 +115,7 @@ func (c *ApiService) DeleteConnectionPolicyTarget(ConnectionPolicySid string, Si "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -120,8 +125,10 @@ func (c *ApiService) DeleteConnectionPolicyTarget(ConnectionPolicySid string, Si return nil } -// func (c *ApiService) FetchConnectionPolicyTarget(ConnectionPolicySid string, Sid string) (*VoiceV1ConnectionPolicyTarget, error) { + return c.FetchConnectionPolicyTargetWithContext(context.TODO(), ConnectionPolicySid, Sid) +} +func (c *ApiService) FetchConnectionPolicyTargetWithContext(ctx context.Context, ConnectionPolicySid string, Sid string) (*VoiceV1ConnectionPolicyTarget, error) { path := "/v1/ConnectionPolicies/{ConnectionPolicySid}/Targets/{Sid}" path = strings.Replace(path, "{"+"ConnectionPolicySid"+"}", ConnectionPolicySid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -131,7 +138,7 @@ func (c *ApiService) FetchConnectionPolicyTarget(ConnectionPolicySid string, Sid "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -165,6 +172,11 @@ func (params *ListConnectionPolicyTargetParams) SetLimit(Limit int) *ListConnect // Retrieve a single page of ConnectionPolicyTarget records from the API. Request is executed immediately. func (c *ApiService) PageConnectionPolicyTarget(ConnectionPolicySid string, params *ListConnectionPolicyTargetParams, pageToken, pageNumber string) (*ListConnectionPolicyTargetResponse, error) { + return c.PageConnectionPolicyTargetWithContext(context.TODO(), ConnectionPolicySid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ConnectionPolicyTarget records from the API. Request is executed immediately. +func (c *ApiService) PageConnectionPolicyTargetWithContext(ctx context.Context, ConnectionPolicySid string, params *ListConnectionPolicyTargetParams, pageToken, pageNumber string) (*ListConnectionPolicyTargetResponse, error) { path := "/v1/ConnectionPolicies/{ConnectionPolicySid}/Targets" path = strings.Replace(path, "{"+"ConnectionPolicySid"+"}", ConnectionPolicySid, -1) @@ -185,7 +197,7 @@ func (c *ApiService) PageConnectionPolicyTarget(ConnectionPolicySid string, para data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -202,7 +214,12 @@ func (c *ApiService) PageConnectionPolicyTarget(ConnectionPolicySid string, para // Lists ConnectionPolicyTarget records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListConnectionPolicyTarget(ConnectionPolicySid string, params *ListConnectionPolicyTargetParams) ([]VoiceV1ConnectionPolicyTarget, error) { - response, errors := c.StreamConnectionPolicyTarget(ConnectionPolicySid, params) + return c.ListConnectionPolicyTargetWithContext(context.TODO(), ConnectionPolicySid, params) +} + +// Lists ConnectionPolicyTarget records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListConnectionPolicyTargetWithContext(ctx context.Context, ConnectionPolicySid string, params *ListConnectionPolicyTargetParams) ([]VoiceV1ConnectionPolicyTarget, error) { + response, errors := c.StreamConnectionPolicyTargetWithContext(ctx, ConnectionPolicySid, params) records := make([]VoiceV1ConnectionPolicyTarget, 0) for record := range response { @@ -218,6 +235,11 @@ func (c *ApiService) ListConnectionPolicyTarget(ConnectionPolicySid string, para // Streams ConnectionPolicyTarget records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamConnectionPolicyTarget(ConnectionPolicySid string, params *ListConnectionPolicyTargetParams) (chan VoiceV1ConnectionPolicyTarget, chan error) { + return c.StreamConnectionPolicyTargetWithContext(context.TODO(), ConnectionPolicySid, params) +} + +// Streams ConnectionPolicyTarget records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamConnectionPolicyTargetWithContext(ctx context.Context, ConnectionPolicySid string, params *ListConnectionPolicyTargetParams) (chan VoiceV1ConnectionPolicyTarget, chan error) { if params == nil { params = &ListConnectionPolicyTargetParams{} } @@ -226,19 +248,19 @@ func (c *ApiService) StreamConnectionPolicyTarget(ConnectionPolicySid string, pa recordChannel := make(chan VoiceV1ConnectionPolicyTarget, 1) errorChannel := make(chan error, 1) - response, err := c.PageConnectionPolicyTarget(ConnectionPolicySid, params, "", "") + response, err := c.PageConnectionPolicyTargetWithContext(ctx, ConnectionPolicySid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamConnectionPolicyTarget(response, params, recordChannel, errorChannel) + go c.streamConnectionPolicyTargetWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamConnectionPolicyTarget(response *ListConnectionPolicyTargetResponse, params *ListConnectionPolicyTargetParams, recordChannel chan VoiceV1ConnectionPolicyTarget, errorChannel chan error) { +func (c *ApiService) streamConnectionPolicyTargetWithContext(ctx context.Context, response *ListConnectionPolicyTargetResponse, params *ListConnectionPolicyTargetParams, recordChannel chan VoiceV1ConnectionPolicyTarget, errorChannel chan error) { curRecord := 1 for response != nil { @@ -253,7 +275,7 @@ func (c *ApiService) streamConnectionPolicyTarget(response *ListConnectionPolicy } } - record, err := client.GetNext(c.baseURL, response, c.getNextListConnectionPolicyTargetResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListConnectionPolicyTargetResponseWithContext) if err != nil { errorChannel <- err break @@ -268,11 +290,11 @@ func (c *ApiService) streamConnectionPolicyTarget(response *ListConnectionPolicy close(errorChannel) } -func (c *ApiService) getNextListConnectionPolicyTargetResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListConnectionPolicyTargetResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -321,8 +343,10 @@ func (params *UpdateConnectionPolicyTargetParams) SetEnabled(Enabled bool) *Upda return params } -// func (c *ApiService) UpdateConnectionPolicyTarget(ConnectionPolicySid string, Sid string, params *UpdateConnectionPolicyTargetParams) (*VoiceV1ConnectionPolicyTarget, error) { + return c.UpdateConnectionPolicyTargetWithContext(context.TODO(), ConnectionPolicySid, Sid, params) +} +func (c *ApiService) UpdateConnectionPolicyTargetWithContext(ctx context.Context, ConnectionPolicySid string, Sid string, params *UpdateConnectionPolicyTargetParams) (*VoiceV1ConnectionPolicyTarget, error) { path := "/v1/ConnectionPolicies/{ConnectionPolicySid}/Targets/{Sid}" path = strings.Replace(path, "{"+"ConnectionPolicySid"+"}", ConnectionPolicySid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -348,7 +372,7 @@ func (c *ApiService) UpdateConnectionPolicyTarget(ConnectionPolicySid string, Si data.Set("Enabled", fmt.Sprint(*params.Enabled)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/voice/v1/dialing_permissions_bulk_country_updates.go b/rest/voice/v1/dialing_permissions_bulk_country_updates.go index e23b743ab..1c80ab4b9 100644 --- a/rest/voice/v1/dialing_permissions_bulk_country_updates.go +++ b/rest/voice/v1/dialing_permissions_bulk_country_updates.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" ) @@ -32,6 +33,9 @@ func (params *CreateDialingPermissionsCountryBulkUpdateParams) SetUpdateRequest( // Create a bulk update request to change voice dialing country permissions of one or more countries identified by the corresponding [ISO country code](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) func (c *ApiService) CreateDialingPermissionsCountryBulkUpdate(params *CreateDialingPermissionsCountryBulkUpdateParams) (*VoiceV1DialingPermissionsCountryBulkUpdate, error) { + return c.CreateDialingPermissionsCountryBulkUpdateWithContext(context.TODO(), params) +} +func (c *ApiService) CreateDialingPermissionsCountryBulkUpdateWithContext(ctx context.Context, params *CreateDialingPermissionsCountryBulkUpdateParams) (*VoiceV1DialingPermissionsCountryBulkUpdate, error) { path := "/v1/DialingPermissions/BulkCountryUpdates" data := url.Values{} @@ -43,7 +47,7 @@ func (c *ApiService) CreateDialingPermissionsCountryBulkUpdate(params *CreateDia data.Set("UpdateRequest", *params.UpdateRequest) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/voice/v1/dialing_permissions_countries.go b/rest/voice/v1/dialing_permissions_countries.go index fadf1dac2..56a5b8959 100644 --- a/rest/voice/v1/dialing_permissions_countries.go +++ b/rest/voice/v1/dialing_permissions_countries.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -25,6 +26,9 @@ import ( // Retrieve voice dialing country permissions identified by the given ISO country code func (c *ApiService) FetchDialingPermissionsCountry(IsoCode string) (*VoiceV1DialingPermissionsCountryInstance, error) { + return c.FetchDialingPermissionsCountryWithContext(context.TODO(), IsoCode) +} +func (c *ApiService) FetchDialingPermissionsCountryWithContext(ctx context.Context, IsoCode string) (*VoiceV1DialingPermissionsCountryInstance, error) { path := "/v1/DialingPermissions/Countries/{IsoCode}" path = strings.Replace(path, "{"+"IsoCode"+"}", IsoCode, -1) @@ -33,7 +37,7 @@ func (c *ApiService) FetchDialingPermissionsCountry(IsoCode string) (*VoiceV1Dia "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -103,6 +107,11 @@ func (params *ListDialingPermissionsCountryParams) SetLimit(Limit int) *ListDial // Retrieve a single page of DialingPermissionsCountry records from the API. Request is executed immediately. func (c *ApiService) PageDialingPermissionsCountry(params *ListDialingPermissionsCountryParams, pageToken, pageNumber string) (*ListDialingPermissionsCountryResponse, error) { + return c.PageDialingPermissionsCountryWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of DialingPermissionsCountry records from the API. Request is executed immediately. +func (c *ApiService) PageDialingPermissionsCountryWithContext(ctx context.Context, params *ListDialingPermissionsCountryParams, pageToken, pageNumber string) (*ListDialingPermissionsCountryResponse, error) { path := "/v1/DialingPermissions/Countries" data := url.Values{} @@ -139,7 +148,7 @@ func (c *ApiService) PageDialingPermissionsCountry(params *ListDialingPermission data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -156,7 +165,12 @@ func (c *ApiService) PageDialingPermissionsCountry(params *ListDialingPermission // Lists DialingPermissionsCountry records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListDialingPermissionsCountry(params *ListDialingPermissionsCountryParams) ([]VoiceV1DialingPermissionsCountry, error) { - response, errors := c.StreamDialingPermissionsCountry(params) + return c.ListDialingPermissionsCountryWithContext(context.TODO(), params) +} + +// Lists DialingPermissionsCountry records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListDialingPermissionsCountryWithContext(ctx context.Context, params *ListDialingPermissionsCountryParams) ([]VoiceV1DialingPermissionsCountry, error) { + response, errors := c.StreamDialingPermissionsCountryWithContext(ctx, params) records := make([]VoiceV1DialingPermissionsCountry, 0) for record := range response { @@ -172,6 +186,11 @@ func (c *ApiService) ListDialingPermissionsCountry(params *ListDialingPermission // Streams DialingPermissionsCountry records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamDialingPermissionsCountry(params *ListDialingPermissionsCountryParams) (chan VoiceV1DialingPermissionsCountry, chan error) { + return c.StreamDialingPermissionsCountryWithContext(context.TODO(), params) +} + +// Streams DialingPermissionsCountry records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamDialingPermissionsCountryWithContext(ctx context.Context, params *ListDialingPermissionsCountryParams) (chan VoiceV1DialingPermissionsCountry, chan error) { if params == nil { params = &ListDialingPermissionsCountryParams{} } @@ -180,19 +199,19 @@ func (c *ApiService) StreamDialingPermissionsCountry(params *ListDialingPermissi recordChannel := make(chan VoiceV1DialingPermissionsCountry, 1) errorChannel := make(chan error, 1) - response, err := c.PageDialingPermissionsCountry(params, "", "") + response, err := c.PageDialingPermissionsCountryWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamDialingPermissionsCountry(response, params, recordChannel, errorChannel) + go c.streamDialingPermissionsCountryWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamDialingPermissionsCountry(response *ListDialingPermissionsCountryResponse, params *ListDialingPermissionsCountryParams, recordChannel chan VoiceV1DialingPermissionsCountry, errorChannel chan error) { +func (c *ApiService) streamDialingPermissionsCountryWithContext(ctx context.Context, response *ListDialingPermissionsCountryResponse, params *ListDialingPermissionsCountryParams, recordChannel chan VoiceV1DialingPermissionsCountry, errorChannel chan error) { curRecord := 1 for response != nil { @@ -207,7 +226,7 @@ func (c *ApiService) streamDialingPermissionsCountry(response *ListDialingPermis } } - record, err := client.GetNext(c.baseURL, response, c.getNextListDialingPermissionsCountryResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListDialingPermissionsCountryResponseWithContext) if err != nil { errorChannel <- err break @@ -222,11 +241,11 @@ func (c *ApiService) streamDialingPermissionsCountry(response *ListDialingPermis close(errorChannel) } -func (c *ApiService) getNextListDialingPermissionsCountryResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListDialingPermissionsCountryResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/voice/v1/dialing_permissions_countries_high_risk_special_prefixes.go b/rest/voice/v1/dialing_permissions_countries_high_risk_special_prefixes.go index 6adfc1667..df45210ec 100644 --- a/rest/voice/v1/dialing_permissions_countries_high_risk_special_prefixes.go +++ b/rest/voice/v1/dialing_permissions_countries_high_risk_special_prefixes.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -42,6 +43,11 @@ func (params *ListDialingPermissionsHrsPrefixesParams) SetLimit(Limit int) *List // Retrieve a single page of DialingPermissionsHrsPrefixes records from the API. Request is executed immediately. func (c *ApiService) PageDialingPermissionsHrsPrefixes(IsoCode string, params *ListDialingPermissionsHrsPrefixesParams, pageToken, pageNumber string) (*ListDialingPermissionsHrsPrefixesResponse, error) { + return c.PageDialingPermissionsHrsPrefixesWithContext(context.TODO(), IsoCode, params, pageToken, pageNumber) +} + +// Retrieve a single page of DialingPermissionsHrsPrefixes records from the API. Request is executed immediately. +func (c *ApiService) PageDialingPermissionsHrsPrefixesWithContext(ctx context.Context, IsoCode string, params *ListDialingPermissionsHrsPrefixesParams, pageToken, pageNumber string) (*ListDialingPermissionsHrsPrefixesResponse, error) { path := "/v1/DialingPermissions/Countries/{IsoCode}/HighRiskSpecialPrefixes" path = strings.Replace(path, "{"+"IsoCode"+"}", IsoCode, -1) @@ -62,7 +68,7 @@ func (c *ApiService) PageDialingPermissionsHrsPrefixes(IsoCode string, params *L data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -79,7 +85,12 @@ func (c *ApiService) PageDialingPermissionsHrsPrefixes(IsoCode string, params *L // Lists DialingPermissionsHrsPrefixes records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListDialingPermissionsHrsPrefixes(IsoCode string, params *ListDialingPermissionsHrsPrefixesParams) ([]VoiceV1DialingPermissionsHrsPrefixes, error) { - response, errors := c.StreamDialingPermissionsHrsPrefixes(IsoCode, params) + return c.ListDialingPermissionsHrsPrefixesWithContext(context.TODO(), IsoCode, params) +} + +// Lists DialingPermissionsHrsPrefixes records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListDialingPermissionsHrsPrefixesWithContext(ctx context.Context, IsoCode string, params *ListDialingPermissionsHrsPrefixesParams) ([]VoiceV1DialingPermissionsHrsPrefixes, error) { + response, errors := c.StreamDialingPermissionsHrsPrefixesWithContext(ctx, IsoCode, params) records := make([]VoiceV1DialingPermissionsHrsPrefixes, 0) for record := range response { @@ -95,6 +106,11 @@ func (c *ApiService) ListDialingPermissionsHrsPrefixes(IsoCode string, params *L // Streams DialingPermissionsHrsPrefixes records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamDialingPermissionsHrsPrefixes(IsoCode string, params *ListDialingPermissionsHrsPrefixesParams) (chan VoiceV1DialingPermissionsHrsPrefixes, chan error) { + return c.StreamDialingPermissionsHrsPrefixesWithContext(context.TODO(), IsoCode, params) +} + +// Streams DialingPermissionsHrsPrefixes records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamDialingPermissionsHrsPrefixesWithContext(ctx context.Context, IsoCode string, params *ListDialingPermissionsHrsPrefixesParams) (chan VoiceV1DialingPermissionsHrsPrefixes, chan error) { if params == nil { params = &ListDialingPermissionsHrsPrefixesParams{} } @@ -103,19 +119,19 @@ func (c *ApiService) StreamDialingPermissionsHrsPrefixes(IsoCode string, params recordChannel := make(chan VoiceV1DialingPermissionsHrsPrefixes, 1) errorChannel := make(chan error, 1) - response, err := c.PageDialingPermissionsHrsPrefixes(IsoCode, params, "", "") + response, err := c.PageDialingPermissionsHrsPrefixesWithContext(ctx, IsoCode, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamDialingPermissionsHrsPrefixes(response, params, recordChannel, errorChannel) + go c.streamDialingPermissionsHrsPrefixesWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamDialingPermissionsHrsPrefixes(response *ListDialingPermissionsHrsPrefixesResponse, params *ListDialingPermissionsHrsPrefixesParams, recordChannel chan VoiceV1DialingPermissionsHrsPrefixes, errorChannel chan error) { +func (c *ApiService) streamDialingPermissionsHrsPrefixesWithContext(ctx context.Context, response *ListDialingPermissionsHrsPrefixesResponse, params *ListDialingPermissionsHrsPrefixesParams, recordChannel chan VoiceV1DialingPermissionsHrsPrefixes, errorChannel chan error) { curRecord := 1 for response != nil { @@ -130,7 +146,7 @@ func (c *ApiService) streamDialingPermissionsHrsPrefixes(response *ListDialingPe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListDialingPermissionsHrsPrefixesResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListDialingPermissionsHrsPrefixesResponseWithContext) if err != nil { errorChannel <- err break @@ -145,11 +161,11 @@ func (c *ApiService) streamDialingPermissionsHrsPrefixes(response *ListDialingPe close(errorChannel) } -func (c *ApiService) getNextListDialingPermissionsHrsPrefixesResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListDialingPermissionsHrsPrefixesResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/voice/v1/ip_records.go b/rest/voice/v1/ip_records.go index 834c5b324..78e499fc9 100644 --- a/rest/voice/v1/ip_records.go +++ b/rest/voice/v1/ip_records.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -46,8 +47,10 @@ func (params *CreateIpRecordParams) SetCidrPrefixLength(CidrPrefixLength int) *C return params } -// func (c *ApiService) CreateIpRecord(params *CreateIpRecordParams) (*VoiceV1IpRecord, error) { + return c.CreateIpRecordWithContext(context.TODO(), params) +} +func (c *ApiService) CreateIpRecordWithContext(ctx context.Context, params *CreateIpRecordParams) (*VoiceV1IpRecord, error) { path := "/v1/IpRecords" data := url.Values{} @@ -65,7 +68,7 @@ func (c *ApiService) CreateIpRecord(params *CreateIpRecordParams) (*VoiceV1IpRec data.Set("CidrPrefixLength", fmt.Sprint(*params.CidrPrefixLength)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -80,8 +83,10 @@ func (c *ApiService) CreateIpRecord(params *CreateIpRecordParams) (*VoiceV1IpRec return ps, err } -// func (c *ApiService) DeleteIpRecord(Sid string) error { + return c.DeleteIpRecordWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteIpRecordWithContext(ctx context.Context, Sid string) error { path := "/v1/IpRecords/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -90,7 +95,7 @@ func (c *ApiService) DeleteIpRecord(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -100,8 +105,10 @@ func (c *ApiService) DeleteIpRecord(Sid string) error { return nil } -// func (c *ApiService) FetchIpRecord(Sid string) (*VoiceV1IpRecord, error) { + return c.FetchIpRecordWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchIpRecordWithContext(ctx context.Context, Sid string) (*VoiceV1IpRecord, error) { path := "/v1/IpRecords/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -110,7 +117,7 @@ func (c *ApiService) FetchIpRecord(Sid string) (*VoiceV1IpRecord, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -144,6 +151,11 @@ func (params *ListIpRecordParams) SetLimit(Limit int) *ListIpRecordParams { // Retrieve a single page of IpRecord records from the API. Request is executed immediately. func (c *ApiService) PageIpRecord(params *ListIpRecordParams, pageToken, pageNumber string) (*ListIpRecordResponse, error) { + return c.PageIpRecordWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of IpRecord records from the API. Request is executed immediately. +func (c *ApiService) PageIpRecordWithContext(ctx context.Context, params *ListIpRecordParams, pageToken, pageNumber string) (*ListIpRecordResponse, error) { path := "/v1/IpRecords" data := url.Values{} @@ -162,7 +174,7 @@ func (c *ApiService) PageIpRecord(params *ListIpRecordParams, pageToken, pageNum data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -179,7 +191,12 @@ func (c *ApiService) PageIpRecord(params *ListIpRecordParams, pageToken, pageNum // Lists IpRecord records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListIpRecord(params *ListIpRecordParams) ([]VoiceV1IpRecord, error) { - response, errors := c.StreamIpRecord(params) + return c.ListIpRecordWithContext(context.TODO(), params) +} + +// Lists IpRecord records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListIpRecordWithContext(ctx context.Context, params *ListIpRecordParams) ([]VoiceV1IpRecord, error) { + response, errors := c.StreamIpRecordWithContext(ctx, params) records := make([]VoiceV1IpRecord, 0) for record := range response { @@ -195,6 +212,11 @@ func (c *ApiService) ListIpRecord(params *ListIpRecordParams) ([]VoiceV1IpRecord // Streams IpRecord records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamIpRecord(params *ListIpRecordParams) (chan VoiceV1IpRecord, chan error) { + return c.StreamIpRecordWithContext(context.TODO(), params) +} + +// Streams IpRecord records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamIpRecordWithContext(ctx context.Context, params *ListIpRecordParams) (chan VoiceV1IpRecord, chan error) { if params == nil { params = &ListIpRecordParams{} } @@ -203,19 +225,19 @@ func (c *ApiService) StreamIpRecord(params *ListIpRecordParams) (chan VoiceV1IpR recordChannel := make(chan VoiceV1IpRecord, 1) errorChannel := make(chan error, 1) - response, err := c.PageIpRecord(params, "", "") + response, err := c.PageIpRecordWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamIpRecord(response, params, recordChannel, errorChannel) + go c.streamIpRecordWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamIpRecord(response *ListIpRecordResponse, params *ListIpRecordParams, recordChannel chan VoiceV1IpRecord, errorChannel chan error) { +func (c *ApiService) streamIpRecordWithContext(ctx context.Context, response *ListIpRecordResponse, params *ListIpRecordParams, recordChannel chan VoiceV1IpRecord, errorChannel chan error) { curRecord := 1 for response != nil { @@ -230,7 +252,7 @@ func (c *ApiService) streamIpRecord(response *ListIpRecordResponse, params *List } } - record, err := client.GetNext(c.baseURL, response, c.getNextListIpRecordResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListIpRecordResponseWithContext) if err != nil { errorChannel <- err break @@ -245,11 +267,11 @@ func (c *ApiService) streamIpRecord(response *ListIpRecordResponse, params *List close(errorChannel) } -func (c *ApiService) getNextListIpRecordResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListIpRecordResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -274,8 +296,10 @@ func (params *UpdateIpRecordParams) SetFriendlyName(FriendlyName string) *Update return params } -// func (c *ApiService) UpdateIpRecord(Sid string, params *UpdateIpRecordParams) (*VoiceV1IpRecord, error) { + return c.UpdateIpRecordWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateIpRecordWithContext(ctx context.Context, Sid string, params *UpdateIpRecordParams) (*VoiceV1IpRecord, error) { path := "/v1/IpRecords/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -288,7 +312,7 @@ func (c *ApiService) UpdateIpRecord(Sid string, params *UpdateIpRecordParams) (* data.Set("FriendlyName", *params.FriendlyName) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/voice/v1/settings.go b/rest/voice/v1/settings.go index ce2043ed9..0755ce5ef 100644 --- a/rest/voice/v1/settings.go +++ b/rest/voice/v1/settings.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -22,6 +23,9 @@ import ( // Retrieve voice dialing permissions inheritance for the sub-account func (c *ApiService) FetchDialingPermissionsSettings() (*VoiceV1DialingPermissionsSettings, error) { + return c.FetchDialingPermissionsSettingsWithContext(context.TODO()) +} +func (c *ApiService) FetchDialingPermissionsSettingsWithContext(ctx context.Context) (*VoiceV1DialingPermissionsSettings, error) { path := "/v1/Settings" data := url.Values{} @@ -29,7 +33,7 @@ func (c *ApiService) FetchDialingPermissionsSettings() (*VoiceV1DialingPermissio "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -57,6 +61,9 @@ func (params *UpdateDialingPermissionsSettingsParams) SetDialingPermissionsInher // Update voice dialing permissions inheritance for the sub-account func (c *ApiService) UpdateDialingPermissionsSettings(params *UpdateDialingPermissionsSettingsParams) (*VoiceV1DialingPermissionsSettings, error) { + return c.UpdateDialingPermissionsSettingsWithContext(context.TODO(), params) +} +func (c *ApiService) UpdateDialingPermissionsSettingsWithContext(ctx context.Context, params *UpdateDialingPermissionsSettingsParams) (*VoiceV1DialingPermissionsSettings, error) { path := "/v1/Settings" data := url.Values{} @@ -68,7 +75,7 @@ func (c *ApiService) UpdateDialingPermissionsSettings(params *UpdateDialingPermi data.Set("DialingPermissionsInheritance", fmt.Sprint(*params.DialingPermissionsInheritance)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/voice/v1/source_ip_mappings.go b/rest/voice/v1/source_ip_mappings.go index 900078349..f3ad618fb 100644 --- a/rest/voice/v1/source_ip_mappings.go +++ b/rest/voice/v1/source_ip_mappings.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -40,8 +41,10 @@ func (params *CreateSourceIpMappingParams) SetSipDomainSid(SipDomainSid string) return params } -// func (c *ApiService) CreateSourceIpMapping(params *CreateSourceIpMappingParams) (*VoiceV1SourceIpMapping, error) { + return c.CreateSourceIpMappingWithContext(context.TODO(), params) +} +func (c *ApiService) CreateSourceIpMappingWithContext(ctx context.Context, params *CreateSourceIpMappingParams) (*VoiceV1SourceIpMapping, error) { path := "/v1/SourceIpMappings" data := url.Values{} @@ -56,7 +59,7 @@ func (c *ApiService) CreateSourceIpMapping(params *CreateSourceIpMappingParams) data.Set("SipDomainSid", *params.SipDomainSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -71,8 +74,10 @@ func (c *ApiService) CreateSourceIpMapping(params *CreateSourceIpMappingParams) return ps, err } -// func (c *ApiService) DeleteSourceIpMapping(Sid string) error { + return c.DeleteSourceIpMappingWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteSourceIpMappingWithContext(ctx context.Context, Sid string) error { path := "/v1/SourceIpMappings/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -81,7 +86,7 @@ func (c *ApiService) DeleteSourceIpMapping(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -91,8 +96,10 @@ func (c *ApiService) DeleteSourceIpMapping(Sid string) error { return nil } -// func (c *ApiService) FetchSourceIpMapping(Sid string) (*VoiceV1SourceIpMapping, error) { + return c.FetchSourceIpMappingWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchSourceIpMappingWithContext(ctx context.Context, Sid string) (*VoiceV1SourceIpMapping, error) { path := "/v1/SourceIpMappings/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -101,7 +108,7 @@ func (c *ApiService) FetchSourceIpMapping(Sid string) (*VoiceV1SourceIpMapping, "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -135,6 +142,11 @@ func (params *ListSourceIpMappingParams) SetLimit(Limit int) *ListSourceIpMappin // Retrieve a single page of SourceIpMapping records from the API. Request is executed immediately. func (c *ApiService) PageSourceIpMapping(params *ListSourceIpMappingParams, pageToken, pageNumber string) (*ListSourceIpMappingResponse, error) { + return c.PageSourceIpMappingWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of SourceIpMapping records from the API. Request is executed immediately. +func (c *ApiService) PageSourceIpMappingWithContext(ctx context.Context, params *ListSourceIpMappingParams, pageToken, pageNumber string) (*ListSourceIpMappingResponse, error) { path := "/v1/SourceIpMappings" data := url.Values{} @@ -153,7 +165,7 @@ func (c *ApiService) PageSourceIpMapping(params *ListSourceIpMappingParams, page data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -170,7 +182,12 @@ func (c *ApiService) PageSourceIpMapping(params *ListSourceIpMappingParams, page // Lists SourceIpMapping records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListSourceIpMapping(params *ListSourceIpMappingParams) ([]VoiceV1SourceIpMapping, error) { - response, errors := c.StreamSourceIpMapping(params) + return c.ListSourceIpMappingWithContext(context.TODO(), params) +} + +// Lists SourceIpMapping records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListSourceIpMappingWithContext(ctx context.Context, params *ListSourceIpMappingParams) ([]VoiceV1SourceIpMapping, error) { + response, errors := c.StreamSourceIpMappingWithContext(ctx, params) records := make([]VoiceV1SourceIpMapping, 0) for record := range response { @@ -186,6 +203,11 @@ func (c *ApiService) ListSourceIpMapping(params *ListSourceIpMappingParams) ([]V // Streams SourceIpMapping records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamSourceIpMapping(params *ListSourceIpMappingParams) (chan VoiceV1SourceIpMapping, chan error) { + return c.StreamSourceIpMappingWithContext(context.TODO(), params) +} + +// Streams SourceIpMapping records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamSourceIpMappingWithContext(ctx context.Context, params *ListSourceIpMappingParams) (chan VoiceV1SourceIpMapping, chan error) { if params == nil { params = &ListSourceIpMappingParams{} } @@ -194,19 +216,19 @@ func (c *ApiService) StreamSourceIpMapping(params *ListSourceIpMappingParams) (c recordChannel := make(chan VoiceV1SourceIpMapping, 1) errorChannel := make(chan error, 1) - response, err := c.PageSourceIpMapping(params, "", "") + response, err := c.PageSourceIpMappingWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSourceIpMapping(response, params, recordChannel, errorChannel) + go c.streamSourceIpMappingWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamSourceIpMapping(response *ListSourceIpMappingResponse, params *ListSourceIpMappingParams, recordChannel chan VoiceV1SourceIpMapping, errorChannel chan error) { +func (c *ApiService) streamSourceIpMappingWithContext(ctx context.Context, response *ListSourceIpMappingResponse, params *ListSourceIpMappingParams, recordChannel chan VoiceV1SourceIpMapping, errorChannel chan error) { curRecord := 1 for response != nil { @@ -221,7 +243,7 @@ func (c *ApiService) streamSourceIpMapping(response *ListSourceIpMappingResponse } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSourceIpMappingResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListSourceIpMappingResponseWithContext) if err != nil { errorChannel <- err break @@ -236,11 +258,11 @@ func (c *ApiService) streamSourceIpMapping(response *ListSourceIpMappingResponse close(errorChannel) } -func (c *ApiService) getNextListSourceIpMappingResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSourceIpMappingResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -265,8 +287,10 @@ func (params *UpdateSourceIpMappingParams) SetSipDomainSid(SipDomainSid string) return params } -// func (c *ApiService) UpdateSourceIpMapping(Sid string, params *UpdateSourceIpMappingParams) (*VoiceV1SourceIpMapping, error) { + return c.UpdateSourceIpMappingWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateSourceIpMappingWithContext(ctx context.Context, Sid string, params *UpdateSourceIpMappingParams) (*VoiceV1SourceIpMapping, error) { path := "/v1/SourceIpMappings/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -279,7 +303,7 @@ func (c *ApiService) UpdateSourceIpMapping(Sid string, params *UpdateSourceIpMap data.Set("SipDomainSid", *params.SipDomainSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/wireless/v1/api_service.go b/rest/wireless/v1/api_service.go index b3abe1272..d27acba71 100644 --- a/rest/wireless/v1/api_service.go +++ b/rest/wireless/v1/api_service.go @@ -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 { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://wireless.twilio.com", + } +} diff --git a/rest/wireless/v1/commands.go b/rest/wireless/v1/commands.go index 77ad1ddd4..2a8ccdeeb 100644 --- a/rest/wireless/v1/commands.go +++ b/rest/wireless/v1/commands.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -72,6 +73,9 @@ func (params *CreateCommandParams) SetDeliveryReceiptRequested(DeliveryReceiptRe // Send a Command to a Sim. func (c *ApiService) CreateCommand(params *CreateCommandParams) (*WirelessV1Command, error) { + return c.CreateCommandWithContext(context.TODO(), params) +} +func (c *ApiService) CreateCommandWithContext(ctx context.Context, params *CreateCommandParams) (*WirelessV1Command, error) { path := "/v1/Commands" data := url.Values{} @@ -101,7 +105,7 @@ func (c *ApiService) CreateCommand(params *CreateCommandParams) (*WirelessV1Comm data.Set("DeliveryReceiptRequested", fmt.Sprint(*params.DeliveryReceiptRequested)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -118,6 +122,9 @@ func (c *ApiService) CreateCommand(params *CreateCommandParams) (*WirelessV1Comm // Delete a Command instance from your account. func (c *ApiService) DeleteCommand(Sid string) error { + return c.DeleteCommandWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteCommandWithContext(ctx context.Context, Sid string) error { path := "/v1/Commands/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -126,7 +133,7 @@ func (c *ApiService) DeleteCommand(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -138,6 +145,9 @@ func (c *ApiService) DeleteCommand(Sid string) error { // Fetch a Command instance from your account. func (c *ApiService) FetchCommand(Sid string) (*WirelessV1Command, error) { + return c.FetchCommandWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchCommandWithContext(ctx context.Context, Sid string) (*WirelessV1Command, error) { path := "/v1/Commands/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -146,7 +156,7 @@ func (c *ApiService) FetchCommand(Sid string) (*WirelessV1Command, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -204,6 +214,11 @@ func (params *ListCommandParams) SetLimit(Limit int) *ListCommandParams { // Retrieve a single page of Command records from the API. Request is executed immediately. func (c *ApiService) PageCommand(params *ListCommandParams, pageToken, pageNumber string) (*ListCommandResponse, error) { + return c.PageCommandWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Command records from the API. Request is executed immediately. +func (c *ApiService) PageCommandWithContext(ctx context.Context, params *ListCommandParams, pageToken, pageNumber string) (*ListCommandResponse, error) { path := "/v1/Commands" data := url.Values{} @@ -234,7 +249,7 @@ func (c *ApiService) PageCommand(params *ListCommandParams, pageToken, pageNumbe data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -251,7 +266,12 @@ func (c *ApiService) PageCommand(params *ListCommandParams, pageToken, pageNumbe // Lists Command records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListCommand(params *ListCommandParams) ([]WirelessV1Command, error) { - response, errors := c.StreamCommand(params) + return c.ListCommandWithContext(context.TODO(), params) +} + +// Lists Command records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListCommandWithContext(ctx context.Context, params *ListCommandParams) ([]WirelessV1Command, error) { + response, errors := c.StreamCommandWithContext(ctx, params) records := make([]WirelessV1Command, 0) for record := range response { @@ -267,6 +287,11 @@ func (c *ApiService) ListCommand(params *ListCommandParams) ([]WirelessV1Command // Streams Command records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamCommand(params *ListCommandParams) (chan WirelessV1Command, chan error) { + return c.StreamCommandWithContext(context.TODO(), params) +} + +// Streams Command records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamCommandWithContext(ctx context.Context, params *ListCommandParams) (chan WirelessV1Command, chan error) { if params == nil { params = &ListCommandParams{} } @@ -275,19 +300,19 @@ func (c *ApiService) StreamCommand(params *ListCommandParams) (chan WirelessV1Co recordChannel := make(chan WirelessV1Command, 1) errorChannel := make(chan error, 1) - response, err := c.PageCommand(params, "", "") + response, err := c.PageCommandWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamCommand(response, params, recordChannel, errorChannel) + go c.streamCommandWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamCommand(response *ListCommandResponse, params *ListCommandParams, recordChannel chan WirelessV1Command, errorChannel chan error) { +func (c *ApiService) streamCommandWithContext(ctx context.Context, response *ListCommandResponse, params *ListCommandParams, recordChannel chan WirelessV1Command, errorChannel chan error) { curRecord := 1 for response != nil { @@ -302,7 +327,7 @@ func (c *ApiService) streamCommand(response *ListCommandResponse, params *ListCo } } - record, err := client.GetNext(c.baseURL, response, c.getNextListCommandResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListCommandResponseWithContext) if err != nil { errorChannel <- err break @@ -317,11 +342,11 @@ func (c *ApiService) streamCommand(response *ListCommandResponse, params *ListCo close(errorChannel) } -func (c *ApiService) getNextListCommandResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListCommandResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/wireless/v1/rate_plans.go b/rest/wireless/v1/rate_plans.go index 9f71acaaf..0f34ec841 100644 --- a/rest/wireless/v1/rate_plans.go +++ b/rest/wireless/v1/rate_plans.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -100,8 +101,10 @@ func (params *CreateRatePlanParams) SetDataLimitStrategy(DataLimitStrategy strin return params } -// func (c *ApiService) CreateRatePlan(params *CreateRatePlanParams) (*WirelessV1RatePlan, error) { + return c.CreateRatePlanWithContext(context.TODO(), params) +} +func (c *ApiService) CreateRatePlanWithContext(ctx context.Context, params *CreateRatePlanParams) (*WirelessV1RatePlan, error) { path := "/v1/RatePlans" data := url.Values{} @@ -148,7 +151,7 @@ func (c *ApiService) CreateRatePlan(params *CreateRatePlanParams) (*WirelessV1Ra data.Set("DataLimitStrategy", fmt.Sprint(*params.DataLimitStrategy)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -163,8 +166,10 @@ func (c *ApiService) CreateRatePlan(params *CreateRatePlanParams) (*WirelessV1Ra return ps, err } -// func (c *ApiService) DeleteRatePlan(Sid string) error { + return c.DeleteRatePlanWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteRatePlanWithContext(ctx context.Context, Sid string) error { path := "/v1/RatePlans/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -173,7 +178,7 @@ func (c *ApiService) DeleteRatePlan(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -183,8 +188,10 @@ func (c *ApiService) DeleteRatePlan(Sid string) error { return nil } -// func (c *ApiService) FetchRatePlan(Sid string) (*WirelessV1RatePlan, error) { + return c.FetchRatePlanWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchRatePlanWithContext(ctx context.Context, Sid string) (*WirelessV1RatePlan, error) { path := "/v1/RatePlans/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -193,7 +200,7 @@ func (c *ApiService) FetchRatePlan(Sid string) (*WirelessV1RatePlan, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -227,6 +234,11 @@ func (params *ListRatePlanParams) SetLimit(Limit int) *ListRatePlanParams { // Retrieve a single page of RatePlan records from the API. Request is executed immediately. func (c *ApiService) PageRatePlan(params *ListRatePlanParams, pageToken, pageNumber string) (*ListRatePlanResponse, error) { + return c.PageRatePlanWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of RatePlan records from the API. Request is executed immediately. +func (c *ApiService) PageRatePlanWithContext(ctx context.Context, params *ListRatePlanParams, pageToken, pageNumber string) (*ListRatePlanResponse, error) { path := "/v1/RatePlans" data := url.Values{} @@ -245,7 +257,7 @@ func (c *ApiService) PageRatePlan(params *ListRatePlanParams, pageToken, pageNum data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -262,7 +274,12 @@ func (c *ApiService) PageRatePlan(params *ListRatePlanParams, pageToken, pageNum // Lists RatePlan records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListRatePlan(params *ListRatePlanParams) ([]WirelessV1RatePlan, error) { - response, errors := c.StreamRatePlan(params) + return c.ListRatePlanWithContext(context.TODO(), params) +} + +// Lists RatePlan records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListRatePlanWithContext(ctx context.Context, params *ListRatePlanParams) ([]WirelessV1RatePlan, error) { + response, errors := c.StreamRatePlanWithContext(ctx, params) records := make([]WirelessV1RatePlan, 0) for record := range response { @@ -278,6 +295,11 @@ func (c *ApiService) ListRatePlan(params *ListRatePlanParams) ([]WirelessV1RateP // Streams RatePlan records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamRatePlan(params *ListRatePlanParams) (chan WirelessV1RatePlan, chan error) { + return c.StreamRatePlanWithContext(context.TODO(), params) +} + +// Streams RatePlan records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamRatePlanWithContext(ctx context.Context, params *ListRatePlanParams) (chan WirelessV1RatePlan, chan error) { if params == nil { params = &ListRatePlanParams{} } @@ -286,19 +308,19 @@ func (c *ApiService) StreamRatePlan(params *ListRatePlanParams) (chan WirelessV1 recordChannel := make(chan WirelessV1RatePlan, 1) errorChannel := make(chan error, 1) - response, err := c.PageRatePlan(params, "", "") + response, err := c.PageRatePlanWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamRatePlan(response, params, recordChannel, errorChannel) + go c.streamRatePlanWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamRatePlan(response *ListRatePlanResponse, params *ListRatePlanParams, recordChannel chan WirelessV1RatePlan, errorChannel chan error) { +func (c *ApiService) streamRatePlanWithContext(ctx context.Context, response *ListRatePlanResponse, params *ListRatePlanParams, recordChannel chan WirelessV1RatePlan, errorChannel chan error) { curRecord := 1 for response != nil { @@ -313,7 +335,7 @@ func (c *ApiService) streamRatePlan(response *ListRatePlanResponse, params *List } } - record, err := client.GetNext(c.baseURL, response, c.getNextListRatePlanResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListRatePlanResponseWithContext) if err != nil { errorChannel <- err break @@ -328,11 +350,11 @@ func (c *ApiService) streamRatePlan(response *ListRatePlanResponse, params *List close(errorChannel) } -func (c *ApiService) getNextListRatePlanResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListRatePlanResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -363,8 +385,10 @@ func (params *UpdateRatePlanParams) SetFriendlyName(FriendlyName string) *Update return params } -// func (c *ApiService) UpdateRatePlan(Sid string, params *UpdateRatePlanParams) (*WirelessV1RatePlan, error) { + return c.UpdateRatePlanWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateRatePlanWithContext(ctx context.Context, Sid string, params *UpdateRatePlanParams) (*WirelessV1RatePlan, error) { path := "/v1/RatePlans/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -380,7 +404,7 @@ func (c *ApiService) UpdateRatePlan(Sid string, params *UpdateRatePlanParams) (* data.Set("FriendlyName", *params.FriendlyName) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/wireless/v1/sims.go b/rest/wireless/v1/sims.go index 0b20c5970..ece3dddf7 100644 --- a/rest/wireless/v1/sims.go +++ b/rest/wireless/v1/sims.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -25,6 +26,9 @@ import ( // Delete a Sim resource on your Account. func (c *ApiService) DeleteSim(Sid string) error { + return c.DeleteSimWithContext(context.TODO(), Sid) +} +func (c *ApiService) DeleteSimWithContext(ctx context.Context, Sid string) error { path := "/v1/Sims/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -33,7 +37,7 @@ func (c *ApiService) DeleteSim(Sid string) error { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.DeleteWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -45,6 +49,9 @@ func (c *ApiService) DeleteSim(Sid string) error { // Fetch a Sim resource on your Account. func (c *ApiService) FetchSim(Sid string) (*WirelessV1Sim, error) { + return c.FetchSimWithContext(context.TODO(), Sid) +} +func (c *ApiService) FetchSimWithContext(ctx context.Context, Sid string) (*WirelessV1Sim, error) { path := "/v1/Sims/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -53,7 +60,7 @@ func (c *ApiService) FetchSim(Sid string) (*WirelessV1Sim, error) { "Content-Type": "application/x-www-form-urlencoded", } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -117,6 +124,11 @@ func (params *ListSimParams) SetLimit(Limit int) *ListSimParams { // Retrieve a single page of Sim records from the API. Request is executed immediately. func (c *ApiService) PageSim(params *ListSimParams, pageToken, pageNumber string) (*ListSimResponse, error) { + return c.PageSimWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Sim records from the API. Request is executed immediately. +func (c *ApiService) PageSimWithContext(ctx context.Context, params *ListSimParams, pageToken, pageNumber string) (*ListSimResponse, error) { path := "/v1/Sims" data := url.Values{} @@ -150,7 +162,7 @@ func (c *ApiService) PageSim(params *ListSimParams, pageToken, pageNumber string data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -167,7 +179,12 @@ func (c *ApiService) PageSim(params *ListSimParams, pageToken, pageNumber string // Lists Sim records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListSim(params *ListSimParams) ([]WirelessV1Sim, error) { - response, errors := c.StreamSim(params) + return c.ListSimWithContext(context.TODO(), params) +} + +// Lists Sim records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListSimWithContext(ctx context.Context, params *ListSimParams) ([]WirelessV1Sim, error) { + response, errors := c.StreamSimWithContext(ctx, params) records := make([]WirelessV1Sim, 0) for record := range response { @@ -183,6 +200,11 @@ func (c *ApiService) ListSim(params *ListSimParams) ([]WirelessV1Sim, error) { // Streams Sim records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamSim(params *ListSimParams) (chan WirelessV1Sim, chan error) { + return c.StreamSimWithContext(context.TODO(), params) +} + +// Streams Sim records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamSimWithContext(ctx context.Context, params *ListSimParams) (chan WirelessV1Sim, chan error) { if params == nil { params = &ListSimParams{} } @@ -191,19 +213,19 @@ func (c *ApiService) StreamSim(params *ListSimParams) (chan WirelessV1Sim, chan recordChannel := make(chan WirelessV1Sim, 1) errorChannel := make(chan error, 1) - response, err := c.PageSim(params, "", "") + response, err := c.PageSimWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSim(response, params, recordChannel, errorChannel) + go c.streamSimWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamSim(response *ListSimResponse, params *ListSimParams, recordChannel chan WirelessV1Sim, errorChannel chan error) { +func (c *ApiService) streamSimWithContext(ctx context.Context, response *ListSimResponse, params *ListSimParams, recordChannel chan WirelessV1Sim, errorChannel chan error) { curRecord := 1 for response != nil { @@ -218,7 +240,7 @@ func (c *ApiService) streamSim(response *ListSimResponse, params *ListSimParams, } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSimResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListSimResponseWithContext) if err != nil { errorChannel <- err break @@ -233,11 +255,11 @@ func (c *ApiService) streamSim(response *ListSimResponse, params *ListSimParams, close(errorChannel) } -func (c *ApiService) getNextListSimResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSimResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -366,6 +388,9 @@ func (params *UpdateSimParams) SetAccountSid(AccountSid string) *UpdateSimParams // Updates the given properties of a Sim resource on your Account. func (c *ApiService) UpdateSim(Sid string, params *UpdateSimParams) (*WirelessV1Sim, error) { + return c.UpdateSimWithContext(context.TODO(), Sid, params) +} +func (c *ApiService) UpdateSimWithContext(ctx context.Context, Sid string, params *UpdateSimParams) (*WirelessV1Sim, error) { path := "/v1/Sims/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -429,7 +454,7 @@ func (c *ApiService) UpdateSim(Sid string, params *UpdateSimParams) (*WirelessV1 data.Set("AccountSid", *params.AccountSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.PostWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/wireless/v1/sims_data_sessions.go b/rest/wireless/v1/sims_data_sessions.go index 3133db4b4..2320a3f74 100644 --- a/rest/wireless/v1/sims_data_sessions.go +++ b/rest/wireless/v1/sims_data_sessions.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -42,6 +43,11 @@ func (params *ListDataSessionParams) SetLimit(Limit int) *ListDataSessionParams // Retrieve a single page of DataSession records from the API. Request is executed immediately. func (c *ApiService) PageDataSession(SimSid string, params *ListDataSessionParams, pageToken, pageNumber string) (*ListDataSessionResponse, error) { + return c.PageDataSessionWithContext(context.TODO(), SimSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of DataSession records from the API. Request is executed immediately. +func (c *ApiService) PageDataSessionWithContext(ctx context.Context, SimSid string, params *ListDataSessionParams, pageToken, pageNumber string) (*ListDataSessionResponse, error) { path := "/v1/Sims/{SimSid}/DataSessions" path = strings.Replace(path, "{"+"SimSid"+"}", SimSid, -1) @@ -62,7 +68,7 @@ func (c *ApiService) PageDataSession(SimSid string, params *ListDataSessionParam data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -79,7 +85,12 @@ func (c *ApiService) PageDataSession(SimSid string, params *ListDataSessionParam // Lists DataSession records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListDataSession(SimSid string, params *ListDataSessionParams) ([]WirelessV1DataSession, error) { - response, errors := c.StreamDataSession(SimSid, params) + return c.ListDataSessionWithContext(context.TODO(), SimSid, params) +} + +// Lists DataSession records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListDataSessionWithContext(ctx context.Context, SimSid string, params *ListDataSessionParams) ([]WirelessV1DataSession, error) { + response, errors := c.StreamDataSessionWithContext(ctx, SimSid, params) records := make([]WirelessV1DataSession, 0) for record := range response { @@ -95,6 +106,11 @@ func (c *ApiService) ListDataSession(SimSid string, params *ListDataSessionParam // Streams DataSession records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamDataSession(SimSid string, params *ListDataSessionParams) (chan WirelessV1DataSession, chan error) { + return c.StreamDataSessionWithContext(context.TODO(), SimSid, params) +} + +// Streams DataSession records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamDataSessionWithContext(ctx context.Context, SimSid string, params *ListDataSessionParams) (chan WirelessV1DataSession, chan error) { if params == nil { params = &ListDataSessionParams{} } @@ -103,19 +119,19 @@ func (c *ApiService) StreamDataSession(SimSid string, params *ListDataSessionPar recordChannel := make(chan WirelessV1DataSession, 1) errorChannel := make(chan error, 1) - response, err := c.PageDataSession(SimSid, params, "", "") + response, err := c.PageDataSessionWithContext(ctx, SimSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamDataSession(response, params, recordChannel, errorChannel) + go c.streamDataSessionWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamDataSession(response *ListDataSessionResponse, params *ListDataSessionParams, recordChannel chan WirelessV1DataSession, errorChannel chan error) { +func (c *ApiService) streamDataSessionWithContext(ctx context.Context, response *ListDataSessionResponse, params *ListDataSessionParams, recordChannel chan WirelessV1DataSession, errorChannel chan error) { curRecord := 1 for response != nil { @@ -130,7 +146,7 @@ func (c *ApiService) streamDataSession(response *ListDataSessionResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListDataSessionResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListDataSessionResponseWithContext) if err != nil { errorChannel <- err break @@ -145,11 +161,11 @@ func (c *ApiService) streamDataSession(response *ListDataSessionResponse, params close(errorChannel) } -func (c *ApiService) getNextListDataSessionResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListDataSessionResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/wireless/v1/sims_usage_records.go b/rest/wireless/v1/sims_usage_records.go index b1f597e90..4ea2ee992 100644 --- a/rest/wireless/v1/sims_usage_records.go +++ b/rest/wireless/v1/sims_usage_records.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -61,6 +62,11 @@ func (params *ListUsageRecordParams) SetLimit(Limit int) *ListUsageRecordParams // Retrieve a single page of UsageRecord records from the API. Request is executed immediately. func (c *ApiService) PageUsageRecord(SimSid string, params *ListUsageRecordParams, pageToken, pageNumber string) (*ListUsageRecordResponse, error) { + return c.PageUsageRecordWithContext(context.TODO(), SimSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of UsageRecord records from the API. Request is executed immediately. +func (c *ApiService) PageUsageRecordWithContext(ctx context.Context, SimSid string, params *ListUsageRecordParams, pageToken, pageNumber string) (*ListUsageRecordResponse, error) { path := "/v1/Sims/{SimSid}/UsageRecords" path = strings.Replace(path, "{"+"SimSid"+"}", SimSid, -1) @@ -90,7 +96,7 @@ func (c *ApiService) PageUsageRecord(SimSid string, params *ListUsageRecordParam data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -107,7 +113,12 @@ func (c *ApiService) PageUsageRecord(SimSid string, params *ListUsageRecordParam // Lists UsageRecord records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListUsageRecord(SimSid string, params *ListUsageRecordParams) ([]WirelessV1UsageRecord, error) { - response, errors := c.StreamUsageRecord(SimSid, params) + return c.ListUsageRecordWithContext(context.TODO(), SimSid, params) +} + +// Lists UsageRecord records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListUsageRecordWithContext(ctx context.Context, SimSid string, params *ListUsageRecordParams) ([]WirelessV1UsageRecord, error) { + response, errors := c.StreamUsageRecordWithContext(ctx, SimSid, params) records := make([]WirelessV1UsageRecord, 0) for record := range response { @@ -123,6 +134,11 @@ func (c *ApiService) ListUsageRecord(SimSid string, params *ListUsageRecordParam // Streams UsageRecord records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamUsageRecord(SimSid string, params *ListUsageRecordParams) (chan WirelessV1UsageRecord, chan error) { + return c.StreamUsageRecordWithContext(context.TODO(), SimSid, params) +} + +// Streams UsageRecord records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamUsageRecordWithContext(ctx context.Context, SimSid string, params *ListUsageRecordParams) (chan WirelessV1UsageRecord, chan error) { if params == nil { params = &ListUsageRecordParams{} } @@ -131,19 +147,19 @@ func (c *ApiService) StreamUsageRecord(SimSid string, params *ListUsageRecordPar recordChannel := make(chan WirelessV1UsageRecord, 1) errorChannel := make(chan error, 1) - response, err := c.PageUsageRecord(SimSid, params, "", "") + response, err := c.PageUsageRecordWithContext(ctx, SimSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUsageRecord(response, params, recordChannel, errorChannel) + go c.streamUsageRecordWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamUsageRecord(response *ListUsageRecordResponse, params *ListUsageRecordParams, recordChannel chan WirelessV1UsageRecord, errorChannel chan error) { +func (c *ApiService) streamUsageRecordWithContext(ctx context.Context, response *ListUsageRecordResponse, params *ListUsageRecordParams, recordChannel chan WirelessV1UsageRecord, errorChannel chan error) { curRecord := 1 for response != nil { @@ -158,7 +174,7 @@ func (c *ApiService) streamUsageRecord(response *ListUsageRecordResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUsageRecordResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListUsageRecordResponseWithContext) if err != nil { errorChannel <- err break @@ -173,11 +189,11 @@ func (c *ApiService) streamUsageRecord(response *ListUsageRecordResponse, params close(errorChannel) } -func (c *ApiService) getNextListUsageRecordResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUsageRecordResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/wireless/v1/usage_records.go b/rest/wireless/v1/usage_records.go index f6fe57903..46a3e20f3 100644 --- a/rest/wireless/v1/usage_records.go +++ b/rest/wireless/v1/usage_records.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -60,6 +61,11 @@ func (params *ListAccountUsageRecordParams) SetLimit(Limit int) *ListAccountUsag // Retrieve a single page of AccountUsageRecord records from the API. Request is executed immediately. func (c *ApiService) PageAccountUsageRecord(params *ListAccountUsageRecordParams, pageToken, pageNumber string) (*ListAccountUsageRecordResponse, error) { + return c.PageAccountUsageRecordWithContext(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of AccountUsageRecord records from the API. Request is executed immediately. +func (c *ApiService) PageAccountUsageRecordWithContext(ctx context.Context, params *ListAccountUsageRecordParams, pageToken, pageNumber string) (*ListAccountUsageRecordResponse, error) { path := "/v1/UsageRecords" data := url.Values{} @@ -87,7 +93,7 @@ func (c *ApiService) PageAccountUsageRecord(params *ListAccountUsageRecordParams data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.GetWithContext(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -104,7 +110,12 @@ func (c *ApiService) PageAccountUsageRecord(params *ListAccountUsageRecordParams // Lists AccountUsageRecord records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListAccountUsageRecord(params *ListAccountUsageRecordParams) ([]WirelessV1AccountUsageRecord, error) { - response, errors := c.StreamAccountUsageRecord(params) + return c.ListAccountUsageRecordWithContext(context.TODO(), params) +} + +// Lists AccountUsageRecord records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListAccountUsageRecordWithContext(ctx context.Context, params *ListAccountUsageRecordParams) ([]WirelessV1AccountUsageRecord, error) { + response, errors := c.StreamAccountUsageRecordWithContext(ctx, params) records := make([]WirelessV1AccountUsageRecord, 0) for record := range response { @@ -120,6 +131,11 @@ func (c *ApiService) ListAccountUsageRecord(params *ListAccountUsageRecordParams // Streams AccountUsageRecord records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamAccountUsageRecord(params *ListAccountUsageRecordParams) (chan WirelessV1AccountUsageRecord, chan error) { + return c.StreamAccountUsageRecordWithContext(context.TODO(), params) +} + +// Streams AccountUsageRecord records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamAccountUsageRecordWithContext(ctx context.Context, params *ListAccountUsageRecordParams) (chan WirelessV1AccountUsageRecord, chan error) { if params == nil { params = &ListAccountUsageRecordParams{} } @@ -128,19 +144,19 @@ func (c *ApiService) StreamAccountUsageRecord(params *ListAccountUsageRecordPara recordChannel := make(chan WirelessV1AccountUsageRecord, 1) errorChannel := make(chan error, 1) - response, err := c.PageAccountUsageRecord(params, "", "") + response, err := c.PageAccountUsageRecordWithContext(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamAccountUsageRecord(response, params, recordChannel, errorChannel) + go c.streamAccountUsageRecordWithContext(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamAccountUsageRecord(response *ListAccountUsageRecordResponse, params *ListAccountUsageRecordParams, recordChannel chan WirelessV1AccountUsageRecord, errorChannel chan error) { +func (c *ApiService) streamAccountUsageRecordWithContext(ctx context.Context, response *ListAccountUsageRecordResponse, params *ListAccountUsageRecordParams, recordChannel chan WirelessV1AccountUsageRecord, errorChannel chan error) { curRecord := 1 for response != nil { @@ -155,7 +171,7 @@ func (c *ApiService) streamAccountUsageRecord(response *ListAccountUsageRecordRe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListAccountUsageRecordResponse) + record, err := client.GetNextWithContext(ctx, c.baseURL, response, c.getNextListAccountUsageRecordResponseWithContext) if err != nil { errorChannel <- err break @@ -170,11 +186,11 @@ func (c *ApiService) streamAccountUsageRecord(response *ListAccountUsageRecordRe close(errorChannel) } -func (c *ApiService) getNextListAccountUsageRecordResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListAccountUsageRecordResponseWithContext(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.GetWithContext(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/twiml/messaging_response.go b/twiml/messaging_response.go index e36e96fd6..06a6ba772 100644 --- a/twiml/messaging_response.go +++ b/twiml/messaging_response.go @@ -13,7 +13,7 @@ func Messages(verbs []Element) (string, error) { return ToXML(doc) } -//MessagingRedirect TwiML Verb +// MessagingRedirect TwiML Verb type MessagingRedirect struct { // url: Redirect URL // method: Redirect URL method @@ -43,7 +43,7 @@ func (m MessagingRedirect) GetInnerElements() []Element { return m.InnerElements } -//MessagingMessage TwiML Verb +// MessagingMessage TwiML Verb type MessagingMessage struct { // body: Message Body // to: Phone Number to send Message to @@ -85,7 +85,7 @@ func (m MessagingMessage) GetInnerElements() []Element { return m.InnerElements } -//MessagingMedia TwiML Noun +// MessagingMedia TwiML Noun type MessagingMedia struct { // url: Media URL // OptionalAttributes: additional attributes @@ -110,7 +110,7 @@ func (m MessagingMedia) GetInnerElements() []Element { return m.InnerElements } -//MessagingBody TwiML Noun +// MessagingBody TwiML Noun type MessagingBody struct { // message: Message Body // OptionalAttributes: additional attributes diff --git a/twiml/voice_response.go b/twiml/voice_response.go index d7e3c9ac1..65e332ace 100644 --- a/twiml/voice_response.go +++ b/twiml/voice_response.go @@ -13,7 +13,7 @@ func Voice(verbs []Element) (string, error) { return ToXML(doc) } -//VoiceRefer TwiML Verb +// VoiceRefer TwiML Verb type VoiceRefer struct { // action: Action URL // method: Action URL method @@ -44,7 +44,7 @@ func (m VoiceRefer) GetInnerElements() []Element { return m.InnerElements } -//VoiceReferSip TwiML Noun used in +// VoiceReferSip TwiML Noun used in type VoiceReferSip struct { // sip_url: SIP URL // OptionalAttributes: additional attributes @@ -69,7 +69,7 @@ func (m VoiceReferSip) GetInnerElements() []Element { return m.InnerElements } -//VoiceStop TwiML Verb +// VoiceStop TwiML Verb type VoiceStop struct { // OptionalAttributes: additional attributes InnerElements []Element @@ -92,7 +92,7 @@ func (m VoiceStop) GetInnerElements() []Element { return m.InnerElements } -//VoiceTranscription TwiML Noun +// VoiceTranscription TwiML Noun type VoiceTranscription struct { // name: Friendly name given to the Transcription // track: Track to be analyze by the provider @@ -159,7 +159,7 @@ func (m VoiceTranscription) GetInnerElements() []Element { return m.InnerElements } -//VoiceParameter TwiML Noun +// VoiceParameter TwiML Noun type VoiceParameter struct { // name: The name of the custom parameter // value: The value of the custom parameter @@ -190,7 +190,7 @@ func (m VoiceParameter) GetInnerElements() []Element { return m.InnerElements } -//VoiceConfig TwiML Noun +// VoiceConfig TwiML Noun type VoiceConfig struct { // name: The name of the custom config // value: The value of the custom config @@ -221,7 +221,7 @@ func (m VoiceConfig) GetInnerElements() []Element { return m.InnerElements } -//VoiceSipRec TwiML Noun +// VoiceSipRec TwiML Noun type VoiceSipRec struct { // name: Friendly name given to SIPREC // connector_name: Unique name for Connector @@ -261,7 +261,7 @@ func (m VoiceSipRec) GetInnerElements() []Element { return m.InnerElements } -//VoiceStream TwiML Noun +// VoiceStream TwiML Noun type VoiceStream struct { // name: Friendly name given to the Stream // connector_name: Unique name for Stream Connector @@ -304,7 +304,7 @@ func (m VoiceStream) GetInnerElements() []Element { return m.InnerElements } -//VoiceStart TwiML Verb +// VoiceStart TwiML Verb type VoiceStart struct { // action: Action URL // method: Action URL method @@ -335,7 +335,7 @@ func (m VoiceStart) GetInnerElements() []Element { return m.InnerElements } -//VoicePrompt Twiml Verb +// VoicePrompt Twiml Verb type VoicePrompt struct { // for_: Name of the payment source data element // error_type: Type of error @@ -375,7 +375,7 @@ func (m VoicePrompt) GetInnerElements() []Element { return m.InnerElements } -//VoicePause TwiML Verb +// VoicePause TwiML Verb type VoicePause struct { // length: Length in seconds to pause // OptionalAttributes: additional attributes @@ -403,7 +403,7 @@ func (m VoicePause) GetInnerElements() []Element { return m.InnerElements } -//VoicePlay TwiML Verb +// VoicePlay TwiML Verb type VoicePlay struct { // url: Media URL // loop: Times to loop media @@ -436,7 +436,7 @@ func (m VoicePlay) GetInnerElements() []Element { return m.InnerElements } -//VoiceSay TwiML Verb +// VoiceSay TwiML Verb type VoiceSay struct { // message: Message to say // voice: Voice to use @@ -472,7 +472,7 @@ func (m VoiceSay) GetInnerElements() []Element { return m.InnerElements } -//VoiceW Improving Pronunciation by Specifying Parts of Speech in +// VoiceW Improving Pronunciation by Specifying Parts of Speech in type VoiceW struct { // words: Words to speak // role: Customize the pronunciation of words by specifying the word’s part of speech or alternate meaning @@ -502,7 +502,7 @@ func (m VoiceW) GetInnerElements() []Element { return m.InnerElements } -//VoiceSub Pronouncing Acronyms and Abbreviations in +// VoiceSub Pronouncing Acronyms and Abbreviations in type VoiceSub struct { // words: Words to be substituted // alias: Substitute a different word (or pronunciation) for selected text such as an acronym or abbreviation @@ -532,7 +532,7 @@ func (m VoiceSub) GetInnerElements() []Element { return m.InnerElements } -//VoiceSayAs Controlling How Special Types of Words Are Spoken in +// VoiceSayAs Controlling How Special Types of Words Are Spoken in type VoiceSayAs struct { // words: Words to be interpreted // interpret-as: Specify the type of words are spoken @@ -565,7 +565,7 @@ func (m VoiceSayAs) GetInnerElements() []Element { return m.InnerElements } -//VoiceProsody Controling Volume, Speaking Rate, and Pitch in +// VoiceProsody Controling Volume, Speaking Rate, and Pitch in type VoiceProsody struct { // words: Words to speak // volume: Specify the volume, available values: default, silent, x-soft, soft, medium, loud, x-loud, +ndB, -ndB @@ -601,7 +601,7 @@ func (m VoiceProsody) GetInnerElements() []Element { return m.InnerElements } -//VoiceS Adding A Pause Between Sentences in +// VoiceS Adding A Pause Between Sentences in type VoiceS struct { // words: Words to speak // OptionalAttributes: additional attributes @@ -626,7 +626,7 @@ func (m VoiceS) GetInnerElements() []Element { return m.InnerElements } -//VoicePhoneme Using Phonetic Pronunciation in +// VoicePhoneme Using Phonetic Pronunciation in type VoicePhoneme struct { // words: Words to speak // alphabet: Specify the phonetic alphabet @@ -659,7 +659,7 @@ func (m VoicePhoneme) GetInnerElements() []Element { return m.InnerElements } -//VoiceLang Specifying Another Language for Specific Words in +// VoiceLang Specifying Another Language for Specific Words in type VoiceLang struct { // words: Words to speak // xml:lang: Specify the language @@ -689,7 +689,7 @@ func (m VoiceLang) GetInnerElements() []Element { return m.InnerElements } -//VoiceP Adding a Pause Between Paragraphs in +// VoiceP Adding a Pause Between Paragraphs in type VoiceP struct { // words: Words to speak // OptionalAttributes: additional attributes @@ -714,7 +714,7 @@ func (m VoiceP) GetInnerElements() []Element { return m.InnerElements } -//VoiceEmphasis Emphasizing Words in +// VoiceEmphasis Emphasizing Words in type VoiceEmphasis struct { // words: Words to emphasize // level: Specify the degree of emphasis @@ -744,7 +744,7 @@ func (m VoiceEmphasis) GetInnerElements() []Element { return m.InnerElements } -//VoiceBreak Adding a Pause in +// VoiceBreak Adding a Pause in type VoiceBreak struct { // strength: Set a pause based on strength // time: Set a pause to a specific length of time in seconds or milliseconds, available values: [number]s, [number]ms @@ -775,7 +775,7 @@ func (m VoiceBreak) GetInnerElements() []Element { return m.InnerElements } -//VoicePay Twiml Verb +// VoicePay Twiml Verb type VoicePay struct { // input: Input type Twilio should accept // action: Action URL @@ -854,7 +854,7 @@ func (m VoicePay) GetInnerElements() []Element { return m.InnerElements } -//VoiceSms TwiML Noun +// VoiceSms TwiML Noun type VoiceSms struct { // message: Message body // to: Number to send message to @@ -896,7 +896,7 @@ func (m VoiceSms) GetInnerElements() []Element { return m.InnerElements } -//VoiceReject TwiML Verb +// VoiceReject TwiML Verb type VoiceReject struct { // reason: Rejection reason // OptionalAttributes: additional attributes @@ -924,7 +924,7 @@ func (m VoiceReject) GetInnerElements() []Element { return m.InnerElements } -//VoiceRedirect TwiML Verb +// VoiceRedirect TwiML Verb type VoiceRedirect struct { // url: Redirect URL // method: Redirect URL method @@ -954,7 +954,7 @@ func (m VoiceRedirect) GetInnerElements() []Element { return m.InnerElements } -//VoiceRecord TwiML Verb +// VoiceRecord TwiML Verb type VoiceRecord struct { // action: Action URL // method: Action URL method @@ -1015,7 +1015,7 @@ func (m VoiceRecord) GetInnerElements() []Element { return m.InnerElements } -//VoiceQueue TwiML Noun +// VoiceQueue TwiML Noun type VoiceQueue struct { // name: Queue name // url: Action URL @@ -1054,7 +1054,7 @@ func (m VoiceQueue) GetInnerElements() []Element { return m.InnerElements } -//VoiceLeave TwiML Verb +// VoiceLeave TwiML Verb type VoiceLeave struct { // OptionalAttributes: additional attributes InnerElements []Element @@ -1077,7 +1077,7 @@ func (m VoiceLeave) GetInnerElements() []Element { return m.InnerElements } -//VoiceHangup TwiML Verb +// VoiceHangup TwiML Verb type VoiceHangup struct { // OptionalAttributes: additional attributes InnerElements []Element @@ -1100,7 +1100,7 @@ func (m VoiceHangup) GetInnerElements() []Element { return m.InnerElements } -//VoiceGather TwiML Verb +// VoiceGather TwiML Verb type VoiceGather struct { // input: Input type Twilio should accept // action: Action URL @@ -1179,7 +1179,7 @@ func (m VoiceGather) GetInnerElements() []Element { return m.InnerElements } -//VoiceEnqueue TwiML Noun +// VoiceEnqueue TwiML Noun type VoiceEnqueue struct { // name: Friendly name // action: Action URL @@ -1224,7 +1224,7 @@ func (m VoiceEnqueue) GetInnerElements() []Element { return m.InnerElements } -//VoiceTask TwiML Noun +// VoiceTask TwiML Noun type VoiceTask struct { // body: TaskRouter task attributes // priority: Task priority @@ -1257,7 +1257,7 @@ func (m VoiceTask) GetInnerElements() []Element { return m.InnerElements } -//VoiceEcho TwiML Verb +// VoiceEcho TwiML Verb type VoiceEcho struct { // OptionalAttributes: additional attributes InnerElements []Element @@ -1280,7 +1280,7 @@ func (m VoiceEcho) GetInnerElements() []Element { return m.InnerElements } -//VoiceDial TwiML Verb +// VoiceDial TwiML Verb type VoiceDial struct { // number: Phone number to dial // action: Action URL @@ -1361,7 +1361,7 @@ func (m VoiceDial) GetInnerElements() []Element { return m.InnerElements } -//VoiceApplication TwiML Noun +// VoiceApplication TwiML Noun type VoiceApplication struct { // application_sid: Application sid // url: TwiML URL @@ -1409,7 +1409,7 @@ func (m VoiceApplication) GetInnerElements() []Element { return m.InnerElements } -//VoiceApplicationSid TwiML Noun +// VoiceApplicationSid TwiML Noun type VoiceApplicationSid struct { // sid: Application sid to dial // OptionalAttributes: additional attributes @@ -1434,7 +1434,7 @@ func (m VoiceApplicationSid) GetInnerElements() []Element { return m.InnerElements } -//VoiceSip TwiML Noun +// VoiceSip TwiML Noun type VoiceSip struct { // sip_url: SIP URL // username: SIP Username @@ -1503,7 +1503,7 @@ func (m VoiceSip) GetInnerElements() []Element { return m.InnerElements } -//VoiceSim TwiML Noun +// VoiceSim TwiML Noun type VoiceSim struct { // sim_sid: SIM SID // OptionalAttributes: additional attributes @@ -1528,7 +1528,7 @@ func (m VoiceSim) GetInnerElements() []Element { return m.InnerElements } -//VoiceNumber TwiML Noun +// VoiceNumber TwiML Noun type VoiceNumber struct { // phone_number: Phone Number to dial // send_digits: DTMF tones to play when the call is answered @@ -1597,7 +1597,7 @@ func (m VoiceNumber) GetInnerElements() []Element { return m.InnerElements } -//VoiceConference TwiML Noun +// VoiceConference TwiML Noun type VoiceConference struct { // name: Conference name // muted: Join the conference muted @@ -1684,7 +1684,7 @@ func (m VoiceConference) GetInnerElements() []Element { return m.InnerElements } -//VoiceClient TwiML Noun +// VoiceClient TwiML Noun type VoiceClient struct { // identity: Client identity // url: Client URL @@ -1726,7 +1726,7 @@ func (m VoiceClient) GetInnerElements() []Element { return m.InnerElements } -//VoiceIdentity TwiML Noun +// VoiceIdentity TwiML Noun type VoiceIdentity struct { // client_identity: Identity of the client to dial // OptionalAttributes: additional attributes @@ -1751,7 +1751,7 @@ func (m VoiceIdentity) GetInnerElements() []Element { return m.InnerElements } -//VoiceConnect TwiML Verb +// VoiceConnect TwiML Verb type VoiceConnect struct { // action: Action URL // method: Action URL method @@ -1782,7 +1782,7 @@ func (m VoiceConnect) GetInnerElements() []Element { return m.InnerElements } -//VoiceAssistant TwiML Noun +// VoiceAssistant TwiML Noun type VoiceAssistant struct { // id: The assistant ID of the AI Assistant // language: Language to be used for both text-to-speech and transcription @@ -1870,7 +1870,7 @@ func (m VoiceAssistant) GetInnerElements() []Element { return m.InnerElements } -//VoiceLanguage TwiML Noun +// VoiceLanguage TwiML Noun type VoiceLanguage struct { // code: Language code of this language setting is for // tts_provider: Provider to be used for text-to-speech of this language @@ -1910,7 +1910,7 @@ func (m VoiceLanguage) GetInnerElements() []Element { return m.InnerElements } -//VoiceConversationRelay TwiML Noun +// VoiceConversationRelay TwiML Noun type VoiceConversationRelay struct { // url: URL of the remote service where the session is connected to // language: Language to be used for both text-to-speech and transcription @@ -1998,7 +1998,7 @@ func (m VoiceConversationRelay) GetInnerElements() []Element { return m.InnerElements } -//VoiceConversation TwiML Noun +// VoiceConversation TwiML Noun type VoiceConversation struct { // service_instance_sid: Service instance Sid // inbound_autocreation: Inbound autocreation @@ -2065,7 +2065,7 @@ func (m VoiceConversation) GetInnerElements() []Element { return m.InnerElements } -//VoiceVirtualAgent TwiML Noun +// VoiceVirtualAgent TwiML Noun type VoiceVirtualAgent struct { // connector_name: Defines the conversation profile Dialogflow needs to use // language: Language to be used by Dialogflow to transcribe speech @@ -2105,7 +2105,7 @@ func (m VoiceVirtualAgent) GetInnerElements() []Element { return m.InnerElements } -//VoiceAutopilot TwiML Noun +// VoiceAutopilot TwiML Noun type VoiceAutopilot struct { // name: Autopilot assistant sid or unique name // OptionalAttributes: additional attributes @@ -2130,7 +2130,7 @@ func (m VoiceAutopilot) GetInnerElements() []Element { return m.InnerElements } -//VoiceRoom TwiML Noun +// VoiceRoom TwiML Noun type VoiceRoom struct { // name: Room name // participant_identity: Participant identity when connecting to the Room