diff --git a/cluster_test.go b/cluster_test.go index 39a34628f..29dd7a9fe 100644 --- a/cluster_test.go +++ b/cluster_test.go @@ -4,12 +4,13 @@ package twilio import ( + "os" + "testing" + "github.com/stretchr/testify/assert" Api "github.com/twilio/twilio-go/rest/api/v2010" ChatV2 "github.com/twilio/twilio-go/rest/chat/v2" EventsV1 "github.com/twilio/twilio-go/rest/events/v1" - "os" - "testing" ) var from string diff --git a/rest/accounts/v1/api_service.go b/rest/accounts/v1/api_service.go index 4ed284a19..2b5cefcef 100644 --- a/rest/accounts/v1/api_service.go +++ b/rest/accounts/v1/api_service.go @@ -20,10 +20,14 @@ import ( type ApiService struct { baseURL string - requestHandler *twilio.RequestHandler + requestHandler *twilio.RequestHandlerWithCtx } func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { + return NewApiServiceWithCtx(twilio.UpgradeRequestHandler(requestHandler)) +} + +func NewApiServiceWithCtx(requestHandler *twilio.RequestHandlerWithCtx) *ApiService { return &ApiService{ requestHandler: requestHandler, baseURL: "https://accounts.twilio.com", @@ -33,3 +37,7 @@ func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { func NewApiServiceWithClient(client twilio.BaseClient) *ApiService { return NewApiService(twilio.NewRequestHandler(client)) } + +func NewApiServiceWithClientWithCtx(client twilio.BaseClientWithCtx) *ApiService { + return NewApiServiceWithCtx(twilio.NewRequestHandlerWithCtx(client)) +} diff --git a/rest/accounts/v1/auth_tokens_promote.go b/rest/accounts/v1/auth_tokens_promote.go index 1f1f50146..b5f33bd54 100644 --- a/rest/accounts/v1/auth_tokens_promote.go +++ b/rest/accounts/v1/auth_tokens_promote.go @@ -15,18 +15,24 @@ 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.UpdateAuthTokenPromotionWithCtx(context.TODO()) +} + +// 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) UpdateAuthTokenPromotionWithCtx(ctx context.Context) (*AccountsV1AuthTokenPromotion, error) { path := "/v1/AuthTokens/Promote" data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 a187a99d1..c352c687e 100644 --- a/rest/accounts/v1/auth_tokens_secondary.go +++ b/rest/accounts/v1/auth_tokens_secondary.go @@ -15,18 +15,24 @@ package openapi import ( + "context" "encoding/json" "net/url" ) // Create a new secondary Auth Token func (c *ApiService) CreateSecondaryAuthToken() (*AccountsV1SecondaryAuthToken, error) { + return c.CreateSecondaryAuthTokenWithCtx(context.TODO()) +} + +// Create a new secondary Auth Token +func (c *ApiService) CreateSecondaryAuthTokenWithCtx(ctx context.Context) (*AccountsV1SecondaryAuthToken, error) { path := "/v1/AuthTokens/Secondary" data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -43,12 +49,17 @@ func (c *ApiService) CreateSecondaryAuthToken() (*AccountsV1SecondaryAuthToken, // Delete the secondary Auth Token from your account func (c *ApiService) DeleteSecondaryAuthToken() error { + return c.DeleteSecondaryAuthTokenWithCtx(context.TODO()) +} + +// Delete the secondary Auth Token from your account +func (c *ApiService) DeleteSecondaryAuthTokenWithCtx(ctx context.Context) error { path := "/v1/AuthTokens/Secondary" data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } diff --git a/rest/accounts/v1/credentials_aws.go b/rest/accounts/v1/credentials_aws.go index 3ec1b2945..e6e409d06 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,11 @@ func (params *CreateCredentialAwsParams) SetAccountSid(AccountSid string) *Creat // Create a new AWS Credential func (c *ApiService) CreateCredentialAws(params *CreateCredentialAwsParams) (*AccountsV1CredentialAws, error) { + return c.CreateCredentialAwsWithCtx(context.TODO(), params) +} + +// Create a new AWS Credential +func (c *ApiService) CreateCredentialAwsWithCtx(ctx context.Context, params *CreateCredentialAwsParams) (*AccountsV1CredentialAws, error) { path := "/v1/Credentials/AWS" data := url.Values{} @@ -63,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -80,13 +86,18 @@ func (c *ApiService) CreateCredentialAws(params *CreateCredentialAwsParams) (*Ac // Delete a Credential from your account func (c *ApiService) DeleteCredentialAws(Sid string) error { + return c.DeleteCredentialAwsWithCtx(context.TODO(), Sid) +} + +// Delete a Credential from your account +func (c *ApiService) DeleteCredentialAwsWithCtx(ctx context.Context, Sid string) error { path := "/v1/Credentials/AWS/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -98,13 +109,18 @@ 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.FetchCredentialAwsWithCtx(context.TODO(), Sid) +} + +// Fetch the AWS credentials specified by the provided Credential Sid +func (c *ApiService) FetchCredentialAwsWithCtx(ctx context.Context, Sid string) (*AccountsV1CredentialAws, error) { path := "/v1/Credentials/AWS/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -138,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.PageCredentialAwsWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of CredentialAws records from the API. Request is executed immediately. +func (c *ApiService) PageCredentialAwsWithCtx(ctx context.Context, params *ListCredentialAwsParams, pageToken, pageNumber string) (*ListCredentialAwsResponse, error) { path := "/v1/Credentials/AWS" data := url.Values{} @@ -154,7 +175,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -171,7 +192,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.ListCredentialAwsWithCtx(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) ListCredentialAwsWithCtx(ctx context.Context, params *ListCredentialAwsParams) ([]AccountsV1CredentialAws, error) { + response, errors := c.StreamCredentialAwsWithCtx(ctx, params) records := make([]AccountsV1CredentialAws, 0) for record := range response { @@ -187,6 +213,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.StreamCredentialAwsWithCtx(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) StreamCredentialAwsWithCtx(ctx context.Context, params *ListCredentialAwsParams) (chan AccountsV1CredentialAws, chan error) { if params == nil { params = &ListCredentialAwsParams{} } @@ -195,19 +226,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.PageCredentialAwsWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamCredentialAws(response, params, recordChannel, errorChannel) + go c.streamCredentialAws(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) streamCredentialAws(ctx context.Context, response *ListCredentialAwsResponse, params *ListCredentialAwsParams, recordChannel chan AccountsV1CredentialAws, errorChannel chan error) { curRecord := 1 for response != nil { @@ -222,7 +253,7 @@ func (c *ApiService) streamCredentialAws(response *ListCredentialAwsResponse, pa } } - record, err := client.GetNext(c.baseURL, response, c.getNextListCredentialAwsResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListCredentialAwsResponse) if err != nil { errorChannel <- err break @@ -237,11 +268,11 @@ func (c *ApiService) streamCredentialAws(response *ListCredentialAwsResponse, pa close(errorChannel) } -func (c *ApiService) getNextListCredentialAwsResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListCredentialAwsResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -268,6 +299,11 @@ 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.UpdateCredentialAwsWithCtx(context.TODO(), Sid, params) +} + +// Modify the properties of a given Account +func (c *ApiService) UpdateCredentialAwsWithCtx(ctx context.Context, Sid string, params *UpdateCredentialAwsParams) (*AccountsV1CredentialAws, error) { path := "/v1/Credentials/AWS/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -278,7 +314,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.Post(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 8e78888e7..dfb07363c 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,11 @@ func (params *CreateCredentialPublicKeyParams) SetAccountSid(AccountSid string) // Create a new Public Key Credential func (c *ApiService) CreateCredentialPublicKey(params *CreateCredentialPublicKeyParams) (*AccountsV1CredentialPublicKey, error) { + return c.CreateCredentialPublicKeyWithCtx(context.TODO(), params) +} + +// Create a new Public Key Credential +func (c *ApiService) CreateCredentialPublicKeyWithCtx(ctx context.Context, params *CreateCredentialPublicKeyParams) (*AccountsV1CredentialPublicKey, error) { path := "/v1/Credentials/PublicKeys" data := url.Values{} @@ -63,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -80,13 +86,18 @@ func (c *ApiService) CreateCredentialPublicKey(params *CreateCredentialPublicKey // Delete a Credential from your account func (c *ApiService) DeleteCredentialPublicKey(Sid string) error { + return c.DeleteCredentialPublicKeyWithCtx(context.TODO(), Sid) +} + +// Delete a Credential from your account +func (c *ApiService) DeleteCredentialPublicKeyWithCtx(ctx context.Context, Sid string) error { path := "/v1/Credentials/PublicKeys/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -98,13 +109,18 @@ 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.FetchCredentialPublicKeyWithCtx(context.TODO(), Sid) +} + +// Fetch the public key specified by the provided Credential Sid +func (c *ApiService) FetchCredentialPublicKeyWithCtx(ctx context.Context, Sid string) (*AccountsV1CredentialPublicKey, error) { path := "/v1/Credentials/PublicKeys/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -138,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.PageCredentialPublicKeyWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of CredentialPublicKey records from the API. Request is executed immediately. +func (c *ApiService) PageCredentialPublicKeyWithCtx(ctx context.Context, params *ListCredentialPublicKeyParams, pageToken, pageNumber string) (*ListCredentialPublicKeyResponse, error) { path := "/v1/Credentials/PublicKeys" data := url.Values{} @@ -154,7 +175,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -171,7 +192,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.ListCredentialPublicKeyWithCtx(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) ListCredentialPublicKeyWithCtx(ctx context.Context, params *ListCredentialPublicKeyParams) ([]AccountsV1CredentialPublicKey, error) { + response, errors := c.StreamCredentialPublicKeyWithCtx(ctx, params) records := make([]AccountsV1CredentialPublicKey, 0) for record := range response { @@ -187,6 +213,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.StreamCredentialPublicKeyWithCtx(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) StreamCredentialPublicKeyWithCtx(ctx context.Context, params *ListCredentialPublicKeyParams) (chan AccountsV1CredentialPublicKey, chan error) { if params == nil { params = &ListCredentialPublicKeyParams{} } @@ -195,19 +226,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.PageCredentialPublicKeyWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamCredentialPublicKey(response, params, recordChannel, errorChannel) + go c.streamCredentialPublicKey(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) streamCredentialPublicKey(ctx context.Context, response *ListCredentialPublicKeyResponse, params *ListCredentialPublicKeyParams, recordChannel chan AccountsV1CredentialPublicKey, errorChannel chan error) { curRecord := 1 for response != nil { @@ -222,7 +253,7 @@ func (c *ApiService) streamCredentialPublicKey(response *ListCredentialPublicKey } } - record, err := client.GetNext(c.baseURL, response, c.getNextListCredentialPublicKeyResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListCredentialPublicKeyResponse) if err != nil { errorChannel <- err break @@ -237,11 +268,11 @@ func (c *ApiService) streamCredentialPublicKey(response *ListCredentialPublicKey close(errorChannel) } -func (c *ApiService) getNextListCredentialPublicKeyResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListCredentialPublicKeyResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -268,6 +299,11 @@ 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.UpdateCredentialPublicKeyWithCtx(context.TODO(), Sid, params) +} + +// Modify the properties of a given Account +func (c *ApiService) UpdateCredentialPublicKeyWithCtx(ctx context.Context, Sid string, params *UpdateCredentialPublicKeyParams) (*AccountsV1CredentialPublicKey, error) { path := "/v1/Credentials/PublicKeys/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -278,7 +314,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.Post(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 9d72732d9..d5c1e96f2 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,11 @@ 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.CreateAccountWithCtx(context.TODO(), params) +} + +// Create a new Twilio Subaccount from the account making the request +func (c *ApiService) CreateAccountWithCtx(ctx context.Context, params *CreateAccountParams) (*ApiV2010Account, error) { path := "/2010-04-01/Accounts.json" data := url.Values{} @@ -45,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -62,13 +68,18 @@ 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.FetchAccountWithCtx(context.TODO(), Sid) +} + +// Fetch the account specified by the provided Account Sid +func (c *ApiService) FetchAccountWithCtx(ctx context.Context, Sid string) (*ApiV2010Account, error) { path := "/2010-04-01/Accounts/{Sid}.json" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -114,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.PageAccountWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Account records from the API. Request is executed immediately. +func (c *ApiService) PageAccountWithCtx(ctx context.Context, params *ListAccountParams, pageToken, pageNumber string) (*ListAccountResponse, error) { path := "/2010-04-01/Accounts.json" data := url.Values{} @@ -136,7 +152,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -153,7 +169,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.ListAccountWithCtx(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) ListAccountWithCtx(ctx context.Context, params *ListAccountParams) ([]ApiV2010Account, error) { + response, errors := c.StreamAccountWithCtx(ctx, params) records := make([]ApiV2010Account, 0) for record := range response { @@ -169,6 +190,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.StreamAccountWithCtx(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) StreamAccountWithCtx(ctx context.Context, params *ListAccountParams) (chan ApiV2010Account, chan error) { if params == nil { params = &ListAccountParams{} } @@ -177,19 +203,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.PageAccountWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamAccount(response, params, recordChannel, errorChannel) + go c.streamAccount(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) streamAccount(ctx context.Context, response *ListAccountResponse, params *ListAccountParams, recordChannel chan ApiV2010Account, errorChannel chan error) { curRecord := 1 for response != nil { @@ -204,7 +230,7 @@ func (c *ApiService) streamAccount(response *ListAccountResponse, params *ListAc } } - record, err := client.GetNext(c.baseURL, response, c.getNextListAccountResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListAccountResponse) if err != nil { errorChannel <- err break @@ -219,11 +245,11 @@ func (c *ApiService) streamAccount(response *ListAccountResponse, params *ListAc close(errorChannel) } -func (c *ApiService) getNextListAccountResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListAccountResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -256,6 +282,11 @@ 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.UpdateAccountWithCtx(context.TODO(), Sid, params) +} + +// Modify the properties of a given Account +func (c *ApiService) UpdateAccountWithCtx(ctx context.Context, Sid string, params *UpdateAccountParams) (*ApiV2010Account, error) { path := "/2010-04-01/Accounts/{Sid}.json" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -269,7 +300,7 @@ func (c *ApiService) UpdateAccount(Sid string, params *UpdateAccountParams) (*Ap data.Set("Status", *params.Status) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 578bd7b84..1fefaf860 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" @@ -90,6 +91,11 @@ func (params *CreateAddressParams) SetAutoCorrectAddress(AutoCorrectAddress bool // func (c *ApiService) CreateAddress(params *CreateAddressParams) (*ApiV2010Address, error) { + return c.CreateAddressWithCtx(context.TODO(), params) +} + +// +func (c *ApiService) CreateAddressWithCtx(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) @@ -128,7 +134,7 @@ func (c *ApiService) CreateAddress(params *CreateAddressParams) (*ApiV2010Addres data.Set("AutoCorrectAddress", fmt.Sprint(*params.AutoCorrectAddress)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -156,6 +162,11 @@ func (params *DeleteAddressParams) SetPathAccountSid(PathAccountSid string) *Del // func (c *ApiService) DeleteAddress(Sid string, params *DeleteAddressParams) error { + return c.DeleteAddressWithCtx(context.TODO(), Sid, params) +} + +// +func (c *ApiService) DeleteAddressWithCtx(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) @@ -167,7 +178,7 @@ func (c *ApiService) DeleteAddress(Sid string, params *DeleteAddressParams) erro data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -190,6 +201,11 @@ func (params *FetchAddressParams) SetPathAccountSid(PathAccountSid string) *Fetc // func (c *ApiService) FetchAddress(Sid string, params *FetchAddressParams) (*ApiV2010Address, error) { + return c.FetchAddressWithCtx(context.TODO(), Sid, params) +} + +// +func (c *ApiService) FetchAddressWithCtx(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) @@ -201,7 +217,7 @@ func (c *ApiService) FetchAddress(Sid string, params *FetchAddressParams) (*ApiV data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -259,6 +275,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.PageAddressWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Address records from the API. Request is executed immediately. +func (c *ApiService) PageAddressWithCtx(ctx context.Context, params *ListAddressParams, pageToken, pageNumber string) (*ListAddressResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/Addresses.json" if params != nil && params.PathAccountSid != nil { @@ -290,7 +311,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -307,7 +328,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.ListAddressWithCtx(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) ListAddressWithCtx(ctx context.Context, params *ListAddressParams) ([]ApiV2010Address, error) { + response, errors := c.StreamAddressWithCtx(ctx, params) records := make([]ApiV2010Address, 0) for record := range response { @@ -323,6 +349,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.StreamAddressWithCtx(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) StreamAddressWithCtx(ctx context.Context, params *ListAddressParams) (chan ApiV2010Address, chan error) { if params == nil { params = &ListAddressParams{} } @@ -331,19 +362,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.PageAddressWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamAddress(response, params, recordChannel, errorChannel) + go c.streamAddress(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) streamAddress(ctx context.Context, response *ListAddressResponse, params *ListAddressParams, recordChannel chan ApiV2010Address, errorChannel chan error) { curRecord := 1 for response != nil { @@ -358,7 +389,7 @@ func (c *ApiService) streamAddress(response *ListAddressResponse, params *ListAd } } - record, err := client.GetNext(c.baseURL, response, c.getNextListAddressResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListAddressResponse) if err != nil { errorChannel <- err break @@ -373,11 +404,11 @@ func (c *ApiService) streamAddress(response *ListAddressResponse, params *ListAd close(errorChannel) } -func (c *ApiService) getNextListAddressResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListAddressResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -452,6 +483,11 @@ func (params *UpdateAddressParams) SetAutoCorrectAddress(AutoCorrectAddress bool // func (c *ApiService) UpdateAddress(Sid string, params *UpdateAddressParams) (*ApiV2010Address, error) { + return c.UpdateAddressWithCtx(context.TODO(), Sid, params) +} + +// +func (c *ApiService) UpdateAddressWithCtx(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) @@ -488,7 +524,7 @@ func (c *ApiService) UpdateAddress(Sid string, params *UpdateAddressParams) (*Ap data.Set("AutoCorrectAddress", fmt.Sprint(*params.AutoCorrectAddress)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 f1cf03f13..d3d3fc4e6 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.PageDependentPhoneNumberWithCtx(context.TODO(), AddressSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of DependentPhoneNumber records from the API. Request is executed immediately. +func (c *ApiService) PageDependentPhoneNumberWithCtx(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 { @@ -71,7 +77,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -88,7 +94,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.ListDependentPhoneNumberWithCtx(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) ListDependentPhoneNumberWithCtx(ctx context.Context, AddressSid string, params *ListDependentPhoneNumberParams) ([]ApiV2010DependentPhoneNumber, error) { + response, errors := c.StreamDependentPhoneNumberWithCtx(ctx, AddressSid, params) records := make([]ApiV2010DependentPhoneNumber, 0) for record := range response { @@ -104,6 +115,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.StreamDependentPhoneNumberWithCtx(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) StreamDependentPhoneNumberWithCtx(ctx context.Context, AddressSid string, params *ListDependentPhoneNumberParams) (chan ApiV2010DependentPhoneNumber, chan error) { if params == nil { params = &ListDependentPhoneNumberParams{} } @@ -112,19 +128,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.PageDependentPhoneNumberWithCtx(ctx, AddressSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamDependentPhoneNumber(response, params, recordChannel, errorChannel) + go c.streamDependentPhoneNumber(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) streamDependentPhoneNumber(ctx context.Context, response *ListDependentPhoneNumberResponse, params *ListDependentPhoneNumberParams, recordChannel chan ApiV2010DependentPhoneNumber, errorChannel chan error) { curRecord := 1 for response != nil { @@ -139,7 +155,7 @@ func (c *ApiService) streamDependentPhoneNumber(response *ListDependentPhoneNumb } } - record, err := client.GetNext(c.baseURL, response, c.getNextListDependentPhoneNumberResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListDependentPhoneNumberResponse) if err != nil { errorChannel <- err break @@ -154,11 +170,11 @@ func (c *ApiService) streamDependentPhoneNumber(response *ListDependentPhoneNumb close(errorChannel) } -func (c *ApiService) getNextListDependentPhoneNumberResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListDependentPhoneNumberResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 48beb049b..09e1f9e2b 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" @@ -126,6 +127,11 @@ func (params *CreateApplicationParams) SetFriendlyName(FriendlyName string) *Cre // Create a new application within your account func (c *ApiService) CreateApplication(params *CreateApplicationParams) (*ApiV2010Application, error) { + return c.CreateApplicationWithCtx(context.TODO(), params) +} + +// Create a new application within your account +func (c *ApiService) CreateApplicationWithCtx(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) @@ -182,7 +188,7 @@ func (c *ApiService) CreateApplication(params *CreateApplicationParams) (*ApiV20 data.Set("FriendlyName", *params.FriendlyName) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -210,6 +216,11 @@ 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.DeleteApplicationWithCtx(context.TODO(), Sid, params) +} + +// Delete the application by the specified application sid +func (c *ApiService) DeleteApplicationWithCtx(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) @@ -221,7 +232,7 @@ func (c *ApiService) DeleteApplication(Sid string, params *DeleteApplicationPara data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -244,6 +255,11 @@ 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.FetchApplicationWithCtx(context.TODO(), Sid, params) +} + +// Fetch the application specified by the provided sid +func (c *ApiService) FetchApplicationWithCtx(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) @@ -255,7 +271,7 @@ func (c *ApiService) FetchApplication(Sid string, params *FetchApplicationParams data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -301,6 +317,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.PageApplicationWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Application records from the API. Request is executed immediately. +func (c *ApiService) PageApplicationWithCtx(ctx context.Context, params *ListApplicationParams, pageToken, pageNumber string) (*ListApplicationResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/Applications.json" if params != nil && params.PathAccountSid != nil { @@ -326,7 +347,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -343,7 +364,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.ListApplicationWithCtx(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) ListApplicationWithCtx(ctx context.Context, params *ListApplicationParams) ([]ApiV2010Application, error) { + response, errors := c.StreamApplicationWithCtx(ctx, params) records := make([]ApiV2010Application, 0) for record := range response { @@ -359,6 +385,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.StreamApplicationWithCtx(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) StreamApplicationWithCtx(ctx context.Context, params *ListApplicationParams) (chan ApiV2010Application, chan error) { if params == nil { params = &ListApplicationParams{} } @@ -367,19 +398,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.PageApplicationWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamApplication(response, params, recordChannel, errorChannel) + go c.streamApplication(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) streamApplication(ctx context.Context, response *ListApplicationResponse, params *ListApplicationParams, recordChannel chan ApiV2010Application, errorChannel chan error) { curRecord := 1 for response != nil { @@ -394,7 +425,7 @@ func (c *ApiService) streamApplication(response *ListApplicationResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListApplicationResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListApplicationResponse) if err != nil { errorChannel <- err break @@ -409,11 +440,11 @@ func (c *ApiService) streamApplication(response *ListApplicationResponse, params close(errorChannel) } -func (c *ApiService) getNextListApplicationResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListApplicationResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -530,6 +561,11 @@ func (params *UpdateApplicationParams) SetMessageStatusCallback(MessageStatusCal // Updates the application's properties func (c *ApiService) UpdateApplication(Sid string, params *UpdateApplicationParams) (*ApiV2010Application, error) { + return c.UpdateApplicationWithCtx(context.TODO(), Sid, params) +} + +// Updates the application's properties +func (c *ApiService) UpdateApplicationWithCtx(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) @@ -587,7 +623,7 @@ func (c *ApiService) UpdateApplication(Sid string, params *UpdateApplicationPara data.Set("MessageStatusCallback", *params.MessageStatusCallback) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 c6c0b4e0b..562332f18 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,11 @@ 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.FetchAuthorizedConnectAppWithCtx(context.TODO(), ConnectAppSid, params) +} + +// Fetch an instance of an authorized-connect-app +func (c *ApiService) FetchAuthorizedConnectAppWithCtx(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) @@ -47,7 +53,7 @@ func (c *ApiService) FetchAuthorizedConnectApp(ConnectAppSid string, params *Fet data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -87,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.PageAuthorizedConnectAppWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of AuthorizedConnectApp records from the API. Request is executed immediately. +func (c *ApiService) PageAuthorizedConnectAppWithCtx(ctx context.Context, params *ListAuthorizedConnectAppParams, pageToken, pageNumber string) (*ListAuthorizedConnectAppResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/AuthorizedConnectApps.json" if params != nil && params.PathAccountSid != nil { @@ -109,7 +120,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -126,7 +137,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.ListAuthorizedConnectAppWithCtx(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) ListAuthorizedConnectAppWithCtx(ctx context.Context, params *ListAuthorizedConnectAppParams) ([]ApiV2010AuthorizedConnectApp, error) { + response, errors := c.StreamAuthorizedConnectAppWithCtx(ctx, params) records := make([]ApiV2010AuthorizedConnectApp, 0) for record := range response { @@ -142,6 +158,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.StreamAuthorizedConnectAppWithCtx(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) StreamAuthorizedConnectAppWithCtx(ctx context.Context, params *ListAuthorizedConnectAppParams) (chan ApiV2010AuthorizedConnectApp, chan error) { if params == nil { params = &ListAuthorizedConnectAppParams{} } @@ -150,19 +171,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.PageAuthorizedConnectAppWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamAuthorizedConnectApp(response, params, recordChannel, errorChannel) + go c.streamAuthorizedConnectApp(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) streamAuthorizedConnectApp(ctx context.Context, response *ListAuthorizedConnectAppResponse, params *ListAuthorizedConnectAppParams, recordChannel chan ApiV2010AuthorizedConnectApp, errorChannel chan error) { curRecord := 1 for response != nil { @@ -177,7 +198,7 @@ func (c *ApiService) streamAuthorizedConnectApp(response *ListAuthorizedConnectA } } - record, err := client.GetNext(c.baseURL, response, c.getNextListAuthorizedConnectAppResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListAuthorizedConnectAppResponse) if err != nil { errorChannel <- err break @@ -192,11 +213,11 @@ func (c *ApiService) streamAuthorizedConnectApp(response *ListAuthorizedConnectA close(errorChannel) } -func (c *ApiService) getNextListAuthorizedConnectAppResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListAuthorizedConnectAppResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 5cc813f87..308b800d8 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" @@ -36,6 +37,11 @@ func (params *FetchAvailablePhoneNumberCountryParams) SetPathAccountSid(PathAcco // func (c *ApiService) FetchAvailablePhoneNumberCountry(CountryCode string, params *FetchAvailablePhoneNumberCountryParams) (*ApiV2010AvailablePhoneNumberCountry, error) { + return c.FetchAvailablePhoneNumberCountryWithCtx(context.TODO(), CountryCode, params) +} + +// +func (c *ApiService) FetchAvailablePhoneNumberCountryWithCtx(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) @@ -47,7 +53,7 @@ func (c *ApiService) FetchAvailablePhoneNumberCountry(CountryCode string, params data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -87,6 +93,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.PageAvailablePhoneNumberCountryWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of AvailablePhoneNumberCountry records from the API. Request is executed immediately. +func (c *ApiService) PageAvailablePhoneNumberCountryWithCtx(ctx context.Context, params *ListAvailablePhoneNumberCountryParams, pageToken, pageNumber string) (*ListAvailablePhoneNumberCountryResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers.json" if params != nil && params.PathAccountSid != nil { @@ -109,7 +120,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -126,7 +137,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.ListAvailablePhoneNumberCountryWithCtx(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) ListAvailablePhoneNumberCountryWithCtx(ctx context.Context, params *ListAvailablePhoneNumberCountryParams) ([]ApiV2010AvailablePhoneNumberCountry, error) { + response, errors := c.StreamAvailablePhoneNumberCountryWithCtx(ctx, params) records := make([]ApiV2010AvailablePhoneNumberCountry, 0) for record := range response { @@ -142,6 +158,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.StreamAvailablePhoneNumberCountryWithCtx(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) StreamAvailablePhoneNumberCountryWithCtx(ctx context.Context, params *ListAvailablePhoneNumberCountryParams) (chan ApiV2010AvailablePhoneNumberCountry, chan error) { if params == nil { params = &ListAvailablePhoneNumberCountryParams{} } @@ -150,19 +171,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.PageAvailablePhoneNumberCountryWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamAvailablePhoneNumberCountry(response, params, recordChannel, errorChannel) + go c.streamAvailablePhoneNumberCountry(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) streamAvailablePhoneNumberCountry(ctx context.Context, response *ListAvailablePhoneNumberCountryResponse, params *ListAvailablePhoneNumberCountryParams, recordChannel chan ApiV2010AvailablePhoneNumberCountry, errorChannel chan error) { curRecord := 1 for response != nil { @@ -177,7 +198,7 @@ func (c *ApiService) streamAvailablePhoneNumberCountry(response *ListAvailablePh } } - record, err := client.GetNext(c.baseURL, response, c.getNextListAvailablePhoneNumberCountryResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListAvailablePhoneNumberCountryResponse) if err != nil { errorChannel <- err break @@ -192,11 +213,11 @@ func (c *ApiService) streamAvailablePhoneNumberCountry(response *ListAvailablePh close(errorChannel) } -func (c *ApiService) getNextListAvailablePhoneNumberCountryResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListAvailablePhoneNumberCountryResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 9d7ffaecf..c8dc406f5 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.PageAvailablePhoneNumberLocalWithCtx(context.TODO(), CountryCode, params, pageToken, pageNumber) +} + +// Retrieve a single page of AvailablePhoneNumberLocal records from the API. Request is executed immediately. +func (c *ApiService) PageAvailablePhoneNumberLocalWithCtx(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 { @@ -233,7 +239,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -250,7 +256,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.ListAvailablePhoneNumberLocalWithCtx(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) ListAvailablePhoneNumberLocalWithCtx(ctx context.Context, CountryCode string, params *ListAvailablePhoneNumberLocalParams) ([]ApiV2010AvailablePhoneNumberLocal, error) { + response, errors := c.StreamAvailablePhoneNumberLocalWithCtx(ctx, CountryCode, params) records := make([]ApiV2010AvailablePhoneNumberLocal, 0) for record := range response { @@ -266,6 +277,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.StreamAvailablePhoneNumberLocalWithCtx(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) StreamAvailablePhoneNumberLocalWithCtx(ctx context.Context, CountryCode string, params *ListAvailablePhoneNumberLocalParams) (chan ApiV2010AvailablePhoneNumberLocal, chan error) { if params == nil { params = &ListAvailablePhoneNumberLocalParams{} } @@ -274,19 +290,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.PageAvailablePhoneNumberLocalWithCtx(ctx, CountryCode, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamAvailablePhoneNumberLocal(response, params, recordChannel, errorChannel) + go c.streamAvailablePhoneNumberLocal(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) streamAvailablePhoneNumberLocal(ctx context.Context, response *ListAvailablePhoneNumberLocalResponse, params *ListAvailablePhoneNumberLocalParams, recordChannel chan ApiV2010AvailablePhoneNumberLocal, errorChannel chan error) { curRecord := 1 for response != nil { @@ -301,7 +317,7 @@ func (c *ApiService) streamAvailablePhoneNumberLocal(response *ListAvailablePhon } } - record, err := client.GetNext(c.baseURL, response, c.getNextListAvailablePhoneNumberLocalResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListAvailablePhoneNumberLocalResponse) if err != nil { errorChannel <- err break @@ -316,11 +332,11 @@ func (c *ApiService) streamAvailablePhoneNumberLocal(response *ListAvailablePhon close(errorChannel) } -func (c *ApiService) getNextListAvailablePhoneNumberLocalResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListAvailablePhoneNumberLocalResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 30f22af46..5b1ab92b2 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.PageAvailablePhoneNumberMachineToMachineWithCtx(context.TODO(), CountryCode, params, pageToken, pageNumber) +} + +// Retrieve a single page of AvailablePhoneNumberMachineToMachine records from the API. Request is executed immediately. +func (c *ApiService) PageAvailablePhoneNumberMachineToMachineWithCtx(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 { @@ -233,7 +239,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -250,7 +256,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.ListAvailablePhoneNumberMachineToMachineWithCtx(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) ListAvailablePhoneNumberMachineToMachineWithCtx(ctx context.Context, CountryCode string, params *ListAvailablePhoneNumberMachineToMachineParams) ([]ApiV2010AvailablePhoneNumberMachineToMachine, error) { + response, errors := c.StreamAvailablePhoneNumberMachineToMachineWithCtx(ctx, CountryCode, params) records := make([]ApiV2010AvailablePhoneNumberMachineToMachine, 0) for record := range response { @@ -266,6 +277,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.StreamAvailablePhoneNumberMachineToMachineWithCtx(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) StreamAvailablePhoneNumberMachineToMachineWithCtx(ctx context.Context, CountryCode string, params *ListAvailablePhoneNumberMachineToMachineParams) (chan ApiV2010AvailablePhoneNumberMachineToMachine, chan error) { if params == nil { params = &ListAvailablePhoneNumberMachineToMachineParams{} } @@ -274,19 +290,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.PageAvailablePhoneNumberMachineToMachineWithCtx(ctx, CountryCode, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamAvailablePhoneNumberMachineToMachine(response, params, recordChannel, errorChannel) + go c.streamAvailablePhoneNumberMachineToMachine(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) streamAvailablePhoneNumberMachineToMachine(ctx context.Context, response *ListAvailablePhoneNumberMachineToMachineResponse, params *ListAvailablePhoneNumberMachineToMachineParams, recordChannel chan ApiV2010AvailablePhoneNumberMachineToMachine, errorChannel chan error) { curRecord := 1 for response != nil { @@ -301,7 +317,7 @@ func (c *ApiService) streamAvailablePhoneNumberMachineToMachine(response *ListAv } } - record, err := client.GetNext(c.baseURL, response, c.getNextListAvailablePhoneNumberMachineToMachineResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListAvailablePhoneNumberMachineToMachineResponse) if err != nil { errorChannel <- err break @@ -316,11 +332,11 @@ func (c *ApiService) streamAvailablePhoneNumberMachineToMachine(response *ListAv close(errorChannel) } -func (c *ApiService) getNextListAvailablePhoneNumberMachineToMachineResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListAvailablePhoneNumberMachineToMachineResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 df649b4d0..6b05f7335 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.PageAvailablePhoneNumberMobileWithCtx(context.TODO(), CountryCode, params, pageToken, pageNumber) +} + +// Retrieve a single page of AvailablePhoneNumberMobile records from the API. Request is executed immediately. +func (c *ApiService) PageAvailablePhoneNumberMobileWithCtx(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 { @@ -233,7 +239,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -250,7 +256,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.ListAvailablePhoneNumberMobileWithCtx(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) ListAvailablePhoneNumberMobileWithCtx(ctx context.Context, CountryCode string, params *ListAvailablePhoneNumberMobileParams) ([]ApiV2010AvailablePhoneNumberMobile, error) { + response, errors := c.StreamAvailablePhoneNumberMobileWithCtx(ctx, CountryCode, params) records := make([]ApiV2010AvailablePhoneNumberMobile, 0) for record := range response { @@ -266,6 +277,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.StreamAvailablePhoneNumberMobileWithCtx(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) StreamAvailablePhoneNumberMobileWithCtx(ctx context.Context, CountryCode string, params *ListAvailablePhoneNumberMobileParams) (chan ApiV2010AvailablePhoneNumberMobile, chan error) { if params == nil { params = &ListAvailablePhoneNumberMobileParams{} } @@ -274,19 +290,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.PageAvailablePhoneNumberMobileWithCtx(ctx, CountryCode, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamAvailablePhoneNumberMobile(response, params, recordChannel, errorChannel) + go c.streamAvailablePhoneNumberMobile(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) streamAvailablePhoneNumberMobile(ctx context.Context, response *ListAvailablePhoneNumberMobileResponse, params *ListAvailablePhoneNumberMobileParams, recordChannel chan ApiV2010AvailablePhoneNumberMobile, errorChannel chan error) { curRecord := 1 for response != nil { @@ -301,7 +317,7 @@ func (c *ApiService) streamAvailablePhoneNumberMobile(response *ListAvailablePho } } - record, err := client.GetNext(c.baseURL, response, c.getNextListAvailablePhoneNumberMobileResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListAvailablePhoneNumberMobileResponse) if err != nil { errorChannel <- err break @@ -316,11 +332,11 @@ func (c *ApiService) streamAvailablePhoneNumberMobile(response *ListAvailablePho close(errorChannel) } -func (c *ApiService) getNextListAvailablePhoneNumberMobileResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListAvailablePhoneNumberMobileResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 46f936ea2..632dc3975 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.PageAvailablePhoneNumberNationalWithCtx(context.TODO(), CountryCode, params, pageToken, pageNumber) +} + +// Retrieve a single page of AvailablePhoneNumberNational records from the API. Request is executed immediately. +func (c *ApiService) PageAvailablePhoneNumberNationalWithCtx(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 { @@ -233,7 +239,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -250,7 +256,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.ListAvailablePhoneNumberNationalWithCtx(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) ListAvailablePhoneNumberNationalWithCtx(ctx context.Context, CountryCode string, params *ListAvailablePhoneNumberNationalParams) ([]ApiV2010AvailablePhoneNumberNational, error) { + response, errors := c.StreamAvailablePhoneNumberNationalWithCtx(ctx, CountryCode, params) records := make([]ApiV2010AvailablePhoneNumberNational, 0) for record := range response { @@ -266,6 +277,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.StreamAvailablePhoneNumberNationalWithCtx(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) StreamAvailablePhoneNumberNationalWithCtx(ctx context.Context, CountryCode string, params *ListAvailablePhoneNumberNationalParams) (chan ApiV2010AvailablePhoneNumberNational, chan error) { if params == nil { params = &ListAvailablePhoneNumberNationalParams{} } @@ -274,19 +290,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.PageAvailablePhoneNumberNationalWithCtx(ctx, CountryCode, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamAvailablePhoneNumberNational(response, params, recordChannel, errorChannel) + go c.streamAvailablePhoneNumberNational(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) streamAvailablePhoneNumberNational(ctx context.Context, response *ListAvailablePhoneNumberNationalResponse, params *ListAvailablePhoneNumberNationalParams, recordChannel chan ApiV2010AvailablePhoneNumberNational, errorChannel chan error) { curRecord := 1 for response != nil { @@ -301,7 +317,7 @@ func (c *ApiService) streamAvailablePhoneNumberNational(response *ListAvailableP } } - record, err := client.GetNext(c.baseURL, response, c.getNextListAvailablePhoneNumberNationalResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListAvailablePhoneNumberNationalResponse) if err != nil { errorChannel <- err break @@ -316,11 +332,11 @@ func (c *ApiService) streamAvailablePhoneNumberNational(response *ListAvailableP close(errorChannel) } -func (c *ApiService) getNextListAvailablePhoneNumberNationalResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListAvailablePhoneNumberNationalResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 9c6abff87..557676e3a 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.PageAvailablePhoneNumberSharedCostWithCtx(context.TODO(), CountryCode, params, pageToken, pageNumber) +} + +// Retrieve a single page of AvailablePhoneNumberSharedCost records from the API. Request is executed immediately. +func (c *ApiService) PageAvailablePhoneNumberSharedCostWithCtx(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 { @@ -233,7 +239,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -250,7 +256,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.ListAvailablePhoneNumberSharedCostWithCtx(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) ListAvailablePhoneNumberSharedCostWithCtx(ctx context.Context, CountryCode string, params *ListAvailablePhoneNumberSharedCostParams) ([]ApiV2010AvailablePhoneNumberSharedCost, error) { + response, errors := c.StreamAvailablePhoneNumberSharedCostWithCtx(ctx, CountryCode, params) records := make([]ApiV2010AvailablePhoneNumberSharedCost, 0) for record := range response { @@ -266,6 +277,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.StreamAvailablePhoneNumberSharedCostWithCtx(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) StreamAvailablePhoneNumberSharedCostWithCtx(ctx context.Context, CountryCode string, params *ListAvailablePhoneNumberSharedCostParams) (chan ApiV2010AvailablePhoneNumberSharedCost, chan error) { if params == nil { params = &ListAvailablePhoneNumberSharedCostParams{} } @@ -274,19 +290,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.PageAvailablePhoneNumberSharedCostWithCtx(ctx, CountryCode, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamAvailablePhoneNumberSharedCost(response, params, recordChannel, errorChannel) + go c.streamAvailablePhoneNumberSharedCost(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) streamAvailablePhoneNumberSharedCost(ctx context.Context, response *ListAvailablePhoneNumberSharedCostResponse, params *ListAvailablePhoneNumberSharedCostParams, recordChannel chan ApiV2010AvailablePhoneNumberSharedCost, errorChannel chan error) { curRecord := 1 for response != nil { @@ -301,7 +317,7 @@ func (c *ApiService) streamAvailablePhoneNumberSharedCost(response *ListAvailabl } } - record, err := client.GetNext(c.baseURL, response, c.getNextListAvailablePhoneNumberSharedCostResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListAvailablePhoneNumberSharedCostResponse) if err != nil { errorChannel <- err break @@ -316,11 +332,11 @@ func (c *ApiService) streamAvailablePhoneNumberSharedCost(response *ListAvailabl close(errorChannel) } -func (c *ApiService) getNextListAvailablePhoneNumberSharedCostResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListAvailablePhoneNumberSharedCostResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 7d4be3c1f..f5179ac0f 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.PageAvailablePhoneNumberTollFreeWithCtx(context.TODO(), CountryCode, params, pageToken, pageNumber) +} + +// Retrieve a single page of AvailablePhoneNumberTollFree records from the API. Request is executed immediately. +func (c *ApiService) PageAvailablePhoneNumberTollFreeWithCtx(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 { @@ -233,7 +239,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -250,7 +256,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.ListAvailablePhoneNumberTollFreeWithCtx(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) ListAvailablePhoneNumberTollFreeWithCtx(ctx context.Context, CountryCode string, params *ListAvailablePhoneNumberTollFreeParams) ([]ApiV2010AvailablePhoneNumberTollFree, error) { + response, errors := c.StreamAvailablePhoneNumberTollFreeWithCtx(ctx, CountryCode, params) records := make([]ApiV2010AvailablePhoneNumberTollFree, 0) for record := range response { @@ -266,6 +277,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.StreamAvailablePhoneNumberTollFreeWithCtx(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) StreamAvailablePhoneNumberTollFreeWithCtx(ctx context.Context, CountryCode string, params *ListAvailablePhoneNumberTollFreeParams) (chan ApiV2010AvailablePhoneNumberTollFree, chan error) { if params == nil { params = &ListAvailablePhoneNumberTollFreeParams{} } @@ -274,19 +290,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.PageAvailablePhoneNumberTollFreeWithCtx(ctx, CountryCode, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamAvailablePhoneNumberTollFree(response, params, recordChannel, errorChannel) + go c.streamAvailablePhoneNumberTollFree(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) streamAvailablePhoneNumberTollFree(ctx context.Context, response *ListAvailablePhoneNumberTollFreeResponse, params *ListAvailablePhoneNumberTollFreeParams, recordChannel chan ApiV2010AvailablePhoneNumberTollFree, errorChannel chan error) { curRecord := 1 for response != nil { @@ -301,7 +317,7 @@ func (c *ApiService) streamAvailablePhoneNumberTollFree(response *ListAvailableP } } - record, err := client.GetNext(c.baseURL, response, c.getNextListAvailablePhoneNumberTollFreeResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListAvailablePhoneNumberTollFreeResponse) if err != nil { errorChannel <- err break @@ -316,11 +332,11 @@ func (c *ApiService) streamAvailablePhoneNumberTollFree(response *ListAvailableP close(errorChannel) } -func (c *ApiService) getNextListAvailablePhoneNumberTollFreeResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListAvailablePhoneNumberTollFreeResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 a2534d8e5..270a15b35 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.PageAvailablePhoneNumberVoipWithCtx(context.TODO(), CountryCode, params, pageToken, pageNumber) +} + +// Retrieve a single page of AvailablePhoneNumberVoip records from the API. Request is executed immediately. +func (c *ApiService) PageAvailablePhoneNumberVoipWithCtx(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 { @@ -233,7 +239,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -250,7 +256,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.ListAvailablePhoneNumberVoipWithCtx(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) ListAvailablePhoneNumberVoipWithCtx(ctx context.Context, CountryCode string, params *ListAvailablePhoneNumberVoipParams) ([]ApiV2010AvailablePhoneNumberVoip, error) { + response, errors := c.StreamAvailablePhoneNumberVoipWithCtx(ctx, CountryCode, params) records := make([]ApiV2010AvailablePhoneNumberVoip, 0) for record := range response { @@ -266,6 +277,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.StreamAvailablePhoneNumberVoipWithCtx(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) StreamAvailablePhoneNumberVoipWithCtx(ctx context.Context, CountryCode string, params *ListAvailablePhoneNumberVoipParams) (chan ApiV2010AvailablePhoneNumberVoip, chan error) { if params == nil { params = &ListAvailablePhoneNumberVoipParams{} } @@ -274,19 +290,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.PageAvailablePhoneNumberVoipWithCtx(ctx, CountryCode, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamAvailablePhoneNumberVoip(response, params, recordChannel, errorChannel) + go c.streamAvailablePhoneNumberVoip(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) streamAvailablePhoneNumberVoip(ctx context.Context, response *ListAvailablePhoneNumberVoipResponse, params *ListAvailablePhoneNumberVoipParams, recordChannel chan ApiV2010AvailablePhoneNumberVoip, errorChannel chan error) { curRecord := 1 for response != nil { @@ -301,7 +317,7 @@ func (c *ApiService) streamAvailablePhoneNumberVoip(response *ListAvailablePhone } } - record, err := client.GetNext(c.baseURL, response, c.getNextListAvailablePhoneNumberVoipResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListAvailablePhoneNumberVoipResponse) if err != nil { errorChannel <- err break @@ -316,11 +332,11 @@ func (c *ApiService) streamAvailablePhoneNumberVoip(response *ListAvailablePhone close(errorChannel) } -func (c *ApiService) getNextListAvailablePhoneNumberVoipResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListAvailablePhoneNumberVoipResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 043ab1aad..7a334f2e7 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,11 @@ 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.FetchBalanceWithCtx(context.TODO(), params) +} + +// 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) FetchBalanceWithCtx(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) @@ -43,7 +49,7 @@ func (c *ApiService) FetchBalance(params *FetchBalanceParams) (*ApiV2010Balance, data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(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 cb5b0cf61..d796aec7d 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,11 @@ 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.CreateCallWithCtx(context.TODO(), params) +} + +// Create a new outgoing call to phones, SIP-enabled endpoints or Twilio Client connections +func (c *ApiService) CreateCallWithCtx(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) @@ -367,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -395,6 +401,11 @@ 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.DeleteCallWithCtx(context.TODO(), Sid, params) +} + +// 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) DeleteCallWithCtx(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) @@ -406,7 +417,7 @@ func (c *ApiService) DeleteCall(Sid string, params *DeleteCallParams) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -429,6 +440,11 @@ 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.FetchCallWithCtx(context.TODO(), Sid, params) +} + +// Fetch the call specified by the provided Call SID +func (c *ApiService) FetchCallWithCtx(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) @@ -440,7 +456,7 @@ func (c *ApiService) FetchCall(Sid string, params *FetchCallParams) (*ApiV2010Ca data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -540,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.PageCallWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Call records from the API. Request is executed immediately. +func (c *ApiService) PageCallWithCtx(ctx context.Context, params *ListCallParams, pageToken, pageNumber string) (*ListCallResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/Calls.json" if params != nil && params.PathAccountSid != nil { @@ -592,7 +613,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -609,7 +630,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.ListCallWithCtx(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) ListCallWithCtx(ctx context.Context, params *ListCallParams) ([]ApiV2010Call, error) { + response, errors := c.StreamCallWithCtx(ctx, params) records := make([]ApiV2010Call, 0) for record := range response { @@ -625,6 +651,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.StreamCallWithCtx(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) StreamCallWithCtx(ctx context.Context, params *ListCallParams) (chan ApiV2010Call, chan error) { if params == nil { params = &ListCallParams{} } @@ -633,19 +664,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.PageCallWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamCall(response, params, recordChannel, errorChannel) + go c.streamCall(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) streamCall(ctx context.Context, response *ListCallResponse, params *ListCallParams, recordChannel chan ApiV2010Call, errorChannel chan error) { curRecord := 1 for response != nil { @@ -660,7 +691,7 @@ func (c *ApiService) streamCall(response *ListCallResponse, params *ListCallPara } } - record, err := client.GetNext(c.baseURL, response, c.getNextListCallResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListCallResponse) if err != nil { errorChannel <- err break @@ -675,11 +706,11 @@ func (c *ApiService) streamCall(response *ListCallResponse, params *ListCallPara close(errorChannel) } -func (c *ApiService) getNextListCallResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListCallResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -760,6 +791,11 @@ 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.UpdateCallWithCtx(context.TODO(), Sid, params) +} + +// Initiates a call redirect or terminates a call +func (c *ApiService) UpdateCallWithCtx(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) @@ -799,7 +835,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.Post(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 07ce9789a..ce5ed3ed6 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.PageCallEventWithCtx(context.TODO(), CallSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of CallEvent records from the API. Request is executed immediately. +func (c *ApiService) PageCallEventWithCtx(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 { @@ -71,7 +77,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -88,7 +94,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.ListCallEventWithCtx(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) ListCallEventWithCtx(ctx context.Context, CallSid string, params *ListCallEventParams) ([]ApiV2010CallEvent, error) { + response, errors := c.StreamCallEventWithCtx(ctx, CallSid, params) records := make([]ApiV2010CallEvent, 0) for record := range response { @@ -104,6 +115,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.StreamCallEventWithCtx(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) StreamCallEventWithCtx(ctx context.Context, CallSid string, params *ListCallEventParams) (chan ApiV2010CallEvent, chan error) { if params == nil { params = &ListCallEventParams{} } @@ -112,19 +128,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.PageCallEventWithCtx(ctx, CallSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamCallEvent(response, params, recordChannel, errorChannel) + go c.streamCallEvent(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) streamCallEvent(ctx context.Context, response *ListCallEventResponse, params *ListCallEventParams, recordChannel chan ApiV2010CallEvent, errorChannel chan error) { curRecord := 1 for response != nil { @@ -139,7 +155,7 @@ func (c *ApiService) streamCallEvent(response *ListCallEventResponse, params *Li } } - record, err := client.GetNext(c.baseURL, response, c.getNextListCallEventResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListCallEventResponse) if err != nil { errorChannel <- err break @@ -154,11 +170,11 @@ func (c *ApiService) streamCallEvent(response *ListCallEventResponse, params *Li close(errorChannel) } -func (c *ApiService) getNextListCallEventResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListCallEventResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_calls_feedback.go b/rest/api/v2010/accounts_calls_feedback.go index 93e2b9a43..17be8f00e 100644 --- a/rest/api/v2010/accounts_calls_feedback.go +++ b/rest/api/v2010/accounts_calls_feedback.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -34,6 +35,11 @@ func (params *FetchCallFeedbackParams) SetPathAccountSid(PathAccountSid string) // Fetch a Feedback resource from a call func (c *ApiService) FetchCallFeedback(CallSid string, params *FetchCallFeedbackParams) (*ApiV2010CallFeedback, error) { + return c.FetchCallFeedbackWithCtx(context.TODO(), CallSid, params) +} + +// Fetch a Feedback resource from a call +func (c *ApiService) FetchCallFeedbackWithCtx(ctx context.Context, CallSid string, params *FetchCallFeedbackParams) (*ApiV2010CallFeedback, error) { path := "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Feedback.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -45,7 +51,7 @@ func (c *ApiService) FetchCallFeedback(CallSid string, params *FetchCallFeedback data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -85,6 +91,11 @@ func (params *UpdateCallFeedbackParams) SetIssue(Issue []string) *UpdateCallFeed // Update a Feedback resource for a call func (c *ApiService) UpdateCallFeedback(CallSid string, params *UpdateCallFeedbackParams) (*ApiV2010CallFeedback, error) { + return c.UpdateCallFeedbackWithCtx(context.TODO(), CallSid, params) +} + +// Update a Feedback resource for a call +func (c *ApiService) UpdateCallFeedbackWithCtx(ctx context.Context, CallSid string, params *UpdateCallFeedbackParams) (*ApiV2010CallFeedback, error) { path := "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Feedback.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -105,7 +116,7 @@ func (c *ApiService) UpdateCallFeedback(CallSid string, params *UpdateCallFeedba } } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/api/v2010/accounts_calls_feedback_summary.go b/rest/api/v2010/accounts_calls_feedback_summary.go index 0cdef1d54..4f0a5e1ae 100644 --- a/rest/api/v2010/accounts_calls_feedback_summary.go +++ b/rest/api/v2010/accounts_calls_feedback_summary.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -64,6 +65,11 @@ func (params *CreateCallFeedbackSummaryParams) SetStatusCallbackMethod(StatusCal // Create a FeedbackSummary resource for a call func (c *ApiService) CreateCallFeedbackSummary(params *CreateCallFeedbackSummaryParams) (*ApiV2010CallFeedbackSummary, error) { + return c.CreateCallFeedbackSummaryWithCtx(context.TODO(), params) +} + +// Create a FeedbackSummary resource for a call +func (c *ApiService) CreateCallFeedbackSummaryWithCtx(ctx context.Context, params *CreateCallFeedbackSummaryParams) (*ApiV2010CallFeedbackSummary, error) { path := "/2010-04-01/Accounts/{AccountSid}/Calls/FeedbackSummary.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -90,7 +96,7 @@ func (c *ApiService) CreateCallFeedbackSummary(params *CreateCallFeedbackSummary data.Set("StatusCallbackMethod", *params.StatusCallbackMethod) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -118,6 +124,11 @@ func (params *DeleteCallFeedbackSummaryParams) SetPathAccountSid(PathAccountSid // Delete a FeedbackSummary resource from a call func (c *ApiService) DeleteCallFeedbackSummary(Sid string, params *DeleteCallFeedbackSummaryParams) error { + return c.DeleteCallFeedbackSummaryWithCtx(context.TODO(), Sid, params) +} + +// Delete a FeedbackSummary resource from a call +func (c *ApiService) DeleteCallFeedbackSummaryWithCtx(ctx context.Context, Sid string, params *DeleteCallFeedbackSummaryParams) error { path := "/2010-04-01/Accounts/{AccountSid}/Calls/FeedbackSummary/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -129,7 +140,7 @@ func (c *ApiService) DeleteCallFeedbackSummary(Sid string, params *DeleteCallFee data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -152,6 +163,11 @@ func (params *FetchCallFeedbackSummaryParams) SetPathAccountSid(PathAccountSid s // Fetch a FeedbackSummary resource from a call func (c *ApiService) FetchCallFeedbackSummary(Sid string, params *FetchCallFeedbackSummaryParams) (*ApiV2010CallFeedbackSummary, error) { + return c.FetchCallFeedbackSummaryWithCtx(context.TODO(), Sid, params) +} + +// Fetch a FeedbackSummary resource from a call +func (c *ApiService) FetchCallFeedbackSummaryWithCtx(ctx context.Context, Sid string, params *FetchCallFeedbackSummaryParams) (*ApiV2010CallFeedbackSummary, error) { path := "/2010-04-01/Accounts/{AccountSid}/Calls/FeedbackSummary/{Sid}.json" if params != nil && params.PathAccountSid != nil { path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) @@ -163,7 +179,7 @@ func (c *ApiService) FetchCallFeedbackSummary(Sid string, params *FetchCallFeedb data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) 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 4004ae82b..75b9d3c29 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" @@ -36,6 +37,11 @@ func (params *FetchCallNotificationParams) SetPathAccountSid(PathAccountSid stri // func (c *ApiService) FetchCallNotification(CallSid string, Sid string, params *FetchCallNotificationParams) (*ApiV2010CallNotificationInstance, error) { + return c.FetchCallNotificationWithCtx(context.TODO(), CallSid, Sid, params) +} + +// +func (c *ApiService) FetchCallNotificationWithCtx(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) @@ -48,7 +54,7 @@ func (c *ApiService) FetchCallNotification(CallSid string, Sid string, params *F data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -112,6 +118,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.PageCallNotificationWithCtx(context.TODO(), CallSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of CallNotification records from the API. Request is executed immediately. +func (c *ApiService) PageCallNotificationWithCtx(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 { @@ -147,7 +158,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -164,7 +175,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.ListCallNotificationWithCtx(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) ListCallNotificationWithCtx(ctx context.Context, CallSid string, params *ListCallNotificationParams) ([]ApiV2010CallNotification, error) { + response, errors := c.StreamCallNotificationWithCtx(ctx, CallSid, params) records := make([]ApiV2010CallNotification, 0) for record := range response { @@ -180,6 +196,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.StreamCallNotificationWithCtx(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) StreamCallNotificationWithCtx(ctx context.Context, CallSid string, params *ListCallNotificationParams) (chan ApiV2010CallNotification, chan error) { if params == nil { params = &ListCallNotificationParams{} } @@ -188,19 +209,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.PageCallNotificationWithCtx(ctx, CallSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamCallNotification(response, params, recordChannel, errorChannel) + go c.streamCallNotification(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) streamCallNotification(ctx context.Context, response *ListCallNotificationResponse, params *ListCallNotificationParams, recordChannel chan ApiV2010CallNotification, errorChannel chan error) { curRecord := 1 for response != nil { @@ -215,7 +236,7 @@ func (c *ApiService) streamCallNotification(response *ListCallNotificationRespon } } - record, err := client.GetNext(c.baseURL, response, c.getNextListCallNotificationResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListCallNotificationResponse) if err != nil { errorChannel <- err break @@ -230,11 +251,11 @@ func (c *ApiService) streamCallNotification(response *ListCallNotificationRespon close(errorChannel) } -func (c *ApiService) getNextListCallNotificationResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListCallNotificationResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 82e68055c..abd58b1c3 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,11 @@ 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.CreatePaymentsWithCtx(context.TODO(), CallSid, params) +} + +// create an instance of payments. This will start a new payments session +func (c *ApiService) CreatePaymentsWithCtx(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) @@ -196,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -248,6 +254,11 @@ 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.UpdatePaymentsWithCtx(context.TODO(), CallSid, Sid, params) +} + +// update an instance of payments with different phases of payment flows. +func (c *ApiService) UpdatePaymentsWithCtx(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) @@ -273,7 +284,7 @@ func (c *ApiService) UpdatePayments(CallSid string, Sid string, params *UpdatePa data.Set("Status", *params.Status) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 18915d3f3..dda544ad0 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,11 @@ func (params *CreateCallRecordingParams) SetRecordingTrack(RecordingTrack string // Create a recording for the call func (c *ApiService) CreateCallRecording(CallSid string, params *CreateCallRecordingParams) (*ApiV2010CallRecording, error) { + return c.CreateCallRecordingWithCtx(context.TODO(), CallSid, params) +} + +// Create a recording for the call +func (c *ApiService) CreateCallRecordingWithCtx(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) @@ -104,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -132,6 +138,11 @@ 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.DeleteCallRecordingWithCtx(context.TODO(), CallSid, Sid, params) +} + +// Delete a recording from your account +func (c *ApiService) DeleteCallRecordingWithCtx(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) @@ -144,7 +155,7 @@ func (c *ApiService) DeleteCallRecording(CallSid string, Sid string, params *Del data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -167,6 +178,11 @@ 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.FetchCallRecordingWithCtx(context.TODO(), CallSid, Sid, params) +} + +// Fetch an instance of a recording for a call +func (c *ApiService) FetchCallRecordingWithCtx(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) @@ -179,7 +195,7 @@ func (c *ApiService) FetchCallRecording(CallSid string, Sid string, params *Fetc data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -237,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.PageCallRecordingWithCtx(context.TODO(), CallSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of CallRecording records from the API. Request is executed immediately. +func (c *ApiService) PageCallRecordingWithCtx(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 { @@ -269,7 +290,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -286,7 +307,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.ListCallRecordingWithCtx(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) ListCallRecordingWithCtx(ctx context.Context, CallSid string, params *ListCallRecordingParams) ([]ApiV2010CallRecording, error) { + response, errors := c.StreamCallRecordingWithCtx(ctx, CallSid, params) records := make([]ApiV2010CallRecording, 0) for record := range response { @@ -302,6 +328,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.StreamCallRecordingWithCtx(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) StreamCallRecordingWithCtx(ctx context.Context, CallSid string, params *ListCallRecordingParams) (chan ApiV2010CallRecording, chan error) { if params == nil { params = &ListCallRecordingParams{} } @@ -310,19 +341,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.PageCallRecordingWithCtx(ctx, CallSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamCallRecording(response, params, recordChannel, errorChannel) + go c.streamCallRecording(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) streamCallRecording(ctx context.Context, response *ListCallRecordingResponse, params *ListCallRecordingParams, recordChannel chan ApiV2010CallRecording, errorChannel chan error) { curRecord := 1 for response != nil { @@ -337,7 +368,7 @@ func (c *ApiService) streamCallRecording(response *ListCallRecordingResponse, pa } } - record, err := client.GetNext(c.baseURL, response, c.getNextListCallRecordingResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListCallRecordingResponse) if err != nil { errorChannel <- err break @@ -352,11 +383,11 @@ func (c *ApiService) streamCallRecording(response *ListCallRecordingResponse, pa close(errorChannel) } -func (c *ApiService) getNextListCallRecordingResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListCallRecordingResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -395,6 +426,11 @@ 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.UpdateCallRecordingWithCtx(context.TODO(), CallSid, Sid, params) +} + +// 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) UpdateCallRecordingWithCtx(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) @@ -414,7 +450,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.Post(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 cdd2cf22c..8266f3742 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" "net/url" "strings" @@ -1251,6 +1252,11 @@ func (params *CreateSiprecParams) SetParameter99Value(Parameter99Value string) * // Create a Siprec func (c *ApiService) CreateSiprec(CallSid string, params *CreateSiprecParams) (*ApiV2010Siprec, error) { + return c.CreateSiprecWithCtx(context.TODO(), CallSid, params) +} + +// Create a Siprec +func (c *ApiService) CreateSiprecWithCtx(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) @@ -1872,7 +1878,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -1906,6 +1912,11 @@ 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.UpdateSiprecWithCtx(context.TODO(), CallSid, Sid, params) +} + +// Stop a Siprec using either the SID of the Siprec resource or the `name` used when creating the resource +func (c *ApiService) UpdateSiprecWithCtx(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) @@ -1922,7 +1933,7 @@ func (c *ApiService) UpdateSiprec(CallSid string, Sid string, params *UpdateSipr data.Set("Status", *params.Status) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 ec4e9497c..7bf06a0b9 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" "net/url" "strings" @@ -1251,6 +1252,11 @@ func (params *CreateStreamParams) SetParameter99Value(Parameter99Value string) * // Create a Stream func (c *ApiService) CreateStream(CallSid string, params *CreateStreamParams) (*ApiV2010Stream, error) { + return c.CreateStreamWithCtx(context.TODO(), CallSid, params) +} + +// Create a Stream +func (c *ApiService) CreateStreamWithCtx(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) @@ -1872,7 +1878,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -1906,6 +1912,11 @@ 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.UpdateStreamWithCtx(context.TODO(), CallSid, Sid, params) +} + +// Stop a Stream using either the SID of the Stream resource or the `name` used when creating the resource +func (c *ApiService) UpdateStreamWithCtx(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) @@ -1922,7 +1933,7 @@ func (c *ApiService) UpdateStream(CallSid string, Sid string, params *UpdateStre data.Set("Status", *params.Status) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 2897051e7..2366b8a4f 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,11 @@ 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.FetchConferenceWithCtx(context.TODO(), Sid, params) +} + +// Fetch an instance of a conference +func (c *ApiService) FetchConferenceWithCtx(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) @@ -47,7 +53,7 @@ func (c *ApiService) FetchConference(Sid string, params *FetchConferenceParams) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -135,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.PageConferenceWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Conference records from the API. Request is executed immediately. +func (c *ApiService) PageConferenceWithCtx(ctx context.Context, params *ListConferenceParams, pageToken, pageNumber string) (*ListConferenceResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/Conferences.json" if params != nil && params.PathAccountSid != nil { @@ -181,7 +192,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -198,7 +209,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.ListConferenceWithCtx(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) ListConferenceWithCtx(ctx context.Context, params *ListConferenceParams) ([]ApiV2010Conference, error) { + response, errors := c.StreamConferenceWithCtx(ctx, params) records := make([]ApiV2010Conference, 0) for record := range response { @@ -214,6 +230,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.StreamConferenceWithCtx(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) StreamConferenceWithCtx(ctx context.Context, params *ListConferenceParams) (chan ApiV2010Conference, chan error) { if params == nil { params = &ListConferenceParams{} } @@ -222,19 +243,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.PageConferenceWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamConference(response, params, recordChannel, errorChannel) + go c.streamConference(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) streamConference(ctx context.Context, response *ListConferenceResponse, params *ListConferenceParams, recordChannel chan ApiV2010Conference, errorChannel chan error) { curRecord := 1 for response != nil { @@ -249,7 +270,7 @@ func (c *ApiService) streamConference(response *ListConferenceResponse, params * } } - record, err := client.GetNext(c.baseURL, response, c.getNextListConferenceResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListConferenceResponse) if err != nil { errorChannel <- err break @@ -264,11 +285,11 @@ func (c *ApiService) streamConference(response *ListConferenceResponse, params * close(errorChannel) } -func (c *ApiService) getNextListConferenceResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListConferenceResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -313,6 +334,11 @@ func (params *UpdateConferenceParams) SetAnnounceMethod(AnnounceMethod string) * // func (c *ApiService) UpdateConference(Sid string, params *UpdateConferenceParams) (*ApiV2010Conference, error) { + return c.UpdateConferenceWithCtx(context.TODO(), Sid, params) +} + +// +func (c *ApiService) UpdateConferenceWithCtx(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) @@ -334,7 +360,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.Post(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 19d63f93b..15fae8579 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" @@ -312,6 +313,11 @@ func (params *CreateParticipantParams) SetAmdStatusCallbackMethod(AmdStatusCallb // func (c *ApiService) CreateParticipant(ConferenceSid string, params *CreateParticipantParams) (*ApiV2010Participant, error) { + return c.CreateParticipantWithCtx(context.TODO(), ConferenceSid, params) +} + +// +func (c *ApiService) CreateParticipantWithCtx(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) @@ -470,7 +476,7 @@ func (c *ApiService) CreateParticipant(ConferenceSid string, params *CreateParti data.Set("AmdStatusCallbackMethod", *params.AmdStatusCallbackMethod) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -498,6 +504,11 @@ 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.DeleteParticipantWithCtx(context.TODO(), ConferenceSid, CallSid, params) +} + +// Kick a participant from a given conference +func (c *ApiService) DeleteParticipantWithCtx(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) @@ -510,7 +521,7 @@ func (c *ApiService) DeleteParticipant(ConferenceSid string, CallSid string, par data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -533,6 +544,11 @@ 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.FetchParticipantWithCtx(context.TODO(), ConferenceSid, CallSid, params) +} + +// Fetch an instance of a participant +func (c *ApiService) FetchParticipantWithCtx(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) @@ -545,7 +561,7 @@ func (c *ApiService) FetchParticipant(ConferenceSid string, CallSid string, para data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -603,6 +619,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.PageParticipantWithCtx(context.TODO(), ConferenceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Participant records from the API. Request is executed immediately. +func (c *ApiService) PageParticipantWithCtx(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 { @@ -635,7 +656,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -652,7 +673,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.ListParticipantWithCtx(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) ListParticipantWithCtx(ctx context.Context, ConferenceSid string, params *ListParticipantParams) ([]ApiV2010Participant, error) { + response, errors := c.StreamParticipantWithCtx(ctx, ConferenceSid, params) records := make([]ApiV2010Participant, 0) for record := range response { @@ -668,6 +694,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.StreamParticipantWithCtx(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) StreamParticipantWithCtx(ctx context.Context, ConferenceSid string, params *ListParticipantParams) (chan ApiV2010Participant, chan error) { if params == nil { params = &ListParticipantParams{} } @@ -676,19 +707,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.PageParticipantWithCtx(ctx, ConferenceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamParticipant(response, params, recordChannel, errorChannel) + go c.streamParticipant(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) streamParticipant(ctx context.Context, response *ListParticipantResponse, params *ListParticipantParams, recordChannel chan ApiV2010Participant, errorChannel chan error) { curRecord := 1 for response != nil { @@ -703,7 +734,7 @@ func (c *ApiService) streamParticipant(response *ListParticipantResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListParticipantResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListParticipantResponse) if err != nil { errorChannel <- err break @@ -718,11 +749,11 @@ func (c *ApiService) streamParticipant(response *ListParticipantResponse, params close(errorChannel) } -func (c *ApiService) getNextListParticipantResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListParticipantResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -821,6 +852,11 @@ 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.UpdateParticipantWithCtx(context.TODO(), ConferenceSid, CallSid, params) +} + +// Update the properties of the participant +func (c *ApiService) UpdateParticipantWithCtx(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) @@ -870,7 +906,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.Post(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 2fab01c6f..de917b04a 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,11 @@ func (params *DeleteConferenceRecordingParams) SetPathAccountSid(PathAccountSid // Delete a recording from your account func (c *ApiService) DeleteConferenceRecording(ConferenceSid string, Sid string, params *DeleteConferenceRecordingParams) error { + return c.DeleteConferenceRecordingWithCtx(context.TODO(), ConferenceSid, Sid, params) +} + +// Delete a recording from your account +func (c *ApiService) DeleteConferenceRecordingWithCtx(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) @@ -48,7 +54,7 @@ func (c *ApiService) DeleteConferenceRecording(ConferenceSid string, Sid string, data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -71,6 +77,11 @@ 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.FetchConferenceRecordingWithCtx(context.TODO(), ConferenceSid, Sid, params) +} + +// Fetch an instance of a recording for a call +func (c *ApiService) FetchConferenceRecordingWithCtx(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) @@ -83,7 +94,7 @@ func (c *ApiService) FetchConferenceRecording(ConferenceSid string, Sid string, data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -141,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.PageConferenceRecordingWithCtx(context.TODO(), ConferenceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ConferenceRecording records from the API. Request is executed immediately. +func (c *ApiService) PageConferenceRecordingWithCtx(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 { @@ -173,7 +189,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -190,7 +206,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.ListConferenceRecordingWithCtx(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) ListConferenceRecordingWithCtx(ctx context.Context, ConferenceSid string, params *ListConferenceRecordingParams) ([]ApiV2010ConferenceRecording, error) { + response, errors := c.StreamConferenceRecordingWithCtx(ctx, ConferenceSid, params) records := make([]ApiV2010ConferenceRecording, 0) for record := range response { @@ -206,6 +227,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.StreamConferenceRecordingWithCtx(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) StreamConferenceRecordingWithCtx(ctx context.Context, ConferenceSid string, params *ListConferenceRecordingParams) (chan ApiV2010ConferenceRecording, chan error) { if params == nil { params = &ListConferenceRecordingParams{} } @@ -214,19 +240,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.PageConferenceRecordingWithCtx(ctx, ConferenceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamConferenceRecording(response, params, recordChannel, errorChannel) + go c.streamConferenceRecording(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) streamConferenceRecording(ctx context.Context, response *ListConferenceRecordingResponse, params *ListConferenceRecordingParams, recordChannel chan ApiV2010ConferenceRecording, errorChannel chan error) { curRecord := 1 for response != nil { @@ -241,7 +267,7 @@ func (c *ApiService) streamConferenceRecording(response *ListConferenceRecording } } - record, err := client.GetNext(c.baseURL, response, c.getNextListConferenceRecordingResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListConferenceRecordingResponse) if err != nil { errorChannel <- err break @@ -256,11 +282,11 @@ func (c *ApiService) streamConferenceRecording(response *ListConferenceRecording close(errorChannel) } -func (c *ApiService) getNextListConferenceRecordingResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListConferenceRecordingResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -299,6 +325,11 @@ 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.UpdateConferenceRecordingWithCtx(context.TODO(), ConferenceSid, Sid, params) +} + +// 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) UpdateConferenceRecordingWithCtx(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) @@ -318,7 +349,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.Post(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 f37ece34c..462e16366 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,11 @@ func (params *DeleteConnectAppParams) SetPathAccountSid(PathAccountSid string) * // Delete an instance of a connect-app func (c *ApiService) DeleteConnectApp(Sid string, params *DeleteConnectAppParams) error { + return c.DeleteConnectAppWithCtx(context.TODO(), Sid, params) +} + +// Delete an instance of a connect-app +func (c *ApiService) DeleteConnectAppWithCtx(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) @@ -47,7 +53,7 @@ func (c *ApiService) DeleteConnectApp(Sid string, params *DeleteConnectAppParams data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -70,6 +76,11 @@ 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.FetchConnectAppWithCtx(context.TODO(), Sid, params) +} + +// Fetch an instance of a connect-app +func (c *ApiService) FetchConnectAppWithCtx(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) @@ -81,7 +92,7 @@ func (c *ApiService) FetchConnectApp(Sid string, params *FetchConnectAppParams) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -121,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.PageConnectAppWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of ConnectApp records from the API. Request is executed immediately. +func (c *ApiService) PageConnectAppWithCtx(ctx context.Context, params *ListConnectAppParams, pageToken, pageNumber string) (*ListConnectAppResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/ConnectApps.json" if params != nil && params.PathAccountSid != nil { @@ -143,7 +159,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -160,7 +176,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.ListConnectAppWithCtx(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) ListConnectAppWithCtx(ctx context.Context, params *ListConnectAppParams) ([]ApiV2010ConnectApp, error) { + response, errors := c.StreamConnectAppWithCtx(ctx, params) records := make([]ApiV2010ConnectApp, 0) for record := range response { @@ -176,6 +197,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.StreamConnectAppWithCtx(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) StreamConnectAppWithCtx(ctx context.Context, params *ListConnectAppParams) (chan ApiV2010ConnectApp, chan error) { if params == nil { params = &ListConnectAppParams{} } @@ -184,19 +210,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.PageConnectAppWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamConnectApp(response, params, recordChannel, errorChannel) + go c.streamConnectApp(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) streamConnectApp(ctx context.Context, response *ListConnectAppResponse, params *ListConnectAppParams, recordChannel chan ApiV2010ConnectApp, errorChannel chan error) { curRecord := 1 for response != nil { @@ -211,7 +237,7 @@ func (c *ApiService) streamConnectApp(response *ListConnectAppResponse, params * } } - record, err := client.GetNext(c.baseURL, response, c.getNextListConnectAppResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListConnectAppResponse) if err != nil { errorChannel <- err break @@ -226,11 +252,11 @@ func (c *ApiService) streamConnectApp(response *ListConnectAppResponse, params * close(errorChannel) } -func (c *ApiService) getNextListConnectAppResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListConnectAppResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -305,6 +331,11 @@ 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.UpdateConnectAppWithCtx(context.TODO(), Sid, params) +} + +// Update a connect-app with the specified parameters +func (c *ApiService) UpdateConnectAppWithCtx(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) @@ -343,7 +374,7 @@ func (c *ApiService) UpdateConnectApp(Sid string, params *UpdateConnectAppParams } } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 a97f6e225..994f8abe5 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,11 @@ func (params *CreateIncomingPhoneNumberParams) SetAreaCode(AreaCode string) *Cre // Purchase a phone-number for the account. func (c *ApiService) CreateIncomingPhoneNumber(params *CreateIncomingPhoneNumberParams) (*ApiV2010IncomingPhoneNumber, error) { + return c.CreateIncomingPhoneNumberWithCtx(context.TODO(), params) +} + +// Purchase a phone-number for the account. +func (c *ApiService) CreateIncomingPhoneNumberWithCtx(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) @@ -263,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -291,6 +297,11 @@ 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.DeleteIncomingPhoneNumberWithCtx(context.TODO(), Sid, params) +} + +// Delete a phone-numbers belonging to the account used to make the request. +func (c *ApiService) DeleteIncomingPhoneNumberWithCtx(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) @@ -302,7 +313,7 @@ func (c *ApiService) DeleteIncomingPhoneNumber(Sid string, params *DeleteIncomin data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -325,6 +336,11 @@ 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.FetchIncomingPhoneNumberWithCtx(context.TODO(), Sid, params) +} + +// Fetch an incoming-phone-number belonging to the account used to make the request. +func (c *ApiService) FetchIncomingPhoneNumberWithCtx(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) @@ -336,7 +352,7 @@ func (c *ApiService) FetchIncomingPhoneNumber(Sid string, params *FetchIncomingP data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -400,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.PageIncomingPhoneNumberWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of IncomingPhoneNumber records from the API. Request is executed immediately. +func (c *ApiService) PageIncomingPhoneNumberWithCtx(ctx context.Context, params *ListIncomingPhoneNumberParams, pageToken, pageNumber string) (*ListIncomingPhoneNumberResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers.json" if params != nil && params.PathAccountSid != nil { @@ -434,7 +455,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -451,7 +472,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.ListIncomingPhoneNumberWithCtx(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) ListIncomingPhoneNumberWithCtx(ctx context.Context, params *ListIncomingPhoneNumberParams) ([]ApiV2010IncomingPhoneNumber, error) { + response, errors := c.StreamIncomingPhoneNumberWithCtx(ctx, params) records := make([]ApiV2010IncomingPhoneNumber, 0) for record := range response { @@ -467,6 +493,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.StreamIncomingPhoneNumberWithCtx(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) StreamIncomingPhoneNumberWithCtx(ctx context.Context, params *ListIncomingPhoneNumberParams) (chan ApiV2010IncomingPhoneNumber, chan error) { if params == nil { params = &ListIncomingPhoneNumberParams{} } @@ -475,19 +506,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.PageIncomingPhoneNumberWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamIncomingPhoneNumber(response, params, recordChannel, errorChannel) + go c.streamIncomingPhoneNumber(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) streamIncomingPhoneNumber(ctx context.Context, response *ListIncomingPhoneNumberResponse, params *ListIncomingPhoneNumberParams, recordChannel chan ApiV2010IncomingPhoneNumber, errorChannel chan error) { curRecord := 1 for response != nil { @@ -502,7 +533,7 @@ func (c *ApiService) streamIncomingPhoneNumber(response *ListIncomingPhoneNumber } } - record, err := client.GetNext(c.baseURL, response, c.getNextListIncomingPhoneNumberResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListIncomingPhoneNumberResponse) if err != nil { errorChannel <- err break @@ -517,11 +548,11 @@ func (c *ApiService) streamIncomingPhoneNumber(response *ListIncomingPhoneNumber close(errorChannel) } -func (c *ApiService) getNextListIncomingPhoneNumberResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListIncomingPhoneNumberResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -686,6 +717,11 @@ 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.UpdateIncomingPhoneNumberWithCtx(context.TODO(), Sid, params) +} + +// Update an incoming-phone-number instance. +func (c *ApiService) UpdateIncomingPhoneNumberWithCtx(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) @@ -767,7 +803,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.Post(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 c6ccd00d5..f79666b08 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,11 @@ 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.CreateIncomingPhoneNumberAssignedAddOnWithCtx(context.TODO(), ResourceSid, params) +} + +// Assign an Add-on installation to the Number specified. +func (c *ApiService) CreateIncomingPhoneNumberAssignedAddOnWithCtx(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) @@ -57,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -85,6 +91,11 @@ 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.DeleteIncomingPhoneNumberAssignedAddOnWithCtx(context.TODO(), ResourceSid, Sid, params) +} + +// Remove the assignment of an Add-on installation from the Number specified. +func (c *ApiService) DeleteIncomingPhoneNumberAssignedAddOnWithCtx(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) @@ -97,7 +108,7 @@ func (c *ApiService) DeleteIncomingPhoneNumberAssignedAddOn(ResourceSid string, data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -120,6 +131,11 @@ 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.FetchIncomingPhoneNumberAssignedAddOnWithCtx(context.TODO(), ResourceSid, Sid, params) +} + +// Fetch an instance of an Add-on installation currently assigned to this Number. +func (c *ApiService) FetchIncomingPhoneNumberAssignedAddOnWithCtx(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) @@ -132,7 +148,7 @@ func (c *ApiService) FetchIncomingPhoneNumberAssignedAddOn(ResourceSid string, S data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -172,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.PageIncomingPhoneNumberAssignedAddOnWithCtx(context.TODO(), ResourceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of IncomingPhoneNumberAssignedAddOn records from the API. Request is executed immediately. +func (c *ApiService) PageIncomingPhoneNumberAssignedAddOnWithCtx(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 { @@ -195,7 +216,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -212,7 +233,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.ListIncomingPhoneNumberAssignedAddOnWithCtx(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) ListIncomingPhoneNumberAssignedAddOnWithCtx(ctx context.Context, ResourceSid string, params *ListIncomingPhoneNumberAssignedAddOnParams) ([]ApiV2010IncomingPhoneNumberAssignedAddOn, error) { + response, errors := c.StreamIncomingPhoneNumberAssignedAddOnWithCtx(ctx, ResourceSid, params) records := make([]ApiV2010IncomingPhoneNumberAssignedAddOn, 0) for record := range response { @@ -228,6 +254,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.StreamIncomingPhoneNumberAssignedAddOnWithCtx(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) StreamIncomingPhoneNumberAssignedAddOnWithCtx(ctx context.Context, ResourceSid string, params *ListIncomingPhoneNumberAssignedAddOnParams) (chan ApiV2010IncomingPhoneNumberAssignedAddOn, chan error) { if params == nil { params = &ListIncomingPhoneNumberAssignedAddOnParams{} } @@ -236,19 +267,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.PageIncomingPhoneNumberAssignedAddOnWithCtx(ctx, ResourceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamIncomingPhoneNumberAssignedAddOn(response, params, recordChannel, errorChannel) + go c.streamIncomingPhoneNumberAssignedAddOn(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) streamIncomingPhoneNumberAssignedAddOn(ctx context.Context, response *ListIncomingPhoneNumberAssignedAddOnResponse, params *ListIncomingPhoneNumberAssignedAddOnParams, recordChannel chan ApiV2010IncomingPhoneNumberAssignedAddOn, errorChannel chan error) { curRecord := 1 for response != nil { @@ -263,7 +294,7 @@ func (c *ApiService) streamIncomingPhoneNumberAssignedAddOn(response *ListIncomi } } - record, err := client.GetNext(c.baseURL, response, c.getNextListIncomingPhoneNumberAssignedAddOnResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListIncomingPhoneNumberAssignedAddOnResponse) if err != nil { errorChannel <- err break @@ -278,11 +309,11 @@ func (c *ApiService) streamIncomingPhoneNumberAssignedAddOn(response *ListIncomi close(errorChannel) } -func (c *ApiService) getNextListIncomingPhoneNumberAssignedAddOnResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListIncomingPhoneNumberAssignedAddOnResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 981b2137a..8e27e143f 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,11 @@ 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.FetchIncomingPhoneNumberAssignedAddOnExtensionWithCtx(context.TODO(), ResourceSid, AssignedAddOnSid, Sid, params) +} + +// Fetch an instance of an Extension for the Assigned Add-on. +func (c *ApiService) FetchIncomingPhoneNumberAssignedAddOnExtensionWithCtx(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) @@ -49,7 +55,7 @@ func (c *ApiService) FetchIncomingPhoneNumberAssignedAddOnExtension(ResourceSid data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -89,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.PageIncomingPhoneNumberAssignedAddOnExtensionWithCtx(context.TODO(), ResourceSid, AssignedAddOnSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of IncomingPhoneNumberAssignedAddOnExtension records from the API. Request is executed immediately. +func (c *ApiService) PageIncomingPhoneNumberAssignedAddOnExtensionWithCtx(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 { @@ -113,7 +124,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -130,7 +141,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.ListIncomingPhoneNumberAssignedAddOnExtensionWithCtx(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) ListIncomingPhoneNumberAssignedAddOnExtensionWithCtx(ctx context.Context, ResourceSid string, AssignedAddOnSid string, params *ListIncomingPhoneNumberAssignedAddOnExtensionParams) ([]ApiV2010IncomingPhoneNumberAssignedAddOnExtension, error) { + response, errors := c.StreamIncomingPhoneNumberAssignedAddOnExtensionWithCtx(ctx, ResourceSid, AssignedAddOnSid, params) records := make([]ApiV2010IncomingPhoneNumberAssignedAddOnExtension, 0) for record := range response { @@ -146,6 +162,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.StreamIncomingPhoneNumberAssignedAddOnExtensionWithCtx(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) StreamIncomingPhoneNumberAssignedAddOnExtensionWithCtx(ctx context.Context, ResourceSid string, AssignedAddOnSid string, params *ListIncomingPhoneNumberAssignedAddOnExtensionParams) (chan ApiV2010IncomingPhoneNumberAssignedAddOnExtension, chan error) { if params == nil { params = &ListIncomingPhoneNumberAssignedAddOnExtensionParams{} } @@ -154,19 +175,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.PageIncomingPhoneNumberAssignedAddOnExtensionWithCtx(ctx, ResourceSid, AssignedAddOnSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamIncomingPhoneNumberAssignedAddOnExtension(response, params, recordChannel, errorChannel) + go c.streamIncomingPhoneNumberAssignedAddOnExtension(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) streamIncomingPhoneNumberAssignedAddOnExtension(ctx context.Context, response *ListIncomingPhoneNumberAssignedAddOnExtensionResponse, params *ListIncomingPhoneNumberAssignedAddOnExtensionParams, recordChannel chan ApiV2010IncomingPhoneNumberAssignedAddOnExtension, errorChannel chan error) { curRecord := 1 for response != nil { @@ -181,7 +202,7 @@ func (c *ApiService) streamIncomingPhoneNumberAssignedAddOnExtension(response *L } } - record, err := client.GetNext(c.baseURL, response, c.getNextListIncomingPhoneNumberAssignedAddOnExtensionResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListIncomingPhoneNumberAssignedAddOnExtensionResponse) if err != nil { errorChannel <- err break @@ -196,11 +217,11 @@ func (c *ApiService) streamIncomingPhoneNumberAssignedAddOnExtension(response *L close(errorChannel) } -func (c *ApiService) getNextListIncomingPhoneNumberAssignedAddOnExtensionResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListIncomingPhoneNumberAssignedAddOnExtensionResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 e40f5ff44..825b7c28c 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" @@ -174,6 +175,11 @@ func (params *CreateIncomingPhoneNumberLocalParams) SetBundleSid(BundleSid strin // func (c *ApiService) CreateIncomingPhoneNumberLocal(params *CreateIncomingPhoneNumberLocalParams) (*ApiV2010IncomingPhoneNumberLocal, error) { + return c.CreateIncomingPhoneNumberLocalWithCtx(context.TODO(), params) +} + +// +func (c *ApiService) CreateIncomingPhoneNumberLocalWithCtx(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) @@ -254,7 +260,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -318,6 +324,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.PageIncomingPhoneNumberLocalWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of IncomingPhoneNumberLocal records from the API. Request is executed immediately. +func (c *ApiService) PageIncomingPhoneNumberLocalWithCtx(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 { @@ -352,7 +363,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -369,7 +380,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.ListIncomingPhoneNumberLocalWithCtx(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) ListIncomingPhoneNumberLocalWithCtx(ctx context.Context, params *ListIncomingPhoneNumberLocalParams) ([]ApiV2010IncomingPhoneNumberLocal, error) { + response, errors := c.StreamIncomingPhoneNumberLocalWithCtx(ctx, params) records := make([]ApiV2010IncomingPhoneNumberLocal, 0) for record := range response { @@ -385,6 +401,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.StreamIncomingPhoneNumberLocalWithCtx(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) StreamIncomingPhoneNumberLocalWithCtx(ctx context.Context, params *ListIncomingPhoneNumberLocalParams) (chan ApiV2010IncomingPhoneNumberLocal, chan error) { if params == nil { params = &ListIncomingPhoneNumberLocalParams{} } @@ -393,19 +414,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.PageIncomingPhoneNumberLocalWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamIncomingPhoneNumberLocal(response, params, recordChannel, errorChannel) + go c.streamIncomingPhoneNumberLocal(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) streamIncomingPhoneNumberLocal(ctx context.Context, response *ListIncomingPhoneNumberLocalResponse, params *ListIncomingPhoneNumberLocalParams, recordChannel chan ApiV2010IncomingPhoneNumberLocal, errorChannel chan error) { curRecord := 1 for response != nil { @@ -420,7 +441,7 @@ func (c *ApiService) streamIncomingPhoneNumberLocal(response *ListIncomingPhoneN } } - record, err := client.GetNext(c.baseURL, response, c.getNextListIncomingPhoneNumberLocalResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListIncomingPhoneNumberLocalResponse) if err != nil { errorChannel <- err break @@ -435,11 +456,11 @@ func (c *ApiService) streamIncomingPhoneNumberLocal(response *ListIncomingPhoneN close(errorChannel) } -func (c *ApiService) getNextListIncomingPhoneNumberLocalResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListIncomingPhoneNumberLocalResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 feaef417a..79b71caac 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" @@ -174,6 +175,11 @@ func (params *CreateIncomingPhoneNumberMobileParams) SetBundleSid(BundleSid stri // func (c *ApiService) CreateIncomingPhoneNumberMobile(params *CreateIncomingPhoneNumberMobileParams) (*ApiV2010IncomingPhoneNumberMobile, error) { + return c.CreateIncomingPhoneNumberMobileWithCtx(context.TODO(), params) +} + +// +func (c *ApiService) CreateIncomingPhoneNumberMobileWithCtx(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) @@ -254,7 +260,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -318,6 +324,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.PageIncomingPhoneNumberMobileWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of IncomingPhoneNumberMobile records from the API. Request is executed immediately. +func (c *ApiService) PageIncomingPhoneNumberMobileWithCtx(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 { @@ -352,7 +363,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -369,7 +380,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.ListIncomingPhoneNumberMobileWithCtx(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) ListIncomingPhoneNumberMobileWithCtx(ctx context.Context, params *ListIncomingPhoneNumberMobileParams) ([]ApiV2010IncomingPhoneNumberMobile, error) { + response, errors := c.StreamIncomingPhoneNumberMobileWithCtx(ctx, params) records := make([]ApiV2010IncomingPhoneNumberMobile, 0) for record := range response { @@ -385,6 +401,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.StreamIncomingPhoneNumberMobileWithCtx(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) StreamIncomingPhoneNumberMobileWithCtx(ctx context.Context, params *ListIncomingPhoneNumberMobileParams) (chan ApiV2010IncomingPhoneNumberMobile, chan error) { if params == nil { params = &ListIncomingPhoneNumberMobileParams{} } @@ -393,19 +414,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.PageIncomingPhoneNumberMobileWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamIncomingPhoneNumberMobile(response, params, recordChannel, errorChannel) + go c.streamIncomingPhoneNumberMobile(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) streamIncomingPhoneNumberMobile(ctx context.Context, response *ListIncomingPhoneNumberMobileResponse, params *ListIncomingPhoneNumberMobileParams, recordChannel chan ApiV2010IncomingPhoneNumberMobile, errorChannel chan error) { curRecord := 1 for response != nil { @@ -420,7 +441,7 @@ func (c *ApiService) streamIncomingPhoneNumberMobile(response *ListIncomingPhone } } - record, err := client.GetNext(c.baseURL, response, c.getNextListIncomingPhoneNumberMobileResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListIncomingPhoneNumberMobileResponse) if err != nil { errorChannel <- err break @@ -435,11 +456,11 @@ func (c *ApiService) streamIncomingPhoneNumberMobile(response *ListIncomingPhone close(errorChannel) } -func (c *ApiService) getNextListIncomingPhoneNumberMobileResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListIncomingPhoneNumberMobileResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 f178aed9e..61c080a27 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" @@ -174,6 +175,11 @@ func (params *CreateIncomingPhoneNumberTollFreeParams) SetBundleSid(BundleSid st // func (c *ApiService) CreateIncomingPhoneNumberTollFree(params *CreateIncomingPhoneNumberTollFreeParams) (*ApiV2010IncomingPhoneNumberTollFree, error) { + return c.CreateIncomingPhoneNumberTollFreeWithCtx(context.TODO(), params) +} + +// +func (c *ApiService) CreateIncomingPhoneNumberTollFreeWithCtx(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) @@ -254,7 +260,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -318,6 +324,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.PageIncomingPhoneNumberTollFreeWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of IncomingPhoneNumberTollFree records from the API. Request is executed immediately. +func (c *ApiService) PageIncomingPhoneNumberTollFreeWithCtx(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 { @@ -352,7 +363,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -369,7 +380,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.ListIncomingPhoneNumberTollFreeWithCtx(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) ListIncomingPhoneNumberTollFreeWithCtx(ctx context.Context, params *ListIncomingPhoneNumberTollFreeParams) ([]ApiV2010IncomingPhoneNumberTollFree, error) { + response, errors := c.StreamIncomingPhoneNumberTollFreeWithCtx(ctx, params) records := make([]ApiV2010IncomingPhoneNumberTollFree, 0) for record := range response { @@ -385,6 +401,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.StreamIncomingPhoneNumberTollFreeWithCtx(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) StreamIncomingPhoneNumberTollFreeWithCtx(ctx context.Context, params *ListIncomingPhoneNumberTollFreeParams) (chan ApiV2010IncomingPhoneNumberTollFree, chan error) { if params == nil { params = &ListIncomingPhoneNumberTollFreeParams{} } @@ -393,19 +414,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.PageIncomingPhoneNumberTollFreeWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamIncomingPhoneNumberTollFree(response, params, recordChannel, errorChannel) + go c.streamIncomingPhoneNumberTollFree(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) streamIncomingPhoneNumberTollFree(ctx context.Context, response *ListIncomingPhoneNumberTollFreeResponse, params *ListIncomingPhoneNumberTollFreeParams, recordChannel chan ApiV2010IncomingPhoneNumberTollFree, errorChannel chan error) { curRecord := 1 for response != nil { @@ -420,7 +441,7 @@ func (c *ApiService) streamIncomingPhoneNumberTollFree(response *ListIncomingPho } } - record, err := client.GetNext(c.baseURL, response, c.getNextListIncomingPhoneNumberTollFreeResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListIncomingPhoneNumberTollFreeResponse) if err != nil { errorChannel <- err break @@ -435,11 +456,11 @@ func (c *ApiService) streamIncomingPhoneNumberTollFree(response *ListIncomingPho close(errorChannel) } -func (c *ApiService) getNextListIncomingPhoneNumberTollFreeResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListIncomingPhoneNumberTollFreeResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 47e4335d5..21d88b539 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" @@ -42,6 +43,11 @@ func (params *CreateNewKeyParams) SetFriendlyName(FriendlyName string) *CreateNe // func (c *ApiService) CreateNewKey(params *CreateNewKeyParams) (*ApiV2010NewKey, error) { + return c.CreateNewKeyWithCtx(context.TODO(), params) +} + +// +func (c *ApiService) CreateNewKeyWithCtx(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) @@ -56,7 +62,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -84,6 +90,11 @@ func (params *DeleteKeyParams) SetPathAccountSid(PathAccountSid string) *DeleteK // func (c *ApiService) DeleteKey(Sid string, params *DeleteKeyParams) error { + return c.DeleteKeyWithCtx(context.TODO(), Sid, params) +} + +// +func (c *ApiService) DeleteKeyWithCtx(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) @@ -95,7 +106,7 @@ func (c *ApiService) DeleteKey(Sid string, params *DeleteKeyParams) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -118,6 +129,11 @@ func (params *FetchKeyParams) SetPathAccountSid(PathAccountSid string) *FetchKey // func (c *ApiService) FetchKey(Sid string, params *FetchKeyParams) (*ApiV2010Key, error) { + return c.FetchKeyWithCtx(context.TODO(), Sid, params) +} + +// +func (c *ApiService) FetchKeyWithCtx(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) @@ -129,7 +145,7 @@ func (c *ApiService) FetchKey(Sid string, params *FetchKeyParams) (*ApiV2010Key, data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -169,6 +185,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.PageKeyWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Key records from the API. Request is executed immediately. +func (c *ApiService) PageKeyWithCtx(ctx context.Context, params *ListKeyParams, pageToken, pageNumber string) (*ListKeyResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/Keys.json" if params != nil && params.PathAccountSid != nil { @@ -191,7 +212,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -208,7 +229,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.ListKeyWithCtx(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) ListKeyWithCtx(ctx context.Context, params *ListKeyParams) ([]ApiV2010Key, error) { + response, errors := c.StreamKeyWithCtx(ctx, params) records := make([]ApiV2010Key, 0) for record := range response { @@ -224,6 +250,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.StreamKeyWithCtx(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) StreamKeyWithCtx(ctx context.Context, params *ListKeyParams) (chan ApiV2010Key, chan error) { if params == nil { params = &ListKeyParams{} } @@ -232,19 +263,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.PageKeyWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamKey(response, params, recordChannel, errorChannel) + go c.streamKey(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) streamKey(ctx context.Context, response *ListKeyResponse, params *ListKeyParams, recordChannel chan ApiV2010Key, errorChannel chan error) { curRecord := 1 for response != nil { @@ -259,7 +290,7 @@ func (c *ApiService) streamKey(response *ListKeyResponse, params *ListKeyParams, } } - record, err := client.GetNext(c.baseURL, response, c.getNextListKeyResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListKeyResponse) if err != nil { errorChannel <- err break @@ -274,11 +305,11 @@ func (c *ApiService) streamKey(response *ListKeyResponse, params *ListKeyParams, close(errorChannel) } -func (c *ApiService) getNextListKeyResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListKeyResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -311,6 +342,11 @@ func (params *UpdateKeyParams) SetFriendlyName(FriendlyName string) *UpdateKeyPa // func (c *ApiService) UpdateKey(Sid string, params *UpdateKeyParams) (*ApiV2010Key, error) { + return c.UpdateKeyWithCtx(context.TODO(), Sid, params) +} + +// +func (c *ApiService) UpdateKeyWithCtx(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) @@ -326,7 +362,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.Post(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 42d3c7151..ae6375fbe 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" @@ -157,6 +158,11 @@ func (params *CreateMessageParams) SetMediaUrl(MediaUrl []string) *CreateMessage // Send a message from the account used to make the request func (c *ApiService) CreateMessage(params *CreateMessageParams) (*ApiV2010Message, error) { + return c.CreateMessageWithCtx(context.TODO(), params) +} + +// Send a message from the account used to make the request +func (c *ApiService) CreateMessageWithCtx(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) @@ -232,7 +238,7 @@ func (c *ApiService) CreateMessage(params *CreateMessageParams) (*ApiV2010Messag } } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -260,6 +266,11 @@ func (params *DeleteMessageParams) SetPathAccountSid(PathAccountSid string) *Del // Deletes a message record from your account func (c *ApiService) DeleteMessage(Sid string, params *DeleteMessageParams) error { + return c.DeleteMessageWithCtx(context.TODO(), Sid, params) +} + +// Deletes a message record from your account +func (c *ApiService) DeleteMessageWithCtx(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) @@ -271,7 +282,7 @@ func (c *ApiService) DeleteMessage(Sid string, params *DeleteMessageParams) erro data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -294,6 +305,11 @@ func (params *FetchMessageParams) SetPathAccountSid(PathAccountSid string) *Fetc // Fetch a message belonging to the account used to make the request func (c *ApiService) FetchMessage(Sid string, params *FetchMessageParams) (*ApiV2010Message, error) { + return c.FetchMessageWithCtx(context.TODO(), Sid, params) +} + +// Fetch a message belonging to the account used to make the request +func (c *ApiService) FetchMessageWithCtx(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) @@ -305,7 +321,7 @@ func (c *ApiService) FetchMessage(Sid string, params *FetchMessageParams) (*ApiV data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -375,6 +391,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.PageMessageWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Message records from the API. Request is executed immediately. +func (c *ApiService) PageMessageWithCtx(ctx context.Context, params *ListMessageParams, pageToken, pageNumber string) (*ListMessageResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/Messages.json" if params != nil && params.PathAccountSid != nil { @@ -412,7 +433,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -429,7 +450,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.ListMessageWithCtx(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) ListMessageWithCtx(ctx context.Context, params *ListMessageParams) ([]ApiV2010Message, error) { + response, errors := c.StreamMessageWithCtx(ctx, params) records := make([]ApiV2010Message, 0) for record := range response { @@ -445,6 +471,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.StreamMessageWithCtx(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) StreamMessageWithCtx(ctx context.Context, params *ListMessageParams) (chan ApiV2010Message, chan error) { if params == nil { params = &ListMessageParams{} } @@ -453,19 +484,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.PageMessageWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamMessage(response, params, recordChannel, errorChannel) + go c.streamMessage(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) streamMessage(ctx context.Context, response *ListMessageResponse, params *ListMessageParams, recordChannel chan ApiV2010Message, errorChannel chan error) { curRecord := 1 for response != nil { @@ -480,7 +511,7 @@ func (c *ApiService) streamMessage(response *ListMessageResponse, params *ListMe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListMessageResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListMessageResponse) if err != nil { errorChannel <- err break @@ -495,11 +526,11 @@ func (c *ApiService) streamMessage(response *ListMessageResponse, params *ListMe close(errorChannel) } -func (c *ApiService) getNextListMessageResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListMessageResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -538,6 +569,11 @@ func (params *UpdateMessageParams) SetStatus(Status string) *UpdateMessageParams // To redact a message-body from a post-flight message record, post to the message instance resource with an empty body func (c *ApiService) UpdateMessage(Sid string, params *UpdateMessageParams) (*ApiV2010Message, error) { + return c.UpdateMessageWithCtx(context.TODO(), Sid, params) +} + +// To redact a message-body from a post-flight message record, post to the message instance resource with an empty body +func (c *ApiService) UpdateMessageWithCtx(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) @@ -556,7 +592,7 @@ func (c *ApiService) UpdateMessage(Sid string, params *UpdateMessageParams) (*Ap data.Set("Status", *params.Status) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 195ef83ec..aaf583c7d 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" "net/url" "strings" @@ -39,6 +40,11 @@ func (params *CreateMessageFeedbackParams) SetOutcome(Outcome string) *CreateMes // func (c *ApiService) CreateMessageFeedback(MessageSid string, params *CreateMessageFeedbackParams) (*ApiV2010MessageFeedback, error) { + return c.CreateMessageFeedbackWithCtx(context.TODO(), MessageSid, params) +} + +// +func (c *ApiService) CreateMessageFeedbackWithCtx(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) @@ -54,7 +60,7 @@ func (c *ApiService) CreateMessageFeedback(MessageSid string, params *CreateMess data.Set("Outcome", *params.Outcome) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 eb138083d..d1505c810 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,11 @@ func (params *DeleteMediaParams) SetPathAccountSid(PathAccountSid string) *Delet // Delete media from your account. Once delete, you will no longer be billed func (c *ApiService) DeleteMedia(MessageSid string, Sid string, params *DeleteMediaParams) error { + return c.DeleteMediaWithCtx(context.TODO(), MessageSid, Sid, params) +} + +// Delete media from your account. Once delete, you will no longer be billed +func (c *ApiService) DeleteMediaWithCtx(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) @@ -49,7 +55,7 @@ func (c *ApiService) DeleteMedia(MessageSid string, Sid string, params *DeleteMe data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -72,6 +78,11 @@ func (params *FetchMediaParams) SetPathAccountSid(PathAccountSid string) *FetchM // Fetch a single media instance belonging to the account used to make the request func (c *ApiService) FetchMedia(MessageSid string, Sid string, params *FetchMediaParams) (*ApiV2010Media, error) { + return c.FetchMediaWithCtx(context.TODO(), MessageSid, Sid, params) +} + +// Fetch a single media instance belonging to the account used to make the request +func (c *ApiService) FetchMediaWithCtx(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) @@ -84,7 +95,7 @@ func (c *ApiService) FetchMedia(MessageSid string, Sid string, params *FetchMedi data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -142,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.PageMediaWithCtx(context.TODO(), MessageSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Media records from the API. Request is executed immediately. +func (c *ApiService) PageMediaWithCtx(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 { @@ -174,7 +190,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -191,7 +207,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.ListMediaWithCtx(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) ListMediaWithCtx(ctx context.Context, MessageSid string, params *ListMediaParams) ([]ApiV2010Media, error) { + response, errors := c.StreamMediaWithCtx(ctx, MessageSid, params) records := make([]ApiV2010Media, 0) for record := range response { @@ -207,6 +228,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.StreamMediaWithCtx(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) StreamMediaWithCtx(ctx context.Context, MessageSid string, params *ListMediaParams) (chan ApiV2010Media, chan error) { if params == nil { params = &ListMediaParams{} } @@ -215,19 +241,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.PageMediaWithCtx(ctx, MessageSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamMedia(response, params, recordChannel, errorChannel) + go c.streamMedia(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) streamMedia(ctx context.Context, response *ListMediaResponse, params *ListMediaParams, recordChannel chan ApiV2010Media, errorChannel chan error) { curRecord := 1 for response != nil { @@ -242,7 +268,7 @@ func (c *ApiService) streamMedia(response *ListMediaResponse, params *ListMediaP } } - record, err := client.GetNext(c.baseURL, response, c.getNextListMediaResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListMediaResponse) if err != nil { errorChannel <- err break @@ -257,11 +283,11 @@ func (c *ApiService) streamMedia(response *ListMediaResponse, params *ListMediaP close(errorChannel) } -func (c *ApiService) getNextListMediaResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListMediaResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 4151a7021..c4f9482fe 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,11 @@ 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.FetchNotificationWithCtx(context.TODO(), Sid, params) +} + +// Fetch a notification belonging to the account used to make the request +func (c *ApiService) FetchNotificationWithCtx(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) @@ -47,7 +53,7 @@ func (c *ApiService) FetchNotification(Sid string, params *FetchNotificationPara data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -111,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.PageNotificationWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Notification records from the API. Request is executed immediately. +func (c *ApiService) PageNotificationWithCtx(ctx context.Context, params *ListNotificationParams, pageToken, pageNumber string) (*ListNotificationResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/Notifications.json" if params != nil && params.PathAccountSid != nil { @@ -145,7 +156,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -162,7 +173,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.ListNotificationWithCtx(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) ListNotificationWithCtx(ctx context.Context, params *ListNotificationParams) ([]ApiV2010Notification, error) { + response, errors := c.StreamNotificationWithCtx(ctx, params) records := make([]ApiV2010Notification, 0) for record := range response { @@ -178,6 +194,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.StreamNotificationWithCtx(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) StreamNotificationWithCtx(ctx context.Context, params *ListNotificationParams) (chan ApiV2010Notification, chan error) { if params == nil { params = &ListNotificationParams{} } @@ -186,19 +207,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.PageNotificationWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamNotification(response, params, recordChannel, errorChannel) + go c.streamNotification(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) streamNotification(ctx context.Context, response *ListNotificationResponse, params *ListNotificationParams, recordChannel chan ApiV2010Notification, errorChannel chan error) { curRecord := 1 for response != nil { @@ -213,7 +234,7 @@ func (c *ApiService) streamNotification(response *ListNotificationResponse, para } } - record, err := client.GetNext(c.baseURL, response, c.getNextListNotificationResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListNotificationResponse) if err != nil { errorChannel <- err break @@ -228,11 +249,11 @@ func (c *ApiService) streamNotification(response *ListNotificationResponse, para close(errorChannel) } -func (c *ApiService) getNextListNotificationResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListNotificationResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 1d91a9389..92ccdb159 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" @@ -72,6 +73,11 @@ func (params *CreateValidationRequestParams) SetStatusCallbackMethod(StatusCallb // func (c *ApiService) CreateValidationRequest(params *CreateValidationRequestParams) (*ApiV2010ValidationRequest, error) { + return c.CreateValidationRequestWithCtx(context.TODO(), params) +} + +// +func (c *ApiService) CreateValidationRequestWithCtx(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) @@ -101,7 +107,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -129,6 +135,11 @@ 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.DeleteOutgoingCallerIdWithCtx(context.TODO(), Sid, params) +} + +// Delete the caller-id specified from the account +func (c *ApiService) DeleteOutgoingCallerIdWithCtx(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) @@ -140,7 +151,7 @@ func (c *ApiService) DeleteOutgoingCallerId(Sid string, params *DeleteOutgoingCa data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -163,6 +174,11 @@ 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.FetchOutgoingCallerIdWithCtx(context.TODO(), Sid, params) +} + +// Fetch an outgoing-caller-id belonging to the account used to make the request +func (c *ApiService) FetchOutgoingCallerIdWithCtx(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) @@ -174,7 +190,7 @@ func (c *ApiService) FetchOutgoingCallerId(Sid string, params *FetchOutgoingCall data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -226,6 +242,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.PageOutgoingCallerIdWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of OutgoingCallerId records from the API. Request is executed immediately. +func (c *ApiService) PageOutgoingCallerIdWithCtx(ctx context.Context, params *ListOutgoingCallerIdParams, pageToken, pageNumber string) (*ListOutgoingCallerIdResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/OutgoingCallerIds.json" if params != nil && params.PathAccountSid != nil { @@ -254,7 +275,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -271,7 +292,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.ListOutgoingCallerIdWithCtx(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) ListOutgoingCallerIdWithCtx(ctx context.Context, params *ListOutgoingCallerIdParams) ([]ApiV2010OutgoingCallerId, error) { + response, errors := c.StreamOutgoingCallerIdWithCtx(ctx, params) records := make([]ApiV2010OutgoingCallerId, 0) for record := range response { @@ -287,6 +313,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.StreamOutgoingCallerIdWithCtx(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) StreamOutgoingCallerIdWithCtx(ctx context.Context, params *ListOutgoingCallerIdParams) (chan ApiV2010OutgoingCallerId, chan error) { if params == nil { params = &ListOutgoingCallerIdParams{} } @@ -295,19 +326,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.PageOutgoingCallerIdWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamOutgoingCallerId(response, params, recordChannel, errorChannel) + go c.streamOutgoingCallerId(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) streamOutgoingCallerId(ctx context.Context, response *ListOutgoingCallerIdResponse, params *ListOutgoingCallerIdParams, recordChannel chan ApiV2010OutgoingCallerId, errorChannel chan error) { curRecord := 1 for response != nil { @@ -322,7 +353,7 @@ func (c *ApiService) streamOutgoingCallerId(response *ListOutgoingCallerIdRespon } } - record, err := client.GetNext(c.baseURL, response, c.getNextListOutgoingCallerIdResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListOutgoingCallerIdResponse) if err != nil { errorChannel <- err break @@ -337,11 +368,11 @@ func (c *ApiService) streamOutgoingCallerId(response *ListOutgoingCallerIdRespon close(errorChannel) } -func (c *ApiService) getNextListOutgoingCallerIdResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListOutgoingCallerIdResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -374,6 +405,11 @@ func (params *UpdateOutgoingCallerIdParams) SetFriendlyName(FriendlyName string) // Updates the caller-id func (c *ApiService) UpdateOutgoingCallerId(Sid string, params *UpdateOutgoingCallerIdParams) (*ApiV2010OutgoingCallerId, error) { + return c.UpdateOutgoingCallerIdWithCtx(context.TODO(), Sid, params) +} + +// Updates the caller-id +func (c *ApiService) UpdateOutgoingCallerIdWithCtx(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) @@ -389,7 +425,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.Post(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 562a37437..f4b7f8921 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,11 @@ func (params *CreateQueueParams) SetMaxSize(MaxSize int) *CreateQueueParams { // Create a queue func (c *ApiService) CreateQueue(params *CreateQueueParams) (*ApiV2010Queue, error) { + return c.CreateQueueWithCtx(context.TODO(), params) +} + +// Create a queue +func (c *ApiService) CreateQueueWithCtx(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) @@ -65,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -93,6 +99,11 @@ func (params *DeleteQueueParams) SetPathAccountSid(PathAccountSid string) *Delet // Remove an empty queue func (c *ApiService) DeleteQueue(Sid string, params *DeleteQueueParams) error { + return c.DeleteQueueWithCtx(context.TODO(), Sid, params) +} + +// Remove an empty queue +func (c *ApiService) DeleteQueueWithCtx(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) @@ -104,7 +115,7 @@ func (c *ApiService) DeleteQueue(Sid string, params *DeleteQueueParams) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -127,6 +138,11 @@ 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.FetchQueueWithCtx(context.TODO(), Sid, params) +} + +// Fetch an instance of a queue identified by the QueueSid +func (c *ApiService) FetchQueueWithCtx(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) @@ -138,7 +154,7 @@ func (c *ApiService) FetchQueue(Sid string, params *FetchQueueParams) (*ApiV2010 data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -178,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.PageQueueWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Queue records from the API. Request is executed immediately. +func (c *ApiService) PageQueueWithCtx(ctx context.Context, params *ListQueueParams, pageToken, pageNumber string) (*ListQueueResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/Queues.json" if params != nil && params.PathAccountSid != nil { @@ -200,7 +221,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -217,7 +238,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.ListQueueWithCtx(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) ListQueueWithCtx(ctx context.Context, params *ListQueueParams) ([]ApiV2010Queue, error) { + response, errors := c.StreamQueueWithCtx(ctx, params) records := make([]ApiV2010Queue, 0) for record := range response { @@ -233,6 +259,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.StreamQueueWithCtx(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) StreamQueueWithCtx(ctx context.Context, params *ListQueueParams) (chan ApiV2010Queue, chan error) { if params == nil { params = &ListQueueParams{} } @@ -241,19 +272,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.PageQueueWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamQueue(response, params, recordChannel, errorChannel) + go c.streamQueue(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) streamQueue(ctx context.Context, response *ListQueueResponse, params *ListQueueParams, recordChannel chan ApiV2010Queue, errorChannel chan error) { curRecord := 1 for response != nil { @@ -268,7 +299,7 @@ func (c *ApiService) streamQueue(response *ListQueueResponse, params *ListQueueP } } - record, err := client.GetNext(c.baseURL, response, c.getNextListQueueResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListQueueResponse) if err != nil { errorChannel <- err break @@ -283,11 +314,11 @@ func (c *ApiService) streamQueue(response *ListQueueResponse, params *ListQueueP close(errorChannel) } -func (c *ApiService) getNextListQueueResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListQueueResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -326,6 +357,11 @@ 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.UpdateQueueWithCtx(context.TODO(), Sid, params) +} + +// Update the queue with the new parameters +func (c *ApiService) UpdateQueueWithCtx(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) @@ -344,7 +380,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.Post(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 71ddeb65e..dbf6e08da 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,11 @@ 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.FetchMemberWithCtx(context.TODO(), QueueSid, CallSid, params) +} + +// Fetch a specific member from the queue +func (c *ApiService) FetchMemberWithCtx(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) @@ -48,7 +54,7 @@ func (c *ApiService) FetchMember(QueueSid string, CallSid string, params *FetchM data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -88,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.PageMemberWithCtx(context.TODO(), QueueSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Member records from the API. Request is executed immediately. +func (c *ApiService) PageMemberWithCtx(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 { @@ -111,7 +122,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -128,7 +139,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.ListMemberWithCtx(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) ListMemberWithCtx(ctx context.Context, QueueSid string, params *ListMemberParams) ([]ApiV2010Member, error) { + response, errors := c.StreamMemberWithCtx(ctx, QueueSid, params) records := make([]ApiV2010Member, 0) for record := range response { @@ -144,6 +160,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.StreamMemberWithCtx(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) StreamMemberWithCtx(ctx context.Context, QueueSid string, params *ListMemberParams) (chan ApiV2010Member, chan error) { if params == nil { params = &ListMemberParams{} } @@ -152,19 +173,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.PageMemberWithCtx(ctx, QueueSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamMember(response, params, recordChannel, errorChannel) + go c.streamMember(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) streamMember(ctx context.Context, response *ListMemberResponse, params *ListMemberParams, recordChannel chan ApiV2010Member, errorChannel chan error) { curRecord := 1 for response != nil { @@ -179,7 +200,7 @@ func (c *ApiService) streamMember(response *ListMemberResponse, params *ListMemb } } - record, err := client.GetNext(c.baseURL, response, c.getNextListMemberResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListMemberResponse) if err != nil { errorChannel <- err break @@ -194,11 +215,11 @@ func (c *ApiService) streamMember(response *ListMemberResponse, params *ListMemb close(errorChannel) } -func (c *ApiService) getNextListMemberResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListMemberResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -237,6 +258,11 @@ 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.UpdateMemberWithCtx(context.TODO(), QueueSid, CallSid, params) +} + +// Dequeue a member from a queue and have the member's call begin executing the TwiML document at that URL +func (c *ApiService) UpdateMemberWithCtx(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) @@ -256,7 +282,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.Post(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 cae717617..3f0147dfc 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,11 @@ func (params *DeleteRecordingParams) SetPathAccountSid(PathAccountSid string) *D // Delete a recording from your account func (c *ApiService) DeleteRecording(Sid string, params *DeleteRecordingParams) error { + return c.DeleteRecordingWithCtx(context.TODO(), Sid, params) +} + +// Delete a recording from your account +func (c *ApiService) DeleteRecordingWithCtx(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) @@ -48,7 +54,7 @@ func (c *ApiService) DeleteRecording(Sid string, params *DeleteRecordingParams) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -77,6 +83,11 @@ func (params *FetchRecordingParams) SetIncludeSoftDeleted(IncludeSoftDeleted boo // Fetch an instance of a recording func (c *ApiService) FetchRecording(Sid string, params *FetchRecordingParams) (*ApiV2010Recording, error) { + return c.FetchRecordingWithCtx(context.TODO(), Sid, params) +} + +// Fetch an instance of a recording +func (c *ApiService) FetchRecordingWithCtx(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) @@ -92,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -168,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.PageRecordingWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Recording records from the API. Request is executed immediately. +func (c *ApiService) PageRecordingWithCtx(ctx context.Context, params *ListRecordingParams, pageToken, pageNumber string) (*ListRecordingResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/Recordings.json" if params != nil && params.PathAccountSid != nil { @@ -208,7 +224,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -225,7 +241,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.ListRecordingWithCtx(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) ListRecordingWithCtx(ctx context.Context, params *ListRecordingParams) ([]ApiV2010Recording, error) { + response, errors := c.StreamRecordingWithCtx(ctx, params) records := make([]ApiV2010Recording, 0) for record := range response { @@ -241,6 +262,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.StreamRecordingWithCtx(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) StreamRecordingWithCtx(ctx context.Context, params *ListRecordingParams) (chan ApiV2010Recording, chan error) { if params == nil { params = &ListRecordingParams{} } @@ -249,19 +275,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.PageRecordingWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamRecording(response, params, recordChannel, errorChannel) + go c.streamRecording(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) streamRecording(ctx context.Context, response *ListRecordingResponse, params *ListRecordingParams, recordChannel chan ApiV2010Recording, errorChannel chan error) { curRecord := 1 for response != nil { @@ -276,7 +302,7 @@ func (c *ApiService) streamRecording(response *ListRecordingResponse, params *Li } } - record, err := client.GetNext(c.baseURL, response, c.getNextListRecordingResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListRecordingResponse) if err != nil { errorChannel <- err break @@ -291,11 +317,11 @@ func (c *ApiService) streamRecording(response *ListRecordingResponse, params *Li close(errorChannel) } -func (c *ApiService) getNextListRecordingResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListRecordingResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 69857f08e..022bc7fef 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,11 @@ 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.DeleteRecordingAddOnResultWithCtx(context.TODO(), ReferenceSid, Sid, params) +} + +// Delete a result and purge all associated Payloads +func (c *ApiService) DeleteRecordingAddOnResultWithCtx(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) @@ -48,7 +54,7 @@ func (c *ApiService) DeleteRecordingAddOnResult(ReferenceSid string, Sid string, data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -71,6 +77,11 @@ 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.FetchRecordingAddOnResultWithCtx(context.TODO(), ReferenceSid, Sid, params) +} + +// Fetch an instance of an AddOnResult +func (c *ApiService) FetchRecordingAddOnResultWithCtx(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) @@ -83,7 +94,7 @@ func (c *ApiService) FetchRecordingAddOnResult(ReferenceSid string, Sid string, data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -123,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.PageRecordingAddOnResultWithCtx(context.TODO(), ReferenceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of RecordingAddOnResult records from the API. Request is executed immediately. +func (c *ApiService) PageRecordingAddOnResultWithCtx(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 { @@ -146,7 +162,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -163,7 +179,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.ListRecordingAddOnResultWithCtx(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) ListRecordingAddOnResultWithCtx(ctx context.Context, ReferenceSid string, params *ListRecordingAddOnResultParams) ([]ApiV2010RecordingAddOnResult, error) { + response, errors := c.StreamRecordingAddOnResultWithCtx(ctx, ReferenceSid, params) records := make([]ApiV2010RecordingAddOnResult, 0) for record := range response { @@ -179,6 +200,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.StreamRecordingAddOnResultWithCtx(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) StreamRecordingAddOnResultWithCtx(ctx context.Context, ReferenceSid string, params *ListRecordingAddOnResultParams) (chan ApiV2010RecordingAddOnResult, chan error) { if params == nil { params = &ListRecordingAddOnResultParams{} } @@ -187,19 +213,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.PageRecordingAddOnResultWithCtx(ctx, ReferenceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamRecordingAddOnResult(response, params, recordChannel, errorChannel) + go c.streamRecordingAddOnResult(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) streamRecordingAddOnResult(ctx context.Context, response *ListRecordingAddOnResultResponse, params *ListRecordingAddOnResultParams, recordChannel chan ApiV2010RecordingAddOnResult, errorChannel chan error) { curRecord := 1 for response != nil { @@ -214,7 +240,7 @@ func (c *ApiService) streamRecordingAddOnResult(response *ListRecordingAddOnResu } } - record, err := client.GetNext(c.baseURL, response, c.getNextListRecordingAddOnResultResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListRecordingAddOnResultResponse) if err != nil { errorChannel <- err break @@ -229,11 +255,11 @@ func (c *ApiService) streamRecordingAddOnResult(response *ListRecordingAddOnResu close(errorChannel) } -func (c *ApiService) getNextListRecordingAddOnResultResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListRecordingAddOnResultResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 e9738d49a..07619ac78 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,11 @@ 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.DeleteRecordingAddOnResultPayloadWithCtx(context.TODO(), ReferenceSid, AddOnResultSid, Sid, params) +} + +// Delete a payload from the result along with all associated Data +func (c *ApiService) DeleteRecordingAddOnResultPayloadWithCtx(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) @@ -49,7 +55,7 @@ func (c *ApiService) DeleteRecordingAddOnResultPayload(ReferenceSid string, AddO data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -72,6 +78,11 @@ 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.FetchRecordingAddOnResultPayloadWithCtx(context.TODO(), ReferenceSid, AddOnResultSid, Sid, params) +} + +// Fetch an instance of a result payload +func (c *ApiService) FetchRecordingAddOnResultPayloadWithCtx(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) @@ -85,7 +96,7 @@ func (c *ApiService) FetchRecordingAddOnResultPayload(ReferenceSid string, AddOn data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -125,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.PageRecordingAddOnResultPayloadWithCtx(context.TODO(), ReferenceSid, AddOnResultSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of RecordingAddOnResultPayload records from the API. Request is executed immediately. +func (c *ApiService) PageRecordingAddOnResultPayloadWithCtx(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 { @@ -149,7 +165,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -166,7 +182,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.ListRecordingAddOnResultPayloadWithCtx(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) ListRecordingAddOnResultPayloadWithCtx(ctx context.Context, ReferenceSid string, AddOnResultSid string, params *ListRecordingAddOnResultPayloadParams) ([]ApiV2010RecordingAddOnResultPayload, error) { + response, errors := c.StreamRecordingAddOnResultPayloadWithCtx(ctx, ReferenceSid, AddOnResultSid, params) records := make([]ApiV2010RecordingAddOnResultPayload, 0) for record := range response { @@ -182,6 +203,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.StreamRecordingAddOnResultPayloadWithCtx(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) StreamRecordingAddOnResultPayloadWithCtx(ctx context.Context, ReferenceSid string, AddOnResultSid string, params *ListRecordingAddOnResultPayloadParams) (chan ApiV2010RecordingAddOnResultPayload, chan error) { if params == nil { params = &ListRecordingAddOnResultPayloadParams{} } @@ -190,19 +216,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.PageRecordingAddOnResultPayloadWithCtx(ctx, ReferenceSid, AddOnResultSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamRecordingAddOnResultPayload(response, params, recordChannel, errorChannel) + go c.streamRecordingAddOnResultPayload(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) streamRecordingAddOnResultPayload(ctx context.Context, response *ListRecordingAddOnResultPayloadResponse, params *ListRecordingAddOnResultPayloadParams, recordChannel chan ApiV2010RecordingAddOnResultPayload, errorChannel chan error) { curRecord := 1 for response != nil { @@ -217,7 +243,7 @@ func (c *ApiService) streamRecordingAddOnResultPayload(response *ListRecordingAd } } - record, err := client.GetNext(c.baseURL, response, c.getNextListRecordingAddOnResultPayloadResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListRecordingAddOnResultPayloadResponse) if err != nil { errorChannel <- err break @@ -232,11 +258,11 @@ func (c *ApiService) streamRecordingAddOnResultPayload(response *ListRecordingAd close(errorChannel) } -func (c *ApiService) getNextListRecordingAddOnResultPayloadResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListRecordingAddOnResultPayloadResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) 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 c1ca8d02e..64811607f 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" @@ -36,6 +37,11 @@ func (params *DeleteRecordingTranscriptionParams) SetPathAccountSid(PathAccountS // func (c *ApiService) DeleteRecordingTranscription(RecordingSid string, Sid string, params *DeleteRecordingTranscriptionParams) error { + return c.DeleteRecordingTranscriptionWithCtx(context.TODO(), RecordingSid, Sid, params) +} + +// +func (c *ApiService) DeleteRecordingTranscriptionWithCtx(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) @@ -48,7 +54,7 @@ func (c *ApiService) DeleteRecordingTranscription(RecordingSid string, Sid strin data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -71,6 +77,11 @@ func (params *FetchRecordingTranscriptionParams) SetPathAccountSid(PathAccountSi // func (c *ApiService) FetchRecordingTranscription(RecordingSid string, Sid string, params *FetchRecordingTranscriptionParams) (*ApiV2010RecordingTranscription, error) { + return c.FetchRecordingTranscriptionWithCtx(context.TODO(), RecordingSid, Sid, params) +} + +// +func (c *ApiService) FetchRecordingTranscriptionWithCtx(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) @@ -83,7 +94,7 @@ func (c *ApiService) FetchRecordingTranscription(RecordingSid string, Sid string data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -123,6 +134,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.PageRecordingTranscriptionWithCtx(context.TODO(), RecordingSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of RecordingTranscription records from the API. Request is executed immediately. +func (c *ApiService) PageRecordingTranscriptionWithCtx(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 { @@ -146,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -163,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.ListRecordingTranscriptionWithCtx(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) ListRecordingTranscriptionWithCtx(ctx context.Context, RecordingSid string, params *ListRecordingTranscriptionParams) ([]ApiV2010RecordingTranscription, error) { + response, errors := c.StreamRecordingTranscriptionWithCtx(ctx, RecordingSid, params) records := make([]ApiV2010RecordingTranscription, 0) for record := range response { @@ -179,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.StreamRecordingTranscriptionWithCtx(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) StreamRecordingTranscriptionWithCtx(ctx context.Context, RecordingSid string, params *ListRecordingTranscriptionParams) (chan ApiV2010RecordingTranscription, chan error) { if params == nil { params = &ListRecordingTranscriptionParams{} } @@ -187,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.PageRecordingTranscriptionWithCtx(ctx, RecordingSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamRecordingTranscription(response, params, recordChannel, errorChannel) + go c.streamRecordingTranscription(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) streamRecordingTranscription(ctx context.Context, response *ListRecordingTranscriptionResponse, params *ListRecordingTranscriptionParams, recordChannel chan ApiV2010RecordingTranscription, errorChannel chan error) { curRecord := 1 for response != nil { @@ -214,7 +240,7 @@ func (c *ApiService) streamRecordingTranscription(response *ListRecordingTranscr } } - record, err := client.GetNext(c.baseURL, response, c.getNextListRecordingTranscriptionResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListRecordingTranscriptionResponse) if err != nil { errorChannel <- err break @@ -229,11 +255,11 @@ func (c *ApiService) streamRecordingTranscription(response *ListRecordingTranscr close(errorChannel) } -func (c *ApiService) getNextListRecordingTranscriptionResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListRecordingTranscriptionResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 dd1b18853..9f347ad8d 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,11 @@ 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.CreateNewSigningKeyWithCtx(context.TODO(), params) +} + +// Create a new Signing Key for the account making the request. +func (c *ApiService) CreateNewSigningKeyWithCtx(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) @@ -56,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -84,6 +90,11 @@ func (params *DeleteSigningKeyParams) SetPathAccountSid(PathAccountSid string) * // func (c *ApiService) DeleteSigningKey(Sid string, params *DeleteSigningKeyParams) error { + return c.DeleteSigningKeyWithCtx(context.TODO(), Sid, params) +} + +// +func (c *ApiService) DeleteSigningKeyWithCtx(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) @@ -95,7 +106,7 @@ func (c *ApiService) DeleteSigningKey(Sid string, params *DeleteSigningKeyParams data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -118,6 +129,11 @@ func (params *FetchSigningKeyParams) SetPathAccountSid(PathAccountSid string) *F // func (c *ApiService) FetchSigningKey(Sid string, params *FetchSigningKeyParams) (*ApiV2010SigningKey, error) { + return c.FetchSigningKeyWithCtx(context.TODO(), Sid, params) +} + +// +func (c *ApiService) FetchSigningKeyWithCtx(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) @@ -129,7 +145,7 @@ func (c *ApiService) FetchSigningKey(Sid string, params *FetchSigningKeyParams) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -169,6 +185,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.PageSigningKeyWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of SigningKey records from the API. Request is executed immediately. +func (c *ApiService) PageSigningKeyWithCtx(ctx context.Context, params *ListSigningKeyParams, pageToken, pageNumber string) (*ListSigningKeyResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/SigningKeys.json" if params != nil && params.PathAccountSid != nil { @@ -191,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -208,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.ListSigningKeyWithCtx(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) ListSigningKeyWithCtx(ctx context.Context, params *ListSigningKeyParams) ([]ApiV2010SigningKey, error) { + response, errors := c.StreamSigningKeyWithCtx(ctx, params) records := make([]ApiV2010SigningKey, 0) for record := range response { @@ -224,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.StreamSigningKeyWithCtx(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) StreamSigningKeyWithCtx(ctx context.Context, params *ListSigningKeyParams) (chan ApiV2010SigningKey, chan error) { if params == nil { params = &ListSigningKeyParams{} } @@ -232,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.PageSigningKeyWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSigningKey(response, params, recordChannel, errorChannel) + go c.streamSigningKey(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) streamSigningKey(ctx context.Context, response *ListSigningKeyResponse, params *ListSigningKeyParams, recordChannel chan ApiV2010SigningKey, errorChannel chan error) { curRecord := 1 for response != nil { @@ -259,7 +290,7 @@ func (c *ApiService) streamSigningKey(response *ListSigningKeyResponse, params * } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSigningKeyResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListSigningKeyResponse) if err != nil { errorChannel <- err break @@ -274,11 +305,11 @@ func (c *ApiService) streamSigningKey(response *ListSigningKeyResponse, params * close(errorChannel) } -func (c *ApiService) getNextListSigningKeyResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSigningKeyResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -311,6 +342,11 @@ func (params *UpdateSigningKeyParams) SetFriendlyName(FriendlyName string) *Upda // func (c *ApiService) UpdateSigningKey(Sid string, params *UpdateSigningKeyParams) (*ApiV2010SigningKey, error) { + return c.UpdateSigningKeyWithCtx(context.TODO(), Sid, params) +} + +// +func (c *ApiService) UpdateSigningKeyWithCtx(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) @@ -326,7 +362,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.Post(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 17a523bc0..a106f5b9d 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,11 @@ func (params *CreateSipCredentialListParams) SetFriendlyName(FriendlyName string // Create a Credential List func (c *ApiService) CreateSipCredentialList(params *CreateSipCredentialListParams) (*ApiV2010SipCredentialList, error) { + return c.CreateSipCredentialListWithCtx(context.TODO(), params) +} + +// Create a Credential List +func (c *ApiService) CreateSipCredentialListWithCtx(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) @@ -56,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -84,6 +90,11 @@ func (params *DeleteSipCredentialListParams) SetPathAccountSid(PathAccountSid st // Delete a Credential List func (c *ApiService) DeleteSipCredentialList(Sid string, params *DeleteSipCredentialListParams) error { + return c.DeleteSipCredentialListWithCtx(context.TODO(), Sid, params) +} + +// Delete a Credential List +func (c *ApiService) DeleteSipCredentialListWithCtx(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) @@ -95,7 +106,7 @@ func (c *ApiService) DeleteSipCredentialList(Sid string, params *DeleteSipCreden data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -118,6 +129,11 @@ func (params *FetchSipCredentialListParams) SetPathAccountSid(PathAccountSid str // Get a Credential List func (c *ApiService) FetchSipCredentialList(Sid string, params *FetchSipCredentialListParams) (*ApiV2010SipCredentialList, error) { + return c.FetchSipCredentialListWithCtx(context.TODO(), Sid, params) +} + +// Get a Credential List +func (c *ApiService) FetchSipCredentialListWithCtx(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) @@ -129,7 +145,7 @@ func (c *ApiService) FetchSipCredentialList(Sid string, params *FetchSipCredenti data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -169,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.PageSipCredentialListWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of SipCredentialList records from the API. Request is executed immediately. +func (c *ApiService) PageSipCredentialListWithCtx(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 { @@ -191,7 +212,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -208,7 +229,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.ListSipCredentialListWithCtx(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) ListSipCredentialListWithCtx(ctx context.Context, params *ListSipCredentialListParams) ([]ApiV2010SipCredentialList, error) { + response, errors := c.StreamSipCredentialListWithCtx(ctx, params) records := make([]ApiV2010SipCredentialList, 0) for record := range response { @@ -224,6 +250,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.StreamSipCredentialListWithCtx(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) StreamSipCredentialListWithCtx(ctx context.Context, params *ListSipCredentialListParams) (chan ApiV2010SipCredentialList, chan error) { if params == nil { params = &ListSipCredentialListParams{} } @@ -232,19 +263,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.PageSipCredentialListWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSipCredentialList(response, params, recordChannel, errorChannel) + go c.streamSipCredentialList(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) streamSipCredentialList(ctx context.Context, response *ListSipCredentialListResponse, params *ListSipCredentialListParams, recordChannel chan ApiV2010SipCredentialList, errorChannel chan error) { curRecord := 1 for response != nil { @@ -259,7 +290,7 @@ func (c *ApiService) streamSipCredentialList(response *ListSipCredentialListResp } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSipCredentialListResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListSipCredentialListResponse) if err != nil { errorChannel <- err break @@ -274,11 +305,11 @@ func (c *ApiService) streamSipCredentialList(response *ListSipCredentialListResp close(errorChannel) } -func (c *ApiService) getNextListSipCredentialListResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSipCredentialListResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -311,6 +342,11 @@ func (params *UpdateSipCredentialListParams) SetFriendlyName(FriendlyName string // Update a Credential List func (c *ApiService) UpdateSipCredentialList(Sid string, params *UpdateSipCredentialListParams) (*ApiV2010SipCredentialList, error) { + return c.UpdateSipCredentialListWithCtx(context.TODO(), Sid, params) +} + +// Update a Credential List +func (c *ApiService) UpdateSipCredentialListWithCtx(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) @@ -326,7 +362,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.Post(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 e82f254f2..acbc8f538 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,11 @@ func (params *CreateSipCredentialParams) SetPassword(Password string) *CreateSip // Create a new credential resource. func (c *ApiService) CreateSipCredential(CredentialListSid string, params *CreateSipCredentialParams) (*ApiV2010SipCredential, error) { + return c.CreateSipCredentialWithCtx(context.TODO(), CredentialListSid, params) +} + +// Create a new credential resource. +func (c *ApiService) CreateSipCredentialWithCtx(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) @@ -66,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -94,6 +100,11 @@ func (params *DeleteSipCredentialParams) SetPathAccountSid(PathAccountSid string // Delete a credential resource. func (c *ApiService) DeleteSipCredential(CredentialListSid string, Sid string, params *DeleteSipCredentialParams) error { + return c.DeleteSipCredentialWithCtx(context.TODO(), CredentialListSid, Sid, params) +} + +// Delete a credential resource. +func (c *ApiService) DeleteSipCredentialWithCtx(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) @@ -106,7 +117,7 @@ func (c *ApiService) DeleteSipCredential(CredentialListSid string, Sid string, p data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -129,6 +140,11 @@ func (params *FetchSipCredentialParams) SetPathAccountSid(PathAccountSid string) // Fetch a single credential. func (c *ApiService) FetchSipCredential(CredentialListSid string, Sid string, params *FetchSipCredentialParams) (*ApiV2010SipCredential, error) { + return c.FetchSipCredentialWithCtx(context.TODO(), CredentialListSid, Sid, params) +} + +// Fetch a single credential. +func (c *ApiService) FetchSipCredentialWithCtx(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) @@ -141,7 +157,7 @@ func (c *ApiService) FetchSipCredential(CredentialListSid string, Sid string, pa data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -181,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.PageSipCredentialWithCtx(context.TODO(), CredentialListSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of SipCredential records from the API. Request is executed immediately. +func (c *ApiService) PageSipCredentialWithCtx(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 { @@ -204,7 +225,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -221,7 +242,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.ListSipCredentialWithCtx(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) ListSipCredentialWithCtx(ctx context.Context, CredentialListSid string, params *ListSipCredentialParams) ([]ApiV2010SipCredential, error) { + response, errors := c.StreamSipCredentialWithCtx(ctx, CredentialListSid, params) records := make([]ApiV2010SipCredential, 0) for record := range response { @@ -237,6 +263,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.StreamSipCredentialWithCtx(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) StreamSipCredentialWithCtx(ctx context.Context, CredentialListSid string, params *ListSipCredentialParams) (chan ApiV2010SipCredential, chan error) { if params == nil { params = &ListSipCredentialParams{} } @@ -245,19 +276,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.PageSipCredentialWithCtx(ctx, CredentialListSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSipCredential(response, params, recordChannel, errorChannel) + go c.streamSipCredential(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) streamSipCredential(ctx context.Context, response *ListSipCredentialResponse, params *ListSipCredentialParams, recordChannel chan ApiV2010SipCredential, errorChannel chan error) { curRecord := 1 for response != nil { @@ -272,7 +303,7 @@ func (c *ApiService) streamSipCredential(response *ListSipCredentialResponse, pa } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSipCredentialResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListSipCredentialResponse) if err != nil { errorChannel <- err break @@ -287,11 +318,11 @@ func (c *ApiService) streamSipCredential(response *ListSipCredentialResponse, pa close(errorChannel) } -func (c *ApiService) getNextListSipCredentialResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSipCredentialResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -324,6 +355,11 @@ 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.UpdateSipCredentialWithCtx(context.TODO(), CredentialListSid, Sid, params) +} + +// Update a credential resource. +func (c *ApiService) UpdateSipCredentialWithCtx(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) @@ -340,7 +376,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.Post(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 e0868c6f0..928d50251 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,11 @@ func (params *CreateSipDomainParams) SetEmergencyCallerSid(EmergencyCallerSid st // Create a new Domain func (c *ApiService) CreateSipDomain(params *CreateSipDomainParams) (*ApiV2010SipDomain, error) { + return c.CreateSipDomainWithCtx(context.TODO(), params) +} + +// Create a new Domain +func (c *ApiService) CreateSipDomainWithCtx(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) @@ -164,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -192,6 +198,11 @@ func (params *DeleteSipDomainParams) SetPathAccountSid(PathAccountSid string) *D // Delete an instance of a Domain func (c *ApiService) DeleteSipDomain(Sid string, params *DeleteSipDomainParams) error { + return c.DeleteSipDomainWithCtx(context.TODO(), Sid, params) +} + +// Delete an instance of a Domain +func (c *ApiService) DeleteSipDomainWithCtx(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) @@ -203,7 +214,7 @@ func (c *ApiService) DeleteSipDomain(Sid string, params *DeleteSipDomainParams) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -226,6 +237,11 @@ 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.FetchSipDomainWithCtx(context.TODO(), Sid, params) +} + +// Fetch an instance of a Domain +func (c *ApiService) FetchSipDomainWithCtx(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) @@ -237,7 +253,7 @@ func (c *ApiService) FetchSipDomain(Sid string, params *FetchSipDomainParams) (* data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -277,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.PageSipDomainWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of SipDomain records from the API. Request is executed immediately. +func (c *ApiService) PageSipDomainWithCtx(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 { @@ -299,7 +320,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -316,7 +337,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.ListSipDomainWithCtx(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) ListSipDomainWithCtx(ctx context.Context, params *ListSipDomainParams) ([]ApiV2010SipDomain, error) { + response, errors := c.StreamSipDomainWithCtx(ctx, params) records := make([]ApiV2010SipDomain, 0) for record := range response { @@ -332,6 +358,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.StreamSipDomainWithCtx(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) StreamSipDomainWithCtx(ctx context.Context, params *ListSipDomainParams) (chan ApiV2010SipDomain, chan error) { if params == nil { params = &ListSipDomainParams{} } @@ -340,19 +371,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.PageSipDomainWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSipDomain(response, params, recordChannel, errorChannel) + go c.streamSipDomain(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) streamSipDomain(ctx context.Context, response *ListSipDomainResponse, params *ListSipDomainParams, recordChannel chan ApiV2010SipDomain, errorChannel chan error) { curRecord := 1 for response != nil { @@ -367,7 +398,7 @@ func (c *ApiService) streamSipDomain(response *ListSipDomainResponse, params *Li } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSipDomainResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListSipDomainResponse) if err != nil { errorChannel <- err break @@ -382,11 +413,11 @@ func (c *ApiService) streamSipDomain(response *ListSipDomainResponse, params *Li close(errorChannel) } -func (c *ApiService) getNextListSipDomainResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSipDomainResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -491,6 +522,11 @@ func (params *UpdateSipDomainParams) SetEmergencyCallerSid(EmergencyCallerSid st // Update the attributes of a domain func (c *ApiService) UpdateSipDomain(Sid string, params *UpdateSipDomainParams) (*ApiV2010SipDomain, error) { + return c.UpdateSipDomainWithCtx(context.TODO(), Sid, params) +} + +// Update the attributes of a domain +func (c *ApiService) UpdateSipDomainWithCtx(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) @@ -542,7 +578,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.Post(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 f3d34690e..707f85106 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,11 @@ func (params *CreateSipAuthCallsCredentialListMappingParams) SetCredentialListSi // Create a new credential list mapping resource func (c *ApiService) CreateSipAuthCallsCredentialListMapping(DomainSid string, params *CreateSipAuthCallsCredentialListMappingParams) (*ApiV2010SipAuthCallsCredentialListMapping, error) { + return c.CreateSipAuthCallsCredentialListMappingWithCtx(context.TODO(), DomainSid, params) +} + +// Create a new credential list mapping resource +func (c *ApiService) CreateSipAuthCallsCredentialListMappingWithCtx(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) @@ -57,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -85,6 +91,11 @@ 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.DeleteSipAuthCallsCredentialListMappingWithCtx(context.TODO(), DomainSid, Sid, params) +} + +// Delete a credential list mapping from the requested domain +func (c *ApiService) DeleteSipAuthCallsCredentialListMappingWithCtx(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) @@ -97,7 +108,7 @@ func (c *ApiService) DeleteSipAuthCallsCredentialListMapping(DomainSid string, S data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -120,6 +131,11 @@ 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.FetchSipAuthCallsCredentialListMappingWithCtx(context.TODO(), DomainSid, Sid, params) +} + +// Fetch a specific instance of a credential list mapping +func (c *ApiService) FetchSipAuthCallsCredentialListMappingWithCtx(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) @@ -132,7 +148,7 @@ func (c *ApiService) FetchSipAuthCallsCredentialListMapping(DomainSid string, Si data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -172,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.PageSipAuthCallsCredentialListMappingWithCtx(context.TODO(), DomainSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of SipAuthCallsCredentialListMapping records from the API. Request is executed immediately. +func (c *ApiService) PageSipAuthCallsCredentialListMappingWithCtx(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 { @@ -195,7 +216,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -212,7 +233,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.ListSipAuthCallsCredentialListMappingWithCtx(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) ListSipAuthCallsCredentialListMappingWithCtx(ctx context.Context, DomainSid string, params *ListSipAuthCallsCredentialListMappingParams) ([]ApiV2010SipAuthCallsCredentialListMapping, error) { + response, errors := c.StreamSipAuthCallsCredentialListMappingWithCtx(ctx, DomainSid, params) records := make([]ApiV2010SipAuthCallsCredentialListMapping, 0) for record := range response { @@ -228,6 +254,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.StreamSipAuthCallsCredentialListMappingWithCtx(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) StreamSipAuthCallsCredentialListMappingWithCtx(ctx context.Context, DomainSid string, params *ListSipAuthCallsCredentialListMappingParams) (chan ApiV2010SipAuthCallsCredentialListMapping, chan error) { if params == nil { params = &ListSipAuthCallsCredentialListMappingParams{} } @@ -236,19 +267,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.PageSipAuthCallsCredentialListMappingWithCtx(ctx, DomainSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSipAuthCallsCredentialListMapping(response, params, recordChannel, errorChannel) + go c.streamSipAuthCallsCredentialListMapping(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) streamSipAuthCallsCredentialListMapping(ctx context.Context, response *ListSipAuthCallsCredentialListMappingResponse, params *ListSipAuthCallsCredentialListMappingParams, recordChannel chan ApiV2010SipAuthCallsCredentialListMapping, errorChannel chan error) { curRecord := 1 for response != nil { @@ -263,7 +294,7 @@ func (c *ApiService) streamSipAuthCallsCredentialListMapping(response *ListSipAu } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSipAuthCallsCredentialListMappingResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListSipAuthCallsCredentialListMappingResponse) if err != nil { errorChannel <- err break @@ -278,11 +309,11 @@ func (c *ApiService) streamSipAuthCallsCredentialListMapping(response *ListSipAu close(errorChannel) } -func (c *ApiService) getNextListSipAuthCallsCredentialListMappingResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSipAuthCallsCredentialListMappingResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 86daa24f0..8714e46be 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,11 @@ func (params *CreateSipAuthCallsIpAccessControlListMappingParams) SetIpAccessCon // Create a new IP Access Control List mapping func (c *ApiService) CreateSipAuthCallsIpAccessControlListMapping(DomainSid string, params *CreateSipAuthCallsIpAccessControlListMappingParams) (*ApiV2010SipAuthCallsIpAccessControlListMapping, error) { + return c.CreateSipAuthCallsIpAccessControlListMappingWithCtx(context.TODO(), DomainSid, params) +} + +// Create a new IP Access Control List mapping +func (c *ApiService) CreateSipAuthCallsIpAccessControlListMappingWithCtx(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) @@ -57,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -85,6 +91,11 @@ 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.DeleteSipAuthCallsIpAccessControlListMappingWithCtx(context.TODO(), DomainSid, Sid, params) +} + +// Delete an IP Access Control List mapping from the requested domain +func (c *ApiService) DeleteSipAuthCallsIpAccessControlListMappingWithCtx(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) @@ -97,7 +108,7 @@ func (c *ApiService) DeleteSipAuthCallsIpAccessControlListMapping(DomainSid stri data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -120,6 +131,11 @@ 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.FetchSipAuthCallsIpAccessControlListMappingWithCtx(context.TODO(), DomainSid, Sid, params) +} + +// Fetch a specific instance of an IP Access Control List mapping +func (c *ApiService) FetchSipAuthCallsIpAccessControlListMappingWithCtx(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) @@ -132,7 +148,7 @@ func (c *ApiService) FetchSipAuthCallsIpAccessControlListMapping(DomainSid strin data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -172,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.PageSipAuthCallsIpAccessControlListMappingWithCtx(context.TODO(), DomainSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of SipAuthCallsIpAccessControlListMapping records from the API. Request is executed immediately. +func (c *ApiService) PageSipAuthCallsIpAccessControlListMappingWithCtx(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 { @@ -195,7 +216,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -212,7 +233,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.ListSipAuthCallsIpAccessControlListMappingWithCtx(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) ListSipAuthCallsIpAccessControlListMappingWithCtx(ctx context.Context, DomainSid string, params *ListSipAuthCallsIpAccessControlListMappingParams) ([]ApiV2010SipAuthCallsIpAccessControlListMapping, error) { + response, errors := c.StreamSipAuthCallsIpAccessControlListMappingWithCtx(ctx, DomainSid, params) records := make([]ApiV2010SipAuthCallsIpAccessControlListMapping, 0) for record := range response { @@ -228,6 +254,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.StreamSipAuthCallsIpAccessControlListMappingWithCtx(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) StreamSipAuthCallsIpAccessControlListMappingWithCtx(ctx context.Context, DomainSid string, params *ListSipAuthCallsIpAccessControlListMappingParams) (chan ApiV2010SipAuthCallsIpAccessControlListMapping, chan error) { if params == nil { params = &ListSipAuthCallsIpAccessControlListMappingParams{} } @@ -236,19 +267,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.PageSipAuthCallsIpAccessControlListMappingWithCtx(ctx, DomainSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSipAuthCallsIpAccessControlListMapping(response, params, recordChannel, errorChannel) + go c.streamSipAuthCallsIpAccessControlListMapping(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) streamSipAuthCallsIpAccessControlListMapping(ctx context.Context, response *ListSipAuthCallsIpAccessControlListMappingResponse, params *ListSipAuthCallsIpAccessControlListMappingParams, recordChannel chan ApiV2010SipAuthCallsIpAccessControlListMapping, errorChannel chan error) { curRecord := 1 for response != nil { @@ -263,7 +294,7 @@ func (c *ApiService) streamSipAuthCallsIpAccessControlListMapping(response *List } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSipAuthCallsIpAccessControlListMappingResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListSipAuthCallsIpAccessControlListMappingResponse) if err != nil { errorChannel <- err break @@ -278,11 +309,11 @@ func (c *ApiService) streamSipAuthCallsIpAccessControlListMapping(response *List close(errorChannel) } -func (c *ApiService) getNextListSipAuthCallsIpAccessControlListMappingResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSipAuthCallsIpAccessControlListMappingResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 431e5099b..3e1fdf7e3 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,11 @@ func (params *CreateSipAuthRegistrationsCredentialListMappingParams) SetCredenti // Create a new credential list mapping resource func (c *ApiService) CreateSipAuthRegistrationsCredentialListMapping(DomainSid string, params *CreateSipAuthRegistrationsCredentialListMappingParams) (*ApiV2010SipAuthRegistrationsCredentialListMapping, error) { + return c.CreateSipAuthRegistrationsCredentialListMappingWithCtx(context.TODO(), DomainSid, params) +} + +// Create a new credential list mapping resource +func (c *ApiService) CreateSipAuthRegistrationsCredentialListMappingWithCtx(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) @@ -57,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -85,6 +91,11 @@ 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.DeleteSipAuthRegistrationsCredentialListMappingWithCtx(context.TODO(), DomainSid, Sid, params) +} + +// Delete a credential list mapping from the requested domain +func (c *ApiService) DeleteSipAuthRegistrationsCredentialListMappingWithCtx(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) @@ -97,7 +108,7 @@ func (c *ApiService) DeleteSipAuthRegistrationsCredentialListMapping(DomainSid s data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -120,6 +131,11 @@ 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.FetchSipAuthRegistrationsCredentialListMappingWithCtx(context.TODO(), DomainSid, Sid, params) +} + +// Fetch a specific instance of a credential list mapping +func (c *ApiService) FetchSipAuthRegistrationsCredentialListMappingWithCtx(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) @@ -132,7 +148,7 @@ func (c *ApiService) FetchSipAuthRegistrationsCredentialListMapping(DomainSid st data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -172,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.PageSipAuthRegistrationsCredentialListMappingWithCtx(context.TODO(), DomainSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of SipAuthRegistrationsCredentialListMapping records from the API. Request is executed immediately. +func (c *ApiService) PageSipAuthRegistrationsCredentialListMappingWithCtx(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 { @@ -195,7 +216,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -212,7 +233,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.ListSipAuthRegistrationsCredentialListMappingWithCtx(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) ListSipAuthRegistrationsCredentialListMappingWithCtx(ctx context.Context, DomainSid string, params *ListSipAuthRegistrationsCredentialListMappingParams) ([]ApiV2010SipAuthRegistrationsCredentialListMapping, error) { + response, errors := c.StreamSipAuthRegistrationsCredentialListMappingWithCtx(ctx, DomainSid, params) records := make([]ApiV2010SipAuthRegistrationsCredentialListMapping, 0) for record := range response { @@ -228,6 +254,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.StreamSipAuthRegistrationsCredentialListMappingWithCtx(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) StreamSipAuthRegistrationsCredentialListMappingWithCtx(ctx context.Context, DomainSid string, params *ListSipAuthRegistrationsCredentialListMappingParams) (chan ApiV2010SipAuthRegistrationsCredentialListMapping, chan error) { if params == nil { params = &ListSipAuthRegistrationsCredentialListMappingParams{} } @@ -236,19 +267,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.PageSipAuthRegistrationsCredentialListMappingWithCtx(ctx, DomainSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSipAuthRegistrationsCredentialListMapping(response, params, recordChannel, errorChannel) + go c.streamSipAuthRegistrationsCredentialListMapping(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) streamSipAuthRegistrationsCredentialListMapping(ctx context.Context, response *ListSipAuthRegistrationsCredentialListMappingResponse, params *ListSipAuthRegistrationsCredentialListMappingParams, recordChannel chan ApiV2010SipAuthRegistrationsCredentialListMapping, errorChannel chan error) { curRecord := 1 for response != nil { @@ -263,7 +294,7 @@ func (c *ApiService) streamSipAuthRegistrationsCredentialListMapping(response *L } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSipAuthRegistrationsCredentialListMappingResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListSipAuthRegistrationsCredentialListMappingResponse) if err != nil { errorChannel <- err break @@ -278,11 +309,11 @@ func (c *ApiService) streamSipAuthRegistrationsCredentialListMapping(response *L close(errorChannel) } -func (c *ApiService) getNextListSipAuthRegistrationsCredentialListMappingResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSipAuthRegistrationsCredentialListMappingResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 09ac9162e..2d8480dac 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,11 @@ func (params *CreateSipCredentialListMappingParams) SetCredentialListSid(Credent // Create a CredentialListMapping resource for an account. func (c *ApiService) CreateSipCredentialListMapping(DomainSid string, params *CreateSipCredentialListMappingParams) (*ApiV2010SipCredentialListMapping, error) { + return c.CreateSipCredentialListMappingWithCtx(context.TODO(), DomainSid, params) +} + +// Create a CredentialListMapping resource for an account. +func (c *ApiService) CreateSipCredentialListMappingWithCtx(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) @@ -57,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -85,6 +91,11 @@ 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.DeleteSipCredentialListMappingWithCtx(context.TODO(), DomainSid, Sid, params) +} + +// Delete a CredentialListMapping resource from an account. +func (c *ApiService) DeleteSipCredentialListMappingWithCtx(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) @@ -97,7 +108,7 @@ func (c *ApiService) DeleteSipCredentialListMapping(DomainSid string, Sid string data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -120,6 +131,11 @@ 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.FetchSipCredentialListMappingWithCtx(context.TODO(), DomainSid, Sid, params) +} + +// Fetch a single CredentialListMapping resource from an account. +func (c *ApiService) FetchSipCredentialListMappingWithCtx(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) @@ -132,7 +148,7 @@ func (c *ApiService) FetchSipCredentialListMapping(DomainSid string, Sid string, data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -172,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.PageSipCredentialListMappingWithCtx(context.TODO(), DomainSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of SipCredentialListMapping records from the API. Request is executed immediately. +func (c *ApiService) PageSipCredentialListMappingWithCtx(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 { @@ -195,7 +216,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -212,7 +233,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.ListSipCredentialListMappingWithCtx(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) ListSipCredentialListMappingWithCtx(ctx context.Context, DomainSid string, params *ListSipCredentialListMappingParams) ([]ApiV2010SipCredentialListMapping, error) { + response, errors := c.StreamSipCredentialListMappingWithCtx(ctx, DomainSid, params) records := make([]ApiV2010SipCredentialListMapping, 0) for record := range response { @@ -228,6 +254,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.StreamSipCredentialListMappingWithCtx(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) StreamSipCredentialListMappingWithCtx(ctx context.Context, DomainSid string, params *ListSipCredentialListMappingParams) (chan ApiV2010SipCredentialListMapping, chan error) { if params == nil { params = &ListSipCredentialListMappingParams{} } @@ -236,19 +267,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.PageSipCredentialListMappingWithCtx(ctx, DomainSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSipCredentialListMapping(response, params, recordChannel, errorChannel) + go c.streamSipCredentialListMapping(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) streamSipCredentialListMapping(ctx context.Context, response *ListSipCredentialListMappingResponse, params *ListSipCredentialListMappingParams, recordChannel chan ApiV2010SipCredentialListMapping, errorChannel chan error) { curRecord := 1 for response != nil { @@ -263,7 +294,7 @@ func (c *ApiService) streamSipCredentialListMapping(response *ListSipCredentialL } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSipCredentialListMappingResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListSipCredentialListMappingResponse) if err != nil { errorChannel <- err break @@ -278,11 +309,11 @@ func (c *ApiService) streamSipCredentialListMapping(response *ListSipCredentialL close(errorChannel) } -func (c *ApiService) getNextListSipCredentialListMappingResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSipCredentialListMappingResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 e42334eb7..80bec7ab1 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,11 @@ func (params *CreateSipIpAccessControlListMappingParams) SetIpAccessControlListS // Create a new IpAccessControlListMapping resource. func (c *ApiService) CreateSipIpAccessControlListMapping(DomainSid string, params *CreateSipIpAccessControlListMappingParams) (*ApiV2010SipIpAccessControlListMapping, error) { + return c.CreateSipIpAccessControlListMappingWithCtx(context.TODO(), DomainSid, params) +} + +// Create a new IpAccessControlListMapping resource. +func (c *ApiService) CreateSipIpAccessControlListMappingWithCtx(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) @@ -57,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -85,6 +91,11 @@ func (params *DeleteSipIpAccessControlListMappingParams) SetPathAccountSid(PathA // Delete an IpAccessControlListMapping resource. func (c *ApiService) DeleteSipIpAccessControlListMapping(DomainSid string, Sid string, params *DeleteSipIpAccessControlListMappingParams) error { + return c.DeleteSipIpAccessControlListMappingWithCtx(context.TODO(), DomainSid, Sid, params) +} + +// Delete an IpAccessControlListMapping resource. +func (c *ApiService) DeleteSipIpAccessControlListMappingWithCtx(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) @@ -97,7 +108,7 @@ func (c *ApiService) DeleteSipIpAccessControlListMapping(DomainSid string, Sid s data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -120,6 +131,11 @@ func (params *FetchSipIpAccessControlListMappingParams) SetPathAccountSid(PathAc // Fetch an IpAccessControlListMapping resource. func (c *ApiService) FetchSipIpAccessControlListMapping(DomainSid string, Sid string, params *FetchSipIpAccessControlListMappingParams) (*ApiV2010SipIpAccessControlListMapping, error) { + return c.FetchSipIpAccessControlListMappingWithCtx(context.TODO(), DomainSid, Sid, params) +} + +// Fetch an IpAccessControlListMapping resource. +func (c *ApiService) FetchSipIpAccessControlListMappingWithCtx(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) @@ -132,7 +148,7 @@ func (c *ApiService) FetchSipIpAccessControlListMapping(DomainSid string, Sid st data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -172,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.PageSipIpAccessControlListMappingWithCtx(context.TODO(), DomainSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of SipIpAccessControlListMapping records from the API. Request is executed immediately. +func (c *ApiService) PageSipIpAccessControlListMappingWithCtx(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 { @@ -195,7 +216,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -212,7 +233,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.ListSipIpAccessControlListMappingWithCtx(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) ListSipIpAccessControlListMappingWithCtx(ctx context.Context, DomainSid string, params *ListSipIpAccessControlListMappingParams) ([]ApiV2010SipIpAccessControlListMapping, error) { + response, errors := c.StreamSipIpAccessControlListMappingWithCtx(ctx, DomainSid, params) records := make([]ApiV2010SipIpAccessControlListMapping, 0) for record := range response { @@ -228,6 +254,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.StreamSipIpAccessControlListMappingWithCtx(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) StreamSipIpAccessControlListMappingWithCtx(ctx context.Context, DomainSid string, params *ListSipIpAccessControlListMappingParams) (chan ApiV2010SipIpAccessControlListMapping, chan error) { if params == nil { params = &ListSipIpAccessControlListMappingParams{} } @@ -236,19 +267,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.PageSipIpAccessControlListMappingWithCtx(ctx, DomainSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSipIpAccessControlListMapping(response, params, recordChannel, errorChannel) + go c.streamSipIpAccessControlListMapping(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) streamSipIpAccessControlListMapping(ctx context.Context, response *ListSipIpAccessControlListMappingResponse, params *ListSipIpAccessControlListMappingParams, recordChannel chan ApiV2010SipIpAccessControlListMapping, errorChannel chan error) { curRecord := 1 for response != nil { @@ -263,7 +294,7 @@ func (c *ApiService) streamSipIpAccessControlListMapping(response *ListSipIpAcce } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSipIpAccessControlListMappingResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListSipIpAccessControlListMappingResponse) if err != nil { errorChannel <- err break @@ -278,11 +309,11 @@ func (c *ApiService) streamSipIpAccessControlListMapping(response *ListSipIpAcce close(errorChannel) } -func (c *ApiService) getNextListSipIpAccessControlListMappingResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSipIpAccessControlListMappingResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 390bcfa25..44843ee8c 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,11 @@ func (params *CreateSipIpAccessControlListParams) SetFriendlyName(FriendlyName s // Create a new IpAccessControlList resource func (c *ApiService) CreateSipIpAccessControlList(params *CreateSipIpAccessControlListParams) (*ApiV2010SipIpAccessControlList, error) { + return c.CreateSipIpAccessControlListWithCtx(context.TODO(), params) +} + +// Create a new IpAccessControlList resource +func (c *ApiService) CreateSipIpAccessControlListWithCtx(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) @@ -56,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -84,6 +90,11 @@ func (params *DeleteSipIpAccessControlListParams) SetPathAccountSid(PathAccountS // Delete an IpAccessControlList from the requested account func (c *ApiService) DeleteSipIpAccessControlList(Sid string, params *DeleteSipIpAccessControlListParams) error { + return c.DeleteSipIpAccessControlListWithCtx(context.TODO(), Sid, params) +} + +// Delete an IpAccessControlList from the requested account +func (c *ApiService) DeleteSipIpAccessControlListWithCtx(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) @@ -95,7 +106,7 @@ func (c *ApiService) DeleteSipIpAccessControlList(Sid string, params *DeleteSipI data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -118,6 +129,11 @@ func (params *FetchSipIpAccessControlListParams) SetPathAccountSid(PathAccountSi // Fetch a specific instance of an IpAccessControlList func (c *ApiService) FetchSipIpAccessControlList(Sid string, params *FetchSipIpAccessControlListParams) (*ApiV2010SipIpAccessControlList, error) { + return c.FetchSipIpAccessControlListWithCtx(context.TODO(), Sid, params) +} + +// Fetch a specific instance of an IpAccessControlList +func (c *ApiService) FetchSipIpAccessControlListWithCtx(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) @@ -129,7 +145,7 @@ func (c *ApiService) FetchSipIpAccessControlList(Sid string, params *FetchSipIpA data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -169,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.PageSipIpAccessControlListWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of SipIpAccessControlList records from the API. Request is executed immediately. +func (c *ApiService) PageSipIpAccessControlListWithCtx(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 { @@ -191,7 +212,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -208,7 +229,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.ListSipIpAccessControlListWithCtx(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) ListSipIpAccessControlListWithCtx(ctx context.Context, params *ListSipIpAccessControlListParams) ([]ApiV2010SipIpAccessControlList, error) { + response, errors := c.StreamSipIpAccessControlListWithCtx(ctx, params) records := make([]ApiV2010SipIpAccessControlList, 0) for record := range response { @@ -224,6 +250,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.StreamSipIpAccessControlListWithCtx(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) StreamSipIpAccessControlListWithCtx(ctx context.Context, params *ListSipIpAccessControlListParams) (chan ApiV2010SipIpAccessControlList, chan error) { if params == nil { params = &ListSipIpAccessControlListParams{} } @@ -232,19 +263,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.PageSipIpAccessControlListWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSipIpAccessControlList(response, params, recordChannel, errorChannel) + go c.streamSipIpAccessControlList(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) streamSipIpAccessControlList(ctx context.Context, response *ListSipIpAccessControlListResponse, params *ListSipIpAccessControlListParams, recordChannel chan ApiV2010SipIpAccessControlList, errorChannel chan error) { curRecord := 1 for response != nil { @@ -259,7 +290,7 @@ func (c *ApiService) streamSipIpAccessControlList(response *ListSipIpAccessContr } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSipIpAccessControlListResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListSipIpAccessControlListResponse) if err != nil { errorChannel <- err break @@ -274,11 +305,11 @@ func (c *ApiService) streamSipIpAccessControlList(response *ListSipIpAccessContr close(errorChannel) } -func (c *ApiService) getNextListSipIpAccessControlListResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSipIpAccessControlListResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -311,6 +342,11 @@ func (params *UpdateSipIpAccessControlListParams) SetFriendlyName(FriendlyName s // Rename an IpAccessControlList func (c *ApiService) UpdateSipIpAccessControlList(Sid string, params *UpdateSipIpAccessControlListParams) (*ApiV2010SipIpAccessControlList, error) { + return c.UpdateSipIpAccessControlListWithCtx(context.TODO(), Sid, params) +} + +// Rename an IpAccessControlList +func (c *ApiService) UpdateSipIpAccessControlListWithCtx(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) @@ -326,7 +362,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.Post(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 0d92df5e6..0e8c86dd0 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,11 @@ func (params *CreateSipIpAddressParams) SetCidrPrefixLength(CidrPrefixLength int // Create a new IpAddress resource. func (c *ApiService) CreateSipIpAddress(IpAccessControlListSid string, params *CreateSipIpAddressParams) (*ApiV2010SipIpAddress, error) { + return c.CreateSipIpAddressWithCtx(context.TODO(), IpAccessControlListSid, params) +} + +// Create a new IpAddress resource. +func (c *ApiService) CreateSipIpAddressWithCtx(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) @@ -75,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -103,6 +109,11 @@ func (params *DeleteSipIpAddressParams) SetPathAccountSid(PathAccountSid string) // Delete an IpAddress resource. func (c *ApiService) DeleteSipIpAddress(IpAccessControlListSid string, Sid string, params *DeleteSipIpAddressParams) error { + return c.DeleteSipIpAddressWithCtx(context.TODO(), IpAccessControlListSid, Sid, params) +} + +// Delete an IpAddress resource. +func (c *ApiService) DeleteSipIpAddressWithCtx(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) @@ -115,7 +126,7 @@ func (c *ApiService) DeleteSipIpAddress(IpAccessControlListSid string, Sid strin data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -138,6 +149,11 @@ func (params *FetchSipIpAddressParams) SetPathAccountSid(PathAccountSid string) // Read one IpAddress resource. func (c *ApiService) FetchSipIpAddress(IpAccessControlListSid string, Sid string, params *FetchSipIpAddressParams) (*ApiV2010SipIpAddress, error) { + return c.FetchSipIpAddressWithCtx(context.TODO(), IpAccessControlListSid, Sid, params) +} + +// Read one IpAddress resource. +func (c *ApiService) FetchSipIpAddressWithCtx(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) @@ -150,7 +166,7 @@ func (c *ApiService) FetchSipIpAddress(IpAccessControlListSid string, Sid string data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -190,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.PageSipIpAddressWithCtx(context.TODO(), IpAccessControlListSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of SipIpAddress records from the API. Request is executed immediately. +func (c *ApiService) PageSipIpAddressWithCtx(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 { @@ -213,7 +234,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -230,7 +251,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.ListSipIpAddressWithCtx(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) ListSipIpAddressWithCtx(ctx context.Context, IpAccessControlListSid string, params *ListSipIpAddressParams) ([]ApiV2010SipIpAddress, error) { + response, errors := c.StreamSipIpAddressWithCtx(ctx, IpAccessControlListSid, params) records := make([]ApiV2010SipIpAddress, 0) for record := range response { @@ -246,6 +272,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.StreamSipIpAddressWithCtx(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) StreamSipIpAddressWithCtx(ctx context.Context, IpAccessControlListSid string, params *ListSipIpAddressParams) (chan ApiV2010SipIpAddress, chan error) { if params == nil { params = &ListSipIpAddressParams{} } @@ -254,19 +285,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.PageSipIpAddressWithCtx(ctx, IpAccessControlListSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSipIpAddress(response, params, recordChannel, errorChannel) + go c.streamSipIpAddress(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) streamSipIpAddress(ctx context.Context, response *ListSipIpAddressResponse, params *ListSipIpAddressParams, recordChannel chan ApiV2010SipIpAddress, errorChannel chan error) { curRecord := 1 for response != nil { @@ -281,7 +312,7 @@ func (c *ApiService) streamSipIpAddress(response *ListSipIpAddressResponse, para } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSipIpAddressResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListSipIpAddressResponse) if err != nil { errorChannel <- err break @@ -296,11 +327,11 @@ func (c *ApiService) streamSipIpAddress(response *ListSipIpAddressResponse, para close(errorChannel) } -func (c *ApiService) getNextListSipIpAddressResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSipIpAddressResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -345,6 +376,11 @@ func (params *UpdateSipIpAddressParams) SetCidrPrefixLength(CidrPrefixLength int // Update an IpAddress resource. func (c *ApiService) UpdateSipIpAddress(IpAccessControlListSid string, Sid string, params *UpdateSipIpAddressParams) (*ApiV2010SipIpAddress, error) { + return c.UpdateSipIpAddressWithCtx(context.TODO(), IpAccessControlListSid, Sid, params) +} + +// Update an IpAddress resource. +func (c *ApiService) UpdateSipIpAddressWithCtx(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) @@ -367,7 +403,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.Post(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 efac7d190..5e2de567e 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,11 @@ 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.FetchShortCodeWithCtx(context.TODO(), Sid, params) +} + +// Fetch an instance of a short code +func (c *ApiService) FetchShortCodeWithCtx(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) @@ -47,7 +53,7 @@ func (c *ApiService) FetchShortCode(Sid string, params *FetchShortCodeParams) (* data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -99,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.PageShortCodeWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of ShortCode records from the API. Request is executed immediately. +func (c *ApiService) PageShortCodeWithCtx(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 { @@ -127,7 +138,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -144,7 +155,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.ListShortCodeWithCtx(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) ListShortCodeWithCtx(ctx context.Context, params *ListShortCodeParams) ([]ApiV2010ShortCode, error) { + response, errors := c.StreamShortCodeWithCtx(ctx, params) records := make([]ApiV2010ShortCode, 0) for record := range response { @@ -160,6 +176,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.StreamShortCodeWithCtx(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) StreamShortCodeWithCtx(ctx context.Context, params *ListShortCodeParams) (chan ApiV2010ShortCode, chan error) { if params == nil { params = &ListShortCodeParams{} } @@ -168,19 +189,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.PageShortCodeWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamShortCode(response, params, recordChannel, errorChannel) + go c.streamShortCode(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) streamShortCode(ctx context.Context, response *ListShortCodeResponse, params *ListShortCodeParams, recordChannel chan ApiV2010ShortCode, errorChannel chan error) { curRecord := 1 for response != nil { @@ -195,7 +216,7 @@ func (c *ApiService) streamShortCode(response *ListShortCodeResponse, params *Li } } - record, err := client.GetNext(c.baseURL, response, c.getNextListShortCodeResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListShortCodeResponse) if err != nil { errorChannel <- err break @@ -210,11 +231,11 @@ func (c *ApiService) streamShortCode(response *ListShortCodeResponse, params *Li close(errorChannel) } -func (c *ApiService) getNextListShortCodeResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListShortCodeResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -277,6 +298,11 @@ 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.UpdateShortCodeWithCtx(context.TODO(), Sid, params) +} + +// Update a short code with the following parameters +func (c *ApiService) UpdateShortCodeWithCtx(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) @@ -307,7 +333,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.Post(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 1784876d1..89b485bb8 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,11 @@ func (params *CreateTokenParams) SetTtl(Ttl int) *CreateTokenParams { // Create a new token for ICE servers func (c *ApiService) CreateToken(params *CreateTokenParams) (*ApiV2010Token, error) { + return c.CreateTokenWithCtx(context.TODO(), params) +} + +// Create a new token for ICE servers +func (c *ApiService) CreateTokenWithCtx(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) @@ -54,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.Post(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 c62183a14..a9b354b6e 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,11 @@ 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.DeleteTranscriptionWithCtx(context.TODO(), Sid, params) +} + +// Delete a transcription from the account used to make the request +func (c *ApiService) DeleteTranscriptionWithCtx(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) @@ -47,7 +53,7 @@ func (c *ApiService) DeleteTranscription(Sid string, params *DeleteTranscription data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -70,6 +76,11 @@ func (params *FetchTranscriptionParams) SetPathAccountSid(PathAccountSid string) // Fetch an instance of a Transcription func (c *ApiService) FetchTranscription(Sid string, params *FetchTranscriptionParams) (*ApiV2010Transcription, error) { + return c.FetchTranscriptionWithCtx(context.TODO(), Sid, params) +} + +// Fetch an instance of a Transcription +func (c *ApiService) FetchTranscriptionWithCtx(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) @@ -81,7 +92,7 @@ func (c *ApiService) FetchTranscription(Sid string, params *FetchTranscriptionPa data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -121,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.PageTranscriptionWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Transcription records from the API. Request is executed immediately. +func (c *ApiService) PageTranscriptionWithCtx(ctx context.Context, params *ListTranscriptionParams, pageToken, pageNumber string) (*ListTranscriptionResponse, error) { path := "/2010-04-01/Accounts/{AccountSid}/Transcriptions.json" if params != nil && params.PathAccountSid != nil { @@ -143,7 +159,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -160,7 +176,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.ListTranscriptionWithCtx(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) ListTranscriptionWithCtx(ctx context.Context, params *ListTranscriptionParams) ([]ApiV2010Transcription, error) { + response, errors := c.StreamTranscriptionWithCtx(ctx, params) records := make([]ApiV2010Transcription, 0) for record := range response { @@ -176,6 +197,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.StreamTranscriptionWithCtx(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) StreamTranscriptionWithCtx(ctx context.Context, params *ListTranscriptionParams) (chan ApiV2010Transcription, chan error) { if params == nil { params = &ListTranscriptionParams{} } @@ -184,19 +210,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.PageTranscriptionWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamTranscription(response, params, recordChannel, errorChannel) + go c.streamTranscription(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) streamTranscription(ctx context.Context, response *ListTranscriptionResponse, params *ListTranscriptionParams, recordChannel chan ApiV2010Transcription, errorChannel chan error) { curRecord := 1 for response != nil { @@ -211,7 +237,7 @@ func (c *ApiService) streamTranscription(response *ListTranscriptionResponse, pa } } - record, err := client.GetNext(c.baseURL, response, c.getNextListTranscriptionResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListTranscriptionResponse) if err != nil { errorChannel <- err break @@ -226,11 +252,11 @@ func (c *ApiService) streamTranscription(response *ListTranscriptionResponse, pa close(errorChannel) } -func (c *ApiService) getNextListTranscriptionResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListTranscriptionResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 d5ed51a3d..17c8cb5b2 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.PageUsageRecordWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of UsageRecord records from the API. Request is executed immediately. +func (c *ApiService) PageUsageRecordWithCtx(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 { @@ -106,7 +112,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -123,7 +129,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.ListUsageRecordWithCtx(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) ListUsageRecordWithCtx(ctx context.Context, params *ListUsageRecordParams) ([]ApiV2010UsageRecord, error) { + response, errors := c.StreamUsageRecordWithCtx(ctx, params) records := make([]ApiV2010UsageRecord, 0) for record := range response { @@ -139,6 +150,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.StreamUsageRecordWithCtx(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) StreamUsageRecordWithCtx(ctx context.Context, params *ListUsageRecordParams) (chan ApiV2010UsageRecord, chan error) { if params == nil { params = &ListUsageRecordParams{} } @@ -147,19 +163,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.PageUsageRecordWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUsageRecord(response, params, recordChannel, errorChannel) + go c.streamUsageRecord(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) streamUsageRecord(ctx context.Context, response *ListUsageRecordResponse, params *ListUsageRecordParams, recordChannel chan ApiV2010UsageRecord, errorChannel chan error) { curRecord := 1 for response != nil { @@ -174,7 +190,7 @@ func (c *ApiService) streamUsageRecord(response *ListUsageRecordResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUsageRecordResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListUsageRecordResponse) if err != nil { errorChannel <- err break @@ -189,11 +205,11 @@ func (c *ApiService) streamUsageRecord(response *ListUsageRecordResponse, params close(errorChannel) } -func (c *ApiService) getNextListUsageRecordResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUsageRecordResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 2719f2426..7c686bdd3 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.PageUsageRecordAllTimeWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of UsageRecordAllTime records from the API. Request is executed immediately. +func (c *ApiService) PageUsageRecordAllTimeWithCtx(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 { @@ -106,7 +112,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -123,7 +129,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.ListUsageRecordAllTimeWithCtx(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) ListUsageRecordAllTimeWithCtx(ctx context.Context, params *ListUsageRecordAllTimeParams) ([]ApiV2010UsageRecordAllTime, error) { + response, errors := c.StreamUsageRecordAllTimeWithCtx(ctx, params) records := make([]ApiV2010UsageRecordAllTime, 0) for record := range response { @@ -139,6 +150,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.StreamUsageRecordAllTimeWithCtx(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) StreamUsageRecordAllTimeWithCtx(ctx context.Context, params *ListUsageRecordAllTimeParams) (chan ApiV2010UsageRecordAllTime, chan error) { if params == nil { params = &ListUsageRecordAllTimeParams{} } @@ -147,19 +163,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.PageUsageRecordAllTimeWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUsageRecordAllTime(response, params, recordChannel, errorChannel) + go c.streamUsageRecordAllTime(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) streamUsageRecordAllTime(ctx context.Context, response *ListUsageRecordAllTimeResponse, params *ListUsageRecordAllTimeParams, recordChannel chan ApiV2010UsageRecordAllTime, errorChannel chan error) { curRecord := 1 for response != nil { @@ -174,7 +190,7 @@ func (c *ApiService) streamUsageRecordAllTime(response *ListUsageRecordAllTimeRe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUsageRecordAllTimeResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListUsageRecordAllTimeResponse) if err != nil { errorChannel <- err break @@ -189,11 +205,11 @@ func (c *ApiService) streamUsageRecordAllTime(response *ListUsageRecordAllTimeRe close(errorChannel) } -func (c *ApiService) getNextListUsageRecordAllTimeResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUsageRecordAllTimeResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 c27a64969..e5b728a51 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.PageUsageRecordDailyWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of UsageRecordDaily records from the API. Request is executed immediately. +func (c *ApiService) PageUsageRecordDailyWithCtx(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 { @@ -106,7 +112,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -123,7 +129,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.ListUsageRecordDailyWithCtx(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) ListUsageRecordDailyWithCtx(ctx context.Context, params *ListUsageRecordDailyParams) ([]ApiV2010UsageRecordDaily, error) { + response, errors := c.StreamUsageRecordDailyWithCtx(ctx, params) records := make([]ApiV2010UsageRecordDaily, 0) for record := range response { @@ -139,6 +150,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.StreamUsageRecordDailyWithCtx(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) StreamUsageRecordDailyWithCtx(ctx context.Context, params *ListUsageRecordDailyParams) (chan ApiV2010UsageRecordDaily, chan error) { if params == nil { params = &ListUsageRecordDailyParams{} } @@ -147,19 +163,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.PageUsageRecordDailyWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUsageRecordDaily(response, params, recordChannel, errorChannel) + go c.streamUsageRecordDaily(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) streamUsageRecordDaily(ctx context.Context, response *ListUsageRecordDailyResponse, params *ListUsageRecordDailyParams, recordChannel chan ApiV2010UsageRecordDaily, errorChannel chan error) { curRecord := 1 for response != nil { @@ -174,7 +190,7 @@ func (c *ApiService) streamUsageRecordDaily(response *ListUsageRecordDailyRespon } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUsageRecordDailyResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListUsageRecordDailyResponse) if err != nil { errorChannel <- err break @@ -189,11 +205,11 @@ func (c *ApiService) streamUsageRecordDaily(response *ListUsageRecordDailyRespon close(errorChannel) } -func (c *ApiService) getNextListUsageRecordDailyResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUsageRecordDailyResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 23ec9b62d..46bbc487d 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.PageUsageRecordLastMonthWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of UsageRecordLastMonth records from the API. Request is executed immediately. +func (c *ApiService) PageUsageRecordLastMonthWithCtx(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 { @@ -106,7 +112,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -123,7 +129,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.ListUsageRecordLastMonthWithCtx(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) ListUsageRecordLastMonthWithCtx(ctx context.Context, params *ListUsageRecordLastMonthParams) ([]ApiV2010UsageRecordLastMonth, error) { + response, errors := c.StreamUsageRecordLastMonthWithCtx(ctx, params) records := make([]ApiV2010UsageRecordLastMonth, 0) for record := range response { @@ -139,6 +150,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.StreamUsageRecordLastMonthWithCtx(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) StreamUsageRecordLastMonthWithCtx(ctx context.Context, params *ListUsageRecordLastMonthParams) (chan ApiV2010UsageRecordLastMonth, chan error) { if params == nil { params = &ListUsageRecordLastMonthParams{} } @@ -147,19 +163,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.PageUsageRecordLastMonthWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUsageRecordLastMonth(response, params, recordChannel, errorChannel) + go c.streamUsageRecordLastMonth(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) streamUsageRecordLastMonth(ctx context.Context, response *ListUsageRecordLastMonthResponse, params *ListUsageRecordLastMonthParams, recordChannel chan ApiV2010UsageRecordLastMonth, errorChannel chan error) { curRecord := 1 for response != nil { @@ -174,7 +190,7 @@ func (c *ApiService) streamUsageRecordLastMonth(response *ListUsageRecordLastMon } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUsageRecordLastMonthResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListUsageRecordLastMonthResponse) if err != nil { errorChannel <- err break @@ -189,11 +205,11 @@ func (c *ApiService) streamUsageRecordLastMonth(response *ListUsageRecordLastMon close(errorChannel) } -func (c *ApiService) getNextListUsageRecordLastMonthResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUsageRecordLastMonthResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 82dc2e4ec..81558b9d8 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.PageUsageRecordMonthlyWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of UsageRecordMonthly records from the API. Request is executed immediately. +func (c *ApiService) PageUsageRecordMonthlyWithCtx(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 { @@ -106,7 +112,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -123,7 +129,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.ListUsageRecordMonthlyWithCtx(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) ListUsageRecordMonthlyWithCtx(ctx context.Context, params *ListUsageRecordMonthlyParams) ([]ApiV2010UsageRecordMonthly, error) { + response, errors := c.StreamUsageRecordMonthlyWithCtx(ctx, params) records := make([]ApiV2010UsageRecordMonthly, 0) for record := range response { @@ -139,6 +150,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.StreamUsageRecordMonthlyWithCtx(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) StreamUsageRecordMonthlyWithCtx(ctx context.Context, params *ListUsageRecordMonthlyParams) (chan ApiV2010UsageRecordMonthly, chan error) { if params == nil { params = &ListUsageRecordMonthlyParams{} } @@ -147,19 +163,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.PageUsageRecordMonthlyWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUsageRecordMonthly(response, params, recordChannel, errorChannel) + go c.streamUsageRecordMonthly(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) streamUsageRecordMonthly(ctx context.Context, response *ListUsageRecordMonthlyResponse, params *ListUsageRecordMonthlyParams, recordChannel chan ApiV2010UsageRecordMonthly, errorChannel chan error) { curRecord := 1 for response != nil { @@ -174,7 +190,7 @@ func (c *ApiService) streamUsageRecordMonthly(response *ListUsageRecordMonthlyRe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUsageRecordMonthlyResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListUsageRecordMonthlyResponse) if err != nil { errorChannel <- err break @@ -189,11 +205,11 @@ func (c *ApiService) streamUsageRecordMonthly(response *ListUsageRecordMonthlyRe close(errorChannel) } -func (c *ApiService) getNextListUsageRecordMonthlyResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUsageRecordMonthlyResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 b3b79e816..b764edfe5 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.PageUsageRecordThisMonthWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of UsageRecordThisMonth records from the API. Request is executed immediately. +func (c *ApiService) PageUsageRecordThisMonthWithCtx(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 { @@ -106,7 +112,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -123,7 +129,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.ListUsageRecordThisMonthWithCtx(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) ListUsageRecordThisMonthWithCtx(ctx context.Context, params *ListUsageRecordThisMonthParams) ([]ApiV2010UsageRecordThisMonth, error) { + response, errors := c.StreamUsageRecordThisMonthWithCtx(ctx, params) records := make([]ApiV2010UsageRecordThisMonth, 0) for record := range response { @@ -139,6 +150,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.StreamUsageRecordThisMonthWithCtx(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) StreamUsageRecordThisMonthWithCtx(ctx context.Context, params *ListUsageRecordThisMonthParams) (chan ApiV2010UsageRecordThisMonth, chan error) { if params == nil { params = &ListUsageRecordThisMonthParams{} } @@ -147,19 +163,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.PageUsageRecordThisMonthWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUsageRecordThisMonth(response, params, recordChannel, errorChannel) + go c.streamUsageRecordThisMonth(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) streamUsageRecordThisMonth(ctx context.Context, response *ListUsageRecordThisMonthResponse, params *ListUsageRecordThisMonthParams, recordChannel chan ApiV2010UsageRecordThisMonth, errorChannel chan error) { curRecord := 1 for response != nil { @@ -174,7 +190,7 @@ func (c *ApiService) streamUsageRecordThisMonth(response *ListUsageRecordThisMon } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUsageRecordThisMonthResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListUsageRecordThisMonthResponse) if err != nil { errorChannel <- err break @@ -189,11 +205,11 @@ func (c *ApiService) streamUsageRecordThisMonth(response *ListUsageRecordThisMon close(errorChannel) } -func (c *ApiService) getNextListUsageRecordThisMonthResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUsageRecordThisMonthResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 f9ce2c74a..b49f3bfd2 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.PageUsageRecordTodayWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of UsageRecordToday records from the API. Request is executed immediately. +func (c *ApiService) PageUsageRecordTodayWithCtx(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 { @@ -106,7 +112,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -123,7 +129,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.ListUsageRecordTodayWithCtx(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) ListUsageRecordTodayWithCtx(ctx context.Context, params *ListUsageRecordTodayParams) ([]ApiV2010UsageRecordToday, error) { + response, errors := c.StreamUsageRecordTodayWithCtx(ctx, params) records := make([]ApiV2010UsageRecordToday, 0) for record := range response { @@ -139,6 +150,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.StreamUsageRecordTodayWithCtx(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) StreamUsageRecordTodayWithCtx(ctx context.Context, params *ListUsageRecordTodayParams) (chan ApiV2010UsageRecordToday, chan error) { if params == nil { params = &ListUsageRecordTodayParams{} } @@ -147,19 +163,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.PageUsageRecordTodayWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUsageRecordToday(response, params, recordChannel, errorChannel) + go c.streamUsageRecordToday(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) streamUsageRecordToday(ctx context.Context, response *ListUsageRecordTodayResponse, params *ListUsageRecordTodayParams, recordChannel chan ApiV2010UsageRecordToday, errorChannel chan error) { curRecord := 1 for response != nil { @@ -174,7 +190,7 @@ func (c *ApiService) streamUsageRecordToday(response *ListUsageRecordTodayRespon } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUsageRecordTodayResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListUsageRecordTodayResponse) if err != nil { errorChannel <- err break @@ -189,11 +205,11 @@ func (c *ApiService) streamUsageRecordToday(response *ListUsageRecordTodayRespon close(errorChannel) } -func (c *ApiService) getNextListUsageRecordTodayResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUsageRecordTodayResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 e601fd804..8082643fc 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.PageUsageRecordYearlyWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of UsageRecordYearly records from the API. Request is executed immediately. +func (c *ApiService) PageUsageRecordYearlyWithCtx(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 { @@ -106,7 +112,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -123,7 +129,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.ListUsageRecordYearlyWithCtx(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) ListUsageRecordYearlyWithCtx(ctx context.Context, params *ListUsageRecordYearlyParams) ([]ApiV2010UsageRecordYearly, error) { + response, errors := c.StreamUsageRecordYearlyWithCtx(ctx, params) records := make([]ApiV2010UsageRecordYearly, 0) for record := range response { @@ -139,6 +150,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.StreamUsageRecordYearlyWithCtx(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) StreamUsageRecordYearlyWithCtx(ctx context.Context, params *ListUsageRecordYearlyParams) (chan ApiV2010UsageRecordYearly, chan error) { if params == nil { params = &ListUsageRecordYearlyParams{} } @@ -147,19 +163,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.PageUsageRecordYearlyWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUsageRecordYearly(response, params, recordChannel, errorChannel) + go c.streamUsageRecordYearly(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) streamUsageRecordYearly(ctx context.Context, response *ListUsageRecordYearlyResponse, params *ListUsageRecordYearlyParams, recordChannel chan ApiV2010UsageRecordYearly, errorChannel chan error) { curRecord := 1 for response != nil { @@ -174,7 +190,7 @@ func (c *ApiService) streamUsageRecordYearly(response *ListUsageRecordYearlyResp } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUsageRecordYearlyResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListUsageRecordYearlyResponse) if err != nil { errorChannel <- err break @@ -189,11 +205,11 @@ func (c *ApiService) streamUsageRecordYearly(response *ListUsageRecordYearlyResp close(errorChannel) } -func (c *ApiService) getNextListUsageRecordYearlyResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUsageRecordYearlyResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 5293f7a19..4b1007bc6 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.PageUsageRecordYesterdayWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of UsageRecordYesterday records from the API. Request is executed immediately. +func (c *ApiService) PageUsageRecordYesterdayWithCtx(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 { @@ -106,7 +112,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -123,7 +129,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.ListUsageRecordYesterdayWithCtx(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) ListUsageRecordYesterdayWithCtx(ctx context.Context, params *ListUsageRecordYesterdayParams) ([]ApiV2010UsageRecordYesterday, error) { + response, errors := c.StreamUsageRecordYesterdayWithCtx(ctx, params) records := make([]ApiV2010UsageRecordYesterday, 0) for record := range response { @@ -139,6 +150,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.StreamUsageRecordYesterdayWithCtx(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) StreamUsageRecordYesterdayWithCtx(ctx context.Context, params *ListUsageRecordYesterdayParams) (chan ApiV2010UsageRecordYesterday, chan error) { if params == nil { params = &ListUsageRecordYesterdayParams{} } @@ -147,19 +163,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.PageUsageRecordYesterdayWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUsageRecordYesterday(response, params, recordChannel, errorChannel) + go c.streamUsageRecordYesterday(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) streamUsageRecordYesterday(ctx context.Context, response *ListUsageRecordYesterdayResponse, params *ListUsageRecordYesterdayParams, recordChannel chan ApiV2010UsageRecordYesterday, errorChannel chan error) { curRecord := 1 for response != nil { @@ -174,7 +190,7 @@ func (c *ApiService) streamUsageRecordYesterday(response *ListUsageRecordYesterd } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUsageRecordYesterdayResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListUsageRecordYesterdayResponse) if err != nil { errorChannel <- err break @@ -189,11 +205,11 @@ func (c *ApiService) streamUsageRecordYesterday(response *ListUsageRecordYesterd close(errorChannel) } -func (c *ApiService) getNextListUsageRecordYesterdayResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUsageRecordYesterdayResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 da4333b3a..ad5c7f97b 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,11 @@ func (params *CreateUsageTriggerParams) SetTriggerBy(TriggerBy string) *CreateUs // Create a new UsageTrigger func (c *ApiService) CreateUsageTrigger(params *CreateUsageTriggerParams) (*ApiV2010UsageTrigger, error) { + return c.CreateUsageTriggerWithCtx(context.TODO(), params) +} + +// Create a new UsageTrigger +func (c *ApiService) CreateUsageTriggerWithCtx(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) @@ -110,7 +116,7 @@ func (c *ApiService) CreateUsageTrigger(params *CreateUsageTriggerParams) (*ApiV data.Set("TriggerBy", *params.TriggerBy) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -138,6 +144,11 @@ func (params *DeleteUsageTriggerParams) SetPathAccountSid(PathAccountSid string) // func (c *ApiService) DeleteUsageTrigger(Sid string, params *DeleteUsageTriggerParams) error { + return c.DeleteUsageTriggerWithCtx(context.TODO(), Sid, params) +} + +// +func (c *ApiService) DeleteUsageTriggerWithCtx(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) @@ -149,7 +160,7 @@ func (c *ApiService) DeleteUsageTrigger(Sid string, params *DeleteUsageTriggerPa data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -172,6 +183,11 @@ 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.FetchUsageTriggerWithCtx(context.TODO(), Sid, params) +} + +// Fetch and instance of a usage-trigger +func (c *ApiService) FetchUsageTriggerWithCtx(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) @@ -183,7 +199,7 @@ func (c *ApiService) FetchUsageTrigger(Sid string, params *FetchUsageTriggerPara data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -241,6 +257,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.PageUsageTriggerWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of UsageTrigger records from the API. Request is executed immediately. +func (c *ApiService) PageUsageTriggerWithCtx(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 { @@ -272,7 +293,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -289,7 +310,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.ListUsageTriggerWithCtx(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) ListUsageTriggerWithCtx(ctx context.Context, params *ListUsageTriggerParams) ([]ApiV2010UsageTrigger, error) { + response, errors := c.StreamUsageTriggerWithCtx(ctx, params) records := make([]ApiV2010UsageTrigger, 0) for record := range response { @@ -305,6 +331,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.StreamUsageTriggerWithCtx(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) StreamUsageTriggerWithCtx(ctx context.Context, params *ListUsageTriggerParams) (chan ApiV2010UsageTrigger, chan error) { if params == nil { params = &ListUsageTriggerParams{} } @@ -313,19 +344,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.PageUsageTriggerWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUsageTrigger(response, params, recordChannel, errorChannel) + go c.streamUsageTrigger(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) streamUsageTrigger(ctx context.Context, response *ListUsageTriggerResponse, params *ListUsageTriggerParams, recordChannel chan ApiV2010UsageTrigger, errorChannel chan error) { curRecord := 1 for response != nil { @@ -340,7 +371,7 @@ func (c *ApiService) streamUsageTrigger(response *ListUsageTriggerResponse, para } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUsageTriggerResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListUsageTriggerResponse) if err != nil { errorChannel <- err break @@ -355,11 +386,11 @@ func (c *ApiService) streamUsageTrigger(response *ListUsageTriggerResponse, para close(errorChannel) } -func (c *ApiService) getNextListUsageTriggerResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUsageTriggerResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -404,6 +435,11 @@ 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.UpdateUsageTriggerWithCtx(context.TODO(), Sid, params) +} + +// Update an instance of a usage trigger +func (c *ApiService) UpdateUsageTriggerWithCtx(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) @@ -425,7 +461,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.Post(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 72350733f..af2aefd5d 100644 --- a/rest/api/v2010/api_service.go +++ b/rest/api/v2010/api_service.go @@ -20,10 +20,14 @@ import ( type ApiService struct { baseURL string - requestHandler *twilio.RequestHandler + requestHandler *twilio.RequestHandlerWithCtx } func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { + return NewApiServiceWithCtx(twilio.UpgradeRequestHandler(requestHandler)) +} + +func NewApiServiceWithCtx(requestHandler *twilio.RequestHandlerWithCtx) *ApiService { return &ApiService{ requestHandler: requestHandler, baseURL: "https://api.twilio.com", @@ -33,3 +37,7 @@ func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { func NewApiServiceWithClient(client twilio.BaseClient) *ApiService { return NewApiService(twilio.NewRequestHandler(client)) } + +func NewApiServiceWithClientWithCtx(client twilio.BaseClientWithCtx) *ApiService { + return NewApiServiceWithCtx(twilio.NewRequestHandlerWithCtx(client)) +} diff --git a/rest/autopilot/v1/api_service.go b/rest/autopilot/v1/api_service.go index 87ab7481e..b869126dc 100644 --- a/rest/autopilot/v1/api_service.go +++ b/rest/autopilot/v1/api_service.go @@ -20,10 +20,14 @@ import ( type ApiService struct { baseURL string - requestHandler *twilio.RequestHandler + requestHandler *twilio.RequestHandlerWithCtx } func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { + return NewApiServiceWithCtx(twilio.UpgradeRequestHandler(requestHandler)) +} + +func NewApiServiceWithCtx(requestHandler *twilio.RequestHandlerWithCtx) *ApiService { return &ApiService{ requestHandler: requestHandler, baseURL: "https://autopilot.twilio.com", @@ -33,3 +37,7 @@ func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { func NewApiServiceWithClient(client twilio.BaseClient) *ApiService { return NewApiService(twilio.NewRequestHandler(client)) } + +func NewApiServiceWithClientWithCtx(client twilio.BaseClientWithCtx) *ApiService { + return NewApiServiceWithCtx(twilio.NewRequestHandlerWithCtx(client)) +} diff --git a/rest/autopilot/v1/assistants.go b/rest/autopilot/v1/assistants.go index 38e5c7736..f9396561d 100644 --- a/rest/autopilot/v1/assistants.go +++ b/rest/autopilot/v1/assistants.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -72,6 +73,11 @@ func (params *CreateAssistantParams) SetDefaults(Defaults interface{}) *CreateAs // func (c *ApiService) CreateAssistant(params *CreateAssistantParams) (*AutopilotV1Assistant, error) { + return c.CreateAssistantWithCtx(context.TODO(), params) +} + +// +func (c *ApiService) CreateAssistantWithCtx(ctx context.Context, params *CreateAssistantParams) (*AutopilotV1Assistant, error) { path := "/v1/Assistants" data := url.Values{} @@ -111,7 +117,7 @@ func (c *ApiService) CreateAssistant(params *CreateAssistantParams) (*AutopilotV data.Set("Defaults", string(v)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -128,13 +134,18 @@ func (c *ApiService) CreateAssistant(params *CreateAssistantParams) (*AutopilotV // func (c *ApiService) DeleteAssistant(Sid string) error { + return c.DeleteAssistantWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) DeleteAssistantWithCtx(ctx context.Context, Sid string) error { path := "/v1/Assistants/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -146,13 +157,18 @@ func (c *ApiService) DeleteAssistant(Sid string) error { // func (c *ApiService) FetchAssistant(Sid string) (*AutopilotV1Assistant, error) { + return c.FetchAssistantWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) FetchAssistantWithCtx(ctx context.Context, Sid string) (*AutopilotV1Assistant, error) { path := "/v1/Assistants/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -186,6 +202,11 @@ func (params *ListAssistantParams) SetLimit(Limit int) *ListAssistantParams { // Retrieve a single page of Assistant records from the API. Request is executed immediately. func (c *ApiService) PageAssistant(params *ListAssistantParams, pageToken, pageNumber string) (*ListAssistantResponse, error) { + return c.PageAssistantWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Assistant records from the API. Request is executed immediately. +func (c *ApiService) PageAssistantWithCtx(ctx context.Context, params *ListAssistantParams, pageToken, pageNumber string) (*ListAssistantResponse, error) { path := "/v1/Assistants" data := url.Values{} @@ -202,7 +223,7 @@ func (c *ApiService) PageAssistant(params *ListAssistantParams, pageToken, pageN data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -219,7 +240,12 @@ func (c *ApiService) PageAssistant(params *ListAssistantParams, pageToken, pageN // Lists Assistant records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListAssistant(params *ListAssistantParams) ([]AutopilotV1Assistant, error) { - response, errors := c.StreamAssistant(params) + return c.ListAssistantWithCtx(context.TODO(), params) +} + +// Lists Assistant records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListAssistantWithCtx(ctx context.Context, params *ListAssistantParams) ([]AutopilotV1Assistant, error) { + response, errors := c.StreamAssistantWithCtx(ctx, params) records := make([]AutopilotV1Assistant, 0) for record := range response { @@ -235,6 +261,11 @@ func (c *ApiService) ListAssistant(params *ListAssistantParams) ([]AutopilotV1As // Streams Assistant records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamAssistant(params *ListAssistantParams) (chan AutopilotV1Assistant, chan error) { + return c.StreamAssistantWithCtx(context.TODO(), params) +} + +// Streams Assistant records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamAssistantWithCtx(ctx context.Context, params *ListAssistantParams) (chan AutopilotV1Assistant, chan error) { if params == nil { params = &ListAssistantParams{} } @@ -243,19 +274,19 @@ func (c *ApiService) StreamAssistant(params *ListAssistantParams) (chan Autopilo recordChannel := make(chan AutopilotV1Assistant, 1) errorChannel := make(chan error, 1) - response, err := c.PageAssistant(params, "", "") + response, err := c.PageAssistantWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamAssistant(response, params, recordChannel, errorChannel) + go c.streamAssistant(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamAssistant(response *ListAssistantResponse, params *ListAssistantParams, recordChannel chan AutopilotV1Assistant, errorChannel chan error) { +func (c *ApiService) streamAssistant(ctx context.Context, response *ListAssistantResponse, params *ListAssistantParams, recordChannel chan AutopilotV1Assistant, errorChannel chan error) { curRecord := 1 for response != nil { @@ -270,7 +301,7 @@ func (c *ApiService) streamAssistant(response *ListAssistantResponse, params *Li } } - record, err := client.GetNext(c.baseURL, response, c.getNextListAssistantResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListAssistantResponse) if err != nil { errorChannel <- err break @@ -285,11 +316,11 @@ func (c *ApiService) streamAssistant(response *ListAssistantResponse, params *Li close(errorChannel) } -func (c *ApiService) getNextListAssistantResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListAssistantResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -358,6 +389,11 @@ func (params *UpdateAssistantParams) SetDevelopmentStage(DevelopmentStage string // func (c *ApiService) UpdateAssistant(Sid string, params *UpdateAssistantParams) (*AutopilotV1Assistant, error) { + return c.UpdateAssistantWithCtx(context.TODO(), Sid, params) +} + +// +func (c *ApiService) UpdateAssistantWithCtx(ctx context.Context, Sid string, params *UpdateAssistantParams) (*AutopilotV1Assistant, error) { path := "/v1/Assistants/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -401,7 +437,7 @@ func (c *ApiService) UpdateAssistant(Sid string, params *UpdateAssistantParams) data.Set("DevelopmentStage", *params.DevelopmentStage) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/autopilot/v1/assistants_defaults.go b/rest/autopilot/v1/assistants_defaults.go index 1de206914..121650f21 100644 --- a/rest/autopilot/v1/assistants_defaults.go +++ b/rest/autopilot/v1/assistants_defaults.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -22,13 +23,18 @@ import ( // func (c *ApiService) FetchDefaults(AssistantSid string) (*AutopilotV1Defaults, error) { + return c.FetchDefaultsWithCtx(context.TODO(), AssistantSid) +} + +// +func (c *ApiService) FetchDefaultsWithCtx(ctx context.Context, AssistantSid string) (*AutopilotV1Defaults, error) { path := "/v1/Assistants/{AssistantSid}/Defaults" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -56,6 +62,11 @@ func (params *UpdateDefaultsParams) SetDefaults(Defaults interface{}) *UpdateDef // func (c *ApiService) UpdateDefaults(AssistantSid string, params *UpdateDefaultsParams) (*AutopilotV1Defaults, error) { + return c.UpdateDefaultsWithCtx(context.TODO(), AssistantSid, params) +} + +// +func (c *ApiService) UpdateDefaultsWithCtx(ctx context.Context, AssistantSid string, params *UpdateDefaultsParams) (*AutopilotV1Defaults, error) { path := "/v1/Assistants/{AssistantSid}/Defaults" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) @@ -72,7 +83,7 @@ func (c *ApiService) UpdateDefaults(AssistantSid string, params *UpdateDefaultsP data.Set("Defaults", string(v)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/autopilot/v1/assistants_dialogues.go b/rest/autopilot/v1/assistants_dialogues.go index c045a66ad..395079cfa 100644 --- a/rest/autopilot/v1/assistants_dialogues.go +++ b/rest/autopilot/v1/assistants_dialogues.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -22,6 +23,11 @@ import ( // func (c *ApiService) FetchDialogue(AssistantSid string, Sid string) (*AutopilotV1Dialogue, error) { + return c.FetchDialogueWithCtx(context.TODO(), AssistantSid, Sid) +} + +// +func (c *ApiService) FetchDialogueWithCtx(ctx context.Context, AssistantSid string, Sid string) (*AutopilotV1Dialogue, error) { path := "/v1/Assistants/{AssistantSid}/Dialogues/{Sid}" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -29,7 +35,7 @@ func (c *ApiService) FetchDialogue(AssistantSid string, Sid string) (*AutopilotV data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/autopilot/v1/assistants_field_types.go b/rest/autopilot/v1/assistants_field_types.go index c025306b3..ebb3276f5 100644 --- a/rest/autopilot/v1/assistants_field_types.go +++ b/rest/autopilot/v1/assistants_field_types.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -42,6 +43,11 @@ func (params *CreateFieldTypeParams) SetFriendlyName(FriendlyName string) *Creat // func (c *ApiService) CreateFieldType(AssistantSid string, params *CreateFieldTypeParams) (*AutopilotV1FieldType, error) { + return c.CreateFieldTypeWithCtx(context.TODO(), AssistantSid, params) +} + +// +func (c *ApiService) CreateFieldTypeWithCtx(ctx context.Context, AssistantSid string, params *CreateFieldTypeParams) (*AutopilotV1FieldType, error) { path := "/v1/Assistants/{AssistantSid}/FieldTypes" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) @@ -55,7 +61,7 @@ func (c *ApiService) CreateFieldType(AssistantSid string, params *CreateFieldTyp data.Set("FriendlyName", *params.FriendlyName) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -72,6 +78,11 @@ func (c *ApiService) CreateFieldType(AssistantSid string, params *CreateFieldTyp // func (c *ApiService) DeleteFieldType(AssistantSid string, Sid string) error { + return c.DeleteFieldTypeWithCtx(context.TODO(), AssistantSid, Sid) +} + +// +func (c *ApiService) DeleteFieldTypeWithCtx(ctx context.Context, AssistantSid string, Sid string) error { path := "/v1/Assistants/{AssistantSid}/FieldTypes/{Sid}" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -79,7 +90,7 @@ func (c *ApiService) DeleteFieldType(AssistantSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -91,6 +102,11 @@ func (c *ApiService) DeleteFieldType(AssistantSid string, Sid string) error { // func (c *ApiService) FetchFieldType(AssistantSid string, Sid string) (*AutopilotV1FieldType, error) { + return c.FetchFieldTypeWithCtx(context.TODO(), AssistantSid, Sid) +} + +// +func (c *ApiService) FetchFieldTypeWithCtx(ctx context.Context, AssistantSid string, Sid string) (*AutopilotV1FieldType, error) { path := "/v1/Assistants/{AssistantSid}/FieldTypes/{Sid}" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -98,7 +114,7 @@ func (c *ApiService) FetchFieldType(AssistantSid string, Sid string) (*Autopilot data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -132,6 +148,11 @@ func (params *ListFieldTypeParams) SetLimit(Limit int) *ListFieldTypeParams { // Retrieve a single page of FieldType records from the API. Request is executed immediately. func (c *ApiService) PageFieldType(AssistantSid string, params *ListFieldTypeParams, pageToken, pageNumber string) (*ListFieldTypeResponse, error) { + return c.PageFieldTypeWithCtx(context.TODO(), AssistantSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of FieldType records from the API. Request is executed immediately. +func (c *ApiService) PageFieldTypeWithCtx(ctx context.Context, AssistantSid string, params *ListFieldTypeParams, pageToken, pageNumber string) (*ListFieldTypeResponse, error) { path := "/v1/Assistants/{AssistantSid}/FieldTypes" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) @@ -150,7 +171,7 @@ func (c *ApiService) PageFieldType(AssistantSid string, params *ListFieldTypePar data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -167,7 +188,12 @@ func (c *ApiService) PageFieldType(AssistantSid string, params *ListFieldTypePar // Lists FieldType records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListFieldType(AssistantSid string, params *ListFieldTypeParams) ([]AutopilotV1FieldType, error) { - response, errors := c.StreamFieldType(AssistantSid, params) + return c.ListFieldTypeWithCtx(context.TODO(), AssistantSid, params) +} + +// Lists FieldType records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListFieldTypeWithCtx(ctx context.Context, AssistantSid string, params *ListFieldTypeParams) ([]AutopilotV1FieldType, error) { + response, errors := c.StreamFieldTypeWithCtx(ctx, AssistantSid, params) records := make([]AutopilotV1FieldType, 0) for record := range response { @@ -183,6 +209,11 @@ func (c *ApiService) ListFieldType(AssistantSid string, params *ListFieldTypePar // Streams FieldType records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamFieldType(AssistantSid string, params *ListFieldTypeParams) (chan AutopilotV1FieldType, chan error) { + return c.StreamFieldTypeWithCtx(context.TODO(), AssistantSid, params) +} + +// Streams FieldType records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamFieldTypeWithCtx(ctx context.Context, AssistantSid string, params *ListFieldTypeParams) (chan AutopilotV1FieldType, chan error) { if params == nil { params = &ListFieldTypeParams{} } @@ -191,19 +222,19 @@ func (c *ApiService) StreamFieldType(AssistantSid string, params *ListFieldTypeP recordChannel := make(chan AutopilotV1FieldType, 1) errorChannel := make(chan error, 1) - response, err := c.PageFieldType(AssistantSid, params, "", "") + response, err := c.PageFieldTypeWithCtx(ctx, AssistantSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamFieldType(response, params, recordChannel, errorChannel) + go c.streamFieldType(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamFieldType(response *ListFieldTypeResponse, params *ListFieldTypeParams, recordChannel chan AutopilotV1FieldType, errorChannel chan error) { +func (c *ApiService) streamFieldType(ctx context.Context, response *ListFieldTypeResponse, params *ListFieldTypeParams, recordChannel chan AutopilotV1FieldType, errorChannel chan error) { curRecord := 1 for response != nil { @@ -218,7 +249,7 @@ func (c *ApiService) streamFieldType(response *ListFieldTypeResponse, params *Li } } - record, err := client.GetNext(c.baseURL, response, c.getNextListFieldTypeResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListFieldTypeResponse) if err != nil { errorChannel <- err break @@ -233,11 +264,11 @@ func (c *ApiService) streamFieldType(response *ListFieldTypeResponse, params *Li close(errorChannel) } -func (c *ApiService) getNextListFieldTypeResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListFieldTypeResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -270,6 +301,11 @@ func (params *UpdateFieldTypeParams) SetUniqueName(UniqueName string) *UpdateFie // func (c *ApiService) UpdateFieldType(AssistantSid string, Sid string, params *UpdateFieldTypeParams) (*AutopilotV1FieldType, error) { + return c.UpdateFieldTypeWithCtx(context.TODO(), AssistantSid, Sid, params) +} + +// +func (c *ApiService) UpdateFieldTypeWithCtx(ctx context.Context, AssistantSid string, Sid string, params *UpdateFieldTypeParams) (*AutopilotV1FieldType, error) { path := "/v1/Assistants/{AssistantSid}/FieldTypes/{Sid}" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -284,7 +320,7 @@ func (c *ApiService) UpdateFieldType(AssistantSid string, Sid string, params *Up data.Set("UniqueName", *params.UniqueName) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/autopilot/v1/assistants_field_types_field_values.go b/rest/autopilot/v1/assistants_field_types_field_values.go index af7e52632..6569202b7 100644 --- a/rest/autopilot/v1/assistants_field_types_field_values.go +++ b/rest/autopilot/v1/assistants_field_types_field_values.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -48,6 +49,11 @@ func (params *CreateFieldValueParams) SetSynonymOf(SynonymOf string) *CreateFiel // func (c *ApiService) CreateFieldValue(AssistantSid string, FieldTypeSid string, params *CreateFieldValueParams) (*AutopilotV1FieldValue, error) { + return c.CreateFieldValueWithCtx(context.TODO(), AssistantSid, FieldTypeSid, params) +} + +// +func (c *ApiService) CreateFieldValueWithCtx(ctx context.Context, AssistantSid string, FieldTypeSid string, params *CreateFieldValueParams) (*AutopilotV1FieldValue, error) { path := "/v1/Assistants/{AssistantSid}/FieldTypes/{FieldTypeSid}/FieldValues" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) path = strings.Replace(path, "{"+"FieldTypeSid"+"}", FieldTypeSid, -1) @@ -65,7 +71,7 @@ func (c *ApiService) CreateFieldValue(AssistantSid string, FieldTypeSid string, data.Set("SynonymOf", *params.SynonymOf) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -82,6 +88,11 @@ func (c *ApiService) CreateFieldValue(AssistantSid string, FieldTypeSid string, // func (c *ApiService) DeleteFieldValue(AssistantSid string, FieldTypeSid string, Sid string) error { + return c.DeleteFieldValueWithCtx(context.TODO(), AssistantSid, FieldTypeSid, Sid) +} + +// +func (c *ApiService) DeleteFieldValueWithCtx(ctx context.Context, AssistantSid string, FieldTypeSid string, Sid string) error { path := "/v1/Assistants/{AssistantSid}/FieldTypes/{FieldTypeSid}/FieldValues/{Sid}" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) path = strings.Replace(path, "{"+"FieldTypeSid"+"}", FieldTypeSid, -1) @@ -90,7 +101,7 @@ func (c *ApiService) DeleteFieldValue(AssistantSid string, FieldTypeSid string, data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -102,6 +113,11 @@ func (c *ApiService) DeleteFieldValue(AssistantSid string, FieldTypeSid string, // func (c *ApiService) FetchFieldValue(AssistantSid string, FieldTypeSid string, Sid string) (*AutopilotV1FieldValue, error) { + return c.FetchFieldValueWithCtx(context.TODO(), AssistantSid, FieldTypeSid, Sid) +} + +// +func (c *ApiService) FetchFieldValueWithCtx(ctx context.Context, AssistantSid string, FieldTypeSid string, Sid string) (*AutopilotV1FieldValue, error) { path := "/v1/Assistants/{AssistantSid}/FieldTypes/{FieldTypeSid}/FieldValues/{Sid}" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) path = strings.Replace(path, "{"+"FieldTypeSid"+"}", FieldTypeSid, -1) @@ -110,7 +126,7 @@ func (c *ApiService) FetchFieldValue(AssistantSid string, FieldTypeSid string, S data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -150,6 +166,11 @@ func (params *ListFieldValueParams) SetLimit(Limit int) *ListFieldValueParams { // Retrieve a single page of FieldValue records from the API. Request is executed immediately. func (c *ApiService) PageFieldValue(AssistantSid string, FieldTypeSid string, params *ListFieldValueParams, pageToken, pageNumber string) (*ListFieldValueResponse, error) { + return c.PageFieldValueWithCtx(context.TODO(), AssistantSid, FieldTypeSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of FieldValue records from the API. Request is executed immediately. +func (c *ApiService) PageFieldValueWithCtx(ctx context.Context, AssistantSid string, FieldTypeSid string, params *ListFieldValueParams, pageToken, pageNumber string) (*ListFieldValueResponse, error) { path := "/v1/Assistants/{AssistantSid}/FieldTypes/{FieldTypeSid}/FieldValues" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) @@ -172,7 +193,7 @@ func (c *ApiService) PageFieldValue(AssistantSid string, FieldTypeSid string, pa data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -189,7 +210,12 @@ func (c *ApiService) PageFieldValue(AssistantSid string, FieldTypeSid string, pa // Lists FieldValue records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListFieldValue(AssistantSid string, FieldTypeSid string, params *ListFieldValueParams) ([]AutopilotV1FieldValue, error) { - response, errors := c.StreamFieldValue(AssistantSid, FieldTypeSid, params) + return c.ListFieldValueWithCtx(context.TODO(), AssistantSid, FieldTypeSid, params) +} + +// Lists FieldValue records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListFieldValueWithCtx(ctx context.Context, AssistantSid string, FieldTypeSid string, params *ListFieldValueParams) ([]AutopilotV1FieldValue, error) { + response, errors := c.StreamFieldValueWithCtx(ctx, AssistantSid, FieldTypeSid, params) records := make([]AutopilotV1FieldValue, 0) for record := range response { @@ -205,6 +231,11 @@ func (c *ApiService) ListFieldValue(AssistantSid string, FieldTypeSid string, pa // Streams FieldValue records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamFieldValue(AssistantSid string, FieldTypeSid string, params *ListFieldValueParams) (chan AutopilotV1FieldValue, chan error) { + return c.StreamFieldValueWithCtx(context.TODO(), AssistantSid, FieldTypeSid, params) +} + +// Streams FieldValue records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamFieldValueWithCtx(ctx context.Context, AssistantSid string, FieldTypeSid string, params *ListFieldValueParams) (chan AutopilotV1FieldValue, chan error) { if params == nil { params = &ListFieldValueParams{} } @@ -213,19 +244,19 @@ func (c *ApiService) StreamFieldValue(AssistantSid string, FieldTypeSid string, recordChannel := make(chan AutopilotV1FieldValue, 1) errorChannel := make(chan error, 1) - response, err := c.PageFieldValue(AssistantSid, FieldTypeSid, params, "", "") + response, err := c.PageFieldValueWithCtx(ctx, AssistantSid, FieldTypeSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamFieldValue(response, params, recordChannel, errorChannel) + go c.streamFieldValue(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamFieldValue(response *ListFieldValueResponse, params *ListFieldValueParams, recordChannel chan AutopilotV1FieldValue, errorChannel chan error) { +func (c *ApiService) streamFieldValue(ctx context.Context, response *ListFieldValueResponse, params *ListFieldValueParams, recordChannel chan AutopilotV1FieldValue, errorChannel chan error) { curRecord := 1 for response != nil { @@ -240,7 +271,7 @@ func (c *ApiService) streamFieldValue(response *ListFieldValueResponse, params * } } - record, err := client.GetNext(c.baseURL, response, c.getNextListFieldValueResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListFieldValueResponse) if err != nil { errorChannel <- err break @@ -255,11 +286,11 @@ func (c *ApiService) streamFieldValue(response *ListFieldValueResponse, params * close(errorChannel) } -func (c *ApiService) getNextListFieldValueResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListFieldValueResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/autopilot/v1/assistants_model_builds.go b/rest/autopilot/v1/assistants_model_builds.go index fcd4c67f9..d0ae7fd94 100644 --- a/rest/autopilot/v1/assistants_model_builds.go +++ b/rest/autopilot/v1/assistants_model_builds.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -42,6 +43,11 @@ func (params *CreateModelBuildParams) SetUniqueName(UniqueName string) *CreateMo // func (c *ApiService) CreateModelBuild(AssistantSid string, params *CreateModelBuildParams) (*AutopilotV1ModelBuild, error) { + return c.CreateModelBuildWithCtx(context.TODO(), AssistantSid, params) +} + +// +func (c *ApiService) CreateModelBuildWithCtx(ctx context.Context, AssistantSid string, params *CreateModelBuildParams) (*AutopilotV1ModelBuild, error) { path := "/v1/Assistants/{AssistantSid}/ModelBuilds" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) @@ -55,7 +61,7 @@ func (c *ApiService) CreateModelBuild(AssistantSid string, params *CreateModelBu data.Set("UniqueName", *params.UniqueName) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -72,6 +78,11 @@ func (c *ApiService) CreateModelBuild(AssistantSid string, params *CreateModelBu // func (c *ApiService) DeleteModelBuild(AssistantSid string, Sid string) error { + return c.DeleteModelBuildWithCtx(context.TODO(), AssistantSid, Sid) +} + +// +func (c *ApiService) DeleteModelBuildWithCtx(ctx context.Context, AssistantSid string, Sid string) error { path := "/v1/Assistants/{AssistantSid}/ModelBuilds/{Sid}" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -79,7 +90,7 @@ func (c *ApiService) DeleteModelBuild(AssistantSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -91,6 +102,11 @@ func (c *ApiService) DeleteModelBuild(AssistantSid string, Sid string) error { // func (c *ApiService) FetchModelBuild(AssistantSid string, Sid string) (*AutopilotV1ModelBuild, error) { + return c.FetchModelBuildWithCtx(context.TODO(), AssistantSid, Sid) +} + +// +func (c *ApiService) FetchModelBuildWithCtx(ctx context.Context, AssistantSid string, Sid string) (*AutopilotV1ModelBuild, error) { path := "/v1/Assistants/{AssistantSid}/ModelBuilds/{Sid}" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -98,7 +114,7 @@ func (c *ApiService) FetchModelBuild(AssistantSid string, Sid string) (*Autopilo data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -132,6 +148,11 @@ func (params *ListModelBuildParams) SetLimit(Limit int) *ListModelBuildParams { // Retrieve a single page of ModelBuild records from the API. Request is executed immediately. func (c *ApiService) PageModelBuild(AssistantSid string, params *ListModelBuildParams, pageToken, pageNumber string) (*ListModelBuildResponse, error) { + return c.PageModelBuildWithCtx(context.TODO(), AssistantSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ModelBuild records from the API. Request is executed immediately. +func (c *ApiService) PageModelBuildWithCtx(ctx context.Context, AssistantSid string, params *ListModelBuildParams, pageToken, pageNumber string) (*ListModelBuildResponse, error) { path := "/v1/Assistants/{AssistantSid}/ModelBuilds" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) @@ -150,7 +171,7 @@ func (c *ApiService) PageModelBuild(AssistantSid string, params *ListModelBuildP data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -167,7 +188,12 @@ func (c *ApiService) PageModelBuild(AssistantSid string, params *ListModelBuildP // Lists ModelBuild records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListModelBuild(AssistantSid string, params *ListModelBuildParams) ([]AutopilotV1ModelBuild, error) { - response, errors := c.StreamModelBuild(AssistantSid, params) + return c.ListModelBuildWithCtx(context.TODO(), AssistantSid, params) +} + +// Lists ModelBuild records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListModelBuildWithCtx(ctx context.Context, AssistantSid string, params *ListModelBuildParams) ([]AutopilotV1ModelBuild, error) { + response, errors := c.StreamModelBuildWithCtx(ctx, AssistantSid, params) records := make([]AutopilotV1ModelBuild, 0) for record := range response { @@ -183,6 +209,11 @@ func (c *ApiService) ListModelBuild(AssistantSid string, params *ListModelBuildP // Streams ModelBuild records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamModelBuild(AssistantSid string, params *ListModelBuildParams) (chan AutopilotV1ModelBuild, chan error) { + return c.StreamModelBuildWithCtx(context.TODO(), AssistantSid, params) +} + +// Streams ModelBuild records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamModelBuildWithCtx(ctx context.Context, AssistantSid string, params *ListModelBuildParams) (chan AutopilotV1ModelBuild, chan error) { if params == nil { params = &ListModelBuildParams{} } @@ -191,19 +222,19 @@ func (c *ApiService) StreamModelBuild(AssistantSid string, params *ListModelBuil recordChannel := make(chan AutopilotV1ModelBuild, 1) errorChannel := make(chan error, 1) - response, err := c.PageModelBuild(AssistantSid, params, "", "") + response, err := c.PageModelBuildWithCtx(ctx, AssistantSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamModelBuild(response, params, recordChannel, errorChannel) + go c.streamModelBuild(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamModelBuild(response *ListModelBuildResponse, params *ListModelBuildParams, recordChannel chan AutopilotV1ModelBuild, errorChannel chan error) { +func (c *ApiService) streamModelBuild(ctx context.Context, response *ListModelBuildResponse, params *ListModelBuildParams, recordChannel chan AutopilotV1ModelBuild, errorChannel chan error) { curRecord := 1 for response != nil { @@ -218,7 +249,7 @@ func (c *ApiService) streamModelBuild(response *ListModelBuildResponse, params * } } - record, err := client.GetNext(c.baseURL, response, c.getNextListModelBuildResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListModelBuildResponse) if err != nil { errorChannel <- err break @@ -233,11 +264,11 @@ func (c *ApiService) streamModelBuild(response *ListModelBuildResponse, params * close(errorChannel) } -func (c *ApiService) getNextListModelBuildResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListModelBuildResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -264,6 +295,11 @@ func (params *UpdateModelBuildParams) SetUniqueName(UniqueName string) *UpdateMo // func (c *ApiService) UpdateModelBuild(AssistantSid string, Sid string, params *UpdateModelBuildParams) (*AutopilotV1ModelBuild, error) { + return c.UpdateModelBuildWithCtx(context.TODO(), AssistantSid, Sid, params) +} + +// +func (c *ApiService) UpdateModelBuildWithCtx(ctx context.Context, AssistantSid string, Sid string, params *UpdateModelBuildParams) (*AutopilotV1ModelBuild, error) { path := "/v1/Assistants/{AssistantSid}/ModelBuilds/{Sid}" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -275,7 +311,7 @@ func (c *ApiService) UpdateModelBuild(AssistantSid string, Sid string, params *U data.Set("UniqueName", *params.UniqueName) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/autopilot/v1/assistants_queries.go b/rest/autopilot/v1/assistants_queries.go index 8fef763b1..50d5db6cb 100644 --- a/rest/autopilot/v1/assistants_queries.go +++ b/rest/autopilot/v1/assistants_queries.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -54,6 +55,11 @@ func (params *CreateQueryParams) SetModelBuild(ModelBuild string) *CreateQueryPa // func (c *ApiService) CreateQuery(AssistantSid string, params *CreateQueryParams) (*AutopilotV1Query, error) { + return c.CreateQueryWithCtx(context.TODO(), AssistantSid, params) +} + +// +func (c *ApiService) CreateQueryWithCtx(ctx context.Context, AssistantSid string, params *CreateQueryParams) (*AutopilotV1Query, error) { path := "/v1/Assistants/{AssistantSid}/Queries" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) @@ -73,7 +79,7 @@ func (c *ApiService) CreateQuery(AssistantSid string, params *CreateQueryParams) data.Set("ModelBuild", *params.ModelBuild) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -90,6 +96,11 @@ func (c *ApiService) CreateQuery(AssistantSid string, params *CreateQueryParams) // func (c *ApiService) DeleteQuery(AssistantSid string, Sid string) error { + return c.DeleteQueryWithCtx(context.TODO(), AssistantSid, Sid) +} + +// +func (c *ApiService) DeleteQueryWithCtx(ctx context.Context, AssistantSid string, Sid string) error { path := "/v1/Assistants/{AssistantSid}/Queries/{Sid}" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -97,7 +108,7 @@ func (c *ApiService) DeleteQuery(AssistantSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -109,6 +120,11 @@ func (c *ApiService) DeleteQuery(AssistantSid string, Sid string) error { // func (c *ApiService) FetchQuery(AssistantSid string, Sid string) (*AutopilotV1Query, error) { + return c.FetchQueryWithCtx(context.TODO(), AssistantSid, Sid) +} + +// +func (c *ApiService) FetchQueryWithCtx(ctx context.Context, AssistantSid string, Sid string) (*AutopilotV1Query, error) { path := "/v1/Assistants/{AssistantSid}/Queries/{Sid}" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -116,7 +132,7 @@ func (c *ApiService) FetchQuery(AssistantSid string, Sid string) (*AutopilotV1Qu data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -174,6 +190,11 @@ func (params *ListQueryParams) SetLimit(Limit int) *ListQueryParams { // Retrieve a single page of Query records from the API. Request is executed immediately. func (c *ApiService) PageQuery(AssistantSid string, params *ListQueryParams, pageToken, pageNumber string) (*ListQueryResponse, error) { + return c.PageQueryWithCtx(context.TODO(), AssistantSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Query records from the API. Request is executed immediately. +func (c *ApiService) PageQueryWithCtx(ctx context.Context, AssistantSid string, params *ListQueryParams, pageToken, pageNumber string) (*ListQueryResponse, error) { path := "/v1/Assistants/{AssistantSid}/Queries" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) @@ -204,7 +225,7 @@ func (c *ApiService) PageQuery(AssistantSid string, params *ListQueryParams, pag data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -221,7 +242,12 @@ func (c *ApiService) PageQuery(AssistantSid string, params *ListQueryParams, pag // Lists Query records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListQuery(AssistantSid string, params *ListQueryParams) ([]AutopilotV1Query, error) { - response, errors := c.StreamQuery(AssistantSid, params) + return c.ListQueryWithCtx(context.TODO(), AssistantSid, params) +} + +// Lists Query records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListQueryWithCtx(ctx context.Context, AssistantSid string, params *ListQueryParams) ([]AutopilotV1Query, error) { + response, errors := c.StreamQueryWithCtx(ctx, AssistantSid, params) records := make([]AutopilotV1Query, 0) for record := range response { @@ -237,6 +263,11 @@ func (c *ApiService) ListQuery(AssistantSid string, params *ListQueryParams) ([] // Streams Query records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamQuery(AssistantSid string, params *ListQueryParams) (chan AutopilotV1Query, chan error) { + return c.StreamQueryWithCtx(context.TODO(), AssistantSid, params) +} + +// Streams Query records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamQueryWithCtx(ctx context.Context, AssistantSid string, params *ListQueryParams) (chan AutopilotV1Query, chan error) { if params == nil { params = &ListQueryParams{} } @@ -245,19 +276,19 @@ func (c *ApiService) StreamQuery(AssistantSid string, params *ListQueryParams) ( recordChannel := make(chan AutopilotV1Query, 1) errorChannel := make(chan error, 1) - response, err := c.PageQuery(AssistantSid, params, "", "") + response, err := c.PageQueryWithCtx(ctx, AssistantSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamQuery(response, params, recordChannel, errorChannel) + go c.streamQuery(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamQuery(response *ListQueryResponse, params *ListQueryParams, recordChannel chan AutopilotV1Query, errorChannel chan error) { +func (c *ApiService) streamQuery(ctx context.Context, response *ListQueryResponse, params *ListQueryParams, recordChannel chan AutopilotV1Query, errorChannel chan error) { curRecord := 1 for response != nil { @@ -272,7 +303,7 @@ func (c *ApiService) streamQuery(response *ListQueryResponse, params *ListQueryP } } - record, err := client.GetNext(c.baseURL, response, c.getNextListQueryResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListQueryResponse) if err != nil { errorChannel <- err break @@ -287,11 +318,11 @@ func (c *ApiService) streamQuery(response *ListQueryResponse, params *ListQueryP close(errorChannel) } -func (c *ApiService) getNextListQueryResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListQueryResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -324,6 +355,11 @@ func (params *UpdateQueryParams) SetStatus(Status string) *UpdateQueryParams { // func (c *ApiService) UpdateQuery(AssistantSid string, Sid string, params *UpdateQueryParams) (*AutopilotV1Query, error) { + return c.UpdateQueryWithCtx(context.TODO(), AssistantSid, Sid, params) +} + +// +func (c *ApiService) UpdateQueryWithCtx(ctx context.Context, AssistantSid string, Sid string, params *UpdateQueryParams) (*AutopilotV1Query, error) { path := "/v1/Assistants/{AssistantSid}/Queries/{Sid}" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -338,7 +374,7 @@ func (c *ApiService) UpdateQuery(AssistantSid string, Sid string, params *Update data.Set("Status", *params.Status) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/autopilot/v1/assistants_restore.go b/rest/autopilot/v1/assistants_restore.go index bbf3f5457..b786f83a5 100644 --- a/rest/autopilot/v1/assistants_restore.go +++ b/rest/autopilot/v1/assistants_restore.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" ) @@ -32,6 +33,11 @@ func (params *UpdateRestoreAssistantParams) SetAssistant(Assistant string) *Upda // func (c *ApiService) UpdateRestoreAssistant(params *UpdateRestoreAssistantParams) (*AutopilotV1RestoreAssistant, error) { + return c.UpdateRestoreAssistantWithCtx(context.TODO(), params) +} + +// +func (c *ApiService) UpdateRestoreAssistantWithCtx(ctx context.Context, params *UpdateRestoreAssistantParams) (*AutopilotV1RestoreAssistant, error) { path := "/v1/Assistants/Restore" data := url.Values{} @@ -41,7 +47,7 @@ func (c *ApiService) UpdateRestoreAssistant(params *UpdateRestoreAssistantParams data.Set("Assistant", *params.Assistant) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/autopilot/v1/assistants_style_sheet.go b/rest/autopilot/v1/assistants_style_sheet.go index d5b5145f7..899c5a59f 100644 --- a/rest/autopilot/v1/assistants_style_sheet.go +++ b/rest/autopilot/v1/assistants_style_sheet.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -22,13 +23,18 @@ import ( // Returns Style sheet JSON object for the Assistant func (c *ApiService) FetchStyleSheet(AssistantSid string) (*AutopilotV1StyleSheet, error) { + return c.FetchStyleSheetWithCtx(context.TODO(), AssistantSid) +} + +// Returns Style sheet JSON object for the Assistant +func (c *ApiService) FetchStyleSheetWithCtx(ctx context.Context, AssistantSid string) (*AutopilotV1StyleSheet, error) { path := "/v1/Assistants/{AssistantSid}/StyleSheet" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -56,6 +62,11 @@ func (params *UpdateStyleSheetParams) SetStyleSheet(StyleSheet interface{}) *Upd // Updates the style sheet for an Assistant identified by `assistant_sid`. func (c *ApiService) UpdateStyleSheet(AssistantSid string, params *UpdateStyleSheetParams) (*AutopilotV1StyleSheet, error) { + return c.UpdateStyleSheetWithCtx(context.TODO(), AssistantSid, params) +} + +// Updates the style sheet for an Assistant identified by `assistant_sid`. +func (c *ApiService) UpdateStyleSheetWithCtx(ctx context.Context, AssistantSid string, params *UpdateStyleSheetParams) (*AutopilotV1StyleSheet, error) { path := "/v1/Assistants/{AssistantSid}/StyleSheet" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) @@ -72,7 +83,7 @@ func (c *ApiService) UpdateStyleSheet(AssistantSid string, params *UpdateStyleSh data.Set("StyleSheet", string(v)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/autopilot/v1/assistants_tasks.go b/rest/autopilot/v1/assistants_tasks.go index 5f706c91a..5e31e3169 100644 --- a/rest/autopilot/v1/assistants_tasks.go +++ b/rest/autopilot/v1/assistants_tasks.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -54,6 +55,11 @@ func (params *CreateTaskParams) SetActionsUrl(ActionsUrl string) *CreateTaskPara // func (c *ApiService) CreateTask(AssistantSid string, params *CreateTaskParams) (*AutopilotV1Task, error) { + return c.CreateTaskWithCtx(context.TODO(), AssistantSid, params) +} + +// +func (c *ApiService) CreateTaskWithCtx(ctx context.Context, AssistantSid string, params *CreateTaskParams) (*AutopilotV1Task, error) { path := "/v1/Assistants/{AssistantSid}/Tasks" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) @@ -79,7 +85,7 @@ func (c *ApiService) CreateTask(AssistantSid string, params *CreateTaskParams) ( data.Set("ActionsUrl", *params.ActionsUrl) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -96,6 +102,11 @@ func (c *ApiService) CreateTask(AssistantSid string, params *CreateTaskParams) ( // func (c *ApiService) DeleteTask(AssistantSid string, Sid string) error { + return c.DeleteTaskWithCtx(context.TODO(), AssistantSid, Sid) +} + +// +func (c *ApiService) DeleteTaskWithCtx(ctx context.Context, AssistantSid string, Sid string) error { path := "/v1/Assistants/{AssistantSid}/Tasks/{Sid}" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -103,7 +114,7 @@ func (c *ApiService) DeleteTask(AssistantSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -115,6 +126,11 @@ func (c *ApiService) DeleteTask(AssistantSid string, Sid string) error { // func (c *ApiService) FetchTask(AssistantSid string, Sid string) (*AutopilotV1Task, error) { + return c.FetchTaskWithCtx(context.TODO(), AssistantSid, Sid) +} + +// +func (c *ApiService) FetchTaskWithCtx(ctx context.Context, AssistantSid string, Sid string) (*AutopilotV1Task, error) { path := "/v1/Assistants/{AssistantSid}/Tasks/{Sid}" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -122,7 +138,7 @@ func (c *ApiService) FetchTask(AssistantSid string, Sid string) (*AutopilotV1Tas data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -156,6 +172,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(AssistantSid string, params *ListTaskParams, pageToken, pageNumber string) (*ListTaskResponse, error) { + return c.PageTaskWithCtx(context.TODO(), AssistantSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Task records from the API. Request is executed immediately. +func (c *ApiService) PageTaskWithCtx(ctx context.Context, AssistantSid string, params *ListTaskParams, pageToken, pageNumber string) (*ListTaskResponse, error) { path := "/v1/Assistants/{AssistantSid}/Tasks" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) @@ -174,7 +195,7 @@ func (c *ApiService) PageTask(AssistantSid string, params *ListTaskParams, pageT data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -191,7 +212,12 @@ func (c *ApiService) PageTask(AssistantSid 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(AssistantSid string, params *ListTaskParams) ([]AutopilotV1Task, error) { - response, errors := c.StreamTask(AssistantSid, params) + return c.ListTaskWithCtx(context.TODO(), AssistantSid, 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) ListTaskWithCtx(ctx context.Context, AssistantSid string, params *ListTaskParams) ([]AutopilotV1Task, error) { + response, errors := c.StreamTaskWithCtx(ctx, AssistantSid, params) records := make([]AutopilotV1Task, 0) for record := range response { @@ -207,6 +233,11 @@ func (c *ApiService) ListTask(AssistantSid string, params *ListTaskParams) ([]Au // 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(AssistantSid string, params *ListTaskParams) (chan AutopilotV1Task, chan error) { + return c.StreamTaskWithCtx(context.TODO(), AssistantSid, 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) StreamTaskWithCtx(ctx context.Context, AssistantSid string, params *ListTaskParams) (chan AutopilotV1Task, chan error) { if params == nil { params = &ListTaskParams{} } @@ -215,19 +246,19 @@ func (c *ApiService) StreamTask(AssistantSid string, params *ListTaskParams) (ch recordChannel := make(chan AutopilotV1Task, 1) errorChannel := make(chan error, 1) - response, err := c.PageTask(AssistantSid, params, "", "") + response, err := c.PageTaskWithCtx(ctx, AssistantSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamTask(response, params, recordChannel, errorChannel) + go c.streamTask(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamTask(response *ListTaskResponse, params *ListTaskParams, recordChannel chan AutopilotV1Task, errorChannel chan error) { +func (c *ApiService) streamTask(ctx context.Context, response *ListTaskResponse, params *ListTaskParams, recordChannel chan AutopilotV1Task, errorChannel chan error) { curRecord := 1 for response != nil { @@ -242,7 +273,7 @@ func (c *ApiService) streamTask(response *ListTaskResponse, params *ListTaskPara } } - record, err := client.GetNext(c.baseURL, response, c.getNextListTaskResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListTaskResponse) if err != nil { errorChannel <- err break @@ -257,11 +288,11 @@ func (c *ApiService) streamTask(response *ListTaskResponse, params *ListTaskPara close(errorChannel) } -func (c *ApiService) getNextListTaskResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListTaskResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -306,6 +337,11 @@ func (params *UpdateTaskParams) SetActionsUrl(ActionsUrl string) *UpdateTaskPara // func (c *ApiService) UpdateTask(AssistantSid string, Sid string, params *UpdateTaskParams) (*AutopilotV1Task, error) { + return c.UpdateTaskWithCtx(context.TODO(), AssistantSid, Sid, params) +} + +// +func (c *ApiService) UpdateTaskWithCtx(ctx context.Context, AssistantSid string, Sid string, params *UpdateTaskParams) (*AutopilotV1Task, error) { path := "/v1/Assistants/{AssistantSid}/Tasks/{Sid}" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -332,7 +368,7 @@ func (c *ApiService) UpdateTask(AssistantSid string, Sid string, params *UpdateT data.Set("ActionsUrl", *params.ActionsUrl) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/autopilot/v1/assistants_tasks_actions.go b/rest/autopilot/v1/assistants_tasks_actions.go index 9c4097720..4c1088bb7 100644 --- a/rest/autopilot/v1/assistants_tasks_actions.go +++ b/rest/autopilot/v1/assistants_tasks_actions.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -22,6 +23,11 @@ import ( // Returns JSON actions for the Task. func (c *ApiService) FetchTaskActions(AssistantSid string, TaskSid string) (*AutopilotV1TaskActions, error) { + return c.FetchTaskActionsWithCtx(context.TODO(), AssistantSid, TaskSid) +} + +// Returns JSON actions for the Task. +func (c *ApiService) FetchTaskActionsWithCtx(ctx context.Context, AssistantSid string, TaskSid string) (*AutopilotV1TaskActions, error) { path := "/v1/Assistants/{AssistantSid}/Tasks/{TaskSid}/Actions" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) path = strings.Replace(path, "{"+"TaskSid"+"}", TaskSid, -1) @@ -29,7 +35,7 @@ func (c *ApiService) FetchTaskActions(AssistantSid string, TaskSid string) (*Aut data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -57,6 +63,11 @@ func (params *UpdateTaskActionsParams) SetActions(Actions interface{}) *UpdateTa // Updates the actions of an Task identified by {TaskSid} or {TaskUniqueName}. func (c *ApiService) UpdateTaskActions(AssistantSid string, TaskSid string, params *UpdateTaskActionsParams) (*AutopilotV1TaskActions, error) { + return c.UpdateTaskActionsWithCtx(context.TODO(), AssistantSid, TaskSid, params) +} + +// Updates the actions of an Task identified by {TaskSid} or {TaskUniqueName}. +func (c *ApiService) UpdateTaskActionsWithCtx(ctx context.Context, AssistantSid string, TaskSid string, params *UpdateTaskActionsParams) (*AutopilotV1TaskActions, error) { path := "/v1/Assistants/{AssistantSid}/Tasks/{TaskSid}/Actions" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) path = strings.Replace(path, "{"+"TaskSid"+"}", TaskSid, -1) @@ -74,7 +85,7 @@ func (c *ApiService) UpdateTaskActions(AssistantSid string, TaskSid string, para data.Set("Actions", string(v)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/autopilot/v1/assistants_tasks_fields.go b/rest/autopilot/v1/assistants_tasks_fields.go index df0c81afa..52d8ee199 100644 --- a/rest/autopilot/v1/assistants_tasks_fields.go +++ b/rest/autopilot/v1/assistants_tasks_fields.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -42,6 +43,11 @@ func (params *CreateFieldParams) SetUniqueName(UniqueName string) *CreateFieldPa // func (c *ApiService) CreateField(AssistantSid string, TaskSid string, params *CreateFieldParams) (*AutopilotV1Field, error) { + return c.CreateFieldWithCtx(context.TODO(), AssistantSid, TaskSid, params) +} + +// +func (c *ApiService) CreateFieldWithCtx(ctx context.Context, AssistantSid string, TaskSid string, params *CreateFieldParams) (*AutopilotV1Field, error) { path := "/v1/Assistants/{AssistantSid}/Tasks/{TaskSid}/Fields" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) path = strings.Replace(path, "{"+"TaskSid"+"}", TaskSid, -1) @@ -56,7 +62,7 @@ func (c *ApiService) CreateField(AssistantSid string, TaskSid string, params *Cr data.Set("UniqueName", *params.UniqueName) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -73,6 +79,11 @@ func (c *ApiService) CreateField(AssistantSid string, TaskSid string, params *Cr // func (c *ApiService) DeleteField(AssistantSid string, TaskSid string, Sid string) error { + return c.DeleteFieldWithCtx(context.TODO(), AssistantSid, TaskSid, Sid) +} + +// +func (c *ApiService) DeleteFieldWithCtx(ctx context.Context, AssistantSid string, TaskSid string, Sid string) error { path := "/v1/Assistants/{AssistantSid}/Tasks/{TaskSid}/Fields/{Sid}" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) path = strings.Replace(path, "{"+"TaskSid"+"}", TaskSid, -1) @@ -81,7 +92,7 @@ func (c *ApiService) DeleteField(AssistantSid string, TaskSid string, Sid string data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -93,6 +104,11 @@ func (c *ApiService) DeleteField(AssistantSid string, TaskSid string, Sid string // func (c *ApiService) FetchField(AssistantSid string, TaskSid string, Sid string) (*AutopilotV1Field, error) { + return c.FetchFieldWithCtx(context.TODO(), AssistantSid, TaskSid, Sid) +} + +// +func (c *ApiService) FetchFieldWithCtx(ctx context.Context, AssistantSid string, TaskSid string, Sid string) (*AutopilotV1Field, error) { path := "/v1/Assistants/{AssistantSid}/Tasks/{TaskSid}/Fields/{Sid}" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) path = strings.Replace(path, "{"+"TaskSid"+"}", TaskSid, -1) @@ -101,7 +117,7 @@ func (c *ApiService) FetchField(AssistantSid string, TaskSid string, Sid string) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -135,6 +151,11 @@ func (params *ListFieldParams) SetLimit(Limit int) *ListFieldParams { // Retrieve a single page of Field records from the API. Request is executed immediately. func (c *ApiService) PageField(AssistantSid string, TaskSid string, params *ListFieldParams, pageToken, pageNumber string) (*ListFieldResponse, error) { + return c.PageFieldWithCtx(context.TODO(), AssistantSid, TaskSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Field records from the API. Request is executed immediately. +func (c *ApiService) PageFieldWithCtx(ctx context.Context, AssistantSid string, TaskSid string, params *ListFieldParams, pageToken, pageNumber string) (*ListFieldResponse, error) { path := "/v1/Assistants/{AssistantSid}/Tasks/{TaskSid}/Fields" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) @@ -154,7 +175,7 @@ func (c *ApiService) PageField(AssistantSid string, TaskSid string, params *List data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -171,7 +192,12 @@ func (c *ApiService) PageField(AssistantSid string, TaskSid string, params *List // Lists Field records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListField(AssistantSid string, TaskSid string, params *ListFieldParams) ([]AutopilotV1Field, error) { - response, errors := c.StreamField(AssistantSid, TaskSid, params) + return c.ListFieldWithCtx(context.TODO(), AssistantSid, TaskSid, params) +} + +// Lists Field records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListFieldWithCtx(ctx context.Context, AssistantSid string, TaskSid string, params *ListFieldParams) ([]AutopilotV1Field, error) { + response, errors := c.StreamFieldWithCtx(ctx, AssistantSid, TaskSid, params) records := make([]AutopilotV1Field, 0) for record := range response { @@ -187,6 +213,11 @@ func (c *ApiService) ListField(AssistantSid string, TaskSid string, params *List // Streams Field records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamField(AssistantSid string, TaskSid string, params *ListFieldParams) (chan AutopilotV1Field, chan error) { + return c.StreamFieldWithCtx(context.TODO(), AssistantSid, TaskSid, params) +} + +// Streams Field records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamFieldWithCtx(ctx context.Context, AssistantSid string, TaskSid string, params *ListFieldParams) (chan AutopilotV1Field, chan error) { if params == nil { params = &ListFieldParams{} } @@ -195,19 +226,19 @@ func (c *ApiService) StreamField(AssistantSid string, TaskSid string, params *Li recordChannel := make(chan AutopilotV1Field, 1) errorChannel := make(chan error, 1) - response, err := c.PageField(AssistantSid, TaskSid, params, "", "") + response, err := c.PageFieldWithCtx(ctx, AssistantSid, TaskSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamField(response, params, recordChannel, errorChannel) + go c.streamField(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamField(response *ListFieldResponse, params *ListFieldParams, recordChannel chan AutopilotV1Field, errorChannel chan error) { +func (c *ApiService) streamField(ctx context.Context, response *ListFieldResponse, params *ListFieldParams, recordChannel chan AutopilotV1Field, errorChannel chan error) { curRecord := 1 for response != nil { @@ -222,7 +253,7 @@ func (c *ApiService) streamField(response *ListFieldResponse, params *ListFieldP } } - record, err := client.GetNext(c.baseURL, response, c.getNextListFieldResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListFieldResponse) if err != nil { errorChannel <- err break @@ -237,11 +268,11 @@ func (c *ApiService) streamField(response *ListFieldResponse, params *ListFieldP close(errorChannel) } -func (c *ApiService) getNextListFieldResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListFieldResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/autopilot/v1/assistants_tasks_samples.go b/rest/autopilot/v1/assistants_tasks_samples.go index 410168e92..011cd078c 100644 --- a/rest/autopilot/v1/assistants_tasks_samples.go +++ b/rest/autopilot/v1/assistants_tasks_samples.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -48,6 +49,11 @@ func (params *CreateSampleParams) SetSourceChannel(SourceChannel string) *Create // func (c *ApiService) CreateSample(AssistantSid string, TaskSid string, params *CreateSampleParams) (*AutopilotV1Sample, error) { + return c.CreateSampleWithCtx(context.TODO(), AssistantSid, TaskSid, params) +} + +// +func (c *ApiService) CreateSampleWithCtx(ctx context.Context, AssistantSid string, TaskSid string, params *CreateSampleParams) (*AutopilotV1Sample, error) { path := "/v1/Assistants/{AssistantSid}/Tasks/{TaskSid}/Samples" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) path = strings.Replace(path, "{"+"TaskSid"+"}", TaskSid, -1) @@ -65,7 +71,7 @@ func (c *ApiService) CreateSample(AssistantSid string, TaskSid string, params *C data.Set("SourceChannel", *params.SourceChannel) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -82,6 +88,11 @@ func (c *ApiService) CreateSample(AssistantSid string, TaskSid string, params *C // func (c *ApiService) DeleteSample(AssistantSid string, TaskSid string, Sid string) error { + return c.DeleteSampleWithCtx(context.TODO(), AssistantSid, TaskSid, Sid) +} + +// +func (c *ApiService) DeleteSampleWithCtx(ctx context.Context, AssistantSid string, TaskSid string, Sid string) error { path := "/v1/Assistants/{AssistantSid}/Tasks/{TaskSid}/Samples/{Sid}" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) path = strings.Replace(path, "{"+"TaskSid"+"}", TaskSid, -1) @@ -90,7 +101,7 @@ func (c *ApiService) DeleteSample(AssistantSid string, TaskSid string, Sid strin data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -102,6 +113,11 @@ func (c *ApiService) DeleteSample(AssistantSid string, TaskSid string, Sid strin // func (c *ApiService) FetchSample(AssistantSid string, TaskSid string, Sid string) (*AutopilotV1Sample, error) { + return c.FetchSampleWithCtx(context.TODO(), AssistantSid, TaskSid, Sid) +} + +// +func (c *ApiService) FetchSampleWithCtx(ctx context.Context, AssistantSid string, TaskSid string, Sid string) (*AutopilotV1Sample, error) { path := "/v1/Assistants/{AssistantSid}/Tasks/{TaskSid}/Samples/{Sid}" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) path = strings.Replace(path, "{"+"TaskSid"+"}", TaskSid, -1) @@ -110,7 +126,7 @@ func (c *ApiService) FetchSample(AssistantSid string, TaskSid string, Sid string data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -150,6 +166,11 @@ func (params *ListSampleParams) SetLimit(Limit int) *ListSampleParams { // Retrieve a single page of Sample records from the API. Request is executed immediately. func (c *ApiService) PageSample(AssistantSid string, TaskSid string, params *ListSampleParams, pageToken, pageNumber string) (*ListSampleResponse, error) { + return c.PageSampleWithCtx(context.TODO(), AssistantSid, TaskSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Sample records from the API. Request is executed immediately. +func (c *ApiService) PageSampleWithCtx(ctx context.Context, AssistantSid string, TaskSid string, params *ListSampleParams, pageToken, pageNumber string) (*ListSampleResponse, error) { path := "/v1/Assistants/{AssistantSid}/Tasks/{TaskSid}/Samples" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) @@ -172,7 +193,7 @@ func (c *ApiService) PageSample(AssistantSid string, TaskSid string, params *Lis data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -189,7 +210,12 @@ func (c *ApiService) PageSample(AssistantSid string, TaskSid string, params *Lis // Lists Sample records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListSample(AssistantSid string, TaskSid string, params *ListSampleParams) ([]AutopilotV1Sample, error) { - response, errors := c.StreamSample(AssistantSid, TaskSid, params) + return c.ListSampleWithCtx(context.TODO(), AssistantSid, TaskSid, params) +} + +// Lists Sample records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListSampleWithCtx(ctx context.Context, AssistantSid string, TaskSid string, params *ListSampleParams) ([]AutopilotV1Sample, error) { + response, errors := c.StreamSampleWithCtx(ctx, AssistantSid, TaskSid, params) records := make([]AutopilotV1Sample, 0) for record := range response { @@ -205,6 +231,11 @@ func (c *ApiService) ListSample(AssistantSid string, TaskSid string, params *Lis // Streams Sample records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamSample(AssistantSid string, TaskSid string, params *ListSampleParams) (chan AutopilotV1Sample, chan error) { + return c.StreamSampleWithCtx(context.TODO(), AssistantSid, TaskSid, params) +} + +// Streams Sample records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamSampleWithCtx(ctx context.Context, AssistantSid string, TaskSid string, params *ListSampleParams) (chan AutopilotV1Sample, chan error) { if params == nil { params = &ListSampleParams{} } @@ -213,19 +244,19 @@ func (c *ApiService) StreamSample(AssistantSid string, TaskSid string, params *L recordChannel := make(chan AutopilotV1Sample, 1) errorChannel := make(chan error, 1) - response, err := c.PageSample(AssistantSid, TaskSid, params, "", "") + response, err := c.PageSampleWithCtx(ctx, AssistantSid, TaskSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSample(response, params, recordChannel, errorChannel) + go c.streamSample(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamSample(response *ListSampleResponse, params *ListSampleParams, recordChannel chan AutopilotV1Sample, errorChannel chan error) { +func (c *ApiService) streamSample(ctx context.Context, response *ListSampleResponse, params *ListSampleParams, recordChannel chan AutopilotV1Sample, errorChannel chan error) { curRecord := 1 for response != nil { @@ -240,7 +271,7 @@ func (c *ApiService) streamSample(response *ListSampleResponse, params *ListSamp } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSampleResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListSampleResponse) if err != nil { errorChannel <- err break @@ -255,11 +286,11 @@ func (c *ApiService) streamSample(response *ListSampleResponse, params *ListSamp close(errorChannel) } -func (c *ApiService) getNextListSampleResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSampleResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -298,6 +329,11 @@ func (params *UpdateSampleParams) SetSourceChannel(SourceChannel string) *Update // func (c *ApiService) UpdateSample(AssistantSid string, TaskSid string, Sid string, params *UpdateSampleParams) (*AutopilotV1Sample, error) { + return c.UpdateSampleWithCtx(context.TODO(), AssistantSid, TaskSid, Sid, params) +} + +// +func (c *ApiService) UpdateSampleWithCtx(ctx context.Context, AssistantSid string, TaskSid string, Sid string, params *UpdateSampleParams) (*AutopilotV1Sample, error) { path := "/v1/Assistants/{AssistantSid}/Tasks/{TaskSid}/Samples/{Sid}" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) path = strings.Replace(path, "{"+"TaskSid"+"}", TaskSid, -1) @@ -316,7 +352,7 @@ func (c *ApiService) UpdateSample(AssistantSid string, TaskSid string, Sid strin data.Set("SourceChannel", *params.SourceChannel) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/autopilot/v1/assistants_tasks_statistics.go b/rest/autopilot/v1/assistants_tasks_statistics.go index d7b92fc1d..ee1d21946 100644 --- a/rest/autopilot/v1/assistants_tasks_statistics.go +++ b/rest/autopilot/v1/assistants_tasks_statistics.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -22,6 +23,11 @@ import ( // func (c *ApiService) FetchTaskStatistics(AssistantSid string, TaskSid string) (*AutopilotV1TaskStatistics, error) { + return c.FetchTaskStatisticsWithCtx(context.TODO(), AssistantSid, TaskSid) +} + +// +func (c *ApiService) FetchTaskStatisticsWithCtx(ctx context.Context, AssistantSid string, TaskSid string) (*AutopilotV1TaskStatistics, error) { path := "/v1/Assistants/{AssistantSid}/Tasks/{TaskSid}/Statistics" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) path = strings.Replace(path, "{"+"TaskSid"+"}", TaskSid, -1) @@ -29,7 +35,7 @@ func (c *ApiService) FetchTaskStatistics(AssistantSid string, TaskSid string) (* data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/autopilot/v1/assistants_webhooks.go b/rest/autopilot/v1/assistants_webhooks.go index 4562e47f5..559084e5e 100644 --- a/rest/autopilot/v1/assistants_webhooks.go +++ b/rest/autopilot/v1/assistants_webhooks.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -54,6 +55,11 @@ func (params *CreateWebhookParams) SetWebhookMethod(WebhookMethod string) *Creat // func (c *ApiService) CreateWebhook(AssistantSid string, params *CreateWebhookParams) (*AutopilotV1Webhook, error) { + return c.CreateWebhookWithCtx(context.TODO(), AssistantSid, params) +} + +// +func (c *ApiService) CreateWebhookWithCtx(ctx context.Context, AssistantSid string, params *CreateWebhookParams) (*AutopilotV1Webhook, error) { path := "/v1/Assistants/{AssistantSid}/Webhooks" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) @@ -73,7 +79,7 @@ func (c *ApiService) CreateWebhook(AssistantSid string, params *CreateWebhookPar data.Set("WebhookMethod", *params.WebhookMethod) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -90,6 +96,11 @@ func (c *ApiService) CreateWebhook(AssistantSid string, params *CreateWebhookPar // func (c *ApiService) DeleteWebhook(AssistantSid string, Sid string) error { + return c.DeleteWebhookWithCtx(context.TODO(), AssistantSid, Sid) +} + +// +func (c *ApiService) DeleteWebhookWithCtx(ctx context.Context, AssistantSid string, Sid string) error { path := "/v1/Assistants/{AssistantSid}/Webhooks/{Sid}" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -97,7 +108,7 @@ func (c *ApiService) DeleteWebhook(AssistantSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -109,6 +120,11 @@ func (c *ApiService) DeleteWebhook(AssistantSid string, Sid string) error { // func (c *ApiService) FetchWebhook(AssistantSid string, Sid string) (*AutopilotV1Webhook, error) { + return c.FetchWebhookWithCtx(context.TODO(), AssistantSid, Sid) +} + +// +func (c *ApiService) FetchWebhookWithCtx(ctx context.Context, AssistantSid string, Sid string) (*AutopilotV1Webhook, error) { path := "/v1/Assistants/{AssistantSid}/Webhooks/{Sid}" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -116,7 +132,7 @@ func (c *ApiService) FetchWebhook(AssistantSid string, Sid string) (*AutopilotV1 data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -150,6 +166,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(AssistantSid string, params *ListWebhookParams, pageToken, pageNumber string) (*ListWebhookResponse, error) { + return c.PageWebhookWithCtx(context.TODO(), AssistantSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Webhook records from the API. Request is executed immediately. +func (c *ApiService) PageWebhookWithCtx(ctx context.Context, AssistantSid string, params *ListWebhookParams, pageToken, pageNumber string) (*ListWebhookResponse, error) { path := "/v1/Assistants/{AssistantSid}/Webhooks" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) @@ -168,7 +189,7 @@ func (c *ApiService) PageWebhook(AssistantSid string, params *ListWebhookParams, data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -185,7 +206,12 @@ func (c *ApiService) PageWebhook(AssistantSid string, params *ListWebhookParams, // 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(AssistantSid string, params *ListWebhookParams) ([]AutopilotV1Webhook, error) { - response, errors := c.StreamWebhook(AssistantSid, params) + return c.ListWebhookWithCtx(context.TODO(), AssistantSid, 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) ListWebhookWithCtx(ctx context.Context, AssistantSid string, params *ListWebhookParams) ([]AutopilotV1Webhook, error) { + response, errors := c.StreamWebhookWithCtx(ctx, AssistantSid, params) records := make([]AutopilotV1Webhook, 0) for record := range response { @@ -201,6 +227,11 @@ func (c *ApiService) ListWebhook(AssistantSid 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(AssistantSid string, params *ListWebhookParams) (chan AutopilotV1Webhook, chan error) { + return c.StreamWebhookWithCtx(context.TODO(), AssistantSid, 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) StreamWebhookWithCtx(ctx context.Context, AssistantSid string, params *ListWebhookParams) (chan AutopilotV1Webhook, chan error) { if params == nil { params = &ListWebhookParams{} } @@ -209,19 +240,19 @@ func (c *ApiService) StreamWebhook(AssistantSid string, params *ListWebhookParam recordChannel := make(chan AutopilotV1Webhook, 1) errorChannel := make(chan error, 1) - response, err := c.PageWebhook(AssistantSid, params, "", "") + response, err := c.PageWebhookWithCtx(ctx, AssistantSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamWebhook(response, params, recordChannel, errorChannel) + go c.streamWebhook(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamWebhook(response *ListWebhookResponse, params *ListWebhookParams, recordChannel chan AutopilotV1Webhook, errorChannel chan error) { +func (c *ApiService) streamWebhook(ctx context.Context, response *ListWebhookResponse, params *ListWebhookParams, recordChannel chan AutopilotV1Webhook, errorChannel chan error) { curRecord := 1 for response != nil { @@ -236,7 +267,7 @@ func (c *ApiService) streamWebhook(response *ListWebhookResponse, params *ListWe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListWebhookResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListWebhookResponse) if err != nil { errorChannel <- err break @@ -251,11 +282,11 @@ func (c *ApiService) streamWebhook(response *ListWebhookResponse, params *ListWe close(errorChannel) } -func (c *ApiService) getNextListWebhookResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListWebhookResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -300,6 +331,11 @@ func (params *UpdateWebhookParams) SetWebhookMethod(WebhookMethod string) *Updat // func (c *ApiService) UpdateWebhook(AssistantSid string, Sid string, params *UpdateWebhookParams) (*AutopilotV1Webhook, error) { + return c.UpdateWebhookWithCtx(context.TODO(), AssistantSid, Sid, params) +} + +// +func (c *ApiService) UpdateWebhookWithCtx(ctx context.Context, AssistantSid string, Sid string, params *UpdateWebhookParams) (*AutopilotV1Webhook, error) { path := "/v1/Assistants/{AssistantSid}/Webhooks/{Sid}" path = strings.Replace(path, "{"+"AssistantSid"+"}", AssistantSid, -1) path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -320,7 +356,7 @@ func (c *ApiService) UpdateWebhook(AssistantSid string, Sid string, params *Upda data.Set("WebhookMethod", *params.WebhookMethod) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/bulkexports/v1/api_service.go b/rest/bulkexports/v1/api_service.go index f8054d712..fd006ac58 100644 --- a/rest/bulkexports/v1/api_service.go +++ b/rest/bulkexports/v1/api_service.go @@ -20,10 +20,14 @@ import ( type ApiService struct { baseURL string - requestHandler *twilio.RequestHandler + requestHandler *twilio.RequestHandlerWithCtx } func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { + return NewApiServiceWithCtx(twilio.UpgradeRequestHandler(requestHandler)) +} + +func NewApiServiceWithCtx(requestHandler *twilio.RequestHandlerWithCtx) *ApiService { return &ApiService{ requestHandler: requestHandler, baseURL: "https://bulkexports.twilio.com", @@ -33,3 +37,7 @@ func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { func NewApiServiceWithClient(client twilio.BaseClient) *ApiService { return NewApiService(twilio.NewRequestHandler(client)) } + +func NewApiServiceWithClientWithCtx(client twilio.BaseClientWithCtx) *ApiService { + return NewApiServiceWithCtx(twilio.NewRequestHandlerWithCtx(client)) +} diff --git a/rest/bulkexports/v1/exports.go b/rest/bulkexports/v1/exports.go index 1cbbbe073..d7b87ee45 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,13 +23,18 @@ import ( // Fetch a specific Export. func (c *ApiService) FetchExport(ResourceType string) (*BulkexportsV1Export, error) { + return c.FetchExportWithCtx(context.TODO(), ResourceType) +} + +// Fetch a specific Export. +func (c *ApiService) FetchExportWithCtx(ctx context.Context, ResourceType string) (*BulkexportsV1Export, error) { path := "/v1/Exports/{ResourceType}" path = strings.Replace(path, "{"+"ResourceType"+"}", ResourceType, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(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 6c9468a05..0c20be8f8 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,13 +24,18 @@ import ( // Fetch a specific Export Configuration. func (c *ApiService) FetchExportConfiguration(ResourceType string) (*BulkexportsV1ExportConfiguration, error) { + return c.FetchExportConfigurationWithCtx(context.TODO(), ResourceType) +} + +// Fetch a specific Export Configuration. +func (c *ApiService) FetchExportConfigurationWithCtx(ctx context.Context, ResourceType string) (*BulkexportsV1ExportConfiguration, error) { path := "/v1/Exports/{ResourceType}/Configuration" path = strings.Replace(path, "{"+"ResourceType"+"}", ResourceType, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -69,6 +75,11 @@ func (params *UpdateExportConfigurationParams) SetWebhookMethod(WebhookMethod st // Update a specific Export Configuration. func (c *ApiService) UpdateExportConfiguration(ResourceType string, params *UpdateExportConfigurationParams) (*BulkexportsV1ExportConfiguration, error) { + return c.UpdateExportConfigurationWithCtx(context.TODO(), ResourceType, params) +} + +// Update a specific Export Configuration. +func (c *ApiService) UpdateExportConfigurationWithCtx(ctx context.Context, ResourceType string, params *UpdateExportConfigurationParams) (*BulkexportsV1ExportConfiguration, error) { path := "/v1/Exports/{ResourceType}/Configuration" path = strings.Replace(path, "{"+"ResourceType"+"}", ResourceType, -1) @@ -85,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.Post(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 528c39540..7a46f3c06 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,11 @@ import ( // Fetch a specific Day. func (c *ApiService) FetchDay(ResourceType string, Day string) (*BulkexportsV1DayInstance, error) { + return c.FetchDayWithCtx(context.TODO(), ResourceType, Day) +} + +// Fetch a specific Day. +func (c *ApiService) FetchDayWithCtx(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) @@ -32,7 +38,7 @@ func (c *ApiService) FetchDay(ResourceType string, Day string) (*BulkexportsV1Da data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -66,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.PageDayWithCtx(context.TODO(), ResourceType, params, pageToken, pageNumber) +} + +// Retrieve a single page of Day records from the API. Request is executed immediately. +func (c *ApiService) PageDayWithCtx(ctx context.Context, ResourceType string, params *ListDayParams, pageToken, pageNumber string) (*ListDayResponse, error) { path := "/v1/Exports/{ResourceType}/Days" path = strings.Replace(path, "{"+"ResourceType"+"}", ResourceType, -1) @@ -84,7 +95,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -101,7 +112,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.ListDayWithCtx(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) ListDayWithCtx(ctx context.Context, ResourceType string, params *ListDayParams) ([]BulkexportsV1Day, error) { + response, errors := c.StreamDayWithCtx(ctx, ResourceType, params) records := make([]BulkexportsV1Day, 0) for record := range response { @@ -117,6 +133,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.StreamDayWithCtx(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) StreamDayWithCtx(ctx context.Context, ResourceType string, params *ListDayParams) (chan BulkexportsV1Day, chan error) { if params == nil { params = &ListDayParams{} } @@ -125,19 +146,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.PageDayWithCtx(ctx, ResourceType, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamDay(response, params, recordChannel, errorChannel) + go c.streamDay(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) streamDay(ctx context.Context, response *ListDayResponse, params *ListDayParams, recordChannel chan BulkexportsV1Day, errorChannel chan error) { curRecord := 1 for response != nil { @@ -152,7 +173,7 @@ func (c *ApiService) streamDay(response *ListDayResponse, params *ListDayParams, } } - record, err := client.GetNext(c.baseURL, response, c.getNextListDayResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListDayResponse) if err != nil { errorChannel <- err break @@ -167,11 +188,11 @@ func (c *ApiService) streamDay(response *ListDayResponse, params *ListDayParams, close(errorChannel) } -func (c *ApiService) getNextListDayResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListDayResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 9f940eaf6..b70b483e5 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" @@ -66,6 +67,11 @@ func (params *CreateExportCustomJobParams) SetEmail(Email string) *CreateExportC // func (c *ApiService) CreateExportCustomJob(ResourceType string, params *CreateExportCustomJobParams) (*BulkexportsV1ExportCustomJob, error) { + return c.CreateExportCustomJobWithCtx(context.TODO(), ResourceType, params) +} + +// +func (c *ApiService) CreateExportCustomJobWithCtx(ctx context.Context, ResourceType string, params *CreateExportCustomJobParams) (*BulkexportsV1ExportCustomJob, error) { path := "/v1/Exports/{ResourceType}/Jobs" path = strings.Replace(path, "{"+"ResourceType"+"}", ResourceType, -1) @@ -91,7 +97,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -108,13 +114,18 @@ func (c *ApiService) CreateExportCustomJob(ResourceType string, params *CreateEx // func (c *ApiService) DeleteJob(JobSid string) error { + return c.DeleteJobWithCtx(context.TODO(), JobSid) +} + +// +func (c *ApiService) DeleteJobWithCtx(ctx context.Context, JobSid string) error { path := "/v1/Exports/Jobs/{JobSid}" path = strings.Replace(path, "{"+"JobSid"+"}", JobSid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -126,13 +137,18 @@ func (c *ApiService) DeleteJob(JobSid string) error { // func (c *ApiService) FetchJob(JobSid string) (*BulkexportsV1Job, error) { + return c.FetchJobWithCtx(context.TODO(), JobSid) +} + +// +func (c *ApiService) FetchJobWithCtx(ctx context.Context, JobSid string) (*BulkexportsV1Job, error) { path := "/v1/Exports/Jobs/{JobSid}" path = strings.Replace(path, "{"+"JobSid"+"}", JobSid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -166,6 +182,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.PageExportCustomJobWithCtx(context.TODO(), ResourceType, params, pageToken, pageNumber) +} + +// Retrieve a single page of ExportCustomJob records from the API. Request is executed immediately. +func (c *ApiService) PageExportCustomJobWithCtx(ctx context.Context, ResourceType string, params *ListExportCustomJobParams, pageToken, pageNumber string) (*ListExportCustomJobResponse, error) { path := "/v1/Exports/{ResourceType}/Jobs" path = strings.Replace(path, "{"+"ResourceType"+"}", ResourceType, -1) @@ -184,7 +205,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -201,7 +222,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.ListExportCustomJobWithCtx(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) ListExportCustomJobWithCtx(ctx context.Context, ResourceType string, params *ListExportCustomJobParams) ([]BulkexportsV1ExportCustomJob, error) { + response, errors := c.StreamExportCustomJobWithCtx(ctx, ResourceType, params) records := make([]BulkexportsV1ExportCustomJob, 0) for record := range response { @@ -217,6 +243,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.StreamExportCustomJobWithCtx(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) StreamExportCustomJobWithCtx(ctx context.Context, ResourceType string, params *ListExportCustomJobParams) (chan BulkexportsV1ExportCustomJob, chan error) { if params == nil { params = &ListExportCustomJobParams{} } @@ -225,19 +256,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.PageExportCustomJobWithCtx(ctx, ResourceType, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamExportCustomJob(response, params, recordChannel, errorChannel) + go c.streamExportCustomJob(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) streamExportCustomJob(ctx context.Context, response *ListExportCustomJobResponse, params *ListExportCustomJobParams, recordChannel chan BulkexportsV1ExportCustomJob, errorChannel chan error) { curRecord := 1 for response != nil { @@ -252,7 +283,7 @@ func (c *ApiService) streamExportCustomJob(response *ListExportCustomJobResponse } } - record, err := client.GetNext(c.baseURL, response, c.getNextListExportCustomJobResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListExportCustomJobResponse) if err != nil { errorChannel <- err break @@ -267,11 +298,11 @@ func (c *ApiService) streamExportCustomJob(response *ListExportCustomJobResponse close(errorChannel) } -func (c *ApiService) getNextListExportCustomJobResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListExportCustomJobResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 8ffb94b7a..417eba3de 100644 --- a/rest/chat/v1/api_service.go +++ b/rest/chat/v1/api_service.go @@ -20,10 +20,14 @@ import ( type ApiService struct { baseURL string - requestHandler *twilio.RequestHandler + requestHandler *twilio.RequestHandlerWithCtx } func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { + return NewApiServiceWithCtx(twilio.UpgradeRequestHandler(requestHandler)) +} + +func NewApiServiceWithCtx(requestHandler *twilio.RequestHandlerWithCtx) *ApiService { return &ApiService{ requestHandler: requestHandler, baseURL: "https://chat.twilio.com", @@ -33,3 +37,7 @@ func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { func NewApiServiceWithClient(client twilio.BaseClient) *ApiService { return NewApiService(twilio.NewRequestHandler(client)) } + +func NewApiServiceWithClientWithCtx(client twilio.BaseClientWithCtx) *ApiService { + return NewApiServiceWithCtx(twilio.NewRequestHandlerWithCtx(client)) +} diff --git a/rest/chat/v1/credentials.go b/rest/chat/v1/credentials.go index 7d1ce09c1..8b5949733 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" @@ -72,6 +73,11 @@ func (params *CreateCredentialParams) SetSecret(Secret string) *CreateCredential // func (c *ApiService) CreateCredential(params *CreateCredentialParams) (*ChatV1Credential, error) { + return c.CreateCredentialWithCtx(context.TODO(), params) +} + +// +func (c *ApiService) CreateCredentialWithCtx(ctx context.Context, params *CreateCredentialParams) (*ChatV1Credential, error) { path := "/v1/Credentials" data := url.Values{} @@ -99,7 +105,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -116,13 +122,18 @@ func (c *ApiService) CreateCredential(params *CreateCredentialParams) (*ChatV1Cr // func (c *ApiService) DeleteCredential(Sid string) error { + return c.DeleteCredentialWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) DeleteCredentialWithCtx(ctx context.Context, Sid string) error { path := "/v1/Credentials/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -134,13 +145,18 @@ func (c *ApiService) DeleteCredential(Sid string) error { // func (c *ApiService) FetchCredential(Sid string) (*ChatV1Credential, error) { + return c.FetchCredentialWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) FetchCredentialWithCtx(ctx context.Context, Sid string) (*ChatV1Credential, error) { path := "/v1/Credentials/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -174,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.PageCredentialWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Credential records from the API. Request is executed immediately. +func (c *ApiService) PageCredentialWithCtx(ctx context.Context, params *ListCredentialParams, pageToken, pageNumber string) (*ListCredentialResponse, error) { path := "/v1/Credentials" data := url.Values{} @@ -190,7 +211,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -207,7 +228,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.ListCredentialWithCtx(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) ListCredentialWithCtx(ctx context.Context, params *ListCredentialParams) ([]ChatV1Credential, error) { + response, errors := c.StreamCredentialWithCtx(ctx, params) records := make([]ChatV1Credential, 0) for record := range response { @@ -223,6 +249,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.StreamCredentialWithCtx(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) StreamCredentialWithCtx(ctx context.Context, params *ListCredentialParams) (chan ChatV1Credential, chan error) { if params == nil { params = &ListCredentialParams{} } @@ -231,19 +262,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.PageCredentialWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamCredential(response, params, recordChannel, errorChannel) + go c.streamCredential(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) streamCredential(ctx context.Context, response *ListCredentialResponse, params *ListCredentialParams, recordChannel chan ChatV1Credential, errorChannel chan error) { curRecord := 1 for response != nil { @@ -258,7 +289,7 @@ func (c *ApiService) streamCredential(response *ListCredentialResponse, params * } } - record, err := client.GetNext(c.baseURL, response, c.getNextListCredentialResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListCredentialResponse) if err != nil { errorChannel <- err break @@ -273,11 +304,11 @@ func (c *ApiService) streamCredential(response *ListCredentialResponse, params * close(errorChannel) } -func (c *ApiService) getNextListCredentialResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListCredentialResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -334,6 +365,11 @@ func (params *UpdateCredentialParams) SetSecret(Secret string) *UpdateCredential // func (c *ApiService) UpdateCredential(Sid string, params *UpdateCredentialParams) (*ChatV1Credential, error) { + return c.UpdateCredentialWithCtx(context.TODO(), Sid, params) +} + +// +func (c *ApiService) UpdateCredentialWithCtx(ctx context.Context, Sid string, params *UpdateCredentialParams) (*ChatV1Credential, error) { path := "/v1/Credentials/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -359,7 +395,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.Post(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 d5b8abda9..04c48ec50 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" @@ -36,6 +37,11 @@ func (params *CreateServiceParams) SetFriendlyName(FriendlyName string) *CreateS // func (c *ApiService) CreateService(params *CreateServiceParams) (*ChatV1Service, error) { + return c.CreateServiceWithCtx(context.TODO(), params) +} + +// +func (c *ApiService) CreateServiceWithCtx(ctx context.Context, params *CreateServiceParams) (*ChatV1Service, error) { path := "/v1/Services" data := url.Values{} @@ -45,7 +51,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -62,13 +68,18 @@ func (c *ApiService) CreateService(params *CreateServiceParams) (*ChatV1Service, // func (c *ApiService) DeleteService(Sid string) error { + return c.DeleteServiceWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) DeleteServiceWithCtx(ctx context.Context, Sid string) error { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -80,13 +91,18 @@ func (c *ApiService) DeleteService(Sid string) error { // func (c *ApiService) FetchService(Sid string) (*ChatV1Service, error) { + return c.FetchServiceWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) FetchServiceWithCtx(ctx context.Context, Sid string) (*ChatV1Service, error) { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -120,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.PageServiceWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Service records from the API. Request is executed immediately. +func (c *ApiService) PageServiceWithCtx(ctx context.Context, params *ListServiceParams, pageToken, pageNumber string) (*ListServiceResponse, error) { path := "/v1/Services" data := url.Values{} @@ -136,7 +157,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -153,7 +174,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.ListServiceWithCtx(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) ListServiceWithCtx(ctx context.Context, params *ListServiceParams) ([]ChatV1Service, error) { + response, errors := c.StreamServiceWithCtx(ctx, params) records := make([]ChatV1Service, 0) for record := range response { @@ -169,6 +195,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.StreamServiceWithCtx(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) StreamServiceWithCtx(ctx context.Context, params *ListServiceParams) (chan ChatV1Service, chan error) { if params == nil { params = &ListServiceParams{} } @@ -177,19 +208,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.PageServiceWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamService(response, params, recordChannel, errorChannel) + go c.streamService(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) streamService(ctx context.Context, response *ListServiceResponse, params *ListServiceParams, recordChannel chan ChatV1Service, errorChannel chan error) { curRecord := 1 for response != nil { @@ -204,7 +235,7 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListServiceResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListServiceResponse) if err != nil { errorChannel <- err break @@ -219,11 +250,11 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe close(errorChannel) } -func (c *ApiService) getNextListServiceResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListServiceResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -568,6 +599,11 @@ func (params *UpdateServiceParams) SetLimitsUserChannels(LimitsUserChannels int) // func (c *ApiService) UpdateService(Sid string, params *UpdateServiceParams) (*ChatV1Service, error) { + return c.UpdateServiceWithCtx(context.TODO(), Sid, params) +} + +// +func (c *ApiService) UpdateServiceWithCtx(ctx context.Context, Sid string, params *UpdateServiceParams) (*ChatV1Service, error) { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -739,7 +775,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.Post(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 a4d54b7ea..866670a8f 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" @@ -54,6 +55,11 @@ func (params *CreateChannelParams) SetType(Type string) *CreateChannelParams { // func (c *ApiService) CreateChannel(ServiceSid string, params *CreateChannelParams) (*ChatV1Channel, error) { + return c.CreateChannelWithCtx(context.TODO(), ServiceSid, params) +} + +// +func (c *ApiService) CreateChannelWithCtx(ctx context.Context, ServiceSid string, params *CreateChannelParams) (*ChatV1Channel, error) { path := "/v1/Services/{ServiceSid}/Channels" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -73,7 +79,7 @@ func (c *ApiService) CreateChannel(ServiceSid string, params *CreateChannelParam data.Set("Type", *params.Type) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -90,6 +96,11 @@ func (c *ApiService) CreateChannel(ServiceSid string, params *CreateChannelParam // func (c *ApiService) DeleteChannel(ServiceSid string, Sid string) error { + return c.DeleteChannelWithCtx(context.TODO(), ServiceSid, Sid) +} + +// +func (c *ApiService) DeleteChannelWithCtx(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) @@ -97,7 +108,7 @@ func (c *ApiService) DeleteChannel(ServiceSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -109,6 +120,11 @@ func (c *ApiService) DeleteChannel(ServiceSid string, Sid string) error { // func (c *ApiService) FetchChannel(ServiceSid string, Sid string) (*ChatV1Channel, error) { + return c.FetchChannelWithCtx(context.TODO(), ServiceSid, Sid) +} + +// +func (c *ApiService) FetchChannelWithCtx(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) @@ -116,7 +132,7 @@ func (c *ApiService) FetchChannel(ServiceSid string, Sid string) (*ChatV1Channel data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -156,6 +172,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.PageChannelWithCtx(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Channel records from the API. Request is executed immediately. +func (c *ApiService) PageChannelWithCtx(ctx context.Context, ServiceSid string, params *ListChannelParams, pageToken, pageNumber string) (*ListChannelResponse, error) { path := "/v1/Services/{ServiceSid}/Channels" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -179,7 +200,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -196,7 +217,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.ListChannelWithCtx(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) ListChannelWithCtx(ctx context.Context, ServiceSid string, params *ListChannelParams) ([]ChatV1Channel, error) { + response, errors := c.StreamChannelWithCtx(ctx, ServiceSid, params) records := make([]ChatV1Channel, 0) for record := range response { @@ -212,6 +238,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.StreamChannelWithCtx(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) StreamChannelWithCtx(ctx context.Context, ServiceSid string, params *ListChannelParams) (chan ChatV1Channel, chan error) { if params == nil { params = &ListChannelParams{} } @@ -220,19 +251,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.PageChannelWithCtx(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamChannel(response, params, recordChannel, errorChannel) + go c.streamChannel(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) streamChannel(ctx context.Context, response *ListChannelResponse, params *ListChannelParams, recordChannel chan ChatV1Channel, errorChannel chan error) { curRecord := 1 for response != nil { @@ -247,7 +278,7 @@ func (c *ApiService) streamChannel(response *ListChannelResponse, params *ListCh } } - record, err := client.GetNext(c.baseURL, response, c.getNextListChannelResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListChannelResponse) if err != nil { errorChannel <- err break @@ -262,11 +293,11 @@ func (c *ApiService) streamChannel(response *ListChannelResponse, params *ListCh close(errorChannel) } -func (c *ApiService) getNextListChannelResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListChannelResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -305,6 +336,11 @@ func (params *UpdateChannelParams) SetAttributes(Attributes string) *UpdateChann // func (c *ApiService) UpdateChannel(ServiceSid string, Sid string, params *UpdateChannelParams) (*ChatV1Channel, error) { + return c.UpdateChannelWithCtx(context.TODO(), ServiceSid, Sid, params) +} + +// +func (c *ApiService) UpdateChannelWithCtx(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) @@ -322,7 +358,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.Post(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 9c7293663..6c07402c0 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" @@ -42,6 +43,11 @@ func (params *CreateInviteParams) SetRoleSid(RoleSid string) *CreateInviteParams // func (c *ApiService) CreateInvite(ServiceSid string, ChannelSid string, params *CreateInviteParams) (*ChatV1Invite, error) { + return c.CreateInviteWithCtx(context.TODO(), ServiceSid, ChannelSid, params) +} + +// +func (c *ApiService) CreateInviteWithCtx(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) @@ -56,7 +62,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -73,6 +79,11 @@ func (c *ApiService) CreateInvite(ServiceSid string, ChannelSid string, params * // func (c *ApiService) DeleteInvite(ServiceSid string, ChannelSid string, Sid string) error { + return c.DeleteInviteWithCtx(context.TODO(), ServiceSid, ChannelSid, Sid) +} + +// +func (c *ApiService) DeleteInviteWithCtx(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) @@ -81,7 +92,7 @@ func (c *ApiService) DeleteInvite(ServiceSid string, ChannelSid string, Sid stri data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -93,6 +104,11 @@ func (c *ApiService) DeleteInvite(ServiceSid string, ChannelSid string, Sid stri // func (c *ApiService) FetchInvite(ServiceSid string, ChannelSid string, Sid string) (*ChatV1Invite, error) { + return c.FetchInviteWithCtx(context.TODO(), ServiceSid, ChannelSid, Sid) +} + +// +func (c *ApiService) FetchInviteWithCtx(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) @@ -101,7 +117,7 @@ func (c *ApiService) FetchInvite(ServiceSid string, ChannelSid string, Sid strin data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -141,6 +157,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.PageInviteWithCtx(context.TODO(), ServiceSid, ChannelSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Invite records from the API. Request is executed immediately. +func (c *ApiService) PageInviteWithCtx(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) @@ -165,7 +186,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -182,7 +203,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.ListInviteWithCtx(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) ListInviteWithCtx(ctx context.Context, ServiceSid string, ChannelSid string, params *ListInviteParams) ([]ChatV1Invite, error) { + response, errors := c.StreamInviteWithCtx(ctx, ServiceSid, ChannelSid, params) records := make([]ChatV1Invite, 0) for record := range response { @@ -198,6 +224,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.StreamInviteWithCtx(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) StreamInviteWithCtx(ctx context.Context, ServiceSid string, ChannelSid string, params *ListInviteParams) (chan ChatV1Invite, chan error) { if params == nil { params = &ListInviteParams{} } @@ -206,19 +237,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.PageInviteWithCtx(ctx, ServiceSid, ChannelSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamInvite(response, params, recordChannel, errorChannel) + go c.streamInvite(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) streamInvite(ctx context.Context, response *ListInviteResponse, params *ListInviteParams, recordChannel chan ChatV1Invite, errorChannel chan error) { curRecord := 1 for response != nil { @@ -233,7 +264,7 @@ func (c *ApiService) streamInvite(response *ListInviteResponse, params *ListInvi } } - record, err := client.GetNext(c.baseURL, response, c.getNextListInviteResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListInviteResponse) if err != nil { errorChannel <- err break @@ -248,11 +279,11 @@ func (c *ApiService) streamInvite(response *ListInviteResponse, params *ListInvi close(errorChannel) } -func (c *ApiService) getNextListInviteResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListInviteResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 43c63e650..b7dae8104 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" @@ -42,6 +43,11 @@ func (params *CreateMemberParams) SetRoleSid(RoleSid string) *CreateMemberParams // func (c *ApiService) CreateMember(ServiceSid string, ChannelSid string, params *CreateMemberParams) (*ChatV1Member, error) { + return c.CreateMemberWithCtx(context.TODO(), ServiceSid, ChannelSid, params) +} + +// +func (c *ApiService) CreateMemberWithCtx(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) @@ -56,7 +62,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -73,6 +79,11 @@ func (c *ApiService) CreateMember(ServiceSid string, ChannelSid string, params * // func (c *ApiService) DeleteMember(ServiceSid string, ChannelSid string, Sid string) error { + return c.DeleteMemberWithCtx(context.TODO(), ServiceSid, ChannelSid, Sid) +} + +// +func (c *ApiService) DeleteMemberWithCtx(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) @@ -81,7 +92,7 @@ func (c *ApiService) DeleteMember(ServiceSid string, ChannelSid string, Sid stri data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -93,6 +104,11 @@ func (c *ApiService) DeleteMember(ServiceSid string, ChannelSid string, Sid stri // func (c *ApiService) FetchMember(ServiceSid string, ChannelSid string, Sid string) (*ChatV1Member, error) { + return c.FetchMemberWithCtx(context.TODO(), ServiceSid, ChannelSid, Sid) +} + +// +func (c *ApiService) FetchMemberWithCtx(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) @@ -101,7 +117,7 @@ func (c *ApiService) FetchMember(ServiceSid string, ChannelSid string, Sid strin data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -141,6 +157,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.PageMemberWithCtx(context.TODO(), ServiceSid, ChannelSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Member records from the API. Request is executed immediately. +func (c *ApiService) PageMemberWithCtx(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) @@ -165,7 +186,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -182,7 +203,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.ListMemberWithCtx(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) ListMemberWithCtx(ctx context.Context, ServiceSid string, ChannelSid string, params *ListMemberParams) ([]ChatV1Member, error) { + response, errors := c.StreamMemberWithCtx(ctx, ServiceSid, ChannelSid, params) records := make([]ChatV1Member, 0) for record := range response { @@ -198,6 +224,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.StreamMemberWithCtx(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) StreamMemberWithCtx(ctx context.Context, ServiceSid string, ChannelSid string, params *ListMemberParams) (chan ChatV1Member, chan error) { if params == nil { params = &ListMemberParams{} } @@ -206,19 +237,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.PageMemberWithCtx(ctx, ServiceSid, ChannelSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamMember(response, params, recordChannel, errorChannel) + go c.streamMember(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) streamMember(ctx context.Context, response *ListMemberResponse, params *ListMemberParams, recordChannel chan ChatV1Member, errorChannel chan error) { curRecord := 1 for response != nil { @@ -233,7 +264,7 @@ func (c *ApiService) streamMember(response *ListMemberResponse, params *ListMemb } } - record, err := client.GetNext(c.baseURL, response, c.getNextListMemberResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListMemberResponse) if err != nil { errorChannel <- err break @@ -248,11 +279,11 @@ func (c *ApiService) streamMember(response *ListMemberResponse, params *ListMemb close(errorChannel) } -func (c *ApiService) getNextListMemberResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListMemberResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -285,6 +316,11 @@ func (params *UpdateMemberParams) SetLastConsumedMessageIndex(LastConsumedMessag // func (c *ApiService) UpdateMember(ServiceSid string, ChannelSid string, Sid string, params *UpdateMemberParams) (*ChatV1Member, error) { + return c.UpdateMemberWithCtx(context.TODO(), ServiceSid, ChannelSid, Sid, params) +} + +// +func (c *ApiService) UpdateMemberWithCtx(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) @@ -300,7 +336,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.Post(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 d66d42370..6942ea2b3 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" @@ -48,6 +49,11 @@ func (params *CreateMessageParams) SetAttributes(Attributes string) *CreateMessa // func (c *ApiService) CreateMessage(ServiceSid string, ChannelSid string, params *CreateMessageParams) (*ChatV1Message, error) { + return c.CreateMessageWithCtx(context.TODO(), ServiceSid, ChannelSid, params) +} + +// +func (c *ApiService) CreateMessageWithCtx(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) @@ -65,7 +71,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -82,6 +88,11 @@ func (c *ApiService) CreateMessage(ServiceSid string, ChannelSid string, params // func (c *ApiService) DeleteMessage(ServiceSid string, ChannelSid string, Sid string) error { + return c.DeleteMessageWithCtx(context.TODO(), ServiceSid, ChannelSid, Sid) +} + +// +func (c *ApiService) DeleteMessageWithCtx(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) @@ -90,7 +101,7 @@ func (c *ApiService) DeleteMessage(ServiceSid string, ChannelSid string, Sid str data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -102,6 +113,11 @@ func (c *ApiService) DeleteMessage(ServiceSid string, ChannelSid string, Sid str // func (c *ApiService) FetchMessage(ServiceSid string, ChannelSid string, Sid string) (*ChatV1Message, error) { + return c.FetchMessageWithCtx(context.TODO(), ServiceSid, ChannelSid, Sid) +} + +// +func (c *ApiService) FetchMessageWithCtx(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) @@ -110,7 +126,7 @@ func (c *ApiService) FetchMessage(ServiceSid string, ChannelSid string, Sid stri data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -150,6 +166,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.PageMessageWithCtx(context.TODO(), ServiceSid, ChannelSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Message records from the API. Request is executed immediately. +func (c *ApiService) PageMessageWithCtx(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) @@ -172,7 +193,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -189,7 +210,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.ListMessageWithCtx(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) ListMessageWithCtx(ctx context.Context, ServiceSid string, ChannelSid string, params *ListMessageParams) ([]ChatV1Message, error) { + response, errors := c.StreamMessageWithCtx(ctx, ServiceSid, ChannelSid, params) records := make([]ChatV1Message, 0) for record := range response { @@ -205,6 +231,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.StreamMessageWithCtx(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) StreamMessageWithCtx(ctx context.Context, ServiceSid string, ChannelSid string, params *ListMessageParams) (chan ChatV1Message, chan error) { if params == nil { params = &ListMessageParams{} } @@ -213,19 +244,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.PageMessageWithCtx(ctx, ServiceSid, ChannelSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamMessage(response, params, recordChannel, errorChannel) + go c.streamMessage(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) streamMessage(ctx context.Context, response *ListMessageResponse, params *ListMessageParams, recordChannel chan ChatV1Message, errorChannel chan error) { curRecord := 1 for response != nil { @@ -240,7 +271,7 @@ func (c *ApiService) streamMessage(response *ListMessageResponse, params *ListMe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListMessageResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListMessageResponse) if err != nil { errorChannel <- err break @@ -255,11 +286,11 @@ func (c *ApiService) streamMessage(response *ListMessageResponse, params *ListMe close(errorChannel) } -func (c *ApiService) getNextListMessageResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListMessageResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -292,6 +323,11 @@ func (params *UpdateMessageParams) SetAttributes(Attributes string) *UpdateMessa // func (c *ApiService) UpdateMessage(ServiceSid string, ChannelSid string, Sid string, params *UpdateMessageParams) (*ChatV1Message, error) { + return c.UpdateMessageWithCtx(context.TODO(), ServiceSid, ChannelSid, Sid, params) +} + +// +func (c *ApiService) UpdateMessageWithCtx(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) @@ -307,7 +343,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.Post(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 f7474658b..d90180f40 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" @@ -48,6 +49,11 @@ func (params *CreateRoleParams) SetPermission(Permission []string) *CreateRolePa // func (c *ApiService) CreateRole(ServiceSid string, params *CreateRoleParams) (*ChatV1Role, error) { + return c.CreateRoleWithCtx(context.TODO(), ServiceSid, params) +} + +// +func (c *ApiService) CreateRoleWithCtx(ctx context.Context, ServiceSid string, params *CreateRoleParams) (*ChatV1Role, error) { path := "/v1/Services/{ServiceSid}/Roles" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -66,7 +72,7 @@ func (c *ApiService) CreateRole(ServiceSid string, params *CreateRoleParams) (*C } } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -83,6 +89,11 @@ func (c *ApiService) CreateRole(ServiceSid string, params *CreateRoleParams) (*C // func (c *ApiService) DeleteRole(ServiceSid string, Sid string) error { + return c.DeleteRoleWithCtx(context.TODO(), ServiceSid, Sid) +} + +// +func (c *ApiService) DeleteRoleWithCtx(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) @@ -90,7 +101,7 @@ func (c *ApiService) DeleteRole(ServiceSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -102,6 +113,11 @@ func (c *ApiService) DeleteRole(ServiceSid string, Sid string) error { // func (c *ApiService) FetchRole(ServiceSid string, Sid string) (*ChatV1Role, error) { + return c.FetchRoleWithCtx(context.TODO(), ServiceSid, Sid) +} + +// +func (c *ApiService) FetchRoleWithCtx(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) @@ -109,7 +125,7 @@ func (c *ApiService) FetchRole(ServiceSid string, Sid string) (*ChatV1Role, erro data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -143,6 +159,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.PageRoleWithCtx(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Role records from the API. Request is executed immediately. +func (c *ApiService) PageRoleWithCtx(ctx context.Context, ServiceSid string, params *ListRoleParams, pageToken, pageNumber string) (*ListRoleResponse, error) { path := "/v1/Services/{ServiceSid}/Roles" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -161,7 +182,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -178,7 +199,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.ListRoleWithCtx(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) ListRoleWithCtx(ctx context.Context, ServiceSid string, params *ListRoleParams) ([]ChatV1Role, error) { + response, errors := c.StreamRoleWithCtx(ctx, ServiceSid, params) records := make([]ChatV1Role, 0) for record := range response { @@ -194,6 +220,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.StreamRoleWithCtx(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) StreamRoleWithCtx(ctx context.Context, ServiceSid string, params *ListRoleParams) (chan ChatV1Role, chan error) { if params == nil { params = &ListRoleParams{} } @@ -202,19 +233,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.PageRoleWithCtx(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamRole(response, params, recordChannel, errorChannel) + go c.streamRole(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) streamRole(ctx context.Context, response *ListRoleResponse, params *ListRoleParams, recordChannel chan ChatV1Role, errorChannel chan error) { curRecord := 1 for response != nil { @@ -229,7 +260,7 @@ func (c *ApiService) streamRole(response *ListRoleResponse, params *ListRolePara } } - record, err := client.GetNext(c.baseURL, response, c.getNextListRoleResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListRoleResponse) if err != nil { errorChannel <- err break @@ -244,11 +275,11 @@ func (c *ApiService) streamRole(response *ListRoleResponse, params *ListRolePara close(errorChannel) } -func (c *ApiService) getNextListRoleResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListRoleResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -275,6 +306,11 @@ func (params *UpdateRoleParams) SetPermission(Permission []string) *UpdateRolePa // func (c *ApiService) UpdateRole(ServiceSid string, Sid string, params *UpdateRoleParams) (*ChatV1Role, error) { + return c.UpdateRoleWithCtx(context.TODO(), ServiceSid, Sid, params) +} + +// +func (c *ApiService) UpdateRoleWithCtx(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) @@ -288,7 +324,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.Post(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 7a58491fd..472bdfd1c 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" @@ -54,6 +55,11 @@ func (params *CreateUserParams) SetFriendlyName(FriendlyName string) *CreateUser // func (c *ApiService) CreateUser(ServiceSid string, params *CreateUserParams) (*ChatV1User, error) { + return c.CreateUserWithCtx(context.TODO(), ServiceSid, params) +} + +// +func (c *ApiService) CreateUserWithCtx(ctx context.Context, ServiceSid string, params *CreateUserParams) (*ChatV1User, error) { path := "/v1/Services/{ServiceSid}/Users" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -73,7 +79,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -90,6 +96,11 @@ func (c *ApiService) CreateUser(ServiceSid string, params *CreateUserParams) (*C // func (c *ApiService) DeleteUser(ServiceSid string, Sid string) error { + return c.DeleteUserWithCtx(context.TODO(), ServiceSid, Sid) +} + +// +func (c *ApiService) DeleteUserWithCtx(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) @@ -97,7 +108,7 @@ func (c *ApiService) DeleteUser(ServiceSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -109,6 +120,11 @@ func (c *ApiService) DeleteUser(ServiceSid string, Sid string) error { // func (c *ApiService) FetchUser(ServiceSid string, Sid string) (*ChatV1User, error) { + return c.FetchUserWithCtx(context.TODO(), ServiceSid, Sid) +} + +// +func (c *ApiService) FetchUserWithCtx(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) @@ -116,7 +132,7 @@ func (c *ApiService) FetchUser(ServiceSid string, Sid string) (*ChatV1User, erro data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -150,6 +166,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.PageUserWithCtx(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of User records from the API. Request is executed immediately. +func (c *ApiService) PageUserWithCtx(ctx context.Context, ServiceSid string, params *ListUserParams, pageToken, pageNumber string) (*ListUserResponse, error) { path := "/v1/Services/{ServiceSid}/Users" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -168,7 +189,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -185,7 +206,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.ListUserWithCtx(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) ListUserWithCtx(ctx context.Context, ServiceSid string, params *ListUserParams) ([]ChatV1User, error) { + response, errors := c.StreamUserWithCtx(ctx, ServiceSid, params) records := make([]ChatV1User, 0) for record := range response { @@ -201,6 +227,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.StreamUserWithCtx(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) StreamUserWithCtx(ctx context.Context, ServiceSid string, params *ListUserParams) (chan ChatV1User, chan error) { if params == nil { params = &ListUserParams{} } @@ -209,19 +240,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.PageUserWithCtx(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUser(response, params, recordChannel, errorChannel) + go c.streamUser(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) streamUser(ctx context.Context, response *ListUserResponse, params *ListUserParams, recordChannel chan ChatV1User, errorChannel chan error) { curRecord := 1 for response != nil { @@ -236,7 +267,7 @@ func (c *ApiService) streamUser(response *ListUserResponse, params *ListUserPara } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUserResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListUserResponse) if err != nil { errorChannel <- err break @@ -251,11 +282,11 @@ func (c *ApiService) streamUser(response *ListUserResponse, params *ListUserPara close(errorChannel) } -func (c *ApiService) getNextListUserResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUserResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -294,6 +325,11 @@ func (params *UpdateUserParams) SetFriendlyName(FriendlyName string) *UpdateUser // func (c *ApiService) UpdateUser(ServiceSid string, Sid string, params *UpdateUserParams) (*ChatV1User, error) { + return c.UpdateUserWithCtx(context.TODO(), ServiceSid, Sid, params) +} + +// +func (c *ApiService) UpdateUserWithCtx(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) @@ -311,7 +347,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.Post(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 eb3c21f9a..0ebf658d7 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.PageUserChannelWithCtx(context.TODO(), ServiceSid, UserSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of UserChannel records from the API. Request is executed immediately. +func (c *ApiService) PageUserChannelWithCtx(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) @@ -61,7 +67,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -78,7 +84,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.ListUserChannelWithCtx(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) ListUserChannelWithCtx(ctx context.Context, ServiceSid string, UserSid string, params *ListUserChannelParams) ([]ChatV1UserChannel, error) { + response, errors := c.StreamUserChannelWithCtx(ctx, ServiceSid, UserSid, params) records := make([]ChatV1UserChannel, 0) for record := range response { @@ -94,6 +105,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.StreamUserChannelWithCtx(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) StreamUserChannelWithCtx(ctx context.Context, ServiceSid string, UserSid string, params *ListUserChannelParams) (chan ChatV1UserChannel, chan error) { if params == nil { params = &ListUserChannelParams{} } @@ -102,19 +118,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.PageUserChannelWithCtx(ctx, ServiceSid, UserSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUserChannel(response, params, recordChannel, errorChannel) + go c.streamUserChannel(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) streamUserChannel(ctx context.Context, response *ListUserChannelResponse, params *ListUserChannelParams, recordChannel chan ChatV1UserChannel, errorChannel chan error) { curRecord := 1 for response != nil { @@ -129,7 +145,7 @@ func (c *ApiService) streamUserChannel(response *ListUserChannelResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUserChannelResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListUserChannelResponse) if err != nil { errorChannel <- err break @@ -144,11 +160,11 @@ func (c *ApiService) streamUserChannel(response *ListUserChannelResponse, params close(errorChannel) } -func (c *ApiService) getNextListUserChannelResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUserChannelResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 8ffb94b7a..417eba3de 100644 --- a/rest/chat/v2/api_service.go +++ b/rest/chat/v2/api_service.go @@ -20,10 +20,14 @@ import ( type ApiService struct { baseURL string - requestHandler *twilio.RequestHandler + requestHandler *twilio.RequestHandlerWithCtx } func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { + return NewApiServiceWithCtx(twilio.UpgradeRequestHandler(requestHandler)) +} + +func NewApiServiceWithCtx(requestHandler *twilio.RequestHandlerWithCtx) *ApiService { return &ApiService{ requestHandler: requestHandler, baseURL: "https://chat.twilio.com", @@ -33,3 +37,7 @@ func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { func NewApiServiceWithClient(client twilio.BaseClient) *ApiService { return NewApiService(twilio.NewRequestHandler(client)) } + +func NewApiServiceWithClientWithCtx(client twilio.BaseClientWithCtx) *ApiService { + return NewApiServiceWithCtx(twilio.NewRequestHandlerWithCtx(client)) +} diff --git a/rest/chat/v2/credentials.go b/rest/chat/v2/credentials.go index 376caa738..05ac66db1 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" @@ -72,6 +73,11 @@ func (params *CreateCredentialParams) SetSecret(Secret string) *CreateCredential // func (c *ApiService) CreateCredential(params *CreateCredentialParams) (*ChatV2Credential, error) { + return c.CreateCredentialWithCtx(context.TODO(), params) +} + +// +func (c *ApiService) CreateCredentialWithCtx(ctx context.Context, params *CreateCredentialParams) (*ChatV2Credential, error) { path := "/v2/Credentials" data := url.Values{} @@ -99,7 +105,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -116,13 +122,18 @@ func (c *ApiService) CreateCredential(params *CreateCredentialParams) (*ChatV2Cr // func (c *ApiService) DeleteCredential(Sid string) error { + return c.DeleteCredentialWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) DeleteCredentialWithCtx(ctx context.Context, Sid string) error { path := "/v2/Credentials/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -134,13 +145,18 @@ func (c *ApiService) DeleteCredential(Sid string) error { // func (c *ApiService) FetchCredential(Sid string) (*ChatV2Credential, error) { + return c.FetchCredentialWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) FetchCredentialWithCtx(ctx context.Context, Sid string) (*ChatV2Credential, error) { path := "/v2/Credentials/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -174,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.PageCredentialWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Credential records from the API. Request is executed immediately. +func (c *ApiService) PageCredentialWithCtx(ctx context.Context, params *ListCredentialParams, pageToken, pageNumber string) (*ListCredentialResponse, error) { path := "/v2/Credentials" data := url.Values{} @@ -190,7 +211,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -207,7 +228,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.ListCredentialWithCtx(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) ListCredentialWithCtx(ctx context.Context, params *ListCredentialParams) ([]ChatV2Credential, error) { + response, errors := c.StreamCredentialWithCtx(ctx, params) records := make([]ChatV2Credential, 0) for record := range response { @@ -223,6 +249,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.StreamCredentialWithCtx(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) StreamCredentialWithCtx(ctx context.Context, params *ListCredentialParams) (chan ChatV2Credential, chan error) { if params == nil { params = &ListCredentialParams{} } @@ -231,19 +262,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.PageCredentialWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamCredential(response, params, recordChannel, errorChannel) + go c.streamCredential(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) streamCredential(ctx context.Context, response *ListCredentialResponse, params *ListCredentialParams, recordChannel chan ChatV2Credential, errorChannel chan error) { curRecord := 1 for response != nil { @@ -258,7 +289,7 @@ func (c *ApiService) streamCredential(response *ListCredentialResponse, params * } } - record, err := client.GetNext(c.baseURL, response, c.getNextListCredentialResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListCredentialResponse) if err != nil { errorChannel <- err break @@ -273,11 +304,11 @@ func (c *ApiService) streamCredential(response *ListCredentialResponse, params * close(errorChannel) } -func (c *ApiService) getNextListCredentialResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListCredentialResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -334,6 +365,11 @@ func (params *UpdateCredentialParams) SetSecret(Secret string) *UpdateCredential // func (c *ApiService) UpdateCredential(Sid string, params *UpdateCredentialParams) (*ChatV2Credential, error) { + return c.UpdateCredentialWithCtx(context.TODO(), Sid, params) +} + +// +func (c *ApiService) UpdateCredentialWithCtx(ctx context.Context, Sid string, params *UpdateCredentialParams) (*ChatV2Credential, error) { path := "/v2/Credentials/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -359,7 +395,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.Post(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 8a5a3e2a1..8f8c68fec 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" @@ -36,6 +37,11 @@ func (params *CreateServiceParams) SetFriendlyName(FriendlyName string) *CreateS // func (c *ApiService) CreateService(params *CreateServiceParams) (*ChatV2Service, error) { + return c.CreateServiceWithCtx(context.TODO(), params) +} + +// +func (c *ApiService) CreateServiceWithCtx(ctx context.Context, params *CreateServiceParams) (*ChatV2Service, error) { path := "/v2/Services" data := url.Values{} @@ -45,7 +51,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -62,13 +68,18 @@ func (c *ApiService) CreateService(params *CreateServiceParams) (*ChatV2Service, // func (c *ApiService) DeleteService(Sid string) error { + return c.DeleteServiceWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) DeleteServiceWithCtx(ctx context.Context, Sid string) error { path := "/v2/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -80,13 +91,18 @@ func (c *ApiService) DeleteService(Sid string) error { // func (c *ApiService) FetchService(Sid string) (*ChatV2Service, error) { + return c.FetchServiceWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) FetchServiceWithCtx(ctx context.Context, Sid string) (*ChatV2Service, error) { path := "/v2/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -120,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.PageServiceWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Service records from the API. Request is executed immediately. +func (c *ApiService) PageServiceWithCtx(ctx context.Context, params *ListServiceParams, pageToken, pageNumber string) (*ListServiceResponse, error) { path := "/v2/Services" data := url.Values{} @@ -136,7 +157,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -153,7 +174,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.ListServiceWithCtx(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) ListServiceWithCtx(ctx context.Context, params *ListServiceParams) ([]ChatV2Service, error) { + response, errors := c.StreamServiceWithCtx(ctx, params) records := make([]ChatV2Service, 0) for record := range response { @@ -169,6 +195,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.StreamServiceWithCtx(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) StreamServiceWithCtx(ctx context.Context, params *ListServiceParams) (chan ChatV2Service, chan error) { if params == nil { params = &ListServiceParams{} } @@ -177,19 +208,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.PageServiceWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamService(response, params, recordChannel, errorChannel) + go c.streamService(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) streamService(ctx context.Context, response *ListServiceResponse, params *ListServiceParams, recordChannel chan ChatV2Service, errorChannel chan error) { curRecord := 1 for response != nil { @@ -204,7 +235,7 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListServiceResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListServiceResponse) if err != nil { errorChannel <- err break @@ -219,11 +250,11 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe close(errorChannel) } -func (c *ApiService) getNextListServiceResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListServiceResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -430,6 +461,11 @@ func (params *UpdateServiceParams) SetNotificationsLogEnabled(NotificationsLogEn // func (c *ApiService) UpdateService(Sid string, params *UpdateServiceParams) (*ChatV2Service, error) { + return c.UpdateServiceWithCtx(context.TODO(), Sid, params) +} + +// +func (c *ApiService) UpdateServiceWithCtx(ctx context.Context, Sid string, params *UpdateServiceParams) (*ChatV2Service, error) { path := "/v2/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -532,7 +568,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.Post(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 74d6d4a21..c7606639c 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" @@ -25,6 +26,11 @@ import ( // func (c *ApiService) DeleteBinding(ServiceSid string, Sid string) error { + return c.DeleteBindingWithCtx(context.TODO(), ServiceSid, Sid) +} + +// +func (c *ApiService) DeleteBindingWithCtx(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) @@ -32,7 +38,7 @@ func (c *ApiService) DeleteBinding(ServiceSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -44,6 +50,11 @@ func (c *ApiService) DeleteBinding(ServiceSid string, Sid string) error { // func (c *ApiService) FetchBinding(ServiceSid string, Sid string) (*ChatV2Binding, error) { + return c.FetchBindingWithCtx(context.TODO(), ServiceSid, Sid) +} + +// +func (c *ApiService) FetchBindingWithCtx(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) @@ -51,7 +62,7 @@ func (c *ApiService) FetchBinding(ServiceSid string, Sid string) (*ChatV2Binding data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -97,6 +108,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.PageBindingWithCtx(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Binding records from the API. Request is executed immediately. +func (c *ApiService) PageBindingWithCtx(ctx context.Context, ServiceSid string, params *ListBindingParams, pageToken, pageNumber string) (*ListBindingResponse, error) { path := "/v2/Services/{ServiceSid}/Bindings" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -125,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -142,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.ListBindingWithCtx(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) ListBindingWithCtx(ctx context.Context, ServiceSid string, params *ListBindingParams) ([]ChatV2Binding, error) { + response, errors := c.StreamBindingWithCtx(ctx, ServiceSid, params) records := make([]ChatV2Binding, 0) for record := range response { @@ -158,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.StreamBindingWithCtx(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) StreamBindingWithCtx(ctx context.Context, ServiceSid string, params *ListBindingParams) (chan ChatV2Binding, chan error) { if params == nil { params = &ListBindingParams{} } @@ -166,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.PageBindingWithCtx(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamBinding(response, params, recordChannel, errorChannel) + go c.streamBinding(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) streamBinding(ctx context.Context, response *ListBindingResponse, params *ListBindingParams, recordChannel chan ChatV2Binding, errorChannel chan error) { curRecord := 1 for response != nil { @@ -193,7 +219,7 @@ func (c *ApiService) streamBinding(response *ListBindingResponse, params *ListBi } } - record, err := client.GetNext(c.baseURL, response, c.getNextListBindingResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListBindingResponse) if err != nil { errorChannel <- err break @@ -208,11 +234,11 @@ func (c *ApiService) streamBinding(response *ListBindingResponse, params *ListBi close(errorChannel) } -func (c *ApiService) getNextListBindingResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListBindingResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 56b59eb66..977f81297 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" @@ -79,6 +80,11 @@ func (params *CreateChannelParams) SetCreatedBy(CreatedBy string) *CreateChannel // func (c *ApiService) CreateChannel(ServiceSid string, params *CreateChannelParams) (*ChatV2Channel, error) { + return c.CreateChannelWithCtx(context.TODO(), ServiceSid, params) +} + +// +func (c *ApiService) CreateChannelWithCtx(ctx context.Context, ServiceSid string, params *CreateChannelParams) (*ChatV2Channel, error) { path := "/v2/Services/{ServiceSid}/Channels" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -111,7 +117,7 @@ func (c *ApiService) CreateChannel(ServiceSid string, params *CreateChannelParam headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -139,6 +145,11 @@ func (params *DeleteChannelParams) SetXTwilioWebhookEnabled(XTwilioWebhookEnable // func (c *ApiService) DeleteChannel(ServiceSid string, Sid string, params *DeleteChannelParams) error { + return c.DeleteChannelWithCtx(context.TODO(), ServiceSid, Sid, params) +} + +// +func (c *ApiService) DeleteChannelWithCtx(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) @@ -150,7 +161,7 @@ func (c *ApiService) DeleteChannel(ServiceSid string, Sid string, params *Delete headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -162,6 +173,11 @@ func (c *ApiService) DeleteChannel(ServiceSid string, Sid string, params *Delete // func (c *ApiService) FetchChannel(ServiceSid string, Sid string) (*ChatV2Channel, error) { + return c.FetchChannelWithCtx(context.TODO(), ServiceSid, Sid) +} + +// +func (c *ApiService) FetchChannelWithCtx(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) @@ -169,7 +185,7 @@ func (c *ApiService) FetchChannel(ServiceSid string, Sid string) (*ChatV2Channel data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -209,6 +225,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.PageChannelWithCtx(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Channel records from the API. Request is executed immediately. +func (c *ApiService) PageChannelWithCtx(ctx context.Context, ServiceSid string, params *ListChannelParams, pageToken, pageNumber string) (*ListChannelResponse, error) { path := "/v2/Services/{ServiceSid}/Channels" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -232,7 +253,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -249,7 +270,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.ListChannelWithCtx(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) ListChannelWithCtx(ctx context.Context, ServiceSid string, params *ListChannelParams) ([]ChatV2Channel, error) { + response, errors := c.StreamChannelWithCtx(ctx, ServiceSid, params) records := make([]ChatV2Channel, 0) for record := range response { @@ -265,6 +291,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.StreamChannelWithCtx(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) StreamChannelWithCtx(ctx context.Context, ServiceSid string, params *ListChannelParams) (chan ChatV2Channel, chan error) { if params == nil { params = &ListChannelParams{} } @@ -273,19 +304,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.PageChannelWithCtx(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamChannel(response, params, recordChannel, errorChannel) + go c.streamChannel(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) streamChannel(ctx context.Context, response *ListChannelResponse, params *ListChannelParams, recordChannel chan ChatV2Channel, errorChannel chan error) { curRecord := 1 for response != nil { @@ -300,7 +331,7 @@ func (c *ApiService) streamChannel(response *ListChannelResponse, params *ListCh } } - record, err := client.GetNext(c.baseURL, response, c.getNextListChannelResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListChannelResponse) if err != nil { errorChannel <- err break @@ -315,11 +346,11 @@ func (c *ApiService) streamChannel(response *ListChannelResponse, params *ListCh close(errorChannel) } -func (c *ApiService) getNextListChannelResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListChannelResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -382,6 +413,11 @@ func (params *UpdateChannelParams) SetCreatedBy(CreatedBy string) *UpdateChannel // func (c *ApiService) UpdateChannel(ServiceSid string, Sid string, params *UpdateChannelParams) (*ChatV2Channel, error) { + return c.UpdateChannelWithCtx(context.TODO(), ServiceSid, Sid, params) +} + +// +func (c *ApiService) UpdateChannelWithCtx(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) @@ -412,7 +448,7 @@ func (c *ApiService) UpdateChannel(ServiceSid string, Sid string, params *Update headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 0b02c00d2..180dc2927 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" @@ -42,6 +43,11 @@ func (params *CreateInviteParams) SetRoleSid(RoleSid string) *CreateInviteParams // func (c *ApiService) CreateInvite(ServiceSid string, ChannelSid string, params *CreateInviteParams) (*ChatV2Invite, error) { + return c.CreateInviteWithCtx(context.TODO(), ServiceSid, ChannelSid, params) +} + +// +func (c *ApiService) CreateInviteWithCtx(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) @@ -56,7 +62,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -73,6 +79,11 @@ func (c *ApiService) CreateInvite(ServiceSid string, ChannelSid string, params * // func (c *ApiService) DeleteInvite(ServiceSid string, ChannelSid string, Sid string) error { + return c.DeleteInviteWithCtx(context.TODO(), ServiceSid, ChannelSid, Sid) +} + +// +func (c *ApiService) DeleteInviteWithCtx(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) @@ -81,7 +92,7 @@ func (c *ApiService) DeleteInvite(ServiceSid string, ChannelSid string, Sid stri data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -93,6 +104,11 @@ func (c *ApiService) DeleteInvite(ServiceSid string, ChannelSid string, Sid stri // func (c *ApiService) FetchInvite(ServiceSid string, ChannelSid string, Sid string) (*ChatV2Invite, error) { + return c.FetchInviteWithCtx(context.TODO(), ServiceSid, ChannelSid, Sid) +} + +// +func (c *ApiService) FetchInviteWithCtx(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) @@ -101,7 +117,7 @@ func (c *ApiService) FetchInvite(ServiceSid string, ChannelSid string, Sid strin data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -141,6 +157,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.PageInviteWithCtx(context.TODO(), ServiceSid, ChannelSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Invite records from the API. Request is executed immediately. +func (c *ApiService) PageInviteWithCtx(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) @@ -165,7 +186,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -182,7 +203,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.ListInviteWithCtx(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) ListInviteWithCtx(ctx context.Context, ServiceSid string, ChannelSid string, params *ListInviteParams) ([]ChatV2Invite, error) { + response, errors := c.StreamInviteWithCtx(ctx, ServiceSid, ChannelSid, params) records := make([]ChatV2Invite, 0) for record := range response { @@ -198,6 +224,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.StreamInviteWithCtx(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) StreamInviteWithCtx(ctx context.Context, ServiceSid string, ChannelSid string, params *ListInviteParams) (chan ChatV2Invite, chan error) { if params == nil { params = &ListInviteParams{} } @@ -206,19 +237,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.PageInviteWithCtx(ctx, ServiceSid, ChannelSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamInvite(response, params, recordChannel, errorChannel) + go c.streamInvite(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) streamInvite(ctx context.Context, response *ListInviteResponse, params *ListInviteParams, recordChannel chan ChatV2Invite, errorChannel chan error) { curRecord := 1 for response != nil { @@ -233,7 +264,7 @@ func (c *ApiService) streamInvite(response *ListInviteResponse, params *ListInvi } } - record, err := client.GetNext(c.baseURL, response, c.getNextListInviteResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListInviteResponse) if err != nil { errorChannel <- err break @@ -248,11 +279,11 @@ func (c *ApiService) streamInvite(response *ListInviteResponse, params *ListInvi close(errorChannel) } -func (c *ApiService) getNextListInviteResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListInviteResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 c0cefe5e9..39dd6abb0 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" @@ -79,6 +80,11 @@ func (params *CreateMemberParams) SetAttributes(Attributes string) *CreateMember // func (c *ApiService) CreateMember(ServiceSid string, ChannelSid string, params *CreateMemberParams) (*ChatV2Member, error) { + return c.CreateMemberWithCtx(context.TODO(), ServiceSid, ChannelSid, params) +} + +// +func (c *ApiService) CreateMemberWithCtx(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) @@ -112,7 +118,7 @@ func (c *ApiService) CreateMember(ServiceSid string, ChannelSid string, params * headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -140,6 +146,11 @@ func (params *DeleteMemberParams) SetXTwilioWebhookEnabled(XTwilioWebhookEnabled // func (c *ApiService) DeleteMember(ServiceSid string, ChannelSid string, Sid string, params *DeleteMemberParams) error { + return c.DeleteMemberWithCtx(context.TODO(), ServiceSid, ChannelSid, Sid, params) +} + +// +func (c *ApiService) DeleteMemberWithCtx(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) @@ -152,7 +163,7 @@ func (c *ApiService) DeleteMember(ServiceSid string, ChannelSid string, Sid stri headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -164,6 +175,11 @@ func (c *ApiService) DeleteMember(ServiceSid string, ChannelSid string, Sid stri // func (c *ApiService) FetchMember(ServiceSid string, ChannelSid string, Sid string) (*ChatV2Member, error) { + return c.FetchMemberWithCtx(context.TODO(), ServiceSid, ChannelSid, Sid) +} + +// +func (c *ApiService) FetchMemberWithCtx(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) @@ -172,7 +188,7 @@ func (c *ApiService) FetchMember(ServiceSid string, ChannelSid string, Sid strin data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -212,6 +228,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.PageMemberWithCtx(context.TODO(), ServiceSid, ChannelSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Member records from the API. Request is executed immediately. +func (c *ApiService) PageMemberWithCtx(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) @@ -236,7 +257,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -253,7 +274,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.ListMemberWithCtx(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) ListMemberWithCtx(ctx context.Context, ServiceSid string, ChannelSid string, params *ListMemberParams) ([]ChatV2Member, error) { + response, errors := c.StreamMemberWithCtx(ctx, ServiceSid, ChannelSid, params) records := make([]ChatV2Member, 0) for record := range response { @@ -269,6 +295,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.StreamMemberWithCtx(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) StreamMemberWithCtx(ctx context.Context, ServiceSid string, ChannelSid string, params *ListMemberParams) (chan ChatV2Member, chan error) { if params == nil { params = &ListMemberParams{} } @@ -277,19 +308,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.PageMemberWithCtx(ctx, ServiceSid, ChannelSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamMember(response, params, recordChannel, errorChannel) + go c.streamMember(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) streamMember(ctx context.Context, response *ListMemberResponse, params *ListMemberParams, recordChannel chan ChatV2Member, errorChannel chan error) { curRecord := 1 for response != nil { @@ -304,7 +335,7 @@ func (c *ApiService) streamMember(response *ListMemberResponse, params *ListMemb } } - record, err := client.GetNext(c.baseURL, response, c.getNextListMemberResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListMemberResponse) if err != nil { errorChannel <- err break @@ -319,11 +350,11 @@ func (c *ApiService) streamMember(response *ListMemberResponse, params *ListMemb close(errorChannel) } -func (c *ApiService) getNextListMemberResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListMemberResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -386,6 +417,11 @@ func (params *UpdateMemberParams) SetAttributes(Attributes string) *UpdateMember // func (c *ApiService) UpdateMember(ServiceSid string, ChannelSid string, Sid string, params *UpdateMemberParams) (*ChatV2Member, error) { + return c.UpdateMemberWithCtx(context.TODO(), ServiceSid, ChannelSid, Sid, params) +} + +// +func (c *ApiService) UpdateMemberWithCtx(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) @@ -417,7 +453,7 @@ func (c *ApiService) UpdateMember(ServiceSid string, ChannelSid string, Sid stri headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 ca4ddb383..de2472a0e 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" @@ -79,6 +80,11 @@ func (params *CreateMessageParams) SetMediaSid(MediaSid string) *CreateMessagePa // func (c *ApiService) CreateMessage(ServiceSid string, ChannelSid string, params *CreateMessageParams) (*ChatV2Message, error) { + return c.CreateMessageWithCtx(context.TODO(), ServiceSid, ChannelSid, params) +} + +// +func (c *ApiService) CreateMessageWithCtx(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) @@ -112,7 +118,7 @@ func (c *ApiService) CreateMessage(ServiceSid string, ChannelSid string, params headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -140,6 +146,11 @@ func (params *DeleteMessageParams) SetXTwilioWebhookEnabled(XTwilioWebhookEnable // func (c *ApiService) DeleteMessage(ServiceSid string, ChannelSid string, Sid string, params *DeleteMessageParams) error { + return c.DeleteMessageWithCtx(context.TODO(), ServiceSid, ChannelSid, Sid, params) +} + +// +func (c *ApiService) DeleteMessageWithCtx(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) @@ -152,7 +163,7 @@ func (c *ApiService) DeleteMessage(ServiceSid string, ChannelSid string, Sid str headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -164,6 +175,11 @@ func (c *ApiService) DeleteMessage(ServiceSid string, ChannelSid string, Sid str // func (c *ApiService) FetchMessage(ServiceSid string, ChannelSid string, Sid string) (*ChatV2Message, error) { + return c.FetchMessageWithCtx(context.TODO(), ServiceSid, ChannelSid, Sid) +} + +// +func (c *ApiService) FetchMessageWithCtx(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) @@ -172,7 +188,7 @@ func (c *ApiService) FetchMessage(ServiceSid string, ChannelSid string, Sid stri data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -212,6 +228,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.PageMessageWithCtx(context.TODO(), ServiceSid, ChannelSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Message records from the API. Request is executed immediately. +func (c *ApiService) PageMessageWithCtx(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) @@ -234,7 +255,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -251,7 +272,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.ListMessageWithCtx(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) ListMessageWithCtx(ctx context.Context, ServiceSid string, ChannelSid string, params *ListMessageParams) ([]ChatV2Message, error) { + response, errors := c.StreamMessageWithCtx(ctx, ServiceSid, ChannelSid, params) records := make([]ChatV2Message, 0) for record := range response { @@ -267,6 +293,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.StreamMessageWithCtx(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) StreamMessageWithCtx(ctx context.Context, ServiceSid string, ChannelSid string, params *ListMessageParams) (chan ChatV2Message, chan error) { if params == nil { params = &ListMessageParams{} } @@ -275,19 +306,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.PageMessageWithCtx(ctx, ServiceSid, ChannelSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamMessage(response, params, recordChannel, errorChannel) + go c.streamMessage(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) streamMessage(ctx context.Context, response *ListMessageResponse, params *ListMessageParams, recordChannel chan ChatV2Message, errorChannel chan error) { curRecord := 1 for response != nil { @@ -302,7 +333,7 @@ func (c *ApiService) streamMessage(response *ListMessageResponse, params *ListMe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListMessageResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListMessageResponse) if err != nil { errorChannel <- err break @@ -317,11 +348,11 @@ func (c *ApiService) streamMessage(response *ListMessageResponse, params *ListMe close(errorChannel) } -func (c *ApiService) getNextListMessageResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListMessageResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -384,6 +415,11 @@ func (params *UpdateMessageParams) SetFrom(From string) *UpdateMessageParams { // func (c *ApiService) UpdateMessage(ServiceSid string, ChannelSid string, Sid string, params *UpdateMessageParams) (*ChatV2Message, error) { + return c.UpdateMessageWithCtx(context.TODO(), ServiceSid, ChannelSid, Sid, params) +} + +// +func (c *ApiService) UpdateMessageWithCtx(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) @@ -415,7 +451,7 @@ func (c *ApiService) UpdateMessage(ServiceSid string, ChannelSid string, Sid str headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 6db76bd24..959fc6822 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" @@ -72,6 +73,11 @@ func (params *CreateChannelWebhookParams) SetConfigurationRetryCount(Configurati // func (c *ApiService) CreateChannelWebhook(ServiceSid string, ChannelSid string, params *CreateChannelWebhookParams) (*ChatV2ChannelWebhook, error) { + return c.CreateChannelWebhookWithCtx(context.TODO(), ServiceSid, ChannelSid, params) +} + +// +func (c *ApiService) CreateChannelWebhookWithCtx(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) @@ -105,7 +111,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -122,6 +128,11 @@ func (c *ApiService) CreateChannelWebhook(ServiceSid string, ChannelSid string, // func (c *ApiService) DeleteChannelWebhook(ServiceSid string, ChannelSid string, Sid string) error { + return c.DeleteChannelWebhookWithCtx(context.TODO(), ServiceSid, ChannelSid, Sid) +} + +// +func (c *ApiService) DeleteChannelWebhookWithCtx(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) @@ -130,7 +141,7 @@ func (c *ApiService) DeleteChannelWebhook(ServiceSid string, ChannelSid string, data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -142,6 +153,11 @@ func (c *ApiService) DeleteChannelWebhook(ServiceSid string, ChannelSid string, // func (c *ApiService) FetchChannelWebhook(ServiceSid string, ChannelSid string, Sid string) (*ChatV2ChannelWebhook, error) { + return c.FetchChannelWebhookWithCtx(context.TODO(), ServiceSid, ChannelSid, Sid) +} + +// +func (c *ApiService) FetchChannelWebhookWithCtx(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) @@ -150,7 +166,7 @@ func (c *ApiService) FetchChannelWebhook(ServiceSid string, ChannelSid string, S data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -184,6 +200,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.PageChannelWebhookWithCtx(context.TODO(), ServiceSid, ChannelSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ChannelWebhook records from the API. Request is executed immediately. +func (c *ApiService) PageChannelWebhookWithCtx(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) @@ -203,7 +224,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -220,7 +241,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.ListChannelWebhookWithCtx(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) ListChannelWebhookWithCtx(ctx context.Context, ServiceSid string, ChannelSid string, params *ListChannelWebhookParams) ([]ChatV2ChannelWebhook, error) { + response, errors := c.StreamChannelWebhookWithCtx(ctx, ServiceSid, ChannelSid, params) records := make([]ChatV2ChannelWebhook, 0) for record := range response { @@ -236,6 +262,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.StreamChannelWebhookWithCtx(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) StreamChannelWebhookWithCtx(ctx context.Context, ServiceSid string, ChannelSid string, params *ListChannelWebhookParams) (chan ChatV2ChannelWebhook, chan error) { if params == nil { params = &ListChannelWebhookParams{} } @@ -244,19 +275,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.PageChannelWebhookWithCtx(ctx, ServiceSid, ChannelSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamChannelWebhook(response, params, recordChannel, errorChannel) + go c.streamChannelWebhook(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) streamChannelWebhook(ctx context.Context, response *ListChannelWebhookResponse, params *ListChannelWebhookParams, recordChannel chan ChatV2ChannelWebhook, errorChannel chan error) { curRecord := 1 for response != nil { @@ -271,7 +302,7 @@ func (c *ApiService) streamChannelWebhook(response *ListChannelWebhookResponse, } } - record, err := client.GetNext(c.baseURL, response, c.getNextListChannelWebhookResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListChannelWebhookResponse) if err != nil { errorChannel <- err break @@ -286,11 +317,11 @@ func (c *ApiService) streamChannelWebhook(response *ListChannelWebhookResponse, close(errorChannel) } -func (c *ApiService) getNextListChannelWebhookResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListChannelWebhookResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -347,6 +378,11 @@ func (params *UpdateChannelWebhookParams) SetConfigurationRetryCount(Configurati // func (c *ApiService) UpdateChannelWebhook(ServiceSid string, ChannelSid string, Sid string, params *UpdateChannelWebhookParams) (*ChatV2ChannelWebhook, error) { + return c.UpdateChannelWebhookWithCtx(context.TODO(), ServiceSid, ChannelSid, Sid, params) +} + +// +func (c *ApiService) UpdateChannelWebhookWithCtx(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) @@ -378,7 +414,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.Post(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 36ea514eb..7db39101d 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" @@ -48,6 +49,11 @@ func (params *CreateRoleParams) SetPermission(Permission []string) *CreateRolePa // func (c *ApiService) CreateRole(ServiceSid string, params *CreateRoleParams) (*ChatV2Role, error) { + return c.CreateRoleWithCtx(context.TODO(), ServiceSid, params) +} + +// +func (c *ApiService) CreateRoleWithCtx(ctx context.Context, ServiceSid string, params *CreateRoleParams) (*ChatV2Role, error) { path := "/v2/Services/{ServiceSid}/Roles" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -66,7 +72,7 @@ func (c *ApiService) CreateRole(ServiceSid string, params *CreateRoleParams) (*C } } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -83,6 +89,11 @@ func (c *ApiService) CreateRole(ServiceSid string, params *CreateRoleParams) (*C // func (c *ApiService) DeleteRole(ServiceSid string, Sid string) error { + return c.DeleteRoleWithCtx(context.TODO(), ServiceSid, Sid) +} + +// +func (c *ApiService) DeleteRoleWithCtx(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) @@ -90,7 +101,7 @@ func (c *ApiService) DeleteRole(ServiceSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -102,6 +113,11 @@ func (c *ApiService) DeleteRole(ServiceSid string, Sid string) error { // func (c *ApiService) FetchRole(ServiceSid string, Sid string) (*ChatV2Role, error) { + return c.FetchRoleWithCtx(context.TODO(), ServiceSid, Sid) +} + +// +func (c *ApiService) FetchRoleWithCtx(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) @@ -109,7 +125,7 @@ func (c *ApiService) FetchRole(ServiceSid string, Sid string) (*ChatV2Role, erro data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -143,6 +159,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.PageRoleWithCtx(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Role records from the API. Request is executed immediately. +func (c *ApiService) PageRoleWithCtx(ctx context.Context, ServiceSid string, params *ListRoleParams, pageToken, pageNumber string) (*ListRoleResponse, error) { path := "/v2/Services/{ServiceSid}/Roles" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -161,7 +182,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -178,7 +199,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.ListRoleWithCtx(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) ListRoleWithCtx(ctx context.Context, ServiceSid string, params *ListRoleParams) ([]ChatV2Role, error) { + response, errors := c.StreamRoleWithCtx(ctx, ServiceSid, params) records := make([]ChatV2Role, 0) for record := range response { @@ -194,6 +220,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.StreamRoleWithCtx(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) StreamRoleWithCtx(ctx context.Context, ServiceSid string, params *ListRoleParams) (chan ChatV2Role, chan error) { if params == nil { params = &ListRoleParams{} } @@ -202,19 +233,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.PageRoleWithCtx(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamRole(response, params, recordChannel, errorChannel) + go c.streamRole(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) streamRole(ctx context.Context, response *ListRoleResponse, params *ListRoleParams, recordChannel chan ChatV2Role, errorChannel chan error) { curRecord := 1 for response != nil { @@ -229,7 +260,7 @@ func (c *ApiService) streamRole(response *ListRoleResponse, params *ListRolePara } } - record, err := client.GetNext(c.baseURL, response, c.getNextListRoleResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListRoleResponse) if err != nil { errorChannel <- err break @@ -244,11 +275,11 @@ func (c *ApiService) streamRole(response *ListRoleResponse, params *ListRolePara close(errorChannel) } -func (c *ApiService) getNextListRoleResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListRoleResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -275,6 +306,11 @@ func (params *UpdateRoleParams) SetPermission(Permission []string) *UpdateRolePa // func (c *ApiService) UpdateRole(ServiceSid string, Sid string, params *UpdateRoleParams) (*ChatV2Role, error) { + return c.UpdateRoleWithCtx(context.TODO(), ServiceSid, Sid, params) +} + +// +func (c *ApiService) UpdateRoleWithCtx(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) @@ -288,7 +324,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.Post(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 a7e8298bf..dadeed1b4 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" @@ -60,6 +61,11 @@ func (params *CreateUserParams) SetFriendlyName(FriendlyName string) *CreateUser // func (c *ApiService) CreateUser(ServiceSid string, params *CreateUserParams) (*ChatV2User, error) { + return c.CreateUserWithCtx(context.TODO(), ServiceSid, params) +} + +// +func (c *ApiService) CreateUserWithCtx(ctx context.Context, ServiceSid string, params *CreateUserParams) (*ChatV2User, error) { path := "/v2/Services/{ServiceSid}/Users" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -83,7 +89,7 @@ func (c *ApiService) CreateUser(ServiceSid string, params *CreateUserParams) (*C headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -100,6 +106,11 @@ func (c *ApiService) CreateUser(ServiceSid string, params *CreateUserParams) (*C // func (c *ApiService) DeleteUser(ServiceSid string, Sid string) error { + return c.DeleteUserWithCtx(context.TODO(), ServiceSid, Sid) +} + +// +func (c *ApiService) DeleteUserWithCtx(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) @@ -107,7 +118,7 @@ func (c *ApiService) DeleteUser(ServiceSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -119,6 +130,11 @@ func (c *ApiService) DeleteUser(ServiceSid string, Sid string) error { // func (c *ApiService) FetchUser(ServiceSid string, Sid string) (*ChatV2User, error) { + return c.FetchUserWithCtx(context.TODO(), ServiceSid, Sid) +} + +// +func (c *ApiService) FetchUserWithCtx(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) @@ -126,7 +142,7 @@ func (c *ApiService) FetchUser(ServiceSid string, Sid string) (*ChatV2User, erro data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -160,6 +176,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.PageUserWithCtx(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of User records from the API. Request is executed immediately. +func (c *ApiService) PageUserWithCtx(ctx context.Context, ServiceSid string, params *ListUserParams, pageToken, pageNumber string) (*ListUserResponse, error) { path := "/v2/Services/{ServiceSid}/Users" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -178,7 +199,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -195,7 +216,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.ListUserWithCtx(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) ListUserWithCtx(ctx context.Context, ServiceSid string, params *ListUserParams) ([]ChatV2User, error) { + response, errors := c.StreamUserWithCtx(ctx, ServiceSid, params) records := make([]ChatV2User, 0) for record := range response { @@ -211,6 +237,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.StreamUserWithCtx(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) StreamUserWithCtx(ctx context.Context, ServiceSid string, params *ListUserParams) (chan ChatV2User, chan error) { if params == nil { params = &ListUserParams{} } @@ -219,19 +250,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.PageUserWithCtx(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUser(response, params, recordChannel, errorChannel) + go c.streamUser(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) streamUser(ctx context.Context, response *ListUserResponse, params *ListUserParams, recordChannel chan ChatV2User, errorChannel chan error) { curRecord := 1 for response != nil { @@ -246,7 +277,7 @@ func (c *ApiService) streamUser(response *ListUserResponse, params *ListUserPara } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUserResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListUserResponse) if err != nil { errorChannel <- err break @@ -261,11 +292,11 @@ func (c *ApiService) streamUser(response *ListUserResponse, params *ListUserPara close(errorChannel) } -func (c *ApiService) getNextListUserResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUserResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -310,6 +341,11 @@ func (params *UpdateUserParams) SetFriendlyName(FriendlyName string) *UpdateUser // func (c *ApiService) UpdateUser(ServiceSid string, Sid string, params *UpdateUserParams) (*ChatV2User, error) { + return c.UpdateUserWithCtx(context.TODO(), ServiceSid, Sid, params) +} + +// +func (c *ApiService) UpdateUserWithCtx(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) @@ -331,7 +367,7 @@ func (c *ApiService) UpdateUser(ServiceSid string, Sid string, params *UpdateUse headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 eec6334c4..1041f2ca2 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" @@ -25,6 +26,11 @@ import ( // func (c *ApiService) DeleteUserBinding(ServiceSid string, UserSid string, Sid string) error { + return c.DeleteUserBindingWithCtx(context.TODO(), ServiceSid, UserSid, Sid) +} + +// +func (c *ApiService) DeleteUserBindingWithCtx(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) @@ -33,7 +39,7 @@ func (c *ApiService) DeleteUserBinding(ServiceSid string, UserSid string, Sid st data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -45,6 +51,11 @@ func (c *ApiService) DeleteUserBinding(ServiceSid string, UserSid string, Sid st // func (c *ApiService) FetchUserBinding(ServiceSid string, UserSid string, Sid string) (*ChatV2UserBinding, error) { + return c.FetchUserBindingWithCtx(context.TODO(), ServiceSid, UserSid, Sid) +} + +// +func (c *ApiService) FetchUserBindingWithCtx(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) @@ -53,7 +64,7 @@ func (c *ApiService) FetchUserBinding(ServiceSid string, UserSid string, Sid str data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -93,6 +104,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.PageUserBindingWithCtx(context.TODO(), ServiceSid, UserSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of UserBinding records from the API. Request is executed immediately. +func (c *ApiService) PageUserBindingWithCtx(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) @@ -117,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -134,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.ListUserBindingWithCtx(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) ListUserBindingWithCtx(ctx context.Context, ServiceSid string, UserSid string, params *ListUserBindingParams) ([]ChatV2UserBinding, error) { + response, errors := c.StreamUserBindingWithCtx(ctx, ServiceSid, UserSid, params) records := make([]ChatV2UserBinding, 0) for record := range response { @@ -150,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.StreamUserBindingWithCtx(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) StreamUserBindingWithCtx(ctx context.Context, ServiceSid string, UserSid string, params *ListUserBindingParams) (chan ChatV2UserBinding, chan error) { if params == nil { params = &ListUserBindingParams{} } @@ -158,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.PageUserBindingWithCtx(ctx, ServiceSid, UserSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUserBinding(response, params, recordChannel, errorChannel) + go c.streamUserBinding(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) streamUserBinding(ctx context.Context, response *ListUserBindingResponse, params *ListUserBindingParams, recordChannel chan ChatV2UserBinding, errorChannel chan error) { curRecord := 1 for response != nil { @@ -185,7 +211,7 @@ func (c *ApiService) streamUserBinding(response *ListUserBindingResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUserBindingResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListUserBindingResponse) if err != nil { errorChannel <- err break @@ -200,11 +226,11 @@ func (c *ApiService) streamUserBinding(response *ListUserBindingResponse, params close(errorChannel) } -func (c *ApiService) getNextListUserBindingResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUserBindingResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 7cd5b90e6..55c5443d7 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,11 @@ 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.DeleteUserChannelWithCtx(context.TODO(), ServiceSid, UserSid, ChannelSid, params) +} + +// Removes User from selected Channel. +func (c *ApiService) DeleteUserChannelWithCtx(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) @@ -49,7 +55,7 @@ func (c *ApiService) DeleteUserChannel(ServiceSid string, UserSid string, Channe headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -61,6 +67,11 @@ func (c *ApiService) DeleteUserChannel(ServiceSid string, UserSid string, Channe // func (c *ApiService) FetchUserChannel(ServiceSid string, UserSid string, ChannelSid string) (*ChatV2UserChannel, error) { + return c.FetchUserChannelWithCtx(context.TODO(), ServiceSid, UserSid, ChannelSid) +} + +// +func (c *ApiService) FetchUserChannelWithCtx(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) @@ -69,7 +80,7 @@ func (c *ApiService) FetchUserChannel(ServiceSid string, UserSid string, Channel data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -103,6 +114,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.PageUserChannelWithCtx(context.TODO(), ServiceSid, UserSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of UserChannel records from the API. Request is executed immediately. +func (c *ApiService) PageUserChannelWithCtx(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) @@ -122,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -139,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.ListUserChannelWithCtx(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) ListUserChannelWithCtx(ctx context.Context, ServiceSid string, UserSid string, params *ListUserChannelParams) ([]ChatV2UserChannel, error) { + response, errors := c.StreamUserChannelWithCtx(ctx, ServiceSid, UserSid, params) records := make([]ChatV2UserChannel, 0) for record := range response { @@ -155,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.StreamUserChannelWithCtx(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) StreamUserChannelWithCtx(ctx context.Context, ServiceSid string, UserSid string, params *ListUserChannelParams) (chan ChatV2UserChannel, chan error) { if params == nil { params = &ListUserChannelParams{} } @@ -163,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.PageUserChannelWithCtx(ctx, ServiceSid, UserSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUserChannel(response, params, recordChannel, errorChannel) + go c.streamUserChannel(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) streamUserChannel(ctx context.Context, response *ListUserChannelResponse, params *ListUserChannelParams, recordChannel chan ChatV2UserChannel, errorChannel chan error) { curRecord := 1 for response != nil { @@ -190,7 +216,7 @@ func (c *ApiService) streamUserChannel(response *ListUserChannelResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUserChannelResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListUserChannelResponse) if err != nil { errorChannel <- err break @@ -205,11 +231,11 @@ func (c *ApiService) streamUserChannel(response *ListUserChannelResponse, params close(errorChannel) } -func (c *ApiService) getNextListUserChannelResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUserChannelResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -248,6 +274,11 @@ func (params *UpdateUserChannelParams) SetLastConsumptionTimestamp(LastConsumpti // func (c *ApiService) UpdateUserChannel(ServiceSid string, UserSid string, ChannelSid string, params *UpdateUserChannelParams) (*ChatV2UserChannel, error) { + return c.UpdateUserChannelWithCtx(context.TODO(), ServiceSid, UserSid, ChannelSid, params) +} + +// +func (c *ApiService) UpdateUserChannelWithCtx(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) @@ -266,7 +297,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.Post(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 8ffb94b7a..417eba3de 100644 --- a/rest/chat/v3/api_service.go +++ b/rest/chat/v3/api_service.go @@ -20,10 +20,14 @@ import ( type ApiService struct { baseURL string - requestHandler *twilio.RequestHandler + requestHandler *twilio.RequestHandlerWithCtx } func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { + return NewApiServiceWithCtx(twilio.UpgradeRequestHandler(requestHandler)) +} + +func NewApiServiceWithCtx(requestHandler *twilio.RequestHandlerWithCtx) *ApiService { return &ApiService{ requestHandler: requestHandler, baseURL: "https://chat.twilio.com", @@ -33,3 +37,7 @@ func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { func NewApiServiceWithClient(client twilio.BaseClient) *ApiService { return NewApiService(twilio.NewRequestHandler(client)) } + +func NewApiServiceWithClientWithCtx(client twilio.BaseClientWithCtx) *ApiService { + return NewApiServiceWithCtx(twilio.NewRequestHandlerWithCtx(client)) +} diff --git a/rest/chat/v3/services_channels.go b/rest/chat/v3/services_channels.go index de91eebab..e1a24523f 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" "net/url" "strings" @@ -45,6 +46,11 @@ func (params *UpdateChannelParams) SetMessagingServiceSid(MessagingServiceSid st // Update a specific Channel. func (c *ApiService) UpdateChannel(ServiceSid string, Sid string, params *UpdateChannelParams) (*ChatV3Channel, error) { + return c.UpdateChannelWithCtx(context.TODO(), ServiceSid, Sid, params) +} + +// Update a specific Channel. +func (c *ApiService) UpdateChannelWithCtx(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) @@ -63,7 +69,7 @@ func (c *ApiService) UpdateChannel(ServiceSid string, Sid string, params *Update headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/conversations/v1/api_service.go b/rest/conversations/v1/api_service.go index abd32d7da..8b1c2a179 100644 --- a/rest/conversations/v1/api_service.go +++ b/rest/conversations/v1/api_service.go @@ -20,10 +20,14 @@ import ( type ApiService struct { baseURL string - requestHandler *twilio.RequestHandler + requestHandler *twilio.RequestHandlerWithCtx } func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { + return NewApiServiceWithCtx(twilio.UpgradeRequestHandler(requestHandler)) +} + +func NewApiServiceWithCtx(requestHandler *twilio.RequestHandlerWithCtx) *ApiService { return &ApiService{ requestHandler: requestHandler, baseURL: "https://conversations.twilio.com", @@ -33,3 +37,7 @@ func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { func NewApiServiceWithClient(client twilio.BaseClient) *ApiService { return NewApiService(twilio.NewRequestHandler(client)) } + +func NewApiServiceWithClientWithCtx(client twilio.BaseClientWithCtx) *ApiService { + return NewApiServiceWithCtx(twilio.NewRequestHandlerWithCtx(client)) +} diff --git a/rest/conversations/v1/configuration.go b/rest/conversations/v1/configuration.go index 62b9b2f55..1f59a4ce5 100644 --- a/rest/conversations/v1/configuration.go +++ b/rest/conversations/v1/configuration.go @@ -15,18 +15,24 @@ 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.FetchConfigurationWithCtx(context.TODO()) +} + +// Fetch the global configuration of conversations on your account +func (c *ApiService) FetchConfigurationWithCtx(ctx context.Context) (*ConversationsV1Configuration, error) { path := "/v1/Configuration" data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -72,6 +78,11 @@ func (params *UpdateConfigurationParams) SetDefaultClosedTimer(DefaultClosedTime // Update the global configuration of conversations on your account func (c *ApiService) UpdateConfiguration(params *UpdateConfigurationParams) (*ConversationsV1Configuration, error) { + return c.UpdateConfigurationWithCtx(context.TODO(), params) +} + +// Update the global configuration of conversations on your account +func (c *ApiService) UpdateConfigurationWithCtx(ctx context.Context, params *UpdateConfigurationParams) (*ConversationsV1Configuration, error) { path := "/v1/Configuration" data := url.Values{} @@ -90,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.Post(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 42d933ca8..31c2a4eb4 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" @@ -96,6 +97,11 @@ func (params *CreateConfigurationAddressParams) SetAutoCreationStudioRetryCount( // Create a new address configuration func (c *ApiService) CreateConfigurationAddress(params *CreateConfigurationAddressParams) (*ConversationsV1ConfigurationAddress, error) { + return c.CreateConfigurationAddressWithCtx(context.TODO(), params) +} + +// Create a new address configuration +func (c *ApiService) CreateConfigurationAddressWithCtx(ctx context.Context, params *CreateConfigurationAddressParams) (*ConversationsV1ConfigurationAddress, error) { path := "/v1/Configuration/Addresses" data := url.Values{} @@ -137,7 +143,7 @@ func (c *ApiService) CreateConfigurationAddress(params *CreateConfigurationAddre data.Set("AutoCreation.StudioRetryCount", fmt.Sprint(*params.AutoCreationStudioRetryCount)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -154,13 +160,18 @@ func (c *ApiService) CreateConfigurationAddress(params *CreateConfigurationAddre // Remove an existing address configuration func (c *ApiService) DeleteConfigurationAddress(Sid string) error { + return c.DeleteConfigurationAddressWithCtx(context.TODO(), Sid) +} + +// Remove an existing address configuration +func (c *ApiService) DeleteConfigurationAddressWithCtx(ctx context.Context, Sid string) error { path := "/v1/Configuration/Addresses/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -172,13 +183,18 @@ func (c *ApiService) DeleteConfigurationAddress(Sid string) error { // Fetch an address configuration func (c *ApiService) FetchConfigurationAddress(Sid string) (*ConversationsV1ConfigurationAddress, error) { + return c.FetchConfigurationAddressWithCtx(context.TODO(), Sid) +} + +// Fetch an address configuration +func (c *ApiService) FetchConfigurationAddressWithCtx(ctx context.Context, Sid string) (*ConversationsV1ConfigurationAddress, error) { path := "/v1/Configuration/Addresses/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -218,6 +234,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.PageConfigurationAddressWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of ConfigurationAddress records from the API. Request is executed immediately. +func (c *ApiService) PageConfigurationAddressWithCtx(ctx context.Context, params *ListConfigurationAddressParams, pageToken, pageNumber string) (*ListConfigurationAddressResponse, error) { path := "/v1/Configuration/Addresses" data := url.Values{} @@ -237,7 +258,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -254,7 +275,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.ListConfigurationAddressWithCtx(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) ListConfigurationAddressWithCtx(ctx context.Context, params *ListConfigurationAddressParams) ([]ConversationsV1ConfigurationAddress, error) { + response, errors := c.StreamConfigurationAddressWithCtx(ctx, params) records := make([]ConversationsV1ConfigurationAddress, 0) for record := range response { @@ -270,6 +296,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.StreamConfigurationAddressWithCtx(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) StreamConfigurationAddressWithCtx(ctx context.Context, params *ListConfigurationAddressParams) (chan ConversationsV1ConfigurationAddress, chan error) { if params == nil { params = &ListConfigurationAddressParams{} } @@ -278,19 +309,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.PageConfigurationAddressWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamConfigurationAddress(response, params, recordChannel, errorChannel) + go c.streamConfigurationAddress(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) streamConfigurationAddress(ctx context.Context, response *ListConfigurationAddressResponse, params *ListConfigurationAddressParams, recordChannel chan ConversationsV1ConfigurationAddress, errorChannel chan error) { curRecord := 1 for response != nil { @@ -305,7 +336,7 @@ func (c *ApiService) streamConfigurationAddress(response *ListConfigurationAddre } } - record, err := client.GetNext(c.baseURL, response, c.getNextListConfigurationAddressResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListConfigurationAddressResponse) if err != nil { errorChannel <- err break @@ -320,11 +351,11 @@ func (c *ApiService) streamConfigurationAddress(response *ListConfigurationAddre close(errorChannel) } -func (c *ApiService) getNextListConfigurationAddressResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListConfigurationAddressResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -399,6 +430,11 @@ func (params *UpdateConfigurationAddressParams) SetAutoCreationStudioRetryCount( // Update an existing address configuration func (c *ApiService) UpdateConfigurationAddress(Sid string, params *UpdateConfigurationAddressParams) (*ConversationsV1ConfigurationAddress, error) { + return c.UpdateConfigurationAddressWithCtx(context.TODO(), Sid, params) +} + +// Update an existing address configuration +func (c *ApiService) UpdateConfigurationAddressWithCtx(ctx context.Context, Sid string, params *UpdateConfigurationAddressParams) (*ConversationsV1ConfigurationAddress, error) { path := "/v1/Configuration/Addresses/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -435,7 +471,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.Post(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 bece581d0..5bc60257c 100644 --- a/rest/conversations/v1/configuration_webhooks.go +++ b/rest/conversations/v1/configuration_webhooks.go @@ -15,18 +15,24 @@ package openapi import ( + "context" "encoding/json" "net/url" ) // func (c *ApiService) FetchConfigurationWebhook() (*ConversationsV1ConfigurationWebhook, error) { + return c.FetchConfigurationWebhookWithCtx(context.TODO()) +} + +// +func (c *ApiService) FetchConfigurationWebhookWithCtx(ctx context.Context) (*ConversationsV1ConfigurationWebhook, error) { path := "/v1/Configuration/Webhooks" data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -78,6 +84,11 @@ func (params *UpdateConfigurationWebhookParams) SetTarget(Target string) *Update // func (c *ApiService) UpdateConfigurationWebhook(params *UpdateConfigurationWebhookParams) (*ConversationsV1ConfigurationWebhook, error) { + return c.UpdateConfigurationWebhookWithCtx(context.TODO(), params) +} + +// +func (c *ApiService) UpdateConfigurationWebhookWithCtx(ctx context.Context, params *UpdateConfigurationWebhookParams) (*ConversationsV1ConfigurationWebhook, error) { path := "/v1/Configuration/Webhooks" data := url.Values{} @@ -101,7 +112,7 @@ func (c *ApiService) UpdateConfigurationWebhook(params *UpdateConfigurationWebho data.Set("Target", *params.Target) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 7fac5f4e6..bcf1e3931 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" @@ -91,6 +92,11 @@ func (params *CreateConversationParams) SetTimersClosed(TimersClosed string) *Cr // Create a new conversation in your account's default service func (c *ApiService) CreateConversation(params *CreateConversationParams) (*ConversationsV1Conversation, error) { + return c.CreateConversationWithCtx(context.TODO(), params) +} + +// Create a new conversation in your account's default service +func (c *ApiService) CreateConversationWithCtx(ctx context.Context, params *CreateConversationParams) (*ConversationsV1Conversation, error) { path := "/v1/Conversations" data := url.Values{} @@ -128,7 +134,7 @@ func (c *ApiService) CreateConversation(params *CreateConversationParams) (*Conv headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -156,6 +162,11 @@ 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.DeleteConversationWithCtx(context.TODO(), Sid, params) +} + +// Remove a conversation from your account's default service +func (c *ApiService) DeleteConversationWithCtx(ctx context.Context, Sid string, params *DeleteConversationParams) error { path := "/v1/Conversations/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -166,7 +177,7 @@ func (c *ApiService) DeleteConversation(Sid string, params *DeleteConversationPa headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -178,13 +189,18 @@ 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.FetchConversationWithCtx(context.TODO(), Sid) +} + +// Fetch a conversation from your account's default service +func (c *ApiService) FetchConversationWithCtx(ctx context.Context, Sid string) (*ConversationsV1Conversation, error) { path := "/v1/Conversations/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -218,6 +234,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.PageConversationWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Conversation records from the API. Request is executed immediately. +func (c *ApiService) PageConversationWithCtx(ctx context.Context, params *ListConversationParams, pageToken, pageNumber string) (*ListConversationResponse, error) { path := "/v1/Conversations" data := url.Values{} @@ -234,7 +255,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -251,7 +272,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.ListConversationWithCtx(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) ListConversationWithCtx(ctx context.Context, params *ListConversationParams) ([]ConversationsV1Conversation, error) { + response, errors := c.StreamConversationWithCtx(ctx, params) records := make([]ConversationsV1Conversation, 0) for record := range response { @@ -267,6 +293,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.StreamConversationWithCtx(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) StreamConversationWithCtx(ctx context.Context, params *ListConversationParams) (chan ConversationsV1Conversation, chan error) { if params == nil { params = &ListConversationParams{} } @@ -275,19 +306,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.PageConversationWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamConversation(response, params, recordChannel, errorChannel) + go c.streamConversation(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) streamConversation(ctx context.Context, response *ListConversationResponse, params *ListConversationParams, recordChannel chan ConversationsV1Conversation, errorChannel chan error) { curRecord := 1 for response != nil { @@ -302,7 +333,7 @@ func (c *ApiService) streamConversation(response *ListConversationResponse, para } } - record, err := client.GetNext(c.baseURL, response, c.getNextListConversationResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListConversationResponse) if err != nil { errorChannel <- err break @@ -317,11 +348,11 @@ func (c *ApiService) streamConversation(response *ListConversationResponse, para close(errorChannel) } -func (c *ApiService) getNextListConversationResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListConversationResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -402,6 +433,11 @@ func (params *UpdateConversationParams) SetUniqueName(UniqueName string) *Update // Update an existing conversation in your account's default service func (c *ApiService) UpdateConversation(Sid string, params *UpdateConversationParams) (*ConversationsV1Conversation, error) { + return c.UpdateConversationWithCtx(context.TODO(), Sid, params) +} + +// Update an existing conversation in your account's default service +func (c *ApiService) UpdateConversationWithCtx(ctx context.Context, Sid string, params *UpdateConversationParams) (*ConversationsV1Conversation, error) { path := "/v1/Conversations/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -440,7 +476,7 @@ func (c *ApiService) UpdateConversation(Sid string, params *UpdateConversationPa headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 1af4f8c5d..daa90c07a 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" @@ -73,6 +74,11 @@ func (params *CreateConversationMessageParams) SetMediaSid(MediaSid string) *Cre // Add a new message to the conversation func (c *ApiService) CreateConversationMessage(ConversationSid string, params *CreateConversationMessageParams) (*ConversationsV1ConversationMessage, error) { + return c.CreateConversationMessageWithCtx(context.TODO(), ConversationSid, params) +} + +// Add a new message to the conversation +func (c *ApiService) CreateConversationMessageWithCtx(ctx context.Context, ConversationSid string, params *CreateConversationMessageParams) (*ConversationsV1ConversationMessage, error) { path := "/v1/Conversations/{ConversationSid}/Messages" path = strings.Replace(path, "{"+"ConversationSid"+"}", ConversationSid, -1) @@ -102,7 +108,7 @@ func (c *ApiService) CreateConversationMessage(ConversationSid string, params *C headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -130,6 +136,11 @@ func (params *DeleteConversationMessageParams) SetXTwilioWebhookEnabled(XTwilioW // Remove a message from the conversation func (c *ApiService) DeleteConversationMessage(ConversationSid string, Sid string, params *DeleteConversationMessageParams) error { + return c.DeleteConversationMessageWithCtx(context.TODO(), ConversationSid, Sid, params) +} + +// Remove a message from the conversation +func (c *ApiService) DeleteConversationMessageWithCtx(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) @@ -141,7 +152,7 @@ func (c *ApiService) DeleteConversationMessage(ConversationSid string, Sid strin headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -153,6 +164,11 @@ 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.FetchConversationMessageWithCtx(context.TODO(), ConversationSid, Sid) +} + +// Fetch a message from the conversation +func (c *ApiService) FetchConversationMessageWithCtx(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) @@ -160,7 +176,7 @@ func (c *ApiService) FetchConversationMessage(ConversationSid string, Sid string data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -200,6 +216,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.PageConversationMessageWithCtx(context.TODO(), ConversationSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ConversationMessage records from the API. Request is executed immediately. +func (c *ApiService) PageConversationMessageWithCtx(ctx context.Context, ConversationSid string, params *ListConversationMessageParams, pageToken, pageNumber string) (*ListConversationMessageResponse, error) { path := "/v1/Conversations/{ConversationSid}/Messages" path = strings.Replace(path, "{"+"ConversationSid"+"}", ConversationSid, -1) @@ -221,7 +242,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -238,7 +259,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.ListConversationMessageWithCtx(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) ListConversationMessageWithCtx(ctx context.Context, ConversationSid string, params *ListConversationMessageParams) ([]ConversationsV1ConversationMessage, error) { + response, errors := c.StreamConversationMessageWithCtx(ctx, ConversationSid, params) records := make([]ConversationsV1ConversationMessage, 0) for record := range response { @@ -254,6 +280,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.StreamConversationMessageWithCtx(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) StreamConversationMessageWithCtx(ctx context.Context, ConversationSid string, params *ListConversationMessageParams) (chan ConversationsV1ConversationMessage, chan error) { if params == nil { params = &ListConversationMessageParams{} } @@ -262,19 +293,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.PageConversationMessageWithCtx(ctx, ConversationSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamConversationMessage(response, params, recordChannel, errorChannel) + go c.streamConversationMessage(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) streamConversationMessage(ctx context.Context, response *ListConversationMessageResponse, params *ListConversationMessageParams, recordChannel chan ConversationsV1ConversationMessage, errorChannel chan error) { curRecord := 1 for response != nil { @@ -289,7 +320,7 @@ func (c *ApiService) streamConversationMessage(response *ListConversationMessage } } - record, err := client.GetNext(c.baseURL, response, c.getNextListConversationMessageResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListConversationMessageResponse) if err != nil { errorChannel <- err break @@ -304,11 +335,11 @@ func (c *ApiService) streamConversationMessage(response *ListConversationMessage close(errorChannel) } -func (c *ApiService) getNextListConversationMessageResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListConversationMessageResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -365,6 +396,11 @@ func (params *UpdateConversationMessageParams) SetAttributes(Attributes string) // Update an existing message in the conversation func (c *ApiService) UpdateConversationMessage(ConversationSid string, Sid string, params *UpdateConversationMessageParams) (*ConversationsV1ConversationMessage, error) { + return c.UpdateConversationMessageWithCtx(context.TODO(), ConversationSid, Sid, params) +} + +// Update an existing message in the conversation +func (c *ApiService) UpdateConversationMessageWithCtx(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) @@ -392,7 +428,7 @@ func (c *ApiService) UpdateConversationMessage(ConversationSid string, Sid strin headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 25cb7fd58..c0e8fae06 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,11 @@ 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.FetchConversationMessageReceiptWithCtx(context.TODO(), ConversationSid, MessageSid, Sid) +} + +// Fetch the delivery and read receipts of the conversation message +func (c *ApiService) FetchConversationMessageReceiptWithCtx(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) @@ -33,7 +39,7 @@ func (c *ApiService) FetchConversationMessageReceipt(ConversationSid string, Mes data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -67,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.PageConversationMessageReceiptWithCtx(context.TODO(), ConversationSid, MessageSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ConversationMessageReceipt records from the API. Request is executed immediately. +func (c *ApiService) PageConversationMessageReceiptWithCtx(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) @@ -86,7 +97,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -103,7 +114,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.ListConversationMessageReceiptWithCtx(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) ListConversationMessageReceiptWithCtx(ctx context.Context, ConversationSid string, MessageSid string, params *ListConversationMessageReceiptParams) ([]ConversationsV1ConversationMessageReceipt, error) { + response, errors := c.StreamConversationMessageReceiptWithCtx(ctx, ConversationSid, MessageSid, params) records := make([]ConversationsV1ConversationMessageReceipt, 0) for record := range response { @@ -119,6 +135,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.StreamConversationMessageReceiptWithCtx(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) StreamConversationMessageReceiptWithCtx(ctx context.Context, ConversationSid string, MessageSid string, params *ListConversationMessageReceiptParams) (chan ConversationsV1ConversationMessageReceipt, chan error) { if params == nil { params = &ListConversationMessageReceiptParams{} } @@ -127,19 +148,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.PageConversationMessageReceiptWithCtx(ctx, ConversationSid, MessageSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamConversationMessageReceipt(response, params, recordChannel, errorChannel) + go c.streamConversationMessageReceipt(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) streamConversationMessageReceipt(ctx context.Context, response *ListConversationMessageReceiptResponse, params *ListConversationMessageReceiptParams, recordChannel chan ConversationsV1ConversationMessageReceipt, errorChannel chan error) { curRecord := 1 for response != nil { @@ -154,7 +175,7 @@ func (c *ApiService) streamConversationMessageReceipt(response *ListConversation } } - record, err := client.GetNext(c.baseURL, response, c.getNextListConversationMessageReceiptResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListConversationMessageReceiptResponse) if err != nil { errorChannel <- err break @@ -169,11 +190,11 @@ func (c *ApiService) streamConversationMessageReceipt(response *ListConversation close(errorChannel) } -func (c *ApiService) getNextListConversationMessageReceiptResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListConversationMessageReceiptResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 85dc93b09..f3c17d28b 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,11 @@ 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.CreateConversationParticipantWithCtx(context.TODO(), ConversationSid, params) +} + +// Add a new participant to the conversation +func (c *ApiService) CreateConversationParticipantWithCtx(ctx context.Context, ConversationSid string, params *CreateConversationParticipantParams) (*ConversationsV1ConversationParticipant, error) { path := "/v1/Conversations/{ConversationSid}/Participants" path = strings.Replace(path, "{"+"ConversationSid"+"}", ConversationSid, -1) @@ -120,7 +126,7 @@ func (c *ApiService) CreateConversationParticipant(ConversationSid string, param headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -148,6 +154,11 @@ func (params *DeleteConversationParticipantParams) SetXTwilioWebhookEnabled(XTwi // Remove a participant from the conversation func (c *ApiService) DeleteConversationParticipant(ConversationSid string, Sid string, params *DeleteConversationParticipantParams) error { + return c.DeleteConversationParticipantWithCtx(context.TODO(), ConversationSid, Sid, params) +} + +// Remove a participant from the conversation +func (c *ApiService) DeleteConversationParticipantWithCtx(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) @@ -159,7 +170,7 @@ func (c *ApiService) DeleteConversationParticipant(ConversationSid string, Sid s headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -171,6 +182,11 @@ 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.FetchConversationParticipantWithCtx(context.TODO(), ConversationSid, Sid) +} + +// Fetch a participant of the conversation +func (c *ApiService) FetchConversationParticipantWithCtx(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) @@ -178,7 +194,7 @@ func (c *ApiService) FetchConversationParticipant(ConversationSid string, Sid st data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -212,6 +228,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.PageConversationParticipantWithCtx(context.TODO(), ConversationSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ConversationParticipant records from the API. Request is executed immediately. +func (c *ApiService) PageConversationParticipantWithCtx(ctx context.Context, ConversationSid string, params *ListConversationParticipantParams, pageToken, pageNumber string) (*ListConversationParticipantResponse, error) { path := "/v1/Conversations/{ConversationSid}/Participants" path = strings.Replace(path, "{"+"ConversationSid"+"}", ConversationSid, -1) @@ -230,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -247,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.ListConversationParticipantWithCtx(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) ListConversationParticipantWithCtx(ctx context.Context, ConversationSid string, params *ListConversationParticipantParams) ([]ConversationsV1ConversationParticipant, error) { + response, errors := c.StreamConversationParticipantWithCtx(ctx, ConversationSid, params) records := make([]ConversationsV1ConversationParticipant, 0) for record := range response { @@ -263,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.StreamConversationParticipantWithCtx(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) StreamConversationParticipantWithCtx(ctx context.Context, ConversationSid string, params *ListConversationParticipantParams) (chan ConversationsV1ConversationParticipant, chan error) { if params == nil { params = &ListConversationParticipantParams{} } @@ -271,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.PageConversationParticipantWithCtx(ctx, ConversationSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamConversationParticipant(response, params, recordChannel, errorChannel) + go c.streamConversationParticipant(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) streamConversationParticipant(ctx context.Context, response *ListConversationParticipantResponse, params *ListConversationParticipantParams, recordChannel chan ConversationsV1ConversationParticipant, errorChannel chan error) { curRecord := 1 for response != nil { @@ -298,7 +329,7 @@ func (c *ApiService) streamConversationParticipant(response *ListConversationPar } } - record, err := client.GetNext(c.baseURL, response, c.getNextListConversationParticipantResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListConversationParticipantResponse) if err != nil { errorChannel <- err break @@ -313,11 +344,11 @@ func (c *ApiService) streamConversationParticipant(response *ListConversationPar close(errorChannel) } -func (c *ApiService) getNextListConversationParticipantResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListConversationParticipantResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -398,6 +429,11 @@ 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.UpdateConversationParticipantWithCtx(context.TODO(), ConversationSid, Sid, params) +} + +// Update an existing participant in the conversation +func (c *ApiService) UpdateConversationParticipantWithCtx(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) @@ -437,7 +473,7 @@ func (c *ApiService) UpdateConversationParticipant(ConversationSid string, Sid s headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 bb6609d3d..9d6eea46b 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,11 @@ func (params *CreateConversationScopedWebhookParams) SetConfigurationReplayAfter // Create a new webhook scoped to the conversation func (c *ApiService) CreateConversationScopedWebhook(ConversationSid string, params *CreateConversationScopedWebhookParams) (*ConversationsV1ConversationScopedWebhook, error) { + return c.CreateConversationScopedWebhookWithCtx(context.TODO(), ConversationSid, params) +} + +// Create a new webhook scoped to the conversation +func (c *ApiService) CreateConversationScopedWebhookWithCtx(ctx context.Context, ConversationSid string, params *CreateConversationScopedWebhookParams) (*ConversationsV1ConversationScopedWebhook, error) { path := "/v1/Conversations/{ConversationSid}/Webhooks" path = strings.Replace(path, "{"+"ConversationSid"+"}", ConversationSid, -1) @@ -104,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -121,6 +127,11 @@ 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.DeleteConversationScopedWebhookWithCtx(context.TODO(), ConversationSid, Sid) +} + +// Remove an existing webhook scoped to the conversation +func (c *ApiService) DeleteConversationScopedWebhookWithCtx(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) @@ -128,7 +139,7 @@ func (c *ApiService) DeleteConversationScopedWebhook(ConversationSid string, Sid data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -140,6 +151,11 @@ 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.FetchConversationScopedWebhookWithCtx(context.TODO(), ConversationSid, Sid) +} + +// Fetch the configuration of a conversation-scoped webhook +func (c *ApiService) FetchConversationScopedWebhookWithCtx(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) @@ -147,7 +163,7 @@ func (c *ApiService) FetchConversationScopedWebhook(ConversationSid string, Sid data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -181,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.PageConversationScopedWebhookWithCtx(context.TODO(), ConversationSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ConversationScopedWebhook records from the API. Request is executed immediately. +func (c *ApiService) PageConversationScopedWebhookWithCtx(ctx context.Context, ConversationSid string, params *ListConversationScopedWebhookParams, pageToken, pageNumber string) (*ListConversationScopedWebhookResponse, error) { path := "/v1/Conversations/{ConversationSid}/Webhooks" path = strings.Replace(path, "{"+"ConversationSid"+"}", ConversationSid, -1) @@ -199,7 +220,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -216,7 +237,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.ListConversationScopedWebhookWithCtx(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) ListConversationScopedWebhookWithCtx(ctx context.Context, ConversationSid string, params *ListConversationScopedWebhookParams) ([]ConversationsV1ConversationScopedWebhook, error) { + response, errors := c.StreamConversationScopedWebhookWithCtx(ctx, ConversationSid, params) records := make([]ConversationsV1ConversationScopedWebhook, 0) for record := range response { @@ -232,6 +258,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.StreamConversationScopedWebhookWithCtx(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) StreamConversationScopedWebhookWithCtx(ctx context.Context, ConversationSid string, params *ListConversationScopedWebhookParams) (chan ConversationsV1ConversationScopedWebhook, chan error) { if params == nil { params = &ListConversationScopedWebhookParams{} } @@ -240,19 +271,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.PageConversationScopedWebhookWithCtx(ctx, ConversationSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamConversationScopedWebhook(response, params, recordChannel, errorChannel) + go c.streamConversationScopedWebhook(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) streamConversationScopedWebhook(ctx context.Context, response *ListConversationScopedWebhookResponse, params *ListConversationScopedWebhookParams, recordChannel chan ConversationsV1ConversationScopedWebhook, errorChannel chan error) { curRecord := 1 for response != nil { @@ -267,7 +298,7 @@ func (c *ApiService) streamConversationScopedWebhook(response *ListConversationS } } - record, err := client.GetNext(c.baseURL, response, c.getNextListConversationScopedWebhookResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListConversationScopedWebhookResponse) if err != nil { errorChannel <- err break @@ -282,11 +313,11 @@ func (c *ApiService) streamConversationScopedWebhook(response *ListConversationS close(errorChannel) } -func (c *ApiService) getNextListConversationScopedWebhookResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListConversationScopedWebhookResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -337,6 +368,11 @@ 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.UpdateConversationScopedWebhookWithCtx(context.TODO(), ConversationSid, Sid, params) +} + +// Update an existing conversation-scoped webhook +func (c *ApiService) UpdateConversationScopedWebhookWithCtx(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) @@ -364,7 +400,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.Post(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 be3d3d586..584502444 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,11 @@ 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.CreateCredentialWithCtx(context.TODO(), params) +} + +// Add a new push notification credential to your account +func (c *ApiService) CreateCredentialWithCtx(ctx context.Context, params *CreateCredentialParams) (*ConversationsV1Credential, error) { path := "/v1/Credentials" data := url.Values{} @@ -99,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -116,13 +122,18 @@ func (c *ApiService) CreateCredential(params *CreateCredentialParams) (*Conversa // Remove a push notification credential from your account func (c *ApiService) DeleteCredential(Sid string) error { + return c.DeleteCredentialWithCtx(context.TODO(), Sid) +} + +// Remove a push notification credential from your account +func (c *ApiService) DeleteCredentialWithCtx(ctx context.Context, Sid string) error { path := "/v1/Credentials/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -134,13 +145,18 @@ 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.FetchCredentialWithCtx(context.TODO(), Sid) +} + +// Fetch a push notification credential from your account +func (c *ApiService) FetchCredentialWithCtx(ctx context.Context, Sid string) (*ConversationsV1Credential, error) { path := "/v1/Credentials/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -174,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.PageCredentialWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Credential records from the API. Request is executed immediately. +func (c *ApiService) PageCredentialWithCtx(ctx context.Context, params *ListCredentialParams, pageToken, pageNumber string) (*ListCredentialResponse, error) { path := "/v1/Credentials" data := url.Values{} @@ -190,7 +211,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -207,7 +228,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.ListCredentialWithCtx(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) ListCredentialWithCtx(ctx context.Context, params *ListCredentialParams) ([]ConversationsV1Credential, error) { + response, errors := c.StreamCredentialWithCtx(ctx, params) records := make([]ConversationsV1Credential, 0) for record := range response { @@ -223,6 +249,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.StreamCredentialWithCtx(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) StreamCredentialWithCtx(ctx context.Context, params *ListCredentialParams) (chan ConversationsV1Credential, chan error) { if params == nil { params = &ListCredentialParams{} } @@ -231,19 +262,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.PageCredentialWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamCredential(response, params, recordChannel, errorChannel) + go c.streamCredential(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) streamCredential(ctx context.Context, response *ListCredentialResponse, params *ListCredentialParams, recordChannel chan ConversationsV1Credential, errorChannel chan error) { curRecord := 1 for response != nil { @@ -258,7 +289,7 @@ func (c *ApiService) streamCredential(response *ListCredentialResponse, params * } } - record, err := client.GetNext(c.baseURL, response, c.getNextListCredentialResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListCredentialResponse) if err != nil { errorChannel <- err break @@ -273,11 +304,11 @@ func (c *ApiService) streamCredential(response *ListCredentialResponse, params * close(errorChannel) } -func (c *ApiService) getNextListCredentialResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListCredentialResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -340,6 +371,11 @@ 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.UpdateCredentialWithCtx(context.TODO(), Sid, params) +} + +// Update an existing push notification credential on your account +func (c *ApiService) UpdateCredentialWithCtx(ctx context.Context, Sid string, params *UpdateCredentialParams) (*ConversationsV1Credential, error) { path := "/v1/Credentials/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -368,7 +404,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.Post(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 955743211..de1751578 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.PageParticipantConversationWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of ParticipantConversation records from the API. Request is executed immediately. +func (c *ApiService) PageParticipantConversationWithCtx(ctx context.Context, params *ListParticipantConversationParams, pageToken, pageNumber string) (*ListParticipantConversationResponse, error) { path := "/v1/ParticipantConversations" data := url.Values{} @@ -75,7 +81,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -92,7 +98,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.ListParticipantConversationWithCtx(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) ListParticipantConversationWithCtx(ctx context.Context, params *ListParticipantConversationParams) ([]ConversationsV1ParticipantConversation, error) { + response, errors := c.StreamParticipantConversationWithCtx(ctx, params) records := make([]ConversationsV1ParticipantConversation, 0) for record := range response { @@ -108,6 +119,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.StreamParticipantConversationWithCtx(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) StreamParticipantConversationWithCtx(ctx context.Context, params *ListParticipantConversationParams) (chan ConversationsV1ParticipantConversation, chan error) { if params == nil { params = &ListParticipantConversationParams{} } @@ -116,19 +132,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.PageParticipantConversationWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamParticipantConversation(response, params, recordChannel, errorChannel) + go c.streamParticipantConversation(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) streamParticipantConversation(ctx context.Context, response *ListParticipantConversationResponse, params *ListParticipantConversationParams, recordChannel chan ConversationsV1ParticipantConversation, errorChannel chan error) { curRecord := 1 for response != nil { @@ -143,7 +159,7 @@ func (c *ApiService) streamParticipantConversation(response *ListParticipantConv } } - record, err := client.GetNext(c.baseURL, response, c.getNextListParticipantConversationResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListParticipantConversationResponse) if err != nil { errorChannel <- err break @@ -158,11 +174,11 @@ func (c *ApiService) streamParticipantConversation(response *ListParticipantConv close(errorChannel) } -func (c *ApiService) getNextListParticipantConversationResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListParticipantConversationResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 db3c08bed..b2d3594d1 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,11 @@ 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.CreateRoleWithCtx(context.TODO(), params) +} + +// Create a new user role in your account's default service +func (c *ApiService) CreateRoleWithCtx(ctx context.Context, params *CreateRoleParams) (*ConversationsV1Role, error) { path := "/v1/Roles" data := url.Values{} @@ -65,7 +71,7 @@ func (c *ApiService) CreateRole(params *CreateRoleParams) (*ConversationsV1Role, } } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -82,13 +88,18 @@ 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.DeleteRoleWithCtx(context.TODO(), Sid) +} + +// Remove a user role from your account's default service +func (c *ApiService) DeleteRoleWithCtx(ctx context.Context, Sid string) error { path := "/v1/Roles/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -100,13 +111,18 @@ 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.FetchRoleWithCtx(context.TODO(), Sid) +} + +// Fetch a user role from your account's default service +func (c *ApiService) FetchRoleWithCtx(ctx context.Context, Sid string) (*ConversationsV1Role, error) { path := "/v1/Roles/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -140,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.PageRoleWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Role records from the API. Request is executed immediately. +func (c *ApiService) PageRoleWithCtx(ctx context.Context, params *ListRoleParams, pageToken, pageNumber string) (*ListRoleResponse, error) { path := "/v1/Roles" data := url.Values{} @@ -156,7 +177,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -173,7 +194,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.ListRoleWithCtx(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) ListRoleWithCtx(ctx context.Context, params *ListRoleParams) ([]ConversationsV1Role, error) { + response, errors := c.StreamRoleWithCtx(ctx, params) records := make([]ConversationsV1Role, 0) for record := range response { @@ -189,6 +215,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.StreamRoleWithCtx(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) StreamRoleWithCtx(ctx context.Context, params *ListRoleParams) (chan ConversationsV1Role, chan error) { if params == nil { params = &ListRoleParams{} } @@ -197,19 +228,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.PageRoleWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamRole(response, params, recordChannel, errorChannel) + go c.streamRole(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) streamRole(ctx context.Context, response *ListRoleResponse, params *ListRoleParams, recordChannel chan ConversationsV1Role, errorChannel chan error) { curRecord := 1 for response != nil { @@ -224,7 +255,7 @@ func (c *ApiService) streamRole(response *ListRoleResponse, params *ListRolePara } } - record, err := client.GetNext(c.baseURL, response, c.getNextListRoleResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListRoleResponse) if err != nil { errorChannel <- err break @@ -239,11 +270,11 @@ func (c *ApiService) streamRole(response *ListRoleResponse, params *ListRolePara close(errorChannel) } -func (c *ApiService) getNextListRoleResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListRoleResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -270,6 +301,11 @@ 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.UpdateRoleWithCtx(context.TODO(), Sid, params) +} + +// Update an existing user role in your account's default service +func (c *ApiService) UpdateRoleWithCtx(ctx context.Context, Sid string, params *UpdateRoleParams) (*ConversationsV1Role, error) { path := "/v1/Roles/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -282,7 +318,7 @@ func (c *ApiService) UpdateRole(Sid string, params *UpdateRoleParams) (*Conversa } } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 495afe477..1e4ca8368 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,11 @@ 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.CreateServiceWithCtx(context.TODO(), params) +} + +// Create a new conversation service on your account +func (c *ApiService) CreateServiceWithCtx(ctx context.Context, params *CreateServiceParams) (*ConversationsV1Service, error) { path := "/v1/Services" data := url.Values{} @@ -45,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -62,13 +68,18 @@ 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.DeleteServiceWithCtx(context.TODO(), Sid) +} + +// Remove a conversation service with all its nested resources from your account +func (c *ApiService) DeleteServiceWithCtx(ctx context.Context, Sid string) error { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -80,13 +91,18 @@ func (c *ApiService) DeleteService(Sid string) error { // Fetch a conversation service from your account func (c *ApiService) FetchService(Sid string) (*ConversationsV1Service, error) { + return c.FetchServiceWithCtx(context.TODO(), Sid) +} + +// Fetch a conversation service from your account +func (c *ApiService) FetchServiceWithCtx(ctx context.Context, Sid string) (*ConversationsV1Service, error) { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -120,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.PageServiceWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Service records from the API. Request is executed immediately. +func (c *ApiService) PageServiceWithCtx(ctx context.Context, params *ListServiceParams, pageToken, pageNumber string) (*ListServiceResponse, error) { path := "/v1/Services" data := url.Values{} @@ -136,7 +157,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -153,7 +174,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.ListServiceWithCtx(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) ListServiceWithCtx(ctx context.Context, params *ListServiceParams) ([]ConversationsV1Service, error) { + response, errors := c.StreamServiceWithCtx(ctx, params) records := make([]ConversationsV1Service, 0) for record := range response { @@ -169,6 +195,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.StreamServiceWithCtx(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) StreamServiceWithCtx(ctx context.Context, params *ListServiceParams) (chan ConversationsV1Service, chan error) { if params == nil { params = &ListServiceParams{} } @@ -177,19 +208,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.PageServiceWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamService(response, params, recordChannel, errorChannel) + go c.streamService(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) streamService(ctx context.Context, response *ListServiceResponse, params *ListServiceParams, recordChannel chan ConversationsV1Service, errorChannel chan error) { curRecord := 1 for response != nil { @@ -204,7 +235,7 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListServiceResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListServiceResponse) if err != nil { errorChannel <- err break @@ -219,11 +250,11 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe close(errorChannel) } -func (c *ApiService) getNextListServiceResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListServiceResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 00708fbc6..b55cfdbda 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,11 @@ import ( // Remove a push notification binding from the conversation service func (c *ApiService) DeleteServiceBinding(ChatServiceSid string, Sid string) error { + return c.DeleteServiceBindingWithCtx(context.TODO(), ChatServiceSid, Sid) +} + +// Remove a push notification binding from the conversation service +func (c *ApiService) DeleteServiceBindingWithCtx(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) @@ -32,7 +38,7 @@ func (c *ApiService) DeleteServiceBinding(ChatServiceSid string, Sid string) err data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -44,6 +50,11 @@ 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.FetchServiceBindingWithCtx(context.TODO(), ChatServiceSid, Sid) +} + +// Fetch a push notification binding from the conversation service +func (c *ApiService) FetchServiceBindingWithCtx(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) @@ -51,7 +62,7 @@ func (c *ApiService) FetchServiceBinding(ChatServiceSid string, Sid string) (*Co data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -97,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.PageServiceBindingWithCtx(context.TODO(), ChatServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ServiceBinding records from the API. Request is executed immediately. +func (c *ApiService) PageServiceBindingWithCtx(ctx context.Context, ChatServiceSid string, params *ListServiceBindingParams, pageToken, pageNumber string) (*ListServiceBindingResponse, error) { path := "/v1/Services/{ChatServiceSid}/Bindings" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) @@ -125,7 +141,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -142,7 +158,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.ListServiceBindingWithCtx(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) ListServiceBindingWithCtx(ctx context.Context, ChatServiceSid string, params *ListServiceBindingParams) ([]ConversationsV1ServiceBinding, error) { + response, errors := c.StreamServiceBindingWithCtx(ctx, ChatServiceSid, params) records := make([]ConversationsV1ServiceBinding, 0) for record := range response { @@ -158,6 +179,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.StreamServiceBindingWithCtx(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) StreamServiceBindingWithCtx(ctx context.Context, ChatServiceSid string, params *ListServiceBindingParams) (chan ConversationsV1ServiceBinding, chan error) { if params == nil { params = &ListServiceBindingParams{} } @@ -166,19 +192,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.PageServiceBindingWithCtx(ctx, ChatServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamServiceBinding(response, params, recordChannel, errorChannel) + go c.streamServiceBinding(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) streamServiceBinding(ctx context.Context, response *ListServiceBindingResponse, params *ListServiceBindingParams, recordChannel chan ConversationsV1ServiceBinding, errorChannel chan error) { curRecord := 1 for response != nil { @@ -193,7 +219,7 @@ func (c *ApiService) streamServiceBinding(response *ListServiceBindingResponse, } } - record, err := client.GetNext(c.baseURL, response, c.getNextListServiceBindingResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListServiceBindingResponse) if err != nil { errorChannel <- err break @@ -208,11 +234,11 @@ func (c *ApiService) streamServiceBinding(response *ListServiceBindingResponse, close(errorChannel) } -func (c *ApiService) getNextListServiceBindingResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListServiceBindingResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 c510801d2..1e8258e79 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,13 +24,18 @@ import ( // Fetch the configuration of a conversation service func (c *ApiService) FetchServiceConfiguration(ChatServiceSid string) (*ConversationsV1ServiceConfiguration, error) { + return c.FetchServiceConfigurationWithCtx(context.TODO(), ChatServiceSid) +} + +// Fetch the configuration of a conversation service +func (c *ApiService) FetchServiceConfigurationWithCtx(ctx context.Context, ChatServiceSid string) (*ConversationsV1ServiceConfiguration, error) { path := "/v1/Services/{ChatServiceSid}/Configuration" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -75,6 +81,11 @@ func (params *UpdateServiceConfigurationParams) SetReachabilityEnabled(Reachabil // Update configuration settings of a conversation service func (c *ApiService) UpdateServiceConfiguration(ChatServiceSid string, params *UpdateServiceConfigurationParams) (*ConversationsV1ServiceConfiguration, error) { + return c.UpdateServiceConfigurationWithCtx(context.TODO(), ChatServiceSid, params) +} + +// Update configuration settings of a conversation service +func (c *ApiService) UpdateServiceConfigurationWithCtx(ctx context.Context, ChatServiceSid string, params *UpdateServiceConfigurationParams) (*ConversationsV1ServiceConfiguration, error) { path := "/v1/Services/{ChatServiceSid}/Configuration" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) @@ -94,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.Post(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 18218bdeb..32802a6ef 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,13 +24,18 @@ import ( // Fetch push notification service settings func (c *ApiService) FetchServiceNotification(ChatServiceSid string) (*ConversationsV1ServiceNotification, error) { + return c.FetchServiceNotificationWithCtx(context.TODO(), ChatServiceSid) +} + +// Fetch push notification service settings +func (c *ApiService) FetchServiceNotificationWithCtx(ctx context.Context, ChatServiceSid string) (*ConversationsV1ServiceNotification, error) { path := "/v1/Services/{ChatServiceSid}/Configuration/Notifications" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -129,6 +135,11 @@ func (params *UpdateServiceNotificationParams) SetNewMessageWithMediaTemplate(Ne // Update push notification service settings func (c *ApiService) UpdateServiceNotification(ChatServiceSid string, params *UpdateServiceNotificationParams) (*ConversationsV1ServiceNotification, error) { + return c.UpdateServiceNotificationWithCtx(context.TODO(), ChatServiceSid, params) +} + +// Update push notification service settings +func (c *ApiService) UpdateServiceNotificationWithCtx(ctx context.Context, ChatServiceSid string, params *UpdateServiceNotificationParams) (*ConversationsV1ServiceNotification, error) { path := "/v1/Services/{ChatServiceSid}/Configuration/Notifications" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) @@ -175,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.Post(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 8f2504f3a..4dfda9add 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,13 +23,18 @@ import ( // Fetch a specific service webhook configuration. func (c *ApiService) FetchServiceWebhookConfiguration(ChatServiceSid string) (*ConversationsV1ServiceWebhookConfiguration, error) { + return c.FetchServiceWebhookConfigurationWithCtx(context.TODO(), ChatServiceSid) +} + +// Fetch a specific service webhook configuration. +func (c *ApiService) FetchServiceWebhookConfigurationWithCtx(ctx context.Context, ChatServiceSid string) (*ConversationsV1ServiceWebhookConfiguration, error) { path := "/v1/Services/{ChatServiceSid}/Configuration/Webhooks" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -74,6 +80,11 @@ func (params *UpdateServiceWebhookConfigurationParams) SetMethod(Method string) // Update a specific Webhook. func (c *ApiService) UpdateServiceWebhookConfiguration(ChatServiceSid string, params *UpdateServiceWebhookConfigurationParams) (*ConversationsV1ServiceWebhookConfiguration, error) { + return c.UpdateServiceWebhookConfigurationWithCtx(context.TODO(), ChatServiceSid, params) +} + +// Update a specific Webhook. +func (c *ApiService) UpdateServiceWebhookConfigurationWithCtx(ctx context.Context, ChatServiceSid string, params *UpdateServiceWebhookConfigurationParams) (*ConversationsV1ServiceWebhookConfiguration, error) { path := "/v1/Services/{ChatServiceSid}/Configuration/Webhooks" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) @@ -95,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.Post(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 df87ec681..500ad8a67 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" @@ -91,6 +92,11 @@ func (params *CreateServiceConversationParams) SetTimersClosed(TimersClosed stri // Create a new conversation in your service func (c *ApiService) CreateServiceConversation(ChatServiceSid string, params *CreateServiceConversationParams) (*ConversationsV1ServiceConversation, error) { + return c.CreateServiceConversationWithCtx(context.TODO(), ChatServiceSid, params) +} + +// Create a new conversation in your service +func (c *ApiService) CreateServiceConversationWithCtx(ctx context.Context, ChatServiceSid string, params *CreateServiceConversationParams) (*ConversationsV1ServiceConversation, error) { path := "/v1/Services/{ChatServiceSid}/Conversations" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) @@ -129,7 +135,7 @@ func (c *ApiService) CreateServiceConversation(ChatServiceSid string, params *Cr headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -157,6 +163,11 @@ func (params *DeleteServiceConversationParams) SetXTwilioWebhookEnabled(XTwilioW // Remove a conversation from your service func (c *ApiService) DeleteServiceConversation(ChatServiceSid string, Sid string, params *DeleteServiceConversationParams) error { + return c.DeleteServiceConversationWithCtx(context.TODO(), ChatServiceSid, Sid, params) +} + +// Remove a conversation from your service +func (c *ApiService) DeleteServiceConversationWithCtx(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) @@ -168,7 +179,7 @@ func (c *ApiService) DeleteServiceConversation(ChatServiceSid string, Sid string headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -180,6 +191,11 @@ 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.FetchServiceConversationWithCtx(context.TODO(), ChatServiceSid, Sid) +} + +// Fetch a conversation from your service +func (c *ApiService) FetchServiceConversationWithCtx(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) @@ -187,7 +203,7 @@ func (c *ApiService) FetchServiceConversation(ChatServiceSid string, Sid string) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -221,6 +237,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.PageServiceConversationWithCtx(context.TODO(), ChatServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ServiceConversation records from the API. Request is executed immediately. +func (c *ApiService) PageServiceConversationWithCtx(ctx context.Context, ChatServiceSid string, params *ListServiceConversationParams, pageToken, pageNumber string) (*ListServiceConversationResponse, error) { path := "/v1/Services/{ChatServiceSid}/Conversations" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) @@ -239,7 +260,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -256,7 +277,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.ListServiceConversationWithCtx(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) ListServiceConversationWithCtx(ctx context.Context, ChatServiceSid string, params *ListServiceConversationParams) ([]ConversationsV1ServiceConversation, error) { + response, errors := c.StreamServiceConversationWithCtx(ctx, ChatServiceSid, params) records := make([]ConversationsV1ServiceConversation, 0) for record := range response { @@ -272,6 +298,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.StreamServiceConversationWithCtx(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) StreamServiceConversationWithCtx(ctx context.Context, ChatServiceSid string, params *ListServiceConversationParams) (chan ConversationsV1ServiceConversation, chan error) { if params == nil { params = &ListServiceConversationParams{} } @@ -280,19 +311,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.PageServiceConversationWithCtx(ctx, ChatServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamServiceConversation(response, params, recordChannel, errorChannel) + go c.streamServiceConversation(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) streamServiceConversation(ctx context.Context, response *ListServiceConversationResponse, params *ListServiceConversationParams, recordChannel chan ConversationsV1ServiceConversation, errorChannel chan error) { curRecord := 1 for response != nil { @@ -307,7 +338,7 @@ func (c *ApiService) streamServiceConversation(response *ListServiceConversation } } - record, err := client.GetNext(c.baseURL, response, c.getNextListServiceConversationResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListServiceConversationResponse) if err != nil { errorChannel <- err break @@ -322,11 +353,11 @@ func (c *ApiService) streamServiceConversation(response *ListServiceConversation close(errorChannel) } -func (c *ApiService) getNextListServiceConversationResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListServiceConversationResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -407,6 +438,11 @@ func (params *UpdateServiceConversationParams) SetUniqueName(UniqueName string) // Update an existing conversation in your service func (c *ApiService) UpdateServiceConversation(ChatServiceSid string, Sid string, params *UpdateServiceConversationParams) (*ConversationsV1ServiceConversation, error) { + return c.UpdateServiceConversationWithCtx(context.TODO(), ChatServiceSid, Sid, params) +} + +// Update an existing conversation in your service +func (c *ApiService) UpdateServiceConversationWithCtx(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) @@ -446,7 +482,7 @@ func (c *ApiService) UpdateServiceConversation(ChatServiceSid string, Sid string headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 cc7103eb5..b0f04dd02 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" @@ -73,6 +74,11 @@ func (params *CreateServiceConversationMessageParams) SetMediaSid(MediaSid strin // 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.CreateServiceConversationMessageWithCtx(context.TODO(), ChatServiceSid, ConversationSid, params) +} + +// Add a new message to the conversation in a specific service +func (c *ApiService) CreateServiceConversationMessageWithCtx(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) @@ -103,7 +109,7 @@ func (c *ApiService) CreateServiceConversationMessage(ChatServiceSid string, Con headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -131,6 +137,11 @@ 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.DeleteServiceConversationMessageWithCtx(context.TODO(), ChatServiceSid, ConversationSid, Sid, params) +} + +// Remove a message from the conversation +func (c *ApiService) DeleteServiceConversationMessageWithCtx(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) @@ -143,7 +154,7 @@ func (c *ApiService) DeleteServiceConversationMessage(ChatServiceSid string, Con headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -155,6 +166,11 @@ 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.FetchServiceConversationMessageWithCtx(context.TODO(), ChatServiceSid, ConversationSid, Sid) +} + +// Fetch a message from the conversation +func (c *ApiService) FetchServiceConversationMessageWithCtx(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) @@ -163,7 +179,7 @@ func (c *ApiService) FetchServiceConversationMessage(ChatServiceSid string, Conv data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -203,6 +219,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.PageServiceConversationMessageWithCtx(context.TODO(), ChatServiceSid, ConversationSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ServiceConversationMessage records from the API. Request is executed immediately. +func (c *ApiService) PageServiceConversationMessageWithCtx(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) @@ -225,7 +246,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -242,7 +263,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.ListServiceConversationMessageWithCtx(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) ListServiceConversationMessageWithCtx(ctx context.Context, ChatServiceSid string, ConversationSid string, params *ListServiceConversationMessageParams) ([]ConversationsV1ServiceConversationMessage, error) { + response, errors := c.StreamServiceConversationMessageWithCtx(ctx, ChatServiceSid, ConversationSid, params) records := make([]ConversationsV1ServiceConversationMessage, 0) for record := range response { @@ -258,6 +284,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.StreamServiceConversationMessageWithCtx(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) StreamServiceConversationMessageWithCtx(ctx context.Context, ChatServiceSid string, ConversationSid string, params *ListServiceConversationMessageParams) (chan ConversationsV1ServiceConversationMessage, chan error) { if params == nil { params = &ListServiceConversationMessageParams{} } @@ -266,19 +297,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.PageServiceConversationMessageWithCtx(ctx, ChatServiceSid, ConversationSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamServiceConversationMessage(response, params, recordChannel, errorChannel) + go c.streamServiceConversationMessage(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) streamServiceConversationMessage(ctx context.Context, response *ListServiceConversationMessageResponse, params *ListServiceConversationMessageParams, recordChannel chan ConversationsV1ServiceConversationMessage, errorChannel chan error) { curRecord := 1 for response != nil { @@ -293,7 +324,7 @@ func (c *ApiService) streamServiceConversationMessage(response *ListServiceConve } } - record, err := client.GetNext(c.baseURL, response, c.getNextListServiceConversationMessageResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListServiceConversationMessageResponse) if err != nil { errorChannel <- err break @@ -308,11 +339,11 @@ func (c *ApiService) streamServiceConversationMessage(response *ListServiceConve close(errorChannel) } -func (c *ApiService) getNextListServiceConversationMessageResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListServiceConversationMessageResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -369,6 +400,11 @@ func (params *UpdateServiceConversationMessageParams) SetAttributes(Attributes s // Update an existing message in the conversation func (c *ApiService) UpdateServiceConversationMessage(ChatServiceSid string, ConversationSid string, Sid string, params *UpdateServiceConversationMessageParams) (*ConversationsV1ServiceConversationMessage, error) { + return c.UpdateServiceConversationMessageWithCtx(context.TODO(), ChatServiceSid, ConversationSid, Sid, params) +} + +// Update an existing message in the conversation +func (c *ApiService) UpdateServiceConversationMessageWithCtx(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) @@ -397,7 +433,7 @@ func (c *ApiService) UpdateServiceConversationMessage(ChatServiceSid string, Con headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 a722e39c2..85f7c0cdc 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,11 @@ 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.FetchServiceConversationMessageReceiptWithCtx(context.TODO(), ChatServiceSid, ConversationSid, MessageSid, Sid) +} + +// Fetch the delivery and read receipts of the conversation message +func (c *ApiService) FetchServiceConversationMessageReceiptWithCtx(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) @@ -34,7 +40,7 @@ func (c *ApiService) FetchServiceConversationMessageReceipt(ChatServiceSid strin data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -68,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.PageServiceConversationMessageReceiptWithCtx(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) PageServiceConversationMessageReceiptWithCtx(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) @@ -88,7 +99,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -105,7 +116,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.ListServiceConversationMessageReceiptWithCtx(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) ListServiceConversationMessageReceiptWithCtx(ctx context.Context, ChatServiceSid string, ConversationSid string, MessageSid string, params *ListServiceConversationMessageReceiptParams) ([]ConversationsV1ServiceConversationMessageReceipt, error) { + response, errors := c.StreamServiceConversationMessageReceiptWithCtx(ctx, ChatServiceSid, ConversationSid, MessageSid, params) records := make([]ConversationsV1ServiceConversationMessageReceipt, 0) for record := range response { @@ -121,6 +137,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.StreamServiceConversationMessageReceiptWithCtx(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) StreamServiceConversationMessageReceiptWithCtx(ctx context.Context, ChatServiceSid string, ConversationSid string, MessageSid string, params *ListServiceConversationMessageReceiptParams) (chan ConversationsV1ServiceConversationMessageReceipt, chan error) { if params == nil { params = &ListServiceConversationMessageReceiptParams{} } @@ -129,19 +150,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.PageServiceConversationMessageReceiptWithCtx(ctx, ChatServiceSid, ConversationSid, MessageSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamServiceConversationMessageReceipt(response, params, recordChannel, errorChannel) + go c.streamServiceConversationMessageReceipt(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) streamServiceConversationMessageReceipt(ctx context.Context, response *ListServiceConversationMessageReceiptResponse, params *ListServiceConversationMessageReceiptParams, recordChannel chan ConversationsV1ServiceConversationMessageReceipt, errorChannel chan error) { curRecord := 1 for response != nil { @@ -156,7 +177,7 @@ func (c *ApiService) streamServiceConversationMessageReceipt(response *ListServi } } - record, err := client.GetNext(c.baseURL, response, c.getNextListServiceConversationMessageReceiptResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListServiceConversationMessageReceiptResponse) if err != nil { errorChannel <- err break @@ -171,11 +192,11 @@ func (c *ApiService) streamServiceConversationMessageReceipt(response *ListServi close(errorChannel) } -func (c *ApiService) getNextListServiceConversationMessageReceiptResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListServiceConversationMessageReceiptResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 f6ffdad84..30e7bc9d7 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,11 @@ 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.CreateServiceConversationParticipantWithCtx(context.TODO(), ChatServiceSid, ConversationSid, params) +} + +// Add a new participant to the conversation in a specific service +func (c *ApiService) CreateServiceConversationParticipantWithCtx(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) @@ -121,7 +127,7 @@ func (c *ApiService) CreateServiceConversationParticipant(ChatServiceSid string, headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -149,6 +155,11 @@ 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.DeleteServiceConversationParticipantWithCtx(context.TODO(), ChatServiceSid, ConversationSid, Sid, params) +} + +// Remove a participant from the conversation +func (c *ApiService) DeleteServiceConversationParticipantWithCtx(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) @@ -161,7 +172,7 @@ func (c *ApiService) DeleteServiceConversationParticipant(ChatServiceSid string, headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -173,6 +184,11 @@ 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.FetchServiceConversationParticipantWithCtx(context.TODO(), ChatServiceSid, ConversationSid, Sid) +} + +// Fetch a participant of the conversation +func (c *ApiService) FetchServiceConversationParticipantWithCtx(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) @@ -181,7 +197,7 @@ func (c *ApiService) FetchServiceConversationParticipant(ChatServiceSid string, data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -215,6 +231,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.PageServiceConversationParticipantWithCtx(context.TODO(), ChatServiceSid, ConversationSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ServiceConversationParticipant records from the API. Request is executed immediately. +func (c *ApiService) PageServiceConversationParticipantWithCtx(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) @@ -234,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -251,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.ListServiceConversationParticipantWithCtx(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) ListServiceConversationParticipantWithCtx(ctx context.Context, ChatServiceSid string, ConversationSid string, params *ListServiceConversationParticipantParams) ([]ConversationsV1ServiceConversationParticipant, error) { + response, errors := c.StreamServiceConversationParticipantWithCtx(ctx, ChatServiceSid, ConversationSid, params) records := make([]ConversationsV1ServiceConversationParticipant, 0) for record := range response { @@ -267,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.StreamServiceConversationParticipantWithCtx(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) StreamServiceConversationParticipantWithCtx(ctx context.Context, ChatServiceSid string, ConversationSid string, params *ListServiceConversationParticipantParams) (chan ConversationsV1ServiceConversationParticipant, chan error) { if params == nil { params = &ListServiceConversationParticipantParams{} } @@ -275,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.PageServiceConversationParticipantWithCtx(ctx, ChatServiceSid, ConversationSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamServiceConversationParticipant(response, params, recordChannel, errorChannel) + go c.streamServiceConversationParticipant(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) streamServiceConversationParticipant(ctx context.Context, response *ListServiceConversationParticipantResponse, params *ListServiceConversationParticipantParams, recordChannel chan ConversationsV1ServiceConversationParticipant, errorChannel chan error) { curRecord := 1 for response != nil { @@ -302,7 +333,7 @@ func (c *ApiService) streamServiceConversationParticipant(response *ListServiceC } } - record, err := client.GetNext(c.baseURL, response, c.getNextListServiceConversationParticipantResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListServiceConversationParticipantResponse) if err != nil { errorChannel <- err break @@ -317,11 +348,11 @@ func (c *ApiService) streamServiceConversationParticipant(response *ListServiceC close(errorChannel) } -func (c *ApiService) getNextListServiceConversationParticipantResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListServiceConversationParticipantResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -402,6 +433,11 @@ 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.UpdateServiceConversationParticipantWithCtx(context.TODO(), ChatServiceSid, ConversationSid, Sid, params) +} + +// Update an existing participant in the conversation +func (c *ApiService) UpdateServiceConversationParticipantWithCtx(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) @@ -442,7 +478,7 @@ func (c *ApiService) UpdateServiceConversationParticipant(ChatServiceSid string, headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 6bdc940ce..881ca33d1 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,11 @@ 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.CreateServiceConversationScopedWebhookWithCtx(context.TODO(), ChatServiceSid, ConversationSid, params) +} + +// Create a new webhook scoped to the conversation in a specific service +func (c *ApiService) CreateServiceConversationScopedWebhookWithCtx(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) @@ -105,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -122,6 +128,11 @@ 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.DeleteServiceConversationScopedWebhookWithCtx(context.TODO(), ChatServiceSid, ConversationSid, Sid) +} + +// Remove an existing webhook scoped to the conversation +func (c *ApiService) DeleteServiceConversationScopedWebhookWithCtx(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) @@ -130,7 +141,7 @@ func (c *ApiService) DeleteServiceConversationScopedWebhook(ChatServiceSid strin data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -142,6 +153,11 @@ 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.FetchServiceConversationScopedWebhookWithCtx(context.TODO(), ChatServiceSid, ConversationSid, Sid) +} + +// Fetch the configuration of a conversation-scoped webhook +func (c *ApiService) FetchServiceConversationScopedWebhookWithCtx(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) @@ -150,7 +166,7 @@ func (c *ApiService) FetchServiceConversationScopedWebhook(ChatServiceSid string data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -184,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.PageServiceConversationScopedWebhookWithCtx(context.TODO(), ChatServiceSid, ConversationSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ServiceConversationScopedWebhook records from the API. Request is executed immediately. +func (c *ApiService) PageServiceConversationScopedWebhookWithCtx(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) @@ -203,7 +224,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -220,7 +241,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.ListServiceConversationScopedWebhookWithCtx(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) ListServiceConversationScopedWebhookWithCtx(ctx context.Context, ChatServiceSid string, ConversationSid string, params *ListServiceConversationScopedWebhookParams) ([]ConversationsV1ServiceConversationScopedWebhook, error) { + response, errors := c.StreamServiceConversationScopedWebhookWithCtx(ctx, ChatServiceSid, ConversationSid, params) records := make([]ConversationsV1ServiceConversationScopedWebhook, 0) for record := range response { @@ -236,6 +262,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.StreamServiceConversationScopedWebhookWithCtx(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) StreamServiceConversationScopedWebhookWithCtx(ctx context.Context, ChatServiceSid string, ConversationSid string, params *ListServiceConversationScopedWebhookParams) (chan ConversationsV1ServiceConversationScopedWebhook, chan error) { if params == nil { params = &ListServiceConversationScopedWebhookParams{} } @@ -244,19 +275,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.PageServiceConversationScopedWebhookWithCtx(ctx, ChatServiceSid, ConversationSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamServiceConversationScopedWebhook(response, params, recordChannel, errorChannel) + go c.streamServiceConversationScopedWebhook(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) streamServiceConversationScopedWebhook(ctx context.Context, response *ListServiceConversationScopedWebhookResponse, params *ListServiceConversationScopedWebhookParams, recordChannel chan ConversationsV1ServiceConversationScopedWebhook, errorChannel chan error) { curRecord := 1 for response != nil { @@ -271,7 +302,7 @@ func (c *ApiService) streamServiceConversationScopedWebhook(response *ListServic } } - record, err := client.GetNext(c.baseURL, response, c.getNextListServiceConversationScopedWebhookResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListServiceConversationScopedWebhookResponse) if err != nil { errorChannel <- err break @@ -286,11 +317,11 @@ func (c *ApiService) streamServiceConversationScopedWebhook(response *ListServic close(errorChannel) } -func (c *ApiService) getNextListServiceConversationScopedWebhookResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListServiceConversationScopedWebhookResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -341,6 +372,11 @@ 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.UpdateServiceConversationScopedWebhookWithCtx(context.TODO(), ChatServiceSid, ConversationSid, Sid, params) +} + +// Update an existing conversation-scoped webhook +func (c *ApiService) UpdateServiceConversationScopedWebhookWithCtx(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) @@ -369,7 +405,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.Post(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 745cea43f..39973014d 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.PageServiceParticipantConversationWithCtx(context.TODO(), ChatServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ServiceParticipantConversation records from the API. Request is executed immediately. +func (c *ApiService) PageServiceParticipantConversationWithCtx(ctx context.Context, ChatServiceSid string, params *ListServiceParticipantConversationParams, pageToken, pageNumber string) (*ListServiceParticipantConversationResponse, error) { path := "/v1/Services/{ChatServiceSid}/ParticipantConversations" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) @@ -78,7 +84,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -95,7 +101,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.ListServiceParticipantConversationWithCtx(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) ListServiceParticipantConversationWithCtx(ctx context.Context, ChatServiceSid string, params *ListServiceParticipantConversationParams) ([]ConversationsV1ServiceParticipantConversation, error) { + response, errors := c.StreamServiceParticipantConversationWithCtx(ctx, ChatServiceSid, params) records := make([]ConversationsV1ServiceParticipantConversation, 0) for record := range response { @@ -111,6 +122,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.StreamServiceParticipantConversationWithCtx(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) StreamServiceParticipantConversationWithCtx(ctx context.Context, ChatServiceSid string, params *ListServiceParticipantConversationParams) (chan ConversationsV1ServiceParticipantConversation, chan error) { if params == nil { params = &ListServiceParticipantConversationParams{} } @@ -119,19 +135,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.PageServiceParticipantConversationWithCtx(ctx, ChatServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamServiceParticipantConversation(response, params, recordChannel, errorChannel) + go c.streamServiceParticipantConversation(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) streamServiceParticipantConversation(ctx context.Context, response *ListServiceParticipantConversationResponse, params *ListServiceParticipantConversationParams, recordChannel chan ConversationsV1ServiceParticipantConversation, errorChannel chan error) { curRecord := 1 for response != nil { @@ -146,7 +162,7 @@ func (c *ApiService) streamServiceParticipantConversation(response *ListServiceP } } - record, err := client.GetNext(c.baseURL, response, c.getNextListServiceParticipantConversationResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListServiceParticipantConversationResponse) if err != nil { errorChannel <- err break @@ -161,11 +177,11 @@ func (c *ApiService) streamServiceParticipantConversation(response *ListServiceP close(errorChannel) } -func (c *ApiService) getNextListServiceParticipantConversationResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListServiceParticipantConversationResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 9e97aa28d..880934b08 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,11 @@ 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.CreateServiceRoleWithCtx(context.TODO(), ChatServiceSid, params) +} + +// Create a new user role in your service +func (c *ApiService) CreateServiceRoleWithCtx(ctx context.Context, ChatServiceSid string, params *CreateServiceRoleParams) (*ConversationsV1ServiceRole, error) { path := "/v1/Services/{ChatServiceSid}/Roles" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) @@ -66,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -83,6 +89,11 @@ 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.DeleteServiceRoleWithCtx(context.TODO(), ChatServiceSid, Sid) +} + +// Remove a user role from your service +func (c *ApiService) DeleteServiceRoleWithCtx(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) @@ -90,7 +101,7 @@ func (c *ApiService) DeleteServiceRole(ChatServiceSid string, Sid string) error data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -102,6 +113,11 @@ 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.FetchServiceRoleWithCtx(context.TODO(), ChatServiceSid, Sid) +} + +// Fetch a user role from your service +func (c *ApiService) FetchServiceRoleWithCtx(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) @@ -109,7 +125,7 @@ func (c *ApiService) FetchServiceRole(ChatServiceSid string, Sid string) (*Conve data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -143,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.PageServiceRoleWithCtx(context.TODO(), ChatServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ServiceRole records from the API. Request is executed immediately. +func (c *ApiService) PageServiceRoleWithCtx(ctx context.Context, ChatServiceSid string, params *ListServiceRoleParams, pageToken, pageNumber string) (*ListServiceRoleResponse, error) { path := "/v1/Services/{ChatServiceSid}/Roles" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) @@ -161,7 +182,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -178,7 +199,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.ListServiceRoleWithCtx(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) ListServiceRoleWithCtx(ctx context.Context, ChatServiceSid string, params *ListServiceRoleParams) ([]ConversationsV1ServiceRole, error) { + response, errors := c.StreamServiceRoleWithCtx(ctx, ChatServiceSid, params) records := make([]ConversationsV1ServiceRole, 0) for record := range response { @@ -194,6 +220,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.StreamServiceRoleWithCtx(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) StreamServiceRoleWithCtx(ctx context.Context, ChatServiceSid string, params *ListServiceRoleParams) (chan ConversationsV1ServiceRole, chan error) { if params == nil { params = &ListServiceRoleParams{} } @@ -202,19 +233,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.PageServiceRoleWithCtx(ctx, ChatServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamServiceRole(response, params, recordChannel, errorChannel) + go c.streamServiceRole(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) streamServiceRole(ctx context.Context, response *ListServiceRoleResponse, params *ListServiceRoleParams, recordChannel chan ConversationsV1ServiceRole, errorChannel chan error) { curRecord := 1 for response != nil { @@ -229,7 +260,7 @@ func (c *ApiService) streamServiceRole(response *ListServiceRoleResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListServiceRoleResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListServiceRoleResponse) if err != nil { errorChannel <- err break @@ -244,11 +275,11 @@ func (c *ApiService) streamServiceRole(response *ListServiceRoleResponse, params close(errorChannel) } -func (c *ApiService) getNextListServiceRoleResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListServiceRoleResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -275,6 +306,11 @@ 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.UpdateServiceRoleWithCtx(context.TODO(), ChatServiceSid, Sid, params) +} + +// Update an existing user role in your service +func (c *ApiService) UpdateServiceRoleWithCtx(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) @@ -288,7 +324,7 @@ func (c *ApiService) UpdateServiceRole(ChatServiceSid string, Sid string, params } } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 59cd24513..3f9effa0f 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,11 @@ 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.CreateServiceUserWithCtx(context.TODO(), ChatServiceSid, params) +} + +// Add a new conversation user to your service +func (c *ApiService) CreateServiceUserWithCtx(ctx context.Context, ChatServiceSid string, params *CreateServiceUserParams) (*ConversationsV1ServiceUser, error) { path := "/v1/Services/{ChatServiceSid}/Users" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) @@ -83,7 +89,7 @@ func (c *ApiService) CreateServiceUser(ChatServiceSid string, params *CreateServ headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -111,6 +117,11 @@ 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.DeleteServiceUserWithCtx(context.TODO(), ChatServiceSid, Sid, params) +} + +// Remove a conversation user from your service +func (c *ApiService) DeleteServiceUserWithCtx(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) @@ -122,7 +133,7 @@ func (c *ApiService) DeleteServiceUser(ChatServiceSid string, Sid string, params headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -134,6 +145,11 @@ 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.FetchServiceUserWithCtx(context.TODO(), ChatServiceSid, Sid) +} + +// Fetch a conversation user from your service +func (c *ApiService) FetchServiceUserWithCtx(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) @@ -141,7 +157,7 @@ func (c *ApiService) FetchServiceUser(ChatServiceSid string, Sid string) (*Conve data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -175,6 +191,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.PageServiceUserWithCtx(context.TODO(), ChatServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ServiceUser records from the API. Request is executed immediately. +func (c *ApiService) PageServiceUserWithCtx(ctx context.Context, ChatServiceSid string, params *ListServiceUserParams, pageToken, pageNumber string) (*ListServiceUserResponse, error) { path := "/v1/Services/{ChatServiceSid}/Users" path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) @@ -193,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -210,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.ListServiceUserWithCtx(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) ListServiceUserWithCtx(ctx context.Context, ChatServiceSid string, params *ListServiceUserParams) ([]ConversationsV1ServiceUser, error) { + response, errors := c.StreamServiceUserWithCtx(ctx, ChatServiceSid, params) records := make([]ConversationsV1ServiceUser, 0) for record := range response { @@ -226,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.StreamServiceUserWithCtx(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) StreamServiceUserWithCtx(ctx context.Context, ChatServiceSid string, params *ListServiceUserParams) (chan ConversationsV1ServiceUser, chan error) { if params == nil { params = &ListServiceUserParams{} } @@ -234,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.PageServiceUserWithCtx(ctx, ChatServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamServiceUser(response, params, recordChannel, errorChannel) + go c.streamServiceUser(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) streamServiceUser(ctx context.Context, response *ListServiceUserResponse, params *ListServiceUserParams, recordChannel chan ConversationsV1ServiceUser, errorChannel chan error) { curRecord := 1 for response != nil { @@ -261,7 +292,7 @@ func (c *ApiService) streamServiceUser(response *ListServiceUserResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListServiceUserResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListServiceUserResponse) if err != nil { errorChannel <- err break @@ -276,11 +307,11 @@ func (c *ApiService) streamServiceUser(response *ListServiceUserResponse, params close(errorChannel) } -func (c *ApiService) getNextListServiceUserResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListServiceUserResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -325,6 +356,11 @@ 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.UpdateServiceUserWithCtx(context.TODO(), ChatServiceSid, Sid, params) +} + +// Update an existing conversation user in your service +func (c *ApiService) UpdateServiceUserWithCtx(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) @@ -346,7 +382,7 @@ func (c *ApiService) UpdateServiceUser(ChatServiceSid string, Sid string, params headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 9db74c531..2b9ae0c2d 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,11 @@ import ( // Delete a specific User Conversation. func (c *ApiService) DeleteServiceUserConversation(ChatServiceSid string, UserSid string, ConversationSid string) error { + return c.DeleteServiceUserConversationWithCtx(context.TODO(), ChatServiceSid, UserSid, ConversationSid) +} + +// Delete a specific User Conversation. +func (c *ApiService) DeleteServiceUserConversationWithCtx(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) @@ -34,7 +40,7 @@ func (c *ApiService) DeleteServiceUserConversation(ChatServiceSid string, UserSi data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -46,6 +52,11 @@ 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.FetchServiceUserConversationWithCtx(context.TODO(), ChatServiceSid, UserSid, ConversationSid) +} + +// Fetch a specific User Conversation. +func (c *ApiService) FetchServiceUserConversationWithCtx(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) @@ -54,7 +65,7 @@ func (c *ApiService) FetchServiceUserConversation(ChatServiceSid string, UserSid data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -88,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.PageServiceUserConversationWithCtx(context.TODO(), ChatServiceSid, UserSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ServiceUserConversation records from the API. Request is executed immediately. +func (c *ApiService) PageServiceUserConversationWithCtx(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) @@ -107,7 +123,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -124,7 +140,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.ListServiceUserConversationWithCtx(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) ListServiceUserConversationWithCtx(ctx context.Context, ChatServiceSid string, UserSid string, params *ListServiceUserConversationParams) ([]ConversationsV1ServiceUserConversation, error) { + response, errors := c.StreamServiceUserConversationWithCtx(ctx, ChatServiceSid, UserSid, params) records := make([]ConversationsV1ServiceUserConversation, 0) for record := range response { @@ -140,6 +161,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.StreamServiceUserConversationWithCtx(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) StreamServiceUserConversationWithCtx(ctx context.Context, ChatServiceSid string, UserSid string, params *ListServiceUserConversationParams) (chan ConversationsV1ServiceUserConversation, chan error) { if params == nil { params = &ListServiceUserConversationParams{} } @@ -148,19 +174,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.PageServiceUserConversationWithCtx(ctx, ChatServiceSid, UserSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamServiceUserConversation(response, params, recordChannel, errorChannel) + go c.streamServiceUserConversation(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) streamServiceUserConversation(ctx context.Context, response *ListServiceUserConversationResponse, params *ListServiceUserConversationParams, recordChannel chan ConversationsV1ServiceUserConversation, errorChannel chan error) { curRecord := 1 for response != nil { @@ -175,7 +201,7 @@ func (c *ApiService) streamServiceUserConversation(response *ListServiceUserConv } } - record, err := client.GetNext(c.baseURL, response, c.getNextListServiceUserConversationResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListServiceUserConversationResponse) if err != nil { errorChannel <- err break @@ -190,11 +216,11 @@ func (c *ApiService) streamServiceUserConversation(response *ListServiceUserConv close(errorChannel) } -func (c *ApiService) getNextListServiceUserConversationResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListServiceUserConversationResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -233,6 +259,11 @@ 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.UpdateServiceUserConversationWithCtx(context.TODO(), ChatServiceSid, UserSid, ConversationSid, params) +} + +// Update a specific User Conversation. +func (c *ApiService) UpdateServiceUserConversationWithCtx(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) @@ -251,7 +282,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.Post(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 a4b7c6977..e555e87ba 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,11 @@ 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.CreateUserWithCtx(context.TODO(), params) +} + +// Add a new conversation user to your account's default service +func (c *ApiService) CreateUserWithCtx(ctx context.Context, params *CreateUserParams) (*ConversationsV1User, error) { path := "/v1/Users" data := url.Values{} @@ -82,7 +88,7 @@ func (c *ApiService) CreateUser(params *CreateUserParams) (*ConversationsV1User, headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -110,6 +116,11 @@ 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.DeleteUserWithCtx(context.TODO(), Sid, params) +} + +// Remove a conversation user from your account's default service +func (c *ApiService) DeleteUserWithCtx(ctx context.Context, Sid string, params *DeleteUserParams) error { path := "/v1/Users/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -120,7 +131,7 @@ func (c *ApiService) DeleteUser(Sid string, params *DeleteUserParams) error { headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -132,13 +143,18 @@ 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.FetchUserWithCtx(context.TODO(), Sid) +} + +// Fetch a conversation user from your account's default service +func (c *ApiService) FetchUserWithCtx(ctx context.Context, Sid string) (*ConversationsV1User, error) { path := "/v1/Users/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -172,6 +188,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.PageUserWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of User records from the API. Request is executed immediately. +func (c *ApiService) PageUserWithCtx(ctx context.Context, params *ListUserParams, pageToken, pageNumber string) (*ListUserResponse, error) { path := "/v1/Users" data := url.Values{} @@ -188,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -205,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.ListUserWithCtx(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) ListUserWithCtx(ctx context.Context, params *ListUserParams) ([]ConversationsV1User, error) { + response, errors := c.StreamUserWithCtx(ctx, params) records := make([]ConversationsV1User, 0) for record := range response { @@ -221,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.StreamUserWithCtx(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) StreamUserWithCtx(ctx context.Context, params *ListUserParams) (chan ConversationsV1User, chan error) { if params == nil { params = &ListUserParams{} } @@ -229,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.PageUserWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUser(response, params, recordChannel, errorChannel) + go c.streamUser(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) streamUser(ctx context.Context, response *ListUserResponse, params *ListUserParams, recordChannel chan ConversationsV1User, errorChannel chan error) { curRecord := 1 for response != nil { @@ -256,7 +287,7 @@ func (c *ApiService) streamUser(response *ListUserResponse, params *ListUserPara } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUserResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListUserResponse) if err != nil { errorChannel <- err break @@ -271,11 +302,11 @@ func (c *ApiService) streamUser(response *ListUserResponse, params *ListUserPara close(errorChannel) } -func (c *ApiService) getNextListUserResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUserResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -320,6 +351,11 @@ 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.UpdateUserWithCtx(context.TODO(), Sid, params) +} + +// Update an existing conversation user in your account's default service +func (c *ApiService) UpdateUserWithCtx(ctx context.Context, Sid string, params *UpdateUserParams) (*ConversationsV1User, error) { path := "/v1/Users/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -340,7 +376,7 @@ func (c *ApiService) UpdateUser(Sid string, params *UpdateUserParams) (*Conversa headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 9e31f8968..98e85e072 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,11 @@ import ( // Delete a specific User Conversation. func (c *ApiService) DeleteUserConversation(UserSid string, ConversationSid string) error { + return c.DeleteUserConversationWithCtx(context.TODO(), UserSid, ConversationSid) +} + +// Delete a specific User Conversation. +func (c *ApiService) DeleteUserConversationWithCtx(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) @@ -33,7 +39,7 @@ func (c *ApiService) DeleteUserConversation(UserSid string, ConversationSid stri data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -45,6 +51,11 @@ 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.FetchUserConversationWithCtx(context.TODO(), UserSid, ConversationSid) +} + +// Fetch a specific User Conversation. +func (c *ApiService) FetchUserConversationWithCtx(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) @@ -52,7 +63,7 @@ func (c *ApiService) FetchUserConversation(UserSid string, ConversationSid strin data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -86,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.PageUserConversationWithCtx(context.TODO(), UserSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of UserConversation records from the API. Request is executed immediately. +func (c *ApiService) PageUserConversationWithCtx(ctx context.Context, UserSid string, params *ListUserConversationParams, pageToken, pageNumber string) (*ListUserConversationResponse, error) { path := "/v1/Users/{UserSid}/Conversations" path = strings.Replace(path, "{"+"UserSid"+"}", UserSid, -1) @@ -104,7 +120,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -121,7 +137,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.ListUserConversationWithCtx(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) ListUserConversationWithCtx(ctx context.Context, UserSid string, params *ListUserConversationParams) ([]ConversationsV1UserConversation, error) { + response, errors := c.StreamUserConversationWithCtx(ctx, UserSid, params) records := make([]ConversationsV1UserConversation, 0) for record := range response { @@ -137,6 +158,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.StreamUserConversationWithCtx(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) StreamUserConversationWithCtx(ctx context.Context, UserSid string, params *ListUserConversationParams) (chan ConversationsV1UserConversation, chan error) { if params == nil { params = &ListUserConversationParams{} } @@ -145,19 +171,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.PageUserConversationWithCtx(ctx, UserSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUserConversation(response, params, recordChannel, errorChannel) + go c.streamUserConversation(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) streamUserConversation(ctx context.Context, response *ListUserConversationResponse, params *ListUserConversationParams, recordChannel chan ConversationsV1UserConversation, errorChannel chan error) { curRecord := 1 for response != nil { @@ -172,7 +198,7 @@ func (c *ApiService) streamUserConversation(response *ListUserConversationRespon } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUserConversationResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListUserConversationResponse) if err != nil { errorChannel <- err break @@ -187,11 +213,11 @@ func (c *ApiService) streamUserConversation(response *ListUserConversationRespon close(errorChannel) } -func (c *ApiService) getNextListUserConversationResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUserConversationResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -230,6 +256,11 @@ func (params *UpdateUserConversationParams) SetLastReadMessageIndex(LastReadMess // Update a specific User Conversation. func (c *ApiService) UpdateUserConversation(UserSid string, ConversationSid string, params *UpdateUserConversationParams) (*ConversationsV1UserConversation, error) { + return c.UpdateUserConversationWithCtx(context.TODO(), UserSid, ConversationSid, params) +} + +// Update a specific User Conversation. +func (c *ApiService) UpdateUserConversationWithCtx(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) @@ -247,7 +278,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.Post(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 89bb15ad1..30c0460d9 100644 --- a/rest/events/v1/api_service.go +++ b/rest/events/v1/api_service.go @@ -20,10 +20,14 @@ import ( type ApiService struct { baseURL string - requestHandler *twilio.RequestHandler + requestHandler *twilio.RequestHandlerWithCtx } func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { + return NewApiServiceWithCtx(twilio.UpgradeRequestHandler(requestHandler)) +} + +func NewApiServiceWithCtx(requestHandler *twilio.RequestHandlerWithCtx) *ApiService { return &ApiService{ requestHandler: requestHandler, baseURL: "https://events.twilio.com", @@ -33,3 +37,7 @@ func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { func NewApiServiceWithClient(client twilio.BaseClient) *ApiService { return NewApiService(twilio.NewRequestHandler(client)) } + +func NewApiServiceWithClientWithCtx(client twilio.BaseClientWithCtx) *ApiService { + return NewApiServiceWithCtx(twilio.NewRequestHandlerWithCtx(client)) +} diff --git a/rest/events/v1/schemas.go b/rest/events/v1/schemas.go index f17c80ec5..bc08ac93f 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,13 +23,18 @@ import ( // Fetch a specific schema with its nested versions. func (c *ApiService) FetchSchema(Id string) (*EventsV1Schema, error) { + return c.FetchSchemaWithCtx(context.TODO(), Id) +} + +// Fetch a specific schema with its nested versions. +func (c *ApiService) FetchSchemaWithCtx(ctx context.Context, Id string) (*EventsV1Schema, error) { path := "/v1/Schemas/{Id}" path = strings.Replace(path, "{"+"Id"+"}", Id, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(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 84aaa0292..0cdd2fbcc 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,11 @@ import ( // Fetch a specific schema and version. func (c *ApiService) FetchSchemaVersion(Id string, SchemaVersion int) (*EventsV1SchemaVersion, error) { + return c.FetchSchemaVersionWithCtx(context.TODO(), Id, SchemaVersion) +} + +// Fetch a specific schema and version. +func (c *ApiService) FetchSchemaVersionWithCtx(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) @@ -32,7 +38,7 @@ func (c *ApiService) FetchSchemaVersion(Id string, SchemaVersion int) (*EventsV1 data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -66,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.PageSchemaVersionWithCtx(context.TODO(), Id, params, pageToken, pageNumber) +} + +// Retrieve a single page of SchemaVersion records from the API. Request is executed immediately. +func (c *ApiService) PageSchemaVersionWithCtx(ctx context.Context, Id string, params *ListSchemaVersionParams, pageToken, pageNumber string) (*ListSchemaVersionResponse, error) { path := "/v1/Schemas/{Id}/Versions" path = strings.Replace(path, "{"+"Id"+"}", Id, -1) @@ -84,7 +95,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -101,7 +112,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.ListSchemaVersionWithCtx(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) ListSchemaVersionWithCtx(ctx context.Context, Id string, params *ListSchemaVersionParams) ([]EventsV1SchemaVersion, error) { + response, errors := c.StreamSchemaVersionWithCtx(ctx, Id, params) records := make([]EventsV1SchemaVersion, 0) for record := range response { @@ -117,6 +133,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.StreamSchemaVersionWithCtx(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) StreamSchemaVersionWithCtx(ctx context.Context, Id string, params *ListSchemaVersionParams) (chan EventsV1SchemaVersion, chan error) { if params == nil { params = &ListSchemaVersionParams{} } @@ -125,19 +146,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.PageSchemaVersionWithCtx(ctx, Id, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSchemaVersion(response, params, recordChannel, errorChannel) + go c.streamSchemaVersion(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) streamSchemaVersion(ctx context.Context, response *ListSchemaVersionResponse, params *ListSchemaVersionParams, recordChannel chan EventsV1SchemaVersion, errorChannel chan error) { curRecord := 1 for response != nil { @@ -152,7 +173,7 @@ func (c *ApiService) streamSchemaVersion(response *ListSchemaVersionResponse, pa } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSchemaVersionResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListSchemaVersionResponse) if err != nil { errorChannel <- err break @@ -167,11 +188,11 @@ func (c *ApiService) streamSchemaVersion(response *ListSchemaVersionResponse, pa close(errorChannel) } -func (c *ApiService) getNextListSchemaVersionResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSchemaVersionResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 d8be25b86..5f210ea39 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,11 @@ func (params *CreateSinkParams) SetSinkType(SinkType string) *CreateSinkParams { // Create a new Sink func (c *ApiService) CreateSink(params *CreateSinkParams) (*EventsV1Sink, error) { + return c.CreateSinkWithCtx(context.TODO(), params) +} + +// Create a new Sink +func (c *ApiService) CreateSinkWithCtx(ctx context.Context, params *CreateSinkParams) (*EventsV1Sink, error) { path := "/v1/Sinks" data := url.Values{} @@ -69,7 +75,7 @@ func (c *ApiService) CreateSink(params *CreateSinkParams) (*EventsV1Sink, error) data.Set("SinkType", *params.SinkType) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -86,13 +92,18 @@ func (c *ApiService) CreateSink(params *CreateSinkParams) (*EventsV1Sink, error) // Delete a specific Sink. func (c *ApiService) DeleteSink(Sid string) error { + return c.DeleteSinkWithCtx(context.TODO(), Sid) +} + +// Delete a specific Sink. +func (c *ApiService) DeleteSinkWithCtx(ctx context.Context, Sid string) error { path := "/v1/Sinks/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -104,13 +115,18 @@ func (c *ApiService) DeleteSink(Sid string) error { // Fetch a specific Sink. func (c *ApiService) FetchSink(Sid string) (*EventsV1Sink, error) { + return c.FetchSinkWithCtx(context.TODO(), Sid) +} + +// Fetch a specific Sink. +func (c *ApiService) FetchSinkWithCtx(ctx context.Context, Sid string) (*EventsV1Sink, error) { path := "/v1/Sinks/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -156,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.PageSinkWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Sink records from the API. Request is executed immediately. +func (c *ApiService) PageSinkWithCtx(ctx context.Context, params *ListSinkParams, pageToken, pageNumber string) (*ListSinkResponse, error) { path := "/v1/Sinks" data := url.Values{} @@ -178,7 +199,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -195,7 +216,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.ListSinkWithCtx(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) ListSinkWithCtx(ctx context.Context, params *ListSinkParams) ([]EventsV1Sink, error) { + response, errors := c.StreamSinkWithCtx(ctx, params) records := make([]EventsV1Sink, 0) for record := range response { @@ -211,6 +237,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.StreamSinkWithCtx(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) StreamSinkWithCtx(ctx context.Context, params *ListSinkParams) (chan EventsV1Sink, chan error) { if params == nil { params = &ListSinkParams{} } @@ -219,19 +250,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.PageSinkWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSink(response, params, recordChannel, errorChannel) + go c.streamSink(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) streamSink(ctx context.Context, response *ListSinkResponse, params *ListSinkParams, recordChannel chan EventsV1Sink, errorChannel chan error) { curRecord := 1 for response != nil { @@ -246,7 +277,7 @@ func (c *ApiService) streamSink(response *ListSinkResponse, params *ListSinkPara } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSinkResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListSinkResponse) if err != nil { errorChannel <- err break @@ -261,11 +292,11 @@ func (c *ApiService) streamSink(response *ListSinkResponse, params *ListSinkPara close(errorChannel) } -func (c *ApiService) getNextListSinkResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSinkResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -292,6 +323,11 @@ func (params *UpdateSinkParams) SetDescription(Description string) *UpdateSinkPa // Update a specific Sink func (c *ApiService) UpdateSink(Sid string, params *UpdateSinkParams) (*EventsV1Sink, error) { + return c.UpdateSinkWithCtx(context.TODO(), Sid, params) +} + +// Update a specific Sink +func (c *ApiService) UpdateSinkWithCtx(ctx context.Context, Sid string, params *UpdateSinkParams) (*EventsV1Sink, error) { path := "/v1/Sinks/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -302,7 +338,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.Post(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 4fb88f431..84d82ac0f 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,13 +23,18 @@ import ( // Create a new Sink Test Event for the given Sink. func (c *ApiService) CreateSinkTest(Sid string) (*EventsV1SinkTest, error) { + return c.CreateSinkTestWithCtx(context.TODO(), Sid) +} + +// Create a new Sink Test Event for the given Sink. +func (c *ApiService) CreateSinkTestWithCtx(ctx context.Context, Sid string) (*EventsV1SinkTest, error) { path := "/v1/Sinks/{Sid}/Test" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 691d80272..3e6a5878a 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,11 @@ 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.CreateSinkValidateWithCtx(context.TODO(), Sid, params) +} + +// Validate that a test event for a Sink was received. +func (c *ApiService) CreateSinkValidateWithCtx(ctx context.Context, Sid string, params *CreateSinkValidateParams) (*EventsV1SinkValidate, error) { path := "/v1/Sinks/{Sid}/Validate" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -43,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.Post(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 d7dcbb567..6bda9da94 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,11 @@ func (params *CreateSubscriptionParams) SetTypes(Types []interface{}) *CreateSub // Create a new Subscription. func (c *ApiService) CreateSubscription(params *CreateSubscriptionParams) (*EventsV1Subscription, error) { + return c.CreateSubscriptionWithCtx(context.TODO(), params) +} + +// Create a new Subscription. +func (c *ApiService) CreateSubscriptionWithCtx(ctx context.Context, params *CreateSubscriptionParams) (*EventsV1Subscription, error) { path := "/v1/Subscriptions" data := url.Values{} @@ -71,7 +77,7 @@ func (c *ApiService) CreateSubscription(params *CreateSubscriptionParams) (*Even } } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -88,13 +94,18 @@ func (c *ApiService) CreateSubscription(params *CreateSubscriptionParams) (*Even // Delete a specific Subscription. func (c *ApiService) DeleteSubscription(Sid string) error { + return c.DeleteSubscriptionWithCtx(context.TODO(), Sid) +} + +// Delete a specific Subscription. +func (c *ApiService) DeleteSubscriptionWithCtx(ctx context.Context, Sid string) error { path := "/v1/Subscriptions/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -106,13 +117,18 @@ func (c *ApiService) DeleteSubscription(Sid string) error { // Fetch a specific Subscription. func (c *ApiService) FetchSubscription(Sid string) (*EventsV1Subscription, error) { + return c.FetchSubscriptionWithCtx(context.TODO(), Sid) +} + +// Fetch a specific Subscription. +func (c *ApiService) FetchSubscriptionWithCtx(ctx context.Context, Sid string) (*EventsV1Subscription, error) { path := "/v1/Subscriptions/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -152,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.PageSubscriptionWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Subscription records from the API. Request is executed immediately. +func (c *ApiService) PageSubscriptionWithCtx(ctx context.Context, params *ListSubscriptionParams, pageToken, pageNumber string) (*ListSubscriptionResponse, error) { path := "/v1/Subscriptions" data := url.Values{} @@ -171,7 +192,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -188,7 +209,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.ListSubscriptionWithCtx(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) ListSubscriptionWithCtx(ctx context.Context, params *ListSubscriptionParams) ([]EventsV1Subscription, error) { + response, errors := c.StreamSubscriptionWithCtx(ctx, params) records := make([]EventsV1Subscription, 0) for record := range response { @@ -204,6 +230,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.StreamSubscriptionWithCtx(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) StreamSubscriptionWithCtx(ctx context.Context, params *ListSubscriptionParams) (chan EventsV1Subscription, chan error) { if params == nil { params = &ListSubscriptionParams{} } @@ -212,19 +243,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.PageSubscriptionWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSubscription(response, params, recordChannel, errorChannel) + go c.streamSubscription(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) streamSubscription(ctx context.Context, response *ListSubscriptionResponse, params *ListSubscriptionParams, recordChannel chan EventsV1Subscription, errorChannel chan error) { curRecord := 1 for response != nil { @@ -239,7 +270,7 @@ func (c *ApiService) streamSubscription(response *ListSubscriptionResponse, para } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSubscriptionResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListSubscriptionResponse) if err != nil { errorChannel <- err break @@ -254,11 +285,11 @@ func (c *ApiService) streamSubscription(response *ListSubscriptionResponse, para close(errorChannel) } -func (c *ApiService) getNextListSubscriptionResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSubscriptionResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -291,6 +322,11 @@ func (params *UpdateSubscriptionParams) SetSinkSid(SinkSid string) *UpdateSubscr // Update a Subscription. func (c *ApiService) UpdateSubscription(Sid string, params *UpdateSubscriptionParams) (*EventsV1Subscription, error) { + return c.UpdateSubscriptionWithCtx(context.TODO(), Sid, params) +} + +// Update a Subscription. +func (c *ApiService) UpdateSubscriptionWithCtx(ctx context.Context, Sid string, params *UpdateSubscriptionParams) (*EventsV1Subscription, error) { path := "/v1/Subscriptions/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -304,7 +340,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.Post(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 0c2d85e0c..a2b5d4aef 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,11 @@ func (params *CreateSubscribedEventParams) SetSchemaVersion(SchemaVersion int) * // Create a new Subscribed Event type for the subscription func (c *ApiService) CreateSubscribedEvent(SubscriptionSid string, params *CreateSubscribedEventParams) (*EventsV1SubscribedEvent, error) { + return c.CreateSubscribedEventWithCtx(context.TODO(), SubscriptionSid, params) +} + +// Create a new Subscribed Event type for the subscription +func (c *ApiService) CreateSubscribedEventWithCtx(ctx context.Context, SubscriptionSid string, params *CreateSubscribedEventParams) (*EventsV1SubscribedEvent, error) { path := "/v1/Subscriptions/{SubscriptionSid}/SubscribedEvents" path = strings.Replace(path, "{"+"SubscriptionSid"+"}", SubscriptionSid, -1) @@ -55,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -72,6 +78,11 @@ 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.DeleteSubscribedEventWithCtx(context.TODO(), SubscriptionSid, Type) +} + +// Remove an event type from a subscription. +func (c *ApiService) DeleteSubscribedEventWithCtx(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) @@ -79,7 +90,7 @@ func (c *ApiService) DeleteSubscribedEvent(SubscriptionSid string, Type string) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -91,6 +102,11 @@ 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.FetchSubscribedEventWithCtx(context.TODO(), SubscriptionSid, Type) +} + +// Read an Event for a Subscription. +func (c *ApiService) FetchSubscribedEventWithCtx(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) @@ -98,7 +114,7 @@ func (c *ApiService) FetchSubscribedEvent(SubscriptionSid string, Type string) ( data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -132,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.PageSubscribedEventWithCtx(context.TODO(), SubscriptionSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of SubscribedEvent records from the API. Request is executed immediately. +func (c *ApiService) PageSubscribedEventWithCtx(ctx context.Context, SubscriptionSid string, params *ListSubscribedEventParams, pageToken, pageNumber string) (*ListSubscribedEventResponse, error) { path := "/v1/Subscriptions/{SubscriptionSid}/SubscribedEvents" path = strings.Replace(path, "{"+"SubscriptionSid"+"}", SubscriptionSid, -1) @@ -150,7 +171,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -167,7 +188,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.ListSubscribedEventWithCtx(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) ListSubscribedEventWithCtx(ctx context.Context, SubscriptionSid string, params *ListSubscribedEventParams) ([]EventsV1SubscribedEvent, error) { + response, errors := c.StreamSubscribedEventWithCtx(ctx, SubscriptionSid, params) records := make([]EventsV1SubscribedEvent, 0) for record := range response { @@ -183,6 +209,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.StreamSubscribedEventWithCtx(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) StreamSubscribedEventWithCtx(ctx context.Context, SubscriptionSid string, params *ListSubscribedEventParams) (chan EventsV1SubscribedEvent, chan error) { if params == nil { params = &ListSubscribedEventParams{} } @@ -191,19 +222,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.PageSubscribedEventWithCtx(ctx, SubscriptionSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSubscribedEvent(response, params, recordChannel, errorChannel) + go c.streamSubscribedEvent(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) streamSubscribedEvent(ctx context.Context, response *ListSubscribedEventResponse, params *ListSubscribedEventParams, recordChannel chan EventsV1SubscribedEvent, errorChannel chan error) { curRecord := 1 for response != nil { @@ -218,7 +249,7 @@ func (c *ApiService) streamSubscribedEvent(response *ListSubscribedEventResponse } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSubscribedEventResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListSubscribedEventResponse) if err != nil { errorChannel <- err break @@ -233,11 +264,11 @@ func (c *ApiService) streamSubscribedEvent(response *ListSubscribedEventResponse close(errorChannel) } -func (c *ApiService) getNextListSubscribedEventResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSubscribedEventResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -264,6 +295,11 @@ 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.UpdateSubscribedEventWithCtx(context.TODO(), SubscriptionSid, Type, params) +} + +// Update an Event for a Subscription. +func (c *ApiService) UpdateSubscribedEventWithCtx(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) @@ -275,7 +311,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.Post(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 a0423bc62..0cb459aec 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,13 +26,18 @@ import ( // Fetch a specific Event Type. func (c *ApiService) FetchEventType(Type string) (*EventsV1EventType, error) { + return c.FetchEventTypeWithCtx(context.TODO(), Type) +} + +// Fetch a specific Event Type. +func (c *ApiService) FetchEventTypeWithCtx(ctx context.Context, Type string) (*EventsV1EventType, error) { path := "/v1/Types/{Type}" path = strings.Replace(path, "{"+"Type"+"}", Type, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -71,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.PageEventTypeWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of EventType records from the API. Request is executed immediately. +func (c *ApiService) PageEventTypeWithCtx(ctx context.Context, params *ListEventTypeParams, pageToken, pageNumber string) (*ListEventTypeResponse, error) { path := "/v1/Types" data := url.Values{} @@ -90,7 +101,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -107,7 +118,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.ListEventTypeWithCtx(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) ListEventTypeWithCtx(ctx context.Context, params *ListEventTypeParams) ([]EventsV1EventType, error) { + response, errors := c.StreamEventTypeWithCtx(ctx, params) records := make([]EventsV1EventType, 0) for record := range response { @@ -123,6 +139,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.StreamEventTypeWithCtx(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) StreamEventTypeWithCtx(ctx context.Context, params *ListEventTypeParams) (chan EventsV1EventType, chan error) { if params == nil { params = &ListEventTypeParams{} } @@ -131,19 +152,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.PageEventTypeWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamEventType(response, params, recordChannel, errorChannel) + go c.streamEventType(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) streamEventType(ctx context.Context, response *ListEventTypeResponse, params *ListEventTypeParams, recordChannel chan EventsV1EventType, errorChannel chan error) { curRecord := 1 for response != nil { @@ -158,7 +179,7 @@ func (c *ApiService) streamEventType(response *ListEventTypeResponse, params *Li } } - record, err := client.GetNext(c.baseURL, response, c.getNextListEventTypeResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListEventTypeResponse) if err != nil { errorChannel <- err break @@ -173,11 +194,11 @@ func (c *ApiService) streamEventType(response *ListEventTypeResponse, params *Li close(errorChannel) } -func (c *ApiService) getNextListEventTypeResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListEventTypeResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/flex/v1/api_service.go b/rest/flex/v1/api_service.go index f6d8c27bc..85dae8c87 100644 --- a/rest/flex/v1/api_service.go +++ b/rest/flex/v1/api_service.go @@ -20,10 +20,14 @@ import ( type ApiService struct { baseURL string - requestHandler *twilio.RequestHandler + requestHandler *twilio.RequestHandlerWithCtx } func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { + return NewApiServiceWithCtx(twilio.UpgradeRequestHandler(requestHandler)) +} + +func NewApiServiceWithCtx(requestHandler *twilio.RequestHandlerWithCtx) *ApiService { return &ApiService{ requestHandler: requestHandler, baseURL: "https://flex-api.twilio.com", @@ -33,3 +37,7 @@ func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { func NewApiServiceWithClient(client twilio.BaseClient) *ApiService { return NewApiService(twilio.NewRequestHandler(client)) } + +func NewApiServiceWithClientWithCtx(client twilio.BaseClientWithCtx) *ApiService { + return NewApiServiceWithCtx(twilio.NewRequestHandlerWithCtx(client)) +} diff --git a/rest/flex/v1/channels.go b/rest/flex/v1/channels.go index ddf91c9f7..c07127677 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" @@ -90,6 +91,11 @@ func (params *CreateChannelParams) SetLongLived(LongLived bool) *CreateChannelPa // func (c *ApiService) CreateChannel(params *CreateChannelParams) (*FlexV1Channel, error) { + return c.CreateChannelWithCtx(context.TODO(), params) +} + +// +func (c *ApiService) CreateChannelWithCtx(ctx context.Context, params *CreateChannelParams) (*FlexV1Channel, error) { path := "/v1/Channels" data := url.Values{} @@ -126,7 +132,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -143,13 +149,18 @@ func (c *ApiService) CreateChannel(params *CreateChannelParams) (*FlexV1Channel, // func (c *ApiService) DeleteChannel(Sid string) error { + return c.DeleteChannelWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) DeleteChannelWithCtx(ctx context.Context, Sid string) error { path := "/v1/Channels/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -161,13 +172,18 @@ func (c *ApiService) DeleteChannel(Sid string) error { // func (c *ApiService) FetchChannel(Sid string) (*FlexV1Channel, error) { + return c.FetchChannelWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) FetchChannelWithCtx(ctx context.Context, Sid string) (*FlexV1Channel, error) { path := "/v1/Channels/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -201,6 +217,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.PageChannelWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Channel records from the API. Request is executed immediately. +func (c *ApiService) PageChannelWithCtx(ctx context.Context, params *ListChannelParams, pageToken, pageNumber string) (*ListChannelResponse, error) { path := "/v1/Channels" data := url.Values{} @@ -217,7 +238,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -234,7 +255,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.ListChannelWithCtx(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) ListChannelWithCtx(ctx context.Context, params *ListChannelParams) ([]FlexV1Channel, error) { + response, errors := c.StreamChannelWithCtx(ctx, params) records := make([]FlexV1Channel, 0) for record := range response { @@ -250,6 +276,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.StreamChannelWithCtx(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) StreamChannelWithCtx(ctx context.Context, params *ListChannelParams) (chan FlexV1Channel, chan error) { if params == nil { params = &ListChannelParams{} } @@ -258,19 +289,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.PageChannelWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamChannel(response, params, recordChannel, errorChannel) + go c.streamChannel(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) streamChannel(ctx context.Context, response *ListChannelResponse, params *ListChannelParams, recordChannel chan FlexV1Channel, errorChannel chan error) { curRecord := 1 for response != nil { @@ -285,7 +316,7 @@ func (c *ApiService) streamChannel(response *ListChannelResponse, params *ListCh } } - record, err := client.GetNext(c.baseURL, response, c.getNextListChannelResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListChannelResponse) if err != nil { errorChannel <- err break @@ -300,11 +331,11 @@ func (c *ApiService) streamChannel(response *ListChannelResponse, params *ListCh close(errorChannel) } -func (c *ApiService) getNextListChannelResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListChannelResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 a106cb399..581bc838c 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" ) @@ -32,6 +33,11 @@ func (params *FetchConfigurationParams) SetUiVersion(UiVersion string) *FetchCon // func (c *ApiService) FetchConfiguration(params *FetchConfigurationParams) (*FlexV1Configuration, error) { + return c.FetchConfigurationWithCtx(context.TODO(), params) +} + +// +func (c *ApiService) FetchConfigurationWithCtx(ctx context.Context, params *FetchConfigurationParams) (*FlexV1Configuration, error) { path := "/v1/Configuration" data := url.Values{} @@ -41,7 +47,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/flex/v1/flex_flows.go b/rest/flex/v1/flex_flows.go index 705066713..2ce742137 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" @@ -132,6 +133,11 @@ func (params *CreateFlexFlowParams) SetIntegrationRetryCount(IntegrationRetryCou // func (c *ApiService) CreateFlexFlow(params *CreateFlexFlowParams) (*FlexV1FlexFlow, error) { + return c.CreateFlexFlowWithCtx(context.TODO(), params) +} + +// +func (c *ApiService) CreateFlexFlowWithCtx(ctx context.Context, params *CreateFlexFlowParams) (*FlexV1FlexFlow, error) { path := "/v1/FlexFlows" data := url.Values{} @@ -189,7 +195,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -206,13 +212,18 @@ func (c *ApiService) CreateFlexFlow(params *CreateFlexFlowParams) (*FlexV1FlexFl // func (c *ApiService) DeleteFlexFlow(Sid string) error { + return c.DeleteFlexFlowWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) DeleteFlexFlowWithCtx(ctx context.Context, Sid string) error { path := "/v1/FlexFlows/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -224,13 +235,18 @@ func (c *ApiService) DeleteFlexFlow(Sid string) error { // func (c *ApiService) FetchFlexFlow(Sid string) (*FlexV1FlexFlow, error) { + return c.FetchFlexFlowWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) FetchFlexFlowWithCtx(ctx context.Context, Sid string) (*FlexV1FlexFlow, error) { path := "/v1/FlexFlows/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -270,6 +286,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.PageFlexFlowWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of FlexFlow records from the API. Request is executed immediately. +func (c *ApiService) PageFlexFlowWithCtx(ctx context.Context, params *ListFlexFlowParams, pageToken, pageNumber string) (*ListFlexFlowResponse, error) { path := "/v1/FlexFlows" data := url.Values{} @@ -289,7 +310,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -306,7 +327,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.ListFlexFlowWithCtx(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) ListFlexFlowWithCtx(ctx context.Context, params *ListFlexFlowParams) ([]FlexV1FlexFlow, error) { + response, errors := c.StreamFlexFlowWithCtx(ctx, params) records := make([]FlexV1FlexFlow, 0) for record := range response { @@ -322,6 +348,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.StreamFlexFlowWithCtx(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) StreamFlexFlowWithCtx(ctx context.Context, params *ListFlexFlowParams) (chan FlexV1FlexFlow, chan error) { if params == nil { params = &ListFlexFlowParams{} } @@ -330,19 +361,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.PageFlexFlowWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamFlexFlow(response, params, recordChannel, errorChannel) + go c.streamFlexFlow(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) streamFlexFlow(ctx context.Context, response *ListFlexFlowResponse, params *ListFlexFlowParams, recordChannel chan FlexV1FlexFlow, errorChannel chan error) { curRecord := 1 for response != nil { @@ -357,7 +388,7 @@ func (c *ApiService) streamFlexFlow(response *ListFlexFlowResponse, params *List } } - record, err := client.GetNext(c.baseURL, response, c.getNextListFlexFlowResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListFlexFlowResponse) if err != nil { errorChannel <- err break @@ -372,11 +403,11 @@ func (c *ApiService) streamFlexFlow(response *ListFlexFlowResponse, params *List close(errorChannel) } -func (c *ApiService) getNextListFlexFlowResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListFlexFlowResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -499,6 +530,11 @@ func (params *UpdateFlexFlowParams) SetIntegrationRetryCount(IntegrationRetryCou // func (c *ApiService) UpdateFlexFlow(Sid string, params *UpdateFlexFlowParams) (*FlexV1FlexFlow, error) { + return c.UpdateFlexFlowWithCtx(context.TODO(), Sid, params) +} + +// +func (c *ApiService) UpdateFlexFlowWithCtx(ctx context.Context, Sid string, params *UpdateFlexFlowParams) (*FlexV1FlexFlow, error) { path := "/v1/FlexFlows/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -557,7 +593,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.Post(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 26ffe3c68..977069540 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" @@ -39,6 +40,11 @@ func (params *CreateInteractionParams) SetRouting(Routing interface{}) *CreateIn // Create a new Interaction. func (c *ApiService) CreateInteraction(params *CreateInteractionParams) (*FlexV1Interaction, error) { + return c.CreateInteractionWithCtx(context.TODO(), params) +} + +// Create a new Interaction. +func (c *ApiService) CreateInteractionWithCtx(ctx context.Context, params *CreateInteractionParams) (*FlexV1Interaction, error) { path := "/v1/Interactions" data := url.Values{} @@ -63,7 +69,7 @@ func (c *ApiService) CreateInteraction(params *CreateInteractionParams) (*FlexV1 data.Set("Routing", string(v)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -80,13 +86,18 @@ func (c *ApiService) CreateInteraction(params *CreateInteractionParams) (*FlexV1 // func (c *ApiService) FetchInteraction(Sid string) (*FlexV1Interaction, error) { + return c.FetchInteractionWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) FetchInteractionWithCtx(ctx context.Context, Sid string) (*FlexV1Interaction, error) { path := "/v1/Interactions/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(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 000cf957a..ea57f38bc 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,11 @@ import ( // Fetch a Channel for an Interaction. func (c *ApiService) FetchInteractionChannel(InteractionSid string, Sid string) (*FlexV1InteractionChannel, error) { + return c.FetchInteractionChannelWithCtx(context.TODO(), InteractionSid, Sid) +} + +// Fetch a Channel for an Interaction. +func (c *ApiService) FetchInteractionChannelWithCtx(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) @@ -32,7 +38,7 @@ func (c *ApiService) FetchInteractionChannel(InteractionSid string, Sid string) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -66,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.PageInteractionChannelWithCtx(context.TODO(), InteractionSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of InteractionChannel records from the API. Request is executed immediately. +func (c *ApiService) PageInteractionChannelWithCtx(ctx context.Context, InteractionSid string, params *ListInteractionChannelParams, pageToken, pageNumber string) (*ListInteractionChannelResponse, error) { path := "/v1/Interactions/{InteractionSid}/Channels" path = strings.Replace(path, "{"+"InteractionSid"+"}", InteractionSid, -1) @@ -84,7 +95,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -101,7 +112,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.ListInteractionChannelWithCtx(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) ListInteractionChannelWithCtx(ctx context.Context, InteractionSid string, params *ListInteractionChannelParams) ([]FlexV1InteractionChannel, error) { + response, errors := c.StreamInteractionChannelWithCtx(ctx, InteractionSid, params) records := make([]FlexV1InteractionChannel, 0) for record := range response { @@ -117,6 +133,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.StreamInteractionChannelWithCtx(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) StreamInteractionChannelWithCtx(ctx context.Context, InteractionSid string, params *ListInteractionChannelParams) (chan FlexV1InteractionChannel, chan error) { if params == nil { params = &ListInteractionChannelParams{} } @@ -125,19 +146,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.PageInteractionChannelWithCtx(ctx, InteractionSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamInteractionChannel(response, params, recordChannel, errorChannel) + go c.streamInteractionChannel(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) streamInteractionChannel(ctx context.Context, response *ListInteractionChannelResponse, params *ListInteractionChannelParams, recordChannel chan FlexV1InteractionChannel, errorChannel chan error) { curRecord := 1 for response != nil { @@ -152,7 +173,7 @@ func (c *ApiService) streamInteractionChannel(response *ListInteractionChannelRe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListInteractionChannelResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListInteractionChannelResponse) if err != nil { errorChannel <- err break @@ -167,11 +188,11 @@ func (c *ApiService) streamInteractionChannel(response *ListInteractionChannelRe close(errorChannel) } -func (c *ApiService) getNextListInteractionChannelResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListInteractionChannelResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -204,6 +225,11 @@ func (params *UpdateInteractionChannelParams) SetRouting(Routing interface{}) *U // Update an existing Interaction Channel. func (c *ApiService) UpdateInteractionChannel(InteractionSid string, Sid string, params *UpdateInteractionChannelParams) (*FlexV1InteractionChannel, error) { + return c.UpdateInteractionChannelWithCtx(context.TODO(), InteractionSid, Sid, params) +} + +// Update an existing Interaction Channel. +func (c *ApiService) UpdateInteractionChannelWithCtx(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) @@ -224,7 +250,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.Post(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 9f831a849..85887e987 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,11 @@ func (params *CreateInteractionChannelInviteParams) SetRouting(Routing interface // Invite an Agent or a TaskQueue to a Channel. func (c *ApiService) CreateInteractionChannelInvite(InteractionSid string, ChannelSid string, params *CreateInteractionChannelInviteParams) (*FlexV1InteractionChannelInvite, error) { + return c.CreateInteractionChannelInviteWithCtx(context.TODO(), InteractionSid, ChannelSid, params) +} + +// Invite an Agent or a TaskQueue to a Channel. +func (c *ApiService) CreateInteractionChannelInviteWithCtx(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) @@ -53,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -87,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.PageInteractionChannelInviteWithCtx(context.TODO(), InteractionSid, ChannelSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of InteractionChannelInvite records from the API. Request is executed immediately. +func (c *ApiService) PageInteractionChannelInviteWithCtx(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) @@ -106,7 +117,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -123,7 +134,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.ListInteractionChannelInviteWithCtx(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) ListInteractionChannelInviteWithCtx(ctx context.Context, InteractionSid string, ChannelSid string, params *ListInteractionChannelInviteParams) ([]FlexV1InteractionChannelInvite, error) { + response, errors := c.StreamInteractionChannelInviteWithCtx(ctx, InteractionSid, ChannelSid, params) records := make([]FlexV1InteractionChannelInvite, 0) for record := range response { @@ -139,6 +155,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.StreamInteractionChannelInviteWithCtx(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) StreamInteractionChannelInviteWithCtx(ctx context.Context, InteractionSid string, ChannelSid string, params *ListInteractionChannelInviteParams) (chan FlexV1InteractionChannelInvite, chan error) { if params == nil { params = &ListInteractionChannelInviteParams{} } @@ -147,19 +168,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.PageInteractionChannelInviteWithCtx(ctx, InteractionSid, ChannelSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamInteractionChannelInvite(response, params, recordChannel, errorChannel) + go c.streamInteractionChannelInvite(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) streamInteractionChannelInvite(ctx context.Context, response *ListInteractionChannelInviteResponse, params *ListInteractionChannelInviteParams, recordChannel chan FlexV1InteractionChannelInvite, errorChannel chan error) { curRecord := 1 for response != nil { @@ -174,7 +195,7 @@ func (c *ApiService) streamInteractionChannelInvite(response *ListInteractionCha } } - record, err := client.GetNext(c.baseURL, response, c.getNextListInteractionChannelInviteResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListInteractionChannelInviteResponse) if err != nil { errorChannel <- err break @@ -189,11 +210,11 @@ func (c *ApiService) streamInteractionChannelInvite(response *ListInteractionCha close(errorChannel) } -func (c *ApiService) getNextListInteractionChannelInviteResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListInteractionChannelInviteResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 3550249c1..977f0ea18 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" @@ -42,6 +43,11 @@ func (params *CreateInteractionChannelParticipantParams) SetMediaProperties(Medi // Add a Participant to a Channel. func (c *ApiService) CreateInteractionChannelParticipant(InteractionSid string, ChannelSid string, params *CreateInteractionChannelParticipantParams) (*FlexV1InteractionChannelParticipant, error) { + return c.CreateInteractionChannelParticipantWithCtx(context.TODO(), InteractionSid, ChannelSid, params) +} + +// Add a Participant to a Channel. +func (c *ApiService) CreateInteractionChannelParticipantWithCtx(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) @@ -62,7 +68,7 @@ func (c *ApiService) CreateInteractionChannelParticipant(InteractionSid string, data.Set("MediaProperties", string(v)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -96,6 +102,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.PageInteractionChannelParticipantWithCtx(context.TODO(), InteractionSid, ChannelSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of InteractionChannelParticipant records from the API. Request is executed immediately. +func (c *ApiService) PageInteractionChannelParticipantWithCtx(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) @@ -115,7 +126,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -132,7 +143,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.ListInteractionChannelParticipantWithCtx(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) ListInteractionChannelParticipantWithCtx(ctx context.Context, InteractionSid string, ChannelSid string, params *ListInteractionChannelParticipantParams) ([]FlexV1InteractionChannelParticipant, error) { + response, errors := c.StreamInteractionChannelParticipantWithCtx(ctx, InteractionSid, ChannelSid, params) records := make([]FlexV1InteractionChannelParticipant, 0) for record := range response { @@ -148,6 +164,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.StreamInteractionChannelParticipantWithCtx(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) StreamInteractionChannelParticipantWithCtx(ctx context.Context, InteractionSid string, ChannelSid string, params *ListInteractionChannelParticipantParams) (chan FlexV1InteractionChannelParticipant, chan error) { if params == nil { params = &ListInteractionChannelParticipantParams{} } @@ -156,19 +177,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.PageInteractionChannelParticipantWithCtx(ctx, InteractionSid, ChannelSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamInteractionChannelParticipant(response, params, recordChannel, errorChannel) + go c.streamInteractionChannelParticipant(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) streamInteractionChannelParticipant(ctx context.Context, response *ListInteractionChannelParticipantResponse, params *ListInteractionChannelParticipantParams, recordChannel chan FlexV1InteractionChannelParticipant, errorChannel chan error) { curRecord := 1 for response != nil { @@ -183,7 +204,7 @@ func (c *ApiService) streamInteractionChannelParticipant(response *ListInteracti } } - record, err := client.GetNext(c.baseURL, response, c.getNextListInteractionChannelParticipantResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListInteractionChannelParticipantResponse) if err != nil { errorChannel <- err break @@ -198,11 +219,11 @@ func (c *ApiService) streamInteractionChannelParticipant(response *ListInteracti close(errorChannel) } -func (c *ApiService) getNextListInteractionChannelParticipantResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListInteractionChannelParticipantResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -229,6 +250,11 @@ 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.UpdateInteractionChannelParticipantWithCtx(context.TODO(), InteractionSid, ChannelSid, Sid, params) +} + +// Update an existing Channel Participant. +func (c *ApiService) UpdateInteractionChannelParticipantWithCtx(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) @@ -241,7 +267,7 @@ func (c *ApiService) UpdateInteractionChannelParticipant(InteractionSid string, data.Set("Status", *params.Status) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/flex/v1/web_channels.go b/rest/flex/v1/web_channels.go index 589a70e06..307b5f2c6 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" @@ -66,6 +67,11 @@ func (params *CreateWebChannelParams) SetPreEngagementData(PreEngagementData str // func (c *ApiService) CreateWebChannel(params *CreateWebChannelParams) (*FlexV1WebChannel, error) { + return c.CreateWebChannelWithCtx(context.TODO(), params) +} + +// +func (c *ApiService) CreateWebChannelWithCtx(ctx context.Context, params *CreateWebChannelParams) (*FlexV1WebChannel, error) { path := "/v1/WebChannels" data := url.Values{} @@ -90,7 +96,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -107,13 +113,18 @@ func (c *ApiService) CreateWebChannel(params *CreateWebChannelParams) (*FlexV1We // func (c *ApiService) DeleteWebChannel(Sid string) error { + return c.DeleteWebChannelWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) DeleteWebChannelWithCtx(ctx context.Context, Sid string) error { path := "/v1/WebChannels/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -125,13 +136,18 @@ func (c *ApiService) DeleteWebChannel(Sid string) error { // func (c *ApiService) FetchWebChannel(Sid string) (*FlexV1WebChannel, error) { + return c.FetchWebChannelWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) FetchWebChannelWithCtx(ctx context.Context, Sid string) (*FlexV1WebChannel, error) { path := "/v1/WebChannels/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -165,6 +181,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.PageWebChannelWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of WebChannel records from the API. Request is executed immediately. +func (c *ApiService) PageWebChannelWithCtx(ctx context.Context, params *ListWebChannelParams, pageToken, pageNumber string) (*ListWebChannelResponse, error) { path := "/v1/WebChannels" data := url.Values{} @@ -181,7 +202,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -198,7 +219,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.ListWebChannelWithCtx(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) ListWebChannelWithCtx(ctx context.Context, params *ListWebChannelParams) ([]FlexV1WebChannel, error) { + response, errors := c.StreamWebChannelWithCtx(ctx, params) records := make([]FlexV1WebChannel, 0) for record := range response { @@ -214,6 +240,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.StreamWebChannelWithCtx(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) StreamWebChannelWithCtx(ctx context.Context, params *ListWebChannelParams) (chan FlexV1WebChannel, chan error) { if params == nil { params = &ListWebChannelParams{} } @@ -222,19 +253,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.PageWebChannelWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamWebChannel(response, params, recordChannel, errorChannel) + go c.streamWebChannel(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) streamWebChannel(ctx context.Context, response *ListWebChannelResponse, params *ListWebChannelParams, recordChannel chan FlexV1WebChannel, errorChannel chan error) { curRecord := 1 for response != nil { @@ -249,7 +280,7 @@ func (c *ApiService) streamWebChannel(response *ListWebChannelResponse, params * } } - record, err := client.GetNext(c.baseURL, response, c.getNextListWebChannelResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListWebChannelResponse) if err != nil { errorChannel <- err break @@ -264,11 +295,11 @@ func (c *ApiService) streamWebChannel(response *ListWebChannelResponse, params * close(errorChannel) } -func (c *ApiService) getNextListWebChannelResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListWebChannelResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -301,6 +332,11 @@ func (params *UpdateWebChannelParams) SetPostEngagementData(PostEngagementData s // func (c *ApiService) UpdateWebChannel(Sid string, params *UpdateWebChannelParams) (*FlexV1WebChannel, error) { + return c.UpdateWebChannelWithCtx(context.TODO(), Sid, params) +} + +// +func (c *ApiService) UpdateWebChannelWithCtx(ctx context.Context, Sid string, params *UpdateWebChannelParams) (*FlexV1WebChannel, error) { path := "/v1/WebChannels/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -314,7 +350,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.Post(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 d4259bea7..514a61cb8 100644 --- a/rest/frontline/v1/api_service.go +++ b/rest/frontline/v1/api_service.go @@ -20,10 +20,14 @@ import ( type ApiService struct { baseURL string - requestHandler *twilio.RequestHandler + requestHandler *twilio.RequestHandlerWithCtx } func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { + return NewApiServiceWithCtx(twilio.UpgradeRequestHandler(requestHandler)) +} + +func NewApiServiceWithCtx(requestHandler *twilio.RequestHandlerWithCtx) *ApiService { return &ApiService{ requestHandler: requestHandler, baseURL: "https://frontline-api.twilio.com", @@ -33,3 +37,7 @@ func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { func NewApiServiceWithClient(client twilio.BaseClient) *ApiService { return NewApiService(twilio.NewRequestHandler(client)) } + +func NewApiServiceWithClientWithCtx(client twilio.BaseClientWithCtx) *ApiService { + return NewApiServiceWithCtx(twilio.NewRequestHandlerWithCtx(client)) +} diff --git a/rest/frontline/v1/users.go b/rest/frontline/v1/users.go index b6994cab2..3057e5359 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,13 +24,18 @@ import ( // Fetch a frontline user func (c *ApiService) FetchUser(Sid string) (*FrontlineV1User, error) { + return c.FetchUserWithCtx(context.TODO(), Sid) +} + +// Fetch a frontline user +func (c *ApiService) FetchUserWithCtx(ctx context.Context, Sid string) (*FrontlineV1User, error) { path := "/v1/Users/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -75,6 +81,11 @@ func (params *UpdateUserParams) SetIsAvailable(IsAvailable bool) *UpdateUserPara // Update an existing frontline user func (c *ApiService) UpdateUser(Sid string, params *UpdateUserParams) (*FrontlineV1User, error) { + return c.UpdateUserWithCtx(context.TODO(), Sid, params) +} + +// Update an existing frontline user +func (c *ApiService) UpdateUserWithCtx(ctx context.Context, Sid string, params *UpdateUserParams) (*FrontlineV1User, error) { path := "/v1/Users/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -94,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.Post(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 42a4a9fda..bcdcf2460 100644 --- a/rest/insights/v1/api_service.go +++ b/rest/insights/v1/api_service.go @@ -20,10 +20,14 @@ import ( type ApiService struct { baseURL string - requestHandler *twilio.RequestHandler + requestHandler *twilio.RequestHandlerWithCtx } func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { + return NewApiServiceWithCtx(twilio.UpgradeRequestHandler(requestHandler)) +} + +func NewApiServiceWithCtx(requestHandler *twilio.RequestHandlerWithCtx) *ApiService { return &ApiService{ requestHandler: requestHandler, baseURL: "https://insights.twilio.com", @@ -33,3 +37,7 @@ func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { func NewApiServiceWithClient(client twilio.BaseClient) *ApiService { return NewApiService(twilio.NewRequestHandler(client)) } + +func NewApiServiceWithClientWithCtx(client twilio.BaseClientWithCtx) *ApiService { + return NewApiServiceWithCtx(twilio.NewRequestHandlerWithCtx(client)) +} diff --git a/rest/insights/v1/conferences.go b/rest/insights/v1/conferences.go index 84bb57a44..a65fa7a7d 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,13 +26,18 @@ import ( // Fetch a specific Conference. func (c *ApiService) FetchConference(ConferenceSid string) (*InsightsV1Conference, error) { + return c.FetchConferenceWithCtx(context.TODO(), ConferenceSid) +} + +// Fetch a specific Conference. +func (c *ApiService) FetchConferenceWithCtx(ctx context.Context, ConferenceSid string) (*InsightsV1Conference, error) { path := "/v1/Conferences/{ConferenceSid}" path = strings.Replace(path, "{"+"ConferenceSid"+"}", ConferenceSid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -125,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.PageConferenceWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Conference records from the API. Request is executed immediately. +func (c *ApiService) PageConferenceWithCtx(ctx context.Context, params *ListConferenceParams, pageToken, pageNumber string) (*ListConferenceResponse, error) { path := "/v1/Conferences" data := url.Values{} @@ -171,7 +182,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -188,7 +199,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.ListConferenceWithCtx(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) ListConferenceWithCtx(ctx context.Context, params *ListConferenceParams) ([]InsightsV1Conference, error) { + response, errors := c.StreamConferenceWithCtx(ctx, params) records := make([]InsightsV1Conference, 0) for record := range response { @@ -204,6 +220,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.StreamConferenceWithCtx(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) StreamConferenceWithCtx(ctx context.Context, params *ListConferenceParams) (chan InsightsV1Conference, chan error) { if params == nil { params = &ListConferenceParams{} } @@ -212,19 +233,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.PageConferenceWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamConference(response, params, recordChannel, errorChannel) + go c.streamConference(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) streamConference(ctx context.Context, response *ListConferenceResponse, params *ListConferenceParams, recordChannel chan InsightsV1Conference, errorChannel chan error) { curRecord := 1 for response != nil { @@ -239,7 +260,7 @@ func (c *ApiService) streamConference(response *ListConferenceResponse, params * } } - record, err := client.GetNext(c.baseURL, response, c.getNextListConferenceResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListConferenceResponse) if err != nil { errorChannel <- err break @@ -254,11 +275,11 @@ func (c *ApiService) streamConference(response *ListConferenceResponse, params * close(errorChannel) } -func (c *ApiService) getNextListConferenceResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListConferenceResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 7b42e69c8..ca85444c6 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,11 @@ func (params *FetchConferenceParticipantParams) SetMetrics(Metrics string) *Fetc // Fetch a specific Conference Participant Summary. func (c *ApiService) FetchConferenceParticipant(ConferenceSid string, ParticipantSid string, params *FetchConferenceParticipantParams) (*InsightsV1ConferenceParticipant, error) { + return c.FetchConferenceParticipantWithCtx(context.TODO(), ConferenceSid, ParticipantSid, params) +} + +// Fetch a specific Conference Participant Summary. +func (c *ApiService) FetchConferenceParticipantWithCtx(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) @@ -56,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -108,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.PageConferenceParticipantWithCtx(context.TODO(), ConferenceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ConferenceParticipant records from the API. Request is executed immediately. +func (c *ApiService) PageConferenceParticipantWithCtx(ctx context.Context, ConferenceSid string, params *ListConferenceParticipantParams, pageToken, pageNumber string) (*ListConferenceParticipantResponse, error) { path := "/v1/Conferences/{ConferenceSid}/Participants" path = strings.Replace(path, "{"+"ConferenceSid"+"}", ConferenceSid, -1) @@ -135,7 +146,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -152,7 +163,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.ListConferenceParticipantWithCtx(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) ListConferenceParticipantWithCtx(ctx context.Context, ConferenceSid string, params *ListConferenceParticipantParams) ([]InsightsV1ConferenceParticipant, error) { + response, errors := c.StreamConferenceParticipantWithCtx(ctx, ConferenceSid, params) records := make([]InsightsV1ConferenceParticipant, 0) for record := range response { @@ -168,6 +184,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.StreamConferenceParticipantWithCtx(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) StreamConferenceParticipantWithCtx(ctx context.Context, ConferenceSid string, params *ListConferenceParticipantParams) (chan InsightsV1ConferenceParticipant, chan error) { if params == nil { params = &ListConferenceParticipantParams{} } @@ -176,19 +197,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.PageConferenceParticipantWithCtx(ctx, ConferenceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamConferenceParticipant(response, params, recordChannel, errorChannel) + go c.streamConferenceParticipant(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) streamConferenceParticipant(ctx context.Context, response *ListConferenceParticipantResponse, params *ListConferenceParticipantParams, recordChannel chan InsightsV1ConferenceParticipant, errorChannel chan error) { curRecord := 1 for response != nil { @@ -203,7 +224,7 @@ func (c *ApiService) streamConferenceParticipant(response *ListConferencePartici } } - record, err := client.GetNext(c.baseURL, response, c.getNextListConferenceParticipantResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListConferenceParticipantResponse) if err != nil { errorChannel <- err break @@ -218,11 +239,11 @@ func (c *ApiService) streamConferenceParticipant(response *ListConferencePartici close(errorChannel) } -func (c *ApiService) getNextListConferenceParticipantResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListConferenceParticipantResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 632bb3a94..00500b603 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,13 +27,18 @@ import ( // Get Video Log Analyzer data for a Room. func (c *ApiService) FetchVideoRoomSummary(RoomSid string) (*InsightsV1VideoRoomSummary, error) { + return c.FetchVideoRoomSummaryWithCtx(context.TODO(), RoomSid) +} + +// Get Video Log Analyzer data for a Room. +func (c *ApiService) FetchVideoRoomSummaryWithCtx(ctx context.Context, RoomSid string) (*InsightsV1VideoRoomSummary, error) { path := "/v1/Video/Rooms/{RoomSid}" path = strings.Replace(path, "{"+"RoomSid"+"}", RoomSid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -96,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.PageVideoRoomSummaryWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of VideoRoomSummary records from the API. Request is executed immediately. +func (c *ApiService) PageVideoRoomSummaryWithCtx(ctx context.Context, params *ListVideoRoomSummaryParams, pageToken, pageNumber string) (*ListVideoRoomSummaryResponse, error) { path := "/v1/Video/Rooms" data := url.Values{} @@ -131,7 +142,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -148,7 +159,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.ListVideoRoomSummaryWithCtx(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) ListVideoRoomSummaryWithCtx(ctx context.Context, params *ListVideoRoomSummaryParams) ([]InsightsV1VideoRoomSummary, error) { + response, errors := c.StreamVideoRoomSummaryWithCtx(ctx, params) records := make([]InsightsV1VideoRoomSummary, 0) for record := range response { @@ -164,6 +180,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.StreamVideoRoomSummaryWithCtx(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) StreamVideoRoomSummaryWithCtx(ctx context.Context, params *ListVideoRoomSummaryParams) (chan InsightsV1VideoRoomSummary, chan error) { if params == nil { params = &ListVideoRoomSummaryParams{} } @@ -172,19 +193,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.PageVideoRoomSummaryWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamVideoRoomSummary(response, params, recordChannel, errorChannel) + go c.streamVideoRoomSummary(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) streamVideoRoomSummary(ctx context.Context, response *ListVideoRoomSummaryResponse, params *ListVideoRoomSummaryParams, recordChannel chan InsightsV1VideoRoomSummary, errorChannel chan error) { curRecord := 1 for response != nil { @@ -199,7 +220,7 @@ func (c *ApiService) streamVideoRoomSummary(response *ListVideoRoomSummaryRespon } } - record, err := client.GetNext(c.baseURL, response, c.getNextListVideoRoomSummaryResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListVideoRoomSummaryResponse) if err != nil { errorChannel <- err break @@ -214,11 +235,11 @@ func (c *ApiService) streamVideoRoomSummary(response *ListVideoRoomSummaryRespon close(errorChannel) } -func (c *ApiService) getNextListVideoRoomSummaryResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListVideoRoomSummaryResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 9606f4ca6..c615bf493 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,11 @@ import ( // Get Video Log Analyzer data for a Room Participant. func (c *ApiService) FetchVideoParticipantSummary(RoomSid string, ParticipantSid string) (*InsightsV1VideoParticipantSummary, error) { + return c.FetchVideoParticipantSummaryWithCtx(context.TODO(), RoomSid, ParticipantSid) +} + +// Get Video Log Analyzer data for a Room Participant. +func (c *ApiService) FetchVideoParticipantSummaryWithCtx(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) @@ -32,7 +38,7 @@ func (c *ApiService) FetchVideoParticipantSummary(RoomSid string, ParticipantSid data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -66,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.PageVideoParticipantSummaryWithCtx(context.TODO(), RoomSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of VideoParticipantSummary records from the API. Request is executed immediately. +func (c *ApiService) PageVideoParticipantSummaryWithCtx(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) @@ -84,7 +95,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -101,7 +112,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.ListVideoParticipantSummaryWithCtx(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) ListVideoParticipantSummaryWithCtx(ctx context.Context, RoomSid string, params *ListVideoParticipantSummaryParams) ([]InsightsV1VideoParticipantSummary, error) { + response, errors := c.StreamVideoParticipantSummaryWithCtx(ctx, RoomSid, params) records := make([]InsightsV1VideoParticipantSummary, 0) for record := range response { @@ -117,6 +133,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.StreamVideoParticipantSummaryWithCtx(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) StreamVideoParticipantSummaryWithCtx(ctx context.Context, RoomSid string, params *ListVideoParticipantSummaryParams) (chan InsightsV1VideoParticipantSummary, chan error) { if params == nil { params = &ListVideoParticipantSummaryParams{} } @@ -125,19 +146,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.PageVideoParticipantSummaryWithCtx(ctx, RoomSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamVideoParticipantSummary(response, params, recordChannel, errorChannel) + go c.streamVideoParticipantSummary(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) streamVideoParticipantSummary(ctx context.Context, response *ListVideoParticipantSummaryResponse, params *ListVideoParticipantSummaryParams, recordChannel chan InsightsV1VideoParticipantSummary, errorChannel chan error) { curRecord := 1 for response != nil { @@ -152,7 +173,7 @@ func (c *ApiService) streamVideoParticipantSummary(response *ListVideoParticipan } } - record, err := client.GetNext(c.baseURL, response, c.getNextListVideoParticipantSummaryResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListVideoParticipantSummaryResponse) if err != nil { errorChannel <- err break @@ -167,11 +188,11 @@ func (c *ApiService) streamVideoParticipantSummary(response *ListVideoParticipan close(errorChannel) } -func (c *ApiService) getNextListVideoParticipantSummaryResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListVideoParticipantSummaryResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 e78674854..47e579f91 100644 --- a/rest/insights/v1/voice.go +++ b/rest/insights/v1/voice.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -22,13 +23,18 @@ import ( // func (c *ApiService) FetchCall(Sid string) (*InsightsV1Call, error) { + return c.FetchCallWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) FetchCallWithCtx(ctx context.Context, Sid string) (*InsightsV1Call, error) { path := "/v1/Voice/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(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 56e04bacc..dd2a6da9b 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,13 +24,18 @@ import ( // Fetch a specific Annotation. func (c *ApiService) FetchAnnotation(CallSid string) (*InsightsV1Annotation, error) { + return c.FetchAnnotationWithCtx(context.TODO(), CallSid) +} + +// Fetch a specific Annotation. +func (c *ApiService) FetchAnnotationWithCtx(ctx context.Context, CallSid string) (*InsightsV1Annotation, error) { path := "/v1/Voice/{CallSid}/Annotation" path = strings.Replace(path, "{"+"CallSid"+"}", CallSid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -93,6 +99,11 @@ func (params *UpdateAnnotationParams) SetIncident(Incident string) *UpdateAnnota // Create/Update the annotation for the call func (c *ApiService) UpdateAnnotation(CallSid string, params *UpdateAnnotationParams) (*InsightsV1Annotation, error) { + return c.UpdateAnnotationWithCtx(context.TODO(), CallSid, params) +} + +// Create/Update the annotation for the call +func (c *ApiService) UpdateAnnotationWithCtx(ctx context.Context, CallSid string, params *UpdateAnnotationParams) (*InsightsV1Annotation, error) { path := "/v1/Voice/{CallSid}/Annotation" path = strings.Replace(path, "{"+"CallSid"+"}", CallSid, -1) @@ -121,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.Post(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 a2bcbdc31..b85e93702 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.PageEventWithCtx(context.TODO(), CallSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Event records from the API. Request is executed immediately. +func (c *ApiService) PageEventWithCtx(ctx context.Context, CallSid string, params *ListEventParams, pageToken, pageNumber string) (*ListEventResponse, error) { path := "/v1/Voice/{CallSid}/Events" path = strings.Replace(path, "{"+"CallSid"+"}", CallSid, -1) @@ -69,7 +75,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -86,7 +92,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.ListEventWithCtx(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) ListEventWithCtx(ctx context.Context, CallSid string, params *ListEventParams) ([]InsightsV1Event, error) { + response, errors := c.StreamEventWithCtx(ctx, CallSid, params) records := make([]InsightsV1Event, 0) for record := range response { @@ -102,6 +113,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.StreamEventWithCtx(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) StreamEventWithCtx(ctx context.Context, CallSid string, params *ListEventParams) (chan InsightsV1Event, chan error) { if params == nil { params = &ListEventParams{} } @@ -110,19 +126,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.PageEventWithCtx(ctx, CallSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamEvent(response, params, recordChannel, errorChannel) + go c.streamEvent(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) streamEvent(ctx context.Context, response *ListEventResponse, params *ListEventParams, recordChannel chan InsightsV1Event, errorChannel chan error) { curRecord := 1 for response != nil { @@ -137,7 +153,7 @@ func (c *ApiService) streamEvent(response *ListEventResponse, params *ListEventP } } - record, err := client.GetNext(c.baseURL, response, c.getNextListEventResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListEventResponse) if err != nil { errorChannel <- err break @@ -152,11 +168,11 @@ func (c *ApiService) streamEvent(response *ListEventResponse, params *ListEventP close(errorChannel) } -func (c *ApiService) getNextListEventResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListEventResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 655a32c1d..d6616816f 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.PageMetricWithCtx(context.TODO(), CallSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Metric records from the API. Request is executed immediately. +func (c *ApiService) PageMetricWithCtx(ctx context.Context, CallSid string, params *ListMetricParams, pageToken, pageNumber string) (*ListMetricResponse, error) { path := "/v1/Voice/{CallSid}/Metrics" path = strings.Replace(path, "{"+"CallSid"+"}", CallSid, -1) @@ -78,7 +84,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -95,7 +101,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.ListMetricWithCtx(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) ListMetricWithCtx(ctx context.Context, CallSid string, params *ListMetricParams) ([]InsightsV1Metric, error) { + response, errors := c.StreamMetricWithCtx(ctx, CallSid, params) records := make([]InsightsV1Metric, 0) for record := range response { @@ -111,6 +122,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.StreamMetricWithCtx(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) StreamMetricWithCtx(ctx context.Context, CallSid string, params *ListMetricParams) (chan InsightsV1Metric, chan error) { if params == nil { params = &ListMetricParams{} } @@ -119,19 +135,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.PageMetricWithCtx(ctx, CallSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamMetric(response, params, recordChannel, errorChannel) + go c.streamMetric(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) streamMetric(ctx context.Context, response *ListMetricResponse, params *ListMetricParams, recordChannel chan InsightsV1Metric, errorChannel chan error) { curRecord := 1 for response != nil { @@ -146,7 +162,7 @@ func (c *ApiService) streamMetric(response *ListMetricResponse, params *ListMetr } } - record, err := client.GetNext(c.baseURL, response, c.getNextListMetricResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListMetricResponse) if err != nil { errorChannel <- err break @@ -161,11 +177,11 @@ func (c *ApiService) streamMetric(response *ListMetricResponse, params *ListMetr close(errorChannel) } -func (c *ApiService) getNextListMetricResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListMetricResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 94d39c42d..e37ef64f1 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,11 @@ func (params *FetchAccountSettingsParams) SetSubaccountSid(SubaccountSid string) // func (c *ApiService) FetchAccountSettings(params *FetchAccountSettingsParams) (*InsightsV1AccountSettings, error) { + return c.FetchAccountSettingsWithCtx(context.TODO(), params) +} + +// +func (c *ApiService) FetchAccountSettingsWithCtx(ctx context.Context, params *FetchAccountSettingsParams) (*InsightsV1AccountSettings, error) { path := "/v1/Voice/Settings" data := url.Values{} @@ -42,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -82,6 +88,11 @@ func (params *UpdateAccountSettingsParams) SetSubaccountSid(SubaccountSid string // func (c *ApiService) UpdateAccountSettings(params *UpdateAccountSettingsParams) (*InsightsV1AccountSettings, error) { + return c.UpdateAccountSettingsWithCtx(context.TODO(), params) +} + +// +func (c *ApiService) UpdateAccountSettingsWithCtx(ctx context.Context, params *UpdateAccountSettingsParams) (*InsightsV1AccountSettings, error) { path := "/v1/Voice/Settings" data := url.Values{} @@ -97,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.Post(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 d51e07048..5fefa68f7 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" @@ -149,6 +150,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.PageCallSummariesWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of CallSummaries records from the API. Request is executed immediately. +func (c *ApiService) PageCallSummariesWithCtx(ctx context.Context, params *ListCallSummariesParams, pageToken, pageNumber string) (*ListCallSummariesResponse, error) { path := "/v1/Voice/Summaries" data := url.Values{} @@ -219,7 +225,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -236,7 +242,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.ListCallSummariesWithCtx(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) ListCallSummariesWithCtx(ctx context.Context, params *ListCallSummariesParams) ([]InsightsV1CallSummaries, error) { + response, errors := c.StreamCallSummariesWithCtx(ctx, params) records := make([]InsightsV1CallSummaries, 0) for record := range response { @@ -252,6 +263,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.StreamCallSummariesWithCtx(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) StreamCallSummariesWithCtx(ctx context.Context, params *ListCallSummariesParams) (chan InsightsV1CallSummaries, chan error) { if params == nil { params = &ListCallSummariesParams{} } @@ -260,19 +276,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.PageCallSummariesWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamCallSummaries(response, params, recordChannel, errorChannel) + go c.streamCallSummaries(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) streamCallSummaries(ctx context.Context, response *ListCallSummariesResponse, params *ListCallSummariesParams, recordChannel chan InsightsV1CallSummaries, errorChannel chan error) { curRecord := 1 for response != nil { @@ -287,7 +303,7 @@ func (c *ApiService) streamCallSummaries(response *ListCallSummariesResponse, pa } } - record, err := client.GetNext(c.baseURL, response, c.getNextListCallSummariesResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListCallSummariesResponse) if err != nil { errorChannel <- err break @@ -302,11 +318,11 @@ func (c *ApiService) streamCallSummaries(response *ListCallSummariesResponse, pa close(errorChannel) } -func (c *ApiService) getNextListCallSummariesResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListCallSummariesResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 38d57bad3..03a2665f1 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,11 @@ func (params *FetchSummaryParams) SetProcessingState(ProcessingState string) *Fe // func (c *ApiService) FetchSummary(CallSid string, params *FetchSummaryParams) (*InsightsV1Summary, error) { + return c.FetchSummaryWithCtx(context.TODO(), CallSid, params) +} + +// +func (c *ApiService) FetchSummaryWithCtx(ctx context.Context, CallSid string, params *FetchSummaryParams) (*InsightsV1Summary, error) { path := "/v1/Voice/{CallSid}/Summary" path = strings.Replace(path, "{"+"CallSid"+"}", CallSid, -1) @@ -43,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.Get(ctx, c.baseURL+path, data, headers) 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 d15ea97c9..be76dfd20 100644 --- a/rest/ip_messaging/v1/api_service.go +++ b/rest/ip_messaging/v1/api_service.go @@ -20,10 +20,14 @@ import ( type ApiService struct { baseURL string - requestHandler *twilio.RequestHandler + requestHandler *twilio.RequestHandlerWithCtx } func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { + return NewApiServiceWithCtx(twilio.UpgradeRequestHandler(requestHandler)) +} + +func NewApiServiceWithCtx(requestHandler *twilio.RequestHandlerWithCtx) *ApiService { return &ApiService{ requestHandler: requestHandler, baseURL: "https://ip-messaging.twilio.com", @@ -33,3 +37,7 @@ func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { func NewApiServiceWithClient(client twilio.BaseClient) *ApiService { return NewApiService(twilio.NewRequestHandler(client)) } + +func NewApiServiceWithClientWithCtx(client twilio.BaseClientWithCtx) *ApiService { + return NewApiServiceWithCtx(twilio.NewRequestHandlerWithCtx(client)) +} diff --git a/rest/ip_messaging/v1/credentials.go b/rest/ip_messaging/v1/credentials.go index 850c839e0..df27c8237 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" @@ -72,6 +73,11 @@ func (params *CreateCredentialParams) SetSecret(Secret string) *CreateCredential // func (c *ApiService) CreateCredential(params *CreateCredentialParams) (*IpMessagingV1Credential, error) { + return c.CreateCredentialWithCtx(context.TODO(), params) +} + +// +func (c *ApiService) CreateCredentialWithCtx(ctx context.Context, params *CreateCredentialParams) (*IpMessagingV1Credential, error) { path := "/v1/Credentials" data := url.Values{} @@ -99,7 +105,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -116,13 +122,18 @@ func (c *ApiService) CreateCredential(params *CreateCredentialParams) (*IpMessag // func (c *ApiService) DeleteCredential(Sid string) error { + return c.DeleteCredentialWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) DeleteCredentialWithCtx(ctx context.Context, Sid string) error { path := "/v1/Credentials/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -134,13 +145,18 @@ func (c *ApiService) DeleteCredential(Sid string) error { // func (c *ApiService) FetchCredential(Sid string) (*IpMessagingV1Credential, error) { + return c.FetchCredentialWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) FetchCredentialWithCtx(ctx context.Context, Sid string) (*IpMessagingV1Credential, error) { path := "/v1/Credentials/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -174,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.PageCredentialWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Credential records from the API. Request is executed immediately. +func (c *ApiService) PageCredentialWithCtx(ctx context.Context, params *ListCredentialParams, pageToken, pageNumber string) (*ListCredentialResponse, error) { path := "/v1/Credentials" data := url.Values{} @@ -190,7 +211,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -207,7 +228,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.ListCredentialWithCtx(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) ListCredentialWithCtx(ctx context.Context, params *ListCredentialParams) ([]IpMessagingV1Credential, error) { + response, errors := c.StreamCredentialWithCtx(ctx, params) records := make([]IpMessagingV1Credential, 0) for record := range response { @@ -223,6 +249,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.StreamCredentialWithCtx(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) StreamCredentialWithCtx(ctx context.Context, params *ListCredentialParams) (chan IpMessagingV1Credential, chan error) { if params == nil { params = &ListCredentialParams{} } @@ -231,19 +262,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.PageCredentialWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamCredential(response, params, recordChannel, errorChannel) + go c.streamCredential(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) streamCredential(ctx context.Context, response *ListCredentialResponse, params *ListCredentialParams, recordChannel chan IpMessagingV1Credential, errorChannel chan error) { curRecord := 1 for response != nil { @@ -258,7 +289,7 @@ func (c *ApiService) streamCredential(response *ListCredentialResponse, params * } } - record, err := client.GetNext(c.baseURL, response, c.getNextListCredentialResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListCredentialResponse) if err != nil { errorChannel <- err break @@ -273,11 +304,11 @@ func (c *ApiService) streamCredential(response *ListCredentialResponse, params * close(errorChannel) } -func (c *ApiService) getNextListCredentialResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListCredentialResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -334,6 +365,11 @@ func (params *UpdateCredentialParams) SetSecret(Secret string) *UpdateCredential // func (c *ApiService) UpdateCredential(Sid string, params *UpdateCredentialParams) (*IpMessagingV1Credential, error) { + return c.UpdateCredentialWithCtx(context.TODO(), Sid, params) +} + +// +func (c *ApiService) UpdateCredentialWithCtx(ctx context.Context, Sid string, params *UpdateCredentialParams) (*IpMessagingV1Credential, error) { path := "/v1/Credentials/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -359,7 +395,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.Post(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 a1370fc84..07bd0ea4b 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" @@ -36,6 +37,11 @@ func (params *CreateServiceParams) SetFriendlyName(FriendlyName string) *CreateS // func (c *ApiService) CreateService(params *CreateServiceParams) (*IpMessagingV1Service, error) { + return c.CreateServiceWithCtx(context.TODO(), params) +} + +// +func (c *ApiService) CreateServiceWithCtx(ctx context.Context, params *CreateServiceParams) (*IpMessagingV1Service, error) { path := "/v1/Services" data := url.Values{} @@ -45,7 +51,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -62,13 +68,18 @@ func (c *ApiService) CreateService(params *CreateServiceParams) (*IpMessagingV1S // func (c *ApiService) DeleteService(Sid string) error { + return c.DeleteServiceWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) DeleteServiceWithCtx(ctx context.Context, Sid string) error { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -80,13 +91,18 @@ func (c *ApiService) DeleteService(Sid string) error { // func (c *ApiService) FetchService(Sid string) (*IpMessagingV1Service, error) { + return c.FetchServiceWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) FetchServiceWithCtx(ctx context.Context, Sid string) (*IpMessagingV1Service, error) { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -120,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.PageServiceWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Service records from the API. Request is executed immediately. +func (c *ApiService) PageServiceWithCtx(ctx context.Context, params *ListServiceParams, pageToken, pageNumber string) (*ListServiceResponse, error) { path := "/v1/Services" data := url.Values{} @@ -136,7 +157,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -153,7 +174,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.ListServiceWithCtx(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) ListServiceWithCtx(ctx context.Context, params *ListServiceParams) ([]IpMessagingV1Service, error) { + response, errors := c.StreamServiceWithCtx(ctx, params) records := make([]IpMessagingV1Service, 0) for record := range response { @@ -169,6 +195,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.StreamServiceWithCtx(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) StreamServiceWithCtx(ctx context.Context, params *ListServiceParams) (chan IpMessagingV1Service, chan error) { if params == nil { params = &ListServiceParams{} } @@ -177,19 +208,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.PageServiceWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamService(response, params, recordChannel, errorChannel) + go c.streamService(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) streamService(ctx context.Context, response *ListServiceResponse, params *ListServiceParams, recordChannel chan IpMessagingV1Service, errorChannel chan error) { curRecord := 1 for response != nil { @@ -204,7 +235,7 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListServiceResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListServiceResponse) if err != nil { errorChannel <- err break @@ -219,11 +250,11 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe close(errorChannel) } -func (c *ApiService) getNextListServiceResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListServiceResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -568,6 +599,11 @@ func (params *UpdateServiceParams) SetLimitsUserChannels(LimitsUserChannels int) // func (c *ApiService) UpdateService(Sid string, params *UpdateServiceParams) (*IpMessagingV1Service, error) { + return c.UpdateServiceWithCtx(context.TODO(), Sid, params) +} + +// +func (c *ApiService) UpdateServiceWithCtx(ctx context.Context, Sid string, params *UpdateServiceParams) (*IpMessagingV1Service, error) { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -739,7 +775,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.Post(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 22d296a9e..150351d4d 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" @@ -54,6 +55,11 @@ func (params *CreateChannelParams) SetType(Type string) *CreateChannelParams { // func (c *ApiService) CreateChannel(ServiceSid string, params *CreateChannelParams) (*IpMessagingV1Channel, error) { + return c.CreateChannelWithCtx(context.TODO(), ServiceSid, params) +} + +// +func (c *ApiService) CreateChannelWithCtx(ctx context.Context, ServiceSid string, params *CreateChannelParams) (*IpMessagingV1Channel, error) { path := "/v1/Services/{ServiceSid}/Channels" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -73,7 +79,7 @@ func (c *ApiService) CreateChannel(ServiceSid string, params *CreateChannelParam data.Set("Type", *params.Type) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -90,6 +96,11 @@ func (c *ApiService) CreateChannel(ServiceSid string, params *CreateChannelParam // func (c *ApiService) DeleteChannel(ServiceSid string, Sid string) error { + return c.DeleteChannelWithCtx(context.TODO(), ServiceSid, Sid) +} + +// +func (c *ApiService) DeleteChannelWithCtx(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) @@ -97,7 +108,7 @@ func (c *ApiService) DeleteChannel(ServiceSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -109,6 +120,11 @@ func (c *ApiService) DeleteChannel(ServiceSid string, Sid string) error { // func (c *ApiService) FetchChannel(ServiceSid string, Sid string) (*IpMessagingV1Channel, error) { + return c.FetchChannelWithCtx(context.TODO(), ServiceSid, Sid) +} + +// +func (c *ApiService) FetchChannelWithCtx(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) @@ -116,7 +132,7 @@ func (c *ApiService) FetchChannel(ServiceSid string, Sid string) (*IpMessagingV1 data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -156,6 +172,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.PageChannelWithCtx(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Channel records from the API. Request is executed immediately. +func (c *ApiService) PageChannelWithCtx(ctx context.Context, ServiceSid string, params *ListChannelParams, pageToken, pageNumber string) (*ListChannelResponse, error) { path := "/v1/Services/{ServiceSid}/Channels" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -179,7 +200,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -196,7 +217,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.ListChannelWithCtx(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) ListChannelWithCtx(ctx context.Context, ServiceSid string, params *ListChannelParams) ([]IpMessagingV1Channel, error) { + response, errors := c.StreamChannelWithCtx(ctx, ServiceSid, params) records := make([]IpMessagingV1Channel, 0) for record := range response { @@ -212,6 +238,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.StreamChannelWithCtx(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) StreamChannelWithCtx(ctx context.Context, ServiceSid string, params *ListChannelParams) (chan IpMessagingV1Channel, chan error) { if params == nil { params = &ListChannelParams{} } @@ -220,19 +251,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.PageChannelWithCtx(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamChannel(response, params, recordChannel, errorChannel) + go c.streamChannel(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) streamChannel(ctx context.Context, response *ListChannelResponse, params *ListChannelParams, recordChannel chan IpMessagingV1Channel, errorChannel chan error) { curRecord := 1 for response != nil { @@ -247,7 +278,7 @@ func (c *ApiService) streamChannel(response *ListChannelResponse, params *ListCh } } - record, err := client.GetNext(c.baseURL, response, c.getNextListChannelResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListChannelResponse) if err != nil { errorChannel <- err break @@ -262,11 +293,11 @@ func (c *ApiService) streamChannel(response *ListChannelResponse, params *ListCh close(errorChannel) } -func (c *ApiService) getNextListChannelResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListChannelResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -305,6 +336,11 @@ func (params *UpdateChannelParams) SetAttributes(Attributes string) *UpdateChann // func (c *ApiService) UpdateChannel(ServiceSid string, Sid string, params *UpdateChannelParams) (*IpMessagingV1Channel, error) { + return c.UpdateChannelWithCtx(context.TODO(), ServiceSid, Sid, params) +} + +// +func (c *ApiService) UpdateChannelWithCtx(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) @@ -322,7 +358,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.Post(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 30253d330..146e4980a 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" @@ -42,6 +43,11 @@ func (params *CreateInviteParams) SetRoleSid(RoleSid string) *CreateInviteParams // func (c *ApiService) CreateInvite(ServiceSid string, ChannelSid string, params *CreateInviteParams) (*IpMessagingV1Invite, error) { + return c.CreateInviteWithCtx(context.TODO(), ServiceSid, ChannelSid, params) +} + +// +func (c *ApiService) CreateInviteWithCtx(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) @@ -56,7 +62,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -73,6 +79,11 @@ func (c *ApiService) CreateInvite(ServiceSid string, ChannelSid string, params * // func (c *ApiService) DeleteInvite(ServiceSid string, ChannelSid string, Sid string) error { + return c.DeleteInviteWithCtx(context.TODO(), ServiceSid, ChannelSid, Sid) +} + +// +func (c *ApiService) DeleteInviteWithCtx(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) @@ -81,7 +92,7 @@ func (c *ApiService) DeleteInvite(ServiceSid string, ChannelSid string, Sid stri data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -93,6 +104,11 @@ func (c *ApiService) DeleteInvite(ServiceSid string, ChannelSid string, Sid stri // func (c *ApiService) FetchInvite(ServiceSid string, ChannelSid string, Sid string) (*IpMessagingV1Invite, error) { + return c.FetchInviteWithCtx(context.TODO(), ServiceSid, ChannelSid, Sid) +} + +// +func (c *ApiService) FetchInviteWithCtx(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) @@ -101,7 +117,7 @@ func (c *ApiService) FetchInvite(ServiceSid string, ChannelSid string, Sid strin data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -141,6 +157,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.PageInviteWithCtx(context.TODO(), ServiceSid, ChannelSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Invite records from the API. Request is executed immediately. +func (c *ApiService) PageInviteWithCtx(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) @@ -165,7 +186,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -182,7 +203,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.ListInviteWithCtx(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) ListInviteWithCtx(ctx context.Context, ServiceSid string, ChannelSid string, params *ListInviteParams) ([]IpMessagingV1Invite, error) { + response, errors := c.StreamInviteWithCtx(ctx, ServiceSid, ChannelSid, params) records := make([]IpMessagingV1Invite, 0) for record := range response { @@ -198,6 +224,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.StreamInviteWithCtx(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) StreamInviteWithCtx(ctx context.Context, ServiceSid string, ChannelSid string, params *ListInviteParams) (chan IpMessagingV1Invite, chan error) { if params == nil { params = &ListInviteParams{} } @@ -206,19 +237,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.PageInviteWithCtx(ctx, ServiceSid, ChannelSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamInvite(response, params, recordChannel, errorChannel) + go c.streamInvite(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) streamInvite(ctx context.Context, response *ListInviteResponse, params *ListInviteParams, recordChannel chan IpMessagingV1Invite, errorChannel chan error) { curRecord := 1 for response != nil { @@ -233,7 +264,7 @@ func (c *ApiService) streamInvite(response *ListInviteResponse, params *ListInvi } } - record, err := client.GetNext(c.baseURL, response, c.getNextListInviteResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListInviteResponse) if err != nil { errorChannel <- err break @@ -248,11 +279,11 @@ func (c *ApiService) streamInvite(response *ListInviteResponse, params *ListInvi close(errorChannel) } -func (c *ApiService) getNextListInviteResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListInviteResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 77b1b4e90..66effd675 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" @@ -42,6 +43,11 @@ func (params *CreateMemberParams) SetRoleSid(RoleSid string) *CreateMemberParams // func (c *ApiService) CreateMember(ServiceSid string, ChannelSid string, params *CreateMemberParams) (*IpMessagingV1Member, error) { + return c.CreateMemberWithCtx(context.TODO(), ServiceSid, ChannelSid, params) +} + +// +func (c *ApiService) CreateMemberWithCtx(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) @@ -56,7 +62,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -73,6 +79,11 @@ func (c *ApiService) CreateMember(ServiceSid string, ChannelSid string, params * // func (c *ApiService) DeleteMember(ServiceSid string, ChannelSid string, Sid string) error { + return c.DeleteMemberWithCtx(context.TODO(), ServiceSid, ChannelSid, Sid) +} + +// +func (c *ApiService) DeleteMemberWithCtx(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) @@ -81,7 +92,7 @@ func (c *ApiService) DeleteMember(ServiceSid string, ChannelSid string, Sid stri data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -93,6 +104,11 @@ func (c *ApiService) DeleteMember(ServiceSid string, ChannelSid string, Sid stri // func (c *ApiService) FetchMember(ServiceSid string, ChannelSid string, Sid string) (*IpMessagingV1Member, error) { + return c.FetchMemberWithCtx(context.TODO(), ServiceSid, ChannelSid, Sid) +} + +// +func (c *ApiService) FetchMemberWithCtx(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) @@ -101,7 +117,7 @@ func (c *ApiService) FetchMember(ServiceSid string, ChannelSid string, Sid strin data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -141,6 +157,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.PageMemberWithCtx(context.TODO(), ServiceSid, ChannelSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Member records from the API. Request is executed immediately. +func (c *ApiService) PageMemberWithCtx(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) @@ -165,7 +186,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -182,7 +203,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.ListMemberWithCtx(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) ListMemberWithCtx(ctx context.Context, ServiceSid string, ChannelSid string, params *ListMemberParams) ([]IpMessagingV1Member, error) { + response, errors := c.StreamMemberWithCtx(ctx, ServiceSid, ChannelSid, params) records := make([]IpMessagingV1Member, 0) for record := range response { @@ -198,6 +224,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.StreamMemberWithCtx(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) StreamMemberWithCtx(ctx context.Context, ServiceSid string, ChannelSid string, params *ListMemberParams) (chan IpMessagingV1Member, chan error) { if params == nil { params = &ListMemberParams{} } @@ -206,19 +237,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.PageMemberWithCtx(ctx, ServiceSid, ChannelSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamMember(response, params, recordChannel, errorChannel) + go c.streamMember(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) streamMember(ctx context.Context, response *ListMemberResponse, params *ListMemberParams, recordChannel chan IpMessagingV1Member, errorChannel chan error) { curRecord := 1 for response != nil { @@ -233,7 +264,7 @@ func (c *ApiService) streamMember(response *ListMemberResponse, params *ListMemb } } - record, err := client.GetNext(c.baseURL, response, c.getNextListMemberResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListMemberResponse) if err != nil { errorChannel <- err break @@ -248,11 +279,11 @@ func (c *ApiService) streamMember(response *ListMemberResponse, params *ListMemb close(errorChannel) } -func (c *ApiService) getNextListMemberResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListMemberResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -285,6 +316,11 @@ func (params *UpdateMemberParams) SetLastConsumedMessageIndex(LastConsumedMessag // func (c *ApiService) UpdateMember(ServiceSid string, ChannelSid string, Sid string, params *UpdateMemberParams) (*IpMessagingV1Member, error) { + return c.UpdateMemberWithCtx(context.TODO(), ServiceSid, ChannelSid, Sid, params) +} + +// +func (c *ApiService) UpdateMemberWithCtx(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) @@ -300,7 +336,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.Post(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 28f929dda..c0164b949 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" @@ -48,6 +49,11 @@ func (params *CreateMessageParams) SetAttributes(Attributes string) *CreateMessa // func (c *ApiService) CreateMessage(ServiceSid string, ChannelSid string, params *CreateMessageParams) (*IpMessagingV1Message, error) { + return c.CreateMessageWithCtx(context.TODO(), ServiceSid, ChannelSid, params) +} + +// +func (c *ApiService) CreateMessageWithCtx(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) @@ -65,7 +71,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -82,6 +88,11 @@ func (c *ApiService) CreateMessage(ServiceSid string, ChannelSid string, params // func (c *ApiService) DeleteMessage(ServiceSid string, ChannelSid string, Sid string) error { + return c.DeleteMessageWithCtx(context.TODO(), ServiceSid, ChannelSid, Sid) +} + +// +func (c *ApiService) DeleteMessageWithCtx(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) @@ -90,7 +101,7 @@ func (c *ApiService) DeleteMessage(ServiceSid string, ChannelSid string, Sid str data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -102,6 +113,11 @@ func (c *ApiService) DeleteMessage(ServiceSid string, ChannelSid string, Sid str // func (c *ApiService) FetchMessage(ServiceSid string, ChannelSid string, Sid string) (*IpMessagingV1Message, error) { + return c.FetchMessageWithCtx(context.TODO(), ServiceSid, ChannelSid, Sid) +} + +// +func (c *ApiService) FetchMessageWithCtx(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) @@ -110,7 +126,7 @@ func (c *ApiService) FetchMessage(ServiceSid string, ChannelSid string, Sid stri data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -150,6 +166,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.PageMessageWithCtx(context.TODO(), ServiceSid, ChannelSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Message records from the API. Request is executed immediately. +func (c *ApiService) PageMessageWithCtx(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) @@ -172,7 +193,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -189,7 +210,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.ListMessageWithCtx(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) ListMessageWithCtx(ctx context.Context, ServiceSid string, ChannelSid string, params *ListMessageParams) ([]IpMessagingV1Message, error) { + response, errors := c.StreamMessageWithCtx(ctx, ServiceSid, ChannelSid, params) records := make([]IpMessagingV1Message, 0) for record := range response { @@ -205,6 +231,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.StreamMessageWithCtx(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) StreamMessageWithCtx(ctx context.Context, ServiceSid string, ChannelSid string, params *ListMessageParams) (chan IpMessagingV1Message, chan error) { if params == nil { params = &ListMessageParams{} } @@ -213,19 +244,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.PageMessageWithCtx(ctx, ServiceSid, ChannelSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamMessage(response, params, recordChannel, errorChannel) + go c.streamMessage(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) streamMessage(ctx context.Context, response *ListMessageResponse, params *ListMessageParams, recordChannel chan IpMessagingV1Message, errorChannel chan error) { curRecord := 1 for response != nil { @@ -240,7 +271,7 @@ func (c *ApiService) streamMessage(response *ListMessageResponse, params *ListMe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListMessageResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListMessageResponse) if err != nil { errorChannel <- err break @@ -255,11 +286,11 @@ func (c *ApiService) streamMessage(response *ListMessageResponse, params *ListMe close(errorChannel) } -func (c *ApiService) getNextListMessageResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListMessageResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -292,6 +323,11 @@ func (params *UpdateMessageParams) SetAttributes(Attributes string) *UpdateMessa // func (c *ApiService) UpdateMessage(ServiceSid string, ChannelSid string, Sid string, params *UpdateMessageParams) (*IpMessagingV1Message, error) { + return c.UpdateMessageWithCtx(context.TODO(), ServiceSid, ChannelSid, Sid, params) +} + +// +func (c *ApiService) UpdateMessageWithCtx(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) @@ -307,7 +343,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.Post(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 3d562e6c0..fc48ae8f0 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" @@ -48,6 +49,11 @@ func (params *CreateRoleParams) SetPermission(Permission []string) *CreateRolePa // func (c *ApiService) CreateRole(ServiceSid string, params *CreateRoleParams) (*IpMessagingV1Role, error) { + return c.CreateRoleWithCtx(context.TODO(), ServiceSid, params) +} + +// +func (c *ApiService) CreateRoleWithCtx(ctx context.Context, ServiceSid string, params *CreateRoleParams) (*IpMessagingV1Role, error) { path := "/v1/Services/{ServiceSid}/Roles" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -66,7 +72,7 @@ func (c *ApiService) CreateRole(ServiceSid string, params *CreateRoleParams) (*I } } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -83,6 +89,11 @@ func (c *ApiService) CreateRole(ServiceSid string, params *CreateRoleParams) (*I // func (c *ApiService) DeleteRole(ServiceSid string, Sid string) error { + return c.DeleteRoleWithCtx(context.TODO(), ServiceSid, Sid) +} + +// +func (c *ApiService) DeleteRoleWithCtx(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) @@ -90,7 +101,7 @@ func (c *ApiService) DeleteRole(ServiceSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -102,6 +113,11 @@ func (c *ApiService) DeleteRole(ServiceSid string, Sid string) error { // func (c *ApiService) FetchRole(ServiceSid string, Sid string) (*IpMessagingV1Role, error) { + return c.FetchRoleWithCtx(context.TODO(), ServiceSid, Sid) +} + +// +func (c *ApiService) FetchRoleWithCtx(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) @@ -109,7 +125,7 @@ func (c *ApiService) FetchRole(ServiceSid string, Sid string) (*IpMessagingV1Rol data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -143,6 +159,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.PageRoleWithCtx(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Role records from the API. Request is executed immediately. +func (c *ApiService) PageRoleWithCtx(ctx context.Context, ServiceSid string, params *ListRoleParams, pageToken, pageNumber string) (*ListRoleResponse, error) { path := "/v1/Services/{ServiceSid}/Roles" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -161,7 +182,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -178,7 +199,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.ListRoleWithCtx(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) ListRoleWithCtx(ctx context.Context, ServiceSid string, params *ListRoleParams) ([]IpMessagingV1Role, error) { + response, errors := c.StreamRoleWithCtx(ctx, ServiceSid, params) records := make([]IpMessagingV1Role, 0) for record := range response { @@ -194,6 +220,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.StreamRoleWithCtx(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) StreamRoleWithCtx(ctx context.Context, ServiceSid string, params *ListRoleParams) (chan IpMessagingV1Role, chan error) { if params == nil { params = &ListRoleParams{} } @@ -202,19 +233,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.PageRoleWithCtx(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamRole(response, params, recordChannel, errorChannel) + go c.streamRole(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) streamRole(ctx context.Context, response *ListRoleResponse, params *ListRoleParams, recordChannel chan IpMessagingV1Role, errorChannel chan error) { curRecord := 1 for response != nil { @@ -229,7 +260,7 @@ func (c *ApiService) streamRole(response *ListRoleResponse, params *ListRolePara } } - record, err := client.GetNext(c.baseURL, response, c.getNextListRoleResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListRoleResponse) if err != nil { errorChannel <- err break @@ -244,11 +275,11 @@ func (c *ApiService) streamRole(response *ListRoleResponse, params *ListRolePara close(errorChannel) } -func (c *ApiService) getNextListRoleResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListRoleResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -275,6 +306,11 @@ func (params *UpdateRoleParams) SetPermission(Permission []string) *UpdateRolePa // func (c *ApiService) UpdateRole(ServiceSid string, Sid string, params *UpdateRoleParams) (*IpMessagingV1Role, error) { + return c.UpdateRoleWithCtx(context.TODO(), ServiceSid, Sid, params) +} + +// +func (c *ApiService) UpdateRoleWithCtx(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) @@ -288,7 +324,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.Post(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 8fe15c616..763da1f55 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" @@ -54,6 +55,11 @@ func (params *CreateUserParams) SetFriendlyName(FriendlyName string) *CreateUser // func (c *ApiService) CreateUser(ServiceSid string, params *CreateUserParams) (*IpMessagingV1User, error) { + return c.CreateUserWithCtx(context.TODO(), ServiceSid, params) +} + +// +func (c *ApiService) CreateUserWithCtx(ctx context.Context, ServiceSid string, params *CreateUserParams) (*IpMessagingV1User, error) { path := "/v1/Services/{ServiceSid}/Users" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -73,7 +79,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -90,6 +96,11 @@ func (c *ApiService) CreateUser(ServiceSid string, params *CreateUserParams) (*I // func (c *ApiService) DeleteUser(ServiceSid string, Sid string) error { + return c.DeleteUserWithCtx(context.TODO(), ServiceSid, Sid) +} + +// +func (c *ApiService) DeleteUserWithCtx(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) @@ -97,7 +108,7 @@ func (c *ApiService) DeleteUser(ServiceSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -109,6 +120,11 @@ func (c *ApiService) DeleteUser(ServiceSid string, Sid string) error { // func (c *ApiService) FetchUser(ServiceSid string, Sid string) (*IpMessagingV1User, error) { + return c.FetchUserWithCtx(context.TODO(), ServiceSid, Sid) +} + +// +func (c *ApiService) FetchUserWithCtx(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) @@ -116,7 +132,7 @@ func (c *ApiService) FetchUser(ServiceSid string, Sid string) (*IpMessagingV1Use data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -150,6 +166,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.PageUserWithCtx(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of User records from the API. Request is executed immediately. +func (c *ApiService) PageUserWithCtx(ctx context.Context, ServiceSid string, params *ListUserParams, pageToken, pageNumber string) (*ListUserResponse, error) { path := "/v1/Services/{ServiceSid}/Users" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -168,7 +189,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -185,7 +206,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.ListUserWithCtx(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) ListUserWithCtx(ctx context.Context, ServiceSid string, params *ListUserParams) ([]IpMessagingV1User, error) { + response, errors := c.StreamUserWithCtx(ctx, ServiceSid, params) records := make([]IpMessagingV1User, 0) for record := range response { @@ -201,6 +227,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.StreamUserWithCtx(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) StreamUserWithCtx(ctx context.Context, ServiceSid string, params *ListUserParams) (chan IpMessagingV1User, chan error) { if params == nil { params = &ListUserParams{} } @@ -209,19 +240,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.PageUserWithCtx(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUser(response, params, recordChannel, errorChannel) + go c.streamUser(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) streamUser(ctx context.Context, response *ListUserResponse, params *ListUserParams, recordChannel chan IpMessagingV1User, errorChannel chan error) { curRecord := 1 for response != nil { @@ -236,7 +267,7 @@ func (c *ApiService) streamUser(response *ListUserResponse, params *ListUserPara } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUserResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListUserResponse) if err != nil { errorChannel <- err break @@ -251,11 +282,11 @@ func (c *ApiService) streamUser(response *ListUserResponse, params *ListUserPara close(errorChannel) } -func (c *ApiService) getNextListUserResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUserResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -294,6 +325,11 @@ func (params *UpdateUserParams) SetFriendlyName(FriendlyName string) *UpdateUser // func (c *ApiService) UpdateUser(ServiceSid string, Sid string, params *UpdateUserParams) (*IpMessagingV1User, error) { + return c.UpdateUserWithCtx(context.TODO(), ServiceSid, Sid, params) +} + +// +func (c *ApiService) UpdateUserWithCtx(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) @@ -311,7 +347,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.Post(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 32b0dfc05..feca95430 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.PageUserChannelWithCtx(context.TODO(), ServiceSid, UserSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of UserChannel records from the API. Request is executed immediately. +func (c *ApiService) PageUserChannelWithCtx(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) @@ -61,7 +67,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -78,7 +84,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.ListUserChannelWithCtx(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) ListUserChannelWithCtx(ctx context.Context, ServiceSid string, UserSid string, params *ListUserChannelParams) ([]IpMessagingV1UserChannel, error) { + response, errors := c.StreamUserChannelWithCtx(ctx, ServiceSid, UserSid, params) records := make([]IpMessagingV1UserChannel, 0) for record := range response { @@ -94,6 +105,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.StreamUserChannelWithCtx(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) StreamUserChannelWithCtx(ctx context.Context, ServiceSid string, UserSid string, params *ListUserChannelParams) (chan IpMessagingV1UserChannel, chan error) { if params == nil { params = &ListUserChannelParams{} } @@ -102,19 +118,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.PageUserChannelWithCtx(ctx, ServiceSid, UserSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUserChannel(response, params, recordChannel, errorChannel) + go c.streamUserChannel(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) streamUserChannel(ctx context.Context, response *ListUserChannelResponse, params *ListUserChannelParams, recordChannel chan IpMessagingV1UserChannel, errorChannel chan error) { curRecord := 1 for response != nil { @@ -129,7 +145,7 @@ func (c *ApiService) streamUserChannel(response *ListUserChannelResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUserChannelResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListUserChannelResponse) if err != nil { errorChannel <- err break @@ -144,11 +160,11 @@ func (c *ApiService) streamUserChannel(response *ListUserChannelResponse, params close(errorChannel) } -func (c *ApiService) getNextListUserChannelResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUserChannelResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 d15ea97c9..be76dfd20 100644 --- a/rest/ip_messaging/v2/api_service.go +++ b/rest/ip_messaging/v2/api_service.go @@ -20,10 +20,14 @@ import ( type ApiService struct { baseURL string - requestHandler *twilio.RequestHandler + requestHandler *twilio.RequestHandlerWithCtx } func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { + return NewApiServiceWithCtx(twilio.UpgradeRequestHandler(requestHandler)) +} + +func NewApiServiceWithCtx(requestHandler *twilio.RequestHandlerWithCtx) *ApiService { return &ApiService{ requestHandler: requestHandler, baseURL: "https://ip-messaging.twilio.com", @@ -33,3 +37,7 @@ func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { func NewApiServiceWithClient(client twilio.BaseClient) *ApiService { return NewApiService(twilio.NewRequestHandler(client)) } + +func NewApiServiceWithClientWithCtx(client twilio.BaseClientWithCtx) *ApiService { + return NewApiServiceWithCtx(twilio.NewRequestHandlerWithCtx(client)) +} diff --git a/rest/ip_messaging/v2/credentials.go b/rest/ip_messaging/v2/credentials.go index 7d4227335..b5ad71f9e 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" @@ -72,6 +73,11 @@ func (params *CreateCredentialParams) SetSecret(Secret string) *CreateCredential // func (c *ApiService) CreateCredential(params *CreateCredentialParams) (*IpMessagingV2Credential, error) { + return c.CreateCredentialWithCtx(context.TODO(), params) +} + +// +func (c *ApiService) CreateCredentialWithCtx(ctx context.Context, params *CreateCredentialParams) (*IpMessagingV2Credential, error) { path := "/v2/Credentials" data := url.Values{} @@ -99,7 +105,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -116,13 +122,18 @@ func (c *ApiService) CreateCredential(params *CreateCredentialParams) (*IpMessag // func (c *ApiService) DeleteCredential(Sid string) error { + return c.DeleteCredentialWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) DeleteCredentialWithCtx(ctx context.Context, Sid string) error { path := "/v2/Credentials/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -134,13 +145,18 @@ func (c *ApiService) DeleteCredential(Sid string) error { // func (c *ApiService) FetchCredential(Sid string) (*IpMessagingV2Credential, error) { + return c.FetchCredentialWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) FetchCredentialWithCtx(ctx context.Context, Sid string) (*IpMessagingV2Credential, error) { path := "/v2/Credentials/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -174,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.PageCredentialWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Credential records from the API. Request is executed immediately. +func (c *ApiService) PageCredentialWithCtx(ctx context.Context, params *ListCredentialParams, pageToken, pageNumber string) (*ListCredentialResponse, error) { path := "/v2/Credentials" data := url.Values{} @@ -190,7 +211,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -207,7 +228,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.ListCredentialWithCtx(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) ListCredentialWithCtx(ctx context.Context, params *ListCredentialParams) ([]IpMessagingV2Credential, error) { + response, errors := c.StreamCredentialWithCtx(ctx, params) records := make([]IpMessagingV2Credential, 0) for record := range response { @@ -223,6 +249,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.StreamCredentialWithCtx(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) StreamCredentialWithCtx(ctx context.Context, params *ListCredentialParams) (chan IpMessagingV2Credential, chan error) { if params == nil { params = &ListCredentialParams{} } @@ -231,19 +262,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.PageCredentialWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamCredential(response, params, recordChannel, errorChannel) + go c.streamCredential(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) streamCredential(ctx context.Context, response *ListCredentialResponse, params *ListCredentialParams, recordChannel chan IpMessagingV2Credential, errorChannel chan error) { curRecord := 1 for response != nil { @@ -258,7 +289,7 @@ func (c *ApiService) streamCredential(response *ListCredentialResponse, params * } } - record, err := client.GetNext(c.baseURL, response, c.getNextListCredentialResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListCredentialResponse) if err != nil { errorChannel <- err break @@ -273,11 +304,11 @@ func (c *ApiService) streamCredential(response *ListCredentialResponse, params * close(errorChannel) } -func (c *ApiService) getNextListCredentialResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListCredentialResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -334,6 +365,11 @@ func (params *UpdateCredentialParams) SetSecret(Secret string) *UpdateCredential // func (c *ApiService) UpdateCredential(Sid string, params *UpdateCredentialParams) (*IpMessagingV2Credential, error) { + return c.UpdateCredentialWithCtx(context.TODO(), Sid, params) +} + +// +func (c *ApiService) UpdateCredentialWithCtx(ctx context.Context, Sid string, params *UpdateCredentialParams) (*IpMessagingV2Credential, error) { path := "/v2/Credentials/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -359,7 +395,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.Post(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 3b093dcd5..9266033fd 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" @@ -36,6 +37,11 @@ func (params *CreateServiceParams) SetFriendlyName(FriendlyName string) *CreateS // func (c *ApiService) CreateService(params *CreateServiceParams) (*IpMessagingV2Service, error) { + return c.CreateServiceWithCtx(context.TODO(), params) +} + +// +func (c *ApiService) CreateServiceWithCtx(ctx context.Context, params *CreateServiceParams) (*IpMessagingV2Service, error) { path := "/v2/Services" data := url.Values{} @@ -45,7 +51,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -62,13 +68,18 @@ func (c *ApiService) CreateService(params *CreateServiceParams) (*IpMessagingV2S // func (c *ApiService) DeleteService(Sid string) error { + return c.DeleteServiceWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) DeleteServiceWithCtx(ctx context.Context, Sid string) error { path := "/v2/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -80,13 +91,18 @@ func (c *ApiService) DeleteService(Sid string) error { // func (c *ApiService) FetchService(Sid string) (*IpMessagingV2Service, error) { + return c.FetchServiceWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) FetchServiceWithCtx(ctx context.Context, Sid string) (*IpMessagingV2Service, error) { path := "/v2/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -120,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.PageServiceWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Service records from the API. Request is executed immediately. +func (c *ApiService) PageServiceWithCtx(ctx context.Context, params *ListServiceParams, pageToken, pageNumber string) (*ListServiceResponse, error) { path := "/v2/Services" data := url.Values{} @@ -136,7 +157,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -153,7 +174,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.ListServiceWithCtx(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) ListServiceWithCtx(ctx context.Context, params *ListServiceParams) ([]IpMessagingV2Service, error) { + response, errors := c.StreamServiceWithCtx(ctx, params) records := make([]IpMessagingV2Service, 0) for record := range response { @@ -169,6 +195,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.StreamServiceWithCtx(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) StreamServiceWithCtx(ctx context.Context, params *ListServiceParams) (chan IpMessagingV2Service, chan error) { if params == nil { params = &ListServiceParams{} } @@ -177,19 +208,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.PageServiceWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamService(response, params, recordChannel, errorChannel) + go c.streamService(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) streamService(ctx context.Context, response *ListServiceResponse, params *ListServiceParams, recordChannel chan IpMessagingV2Service, errorChannel chan error) { curRecord := 1 for response != nil { @@ -204,7 +235,7 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListServiceResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListServiceResponse) if err != nil { errorChannel <- err break @@ -219,11 +250,11 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe close(errorChannel) } -func (c *ApiService) getNextListServiceResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListServiceResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -430,6 +461,11 @@ func (params *UpdateServiceParams) SetNotificationsLogEnabled(NotificationsLogEn // func (c *ApiService) UpdateService(Sid string, params *UpdateServiceParams) (*IpMessagingV2Service, error) { + return c.UpdateServiceWithCtx(context.TODO(), Sid, params) +} + +// +func (c *ApiService) UpdateServiceWithCtx(ctx context.Context, Sid string, params *UpdateServiceParams) (*IpMessagingV2Service, error) { path := "/v2/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -532,7 +568,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.Post(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 248da0f90..140ed9319 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" @@ -25,6 +26,11 @@ import ( // func (c *ApiService) DeleteBinding(ServiceSid string, Sid string) error { + return c.DeleteBindingWithCtx(context.TODO(), ServiceSid, Sid) +} + +// +func (c *ApiService) DeleteBindingWithCtx(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) @@ -32,7 +38,7 @@ func (c *ApiService) DeleteBinding(ServiceSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -44,6 +50,11 @@ func (c *ApiService) DeleteBinding(ServiceSid string, Sid string) error { // func (c *ApiService) FetchBinding(ServiceSid string, Sid string) (*IpMessagingV2Binding, error) { + return c.FetchBindingWithCtx(context.TODO(), ServiceSid, Sid) +} + +// +func (c *ApiService) FetchBindingWithCtx(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) @@ -51,7 +62,7 @@ func (c *ApiService) FetchBinding(ServiceSid string, Sid string) (*IpMessagingV2 data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -97,6 +108,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.PageBindingWithCtx(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Binding records from the API. Request is executed immediately. +func (c *ApiService) PageBindingWithCtx(ctx context.Context, ServiceSid string, params *ListBindingParams, pageToken, pageNumber string) (*ListBindingResponse, error) { path := "/v2/Services/{ServiceSid}/Bindings" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -125,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -142,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.ListBindingWithCtx(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) ListBindingWithCtx(ctx context.Context, ServiceSid string, params *ListBindingParams) ([]IpMessagingV2Binding, error) { + response, errors := c.StreamBindingWithCtx(ctx, ServiceSid, params) records := make([]IpMessagingV2Binding, 0) for record := range response { @@ -158,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.StreamBindingWithCtx(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) StreamBindingWithCtx(ctx context.Context, ServiceSid string, params *ListBindingParams) (chan IpMessagingV2Binding, chan error) { if params == nil { params = &ListBindingParams{} } @@ -166,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.PageBindingWithCtx(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamBinding(response, params, recordChannel, errorChannel) + go c.streamBinding(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) streamBinding(ctx context.Context, response *ListBindingResponse, params *ListBindingParams, recordChannel chan IpMessagingV2Binding, errorChannel chan error) { curRecord := 1 for response != nil { @@ -193,7 +219,7 @@ func (c *ApiService) streamBinding(response *ListBindingResponse, params *ListBi } } - record, err := client.GetNext(c.baseURL, response, c.getNextListBindingResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListBindingResponse) if err != nil { errorChannel <- err break @@ -208,11 +234,11 @@ func (c *ApiService) streamBinding(response *ListBindingResponse, params *ListBi close(errorChannel) } -func (c *ApiService) getNextListBindingResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListBindingResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 98a24ca5d..bcbb55297 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" @@ -79,6 +80,11 @@ func (params *CreateChannelParams) SetCreatedBy(CreatedBy string) *CreateChannel // func (c *ApiService) CreateChannel(ServiceSid string, params *CreateChannelParams) (*IpMessagingV2Channel, error) { + return c.CreateChannelWithCtx(context.TODO(), ServiceSid, params) +} + +// +func (c *ApiService) CreateChannelWithCtx(ctx context.Context, ServiceSid string, params *CreateChannelParams) (*IpMessagingV2Channel, error) { path := "/v2/Services/{ServiceSid}/Channels" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -111,7 +117,7 @@ func (c *ApiService) CreateChannel(ServiceSid string, params *CreateChannelParam headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -139,6 +145,11 @@ func (params *DeleteChannelParams) SetXTwilioWebhookEnabled(XTwilioWebhookEnable // func (c *ApiService) DeleteChannel(ServiceSid string, Sid string, params *DeleteChannelParams) error { + return c.DeleteChannelWithCtx(context.TODO(), ServiceSid, Sid, params) +} + +// +func (c *ApiService) DeleteChannelWithCtx(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) @@ -150,7 +161,7 @@ func (c *ApiService) DeleteChannel(ServiceSid string, Sid string, params *Delete headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -162,6 +173,11 @@ func (c *ApiService) DeleteChannel(ServiceSid string, Sid string, params *Delete // func (c *ApiService) FetchChannel(ServiceSid string, Sid string) (*IpMessagingV2Channel, error) { + return c.FetchChannelWithCtx(context.TODO(), ServiceSid, Sid) +} + +// +func (c *ApiService) FetchChannelWithCtx(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) @@ -169,7 +185,7 @@ func (c *ApiService) FetchChannel(ServiceSid string, Sid string) (*IpMessagingV2 data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -209,6 +225,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.PageChannelWithCtx(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Channel records from the API. Request is executed immediately. +func (c *ApiService) PageChannelWithCtx(ctx context.Context, ServiceSid string, params *ListChannelParams, pageToken, pageNumber string) (*ListChannelResponse, error) { path := "/v2/Services/{ServiceSid}/Channels" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -232,7 +253,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -249,7 +270,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.ListChannelWithCtx(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) ListChannelWithCtx(ctx context.Context, ServiceSid string, params *ListChannelParams) ([]IpMessagingV2Channel, error) { + response, errors := c.StreamChannelWithCtx(ctx, ServiceSid, params) records := make([]IpMessagingV2Channel, 0) for record := range response { @@ -265,6 +291,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.StreamChannelWithCtx(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) StreamChannelWithCtx(ctx context.Context, ServiceSid string, params *ListChannelParams) (chan IpMessagingV2Channel, chan error) { if params == nil { params = &ListChannelParams{} } @@ -273,19 +304,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.PageChannelWithCtx(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamChannel(response, params, recordChannel, errorChannel) + go c.streamChannel(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) streamChannel(ctx context.Context, response *ListChannelResponse, params *ListChannelParams, recordChannel chan IpMessagingV2Channel, errorChannel chan error) { curRecord := 1 for response != nil { @@ -300,7 +331,7 @@ func (c *ApiService) streamChannel(response *ListChannelResponse, params *ListCh } } - record, err := client.GetNext(c.baseURL, response, c.getNextListChannelResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListChannelResponse) if err != nil { errorChannel <- err break @@ -315,11 +346,11 @@ func (c *ApiService) streamChannel(response *ListChannelResponse, params *ListCh close(errorChannel) } -func (c *ApiService) getNextListChannelResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListChannelResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -382,6 +413,11 @@ func (params *UpdateChannelParams) SetCreatedBy(CreatedBy string) *UpdateChannel // func (c *ApiService) UpdateChannel(ServiceSid string, Sid string, params *UpdateChannelParams) (*IpMessagingV2Channel, error) { + return c.UpdateChannelWithCtx(context.TODO(), ServiceSid, Sid, params) +} + +// +func (c *ApiService) UpdateChannelWithCtx(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) @@ -412,7 +448,7 @@ func (c *ApiService) UpdateChannel(ServiceSid string, Sid string, params *Update headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 f02e2cbbc..4ca3551a5 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" @@ -42,6 +43,11 @@ func (params *CreateInviteParams) SetRoleSid(RoleSid string) *CreateInviteParams // func (c *ApiService) CreateInvite(ServiceSid string, ChannelSid string, params *CreateInviteParams) (*IpMessagingV2Invite, error) { + return c.CreateInviteWithCtx(context.TODO(), ServiceSid, ChannelSid, params) +} + +// +func (c *ApiService) CreateInviteWithCtx(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) @@ -56,7 +62,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -73,6 +79,11 @@ func (c *ApiService) CreateInvite(ServiceSid string, ChannelSid string, params * // func (c *ApiService) DeleteInvite(ServiceSid string, ChannelSid string, Sid string) error { + return c.DeleteInviteWithCtx(context.TODO(), ServiceSid, ChannelSid, Sid) +} + +// +func (c *ApiService) DeleteInviteWithCtx(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) @@ -81,7 +92,7 @@ func (c *ApiService) DeleteInvite(ServiceSid string, ChannelSid string, Sid stri data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -93,6 +104,11 @@ func (c *ApiService) DeleteInvite(ServiceSid string, ChannelSid string, Sid stri // func (c *ApiService) FetchInvite(ServiceSid string, ChannelSid string, Sid string) (*IpMessagingV2Invite, error) { + return c.FetchInviteWithCtx(context.TODO(), ServiceSid, ChannelSid, Sid) +} + +// +func (c *ApiService) FetchInviteWithCtx(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) @@ -101,7 +117,7 @@ func (c *ApiService) FetchInvite(ServiceSid string, ChannelSid string, Sid strin data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -141,6 +157,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.PageInviteWithCtx(context.TODO(), ServiceSid, ChannelSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Invite records from the API. Request is executed immediately. +func (c *ApiService) PageInviteWithCtx(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) @@ -165,7 +186,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -182,7 +203,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.ListInviteWithCtx(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) ListInviteWithCtx(ctx context.Context, ServiceSid string, ChannelSid string, params *ListInviteParams) ([]IpMessagingV2Invite, error) { + response, errors := c.StreamInviteWithCtx(ctx, ServiceSid, ChannelSid, params) records := make([]IpMessagingV2Invite, 0) for record := range response { @@ -198,6 +224,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.StreamInviteWithCtx(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) StreamInviteWithCtx(ctx context.Context, ServiceSid string, ChannelSid string, params *ListInviteParams) (chan IpMessagingV2Invite, chan error) { if params == nil { params = &ListInviteParams{} } @@ -206,19 +237,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.PageInviteWithCtx(ctx, ServiceSid, ChannelSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamInvite(response, params, recordChannel, errorChannel) + go c.streamInvite(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) streamInvite(ctx context.Context, response *ListInviteResponse, params *ListInviteParams, recordChannel chan IpMessagingV2Invite, errorChannel chan error) { curRecord := 1 for response != nil { @@ -233,7 +264,7 @@ func (c *ApiService) streamInvite(response *ListInviteResponse, params *ListInvi } } - record, err := client.GetNext(c.baseURL, response, c.getNextListInviteResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListInviteResponse) if err != nil { errorChannel <- err break @@ -248,11 +279,11 @@ func (c *ApiService) streamInvite(response *ListInviteResponse, params *ListInvi close(errorChannel) } -func (c *ApiService) getNextListInviteResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListInviteResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 724db92cf..f74bb7044 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" @@ -79,6 +80,11 @@ func (params *CreateMemberParams) SetAttributes(Attributes string) *CreateMember // func (c *ApiService) CreateMember(ServiceSid string, ChannelSid string, params *CreateMemberParams) (*IpMessagingV2Member, error) { + return c.CreateMemberWithCtx(context.TODO(), ServiceSid, ChannelSid, params) +} + +// +func (c *ApiService) CreateMemberWithCtx(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) @@ -112,7 +118,7 @@ func (c *ApiService) CreateMember(ServiceSid string, ChannelSid string, params * headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -140,6 +146,11 @@ func (params *DeleteMemberParams) SetXTwilioWebhookEnabled(XTwilioWebhookEnabled // func (c *ApiService) DeleteMember(ServiceSid string, ChannelSid string, Sid string, params *DeleteMemberParams) error { + return c.DeleteMemberWithCtx(context.TODO(), ServiceSid, ChannelSid, Sid, params) +} + +// +func (c *ApiService) DeleteMemberWithCtx(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) @@ -152,7 +163,7 @@ func (c *ApiService) DeleteMember(ServiceSid string, ChannelSid string, Sid stri headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -164,6 +175,11 @@ func (c *ApiService) DeleteMember(ServiceSid string, ChannelSid string, Sid stri // func (c *ApiService) FetchMember(ServiceSid string, ChannelSid string, Sid string) (*IpMessagingV2Member, error) { + return c.FetchMemberWithCtx(context.TODO(), ServiceSid, ChannelSid, Sid) +} + +// +func (c *ApiService) FetchMemberWithCtx(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) @@ -172,7 +188,7 @@ func (c *ApiService) FetchMember(ServiceSid string, ChannelSid string, Sid strin data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -212,6 +228,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.PageMemberWithCtx(context.TODO(), ServiceSid, ChannelSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Member records from the API. Request is executed immediately. +func (c *ApiService) PageMemberWithCtx(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) @@ -236,7 +257,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -253,7 +274,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.ListMemberWithCtx(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) ListMemberWithCtx(ctx context.Context, ServiceSid string, ChannelSid string, params *ListMemberParams) ([]IpMessagingV2Member, error) { + response, errors := c.StreamMemberWithCtx(ctx, ServiceSid, ChannelSid, params) records := make([]IpMessagingV2Member, 0) for record := range response { @@ -269,6 +295,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.StreamMemberWithCtx(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) StreamMemberWithCtx(ctx context.Context, ServiceSid string, ChannelSid string, params *ListMemberParams) (chan IpMessagingV2Member, chan error) { if params == nil { params = &ListMemberParams{} } @@ -277,19 +308,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.PageMemberWithCtx(ctx, ServiceSid, ChannelSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamMember(response, params, recordChannel, errorChannel) + go c.streamMember(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) streamMember(ctx context.Context, response *ListMemberResponse, params *ListMemberParams, recordChannel chan IpMessagingV2Member, errorChannel chan error) { curRecord := 1 for response != nil { @@ -304,7 +335,7 @@ func (c *ApiService) streamMember(response *ListMemberResponse, params *ListMemb } } - record, err := client.GetNext(c.baseURL, response, c.getNextListMemberResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListMemberResponse) if err != nil { errorChannel <- err break @@ -319,11 +350,11 @@ func (c *ApiService) streamMember(response *ListMemberResponse, params *ListMemb close(errorChannel) } -func (c *ApiService) getNextListMemberResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListMemberResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -386,6 +417,11 @@ func (params *UpdateMemberParams) SetAttributes(Attributes string) *UpdateMember // func (c *ApiService) UpdateMember(ServiceSid string, ChannelSid string, Sid string, params *UpdateMemberParams) (*IpMessagingV2Member, error) { + return c.UpdateMemberWithCtx(context.TODO(), ServiceSid, ChannelSid, Sid, params) +} + +// +func (c *ApiService) UpdateMemberWithCtx(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) @@ -417,7 +453,7 @@ func (c *ApiService) UpdateMember(ServiceSid string, ChannelSid string, Sid stri headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 4f53a5345..f1fa63c12 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" @@ -79,6 +80,11 @@ func (params *CreateMessageParams) SetMediaSid(MediaSid string) *CreateMessagePa // func (c *ApiService) CreateMessage(ServiceSid string, ChannelSid string, params *CreateMessageParams) (*IpMessagingV2Message, error) { + return c.CreateMessageWithCtx(context.TODO(), ServiceSid, ChannelSid, params) +} + +// +func (c *ApiService) CreateMessageWithCtx(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) @@ -112,7 +118,7 @@ func (c *ApiService) CreateMessage(ServiceSid string, ChannelSid string, params headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -140,6 +146,11 @@ func (params *DeleteMessageParams) SetXTwilioWebhookEnabled(XTwilioWebhookEnable // func (c *ApiService) DeleteMessage(ServiceSid string, ChannelSid string, Sid string, params *DeleteMessageParams) error { + return c.DeleteMessageWithCtx(context.TODO(), ServiceSid, ChannelSid, Sid, params) +} + +// +func (c *ApiService) DeleteMessageWithCtx(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) @@ -152,7 +163,7 @@ func (c *ApiService) DeleteMessage(ServiceSid string, ChannelSid string, Sid str headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -164,6 +175,11 @@ func (c *ApiService) DeleteMessage(ServiceSid string, ChannelSid string, Sid str // func (c *ApiService) FetchMessage(ServiceSid string, ChannelSid string, Sid string) (*IpMessagingV2Message, error) { + return c.FetchMessageWithCtx(context.TODO(), ServiceSid, ChannelSid, Sid) +} + +// +func (c *ApiService) FetchMessageWithCtx(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) @@ -172,7 +188,7 @@ func (c *ApiService) FetchMessage(ServiceSid string, ChannelSid string, Sid stri data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -212,6 +228,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.PageMessageWithCtx(context.TODO(), ServiceSid, ChannelSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Message records from the API. Request is executed immediately. +func (c *ApiService) PageMessageWithCtx(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) @@ -234,7 +255,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -251,7 +272,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.ListMessageWithCtx(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) ListMessageWithCtx(ctx context.Context, ServiceSid string, ChannelSid string, params *ListMessageParams) ([]IpMessagingV2Message, error) { + response, errors := c.StreamMessageWithCtx(ctx, ServiceSid, ChannelSid, params) records := make([]IpMessagingV2Message, 0) for record := range response { @@ -267,6 +293,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.StreamMessageWithCtx(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) StreamMessageWithCtx(ctx context.Context, ServiceSid string, ChannelSid string, params *ListMessageParams) (chan IpMessagingV2Message, chan error) { if params == nil { params = &ListMessageParams{} } @@ -275,19 +306,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.PageMessageWithCtx(ctx, ServiceSid, ChannelSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamMessage(response, params, recordChannel, errorChannel) + go c.streamMessage(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) streamMessage(ctx context.Context, response *ListMessageResponse, params *ListMessageParams, recordChannel chan IpMessagingV2Message, errorChannel chan error) { curRecord := 1 for response != nil { @@ -302,7 +333,7 @@ func (c *ApiService) streamMessage(response *ListMessageResponse, params *ListMe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListMessageResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListMessageResponse) if err != nil { errorChannel <- err break @@ -317,11 +348,11 @@ func (c *ApiService) streamMessage(response *ListMessageResponse, params *ListMe close(errorChannel) } -func (c *ApiService) getNextListMessageResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListMessageResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -384,6 +415,11 @@ func (params *UpdateMessageParams) SetFrom(From string) *UpdateMessageParams { // func (c *ApiService) UpdateMessage(ServiceSid string, ChannelSid string, Sid string, params *UpdateMessageParams) (*IpMessagingV2Message, error) { + return c.UpdateMessageWithCtx(context.TODO(), ServiceSid, ChannelSid, Sid, params) +} + +// +func (c *ApiService) UpdateMessageWithCtx(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) @@ -415,7 +451,7 @@ func (c *ApiService) UpdateMessage(ServiceSid string, ChannelSid string, Sid str headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 76535a9e2..23baff19e 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" @@ -72,6 +73,11 @@ func (params *CreateChannelWebhookParams) SetConfigurationRetryCount(Configurati // func (c *ApiService) CreateChannelWebhook(ServiceSid string, ChannelSid string, params *CreateChannelWebhookParams) (*IpMessagingV2ChannelWebhook, error) { + return c.CreateChannelWebhookWithCtx(context.TODO(), ServiceSid, ChannelSid, params) +} + +// +func (c *ApiService) CreateChannelWebhookWithCtx(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) @@ -105,7 +111,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -122,6 +128,11 @@ func (c *ApiService) CreateChannelWebhook(ServiceSid string, ChannelSid string, // func (c *ApiService) DeleteChannelWebhook(ServiceSid string, ChannelSid string, Sid string) error { + return c.DeleteChannelWebhookWithCtx(context.TODO(), ServiceSid, ChannelSid, Sid) +} + +// +func (c *ApiService) DeleteChannelWebhookWithCtx(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) @@ -130,7 +141,7 @@ func (c *ApiService) DeleteChannelWebhook(ServiceSid string, ChannelSid string, data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -142,6 +153,11 @@ func (c *ApiService) DeleteChannelWebhook(ServiceSid string, ChannelSid string, // func (c *ApiService) FetchChannelWebhook(ServiceSid string, ChannelSid string, Sid string) (*IpMessagingV2ChannelWebhook, error) { + return c.FetchChannelWebhookWithCtx(context.TODO(), ServiceSid, ChannelSid, Sid) +} + +// +func (c *ApiService) FetchChannelWebhookWithCtx(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) @@ -150,7 +166,7 @@ func (c *ApiService) FetchChannelWebhook(ServiceSid string, ChannelSid string, S data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -184,6 +200,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.PageChannelWebhookWithCtx(context.TODO(), ServiceSid, ChannelSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ChannelWebhook records from the API. Request is executed immediately. +func (c *ApiService) PageChannelWebhookWithCtx(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) @@ -203,7 +224,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -220,7 +241,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.ListChannelWebhookWithCtx(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) ListChannelWebhookWithCtx(ctx context.Context, ServiceSid string, ChannelSid string, params *ListChannelWebhookParams) ([]IpMessagingV2ChannelWebhook, error) { + response, errors := c.StreamChannelWebhookWithCtx(ctx, ServiceSid, ChannelSid, params) records := make([]IpMessagingV2ChannelWebhook, 0) for record := range response { @@ -236,6 +262,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.StreamChannelWebhookWithCtx(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) StreamChannelWebhookWithCtx(ctx context.Context, ServiceSid string, ChannelSid string, params *ListChannelWebhookParams) (chan IpMessagingV2ChannelWebhook, chan error) { if params == nil { params = &ListChannelWebhookParams{} } @@ -244,19 +275,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.PageChannelWebhookWithCtx(ctx, ServiceSid, ChannelSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamChannelWebhook(response, params, recordChannel, errorChannel) + go c.streamChannelWebhook(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) streamChannelWebhook(ctx context.Context, response *ListChannelWebhookResponse, params *ListChannelWebhookParams, recordChannel chan IpMessagingV2ChannelWebhook, errorChannel chan error) { curRecord := 1 for response != nil { @@ -271,7 +302,7 @@ func (c *ApiService) streamChannelWebhook(response *ListChannelWebhookResponse, } } - record, err := client.GetNext(c.baseURL, response, c.getNextListChannelWebhookResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListChannelWebhookResponse) if err != nil { errorChannel <- err break @@ -286,11 +317,11 @@ func (c *ApiService) streamChannelWebhook(response *ListChannelWebhookResponse, close(errorChannel) } -func (c *ApiService) getNextListChannelWebhookResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListChannelWebhookResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -347,6 +378,11 @@ func (params *UpdateChannelWebhookParams) SetConfigurationRetryCount(Configurati // func (c *ApiService) UpdateChannelWebhook(ServiceSid string, ChannelSid string, Sid string, params *UpdateChannelWebhookParams) (*IpMessagingV2ChannelWebhook, error) { + return c.UpdateChannelWebhookWithCtx(context.TODO(), ServiceSid, ChannelSid, Sid, params) +} + +// +func (c *ApiService) UpdateChannelWebhookWithCtx(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) @@ -378,7 +414,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.Post(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 62bc98a4d..7f802e7b5 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" @@ -48,6 +49,11 @@ func (params *CreateRoleParams) SetPermission(Permission []string) *CreateRolePa // func (c *ApiService) CreateRole(ServiceSid string, params *CreateRoleParams) (*IpMessagingV2Role, error) { + return c.CreateRoleWithCtx(context.TODO(), ServiceSid, params) +} + +// +func (c *ApiService) CreateRoleWithCtx(ctx context.Context, ServiceSid string, params *CreateRoleParams) (*IpMessagingV2Role, error) { path := "/v2/Services/{ServiceSid}/Roles" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -66,7 +72,7 @@ func (c *ApiService) CreateRole(ServiceSid string, params *CreateRoleParams) (*I } } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -83,6 +89,11 @@ func (c *ApiService) CreateRole(ServiceSid string, params *CreateRoleParams) (*I // func (c *ApiService) DeleteRole(ServiceSid string, Sid string) error { + return c.DeleteRoleWithCtx(context.TODO(), ServiceSid, Sid) +} + +// +func (c *ApiService) DeleteRoleWithCtx(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) @@ -90,7 +101,7 @@ func (c *ApiService) DeleteRole(ServiceSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -102,6 +113,11 @@ func (c *ApiService) DeleteRole(ServiceSid string, Sid string) error { // func (c *ApiService) FetchRole(ServiceSid string, Sid string) (*IpMessagingV2Role, error) { + return c.FetchRoleWithCtx(context.TODO(), ServiceSid, Sid) +} + +// +func (c *ApiService) FetchRoleWithCtx(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) @@ -109,7 +125,7 @@ func (c *ApiService) FetchRole(ServiceSid string, Sid string) (*IpMessagingV2Rol data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -143,6 +159,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.PageRoleWithCtx(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Role records from the API. Request is executed immediately. +func (c *ApiService) PageRoleWithCtx(ctx context.Context, ServiceSid string, params *ListRoleParams, pageToken, pageNumber string) (*ListRoleResponse, error) { path := "/v2/Services/{ServiceSid}/Roles" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -161,7 +182,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -178,7 +199,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.ListRoleWithCtx(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) ListRoleWithCtx(ctx context.Context, ServiceSid string, params *ListRoleParams) ([]IpMessagingV2Role, error) { + response, errors := c.StreamRoleWithCtx(ctx, ServiceSid, params) records := make([]IpMessagingV2Role, 0) for record := range response { @@ -194,6 +220,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.StreamRoleWithCtx(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) StreamRoleWithCtx(ctx context.Context, ServiceSid string, params *ListRoleParams) (chan IpMessagingV2Role, chan error) { if params == nil { params = &ListRoleParams{} } @@ -202,19 +233,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.PageRoleWithCtx(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamRole(response, params, recordChannel, errorChannel) + go c.streamRole(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) streamRole(ctx context.Context, response *ListRoleResponse, params *ListRoleParams, recordChannel chan IpMessagingV2Role, errorChannel chan error) { curRecord := 1 for response != nil { @@ -229,7 +260,7 @@ func (c *ApiService) streamRole(response *ListRoleResponse, params *ListRolePara } } - record, err := client.GetNext(c.baseURL, response, c.getNextListRoleResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListRoleResponse) if err != nil { errorChannel <- err break @@ -244,11 +275,11 @@ func (c *ApiService) streamRole(response *ListRoleResponse, params *ListRolePara close(errorChannel) } -func (c *ApiService) getNextListRoleResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListRoleResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -275,6 +306,11 @@ func (params *UpdateRoleParams) SetPermission(Permission []string) *UpdateRolePa // func (c *ApiService) UpdateRole(ServiceSid string, Sid string, params *UpdateRoleParams) (*IpMessagingV2Role, error) { + return c.UpdateRoleWithCtx(context.TODO(), ServiceSid, Sid, params) +} + +// +func (c *ApiService) UpdateRoleWithCtx(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) @@ -288,7 +324,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.Post(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 8a490a67e..0771be0b7 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" @@ -60,6 +61,11 @@ func (params *CreateUserParams) SetFriendlyName(FriendlyName string) *CreateUser // func (c *ApiService) CreateUser(ServiceSid string, params *CreateUserParams) (*IpMessagingV2User, error) { + return c.CreateUserWithCtx(context.TODO(), ServiceSid, params) +} + +// +func (c *ApiService) CreateUserWithCtx(ctx context.Context, ServiceSid string, params *CreateUserParams) (*IpMessagingV2User, error) { path := "/v2/Services/{ServiceSid}/Users" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -83,7 +89,7 @@ func (c *ApiService) CreateUser(ServiceSid string, params *CreateUserParams) (*I headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -100,6 +106,11 @@ func (c *ApiService) CreateUser(ServiceSid string, params *CreateUserParams) (*I // func (c *ApiService) DeleteUser(ServiceSid string, Sid string) error { + return c.DeleteUserWithCtx(context.TODO(), ServiceSid, Sid) +} + +// +func (c *ApiService) DeleteUserWithCtx(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) @@ -107,7 +118,7 @@ func (c *ApiService) DeleteUser(ServiceSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -119,6 +130,11 @@ func (c *ApiService) DeleteUser(ServiceSid string, Sid string) error { // func (c *ApiService) FetchUser(ServiceSid string, Sid string) (*IpMessagingV2User, error) { + return c.FetchUserWithCtx(context.TODO(), ServiceSid, Sid) +} + +// +func (c *ApiService) FetchUserWithCtx(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) @@ -126,7 +142,7 @@ func (c *ApiService) FetchUser(ServiceSid string, Sid string) (*IpMessagingV2Use data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -160,6 +176,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.PageUserWithCtx(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of User records from the API. Request is executed immediately. +func (c *ApiService) PageUserWithCtx(ctx context.Context, ServiceSid string, params *ListUserParams, pageToken, pageNumber string) (*ListUserResponse, error) { path := "/v2/Services/{ServiceSid}/Users" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -178,7 +199,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -195,7 +216,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.ListUserWithCtx(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) ListUserWithCtx(ctx context.Context, ServiceSid string, params *ListUserParams) ([]IpMessagingV2User, error) { + response, errors := c.StreamUserWithCtx(ctx, ServiceSid, params) records := make([]IpMessagingV2User, 0) for record := range response { @@ -211,6 +237,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.StreamUserWithCtx(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) StreamUserWithCtx(ctx context.Context, ServiceSid string, params *ListUserParams) (chan IpMessagingV2User, chan error) { if params == nil { params = &ListUserParams{} } @@ -219,19 +250,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.PageUserWithCtx(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUser(response, params, recordChannel, errorChannel) + go c.streamUser(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) streamUser(ctx context.Context, response *ListUserResponse, params *ListUserParams, recordChannel chan IpMessagingV2User, errorChannel chan error) { curRecord := 1 for response != nil { @@ -246,7 +277,7 @@ func (c *ApiService) streamUser(response *ListUserResponse, params *ListUserPara } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUserResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListUserResponse) if err != nil { errorChannel <- err break @@ -261,11 +292,11 @@ func (c *ApiService) streamUser(response *ListUserResponse, params *ListUserPara close(errorChannel) } -func (c *ApiService) getNextListUserResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUserResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -310,6 +341,11 @@ func (params *UpdateUserParams) SetFriendlyName(FriendlyName string) *UpdateUser // func (c *ApiService) UpdateUser(ServiceSid string, Sid string, params *UpdateUserParams) (*IpMessagingV2User, error) { + return c.UpdateUserWithCtx(context.TODO(), ServiceSid, Sid, params) +} + +// +func (c *ApiService) UpdateUserWithCtx(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) @@ -331,7 +367,7 @@ func (c *ApiService) UpdateUser(ServiceSid string, Sid string, params *UpdateUse headers["X-Twilio-Webhook-Enabled"] = *params.XTwilioWebhookEnabled } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 3ee4e8c86..75931aa1b 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" @@ -25,6 +26,11 @@ import ( // func (c *ApiService) DeleteUserBinding(ServiceSid string, UserSid string, Sid string) error { + return c.DeleteUserBindingWithCtx(context.TODO(), ServiceSid, UserSid, Sid) +} + +// +func (c *ApiService) DeleteUserBindingWithCtx(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) @@ -33,7 +39,7 @@ func (c *ApiService) DeleteUserBinding(ServiceSid string, UserSid string, Sid st data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -45,6 +51,11 @@ func (c *ApiService) DeleteUserBinding(ServiceSid string, UserSid string, Sid st // func (c *ApiService) FetchUserBinding(ServiceSid string, UserSid string, Sid string) (*IpMessagingV2UserBinding, error) { + return c.FetchUserBindingWithCtx(context.TODO(), ServiceSid, UserSid, Sid) +} + +// +func (c *ApiService) FetchUserBindingWithCtx(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) @@ -53,7 +64,7 @@ func (c *ApiService) FetchUserBinding(ServiceSid string, UserSid string, Sid str data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -93,6 +104,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.PageUserBindingWithCtx(context.TODO(), ServiceSid, UserSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of UserBinding records from the API. Request is executed immediately. +func (c *ApiService) PageUserBindingWithCtx(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) @@ -117,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -134,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.ListUserBindingWithCtx(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) ListUserBindingWithCtx(ctx context.Context, ServiceSid string, UserSid string, params *ListUserBindingParams) ([]IpMessagingV2UserBinding, error) { + response, errors := c.StreamUserBindingWithCtx(ctx, ServiceSid, UserSid, params) records := make([]IpMessagingV2UserBinding, 0) for record := range response { @@ -150,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.StreamUserBindingWithCtx(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) StreamUserBindingWithCtx(ctx context.Context, ServiceSid string, UserSid string, params *ListUserBindingParams) (chan IpMessagingV2UserBinding, chan error) { if params == nil { params = &ListUserBindingParams{} } @@ -158,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.PageUserBindingWithCtx(ctx, ServiceSid, UserSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUserBinding(response, params, recordChannel, errorChannel) + go c.streamUserBinding(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) streamUserBinding(ctx context.Context, response *ListUserBindingResponse, params *ListUserBindingParams, recordChannel chan IpMessagingV2UserBinding, errorChannel chan error) { curRecord := 1 for response != nil { @@ -185,7 +211,7 @@ func (c *ApiService) streamUserBinding(response *ListUserBindingResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUserBindingResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListUserBindingResponse) if err != nil { errorChannel <- err break @@ -200,11 +226,11 @@ func (c *ApiService) streamUserBinding(response *ListUserBindingResponse, params close(errorChannel) } -func (c *ApiService) getNextListUserBindingResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUserBindingResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 08d882ce7..c3d44857b 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" @@ -26,6 +27,11 @@ import ( // func (c *ApiService) DeleteUserChannel(ServiceSid string, UserSid string, ChannelSid string) error { + return c.DeleteUserChannelWithCtx(context.TODO(), ServiceSid, UserSid, ChannelSid) +} + +// +func (c *ApiService) DeleteUserChannelWithCtx(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) @@ -34,7 +40,7 @@ func (c *ApiService) DeleteUserChannel(ServiceSid string, UserSid string, Channe data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -46,6 +52,11 @@ func (c *ApiService) DeleteUserChannel(ServiceSid string, UserSid string, Channe // func (c *ApiService) FetchUserChannel(ServiceSid string, UserSid string, ChannelSid string) (*IpMessagingV2UserChannel, error) { + return c.FetchUserChannelWithCtx(context.TODO(), ServiceSid, UserSid, ChannelSid) +} + +// +func (c *ApiService) FetchUserChannelWithCtx(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) @@ -54,7 +65,7 @@ func (c *ApiService) FetchUserChannel(ServiceSid string, UserSid string, Channel data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -88,6 +99,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.PageUserChannelWithCtx(context.TODO(), ServiceSid, UserSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of UserChannel records from the API. Request is executed immediately. +func (c *ApiService) PageUserChannelWithCtx(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) @@ -107,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -124,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.ListUserChannelWithCtx(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) ListUserChannelWithCtx(ctx context.Context, ServiceSid string, UserSid string, params *ListUserChannelParams) ([]IpMessagingV2UserChannel, error) { + response, errors := c.StreamUserChannelWithCtx(ctx, ServiceSid, UserSid, params) records := make([]IpMessagingV2UserChannel, 0) for record := range response { @@ -140,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.StreamUserChannelWithCtx(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) StreamUserChannelWithCtx(ctx context.Context, ServiceSid string, UserSid string, params *ListUserChannelParams) (chan IpMessagingV2UserChannel, chan error) { if params == nil { params = &ListUserChannelParams{} } @@ -148,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.PageUserChannelWithCtx(ctx, ServiceSid, UserSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUserChannel(response, params, recordChannel, errorChannel) + go c.streamUserChannel(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) streamUserChannel(ctx context.Context, response *ListUserChannelResponse, params *ListUserChannelParams, recordChannel chan IpMessagingV2UserChannel, errorChannel chan error) { curRecord := 1 for response != nil { @@ -175,7 +201,7 @@ func (c *ApiService) streamUserChannel(response *ListUserChannelResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUserChannelResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListUserChannelResponse) if err != nil { errorChannel <- err break @@ -190,11 +216,11 @@ func (c *ApiService) streamUserChannel(response *ListUserChannelResponse, params close(errorChannel) } -func (c *ApiService) getNextListUserChannelResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUserChannelResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -233,6 +259,11 @@ func (params *UpdateUserChannelParams) SetLastConsumptionTimestamp(LastConsumpti // func (c *ApiService) UpdateUserChannel(ServiceSid string, UserSid string, ChannelSid string, params *UpdateUserChannelParams) (*IpMessagingV2UserChannel, error) { + return c.UpdateUserChannelWithCtx(context.TODO(), ServiceSid, UserSid, ChannelSid, params) +} + +// +func (c *ApiService) UpdateUserChannelWithCtx(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) @@ -251,7 +282,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.Post(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 a28eaac94..1aa9d4725 100644 --- a/rest/lookups/v1/api_service.go +++ b/rest/lookups/v1/api_service.go @@ -20,10 +20,14 @@ import ( type ApiService struct { baseURL string - requestHandler *twilio.RequestHandler + requestHandler *twilio.RequestHandlerWithCtx } func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { + return NewApiServiceWithCtx(twilio.UpgradeRequestHandler(requestHandler)) +} + +func NewApiServiceWithCtx(requestHandler *twilio.RequestHandlerWithCtx) *ApiService { return &ApiService{ requestHandler: requestHandler, baseURL: "https://lookups.twilio.com", @@ -33,3 +37,7 @@ func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { func NewApiServiceWithClient(client twilio.BaseClient) *ApiService { return NewApiService(twilio.NewRequestHandler(client)) } + +func NewApiServiceWithClientWithCtx(client twilio.BaseClientWithCtx) *ApiService { + return NewApiServiceWithCtx(twilio.NewRequestHandlerWithCtx(client)) +} diff --git a/rest/lookups/v1/phone_numbers.go b/rest/lookups/v1/phone_numbers.go index 437c00a8f..8b3321e05 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" @@ -51,6 +52,11 @@ func (params *FetchPhoneNumberParams) SetAddOnsData(AddOnsData map[string]interf // func (c *ApiService) FetchPhoneNumber(PhoneNumber string, params *FetchPhoneNumberParams) (*LookupsV1PhoneNumber, error) { + return c.FetchPhoneNumberWithCtx(context.TODO(), PhoneNumber, params) +} + +// +func (c *ApiService) FetchPhoneNumberWithCtx(ctx context.Context, PhoneNumber string, params *FetchPhoneNumberParams) (*LookupsV1PhoneNumber, error) { path := "/v1/PhoneNumbers/{PhoneNumber}" path = strings.Replace(path, "{"+"PhoneNumber"+"}", PhoneNumber, -1) @@ -80,7 +86,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.Get(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 a28eaac94..1aa9d4725 100644 --- a/rest/lookups/v2/api_service.go +++ b/rest/lookups/v2/api_service.go @@ -20,10 +20,14 @@ import ( type ApiService struct { baseURL string - requestHandler *twilio.RequestHandler + requestHandler *twilio.RequestHandlerWithCtx } func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { + return NewApiServiceWithCtx(twilio.UpgradeRequestHandler(requestHandler)) +} + +func NewApiServiceWithCtx(requestHandler *twilio.RequestHandlerWithCtx) *ApiService { return &ApiService{ requestHandler: requestHandler, baseURL: "https://lookups.twilio.com", @@ -33,3 +37,7 @@ func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { func NewApiServiceWithClient(client twilio.BaseClient) *ApiService { return NewApiService(twilio.NewRequestHandler(client)) } + +func NewApiServiceWithClientWithCtx(client twilio.BaseClientWithCtx) *ApiService { + return NewApiServiceWithCtx(twilio.NewRequestHandlerWithCtx(client)) +} diff --git a/rest/lookups/v2/phone_numbers.go b/rest/lookups/v2/phone_numbers.go index ee05a0ae3..db74d891f 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" @@ -39,6 +40,11 @@ func (params *FetchPhoneNumberParams) SetCountryCode(CountryCode string) *FetchP // func (c *ApiService) FetchPhoneNumber(PhoneNumber string, params *FetchPhoneNumberParams) (*LookupsV2PhoneNumber, error) { + return c.FetchPhoneNumberWithCtx(context.TODO(), PhoneNumber, params) +} + +// +func (c *ApiService) FetchPhoneNumberWithCtx(ctx context.Context, PhoneNumber string, params *FetchPhoneNumberParams) (*LookupsV2PhoneNumber, error) { path := "/v2/PhoneNumbers/{PhoneNumber}" path = strings.Replace(path, "{"+"PhoneNumber"+"}", PhoneNumber, -1) @@ -52,7 +58,7 @@ func (c *ApiService) FetchPhoneNumber(PhoneNumber string, params *FetchPhoneNumb data.Set("CountryCode", *params.CountryCode) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/media/v1/api_service.go b/rest/media/v1/api_service.go index 59274da84..3b80d6e77 100644 --- a/rest/media/v1/api_service.go +++ b/rest/media/v1/api_service.go @@ -20,10 +20,14 @@ import ( type ApiService struct { baseURL string - requestHandler *twilio.RequestHandler + requestHandler *twilio.RequestHandlerWithCtx } func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { + return NewApiServiceWithCtx(twilio.UpgradeRequestHandler(requestHandler)) +} + +func NewApiServiceWithCtx(requestHandler *twilio.RequestHandlerWithCtx) *ApiService { return &ApiService{ requestHandler: requestHandler, baseURL: "https://media.twilio.com", @@ -33,3 +37,7 @@ func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { func NewApiServiceWithClient(client twilio.BaseClient) *ApiService { return NewApiService(twilio.NewRequestHandler(client)) } + +func NewApiServiceWithClientWithCtx(client twilio.BaseClientWithCtx) *ApiService { + return NewApiServiceWithCtx(twilio.NewRequestHandlerWithCtx(client)) +} diff --git a/rest/media/v1/media_processors.go b/rest/media/v1/media_processors.go index ade02cd54..65440d197 100644 --- a/rest/media/v1/media_processors.go +++ b/rest/media/v1/media_processors.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -66,6 +67,11 @@ func (params *CreateMediaProcessorParams) SetMaxDuration(MaxDuration int) *Creat // func (c *ApiService) CreateMediaProcessor(params *CreateMediaProcessorParams) (*MediaV1MediaProcessor, error) { + return c.CreateMediaProcessorWithCtx(context.TODO(), params) +} + +// +func (c *ApiService) CreateMediaProcessorWithCtx(ctx context.Context, params *CreateMediaProcessorParams) (*MediaV1MediaProcessor, error) { path := "/v1/MediaProcessors" data := url.Values{} @@ -96,7 +102,7 @@ func (c *ApiService) CreateMediaProcessor(params *CreateMediaProcessorParams) (* data.Set("MaxDuration", fmt.Sprint(*params.MaxDuration)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -113,13 +119,18 @@ func (c *ApiService) CreateMediaProcessor(params *CreateMediaProcessorParams) (* // Returns a single MediaProcessor resource identified by a SID. func (c *ApiService) FetchMediaProcessor(Sid string) (*MediaV1MediaProcessor, error) { + return c.FetchMediaProcessorWithCtx(context.TODO(), Sid) +} + +// Returns a single MediaProcessor resource identified by a SID. +func (c *ApiService) FetchMediaProcessorWithCtx(ctx context.Context, Sid string) (*MediaV1MediaProcessor, error) { path := "/v1/MediaProcessors/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -165,6 +176,11 @@ func (params *ListMediaProcessorParams) SetLimit(Limit int) *ListMediaProcessorP // Retrieve a single page of MediaProcessor records from the API. Request is executed immediately. func (c *ApiService) PageMediaProcessor(params *ListMediaProcessorParams, pageToken, pageNumber string) (*ListMediaProcessorResponse, error) { + return c.PageMediaProcessorWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of MediaProcessor records from the API. Request is executed immediately. +func (c *ApiService) PageMediaProcessorWithCtx(ctx context.Context, params *ListMediaProcessorParams, pageToken, pageNumber string) (*ListMediaProcessorResponse, error) { path := "/v1/MediaProcessors" data := url.Values{} @@ -187,7 +203,7 @@ func (c *ApiService) PageMediaProcessor(params *ListMediaProcessorParams, pageTo data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -204,7 +220,12 @@ func (c *ApiService) PageMediaProcessor(params *ListMediaProcessorParams, pageTo // Lists MediaProcessor records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListMediaProcessor(params *ListMediaProcessorParams) ([]MediaV1MediaProcessor, error) { - response, errors := c.StreamMediaProcessor(params) + return c.ListMediaProcessorWithCtx(context.TODO(), params) +} + +// Lists MediaProcessor records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListMediaProcessorWithCtx(ctx context.Context, params *ListMediaProcessorParams) ([]MediaV1MediaProcessor, error) { + response, errors := c.StreamMediaProcessorWithCtx(ctx, params) records := make([]MediaV1MediaProcessor, 0) for record := range response { @@ -220,6 +241,11 @@ func (c *ApiService) ListMediaProcessor(params *ListMediaProcessorParams) ([]Med // Streams MediaProcessor records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamMediaProcessor(params *ListMediaProcessorParams) (chan MediaV1MediaProcessor, chan error) { + return c.StreamMediaProcessorWithCtx(context.TODO(), params) +} + +// Streams MediaProcessor records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamMediaProcessorWithCtx(ctx context.Context, params *ListMediaProcessorParams) (chan MediaV1MediaProcessor, chan error) { if params == nil { params = &ListMediaProcessorParams{} } @@ -228,19 +254,19 @@ func (c *ApiService) StreamMediaProcessor(params *ListMediaProcessorParams) (cha recordChannel := make(chan MediaV1MediaProcessor, 1) errorChannel := make(chan error, 1) - response, err := c.PageMediaProcessor(params, "", "") + response, err := c.PageMediaProcessorWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamMediaProcessor(response, params, recordChannel, errorChannel) + go c.streamMediaProcessor(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamMediaProcessor(response *ListMediaProcessorResponse, params *ListMediaProcessorParams, recordChannel chan MediaV1MediaProcessor, errorChannel chan error) { +func (c *ApiService) streamMediaProcessor(ctx context.Context, response *ListMediaProcessorResponse, params *ListMediaProcessorParams, recordChannel chan MediaV1MediaProcessor, errorChannel chan error) { curRecord := 1 for response != nil { @@ -255,7 +281,7 @@ func (c *ApiService) streamMediaProcessor(response *ListMediaProcessorResponse, } } - record, err := client.GetNext(c.baseURL, response, c.getNextListMediaProcessorResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListMediaProcessorResponse) if err != nil { errorChannel <- err break @@ -270,11 +296,11 @@ func (c *ApiService) streamMediaProcessor(response *ListMediaProcessorResponse, close(errorChannel) } -func (c *ApiService) getNextListMediaProcessorResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListMediaProcessorResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -301,6 +327,11 @@ func (params *UpdateMediaProcessorParams) SetStatus(Status string) *UpdateMediaP // Updates a MediaProcessor resource identified by a SID. func (c *ApiService) UpdateMediaProcessor(Sid string, params *UpdateMediaProcessorParams) (*MediaV1MediaProcessor, error) { + return c.UpdateMediaProcessorWithCtx(context.TODO(), Sid, params) +} + +// Updates a MediaProcessor resource identified by a SID. +func (c *ApiService) UpdateMediaProcessorWithCtx(ctx context.Context, Sid string, params *UpdateMediaProcessorParams) (*MediaV1MediaProcessor, error) { path := "/v1/MediaProcessors/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -311,7 +342,7 @@ func (c *ApiService) UpdateMediaProcessor(Sid string, params *UpdateMediaProcess data.Set("Status", *params.Status) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/media/v1/media_recordings.go b/rest/media/v1/media_recordings.go index 631f8a8c2..c04f54d9b 100644 --- a/rest/media/v1/media_recordings.go +++ b/rest/media/v1/media_recordings.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -25,13 +26,18 @@ import ( // Deletes a MediaRecording resource identified by a SID. func (c *ApiService) DeleteMediaRecording(Sid string) error { + return c.DeleteMediaRecordingWithCtx(context.TODO(), Sid) +} + +// Deletes a MediaRecording resource identified by a SID. +func (c *ApiService) DeleteMediaRecordingWithCtx(ctx context.Context, Sid string) error { path := "/v1/MediaRecordings/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -43,13 +49,18 @@ func (c *ApiService) DeleteMediaRecording(Sid string) error { // Returns a single MediaRecording resource identified by a SID. func (c *ApiService) FetchMediaRecording(Sid string) (*MediaV1MediaRecording, error) { + return c.FetchMediaRecordingWithCtx(context.TODO(), Sid) +} + +// Returns a single MediaRecording resource identified by a SID. +func (c *ApiService) FetchMediaRecordingWithCtx(ctx context.Context, Sid string) (*MediaV1MediaRecording, error) { path := "/v1/MediaRecordings/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -107,6 +118,11 @@ func (params *ListMediaRecordingParams) SetLimit(Limit int) *ListMediaRecordingP // Retrieve a single page of MediaRecording records from the API. Request is executed immediately. func (c *ApiService) PageMediaRecording(params *ListMediaRecordingParams, pageToken, pageNumber string) (*ListMediaRecordingResponse, error) { + return c.PageMediaRecordingWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of MediaRecording records from the API. Request is executed immediately. +func (c *ApiService) PageMediaRecordingWithCtx(ctx context.Context, params *ListMediaRecordingParams, pageToken, pageNumber string) (*ListMediaRecordingResponse, error) { path := "/v1/MediaRecordings" data := url.Values{} @@ -135,7 +151,7 @@ func (c *ApiService) PageMediaRecording(params *ListMediaRecordingParams, pageTo data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -152,7 +168,12 @@ func (c *ApiService) PageMediaRecording(params *ListMediaRecordingParams, pageTo // Lists MediaRecording records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListMediaRecording(params *ListMediaRecordingParams) ([]MediaV1MediaRecording, error) { - response, errors := c.StreamMediaRecording(params) + return c.ListMediaRecordingWithCtx(context.TODO(), params) +} + +// Lists MediaRecording records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListMediaRecordingWithCtx(ctx context.Context, params *ListMediaRecordingParams) ([]MediaV1MediaRecording, error) { + response, errors := c.StreamMediaRecordingWithCtx(ctx, params) records := make([]MediaV1MediaRecording, 0) for record := range response { @@ -168,6 +189,11 @@ func (c *ApiService) ListMediaRecording(params *ListMediaRecordingParams) ([]Med // Streams MediaRecording records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamMediaRecording(params *ListMediaRecordingParams) (chan MediaV1MediaRecording, chan error) { + return c.StreamMediaRecordingWithCtx(context.TODO(), params) +} + +// Streams MediaRecording records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamMediaRecordingWithCtx(ctx context.Context, params *ListMediaRecordingParams) (chan MediaV1MediaRecording, chan error) { if params == nil { params = &ListMediaRecordingParams{} } @@ -176,19 +202,19 @@ func (c *ApiService) StreamMediaRecording(params *ListMediaRecordingParams) (cha recordChannel := make(chan MediaV1MediaRecording, 1) errorChannel := make(chan error, 1) - response, err := c.PageMediaRecording(params, "", "") + response, err := c.PageMediaRecordingWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamMediaRecording(response, params, recordChannel, errorChannel) + go c.streamMediaRecording(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamMediaRecording(response *ListMediaRecordingResponse, params *ListMediaRecordingParams, recordChannel chan MediaV1MediaRecording, errorChannel chan error) { +func (c *ApiService) streamMediaRecording(ctx context.Context, response *ListMediaRecordingResponse, params *ListMediaRecordingParams, recordChannel chan MediaV1MediaRecording, errorChannel chan error) { curRecord := 1 for response != nil { @@ -203,7 +229,7 @@ func (c *ApiService) streamMediaRecording(response *ListMediaRecordingResponse, } } - record, err := client.GetNext(c.baseURL, response, c.getNextListMediaRecordingResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListMediaRecordingResponse) if err != nil { errorChannel <- err break @@ -218,11 +244,11 @@ func (c *ApiService) streamMediaRecording(response *ListMediaRecordingResponse, close(errorChannel) } -func (c *ApiService) getNextListMediaRecordingResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListMediaRecordingResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/media/v1/player_streamers.go b/rest/media/v1/player_streamers.go index ca3ea7781..8abe48e14 100644 --- a/rest/media/v1/player_streamers.go +++ b/rest/media/v1/player_streamers.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -54,6 +55,11 @@ func (params *CreatePlayerStreamerParams) SetMaxDuration(MaxDuration int) *Creat // func (c *ApiService) CreatePlayerStreamer(params *CreatePlayerStreamerParams) (*MediaV1PlayerStreamer, error) { + return c.CreatePlayerStreamerWithCtx(context.TODO(), params) +} + +// +func (c *ApiService) CreatePlayerStreamerWithCtx(ctx context.Context, params *CreatePlayerStreamerParams) (*MediaV1PlayerStreamer, error) { path := "/v1/PlayerStreamers" data := url.Values{} @@ -72,7 +78,7 @@ func (c *ApiService) CreatePlayerStreamer(params *CreatePlayerStreamerParams) (* data.Set("MaxDuration", fmt.Sprint(*params.MaxDuration)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -89,13 +95,18 @@ func (c *ApiService) CreatePlayerStreamer(params *CreatePlayerStreamerParams) (* // Returns a single PlayerStreamer resource identified by a SID. func (c *ApiService) FetchPlayerStreamer(Sid string) (*MediaV1PlayerStreamer, error) { + return c.FetchPlayerStreamerWithCtx(context.TODO(), Sid) +} + +// Returns a single PlayerStreamer resource identified by a SID. +func (c *ApiService) FetchPlayerStreamerWithCtx(ctx context.Context, Sid string) (*MediaV1PlayerStreamer, error) { path := "/v1/PlayerStreamers/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -141,6 +152,11 @@ func (params *ListPlayerStreamerParams) SetLimit(Limit int) *ListPlayerStreamerP // Retrieve a single page of PlayerStreamer records from the API. Request is executed immediately. func (c *ApiService) PagePlayerStreamer(params *ListPlayerStreamerParams, pageToken, pageNumber string) (*ListPlayerStreamerResponse, error) { + return c.PagePlayerStreamerWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of PlayerStreamer records from the API. Request is executed immediately. +func (c *ApiService) PagePlayerStreamerWithCtx(ctx context.Context, params *ListPlayerStreamerParams, pageToken, pageNumber string) (*ListPlayerStreamerResponse, error) { path := "/v1/PlayerStreamers" data := url.Values{} @@ -163,7 +179,7 @@ func (c *ApiService) PagePlayerStreamer(params *ListPlayerStreamerParams, pageTo data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -180,7 +196,12 @@ func (c *ApiService) PagePlayerStreamer(params *ListPlayerStreamerParams, pageTo // Lists PlayerStreamer records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. func (c *ApiService) ListPlayerStreamer(params *ListPlayerStreamerParams) ([]MediaV1PlayerStreamer, error) { - response, errors := c.StreamPlayerStreamer(params) + return c.ListPlayerStreamerWithCtx(context.TODO(), params) +} + +// Lists PlayerStreamer records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. +func (c *ApiService) ListPlayerStreamerWithCtx(ctx context.Context, params *ListPlayerStreamerParams) ([]MediaV1PlayerStreamer, error) { + response, errors := c.StreamPlayerStreamerWithCtx(ctx, params) records := make([]MediaV1PlayerStreamer, 0) for record := range response { @@ -196,6 +217,11 @@ func (c *ApiService) ListPlayerStreamer(params *ListPlayerStreamerParams) ([]Med // Streams PlayerStreamer records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. func (c *ApiService) StreamPlayerStreamer(params *ListPlayerStreamerParams) (chan MediaV1PlayerStreamer, chan error) { + return c.StreamPlayerStreamerWithCtx(context.TODO(), params) +} + +// Streams PlayerStreamer records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. +func (c *ApiService) StreamPlayerStreamerWithCtx(ctx context.Context, params *ListPlayerStreamerParams) (chan MediaV1PlayerStreamer, chan error) { if params == nil { params = &ListPlayerStreamerParams{} } @@ -204,19 +230,19 @@ func (c *ApiService) StreamPlayerStreamer(params *ListPlayerStreamerParams) (cha recordChannel := make(chan MediaV1PlayerStreamer, 1) errorChannel := make(chan error, 1) - response, err := c.PagePlayerStreamer(params, "", "") + response, err := c.PagePlayerStreamerWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamPlayerStreamer(response, params, recordChannel, errorChannel) + go c.streamPlayerStreamer(ctx, response, params, recordChannel, errorChannel) } return recordChannel, errorChannel } -func (c *ApiService) streamPlayerStreamer(response *ListPlayerStreamerResponse, params *ListPlayerStreamerParams, recordChannel chan MediaV1PlayerStreamer, errorChannel chan error) { +func (c *ApiService) streamPlayerStreamer(ctx context.Context, response *ListPlayerStreamerResponse, params *ListPlayerStreamerParams, recordChannel chan MediaV1PlayerStreamer, errorChannel chan error) { curRecord := 1 for response != nil { @@ -231,7 +257,7 @@ func (c *ApiService) streamPlayerStreamer(response *ListPlayerStreamerResponse, } } - record, err := client.GetNext(c.baseURL, response, c.getNextListPlayerStreamerResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListPlayerStreamerResponse) if err != nil { errorChannel <- err break @@ -246,11 +272,11 @@ func (c *ApiService) streamPlayerStreamer(response *ListPlayerStreamerResponse, close(errorChannel) } -func (c *ApiService) getNextListPlayerStreamerResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListPlayerStreamerResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -277,6 +303,11 @@ func (params *UpdatePlayerStreamerParams) SetStatus(Status string) *UpdatePlayer // Updates a PlayerStreamer resource identified by a SID. func (c *ApiService) UpdatePlayerStreamer(Sid string, params *UpdatePlayerStreamerParams) (*MediaV1PlayerStreamer, error) { + return c.UpdatePlayerStreamerWithCtx(context.TODO(), Sid, params) +} + +// Updates a PlayerStreamer resource identified by a SID. +func (c *ApiService) UpdatePlayerStreamerWithCtx(ctx context.Context, Sid string, params *UpdatePlayerStreamerParams) (*MediaV1PlayerStreamer, error) { path := "/v1/PlayerStreamers/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -287,7 +318,7 @@ func (c *ApiService) UpdatePlayerStreamer(Sid string, params *UpdatePlayerStream data.Set("Status", *params.Status) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/media/v1/player_streamers_playback_grant.go b/rest/media/v1/player_streamers_playback_grant.go index 9ad55e06a..11aa484b6 100644 --- a/rest/media/v1/player_streamers_playback_grant.go +++ b/rest/media/v1/player_streamers_playback_grant.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "fmt" "net/url" @@ -40,6 +41,11 @@ func (params *CreatePlayerStreamerPlaybackGrantParams) SetAccessControlAllowOrig // func (c *ApiService) CreatePlayerStreamerPlaybackGrant(Sid string, params *CreatePlayerStreamerPlaybackGrantParams) (*MediaV1PlayerStreamerPlaybackGrant, error) { + return c.CreatePlayerStreamerPlaybackGrantWithCtx(context.TODO(), Sid, params) +} + +// +func (c *ApiService) CreatePlayerStreamerPlaybackGrantWithCtx(ctx context.Context, Sid string, params *CreatePlayerStreamerPlaybackGrantParams) (*MediaV1PlayerStreamerPlaybackGrant, error) { path := "/v1/PlayerStreamers/{Sid}/PlaybackGrant" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -53,7 +59,7 @@ func (c *ApiService) CreatePlayerStreamerPlaybackGrant(Sid string, params *Creat data.Set("AccessControlAllowOrigin", *params.AccessControlAllowOrigin) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -70,13 +76,18 @@ func (c *ApiService) CreatePlayerStreamerPlaybackGrant(Sid string, params *Creat // **This method is not enabled.** Returns a single PlaybackGrant resource identified by a SID. func (c *ApiService) FetchPlayerStreamerPlaybackGrant(Sid string) (*MediaV1PlayerStreamerPlaybackGrant, error) { + return c.FetchPlayerStreamerPlaybackGrantWithCtx(context.TODO(), Sid) +} + +// **This method is not enabled.** Returns a single PlaybackGrant resource identified by a SID. +func (c *ApiService) FetchPlayerStreamerPlaybackGrantWithCtx(ctx context.Context, Sid string) (*MediaV1PlayerStreamerPlaybackGrant, error) { path := "/v1/PlayerStreamers/{Sid}/PlaybackGrant" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) 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 c4cab73dd..085e05711 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" @@ -60,6 +61,11 @@ func (params *CreateBrandRegistrationsParams) SetSkipAutomaticSecVet(SkipAutomat // func (c *ApiService) CreateBrandRegistrations(params *CreateBrandRegistrationsParams) (*MessagingV1BrandRegistrations, error) { + return c.CreateBrandRegistrationsWithCtx(context.TODO(), params) +} + +// +func (c *ApiService) CreateBrandRegistrationsWithCtx(ctx context.Context, params *CreateBrandRegistrationsParams) (*MessagingV1BrandRegistrations, error) { path := "/v1/a2p/BrandRegistrations" data := url.Values{} @@ -81,7 +87,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -98,13 +104,18 @@ func (c *ApiService) CreateBrandRegistrations(params *CreateBrandRegistrationsPa // func (c *ApiService) FetchBrandRegistrations(Sid string) (*MessagingV1BrandRegistrations, error) { + return c.FetchBrandRegistrationsWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) FetchBrandRegistrationsWithCtx(ctx context.Context, Sid string) (*MessagingV1BrandRegistrations, error) { path := "/v1/a2p/BrandRegistrations/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -138,6 +149,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.PageBrandRegistrationsWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of BrandRegistrations records from the API. Request is executed immediately. +func (c *ApiService) PageBrandRegistrationsWithCtx(ctx context.Context, params *ListBrandRegistrationsParams, pageToken, pageNumber string) (*ListBrandRegistrationsResponse, error) { path := "/v1/a2p/BrandRegistrations" data := url.Values{} @@ -154,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -171,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.ListBrandRegistrationsWithCtx(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) ListBrandRegistrationsWithCtx(ctx context.Context, params *ListBrandRegistrationsParams) ([]MessagingV1BrandRegistrations, error) { + response, errors := c.StreamBrandRegistrationsWithCtx(ctx, params) records := make([]MessagingV1BrandRegistrations, 0) for record := range response { @@ -187,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.StreamBrandRegistrationsWithCtx(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) StreamBrandRegistrationsWithCtx(ctx context.Context, params *ListBrandRegistrationsParams) (chan MessagingV1BrandRegistrations, chan error) { if params == nil { params = &ListBrandRegistrationsParams{} } @@ -195,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.PageBrandRegistrationsWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamBrandRegistrations(response, params, recordChannel, errorChannel) + go c.streamBrandRegistrations(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) streamBrandRegistrations(ctx context.Context, response *ListBrandRegistrationsResponse, params *ListBrandRegistrationsParams, recordChannel chan MessagingV1BrandRegistrations, errorChannel chan error) { curRecord := 1 for response != nil { @@ -222,7 +248,7 @@ func (c *ApiService) streamBrandRegistrations(response *ListBrandRegistrationsRe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListBrandRegistrationsResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListBrandRegistrationsResponse) if err != nil { errorChannel <- err break @@ -237,11 +263,11 @@ func (c *ApiService) streamBrandRegistrations(response *ListBrandRegistrationsRe close(errorChannel) } -func (c *ApiService) getNextListBrandRegistrationsResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListBrandRegistrationsResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -257,13 +283,18 @@ func (c *ApiService) getNextListBrandRegistrationsResponse(nextPageUrl string) ( // func (c *ApiService) UpdateBrandRegistrations(Sid string) (*MessagingV1BrandRegistrations, error) { + return c.UpdateBrandRegistrationsWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) UpdateBrandRegistrationsWithCtx(ctx context.Context, Sid string) (*MessagingV1BrandRegistrations, error) { path := "/v1/a2p/BrandRegistrations/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 b7e46cdcd..d602dd864 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" @@ -42,6 +43,11 @@ func (params *CreateBrandVettingParams) SetVettingId(VettingId string) *CreateBr // func (c *ApiService) CreateBrandVetting(BrandSid string, params *CreateBrandVettingParams) (*MessagingV1BrandVetting, error) { + return c.CreateBrandVettingWithCtx(context.TODO(), BrandSid, params) +} + +// +func (c *ApiService) CreateBrandVettingWithCtx(ctx context.Context, BrandSid string, params *CreateBrandVettingParams) (*MessagingV1BrandVetting, error) { path := "/v1/a2p/BrandRegistrations/{BrandSid}/Vettings" path = strings.Replace(path, "{"+"BrandSid"+"}", BrandSid, -1) @@ -55,7 +61,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -72,6 +78,11 @@ func (c *ApiService) CreateBrandVetting(BrandSid string, params *CreateBrandVett // func (c *ApiService) FetchBrandVetting(BrandSid string, BrandVettingSid string) (*MessagingV1BrandVetting, error) { + return c.FetchBrandVettingWithCtx(context.TODO(), BrandSid, BrandVettingSid) +} + +// +func (c *ApiService) FetchBrandVettingWithCtx(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) @@ -79,7 +90,7 @@ func (c *ApiService) FetchBrandVetting(BrandSid string, BrandVettingSid string) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -119,6 +130,11 @@ func (params *ListBrandVettingParams) SetLimit(Limit int) *ListBrandVettingParam // 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.PageBrandVettingWithCtx(context.TODO(), BrandSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of BrandVetting records from the API. Request is executed immediately. +func (c *ApiService) PageBrandVettingWithCtx(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) @@ -140,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -157,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.ListBrandVettingWithCtx(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) ListBrandVettingWithCtx(ctx context.Context, BrandSid string, params *ListBrandVettingParams) ([]MessagingV1BrandVetting, error) { + response, errors := c.StreamBrandVettingWithCtx(ctx, BrandSid, params) records := make([]MessagingV1BrandVetting, 0) for record := range response { @@ -173,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.StreamBrandVettingWithCtx(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) StreamBrandVettingWithCtx(ctx context.Context, BrandSid string, params *ListBrandVettingParams) (chan MessagingV1BrandVetting, chan error) { if params == nil { params = &ListBrandVettingParams{} } @@ -181,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.PageBrandVettingWithCtx(ctx, BrandSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamBrandVetting(response, params, recordChannel, errorChannel) + go c.streamBrandVetting(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) streamBrandVetting(ctx context.Context, response *ListBrandVettingResponse, params *ListBrandVettingParams, recordChannel chan MessagingV1BrandVetting, errorChannel chan error) { curRecord := 1 for response != nil { @@ -208,7 +234,7 @@ func (c *ApiService) streamBrandVetting(response *ListBrandVettingResponse, para } } - record, err := client.GetNext(c.baseURL, response, c.getNextListBrandVettingResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListBrandVettingResponse) if err != nil { errorChannel <- err break @@ -223,11 +249,11 @@ func (c *ApiService) streamBrandVetting(response *ListBrandVettingResponse, para close(errorChannel) } -func (c *ApiService) getNextListBrandVettingResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListBrandVettingResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 434465673..01724f091 100644 --- a/rest/messaging/v1/api_service.go +++ b/rest/messaging/v1/api_service.go @@ -20,10 +20,14 @@ import ( type ApiService struct { baseURL string - requestHandler *twilio.RequestHandler + requestHandler *twilio.RequestHandlerWithCtx } func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { + return NewApiServiceWithCtx(twilio.UpgradeRequestHandler(requestHandler)) +} + +func NewApiServiceWithCtx(requestHandler *twilio.RequestHandlerWithCtx) *ApiService { return &ApiService{ requestHandler: requestHandler, baseURL: "https://messaging.twilio.com", @@ -33,3 +37,7 @@ func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { func NewApiServiceWithClient(client twilio.BaseClient) *ApiService { return NewApiService(twilio.NewRequestHandler(client)) } + +func NewApiServiceWithClientWithCtx(client twilio.BaseClientWithCtx) *ApiService { + return NewApiServiceWithCtx(twilio.NewRequestHandlerWithCtx(client)) +} diff --git a/rest/messaging/v1/deactivations.go b/rest/messaging/v1/deactivations.go index 198672a9f..d586c055a 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,11 @@ 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.FetchDeactivationWithCtx(context.TODO(), params) +} + +// Fetch a list of all United States numbers that have been deactivated on a specific date. +func (c *ApiService) FetchDeactivationWithCtx(ctx context.Context, params *FetchDeactivationParams) (*MessagingV1Deactivation, error) { path := "/v1/Deactivations" data := url.Values{} @@ -42,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.Get(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 712b099c4..1c50a6edd 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" @@ -126,6 +127,11 @@ func (params *CreateServiceParams) SetUseInboundWebhookOnNumber(UseInboundWebhoo // func (c *ApiService) CreateService(params *CreateServiceParams) (*MessagingV1Service, error) { + return c.CreateServiceWithCtx(context.TODO(), params) +} + +// +func (c *ApiService) CreateServiceWithCtx(ctx context.Context, params *CreateServiceParams) (*MessagingV1Service, error) { path := "/v1/Services" data := url.Values{} @@ -180,7 +186,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -197,13 +203,18 @@ func (c *ApiService) CreateService(params *CreateServiceParams) (*MessagingV1Ser // func (c *ApiService) DeleteService(Sid string) error { + return c.DeleteServiceWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) DeleteServiceWithCtx(ctx context.Context, Sid string) error { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -215,13 +226,18 @@ func (c *ApiService) DeleteService(Sid string) error { // func (c *ApiService) FetchService(Sid string) (*MessagingV1Service, error) { + return c.FetchServiceWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) FetchServiceWithCtx(ctx context.Context, Sid string) (*MessagingV1Service, error) { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -255,6 +271,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.PageServiceWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Service records from the API. Request is executed immediately. +func (c *ApiService) PageServiceWithCtx(ctx context.Context, params *ListServiceParams, pageToken, pageNumber string) (*ListServiceResponse, error) { path := "/v1/Services" data := url.Values{} @@ -271,7 +292,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -288,7 +309,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.ListServiceWithCtx(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) ListServiceWithCtx(ctx context.Context, params *ListServiceParams) ([]MessagingV1Service, error) { + response, errors := c.StreamServiceWithCtx(ctx, params) records := make([]MessagingV1Service, 0) for record := range response { @@ -304,6 +330,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.StreamServiceWithCtx(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) StreamServiceWithCtx(ctx context.Context, params *ListServiceParams) (chan MessagingV1Service, chan error) { if params == nil { params = &ListServiceParams{} } @@ -312,19 +343,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.PageServiceWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamService(response, params, recordChannel, errorChannel) + go c.streamService(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) streamService(ctx context.Context, response *ListServiceResponse, params *ListServiceParams, recordChannel chan MessagingV1Service, errorChannel chan error) { curRecord := 1 for response != nil { @@ -339,7 +370,7 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListServiceResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListServiceResponse) if err != nil { errorChannel <- err break @@ -354,11 +385,11 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe close(errorChannel) } -func (c *ApiService) getNextListServiceResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListServiceResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -475,6 +506,11 @@ func (params *UpdateServiceParams) SetUseInboundWebhookOnNumber(UseInboundWebhoo // func (c *ApiService) UpdateService(Sid string, params *UpdateServiceParams) (*MessagingV1Service, error) { + return c.UpdateServiceWithCtx(context.TODO(), Sid, params) +} + +// +func (c *ApiService) UpdateServiceWithCtx(ctx context.Context, Sid string, params *UpdateServiceParams) (*MessagingV1Service, error) { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -530,7 +566,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.Post(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 c8a5639cb..6163bd3a7 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" @@ -36,6 +37,11 @@ func (params *CreateAlphaSenderParams) SetAlphaSender(AlphaSender string) *Creat // func (c *ApiService) CreateAlphaSender(ServiceSid string, params *CreateAlphaSenderParams) (*MessagingV1AlphaSender, error) { + return c.CreateAlphaSenderWithCtx(context.TODO(), ServiceSid, params) +} + +// +func (c *ApiService) CreateAlphaSenderWithCtx(ctx context.Context, ServiceSid string, params *CreateAlphaSenderParams) (*MessagingV1AlphaSender, error) { path := "/v1/Services/{ServiceSid}/AlphaSenders" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -46,7 +52,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -63,6 +69,11 @@ func (c *ApiService) CreateAlphaSender(ServiceSid string, params *CreateAlphaSen // func (c *ApiService) DeleteAlphaSender(ServiceSid string, Sid string) error { + return c.DeleteAlphaSenderWithCtx(context.TODO(), ServiceSid, Sid) +} + +// +func (c *ApiService) DeleteAlphaSenderWithCtx(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) @@ -70,7 +81,7 @@ func (c *ApiService) DeleteAlphaSender(ServiceSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -82,6 +93,11 @@ func (c *ApiService) DeleteAlphaSender(ServiceSid string, Sid string) error { // func (c *ApiService) FetchAlphaSender(ServiceSid string, Sid string) (*MessagingV1AlphaSender, error) { + return c.FetchAlphaSenderWithCtx(context.TODO(), ServiceSid, Sid) +} + +// +func (c *ApiService) FetchAlphaSenderWithCtx(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) @@ -89,7 +105,7 @@ func (c *ApiService) FetchAlphaSender(ServiceSid string, Sid string) (*Messaging data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -123,6 +139,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.PageAlphaSenderWithCtx(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of AlphaSender records from the API. Request is executed immediately. +func (c *ApiService) PageAlphaSenderWithCtx(ctx context.Context, ServiceSid string, params *ListAlphaSenderParams, pageToken, pageNumber string) (*ListAlphaSenderResponse, error) { path := "/v1/Services/{ServiceSid}/AlphaSenders" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -141,7 +162,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -158,7 +179,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.ListAlphaSenderWithCtx(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) ListAlphaSenderWithCtx(ctx context.Context, ServiceSid string, params *ListAlphaSenderParams) ([]MessagingV1AlphaSender, error) { + response, errors := c.StreamAlphaSenderWithCtx(ctx, ServiceSid, params) records := make([]MessagingV1AlphaSender, 0) for record := range response { @@ -174,6 +200,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.StreamAlphaSenderWithCtx(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) StreamAlphaSenderWithCtx(ctx context.Context, ServiceSid string, params *ListAlphaSenderParams) (chan MessagingV1AlphaSender, chan error) { if params == nil { params = &ListAlphaSenderParams{} } @@ -182,19 +213,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.PageAlphaSenderWithCtx(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamAlphaSender(response, params, recordChannel, errorChannel) + go c.streamAlphaSender(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) streamAlphaSender(ctx context.Context, response *ListAlphaSenderResponse, params *ListAlphaSenderParams, recordChannel chan MessagingV1AlphaSender, errorChannel chan error) { curRecord := 1 for response != nil { @@ -209,7 +240,7 @@ func (c *ApiService) streamAlphaSender(response *ListAlphaSenderResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListAlphaSenderResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListAlphaSenderResponse) if err != nil { errorChannel <- err break @@ -224,11 +255,11 @@ func (c *ApiService) streamAlphaSender(response *ListAlphaSenderResponse, params close(errorChannel) } -func (c *ApiService) getNextListAlphaSenderResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListAlphaSenderResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 0fdfc82f5..cdb92fe6f 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" @@ -66,6 +67,11 @@ func (params *CreateUsAppToPersonParams) SetHasEmbeddedPhone(HasEmbeddedPhone bo // func (c *ApiService) CreateUsAppToPerson(MessagingServiceSid string, params *CreateUsAppToPersonParams) (*MessagingV1UsAppToPerson, error) { + return c.CreateUsAppToPersonWithCtx(context.TODO(), MessagingServiceSid, params) +} + +// +func (c *ApiService) CreateUsAppToPersonWithCtx(ctx context.Context, MessagingServiceSid string, params *CreateUsAppToPersonParams) (*MessagingV1UsAppToPerson, error) { path := "/v1/Services/{MessagingServiceSid}/Compliance/Usa2p" path = strings.Replace(path, "{"+"MessagingServiceSid"+"}", MessagingServiceSid, -1) @@ -93,7 +99,7 @@ func (c *ApiService) CreateUsAppToPerson(MessagingServiceSid string, params *Cre data.Set("HasEmbeddedPhone", fmt.Sprint(*params.HasEmbeddedPhone)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -110,6 +116,11 @@ func (c *ApiService) CreateUsAppToPerson(MessagingServiceSid string, params *Cre // func (c *ApiService) DeleteUsAppToPerson(MessagingServiceSid string, Sid string) error { + return c.DeleteUsAppToPersonWithCtx(context.TODO(), MessagingServiceSid, Sid) +} + +// +func (c *ApiService) DeleteUsAppToPersonWithCtx(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) @@ -117,7 +128,7 @@ func (c *ApiService) DeleteUsAppToPerson(MessagingServiceSid string, Sid string) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -129,6 +140,11 @@ func (c *ApiService) DeleteUsAppToPerson(MessagingServiceSid string, Sid string) // func (c *ApiService) FetchUsAppToPerson(MessagingServiceSid string, Sid string) (*MessagingV1UsAppToPerson, error) { + return c.FetchUsAppToPersonWithCtx(context.TODO(), MessagingServiceSid, Sid) +} + +// +func (c *ApiService) FetchUsAppToPersonWithCtx(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) @@ -136,7 +152,7 @@ func (c *ApiService) FetchUsAppToPerson(MessagingServiceSid string, Sid string) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -170,6 +186,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.PageUsAppToPersonWithCtx(context.TODO(), MessagingServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of UsAppToPerson records from the API. Request is executed immediately. +func (c *ApiService) PageUsAppToPersonWithCtx(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) @@ -188,7 +209,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -205,7 +226,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.ListUsAppToPersonWithCtx(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) ListUsAppToPersonWithCtx(ctx context.Context, MessagingServiceSid string, params *ListUsAppToPersonParams) ([]MessagingV1UsAppToPerson, error) { + response, errors := c.StreamUsAppToPersonWithCtx(ctx, MessagingServiceSid, params) records := make([]MessagingV1UsAppToPerson, 0) for record := range response { @@ -221,6 +247,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.StreamUsAppToPersonWithCtx(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) StreamUsAppToPersonWithCtx(ctx context.Context, MessagingServiceSid string, params *ListUsAppToPersonParams) (chan MessagingV1UsAppToPerson, chan error) { if params == nil { params = &ListUsAppToPersonParams{} } @@ -229,19 +260,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.PageUsAppToPersonWithCtx(ctx, MessagingServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUsAppToPerson(response, params, recordChannel, errorChannel) + go c.streamUsAppToPerson(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) streamUsAppToPerson(ctx context.Context, response *ListUsAppToPersonResponse, params *ListUsAppToPersonParams, recordChannel chan MessagingV1UsAppToPerson, errorChannel chan error) { curRecord := 1 for response != nil { @@ -256,7 +287,7 @@ func (c *ApiService) streamUsAppToPerson(response *ListUsAppToPersonResponse, pa } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUsAppToPersonResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListUsAppToPersonResponse) if err != nil { errorChannel <- err break @@ -271,11 +302,11 @@ func (c *ApiService) streamUsAppToPerson(response *ListUsAppToPersonResponse, pa close(errorChannel) } -func (c *ApiService) getNextListUsAppToPersonResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUsAppToPersonResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) 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 93a7586c0..895ce2201 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" @@ -33,6 +34,11 @@ func (params *FetchUsAppToPersonUsecaseParams) SetBrandRegistrationSid(BrandRegi // func (c *ApiService) FetchUsAppToPersonUsecase(MessagingServiceSid string, params *FetchUsAppToPersonUsecaseParams) (*MessagingV1UsAppToPersonUsecase, error) { + return c.FetchUsAppToPersonUsecaseWithCtx(context.TODO(), MessagingServiceSid, params) +} + +// +func (c *ApiService) FetchUsAppToPersonUsecaseWithCtx(ctx context.Context, MessagingServiceSid string, params *FetchUsAppToPersonUsecaseParams) (*MessagingV1UsAppToPersonUsecase, error) { path := "/v1/Services/{MessagingServiceSid}/Compliance/Usa2p/Usecases" path = strings.Replace(path, "{"+"MessagingServiceSid"+"}", MessagingServiceSid, -1) @@ -43,7 +49,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.Get(ctx, c.baseURL+path, data, headers) 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 1f2f48fbb..29f8f8494 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" @@ -36,6 +37,11 @@ func (params *CreatePhoneNumberParams) SetPhoneNumberSid(PhoneNumberSid string) // func (c *ApiService) CreatePhoneNumber(ServiceSid string, params *CreatePhoneNumberParams) (*MessagingV1PhoneNumber, error) { + return c.CreatePhoneNumberWithCtx(context.TODO(), ServiceSid, params) +} + +// +func (c *ApiService) CreatePhoneNumberWithCtx(ctx context.Context, ServiceSid string, params *CreatePhoneNumberParams) (*MessagingV1PhoneNumber, error) { path := "/v1/Services/{ServiceSid}/PhoneNumbers" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -46,7 +52,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -63,6 +69,11 @@ func (c *ApiService) CreatePhoneNumber(ServiceSid string, params *CreatePhoneNum // func (c *ApiService) DeletePhoneNumber(ServiceSid string, Sid string) error { + return c.DeletePhoneNumberWithCtx(context.TODO(), ServiceSid, Sid) +} + +// +func (c *ApiService) DeletePhoneNumberWithCtx(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) @@ -70,7 +81,7 @@ func (c *ApiService) DeletePhoneNumber(ServiceSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -82,6 +93,11 @@ func (c *ApiService) DeletePhoneNumber(ServiceSid string, Sid string) error { // func (c *ApiService) FetchPhoneNumber(ServiceSid string, Sid string) (*MessagingV1PhoneNumber, error) { + return c.FetchPhoneNumberWithCtx(context.TODO(), ServiceSid, Sid) +} + +// +func (c *ApiService) FetchPhoneNumberWithCtx(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) @@ -89,7 +105,7 @@ func (c *ApiService) FetchPhoneNumber(ServiceSid string, Sid string) (*Messaging data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -123,6 +139,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.PagePhoneNumberWithCtx(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of PhoneNumber records from the API. Request is executed immediately. +func (c *ApiService) PagePhoneNumberWithCtx(ctx context.Context, ServiceSid string, params *ListPhoneNumberParams, pageToken, pageNumber string) (*ListPhoneNumberResponse, error) { path := "/v1/Services/{ServiceSid}/PhoneNumbers" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -141,7 +162,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -158,7 +179,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.ListPhoneNumberWithCtx(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) ListPhoneNumberWithCtx(ctx context.Context, ServiceSid string, params *ListPhoneNumberParams) ([]MessagingV1PhoneNumber, error) { + response, errors := c.StreamPhoneNumberWithCtx(ctx, ServiceSid, params) records := make([]MessagingV1PhoneNumber, 0) for record := range response { @@ -174,6 +200,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.StreamPhoneNumberWithCtx(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) StreamPhoneNumberWithCtx(ctx context.Context, ServiceSid string, params *ListPhoneNumberParams) (chan MessagingV1PhoneNumber, chan error) { if params == nil { params = &ListPhoneNumberParams{} } @@ -182,19 +213,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.PagePhoneNumberWithCtx(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamPhoneNumber(response, params, recordChannel, errorChannel) + go c.streamPhoneNumber(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) streamPhoneNumber(ctx context.Context, response *ListPhoneNumberResponse, params *ListPhoneNumberParams, recordChannel chan MessagingV1PhoneNumber, errorChannel chan error) { curRecord := 1 for response != nil { @@ -209,7 +240,7 @@ func (c *ApiService) streamPhoneNumber(response *ListPhoneNumberResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListPhoneNumberResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListPhoneNumberResponse) if err != nil { errorChannel <- err break @@ -224,11 +255,11 @@ func (c *ApiService) streamPhoneNumber(response *ListPhoneNumberResponse, params close(errorChannel) } -func (c *ApiService) getNextListPhoneNumberResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListPhoneNumberResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 246c876c7..eb63252ad 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" "net/url" ) @@ -38,6 +39,11 @@ func (params *CreateExternalCampaignParams) SetMessagingServiceSid(MessagingServ // func (c *ApiService) CreateExternalCampaign(params *CreateExternalCampaignParams) (*MessagingV1ExternalCampaign, error) { + return c.CreateExternalCampaignWithCtx(context.TODO(), params) +} + +// +func (c *ApiService) CreateExternalCampaignWithCtx(ctx context.Context, params *CreateExternalCampaignParams) (*MessagingV1ExternalCampaign, error) { path := "/v1/Services/PreregisteredUsa2p" data := url.Values{} @@ -50,7 +56,7 @@ func (c *ApiService) CreateExternalCampaign(params *CreateExternalCampaignParams data.Set("MessagingServiceSid", *params.MessagingServiceSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 19745e3d4..81f8b3dc6 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" @@ -36,6 +37,11 @@ func (params *CreateShortCodeParams) SetShortCodeSid(ShortCodeSid string) *Creat // func (c *ApiService) CreateShortCode(ServiceSid string, params *CreateShortCodeParams) (*MessagingV1ShortCode, error) { + return c.CreateShortCodeWithCtx(context.TODO(), ServiceSid, params) +} + +// +func (c *ApiService) CreateShortCodeWithCtx(ctx context.Context, ServiceSid string, params *CreateShortCodeParams) (*MessagingV1ShortCode, error) { path := "/v1/Services/{ServiceSid}/ShortCodes" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -46,7 +52,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -63,6 +69,11 @@ func (c *ApiService) CreateShortCode(ServiceSid string, params *CreateShortCodeP // func (c *ApiService) DeleteShortCode(ServiceSid string, Sid string) error { + return c.DeleteShortCodeWithCtx(context.TODO(), ServiceSid, Sid) +} + +// +func (c *ApiService) DeleteShortCodeWithCtx(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) @@ -70,7 +81,7 @@ func (c *ApiService) DeleteShortCode(ServiceSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -82,6 +93,11 @@ func (c *ApiService) DeleteShortCode(ServiceSid string, Sid string) error { // func (c *ApiService) FetchShortCode(ServiceSid string, Sid string) (*MessagingV1ShortCode, error) { + return c.FetchShortCodeWithCtx(context.TODO(), ServiceSid, Sid) +} + +// +func (c *ApiService) FetchShortCodeWithCtx(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) @@ -89,7 +105,7 @@ func (c *ApiService) FetchShortCode(ServiceSid string, Sid string) (*MessagingV1 data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -123,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.PageShortCodeWithCtx(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ShortCode records from the API. Request is executed immediately. +func (c *ApiService) PageShortCodeWithCtx(ctx context.Context, ServiceSid string, params *ListShortCodeParams, pageToken, pageNumber string) (*ListShortCodeResponse, error) { path := "/v1/Services/{ServiceSid}/ShortCodes" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -141,7 +162,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -158,7 +179,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.ListShortCodeWithCtx(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) ListShortCodeWithCtx(ctx context.Context, ServiceSid string, params *ListShortCodeParams) ([]MessagingV1ShortCode, error) { + response, errors := c.StreamShortCodeWithCtx(ctx, ServiceSid, params) records := make([]MessagingV1ShortCode, 0) for record := range response { @@ -174,6 +200,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.StreamShortCodeWithCtx(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) StreamShortCodeWithCtx(ctx context.Context, ServiceSid string, params *ListShortCodeParams) (chan MessagingV1ShortCode, chan error) { if params == nil { params = &ListShortCodeParams{} } @@ -182,19 +213,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.PageShortCodeWithCtx(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamShortCode(response, params, recordChannel, errorChannel) + go c.streamShortCode(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) streamShortCode(ctx context.Context, response *ListShortCodeResponse, params *ListShortCodeParams, recordChannel chan MessagingV1ShortCode, errorChannel chan error) { curRecord := 1 for response != nil { @@ -209,7 +240,7 @@ func (c *ApiService) streamShortCode(response *ListShortCodeResponse, params *Li } } - record, err := client.GetNext(c.baseURL, response, c.getNextListShortCodeResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListShortCodeResponse) if err != nil { errorChannel <- err break @@ -224,11 +255,11 @@ func (c *ApiService) streamShortCode(response *ListShortCodeResponse, params *Li close(errorChannel) } -func (c *ApiService) getNextListShortCodeResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListShortCodeResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 6fd408723..90449c666 100644 --- a/rest/messaging/v1/services_usecases.go +++ b/rest/messaging/v1/services_usecases.go @@ -15,18 +15,24 @@ package openapi import ( + "context" "encoding/json" "net/url" ) // func (c *ApiService) FetchUsecase() (*MessagingV1Usecase, error) { + return c.FetchUsecaseWithCtx(context.TODO()) +} + +// +func (c *ApiService) FetchUsecaseWithCtx(ctx context.Context) (*MessagingV1Usecase, error) { path := "/v1/Services/Usecases" data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(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 5be13960a..85bbbf233 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" @@ -162,6 +163,11 @@ func (params *CreateTollfreeVerificationParams) SetBusinessContactPhone(Business // func (c *ApiService) CreateTollfreeVerification(params *CreateTollfreeVerificationParams) (*MessagingV1TollfreeVerification, error) { + return c.CreateTollfreeVerificationWithCtx(context.TODO(), params) +} + +// +func (c *ApiService) CreateTollfreeVerificationWithCtx(ctx context.Context, params *CreateTollfreeVerificationParams) (*MessagingV1TollfreeVerification, error) { path := "/v1/Tollfree/Verifications" data := url.Values{} @@ -238,7 +244,7 @@ func (c *ApiService) CreateTollfreeVerification(params *CreateTollfreeVerificati data.Set("BusinessContactPhone", *params.BusinessContactPhone) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -255,13 +261,18 @@ func (c *ApiService) CreateTollfreeVerification(params *CreateTollfreeVerificati // func (c *ApiService) FetchTollfreeVerification(Sid string) (*MessagingV1TollfreeVerification, error) { + return c.FetchTollfreeVerificationWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) FetchTollfreeVerificationWithCtx(ctx context.Context, Sid string) (*MessagingV1TollfreeVerification, error) { path := "/v1/Tollfree/Verifications/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -307,6 +318,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.PageTollfreeVerificationWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of TollfreeVerification records from the API. Request is executed immediately. +func (c *ApiService) PageTollfreeVerificationWithCtx(ctx context.Context, params *ListTollfreeVerificationParams, pageToken, pageNumber string) (*ListTollfreeVerificationResponse, error) { path := "/v1/Tollfree/Verifications" data := url.Values{} @@ -329,7 +345,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -346,7 +362,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.ListTollfreeVerificationWithCtx(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) ListTollfreeVerificationWithCtx(ctx context.Context, params *ListTollfreeVerificationParams) ([]MessagingV1TollfreeVerification, error) { + response, errors := c.StreamTollfreeVerificationWithCtx(ctx, params) records := make([]MessagingV1TollfreeVerification, 0) for record := range response { @@ -362,6 +383,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.StreamTollfreeVerificationWithCtx(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) StreamTollfreeVerificationWithCtx(ctx context.Context, params *ListTollfreeVerificationParams) (chan MessagingV1TollfreeVerification, chan error) { if params == nil { params = &ListTollfreeVerificationParams{} } @@ -370,19 +396,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.PageTollfreeVerificationWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamTollfreeVerification(response, params, recordChannel, errorChannel) + go c.streamTollfreeVerification(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) streamTollfreeVerification(ctx context.Context, response *ListTollfreeVerificationResponse, params *ListTollfreeVerificationParams, recordChannel chan MessagingV1TollfreeVerification, errorChannel chan error) { curRecord := 1 for response != nil { @@ -397,7 +423,7 @@ func (c *ApiService) streamTollfreeVerification(response *ListTollfreeVerificati } } - record, err := client.GetNext(c.baseURL, response, c.getNextListTollfreeVerificationResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListTollfreeVerificationResponse) if err != nil { errorChannel <- err break @@ -412,11 +438,11 @@ func (c *ApiService) streamTollfreeVerification(response *ListTollfreeVerificati close(errorChannel) } -func (c *ApiService) getNextListTollfreeVerificationResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListTollfreeVerificationResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/microvisor/v1/api_service.go b/rest/microvisor/v1/api_service.go index 2df498b86..7bcf00c7f 100644 --- a/rest/microvisor/v1/api_service.go +++ b/rest/microvisor/v1/api_service.go @@ -20,10 +20,14 @@ import ( type ApiService struct { baseURL string - requestHandler *twilio.RequestHandler + requestHandler *twilio.RequestHandlerWithCtx } func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { + return NewApiServiceWithCtx(twilio.UpgradeRequestHandler(requestHandler)) +} + +func NewApiServiceWithCtx(requestHandler *twilio.RequestHandlerWithCtx) *ApiService { return &ApiService{ requestHandler: requestHandler, baseURL: "https://microvisor.twilio.com", @@ -33,3 +37,7 @@ func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { func NewApiServiceWithClient(client twilio.BaseClient) *ApiService { return NewApiService(twilio.NewRequestHandler(client)) } + +func NewApiServiceWithClientWithCtx(client twilio.BaseClientWithCtx) *ApiService { + return NewApiServiceWithCtx(twilio.NewRequestHandlerWithCtx(client)) +} diff --git a/rest/microvisor/v1/apps.go b/rest/microvisor/v1/apps.go index 31c92a719..314b12c87 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,13 +26,18 @@ import ( // Delete a specific App. func (c *ApiService) DeleteApp(Sid string) error { + return c.DeleteAppWithCtx(context.TODO(), Sid) +} + +// Delete a specific App. +func (c *ApiService) DeleteAppWithCtx(ctx context.Context, Sid string) error { path := "/v1/Apps/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -43,13 +49,18 @@ func (c *ApiService) DeleteApp(Sid string) error { // Fetch a specific App. func (c *ApiService) FetchApp(Sid string) (*MicrovisorV1App, error) { + return c.FetchAppWithCtx(context.TODO(), Sid) +} + +// Fetch a specific App. +func (c *ApiService) FetchAppWithCtx(ctx context.Context, Sid string) (*MicrovisorV1App, error) { path := "/v1/Apps/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -83,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.PageAppWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of App records from the API. Request is executed immediately. +func (c *ApiService) PageAppWithCtx(ctx context.Context, params *ListAppParams, pageToken, pageNumber string) (*ListAppResponse, error) { path := "/v1/Apps" data := url.Values{} @@ -99,7 +115,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -116,7 +132,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.ListAppWithCtx(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) ListAppWithCtx(ctx context.Context, params *ListAppParams) ([]MicrovisorV1App, error) { + response, errors := c.StreamAppWithCtx(ctx, params) records := make([]MicrovisorV1App, 0) for record := range response { @@ -132,6 +153,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.StreamAppWithCtx(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) StreamAppWithCtx(ctx context.Context, params *ListAppParams) (chan MicrovisorV1App, chan error) { if params == nil { params = &ListAppParams{} } @@ -140,19 +166,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.PageAppWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamApp(response, params, recordChannel, errorChannel) + go c.streamApp(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) streamApp(ctx context.Context, response *ListAppResponse, params *ListAppParams, recordChannel chan MicrovisorV1App, errorChannel chan error) { curRecord := 1 for response != nil { @@ -167,7 +193,7 @@ func (c *ApiService) streamApp(response *ListAppResponse, params *ListAppParams, } } - record, err := client.GetNext(c.baseURL, response, c.getNextListAppResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListAppResponse) if err != nil { errorChannel <- err break @@ -182,11 +208,11 @@ func (c *ApiService) streamApp(response *ListAppResponse, params *ListAppParams, close(errorChannel) } -func (c *ApiService) getNextListAppResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListAppResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } diff --git a/rest/microvisor/v1/devices.go b/rest/microvisor/v1/devices.go index dd1357a17..88b441ce8 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,13 +26,18 @@ import ( // Fetch a specific Device. func (c *ApiService) FetchDevice(Sid string) (*MicrovisorV1Device, error) { + return c.FetchDeviceWithCtx(context.TODO(), Sid) +} + +// Fetch a specific Device. +func (c *ApiService) FetchDeviceWithCtx(ctx context.Context, Sid string) (*MicrovisorV1Device, error) { path := "/v1/Devices/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -65,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.PageDeviceWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Device records from the API. Request is executed immediately. +func (c *ApiService) PageDeviceWithCtx(ctx context.Context, params *ListDeviceParams, pageToken, pageNumber string) (*ListDeviceResponse, error) { path := "/v1/Devices" data := url.Values{} @@ -81,7 +92,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -98,7 +109,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.ListDeviceWithCtx(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) ListDeviceWithCtx(ctx context.Context, params *ListDeviceParams) ([]MicrovisorV1Device, error) { + response, errors := c.StreamDeviceWithCtx(ctx, params) records := make([]MicrovisorV1Device, 0) for record := range response { @@ -114,6 +130,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.StreamDeviceWithCtx(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) StreamDeviceWithCtx(ctx context.Context, params *ListDeviceParams) (chan MicrovisorV1Device, chan error) { if params == nil { params = &ListDeviceParams{} } @@ -122,19 +143,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.PageDeviceWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamDevice(response, params, recordChannel, errorChannel) + go c.streamDevice(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) streamDevice(ctx context.Context, response *ListDeviceResponse, params *ListDeviceParams, recordChannel chan MicrovisorV1Device, errorChannel chan error) { curRecord := 1 for response != nil { @@ -149,7 +170,7 @@ func (c *ApiService) streamDevice(response *ListDeviceResponse, params *ListDevi } } - record, err := client.GetNext(c.baseURL, response, c.getNextListDeviceResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListDeviceResponse) if err != nil { errorChannel <- err break @@ -164,11 +185,11 @@ func (c *ApiService) streamDevice(response *ListDeviceResponse, params *ListDevi close(errorChannel) } -func (c *ApiService) getNextListDeviceResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListDeviceResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -207,6 +228,11 @@ func (params *UpdateDeviceParams) SetLoggingEnabled(LoggingEnabled bool) *Update // Update a specific Device. func (c *ApiService) UpdateDevice(Sid string, params *UpdateDeviceParams) (*MicrovisorV1Device, error) { + return c.UpdateDeviceWithCtx(context.TODO(), Sid, params) +} + +// Update a specific Device. +func (c *ApiService) UpdateDeviceWithCtx(ctx context.Context, Sid string, params *UpdateDeviceParams) (*MicrovisorV1Device, error) { path := "/v1/Devices/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -223,7 +249,7 @@ func (c *ApiService) UpdateDevice(Sid string, params *UpdateDeviceParams) (*Micr data.Set("LoggingEnabled", fmt.Sprint(*params.LoggingEnabled)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 7fc808c65..dd79f6549 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" @@ -26,13 +27,18 @@ import ( // func (c *ApiService) FetchAlert(Sid string) (*MonitorV1AlertInstance, error) { + return c.FetchAlertWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) FetchAlertWithCtx(ctx context.Context, Sid string) (*MonitorV1AlertInstance, error) { path := "/v1/Alerts/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -84,6 +90,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.PageAlertWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Alert records from the API. Request is executed immediately. +func (c *ApiService) PageAlertWithCtx(ctx context.Context, params *ListAlertParams, pageToken, pageNumber string) (*ListAlertResponse, error) { path := "/v1/Alerts" data := url.Values{} @@ -109,7 +120,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -126,7 +137,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.ListAlertWithCtx(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) ListAlertWithCtx(ctx context.Context, params *ListAlertParams) ([]MonitorV1Alert, error) { + response, errors := c.StreamAlertWithCtx(ctx, params) records := make([]MonitorV1Alert, 0) for record := range response { @@ -142,6 +158,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.StreamAlertWithCtx(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) StreamAlertWithCtx(ctx context.Context, params *ListAlertParams) (chan MonitorV1Alert, chan error) { if params == nil { params = &ListAlertParams{} } @@ -150,19 +171,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.PageAlertWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamAlert(response, params, recordChannel, errorChannel) + go c.streamAlert(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) streamAlert(ctx context.Context, response *ListAlertResponse, params *ListAlertParams, recordChannel chan MonitorV1Alert, errorChannel chan error) { curRecord := 1 for response != nil { @@ -177,7 +198,7 @@ func (c *ApiService) streamAlert(response *ListAlertResponse, params *ListAlertP } } - record, err := client.GetNext(c.baseURL, response, c.getNextListAlertResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListAlertResponse) if err != nil { errorChannel <- err break @@ -192,11 +213,11 @@ func (c *ApiService) streamAlert(response *ListAlertResponse, params *ListAlertP close(errorChannel) } -func (c *ApiService) getNextListAlertResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListAlertResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 c1d89c5b3..21858e638 100644 --- a/rest/monitor/v1/api_service.go +++ b/rest/monitor/v1/api_service.go @@ -20,10 +20,14 @@ import ( type ApiService struct { baseURL string - requestHandler *twilio.RequestHandler + requestHandler *twilio.RequestHandlerWithCtx } func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { + return NewApiServiceWithCtx(twilio.UpgradeRequestHandler(requestHandler)) +} + +func NewApiServiceWithCtx(requestHandler *twilio.RequestHandlerWithCtx) *ApiService { return &ApiService{ requestHandler: requestHandler, baseURL: "https://monitor.twilio.com", @@ -33,3 +37,7 @@ func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { func NewApiServiceWithClient(client twilio.BaseClient) *ApiService { return NewApiService(twilio.NewRequestHandler(client)) } + +func NewApiServiceWithClientWithCtx(client twilio.BaseClientWithCtx) *ApiService { + return NewApiServiceWithCtx(twilio.NewRequestHandlerWithCtx(client)) +} diff --git a/rest/monitor/v1/events.go b/rest/monitor/v1/events.go index 98492ac46..edc9925c3 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" @@ -26,13 +27,18 @@ import ( // func (c *ApiService) FetchEvent(Sid string) (*MonitorV1Event, error) { + return c.FetchEventWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) FetchEventWithCtx(ctx context.Context, Sid string) (*MonitorV1Event, error) { path := "/v1/Events/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -102,6 +108,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.PageEventWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Event records from the API. Request is executed immediately. +func (c *ApiService) PageEventWithCtx(ctx context.Context, params *ListEventParams, pageToken, pageNumber string) (*ListEventResponse, error) { path := "/v1/Events" data := url.Values{} @@ -136,7 +147,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -153,7 +164,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.ListEventWithCtx(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) ListEventWithCtx(ctx context.Context, params *ListEventParams) ([]MonitorV1Event, error) { + response, errors := c.StreamEventWithCtx(ctx, params) records := make([]MonitorV1Event, 0) for record := range response { @@ -169,6 +185,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.StreamEventWithCtx(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) StreamEventWithCtx(ctx context.Context, params *ListEventParams) (chan MonitorV1Event, chan error) { if params == nil { params = &ListEventParams{} } @@ -177,19 +198,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.PageEventWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamEvent(response, params, recordChannel, errorChannel) + go c.streamEvent(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) streamEvent(ctx context.Context, response *ListEventResponse, params *ListEventParams, recordChannel chan MonitorV1Event, errorChannel chan error) { curRecord := 1 for response != nil { @@ -204,7 +225,7 @@ func (c *ApiService) streamEvent(response *ListEventResponse, params *ListEventP } } - record, err := client.GetNext(c.baseURL, response, c.getNextListEventResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListEventResponse) if err != nil { errorChannel <- err break @@ -219,11 +240,11 @@ func (c *ApiService) streamEvent(response *ListEventResponse, params *ListEventP close(errorChannel) } -func (c *ApiService) getNextListEventResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListEventResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 ff6ad6508..178319724 100644 --- a/rest/notify/v1/api_service.go +++ b/rest/notify/v1/api_service.go @@ -20,10 +20,14 @@ import ( type ApiService struct { baseURL string - requestHandler *twilio.RequestHandler + requestHandler *twilio.RequestHandlerWithCtx } func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { + return NewApiServiceWithCtx(twilio.UpgradeRequestHandler(requestHandler)) +} + +func NewApiServiceWithCtx(requestHandler *twilio.RequestHandlerWithCtx) *ApiService { return &ApiService{ requestHandler: requestHandler, baseURL: "https://notify.twilio.com", @@ -33,3 +37,7 @@ func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { func NewApiServiceWithClient(client twilio.BaseClient) *ApiService { return NewApiService(twilio.NewRequestHandler(client)) } + +func NewApiServiceWithClientWithCtx(client twilio.BaseClientWithCtx) *ApiService { + return NewApiServiceWithCtx(twilio.NewRequestHandlerWithCtx(client)) +} diff --git a/rest/notify/v1/credentials.go b/rest/notify/v1/credentials.go index 196d912d3..7eb4dc9a5 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" @@ -72,6 +73,11 @@ func (params *CreateCredentialParams) SetSecret(Secret string) *CreateCredential // func (c *ApiService) CreateCredential(params *CreateCredentialParams) (*NotifyV1Credential, error) { + return c.CreateCredentialWithCtx(context.TODO(), params) +} + +// +func (c *ApiService) CreateCredentialWithCtx(ctx context.Context, params *CreateCredentialParams) (*NotifyV1Credential, error) { path := "/v1/Credentials" data := url.Values{} @@ -99,7 +105,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -116,13 +122,18 @@ func (c *ApiService) CreateCredential(params *CreateCredentialParams) (*NotifyV1 // func (c *ApiService) DeleteCredential(Sid string) error { + return c.DeleteCredentialWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) DeleteCredentialWithCtx(ctx context.Context, Sid string) error { path := "/v1/Credentials/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -134,13 +145,18 @@ func (c *ApiService) DeleteCredential(Sid string) error { // func (c *ApiService) FetchCredential(Sid string) (*NotifyV1Credential, error) { + return c.FetchCredentialWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) FetchCredentialWithCtx(ctx context.Context, Sid string) (*NotifyV1Credential, error) { path := "/v1/Credentials/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -174,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.PageCredentialWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Credential records from the API. Request is executed immediately. +func (c *ApiService) PageCredentialWithCtx(ctx context.Context, params *ListCredentialParams, pageToken, pageNumber string) (*ListCredentialResponse, error) { path := "/v1/Credentials" data := url.Values{} @@ -190,7 +211,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -207,7 +228,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.ListCredentialWithCtx(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) ListCredentialWithCtx(ctx context.Context, params *ListCredentialParams) ([]NotifyV1Credential, error) { + response, errors := c.StreamCredentialWithCtx(ctx, params) records := make([]NotifyV1Credential, 0) for record := range response { @@ -223,6 +249,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.StreamCredentialWithCtx(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) StreamCredentialWithCtx(ctx context.Context, params *ListCredentialParams) (chan NotifyV1Credential, chan error) { if params == nil { params = &ListCredentialParams{} } @@ -231,19 +262,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.PageCredentialWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamCredential(response, params, recordChannel, errorChannel) + go c.streamCredential(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) streamCredential(ctx context.Context, response *ListCredentialResponse, params *ListCredentialParams, recordChannel chan NotifyV1Credential, errorChannel chan error) { curRecord := 1 for response != nil { @@ -258,7 +289,7 @@ func (c *ApiService) streamCredential(response *ListCredentialResponse, params * } } - record, err := client.GetNext(c.baseURL, response, c.getNextListCredentialResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListCredentialResponse) if err != nil { errorChannel <- err break @@ -273,11 +304,11 @@ func (c *ApiService) streamCredential(response *ListCredentialResponse, params * close(errorChannel) } -func (c *ApiService) getNextListCredentialResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListCredentialResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -334,6 +365,11 @@ func (params *UpdateCredentialParams) SetSecret(Secret string) *UpdateCredential // func (c *ApiService) UpdateCredential(Sid string, params *UpdateCredentialParams) (*NotifyV1Credential, error) { + return c.UpdateCredentialWithCtx(context.TODO(), Sid, params) +} + +// +func (c *ApiService) UpdateCredentialWithCtx(ctx context.Context, Sid string, params *UpdateCredentialParams) (*NotifyV1Credential, error) { path := "/v1/Credentials/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -359,7 +395,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.Post(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 5a6e5f81e..4e75b345c 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" @@ -114,6 +115,11 @@ func (params *CreateServiceParams) SetDeliveryCallbackEnabled(DeliveryCallbackEn // func (c *ApiService) CreateService(params *CreateServiceParams) (*NotifyV1Service, error) { + return c.CreateServiceWithCtx(context.TODO(), params) +} + +// +func (c *ApiService) CreateServiceWithCtx(ctx context.Context, params *CreateServiceParams) (*NotifyV1Service, error) { path := "/v1/Services" data := url.Values{} @@ -162,7 +168,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -179,13 +185,18 @@ func (c *ApiService) CreateService(params *CreateServiceParams) (*NotifyV1Servic // func (c *ApiService) DeleteService(Sid string) error { + return c.DeleteServiceWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) DeleteServiceWithCtx(ctx context.Context, Sid string) error { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -197,13 +208,18 @@ func (c *ApiService) DeleteService(Sid string) error { // func (c *ApiService) FetchService(Sid string) (*NotifyV1Service, error) { + return c.FetchServiceWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) FetchServiceWithCtx(ctx context.Context, Sid string) (*NotifyV1Service, error) { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -243,6 +259,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.PageServiceWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Service records from the API. Request is executed immediately. +func (c *ApiService) PageServiceWithCtx(ctx context.Context, params *ListServiceParams, pageToken, pageNumber string) (*ListServiceResponse, error) { path := "/v1/Services" data := url.Values{} @@ -262,7 +283,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -279,7 +300,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.ListServiceWithCtx(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) ListServiceWithCtx(ctx context.Context, params *ListServiceParams) ([]NotifyV1Service, error) { + response, errors := c.StreamServiceWithCtx(ctx, params) records := make([]NotifyV1Service, 0) for record := range response { @@ -295,6 +321,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.StreamServiceWithCtx(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) StreamServiceWithCtx(ctx context.Context, params *ListServiceParams) (chan NotifyV1Service, chan error) { if params == nil { params = &ListServiceParams{} } @@ -303,19 +334,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.PageServiceWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamService(response, params, recordChannel, errorChannel) + go c.streamService(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) streamService(ctx context.Context, response *ListServiceResponse, params *ListServiceParams, recordChannel chan NotifyV1Service, errorChannel chan error) { curRecord := 1 for response != nil { @@ -330,7 +361,7 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListServiceResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListServiceResponse) if err != nil { errorChannel <- err break @@ -345,11 +376,11 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe close(errorChannel) } -func (c *ApiService) getNextListServiceResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListServiceResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -454,6 +485,11 @@ func (params *UpdateServiceParams) SetDeliveryCallbackEnabled(DeliveryCallbackEn // func (c *ApiService) UpdateService(Sid string, params *UpdateServiceParams) (*NotifyV1Service, error) { + return c.UpdateServiceWithCtx(context.TODO(), Sid, params) +} + +// +func (c *ApiService) UpdateServiceWithCtx(ctx context.Context, Sid string, params *UpdateServiceParams) (*NotifyV1Service, error) { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -503,7 +539,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.Post(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 6240d68eb..037963cb9 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" @@ -72,6 +73,11 @@ func (params *CreateBindingParams) SetEndpoint(Endpoint string) *CreateBindingPa // func (c *ApiService) CreateBinding(ServiceSid string, params *CreateBindingParams) (*NotifyV1Binding, error) { + return c.CreateBindingWithCtx(context.TODO(), ServiceSid, params) +} + +// +func (c *ApiService) CreateBindingWithCtx(ctx context.Context, ServiceSid string, params *CreateBindingParams) (*NotifyV1Binding, error) { path := "/v1/Services/{ServiceSid}/Bindings" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -102,7 +108,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -119,6 +125,11 @@ func (c *ApiService) CreateBinding(ServiceSid string, params *CreateBindingParam // func (c *ApiService) DeleteBinding(ServiceSid string, Sid string) error { + return c.DeleteBindingWithCtx(context.TODO(), ServiceSid, Sid) +} + +// +func (c *ApiService) DeleteBindingWithCtx(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) @@ -126,7 +137,7 @@ func (c *ApiService) DeleteBinding(ServiceSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -138,6 +149,11 @@ func (c *ApiService) DeleteBinding(ServiceSid string, Sid string) error { // func (c *ApiService) FetchBinding(ServiceSid string, Sid string) (*NotifyV1Binding, error) { + return c.FetchBindingWithCtx(context.TODO(), ServiceSid, Sid) +} + +// +func (c *ApiService) FetchBindingWithCtx(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) @@ -145,7 +161,7 @@ func (c *ApiService) FetchBinding(ServiceSid string, Sid string) (*NotifyV1Bindi data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -203,6 +219,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.PageBindingWithCtx(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Binding records from the API. Request is executed immediately. +func (c *ApiService) PageBindingWithCtx(ctx context.Context, ServiceSid string, params *ListBindingParams, pageToken, pageNumber string) (*ListBindingResponse, error) { path := "/v1/Services/{ServiceSid}/Bindings" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -237,7 +258,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -254,7 +275,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.ListBindingWithCtx(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) ListBindingWithCtx(ctx context.Context, ServiceSid string, params *ListBindingParams) ([]NotifyV1Binding, error) { + response, errors := c.StreamBindingWithCtx(ctx, ServiceSid, params) records := make([]NotifyV1Binding, 0) for record := range response { @@ -270,6 +296,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.StreamBindingWithCtx(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) StreamBindingWithCtx(ctx context.Context, ServiceSid string, params *ListBindingParams) (chan NotifyV1Binding, chan error) { if params == nil { params = &ListBindingParams{} } @@ -278,19 +309,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.PageBindingWithCtx(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamBinding(response, params, recordChannel, errorChannel) + go c.streamBinding(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) streamBinding(ctx context.Context, response *ListBindingResponse, params *ListBindingParams, recordChannel chan NotifyV1Binding, errorChannel chan error) { curRecord := 1 for response != nil { @@ -305,7 +336,7 @@ func (c *ApiService) streamBinding(response *ListBindingResponse, params *ListBi } } - record, err := client.GetNext(c.baseURL, response, c.getNextListBindingResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListBindingResponse) if err != nil { errorChannel <- err break @@ -320,11 +351,11 @@ func (c *ApiService) streamBinding(response *ListBindingResponse, params *ListBi close(errorChannel) } -func (c *ApiService) getNextListBindingResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListBindingResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 91bfbcc1c..bfb64e9c3 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" @@ -136,6 +137,11 @@ func (params *CreateNotificationParams) SetTag(Tag []string) *CreateNotification // func (c *ApiService) CreateNotification(ServiceSid string, params *CreateNotificationParams) (*NotifyV1Notification, error) { + return c.CreateNotificationWithCtx(context.TODO(), ServiceSid, params) +} + +// +func (c *ApiService) CreateNotificationWithCtx(ctx context.Context, ServiceSid string, params *CreateNotificationParams) (*NotifyV1Notification, error) { path := "/v1/Services/{ServiceSid}/Notifications" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -247,7 +253,7 @@ func (c *ApiService) CreateNotification(ServiceSid string, params *CreateNotific } } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/numbers/v2/api_service.go b/rest/numbers/v2/api_service.go index 46727785d..39ce8098c 100644 --- a/rest/numbers/v2/api_service.go +++ b/rest/numbers/v2/api_service.go @@ -20,10 +20,14 @@ import ( type ApiService struct { baseURL string - requestHandler *twilio.RequestHandler + requestHandler *twilio.RequestHandlerWithCtx } func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { + return NewApiServiceWithCtx(twilio.UpgradeRequestHandler(requestHandler)) +} + +func NewApiServiceWithCtx(requestHandler *twilio.RequestHandlerWithCtx) *ApiService { return &ApiService{ requestHandler: requestHandler, baseURL: "https://numbers.twilio.com", @@ -33,3 +37,7 @@ func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { func NewApiServiceWithClient(client twilio.BaseClient) *ApiService { return NewApiService(twilio.NewRequestHandler(client)) } + +func NewApiServiceWithClientWithCtx(client twilio.BaseClientWithCtx) *ApiService { + return NewApiServiceWithCtx(twilio.NewRequestHandlerWithCtx(client)) +} diff --git a/rest/numbers/v2/regulatory_compliance_bundles.go b/rest/numbers/v2/regulatory_compliance_bundles.go index cd0a3c8d2..4f1597b5a 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" @@ -73,6 +74,11 @@ func (params *CreateBundleParams) SetNumberType(NumberType string) *CreateBundle // Create a new Bundle. func (c *ApiService) CreateBundle(params *CreateBundleParams) (*NumbersV2Bundle, error) { + return c.CreateBundleWithCtx(context.TODO(), params) +} + +// Create a new Bundle. +func (c *ApiService) CreateBundleWithCtx(ctx context.Context, params *CreateBundleParams) (*NumbersV2Bundle, error) { path := "/v2/RegulatoryCompliance/Bundles" data := url.Values{} @@ -100,7 +106,7 @@ func (c *ApiService) CreateBundle(params *CreateBundleParams) (*NumbersV2Bundle, data.Set("NumberType", *params.NumberType) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -117,13 +123,18 @@ func (c *ApiService) CreateBundle(params *CreateBundleParams) (*NumbersV2Bundle, // Delete a specific Bundle. func (c *ApiService) DeleteBundle(Sid string) error { + return c.DeleteBundleWithCtx(context.TODO(), Sid) +} + +// Delete a specific Bundle. +func (c *ApiService) DeleteBundleWithCtx(ctx context.Context, Sid string) error { path := "/v2/RegulatoryCompliance/Bundles/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -135,13 +146,18 @@ func (c *ApiService) DeleteBundle(Sid string) error { // Fetch a specific Bundle instance. func (c *ApiService) FetchBundle(Sid string) (*NumbersV2Bundle, error) { + return c.FetchBundleWithCtx(context.TODO(), Sid) +} + +// Fetch a specific Bundle instance. +func (c *ApiService) FetchBundleWithCtx(ctx context.Context, Sid string) (*NumbersV2Bundle, error) { path := "/v2/RegulatoryCompliance/Bundles/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -241,6 +257,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.PageBundleWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Bundle records from the API. Request is executed immediately. +func (c *ApiService) PageBundleWithCtx(ctx context.Context, params *ListBundleParams, pageToken, pageNumber string) (*ListBundleResponse, error) { path := "/v2/RegulatoryCompliance/Bundles" data := url.Values{} @@ -290,7 +311,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -307,7 +328,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.ListBundleWithCtx(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) ListBundleWithCtx(ctx context.Context, params *ListBundleParams) ([]NumbersV2Bundle, error) { + response, errors := c.StreamBundleWithCtx(ctx, params) records := make([]NumbersV2Bundle, 0) for record := range response { @@ -323,6 +349,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.StreamBundleWithCtx(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) StreamBundleWithCtx(ctx context.Context, params *ListBundleParams) (chan NumbersV2Bundle, chan error) { if params == nil { params = &ListBundleParams{} } @@ -331,19 +362,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.PageBundleWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamBundle(response, params, recordChannel, errorChannel) + go c.streamBundle(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) streamBundle(ctx context.Context, response *ListBundleResponse, params *ListBundleParams, recordChannel chan NumbersV2Bundle, errorChannel chan error) { curRecord := 1 for response != nil { @@ -358,7 +389,7 @@ func (c *ApiService) streamBundle(response *ListBundleResponse, params *ListBund } } - record, err := client.GetNext(c.baseURL, response, c.getNextListBundleResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListBundleResponse) if err != nil { errorChannel <- err break @@ -373,11 +404,11 @@ func (c *ApiService) streamBundle(response *ListBundleResponse, params *ListBund close(errorChannel) } -func (c *ApiService) getNextListBundleResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListBundleResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -422,6 +453,11 @@ 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.UpdateBundleWithCtx(context.TODO(), Sid, params) +} + +// Updates a Bundle in an account. +func (c *ApiService) UpdateBundleWithCtx(ctx context.Context, Sid string, params *UpdateBundleParams) (*NumbersV2Bundle, error) { path := "/v2/RegulatoryCompliance/Bundles/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -441,7 +477,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.Post(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 b8e6f66e3..525bd7f01 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,11 @@ 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.CreateBundleCopyWithCtx(context.TODO(), BundleSid, params) +} + +// 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) CreateBundleCopyWithCtx(ctx context.Context, BundleSid string, params *CreateBundleCopyParams) (*NumbersV2BundleCopy, error) { path := "/v2/RegulatoryCompliance/Bundles/{BundleSid}/Copies" path = strings.Replace(path, "{"+"BundleSid"+"}", BundleSid, -1) @@ -46,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -80,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.PageBundleCopyWithCtx(context.TODO(), BundleSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of BundleCopy records from the API. Request is executed immediately. +func (c *ApiService) PageBundleCopyWithCtx(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) @@ -98,7 +109,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -115,7 +126,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.ListBundleCopyWithCtx(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) ListBundleCopyWithCtx(ctx context.Context, BundleSid string, params *ListBundleCopyParams) ([]NumbersV2BundleCopy, error) { + response, errors := c.StreamBundleCopyWithCtx(ctx, BundleSid, params) records := make([]NumbersV2BundleCopy, 0) for record := range response { @@ -131,6 +147,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.StreamBundleCopyWithCtx(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) StreamBundleCopyWithCtx(ctx context.Context, BundleSid string, params *ListBundleCopyParams) (chan NumbersV2BundleCopy, chan error) { if params == nil { params = &ListBundleCopyParams{} } @@ -139,19 +160,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.PageBundleCopyWithCtx(ctx, BundleSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamBundleCopy(response, params, recordChannel, errorChannel) + go c.streamBundleCopy(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) streamBundleCopy(ctx context.Context, response *ListBundleCopyResponse, params *ListBundleCopyParams, recordChannel chan NumbersV2BundleCopy, errorChannel chan error) { curRecord := 1 for response != nil { @@ -166,7 +187,7 @@ func (c *ApiService) streamBundleCopy(response *ListBundleCopyResponse, params * } } - record, err := client.GetNext(c.baseURL, response, c.getNextListBundleCopyResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListBundleCopyResponse) if err != nil { errorChannel <- err break @@ -181,11 +202,11 @@ func (c *ApiService) streamBundleCopy(response *ListBundleCopyResponse, params * close(errorChannel) } -func (c *ApiService) getNextListBundleCopyResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListBundleCopyResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 b40de2007..0df6b67d1 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,13 +26,18 @@ import ( // Creates an evaluation for a bundle func (c *ApiService) CreateEvaluation(BundleSid string) (*NumbersV2Evaluation, error) { + return c.CreateEvaluationWithCtx(context.TODO(), BundleSid) +} + +// Creates an evaluation for a bundle +func (c *ApiService) CreateEvaluationWithCtx(ctx context.Context, BundleSid string) (*NumbersV2Evaluation, error) { path := "/v2/RegulatoryCompliance/Bundles/{BundleSid}/Evaluations" path = strings.Replace(path, "{"+"BundleSid"+"}", BundleSid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -48,6 +54,11 @@ func (c *ApiService) CreateEvaluation(BundleSid string) (*NumbersV2Evaluation, e // Fetch specific Evaluation Instance. func (c *ApiService) FetchEvaluation(BundleSid string, Sid string) (*NumbersV2Evaluation, error) { + return c.FetchEvaluationWithCtx(context.TODO(), BundleSid, Sid) +} + +// Fetch specific Evaluation Instance. +func (c *ApiService) FetchEvaluationWithCtx(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) @@ -55,7 +66,7 @@ func (c *ApiService) FetchEvaluation(BundleSid string, Sid string) (*NumbersV2Ev data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -89,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.PageEvaluationWithCtx(context.TODO(), BundleSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Evaluation records from the API. Request is executed immediately. +func (c *ApiService) PageEvaluationWithCtx(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) @@ -107,7 +123,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -124,7 +140,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.ListEvaluationWithCtx(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) ListEvaluationWithCtx(ctx context.Context, BundleSid string, params *ListEvaluationParams) ([]NumbersV2Evaluation, error) { + response, errors := c.StreamEvaluationWithCtx(ctx, BundleSid, params) records := make([]NumbersV2Evaluation, 0) for record := range response { @@ -140,6 +161,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.StreamEvaluationWithCtx(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) StreamEvaluationWithCtx(ctx context.Context, BundleSid string, params *ListEvaluationParams) (chan NumbersV2Evaluation, chan error) { if params == nil { params = &ListEvaluationParams{} } @@ -148,19 +174,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.PageEvaluationWithCtx(ctx, BundleSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamEvaluation(response, params, recordChannel, errorChannel) + go c.streamEvaluation(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) streamEvaluation(ctx context.Context, response *ListEvaluationResponse, params *ListEvaluationParams, recordChannel chan NumbersV2Evaluation, errorChannel chan error) { curRecord := 1 for response != nil { @@ -175,7 +201,7 @@ func (c *ApiService) streamEvaluation(response *ListEvaluationResponse, params * } } - record, err := client.GetNext(c.baseURL, response, c.getNextListEvaluationResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListEvaluationResponse) if err != nil { errorChannel <- err break @@ -190,11 +216,11 @@ func (c *ApiService) streamEvaluation(response *ListEvaluationResponse, params * close(errorChannel) } -func (c *ApiService) getNextListEvaluationResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListEvaluationResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 bdc63e88c..7008f6d56 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,11 @@ func (params *CreateItemAssignmentParams) SetObjectSid(ObjectSid string) *Create // Create a new Assigned Item. func (c *ApiService) CreateItemAssignment(BundleSid string, params *CreateItemAssignmentParams) (*NumbersV2ItemAssignment, error) { + return c.CreateItemAssignmentWithCtx(context.TODO(), BundleSid, params) +} + +// Create a new Assigned Item. +func (c *ApiService) CreateItemAssignmentWithCtx(ctx context.Context, BundleSid string, params *CreateItemAssignmentParams) (*NumbersV2ItemAssignment, error) { path := "/v2/RegulatoryCompliance/Bundles/{BundleSid}/ItemAssignments" path = strings.Replace(path, "{"+"BundleSid"+"}", BundleSid, -1) @@ -46,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -63,6 +69,11 @@ func (c *ApiService) CreateItemAssignment(BundleSid string, params *CreateItemAs // Remove an Assignment Item Instance. func (c *ApiService) DeleteItemAssignment(BundleSid string, Sid string) error { + return c.DeleteItemAssignmentWithCtx(context.TODO(), BundleSid, Sid) +} + +// Remove an Assignment Item Instance. +func (c *ApiService) DeleteItemAssignmentWithCtx(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) @@ -70,7 +81,7 @@ func (c *ApiService) DeleteItemAssignment(BundleSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -82,6 +93,11 @@ 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.FetchItemAssignmentWithCtx(context.TODO(), BundleSid, Sid) +} + +// Fetch specific Assigned Item Instance. +func (c *ApiService) FetchItemAssignmentWithCtx(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) @@ -89,7 +105,7 @@ func (c *ApiService) FetchItemAssignment(BundleSid string, Sid string) (*Numbers data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -123,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.PageItemAssignmentWithCtx(context.TODO(), BundleSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ItemAssignment records from the API. Request is executed immediately. +func (c *ApiService) PageItemAssignmentWithCtx(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) @@ -141,7 +162,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -158,7 +179,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.ListItemAssignmentWithCtx(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) ListItemAssignmentWithCtx(ctx context.Context, BundleSid string, params *ListItemAssignmentParams) ([]NumbersV2ItemAssignment, error) { + response, errors := c.StreamItemAssignmentWithCtx(ctx, BundleSid, params) records := make([]NumbersV2ItemAssignment, 0) for record := range response { @@ -174,6 +200,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.StreamItemAssignmentWithCtx(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) StreamItemAssignmentWithCtx(ctx context.Context, BundleSid string, params *ListItemAssignmentParams) (chan NumbersV2ItemAssignment, chan error) { if params == nil { params = &ListItemAssignmentParams{} } @@ -182,19 +213,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.PageItemAssignmentWithCtx(ctx, BundleSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamItemAssignment(response, params, recordChannel, errorChannel) + go c.streamItemAssignment(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) streamItemAssignment(ctx context.Context, response *ListItemAssignmentResponse, params *ListItemAssignmentParams, recordChannel chan NumbersV2ItemAssignment, errorChannel chan error) { curRecord := 1 for response != nil { @@ -209,7 +240,7 @@ func (c *ApiService) streamItemAssignment(response *ListItemAssignmentResponse, } } - record, err := client.GetNext(c.baseURL, response, c.getNextListItemAssignmentResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListItemAssignmentResponse) if err != nil { errorChannel <- err break @@ -224,11 +255,11 @@ func (c *ApiService) streamItemAssignment(response *ListItemAssignmentResponse, close(errorChannel) } -func (c *ApiService) getNextListItemAssignmentResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListItemAssignmentResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 47fdfeafd..f5aada841 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,11 @@ 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.CreateReplaceItemsWithCtx(context.TODO(), BundleSid, params) +} + +// 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) CreateReplaceItemsWithCtx(ctx context.Context, BundleSid string, params *CreateReplaceItemsParams) (*NumbersV2ReplaceItems, error) { path := "/v2/RegulatoryCompliance/Bundles/{BundleSid}/ReplaceItems" path = strings.Replace(path, "{"+"BundleSid"+"}", BundleSid, -1) @@ -43,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.Post(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 586950315..be8ad8661 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,13 +26,18 @@ import ( // Fetch a specific End-User Type Instance. func (c *ApiService) FetchEndUserType(Sid string) (*NumbersV2EndUserType, error) { + return c.FetchEndUserTypeWithCtx(context.TODO(), Sid) +} + +// Fetch a specific End-User Type Instance. +func (c *ApiService) FetchEndUserTypeWithCtx(ctx context.Context, Sid string) (*NumbersV2EndUserType, error) { path := "/v2/RegulatoryCompliance/EndUserTypes/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -65,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.PageEndUserTypeWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of EndUserType records from the API. Request is executed immediately. +func (c *ApiService) PageEndUserTypeWithCtx(ctx context.Context, params *ListEndUserTypeParams, pageToken, pageNumber string) (*ListEndUserTypeResponse, error) { path := "/v2/RegulatoryCompliance/EndUserTypes" data := url.Values{} @@ -81,7 +92,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -98,7 +109,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.ListEndUserTypeWithCtx(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) ListEndUserTypeWithCtx(ctx context.Context, params *ListEndUserTypeParams) ([]NumbersV2EndUserType, error) { + response, errors := c.StreamEndUserTypeWithCtx(ctx, params) records := make([]NumbersV2EndUserType, 0) for record := range response { @@ -114,6 +130,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.StreamEndUserTypeWithCtx(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) StreamEndUserTypeWithCtx(ctx context.Context, params *ListEndUserTypeParams) (chan NumbersV2EndUserType, chan error) { if params == nil { params = &ListEndUserTypeParams{} } @@ -122,19 +143,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.PageEndUserTypeWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamEndUserType(response, params, recordChannel, errorChannel) + go c.streamEndUserType(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) streamEndUserType(ctx context.Context, response *ListEndUserTypeResponse, params *ListEndUserTypeParams, recordChannel chan NumbersV2EndUserType, errorChannel chan error) { curRecord := 1 for response != nil { @@ -149,7 +170,7 @@ func (c *ApiService) streamEndUserType(response *ListEndUserTypeResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListEndUserTypeResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListEndUserTypeResponse) if err != nil { errorChannel <- err break @@ -164,11 +185,11 @@ func (c *ApiService) streamEndUserType(response *ListEndUserTypeResponse, params close(errorChannel) } -func (c *ApiService) getNextListEndUserTypeResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListEndUserTypeResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 334497be3..55a479b7a 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,11 @@ func (params *CreateEndUserParams) SetAttributes(Attributes interface{}) *Create // Create a new End User. func (c *ApiService) CreateEndUser(params *CreateEndUserParams) (*NumbersV2EndUser, error) { + return c.CreateEndUserWithCtx(context.TODO(), params) +} + +// Create a new End User. +func (c *ApiService) CreateEndUserWithCtx(ctx context.Context, params *CreateEndUserParams) (*NumbersV2EndUser, error) { path := "/v2/RegulatoryCompliance/EndUsers" data := url.Values{} @@ -69,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -86,13 +92,18 @@ func (c *ApiService) CreateEndUser(params *CreateEndUserParams) (*NumbersV2EndUs // Delete a specific End User. func (c *ApiService) DeleteEndUser(Sid string) error { + return c.DeleteEndUserWithCtx(context.TODO(), Sid) +} + +// Delete a specific End User. +func (c *ApiService) DeleteEndUserWithCtx(ctx context.Context, Sid string) error { path := "/v2/RegulatoryCompliance/EndUsers/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -104,13 +115,18 @@ func (c *ApiService) DeleteEndUser(Sid string) error { // Fetch specific End User Instance. func (c *ApiService) FetchEndUser(Sid string) (*NumbersV2EndUser, error) { + return c.FetchEndUserWithCtx(context.TODO(), Sid) +} + +// Fetch specific End User Instance. +func (c *ApiService) FetchEndUserWithCtx(ctx context.Context, Sid string) (*NumbersV2EndUser, error) { path := "/v2/RegulatoryCompliance/EndUsers/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -144,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.PageEndUserWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of EndUser records from the API. Request is executed immediately. +func (c *ApiService) PageEndUserWithCtx(ctx context.Context, params *ListEndUserParams, pageToken, pageNumber string) (*ListEndUserResponse, error) { path := "/v2/RegulatoryCompliance/EndUsers" data := url.Values{} @@ -160,7 +181,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -177,7 +198,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.ListEndUserWithCtx(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) ListEndUserWithCtx(ctx context.Context, params *ListEndUserParams) ([]NumbersV2EndUser, error) { + response, errors := c.StreamEndUserWithCtx(ctx, params) records := make([]NumbersV2EndUser, 0) for record := range response { @@ -193,6 +219,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.StreamEndUserWithCtx(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) StreamEndUserWithCtx(ctx context.Context, params *ListEndUserParams) (chan NumbersV2EndUser, chan error) { if params == nil { params = &ListEndUserParams{} } @@ -201,19 +232,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.PageEndUserWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamEndUser(response, params, recordChannel, errorChannel) + go c.streamEndUser(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) streamEndUser(ctx context.Context, response *ListEndUserResponse, params *ListEndUserParams, recordChannel chan NumbersV2EndUser, errorChannel chan error) { curRecord := 1 for response != nil { @@ -228,7 +259,7 @@ func (c *ApiService) streamEndUser(response *ListEndUserResponse, params *ListEn } } - record, err := client.GetNext(c.baseURL, response, c.getNextListEndUserResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListEndUserResponse) if err != nil { errorChannel <- err break @@ -243,11 +274,11 @@ func (c *ApiService) streamEndUser(response *ListEndUserResponse, params *ListEn close(errorChannel) } -func (c *ApiService) getNextListEndUserResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListEndUserResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -280,6 +311,11 @@ func (params *UpdateEndUserParams) SetAttributes(Attributes interface{}) *Update // Update an existing End User. func (c *ApiService) UpdateEndUser(Sid string, params *UpdateEndUserParams) (*NumbersV2EndUser, error) { + return c.UpdateEndUserWithCtx(context.TODO(), Sid, params) +} + +// Update an existing End User. +func (c *ApiService) UpdateEndUserWithCtx(ctx context.Context, Sid string, params *UpdateEndUserParams) (*NumbersV2EndUser, error) { path := "/v2/RegulatoryCompliance/EndUsers/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -299,7 +335,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.Post(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 f4d28ab92..4cb515ee6 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" @@ -25,13 +26,18 @@ import ( // Fetch specific Regulation Instance. func (c *ApiService) FetchRegulation(Sid string) (*NumbersV2Regulation, error) { + return c.FetchRegulationWithCtx(context.TODO(), Sid) +} + +// Fetch specific Regulation Instance. +func (c *ApiService) FetchRegulationWithCtx(ctx context.Context, Sid string) (*NumbersV2Regulation, error) { path := "/v2/RegulatoryCompliance/Regulations/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -83,6 +89,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.PageRegulationWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Regulation records from the API. Request is executed immediately. +func (c *ApiService) PageRegulationWithCtx(ctx context.Context, params *ListRegulationParams, pageToken, pageNumber string) (*ListRegulationResponse, error) { path := "/v2/RegulatoryCompliance/Regulations" data := url.Values{} @@ -108,7 +119,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -125,7 +136,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.ListRegulationWithCtx(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) ListRegulationWithCtx(ctx context.Context, params *ListRegulationParams) ([]NumbersV2Regulation, error) { + response, errors := c.StreamRegulationWithCtx(ctx, params) records := make([]NumbersV2Regulation, 0) for record := range response { @@ -141,6 +157,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.StreamRegulationWithCtx(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) StreamRegulationWithCtx(ctx context.Context, params *ListRegulationParams) (chan NumbersV2Regulation, chan error) { if params == nil { params = &ListRegulationParams{} } @@ -149,19 +170,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.PageRegulationWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamRegulation(response, params, recordChannel, errorChannel) + go c.streamRegulation(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) streamRegulation(ctx context.Context, response *ListRegulationResponse, params *ListRegulationParams, recordChannel chan NumbersV2Regulation, errorChannel chan error) { curRecord := 1 for response != nil { @@ -176,7 +197,7 @@ func (c *ApiService) streamRegulation(response *ListRegulationResponse, params * } } - record, err := client.GetNext(c.baseURL, response, c.getNextListRegulationResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListRegulationResponse) if err != nil { errorChannel <- err break @@ -191,11 +212,11 @@ func (c *ApiService) streamRegulation(response *ListRegulationResponse, params * close(errorChannel) } -func (c *ApiService) getNextListRegulationResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListRegulationResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 8891d7476..b617e9a3b 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,13 +26,18 @@ import ( // Fetch a specific Supporting Document Type Instance. func (c *ApiService) FetchSupportingDocumentType(Sid string) (*NumbersV2SupportingDocumentType, error) { + return c.FetchSupportingDocumentTypeWithCtx(context.TODO(), Sid) +} + +// Fetch a specific Supporting Document Type Instance. +func (c *ApiService) FetchSupportingDocumentTypeWithCtx(ctx context.Context, Sid string) (*NumbersV2SupportingDocumentType, error) { path := "/v2/RegulatoryCompliance/SupportingDocumentTypes/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -65,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.PageSupportingDocumentTypeWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of SupportingDocumentType records from the API. Request is executed immediately. +func (c *ApiService) PageSupportingDocumentTypeWithCtx(ctx context.Context, params *ListSupportingDocumentTypeParams, pageToken, pageNumber string) (*ListSupportingDocumentTypeResponse, error) { path := "/v2/RegulatoryCompliance/SupportingDocumentTypes" data := url.Values{} @@ -81,7 +92,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -98,7 +109,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.ListSupportingDocumentTypeWithCtx(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) ListSupportingDocumentTypeWithCtx(ctx context.Context, params *ListSupportingDocumentTypeParams) ([]NumbersV2SupportingDocumentType, error) { + response, errors := c.StreamSupportingDocumentTypeWithCtx(ctx, params) records := make([]NumbersV2SupportingDocumentType, 0) for record := range response { @@ -114,6 +130,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.StreamSupportingDocumentTypeWithCtx(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) StreamSupportingDocumentTypeWithCtx(ctx context.Context, params *ListSupportingDocumentTypeParams) (chan NumbersV2SupportingDocumentType, chan error) { if params == nil { params = &ListSupportingDocumentTypeParams{} } @@ -122,19 +143,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.PageSupportingDocumentTypeWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSupportingDocumentType(response, params, recordChannel, errorChannel) + go c.streamSupportingDocumentType(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) streamSupportingDocumentType(ctx context.Context, response *ListSupportingDocumentTypeResponse, params *ListSupportingDocumentTypeParams, recordChannel chan NumbersV2SupportingDocumentType, errorChannel chan error) { curRecord := 1 for response != nil { @@ -149,7 +170,7 @@ func (c *ApiService) streamSupportingDocumentType(response *ListSupportingDocume } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSupportingDocumentTypeResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListSupportingDocumentTypeResponse) if err != nil { errorChannel <- err break @@ -164,11 +185,11 @@ func (c *ApiService) streamSupportingDocumentType(response *ListSupportingDocume close(errorChannel) } -func (c *ApiService) getNextListSupportingDocumentTypeResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSupportingDocumentTypeResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 596fc9232..6848c28ab 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,11 @@ func (params *CreateSupportingDocumentParams) SetAttributes(Attributes interface // Create a new Supporting Document. func (c *ApiService) CreateSupportingDocument(params *CreateSupportingDocumentParams) (*NumbersV2SupportingDocument, error) { + return c.CreateSupportingDocumentWithCtx(context.TODO(), params) +} + +// Create a new Supporting Document. +func (c *ApiService) CreateSupportingDocumentWithCtx(ctx context.Context, params *CreateSupportingDocumentParams) (*NumbersV2SupportingDocument, error) { path := "/v2/RegulatoryCompliance/SupportingDocuments" data := url.Values{} @@ -69,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -86,13 +92,18 @@ func (c *ApiService) CreateSupportingDocument(params *CreateSupportingDocumentPa // Delete a specific Supporting Document. func (c *ApiService) DeleteSupportingDocument(Sid string) error { + return c.DeleteSupportingDocumentWithCtx(context.TODO(), Sid) +} + +// Delete a specific Supporting Document. +func (c *ApiService) DeleteSupportingDocumentWithCtx(ctx context.Context, Sid string) error { path := "/v2/RegulatoryCompliance/SupportingDocuments/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -104,13 +115,18 @@ func (c *ApiService) DeleteSupportingDocument(Sid string) error { // Fetch specific Supporting Document Instance. func (c *ApiService) FetchSupportingDocument(Sid string) (*NumbersV2SupportingDocument, error) { + return c.FetchSupportingDocumentWithCtx(context.TODO(), Sid) +} + +// Fetch specific Supporting Document Instance. +func (c *ApiService) FetchSupportingDocumentWithCtx(ctx context.Context, Sid string) (*NumbersV2SupportingDocument, error) { path := "/v2/RegulatoryCompliance/SupportingDocuments/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -144,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.PageSupportingDocumentWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of SupportingDocument records from the API. Request is executed immediately. +func (c *ApiService) PageSupportingDocumentWithCtx(ctx context.Context, params *ListSupportingDocumentParams, pageToken, pageNumber string) (*ListSupportingDocumentResponse, error) { path := "/v2/RegulatoryCompliance/SupportingDocuments" data := url.Values{} @@ -160,7 +181,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -177,7 +198,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.ListSupportingDocumentWithCtx(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) ListSupportingDocumentWithCtx(ctx context.Context, params *ListSupportingDocumentParams) ([]NumbersV2SupportingDocument, error) { + response, errors := c.StreamSupportingDocumentWithCtx(ctx, params) records := make([]NumbersV2SupportingDocument, 0) for record := range response { @@ -193,6 +219,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.StreamSupportingDocumentWithCtx(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) StreamSupportingDocumentWithCtx(ctx context.Context, params *ListSupportingDocumentParams) (chan NumbersV2SupportingDocument, chan error) { if params == nil { params = &ListSupportingDocumentParams{} } @@ -201,19 +232,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.PageSupportingDocumentWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSupportingDocument(response, params, recordChannel, errorChannel) + go c.streamSupportingDocument(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) streamSupportingDocument(ctx context.Context, response *ListSupportingDocumentResponse, params *ListSupportingDocumentParams, recordChannel chan NumbersV2SupportingDocument, errorChannel chan error) { curRecord := 1 for response != nil { @@ -228,7 +259,7 @@ func (c *ApiService) streamSupportingDocument(response *ListSupportingDocumentRe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSupportingDocumentResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListSupportingDocumentResponse) if err != nil { errorChannel <- err break @@ -243,11 +274,11 @@ func (c *ApiService) streamSupportingDocument(response *ListSupportingDocumentRe close(errorChannel) } -func (c *ApiService) getNextListSupportingDocumentResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSupportingDocumentResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -280,6 +311,11 @@ func (params *UpdateSupportingDocumentParams) SetAttributes(Attributes interface // Update an existing Supporting Document. func (c *ApiService) UpdateSupportingDocument(Sid string, params *UpdateSupportingDocumentParams) (*NumbersV2SupportingDocument, error) { + return c.UpdateSupportingDocumentWithCtx(context.TODO(), Sid, params) +} + +// Update an existing Supporting Document. +func (c *ApiService) UpdateSupportingDocumentWithCtx(ctx context.Context, Sid string, params *UpdateSupportingDocumentParams) (*NumbersV2SupportingDocument, error) { path := "/v2/RegulatoryCompliance/SupportingDocuments/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -299,7 +335,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.Post(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 d301cbc4d..5c152af1e 100644 --- a/rest/oauth/v1/api_service.go +++ b/rest/oauth/v1/api_service.go @@ -20,10 +20,14 @@ import ( type ApiService struct { baseURL string - requestHandler *twilio.RequestHandler + requestHandler *twilio.RequestHandlerWithCtx } func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { + return NewApiServiceWithCtx(twilio.UpgradeRequestHandler(requestHandler)) +} + +func NewApiServiceWithCtx(requestHandler *twilio.RequestHandlerWithCtx) *ApiService { return &ApiService{ requestHandler: requestHandler, baseURL: "https://oauth.twilio.com", @@ -33,3 +37,7 @@ func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { func NewApiServiceWithClient(client twilio.BaseClient) *ApiService { return NewApiService(twilio.NewRequestHandler(client)) } + +func NewApiServiceWithClientWithCtx(client twilio.BaseClientWithCtx) *ApiService { + return NewApiServiceWithCtx(twilio.NewRequestHandlerWithCtx(client)) +} diff --git a/rest/oauth/v1/certs.go b/rest/oauth/v1/certs.go index 994aad87d..16f7c80f9 100644 --- a/rest/oauth/v1/certs.go +++ b/rest/oauth/v1/certs.go @@ -15,18 +15,24 @@ package openapi import ( + "context" "encoding/json" "net/url" ) // Fetches public JWKs func (c *ApiService) FetchCerts() (*OauthV1Certs, error) { + return c.FetchCertsWithCtx(context.TODO()) +} + +// Fetches public JWKs +func (c *ApiService) FetchCertsWithCtx(ctx context.Context) (*OauthV1Certs, error) { path := "/v1/certs" data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(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 86eac4c8a..f11f8b6bd 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,11 @@ func (params *CreateTokenParams) SetDeviceId(DeviceId 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.CreateTokenWithCtx(context.TODO(), params) +} + +// Issues a new Access token (optionally identity_token & refresh_token) in exchange of Oauth grant +func (c *ApiService) CreateTokenWithCtx(ctx context.Context, params *CreateTokenParams) (*OauthV1Token, error) { path := "/v1/token" data := url.Values{} @@ -104,7 +110,7 @@ func (c *ApiService) CreateToken(params *CreateTokenParams) (*OauthV1Token, erro data.Set("DeviceId", *params.DeviceId) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/oauth/v1/userinfo.go b/rest/oauth/v1/userinfo.go index cf2e5f835..a3558bac9 100644 --- a/rest/oauth/v1/userinfo.go +++ b/rest/oauth/v1/userinfo.go @@ -15,18 +15,24 @@ package openapi import ( + "context" "encoding/json" "net/url" ) // Retrieves the consented UserInfo and other claims about the logged-in subject (end-user). func (c *ApiService) FetchUserInfo() (*OauthV1UserInfo, error) { + return c.FetchUserInfoWithCtx(context.TODO()) +} + +// Retrieves the consented UserInfo and other claims about the logged-in subject (end-user). +func (c *ApiService) FetchUserInfoWithCtx(ctx context.Context) (*OauthV1UserInfo, error) { path := "/v1/userinfo" data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/oauth/v1/well_known_openid_configuration.go b/rest/oauth/v1/well_known_openid_configuration.go index 1ed9a58ee..ebfdf9824 100644 --- a/rest/oauth/v1/well_known_openid_configuration.go +++ b/rest/oauth/v1/well_known_openid_configuration.go @@ -15,18 +15,24 @@ package openapi import ( + "context" "encoding/json" "net/url" ) // Fetch configuration details about the OpenID Connect Authorization Server func (c *ApiService) FetchOpenidDiscovery() (*OauthV1OpenidDiscovery, error) { + return c.FetchOpenidDiscoveryWithCtx(context.TODO()) +} + +// Fetch configuration details about the OpenID Connect Authorization Server +func (c *ApiService) FetchOpenidDiscoveryWithCtx(ctx context.Context) (*OauthV1OpenidDiscovery, error) { path := "/v1/well-known/openid-configuration" data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(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 dd1d948c5..6e2c10f0a 100644 --- a/rest/pricing/v1/api_service.go +++ b/rest/pricing/v1/api_service.go @@ -20,10 +20,14 @@ import ( type ApiService struct { baseURL string - requestHandler *twilio.RequestHandler + requestHandler *twilio.RequestHandlerWithCtx } func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { + return NewApiServiceWithCtx(twilio.UpgradeRequestHandler(requestHandler)) +} + +func NewApiServiceWithCtx(requestHandler *twilio.RequestHandlerWithCtx) *ApiService { return &ApiService{ requestHandler: requestHandler, baseURL: "https://pricing.twilio.com", @@ -33,3 +37,7 @@ func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { func NewApiServiceWithClient(client twilio.BaseClient) *ApiService { return NewApiService(twilio.NewRequestHandler(client)) } + +func NewApiServiceWithClientWithCtx(client twilio.BaseClientWithCtx) *ApiService { + return NewApiServiceWithCtx(twilio.NewRequestHandlerWithCtx(client)) +} diff --git a/rest/pricing/v1/messaging_countries.go b/rest/pricing/v1/messaging_countries.go index 44948443b..acce1152f 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" @@ -25,13 +26,18 @@ import ( // func (c *ApiService) FetchMessagingCountry(IsoCountry string) (*PricingV1MessagingCountryInstance, error) { + return c.FetchMessagingCountryWithCtx(context.TODO(), IsoCountry) +} + +// +func (c *ApiService) FetchMessagingCountryWithCtx(ctx context.Context, IsoCountry string) (*PricingV1MessagingCountryInstance, error) { path := "/v1/Messaging/Countries/{IsoCountry}" path = strings.Replace(path, "{"+"IsoCountry"+"}", IsoCountry, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -65,6 +71,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.PageMessagingCountryWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of MessagingCountry records from the API. Request is executed immediately. +func (c *ApiService) PageMessagingCountryWithCtx(ctx context.Context, params *ListMessagingCountryParams, pageToken, pageNumber string) (*ListMessagingCountryResponse, error) { path := "/v1/Messaging/Countries" data := url.Values{} @@ -81,7 +92,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -98,7 +109,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.ListMessagingCountryWithCtx(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) ListMessagingCountryWithCtx(ctx context.Context, params *ListMessagingCountryParams) ([]PricingV1MessagingCountry, error) { + response, errors := c.StreamMessagingCountryWithCtx(ctx, params) records := make([]PricingV1MessagingCountry, 0) for record := range response { @@ -114,6 +130,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.StreamMessagingCountryWithCtx(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) StreamMessagingCountryWithCtx(ctx context.Context, params *ListMessagingCountryParams) (chan PricingV1MessagingCountry, chan error) { if params == nil { params = &ListMessagingCountryParams{} } @@ -122,19 +143,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.PageMessagingCountryWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamMessagingCountry(response, params, recordChannel, errorChannel) + go c.streamMessagingCountry(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) streamMessagingCountry(ctx context.Context, response *ListMessagingCountryResponse, params *ListMessagingCountryParams, recordChannel chan PricingV1MessagingCountry, errorChannel chan error) { curRecord := 1 for response != nil { @@ -149,7 +170,7 @@ func (c *ApiService) streamMessagingCountry(response *ListMessagingCountryRespon } } - record, err := client.GetNext(c.baseURL, response, c.getNextListMessagingCountryResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListMessagingCountryResponse) if err != nil { errorChannel <- err break @@ -164,11 +185,11 @@ func (c *ApiService) streamMessagingCountry(response *ListMessagingCountryRespon close(errorChannel) } -func (c *ApiService) getNextListMessagingCountryResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListMessagingCountryResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 45e54bb34..cb2c2bc62 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" @@ -25,13 +26,18 @@ import ( // func (c *ApiService) FetchPhoneNumberCountry(IsoCountry string) (*PricingV1PhoneNumberCountryInstance, error) { + return c.FetchPhoneNumberCountryWithCtx(context.TODO(), IsoCountry) +} + +// +func (c *ApiService) FetchPhoneNumberCountryWithCtx(ctx context.Context, IsoCountry string) (*PricingV1PhoneNumberCountryInstance, error) { path := "/v1/PhoneNumbers/Countries/{IsoCountry}" path = strings.Replace(path, "{"+"IsoCountry"+"}", IsoCountry, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -65,6 +71,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.PagePhoneNumberCountryWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of PhoneNumberCountry records from the API. Request is executed immediately. +func (c *ApiService) PagePhoneNumberCountryWithCtx(ctx context.Context, params *ListPhoneNumberCountryParams, pageToken, pageNumber string) (*ListPhoneNumberCountryResponse, error) { path := "/v1/PhoneNumbers/Countries" data := url.Values{} @@ -81,7 +92,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -98,7 +109,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.ListPhoneNumberCountryWithCtx(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) ListPhoneNumberCountryWithCtx(ctx context.Context, params *ListPhoneNumberCountryParams) ([]PricingV1PhoneNumberCountry, error) { + response, errors := c.StreamPhoneNumberCountryWithCtx(ctx, params) records := make([]PricingV1PhoneNumberCountry, 0) for record := range response { @@ -114,6 +130,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.StreamPhoneNumberCountryWithCtx(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) StreamPhoneNumberCountryWithCtx(ctx context.Context, params *ListPhoneNumberCountryParams) (chan PricingV1PhoneNumberCountry, chan error) { if params == nil { params = &ListPhoneNumberCountryParams{} } @@ -122,19 +143,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.PagePhoneNumberCountryWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamPhoneNumberCountry(response, params, recordChannel, errorChannel) + go c.streamPhoneNumberCountry(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) streamPhoneNumberCountry(ctx context.Context, response *ListPhoneNumberCountryResponse, params *ListPhoneNumberCountryParams, recordChannel chan PricingV1PhoneNumberCountry, errorChannel chan error) { curRecord := 1 for response != nil { @@ -149,7 +170,7 @@ func (c *ApiService) streamPhoneNumberCountry(response *ListPhoneNumberCountryRe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListPhoneNumberCountryResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListPhoneNumberCountryResponse) if err != nil { errorChannel <- err break @@ -164,11 +185,11 @@ func (c *ApiService) streamPhoneNumberCountry(response *ListPhoneNumberCountryRe close(errorChannel) } -func (c *ApiService) getNextListPhoneNumberCountryResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListPhoneNumberCountryResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 97a5dce22..1d6e3faec 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" @@ -25,13 +26,18 @@ import ( // func (c *ApiService) FetchVoiceCountry(IsoCountry string) (*PricingV1VoiceCountryInstance, error) { + return c.FetchVoiceCountryWithCtx(context.TODO(), IsoCountry) +} + +// +func (c *ApiService) FetchVoiceCountryWithCtx(ctx context.Context, IsoCountry string) (*PricingV1VoiceCountryInstance, error) { path := "/v1/Voice/Countries/{IsoCountry}" path = strings.Replace(path, "{"+"IsoCountry"+"}", IsoCountry, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -65,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.PageVoiceCountryWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of VoiceCountry records from the API. Request is executed immediately. +func (c *ApiService) PageVoiceCountryWithCtx(ctx context.Context, params *ListVoiceCountryParams, pageToken, pageNumber string) (*ListVoiceCountryResponse, error) { path := "/v1/Voice/Countries" data := url.Values{} @@ -81,7 +92,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -98,7 +109,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.ListVoiceCountryWithCtx(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) ListVoiceCountryWithCtx(ctx context.Context, params *ListVoiceCountryParams) ([]PricingV1VoiceCountry, error) { + response, errors := c.StreamVoiceCountryWithCtx(ctx, params) records := make([]PricingV1VoiceCountry, 0) for record := range response { @@ -114,6 +130,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.StreamVoiceCountryWithCtx(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) StreamVoiceCountryWithCtx(ctx context.Context, params *ListVoiceCountryParams) (chan PricingV1VoiceCountry, chan error) { if params == nil { params = &ListVoiceCountryParams{} } @@ -122,19 +143,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.PageVoiceCountryWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamVoiceCountry(response, params, recordChannel, errorChannel) + go c.streamVoiceCountry(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) streamVoiceCountry(ctx context.Context, response *ListVoiceCountryResponse, params *ListVoiceCountryParams, recordChannel chan PricingV1VoiceCountry, errorChannel chan error) { curRecord := 1 for response != nil { @@ -149,7 +170,7 @@ func (c *ApiService) streamVoiceCountry(response *ListVoiceCountryResponse, para } } - record, err := client.GetNext(c.baseURL, response, c.getNextListVoiceCountryResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListVoiceCountryResponse) if err != nil { errorChannel <- err break @@ -164,11 +185,11 @@ func (c *ApiService) streamVoiceCountry(response *ListVoiceCountryResponse, para close(errorChannel) } -func (c *ApiService) getNextListVoiceCountryResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListVoiceCountryResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 a7993a1bb..d25f72547 100644 --- a/rest/pricing/v1/voice_numbers.go +++ b/rest/pricing/v1/voice_numbers.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -22,13 +23,18 @@ import ( // func (c *ApiService) FetchVoiceNumber(Number string) (*PricingV1VoiceNumber, error) { + return c.FetchVoiceNumberWithCtx(context.TODO(), Number) +} + +// +func (c *ApiService) FetchVoiceNumberWithCtx(ctx context.Context, Number string) (*PricingV1VoiceNumber, error) { path := "/v1/Voice/Numbers/{Number}" path = strings.Replace(path, "{"+"Number"+"}", Number, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(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 dd1d948c5..6e2c10f0a 100644 --- a/rest/pricing/v2/api_service.go +++ b/rest/pricing/v2/api_service.go @@ -20,10 +20,14 @@ import ( type ApiService struct { baseURL string - requestHandler *twilio.RequestHandler + requestHandler *twilio.RequestHandlerWithCtx } func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { + return NewApiServiceWithCtx(twilio.UpgradeRequestHandler(requestHandler)) +} + +func NewApiServiceWithCtx(requestHandler *twilio.RequestHandlerWithCtx) *ApiService { return &ApiService{ requestHandler: requestHandler, baseURL: "https://pricing.twilio.com", @@ -33,3 +37,7 @@ func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { func NewApiServiceWithClient(client twilio.BaseClient) *ApiService { return NewApiService(twilio.NewRequestHandler(client)) } + +func NewApiServiceWithClientWithCtx(client twilio.BaseClientWithCtx) *ApiService { + return NewApiServiceWithCtx(twilio.NewRequestHandlerWithCtx(client)) +} diff --git a/rest/pricing/v2/trunking_countries.go b/rest/pricing/v2/trunking_countries.go index 4a8b32d7c..4363162f1 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,13 +26,18 @@ import ( // Fetch a specific Country. func (c *ApiService) FetchTrunkingCountry(IsoCountry string) (*PricingV2TrunkingCountryInstance, error) { + return c.FetchTrunkingCountryWithCtx(context.TODO(), IsoCountry) +} + +// Fetch a specific Country. +func (c *ApiService) FetchTrunkingCountryWithCtx(ctx context.Context, IsoCountry string) (*PricingV2TrunkingCountryInstance, error) { path := "/v2/Trunking/Countries/{IsoCountry}" path = strings.Replace(path, "{"+"IsoCountry"+"}", IsoCountry, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -65,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.PageTrunkingCountryWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of TrunkingCountry records from the API. Request is executed immediately. +func (c *ApiService) PageTrunkingCountryWithCtx(ctx context.Context, params *ListTrunkingCountryParams, pageToken, pageNumber string) (*ListTrunkingCountryResponse, error) { path := "/v2/Trunking/Countries" data := url.Values{} @@ -81,7 +92,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -98,7 +109,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.ListTrunkingCountryWithCtx(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) ListTrunkingCountryWithCtx(ctx context.Context, params *ListTrunkingCountryParams) ([]PricingV2TrunkingCountry, error) { + response, errors := c.StreamTrunkingCountryWithCtx(ctx, params) records := make([]PricingV2TrunkingCountry, 0) for record := range response { @@ -114,6 +130,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.StreamTrunkingCountryWithCtx(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) StreamTrunkingCountryWithCtx(ctx context.Context, params *ListTrunkingCountryParams) (chan PricingV2TrunkingCountry, chan error) { if params == nil { params = &ListTrunkingCountryParams{} } @@ -122,19 +143,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.PageTrunkingCountryWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamTrunkingCountry(response, params, recordChannel, errorChannel) + go c.streamTrunkingCountry(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) streamTrunkingCountry(ctx context.Context, response *ListTrunkingCountryResponse, params *ListTrunkingCountryParams, recordChannel chan PricingV2TrunkingCountry, errorChannel chan error) { curRecord := 1 for response != nil { @@ -149,7 +170,7 @@ func (c *ApiService) streamTrunkingCountry(response *ListTrunkingCountryResponse } } - record, err := client.GetNext(c.baseURL, response, c.getNextListTrunkingCountryResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListTrunkingCountryResponse) if err != nil { errorChannel <- err break @@ -164,11 +185,11 @@ func (c *ApiService) streamTrunkingCountry(response *ListTrunkingCountryResponse close(errorChannel) } -func (c *ApiService) getNextListTrunkingCountryResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListTrunkingCountryResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 7ecd14fe0..0ab984606 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,11 @@ 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.FetchTrunkingNumberWithCtx(context.TODO(), DestinationNumber, params) +} + +// Fetch pricing information for a specific destination and, optionally, origination phone number. +func (c *ApiService) FetchTrunkingNumberWithCtx(ctx context.Context, DestinationNumber string, params *FetchTrunkingNumberParams) (*PricingV2TrunkingNumber, error) { path := "/v2/Trunking/Numbers/{DestinationNumber}" path = strings.Replace(path, "{"+"DestinationNumber"+"}", DestinationNumber, -1) @@ -43,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.Get(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 21ba246d8..c605d6851 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,13 +26,18 @@ import ( // Fetch a specific Country. func (c *ApiService) FetchVoiceCountry(IsoCountry string) (*PricingV2VoiceCountryInstance, error) { + return c.FetchVoiceCountryWithCtx(context.TODO(), IsoCountry) +} + +// Fetch a specific Country. +func (c *ApiService) FetchVoiceCountryWithCtx(ctx context.Context, IsoCountry string) (*PricingV2VoiceCountryInstance, error) { path := "/v2/Voice/Countries/{IsoCountry}" path = strings.Replace(path, "{"+"IsoCountry"+"}", IsoCountry, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -65,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.PageVoiceCountryWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of VoiceCountry records from the API. Request is executed immediately. +func (c *ApiService) PageVoiceCountryWithCtx(ctx context.Context, params *ListVoiceCountryParams, pageToken, pageNumber string) (*ListVoiceCountryResponse, error) { path := "/v2/Voice/Countries" data := url.Values{} @@ -81,7 +92,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -98,7 +109,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.ListVoiceCountryWithCtx(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) ListVoiceCountryWithCtx(ctx context.Context, params *ListVoiceCountryParams) ([]PricingV2VoiceCountry, error) { + response, errors := c.StreamVoiceCountryWithCtx(ctx, params) records := make([]PricingV2VoiceCountry, 0) for record := range response { @@ -114,6 +130,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.StreamVoiceCountryWithCtx(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) StreamVoiceCountryWithCtx(ctx context.Context, params *ListVoiceCountryParams) (chan PricingV2VoiceCountry, chan error) { if params == nil { params = &ListVoiceCountryParams{} } @@ -122,19 +143,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.PageVoiceCountryWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamVoiceCountry(response, params, recordChannel, errorChannel) + go c.streamVoiceCountry(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) streamVoiceCountry(ctx context.Context, response *ListVoiceCountryResponse, params *ListVoiceCountryParams, recordChannel chan PricingV2VoiceCountry, errorChannel chan error) { curRecord := 1 for response != nil { @@ -149,7 +170,7 @@ func (c *ApiService) streamVoiceCountry(response *ListVoiceCountryResponse, para } } - record, err := client.GetNext(c.baseURL, response, c.getNextListVoiceCountryResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListVoiceCountryResponse) if err != nil { errorChannel <- err break @@ -164,11 +185,11 @@ func (c *ApiService) streamVoiceCountry(response *ListVoiceCountryResponse, para close(errorChannel) } -func (c *ApiService) getNextListVoiceCountryResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListVoiceCountryResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 bb56cee05..490a4918e 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,11 @@ 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.FetchVoiceNumberWithCtx(context.TODO(), DestinationNumber, params) +} + +// Fetch pricing information for a specific destination and, optionally, origination phone number. +func (c *ApiService) FetchVoiceNumberWithCtx(ctx context.Context, DestinationNumber string, params *FetchVoiceNumberParams) (*PricingV2VoiceNumber, error) { path := "/v2/Voice/Numbers/{DestinationNumber}" path = strings.Replace(path, "{"+"DestinationNumber"+"}", DestinationNumber, -1) @@ -43,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.Get(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 8a6c62264..70fd2e7a8 100644 --- a/rest/proxy/v1/api_service.go +++ b/rest/proxy/v1/api_service.go @@ -20,10 +20,14 @@ import ( type ApiService struct { baseURL string - requestHandler *twilio.RequestHandler + requestHandler *twilio.RequestHandlerWithCtx } func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { + return NewApiServiceWithCtx(twilio.UpgradeRequestHandler(requestHandler)) +} + +func NewApiServiceWithCtx(requestHandler *twilio.RequestHandlerWithCtx) *ApiService { return &ApiService{ requestHandler: requestHandler, baseURL: "https://proxy.twilio.com", @@ -33,3 +37,7 @@ func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { func NewApiServiceWithClient(client twilio.BaseClient) *ApiService { return NewApiService(twilio.NewRequestHandler(client)) } + +func NewApiServiceWithClientWithCtx(client twilio.BaseClientWithCtx) *ApiService { + return NewApiServiceWithCtx(twilio.NewRequestHandlerWithCtx(client)) +} diff --git a/rest/proxy/v1/services.go b/rest/proxy/v1/services.go index 4e7d4dc6b..c97a15963 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,11 @@ func (params *CreateServiceParams) SetChatInstanceSid(ChatInstanceSid string) *C // Create a new Service for Twilio Proxy func (c *ApiService) CreateService(params *CreateServiceParams) (*ProxyV1Service, error) { + return c.CreateServiceWithCtx(context.TODO(), params) +} + +// Create a new Service for Twilio Proxy +func (c *ApiService) CreateServiceWithCtx(ctx context.Context, params *CreateServiceParams) (*ProxyV1Service, error) { path := "/v1/Services" data := url.Values{} @@ -108,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -125,13 +131,18 @@ func (c *ApiService) CreateService(params *CreateServiceParams) (*ProxyV1Service // Delete a specific Service. func (c *ApiService) DeleteService(Sid string) error { + return c.DeleteServiceWithCtx(context.TODO(), Sid) +} + +// Delete a specific Service. +func (c *ApiService) DeleteServiceWithCtx(ctx context.Context, Sid string) error { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -143,13 +154,18 @@ func (c *ApiService) DeleteService(Sid string) error { // Fetch a specific Service. func (c *ApiService) FetchService(Sid string) (*ProxyV1Service, error) { + return c.FetchServiceWithCtx(context.TODO(), Sid) +} + +// Fetch a specific Service. +func (c *ApiService) FetchServiceWithCtx(ctx context.Context, Sid string) (*ProxyV1Service, error) { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -183,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.PageServiceWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Service records from the API. Request is executed immediately. +func (c *ApiService) PageServiceWithCtx(ctx context.Context, params *ListServiceParams, pageToken, pageNumber string) (*ListServiceResponse, error) { path := "/v1/Services" data := url.Values{} @@ -199,7 +220,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -216,7 +237,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.ListServiceWithCtx(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) ListServiceWithCtx(ctx context.Context, params *ListServiceParams) ([]ProxyV1Service, error) { + response, errors := c.StreamServiceWithCtx(ctx, params) records := make([]ProxyV1Service, 0) for record := range response { @@ -232,6 +258,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.StreamServiceWithCtx(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) StreamServiceWithCtx(ctx context.Context, params *ListServiceParams) (chan ProxyV1Service, chan error) { if params == nil { params = &ListServiceParams{} } @@ -240,19 +271,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.PageServiceWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamService(response, params, recordChannel, errorChannel) + go c.streamService(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) streamService(ctx context.Context, response *ListServiceResponse, params *ListServiceParams, recordChannel chan ProxyV1Service, errorChannel chan error) { curRecord := 1 for response != nil { @@ -267,7 +298,7 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListServiceResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListServiceResponse) if err != nil { errorChannel <- err break @@ -282,11 +313,11 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe close(errorChannel) } -func (c *ApiService) getNextListServiceResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListServiceResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -355,6 +386,11 @@ func (params *UpdateServiceParams) SetChatInstanceSid(ChatInstanceSid string) *U // Update a specific Service. func (c *ApiService) UpdateService(Sid string, params *UpdateServiceParams) (*ProxyV1Service, error) { + return c.UpdateServiceWithCtx(context.TODO(), Sid, params) +} + +// Update a specific Service. +func (c *ApiService) UpdateServiceWithCtx(ctx context.Context, Sid string, params *UpdateServiceParams) (*ProxyV1Service, error) { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -386,7 +422,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.Post(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 5c5f10ef1..191c184ce 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,11 @@ 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.CreatePhoneNumberWithCtx(context.TODO(), ServiceSid, params) +} + +// Add a Phone Number to a Service's Proxy Number Pool. +func (c *ApiService) CreatePhoneNumberWithCtx(ctx context.Context, ServiceSid string, params *CreatePhoneNumberParams) (*ProxyV1PhoneNumber, error) { path := "/v1/Services/{ServiceSid}/PhoneNumbers" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -64,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -81,6 +87,11 @@ 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.DeletePhoneNumberWithCtx(context.TODO(), ServiceSid, Sid) +} + +// Delete a specific Phone Number from a Service. +func (c *ApiService) DeletePhoneNumberWithCtx(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) @@ -88,7 +99,7 @@ func (c *ApiService) DeletePhoneNumber(ServiceSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -100,6 +111,11 @@ 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.FetchPhoneNumberWithCtx(context.TODO(), ServiceSid, Sid) +} + +// Fetch a specific Phone Number. +func (c *ApiService) FetchPhoneNumberWithCtx(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) @@ -107,7 +123,7 @@ func (c *ApiService) FetchPhoneNumber(ServiceSid string, Sid string) (*ProxyV1Ph data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -141,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.PagePhoneNumberWithCtx(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of PhoneNumber records from the API. Request is executed immediately. +func (c *ApiService) PagePhoneNumberWithCtx(ctx context.Context, ServiceSid string, params *ListPhoneNumberParams, pageToken, pageNumber string) (*ListPhoneNumberResponse, error) { path := "/v1/Services/{ServiceSid}/PhoneNumbers" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -159,7 +180,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -176,7 +197,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.ListPhoneNumberWithCtx(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) ListPhoneNumberWithCtx(ctx context.Context, ServiceSid string, params *ListPhoneNumberParams) ([]ProxyV1PhoneNumber, error) { + response, errors := c.StreamPhoneNumberWithCtx(ctx, ServiceSid, params) records := make([]ProxyV1PhoneNumber, 0) for record := range response { @@ -192,6 +218,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.StreamPhoneNumberWithCtx(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) StreamPhoneNumberWithCtx(ctx context.Context, ServiceSid string, params *ListPhoneNumberParams) (chan ProxyV1PhoneNumber, chan error) { if params == nil { params = &ListPhoneNumberParams{} } @@ -200,19 +231,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.PagePhoneNumberWithCtx(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamPhoneNumber(response, params, recordChannel, errorChannel) + go c.streamPhoneNumber(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) streamPhoneNumber(ctx context.Context, response *ListPhoneNumberResponse, params *ListPhoneNumberParams, recordChannel chan ProxyV1PhoneNumber, errorChannel chan error) { curRecord := 1 for response != nil { @@ -227,7 +258,7 @@ func (c *ApiService) streamPhoneNumber(response *ListPhoneNumberResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListPhoneNumberResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListPhoneNumberResponse) if err != nil { errorChannel <- err break @@ -242,11 +273,11 @@ func (c *ApiService) streamPhoneNumber(response *ListPhoneNumberResponse, params close(errorChannel) } -func (c *ApiService) getNextListPhoneNumberResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListPhoneNumberResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -273,6 +304,11 @@ 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.UpdatePhoneNumberWithCtx(context.TODO(), ServiceSid, Sid, params) +} + +// Update a specific Proxy Number. +func (c *ApiService) UpdatePhoneNumberWithCtx(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) @@ -284,7 +320,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.Post(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 4adc3a65a..aebf25d65 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" @@ -73,6 +74,11 @@ func (params *CreateSessionParams) SetFailOnParticipantConflict(FailOnParticipan // Create a new Session func (c *ApiService) CreateSession(ServiceSid string, params *CreateSessionParams) (*ProxyV1Session, error) { + return c.CreateSessionWithCtx(context.TODO(), ServiceSid, params) +} + +// Create a new Session +func (c *ApiService) CreateSessionWithCtx(ctx context.Context, ServiceSid string, params *CreateSessionParams) (*ProxyV1Session, error) { path := "/v1/Services/{ServiceSid}/Sessions" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -109,7 +115,7 @@ func (c *ApiService) CreateSession(ServiceSid string, params *CreateSessionParam data.Set("FailOnParticipantConflict", fmt.Sprint(*params.FailOnParticipantConflict)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -126,6 +132,11 @@ func (c *ApiService) CreateSession(ServiceSid string, params *CreateSessionParam // Delete a specific Session. func (c *ApiService) DeleteSession(ServiceSid string, Sid string) error { + return c.DeleteSessionWithCtx(context.TODO(), ServiceSid, Sid) +} + +// Delete a specific Session. +func (c *ApiService) DeleteSessionWithCtx(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) @@ -133,7 +144,7 @@ func (c *ApiService) DeleteSession(ServiceSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -145,6 +156,11 @@ 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.FetchSessionWithCtx(context.TODO(), ServiceSid, Sid) +} + +// Fetch a specific Session. +func (c *ApiService) FetchSessionWithCtx(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) @@ -152,7 +168,7 @@ func (c *ApiService) FetchSession(ServiceSid string, Sid string) (*ProxyV1Sessio data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -186,6 +202,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.PageSessionWithCtx(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Session records from the API. Request is executed immediately. +func (c *ApiService) PageSessionWithCtx(ctx context.Context, ServiceSid string, params *ListSessionParams, pageToken, pageNumber string) (*ListSessionResponse, error) { path := "/v1/Services/{ServiceSid}/Sessions" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -204,7 +225,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -221,7 +242,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.ListSessionWithCtx(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) ListSessionWithCtx(ctx context.Context, ServiceSid string, params *ListSessionParams) ([]ProxyV1Session, error) { + response, errors := c.StreamSessionWithCtx(ctx, ServiceSid, params) records := make([]ProxyV1Session, 0) for record := range response { @@ -237,6 +263,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.StreamSessionWithCtx(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) StreamSessionWithCtx(ctx context.Context, ServiceSid string, params *ListSessionParams) (chan ProxyV1Session, chan error) { if params == nil { params = &ListSessionParams{} } @@ -245,19 +276,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.PageSessionWithCtx(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSession(response, params, recordChannel, errorChannel) + go c.streamSession(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) streamSession(ctx context.Context, response *ListSessionResponse, params *ListSessionParams, recordChannel chan ProxyV1Session, errorChannel chan error) { curRecord := 1 for response != nil { @@ -272,7 +303,7 @@ func (c *ApiService) streamSession(response *ListSessionResponse, params *ListSe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSessionResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListSessionResponse) if err != nil { errorChannel <- err break @@ -287,11 +318,11 @@ func (c *ApiService) streamSession(response *ListSessionResponse, params *ListSe close(errorChannel) } -func (c *ApiService) getNextListSessionResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSessionResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -336,6 +367,11 @@ func (params *UpdateSessionParams) SetFailOnParticipantConflict(FailOnParticipan // Update a specific Session. func (c *ApiService) UpdateSession(ServiceSid string, Sid string, params *UpdateSessionParams) (*ProxyV1Session, error) { + return c.UpdateSessionWithCtx(context.TODO(), ServiceSid, Sid, params) +} + +// Update a specific Session. +func (c *ApiService) UpdateSessionWithCtx(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) @@ -356,7 +392,7 @@ func (c *ApiService) UpdateSession(ServiceSid string, Sid string, params *Update data.Set("FailOnParticipantConflict", fmt.Sprint(*params.FailOnParticipantConflict)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 106d43666..a07c1799f 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,11 @@ import ( // Delete a specific Interaction. func (c *ApiService) DeleteInteraction(ServiceSid string, SessionSid string, Sid string) error { + return c.DeleteInteractionWithCtx(context.TODO(), ServiceSid, SessionSid, Sid) +} + +// Delete a specific Interaction. +func (c *ApiService) DeleteInteractionWithCtx(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) @@ -33,7 +39,7 @@ func (c *ApiService) DeleteInteraction(ServiceSid string, SessionSid string, Sid data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -45,6 +51,11 @@ 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.FetchInteractionWithCtx(context.TODO(), ServiceSid, SessionSid, Sid) +} + +// Retrieve a list of Interactions for a given [Session](https://www.twilio.com/docs/proxy/api/session). +func (c *ApiService) FetchInteractionWithCtx(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) @@ -53,7 +64,7 @@ func (c *ApiService) FetchInteraction(ServiceSid string, SessionSid string, Sid data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -87,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.PageInteractionWithCtx(context.TODO(), ServiceSid, SessionSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Interaction records from the API. Request is executed immediately. +func (c *ApiService) PageInteractionWithCtx(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) @@ -106,7 +122,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -123,7 +139,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.ListInteractionWithCtx(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) ListInteractionWithCtx(ctx context.Context, ServiceSid string, SessionSid string, params *ListInteractionParams) ([]ProxyV1Interaction, error) { + response, errors := c.StreamInteractionWithCtx(ctx, ServiceSid, SessionSid, params) records := make([]ProxyV1Interaction, 0) for record := range response { @@ -139,6 +160,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.StreamInteractionWithCtx(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) StreamInteractionWithCtx(ctx context.Context, ServiceSid string, SessionSid string, params *ListInteractionParams) (chan ProxyV1Interaction, chan error) { if params == nil { params = &ListInteractionParams{} } @@ -147,19 +173,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.PageInteractionWithCtx(ctx, ServiceSid, SessionSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamInteraction(response, params, recordChannel, errorChannel) + go c.streamInteraction(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) streamInteraction(ctx context.Context, response *ListInteractionResponse, params *ListInteractionParams, recordChannel chan ProxyV1Interaction, errorChannel chan error) { curRecord := 1 for response != nil { @@ -174,7 +200,7 @@ func (c *ApiService) streamInteraction(response *ListInteractionResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListInteractionResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListInteractionResponse) if err != nil { errorChannel <- err break @@ -189,11 +215,11 @@ func (c *ApiService) streamInteraction(response *ListInteractionResponse, params close(errorChannel) } -func (c *ApiService) getNextListInteractionResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListInteractionResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 ef3e567ce..6756ca7bb 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" @@ -60,6 +61,11 @@ func (params *CreateParticipantParams) SetFailOnParticipantConflict(FailOnPartic // Add a new Participant to the Session func (c *ApiService) CreateParticipant(ServiceSid string, SessionSid string, params *CreateParticipantParams) (*ProxyV1Participant, error) { + return c.CreateParticipantWithCtx(context.TODO(), ServiceSid, SessionSid, params) +} + +// Add a new Participant to the Session +func (c *ApiService) CreateParticipantWithCtx(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) @@ -83,7 +89,7 @@ func (c *ApiService) CreateParticipant(ServiceSid string, SessionSid string, par data.Set("FailOnParticipantConflict", fmt.Sprint(*params.FailOnParticipantConflict)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -100,6 +106,11 @@ 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.DeleteParticipantWithCtx(context.TODO(), ServiceSid, SessionSid, Sid) +} + +// 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) DeleteParticipantWithCtx(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) @@ -108,7 +119,7 @@ func (c *ApiService) DeleteParticipant(ServiceSid string, SessionSid string, Sid data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -120,6 +131,11 @@ 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.FetchParticipantWithCtx(context.TODO(), ServiceSid, SessionSid, Sid) +} + +// Fetch a specific Participant. +func (c *ApiService) FetchParticipantWithCtx(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) @@ -128,7 +144,7 @@ func (c *ApiService) FetchParticipant(ServiceSid string, SessionSid string, Sid data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -162,6 +178,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.PageParticipantWithCtx(context.TODO(), ServiceSid, SessionSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Participant records from the API. Request is executed immediately. +func (c *ApiService) PageParticipantWithCtx(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) @@ -181,7 +202,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -198,7 +219,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.ListParticipantWithCtx(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) ListParticipantWithCtx(ctx context.Context, ServiceSid string, SessionSid string, params *ListParticipantParams) ([]ProxyV1Participant, error) { + response, errors := c.StreamParticipantWithCtx(ctx, ServiceSid, SessionSid, params) records := make([]ProxyV1Participant, 0) for record := range response { @@ -214,6 +240,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.StreamParticipantWithCtx(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) StreamParticipantWithCtx(ctx context.Context, ServiceSid string, SessionSid string, params *ListParticipantParams) (chan ProxyV1Participant, chan error) { if params == nil { params = &ListParticipantParams{} } @@ -222,19 +253,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.PageParticipantWithCtx(ctx, ServiceSid, SessionSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamParticipant(response, params, recordChannel, errorChannel) + go c.streamParticipant(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) streamParticipant(ctx context.Context, response *ListParticipantResponse, params *ListParticipantParams, recordChannel chan ProxyV1Participant, errorChannel chan error) { curRecord := 1 for response != nil { @@ -249,7 +280,7 @@ func (c *ApiService) streamParticipant(response *ListParticipantResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListParticipantResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListParticipantResponse) if err != nil { errorChannel <- err break @@ -264,11 +295,11 @@ func (c *ApiService) streamParticipant(response *ListParticipantResponse, params close(errorChannel) } -func (c *ApiService) getNextListParticipantResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListParticipantResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 a9123737b..107396429 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,11 @@ 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.CreateMessageInteractionWithCtx(context.TODO(), ServiceSid, SessionSid, ParticipantSid, params) +} + +// 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) CreateMessageInteractionWithCtx(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) @@ -59,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -76,6 +82,11 @@ func (c *ApiService) CreateMessageInteraction(ServiceSid string, SessionSid stri // func (c *ApiService) FetchMessageInteraction(ServiceSid string, SessionSid string, ParticipantSid string, Sid string) (*ProxyV1MessageInteraction, error) { + return c.FetchMessageInteractionWithCtx(context.TODO(), ServiceSid, SessionSid, ParticipantSid, Sid) +} + +// +func (c *ApiService) FetchMessageInteractionWithCtx(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) @@ -85,7 +96,7 @@ func (c *ApiService) FetchMessageInteraction(ServiceSid string, SessionSid strin data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -119,6 +130,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.PageMessageInteractionWithCtx(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) PageMessageInteractionWithCtx(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) @@ -139,7 +155,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -156,7 +172,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.ListMessageInteractionWithCtx(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) ListMessageInteractionWithCtx(ctx context.Context, ServiceSid string, SessionSid string, ParticipantSid string, params *ListMessageInteractionParams) ([]ProxyV1MessageInteraction, error) { + response, errors := c.StreamMessageInteractionWithCtx(ctx, ServiceSid, SessionSid, ParticipantSid, params) records := make([]ProxyV1MessageInteraction, 0) for record := range response { @@ -172,6 +193,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.StreamMessageInteractionWithCtx(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) StreamMessageInteractionWithCtx(ctx context.Context, ServiceSid string, SessionSid string, ParticipantSid string, params *ListMessageInteractionParams) (chan ProxyV1MessageInteraction, chan error) { if params == nil { params = &ListMessageInteractionParams{} } @@ -180,19 +206,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.PageMessageInteractionWithCtx(ctx, ServiceSid, SessionSid, ParticipantSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamMessageInteraction(response, params, recordChannel, errorChannel) + go c.streamMessageInteraction(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) streamMessageInteraction(ctx context.Context, response *ListMessageInteractionResponse, params *ListMessageInteractionParams, recordChannel chan ProxyV1MessageInteraction, errorChannel chan error) { curRecord := 1 for response != nil { @@ -207,7 +233,7 @@ func (c *ApiService) streamMessageInteraction(response *ListMessageInteractionRe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListMessageInteractionResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListMessageInteractionResponse) if err != nil { errorChannel <- err break @@ -222,11 +248,11 @@ func (c *ApiService) streamMessageInteraction(response *ListMessageInteractionRe close(errorChannel) } -func (c *ApiService) getNextListMessageInteractionResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListMessageInteractionResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 34c743506..c139b0583 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,11 @@ 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.CreateShortCodeWithCtx(context.TODO(), ServiceSid, params) +} + +// Add a Short Code to the Proxy Number Pool for the Service. +func (c *ApiService) CreateShortCodeWithCtx(ctx context.Context, ServiceSid string, params *CreateShortCodeParams) (*ProxyV1ShortCode, error) { path := "/v1/Services/{ServiceSid}/ShortCodes" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -46,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -63,6 +69,11 @@ 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.DeleteShortCodeWithCtx(context.TODO(), ServiceSid, Sid) +} + +// Delete a specific Short Code from a Service. +func (c *ApiService) DeleteShortCodeWithCtx(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) @@ -70,7 +81,7 @@ func (c *ApiService) DeleteShortCode(ServiceSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -82,6 +93,11 @@ 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.FetchShortCodeWithCtx(context.TODO(), ServiceSid, Sid) +} + +// Fetch a specific Short Code. +func (c *ApiService) FetchShortCodeWithCtx(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) @@ -89,7 +105,7 @@ func (c *ApiService) FetchShortCode(ServiceSid string, Sid string) (*ProxyV1Shor data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -123,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.PageShortCodeWithCtx(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ShortCode records from the API. Request is executed immediately. +func (c *ApiService) PageShortCodeWithCtx(ctx context.Context, ServiceSid string, params *ListShortCodeParams, pageToken, pageNumber string) (*ListShortCodeResponse, error) { path := "/v1/Services/{ServiceSid}/ShortCodes" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -141,7 +162,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -158,7 +179,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.ListShortCodeWithCtx(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) ListShortCodeWithCtx(ctx context.Context, ServiceSid string, params *ListShortCodeParams) ([]ProxyV1ShortCode, error) { + response, errors := c.StreamShortCodeWithCtx(ctx, ServiceSid, params) records := make([]ProxyV1ShortCode, 0) for record := range response { @@ -174,6 +200,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.StreamShortCodeWithCtx(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) StreamShortCodeWithCtx(ctx context.Context, ServiceSid string, params *ListShortCodeParams) (chan ProxyV1ShortCode, chan error) { if params == nil { params = &ListShortCodeParams{} } @@ -182,19 +213,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.PageShortCodeWithCtx(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamShortCode(response, params, recordChannel, errorChannel) + go c.streamShortCode(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) streamShortCode(ctx context.Context, response *ListShortCodeResponse, params *ListShortCodeParams, recordChannel chan ProxyV1ShortCode, errorChannel chan error) { curRecord := 1 for response != nil { @@ -209,7 +240,7 @@ func (c *ApiService) streamShortCode(response *ListShortCodeResponse, params *Li } } - record, err := client.GetNext(c.baseURL, response, c.getNextListShortCodeResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListShortCodeResponse) if err != nil { errorChannel <- err break @@ -224,11 +255,11 @@ func (c *ApiService) streamShortCode(response *ListShortCodeResponse, params *Li close(errorChannel) } -func (c *ApiService) getNextListShortCodeResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListShortCodeResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -255,6 +286,11 @@ 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.UpdateShortCodeWithCtx(context.TODO(), ServiceSid, Sid, params) +} + +// Update a specific Short Code. +func (c *ApiService) UpdateShortCodeWithCtx(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) @@ -266,7 +302,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.Post(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 c563e84c9..9140d4659 100644 --- a/rest/routes/v2/api_service.go +++ b/rest/routes/v2/api_service.go @@ -20,10 +20,14 @@ import ( type ApiService struct { baseURL string - requestHandler *twilio.RequestHandler + requestHandler *twilio.RequestHandlerWithCtx } func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { + return NewApiServiceWithCtx(twilio.UpgradeRequestHandler(requestHandler)) +} + +func NewApiServiceWithCtx(requestHandler *twilio.RequestHandlerWithCtx) *ApiService { return &ApiService{ requestHandler: requestHandler, baseURL: "https://routes.twilio.com", @@ -33,3 +37,7 @@ func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { func NewApiServiceWithClient(client twilio.BaseClient) *ApiService { return NewApiService(twilio.NewRequestHandler(client)) } + +func NewApiServiceWithClientWithCtx(client twilio.BaseClientWithCtx) *ApiService { + return NewApiServiceWithCtx(twilio.NewRequestHandlerWithCtx(client)) +} diff --git a/rest/routes/v2/phone_numbers.go b/rest/routes/v2/phone_numbers.go index 7614b6d2a..fb0944243 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,13 +23,18 @@ import ( // Fetch the Inbound Processing Region assigned to a phone number. func (c *ApiService) FetchPhoneNumber(PhoneNumber string) (*RoutesV2PhoneNumber, error) { + return c.FetchPhoneNumberWithCtx(context.TODO(), PhoneNumber) +} + +// Fetch the Inbound Processing Region assigned to a phone number. +func (c *ApiService) FetchPhoneNumberWithCtx(ctx context.Context, PhoneNumber string) (*RoutesV2PhoneNumber, error) { path := "/v2/PhoneNumbers/{PhoneNumber}" path = strings.Replace(path, "{"+"PhoneNumber"+"}", PhoneNumber, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -62,6 +68,11 @@ 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.UpdatePhoneNumberWithCtx(context.TODO(), PhoneNumber, params) +} + +// Assign an Inbound Processing Region to a phone number. +func (c *ApiService) UpdatePhoneNumberWithCtx(ctx context.Context, PhoneNumber string, params *UpdatePhoneNumberParams) (*RoutesV2PhoneNumber, error) { path := "/v2/PhoneNumbers/{PhoneNumber}" path = strings.Replace(path, "{"+"PhoneNumber"+"}", PhoneNumber, -1) @@ -75,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.Post(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 bdaa766ef..350816be8 100644 --- a/rest/routes/v2/sip_domains.go +++ b/rest/routes/v2/sip_domains.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -22,13 +23,18 @@ import ( // func (c *ApiService) FetchSipDomain(SipDomain string) (*RoutesV2SipDomain, error) { + return c.FetchSipDomainWithCtx(context.TODO(), SipDomain) +} + +// +func (c *ApiService) FetchSipDomainWithCtx(ctx context.Context, SipDomain string) (*RoutesV2SipDomain, error) { path := "/v2/SipDomains/{SipDomain}" path = strings.Replace(path, "{"+"SipDomain"+"}", SipDomain, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -62,6 +68,11 @@ func (params *UpdateSipDomainParams) SetFriendlyName(FriendlyName string) *Updat // func (c *ApiService) UpdateSipDomain(SipDomain string, params *UpdateSipDomainParams) (*RoutesV2SipDomain, error) { + return c.UpdateSipDomainWithCtx(context.TODO(), SipDomain, params) +} + +// +func (c *ApiService) UpdateSipDomainWithCtx(ctx context.Context, SipDomain string, params *UpdateSipDomainParams) (*RoutesV2SipDomain, error) { path := "/v2/SipDomains/{SipDomain}" path = strings.Replace(path, "{"+"SipDomain"+"}", SipDomain, -1) @@ -75,7 +86,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.Post(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 e5734e5fa..c61cdbfeb 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,13 +23,18 @@ import ( // Fetch the Inbound Processing Region assigned to a SIP Trunk. func (c *ApiService) FetchTrunks(SipTrunkDomain string) (*RoutesV2Trunks, error) { + return c.FetchTrunksWithCtx(context.TODO(), SipTrunkDomain) +} + +// Fetch the Inbound Processing Region assigned to a SIP Trunk. +func (c *ApiService) FetchTrunksWithCtx(ctx context.Context, SipTrunkDomain string) (*RoutesV2Trunks, error) { path := "/v2/Trunks/{SipTrunkDomain}" path = strings.Replace(path, "{"+"SipTrunkDomain"+"}", SipTrunkDomain, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -62,6 +68,11 @@ 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.UpdateTrunksWithCtx(context.TODO(), SipTrunkDomain, params) +} + +// Assign an Inbound Processing Region to a SIP Trunk +func (c *ApiService) UpdateTrunksWithCtx(ctx context.Context, SipTrunkDomain string, params *UpdateTrunksParams) (*RoutesV2Trunks, error) { path := "/v2/Trunks/{SipTrunkDomain}" path = strings.Replace(path, "{"+"SipTrunkDomain"+"}", SipTrunkDomain, -1) @@ -75,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.Post(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 7ff947e82..f9e067913 100644 --- a/rest/serverless/v1/api_service.go +++ b/rest/serverless/v1/api_service.go @@ -20,10 +20,14 @@ import ( type ApiService struct { baseURL string - requestHandler *twilio.RequestHandler + requestHandler *twilio.RequestHandlerWithCtx } func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { + return NewApiServiceWithCtx(twilio.UpgradeRequestHandler(requestHandler)) +} + +func NewApiServiceWithCtx(requestHandler *twilio.RequestHandlerWithCtx) *ApiService { return &ApiService{ requestHandler: requestHandler, baseURL: "https://serverless.twilio.com", @@ -33,3 +37,7 @@ func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { func NewApiServiceWithClient(client twilio.BaseClient) *ApiService { return NewApiService(twilio.NewRequestHandler(client)) } + +func NewApiServiceWithClientWithCtx(client twilio.BaseClientWithCtx) *ApiService { + return NewApiServiceWithCtx(twilio.NewRequestHandlerWithCtx(client)) +} diff --git a/rest/serverless/v1/services.go b/rest/serverless/v1/services.go index cc1c5abca..2d3e223e2 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,11 @@ func (params *CreateServiceParams) SetUiEditable(UiEditable bool) *CreateService // Create a new Service resource. func (c *ApiService) CreateService(params *CreateServiceParams) (*ServerlessV1Service, error) { + return c.CreateServiceWithCtx(context.TODO(), params) +} + +// Create a new Service resource. +func (c *ApiService) CreateServiceWithCtx(ctx context.Context, params *CreateServiceParams) (*ServerlessV1Service, error) { path := "/v1/Services" data := url.Values{} @@ -72,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -89,13 +95,18 @@ func (c *ApiService) CreateService(params *CreateServiceParams) (*ServerlessV1Se // Delete a Service resource. func (c *ApiService) DeleteService(Sid string) error { + return c.DeleteServiceWithCtx(context.TODO(), Sid) +} + +// Delete a Service resource. +func (c *ApiService) DeleteServiceWithCtx(ctx context.Context, Sid string) error { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -107,13 +118,18 @@ func (c *ApiService) DeleteService(Sid string) error { // Retrieve a specific Service resource. func (c *ApiService) FetchService(Sid string) (*ServerlessV1Service, error) { + return c.FetchServiceWithCtx(context.TODO(), Sid) +} + +// Retrieve a specific Service resource. +func (c *ApiService) FetchServiceWithCtx(ctx context.Context, Sid string) (*ServerlessV1Service, error) { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -147,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.PageServiceWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Service records from the API. Request is executed immediately. +func (c *ApiService) PageServiceWithCtx(ctx context.Context, params *ListServiceParams, pageToken, pageNumber string) (*ListServiceResponse, error) { path := "/v1/Services" data := url.Values{} @@ -163,7 +184,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -180,7 +201,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.ListServiceWithCtx(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) ListServiceWithCtx(ctx context.Context, params *ListServiceParams) ([]ServerlessV1Service, error) { + response, errors := c.StreamServiceWithCtx(ctx, params) records := make([]ServerlessV1Service, 0) for record := range response { @@ -196,6 +222,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.StreamServiceWithCtx(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) StreamServiceWithCtx(ctx context.Context, params *ListServiceParams) (chan ServerlessV1Service, chan error) { if params == nil { params = &ListServiceParams{} } @@ -204,19 +235,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.PageServiceWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamService(response, params, recordChannel, errorChannel) + go c.streamService(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) streamService(ctx context.Context, response *ListServiceResponse, params *ListServiceParams, recordChannel chan ServerlessV1Service, errorChannel chan error) { curRecord := 1 for response != nil { @@ -231,7 +262,7 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListServiceResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListServiceResponse) if err != nil { errorChannel <- err break @@ -246,11 +277,11 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe close(errorChannel) } -func (c *ApiService) getNextListServiceResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListServiceResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -289,6 +320,11 @@ func (params *UpdateServiceParams) SetUiEditable(UiEditable bool) *UpdateService // Update a specific Service resource. func (c *ApiService) UpdateService(Sid string, params *UpdateServiceParams) (*ServerlessV1Service, error) { + return c.UpdateServiceWithCtx(context.TODO(), Sid, params) +} + +// Update a specific Service resource. +func (c *ApiService) UpdateServiceWithCtx(ctx context.Context, Sid string, params *UpdateServiceParams) (*ServerlessV1Service, error) { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -305,7 +341,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.Post(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 5ce0a10a6..952ec124a 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,11 @@ func (params *CreateAssetParams) SetFriendlyName(FriendlyName string) *CreateAss // Create a new Asset resource. func (c *ApiService) CreateAsset(ServiceSid string, params *CreateAssetParams) (*ServerlessV1Asset, error) { + return c.CreateAssetWithCtx(context.TODO(), ServiceSid, params) +} + +// Create a new Asset resource. +func (c *ApiService) CreateAssetWithCtx(ctx context.Context, ServiceSid string, params *CreateAssetParams) (*ServerlessV1Asset, error) { path := "/v1/Services/{ServiceSid}/Assets" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -46,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -63,6 +69,11 @@ func (c *ApiService) CreateAsset(ServiceSid string, params *CreateAssetParams) ( // Delete an Asset resource. func (c *ApiService) DeleteAsset(ServiceSid string, Sid string) error { + return c.DeleteAssetWithCtx(context.TODO(), ServiceSid, Sid) +} + +// Delete an Asset resource. +func (c *ApiService) DeleteAssetWithCtx(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) @@ -70,7 +81,7 @@ func (c *ApiService) DeleteAsset(ServiceSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -82,6 +93,11 @@ 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.FetchAssetWithCtx(context.TODO(), ServiceSid, Sid) +} + +// Retrieve a specific Asset resource. +func (c *ApiService) FetchAssetWithCtx(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) @@ -89,7 +105,7 @@ func (c *ApiService) FetchAsset(ServiceSid string, Sid string) (*ServerlessV1Ass data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -123,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.PageAssetWithCtx(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Asset records from the API. Request is executed immediately. +func (c *ApiService) PageAssetWithCtx(ctx context.Context, ServiceSid string, params *ListAssetParams, pageToken, pageNumber string) (*ListAssetResponse, error) { path := "/v1/Services/{ServiceSid}/Assets" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -141,7 +162,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -158,7 +179,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.ListAssetWithCtx(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) ListAssetWithCtx(ctx context.Context, ServiceSid string, params *ListAssetParams) ([]ServerlessV1Asset, error) { + response, errors := c.StreamAssetWithCtx(ctx, ServiceSid, params) records := make([]ServerlessV1Asset, 0) for record := range response { @@ -174,6 +200,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.StreamAssetWithCtx(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) StreamAssetWithCtx(ctx context.Context, ServiceSid string, params *ListAssetParams) (chan ServerlessV1Asset, chan error) { if params == nil { params = &ListAssetParams{} } @@ -182,19 +213,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.PageAssetWithCtx(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamAsset(response, params, recordChannel, errorChannel) + go c.streamAsset(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) streamAsset(ctx context.Context, response *ListAssetResponse, params *ListAssetParams, recordChannel chan ServerlessV1Asset, errorChannel chan error) { curRecord := 1 for response != nil { @@ -209,7 +240,7 @@ func (c *ApiService) streamAsset(response *ListAssetResponse, params *ListAssetP } } - record, err := client.GetNext(c.baseURL, response, c.getNextListAssetResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListAssetResponse) if err != nil { errorChannel <- err break @@ -224,11 +255,11 @@ func (c *ApiService) streamAsset(response *ListAssetResponse, params *ListAssetP close(errorChannel) } -func (c *ApiService) getNextListAssetResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListAssetResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -255,6 +286,11 @@ 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.UpdateAssetWithCtx(context.TODO(), ServiceSid, Sid, params) +} + +// Update a specific Asset resource. +func (c *ApiService) UpdateAssetWithCtx(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) @@ -266,7 +302,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.Post(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 f3a8e510b..81eff6a8f 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,11 @@ import ( // Retrieve a specific Asset Version. func (c *ApiService) FetchAssetVersion(ServiceSid string, AssetSid string, Sid string) (*ServerlessV1AssetVersion, error) { + return c.FetchAssetVersionWithCtx(context.TODO(), ServiceSid, AssetSid, Sid) +} + +// Retrieve a specific Asset Version. +func (c *ApiService) FetchAssetVersionWithCtx(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) @@ -33,7 +39,7 @@ func (c *ApiService) FetchAssetVersion(ServiceSid string, AssetSid string, Sid s data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -67,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.PageAssetVersionWithCtx(context.TODO(), ServiceSid, AssetSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of AssetVersion records from the API. Request is executed immediately. +func (c *ApiService) PageAssetVersionWithCtx(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) @@ -86,7 +97,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -103,7 +114,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.ListAssetVersionWithCtx(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) ListAssetVersionWithCtx(ctx context.Context, ServiceSid string, AssetSid string, params *ListAssetVersionParams) ([]ServerlessV1AssetVersion, error) { + response, errors := c.StreamAssetVersionWithCtx(ctx, ServiceSid, AssetSid, params) records := make([]ServerlessV1AssetVersion, 0) for record := range response { @@ -119,6 +135,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.StreamAssetVersionWithCtx(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) StreamAssetVersionWithCtx(ctx context.Context, ServiceSid string, AssetSid string, params *ListAssetVersionParams) (chan ServerlessV1AssetVersion, chan error) { if params == nil { params = &ListAssetVersionParams{} } @@ -127,19 +148,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.PageAssetVersionWithCtx(ctx, ServiceSid, AssetSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamAssetVersion(response, params, recordChannel, errorChannel) + go c.streamAssetVersion(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) streamAssetVersion(ctx context.Context, response *ListAssetVersionResponse, params *ListAssetVersionParams, recordChannel chan ServerlessV1AssetVersion, errorChannel chan error) { curRecord := 1 for response != nil { @@ -154,7 +175,7 @@ func (c *ApiService) streamAssetVersion(response *ListAssetVersionResponse, para } } - record, err := client.GetNext(c.baseURL, response, c.getNextListAssetVersionResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListAssetVersionResponse) if err != nil { errorChannel <- err break @@ -169,11 +190,11 @@ func (c *ApiService) streamAssetVersion(response *ListAssetVersionResponse, para close(errorChannel) } -func (c *ApiService) getNextListAssetVersionResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListAssetVersionResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 838001d90..4217b57fb 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,11 @@ 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.CreateBuildWithCtx(context.TODO(), ServiceSid, params) +} + +// Create a new Build resource. At least one function version or asset version is required. +func (c *ApiService) CreateBuildWithCtx(ctx context.Context, ServiceSid string, params *CreateBuildParams) (*ServerlessV1Build, error) { path := "/v1/Services/{ServiceSid}/Builds" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -77,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -94,6 +100,11 @@ func (c *ApiService) CreateBuild(ServiceSid string, params *CreateBuildParams) ( // Delete a Build resource. func (c *ApiService) DeleteBuild(ServiceSid string, Sid string) error { + return c.DeleteBuildWithCtx(context.TODO(), ServiceSid, Sid) +} + +// Delete a Build resource. +func (c *ApiService) DeleteBuildWithCtx(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) @@ -101,7 +112,7 @@ func (c *ApiService) DeleteBuild(ServiceSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -113,6 +124,11 @@ 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.FetchBuildWithCtx(context.TODO(), ServiceSid, Sid) +} + +// Retrieve a specific Build resource. +func (c *ApiService) FetchBuildWithCtx(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) @@ -120,7 +136,7 @@ func (c *ApiService) FetchBuild(ServiceSid string, Sid string) (*ServerlessV1Bui data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -154,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.PageBuildWithCtx(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Build records from the API. Request is executed immediately. +func (c *ApiService) PageBuildWithCtx(ctx context.Context, ServiceSid string, params *ListBuildParams, pageToken, pageNumber string) (*ListBuildResponse, error) { path := "/v1/Services/{ServiceSid}/Builds" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -172,7 +193,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -189,7 +210,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.ListBuildWithCtx(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) ListBuildWithCtx(ctx context.Context, ServiceSid string, params *ListBuildParams) ([]ServerlessV1Build, error) { + response, errors := c.StreamBuildWithCtx(ctx, ServiceSid, params) records := make([]ServerlessV1Build, 0) for record := range response { @@ -205,6 +231,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.StreamBuildWithCtx(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) StreamBuildWithCtx(ctx context.Context, ServiceSid string, params *ListBuildParams) (chan ServerlessV1Build, chan error) { if params == nil { params = &ListBuildParams{} } @@ -213,19 +244,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.PageBuildWithCtx(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamBuild(response, params, recordChannel, errorChannel) + go c.streamBuild(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) streamBuild(ctx context.Context, response *ListBuildResponse, params *ListBuildParams, recordChannel chan ServerlessV1Build, errorChannel chan error) { curRecord := 1 for response != nil { @@ -240,7 +271,7 @@ func (c *ApiService) streamBuild(response *ListBuildResponse, params *ListBuildP } } - record, err := client.GetNext(c.baseURL, response, c.getNextListBuildResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListBuildResponse) if err != nil { errorChannel <- err break @@ -255,11 +286,11 @@ func (c *ApiService) streamBuild(response *ListBuildResponse, params *ListBuildP close(errorChannel) } -func (c *ApiService) getNextListBuildResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListBuildResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 81a3e2553..68ba1b468 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,11 @@ import ( // Retrieve a specific Build resource. func (c *ApiService) FetchBuildStatus(ServiceSid string, Sid string) (*ServerlessV1BuildStatus, error) { + return c.FetchBuildStatusWithCtx(context.TODO(), ServiceSid, Sid) +} + +// Retrieve a specific Build resource. +func (c *ApiService) FetchBuildStatusWithCtx(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) @@ -29,7 +35,7 @@ func (c *ApiService) FetchBuildStatus(ServiceSid string, Sid string) (*Serverles data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(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 0dd9b37b4..553fa20cc 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,11 @@ func (params *CreateEnvironmentParams) SetDomainSuffix(DomainSuffix string) *Cre // Create a new environment. func (c *ApiService) CreateEnvironment(ServiceSid string, params *CreateEnvironmentParams) (*ServerlessV1Environment, error) { + return c.CreateEnvironmentWithCtx(context.TODO(), ServiceSid, params) +} + +// Create a new environment. +func (c *ApiService) CreateEnvironmentWithCtx(ctx context.Context, ServiceSid string, params *CreateEnvironmentParams) (*ServerlessV1Environment, error) { path := "/v1/Services/{ServiceSid}/Environments" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -55,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -72,6 +78,11 @@ func (c *ApiService) CreateEnvironment(ServiceSid string, params *CreateEnvironm // Delete a specific environment. func (c *ApiService) DeleteEnvironment(ServiceSid string, Sid string) error { + return c.DeleteEnvironmentWithCtx(context.TODO(), ServiceSid, Sid) +} + +// Delete a specific environment. +func (c *ApiService) DeleteEnvironmentWithCtx(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) @@ -79,7 +90,7 @@ func (c *ApiService) DeleteEnvironment(ServiceSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -91,6 +102,11 @@ 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.FetchEnvironmentWithCtx(context.TODO(), ServiceSid, Sid) +} + +// Retrieve a specific environment. +func (c *ApiService) FetchEnvironmentWithCtx(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) @@ -98,7 +114,7 @@ func (c *ApiService) FetchEnvironment(ServiceSid string, Sid string) (*Serverles data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -132,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.PageEnvironmentWithCtx(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Environment records from the API. Request is executed immediately. +func (c *ApiService) PageEnvironmentWithCtx(ctx context.Context, ServiceSid string, params *ListEnvironmentParams, pageToken, pageNumber string) (*ListEnvironmentResponse, error) { path := "/v1/Services/{ServiceSid}/Environments" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -150,7 +171,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -167,7 +188,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.ListEnvironmentWithCtx(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) ListEnvironmentWithCtx(ctx context.Context, ServiceSid string, params *ListEnvironmentParams) ([]ServerlessV1Environment, error) { + response, errors := c.StreamEnvironmentWithCtx(ctx, ServiceSid, params) records := make([]ServerlessV1Environment, 0) for record := range response { @@ -183,6 +209,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.StreamEnvironmentWithCtx(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) StreamEnvironmentWithCtx(ctx context.Context, ServiceSid string, params *ListEnvironmentParams) (chan ServerlessV1Environment, chan error) { if params == nil { params = &ListEnvironmentParams{} } @@ -191,19 +222,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.PageEnvironmentWithCtx(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamEnvironment(response, params, recordChannel, errorChannel) + go c.streamEnvironment(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) streamEnvironment(ctx context.Context, response *ListEnvironmentResponse, params *ListEnvironmentParams, recordChannel chan ServerlessV1Environment, errorChannel chan error) { curRecord := 1 for response != nil { @@ -218,7 +249,7 @@ func (c *ApiService) streamEnvironment(response *ListEnvironmentResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListEnvironmentResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListEnvironmentResponse) if err != nil { errorChannel <- err break @@ -233,11 +264,11 @@ func (c *ApiService) streamEnvironment(response *ListEnvironmentResponse, params close(errorChannel) } -func (c *ApiService) getNextListEnvironmentResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListEnvironmentResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 d061c40c0..1b9279475 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" @@ -36,6 +37,11 @@ func (params *CreateDeploymentParams) SetBuildSid(BuildSid string) *CreateDeploy // Create a new Deployment. func (c *ApiService) CreateDeployment(ServiceSid string, EnvironmentSid string, params *CreateDeploymentParams) (*ServerlessV1Deployment, error) { + return c.CreateDeploymentWithCtx(context.TODO(), ServiceSid, EnvironmentSid, params) +} + +// Create a new Deployment. +func (c *ApiService) CreateDeploymentWithCtx(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) @@ -47,7 +53,7 @@ func (c *ApiService) CreateDeployment(ServiceSid string, EnvironmentSid string, data.Set("BuildSid", *params.BuildSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -64,6 +70,11 @@ 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.FetchDeploymentWithCtx(context.TODO(), ServiceSid, EnvironmentSid, Sid) +} + +// Retrieve a specific Deployment. +func (c *ApiService) FetchDeploymentWithCtx(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) @@ -72,7 +83,7 @@ func (c *ApiService) FetchDeployment(ServiceSid string, EnvironmentSid string, S data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -106,6 +117,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.PageDeploymentWithCtx(context.TODO(), ServiceSid, EnvironmentSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Deployment records from the API. Request is executed immediately. +func (c *ApiService) PageDeploymentWithCtx(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) @@ -125,7 +141,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -142,7 +158,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.ListDeploymentWithCtx(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) ListDeploymentWithCtx(ctx context.Context, ServiceSid string, EnvironmentSid string, params *ListDeploymentParams) ([]ServerlessV1Deployment, error) { + response, errors := c.StreamDeploymentWithCtx(ctx, ServiceSid, EnvironmentSid, params) records := make([]ServerlessV1Deployment, 0) for record := range response { @@ -158,6 +179,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.StreamDeploymentWithCtx(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) StreamDeploymentWithCtx(ctx context.Context, ServiceSid string, EnvironmentSid string, params *ListDeploymentParams) (chan ServerlessV1Deployment, chan error) { if params == nil { params = &ListDeploymentParams{} } @@ -166,19 +192,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.PageDeploymentWithCtx(ctx, ServiceSid, EnvironmentSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamDeployment(response, params, recordChannel, errorChannel) + go c.streamDeployment(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) streamDeployment(ctx context.Context, response *ListDeploymentResponse, params *ListDeploymentParams, recordChannel chan ServerlessV1Deployment, errorChannel chan error) { curRecord := 1 for response != nil { @@ -193,7 +219,7 @@ func (c *ApiService) streamDeployment(response *ListDeploymentResponse, params * } } - record, err := client.GetNext(c.baseURL, response, c.getNextListDeploymentResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListDeploymentResponse) if err != nil { errorChannel <- err break @@ -208,11 +234,11 @@ func (c *ApiService) streamDeployment(response *ListDeploymentResponse, params * close(errorChannel) } -func (c *ApiService) getNextListDeploymentResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListDeploymentResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 7fbbc264d..c01316d4c 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,11 @@ import ( // Retrieve a specific log. func (c *ApiService) FetchLog(ServiceSid string, EnvironmentSid string, Sid string) (*ServerlessV1Log, error) { + return c.FetchLogWithCtx(context.TODO(), ServiceSid, EnvironmentSid, Sid) +} + +// Retrieve a specific log. +func (c *ApiService) FetchLogWithCtx(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) @@ -34,7 +40,7 @@ func (c *ApiService) FetchLog(ServiceSid string, EnvironmentSid string, Sid stri data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -86,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.PageLogWithCtx(context.TODO(), ServiceSid, EnvironmentSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Log records from the API. Request is executed immediately. +func (c *ApiService) PageLogWithCtx(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) @@ -114,7 +125,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -131,7 +142,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.ListLogWithCtx(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) ListLogWithCtx(ctx context.Context, ServiceSid string, EnvironmentSid string, params *ListLogParams) ([]ServerlessV1Log, error) { + response, errors := c.StreamLogWithCtx(ctx, ServiceSid, EnvironmentSid, params) records := make([]ServerlessV1Log, 0) for record := range response { @@ -147,6 +163,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.StreamLogWithCtx(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) StreamLogWithCtx(ctx context.Context, ServiceSid string, EnvironmentSid string, params *ListLogParams) (chan ServerlessV1Log, chan error) { if params == nil { params = &ListLogParams{} } @@ -155,19 +176,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.PageLogWithCtx(ctx, ServiceSid, EnvironmentSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamLog(response, params, recordChannel, errorChannel) + go c.streamLog(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) streamLog(ctx context.Context, response *ListLogResponse, params *ListLogParams, recordChannel chan ServerlessV1Log, errorChannel chan error) { curRecord := 1 for response != nil { @@ -182,7 +203,7 @@ func (c *ApiService) streamLog(response *ListLogResponse, params *ListLogParams, } } - record, err := client.GetNext(c.baseURL, response, c.getNextListLogResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListLogResponse) if err != nil { errorChannel <- err break @@ -197,11 +218,11 @@ func (c *ApiService) streamLog(response *ListLogResponse, params *ListLogParams, close(errorChannel) } -func (c *ApiService) getNextListLogResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListLogResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 891919414..236c9cb03 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,11 @@ 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.CreateVariableWithCtx(context.TODO(), ServiceSid, EnvironmentSid, params) +} + +// Create a new Variable. +func (c *ApiService) CreateVariableWithCtx(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) @@ -56,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -73,6 +79,11 @@ 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.DeleteVariableWithCtx(context.TODO(), ServiceSid, EnvironmentSid, Sid) +} + +// Delete a specific Variable. +func (c *ApiService) DeleteVariableWithCtx(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) @@ -81,7 +92,7 @@ func (c *ApiService) DeleteVariable(ServiceSid string, EnvironmentSid string, Si data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -93,6 +104,11 @@ 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.FetchVariableWithCtx(context.TODO(), ServiceSid, EnvironmentSid, Sid) +} + +// Retrieve a specific Variable. +func (c *ApiService) FetchVariableWithCtx(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) @@ -101,7 +117,7 @@ func (c *ApiService) FetchVariable(ServiceSid string, EnvironmentSid string, Sid data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -135,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.PageVariableWithCtx(context.TODO(), ServiceSid, EnvironmentSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Variable records from the API. Request is executed immediately. +func (c *ApiService) PageVariableWithCtx(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) @@ -154,7 +175,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -171,7 +192,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.ListVariableWithCtx(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) ListVariableWithCtx(ctx context.Context, ServiceSid string, EnvironmentSid string, params *ListVariableParams) ([]ServerlessV1Variable, error) { + response, errors := c.StreamVariableWithCtx(ctx, ServiceSid, EnvironmentSid, params) records := make([]ServerlessV1Variable, 0) for record := range response { @@ -187,6 +213,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.StreamVariableWithCtx(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) StreamVariableWithCtx(ctx context.Context, ServiceSid string, EnvironmentSid string, params *ListVariableParams) (chan ServerlessV1Variable, chan error) { if params == nil { params = &ListVariableParams{} } @@ -195,19 +226,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.PageVariableWithCtx(ctx, ServiceSid, EnvironmentSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamVariable(response, params, recordChannel, errorChannel) + go c.streamVariable(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) streamVariable(ctx context.Context, response *ListVariableResponse, params *ListVariableParams, recordChannel chan ServerlessV1Variable, errorChannel chan error) { curRecord := 1 for response != nil { @@ -222,7 +253,7 @@ func (c *ApiService) streamVariable(response *ListVariableResponse, params *List } } - record, err := client.GetNext(c.baseURL, response, c.getNextListVariableResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListVariableResponse) if err != nil { errorChannel <- err break @@ -237,11 +268,11 @@ func (c *ApiService) streamVariable(response *ListVariableResponse, params *List close(errorChannel) } -func (c *ApiService) getNextListVariableResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListVariableResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -274,6 +305,11 @@ 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.UpdateVariableWithCtx(context.TODO(), ServiceSid, EnvironmentSid, Sid, params) +} + +// Update a specific Variable. +func (c *ApiService) UpdateVariableWithCtx(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) @@ -289,7 +325,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.Post(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 73dd19964..c02101d53 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,11 @@ func (params *CreateFunctionParams) SetFriendlyName(FriendlyName string) *Create // Create a new Function resource. func (c *ApiService) CreateFunction(ServiceSid string, params *CreateFunctionParams) (*ServerlessV1Function, error) { + return c.CreateFunctionWithCtx(context.TODO(), ServiceSid, params) +} + +// Create a new Function resource. +func (c *ApiService) CreateFunctionWithCtx(ctx context.Context, ServiceSid string, params *CreateFunctionParams) (*ServerlessV1Function, error) { path := "/v1/Services/{ServiceSid}/Functions" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -46,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -63,6 +69,11 @@ func (c *ApiService) CreateFunction(ServiceSid string, params *CreateFunctionPar // Delete a Function resource. func (c *ApiService) DeleteFunction(ServiceSid string, Sid string) error { + return c.DeleteFunctionWithCtx(context.TODO(), ServiceSid, Sid) +} + +// Delete a Function resource. +func (c *ApiService) DeleteFunctionWithCtx(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) @@ -70,7 +81,7 @@ func (c *ApiService) DeleteFunction(ServiceSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -82,6 +93,11 @@ 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.FetchFunctionWithCtx(context.TODO(), ServiceSid, Sid) +} + +// Retrieve a specific Function resource. +func (c *ApiService) FetchFunctionWithCtx(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) @@ -89,7 +105,7 @@ func (c *ApiService) FetchFunction(ServiceSid string, Sid string) (*ServerlessV1 data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -123,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.PageFunctionWithCtx(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Function records from the API. Request is executed immediately. +func (c *ApiService) PageFunctionWithCtx(ctx context.Context, ServiceSid string, params *ListFunctionParams, pageToken, pageNumber string) (*ListFunctionResponse, error) { path := "/v1/Services/{ServiceSid}/Functions" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -141,7 +162,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -158,7 +179,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.ListFunctionWithCtx(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) ListFunctionWithCtx(ctx context.Context, ServiceSid string, params *ListFunctionParams) ([]ServerlessV1Function, error) { + response, errors := c.StreamFunctionWithCtx(ctx, ServiceSid, params) records := make([]ServerlessV1Function, 0) for record := range response { @@ -174,6 +200,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.StreamFunctionWithCtx(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) StreamFunctionWithCtx(ctx context.Context, ServiceSid string, params *ListFunctionParams) (chan ServerlessV1Function, chan error) { if params == nil { params = &ListFunctionParams{} } @@ -182,19 +213,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.PageFunctionWithCtx(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamFunction(response, params, recordChannel, errorChannel) + go c.streamFunction(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) streamFunction(ctx context.Context, response *ListFunctionResponse, params *ListFunctionParams, recordChannel chan ServerlessV1Function, errorChannel chan error) { curRecord := 1 for response != nil { @@ -209,7 +240,7 @@ func (c *ApiService) streamFunction(response *ListFunctionResponse, params *List } } - record, err := client.GetNext(c.baseURL, response, c.getNextListFunctionResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListFunctionResponse) if err != nil { errorChannel <- err break @@ -224,11 +255,11 @@ func (c *ApiService) streamFunction(response *ListFunctionResponse, params *List close(errorChannel) } -func (c *ApiService) getNextListFunctionResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListFunctionResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -255,6 +286,11 @@ 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.UpdateFunctionWithCtx(context.TODO(), ServiceSid, Sid, params) +} + +// Update a specific Function resource. +func (c *ApiService) UpdateFunctionWithCtx(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) @@ -266,7 +302,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.Post(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 28f14f84a..85501095e 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,11 @@ import ( // Retrieve a specific Function Version resource. func (c *ApiService) FetchFunctionVersion(ServiceSid string, FunctionSid string, Sid string) (*ServerlessV1FunctionVersion, error) { + return c.FetchFunctionVersionWithCtx(context.TODO(), ServiceSid, FunctionSid, Sid) +} + +// Retrieve a specific Function Version resource. +func (c *ApiService) FetchFunctionVersionWithCtx(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) @@ -33,7 +39,7 @@ func (c *ApiService) FetchFunctionVersion(ServiceSid string, FunctionSid string, data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -67,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.PageFunctionVersionWithCtx(context.TODO(), ServiceSid, FunctionSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of FunctionVersion records from the API. Request is executed immediately. +func (c *ApiService) PageFunctionVersionWithCtx(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) @@ -86,7 +97,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -103,7 +114,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.ListFunctionVersionWithCtx(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) ListFunctionVersionWithCtx(ctx context.Context, ServiceSid string, FunctionSid string, params *ListFunctionVersionParams) ([]ServerlessV1FunctionVersion, error) { + response, errors := c.StreamFunctionVersionWithCtx(ctx, ServiceSid, FunctionSid, params) records := make([]ServerlessV1FunctionVersion, 0) for record := range response { @@ -119,6 +135,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.StreamFunctionVersionWithCtx(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) StreamFunctionVersionWithCtx(ctx context.Context, ServiceSid string, FunctionSid string, params *ListFunctionVersionParams) (chan ServerlessV1FunctionVersion, chan error) { if params == nil { params = &ListFunctionVersionParams{} } @@ -127,19 +148,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.PageFunctionVersionWithCtx(ctx, ServiceSid, FunctionSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamFunctionVersion(response, params, recordChannel, errorChannel) + go c.streamFunctionVersion(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) streamFunctionVersion(ctx context.Context, response *ListFunctionVersionResponse, params *ListFunctionVersionParams, recordChannel chan ServerlessV1FunctionVersion, errorChannel chan error) { curRecord := 1 for response != nil { @@ -154,7 +175,7 @@ func (c *ApiService) streamFunctionVersion(response *ListFunctionVersionResponse } } - record, err := client.GetNext(c.baseURL, response, c.getNextListFunctionVersionResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListFunctionVersionResponse) if err != nil { errorChannel <- err break @@ -169,11 +190,11 @@ func (c *ApiService) streamFunctionVersion(response *ListFunctionVersionResponse close(errorChannel) } -func (c *ApiService) getNextListFunctionVersionResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListFunctionVersionResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 d4524759a..9302a0b51 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,11 @@ 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.FetchFunctionVersionContentWithCtx(context.TODO(), ServiceSid, FunctionSid, Sid) +} + +// Retrieve a the content of a specific Function Version resource. +func (c *ApiService) FetchFunctionVersionContentWithCtx(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) @@ -30,7 +36,7 @@ func (c *ApiService) FetchFunctionVersionContent(ServiceSid string, FunctionSid data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(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 e6af2fdce..7125eb5f1 100644 --- a/rest/studio/v1/api_service.go +++ b/rest/studio/v1/api_service.go @@ -20,10 +20,14 @@ import ( type ApiService struct { baseURL string - requestHandler *twilio.RequestHandler + requestHandler *twilio.RequestHandlerWithCtx } func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { + return NewApiServiceWithCtx(twilio.UpgradeRequestHandler(requestHandler)) +} + +func NewApiServiceWithCtx(requestHandler *twilio.RequestHandlerWithCtx) *ApiService { return &ApiService{ requestHandler: requestHandler, baseURL: "https://studio.twilio.com", @@ -33,3 +37,7 @@ func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { func NewApiServiceWithClient(client twilio.BaseClient) *ApiService { return NewApiService(twilio.NewRequestHandler(client)) } + +func NewApiServiceWithClientWithCtx(client twilio.BaseClientWithCtx) *ApiService { + return NewApiServiceWithCtx(twilio.NewRequestHandlerWithCtx(client)) +} diff --git a/rest/studio/v1/flows.go b/rest/studio/v1/flows.go index 4cf073e28..60910bcc8 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,13 +26,18 @@ import ( // Delete a specific Flow. func (c *ApiService) DeleteFlow(Sid string) error { + return c.DeleteFlowWithCtx(context.TODO(), Sid) +} + +// Delete a specific Flow. +func (c *ApiService) DeleteFlowWithCtx(ctx context.Context, Sid string) error { path := "/v1/Flows/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -43,13 +49,18 @@ func (c *ApiService) DeleteFlow(Sid string) error { // Retrieve a specific Flow. func (c *ApiService) FetchFlow(Sid string) (*StudioV1Flow, error) { + return c.FetchFlowWithCtx(context.TODO(), Sid) +} + +// Retrieve a specific Flow. +func (c *ApiService) FetchFlowWithCtx(ctx context.Context, Sid string) (*StudioV1Flow, error) { path := "/v1/Flows/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -83,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.PageFlowWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Flow records from the API. Request is executed immediately. +func (c *ApiService) PageFlowWithCtx(ctx context.Context, params *ListFlowParams, pageToken, pageNumber string) (*ListFlowResponse, error) { path := "/v1/Flows" data := url.Values{} @@ -99,7 +115,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -116,7 +132,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.ListFlowWithCtx(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) ListFlowWithCtx(ctx context.Context, params *ListFlowParams) ([]StudioV1Flow, error) { + response, errors := c.StreamFlowWithCtx(ctx, params) records := make([]StudioV1Flow, 0) for record := range response { @@ -132,6 +153,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.StreamFlowWithCtx(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) StreamFlowWithCtx(ctx context.Context, params *ListFlowParams) (chan StudioV1Flow, chan error) { if params == nil { params = &ListFlowParams{} } @@ -140,19 +166,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.PageFlowWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamFlow(response, params, recordChannel, errorChannel) + go c.streamFlow(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) streamFlow(ctx context.Context, response *ListFlowResponse, params *ListFlowParams, recordChannel chan StudioV1Flow, errorChannel chan error) { curRecord := 1 for response != nil { @@ -167,7 +193,7 @@ func (c *ApiService) streamFlow(response *ListFlowResponse, params *ListFlowPara } } - record, err := client.GetNext(c.baseURL, response, c.getNextListFlowResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListFlowResponse) if err != nil { errorChannel <- err break @@ -182,11 +208,11 @@ func (c *ApiService) streamFlow(response *ListFlowResponse, params *ListFlowPara close(errorChannel) } -func (c *ApiService) getNextListFlowResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListFlowResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 2d51100b2..d5391c191 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,11 @@ func (params *CreateEngagementParams) SetParameters(Parameters interface{}) *Cre // Triggers a new Engagement for the Flow func (c *ApiService) CreateEngagement(FlowSid string, params *CreateEngagementParams) (*StudioV1Engagement, error) { + return c.CreateEngagementWithCtx(context.TODO(), FlowSid, params) +} + +// Triggers a new Engagement for the Flow +func (c *ApiService) CreateEngagementWithCtx(ctx context.Context, FlowSid string, params *CreateEngagementParams) (*StudioV1Engagement, error) { path := "/v1/Flows/{FlowSid}/Engagements" path = strings.Replace(path, "{"+"FlowSid"+"}", FlowSid, -1) @@ -70,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -87,6 +93,11 @@ 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.DeleteEngagementWithCtx(context.TODO(), FlowSid, Sid) +} + +// Delete this Engagement and all Steps relating to it. +func (c *ApiService) DeleteEngagementWithCtx(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) @@ -94,7 +105,7 @@ func (c *ApiService) DeleteEngagement(FlowSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -106,6 +117,11 @@ func (c *ApiService) DeleteEngagement(FlowSid string, Sid string) error { // Retrieve an Engagement func (c *ApiService) FetchEngagement(FlowSid string, Sid string) (*StudioV1Engagement, error) { + return c.FetchEngagementWithCtx(context.TODO(), FlowSid, Sid) +} + +// Retrieve an Engagement +func (c *ApiService) FetchEngagementWithCtx(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) @@ -113,7 +129,7 @@ func (c *ApiService) FetchEngagement(FlowSid string, Sid string) (*StudioV1Engag data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -147,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.PageEngagementWithCtx(context.TODO(), FlowSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Engagement records from the API. Request is executed immediately. +func (c *ApiService) PageEngagementWithCtx(ctx context.Context, FlowSid string, params *ListEngagementParams, pageToken, pageNumber string) (*ListEngagementResponse, error) { path := "/v1/Flows/{FlowSid}/Engagements" path = strings.Replace(path, "{"+"FlowSid"+"}", FlowSid, -1) @@ -165,7 +186,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -182,7 +203,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.ListEngagementWithCtx(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) ListEngagementWithCtx(ctx context.Context, FlowSid string, params *ListEngagementParams) ([]StudioV1Engagement, error) { + response, errors := c.StreamEngagementWithCtx(ctx, FlowSid, params) records := make([]StudioV1Engagement, 0) for record := range response { @@ -198,6 +224,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.StreamEngagementWithCtx(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) StreamEngagementWithCtx(ctx context.Context, FlowSid string, params *ListEngagementParams) (chan StudioV1Engagement, chan error) { if params == nil { params = &ListEngagementParams{} } @@ -206,19 +237,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.PageEngagementWithCtx(ctx, FlowSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamEngagement(response, params, recordChannel, errorChannel) + go c.streamEngagement(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) streamEngagement(ctx context.Context, response *ListEngagementResponse, params *ListEngagementParams, recordChannel chan StudioV1Engagement, errorChannel chan error) { curRecord := 1 for response != nil { @@ -233,7 +264,7 @@ func (c *ApiService) streamEngagement(response *ListEngagementResponse, params * } } - record, err := client.GetNext(c.baseURL, response, c.getNextListEngagementResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListEngagementResponse) if err != nil { errorChannel <- err break @@ -248,11 +279,11 @@ func (c *ApiService) streamEngagement(response *ListEngagementResponse, params * close(errorChannel) } -func (c *ApiService) getNextListEngagementResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListEngagementResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 d6d963662..b14ddbc53 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,11 @@ import ( // Retrieve the most recent context for an Engagement. func (c *ApiService) FetchEngagementContext(FlowSid string, EngagementSid string) (*StudioV1EngagementContext, error) { + return c.FetchEngagementContextWithCtx(context.TODO(), FlowSid, EngagementSid) +} + +// Retrieve the most recent context for an Engagement. +func (c *ApiService) FetchEngagementContextWithCtx(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) @@ -29,7 +35,7 @@ func (c *ApiService) FetchEngagementContext(FlowSid string, EngagementSid string data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(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 11dac1105..455933c23 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,11 @@ import ( // Retrieve a Step. func (c *ApiService) FetchStep(FlowSid string, EngagementSid string, Sid string) (*StudioV1Step, error) { + return c.FetchStepWithCtx(context.TODO(), FlowSid, EngagementSid, Sid) +} + +// Retrieve a Step. +func (c *ApiService) FetchStepWithCtx(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) @@ -33,7 +39,7 @@ func (c *ApiService) FetchStep(FlowSid string, EngagementSid string, Sid string) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -67,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.PageStepWithCtx(context.TODO(), FlowSid, EngagementSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Step records from the API. Request is executed immediately. +func (c *ApiService) PageStepWithCtx(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) @@ -86,7 +97,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -103,7 +114,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.ListStepWithCtx(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) ListStepWithCtx(ctx context.Context, FlowSid string, EngagementSid string, params *ListStepParams) ([]StudioV1Step, error) { + response, errors := c.StreamStepWithCtx(ctx, FlowSid, EngagementSid, params) records := make([]StudioV1Step, 0) for record := range response { @@ -119,6 +135,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.StreamStepWithCtx(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) StreamStepWithCtx(ctx context.Context, FlowSid string, EngagementSid string, params *ListStepParams) (chan StudioV1Step, chan error) { if params == nil { params = &ListStepParams{} } @@ -127,19 +148,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.PageStepWithCtx(ctx, FlowSid, EngagementSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamStep(response, params, recordChannel, errorChannel) + go c.streamStep(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) streamStep(ctx context.Context, response *ListStepResponse, params *ListStepParams, recordChannel chan StudioV1Step, errorChannel chan error) { curRecord := 1 for response != nil { @@ -154,7 +175,7 @@ func (c *ApiService) streamStep(response *ListStepResponse, params *ListStepPara } } - record, err := client.GetNext(c.baseURL, response, c.getNextListStepResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListStepResponse) if err != nil { errorChannel <- err break @@ -169,11 +190,11 @@ func (c *ApiService) streamStep(response *ListStepResponse, params *ListStepPara close(errorChannel) } -func (c *ApiService) getNextListStepResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListStepResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 882d50c84..7edf7e0f3 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,11 @@ import ( // Retrieve the context for an Engagement Step. func (c *ApiService) FetchStepContext(FlowSid string, EngagementSid string, StepSid string) (*StudioV1StepContext, error) { + return c.FetchStepContextWithCtx(context.TODO(), FlowSid, EngagementSid, StepSid) +} + +// Retrieve the context for an Engagement Step. +func (c *ApiService) FetchStepContextWithCtx(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) @@ -30,7 +36,7 @@ func (c *ApiService) FetchStepContext(FlowSid string, EngagementSid string, Step data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(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 d599ce1ac..c059229ac 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,11 @@ func (params *CreateExecutionParams) SetParameters(Parameters interface{}) *Crea // Triggers a new Execution for the Flow func (c *ApiService) CreateExecution(FlowSid string, params *CreateExecutionParams) (*StudioV1Execution, error) { + return c.CreateExecutionWithCtx(context.TODO(), FlowSid, params) +} + +// Triggers a new Execution for the Flow +func (c *ApiService) CreateExecutionWithCtx(ctx context.Context, FlowSid string, params *CreateExecutionParams) (*StudioV1Execution, error) { path := "/v1/Flows/{FlowSid}/Executions" path = strings.Replace(path, "{"+"FlowSid"+"}", FlowSid, -1) @@ -71,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -88,6 +94,11 @@ 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.DeleteExecutionWithCtx(context.TODO(), FlowSid, Sid) +} + +// Delete the Execution and all Steps relating to it. +func (c *ApiService) DeleteExecutionWithCtx(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) @@ -95,7 +106,7 @@ func (c *ApiService) DeleteExecution(FlowSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -107,6 +118,11 @@ func (c *ApiService) DeleteExecution(FlowSid string, Sid string) error { // Retrieve an Execution func (c *ApiService) FetchExecution(FlowSid string, Sid string) (*StudioV1Execution, error) { + return c.FetchExecutionWithCtx(context.TODO(), FlowSid, Sid) +} + +// Retrieve an Execution +func (c *ApiService) FetchExecutionWithCtx(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) @@ -114,7 +130,7 @@ func (c *ApiService) FetchExecution(FlowSid string, Sid string) (*StudioV1Execut data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -160,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.PageExecutionWithCtx(context.TODO(), FlowSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Execution records from the API. Request is executed immediately. +func (c *ApiService) PageExecutionWithCtx(ctx context.Context, FlowSid string, params *ListExecutionParams, pageToken, pageNumber string) (*ListExecutionResponse, error) { path := "/v1/Flows/{FlowSid}/Executions" path = strings.Replace(path, "{"+"FlowSid"+"}", FlowSid, -1) @@ -184,7 +205,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -201,7 +222,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.ListExecutionWithCtx(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) ListExecutionWithCtx(ctx context.Context, FlowSid string, params *ListExecutionParams) ([]StudioV1Execution, error) { + response, errors := c.StreamExecutionWithCtx(ctx, FlowSid, params) records := make([]StudioV1Execution, 0) for record := range response { @@ -217,6 +243,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.StreamExecutionWithCtx(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) StreamExecutionWithCtx(ctx context.Context, FlowSid string, params *ListExecutionParams) (chan StudioV1Execution, chan error) { if params == nil { params = &ListExecutionParams{} } @@ -225,19 +256,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.PageExecutionWithCtx(ctx, FlowSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamExecution(response, params, recordChannel, errorChannel) + go c.streamExecution(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) streamExecution(ctx context.Context, response *ListExecutionResponse, params *ListExecutionParams, recordChannel chan StudioV1Execution, errorChannel chan error) { curRecord := 1 for response != nil { @@ -252,7 +283,7 @@ func (c *ApiService) streamExecution(response *ListExecutionResponse, params *Li } } - record, err := client.GetNext(c.baseURL, response, c.getNextListExecutionResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListExecutionResponse) if err != nil { errorChannel <- err break @@ -267,11 +298,11 @@ func (c *ApiService) streamExecution(response *ListExecutionResponse, params *Li close(errorChannel) } -func (c *ApiService) getNextListExecutionResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListExecutionResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -298,6 +329,11 @@ 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.UpdateExecutionWithCtx(context.TODO(), FlowSid, Sid, params) +} + +// Update the status of an Execution to `ended`. +func (c *ApiService) UpdateExecutionWithCtx(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) @@ -309,7 +345,7 @@ func (c *ApiService) UpdateExecution(FlowSid string, Sid string, params *UpdateE data.Set("Status", *params.Status) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 c7eb6665a..2eb23c668 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,11 @@ import ( // Retrieve the most recent context for an Execution. func (c *ApiService) FetchExecutionContext(FlowSid string, ExecutionSid string) (*StudioV1ExecutionContext, error) { + return c.FetchExecutionContextWithCtx(context.TODO(), FlowSid, ExecutionSid) +} + +// Retrieve the most recent context for an Execution. +func (c *ApiService) FetchExecutionContextWithCtx(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) @@ -29,7 +35,7 @@ func (c *ApiService) FetchExecutionContext(FlowSid string, ExecutionSid string) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(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 c4423c3ff..9f318a0a8 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,11 @@ import ( // Retrieve a Step. func (c *ApiService) FetchExecutionStep(FlowSid string, ExecutionSid string, Sid string) (*StudioV1ExecutionStep, error) { + return c.FetchExecutionStepWithCtx(context.TODO(), FlowSid, ExecutionSid, Sid) +} + +// Retrieve a Step. +func (c *ApiService) FetchExecutionStepWithCtx(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) @@ -33,7 +39,7 @@ func (c *ApiService) FetchExecutionStep(FlowSid string, ExecutionSid string, Sid data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -67,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.PageExecutionStepWithCtx(context.TODO(), FlowSid, ExecutionSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ExecutionStep records from the API. Request is executed immediately. +func (c *ApiService) PageExecutionStepWithCtx(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) @@ -86,7 +97,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -103,7 +114,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.ListExecutionStepWithCtx(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) ListExecutionStepWithCtx(ctx context.Context, FlowSid string, ExecutionSid string, params *ListExecutionStepParams) ([]StudioV1ExecutionStep, error) { + response, errors := c.StreamExecutionStepWithCtx(ctx, FlowSid, ExecutionSid, params) records := make([]StudioV1ExecutionStep, 0) for record := range response { @@ -119,6 +135,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.StreamExecutionStepWithCtx(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) StreamExecutionStepWithCtx(ctx context.Context, FlowSid string, ExecutionSid string, params *ListExecutionStepParams) (chan StudioV1ExecutionStep, chan error) { if params == nil { params = &ListExecutionStepParams{} } @@ -127,19 +148,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.PageExecutionStepWithCtx(ctx, FlowSid, ExecutionSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamExecutionStep(response, params, recordChannel, errorChannel) + go c.streamExecutionStep(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) streamExecutionStep(ctx context.Context, response *ListExecutionStepResponse, params *ListExecutionStepParams, recordChannel chan StudioV1ExecutionStep, errorChannel chan error) { curRecord := 1 for response != nil { @@ -154,7 +175,7 @@ func (c *ApiService) streamExecutionStep(response *ListExecutionStepResponse, pa } } - record, err := client.GetNext(c.baseURL, response, c.getNextListExecutionStepResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListExecutionStepResponse) if err != nil { errorChannel <- err break @@ -169,11 +190,11 @@ func (c *ApiService) streamExecutionStep(response *ListExecutionStepResponse, pa close(errorChannel) } -func (c *ApiService) getNextListExecutionStepResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListExecutionStepResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 338594176..f4e5d9ba9 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,11 @@ import ( // Retrieve the context for an Execution Step. func (c *ApiService) FetchExecutionStepContext(FlowSid string, ExecutionSid string, StepSid string) (*StudioV1ExecutionStepContext, error) { + return c.FetchExecutionStepContextWithCtx(context.TODO(), FlowSid, ExecutionSid, StepSid) +} + +// Retrieve the context for an Execution Step. +func (c *ApiService) FetchExecutionStepContextWithCtx(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) @@ -30,7 +36,7 @@ func (c *ApiService) FetchExecutionStepContext(FlowSid string, ExecutionSid stri data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(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 e6af2fdce..7125eb5f1 100644 --- a/rest/studio/v2/api_service.go +++ b/rest/studio/v2/api_service.go @@ -20,10 +20,14 @@ import ( type ApiService struct { baseURL string - requestHandler *twilio.RequestHandler + requestHandler *twilio.RequestHandlerWithCtx } func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { + return NewApiServiceWithCtx(twilio.UpgradeRequestHandler(requestHandler)) +} + +func NewApiServiceWithCtx(requestHandler *twilio.RequestHandlerWithCtx) *ApiService { return &ApiService{ requestHandler: requestHandler, baseURL: "https://studio.twilio.com", @@ -33,3 +37,7 @@ func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { func NewApiServiceWithClient(client twilio.BaseClient) *ApiService { return NewApiService(twilio.NewRequestHandler(client)) } + +func NewApiServiceWithClientWithCtx(client twilio.BaseClientWithCtx) *ApiService { + return NewApiServiceWithCtx(twilio.NewRequestHandlerWithCtx(client)) +} diff --git a/rest/studio/v2/flows.go b/rest/studio/v2/flows.go index faa9f4dd3..a79bee512 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,11 @@ func (params *CreateFlowParams) SetCommitMessage(CommitMessage string) *CreateFl // Create a Flow. func (c *ApiService) CreateFlow(params *CreateFlowParams) (*StudioV2Flow, error) { + return c.CreateFlowWithCtx(context.TODO(), params) +} + +// Create a Flow. +func (c *ApiService) CreateFlowWithCtx(ctx context.Context, params *CreateFlowParams) (*StudioV2Flow, error) { path := "/v2/Flows" data := url.Values{} @@ -78,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -95,13 +101,18 @@ func (c *ApiService) CreateFlow(params *CreateFlowParams) (*StudioV2Flow, error) // Delete a specific Flow. func (c *ApiService) DeleteFlow(Sid string) error { + return c.DeleteFlowWithCtx(context.TODO(), Sid) +} + +// Delete a specific Flow. +func (c *ApiService) DeleteFlowWithCtx(ctx context.Context, Sid string) error { path := "/v2/Flows/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -113,13 +124,18 @@ func (c *ApiService) DeleteFlow(Sid string) error { // Retrieve a specific Flow. func (c *ApiService) FetchFlow(Sid string) (*StudioV2Flow, error) { + return c.FetchFlowWithCtx(context.TODO(), Sid) +} + +// Retrieve a specific Flow. +func (c *ApiService) FetchFlowWithCtx(ctx context.Context, Sid string) (*StudioV2Flow, error) { path := "/v2/Flows/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -153,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.PageFlowWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Flow records from the API. Request is executed immediately. +func (c *ApiService) PageFlowWithCtx(ctx context.Context, params *ListFlowParams, pageToken, pageNumber string) (*ListFlowResponse, error) { path := "/v2/Flows" data := url.Values{} @@ -169,7 +190,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -186,7 +207,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.ListFlowWithCtx(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) ListFlowWithCtx(ctx context.Context, params *ListFlowParams) ([]StudioV2Flow, error) { + response, errors := c.StreamFlowWithCtx(ctx, params) records := make([]StudioV2Flow, 0) for record := range response { @@ -202,6 +228,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.StreamFlowWithCtx(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) StreamFlowWithCtx(ctx context.Context, params *ListFlowParams) (chan StudioV2Flow, chan error) { if params == nil { params = &ListFlowParams{} } @@ -210,19 +241,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.PageFlowWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamFlow(response, params, recordChannel, errorChannel) + go c.streamFlow(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) streamFlow(ctx context.Context, response *ListFlowResponse, params *ListFlowParams, recordChannel chan StudioV2Flow, errorChannel chan error) { curRecord := 1 for response != nil { @@ -237,7 +268,7 @@ func (c *ApiService) streamFlow(response *ListFlowResponse, params *ListFlowPara } } - record, err := client.GetNext(c.baseURL, response, c.getNextListFlowResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListFlowResponse) if err != nil { errorChannel <- err break @@ -252,11 +283,11 @@ func (c *ApiService) streamFlow(response *ListFlowResponse, params *ListFlowPara close(errorChannel) } -func (c *ApiService) getNextListFlowResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListFlowResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -301,6 +332,11 @@ func (params *UpdateFlowParams) SetCommitMessage(CommitMessage string) *UpdateFl // Update a Flow. func (c *ApiService) UpdateFlow(Sid string, params *UpdateFlowParams) (*StudioV2Flow, error) { + return c.UpdateFlowWithCtx(context.TODO(), Sid, params) +} + +// Update a Flow. +func (c *ApiService) UpdateFlowWithCtx(ctx context.Context, Sid string, params *UpdateFlowParams) (*StudioV2Flow, error) { path := "/v2/Flows/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -326,7 +362,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.Post(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 b1a867453..9bfd84d6d 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,11 @@ func (params *CreateExecutionParams) SetParameters(Parameters interface{}) *Crea // Triggers a new Execution for the Flow func (c *ApiService) CreateExecution(FlowSid string, params *CreateExecutionParams) (*StudioV2Execution, error) { + return c.CreateExecutionWithCtx(context.TODO(), FlowSid, params) +} + +// Triggers a new Execution for the Flow +func (c *ApiService) CreateExecutionWithCtx(ctx context.Context, FlowSid string, params *CreateExecutionParams) (*StudioV2Execution, error) { path := "/v2/Flows/{FlowSid}/Executions" path = strings.Replace(path, "{"+"FlowSid"+"}", FlowSid, -1) @@ -71,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -88,6 +94,11 @@ 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.DeleteExecutionWithCtx(context.TODO(), FlowSid, Sid) +} + +// Delete the Execution and all Steps relating to it. +func (c *ApiService) DeleteExecutionWithCtx(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) @@ -95,7 +106,7 @@ func (c *ApiService) DeleteExecution(FlowSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -107,6 +118,11 @@ func (c *ApiService) DeleteExecution(FlowSid string, Sid string) error { // Retrieve an Execution func (c *ApiService) FetchExecution(FlowSid string, Sid string) (*StudioV2Execution, error) { + return c.FetchExecutionWithCtx(context.TODO(), FlowSid, Sid) +} + +// Retrieve an Execution +func (c *ApiService) FetchExecutionWithCtx(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) @@ -114,7 +130,7 @@ func (c *ApiService) FetchExecution(FlowSid string, Sid string) (*StudioV2Execut data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -160,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.PageExecutionWithCtx(context.TODO(), FlowSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Execution records from the API. Request is executed immediately. +func (c *ApiService) PageExecutionWithCtx(ctx context.Context, FlowSid string, params *ListExecutionParams, pageToken, pageNumber string) (*ListExecutionResponse, error) { path := "/v2/Flows/{FlowSid}/Executions" path = strings.Replace(path, "{"+"FlowSid"+"}", FlowSid, -1) @@ -184,7 +205,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -201,7 +222,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.ListExecutionWithCtx(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) ListExecutionWithCtx(ctx context.Context, FlowSid string, params *ListExecutionParams) ([]StudioV2Execution, error) { + response, errors := c.StreamExecutionWithCtx(ctx, FlowSid, params) records := make([]StudioV2Execution, 0) for record := range response { @@ -217,6 +243,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.StreamExecutionWithCtx(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) StreamExecutionWithCtx(ctx context.Context, FlowSid string, params *ListExecutionParams) (chan StudioV2Execution, chan error) { if params == nil { params = &ListExecutionParams{} } @@ -225,19 +256,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.PageExecutionWithCtx(ctx, FlowSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamExecution(response, params, recordChannel, errorChannel) + go c.streamExecution(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) streamExecution(ctx context.Context, response *ListExecutionResponse, params *ListExecutionParams, recordChannel chan StudioV2Execution, errorChannel chan error) { curRecord := 1 for response != nil { @@ -252,7 +283,7 @@ func (c *ApiService) streamExecution(response *ListExecutionResponse, params *Li } } - record, err := client.GetNext(c.baseURL, response, c.getNextListExecutionResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListExecutionResponse) if err != nil { errorChannel <- err break @@ -267,11 +298,11 @@ func (c *ApiService) streamExecution(response *ListExecutionResponse, params *Li close(errorChannel) } -func (c *ApiService) getNextListExecutionResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListExecutionResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -298,6 +329,11 @@ 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.UpdateExecutionWithCtx(context.TODO(), FlowSid, Sid, params) +} + +// Update the status of an Execution to `ended`. +func (c *ApiService) UpdateExecutionWithCtx(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) @@ -309,7 +345,7 @@ func (c *ApiService) UpdateExecution(FlowSid string, Sid string, params *UpdateE data.Set("Status", *params.Status) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 63082ea22..855310fd7 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,11 @@ import ( // Retrieve the most recent context for an Execution. func (c *ApiService) FetchExecutionContext(FlowSid string, ExecutionSid string) (*StudioV2ExecutionContext, error) { + return c.FetchExecutionContextWithCtx(context.TODO(), FlowSid, ExecutionSid) +} + +// Retrieve the most recent context for an Execution. +func (c *ApiService) FetchExecutionContextWithCtx(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) @@ -29,7 +35,7 @@ func (c *ApiService) FetchExecutionContext(FlowSid string, ExecutionSid string) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(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 f614e28c0..58821d027 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,11 @@ import ( // Retrieve a Step. func (c *ApiService) FetchExecutionStep(FlowSid string, ExecutionSid string, Sid string) (*StudioV2ExecutionStep, error) { + return c.FetchExecutionStepWithCtx(context.TODO(), FlowSid, ExecutionSid, Sid) +} + +// Retrieve a Step. +func (c *ApiService) FetchExecutionStepWithCtx(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) @@ -33,7 +39,7 @@ func (c *ApiService) FetchExecutionStep(FlowSid string, ExecutionSid string, Sid data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -67,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.PageExecutionStepWithCtx(context.TODO(), FlowSid, ExecutionSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ExecutionStep records from the API. Request is executed immediately. +func (c *ApiService) PageExecutionStepWithCtx(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) @@ -86,7 +97,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -103,7 +114,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.ListExecutionStepWithCtx(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) ListExecutionStepWithCtx(ctx context.Context, FlowSid string, ExecutionSid string, params *ListExecutionStepParams) ([]StudioV2ExecutionStep, error) { + response, errors := c.StreamExecutionStepWithCtx(ctx, FlowSid, ExecutionSid, params) records := make([]StudioV2ExecutionStep, 0) for record := range response { @@ -119,6 +135,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.StreamExecutionStepWithCtx(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) StreamExecutionStepWithCtx(ctx context.Context, FlowSid string, ExecutionSid string, params *ListExecutionStepParams) (chan StudioV2ExecutionStep, chan error) { if params == nil { params = &ListExecutionStepParams{} } @@ -127,19 +148,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.PageExecutionStepWithCtx(ctx, FlowSid, ExecutionSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamExecutionStep(response, params, recordChannel, errorChannel) + go c.streamExecutionStep(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) streamExecutionStep(ctx context.Context, response *ListExecutionStepResponse, params *ListExecutionStepParams, recordChannel chan StudioV2ExecutionStep, errorChannel chan error) { curRecord := 1 for response != nil { @@ -154,7 +175,7 @@ func (c *ApiService) streamExecutionStep(response *ListExecutionStepResponse, pa } } - record, err := client.GetNext(c.baseURL, response, c.getNextListExecutionStepResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListExecutionStepResponse) if err != nil { errorChannel <- err break @@ -169,11 +190,11 @@ func (c *ApiService) streamExecutionStep(response *ListExecutionStepResponse, pa close(errorChannel) } -func (c *ApiService) getNextListExecutionStepResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListExecutionStepResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 c1cf4ecfd..ddc1b9ff2 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,11 @@ import ( // Retrieve the context for an Execution Step. func (c *ApiService) FetchExecutionStepContext(FlowSid string, ExecutionSid string, StepSid string) (*StudioV2ExecutionStepContext, error) { + return c.FetchExecutionStepContextWithCtx(context.TODO(), FlowSid, ExecutionSid, StepSid) +} + +// Retrieve the context for an Execution Step. +func (c *ApiService) FetchExecutionStepContextWithCtx(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) @@ -30,7 +36,7 @@ func (c *ApiService) FetchExecutionStepContext(FlowSid string, ExecutionSid stri data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(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 5d04f5e41..016ea80d6 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,11 @@ import ( // Retrieve a specific Flow revision. func (c *ApiService) FetchFlowRevision(Sid string, Revision string) (*StudioV2FlowRevision, error) { + return c.FetchFlowRevisionWithCtx(context.TODO(), Sid, Revision) +} + +// Retrieve a specific Flow revision. +func (c *ApiService) FetchFlowRevisionWithCtx(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) @@ -32,7 +38,7 @@ func (c *ApiService) FetchFlowRevision(Sid string, Revision string) (*StudioV2Fl data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -66,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.PageFlowRevisionWithCtx(context.TODO(), Sid, params, pageToken, pageNumber) +} + +// Retrieve a single page of FlowRevision records from the API. Request is executed immediately. +func (c *ApiService) PageFlowRevisionWithCtx(ctx context.Context, Sid string, params *ListFlowRevisionParams, pageToken, pageNumber string) (*ListFlowRevisionResponse, error) { path := "/v2/Flows/{Sid}/Revisions" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -84,7 +95,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -101,7 +112,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.ListFlowRevisionWithCtx(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) ListFlowRevisionWithCtx(ctx context.Context, Sid string, params *ListFlowRevisionParams) ([]StudioV2FlowRevision, error) { + response, errors := c.StreamFlowRevisionWithCtx(ctx, Sid, params) records := make([]StudioV2FlowRevision, 0) for record := range response { @@ -117,6 +133,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.StreamFlowRevisionWithCtx(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) StreamFlowRevisionWithCtx(ctx context.Context, Sid string, params *ListFlowRevisionParams) (chan StudioV2FlowRevision, chan error) { if params == nil { params = &ListFlowRevisionParams{} } @@ -125,19 +146,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.PageFlowRevisionWithCtx(ctx, Sid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamFlowRevision(response, params, recordChannel, errorChannel) + go c.streamFlowRevision(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) streamFlowRevision(ctx context.Context, response *ListFlowRevisionResponse, params *ListFlowRevisionParams, recordChannel chan StudioV2FlowRevision, errorChannel chan error) { curRecord := 1 for response != nil { @@ -152,7 +173,7 @@ func (c *ApiService) streamFlowRevision(response *ListFlowRevisionResponse, para } } - record, err := client.GetNext(c.baseURL, response, c.getNextListFlowRevisionResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListFlowRevisionResponse) if err != nil { errorChannel <- err break @@ -167,11 +188,11 @@ func (c *ApiService) streamFlowRevision(response *ListFlowRevisionResponse, para close(errorChannel) } -func (c *ApiService) getNextListFlowRevisionResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListFlowRevisionResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 cab908acf..71bebd2ac 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,13 +23,18 @@ import ( // Fetch flow test users func (c *ApiService) FetchTestUser(Sid string) (*StudioV2TestUser, error) { + return c.FetchTestUserWithCtx(context.TODO(), Sid) +} + +// Fetch flow test users +func (c *ApiService) FetchTestUserWithCtx(ctx context.Context, Sid string) (*StudioV2TestUser, error) { path := "/v2/Flows/{Sid}/TestUsers" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -56,6 +62,11 @@ func (params *UpdateTestUserParams) SetTestUsers(TestUsers []string) *UpdateTest // Update flow test users func (c *ApiService) UpdateTestUser(Sid string, params *UpdateTestUserParams) (*StudioV2TestUser, error) { + return c.UpdateTestUserWithCtx(context.TODO(), Sid, params) +} + +// Update flow test users +func (c *ApiService) UpdateTestUserWithCtx(ctx context.Context, Sid string, params *UpdateTestUserParams) (*StudioV2TestUser, error) { path := "/v2/Flows/{Sid}/TestUsers" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -68,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.Post(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 b589afdc4..0a3736da9 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" "net/url" ) @@ -50,6 +51,11 @@ func (params *UpdateFlowValidateParams) SetCommitMessage(CommitMessage string) * // Validate flow JSON definition func (c *ApiService) UpdateFlowValidate(params *UpdateFlowValidateParams) (*StudioV2FlowValidate, error) { + return c.UpdateFlowValidateWithCtx(context.TODO(), params) +} + +// Validate flow JSON definition +func (c *ApiService) UpdateFlowValidateWithCtx(ctx context.Context, params *UpdateFlowValidateParams) (*StudioV2FlowValidate, error) { path := "/v2/Flows/Validate" data := url.Values{} @@ -74,7 +80,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.Post(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 1f79d973d..98ec0c516 100644 --- a/rest/supersim/v1/api_service.go +++ b/rest/supersim/v1/api_service.go @@ -20,10 +20,14 @@ import ( type ApiService struct { baseURL string - requestHandler *twilio.RequestHandler + requestHandler *twilio.RequestHandlerWithCtx } func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { + return NewApiServiceWithCtx(twilio.UpgradeRequestHandler(requestHandler)) +} + +func NewApiServiceWithCtx(requestHandler *twilio.RequestHandlerWithCtx) *ApiService { return &ApiService{ requestHandler: requestHandler, baseURL: "https://supersim.twilio.com", @@ -33,3 +37,7 @@ func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { func NewApiServiceWithClient(client twilio.BaseClient) *ApiService { return NewApiService(twilio.NewRequestHandler(client)) } + +func NewApiServiceWithClientWithCtx(client twilio.BaseClientWithCtx) *ApiService { + return NewApiServiceWithCtx(twilio.NewRequestHandlerWithCtx(client)) +} diff --git a/rest/supersim/v1/e_sim_profiles.go b/rest/supersim/v1/e_sim_profiles.go index f5940a5e6..c7882365a 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" @@ -48,6 +49,11 @@ func (params *CreateEsimProfileParams) SetEid(Eid string) *CreateEsimProfilePara // Order an eSIM Profile. func (c *ApiService) CreateEsimProfile(params *CreateEsimProfileParams) (*SupersimV1EsimProfile, error) { + return c.CreateEsimProfileWithCtx(context.TODO(), params) +} + +// Order an eSIM Profile. +func (c *ApiService) CreateEsimProfileWithCtx(ctx context.Context, params *CreateEsimProfileParams) (*SupersimV1EsimProfile, error) { path := "/v1/ESimProfiles" data := url.Values{} @@ -63,7 +69,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -80,13 +86,18 @@ func (c *ApiService) CreateEsimProfile(params *CreateEsimProfileParams) (*Supers // Fetch an eSIM Profile. func (c *ApiService) FetchEsimProfile(Sid string) (*SupersimV1EsimProfile, error) { + return c.FetchEsimProfileWithCtx(context.TODO(), Sid) +} + +// Fetch an eSIM Profile. +func (c *ApiService) FetchEsimProfileWithCtx(ctx context.Context, Sid string) (*SupersimV1EsimProfile, error) { path := "/v1/ESimProfiles/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -138,6 +149,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.PageEsimProfileWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of EsimProfile records from the API. Request is executed immediately. +func (c *ApiService) PageEsimProfileWithCtx(ctx context.Context, params *ListEsimProfileParams, pageToken, pageNumber string) (*ListEsimProfileResponse, error) { path := "/v1/ESimProfiles" data := url.Values{} @@ -163,7 +179,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -180,7 +196,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.ListEsimProfileWithCtx(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) ListEsimProfileWithCtx(ctx context.Context, params *ListEsimProfileParams) ([]SupersimV1EsimProfile, error) { + response, errors := c.StreamEsimProfileWithCtx(ctx, params) records := make([]SupersimV1EsimProfile, 0) for record := range response { @@ -196,6 +217,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.StreamEsimProfileWithCtx(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) StreamEsimProfileWithCtx(ctx context.Context, params *ListEsimProfileParams) (chan SupersimV1EsimProfile, chan error) { if params == nil { params = &ListEsimProfileParams{} } @@ -204,19 +230,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.PageEsimProfileWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamEsimProfile(response, params, recordChannel, errorChannel) + go c.streamEsimProfile(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) streamEsimProfile(ctx context.Context, response *ListEsimProfileResponse, params *ListEsimProfileParams, recordChannel chan SupersimV1EsimProfile, errorChannel chan error) { curRecord := 1 for response != nil { @@ -231,7 +257,7 @@ func (c *ApiService) streamEsimProfile(response *ListEsimProfileResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListEsimProfileResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListEsimProfileResponse) if err != nil { errorChannel <- err break @@ -246,11 +272,11 @@ func (c *ApiService) streamEsimProfile(response *ListEsimProfileResponse, params close(errorChannel) } -func (c *ApiService) getNextListEsimProfileResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListEsimProfileResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 848aeb7a5..0f61aa7c8 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,11 @@ func (params *CreateFleetParams) SetSmsCommandsMethod(SmsCommandsMethod string) // Create a Fleet func (c *ApiService) CreateFleet(params *CreateFleetParams) (*SupersimV1Fleet, error) { + return c.CreateFleetWithCtx(context.TODO(), params) +} + +// Create a Fleet +func (c *ApiService) CreateFleetWithCtx(ctx context.Context, params *CreateFleetParams) (*SupersimV1Fleet, error) { path := "/v1/Fleets" data := url.Values{} @@ -117,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -134,13 +140,18 @@ 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.FetchFleetWithCtx(context.TODO(), Sid) +} + +// Fetch a Fleet instance from your account. +func (c *ApiService) FetchFleetWithCtx(ctx context.Context, Sid string) (*SupersimV1Fleet, error) { path := "/v1/Fleets/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -180,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.PageFleetWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Fleet records from the API. Request is executed immediately. +func (c *ApiService) PageFleetWithCtx(ctx context.Context, params *ListFleetParams, pageToken, pageNumber string) (*ListFleetResponse, error) { path := "/v1/Fleets" data := url.Values{} @@ -199,7 +215,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -216,7 +232,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.ListFleetWithCtx(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) ListFleetWithCtx(ctx context.Context, params *ListFleetParams) ([]SupersimV1Fleet, error) { + response, errors := c.StreamFleetWithCtx(ctx, params) records := make([]SupersimV1Fleet, 0) for record := range response { @@ -232,6 +253,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.StreamFleetWithCtx(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) StreamFleetWithCtx(ctx context.Context, params *ListFleetParams) (chan SupersimV1Fleet, chan error) { if params == nil { params = &ListFleetParams{} } @@ -240,19 +266,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.PageFleetWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamFleet(response, params, recordChannel, errorChannel) + go c.streamFleet(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) streamFleet(ctx context.Context, response *ListFleetResponse, params *ListFleetParams, recordChannel chan SupersimV1Fleet, errorChannel chan error) { curRecord := 1 for response != nil { @@ -267,7 +293,7 @@ func (c *ApiService) streamFleet(response *ListFleetResponse, params *ListFleetP } } - record, err := client.GetNext(c.baseURL, response, c.getNextListFleetResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListFleetResponse) if err != nil { errorChannel <- err break @@ -282,11 +308,11 @@ func (c *ApiService) streamFleet(response *ListFleetResponse, params *ListFleetP close(errorChannel) } -func (c *ApiService) getNextListFleetResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListFleetResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -349,6 +375,11 @@ 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.UpdateFleetWithCtx(context.TODO(), Sid, params) +} + +// Updates the given properties of a Super SIM Fleet instance from your account. +func (c *ApiService) UpdateFleetWithCtx(ctx context.Context, Sid string, params *UpdateFleetParams) (*SupersimV1Fleet, error) { path := "/v1/Fleets/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -377,7 +408,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.Post(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 01fe9c15e..4aad2031d 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,11 @@ 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.CreateIpCommandWithCtx(context.TODO(), params) +} + +// Send an IP Command to a Super SIM. +func (c *ApiService) CreateIpCommandWithCtx(ctx context.Context, params *CreateIpCommandParams) (*SupersimV1IpCommand, error) { path := "/v1/IpCommands" data := url.Values{} @@ -90,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -107,13 +113,18 @@ func (c *ApiService) CreateIpCommand(params *CreateIpCommandParams) (*SupersimV1 // Fetch IP Command instance from your account. func (c *ApiService) FetchIpCommand(Sid string) (*SupersimV1IpCommand, error) { + return c.FetchIpCommandWithCtx(context.TODO(), Sid) +} + +// Fetch IP Command instance from your account. +func (c *ApiService) FetchIpCommandWithCtx(ctx context.Context, Sid string) (*SupersimV1IpCommand, error) { path := "/v1/IpCommands/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -171,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.PageIpCommandWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of IpCommand records from the API. Request is executed immediately. +func (c *ApiService) PageIpCommandWithCtx(ctx context.Context, params *ListIpCommandParams, pageToken, pageNumber string) (*ListIpCommandResponse, error) { path := "/v1/IpCommands" data := url.Values{} @@ -199,7 +215,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -216,7 +232,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.ListIpCommandWithCtx(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) ListIpCommandWithCtx(ctx context.Context, params *ListIpCommandParams) ([]SupersimV1IpCommand, error) { + response, errors := c.StreamIpCommandWithCtx(ctx, params) records := make([]SupersimV1IpCommand, 0) for record := range response { @@ -232,6 +253,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.StreamIpCommandWithCtx(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) StreamIpCommandWithCtx(ctx context.Context, params *ListIpCommandParams) (chan SupersimV1IpCommand, chan error) { if params == nil { params = &ListIpCommandParams{} } @@ -240,19 +266,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.PageIpCommandWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamIpCommand(response, params, recordChannel, errorChannel) + go c.streamIpCommand(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) streamIpCommand(ctx context.Context, response *ListIpCommandResponse, params *ListIpCommandParams, recordChannel chan SupersimV1IpCommand, errorChannel chan error) { curRecord := 1 for response != nil { @@ -267,7 +293,7 @@ func (c *ApiService) streamIpCommand(response *ListIpCommandResponse, params *Li } } - record, err := client.GetNext(c.baseURL, response, c.getNextListIpCommandResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListIpCommandResponse) if err != nil { errorChannel <- err break @@ -282,11 +308,11 @@ func (c *ApiService) streamIpCommand(response *ListIpCommandResponse, params *Li close(errorChannel) } -func (c *ApiService) getNextListIpCommandResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListIpCommandResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 c82957dce..9039bd0ee 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,11 @@ func (params *CreateNetworkAccessProfileParams) SetNetworks(Networks []string) * // Create a new Network Access Profile func (c *ApiService) CreateNetworkAccessProfile(params *CreateNetworkAccessProfileParams) (*SupersimV1NetworkAccessProfile, error) { + return c.CreateNetworkAccessProfileWithCtx(context.TODO(), params) +} + +// Create a new Network Access Profile +func (c *ApiService) CreateNetworkAccessProfileWithCtx(ctx context.Context, params *CreateNetworkAccessProfileParams) (*SupersimV1NetworkAccessProfile, error) { path := "/v1/NetworkAccessProfiles" data := url.Values{} @@ -56,7 +62,7 @@ func (c *ApiService) CreateNetworkAccessProfile(params *CreateNetworkAccessProfi } } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -73,13 +79,18 @@ 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.FetchNetworkAccessProfileWithCtx(context.TODO(), Sid) +} + +// Fetch a Network Access Profile instance from your account. +func (c *ApiService) FetchNetworkAccessProfileWithCtx(ctx context.Context, Sid string) (*SupersimV1NetworkAccessProfile, error) { path := "/v1/NetworkAccessProfiles/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -113,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.PageNetworkAccessProfileWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of NetworkAccessProfile records from the API. Request is executed immediately. +func (c *ApiService) PageNetworkAccessProfileWithCtx(ctx context.Context, params *ListNetworkAccessProfileParams, pageToken, pageNumber string) (*ListNetworkAccessProfileResponse, error) { path := "/v1/NetworkAccessProfiles" data := url.Values{} @@ -129,7 +145,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -146,7 +162,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.ListNetworkAccessProfileWithCtx(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) ListNetworkAccessProfileWithCtx(ctx context.Context, params *ListNetworkAccessProfileParams) ([]SupersimV1NetworkAccessProfile, error) { + response, errors := c.StreamNetworkAccessProfileWithCtx(ctx, params) records := make([]SupersimV1NetworkAccessProfile, 0) for record := range response { @@ -162,6 +183,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.StreamNetworkAccessProfileWithCtx(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) StreamNetworkAccessProfileWithCtx(ctx context.Context, params *ListNetworkAccessProfileParams) (chan SupersimV1NetworkAccessProfile, chan error) { if params == nil { params = &ListNetworkAccessProfileParams{} } @@ -170,19 +196,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.PageNetworkAccessProfileWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamNetworkAccessProfile(response, params, recordChannel, errorChannel) + go c.streamNetworkAccessProfile(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) streamNetworkAccessProfile(ctx context.Context, response *ListNetworkAccessProfileResponse, params *ListNetworkAccessProfileParams, recordChannel chan SupersimV1NetworkAccessProfile, errorChannel chan error) { curRecord := 1 for response != nil { @@ -197,7 +223,7 @@ func (c *ApiService) streamNetworkAccessProfile(response *ListNetworkAccessProfi } } - record, err := client.GetNext(c.baseURL, response, c.getNextListNetworkAccessProfileResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListNetworkAccessProfileResponse) if err != nil { errorChannel <- err break @@ -212,11 +238,11 @@ func (c *ApiService) streamNetworkAccessProfile(response *ListNetworkAccessProfi close(errorChannel) } -func (c *ApiService) getNextListNetworkAccessProfileResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListNetworkAccessProfileResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -243,6 +269,11 @@ 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.UpdateNetworkAccessProfileWithCtx(context.TODO(), Sid, params) +} + +// Updates the given properties of a Network Access Profile in your account. +func (c *ApiService) UpdateNetworkAccessProfileWithCtx(ctx context.Context, Sid string, params *UpdateNetworkAccessProfileParams) (*SupersimV1NetworkAccessProfile, error) { path := "/v1/NetworkAccessProfiles/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -253,7 +284,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.Post(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 f4c06d639..94938b83d 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,11 @@ 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.CreateNetworkAccessProfileNetworkWithCtx(context.TODO(), NetworkAccessProfileSid, params) +} + +// Add a Network resource to the Network Access Profile resource. +func (c *ApiService) CreateNetworkAccessProfileNetworkWithCtx(ctx context.Context, NetworkAccessProfileSid string, params *CreateNetworkAccessProfileNetworkParams) (*SupersimV1NetworkAccessProfileNetwork, error) { path := "/v1/NetworkAccessProfiles/{NetworkAccessProfileSid}/Networks" path = strings.Replace(path, "{"+"NetworkAccessProfileSid"+"}", NetworkAccessProfileSid, -1) @@ -46,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -63,6 +69,11 @@ 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.DeleteNetworkAccessProfileNetworkWithCtx(context.TODO(), NetworkAccessProfileSid, Sid) +} + +// Remove a Network resource from the Network Access Profile resource's. +func (c *ApiService) DeleteNetworkAccessProfileNetworkWithCtx(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) @@ -70,7 +81,7 @@ func (c *ApiService) DeleteNetworkAccessProfileNetwork(NetworkAccessProfileSid s data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -82,6 +93,11 @@ 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.FetchNetworkAccessProfileNetworkWithCtx(context.TODO(), NetworkAccessProfileSid, Sid) +} + +// Fetch a Network Access Profile resource's Network resource. +func (c *ApiService) FetchNetworkAccessProfileNetworkWithCtx(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) @@ -89,7 +105,7 @@ func (c *ApiService) FetchNetworkAccessProfileNetwork(NetworkAccessProfileSid st data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -123,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.PageNetworkAccessProfileNetworkWithCtx(context.TODO(), NetworkAccessProfileSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of NetworkAccessProfileNetwork records from the API. Request is executed immediately. +func (c *ApiService) PageNetworkAccessProfileNetworkWithCtx(ctx context.Context, NetworkAccessProfileSid string, params *ListNetworkAccessProfileNetworkParams, pageToken, pageNumber string) (*ListNetworkAccessProfileNetworkResponse, error) { path := "/v1/NetworkAccessProfiles/{NetworkAccessProfileSid}/Networks" path = strings.Replace(path, "{"+"NetworkAccessProfileSid"+"}", NetworkAccessProfileSid, -1) @@ -141,7 +162,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -158,7 +179,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.ListNetworkAccessProfileNetworkWithCtx(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) ListNetworkAccessProfileNetworkWithCtx(ctx context.Context, NetworkAccessProfileSid string, params *ListNetworkAccessProfileNetworkParams) ([]SupersimV1NetworkAccessProfileNetwork, error) { + response, errors := c.StreamNetworkAccessProfileNetworkWithCtx(ctx, NetworkAccessProfileSid, params) records := make([]SupersimV1NetworkAccessProfileNetwork, 0) for record := range response { @@ -174,6 +200,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.StreamNetworkAccessProfileNetworkWithCtx(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) StreamNetworkAccessProfileNetworkWithCtx(ctx context.Context, NetworkAccessProfileSid string, params *ListNetworkAccessProfileNetworkParams) (chan SupersimV1NetworkAccessProfileNetwork, chan error) { if params == nil { params = &ListNetworkAccessProfileNetworkParams{} } @@ -182,19 +213,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.PageNetworkAccessProfileNetworkWithCtx(ctx, NetworkAccessProfileSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamNetworkAccessProfileNetwork(response, params, recordChannel, errorChannel) + go c.streamNetworkAccessProfileNetwork(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) streamNetworkAccessProfileNetwork(ctx context.Context, response *ListNetworkAccessProfileNetworkResponse, params *ListNetworkAccessProfileNetworkParams, recordChannel chan SupersimV1NetworkAccessProfileNetwork, errorChannel chan error) { curRecord := 1 for response != nil { @@ -209,7 +240,7 @@ func (c *ApiService) streamNetworkAccessProfileNetwork(response *ListNetworkAcce } } - record, err := client.GetNext(c.baseURL, response, c.getNextListNetworkAccessProfileNetworkResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListNetworkAccessProfileNetworkResponse) if err != nil { errorChannel <- err break @@ -224,11 +255,11 @@ func (c *ApiService) streamNetworkAccessProfileNetwork(response *ListNetworkAcce close(errorChannel) } -func (c *ApiService) getNextListNetworkAccessProfileNetworkResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListNetworkAccessProfileNetworkResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 d49f3300b..c6380b518 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,13 +26,18 @@ import ( // Fetch a Network resource. func (c *ApiService) FetchNetwork(Sid string) (*SupersimV1Network, error) { + return c.FetchNetworkWithCtx(context.TODO(), Sid) +} + +// Fetch a Network resource. +func (c *ApiService) FetchNetworkWithCtx(ctx context.Context, Sid string) (*SupersimV1Network, error) { path := "/v1/Networks/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -83,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.PageNetworkWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Network records from the API. Request is executed immediately. +func (c *ApiService) PageNetworkWithCtx(ctx context.Context, params *ListNetworkParams, pageToken, pageNumber string) (*ListNetworkResponse, error) { path := "/v1/Networks" data := url.Values{} @@ -108,7 +119,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -125,7 +136,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.ListNetworkWithCtx(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) ListNetworkWithCtx(ctx context.Context, params *ListNetworkParams) ([]SupersimV1Network, error) { + response, errors := c.StreamNetworkWithCtx(ctx, params) records := make([]SupersimV1Network, 0) for record := range response { @@ -141,6 +157,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.StreamNetworkWithCtx(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) StreamNetworkWithCtx(ctx context.Context, params *ListNetworkParams) (chan SupersimV1Network, chan error) { if params == nil { params = &ListNetworkParams{} } @@ -149,19 +170,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.PageNetworkWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamNetwork(response, params, recordChannel, errorChannel) + go c.streamNetwork(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) streamNetwork(ctx context.Context, response *ListNetworkResponse, params *ListNetworkParams, recordChannel chan SupersimV1Network, errorChannel chan error) { curRecord := 1 for response != nil { @@ -176,7 +197,7 @@ func (c *ApiService) streamNetwork(response *ListNetworkResponse, params *ListNe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListNetworkResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListNetworkResponse) if err != nil { errorChannel <- err break @@ -191,11 +212,11 @@ func (c *ApiService) streamNetwork(response *ListNetworkResponse, params *ListNe close(errorChannel) } -func (c *ApiService) getNextListNetworkResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListNetworkResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 9fa7df013..b13530ad5 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" @@ -47,6 +48,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.PageSettingsUpdateWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of SettingsUpdate records from the API. Request is executed immediately. +func (c *ApiService) PageSettingsUpdateWithCtx(ctx context.Context, params *ListSettingsUpdateParams, pageToken, pageNumber string) (*ListSettingsUpdateResponse, error) { path := "/v1/SettingsUpdates" data := url.Values{} @@ -66,7 +72,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -83,7 +89,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.ListSettingsUpdateWithCtx(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) ListSettingsUpdateWithCtx(ctx context.Context, params *ListSettingsUpdateParams) ([]SupersimV1SettingsUpdate, error) { + response, errors := c.StreamSettingsUpdateWithCtx(ctx, params) records := make([]SupersimV1SettingsUpdate, 0) for record := range response { @@ -99,6 +110,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.StreamSettingsUpdateWithCtx(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) StreamSettingsUpdateWithCtx(ctx context.Context, params *ListSettingsUpdateParams) (chan SupersimV1SettingsUpdate, chan error) { if params == nil { params = &ListSettingsUpdateParams{} } @@ -107,19 +123,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.PageSettingsUpdateWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSettingsUpdate(response, params, recordChannel, errorChannel) + go c.streamSettingsUpdate(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) streamSettingsUpdate(ctx context.Context, response *ListSettingsUpdateResponse, params *ListSettingsUpdateParams, recordChannel chan SupersimV1SettingsUpdate, errorChannel chan error) { curRecord := 1 for response != nil { @@ -134,7 +150,7 @@ func (c *ApiService) streamSettingsUpdate(response *ListSettingsUpdateResponse, } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSettingsUpdateResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListSettingsUpdateResponse) if err != nil { errorChannel <- err break @@ -149,11 +165,11 @@ func (c *ApiService) streamSettingsUpdate(response *ListSettingsUpdateResponse, close(errorChannel) } -func (c *ApiService) getNextListSettingsUpdateResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSettingsUpdateResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 c988a08e0..7e8692bfd 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,11 @@ func (params *CreateSimParams) SetRegistrationCode(RegistrationCode string) *Cre // Register a Super SIM to your Account func (c *ApiService) CreateSim(params *CreateSimParams) (*SupersimV1Sim, error) { + return c.CreateSimWithCtx(context.TODO(), params) +} + +// Register a Super SIM to your Account +func (c *ApiService) CreateSimWithCtx(ctx context.Context, params *CreateSimParams) (*SupersimV1Sim, error) { path := "/v1/Sims" data := url.Values{} @@ -54,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -71,13 +77,18 @@ 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.FetchSimWithCtx(context.TODO(), Sid) +} + +// Fetch a Super SIM instance from your account. +func (c *ApiService) FetchSimWithCtx(ctx context.Context, Sid string) (*SupersimV1Sim, error) { path := "/v1/Sims/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -129,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.PageSimWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Sim records from the API. Request is executed immediately. +func (c *ApiService) PageSimWithCtx(ctx context.Context, params *ListSimParams, pageToken, pageNumber string) (*ListSimResponse, error) { path := "/v1/Sims" data := url.Values{} @@ -154,7 +170,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -171,7 +187,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.ListSimWithCtx(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) ListSimWithCtx(ctx context.Context, params *ListSimParams) ([]SupersimV1Sim, error) { + response, errors := c.StreamSimWithCtx(ctx, params) records := make([]SupersimV1Sim, 0) for record := range response { @@ -187,6 +208,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.StreamSimWithCtx(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) StreamSimWithCtx(ctx context.Context, params *ListSimParams) (chan SupersimV1Sim, chan error) { if params == nil { params = &ListSimParams{} } @@ -195,19 +221,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.PageSimWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSim(response, params, recordChannel, errorChannel) + go c.streamSim(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) streamSim(ctx context.Context, response *ListSimResponse, params *ListSimParams, recordChannel chan SupersimV1Sim, errorChannel chan error) { curRecord := 1 for response != nil { @@ -222,7 +248,7 @@ func (c *ApiService) streamSim(response *ListSimResponse, params *ListSimParams, } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSimResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListSimResponse) if err != nil { errorChannel <- err break @@ -237,11 +263,11 @@ func (c *ApiService) streamSim(response *ListSimResponse, params *ListSimParams, close(errorChannel) } -func (c *ApiService) getNextListSimResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSimResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -298,6 +324,11 @@ 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.UpdateSimWithCtx(context.TODO(), Sid, params) +} + +// Updates the given properties of a Super SIM instance from your account. +func (c *ApiService) UpdateSimWithCtx(ctx context.Context, Sid string, params *UpdateSimParams) (*SupersimV1Sim, error) { path := "/v1/Sims/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -323,7 +354,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.Post(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 c6b866fed..cc9e89292 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.PageBillingPeriodWithCtx(context.TODO(), SimSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of BillingPeriod records from the API. Request is executed immediately. +func (c *ApiService) PageBillingPeriodWithCtx(ctx context.Context, SimSid string, params *ListBillingPeriodParams, pageToken, pageNumber string) (*ListBillingPeriodResponse, error) { path := "/v1/Sims/{SimSid}/BillingPeriods" path = strings.Replace(path, "{"+"SimSid"+"}", SimSid, -1) @@ -60,7 +66,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -77,7 +83,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.ListBillingPeriodWithCtx(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) ListBillingPeriodWithCtx(ctx context.Context, SimSid string, params *ListBillingPeriodParams) ([]SupersimV1BillingPeriod, error) { + response, errors := c.StreamBillingPeriodWithCtx(ctx, SimSid, params) records := make([]SupersimV1BillingPeriod, 0) for record := range response { @@ -93,6 +104,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.StreamBillingPeriodWithCtx(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) StreamBillingPeriodWithCtx(ctx context.Context, SimSid string, params *ListBillingPeriodParams) (chan SupersimV1BillingPeriod, chan error) { if params == nil { params = &ListBillingPeriodParams{} } @@ -101,19 +117,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.PageBillingPeriodWithCtx(ctx, SimSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamBillingPeriod(response, params, recordChannel, errorChannel) + go c.streamBillingPeriod(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) streamBillingPeriod(ctx context.Context, response *ListBillingPeriodResponse, params *ListBillingPeriodParams, recordChannel chan SupersimV1BillingPeriod, errorChannel chan error) { curRecord := 1 for response != nil { @@ -128,7 +144,7 @@ func (c *ApiService) streamBillingPeriod(response *ListBillingPeriodResponse, pa } } - record, err := client.GetNext(c.baseURL, response, c.getNextListBillingPeriodResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListBillingPeriodResponse) if err != nil { errorChannel <- err break @@ -143,11 +159,11 @@ func (c *ApiService) streamBillingPeriod(response *ListBillingPeriodResponse, pa close(errorChannel) } -func (c *ApiService) getNextListBillingPeriodResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListBillingPeriodResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 f1e73eab5..aebe5132d 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.PageSimIpAddressWithCtx(context.TODO(), SimSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of SimIpAddress records from the API. Request is executed immediately. +func (c *ApiService) PageSimIpAddressWithCtx(ctx context.Context, SimSid string, params *ListSimIpAddressParams, pageToken, pageNumber string) (*ListSimIpAddressResponse, error) { path := "/v1/Sims/{SimSid}/IpAddresses" path = strings.Replace(path, "{"+"SimSid"+"}", SimSid, -1) @@ -60,7 +66,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -77,7 +83,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.ListSimIpAddressWithCtx(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) ListSimIpAddressWithCtx(ctx context.Context, SimSid string, params *ListSimIpAddressParams) ([]SupersimV1SimIpAddress, error) { + response, errors := c.StreamSimIpAddressWithCtx(ctx, SimSid, params) records := make([]SupersimV1SimIpAddress, 0) for record := range response { @@ -93,6 +104,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.StreamSimIpAddressWithCtx(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) StreamSimIpAddressWithCtx(ctx context.Context, SimSid string, params *ListSimIpAddressParams) (chan SupersimV1SimIpAddress, chan error) { if params == nil { params = &ListSimIpAddressParams{} } @@ -101,19 +117,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.PageSimIpAddressWithCtx(ctx, SimSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSimIpAddress(response, params, recordChannel, errorChannel) + go c.streamSimIpAddress(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) streamSimIpAddress(ctx context.Context, response *ListSimIpAddressResponse, params *ListSimIpAddressParams, recordChannel chan SupersimV1SimIpAddress, errorChannel chan error) { curRecord := 1 for response != nil { @@ -128,7 +144,7 @@ func (c *ApiService) streamSimIpAddress(response *ListSimIpAddressResponse, para } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSimIpAddressResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListSimIpAddressResponse) if err != nil { errorChannel <- err break @@ -143,11 +159,11 @@ func (c *ApiService) streamSimIpAddress(response *ListSimIpAddressResponse, para close(errorChannel) } -func (c *ApiService) getNextListSimIpAddressResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSimIpAddressResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 6dd16d009..4a6fd0ebb 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,11 @@ func (params *CreateSmsCommandParams) SetCallbackUrl(CallbackUrl string) *Create // Send SMS Command to a Sim. func (c *ApiService) CreateSmsCommand(params *CreateSmsCommandParams) (*SupersimV1SmsCommand, error) { + return c.CreateSmsCommandWithCtx(context.TODO(), params) +} + +// Send SMS Command to a Sim. +func (c *ApiService) CreateSmsCommandWithCtx(ctx context.Context, params *CreateSmsCommandParams) (*SupersimV1SmsCommand, error) { path := "/v1/SmsCommands" data := url.Values{} @@ -72,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -89,13 +95,18 @@ func (c *ApiService) CreateSmsCommand(params *CreateSmsCommandParams) (*Supersim // Fetch SMS Command instance from your account. func (c *ApiService) FetchSmsCommand(Sid string) (*SupersimV1SmsCommand, error) { + return c.FetchSmsCommandWithCtx(context.TODO(), Sid) +} + +// Fetch SMS Command instance from your account. +func (c *ApiService) FetchSmsCommandWithCtx(ctx context.Context, Sid string) (*SupersimV1SmsCommand, error) { path := "/v1/SmsCommands/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -147,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.PageSmsCommandWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of SmsCommand records from the API. Request is executed immediately. +func (c *ApiService) PageSmsCommandWithCtx(ctx context.Context, params *ListSmsCommandParams, pageToken, pageNumber string) (*ListSmsCommandResponse, error) { path := "/v1/SmsCommands" data := url.Values{} @@ -172,7 +188,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -189,7 +205,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.ListSmsCommandWithCtx(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) ListSmsCommandWithCtx(ctx context.Context, params *ListSmsCommandParams) ([]SupersimV1SmsCommand, error) { + response, errors := c.StreamSmsCommandWithCtx(ctx, params) records := make([]SupersimV1SmsCommand, 0) for record := range response { @@ -205,6 +226,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.StreamSmsCommandWithCtx(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) StreamSmsCommandWithCtx(ctx context.Context, params *ListSmsCommandParams) (chan SupersimV1SmsCommand, chan error) { if params == nil { params = &ListSmsCommandParams{} } @@ -213,19 +239,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.PageSmsCommandWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSmsCommand(response, params, recordChannel, errorChannel) + go c.streamSmsCommand(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) streamSmsCommand(ctx context.Context, response *ListSmsCommandResponse, params *ListSmsCommandParams, recordChannel chan SupersimV1SmsCommand, errorChannel chan error) { curRecord := 1 for response != nil { @@ -240,7 +266,7 @@ func (c *ApiService) streamSmsCommand(response *ListSmsCommandResponse, params * } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSmsCommandResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListSmsCommandResponse) if err != nil { errorChannel <- err break @@ -255,11 +281,11 @@ func (c *ApiService) streamSmsCommand(response *ListSmsCommandResponse, params * close(errorChannel) } -func (c *ApiService) getNextListSmsCommandResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSmsCommandResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 1b31e5bae..f04c333ac 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.PageUsageRecordWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of UsageRecord records from the API. Request is executed immediately. +func (c *ApiService) PageUsageRecordWithCtx(ctx context.Context, params *ListUsageRecordParams, pageToken, pageNumber string) (*ListUsageRecordResponse, error) { path := "/v1/UsageRecords" data := url.Values{} @@ -130,7 +136,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -147,7 +153,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.ListUsageRecordWithCtx(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) ListUsageRecordWithCtx(ctx context.Context, params *ListUsageRecordParams) ([]SupersimV1UsageRecord, error) { + response, errors := c.StreamUsageRecordWithCtx(ctx, params) records := make([]SupersimV1UsageRecord, 0) for record := range response { @@ -163,6 +174,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.StreamUsageRecordWithCtx(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) StreamUsageRecordWithCtx(ctx context.Context, params *ListUsageRecordParams) (chan SupersimV1UsageRecord, chan error) { if params == nil { params = &ListUsageRecordParams{} } @@ -171,19 +187,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.PageUsageRecordWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUsageRecord(response, params, recordChannel, errorChannel) + go c.streamUsageRecord(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) streamUsageRecord(ctx context.Context, response *ListUsageRecordResponse, params *ListUsageRecordParams, recordChannel chan SupersimV1UsageRecord, errorChannel chan error) { curRecord := 1 for response != nil { @@ -198,7 +214,7 @@ func (c *ApiService) streamUsageRecord(response *ListUsageRecordResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUsageRecordResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListUsageRecordResponse) if err != nil { errorChannel <- err break @@ -213,11 +229,11 @@ func (c *ApiService) streamUsageRecord(response *ListUsageRecordResponse, params close(errorChannel) } -func (c *ApiService) getNextListUsageRecordResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUsageRecordResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 44fb59f7a..1ee4b85a2 100644 --- a/rest/sync/v1/api_service.go +++ b/rest/sync/v1/api_service.go @@ -20,10 +20,14 @@ import ( type ApiService struct { baseURL string - requestHandler *twilio.RequestHandler + requestHandler *twilio.RequestHandlerWithCtx } func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { + return NewApiServiceWithCtx(twilio.UpgradeRequestHandler(requestHandler)) +} + +func NewApiServiceWithCtx(requestHandler *twilio.RequestHandlerWithCtx) *ApiService { return &ApiService{ requestHandler: requestHandler, baseURL: "https://sync.twilio.com", @@ -33,3 +37,7 @@ func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { func NewApiServiceWithClient(client twilio.BaseClient) *ApiService { return NewApiService(twilio.NewRequestHandler(client)) } + +func NewApiServiceWithClientWithCtx(client twilio.BaseClientWithCtx) *ApiService { + return NewApiServiceWithCtx(twilio.NewRequestHandlerWithCtx(client)) +} diff --git a/rest/sync/v1/services.go b/rest/sync/v1/services.go index 848858339..f13344b2a 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" @@ -72,6 +73,11 @@ func (params *CreateServiceParams) SetWebhooksFromRestEnabled(WebhooksFromRestEn // func (c *ApiService) CreateService(params *CreateServiceParams) (*SyncV1Service, error) { + return c.CreateServiceWithCtx(context.TODO(), params) +} + +// +func (c *ApiService) CreateServiceWithCtx(ctx context.Context, params *CreateServiceParams) (*SyncV1Service, error) { path := "/v1/Services" data := url.Values{} @@ -99,7 +105,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -116,13 +122,18 @@ func (c *ApiService) CreateService(params *CreateServiceParams) (*SyncV1Service, // func (c *ApiService) DeleteService(Sid string) error { + return c.DeleteServiceWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) DeleteServiceWithCtx(ctx context.Context, Sid string) error { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -134,13 +145,18 @@ func (c *ApiService) DeleteService(Sid string) error { // func (c *ApiService) FetchService(Sid string) (*SyncV1Service, error) { + return c.FetchServiceWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) FetchServiceWithCtx(ctx context.Context, Sid string) (*SyncV1Service, error) { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -174,6 +190,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.PageServiceWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Service records from the API. Request is executed immediately. +func (c *ApiService) PageServiceWithCtx(ctx context.Context, params *ListServiceParams, pageToken, pageNumber string) (*ListServiceResponse, error) { path := "/v1/Services" data := url.Values{} @@ -190,7 +211,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -207,7 +228,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.ListServiceWithCtx(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) ListServiceWithCtx(ctx context.Context, params *ListServiceParams) ([]SyncV1Service, error) { + response, errors := c.StreamServiceWithCtx(ctx, params) records := make([]SyncV1Service, 0) for record := range response { @@ -223,6 +249,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.StreamServiceWithCtx(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) StreamServiceWithCtx(ctx context.Context, params *ListServiceParams) (chan SyncV1Service, chan error) { if params == nil { params = &ListServiceParams{} } @@ -231,19 +262,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.PageServiceWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamService(response, params, recordChannel, errorChannel) + go c.streamService(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) streamService(ctx context.Context, response *ListServiceResponse, params *ListServiceParams, recordChannel chan SyncV1Service, errorChannel chan error) { curRecord := 1 for response != nil { @@ -258,7 +289,7 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListServiceResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListServiceResponse) if err != nil { errorChannel <- err break @@ -273,11 +304,11 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe close(errorChannel) } -func (c *ApiService) getNextListServiceResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListServiceResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -340,6 +371,11 @@ func (params *UpdateServiceParams) SetWebhooksFromRestEnabled(WebhooksFromRestEn // func (c *ApiService) UpdateService(Sid string, params *UpdateServiceParams) (*SyncV1Service, error) { + return c.UpdateServiceWithCtx(context.TODO(), Sid, params) +} + +// +func (c *ApiService) UpdateServiceWithCtx(ctx context.Context, Sid string, params *UpdateServiceParams) (*SyncV1Service, error) { path := "/v1/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -368,7 +404,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.Post(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 53d2a1f40..a10abb038 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" @@ -48,6 +49,11 @@ func (params *CreateDocumentParams) SetTtl(Ttl int) *CreateDocumentParams { // func (c *ApiService) CreateDocument(ServiceSid string, params *CreateDocumentParams) (*SyncV1Document, error) { + return c.CreateDocumentWithCtx(context.TODO(), ServiceSid, params) +} + +// +func (c *ApiService) CreateDocumentWithCtx(ctx context.Context, ServiceSid string, params *CreateDocumentParams) (*SyncV1Document, error) { path := "/v1/Services/{ServiceSid}/Documents" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -70,7 +76,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -87,6 +93,11 @@ func (c *ApiService) CreateDocument(ServiceSid string, params *CreateDocumentPar // func (c *ApiService) DeleteDocument(ServiceSid string, Sid string) error { + return c.DeleteDocumentWithCtx(context.TODO(), ServiceSid, Sid) +} + +// +func (c *ApiService) DeleteDocumentWithCtx(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) @@ -94,7 +105,7 @@ func (c *ApiService) DeleteDocument(ServiceSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -106,6 +117,11 @@ func (c *ApiService) DeleteDocument(ServiceSid string, Sid string) error { // func (c *ApiService) FetchDocument(ServiceSid string, Sid string) (*SyncV1Document, error) { + return c.FetchDocumentWithCtx(context.TODO(), ServiceSid, Sid) +} + +// +func (c *ApiService) FetchDocumentWithCtx(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) @@ -113,7 +129,7 @@ func (c *ApiService) FetchDocument(ServiceSid string, Sid string) (*SyncV1Docume data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -147,6 +163,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.PageDocumentWithCtx(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Document records from the API. Request is executed immediately. +func (c *ApiService) PageDocumentWithCtx(ctx context.Context, ServiceSid string, params *ListDocumentParams, pageToken, pageNumber string) (*ListDocumentResponse, error) { path := "/v1/Services/{ServiceSid}/Documents" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -165,7 +186,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -182,7 +203,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.ListDocumentWithCtx(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) ListDocumentWithCtx(ctx context.Context, ServiceSid string, params *ListDocumentParams) ([]SyncV1Document, error) { + response, errors := c.StreamDocumentWithCtx(ctx, ServiceSid, params) records := make([]SyncV1Document, 0) for record := range response { @@ -198,6 +224,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.StreamDocumentWithCtx(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) StreamDocumentWithCtx(ctx context.Context, ServiceSid string, params *ListDocumentParams) (chan SyncV1Document, chan error) { if params == nil { params = &ListDocumentParams{} } @@ -206,19 +237,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.PageDocumentWithCtx(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamDocument(response, params, recordChannel, errorChannel) + go c.streamDocument(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) streamDocument(ctx context.Context, response *ListDocumentResponse, params *ListDocumentParams, recordChannel chan SyncV1Document, errorChannel chan error) { curRecord := 1 for response != nil { @@ -233,7 +264,7 @@ func (c *ApiService) streamDocument(response *ListDocumentResponse, params *List } } - record, err := client.GetNext(c.baseURL, response, c.getNextListDocumentResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListDocumentResponse) if err != nil { errorChannel <- err break @@ -248,11 +279,11 @@ func (c *ApiService) streamDocument(response *ListDocumentResponse, params *List close(errorChannel) } -func (c *ApiService) getNextListDocumentResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListDocumentResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -291,6 +322,11 @@ func (params *UpdateDocumentParams) SetTtl(Ttl int) *UpdateDocumentParams { // func (c *ApiService) UpdateDocument(ServiceSid string, Sid string, params *UpdateDocumentParams) (*SyncV1Document, error) { + return c.UpdateDocumentWithCtx(context.TODO(), ServiceSid, Sid, params) +} + +// +func (c *ApiService) UpdateDocumentWithCtx(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) @@ -315,7 +351,7 @@ func (c *ApiService) UpdateDocument(ServiceSid string, Sid string, params *Updat headers["If-Match"] = *params.IfMatch } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 6fac4984d..69601ba08 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,11 @@ import ( // Delete a specific Sync Document Permission. func (c *ApiService) DeleteDocumentPermission(ServiceSid string, DocumentSid string, Identity string) error { + return c.DeleteDocumentPermissionWithCtx(context.TODO(), ServiceSid, DocumentSid, Identity) +} + +// Delete a specific Sync Document Permission. +func (c *ApiService) DeleteDocumentPermissionWithCtx(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) @@ -33,7 +39,7 @@ func (c *ApiService) DeleteDocumentPermission(ServiceSid string, DocumentSid str data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -45,6 +51,11 @@ 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.FetchDocumentPermissionWithCtx(context.TODO(), ServiceSid, DocumentSid, Identity) +} + +// Fetch a specific Sync Document Permission. +func (c *ApiService) FetchDocumentPermissionWithCtx(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) @@ -53,7 +64,7 @@ func (c *ApiService) FetchDocumentPermission(ServiceSid string, DocumentSid stri data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -87,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.PageDocumentPermissionWithCtx(context.TODO(), ServiceSid, DocumentSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of DocumentPermission records from the API. Request is executed immediately. +func (c *ApiService) PageDocumentPermissionWithCtx(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) @@ -106,7 +122,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -123,7 +139,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.ListDocumentPermissionWithCtx(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) ListDocumentPermissionWithCtx(ctx context.Context, ServiceSid string, DocumentSid string, params *ListDocumentPermissionParams) ([]SyncV1DocumentPermission, error) { + response, errors := c.StreamDocumentPermissionWithCtx(ctx, ServiceSid, DocumentSid, params) records := make([]SyncV1DocumentPermission, 0) for record := range response { @@ -139,6 +160,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.StreamDocumentPermissionWithCtx(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) StreamDocumentPermissionWithCtx(ctx context.Context, ServiceSid string, DocumentSid string, params *ListDocumentPermissionParams) (chan SyncV1DocumentPermission, chan error) { if params == nil { params = &ListDocumentPermissionParams{} } @@ -147,19 +173,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.PageDocumentPermissionWithCtx(ctx, ServiceSid, DocumentSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamDocumentPermission(response, params, recordChannel, errorChannel) + go c.streamDocumentPermission(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) streamDocumentPermission(ctx context.Context, response *ListDocumentPermissionResponse, params *ListDocumentPermissionParams, recordChannel chan SyncV1DocumentPermission, errorChannel chan error) { curRecord := 1 for response != nil { @@ -174,7 +200,7 @@ func (c *ApiService) streamDocumentPermission(response *ListDocumentPermissionRe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListDocumentPermissionResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListDocumentPermissionResponse) if err != nil { errorChannel <- err break @@ -189,11 +215,11 @@ func (c *ApiService) streamDocumentPermission(response *ListDocumentPermissionRe close(errorChannel) } -func (c *ApiService) getNextListDocumentPermissionResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListDocumentPermissionResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -232,6 +258,11 @@ 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.UpdateDocumentPermissionWithCtx(context.TODO(), ServiceSid, DocumentSid, Identity, params) +} + +// Update an identity's access to a specific Sync Document. +func (c *ApiService) UpdateDocumentPermissionWithCtx(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) @@ -250,7 +281,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.Post(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 358ea56bf..c12b8db83 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" @@ -48,6 +49,11 @@ func (params *CreateSyncListParams) SetCollectionTtl(CollectionTtl int) *CreateS // func (c *ApiService) CreateSyncList(ServiceSid string, params *CreateSyncListParams) (*SyncV1SyncList, error) { + return c.CreateSyncListWithCtx(context.TODO(), ServiceSid, params) +} + +// +func (c *ApiService) CreateSyncListWithCtx(ctx context.Context, ServiceSid string, params *CreateSyncListParams) (*SyncV1SyncList, error) { path := "/v1/Services/{ServiceSid}/Lists" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -64,7 +70,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -81,6 +87,11 @@ func (c *ApiService) CreateSyncList(ServiceSid string, params *CreateSyncListPar // func (c *ApiService) DeleteSyncList(ServiceSid string, Sid string) error { + return c.DeleteSyncListWithCtx(context.TODO(), ServiceSid, Sid) +} + +// +func (c *ApiService) DeleteSyncListWithCtx(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) @@ -88,7 +99,7 @@ func (c *ApiService) DeleteSyncList(ServiceSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -100,6 +111,11 @@ func (c *ApiService) DeleteSyncList(ServiceSid string, Sid string) error { // func (c *ApiService) FetchSyncList(ServiceSid string, Sid string) (*SyncV1SyncList, error) { + return c.FetchSyncListWithCtx(context.TODO(), ServiceSid, Sid) +} + +// +func (c *ApiService) FetchSyncListWithCtx(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) @@ -107,7 +123,7 @@ func (c *ApiService) FetchSyncList(ServiceSid string, Sid string) (*SyncV1SyncLi data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -141,6 +157,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.PageSyncListWithCtx(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of SyncList records from the API. Request is executed immediately. +func (c *ApiService) PageSyncListWithCtx(ctx context.Context, ServiceSid string, params *ListSyncListParams, pageToken, pageNumber string) (*ListSyncListResponse, error) { path := "/v1/Services/{ServiceSid}/Lists" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -159,7 +180,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -176,7 +197,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.ListSyncListWithCtx(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) ListSyncListWithCtx(ctx context.Context, ServiceSid string, params *ListSyncListParams) ([]SyncV1SyncList, error) { + response, errors := c.StreamSyncListWithCtx(ctx, ServiceSid, params) records := make([]SyncV1SyncList, 0) for record := range response { @@ -192,6 +218,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.StreamSyncListWithCtx(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) StreamSyncListWithCtx(ctx context.Context, ServiceSid string, params *ListSyncListParams) (chan SyncV1SyncList, chan error) { if params == nil { params = &ListSyncListParams{} } @@ -200,19 +231,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.PageSyncListWithCtx(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSyncList(response, params, recordChannel, errorChannel) + go c.streamSyncList(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) streamSyncList(ctx context.Context, response *ListSyncListResponse, params *ListSyncListParams, recordChannel chan SyncV1SyncList, errorChannel chan error) { curRecord := 1 for response != nil { @@ -227,7 +258,7 @@ func (c *ApiService) streamSyncList(response *ListSyncListResponse, params *List } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSyncListResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListSyncListResponse) if err != nil { errorChannel <- err break @@ -242,11 +273,11 @@ func (c *ApiService) streamSyncList(response *ListSyncListResponse, params *List close(errorChannel) } -func (c *ApiService) getNextListSyncListResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSyncListResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -279,6 +310,11 @@ func (params *UpdateSyncListParams) SetCollectionTtl(CollectionTtl int) *UpdateS // func (c *ApiService) UpdateSyncList(ServiceSid string, Sid string, params *UpdateSyncListParams) (*SyncV1SyncList, error) { + return c.UpdateSyncListWithCtx(context.TODO(), ServiceSid, Sid, params) +} + +// +func (c *ApiService) UpdateSyncListWithCtx(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) @@ -293,7 +329,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.Post(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 3e0bec370..30d50feff 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" @@ -54,6 +55,11 @@ func (params *CreateSyncListItemParams) SetCollectionTtl(CollectionTtl int) *Cre // func (c *ApiService) CreateSyncListItem(ServiceSid string, ListSid string, params *CreateSyncListItemParams) (*SyncV1SyncListItem, error) { + return c.CreateSyncListItemWithCtx(context.TODO(), ServiceSid, ListSid, params) +} + +// +func (c *ApiService) CreateSyncListItemWithCtx(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) @@ -80,7 +86,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -108,6 +114,11 @@ func (params *DeleteSyncListItemParams) SetIfMatch(IfMatch string) *DeleteSyncLi // func (c *ApiService) DeleteSyncListItem(ServiceSid string, ListSid string, Index int, params *DeleteSyncListItemParams) error { + return c.DeleteSyncListItemWithCtx(context.TODO(), ServiceSid, ListSid, Index, params) +} + +// +func (c *ApiService) DeleteSyncListItemWithCtx(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) @@ -120,7 +131,7 @@ func (c *ApiService) DeleteSyncListItem(ServiceSid string, ListSid string, Index headers["If-Match"] = *params.IfMatch } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -132,6 +143,11 @@ func (c *ApiService) DeleteSyncListItem(ServiceSid string, ListSid string, Index // func (c *ApiService) FetchSyncListItem(ServiceSid string, ListSid string, Index int) (*SyncV1SyncListItem, error) { + return c.FetchSyncListItemWithCtx(context.TODO(), ServiceSid, ListSid, Index) +} + +// +func (c *ApiService) FetchSyncListItemWithCtx(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) @@ -140,7 +156,7 @@ func (c *ApiService) FetchSyncListItem(ServiceSid string, ListSid string, Index data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -192,6 +208,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.PageSyncListItemWithCtx(context.TODO(), ServiceSid, ListSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of SyncListItem records from the API. Request is executed immediately. +func (c *ApiService) PageSyncListItemWithCtx(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) @@ -220,7 +241,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -237,7 +258,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.ListSyncListItemWithCtx(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) ListSyncListItemWithCtx(ctx context.Context, ServiceSid string, ListSid string, params *ListSyncListItemParams) ([]SyncV1SyncListItem, error) { + response, errors := c.StreamSyncListItemWithCtx(ctx, ServiceSid, ListSid, params) records := make([]SyncV1SyncListItem, 0) for record := range response { @@ -253,6 +279,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.StreamSyncListItemWithCtx(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) StreamSyncListItemWithCtx(ctx context.Context, ServiceSid string, ListSid string, params *ListSyncListItemParams) (chan SyncV1SyncListItem, chan error) { if params == nil { params = &ListSyncListItemParams{} } @@ -261,19 +292,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.PageSyncListItemWithCtx(ctx, ServiceSid, ListSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSyncListItem(response, params, recordChannel, errorChannel) + go c.streamSyncListItem(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) streamSyncListItem(ctx context.Context, response *ListSyncListItemResponse, params *ListSyncListItemParams, recordChannel chan SyncV1SyncListItem, errorChannel chan error) { curRecord := 1 for response != nil { @@ -288,7 +319,7 @@ func (c *ApiService) streamSyncListItem(response *ListSyncListItemResponse, para } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSyncListItemResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListSyncListItemResponse) if err != nil { errorChannel <- err break @@ -303,11 +334,11 @@ func (c *ApiService) streamSyncListItem(response *ListSyncListItemResponse, para close(errorChannel) } -func (c *ApiService) getNextListSyncListItemResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSyncListItemResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -358,6 +389,11 @@ func (params *UpdateSyncListItemParams) SetCollectionTtl(CollectionTtl int) *Upd // func (c *ApiService) UpdateSyncListItem(ServiceSid string, ListSid string, Index int, params *UpdateSyncListItemParams) (*SyncV1SyncListItem, error) { + return c.UpdateSyncListItemWithCtx(context.TODO(), ServiceSid, ListSid, Index, params) +} + +// +func (c *ApiService) UpdateSyncListItemWithCtx(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) @@ -389,7 +425,7 @@ func (c *ApiService) UpdateSyncListItem(ServiceSid string, ListSid string, Index headers["If-Match"] = *params.IfMatch } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 1e1fc0781..361044dbe 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,11 @@ import ( // Delete a specific Sync List Permission. func (c *ApiService) DeleteSyncListPermission(ServiceSid string, ListSid string, Identity string) error { + return c.DeleteSyncListPermissionWithCtx(context.TODO(), ServiceSid, ListSid, Identity) +} + +// Delete a specific Sync List Permission. +func (c *ApiService) DeleteSyncListPermissionWithCtx(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) @@ -33,7 +39,7 @@ func (c *ApiService) DeleteSyncListPermission(ServiceSid string, ListSid string, data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -45,6 +51,11 @@ 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.FetchSyncListPermissionWithCtx(context.TODO(), ServiceSid, ListSid, Identity) +} + +// Fetch a specific Sync List Permission. +func (c *ApiService) FetchSyncListPermissionWithCtx(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) @@ -53,7 +64,7 @@ func (c *ApiService) FetchSyncListPermission(ServiceSid string, ListSid string, data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -87,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.PageSyncListPermissionWithCtx(context.TODO(), ServiceSid, ListSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of SyncListPermission records from the API. Request is executed immediately. +func (c *ApiService) PageSyncListPermissionWithCtx(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) @@ -106,7 +122,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -123,7 +139,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.ListSyncListPermissionWithCtx(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) ListSyncListPermissionWithCtx(ctx context.Context, ServiceSid string, ListSid string, params *ListSyncListPermissionParams) ([]SyncV1SyncListPermission, error) { + response, errors := c.StreamSyncListPermissionWithCtx(ctx, ServiceSid, ListSid, params) records := make([]SyncV1SyncListPermission, 0) for record := range response { @@ -139,6 +160,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.StreamSyncListPermissionWithCtx(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) StreamSyncListPermissionWithCtx(ctx context.Context, ServiceSid string, ListSid string, params *ListSyncListPermissionParams) (chan SyncV1SyncListPermission, chan error) { if params == nil { params = &ListSyncListPermissionParams{} } @@ -147,19 +173,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.PageSyncListPermissionWithCtx(ctx, ServiceSid, ListSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSyncListPermission(response, params, recordChannel, errorChannel) + go c.streamSyncListPermission(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) streamSyncListPermission(ctx context.Context, response *ListSyncListPermissionResponse, params *ListSyncListPermissionParams, recordChannel chan SyncV1SyncListPermission, errorChannel chan error) { curRecord := 1 for response != nil { @@ -174,7 +200,7 @@ func (c *ApiService) streamSyncListPermission(response *ListSyncListPermissionRe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSyncListPermissionResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListSyncListPermissionResponse) if err != nil { errorChannel <- err break @@ -189,11 +215,11 @@ func (c *ApiService) streamSyncListPermission(response *ListSyncListPermissionRe close(errorChannel) } -func (c *ApiService) getNextListSyncListPermissionResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSyncListPermissionResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -232,6 +258,11 @@ 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.UpdateSyncListPermissionWithCtx(context.TODO(), ServiceSid, ListSid, Identity, params) +} + +// Update an identity's access to a specific Sync List. +func (c *ApiService) UpdateSyncListPermissionWithCtx(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) @@ -250,7 +281,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.Post(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 731ada14d..6a1baa74e 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" @@ -48,6 +49,11 @@ func (params *CreateSyncMapParams) SetCollectionTtl(CollectionTtl int) *CreateSy // func (c *ApiService) CreateSyncMap(ServiceSid string, params *CreateSyncMapParams) (*SyncV1SyncMap, error) { + return c.CreateSyncMapWithCtx(context.TODO(), ServiceSid, params) +} + +// +func (c *ApiService) CreateSyncMapWithCtx(ctx context.Context, ServiceSid string, params *CreateSyncMapParams) (*SyncV1SyncMap, error) { path := "/v1/Services/{ServiceSid}/Maps" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -64,7 +70,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -81,6 +87,11 @@ func (c *ApiService) CreateSyncMap(ServiceSid string, params *CreateSyncMapParam // func (c *ApiService) DeleteSyncMap(ServiceSid string, Sid string) error { + return c.DeleteSyncMapWithCtx(context.TODO(), ServiceSid, Sid) +} + +// +func (c *ApiService) DeleteSyncMapWithCtx(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) @@ -88,7 +99,7 @@ func (c *ApiService) DeleteSyncMap(ServiceSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -100,6 +111,11 @@ func (c *ApiService) DeleteSyncMap(ServiceSid string, Sid string) error { // func (c *ApiService) FetchSyncMap(ServiceSid string, Sid string) (*SyncV1SyncMap, error) { + return c.FetchSyncMapWithCtx(context.TODO(), ServiceSid, Sid) +} + +// +func (c *ApiService) FetchSyncMapWithCtx(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) @@ -107,7 +123,7 @@ func (c *ApiService) FetchSyncMap(ServiceSid string, Sid string) (*SyncV1SyncMap data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -141,6 +157,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.PageSyncMapWithCtx(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of SyncMap records from the API. Request is executed immediately. +func (c *ApiService) PageSyncMapWithCtx(ctx context.Context, ServiceSid string, params *ListSyncMapParams, pageToken, pageNumber string) (*ListSyncMapResponse, error) { path := "/v1/Services/{ServiceSid}/Maps" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -159,7 +180,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -176,7 +197,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.ListSyncMapWithCtx(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) ListSyncMapWithCtx(ctx context.Context, ServiceSid string, params *ListSyncMapParams) ([]SyncV1SyncMap, error) { + response, errors := c.StreamSyncMapWithCtx(ctx, ServiceSid, params) records := make([]SyncV1SyncMap, 0) for record := range response { @@ -192,6 +218,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.StreamSyncMapWithCtx(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) StreamSyncMapWithCtx(ctx context.Context, ServiceSid string, params *ListSyncMapParams) (chan SyncV1SyncMap, chan error) { if params == nil { params = &ListSyncMapParams{} } @@ -200,19 +231,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.PageSyncMapWithCtx(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSyncMap(response, params, recordChannel, errorChannel) + go c.streamSyncMap(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) streamSyncMap(ctx context.Context, response *ListSyncMapResponse, params *ListSyncMapParams, recordChannel chan SyncV1SyncMap, errorChannel chan error) { curRecord := 1 for response != nil { @@ -227,7 +258,7 @@ func (c *ApiService) streamSyncMap(response *ListSyncMapResponse, params *ListSy } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSyncMapResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListSyncMapResponse) if err != nil { errorChannel <- err break @@ -242,11 +273,11 @@ func (c *ApiService) streamSyncMap(response *ListSyncMapResponse, params *ListSy close(errorChannel) } -func (c *ApiService) getNextListSyncMapResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSyncMapResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -279,6 +310,11 @@ func (params *UpdateSyncMapParams) SetCollectionTtl(CollectionTtl int) *UpdateSy // func (c *ApiService) UpdateSyncMap(ServiceSid string, Sid string, params *UpdateSyncMapParams) (*SyncV1SyncMap, error) { + return c.UpdateSyncMapWithCtx(context.TODO(), ServiceSid, Sid, params) +} + +// +func (c *ApiService) UpdateSyncMapWithCtx(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) @@ -293,7 +329,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.Post(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 6a1a39e0d..540c08065 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" @@ -60,6 +61,11 @@ func (params *CreateSyncMapItemParams) SetCollectionTtl(CollectionTtl int) *Crea // func (c *ApiService) CreateSyncMapItem(ServiceSid string, MapSid string, params *CreateSyncMapItemParams) (*SyncV1SyncMapItem, error) { + return c.CreateSyncMapItemWithCtx(context.TODO(), ServiceSid, MapSid, params) +} + +// +func (c *ApiService) CreateSyncMapItemWithCtx(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) @@ -89,7 +95,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -117,6 +123,11 @@ func (params *DeleteSyncMapItemParams) SetIfMatch(IfMatch string) *DeleteSyncMap // func (c *ApiService) DeleteSyncMapItem(ServiceSid string, MapSid string, Key string, params *DeleteSyncMapItemParams) error { + return c.DeleteSyncMapItemWithCtx(context.TODO(), ServiceSid, MapSid, Key, params) +} + +// +func (c *ApiService) DeleteSyncMapItemWithCtx(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) @@ -129,7 +140,7 @@ func (c *ApiService) DeleteSyncMapItem(ServiceSid string, MapSid string, Key str headers["If-Match"] = *params.IfMatch } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -141,6 +152,11 @@ func (c *ApiService) DeleteSyncMapItem(ServiceSid string, MapSid string, Key str // func (c *ApiService) FetchSyncMapItem(ServiceSid string, MapSid string, Key string) (*SyncV1SyncMapItem, error) { + return c.FetchSyncMapItemWithCtx(context.TODO(), ServiceSid, MapSid, Key) +} + +// +func (c *ApiService) FetchSyncMapItemWithCtx(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) @@ -149,7 +165,7 @@ func (c *ApiService) FetchSyncMapItem(ServiceSid string, MapSid string, Key stri data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -201,6 +217,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.PageSyncMapItemWithCtx(context.TODO(), ServiceSid, MapSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of SyncMapItem records from the API. Request is executed immediately. +func (c *ApiService) PageSyncMapItemWithCtx(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) @@ -229,7 +250,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -246,7 +267,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.ListSyncMapItemWithCtx(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) ListSyncMapItemWithCtx(ctx context.Context, ServiceSid string, MapSid string, params *ListSyncMapItemParams) ([]SyncV1SyncMapItem, error) { + response, errors := c.StreamSyncMapItemWithCtx(ctx, ServiceSid, MapSid, params) records := make([]SyncV1SyncMapItem, 0) for record := range response { @@ -262,6 +288,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.StreamSyncMapItemWithCtx(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) StreamSyncMapItemWithCtx(ctx context.Context, ServiceSid string, MapSid string, params *ListSyncMapItemParams) (chan SyncV1SyncMapItem, chan error) { if params == nil { params = &ListSyncMapItemParams{} } @@ -270,19 +301,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.PageSyncMapItemWithCtx(ctx, ServiceSid, MapSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSyncMapItem(response, params, recordChannel, errorChannel) + go c.streamSyncMapItem(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) streamSyncMapItem(ctx context.Context, response *ListSyncMapItemResponse, params *ListSyncMapItemParams, recordChannel chan SyncV1SyncMapItem, errorChannel chan error) { curRecord := 1 for response != nil { @@ -297,7 +328,7 @@ func (c *ApiService) streamSyncMapItem(response *ListSyncMapItemResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSyncMapItemResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListSyncMapItemResponse) if err != nil { errorChannel <- err break @@ -312,11 +343,11 @@ func (c *ApiService) streamSyncMapItem(response *ListSyncMapItemResponse, params close(errorChannel) } -func (c *ApiService) getNextListSyncMapItemResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSyncMapItemResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -367,6 +398,11 @@ func (params *UpdateSyncMapItemParams) SetCollectionTtl(CollectionTtl int) *Upda // func (c *ApiService) UpdateSyncMapItem(ServiceSid string, MapSid string, Key string, params *UpdateSyncMapItemParams) (*SyncV1SyncMapItem, error) { + return c.UpdateSyncMapItemWithCtx(context.TODO(), ServiceSid, MapSid, Key, params) +} + +// +func (c *ApiService) UpdateSyncMapItemWithCtx(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) @@ -398,7 +434,7 @@ func (c *ApiService) UpdateSyncMapItem(ServiceSid string, MapSid string, Key str headers["If-Match"] = *params.IfMatch } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 77ccb0c2b..a6fcda227 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,11 @@ import ( // Delete a specific Sync Map Permission. func (c *ApiService) DeleteSyncMapPermission(ServiceSid string, MapSid string, Identity string) error { + return c.DeleteSyncMapPermissionWithCtx(context.TODO(), ServiceSid, MapSid, Identity) +} + +// Delete a specific Sync Map Permission. +func (c *ApiService) DeleteSyncMapPermissionWithCtx(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) @@ -33,7 +39,7 @@ func (c *ApiService) DeleteSyncMapPermission(ServiceSid string, MapSid string, I data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -45,6 +51,11 @@ 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.FetchSyncMapPermissionWithCtx(context.TODO(), ServiceSid, MapSid, Identity) +} + +// Fetch a specific Sync Map Permission. +func (c *ApiService) FetchSyncMapPermissionWithCtx(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) @@ -53,7 +64,7 @@ func (c *ApiService) FetchSyncMapPermission(ServiceSid string, MapSid string, Id data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -87,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.PageSyncMapPermissionWithCtx(context.TODO(), ServiceSid, MapSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of SyncMapPermission records from the API. Request is executed immediately. +func (c *ApiService) PageSyncMapPermissionWithCtx(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) @@ -106,7 +122,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -123,7 +139,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.ListSyncMapPermissionWithCtx(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) ListSyncMapPermissionWithCtx(ctx context.Context, ServiceSid string, MapSid string, params *ListSyncMapPermissionParams) ([]SyncV1SyncMapPermission, error) { + response, errors := c.StreamSyncMapPermissionWithCtx(ctx, ServiceSid, MapSid, params) records := make([]SyncV1SyncMapPermission, 0) for record := range response { @@ -139,6 +160,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.StreamSyncMapPermissionWithCtx(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) StreamSyncMapPermissionWithCtx(ctx context.Context, ServiceSid string, MapSid string, params *ListSyncMapPermissionParams) (chan SyncV1SyncMapPermission, chan error) { if params == nil { params = &ListSyncMapPermissionParams{} } @@ -147,19 +173,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.PageSyncMapPermissionWithCtx(ctx, ServiceSid, MapSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSyncMapPermission(response, params, recordChannel, errorChannel) + go c.streamSyncMapPermission(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) streamSyncMapPermission(ctx context.Context, response *ListSyncMapPermissionResponse, params *ListSyncMapPermissionParams, recordChannel chan SyncV1SyncMapPermission, errorChannel chan error) { curRecord := 1 for response != nil { @@ -174,7 +200,7 @@ func (c *ApiService) streamSyncMapPermission(response *ListSyncMapPermissionResp } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSyncMapPermissionResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListSyncMapPermissionResponse) if err != nil { errorChannel <- err break @@ -189,11 +215,11 @@ func (c *ApiService) streamSyncMapPermission(response *ListSyncMapPermissionResp close(errorChannel) } -func (c *ApiService) getNextListSyncMapPermissionResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSyncMapPermissionResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -232,6 +258,11 @@ 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.UpdateSyncMapPermissionWithCtx(context.TODO(), ServiceSid, MapSid, Identity, params) +} + +// Update an identity's access to a specific Sync Map. +func (c *ApiService) UpdateSyncMapPermissionWithCtx(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) @@ -250,7 +281,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.Post(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 d16add427..bf5eddade 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,11 @@ func (params *CreateSyncStreamParams) SetTtl(Ttl int) *CreateSyncStreamParams { // Create a new Stream. func (c *ApiService) CreateSyncStream(ServiceSid string, params *CreateSyncStreamParams) (*SyncV1SyncStream, error) { + return c.CreateSyncStreamWithCtx(context.TODO(), ServiceSid, params) +} + +// Create a new Stream. +func (c *ApiService) CreateSyncStreamWithCtx(ctx context.Context, ServiceSid string, params *CreateSyncStreamParams) (*SyncV1SyncStream, error) { path := "/v1/Services/{ServiceSid}/Streams" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -55,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -72,6 +78,11 @@ func (c *ApiService) CreateSyncStream(ServiceSid string, params *CreateSyncStrea // Delete a specific Stream. func (c *ApiService) DeleteSyncStream(ServiceSid string, Sid string) error { + return c.DeleteSyncStreamWithCtx(context.TODO(), ServiceSid, Sid) +} + +// Delete a specific Stream. +func (c *ApiService) DeleteSyncStreamWithCtx(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) @@ -79,7 +90,7 @@ func (c *ApiService) DeleteSyncStream(ServiceSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -91,6 +102,11 @@ 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.FetchSyncStreamWithCtx(context.TODO(), ServiceSid, Sid) +} + +// Fetch a specific Stream. +func (c *ApiService) FetchSyncStreamWithCtx(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) @@ -98,7 +114,7 @@ func (c *ApiService) FetchSyncStream(ServiceSid string, Sid string) (*SyncV1Sync data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -132,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.PageSyncStreamWithCtx(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of SyncStream records from the API. Request is executed immediately. +func (c *ApiService) PageSyncStreamWithCtx(ctx context.Context, ServiceSid string, params *ListSyncStreamParams, pageToken, pageNumber string) (*ListSyncStreamResponse, error) { path := "/v1/Services/{ServiceSid}/Streams" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -150,7 +171,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -167,7 +188,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.ListSyncStreamWithCtx(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) ListSyncStreamWithCtx(ctx context.Context, ServiceSid string, params *ListSyncStreamParams) ([]SyncV1SyncStream, error) { + response, errors := c.StreamSyncStreamWithCtx(ctx, ServiceSid, params) records := make([]SyncV1SyncStream, 0) for record := range response { @@ -183,6 +209,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.StreamSyncStreamWithCtx(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) StreamSyncStreamWithCtx(ctx context.Context, ServiceSid string, params *ListSyncStreamParams) (chan SyncV1SyncStream, chan error) { if params == nil { params = &ListSyncStreamParams{} } @@ -191,19 +222,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.PageSyncStreamWithCtx(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSyncStream(response, params, recordChannel, errorChannel) + go c.streamSyncStream(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) streamSyncStream(ctx context.Context, response *ListSyncStreamResponse, params *ListSyncStreamParams, recordChannel chan SyncV1SyncStream, errorChannel chan error) { curRecord := 1 for response != nil { @@ -218,7 +249,7 @@ func (c *ApiService) streamSyncStream(response *ListSyncStreamResponse, params * } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSyncStreamResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListSyncStreamResponse) if err != nil { errorChannel <- err break @@ -233,11 +264,11 @@ func (c *ApiService) streamSyncStream(response *ListSyncStreamResponse, params * close(errorChannel) } -func (c *ApiService) getNextListSyncStreamResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSyncStreamResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -264,6 +295,11 @@ 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.UpdateSyncStreamWithCtx(context.TODO(), ServiceSid, Sid, params) +} + +// Update a specific Stream. +func (c *ApiService) UpdateSyncStreamWithCtx(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) @@ -275,7 +311,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.Post(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 ab4a47f4e..f434ca322 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,11 @@ func (params *CreateStreamMessageParams) SetData(Data interface{}) *CreateStream // Create a new Stream Message. func (c *ApiService) CreateStreamMessage(ServiceSid string, StreamSid string, params *CreateStreamMessageParams) (*SyncV1StreamMessage, error) { + return c.CreateStreamMessageWithCtx(context.TODO(), ServiceSid, StreamSid, params) +} + +// Create a new Stream Message. +func (c *ApiService) CreateStreamMessageWithCtx(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) @@ -50,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.Post(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 233d22d0b..997f52920 100644 --- a/rest/taskrouter/v1/api_service.go +++ b/rest/taskrouter/v1/api_service.go @@ -20,10 +20,14 @@ import ( type ApiService struct { baseURL string - requestHandler *twilio.RequestHandler + requestHandler *twilio.RequestHandlerWithCtx } func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { + return NewApiServiceWithCtx(twilio.UpgradeRequestHandler(requestHandler)) +} + +func NewApiServiceWithCtx(requestHandler *twilio.RequestHandlerWithCtx) *ApiService { return &ApiService{ requestHandler: requestHandler, baseURL: "https://taskrouter.twilio.com", @@ -33,3 +37,7 @@ func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { func NewApiServiceWithClient(client twilio.BaseClient) *ApiService { return NewApiService(twilio.NewRequestHandler(client)) } + +func NewApiServiceWithClientWithCtx(client twilio.BaseClientWithCtx) *ApiService { + return NewApiServiceWithCtx(twilio.NewRequestHandlerWithCtx(client)) +} diff --git a/rest/taskrouter/v1/workspaces.go b/rest/taskrouter/v1/workspaces.go index a1890a26a..754fa11b4 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" @@ -66,6 +67,11 @@ func (params *CreateWorkspaceParams) SetPrioritizeQueueOrder(PrioritizeQueueOrde // func (c *ApiService) CreateWorkspace(params *CreateWorkspaceParams) (*TaskrouterV1Workspace, error) { + return c.CreateWorkspaceWithCtx(context.TODO(), params) +} + +// +func (c *ApiService) CreateWorkspaceWithCtx(ctx context.Context, params *CreateWorkspaceParams) (*TaskrouterV1Workspace, error) { path := "/v1/Workspaces" data := url.Values{} @@ -90,7 +96,7 @@ func (c *ApiService) CreateWorkspace(params *CreateWorkspaceParams) (*Taskrouter data.Set("PrioritizeQueueOrder", *params.PrioritizeQueueOrder) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -107,13 +113,18 @@ func (c *ApiService) CreateWorkspace(params *CreateWorkspaceParams) (*Taskrouter // func (c *ApiService) DeleteWorkspace(Sid string) error { + return c.DeleteWorkspaceWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) DeleteWorkspaceWithCtx(ctx context.Context, Sid string) error { path := "/v1/Workspaces/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -125,13 +136,18 @@ func (c *ApiService) DeleteWorkspace(Sid string) error { // func (c *ApiService) FetchWorkspace(Sid string) (*TaskrouterV1Workspace, error) { + return c.FetchWorkspaceWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) FetchWorkspaceWithCtx(ctx context.Context, Sid string) (*TaskrouterV1Workspace, error) { path := "/v1/Workspaces/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -171,6 +187,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.PageWorkspaceWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Workspace records from the API. Request is executed immediately. +func (c *ApiService) PageWorkspaceWithCtx(ctx context.Context, params *ListWorkspaceParams, pageToken, pageNumber string) (*ListWorkspaceResponse, error) { path := "/v1/Workspaces" data := url.Values{} @@ -190,7 +211,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -207,7 +228,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.ListWorkspaceWithCtx(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) ListWorkspaceWithCtx(ctx context.Context, params *ListWorkspaceParams) ([]TaskrouterV1Workspace, error) { + response, errors := c.StreamWorkspaceWithCtx(ctx, params) records := make([]TaskrouterV1Workspace, 0) for record := range response { @@ -223,6 +249,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.StreamWorkspaceWithCtx(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) StreamWorkspaceWithCtx(ctx context.Context, params *ListWorkspaceParams) (chan TaskrouterV1Workspace, chan error) { if params == nil { params = &ListWorkspaceParams{} } @@ -231,19 +262,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.PageWorkspaceWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamWorkspace(response, params, recordChannel, errorChannel) + go c.streamWorkspace(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) streamWorkspace(ctx context.Context, response *ListWorkspaceResponse, params *ListWorkspaceParams, recordChannel chan TaskrouterV1Workspace, errorChannel chan error) { curRecord := 1 for response != nil { @@ -258,7 +289,7 @@ func (c *ApiService) streamWorkspace(response *ListWorkspaceResponse, params *Li } } - record, err := client.GetNext(c.baseURL, response, c.getNextListWorkspaceResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListWorkspaceResponse) if err != nil { errorChannel <- err break @@ -273,11 +304,11 @@ func (c *ApiService) streamWorkspace(response *ListWorkspaceResponse, params *Li close(errorChannel) } -func (c *ApiService) getNextListWorkspaceResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListWorkspaceResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -340,6 +371,11 @@ func (params *UpdateWorkspaceParams) SetPrioritizeQueueOrder(PrioritizeQueueOrde // func (c *ApiService) UpdateWorkspace(Sid string, params *UpdateWorkspaceParams) (*TaskrouterV1Workspace, error) { + return c.UpdateWorkspaceWithCtx(context.TODO(), Sid, params) +} + +// +func (c *ApiService) UpdateWorkspaceWithCtx(ctx context.Context, Sid string, params *UpdateWorkspaceParams) (*TaskrouterV1Workspace, error) { path := "/v1/Workspaces/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -368,7 +404,7 @@ func (c *ApiService) UpdateWorkspace(Sid string, params *UpdateWorkspaceParams) data.Set("PrioritizeQueueOrder", *params.PrioritizeQueueOrder) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 563c227c4..a3a169008 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" @@ -42,6 +43,11 @@ func (params *CreateActivityParams) SetAvailable(Available bool) *CreateActivity // func (c *ApiService) CreateActivity(WorkspaceSid string, params *CreateActivityParams) (*TaskrouterV1Activity, error) { + return c.CreateActivityWithCtx(context.TODO(), WorkspaceSid, params) +} + +// +func (c *ApiService) CreateActivityWithCtx(ctx context.Context, WorkspaceSid string, params *CreateActivityParams) (*TaskrouterV1Activity, error) { path := "/v1/Workspaces/{WorkspaceSid}/Activities" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) @@ -55,7 +61,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -72,6 +78,11 @@ func (c *ApiService) CreateActivity(WorkspaceSid string, params *CreateActivityP // func (c *ApiService) DeleteActivity(WorkspaceSid string, Sid string) error { + return c.DeleteActivityWithCtx(context.TODO(), WorkspaceSid, Sid) +} + +// +func (c *ApiService) DeleteActivityWithCtx(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) @@ -79,7 +90,7 @@ func (c *ApiService) DeleteActivity(WorkspaceSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -91,6 +102,11 @@ func (c *ApiService) DeleteActivity(WorkspaceSid string, Sid string) error { // func (c *ApiService) FetchActivity(WorkspaceSid string, Sid string) (*TaskrouterV1Activity, error) { + return c.FetchActivityWithCtx(context.TODO(), WorkspaceSid, Sid) +} + +// +func (c *ApiService) FetchActivityWithCtx(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) @@ -98,7 +114,7 @@ func (c *ApiService) FetchActivity(WorkspaceSid string, Sid string) (*Taskrouter data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -144,6 +160,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.PageActivityWithCtx(context.TODO(), WorkspaceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Activity records from the API. Request is executed immediately. +func (c *ApiService) PageActivityWithCtx(ctx context.Context, WorkspaceSid string, params *ListActivityParams, pageToken, pageNumber string) (*ListActivityResponse, error) { path := "/v1/Workspaces/{WorkspaceSid}/Activities" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) @@ -168,7 +189,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -185,7 +206,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.ListActivityWithCtx(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) ListActivityWithCtx(ctx context.Context, WorkspaceSid string, params *ListActivityParams) ([]TaskrouterV1Activity, error) { + response, errors := c.StreamActivityWithCtx(ctx, WorkspaceSid, params) records := make([]TaskrouterV1Activity, 0) for record := range response { @@ -201,6 +227,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.StreamActivityWithCtx(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) StreamActivityWithCtx(ctx context.Context, WorkspaceSid string, params *ListActivityParams) (chan TaskrouterV1Activity, chan error) { if params == nil { params = &ListActivityParams{} } @@ -209,19 +240,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.PageActivityWithCtx(ctx, WorkspaceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamActivity(response, params, recordChannel, errorChannel) + go c.streamActivity(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) streamActivity(ctx context.Context, response *ListActivityResponse, params *ListActivityParams, recordChannel chan TaskrouterV1Activity, errorChannel chan error) { curRecord := 1 for response != nil { @@ -236,7 +267,7 @@ func (c *ApiService) streamActivity(response *ListActivityResponse, params *List } } - record, err := client.GetNext(c.baseURL, response, c.getNextListActivityResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListActivityResponse) if err != nil { errorChannel <- err break @@ -251,11 +282,11 @@ func (c *ApiService) streamActivity(response *ListActivityResponse, params *List close(errorChannel) } -func (c *ApiService) getNextListActivityResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListActivityResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -282,6 +313,11 @@ func (params *UpdateActivityParams) SetFriendlyName(FriendlyName string) *Update // func (c *ApiService) UpdateActivity(WorkspaceSid string, Sid string, params *UpdateActivityParams) (*TaskrouterV1Activity, error) { + return c.UpdateActivityWithCtx(context.TODO(), WorkspaceSid, Sid, params) +} + +// +func (c *ApiService) UpdateActivityWithCtx(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) @@ -293,7 +329,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.Post(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 5bf253374..f2225950a 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" @@ -59,6 +60,11 @@ func (params *FetchWorkspaceCumulativeStatisticsParams) SetSplitByWaitTime(Split // func (c *ApiService) FetchWorkspaceCumulativeStatistics(WorkspaceSid string, params *FetchWorkspaceCumulativeStatisticsParams) (*TaskrouterV1WorkspaceCumulativeStatistics, error) { + return c.FetchWorkspaceCumulativeStatisticsWithCtx(context.TODO(), WorkspaceSid, params) +} + +// +func (c *ApiService) FetchWorkspaceCumulativeStatisticsWithCtx(ctx context.Context, WorkspaceSid string, params *FetchWorkspaceCumulativeStatisticsParams) (*TaskrouterV1WorkspaceCumulativeStatistics, error) { path := "/v1/Workspaces/{WorkspaceSid}/CumulativeStatistics" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) @@ -81,7 +87,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.Get(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 b9bc46cbf..0b6391cde 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" @@ -26,6 +27,11 @@ import ( // func (c *ApiService) FetchEvent(WorkspaceSid string, Sid string) (*TaskrouterV1Event, error) { + return c.FetchEventWithCtx(context.TODO(), WorkspaceSid, Sid) +} + +// +func (c *ApiService) FetchEventWithCtx(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) @@ -33,7 +39,7 @@ func (c *ApiService) FetchEvent(WorkspaceSid string, Sid string) (*TaskrouterV1E data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -133,6 +139,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.PageEventWithCtx(context.TODO(), WorkspaceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Event records from the API. Request is executed immediately. +func (c *ApiService) PageEventWithCtx(ctx context.Context, WorkspaceSid string, params *ListEventParams, pageToken, pageNumber string) (*ListEventResponse, error) { path := "/v1/Workspaces/{WorkspaceSid}/Events" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) @@ -184,7 +195,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -201,7 +212,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.ListEventWithCtx(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) ListEventWithCtx(ctx context.Context, WorkspaceSid string, params *ListEventParams) ([]TaskrouterV1Event, error) { + response, errors := c.StreamEventWithCtx(ctx, WorkspaceSid, params) records := make([]TaskrouterV1Event, 0) for record := range response { @@ -217,6 +233,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.StreamEventWithCtx(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) StreamEventWithCtx(ctx context.Context, WorkspaceSid string, params *ListEventParams) (chan TaskrouterV1Event, chan error) { if params == nil { params = &ListEventParams{} } @@ -225,19 +246,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.PageEventWithCtx(ctx, WorkspaceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamEvent(response, params, recordChannel, errorChannel) + go c.streamEvent(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) streamEvent(ctx context.Context, response *ListEventResponse, params *ListEventParams, recordChannel chan TaskrouterV1Event, errorChannel chan error) { curRecord := 1 for response != nil { @@ -252,7 +273,7 @@ func (c *ApiService) streamEvent(response *ListEventResponse, params *ListEventP } } - record, err := client.GetNext(c.baseURL, response, c.getNextListEventResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListEventResponse) if err != nil { errorChannel <- err break @@ -267,11 +288,11 @@ func (c *ApiService) streamEvent(response *ListEventResponse, params *ListEventP close(errorChannel) } -func (c *ApiService) getNextListEventResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListEventResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 75593edef..b4257d440 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" @@ -33,6 +34,11 @@ func (params *FetchWorkspaceRealTimeStatisticsParams) SetTaskChannel(TaskChannel // func (c *ApiService) FetchWorkspaceRealTimeStatistics(WorkspaceSid string, params *FetchWorkspaceRealTimeStatisticsParams) (*TaskrouterV1WorkspaceRealTimeStatistics, error) { + return c.FetchWorkspaceRealTimeStatisticsWithCtx(context.TODO(), WorkspaceSid, params) +} + +// +func (c *ApiService) FetchWorkspaceRealTimeStatisticsWithCtx(ctx context.Context, WorkspaceSid string, params *FetchWorkspaceRealTimeStatisticsParams) (*TaskrouterV1WorkspaceRealTimeStatistics, error) { path := "/v1/Workspaces/{WorkspaceSid}/RealTimeStatistics" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) @@ -43,7 +49,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.Get(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 1d92d7d28..19f0f8609 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" @@ -59,6 +60,11 @@ func (params *FetchWorkspaceStatisticsParams) SetSplitByWaitTime(SplitByWaitTime // func (c *ApiService) FetchWorkspaceStatistics(WorkspaceSid string, params *FetchWorkspaceStatisticsParams) (*TaskrouterV1WorkspaceStatistics, error) { + return c.FetchWorkspaceStatisticsWithCtx(context.TODO(), WorkspaceSid, params) +} + +// +func (c *ApiService) FetchWorkspaceStatisticsWithCtx(ctx context.Context, WorkspaceSid string, params *FetchWorkspaceStatisticsParams) (*TaskrouterV1WorkspaceStatistics, error) { path := "/v1/Workspaces/{WorkspaceSid}/Statistics" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) @@ -81,7 +87,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.Get(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 ab0035c54..8e36c9862 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" @@ -48,6 +49,11 @@ func (params *CreateTaskChannelParams) SetChannelOptimizedRouting(ChannelOptimiz // func (c *ApiService) CreateTaskChannel(WorkspaceSid string, params *CreateTaskChannelParams) (*TaskrouterV1TaskChannel, error) { + return c.CreateTaskChannelWithCtx(context.TODO(), WorkspaceSid, params) +} + +// +func (c *ApiService) CreateTaskChannelWithCtx(ctx context.Context, WorkspaceSid string, params *CreateTaskChannelParams) (*TaskrouterV1TaskChannel, error) { path := "/v1/Workspaces/{WorkspaceSid}/TaskChannels" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) @@ -64,7 +70,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -81,6 +87,11 @@ func (c *ApiService) CreateTaskChannel(WorkspaceSid string, params *CreateTaskCh // func (c *ApiService) DeleteTaskChannel(WorkspaceSid string, Sid string) error { + return c.DeleteTaskChannelWithCtx(context.TODO(), WorkspaceSid, Sid) +} + +// +func (c *ApiService) DeleteTaskChannelWithCtx(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) @@ -88,7 +99,7 @@ func (c *ApiService) DeleteTaskChannel(WorkspaceSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -100,6 +111,11 @@ func (c *ApiService) DeleteTaskChannel(WorkspaceSid string, Sid string) error { // func (c *ApiService) FetchTaskChannel(WorkspaceSid string, Sid string) (*TaskrouterV1TaskChannel, error) { + return c.FetchTaskChannelWithCtx(context.TODO(), WorkspaceSid, Sid) +} + +// +func (c *ApiService) FetchTaskChannelWithCtx(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) @@ -107,7 +123,7 @@ func (c *ApiService) FetchTaskChannel(WorkspaceSid string, Sid string) (*Taskrou data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -141,6 +157,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.PageTaskChannelWithCtx(context.TODO(), WorkspaceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of TaskChannel records from the API. Request is executed immediately. +func (c *ApiService) PageTaskChannelWithCtx(ctx context.Context, WorkspaceSid string, params *ListTaskChannelParams, pageToken, pageNumber string) (*ListTaskChannelResponse, error) { path := "/v1/Workspaces/{WorkspaceSid}/TaskChannels" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) @@ -159,7 +180,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -176,7 +197,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.ListTaskChannelWithCtx(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) ListTaskChannelWithCtx(ctx context.Context, WorkspaceSid string, params *ListTaskChannelParams) ([]TaskrouterV1TaskChannel, error) { + response, errors := c.StreamTaskChannelWithCtx(ctx, WorkspaceSid, params) records := make([]TaskrouterV1TaskChannel, 0) for record := range response { @@ -192,6 +218,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.StreamTaskChannelWithCtx(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) StreamTaskChannelWithCtx(ctx context.Context, WorkspaceSid string, params *ListTaskChannelParams) (chan TaskrouterV1TaskChannel, chan error) { if params == nil { params = &ListTaskChannelParams{} } @@ -200,19 +231,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.PageTaskChannelWithCtx(ctx, WorkspaceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamTaskChannel(response, params, recordChannel, errorChannel) + go c.streamTaskChannel(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) streamTaskChannel(ctx context.Context, response *ListTaskChannelResponse, params *ListTaskChannelParams, recordChannel chan TaskrouterV1TaskChannel, errorChannel chan error) { curRecord := 1 for response != nil { @@ -227,7 +258,7 @@ func (c *ApiService) streamTaskChannel(response *ListTaskChannelResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListTaskChannelResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListTaskChannelResponse) if err != nil { errorChannel <- err break @@ -242,11 +273,11 @@ func (c *ApiService) streamTaskChannel(response *ListTaskChannelResponse, params close(errorChannel) } -func (c *ApiService) getNextListTaskChannelResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListTaskChannelResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -279,6 +310,11 @@ func (params *UpdateTaskChannelParams) SetChannelOptimizedRouting(ChannelOptimiz // func (c *ApiService) UpdateTaskChannel(WorkspaceSid string, Sid string, params *UpdateTaskChannelParams) (*TaskrouterV1TaskChannel, error) { + return c.UpdateTaskChannelWithCtx(context.TODO(), WorkspaceSid, Sid, params) +} + +// +func (c *ApiService) UpdateTaskChannelWithCtx(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) @@ -293,7 +329,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.Post(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 158918f08..b084fde9a 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" @@ -66,6 +67,11 @@ func (params *CreateTaskQueueParams) SetAssignmentActivitySid(AssignmentActivity // func (c *ApiService) CreateTaskQueue(WorkspaceSid string, params *CreateTaskQueueParams) (*TaskrouterV1TaskQueue, error) { + return c.CreateTaskQueueWithCtx(context.TODO(), WorkspaceSid, params) +} + +// +func (c *ApiService) CreateTaskQueueWithCtx(ctx context.Context, WorkspaceSid string, params *CreateTaskQueueParams) (*TaskrouterV1TaskQueue, error) { path := "/v1/Workspaces/{WorkspaceSid}/TaskQueues" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) @@ -91,7 +97,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -108,6 +114,11 @@ func (c *ApiService) CreateTaskQueue(WorkspaceSid string, params *CreateTaskQueu // func (c *ApiService) DeleteTaskQueue(WorkspaceSid string, Sid string) error { + return c.DeleteTaskQueueWithCtx(context.TODO(), WorkspaceSid, Sid) +} + +// +func (c *ApiService) DeleteTaskQueueWithCtx(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) @@ -115,7 +126,7 @@ func (c *ApiService) DeleteTaskQueue(WorkspaceSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -127,6 +138,11 @@ func (c *ApiService) DeleteTaskQueue(WorkspaceSid string, Sid string) error { // func (c *ApiService) FetchTaskQueue(WorkspaceSid string, Sid string) (*TaskrouterV1TaskQueue, error) { + return c.FetchTaskQueueWithCtx(context.TODO(), WorkspaceSid, Sid) +} + +// +func (c *ApiService) FetchTaskQueueWithCtx(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) @@ -134,7 +150,7 @@ func (c *ApiService) FetchTaskQueue(WorkspaceSid string, Sid string) (*Taskroute data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -186,6 +202,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.PageTaskQueueWithCtx(context.TODO(), WorkspaceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of TaskQueue records from the API. Request is executed immediately. +func (c *ApiService) PageTaskQueueWithCtx(ctx context.Context, WorkspaceSid string, params *ListTaskQueueParams, pageToken, pageNumber string) (*ListTaskQueueResponse, error) { path := "/v1/Workspaces/{WorkspaceSid}/TaskQueues" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) @@ -213,7 +234,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -230,7 +251,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.ListTaskQueueWithCtx(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) ListTaskQueueWithCtx(ctx context.Context, WorkspaceSid string, params *ListTaskQueueParams) ([]TaskrouterV1TaskQueue, error) { + response, errors := c.StreamTaskQueueWithCtx(ctx, WorkspaceSid, params) records := make([]TaskrouterV1TaskQueue, 0) for record := range response { @@ -246,6 +272,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.StreamTaskQueueWithCtx(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) StreamTaskQueueWithCtx(ctx context.Context, WorkspaceSid string, params *ListTaskQueueParams) (chan TaskrouterV1TaskQueue, chan error) { if params == nil { params = &ListTaskQueueParams{} } @@ -254,19 +285,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.PageTaskQueueWithCtx(ctx, WorkspaceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamTaskQueue(response, params, recordChannel, errorChannel) + go c.streamTaskQueue(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) streamTaskQueue(ctx context.Context, response *ListTaskQueueResponse, params *ListTaskQueueParams, recordChannel chan TaskrouterV1TaskQueue, errorChannel chan error) { curRecord := 1 for response != nil { @@ -281,7 +312,7 @@ func (c *ApiService) streamTaskQueue(response *ListTaskQueueResponse, params *Li } } - record, err := client.GetNext(c.baseURL, response, c.getNextListTaskQueueResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListTaskQueueResponse) if err != nil { errorChannel <- err break @@ -296,11 +327,11 @@ func (c *ApiService) streamTaskQueue(response *ListTaskQueueResponse, params *Li close(errorChannel) } -func (c *ApiService) getNextListTaskQueueResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListTaskQueueResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -357,6 +388,11 @@ func (params *UpdateTaskQueueParams) SetTaskOrder(TaskOrder string) *UpdateTaskQ // func (c *ApiService) UpdateTaskQueue(WorkspaceSid string, Sid string, params *UpdateTaskQueueParams) (*TaskrouterV1TaskQueue, error) { + return c.UpdateTaskQueueWithCtx(context.TODO(), WorkspaceSid, Sid, params) +} + +// +func (c *ApiService) UpdateTaskQueueWithCtx(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) @@ -383,7 +419,7 @@ func (c *ApiService) UpdateTaskQueue(WorkspaceSid string, Sid string, params *Up data.Set("TaskOrder", *params.TaskOrder) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 2216de575..f9dcd95e3 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" @@ -59,6 +60,11 @@ func (params *FetchTaskQueueCumulativeStatisticsParams) SetSplitByWaitTime(Split // func (c *ApiService) FetchTaskQueueCumulativeStatistics(WorkspaceSid string, TaskQueueSid string, params *FetchTaskQueueCumulativeStatisticsParams) (*TaskrouterV1TaskQueueCumulativeStatistics, error) { + return c.FetchTaskQueueCumulativeStatisticsWithCtx(context.TODO(), WorkspaceSid, TaskQueueSid, params) +} + +// +func (c *ApiService) FetchTaskQueueCumulativeStatisticsWithCtx(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) @@ -82,7 +88,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.Get(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 b1605a619..dc27cee28 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,11 @@ func (params *FetchTaskQueueRealTimeStatisticsParams) SetTaskChannel(TaskChannel // func (c *ApiService) FetchTaskQueueRealTimeStatistics(WorkspaceSid string, TaskQueueSid string, params *FetchTaskQueueRealTimeStatisticsParams) (*TaskrouterV1TaskQueueRealTimeStatistics, error) { + return c.FetchTaskQueueRealTimeStatisticsWithCtx(context.TODO(), WorkspaceSid, TaskQueueSid, params) +} + +// +func (c *ApiService) FetchTaskQueueRealTimeStatisticsWithCtx(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) @@ -44,7 +50,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.Get(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 c5ea20fd7..b2efbcc26 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" @@ -61,6 +62,11 @@ func (params *FetchTaskQueueStatisticsParams) SetSplitByWaitTime(SplitByWaitTime // func (c *ApiService) FetchTaskQueueStatistics(WorkspaceSid string, TaskQueueSid string, params *FetchTaskQueueStatisticsParams) (*TaskrouterV1TaskQueueStatistics, error) { + return c.FetchTaskQueueStatisticsWithCtx(context.TODO(), WorkspaceSid, TaskQueueSid, params) +} + +// +func (c *ApiService) FetchTaskQueueStatisticsWithCtx(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) @@ -84,7 +90,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -154,6 +160,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.PageTaskQueuesStatisticsWithCtx(context.TODO(), WorkspaceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of TaskQueuesStatistics records from the API. Request is executed immediately. +func (c *ApiService) PageTaskQueuesStatisticsWithCtx(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) @@ -190,7 +201,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -207,7 +218,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.ListTaskQueuesStatisticsWithCtx(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) ListTaskQueuesStatisticsWithCtx(ctx context.Context, WorkspaceSid string, params *ListTaskQueuesStatisticsParams) ([]TaskrouterV1TaskQueuesStatistics, error) { + response, errors := c.StreamTaskQueuesStatisticsWithCtx(ctx, WorkspaceSid, params) records := make([]TaskrouterV1TaskQueuesStatistics, 0) for record := range response { @@ -223,6 +239,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.StreamTaskQueuesStatisticsWithCtx(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) StreamTaskQueuesStatisticsWithCtx(ctx context.Context, WorkspaceSid string, params *ListTaskQueuesStatisticsParams) (chan TaskrouterV1TaskQueuesStatistics, chan error) { if params == nil { params = &ListTaskQueuesStatisticsParams{} } @@ -231,19 +252,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.PageTaskQueuesStatisticsWithCtx(ctx, WorkspaceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamTaskQueuesStatistics(response, params, recordChannel, errorChannel) + go c.streamTaskQueuesStatistics(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) streamTaskQueuesStatistics(ctx context.Context, response *ListTaskQueuesStatisticsResponse, params *ListTaskQueuesStatisticsParams, recordChannel chan TaskrouterV1TaskQueuesStatistics, errorChannel chan error) { curRecord := 1 for response != nil { @@ -258,7 +279,7 @@ func (c *ApiService) streamTaskQueuesStatistics(response *ListTaskQueuesStatisti } } - record, err := client.GetNext(c.baseURL, response, c.getNextListTaskQueuesStatisticsResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListTaskQueuesStatisticsResponse) if err != nil { errorChannel <- err break @@ -273,11 +294,11 @@ func (c *ApiService) streamTaskQueuesStatistics(response *ListTaskQueuesStatisti close(errorChannel) } -func (c *ApiService) getNextListTaskQueuesStatisticsResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListTaskQueuesStatisticsResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 7005d1273..acf832835 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" @@ -60,6 +61,11 @@ func (params *CreateTaskParams) SetAttributes(Attributes string) *CreateTaskPara // func (c *ApiService) CreateTask(WorkspaceSid string, params *CreateTaskParams) (*TaskrouterV1Task, error) { + return c.CreateTaskWithCtx(context.TODO(), WorkspaceSid, params) +} + +// +func (c *ApiService) CreateTaskWithCtx(ctx context.Context, WorkspaceSid string, params *CreateTaskParams) (*TaskrouterV1Task, error) { path := "/v1/Workspaces/{WorkspaceSid}/Tasks" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) @@ -82,7 +88,7 @@ func (c *ApiService) CreateTask(WorkspaceSid string, params *CreateTaskParams) ( data.Set("Attributes", *params.Attributes) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -110,6 +116,11 @@ func (params *DeleteTaskParams) SetIfMatch(IfMatch string) *DeleteTaskParams { // func (c *ApiService) DeleteTask(WorkspaceSid string, Sid string, params *DeleteTaskParams) error { + return c.DeleteTaskWithCtx(context.TODO(), WorkspaceSid, Sid, params) +} + +// +func (c *ApiService) DeleteTaskWithCtx(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) @@ -121,7 +132,7 @@ func (c *ApiService) DeleteTask(WorkspaceSid string, Sid string, params *DeleteT headers["If-Match"] = *params.IfMatch } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -133,6 +144,11 @@ func (c *ApiService) DeleteTask(WorkspaceSid string, Sid string, params *DeleteT // func (c *ApiService) FetchTask(WorkspaceSid string, Sid string) (*TaskrouterV1Task, error) { + return c.FetchTaskWithCtx(context.TODO(), WorkspaceSid, Sid) +} + +// +func (c *ApiService) FetchTaskWithCtx(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) @@ -140,7 +156,7 @@ func (c *ApiService) FetchTask(WorkspaceSid string, Sid string) (*TaskrouterV1Ta data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -228,6 +244,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.PageTaskWithCtx(context.TODO(), WorkspaceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Task records from the API. Request is executed immediately. +func (c *ApiService) PageTaskWithCtx(ctx context.Context, WorkspaceSid string, params *ListTaskParams, pageToken, pageNumber string) (*ListTaskResponse, error) { path := "/v1/Workspaces/{WorkspaceSid}/Tasks" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) @@ -275,7 +296,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -292,7 +313,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.ListTaskWithCtx(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) ListTaskWithCtx(ctx context.Context, WorkspaceSid string, params *ListTaskParams) ([]TaskrouterV1Task, error) { + response, errors := c.StreamTaskWithCtx(ctx, WorkspaceSid, params) records := make([]TaskrouterV1Task, 0) for record := range response { @@ -308,6 +334,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.StreamTaskWithCtx(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) StreamTaskWithCtx(ctx context.Context, WorkspaceSid string, params *ListTaskParams) (chan TaskrouterV1Task, chan error) { if params == nil { params = &ListTaskParams{} } @@ -316,19 +347,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.PageTaskWithCtx(ctx, WorkspaceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamTask(response, params, recordChannel, errorChannel) + go c.streamTask(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) streamTask(ctx context.Context, response *ListTaskResponse, params *ListTaskParams, recordChannel chan TaskrouterV1Task, errorChannel chan error) { curRecord := 1 for response != nil { @@ -343,7 +374,7 @@ func (c *ApiService) streamTask(response *ListTaskResponse, params *ListTaskPara } } - record, err := client.GetNext(c.baseURL, response, c.getNextListTaskResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListTaskResponse) if err != nil { errorChannel <- err break @@ -358,11 +389,11 @@ func (c *ApiService) streamTask(response *ListTaskResponse, params *ListTaskPara close(errorChannel) } -func (c *ApiService) getNextListTaskResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListTaskResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -419,6 +450,11 @@ func (params *UpdateTaskParams) SetTaskChannel(TaskChannel string) *UpdateTaskPa // func (c *ApiService) UpdateTask(WorkspaceSid string, Sid string, params *UpdateTaskParams) (*TaskrouterV1Task, error) { + return c.UpdateTaskWithCtx(context.TODO(), WorkspaceSid, Sid, params) +} + +// +func (c *ApiService) UpdateTaskWithCtx(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) @@ -446,7 +482,7 @@ func (c *ApiService) UpdateTask(WorkspaceSid string, Sid string, params *UpdateT headers["If-Match"] = *params.IfMatch } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 722512ef3..22ffd4cc4 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" @@ -25,6 +26,11 @@ import ( // func (c *ApiService) FetchTaskReservation(WorkspaceSid string, TaskSid string, Sid string) (*TaskrouterV1TaskReservation, error) { + return c.FetchTaskReservationWithCtx(context.TODO(), WorkspaceSid, TaskSid, Sid) +} + +// +func (c *ApiService) FetchTaskReservationWithCtx(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) @@ -33,7 +39,7 @@ func (c *ApiService) FetchTaskReservation(WorkspaceSid string, TaskSid string, S data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -73,6 +79,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.PageTaskReservationWithCtx(context.TODO(), WorkspaceSid, TaskSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of TaskReservation records from the API. Request is executed immediately. +func (c *ApiService) PageTaskReservationWithCtx(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) @@ -95,7 +106,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -112,7 +123,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.ListTaskReservationWithCtx(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) ListTaskReservationWithCtx(ctx context.Context, WorkspaceSid string, TaskSid string, params *ListTaskReservationParams) ([]TaskrouterV1TaskReservation, error) { + response, errors := c.StreamTaskReservationWithCtx(ctx, WorkspaceSid, TaskSid, params) records := make([]TaskrouterV1TaskReservation, 0) for record := range response { @@ -128,6 +144,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.StreamTaskReservationWithCtx(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) StreamTaskReservationWithCtx(ctx context.Context, WorkspaceSid string, TaskSid string, params *ListTaskReservationParams) (chan TaskrouterV1TaskReservation, chan error) { if params == nil { params = &ListTaskReservationParams{} } @@ -136,19 +157,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.PageTaskReservationWithCtx(ctx, WorkspaceSid, TaskSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamTaskReservation(response, params, recordChannel, errorChannel) + go c.streamTaskReservation(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) streamTaskReservation(ctx context.Context, response *ListTaskReservationResponse, params *ListTaskReservationParams, recordChannel chan TaskrouterV1TaskReservation, errorChannel chan error) { curRecord := 1 for response != nil { @@ -163,7 +184,7 @@ func (c *ApiService) streamTaskReservation(response *ListTaskReservationResponse } } - record, err := client.GetNext(c.baseURL, response, c.getNextListTaskReservationResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListTaskReservationResponse) if err != nil { errorChannel <- err break @@ -178,11 +199,11 @@ func (c *ApiService) streamTaskReservation(response *ListTaskReservationResponse close(errorChannel) } -func (c *ApiService) getNextListTaskReservationResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListTaskReservationResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -527,6 +548,11 @@ func (params *UpdateTaskReservationParams) SetBeepOnCustomerEntrance(BeepOnCusto // func (c *ApiService) UpdateTaskReservation(WorkspaceSid string, TaskSid string, Sid string, params *UpdateTaskReservationParams) (*TaskrouterV1TaskReservation, error) { + return c.UpdateTaskReservationWithCtx(context.TODO(), WorkspaceSid, TaskSid, Sid, params) +} + +// +func (c *ApiService) UpdateTaskReservationWithCtx(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) @@ -705,7 +731,7 @@ func (c *ApiService) UpdateTaskReservation(WorkspaceSid string, TaskSid string, headers["If-Match"] = *params.IfMatch } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 4ea65074a..ea45b2356 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" @@ -48,6 +49,11 @@ func (params *CreateWorkerParams) SetAttributes(Attributes string) *CreateWorker // func (c *ApiService) CreateWorker(WorkspaceSid string, params *CreateWorkerParams) (*TaskrouterV1Worker, error) { + return c.CreateWorkerWithCtx(context.TODO(), WorkspaceSid, params) +} + +// +func (c *ApiService) CreateWorkerWithCtx(ctx context.Context, WorkspaceSid string, params *CreateWorkerParams) (*TaskrouterV1Worker, error) { path := "/v1/Workspaces/{WorkspaceSid}/Workers" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) @@ -64,7 +70,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -92,6 +98,11 @@ func (params *DeleteWorkerParams) SetIfMatch(IfMatch string) *DeleteWorkerParams // func (c *ApiService) DeleteWorker(WorkspaceSid string, Sid string, params *DeleteWorkerParams) error { + return c.DeleteWorkerWithCtx(context.TODO(), WorkspaceSid, Sid, params) +} + +// +func (c *ApiService) DeleteWorkerWithCtx(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) @@ -103,7 +114,7 @@ func (c *ApiService) DeleteWorker(WorkspaceSid string, Sid string, params *Delet headers["If-Match"] = *params.IfMatch } - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -115,6 +126,11 @@ func (c *ApiService) DeleteWorker(WorkspaceSid string, Sid string, params *Delet // func (c *ApiService) FetchWorker(WorkspaceSid string, Sid string) (*TaskrouterV1Worker, error) { + return c.FetchWorkerWithCtx(context.TODO(), WorkspaceSid, Sid) +} + +// +func (c *ApiService) FetchWorkerWithCtx(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) @@ -122,7 +138,7 @@ func (c *ApiService) FetchWorker(WorkspaceSid string, Sid string) (*TaskrouterV1 data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -198,6 +214,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.PageWorkerWithCtx(context.TODO(), WorkspaceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Worker records from the API. Request is executed immediately. +func (c *ApiService) PageWorkerWithCtx(ctx context.Context, WorkspaceSid string, params *ListWorkerParams, pageToken, pageNumber string) (*ListWorkerResponse, error) { path := "/v1/Workspaces/{WorkspaceSid}/Workers" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) @@ -237,7 +258,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -254,7 +275,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.ListWorkerWithCtx(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) ListWorkerWithCtx(ctx context.Context, WorkspaceSid string, params *ListWorkerParams) ([]TaskrouterV1Worker, error) { + response, errors := c.StreamWorkerWithCtx(ctx, WorkspaceSid, params) records := make([]TaskrouterV1Worker, 0) for record := range response { @@ -270,6 +296,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.StreamWorkerWithCtx(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) StreamWorkerWithCtx(ctx context.Context, WorkspaceSid string, params *ListWorkerParams) (chan TaskrouterV1Worker, chan error) { if params == nil { params = &ListWorkerParams{} } @@ -278,19 +309,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.PageWorkerWithCtx(ctx, WorkspaceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamWorker(response, params, recordChannel, errorChannel) + go c.streamWorker(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) streamWorker(ctx context.Context, response *ListWorkerResponse, params *ListWorkerParams, recordChannel chan TaskrouterV1Worker, errorChannel chan error) { curRecord := 1 for response != nil { @@ -305,7 +336,7 @@ func (c *ApiService) streamWorker(response *ListWorkerResponse, params *ListWork } } - record, err := client.GetNext(c.baseURL, response, c.getNextListWorkerResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListWorkerResponse) if err != nil { errorChannel <- err break @@ -320,11 +351,11 @@ func (c *ApiService) streamWorker(response *ListWorkerResponse, params *ListWork close(errorChannel) } -func (c *ApiService) getNextListWorkerResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListWorkerResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -375,6 +406,11 @@ func (params *UpdateWorkerParams) SetRejectPendingReservations(RejectPendingRese // func (c *ApiService) UpdateWorker(WorkspaceSid string, Sid string, params *UpdateWorkerParams) (*TaskrouterV1Worker, error) { + return c.UpdateWorkerWithCtx(context.TODO(), WorkspaceSid, Sid, params) +} + +// +func (c *ApiService) UpdateWorkerWithCtx(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) @@ -399,7 +435,7 @@ func (c *ApiService) UpdateWorker(WorkspaceSid string, Sid string, params *Updat headers["If-Match"] = *params.IfMatch } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 d6e72fafb..e9476d09b 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" @@ -25,6 +26,11 @@ import ( // func (c *ApiService) FetchWorkerChannel(WorkspaceSid string, WorkerSid string, Sid string) (*TaskrouterV1WorkerChannel, error) { + return c.FetchWorkerChannelWithCtx(context.TODO(), WorkspaceSid, WorkerSid, Sid) +} + +// +func (c *ApiService) FetchWorkerChannelWithCtx(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) @@ -33,7 +39,7 @@ func (c *ApiService) FetchWorkerChannel(WorkspaceSid string, WorkerSid string, S data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -67,6 +73,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.PageWorkerChannelWithCtx(context.TODO(), WorkspaceSid, WorkerSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of WorkerChannel records from the API. Request is executed immediately. +func (c *ApiService) PageWorkerChannelWithCtx(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) @@ -86,7 +97,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -103,7 +114,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.ListWorkerChannelWithCtx(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) ListWorkerChannelWithCtx(ctx context.Context, WorkspaceSid string, WorkerSid string, params *ListWorkerChannelParams) ([]TaskrouterV1WorkerChannel, error) { + response, errors := c.StreamWorkerChannelWithCtx(ctx, WorkspaceSid, WorkerSid, params) records := make([]TaskrouterV1WorkerChannel, 0) for record := range response { @@ -119,6 +135,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.StreamWorkerChannelWithCtx(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) StreamWorkerChannelWithCtx(ctx context.Context, WorkspaceSid string, WorkerSid string, params *ListWorkerChannelParams) (chan TaskrouterV1WorkerChannel, chan error) { if params == nil { params = &ListWorkerChannelParams{} } @@ -127,19 +148,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.PageWorkerChannelWithCtx(ctx, WorkspaceSid, WorkerSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamWorkerChannel(response, params, recordChannel, errorChannel) + go c.streamWorkerChannel(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) streamWorkerChannel(ctx context.Context, response *ListWorkerChannelResponse, params *ListWorkerChannelParams, recordChannel chan TaskrouterV1WorkerChannel, errorChannel chan error) { curRecord := 1 for response != nil { @@ -154,7 +175,7 @@ func (c *ApiService) streamWorkerChannel(response *ListWorkerChannelResponse, pa } } - record, err := client.GetNext(c.baseURL, response, c.getNextListWorkerChannelResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListWorkerChannelResponse) if err != nil { errorChannel <- err break @@ -169,11 +190,11 @@ func (c *ApiService) streamWorkerChannel(response *ListWorkerChannelResponse, pa close(errorChannel) } -func (c *ApiService) getNextListWorkerChannelResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListWorkerChannelResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -206,6 +227,11 @@ func (params *UpdateWorkerChannelParams) SetAvailable(Available bool) *UpdateWor // func (c *ApiService) UpdateWorkerChannel(WorkspaceSid string, WorkerSid string, Sid string, params *UpdateWorkerChannelParams) (*TaskrouterV1WorkerChannel, error) { + return c.UpdateWorkerChannelWithCtx(context.TODO(), WorkspaceSid, WorkerSid, Sid, params) +} + +// +func (c *ApiService) UpdateWorkerChannelWithCtx(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) @@ -221,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.Post(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 a6bdc0626..b4059b7c0 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" @@ -53,6 +54,11 @@ func (params *FetchWorkersCumulativeStatisticsParams) SetTaskChannel(TaskChannel // func (c *ApiService) FetchWorkersCumulativeStatistics(WorkspaceSid string, params *FetchWorkersCumulativeStatisticsParams) (*TaskrouterV1WorkersCumulativeStatistics, error) { + return c.FetchWorkersCumulativeStatisticsWithCtx(context.TODO(), WorkspaceSid, params) +} + +// +func (c *ApiService) FetchWorkersCumulativeStatisticsWithCtx(ctx context.Context, WorkspaceSid string, params *FetchWorkersCumulativeStatisticsParams) (*TaskrouterV1WorkersCumulativeStatistics, error) { path := "/v1/Workspaces/{WorkspaceSid}/Workers/CumulativeStatistics" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) @@ -72,7 +78,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.Get(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 7fa3f4fe4..70e15a2ed 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" @@ -33,6 +34,11 @@ func (params *FetchWorkersRealTimeStatisticsParams) SetTaskChannel(TaskChannel s // func (c *ApiService) FetchWorkersRealTimeStatistics(WorkspaceSid string, params *FetchWorkersRealTimeStatisticsParams) (*TaskrouterV1WorkersRealTimeStatistics, error) { + return c.FetchWorkersRealTimeStatisticsWithCtx(context.TODO(), WorkspaceSid, params) +} + +// +func (c *ApiService) FetchWorkersRealTimeStatisticsWithCtx(ctx context.Context, WorkspaceSid string, params *FetchWorkersRealTimeStatisticsParams) (*TaskrouterV1WorkersRealTimeStatistics, error) { path := "/v1/Workspaces/{WorkspaceSid}/Workers/RealTimeStatistics" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) @@ -43,7 +49,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.Get(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 b4da3e341..32f434e71 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" @@ -25,6 +26,11 @@ import ( // func (c *ApiService) FetchWorkerReservation(WorkspaceSid string, WorkerSid string, Sid string) (*TaskrouterV1WorkerReservation, error) { + return c.FetchWorkerReservationWithCtx(context.TODO(), WorkspaceSid, WorkerSid, Sid) +} + +// +func (c *ApiService) FetchWorkerReservationWithCtx(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) @@ -33,7 +39,7 @@ func (c *ApiService) FetchWorkerReservation(WorkspaceSid string, WorkerSid strin data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -73,6 +79,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.PageWorkerReservationWithCtx(context.TODO(), WorkspaceSid, WorkerSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of WorkerReservation records from the API. Request is executed immediately. +func (c *ApiService) PageWorkerReservationWithCtx(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) @@ -95,7 +106,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -112,7 +123,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.ListWorkerReservationWithCtx(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) ListWorkerReservationWithCtx(ctx context.Context, WorkspaceSid string, WorkerSid string, params *ListWorkerReservationParams) ([]TaskrouterV1WorkerReservation, error) { + response, errors := c.StreamWorkerReservationWithCtx(ctx, WorkspaceSid, WorkerSid, params) records := make([]TaskrouterV1WorkerReservation, 0) for record := range response { @@ -128,6 +144,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.StreamWorkerReservationWithCtx(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) StreamWorkerReservationWithCtx(ctx context.Context, WorkspaceSid string, WorkerSid string, params *ListWorkerReservationParams) (chan TaskrouterV1WorkerReservation, chan error) { if params == nil { params = &ListWorkerReservationParams{} } @@ -136,19 +157,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.PageWorkerReservationWithCtx(ctx, WorkspaceSid, WorkerSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamWorkerReservation(response, params, recordChannel, errorChannel) + go c.streamWorkerReservation(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) streamWorkerReservation(ctx context.Context, response *ListWorkerReservationResponse, params *ListWorkerReservationParams, recordChannel chan TaskrouterV1WorkerReservation, errorChannel chan error) { curRecord := 1 for response != nil { @@ -163,7 +184,7 @@ func (c *ApiService) streamWorkerReservation(response *ListWorkerReservationResp } } - record, err := client.GetNext(c.baseURL, response, c.getNextListWorkerReservationResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListWorkerReservationResponse) if err != nil { errorChannel <- err break @@ -178,11 +199,11 @@ func (c *ApiService) streamWorkerReservation(response *ListWorkerReservationResp close(errorChannel) } -func (c *ApiService) getNextListWorkerReservationResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListWorkerReservationResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -515,6 +536,11 @@ func (params *UpdateWorkerReservationParams) SetBeepOnCustomerEntrance(BeepOnCus // func (c *ApiService) UpdateWorkerReservation(WorkspaceSid string, WorkerSid string, Sid string, params *UpdateWorkerReservationParams) (*TaskrouterV1WorkerReservation, error) { + return c.UpdateWorkerReservationWithCtx(context.TODO(), WorkspaceSid, WorkerSid, Sid, params) +} + +// +func (c *ApiService) UpdateWorkerReservationWithCtx(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) @@ -687,7 +713,7 @@ func (c *ApiService) UpdateWorkerReservation(WorkspaceSid string, WorkerSid stri headers["If-Match"] = *params.IfMatch } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 6d2d96495..a868f2e87 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" @@ -53,6 +54,11 @@ func (params *FetchWorkerInstanceStatisticsParams) SetTaskChannel(TaskChannel st // func (c *ApiService) FetchWorkerInstanceStatistics(WorkspaceSid string, WorkerSid string, params *FetchWorkerInstanceStatisticsParams) (*TaskrouterV1WorkerInstanceStatistics, error) { + return c.FetchWorkerInstanceStatisticsWithCtx(context.TODO(), WorkspaceSid, WorkerSid, params) +} + +// +func (c *ApiService) FetchWorkerInstanceStatisticsWithCtx(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) @@ -73,7 +79,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -137,6 +143,11 @@ func (params *FetchWorkerStatisticsParams) SetTaskChannel(TaskChannel string) *F // func (c *ApiService) FetchWorkerStatistics(WorkspaceSid string, params *FetchWorkerStatisticsParams) (*TaskrouterV1WorkerStatistics, error) { + return c.FetchWorkerStatisticsWithCtx(context.TODO(), WorkspaceSid, params) +} + +// +func (c *ApiService) FetchWorkerStatisticsWithCtx(ctx context.Context, WorkspaceSid string, params *FetchWorkerStatisticsParams) (*TaskrouterV1WorkerStatistics, error) { path := "/v1/Workspaces/{WorkspaceSid}/Workers/Statistics" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) @@ -165,7 +176,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.Get(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 e7dadffd7..3370bfb55 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" @@ -60,6 +61,11 @@ func (params *CreateWorkflowParams) SetTaskReservationTimeout(TaskReservationTim // func (c *ApiService) CreateWorkflow(WorkspaceSid string, params *CreateWorkflowParams) (*TaskrouterV1Workflow, error) { + return c.CreateWorkflowWithCtx(context.TODO(), WorkspaceSid, params) +} + +// +func (c *ApiService) CreateWorkflowWithCtx(ctx context.Context, WorkspaceSid string, params *CreateWorkflowParams) (*TaskrouterV1Workflow, error) { path := "/v1/Workspaces/{WorkspaceSid}/Workflows" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) @@ -82,7 +88,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -99,6 +105,11 @@ func (c *ApiService) CreateWorkflow(WorkspaceSid string, params *CreateWorkflowP // func (c *ApiService) DeleteWorkflow(WorkspaceSid string, Sid string) error { + return c.DeleteWorkflowWithCtx(context.TODO(), WorkspaceSid, Sid) +} + +// +func (c *ApiService) DeleteWorkflowWithCtx(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) @@ -106,7 +117,7 @@ func (c *ApiService) DeleteWorkflow(WorkspaceSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -118,6 +129,11 @@ func (c *ApiService) DeleteWorkflow(WorkspaceSid string, Sid string) error { // func (c *ApiService) FetchWorkflow(WorkspaceSid string, Sid string) (*TaskrouterV1Workflow, error) { + return c.FetchWorkflowWithCtx(context.TODO(), WorkspaceSid, Sid) +} + +// +func (c *ApiService) FetchWorkflowWithCtx(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) @@ -125,7 +141,7 @@ func (c *ApiService) FetchWorkflow(WorkspaceSid string, Sid string) (*Taskrouter data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -165,6 +181,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.PageWorkflowWithCtx(context.TODO(), WorkspaceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Workflow records from the API. Request is executed immediately. +func (c *ApiService) PageWorkflowWithCtx(ctx context.Context, WorkspaceSid string, params *ListWorkflowParams, pageToken, pageNumber string) (*ListWorkflowResponse, error) { path := "/v1/Workspaces/{WorkspaceSid}/Workflows" path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1) @@ -186,7 +207,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -203,7 +224,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.ListWorkflowWithCtx(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) ListWorkflowWithCtx(ctx context.Context, WorkspaceSid string, params *ListWorkflowParams) ([]TaskrouterV1Workflow, error) { + response, errors := c.StreamWorkflowWithCtx(ctx, WorkspaceSid, params) records := make([]TaskrouterV1Workflow, 0) for record := range response { @@ -219,6 +245,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.StreamWorkflowWithCtx(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) StreamWorkflowWithCtx(ctx context.Context, WorkspaceSid string, params *ListWorkflowParams) (chan TaskrouterV1Workflow, chan error) { if params == nil { params = &ListWorkflowParams{} } @@ -227,19 +258,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.PageWorkflowWithCtx(ctx, WorkspaceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamWorkflow(response, params, recordChannel, errorChannel) + go c.streamWorkflow(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) streamWorkflow(ctx context.Context, response *ListWorkflowResponse, params *ListWorkflowParams, recordChannel chan TaskrouterV1Workflow, errorChannel chan error) { curRecord := 1 for response != nil { @@ -254,7 +285,7 @@ func (c *ApiService) streamWorkflow(response *ListWorkflowResponse, params *List } } - record, err := client.GetNext(c.baseURL, response, c.getNextListWorkflowResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListWorkflowResponse) if err != nil { errorChannel <- err break @@ -269,11 +300,11 @@ func (c *ApiService) streamWorkflow(response *ListWorkflowResponse, params *List close(errorChannel) } -func (c *ApiService) getNextListWorkflowResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListWorkflowResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -330,6 +361,11 @@ func (params *UpdateWorkflowParams) SetReEvaluateTasks(ReEvaluateTasks string) * // func (c *ApiService) UpdateWorkflow(WorkspaceSid string, Sid string, params *UpdateWorkflowParams) (*TaskrouterV1Workflow, error) { + return c.UpdateWorkflowWithCtx(context.TODO(), WorkspaceSid, Sid, params) +} + +// +func (c *ApiService) UpdateWorkflowWithCtx(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) @@ -356,7 +392,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.Post(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 ee6ebb429..ea9e9aa68 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" @@ -59,6 +60,11 @@ func (params *FetchWorkflowCumulativeStatisticsParams) SetSplitByWaitTime(SplitB // func (c *ApiService) FetchWorkflowCumulativeStatistics(WorkspaceSid string, WorkflowSid string, params *FetchWorkflowCumulativeStatisticsParams) (*TaskrouterV1WorkflowCumulativeStatistics, error) { + return c.FetchWorkflowCumulativeStatisticsWithCtx(context.TODO(), WorkspaceSid, WorkflowSid, params) +} + +// +func (c *ApiService) FetchWorkflowCumulativeStatisticsWithCtx(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) @@ -82,7 +88,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.Get(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 5fb9ab9aa..f4ac53a1e 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" @@ -33,6 +34,11 @@ func (params *FetchWorkflowRealTimeStatisticsParams) SetTaskChannel(TaskChannel // func (c *ApiService) FetchWorkflowRealTimeStatistics(WorkspaceSid string, WorkflowSid string, params *FetchWorkflowRealTimeStatisticsParams) (*TaskrouterV1WorkflowRealTimeStatistics, error) { + return c.FetchWorkflowRealTimeStatisticsWithCtx(context.TODO(), WorkspaceSid, WorkflowSid, params) +} + +// +func (c *ApiService) FetchWorkflowRealTimeStatisticsWithCtx(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) @@ -44,7 +50,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.Get(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 0c20502d5..ea8c3f813 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" @@ -59,6 +60,11 @@ func (params *FetchWorkflowStatisticsParams) SetSplitByWaitTime(SplitByWaitTime // func (c *ApiService) FetchWorkflowStatistics(WorkspaceSid string, WorkflowSid string, params *FetchWorkflowStatisticsParams) (*TaskrouterV1WorkflowStatistics, error) { + return c.FetchWorkflowStatisticsWithCtx(context.TODO(), WorkspaceSid, WorkflowSid, params) +} + +// +func (c *ApiService) FetchWorkflowStatisticsWithCtx(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) @@ -82,7 +88,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.Get(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 9fcddb260..f8d0eb0b2 100644 --- a/rest/trunking/v1/api_service.go +++ b/rest/trunking/v1/api_service.go @@ -20,10 +20,14 @@ import ( type ApiService struct { baseURL string - requestHandler *twilio.RequestHandler + requestHandler *twilio.RequestHandlerWithCtx } func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { + return NewApiServiceWithCtx(twilio.UpgradeRequestHandler(requestHandler)) +} + +func NewApiServiceWithCtx(requestHandler *twilio.RequestHandlerWithCtx) *ApiService { return &ApiService{ requestHandler: requestHandler, baseURL: "https://trunking.twilio.com", @@ -33,3 +37,7 @@ func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { func NewApiServiceWithClient(client twilio.BaseClient) *ApiService { return NewApiService(twilio.NewRequestHandler(client)) } + +func NewApiServiceWithClientWithCtx(client twilio.BaseClientWithCtx) *ApiService { + return NewApiServiceWithCtx(twilio.NewRequestHandlerWithCtx(client)) +} diff --git a/rest/trunking/v1/trunks.go b/rest/trunking/v1/trunks.go index 45a5e80ac..85c90a016 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" @@ -78,6 +79,11 @@ func (params *CreateTrunkParams) SetTransferCallerId(TransferCallerId string) *C // func (c *ApiService) CreateTrunk(params *CreateTrunkParams) (*TrunkingV1Trunk, error) { + return c.CreateTrunkWithCtx(context.TODO(), params) +} + +// +func (c *ApiService) CreateTrunkWithCtx(ctx context.Context, params *CreateTrunkParams) (*TrunkingV1Trunk, error) { path := "/v1/Trunks" data := url.Values{} @@ -108,7 +114,7 @@ func (c *ApiService) CreateTrunk(params *CreateTrunkParams) (*TrunkingV1Trunk, e data.Set("TransferCallerId", *params.TransferCallerId) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -125,13 +131,18 @@ func (c *ApiService) CreateTrunk(params *CreateTrunkParams) (*TrunkingV1Trunk, e // func (c *ApiService) DeleteTrunk(Sid string) error { + return c.DeleteTrunkWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) DeleteTrunkWithCtx(ctx context.Context, Sid string) error { path := "/v1/Trunks/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -143,13 +154,18 @@ func (c *ApiService) DeleteTrunk(Sid string) error { // func (c *ApiService) FetchTrunk(Sid string) (*TrunkingV1Trunk, error) { + return c.FetchTrunkWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) FetchTrunkWithCtx(ctx context.Context, Sid string) (*TrunkingV1Trunk, error) { path := "/v1/Trunks/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -183,6 +199,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.PageTrunkWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Trunk records from the API. Request is executed immediately. +func (c *ApiService) PageTrunkWithCtx(ctx context.Context, params *ListTrunkParams, pageToken, pageNumber string) (*ListTrunkResponse, error) { path := "/v1/Trunks" data := url.Values{} @@ -199,7 +220,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -216,7 +237,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.ListTrunkWithCtx(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) ListTrunkWithCtx(ctx context.Context, params *ListTrunkParams) ([]TrunkingV1Trunk, error) { + response, errors := c.StreamTrunkWithCtx(ctx, params) records := make([]TrunkingV1Trunk, 0) for record := range response { @@ -232,6 +258,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.StreamTrunkWithCtx(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) StreamTrunkWithCtx(ctx context.Context, params *ListTrunkParams) (chan TrunkingV1Trunk, chan error) { if params == nil { params = &ListTrunkParams{} } @@ -240,19 +271,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.PageTrunkWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamTrunk(response, params, recordChannel, errorChannel) + go c.streamTrunk(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) streamTrunk(ctx context.Context, response *ListTrunkResponse, params *ListTrunkParams, recordChannel chan TrunkingV1Trunk, errorChannel chan error) { curRecord := 1 for response != nil { @@ -267,7 +298,7 @@ func (c *ApiService) streamTrunk(response *ListTrunkResponse, params *ListTrunkP } } - record, err := client.GetNext(c.baseURL, response, c.getNextListTrunkResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListTrunkResponse) if err != nil { errorChannel <- err break @@ -282,11 +313,11 @@ func (c *ApiService) streamTrunk(response *ListTrunkResponse, params *ListTrunkP close(errorChannel) } -func (c *ApiService) getNextListTrunkResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListTrunkResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -355,6 +386,11 @@ func (params *UpdateTrunkParams) SetTransferCallerId(TransferCallerId string) *U // func (c *ApiService) UpdateTrunk(Sid string, params *UpdateTrunkParams) (*TrunkingV1Trunk, error) { + return c.UpdateTrunkWithCtx(context.TODO(), Sid, params) +} + +// +func (c *ApiService) UpdateTrunkWithCtx(ctx context.Context, Sid string, params *UpdateTrunkParams) (*TrunkingV1Trunk, error) { path := "/v1/Trunks/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -386,7 +422,7 @@ func (c *ApiService) UpdateTrunk(Sid string, params *UpdateTrunkParams) (*Trunki data.Set("TransferCallerId", *params.TransferCallerId) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 25b8c0f66..fb422c017 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" @@ -36,6 +37,11 @@ func (params *CreateCredentialListParams) SetCredentialListSid(CredentialListSid // func (c *ApiService) CreateCredentialList(TrunkSid string, params *CreateCredentialListParams) (*TrunkingV1CredentialList, error) { + return c.CreateCredentialListWithCtx(context.TODO(), TrunkSid, params) +} + +// +func (c *ApiService) CreateCredentialListWithCtx(ctx context.Context, TrunkSid string, params *CreateCredentialListParams) (*TrunkingV1CredentialList, error) { path := "/v1/Trunks/{TrunkSid}/CredentialLists" path = strings.Replace(path, "{"+"TrunkSid"+"}", TrunkSid, -1) @@ -46,7 +52,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -63,6 +69,11 @@ func (c *ApiService) CreateCredentialList(TrunkSid string, params *CreateCredent // func (c *ApiService) DeleteCredentialList(TrunkSid string, Sid string) error { + return c.DeleteCredentialListWithCtx(context.TODO(), TrunkSid, Sid) +} + +// +func (c *ApiService) DeleteCredentialListWithCtx(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) @@ -70,7 +81,7 @@ func (c *ApiService) DeleteCredentialList(TrunkSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -82,6 +93,11 @@ func (c *ApiService) DeleteCredentialList(TrunkSid string, Sid string) error { // func (c *ApiService) FetchCredentialList(TrunkSid string, Sid string) (*TrunkingV1CredentialList, error) { + return c.FetchCredentialListWithCtx(context.TODO(), TrunkSid, Sid) +} + +// +func (c *ApiService) FetchCredentialListWithCtx(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) @@ -89,7 +105,7 @@ func (c *ApiService) FetchCredentialList(TrunkSid string, Sid string) (*Trunking data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -123,6 +139,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.PageCredentialListWithCtx(context.TODO(), TrunkSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of CredentialList records from the API. Request is executed immediately. +func (c *ApiService) PageCredentialListWithCtx(ctx context.Context, TrunkSid string, params *ListCredentialListParams, pageToken, pageNumber string) (*ListCredentialListResponse, error) { path := "/v1/Trunks/{TrunkSid}/CredentialLists" path = strings.Replace(path, "{"+"TrunkSid"+"}", TrunkSid, -1) @@ -141,7 +162,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -158,7 +179,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.ListCredentialListWithCtx(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) ListCredentialListWithCtx(ctx context.Context, TrunkSid string, params *ListCredentialListParams) ([]TrunkingV1CredentialList, error) { + response, errors := c.StreamCredentialListWithCtx(ctx, TrunkSid, params) records := make([]TrunkingV1CredentialList, 0) for record := range response { @@ -174,6 +200,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.StreamCredentialListWithCtx(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) StreamCredentialListWithCtx(ctx context.Context, TrunkSid string, params *ListCredentialListParams) (chan TrunkingV1CredentialList, chan error) { if params == nil { params = &ListCredentialListParams{} } @@ -182,19 +213,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.PageCredentialListWithCtx(ctx, TrunkSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamCredentialList(response, params, recordChannel, errorChannel) + go c.streamCredentialList(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) streamCredentialList(ctx context.Context, response *ListCredentialListResponse, params *ListCredentialListParams, recordChannel chan TrunkingV1CredentialList, errorChannel chan error) { curRecord := 1 for response != nil { @@ -209,7 +240,7 @@ func (c *ApiService) streamCredentialList(response *ListCredentialListResponse, } } - record, err := client.GetNext(c.baseURL, response, c.getNextListCredentialListResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListCredentialListResponse) if err != nil { errorChannel <- err break @@ -224,11 +255,11 @@ func (c *ApiService) streamCredentialList(response *ListCredentialListResponse, close(errorChannel) } -func (c *ApiService) getNextListCredentialListResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListCredentialListResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 3ab9fdf5a..c73a2e9df 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,11 @@ 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.CreateIpAccessControlListWithCtx(context.TODO(), TrunkSid, params) +} + +// Associate an IP Access Control List with a Trunk +func (c *ApiService) CreateIpAccessControlListWithCtx(ctx context.Context, TrunkSid string, params *CreateIpAccessControlListParams) (*TrunkingV1IpAccessControlList, error) { path := "/v1/Trunks/{TrunkSid}/IpAccessControlLists" path = strings.Replace(path, "{"+"TrunkSid"+"}", TrunkSid, -1) @@ -46,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -63,6 +69,11 @@ 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.DeleteIpAccessControlListWithCtx(context.TODO(), TrunkSid, Sid) +} + +// Remove an associated IP Access Control List from a Trunk +func (c *ApiService) DeleteIpAccessControlListWithCtx(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) @@ -70,7 +81,7 @@ func (c *ApiService) DeleteIpAccessControlList(TrunkSid string, Sid string) erro data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -82,6 +93,11 @@ func (c *ApiService) DeleteIpAccessControlList(TrunkSid string, Sid string) erro // func (c *ApiService) FetchIpAccessControlList(TrunkSid string, Sid string) (*TrunkingV1IpAccessControlList, error) { + return c.FetchIpAccessControlListWithCtx(context.TODO(), TrunkSid, Sid) +} + +// +func (c *ApiService) FetchIpAccessControlListWithCtx(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) @@ -89,7 +105,7 @@ func (c *ApiService) FetchIpAccessControlList(TrunkSid string, Sid string) (*Tru data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -123,6 +139,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.PageIpAccessControlListWithCtx(context.TODO(), TrunkSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of IpAccessControlList records from the API. Request is executed immediately. +func (c *ApiService) PageIpAccessControlListWithCtx(ctx context.Context, TrunkSid string, params *ListIpAccessControlListParams, pageToken, pageNumber string) (*ListIpAccessControlListResponse, error) { path := "/v1/Trunks/{TrunkSid}/IpAccessControlLists" path = strings.Replace(path, "{"+"TrunkSid"+"}", TrunkSid, -1) @@ -141,7 +162,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -158,7 +179,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.ListIpAccessControlListWithCtx(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) ListIpAccessControlListWithCtx(ctx context.Context, TrunkSid string, params *ListIpAccessControlListParams) ([]TrunkingV1IpAccessControlList, error) { + response, errors := c.StreamIpAccessControlListWithCtx(ctx, TrunkSid, params) records := make([]TrunkingV1IpAccessControlList, 0) for record := range response { @@ -174,6 +200,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.StreamIpAccessControlListWithCtx(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) StreamIpAccessControlListWithCtx(ctx context.Context, TrunkSid string, params *ListIpAccessControlListParams) (chan TrunkingV1IpAccessControlList, chan error) { if params == nil { params = &ListIpAccessControlListParams{} } @@ -182,19 +213,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.PageIpAccessControlListWithCtx(ctx, TrunkSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamIpAccessControlList(response, params, recordChannel, errorChannel) + go c.streamIpAccessControlList(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) streamIpAccessControlList(ctx context.Context, response *ListIpAccessControlListResponse, params *ListIpAccessControlListParams, recordChannel chan TrunkingV1IpAccessControlList, errorChannel chan error) { curRecord := 1 for response != nil { @@ -209,7 +240,7 @@ func (c *ApiService) streamIpAccessControlList(response *ListIpAccessControlList } } - record, err := client.GetNext(c.baseURL, response, c.getNextListIpAccessControlListResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListIpAccessControlListResponse) if err != nil { errorChannel <- err break @@ -224,11 +255,11 @@ func (c *ApiService) streamIpAccessControlList(response *ListIpAccessControlList close(errorChannel) } -func (c *ApiService) getNextListIpAccessControlListResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListIpAccessControlListResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 147bdb0e1..f1e5b68c7 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" @@ -60,6 +61,11 @@ func (params *CreateOriginationUrlParams) SetSipUrl(SipUrl string) *CreateOrigin // func (c *ApiService) CreateOriginationUrl(TrunkSid string, params *CreateOriginationUrlParams) (*TrunkingV1OriginationUrl, error) { + return c.CreateOriginationUrlWithCtx(context.TODO(), TrunkSid, params) +} + +// +func (c *ApiService) CreateOriginationUrlWithCtx(ctx context.Context, TrunkSid string, params *CreateOriginationUrlParams) (*TrunkingV1OriginationUrl, error) { path := "/v1/Trunks/{TrunkSid}/OriginationUrls" path = strings.Replace(path, "{"+"TrunkSid"+"}", TrunkSid, -1) @@ -82,7 +88,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -99,6 +105,11 @@ func (c *ApiService) CreateOriginationUrl(TrunkSid string, params *CreateOrigina // func (c *ApiService) DeleteOriginationUrl(TrunkSid string, Sid string) error { + return c.DeleteOriginationUrlWithCtx(context.TODO(), TrunkSid, Sid) +} + +// +func (c *ApiService) DeleteOriginationUrlWithCtx(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) @@ -106,7 +117,7 @@ func (c *ApiService) DeleteOriginationUrl(TrunkSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -118,6 +129,11 @@ func (c *ApiService) DeleteOriginationUrl(TrunkSid string, Sid string) error { // func (c *ApiService) FetchOriginationUrl(TrunkSid string, Sid string) (*TrunkingV1OriginationUrl, error) { + return c.FetchOriginationUrlWithCtx(context.TODO(), TrunkSid, Sid) +} + +// +func (c *ApiService) FetchOriginationUrlWithCtx(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) @@ -125,7 +141,7 @@ func (c *ApiService) FetchOriginationUrl(TrunkSid string, Sid string) (*Trunking data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -159,6 +175,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.PageOriginationUrlWithCtx(context.TODO(), TrunkSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of OriginationUrl records from the API. Request is executed immediately. +func (c *ApiService) PageOriginationUrlWithCtx(ctx context.Context, TrunkSid string, params *ListOriginationUrlParams, pageToken, pageNumber string) (*ListOriginationUrlResponse, error) { path := "/v1/Trunks/{TrunkSid}/OriginationUrls" path = strings.Replace(path, "{"+"TrunkSid"+"}", TrunkSid, -1) @@ -177,7 +198,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -194,7 +215,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.ListOriginationUrlWithCtx(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) ListOriginationUrlWithCtx(ctx context.Context, TrunkSid string, params *ListOriginationUrlParams) ([]TrunkingV1OriginationUrl, error) { + response, errors := c.StreamOriginationUrlWithCtx(ctx, TrunkSid, params) records := make([]TrunkingV1OriginationUrl, 0) for record := range response { @@ -210,6 +236,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.StreamOriginationUrlWithCtx(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) StreamOriginationUrlWithCtx(ctx context.Context, TrunkSid string, params *ListOriginationUrlParams) (chan TrunkingV1OriginationUrl, chan error) { if params == nil { params = &ListOriginationUrlParams{} } @@ -218,19 +249,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.PageOriginationUrlWithCtx(ctx, TrunkSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamOriginationUrl(response, params, recordChannel, errorChannel) + go c.streamOriginationUrl(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) streamOriginationUrl(ctx context.Context, response *ListOriginationUrlResponse, params *ListOriginationUrlParams, recordChannel chan TrunkingV1OriginationUrl, errorChannel chan error) { curRecord := 1 for response != nil { @@ -245,7 +276,7 @@ func (c *ApiService) streamOriginationUrl(response *ListOriginationUrlResponse, } } - record, err := client.GetNext(c.baseURL, response, c.getNextListOriginationUrlResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListOriginationUrlResponse) if err != nil { errorChannel <- err break @@ -260,11 +291,11 @@ func (c *ApiService) streamOriginationUrl(response *ListOriginationUrlResponse, close(errorChannel) } -func (c *ApiService) getNextListOriginationUrlResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListOriginationUrlResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -315,6 +346,11 @@ func (params *UpdateOriginationUrlParams) SetSipUrl(SipUrl string) *UpdateOrigin // func (c *ApiService) UpdateOriginationUrl(TrunkSid string, Sid string, params *UpdateOriginationUrlParams) (*TrunkingV1OriginationUrl, error) { + return c.UpdateOriginationUrlWithCtx(context.TODO(), TrunkSid, Sid, params) +} + +// +func (c *ApiService) UpdateOriginationUrlWithCtx(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) @@ -338,7 +374,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.Post(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 4670e4b37..2460c900d 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" @@ -36,6 +37,11 @@ func (params *CreatePhoneNumberParams) SetPhoneNumberSid(PhoneNumberSid string) // func (c *ApiService) CreatePhoneNumber(TrunkSid string, params *CreatePhoneNumberParams) (*TrunkingV1PhoneNumber, error) { + return c.CreatePhoneNumberWithCtx(context.TODO(), TrunkSid, params) +} + +// +func (c *ApiService) CreatePhoneNumberWithCtx(ctx context.Context, TrunkSid string, params *CreatePhoneNumberParams) (*TrunkingV1PhoneNumber, error) { path := "/v1/Trunks/{TrunkSid}/PhoneNumbers" path = strings.Replace(path, "{"+"TrunkSid"+"}", TrunkSid, -1) @@ -46,7 +52,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -63,6 +69,11 @@ func (c *ApiService) CreatePhoneNumber(TrunkSid string, params *CreatePhoneNumbe // func (c *ApiService) DeletePhoneNumber(TrunkSid string, Sid string) error { + return c.DeletePhoneNumberWithCtx(context.TODO(), TrunkSid, Sid) +} + +// +func (c *ApiService) DeletePhoneNumberWithCtx(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) @@ -70,7 +81,7 @@ func (c *ApiService) DeletePhoneNumber(TrunkSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -82,6 +93,11 @@ func (c *ApiService) DeletePhoneNumber(TrunkSid string, Sid string) error { // func (c *ApiService) FetchPhoneNumber(TrunkSid string, Sid string) (*TrunkingV1PhoneNumber, error) { + return c.FetchPhoneNumberWithCtx(context.TODO(), TrunkSid, Sid) +} + +// +func (c *ApiService) FetchPhoneNumberWithCtx(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) @@ -89,7 +105,7 @@ func (c *ApiService) FetchPhoneNumber(TrunkSid string, Sid string) (*TrunkingV1P data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -123,6 +139,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.PagePhoneNumberWithCtx(context.TODO(), TrunkSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of PhoneNumber records from the API. Request is executed immediately. +func (c *ApiService) PagePhoneNumberWithCtx(ctx context.Context, TrunkSid string, params *ListPhoneNumberParams, pageToken, pageNumber string) (*ListPhoneNumberResponse, error) { path := "/v1/Trunks/{TrunkSid}/PhoneNumbers" path = strings.Replace(path, "{"+"TrunkSid"+"}", TrunkSid, -1) @@ -141,7 +162,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -158,7 +179,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.ListPhoneNumberWithCtx(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) ListPhoneNumberWithCtx(ctx context.Context, TrunkSid string, params *ListPhoneNumberParams) ([]TrunkingV1PhoneNumber, error) { + response, errors := c.StreamPhoneNumberWithCtx(ctx, TrunkSid, params) records := make([]TrunkingV1PhoneNumber, 0) for record := range response { @@ -174,6 +200,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.StreamPhoneNumberWithCtx(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) StreamPhoneNumberWithCtx(ctx context.Context, TrunkSid string, params *ListPhoneNumberParams) (chan TrunkingV1PhoneNumber, chan error) { if params == nil { params = &ListPhoneNumberParams{} } @@ -182,19 +213,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.PagePhoneNumberWithCtx(ctx, TrunkSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamPhoneNumber(response, params, recordChannel, errorChannel) + go c.streamPhoneNumber(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) streamPhoneNumber(ctx context.Context, response *ListPhoneNumberResponse, params *ListPhoneNumberParams, recordChannel chan TrunkingV1PhoneNumber, errorChannel chan error) { curRecord := 1 for response != nil { @@ -209,7 +240,7 @@ func (c *ApiService) streamPhoneNumber(response *ListPhoneNumberResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListPhoneNumberResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListPhoneNumberResponse) if err != nil { errorChannel <- err break @@ -224,11 +255,11 @@ func (c *ApiService) streamPhoneNumber(response *ListPhoneNumberResponse, params close(errorChannel) } -func (c *ApiService) getNextListPhoneNumberResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListPhoneNumberResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 615fd2e51..a8c3a503b 100644 --- a/rest/trunking/v1/trunks_recording.go +++ b/rest/trunking/v1/trunks_recording.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -22,13 +23,18 @@ import ( // func (c *ApiService) FetchRecording(TrunkSid string) (*TrunkingV1Recording, error) { + return c.FetchRecordingWithCtx(context.TODO(), TrunkSid) +} + +// +func (c *ApiService) FetchRecordingWithCtx(ctx context.Context, TrunkSid string) (*TrunkingV1Recording, error) { path := "/v1/Trunks/{TrunkSid}/Recording" path = strings.Replace(path, "{"+"TrunkSid"+"}", TrunkSid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -62,6 +68,11 @@ func (params *UpdateRecordingParams) SetTrim(Trim string) *UpdateRecordingParams // func (c *ApiService) UpdateRecording(TrunkSid string, params *UpdateRecordingParams) (*TrunkingV1Recording, error) { + return c.UpdateRecordingWithCtx(context.TODO(), TrunkSid, params) +} + +// +func (c *ApiService) UpdateRecordingWithCtx(ctx context.Context, TrunkSid string, params *UpdateRecordingParams) (*TrunkingV1Recording, error) { path := "/v1/Trunks/{TrunkSid}/Recording" path = strings.Replace(path, "{"+"TrunkSid"+"}", TrunkSid, -1) @@ -75,7 +86,7 @@ func (c *ApiService) UpdateRecording(TrunkSid string, params *UpdateRecordingPar data.Set("Trim", *params.Trim) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 4811b5e51..0b3f889e1 100644 --- a/rest/trusthub/v1/api_service.go +++ b/rest/trusthub/v1/api_service.go @@ -20,10 +20,14 @@ import ( type ApiService struct { baseURL string - requestHandler *twilio.RequestHandler + requestHandler *twilio.RequestHandlerWithCtx } func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { + return NewApiServiceWithCtx(twilio.UpgradeRequestHandler(requestHandler)) +} + +func NewApiServiceWithCtx(requestHandler *twilio.RequestHandlerWithCtx) *ApiService { return &ApiService{ requestHandler: requestHandler, baseURL: "https://trusthub.twilio.com", @@ -33,3 +37,7 @@ func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { func NewApiServiceWithClient(client twilio.BaseClient) *ApiService { return NewApiService(twilio.NewRequestHandler(client)) } + +func NewApiServiceWithClientWithCtx(client twilio.BaseClientWithCtx) *ApiService { + return NewApiServiceWithCtx(twilio.NewRequestHandlerWithCtx(client)) +} diff --git a/rest/trusthub/v1/customer_profiles.go b/rest/trusthub/v1/customer_profiles.go index f6cf893ca..cd849a9b4 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,11 @@ func (params *CreateCustomerProfileParams) SetStatusCallback(StatusCallback stri // Create a new Customer-Profile. func (c *ApiService) CreateCustomerProfile(params *CreateCustomerProfileParams) (*TrusthubV1CustomerProfile, error) { + return c.CreateCustomerProfileWithCtx(context.TODO(), params) +} + +// Create a new Customer-Profile. +func (c *ApiService) CreateCustomerProfileWithCtx(ctx context.Context, params *CreateCustomerProfileParams) (*TrusthubV1CustomerProfile, error) { path := "/v1/CustomerProfiles" data := url.Values{} @@ -72,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -89,13 +95,18 @@ func (c *ApiService) CreateCustomerProfile(params *CreateCustomerProfileParams) // Delete a specific Customer-Profile. func (c *ApiService) DeleteCustomerProfile(Sid string) error { + return c.DeleteCustomerProfileWithCtx(context.TODO(), Sid) +} + +// Delete a specific Customer-Profile. +func (c *ApiService) DeleteCustomerProfileWithCtx(ctx context.Context, Sid string) error { path := "/v1/CustomerProfiles/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -107,13 +118,18 @@ func (c *ApiService) DeleteCustomerProfile(Sid string) error { // Fetch a specific Customer-Profile instance. func (c *ApiService) FetchCustomerProfile(Sid string) (*TrusthubV1CustomerProfile, error) { + return c.FetchCustomerProfileWithCtx(context.TODO(), Sid) +} + +// Fetch a specific Customer-Profile instance. +func (c *ApiService) FetchCustomerProfileWithCtx(ctx context.Context, Sid string) (*TrusthubV1CustomerProfile, error) { path := "/v1/CustomerProfiles/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -165,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.PageCustomerProfileWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of CustomerProfile records from the API. Request is executed immediately. +func (c *ApiService) PageCustomerProfileWithCtx(ctx context.Context, params *ListCustomerProfileParams, pageToken, pageNumber string) (*ListCustomerProfileResponse, error) { path := "/v1/CustomerProfiles" data := url.Values{} @@ -190,7 +211,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -207,7 +228,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.ListCustomerProfileWithCtx(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) ListCustomerProfileWithCtx(ctx context.Context, params *ListCustomerProfileParams) ([]TrusthubV1CustomerProfile, error) { + response, errors := c.StreamCustomerProfileWithCtx(ctx, params) records := make([]TrusthubV1CustomerProfile, 0) for record := range response { @@ -223,6 +249,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.StreamCustomerProfileWithCtx(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) StreamCustomerProfileWithCtx(ctx context.Context, params *ListCustomerProfileParams) (chan TrusthubV1CustomerProfile, chan error) { if params == nil { params = &ListCustomerProfileParams{} } @@ -231,19 +262,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.PageCustomerProfileWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamCustomerProfile(response, params, recordChannel, errorChannel) + go c.streamCustomerProfile(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) streamCustomerProfile(ctx context.Context, response *ListCustomerProfileResponse, params *ListCustomerProfileParams, recordChannel chan TrusthubV1CustomerProfile, errorChannel chan error) { curRecord := 1 for response != nil { @@ -258,7 +289,7 @@ func (c *ApiService) streamCustomerProfile(response *ListCustomerProfileResponse } } - record, err := client.GetNext(c.baseURL, response, c.getNextListCustomerProfileResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListCustomerProfileResponse) if err != nil { errorChannel <- err break @@ -273,11 +304,11 @@ func (c *ApiService) streamCustomerProfile(response *ListCustomerProfileResponse close(errorChannel) } -func (c *ApiService) getNextListCustomerProfileResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListCustomerProfileResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -322,6 +353,11 @@ 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.UpdateCustomerProfileWithCtx(context.TODO(), Sid, params) +} + +// Updates a Customer-Profile in an account. +func (c *ApiService) UpdateCustomerProfileWithCtx(ctx context.Context, Sid string, params *UpdateCustomerProfileParams) (*TrusthubV1CustomerProfile, error) { path := "/v1/CustomerProfiles/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -341,7 +377,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.Post(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 81f947b6d..7edc1b6ca 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,11 @@ func (params *CreateCustomerProfileChannelEndpointAssignmentParams) SetChannelEn // Create a new Assigned Item. func (c *ApiService) CreateCustomerProfileChannelEndpointAssignment(CustomerProfileSid string, params *CreateCustomerProfileChannelEndpointAssignmentParams) (*TrusthubV1CustomerProfileChannelEndpointAssignment, error) { + return c.CreateCustomerProfileChannelEndpointAssignmentWithCtx(context.TODO(), CustomerProfileSid, params) +} + +// Create a new Assigned Item. +func (c *ApiService) CreateCustomerProfileChannelEndpointAssignmentWithCtx(ctx context.Context, CustomerProfileSid string, params *CreateCustomerProfileChannelEndpointAssignmentParams) (*TrusthubV1CustomerProfileChannelEndpointAssignment, error) { path := "/v1/CustomerProfiles/{CustomerProfileSid}/ChannelEndpointAssignments" path = strings.Replace(path, "{"+"CustomerProfileSid"+"}", CustomerProfileSid, -1) @@ -55,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -72,6 +78,11 @@ func (c *ApiService) CreateCustomerProfileChannelEndpointAssignment(CustomerProf // Remove an Assignment Item Instance. func (c *ApiService) DeleteCustomerProfileChannelEndpointAssignment(CustomerProfileSid string, Sid string) error { + return c.DeleteCustomerProfileChannelEndpointAssignmentWithCtx(context.TODO(), CustomerProfileSid, Sid) +} + +// Remove an Assignment Item Instance. +func (c *ApiService) DeleteCustomerProfileChannelEndpointAssignmentWithCtx(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) @@ -79,7 +90,7 @@ func (c *ApiService) DeleteCustomerProfileChannelEndpointAssignment(CustomerProf data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -91,6 +102,11 @@ func (c *ApiService) DeleteCustomerProfileChannelEndpointAssignment(CustomerProf // Fetch specific Assigned Item Instance. func (c *ApiService) FetchCustomerProfileChannelEndpointAssignment(CustomerProfileSid string, Sid string) (*TrusthubV1CustomerProfileChannelEndpointAssignment, error) { + return c.FetchCustomerProfileChannelEndpointAssignmentWithCtx(context.TODO(), CustomerProfileSid, Sid) +} + +// Fetch specific Assigned Item Instance. +func (c *ApiService) FetchCustomerProfileChannelEndpointAssignmentWithCtx(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) @@ -98,7 +114,7 @@ func (c *ApiService) FetchCustomerProfileChannelEndpointAssignment(CustomerProfi data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -144,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.PageCustomerProfileChannelEndpointAssignmentWithCtx(context.TODO(), CustomerProfileSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of CustomerProfileChannelEndpointAssignment records from the API. Request is executed immediately. +func (c *ApiService) PageCustomerProfileChannelEndpointAssignmentWithCtx(ctx context.Context, CustomerProfileSid string, params *ListCustomerProfileChannelEndpointAssignmentParams, pageToken, pageNumber string) (*ListCustomerProfileChannelEndpointAssignmentResponse, error) { path := "/v1/CustomerProfiles/{CustomerProfileSid}/ChannelEndpointAssignments" path = strings.Replace(path, "{"+"CustomerProfileSid"+"}", CustomerProfileSid, -1) @@ -168,7 +189,7 @@ func (c *ApiService) PageCustomerProfileChannelEndpointAssignment(CustomerProfil data.Set("Page", pageNumber) } - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -185,7 +206,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.ListCustomerProfileChannelEndpointAssignmentWithCtx(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) ListCustomerProfileChannelEndpointAssignmentWithCtx(ctx context.Context, CustomerProfileSid string, params *ListCustomerProfileChannelEndpointAssignmentParams) ([]TrusthubV1CustomerProfileChannelEndpointAssignment, error) { + response, errors := c.StreamCustomerProfileChannelEndpointAssignmentWithCtx(ctx, CustomerProfileSid, params) records := make([]TrusthubV1CustomerProfileChannelEndpointAssignment, 0) for record := range response { @@ -201,6 +227,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.StreamCustomerProfileChannelEndpointAssignmentWithCtx(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) StreamCustomerProfileChannelEndpointAssignmentWithCtx(ctx context.Context, CustomerProfileSid string, params *ListCustomerProfileChannelEndpointAssignmentParams) (chan TrusthubV1CustomerProfileChannelEndpointAssignment, chan error) { if params == nil { params = &ListCustomerProfileChannelEndpointAssignmentParams{} } @@ -209,19 +240,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.PageCustomerProfileChannelEndpointAssignmentWithCtx(ctx, CustomerProfileSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamCustomerProfileChannelEndpointAssignment(response, params, recordChannel, errorChannel) + go c.streamCustomerProfileChannelEndpointAssignment(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) streamCustomerProfileChannelEndpointAssignment(ctx context.Context, response *ListCustomerProfileChannelEndpointAssignmentResponse, params *ListCustomerProfileChannelEndpointAssignmentParams, recordChannel chan TrusthubV1CustomerProfileChannelEndpointAssignment, errorChannel chan error) { curRecord := 1 for response != nil { @@ -236,7 +267,7 @@ func (c *ApiService) streamCustomerProfileChannelEndpointAssignment(response *Li } } - record, err := client.GetNext(c.baseURL, response, c.getNextListCustomerProfileChannelEndpointAssignmentResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListCustomerProfileChannelEndpointAssignmentResponse) if err != nil { errorChannel <- err break @@ -251,11 +282,11 @@ func (c *ApiService) streamCustomerProfileChannelEndpointAssignment(response *Li close(errorChannel) } -func (c *ApiService) getNextListCustomerProfileChannelEndpointAssignmentResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListCustomerProfileChannelEndpointAssignmentResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 e21cc9441..bf967b4b4 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,11 @@ func (params *CreateCustomerProfileEntityAssignmentParams) SetObjectSid(ObjectSi // Create a new Assigned Item. func (c *ApiService) CreateCustomerProfileEntityAssignment(CustomerProfileSid string, params *CreateCustomerProfileEntityAssignmentParams) (*TrusthubV1CustomerProfileEntityAssignment, error) { + return c.CreateCustomerProfileEntityAssignmentWithCtx(context.TODO(), CustomerProfileSid, params) +} + +// Create a new Assigned Item. +func (c *ApiService) CreateCustomerProfileEntityAssignmentWithCtx(ctx context.Context, CustomerProfileSid string, params *CreateCustomerProfileEntityAssignmentParams) (*TrusthubV1CustomerProfileEntityAssignment, error) { path := "/v1/CustomerProfiles/{CustomerProfileSid}/EntityAssignments" path = strings.Replace(path, "{"+"CustomerProfileSid"+"}", CustomerProfileSid, -1) @@ -46,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -63,6 +69,11 @@ func (c *ApiService) CreateCustomerProfileEntityAssignment(CustomerProfileSid st // Remove an Assignment Item Instance. func (c *ApiService) DeleteCustomerProfileEntityAssignment(CustomerProfileSid string, Sid string) error { + return c.DeleteCustomerProfileEntityAssignmentWithCtx(context.TODO(), CustomerProfileSid, Sid) +} + +// Remove an Assignment Item Instance. +func (c *ApiService) DeleteCustomerProfileEntityAssignmentWithCtx(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) @@ -70,7 +81,7 @@ func (c *ApiService) DeleteCustomerProfileEntityAssignment(CustomerProfileSid st data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -82,6 +93,11 @@ func (c *ApiService) DeleteCustomerProfileEntityAssignment(CustomerProfileSid st // Fetch specific Assigned Item Instance. func (c *ApiService) FetchCustomerProfileEntityAssignment(CustomerProfileSid string, Sid string) (*TrusthubV1CustomerProfileEntityAssignment, error) { + return c.FetchCustomerProfileEntityAssignmentWithCtx(context.TODO(), CustomerProfileSid, Sid) +} + +// Fetch specific Assigned Item Instance. +func (c *ApiService) FetchCustomerProfileEntityAssignmentWithCtx(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) @@ -89,7 +105,7 @@ func (c *ApiService) FetchCustomerProfileEntityAssignment(CustomerProfileSid str data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -123,6 +139,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.PageCustomerProfileEntityAssignmentWithCtx(context.TODO(), CustomerProfileSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of CustomerProfileEntityAssignment records from the API. Request is executed immediately. +func (c *ApiService) PageCustomerProfileEntityAssignmentWithCtx(ctx context.Context, CustomerProfileSid string, params *ListCustomerProfileEntityAssignmentParams, pageToken, pageNumber string) (*ListCustomerProfileEntityAssignmentResponse, error) { path := "/v1/CustomerProfiles/{CustomerProfileSid}/EntityAssignments" path = strings.Replace(path, "{"+"CustomerProfileSid"+"}", CustomerProfileSid, -1) @@ -141,7 +162,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -158,7 +179,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.ListCustomerProfileEntityAssignmentWithCtx(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) ListCustomerProfileEntityAssignmentWithCtx(ctx context.Context, CustomerProfileSid string, params *ListCustomerProfileEntityAssignmentParams) ([]TrusthubV1CustomerProfileEntityAssignment, error) { + response, errors := c.StreamCustomerProfileEntityAssignmentWithCtx(ctx, CustomerProfileSid, params) records := make([]TrusthubV1CustomerProfileEntityAssignment, 0) for record := range response { @@ -174,6 +200,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.StreamCustomerProfileEntityAssignmentWithCtx(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) StreamCustomerProfileEntityAssignmentWithCtx(ctx context.Context, CustomerProfileSid string, params *ListCustomerProfileEntityAssignmentParams) (chan TrusthubV1CustomerProfileEntityAssignment, chan error) { if params == nil { params = &ListCustomerProfileEntityAssignmentParams{} } @@ -182,19 +213,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.PageCustomerProfileEntityAssignmentWithCtx(ctx, CustomerProfileSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamCustomerProfileEntityAssignment(response, params, recordChannel, errorChannel) + go c.streamCustomerProfileEntityAssignment(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) streamCustomerProfileEntityAssignment(ctx context.Context, response *ListCustomerProfileEntityAssignmentResponse, params *ListCustomerProfileEntityAssignmentParams, recordChannel chan TrusthubV1CustomerProfileEntityAssignment, errorChannel chan error) { curRecord := 1 for response != nil { @@ -209,7 +240,7 @@ func (c *ApiService) streamCustomerProfileEntityAssignment(response *ListCustome } } - record, err := client.GetNext(c.baseURL, response, c.getNextListCustomerProfileEntityAssignmentResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListCustomerProfileEntityAssignmentResponse) if err != nil { errorChannel <- err break @@ -224,11 +255,11 @@ func (c *ApiService) streamCustomerProfileEntityAssignment(response *ListCustome close(errorChannel) } -func (c *ApiService) getNextListCustomerProfileEntityAssignmentResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListCustomerProfileEntityAssignmentResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 e56546485..1ee49beb8 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,11 @@ func (params *CreateCustomerProfileEvaluationParams) SetPolicySid(PolicySid stri // Create a new Evaluation func (c *ApiService) CreateCustomerProfileEvaluation(CustomerProfileSid string, params *CreateCustomerProfileEvaluationParams) (*TrusthubV1CustomerProfileEvaluation, error) { + return c.CreateCustomerProfileEvaluationWithCtx(context.TODO(), CustomerProfileSid, params) +} + +// Create a new Evaluation +func (c *ApiService) CreateCustomerProfileEvaluationWithCtx(ctx context.Context, CustomerProfileSid string, params *CreateCustomerProfileEvaluationParams) (*TrusthubV1CustomerProfileEvaluation, error) { path := "/v1/CustomerProfiles/{CustomerProfileSid}/Evaluations" path = strings.Replace(path, "{"+"CustomerProfileSid"+"}", CustomerProfileSid, -1) @@ -46,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -63,6 +69,11 @@ func (c *ApiService) CreateCustomerProfileEvaluation(CustomerProfileSid string, // Fetch specific Evaluation Instance. func (c *ApiService) FetchCustomerProfileEvaluation(CustomerProfileSid string, Sid string) (*TrusthubV1CustomerProfileEvaluation, error) { + return c.FetchCustomerProfileEvaluationWithCtx(context.TODO(), CustomerProfileSid, Sid) +} + +// Fetch specific Evaluation Instance. +func (c *ApiService) FetchCustomerProfileEvaluationWithCtx(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) @@ -70,7 +81,7 @@ func (c *ApiService) FetchCustomerProfileEvaluation(CustomerProfileSid string, S data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -104,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.PageCustomerProfileEvaluationWithCtx(context.TODO(), CustomerProfileSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of CustomerProfileEvaluation records from the API. Request is executed immediately. +func (c *ApiService) PageCustomerProfileEvaluationWithCtx(ctx context.Context, CustomerProfileSid string, params *ListCustomerProfileEvaluationParams, pageToken, pageNumber string) (*ListCustomerProfileEvaluationResponse, error) { path := "/v1/CustomerProfiles/{CustomerProfileSid}/Evaluations" path = strings.Replace(path, "{"+"CustomerProfileSid"+"}", CustomerProfileSid, -1) @@ -122,7 +138,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -139,7 +155,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.ListCustomerProfileEvaluationWithCtx(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) ListCustomerProfileEvaluationWithCtx(ctx context.Context, CustomerProfileSid string, params *ListCustomerProfileEvaluationParams) ([]TrusthubV1CustomerProfileEvaluation, error) { + response, errors := c.StreamCustomerProfileEvaluationWithCtx(ctx, CustomerProfileSid, params) records := make([]TrusthubV1CustomerProfileEvaluation, 0) for record := range response { @@ -155,6 +176,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.StreamCustomerProfileEvaluationWithCtx(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) StreamCustomerProfileEvaluationWithCtx(ctx context.Context, CustomerProfileSid string, params *ListCustomerProfileEvaluationParams) (chan TrusthubV1CustomerProfileEvaluation, chan error) { if params == nil { params = &ListCustomerProfileEvaluationParams{} } @@ -163,19 +189,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.PageCustomerProfileEvaluationWithCtx(ctx, CustomerProfileSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamCustomerProfileEvaluation(response, params, recordChannel, errorChannel) + go c.streamCustomerProfileEvaluation(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) streamCustomerProfileEvaluation(ctx context.Context, response *ListCustomerProfileEvaluationResponse, params *ListCustomerProfileEvaluationParams, recordChannel chan TrusthubV1CustomerProfileEvaluation, errorChannel chan error) { curRecord := 1 for response != nil { @@ -190,7 +216,7 @@ func (c *ApiService) streamCustomerProfileEvaluation(response *ListCustomerProfi } } - record, err := client.GetNext(c.baseURL, response, c.getNextListCustomerProfileEvaluationResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListCustomerProfileEvaluationResponse) if err != nil { errorChannel <- err break @@ -205,11 +231,11 @@ func (c *ApiService) streamCustomerProfileEvaluation(response *ListCustomerProfi close(errorChannel) } -func (c *ApiService) getNextListCustomerProfileEvaluationResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListCustomerProfileEvaluationResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 4acde972e..f0f6f799b 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,13 +26,18 @@ import ( // Fetch a specific End-User Type Instance. func (c *ApiService) FetchEndUserType(Sid string) (*TrusthubV1EndUserType, error) { + return c.FetchEndUserTypeWithCtx(context.TODO(), Sid) +} + +// Fetch a specific End-User Type Instance. +func (c *ApiService) FetchEndUserTypeWithCtx(ctx context.Context, Sid string) (*TrusthubV1EndUserType, error) { path := "/v1/EndUserTypes/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -65,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.PageEndUserTypeWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of EndUserType records from the API. Request is executed immediately. +func (c *ApiService) PageEndUserTypeWithCtx(ctx context.Context, params *ListEndUserTypeParams, pageToken, pageNumber string) (*ListEndUserTypeResponse, error) { path := "/v1/EndUserTypes" data := url.Values{} @@ -81,7 +92,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -98,7 +109,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.ListEndUserTypeWithCtx(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) ListEndUserTypeWithCtx(ctx context.Context, params *ListEndUserTypeParams) ([]TrusthubV1EndUserType, error) { + response, errors := c.StreamEndUserTypeWithCtx(ctx, params) records := make([]TrusthubV1EndUserType, 0) for record := range response { @@ -114,6 +130,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.StreamEndUserTypeWithCtx(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) StreamEndUserTypeWithCtx(ctx context.Context, params *ListEndUserTypeParams) (chan TrusthubV1EndUserType, chan error) { if params == nil { params = &ListEndUserTypeParams{} } @@ -122,19 +143,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.PageEndUserTypeWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamEndUserType(response, params, recordChannel, errorChannel) + go c.streamEndUserType(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) streamEndUserType(ctx context.Context, response *ListEndUserTypeResponse, params *ListEndUserTypeParams, recordChannel chan TrusthubV1EndUserType, errorChannel chan error) { curRecord := 1 for response != nil { @@ -149,7 +170,7 @@ func (c *ApiService) streamEndUserType(response *ListEndUserTypeResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListEndUserTypeResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListEndUserTypeResponse) if err != nil { errorChannel <- err break @@ -164,11 +185,11 @@ func (c *ApiService) streamEndUserType(response *ListEndUserTypeResponse, params close(errorChannel) } -func (c *ApiService) getNextListEndUserTypeResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListEndUserTypeResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 47d0b5525..9bda65d9d 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,11 @@ func (params *CreateEndUserParams) SetAttributes(Attributes interface{}) *Create // Create a new End User. func (c *ApiService) CreateEndUser(params *CreateEndUserParams) (*TrusthubV1EndUser, error) { + return c.CreateEndUserWithCtx(context.TODO(), params) +} + +// Create a new End User. +func (c *ApiService) CreateEndUserWithCtx(ctx context.Context, params *CreateEndUserParams) (*TrusthubV1EndUser, error) { path := "/v1/EndUsers" data := url.Values{} @@ -69,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -86,13 +92,18 @@ func (c *ApiService) CreateEndUser(params *CreateEndUserParams) (*TrusthubV1EndU // Delete a specific End User. func (c *ApiService) DeleteEndUser(Sid string) error { + return c.DeleteEndUserWithCtx(context.TODO(), Sid) +} + +// Delete a specific End User. +func (c *ApiService) DeleteEndUserWithCtx(ctx context.Context, Sid string) error { path := "/v1/EndUsers/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -104,13 +115,18 @@ func (c *ApiService) DeleteEndUser(Sid string) error { // Fetch specific End User Instance. func (c *ApiService) FetchEndUser(Sid string) (*TrusthubV1EndUser, error) { + return c.FetchEndUserWithCtx(context.TODO(), Sid) +} + +// Fetch specific End User Instance. +func (c *ApiService) FetchEndUserWithCtx(ctx context.Context, Sid string) (*TrusthubV1EndUser, error) { path := "/v1/EndUsers/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -144,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.PageEndUserWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of EndUser records from the API. Request is executed immediately. +func (c *ApiService) PageEndUserWithCtx(ctx context.Context, params *ListEndUserParams, pageToken, pageNumber string) (*ListEndUserResponse, error) { path := "/v1/EndUsers" data := url.Values{} @@ -160,7 +181,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -177,7 +198,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.ListEndUserWithCtx(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) ListEndUserWithCtx(ctx context.Context, params *ListEndUserParams) ([]TrusthubV1EndUser, error) { + response, errors := c.StreamEndUserWithCtx(ctx, params) records := make([]TrusthubV1EndUser, 0) for record := range response { @@ -193,6 +219,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.StreamEndUserWithCtx(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) StreamEndUserWithCtx(ctx context.Context, params *ListEndUserParams) (chan TrusthubV1EndUser, chan error) { if params == nil { params = &ListEndUserParams{} } @@ -201,19 +232,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.PageEndUserWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamEndUser(response, params, recordChannel, errorChannel) + go c.streamEndUser(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) streamEndUser(ctx context.Context, response *ListEndUserResponse, params *ListEndUserParams, recordChannel chan TrusthubV1EndUser, errorChannel chan error) { curRecord := 1 for response != nil { @@ -228,7 +259,7 @@ func (c *ApiService) streamEndUser(response *ListEndUserResponse, params *ListEn } } - record, err := client.GetNext(c.baseURL, response, c.getNextListEndUserResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListEndUserResponse) if err != nil { errorChannel <- err break @@ -243,11 +274,11 @@ func (c *ApiService) streamEndUser(response *ListEndUserResponse, params *ListEn close(errorChannel) } -func (c *ApiService) getNextListEndUserResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListEndUserResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -280,6 +311,11 @@ func (params *UpdateEndUserParams) SetAttributes(Attributes interface{}) *Update // Update an existing End User. func (c *ApiService) UpdateEndUser(Sid string, params *UpdateEndUserParams) (*TrusthubV1EndUser, error) { + return c.UpdateEndUserWithCtx(context.TODO(), Sid, params) +} + +// Update an existing End User. +func (c *ApiService) UpdateEndUserWithCtx(ctx context.Context, Sid string, params *UpdateEndUserParams) (*TrusthubV1EndUser, error) { path := "/v1/EndUsers/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -299,7 +335,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.Post(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 2c06d0452..281dd3d6b 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,13 +26,18 @@ import ( // Fetch specific Policy Instance. func (c *ApiService) FetchPolicies(Sid string) (*TrusthubV1Policies, error) { + return c.FetchPoliciesWithCtx(context.TODO(), Sid) +} + +// Fetch specific Policy Instance. +func (c *ApiService) FetchPoliciesWithCtx(ctx context.Context, Sid string) (*TrusthubV1Policies, error) { path := "/v1/Policies/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -65,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.PagePoliciesWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Policies records from the API. Request is executed immediately. +func (c *ApiService) PagePoliciesWithCtx(ctx context.Context, params *ListPoliciesParams, pageToken, pageNumber string) (*ListPoliciesResponse, error) { path := "/v1/Policies" data := url.Values{} @@ -81,7 +92,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -98,7 +109,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.ListPoliciesWithCtx(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) ListPoliciesWithCtx(ctx context.Context, params *ListPoliciesParams) ([]TrusthubV1Policies, error) { + response, errors := c.StreamPoliciesWithCtx(ctx, params) records := make([]TrusthubV1Policies, 0) for record := range response { @@ -114,6 +130,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.StreamPoliciesWithCtx(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) StreamPoliciesWithCtx(ctx context.Context, params *ListPoliciesParams) (chan TrusthubV1Policies, chan error) { if params == nil { params = &ListPoliciesParams{} } @@ -122,19 +143,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.PagePoliciesWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamPolicies(response, params, recordChannel, errorChannel) + go c.streamPolicies(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) streamPolicies(ctx context.Context, response *ListPoliciesResponse, params *ListPoliciesParams, recordChannel chan TrusthubV1Policies, errorChannel chan error) { curRecord := 1 for response != nil { @@ -149,7 +170,7 @@ func (c *ApiService) streamPolicies(response *ListPoliciesResponse, params *List } } - record, err := client.GetNext(c.baseURL, response, c.getNextListPoliciesResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListPoliciesResponse) if err != nil { errorChannel <- err break @@ -164,11 +185,11 @@ func (c *ApiService) streamPolicies(response *ListPoliciesResponse, params *List close(errorChannel) } -func (c *ApiService) getNextListPoliciesResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListPoliciesResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 6c929f71e..ca2ecab7b 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,13 +26,18 @@ import ( // Fetch a specific Supporting Document Type Instance. func (c *ApiService) FetchSupportingDocumentType(Sid string) (*TrusthubV1SupportingDocumentType, error) { + return c.FetchSupportingDocumentTypeWithCtx(context.TODO(), Sid) +} + +// Fetch a specific Supporting Document Type Instance. +func (c *ApiService) FetchSupportingDocumentTypeWithCtx(ctx context.Context, Sid string) (*TrusthubV1SupportingDocumentType, error) { path := "/v1/SupportingDocumentTypes/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -65,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.PageSupportingDocumentTypeWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of SupportingDocumentType records from the API. Request is executed immediately. +func (c *ApiService) PageSupportingDocumentTypeWithCtx(ctx context.Context, params *ListSupportingDocumentTypeParams, pageToken, pageNumber string) (*ListSupportingDocumentTypeResponse, error) { path := "/v1/SupportingDocumentTypes" data := url.Values{} @@ -81,7 +92,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -98,7 +109,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.ListSupportingDocumentTypeWithCtx(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) ListSupportingDocumentTypeWithCtx(ctx context.Context, params *ListSupportingDocumentTypeParams) ([]TrusthubV1SupportingDocumentType, error) { + response, errors := c.StreamSupportingDocumentTypeWithCtx(ctx, params) records := make([]TrusthubV1SupportingDocumentType, 0) for record := range response { @@ -114,6 +130,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.StreamSupportingDocumentTypeWithCtx(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) StreamSupportingDocumentTypeWithCtx(ctx context.Context, params *ListSupportingDocumentTypeParams) (chan TrusthubV1SupportingDocumentType, chan error) { if params == nil { params = &ListSupportingDocumentTypeParams{} } @@ -122,19 +143,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.PageSupportingDocumentTypeWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSupportingDocumentType(response, params, recordChannel, errorChannel) + go c.streamSupportingDocumentType(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) streamSupportingDocumentType(ctx context.Context, response *ListSupportingDocumentTypeResponse, params *ListSupportingDocumentTypeParams, recordChannel chan TrusthubV1SupportingDocumentType, errorChannel chan error) { curRecord := 1 for response != nil { @@ -149,7 +170,7 @@ func (c *ApiService) streamSupportingDocumentType(response *ListSupportingDocume } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSupportingDocumentTypeResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListSupportingDocumentTypeResponse) if err != nil { errorChannel <- err break @@ -164,11 +185,11 @@ func (c *ApiService) streamSupportingDocumentType(response *ListSupportingDocume close(errorChannel) } -func (c *ApiService) getNextListSupportingDocumentTypeResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSupportingDocumentTypeResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 ac2e78c0b..a0aada10a 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,11 @@ func (params *CreateSupportingDocumentParams) SetAttributes(Attributes interface // Create a new Supporting Document. func (c *ApiService) CreateSupportingDocument(params *CreateSupportingDocumentParams) (*TrusthubV1SupportingDocument, error) { + return c.CreateSupportingDocumentWithCtx(context.TODO(), params) +} + +// Create a new Supporting Document. +func (c *ApiService) CreateSupportingDocumentWithCtx(ctx context.Context, params *CreateSupportingDocumentParams) (*TrusthubV1SupportingDocument, error) { path := "/v1/SupportingDocuments" data := url.Values{} @@ -69,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -86,13 +92,18 @@ func (c *ApiService) CreateSupportingDocument(params *CreateSupportingDocumentPa // Delete a specific Supporting Document. func (c *ApiService) DeleteSupportingDocument(Sid string) error { + return c.DeleteSupportingDocumentWithCtx(context.TODO(), Sid) +} + +// Delete a specific Supporting Document. +func (c *ApiService) DeleteSupportingDocumentWithCtx(ctx context.Context, Sid string) error { path := "/v1/SupportingDocuments/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -104,13 +115,18 @@ func (c *ApiService) DeleteSupportingDocument(Sid string) error { // Fetch specific Supporting Document Instance. func (c *ApiService) FetchSupportingDocument(Sid string) (*TrusthubV1SupportingDocument, error) { + return c.FetchSupportingDocumentWithCtx(context.TODO(), Sid) +} + +// Fetch specific Supporting Document Instance. +func (c *ApiService) FetchSupportingDocumentWithCtx(ctx context.Context, Sid string) (*TrusthubV1SupportingDocument, error) { path := "/v1/SupportingDocuments/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -144,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.PageSupportingDocumentWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of SupportingDocument records from the API. Request is executed immediately. +func (c *ApiService) PageSupportingDocumentWithCtx(ctx context.Context, params *ListSupportingDocumentParams, pageToken, pageNumber string) (*ListSupportingDocumentResponse, error) { path := "/v1/SupportingDocuments" data := url.Values{} @@ -160,7 +181,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -177,7 +198,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.ListSupportingDocumentWithCtx(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) ListSupportingDocumentWithCtx(ctx context.Context, params *ListSupportingDocumentParams) ([]TrusthubV1SupportingDocument, error) { + response, errors := c.StreamSupportingDocumentWithCtx(ctx, params) records := make([]TrusthubV1SupportingDocument, 0) for record := range response { @@ -193,6 +219,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.StreamSupportingDocumentWithCtx(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) StreamSupportingDocumentWithCtx(ctx context.Context, params *ListSupportingDocumentParams) (chan TrusthubV1SupportingDocument, chan error) { if params == nil { params = &ListSupportingDocumentParams{} } @@ -201,19 +232,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.PageSupportingDocumentWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSupportingDocument(response, params, recordChannel, errorChannel) + go c.streamSupportingDocument(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) streamSupportingDocument(ctx context.Context, response *ListSupportingDocumentResponse, params *ListSupportingDocumentParams, recordChannel chan TrusthubV1SupportingDocument, errorChannel chan error) { curRecord := 1 for response != nil { @@ -228,7 +259,7 @@ func (c *ApiService) streamSupportingDocument(response *ListSupportingDocumentRe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSupportingDocumentResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListSupportingDocumentResponse) if err != nil { errorChannel <- err break @@ -243,11 +274,11 @@ func (c *ApiService) streamSupportingDocument(response *ListSupportingDocumentRe close(errorChannel) } -func (c *ApiService) getNextListSupportingDocumentResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSupportingDocumentResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -280,6 +311,11 @@ func (params *UpdateSupportingDocumentParams) SetAttributes(Attributes interface // Update an existing Supporting Document. func (c *ApiService) UpdateSupportingDocument(Sid string, params *UpdateSupportingDocumentParams) (*TrusthubV1SupportingDocument, error) { + return c.UpdateSupportingDocumentWithCtx(context.TODO(), Sid, params) +} + +// Update an existing Supporting Document. +func (c *ApiService) UpdateSupportingDocumentWithCtx(ctx context.Context, Sid string, params *UpdateSupportingDocumentParams) (*TrusthubV1SupportingDocument, error) { path := "/v1/SupportingDocuments/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -299,7 +335,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.Post(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 5d6de413e..fb0bcf3d7 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,11 @@ func (params *CreateTrustProductParams) SetStatusCallback(StatusCallback string) // Create a new Customer-Profile. func (c *ApiService) CreateTrustProduct(params *CreateTrustProductParams) (*TrusthubV1TrustProduct, error) { + return c.CreateTrustProductWithCtx(context.TODO(), params) +} + +// Create a new Customer-Profile. +func (c *ApiService) CreateTrustProductWithCtx(ctx context.Context, params *CreateTrustProductParams) (*TrusthubV1TrustProduct, error) { path := "/v1/TrustProducts" data := url.Values{} @@ -72,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -89,13 +95,18 @@ func (c *ApiService) CreateTrustProduct(params *CreateTrustProductParams) (*Trus // Delete a specific Customer-Profile. func (c *ApiService) DeleteTrustProduct(Sid string) error { + return c.DeleteTrustProductWithCtx(context.TODO(), Sid) +} + +// Delete a specific Customer-Profile. +func (c *ApiService) DeleteTrustProductWithCtx(ctx context.Context, Sid string) error { path := "/v1/TrustProducts/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -107,13 +118,18 @@ func (c *ApiService) DeleteTrustProduct(Sid string) error { // Fetch a specific Customer-Profile instance. func (c *ApiService) FetchTrustProduct(Sid string) (*TrusthubV1TrustProduct, error) { + return c.FetchTrustProductWithCtx(context.TODO(), Sid) +} + +// Fetch a specific Customer-Profile instance. +func (c *ApiService) FetchTrustProductWithCtx(ctx context.Context, Sid string) (*TrusthubV1TrustProduct, error) { path := "/v1/TrustProducts/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -165,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.PageTrustProductWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of TrustProduct records from the API. Request is executed immediately. +func (c *ApiService) PageTrustProductWithCtx(ctx context.Context, params *ListTrustProductParams, pageToken, pageNumber string) (*ListTrustProductResponse, error) { path := "/v1/TrustProducts" data := url.Values{} @@ -190,7 +211,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -207,7 +228,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.ListTrustProductWithCtx(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) ListTrustProductWithCtx(ctx context.Context, params *ListTrustProductParams) ([]TrusthubV1TrustProduct, error) { + response, errors := c.StreamTrustProductWithCtx(ctx, params) records := make([]TrusthubV1TrustProduct, 0) for record := range response { @@ -223,6 +249,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.StreamTrustProductWithCtx(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) StreamTrustProductWithCtx(ctx context.Context, params *ListTrustProductParams) (chan TrusthubV1TrustProduct, chan error) { if params == nil { params = &ListTrustProductParams{} } @@ -231,19 +262,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.PageTrustProductWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamTrustProduct(response, params, recordChannel, errorChannel) + go c.streamTrustProduct(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) streamTrustProduct(ctx context.Context, response *ListTrustProductResponse, params *ListTrustProductParams, recordChannel chan TrusthubV1TrustProduct, errorChannel chan error) { curRecord := 1 for response != nil { @@ -258,7 +289,7 @@ func (c *ApiService) streamTrustProduct(response *ListTrustProductResponse, para } } - record, err := client.GetNext(c.baseURL, response, c.getNextListTrustProductResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListTrustProductResponse) if err != nil { errorChannel <- err break @@ -273,11 +304,11 @@ func (c *ApiService) streamTrustProduct(response *ListTrustProductResponse, para close(errorChannel) } -func (c *ApiService) getNextListTrustProductResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListTrustProductResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -322,6 +353,11 @@ func (params *UpdateTrustProductParams) SetEmail(Email string) *UpdateTrustProdu // Updates a Customer-Profile in an account. func (c *ApiService) UpdateTrustProduct(Sid string, params *UpdateTrustProductParams) (*TrusthubV1TrustProduct, error) { + return c.UpdateTrustProductWithCtx(context.TODO(), Sid, params) +} + +// Updates a Customer-Profile in an account. +func (c *ApiService) UpdateTrustProductWithCtx(ctx context.Context, Sid string, params *UpdateTrustProductParams) (*TrusthubV1TrustProduct, error) { path := "/v1/TrustProducts/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -341,7 +377,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.Post(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 c90bc4ca0..924a78900 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,11 @@ func (params *CreateTrustProductChannelEndpointAssignmentParams) SetChannelEndpo // Create a new Assigned Item. func (c *ApiService) CreateTrustProductChannelEndpointAssignment(TrustProductSid string, params *CreateTrustProductChannelEndpointAssignmentParams) (*TrusthubV1TrustProductChannelEndpointAssignment, error) { + return c.CreateTrustProductChannelEndpointAssignmentWithCtx(context.TODO(), TrustProductSid, params) +} + +// Create a new Assigned Item. +func (c *ApiService) CreateTrustProductChannelEndpointAssignmentWithCtx(ctx context.Context, TrustProductSid string, params *CreateTrustProductChannelEndpointAssignmentParams) (*TrusthubV1TrustProductChannelEndpointAssignment, error) { path := "/v1/TrustProducts/{TrustProductSid}/ChannelEndpointAssignments" path = strings.Replace(path, "{"+"TrustProductSid"+"}", TrustProductSid, -1) @@ -55,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -72,6 +78,11 @@ func (c *ApiService) CreateTrustProductChannelEndpointAssignment(TrustProductSid // Remove an Assignment Item Instance. func (c *ApiService) DeleteTrustProductChannelEndpointAssignment(TrustProductSid string, Sid string) error { + return c.DeleteTrustProductChannelEndpointAssignmentWithCtx(context.TODO(), TrustProductSid, Sid) +} + +// Remove an Assignment Item Instance. +func (c *ApiService) DeleteTrustProductChannelEndpointAssignmentWithCtx(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) @@ -79,7 +90,7 @@ func (c *ApiService) DeleteTrustProductChannelEndpointAssignment(TrustProductSid data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -91,6 +102,11 @@ func (c *ApiService) DeleteTrustProductChannelEndpointAssignment(TrustProductSid // Fetch specific Assigned Item Instance. func (c *ApiService) FetchTrustProductChannelEndpointAssignment(TrustProductSid string, Sid string) (*TrusthubV1TrustProductChannelEndpointAssignment, error) { + return c.FetchTrustProductChannelEndpointAssignmentWithCtx(context.TODO(), TrustProductSid, Sid) +} + +// Fetch specific Assigned Item Instance. +func (c *ApiService) FetchTrustProductChannelEndpointAssignmentWithCtx(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) @@ -98,7 +114,7 @@ func (c *ApiService) FetchTrustProductChannelEndpointAssignment(TrustProductSid data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -144,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.PageTrustProductChannelEndpointAssignmentWithCtx(context.TODO(), TrustProductSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of TrustProductChannelEndpointAssignment records from the API. Request is executed immediately. +func (c *ApiService) PageTrustProductChannelEndpointAssignmentWithCtx(ctx context.Context, TrustProductSid string, params *ListTrustProductChannelEndpointAssignmentParams, pageToken, pageNumber string) (*ListTrustProductChannelEndpointAssignmentResponse, error) { path := "/v1/TrustProducts/{TrustProductSid}/ChannelEndpointAssignments" path = strings.Replace(path, "{"+"TrustProductSid"+"}", TrustProductSid, -1) @@ -168,7 +189,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -185,7 +206,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.ListTrustProductChannelEndpointAssignmentWithCtx(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) ListTrustProductChannelEndpointAssignmentWithCtx(ctx context.Context, TrustProductSid string, params *ListTrustProductChannelEndpointAssignmentParams) ([]TrusthubV1TrustProductChannelEndpointAssignment, error) { + response, errors := c.StreamTrustProductChannelEndpointAssignmentWithCtx(ctx, TrustProductSid, params) records := make([]TrusthubV1TrustProductChannelEndpointAssignment, 0) for record := range response { @@ -201,6 +227,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.StreamTrustProductChannelEndpointAssignmentWithCtx(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) StreamTrustProductChannelEndpointAssignmentWithCtx(ctx context.Context, TrustProductSid string, params *ListTrustProductChannelEndpointAssignmentParams) (chan TrusthubV1TrustProductChannelEndpointAssignment, chan error) { if params == nil { params = &ListTrustProductChannelEndpointAssignmentParams{} } @@ -209,19 +240,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.PageTrustProductChannelEndpointAssignmentWithCtx(ctx, TrustProductSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamTrustProductChannelEndpointAssignment(response, params, recordChannel, errorChannel) + go c.streamTrustProductChannelEndpointAssignment(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) streamTrustProductChannelEndpointAssignment(ctx context.Context, response *ListTrustProductChannelEndpointAssignmentResponse, params *ListTrustProductChannelEndpointAssignmentParams, recordChannel chan TrusthubV1TrustProductChannelEndpointAssignment, errorChannel chan error) { curRecord := 1 for response != nil { @@ -236,7 +267,7 @@ func (c *ApiService) streamTrustProductChannelEndpointAssignment(response *ListT } } - record, err := client.GetNext(c.baseURL, response, c.getNextListTrustProductChannelEndpointAssignmentResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListTrustProductChannelEndpointAssignmentResponse) if err != nil { errorChannel <- err break @@ -251,11 +282,11 @@ func (c *ApiService) streamTrustProductChannelEndpointAssignment(response *ListT close(errorChannel) } -func (c *ApiService) getNextListTrustProductChannelEndpointAssignmentResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListTrustProductChannelEndpointAssignmentResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 cc5bc2b31..d2d8ec238 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,11 @@ func (params *CreateTrustProductEntityAssignmentParams) SetObjectSid(ObjectSid s // Create a new Assigned Item. func (c *ApiService) CreateTrustProductEntityAssignment(TrustProductSid string, params *CreateTrustProductEntityAssignmentParams) (*TrusthubV1TrustProductEntityAssignment, error) { + return c.CreateTrustProductEntityAssignmentWithCtx(context.TODO(), TrustProductSid, params) +} + +// Create a new Assigned Item. +func (c *ApiService) CreateTrustProductEntityAssignmentWithCtx(ctx context.Context, TrustProductSid string, params *CreateTrustProductEntityAssignmentParams) (*TrusthubV1TrustProductEntityAssignment, error) { path := "/v1/TrustProducts/{TrustProductSid}/EntityAssignments" path = strings.Replace(path, "{"+"TrustProductSid"+"}", TrustProductSid, -1) @@ -46,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -63,6 +69,11 @@ func (c *ApiService) CreateTrustProductEntityAssignment(TrustProductSid string, // Remove an Assignment Item Instance. func (c *ApiService) DeleteTrustProductEntityAssignment(TrustProductSid string, Sid string) error { + return c.DeleteTrustProductEntityAssignmentWithCtx(context.TODO(), TrustProductSid, Sid) +} + +// Remove an Assignment Item Instance. +func (c *ApiService) DeleteTrustProductEntityAssignmentWithCtx(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) @@ -70,7 +81,7 @@ func (c *ApiService) DeleteTrustProductEntityAssignment(TrustProductSid string, data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -82,6 +93,11 @@ func (c *ApiService) DeleteTrustProductEntityAssignment(TrustProductSid string, // Fetch specific Assigned Item Instance. func (c *ApiService) FetchTrustProductEntityAssignment(TrustProductSid string, Sid string) (*TrusthubV1TrustProductEntityAssignment, error) { + return c.FetchTrustProductEntityAssignmentWithCtx(context.TODO(), TrustProductSid, Sid) +} + +// Fetch specific Assigned Item Instance. +func (c *ApiService) FetchTrustProductEntityAssignmentWithCtx(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) @@ -89,7 +105,7 @@ func (c *ApiService) FetchTrustProductEntityAssignment(TrustProductSid string, S data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -123,6 +139,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.PageTrustProductEntityAssignmentWithCtx(context.TODO(), TrustProductSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of TrustProductEntityAssignment records from the API. Request is executed immediately. +func (c *ApiService) PageTrustProductEntityAssignmentWithCtx(ctx context.Context, TrustProductSid string, params *ListTrustProductEntityAssignmentParams, pageToken, pageNumber string) (*ListTrustProductEntityAssignmentResponse, error) { path := "/v1/TrustProducts/{TrustProductSid}/EntityAssignments" path = strings.Replace(path, "{"+"TrustProductSid"+"}", TrustProductSid, -1) @@ -141,7 +162,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -158,7 +179,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.ListTrustProductEntityAssignmentWithCtx(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) ListTrustProductEntityAssignmentWithCtx(ctx context.Context, TrustProductSid string, params *ListTrustProductEntityAssignmentParams) ([]TrusthubV1TrustProductEntityAssignment, error) { + response, errors := c.StreamTrustProductEntityAssignmentWithCtx(ctx, TrustProductSid, params) records := make([]TrusthubV1TrustProductEntityAssignment, 0) for record := range response { @@ -174,6 +200,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.StreamTrustProductEntityAssignmentWithCtx(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) StreamTrustProductEntityAssignmentWithCtx(ctx context.Context, TrustProductSid string, params *ListTrustProductEntityAssignmentParams) (chan TrusthubV1TrustProductEntityAssignment, chan error) { if params == nil { params = &ListTrustProductEntityAssignmentParams{} } @@ -182,19 +213,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.PageTrustProductEntityAssignmentWithCtx(ctx, TrustProductSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamTrustProductEntityAssignment(response, params, recordChannel, errorChannel) + go c.streamTrustProductEntityAssignment(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) streamTrustProductEntityAssignment(ctx context.Context, response *ListTrustProductEntityAssignmentResponse, params *ListTrustProductEntityAssignmentParams, recordChannel chan TrusthubV1TrustProductEntityAssignment, errorChannel chan error) { curRecord := 1 for response != nil { @@ -209,7 +240,7 @@ func (c *ApiService) streamTrustProductEntityAssignment(response *ListTrustProdu } } - record, err := client.GetNext(c.baseURL, response, c.getNextListTrustProductEntityAssignmentResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListTrustProductEntityAssignmentResponse) if err != nil { errorChannel <- err break @@ -224,11 +255,11 @@ func (c *ApiService) streamTrustProductEntityAssignment(response *ListTrustProdu close(errorChannel) } -func (c *ApiService) getNextListTrustProductEntityAssignmentResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListTrustProductEntityAssignmentResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 652c6e9b0..a12adb889 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,11 @@ func (params *CreateTrustProductEvaluationParams) SetPolicySid(PolicySid string) // Create a new Evaluation func (c *ApiService) CreateTrustProductEvaluation(TrustProductSid string, params *CreateTrustProductEvaluationParams) (*TrusthubV1TrustProductEvaluation, error) { + return c.CreateTrustProductEvaluationWithCtx(context.TODO(), TrustProductSid, params) +} + +// Create a new Evaluation +func (c *ApiService) CreateTrustProductEvaluationWithCtx(ctx context.Context, TrustProductSid string, params *CreateTrustProductEvaluationParams) (*TrusthubV1TrustProductEvaluation, error) { path := "/v1/TrustProducts/{TrustProductSid}/Evaluations" path = strings.Replace(path, "{"+"TrustProductSid"+"}", TrustProductSid, -1) @@ -46,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -63,6 +69,11 @@ func (c *ApiService) CreateTrustProductEvaluation(TrustProductSid string, params // Fetch specific Evaluation Instance. func (c *ApiService) FetchTrustProductEvaluation(TrustProductSid string, Sid string) (*TrusthubV1TrustProductEvaluation, error) { + return c.FetchTrustProductEvaluationWithCtx(context.TODO(), TrustProductSid, Sid) +} + +// Fetch specific Evaluation Instance. +func (c *ApiService) FetchTrustProductEvaluationWithCtx(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) @@ -70,7 +81,7 @@ func (c *ApiService) FetchTrustProductEvaluation(TrustProductSid string, Sid str data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -104,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.PageTrustProductEvaluationWithCtx(context.TODO(), TrustProductSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of TrustProductEvaluation records from the API. Request is executed immediately. +func (c *ApiService) PageTrustProductEvaluationWithCtx(ctx context.Context, TrustProductSid string, params *ListTrustProductEvaluationParams, pageToken, pageNumber string) (*ListTrustProductEvaluationResponse, error) { path := "/v1/TrustProducts/{TrustProductSid}/Evaluations" path = strings.Replace(path, "{"+"TrustProductSid"+"}", TrustProductSid, -1) @@ -122,7 +138,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -139,7 +155,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.ListTrustProductEvaluationWithCtx(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) ListTrustProductEvaluationWithCtx(ctx context.Context, TrustProductSid string, params *ListTrustProductEvaluationParams) ([]TrusthubV1TrustProductEvaluation, error) { + response, errors := c.StreamTrustProductEvaluationWithCtx(ctx, TrustProductSid, params) records := make([]TrusthubV1TrustProductEvaluation, 0) for record := range response { @@ -155,6 +176,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.StreamTrustProductEvaluationWithCtx(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) StreamTrustProductEvaluationWithCtx(ctx context.Context, TrustProductSid string, params *ListTrustProductEvaluationParams) (chan TrusthubV1TrustProductEvaluation, chan error) { if params == nil { params = &ListTrustProductEvaluationParams{} } @@ -163,19 +189,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.PageTrustProductEvaluationWithCtx(ctx, TrustProductSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamTrustProductEvaluation(response, params, recordChannel, errorChannel) + go c.streamTrustProductEvaluation(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) streamTrustProductEvaluation(ctx context.Context, response *ListTrustProductEvaluationResponse, params *ListTrustProductEvaluationParams, recordChannel chan TrusthubV1TrustProductEvaluation, errorChannel chan error) { curRecord := 1 for response != nil { @@ -190,7 +216,7 @@ func (c *ApiService) streamTrustProductEvaluation(response *ListTrustProductEval } } - record, err := client.GetNext(c.baseURL, response, c.getNextListTrustProductEvaluationResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListTrustProductEvaluationResponse) if err != nil { errorChannel <- err break @@ -205,11 +231,11 @@ func (c *ApiService) streamTrustProductEvaluation(response *ListTrustProductEval close(errorChannel) } -func (c *ApiService) getNextListTrustProductEvaluationResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListTrustProductEvaluationResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 fa0c14223..764d803df 100644 --- a/rest/verify/v2/api_service.go +++ b/rest/verify/v2/api_service.go @@ -20,10 +20,14 @@ import ( type ApiService struct { baseURL string - requestHandler *twilio.RequestHandler + requestHandler *twilio.RequestHandlerWithCtx } func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { + return NewApiServiceWithCtx(twilio.UpgradeRequestHandler(requestHandler)) +} + +func NewApiServiceWithCtx(requestHandler *twilio.RequestHandlerWithCtx) *ApiService { return &ApiService{ requestHandler: requestHandler, baseURL: "https://verify.twilio.com", @@ -33,3 +37,7 @@ func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { func NewApiServiceWithClient(client twilio.BaseClient) *ApiService { return NewApiService(twilio.NewRequestHandler(client)) } + +func NewApiServiceWithClientWithCtx(client twilio.BaseClientWithCtx) *ApiService { + return NewApiServiceWithCtx(twilio.NewRequestHandlerWithCtx(client)) +} diff --git a/rest/verify/v2/attempts.go b/rest/verify/v2/attempts.go index 68ed4dfad..50ec5dc11 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,13 +27,18 @@ import ( // Fetch a specific verification attempt. func (c *ApiService) FetchVerificationAttempt(Sid string) (*VerifyV2VerificationAttempt, error) { + return c.FetchVerificationAttemptWithCtx(context.TODO(), Sid) +} + +// Fetch a specific verification attempt. +func (c *ApiService) FetchVerificationAttemptWithCtx(ctx context.Context, Sid string) (*VerifyV2VerificationAttempt, error) { path := "/v2/Attempts/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -114,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.PageVerificationAttemptWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of VerificationAttempt records from the API. Request is executed immediately. +func (c *ApiService) PageVerificationAttemptWithCtx(ctx context.Context, params *ListVerificationAttemptParams, pageToken, pageNumber string) (*ListVerificationAttemptResponse, error) { path := "/v2/Attempts" data := url.Values{} @@ -154,7 +165,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -171,7 +182,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.ListVerificationAttemptWithCtx(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) ListVerificationAttemptWithCtx(ctx context.Context, params *ListVerificationAttemptParams) ([]VerifyV2VerificationAttempt, error) { + response, errors := c.StreamVerificationAttemptWithCtx(ctx, params) records := make([]VerifyV2VerificationAttempt, 0) for record := range response { @@ -187,6 +203,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.StreamVerificationAttemptWithCtx(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) StreamVerificationAttemptWithCtx(ctx context.Context, params *ListVerificationAttemptParams) (chan VerifyV2VerificationAttempt, chan error) { if params == nil { params = &ListVerificationAttemptParams{} } @@ -195,19 +216,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.PageVerificationAttemptWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamVerificationAttempt(response, params, recordChannel, errorChannel) + go c.streamVerificationAttempt(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) streamVerificationAttempt(ctx context.Context, response *ListVerificationAttemptResponse, params *ListVerificationAttemptParams, recordChannel chan VerifyV2VerificationAttempt, errorChannel chan error) { curRecord := 1 for response != nil { @@ -222,7 +243,7 @@ func (c *ApiService) streamVerificationAttempt(response *ListVerificationAttempt } } - record, err := client.GetNext(c.baseURL, response, c.getNextListVerificationAttemptResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListVerificationAttemptResponse) if err != nil { errorChannel <- err break @@ -237,11 +258,11 @@ func (c *ApiService) streamVerificationAttempt(response *ListVerificationAttempt close(errorChannel) } -func (c *ApiService) getNextListVerificationAttemptResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListVerificationAttemptResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 29f8f5ecd..4f8034fca 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,11 @@ 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.FetchVerificationAttemptsSummaryWithCtx(context.TODO(), params) +} + +// Get a summary of how many attempts were made and how many were converted. +func (c *ApiService) FetchVerificationAttemptsSummaryWithCtx(ctx context.Context, params *FetchVerificationAttemptsSummaryParams) (*VerifyV2VerificationAttemptsSummary, error) { path := "/v2/Attempts/Summary" data := url.Values{} @@ -88,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/verify/v2/forms.go b/rest/verify/v2/forms.go index 16db4c563..ca9c539f9 100644 --- a/rest/verify/v2/forms.go +++ b/rest/verify/v2/forms.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -22,13 +23,18 @@ import ( // Fetch the forms for a specific Form Type. func (c *ApiService) FetchForm(FormType string) (*VerifyV2Form, error) { + return c.FetchFormWithCtx(context.TODO(), FormType) +} + +// Fetch the forms for a specific Form Type. +func (c *ApiService) FetchFormWithCtx(ctx context.Context, FormType string) (*VerifyV2Form, error) { path := "/v2/Forms/{FormType}" path = strings.Replace(path, "{"+"FormType"+"}", FormType, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } diff --git a/rest/verify/v2/safe_list_numbers.go b/rest/verify/v2/safe_list_numbers.go index 52594bedf..f511e9da9 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,11 @@ func (params *CreateSafelistParams) SetPhoneNumber(PhoneNumber string) *CreateSa // Add a new phone number to SafeList. func (c *ApiService) CreateSafelist(params *CreateSafelistParams) (*VerifyV2Safelist, error) { + return c.CreateSafelistWithCtx(context.TODO(), params) +} + +// Add a new phone number to SafeList. +func (c *ApiService) CreateSafelistWithCtx(ctx context.Context, params *CreateSafelistParams) (*VerifyV2Safelist, error) { path := "/v2/SafeList/Numbers" data := url.Values{} @@ -42,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -59,13 +65,18 @@ func (c *ApiService) CreateSafelist(params *CreateSafelistParams) (*VerifyV2Safe // Remove a phone number from SafeList. func (c *ApiService) DeleteSafelist(PhoneNumber string) error { + return c.DeleteSafelistWithCtx(context.TODO(), PhoneNumber) +} + +// Remove a phone number from SafeList. +func (c *ApiService) DeleteSafelistWithCtx(ctx context.Context, PhoneNumber string) error { path := "/v2/SafeList/Numbers/{PhoneNumber}" path = strings.Replace(path, "{"+"PhoneNumber"+"}", PhoneNumber, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -77,13 +88,18 @@ 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.FetchSafelistWithCtx(context.TODO(), PhoneNumber) +} + +// Check if a phone number exists in SafeList. +func (c *ApiService) FetchSafelistWithCtx(ctx context.Context, PhoneNumber string) (*VerifyV2Safelist, error) { path := "/v2/SafeList/Numbers/{PhoneNumber}" path = strings.Replace(path, "{"+"PhoneNumber"+"}", PhoneNumber, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(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 3f58db0fa..1347dd25e 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" @@ -132,6 +133,11 @@ func (params *CreateServiceParams) SetDefaultTemplateSid(DefaultTemplateSid stri // Create a new Verification Service. func (c *ApiService) CreateService(params *CreateServiceParams) (*VerifyV2Service, error) { + return c.CreateServiceWithCtx(context.TODO(), params) +} + +// Create a new Verification Service. +func (c *ApiService) CreateServiceWithCtx(ctx context.Context, params *CreateServiceParams) (*VerifyV2Service, error) { path := "/v2/Services" data := url.Values{} @@ -189,7 +195,7 @@ func (c *ApiService) CreateService(params *CreateServiceParams) (*VerifyV2Servic data.Set("DefaultTemplateSid", *params.DefaultTemplateSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -206,13 +212,18 @@ func (c *ApiService) CreateService(params *CreateServiceParams) (*VerifyV2Servic // Delete a specific Verification Service Instance. func (c *ApiService) DeleteService(Sid string) error { + return c.DeleteServiceWithCtx(context.TODO(), Sid) +} + +// Delete a specific Verification Service Instance. +func (c *ApiService) DeleteServiceWithCtx(ctx context.Context, Sid string) error { path := "/v2/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -224,13 +235,18 @@ func (c *ApiService) DeleteService(Sid string) error { // Fetch specific Verification Service Instance. func (c *ApiService) FetchService(Sid string) (*VerifyV2Service, error) { + return c.FetchServiceWithCtx(context.TODO(), Sid) +} + +// Fetch specific Verification Service Instance. +func (c *ApiService) FetchServiceWithCtx(ctx context.Context, Sid string) (*VerifyV2Service, error) { path := "/v2/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -264,6 +280,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.PageServiceWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Service records from the API. Request is executed immediately. +func (c *ApiService) PageServiceWithCtx(ctx context.Context, params *ListServiceParams, pageToken, pageNumber string) (*ListServiceResponse, error) { path := "/v2/Services" data := url.Values{} @@ -280,7 +301,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -297,7 +318,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.ListServiceWithCtx(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) ListServiceWithCtx(ctx context.Context, params *ListServiceParams) ([]VerifyV2Service, error) { + response, errors := c.StreamServiceWithCtx(ctx, params) records := make([]VerifyV2Service, 0) for record := range response { @@ -313,6 +339,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.StreamServiceWithCtx(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) StreamServiceWithCtx(ctx context.Context, params *ListServiceParams) (chan VerifyV2Service, chan error) { if params == nil { params = &ListServiceParams{} } @@ -321,19 +352,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.PageServiceWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamService(response, params, recordChannel, errorChannel) + go c.streamService(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) streamService(ctx context.Context, response *ListServiceResponse, params *ListServiceParams, recordChannel chan VerifyV2Service, errorChannel chan error) { curRecord := 1 for response != nil { @@ -348,7 +379,7 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListServiceResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListServiceResponse) if err != nil { errorChannel <- err break @@ -363,11 +394,11 @@ func (c *ApiService) streamService(response *ListServiceResponse, params *ListSe close(errorChannel) } -func (c *ApiService) getNextListServiceResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListServiceResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -490,6 +521,11 @@ func (params *UpdateServiceParams) SetDefaultTemplateSid(DefaultTemplateSid stri // Update a specific Verification Service. func (c *ApiService) UpdateService(Sid string, params *UpdateServiceParams) (*VerifyV2Service, error) { + return c.UpdateServiceWithCtx(context.TODO(), Sid, params) +} + +// Update a specific Verification Service. +func (c *ApiService) UpdateServiceWithCtx(ctx context.Context, Sid string, params *UpdateServiceParams) (*VerifyV2Service, error) { path := "/v2/Services/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -548,7 +584,7 @@ func (c *ApiService) UpdateService(Sid string, params *UpdateServiceParams) (*Ve data.Set("DefaultTemplateSid", *params.DefaultTemplateSid) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 c2921683f..8eba70f7e 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,11 @@ 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.CreateAccessTokenWithCtx(context.TODO(), ServiceSid, params) +} + +// Create a new enrollment Access Token for the Entity +func (c *ApiService) CreateAccessTokenWithCtx(ctx context.Context, ServiceSid string, params *CreateAccessTokenParams) (*VerifyV2AccessToken, error) { path := "/v2/Services/{ServiceSid}/AccessTokens" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -71,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -88,6 +94,11 @@ 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.FetchAccessTokenWithCtx(context.TODO(), ServiceSid, Sid) +} + +// Fetch an Access Token for the Entity +func (c *ApiService) FetchAccessTokenWithCtx(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) @@ -95,7 +106,7 @@ func (c *ApiService) FetchAccessToken(ServiceSid string, Sid string) (*VerifyV2A data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(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 4f5ce3457..57a5aa9e8 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,11 @@ 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.CreateEntityWithCtx(context.TODO(), ServiceSid, params) +} + +// Create a new Entity for the Service +func (c *ApiService) CreateEntityWithCtx(ctx context.Context, ServiceSid string, params *CreateEntityParams) (*VerifyV2Entity, error) { path := "/v2/Services/{ServiceSid}/Entities" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -46,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -63,6 +69,11 @@ func (c *ApiService) CreateEntity(ServiceSid string, params *CreateEntityParams) // Delete a specific Entity. func (c *ApiService) DeleteEntity(ServiceSid string, Identity string) error { + return c.DeleteEntityWithCtx(context.TODO(), ServiceSid, Identity) +} + +// Delete a specific Entity. +func (c *ApiService) DeleteEntityWithCtx(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) @@ -70,7 +81,7 @@ func (c *ApiService) DeleteEntity(ServiceSid string, Identity string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -82,6 +93,11 @@ 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.FetchEntityWithCtx(context.TODO(), ServiceSid, Identity) +} + +// Fetch a specific Entity. +func (c *ApiService) FetchEntityWithCtx(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) @@ -89,7 +105,7 @@ func (c *ApiService) FetchEntity(ServiceSid string, Identity string) (*VerifyV2E data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -123,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.PageEntityWithCtx(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Entity records from the API. Request is executed immediately. +func (c *ApiService) PageEntityWithCtx(ctx context.Context, ServiceSid string, params *ListEntityParams, pageToken, pageNumber string) (*ListEntityResponse, error) { path := "/v2/Services/{ServiceSid}/Entities" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -141,7 +162,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -158,7 +179,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.ListEntityWithCtx(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) ListEntityWithCtx(ctx context.Context, ServiceSid string, params *ListEntityParams) ([]VerifyV2Entity, error) { + response, errors := c.StreamEntityWithCtx(ctx, ServiceSid, params) records := make([]VerifyV2Entity, 0) for record := range response { @@ -174,6 +200,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.StreamEntityWithCtx(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) StreamEntityWithCtx(ctx context.Context, ServiceSid string, params *ListEntityParams) (chan VerifyV2Entity, chan error) { if params == nil { params = &ListEntityParams{} } @@ -182,19 +213,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.PageEntityWithCtx(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamEntity(response, params, recordChannel, errorChannel) + go c.streamEntity(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) streamEntity(ctx context.Context, response *ListEntityResponse, params *ListEntityParams, recordChannel chan VerifyV2Entity, errorChannel chan error) { curRecord := 1 for response != nil { @@ -209,7 +240,7 @@ func (c *ApiService) streamEntity(response *ListEntityResponse, params *ListEnti } } - record, err := client.GetNext(c.baseURL, response, c.getNextListEntityResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListEntityResponse) if err != nil { errorChannel <- err break @@ -224,11 +255,11 @@ func (c *ApiService) streamEntity(response *ListEntityResponse, params *ListEnti close(errorChannel) } -func (c *ApiService) getNextListEntityResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListEntityResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 9b200d5e4..2e3f32cc4 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,11 @@ 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.CreateChallengeWithCtx(context.TODO(), ServiceSid, Identity, params) +} + +// Create a new Challenge for the Factor +func (c *ApiService) CreateChallengeWithCtx(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) @@ -107,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -124,6 +130,11 @@ 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.FetchChallengeWithCtx(context.TODO(), ServiceSid, Identity, Sid) +} + +// Fetch a specific Challenge. +func (c *ApiService) FetchChallengeWithCtx(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) @@ -132,7 +143,7 @@ func (c *ApiService) FetchChallenge(ServiceSid string, Identity string, Sid stri data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -184,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.PageChallengeWithCtx(context.TODO(), ServiceSid, Identity, params, pageToken, pageNumber) +} + +// Retrieve a single page of Challenge records from the API. Request is executed immediately. +func (c *ApiService) PageChallengeWithCtx(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) @@ -212,7 +228,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -229,7 +245,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.ListChallengeWithCtx(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) ListChallengeWithCtx(ctx context.Context, ServiceSid string, Identity string, params *ListChallengeParams) ([]VerifyV2Challenge, error) { + response, errors := c.StreamChallengeWithCtx(ctx, ServiceSid, Identity, params) records := make([]VerifyV2Challenge, 0) for record := range response { @@ -245,6 +266,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.StreamChallengeWithCtx(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) StreamChallengeWithCtx(ctx context.Context, ServiceSid string, Identity string, params *ListChallengeParams) (chan VerifyV2Challenge, chan error) { if params == nil { params = &ListChallengeParams{} } @@ -253,19 +279,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.PageChallengeWithCtx(ctx, ServiceSid, Identity, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamChallenge(response, params, recordChannel, errorChannel) + go c.streamChallenge(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) streamChallenge(ctx context.Context, response *ListChallengeResponse, params *ListChallengeParams, recordChannel chan VerifyV2Challenge, errorChannel chan error) { curRecord := 1 for response != nil { @@ -280,7 +306,7 @@ func (c *ApiService) streamChallenge(response *ListChallengeResponse, params *Li } } - record, err := client.GetNext(c.baseURL, response, c.getNextListChallengeResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListChallengeResponse) if err != nil { errorChannel <- err break @@ -295,11 +321,11 @@ func (c *ApiService) streamChallenge(response *ListChallengeResponse, params *Li close(errorChannel) } -func (c *ApiService) getNextListChallengeResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListChallengeResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -332,6 +358,11 @@ func (params *UpdateChallengeParams) SetMetadata(Metadata interface{}) *UpdateCh // Verify a specific Challenge. func (c *ApiService) UpdateChallenge(ServiceSid string, Identity string, Sid string, params *UpdateChallengeParams) (*VerifyV2Challenge, error) { + return c.UpdateChallengeWithCtx(context.TODO(), ServiceSid, Identity, Sid, params) +} + +// Verify a specific Challenge. +func (c *ApiService) UpdateChallengeWithCtx(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) @@ -353,7 +384,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.Post(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 6d36b964a..73bf28c5b 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,11 @@ 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.CreateNotificationWithCtx(context.TODO(), ServiceSid, Identity, ChallengeSid, params) +} + +// Create a new Notification for the corresponding Challenge +func (c *ApiService) CreateNotificationWithCtx(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) @@ -46,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.Post(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 3f0c08bda..1990f49d6 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,11 @@ func (params *CreateNewFactorParams) SetMetadata(Metadata interface{}) *CreateNe // Create a new Factor for the Entity func (c *ApiService) CreateNewFactor(ServiceSid string, Identity string, params *CreateNewFactorParams) (*VerifyV2NewFactor, error) { + return c.CreateNewFactorWithCtx(context.TODO(), ServiceSid, Identity, params) +} + +// Create a new Factor for the Entity +func (c *ApiService) CreateNewFactorWithCtx(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) @@ -170,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -187,6 +193,11 @@ 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.DeleteFactorWithCtx(context.TODO(), ServiceSid, Identity, Sid) +} + +// Delete a specific Factor. +func (c *ApiService) DeleteFactorWithCtx(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) @@ -195,7 +206,7 @@ func (c *ApiService) DeleteFactor(ServiceSid string, Identity string, Sid string data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -207,6 +218,11 @@ 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.FetchFactorWithCtx(context.TODO(), ServiceSid, Identity, Sid) +} + +// Fetch a specific Factor. +func (c *ApiService) FetchFactorWithCtx(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) @@ -215,7 +231,7 @@ func (c *ApiService) FetchFactor(ServiceSid string, Identity string, Sid string) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -249,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.PageFactorWithCtx(context.TODO(), ServiceSid, Identity, params, pageToken, pageNumber) +} + +// Retrieve a single page of Factor records from the API. Request is executed immediately. +func (c *ApiService) PageFactorWithCtx(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) @@ -268,7 +289,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -285,7 +306,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.ListFactorWithCtx(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) ListFactorWithCtx(ctx context.Context, ServiceSid string, Identity string, params *ListFactorParams) ([]VerifyV2Factor, error) { + response, errors := c.StreamFactorWithCtx(ctx, ServiceSid, Identity, params) records := make([]VerifyV2Factor, 0) for record := range response { @@ -301,6 +327,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.StreamFactorWithCtx(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) StreamFactorWithCtx(ctx context.Context, ServiceSid string, Identity string, params *ListFactorParams) (chan VerifyV2Factor, chan error) { if params == nil { params = &ListFactorParams{} } @@ -309,19 +340,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.PageFactorWithCtx(ctx, ServiceSid, Identity, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamFactor(response, params, recordChannel, errorChannel) + go c.streamFactor(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) streamFactor(ctx context.Context, response *ListFactorResponse, params *ListFactorParams, recordChannel chan VerifyV2Factor, errorChannel chan error) { curRecord := 1 for response != nil { @@ -336,7 +367,7 @@ func (c *ApiService) streamFactor(response *ListFactorResponse, params *ListFact } } - record, err := client.GetNext(c.baseURL, response, c.getNextListFactorResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListFactorResponse) if err != nil { errorChannel <- err break @@ -351,11 +382,11 @@ func (c *ApiService) streamFactor(response *ListFactorResponse, params *ListFact close(errorChannel) } -func (c *ApiService) getNextListFactorResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListFactorResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -430,6 +461,11 @@ 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.UpdateFactorWithCtx(context.TODO(), ServiceSid, Identity, Sid, params) +} + +// Update a specific Factor. This endpoint can be used to Verify a Factor if passed an `AuthPayload` param. +func (c *ApiService) UpdateFactorWithCtx(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) @@ -466,7 +502,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.Post(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 2d3d5fee9..9b7256990 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,11 @@ func (params *CreateMessagingConfigurationParams) SetMessagingServiceSid(Messagi // Create a new MessagingConfiguration for a service. func (c *ApiService) CreateMessagingConfiguration(ServiceSid string, params *CreateMessagingConfigurationParams) (*VerifyV2MessagingConfiguration, error) { + return c.CreateMessagingConfigurationWithCtx(context.TODO(), ServiceSid, params) +} + +// Create a new MessagingConfiguration for a service. +func (c *ApiService) CreateMessagingConfigurationWithCtx(ctx context.Context, ServiceSid string, params *CreateMessagingConfigurationParams) (*VerifyV2MessagingConfiguration, error) { path := "/v2/Services/{ServiceSid}/MessagingConfigurations" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -55,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -72,6 +78,11 @@ func (c *ApiService) CreateMessagingConfiguration(ServiceSid string, params *Cre // Delete a specific MessagingConfiguration. func (c *ApiService) DeleteMessagingConfiguration(ServiceSid string, Country string) error { + return c.DeleteMessagingConfigurationWithCtx(context.TODO(), ServiceSid, Country) +} + +// Delete a specific MessagingConfiguration. +func (c *ApiService) DeleteMessagingConfigurationWithCtx(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) @@ -79,7 +90,7 @@ func (c *ApiService) DeleteMessagingConfiguration(ServiceSid string, Country str data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -91,6 +102,11 @@ func (c *ApiService) DeleteMessagingConfiguration(ServiceSid string, Country str // Fetch a specific MessagingConfiguration. func (c *ApiService) FetchMessagingConfiguration(ServiceSid string, Country string) (*VerifyV2MessagingConfiguration, error) { + return c.FetchMessagingConfigurationWithCtx(context.TODO(), ServiceSid, Country) +} + +// Fetch a specific MessagingConfiguration. +func (c *ApiService) FetchMessagingConfigurationWithCtx(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) @@ -98,7 +114,7 @@ func (c *ApiService) FetchMessagingConfiguration(ServiceSid string, Country stri data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -132,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.PageMessagingConfigurationWithCtx(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of MessagingConfiguration records from the API. Request is executed immediately. +func (c *ApiService) PageMessagingConfigurationWithCtx(ctx context.Context, ServiceSid string, params *ListMessagingConfigurationParams, pageToken, pageNumber string) (*ListMessagingConfigurationResponse, error) { path := "/v2/Services/{ServiceSid}/MessagingConfigurations" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -150,7 +171,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -167,7 +188,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.ListMessagingConfigurationWithCtx(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) ListMessagingConfigurationWithCtx(ctx context.Context, ServiceSid string, params *ListMessagingConfigurationParams) ([]VerifyV2MessagingConfiguration, error) { + response, errors := c.StreamMessagingConfigurationWithCtx(ctx, ServiceSid, params) records := make([]VerifyV2MessagingConfiguration, 0) for record := range response { @@ -183,6 +209,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.StreamMessagingConfigurationWithCtx(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) StreamMessagingConfigurationWithCtx(ctx context.Context, ServiceSid string, params *ListMessagingConfigurationParams) (chan VerifyV2MessagingConfiguration, chan error) { if params == nil { params = &ListMessagingConfigurationParams{} } @@ -191,19 +222,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.PageMessagingConfigurationWithCtx(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamMessagingConfiguration(response, params, recordChannel, errorChannel) + go c.streamMessagingConfiguration(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) streamMessagingConfiguration(ctx context.Context, response *ListMessagingConfigurationResponse, params *ListMessagingConfigurationParams, recordChannel chan VerifyV2MessagingConfiguration, errorChannel chan error) { curRecord := 1 for response != nil { @@ -218,7 +249,7 @@ func (c *ApiService) streamMessagingConfiguration(response *ListMessagingConfigu } } - record, err := client.GetNext(c.baseURL, response, c.getNextListMessagingConfigurationResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListMessagingConfigurationResponse) if err != nil { errorChannel <- err break @@ -233,11 +264,11 @@ func (c *ApiService) streamMessagingConfiguration(response *ListMessagingConfigu close(errorChannel) } -func (c *ApiService) getNextListMessagingConfigurationResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListMessagingConfigurationResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -264,6 +295,11 @@ func (params *UpdateMessagingConfigurationParams) SetMessagingServiceSid(Messagi // Update a specific MessagingConfiguration func (c *ApiService) UpdateMessagingConfiguration(ServiceSid string, Country string, params *UpdateMessagingConfigurationParams) (*VerifyV2MessagingConfiguration, error) { + return c.UpdateMessagingConfigurationWithCtx(context.TODO(), ServiceSid, Country, params) +} + +// Update a specific MessagingConfiguration +func (c *ApiService) UpdateMessagingConfigurationWithCtx(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) @@ -275,7 +311,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.Post(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 82c83ac73..e2f71f81c 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,11 @@ 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.CreateRateLimitWithCtx(context.TODO(), ServiceSid, params) +} + +// Create a new Rate Limit for a Service +func (c *ApiService) CreateRateLimitWithCtx(ctx context.Context, ServiceSid string, params *CreateRateLimitParams) (*VerifyV2RateLimit, error) { path := "/v2/Services/{ServiceSid}/RateLimits" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -55,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -72,6 +78,11 @@ func (c *ApiService) CreateRateLimit(ServiceSid string, params *CreateRateLimitP // Delete a specific Rate Limit. func (c *ApiService) DeleteRateLimit(ServiceSid string, Sid string) error { + return c.DeleteRateLimitWithCtx(context.TODO(), ServiceSid, Sid) +} + +// Delete a specific Rate Limit. +func (c *ApiService) DeleteRateLimitWithCtx(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) @@ -79,7 +90,7 @@ func (c *ApiService) DeleteRateLimit(ServiceSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -91,6 +102,11 @@ 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.FetchRateLimitWithCtx(context.TODO(), ServiceSid, Sid) +} + +// Fetch a specific Rate Limit. +func (c *ApiService) FetchRateLimitWithCtx(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) @@ -98,7 +114,7 @@ func (c *ApiService) FetchRateLimit(ServiceSid string, Sid string) (*VerifyV2Rat data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -132,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.PageRateLimitWithCtx(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of RateLimit records from the API. Request is executed immediately. +func (c *ApiService) PageRateLimitWithCtx(ctx context.Context, ServiceSid string, params *ListRateLimitParams, pageToken, pageNumber string) (*ListRateLimitResponse, error) { path := "/v2/Services/{ServiceSid}/RateLimits" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -150,7 +171,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -167,7 +188,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.ListRateLimitWithCtx(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) ListRateLimitWithCtx(ctx context.Context, ServiceSid string, params *ListRateLimitParams) ([]VerifyV2RateLimit, error) { + response, errors := c.StreamRateLimitWithCtx(ctx, ServiceSid, params) records := make([]VerifyV2RateLimit, 0) for record := range response { @@ -183,6 +209,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.StreamRateLimitWithCtx(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) StreamRateLimitWithCtx(ctx context.Context, ServiceSid string, params *ListRateLimitParams) (chan VerifyV2RateLimit, chan error) { if params == nil { params = &ListRateLimitParams{} } @@ -191,19 +222,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.PageRateLimitWithCtx(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamRateLimit(response, params, recordChannel, errorChannel) + go c.streamRateLimit(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) streamRateLimit(ctx context.Context, response *ListRateLimitResponse, params *ListRateLimitParams, recordChannel chan VerifyV2RateLimit, errorChannel chan error) { curRecord := 1 for response != nil { @@ -218,7 +249,7 @@ func (c *ApiService) streamRateLimit(response *ListRateLimitResponse, params *Li } } - record, err := client.GetNext(c.baseURL, response, c.getNextListRateLimitResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListRateLimitResponse) if err != nil { errorChannel <- err break @@ -233,11 +264,11 @@ func (c *ApiService) streamRateLimit(response *ListRateLimitResponse, params *Li close(errorChannel) } -func (c *ApiService) getNextListRateLimitResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListRateLimitResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -264,6 +295,11 @@ 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.UpdateRateLimitWithCtx(context.TODO(), ServiceSid, Sid, params) +} + +// Update a specific Rate Limit. +func (c *ApiService) UpdateRateLimitWithCtx(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) @@ -275,7 +311,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.Post(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 1eb51fac3..c3fed7e3c 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,11 @@ 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.CreateBucketWithCtx(context.TODO(), ServiceSid, RateLimitSid, params) +} + +// Create a new Bucket for a Rate Limit +func (c *ApiService) CreateBucketWithCtx(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) @@ -56,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -73,6 +79,11 @@ 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.DeleteBucketWithCtx(context.TODO(), ServiceSid, RateLimitSid, Sid) +} + +// Delete a specific Bucket. +func (c *ApiService) DeleteBucketWithCtx(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) @@ -81,7 +92,7 @@ func (c *ApiService) DeleteBucket(ServiceSid string, RateLimitSid string, Sid st data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -93,6 +104,11 @@ 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.FetchBucketWithCtx(context.TODO(), ServiceSid, RateLimitSid, Sid) +} + +// Fetch a specific Bucket. +func (c *ApiService) FetchBucketWithCtx(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) @@ -101,7 +117,7 @@ func (c *ApiService) FetchBucket(ServiceSid string, RateLimitSid string, Sid str data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -135,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.PageBucketWithCtx(context.TODO(), ServiceSid, RateLimitSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Bucket records from the API. Request is executed immediately. +func (c *ApiService) PageBucketWithCtx(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) @@ -154,7 +175,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -171,7 +192,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.ListBucketWithCtx(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) ListBucketWithCtx(ctx context.Context, ServiceSid string, RateLimitSid string, params *ListBucketParams) ([]VerifyV2Bucket, error) { + response, errors := c.StreamBucketWithCtx(ctx, ServiceSid, RateLimitSid, params) records := make([]VerifyV2Bucket, 0) for record := range response { @@ -187,6 +213,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.StreamBucketWithCtx(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) StreamBucketWithCtx(ctx context.Context, ServiceSid string, RateLimitSid string, params *ListBucketParams) (chan VerifyV2Bucket, chan error) { if params == nil { params = &ListBucketParams{} } @@ -195,19 +226,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.PageBucketWithCtx(ctx, ServiceSid, RateLimitSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamBucket(response, params, recordChannel, errorChannel) + go c.streamBucket(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) streamBucket(ctx context.Context, response *ListBucketResponse, params *ListBucketParams, recordChannel chan VerifyV2Bucket, errorChannel chan error) { curRecord := 1 for response != nil { @@ -222,7 +253,7 @@ func (c *ApiService) streamBucket(response *ListBucketResponse, params *ListBuck } } - record, err := client.GetNext(c.baseURL, response, c.getNextListBucketResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListBucketResponse) if err != nil { errorChannel <- err break @@ -237,11 +268,11 @@ func (c *ApiService) streamBucket(response *ListBucketResponse, params *ListBuck close(errorChannel) } -func (c *ApiService) getNextListBucketResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListBucketResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -274,6 +305,11 @@ 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.UpdateBucketWithCtx(context.TODO(), ServiceSid, RateLimitSid, Sid, params) +} + +// Update a specific Bucket. +func (c *ApiService) UpdateBucketWithCtx(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) @@ -289,7 +325,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.Post(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 0f2caad79..ec2bf813e 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" @@ -57,6 +58,11 @@ func (params *CreateVerificationCheckParams) SetPayee(Payee string) *CreateVerif // challenge a specific Verification Check. func (c *ApiService) CreateVerificationCheck(ServiceSid string, params *CreateVerificationCheckParams) (*VerifyV2VerificationCheck, error) { + return c.CreateVerificationCheckWithCtx(context.TODO(), ServiceSid, params) +} + +// challenge a specific Verification Check. +func (c *ApiService) CreateVerificationCheckWithCtx(ctx context.Context, ServiceSid string, params *CreateVerificationCheckParams) (*VerifyV2VerificationCheck, error) { path := "/v2/Services/{ServiceSid}/VerificationCheck" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -79,7 +85,7 @@ func (c *ApiService) CreateVerificationCheck(ServiceSid string, params *CreateVe data.Set("Payee", *params.Payee) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 014e7ceda..ecad5ee14 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" "net/url" "strings" @@ -111,6 +112,11 @@ func (params *CreateVerificationParams) SetTemplateCustomSubstitutions(TemplateC // Create a new Verification using a Service func (c *ApiService) CreateVerification(ServiceSid string, params *CreateVerificationParams) (*VerifyV2Verification, error) { + return c.CreateVerificationWithCtx(context.TODO(), ServiceSid, params) +} + +// Create a new Verification using a Service +func (c *ApiService) CreateVerificationWithCtx(ctx context.Context, ServiceSid string, params *CreateVerificationParams) (*VerifyV2Verification, error) { path := "/v2/Services/{ServiceSid}/Verifications" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -172,7 +178,7 @@ func (c *ApiService) CreateVerification(ServiceSid string, params *CreateVerific data.Set("TemplateCustomSubstitutions", *params.TemplateCustomSubstitutions) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -189,6 +195,11 @@ func (c *ApiService) CreateVerification(ServiceSid string, params *CreateVerific // Fetch a specific Verification func (c *ApiService) FetchVerification(ServiceSid string, Sid string) (*VerifyV2Verification, error) { + return c.FetchVerificationWithCtx(context.TODO(), ServiceSid, Sid) +} + +// Fetch a specific Verification +func (c *ApiService) FetchVerificationWithCtx(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) @@ -196,7 +207,7 @@ func (c *ApiService) FetchVerification(ServiceSid string, Sid string) (*VerifyV2 data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -224,6 +235,11 @@ 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.UpdateVerificationWithCtx(context.TODO(), ServiceSid, Sid, params) +} + +// Update a Verification status +func (c *ApiService) UpdateVerificationWithCtx(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) @@ -235,7 +251,7 @@ func (c *ApiService) UpdateVerification(ServiceSid string, Sid string, params *U data.Set("Status", *params.Status) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 46dd9318c..e3b8eea57 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,11 @@ 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.CreateWebhookWithCtx(context.TODO(), ServiceSid, params) +} + +// Create a new Webhook for the Service +func (c *ApiService) CreateWebhookWithCtx(ctx context.Context, ServiceSid string, params *CreateWebhookParams) (*VerifyV2Webhook, error) { path := "/v2/Services/{ServiceSid}/Webhooks" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -84,7 +90,7 @@ func (c *ApiService) CreateWebhook(ServiceSid string, params *CreateWebhookParam data.Set("Version", *params.Version) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -101,6 +107,11 @@ func (c *ApiService) CreateWebhook(ServiceSid string, params *CreateWebhookParam // Delete a specific Webhook. func (c *ApiService) DeleteWebhook(ServiceSid string, Sid string) error { + return c.DeleteWebhookWithCtx(context.TODO(), ServiceSid, Sid) +} + +// Delete a specific Webhook. +func (c *ApiService) DeleteWebhookWithCtx(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) @@ -108,7 +119,7 @@ func (c *ApiService) DeleteWebhook(ServiceSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -120,6 +131,11 @@ 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.FetchWebhookWithCtx(context.TODO(), ServiceSid, Sid) +} + +// Fetch a specific Webhook. +func (c *ApiService) FetchWebhookWithCtx(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) @@ -127,7 +143,7 @@ func (c *ApiService) FetchWebhook(ServiceSid string, Sid string) (*VerifyV2Webho data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -161,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.PageWebhookWithCtx(context.TODO(), ServiceSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of Webhook records from the API. Request is executed immediately. +func (c *ApiService) PageWebhookWithCtx(ctx context.Context, ServiceSid string, params *ListWebhookParams, pageToken, pageNumber string) (*ListWebhookResponse, error) { path := "/v2/Services/{ServiceSid}/Webhooks" path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1) @@ -179,7 +200,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -196,7 +217,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.ListWebhookWithCtx(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) ListWebhookWithCtx(ctx context.Context, ServiceSid string, params *ListWebhookParams) ([]VerifyV2Webhook, error) { + response, errors := c.StreamWebhookWithCtx(ctx, ServiceSid, params) records := make([]VerifyV2Webhook, 0) for record := range response { @@ -212,6 +238,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.StreamWebhookWithCtx(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) StreamWebhookWithCtx(ctx context.Context, ServiceSid string, params *ListWebhookParams) (chan VerifyV2Webhook, chan error) { if params == nil { params = &ListWebhookParams{} } @@ -220,19 +251,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.PageWebhookWithCtx(ctx, ServiceSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamWebhook(response, params, recordChannel, errorChannel) + go c.streamWebhook(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) streamWebhook(ctx context.Context, response *ListWebhookResponse, params *ListWebhookParams, recordChannel chan VerifyV2Webhook, errorChannel chan error) { curRecord := 1 for response != nil { @@ -247,7 +278,7 @@ func (c *ApiService) streamWebhook(response *ListWebhookResponse, params *ListWe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListWebhookResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListWebhookResponse) if err != nil { errorChannel <- err break @@ -262,11 +293,11 @@ func (c *ApiService) streamWebhook(response *ListWebhookResponse, params *ListWe close(errorChannel) } -func (c *ApiService) getNextListWebhookResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListWebhookResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -317,6 +348,11 @@ func (params *UpdateWebhookParams) SetVersion(Version string) *UpdateWebhookPara // func (c *ApiService) UpdateWebhook(ServiceSid string, Sid string, params *UpdateWebhookParams) (*VerifyV2Webhook, error) { + return c.UpdateWebhookWithCtx(context.TODO(), ServiceSid, Sid, params) +} + +// +func (c *ApiService) UpdateWebhookWithCtx(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) @@ -342,7 +378,7 @@ func (c *ApiService) UpdateWebhook(ServiceSid string, Sid string, params *Update data.Set("Version", *params.Version) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 f7acef3f1..abb0dea23 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.PageVerificationTemplateWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of VerificationTemplate records from the API. Request is executed immediately. +func (c *ApiService) PageVerificationTemplateWithCtx(ctx context.Context, params *ListVerificationTemplateParams, pageToken, pageNumber string) (*ListVerificationTemplateResponse, error) { path := "/v2/Templates" data := url.Values{} @@ -66,7 +72,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -83,7 +89,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.ListVerificationTemplateWithCtx(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) ListVerificationTemplateWithCtx(ctx context.Context, params *ListVerificationTemplateParams) ([]VerifyV2VerificationTemplate, error) { + response, errors := c.StreamVerificationTemplateWithCtx(ctx, params) records := make([]VerifyV2VerificationTemplate, 0) for record := range response { @@ -99,6 +110,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.StreamVerificationTemplateWithCtx(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) StreamVerificationTemplateWithCtx(ctx context.Context, params *ListVerificationTemplateParams) (chan VerifyV2VerificationTemplate, chan error) { if params == nil { params = &ListVerificationTemplateParams{} } @@ -107,19 +123,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.PageVerificationTemplateWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamVerificationTemplate(response, params, recordChannel, errorChannel) + go c.streamVerificationTemplate(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) streamVerificationTemplate(ctx context.Context, response *ListVerificationTemplateResponse, params *ListVerificationTemplateParams, recordChannel chan VerifyV2VerificationTemplate, errorChannel chan error) { curRecord := 1 for response != nil { @@ -134,7 +150,7 @@ func (c *ApiService) streamVerificationTemplate(response *ListVerificationTempla } } - record, err := client.GetNext(c.baseURL, response, c.getNextListVerificationTemplateResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListVerificationTemplateResponse) if err != nil { errorChannel <- err break @@ -149,11 +165,11 @@ func (c *ApiService) streamVerificationTemplate(response *ListVerificationTempla close(errorChannel) } -func (c *ApiService) getNextListVerificationTemplateResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListVerificationTemplateResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 e5f66e599..4a9d3d427 100644 --- a/rest/video/v1/api_service.go +++ b/rest/video/v1/api_service.go @@ -20,10 +20,14 @@ import ( type ApiService struct { baseURL string - requestHandler *twilio.RequestHandler + requestHandler *twilio.RequestHandlerWithCtx } func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { + return NewApiServiceWithCtx(twilio.UpgradeRequestHandler(requestHandler)) +} + +func NewApiServiceWithCtx(requestHandler *twilio.RequestHandlerWithCtx) *ApiService { return &ApiService{ requestHandler: requestHandler, baseURL: "https://video.twilio.com", @@ -33,3 +37,7 @@ func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { func NewApiServiceWithClient(client twilio.BaseClient) *ApiService { return NewApiService(twilio.NewRequestHandler(client)) } + +func NewApiServiceWithClientWithCtx(client twilio.BaseClientWithCtx) *ApiService { + return NewApiServiceWithCtx(twilio.NewRequestHandlerWithCtx(client)) +} diff --git a/rest/video/v1/composition_hooks.go b/rest/video/v1/composition_hooks.go index dcf8e17df..391c7bdc9 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" @@ -91,6 +92,11 @@ func (params *CreateCompositionHookParams) SetTrim(Trim bool) *CreateComposition // func (c *ApiService) CreateCompositionHook(params *CreateCompositionHookParams) (*VideoV1CompositionHook, error) { + return c.CreateCompositionHookWithCtx(context.TODO(), params) +} + +// +func (c *ApiService) CreateCompositionHookWithCtx(ctx context.Context, params *CreateCompositionHookParams) (*VideoV1CompositionHook, error) { path := "/v1/CompositionHooks" data := url.Values{} @@ -137,7 +143,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -154,13 +160,18 @@ 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.DeleteCompositionHookWithCtx(context.TODO(), Sid) +} + +// Delete a Recording CompositionHook resource identified by a `CompositionHook SID`. +func (c *ApiService) DeleteCompositionHookWithCtx(ctx context.Context, Sid string) error { path := "/v1/CompositionHooks/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -172,13 +183,18 @@ 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.FetchCompositionHookWithCtx(context.TODO(), Sid) +} + +// Returns a single CompositionHook resource identified by a CompositionHook SID. +func (c *ApiService) FetchCompositionHookWithCtx(ctx context.Context, Sid string) (*VideoV1CompositionHook, error) { path := "/v1/CompositionHooks/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -236,6 +252,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.PageCompositionHookWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of CompositionHook records from the API. Request is executed immediately. +func (c *ApiService) PageCompositionHookWithCtx(ctx context.Context, params *ListCompositionHookParams, pageToken, pageNumber string) (*ListCompositionHookResponse, error) { path := "/v1/CompositionHooks" data := url.Values{} @@ -264,7 +285,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -281,7 +302,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.ListCompositionHookWithCtx(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) ListCompositionHookWithCtx(ctx context.Context, params *ListCompositionHookParams) ([]VideoV1CompositionHook, error) { + response, errors := c.StreamCompositionHookWithCtx(ctx, params) records := make([]VideoV1CompositionHook, 0) for record := range response { @@ -297,6 +323,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.StreamCompositionHookWithCtx(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) StreamCompositionHookWithCtx(ctx context.Context, params *ListCompositionHookParams) (chan VideoV1CompositionHook, chan error) { if params == nil { params = &ListCompositionHookParams{} } @@ -305,19 +336,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.PageCompositionHookWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamCompositionHook(response, params, recordChannel, errorChannel) + go c.streamCompositionHook(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) streamCompositionHook(ctx context.Context, response *ListCompositionHookResponse, params *ListCompositionHookParams, recordChannel chan VideoV1CompositionHook, errorChannel chan error) { curRecord := 1 for response != nil { @@ -332,7 +363,7 @@ func (c *ApiService) streamCompositionHook(response *ListCompositionHookResponse } } - record, err := client.GetNext(c.baseURL, response, c.getNextListCompositionHookResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListCompositionHookResponse) if err != nil { errorChannel <- err break @@ -347,11 +378,11 @@ func (c *ApiService) streamCompositionHook(response *ListCompositionHookResponse close(errorChannel) } -func (c *ApiService) getNextListCompositionHookResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListCompositionHookResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -432,6 +463,11 @@ func (params *UpdateCompositionHookParams) SetStatusCallbackMethod(StatusCallbac // func (c *ApiService) UpdateCompositionHook(Sid string, params *UpdateCompositionHookParams) (*VideoV1CompositionHook, error) { + return c.UpdateCompositionHookWithCtx(context.TODO(), Sid, params) +} + +// +func (c *ApiService) UpdateCompositionHookWithCtx(ctx context.Context, Sid string, params *UpdateCompositionHookParams) (*VideoV1CompositionHook, error) { path := "/v1/CompositionHooks/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -479,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.Post(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 cdb7f12fa..a324be51e 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" @@ -63,6 +64,11 @@ func (params *CreateCompositionSettingsParams) SetEncryptionEnabled(EncryptionEn // func (c *ApiService) CreateCompositionSettings(params *CreateCompositionSettingsParams) (*VideoV1CompositionSettings, error) { + return c.CreateCompositionSettingsWithCtx(context.TODO(), params) +} + +// +func (c *ApiService) CreateCompositionSettingsWithCtx(ctx context.Context, params *CreateCompositionSettingsParams) (*VideoV1CompositionSettings, error) { path := "/v1/CompositionSettings/Default" data := url.Values{} @@ -87,7 +93,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -104,12 +110,17 @@ func (c *ApiService) CreateCompositionSettings(params *CreateCompositionSettings // func (c *ApiService) FetchCompositionSettings() (*VideoV1CompositionSettings, error) { + return c.FetchCompositionSettingsWithCtx(context.TODO()) +} + +// +func (c *ApiService) FetchCompositionSettingsWithCtx(ctx context.Context) (*VideoV1CompositionSettings, error) { path := "/v1/CompositionSettings/Default" data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(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 d0dce4ee9..92e0229f5 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" @@ -85,6 +86,11 @@ func (params *CreateCompositionParams) SetTrim(Trim bool) *CreateCompositionPara // func (c *ApiService) CreateComposition(params *CreateCompositionParams) (*VideoV1Composition, error) { + return c.CreateCompositionWithCtx(context.TODO(), params) +} + +// +func (c *ApiService) CreateCompositionWithCtx(ctx context.Context, params *CreateCompositionParams) (*VideoV1Composition, error) { path := "/v1/Compositions" data := url.Values{} @@ -128,7 +134,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -145,13 +151,18 @@ 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.DeleteCompositionWithCtx(context.TODO(), Sid) +} + +// Delete a Recording Composition resource identified by a Composition SID. +func (c *ApiService) DeleteCompositionWithCtx(ctx context.Context, Sid string) error { path := "/v1/Compositions/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -163,13 +174,18 @@ 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.FetchCompositionWithCtx(context.TODO(), Sid) +} + +// Returns a single Composition resource identified by a Composition SID. +func (c *ApiService) FetchCompositionWithCtx(ctx context.Context, Sid string) (*VideoV1Composition, error) { path := "/v1/Compositions/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -227,6 +243,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.PageCompositionWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Composition records from the API. Request is executed immediately. +func (c *ApiService) PageCompositionWithCtx(ctx context.Context, params *ListCompositionParams, pageToken, pageNumber string) (*ListCompositionResponse, error) { path := "/v1/Compositions" data := url.Values{} @@ -255,7 +276,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -272,7 +293,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.ListCompositionWithCtx(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) ListCompositionWithCtx(ctx context.Context, params *ListCompositionParams) ([]VideoV1Composition, error) { + response, errors := c.StreamCompositionWithCtx(ctx, params) records := make([]VideoV1Composition, 0) for record := range response { @@ -288,6 +314,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.StreamCompositionWithCtx(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) StreamCompositionWithCtx(ctx context.Context, params *ListCompositionParams) (chan VideoV1Composition, chan error) { if params == nil { params = &ListCompositionParams{} } @@ -296,19 +327,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.PageCompositionWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamComposition(response, params, recordChannel, errorChannel) + go c.streamComposition(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) streamComposition(ctx context.Context, response *ListCompositionResponse, params *ListCompositionParams, recordChannel chan VideoV1Composition, errorChannel chan error) { curRecord := 1 for response != nil { @@ -323,7 +354,7 @@ func (c *ApiService) streamComposition(response *ListCompositionResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListCompositionResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListCompositionResponse) if err != nil { errorChannel <- err break @@ -338,11 +369,11 @@ func (c *ApiService) streamComposition(response *ListCompositionResponse, params close(errorChannel) } -func (c *ApiService) getNextListCompositionResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListCompositionResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 8b675feda..a5de99dea 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" @@ -63,6 +64,11 @@ func (params *CreateRecordingSettingsParams) SetEncryptionEnabled(EncryptionEnab // func (c *ApiService) CreateRecordingSettings(params *CreateRecordingSettingsParams) (*VideoV1RecordingSettings, error) { + return c.CreateRecordingSettingsWithCtx(context.TODO(), params) +} + +// +func (c *ApiService) CreateRecordingSettingsWithCtx(ctx context.Context, params *CreateRecordingSettingsParams) (*VideoV1RecordingSettings, error) { path := "/v1/RecordingSettings/Default" data := url.Values{} @@ -87,7 +93,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -104,12 +110,17 @@ func (c *ApiService) CreateRecordingSettings(params *CreateRecordingSettingsPara // func (c *ApiService) FetchRecordingSettings() (*VideoV1RecordingSettings, error) { + return c.FetchRecordingSettingsWithCtx(context.TODO()) +} + +// +func (c *ApiService) FetchRecordingSettingsWithCtx(ctx context.Context) (*VideoV1RecordingSettings, error) { path := "/v1/RecordingSettings/Default" data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(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 fede4f40f..9e4f419ac 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,13 +27,18 @@ import ( // Delete a Recording resource identified by a Recording SID. func (c *ApiService) DeleteRecording(Sid string) error { + return c.DeleteRecordingWithCtx(context.TODO(), Sid) +} + +// Delete a Recording resource identified by a Recording SID. +func (c *ApiService) DeleteRecordingWithCtx(ctx context.Context, Sid string) error { path := "/v1/Recordings/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -44,13 +50,18 @@ 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.FetchRecordingWithCtx(context.TODO(), Sid) +} + +// Returns a single Recording resource identified by a Recording SID. +func (c *ApiService) FetchRecordingWithCtx(ctx context.Context, Sid string) (*VideoV1Recording, error) { path := "/v1/Recordings/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -120,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.PageRecordingWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Recording records from the API. Request is executed immediately. +func (c *ApiService) PageRecordingWithCtx(ctx context.Context, params *ListRecordingParams, pageToken, pageNumber string) (*ListRecordingResponse, error) { path := "/v1/Recordings" data := url.Values{} @@ -156,7 +172,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -173,7 +189,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.ListRecordingWithCtx(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) ListRecordingWithCtx(ctx context.Context, params *ListRecordingParams) ([]VideoV1Recording, error) { + response, errors := c.StreamRecordingWithCtx(ctx, params) records := make([]VideoV1Recording, 0) for record := range response { @@ -189,6 +210,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.StreamRecordingWithCtx(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) StreamRecordingWithCtx(ctx context.Context, params *ListRecordingParams) (chan VideoV1Recording, chan error) { if params == nil { params = &ListRecordingParams{} } @@ -197,19 +223,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.PageRecordingWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamRecording(response, params, recordChannel, errorChannel) + go c.streamRecording(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) streamRecording(ctx context.Context, response *ListRecordingResponse, params *ListRecordingParams, recordChannel chan VideoV1Recording, errorChannel chan error) { curRecord := 1 for response != nil { @@ -224,7 +250,7 @@ func (c *ApiService) streamRecording(response *ListRecordingResponse, params *Li } } - record, err := client.GetNext(c.baseURL, response, c.getNextListRecordingResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListRecordingResponse) if err != nil { errorChannel <- err break @@ -239,11 +265,11 @@ func (c *ApiService) streamRecording(response *ListRecordingResponse, params *Li close(errorChannel) } -func (c *ApiService) getNextListRecordingResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListRecordingResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 f974f1c20..2637fc505 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" @@ -121,6 +122,11 @@ func (params *CreateRoomParams) SetLargeRoom(LargeRoom bool) *CreateRoomParams { // func (c *ApiService) CreateRoom(params *CreateRoomParams) (*VideoV1Room, error) { + return c.CreateRoomWithCtx(context.TODO(), params) +} + +// +func (c *ApiService) CreateRoomWithCtx(ctx context.Context, params *CreateRoomParams) (*VideoV1Room, error) { path := "/v1/Rooms" data := url.Values{} @@ -180,7 +186,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -197,13 +203,18 @@ func (c *ApiService) CreateRoom(params *CreateRoomParams) (*VideoV1Room, error) // func (c *ApiService) FetchRoom(Sid string) (*VideoV1Room, error) { + return c.FetchRoomWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) FetchRoomWithCtx(ctx context.Context, Sid string) (*VideoV1Room, error) { path := "/v1/Rooms/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -261,6 +272,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.PageRoomWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Room records from the API. Request is executed immediately. +func (c *ApiService) PageRoomWithCtx(ctx context.Context, params *ListRoomParams, pageToken, pageNumber string) (*ListRoomResponse, error) { path := "/v1/Rooms" data := url.Values{} @@ -289,7 +305,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -306,7 +322,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.ListRoomWithCtx(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) ListRoomWithCtx(ctx context.Context, params *ListRoomParams) ([]VideoV1Room, error) { + response, errors := c.StreamRoomWithCtx(ctx, params) records := make([]VideoV1Room, 0) for record := range response { @@ -322,6 +343,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.StreamRoomWithCtx(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) StreamRoomWithCtx(ctx context.Context, params *ListRoomParams) (chan VideoV1Room, chan error) { if params == nil { params = &ListRoomParams{} } @@ -330,19 +356,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.PageRoomWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamRoom(response, params, recordChannel, errorChannel) + go c.streamRoom(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) streamRoom(ctx context.Context, response *ListRoomResponse, params *ListRoomParams, recordChannel chan VideoV1Room, errorChannel chan error) { curRecord := 1 for response != nil { @@ -357,7 +383,7 @@ func (c *ApiService) streamRoom(response *ListRoomResponse, params *ListRoomPara } } - record, err := client.GetNext(c.baseURL, response, c.getNextListRoomResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListRoomResponse) if err != nil { errorChannel <- err break @@ -372,11 +398,11 @@ func (c *ApiService) streamRoom(response *ListRoomResponse, params *ListRoomPara close(errorChannel) } -func (c *ApiService) getNextListRoomResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListRoomResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -403,6 +429,11 @@ func (params *UpdateRoomParams) SetStatus(Status string) *UpdateRoomParams { // func (c *ApiService) UpdateRoom(Sid string, params *UpdateRoomParams) (*VideoV1Room, error) { + return c.UpdateRoomWithCtx(context.TODO(), Sid, params) +} + +// +func (c *ApiService) UpdateRoomWithCtx(ctx context.Context, Sid string, params *UpdateRoomParams) (*VideoV1Room, error) { path := "/v1/Rooms/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -413,7 +444,7 @@ func (c *ApiService) UpdateRoom(Sid string, params *UpdateRoomParams) (*VideoV1R data.Set("Status", *params.Status) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 af815d01e..7fa21c061 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" @@ -26,6 +27,11 @@ import ( // func (c *ApiService) FetchRoomParticipant(RoomSid string, Sid string) (*VideoV1RoomParticipant, error) { + return c.FetchRoomParticipantWithCtx(context.TODO(), RoomSid, Sid) +} + +// +func (c *ApiService) FetchRoomParticipantWithCtx(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) @@ -33,7 +39,7 @@ func (c *ApiService) FetchRoomParticipant(RoomSid string, Sid string) (*VideoV1R data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -91,6 +97,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.PageRoomParticipantWithCtx(context.TODO(), RoomSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of RoomParticipant records from the API. Request is executed immediately. +func (c *ApiService) PageRoomParticipantWithCtx(ctx context.Context, RoomSid string, params *ListRoomParticipantParams, pageToken, pageNumber string) (*ListRoomParticipantResponse, error) { path := "/v1/Rooms/{RoomSid}/Participants" path = strings.Replace(path, "{"+"RoomSid"+"}", RoomSid, -1) @@ -121,7 +132,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -138,7 +149,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.ListRoomParticipantWithCtx(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) ListRoomParticipantWithCtx(ctx context.Context, RoomSid string, params *ListRoomParticipantParams) ([]VideoV1RoomParticipant, error) { + response, errors := c.StreamRoomParticipantWithCtx(ctx, RoomSid, params) records := make([]VideoV1RoomParticipant, 0) for record := range response { @@ -154,6 +170,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.StreamRoomParticipantWithCtx(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) StreamRoomParticipantWithCtx(ctx context.Context, RoomSid string, params *ListRoomParticipantParams) (chan VideoV1RoomParticipant, chan error) { if params == nil { params = &ListRoomParticipantParams{} } @@ -162,19 +183,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.PageRoomParticipantWithCtx(ctx, RoomSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamRoomParticipant(response, params, recordChannel, errorChannel) + go c.streamRoomParticipant(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) streamRoomParticipant(ctx context.Context, response *ListRoomParticipantResponse, params *ListRoomParticipantParams, recordChannel chan VideoV1RoomParticipant, errorChannel chan error) { curRecord := 1 for response != nil { @@ -189,7 +210,7 @@ func (c *ApiService) streamRoomParticipant(response *ListRoomParticipantResponse } } - record, err := client.GetNext(c.baseURL, response, c.getNextListRoomParticipantResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListRoomParticipantResponse) if err != nil { errorChannel <- err break @@ -204,11 +225,11 @@ func (c *ApiService) streamRoomParticipant(response *ListRoomParticipantResponse close(errorChannel) } -func (c *ApiService) getNextListRoomParticipantResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListRoomParticipantResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -235,6 +256,11 @@ func (params *UpdateRoomParticipantParams) SetStatus(Status string) *UpdateRoomP // func (c *ApiService) UpdateRoomParticipant(RoomSid string, Sid string, params *UpdateRoomParticipantParams) (*VideoV1RoomParticipant, error) { + return c.UpdateRoomParticipantWithCtx(context.TODO(), RoomSid, Sid, params) +} + +// +func (c *ApiService) UpdateRoomParticipantWithCtx(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) @@ -246,7 +272,7 @@ func (c *ApiService) UpdateRoomParticipant(RoomSid string, Sid string, params *U data.Set("Status", *params.Status) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 509352a4d..9b5f75602 100644 --- a/rest/video/v1/rooms_participants_anonymize.go +++ b/rest/video/v1/rooms_participants_anonymize.go @@ -15,6 +15,7 @@ package openapi import ( + "context" "encoding/json" "net/url" "strings" @@ -22,6 +23,11 @@ import ( // func (c *ApiService) UpdateRoomParticipantAnonymize(RoomSid string, Sid string) (*VideoV1RoomParticipantAnonymize, error) { + return c.UpdateRoomParticipantAnonymizeWithCtx(context.TODO(), RoomSid, Sid) +} + +// +func (c *ApiService) UpdateRoomParticipantAnonymizeWithCtx(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) @@ -29,7 +35,7 @@ func (c *ApiService) UpdateRoomParticipantAnonymize(RoomSid string, Sid string) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(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 940564dc0..fe0710fad 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,11 @@ 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.FetchRoomParticipantPublishedTrackWithCtx(context.TODO(), RoomSid, ParticipantSid, Sid) +} + +// Returns a single Track resource represented by TrackName or SID. +func (c *ApiService) FetchRoomParticipantPublishedTrackWithCtx(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) @@ -33,7 +39,7 @@ func (c *ApiService) FetchRoomParticipantPublishedTrack(RoomSid string, Particip data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -67,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.PageRoomParticipantPublishedTrackWithCtx(context.TODO(), RoomSid, ParticipantSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of RoomParticipantPublishedTrack records from the API. Request is executed immediately. +func (c *ApiService) PageRoomParticipantPublishedTrackWithCtx(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) @@ -86,7 +97,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -103,7 +114,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.ListRoomParticipantPublishedTrackWithCtx(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) ListRoomParticipantPublishedTrackWithCtx(ctx context.Context, RoomSid string, ParticipantSid string, params *ListRoomParticipantPublishedTrackParams) ([]VideoV1RoomParticipantPublishedTrack, error) { + response, errors := c.StreamRoomParticipantPublishedTrackWithCtx(ctx, RoomSid, ParticipantSid, params) records := make([]VideoV1RoomParticipantPublishedTrack, 0) for record := range response { @@ -119,6 +135,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.StreamRoomParticipantPublishedTrackWithCtx(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) StreamRoomParticipantPublishedTrackWithCtx(ctx context.Context, RoomSid string, ParticipantSid string, params *ListRoomParticipantPublishedTrackParams) (chan VideoV1RoomParticipantPublishedTrack, chan error) { if params == nil { params = &ListRoomParticipantPublishedTrackParams{} } @@ -127,19 +148,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.PageRoomParticipantPublishedTrackWithCtx(ctx, RoomSid, ParticipantSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamRoomParticipantPublishedTrack(response, params, recordChannel, errorChannel) + go c.streamRoomParticipantPublishedTrack(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) streamRoomParticipantPublishedTrack(ctx context.Context, response *ListRoomParticipantPublishedTrackResponse, params *ListRoomParticipantPublishedTrackParams, recordChannel chan VideoV1RoomParticipantPublishedTrack, errorChannel chan error) { curRecord := 1 for response != nil { @@ -154,7 +175,7 @@ func (c *ApiService) streamRoomParticipantPublishedTrack(response *ListRoomParti } } - record, err := client.GetNext(c.baseURL, response, c.getNextListRoomParticipantPublishedTrackResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListRoomParticipantPublishedTrackResponse) if err != nil { errorChannel <- err break @@ -169,11 +190,11 @@ func (c *ApiService) streamRoomParticipantPublishedTrack(response *ListRoomParti close(errorChannel) } -func (c *ApiService) getNextListRoomParticipantPublishedTrackResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListRoomParticipantPublishedTrackResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 551ff66a2..112211f87 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,11 @@ import ( // Returns a list of Subscribe Rules for the Participant. func (c *ApiService) FetchRoomParticipantSubscribeRule(RoomSid string, ParticipantSid string) (*VideoV1RoomParticipantSubscribeRule, error) { + return c.FetchRoomParticipantSubscribeRuleWithCtx(context.TODO(), RoomSid, ParticipantSid) +} + +// Returns a list of Subscribe Rules for the Participant. +func (c *ApiService) FetchRoomParticipantSubscribeRuleWithCtx(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) @@ -29,7 +35,7 @@ func (c *ApiService) FetchRoomParticipantSubscribeRule(RoomSid string, Participa data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -57,6 +63,11 @@ func (params *UpdateRoomParticipantSubscribeRuleParams) SetRules(Rules interface // Update the Subscribe Rules for the Participant func (c *ApiService) UpdateRoomParticipantSubscribeRule(RoomSid string, ParticipantSid string, params *UpdateRoomParticipantSubscribeRuleParams) (*VideoV1RoomParticipantSubscribeRule, error) { + return c.UpdateRoomParticipantSubscribeRuleWithCtx(context.TODO(), RoomSid, ParticipantSid, params) +} + +// Update the Subscribe Rules for the Participant +func (c *ApiService) UpdateRoomParticipantSubscribeRuleWithCtx(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) @@ -74,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.Post(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 ad65dce4a..7f62d5187 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,11 @@ 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.FetchRoomParticipantSubscribedTrackWithCtx(context.TODO(), RoomSid, ParticipantSid, Sid) +} + +// 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) FetchRoomParticipantSubscribedTrackWithCtx(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) @@ -33,7 +39,7 @@ func (c *ApiService) FetchRoomParticipantSubscribedTrack(RoomSid string, Partici data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -67,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.PageRoomParticipantSubscribedTrackWithCtx(context.TODO(), RoomSid, ParticipantSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of RoomParticipantSubscribedTrack records from the API. Request is executed immediately. +func (c *ApiService) PageRoomParticipantSubscribedTrackWithCtx(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) @@ -86,7 +97,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -103,7 +114,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.ListRoomParticipantSubscribedTrackWithCtx(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) ListRoomParticipantSubscribedTrackWithCtx(ctx context.Context, RoomSid string, ParticipantSid string, params *ListRoomParticipantSubscribedTrackParams) ([]VideoV1RoomParticipantSubscribedTrack, error) { + response, errors := c.StreamRoomParticipantSubscribedTrackWithCtx(ctx, RoomSid, ParticipantSid, params) records := make([]VideoV1RoomParticipantSubscribedTrack, 0) for record := range response { @@ -119,6 +135,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.StreamRoomParticipantSubscribedTrackWithCtx(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) StreamRoomParticipantSubscribedTrackWithCtx(ctx context.Context, RoomSid string, ParticipantSid string, params *ListRoomParticipantSubscribedTrackParams) (chan VideoV1RoomParticipantSubscribedTrack, chan error) { if params == nil { params = &ListRoomParticipantSubscribedTrackParams{} } @@ -127,19 +148,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.PageRoomParticipantSubscribedTrackWithCtx(ctx, RoomSid, ParticipantSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamRoomParticipantSubscribedTrack(response, params, recordChannel, errorChannel) + go c.streamRoomParticipantSubscribedTrack(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) streamRoomParticipantSubscribedTrack(ctx context.Context, response *ListRoomParticipantSubscribedTrackResponse, params *ListRoomParticipantSubscribedTrackParams, recordChannel chan VideoV1RoomParticipantSubscribedTrack, errorChannel chan error) { curRecord := 1 for response != nil { @@ -154,7 +175,7 @@ func (c *ApiService) streamRoomParticipantSubscribedTrack(response *ListRoomPart } } - record, err := client.GetNext(c.baseURL, response, c.getNextListRoomParticipantSubscribedTrackResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListRoomParticipantSubscribedTrackResponse) if err != nil { errorChannel <- err break @@ -169,11 +190,11 @@ func (c *ApiService) streamRoomParticipantSubscribedTrack(response *ListRoomPart close(errorChannel) } -func (c *ApiService) getNextListRoomParticipantSubscribedTrackResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListRoomParticipantSubscribedTrackResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 2553d3a4b..707397d31 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,13 +23,18 @@ import ( // Returns a list of Recording Rules for the Room. func (c *ApiService) FetchRoomRecordingRule(RoomSid string) (*VideoV1RoomRecordingRule, error) { + return c.FetchRoomRecordingRuleWithCtx(context.TODO(), RoomSid) +} + +// Returns a list of Recording Rules for the Room. +func (c *ApiService) FetchRoomRecordingRuleWithCtx(ctx context.Context, RoomSid string) (*VideoV1RoomRecordingRule, error) { path := "/v1/Rooms/{RoomSid}/RecordingRules" path = strings.Replace(path, "{"+"RoomSid"+"}", RoomSid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -56,6 +62,11 @@ func (params *UpdateRoomRecordingRuleParams) SetRules(Rules interface{}) *Update // Update the Recording Rules for the Room func (c *ApiService) UpdateRoomRecordingRule(RoomSid string, params *UpdateRoomRecordingRuleParams) (*VideoV1RoomRecordingRule, error) { + return c.UpdateRoomRecordingRuleWithCtx(context.TODO(), RoomSid, params) +} + +// Update the Recording Rules for the Room +func (c *ApiService) UpdateRoomRecordingRuleWithCtx(ctx context.Context, RoomSid string, params *UpdateRoomRecordingRuleParams) (*VideoV1RoomRecordingRule, error) { path := "/v1/Rooms/{RoomSid}/RecordingRules" path = strings.Replace(path, "{"+"RoomSid"+"}", RoomSid, -1) @@ -72,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.Post(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 37b72820c..a780caab9 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" @@ -26,6 +27,11 @@ import ( // func (c *ApiService) DeleteRoomRecording(RoomSid string, Sid string) error { + return c.DeleteRoomRecordingWithCtx(context.TODO(), RoomSid, Sid) +} + +// +func (c *ApiService) DeleteRoomRecordingWithCtx(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) @@ -33,7 +39,7 @@ func (c *ApiService) DeleteRoomRecording(RoomSid string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -45,6 +51,11 @@ func (c *ApiService) DeleteRoomRecording(RoomSid string, Sid string) error { // func (c *ApiService) FetchRoomRecording(RoomSid string, Sid string) (*VideoV1RoomRecording, error) { + return c.FetchRoomRecordingWithCtx(context.TODO(), RoomSid, Sid) +} + +// +func (c *ApiService) FetchRoomRecordingWithCtx(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) @@ -52,7 +63,7 @@ func (c *ApiService) FetchRoomRecording(RoomSid string, Sid string) (*VideoV1Roo data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -110,6 +121,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.PageRoomRecordingWithCtx(context.TODO(), RoomSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of RoomRecording records from the API. Request is executed immediately. +func (c *ApiService) PageRoomRecordingWithCtx(ctx context.Context, RoomSid string, params *ListRoomRecordingParams, pageToken, pageNumber string) (*ListRoomRecordingResponse, error) { path := "/v1/Rooms/{RoomSid}/Recordings" path = strings.Replace(path, "{"+"RoomSid"+"}", RoomSid, -1) @@ -140,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -157,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.ListRoomRecordingWithCtx(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) ListRoomRecordingWithCtx(ctx context.Context, RoomSid string, params *ListRoomRecordingParams) ([]VideoV1RoomRecording, error) { + response, errors := c.StreamRoomRecordingWithCtx(ctx, RoomSid, params) records := make([]VideoV1RoomRecording, 0) for record := range response { @@ -173,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.StreamRoomRecordingWithCtx(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) StreamRoomRecordingWithCtx(ctx context.Context, RoomSid string, params *ListRoomRecordingParams) (chan VideoV1RoomRecording, chan error) { if params == nil { params = &ListRoomRecordingParams{} } @@ -181,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.PageRoomRecordingWithCtx(ctx, RoomSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamRoomRecording(response, params, recordChannel, errorChannel) + go c.streamRoomRecording(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) streamRoomRecording(ctx context.Context, response *ListRoomRecordingResponse, params *ListRoomRecordingParams, recordChannel chan VideoV1RoomRecording, errorChannel chan error) { curRecord := 1 for response != nil { @@ -208,7 +234,7 @@ func (c *ApiService) streamRoomRecording(response *ListRoomRecordingResponse, pa } } - record, err := client.GetNext(c.baseURL, response, c.getNextListRoomRecordingResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListRoomRecordingResponse) if err != nil { errorChannel <- err break @@ -223,11 +249,11 @@ func (c *ApiService) streamRoomRecording(response *ListRoomRecordingResponse, pa close(errorChannel) } -func (c *ApiService) getNextListRoomRecordingResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListRoomRecordingResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 f8b84c0a6..c5e1554d7 100644 --- a/rest/voice/v1/api_service.go +++ b/rest/voice/v1/api_service.go @@ -20,10 +20,14 @@ import ( type ApiService struct { baseURL string - requestHandler *twilio.RequestHandler + requestHandler *twilio.RequestHandlerWithCtx } func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { + return NewApiServiceWithCtx(twilio.UpgradeRequestHandler(requestHandler)) +} + +func NewApiServiceWithCtx(requestHandler *twilio.RequestHandlerWithCtx) *ApiService { return &ApiService{ requestHandler: requestHandler, baseURL: "https://voice.twilio.com", @@ -33,3 +37,7 @@ func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { func NewApiServiceWithClient(client twilio.BaseClient) *ApiService { return NewApiService(twilio.NewRequestHandler(client)) } + +func NewApiServiceWithClientWithCtx(client twilio.BaseClientWithCtx) *ApiService { + return NewApiServiceWithCtx(twilio.NewRequestHandlerWithCtx(client)) +} diff --git a/rest/voice/v1/archives_calls.go b/rest/voice/v1/archives_calls.go index 2749cb824..59f997e5b 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,11 @@ 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.DeleteArchivedCallWithCtx(context.TODO(), Date, Sid) +} + +// Delete an archived call record from Bulk Export. Note: this does not also delete the record from the Voice API. +func (c *ApiService) DeleteArchivedCallWithCtx(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) @@ -29,7 +35,7 @@ func (c *ApiService) DeleteArchivedCall(Date string, Sid string) error { data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(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 8bc50ff79..b626caa5f 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" @@ -90,6 +91,11 @@ func (params *CreateByocTrunkParams) SetFromDomainSid(FromDomainSid string) *Cre // func (c *ApiService) CreateByocTrunk(params *CreateByocTrunkParams) (*VoiceV1ByocTrunk, error) { + return c.CreateByocTrunkWithCtx(context.TODO(), params) +} + +// +func (c *ApiService) CreateByocTrunkWithCtx(ctx context.Context, params *CreateByocTrunkParams) (*VoiceV1ByocTrunk, error) { path := "/v1/ByocTrunks" data := url.Values{} @@ -126,7 +132,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -143,13 +149,18 @@ func (c *ApiService) CreateByocTrunk(params *CreateByocTrunkParams) (*VoiceV1Byo // func (c *ApiService) DeleteByocTrunk(Sid string) error { + return c.DeleteByocTrunkWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) DeleteByocTrunkWithCtx(ctx context.Context, Sid string) error { path := "/v1/ByocTrunks/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -161,13 +172,18 @@ func (c *ApiService) DeleteByocTrunk(Sid string) error { // func (c *ApiService) FetchByocTrunk(Sid string) (*VoiceV1ByocTrunk, error) { + return c.FetchByocTrunkWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) FetchByocTrunkWithCtx(ctx context.Context, Sid string) (*VoiceV1ByocTrunk, error) { path := "/v1/ByocTrunks/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -201,6 +217,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.PageByocTrunkWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of ByocTrunk records from the API. Request is executed immediately. +func (c *ApiService) PageByocTrunkWithCtx(ctx context.Context, params *ListByocTrunkParams, pageToken, pageNumber string) (*ListByocTrunkResponse, error) { path := "/v1/ByocTrunks" data := url.Values{} @@ -217,7 +238,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -234,7 +255,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.ListByocTrunkWithCtx(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) ListByocTrunkWithCtx(ctx context.Context, params *ListByocTrunkParams) ([]VoiceV1ByocTrunk, error) { + response, errors := c.StreamByocTrunkWithCtx(ctx, params) records := make([]VoiceV1ByocTrunk, 0) for record := range response { @@ -250,6 +276,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.StreamByocTrunkWithCtx(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) StreamByocTrunkWithCtx(ctx context.Context, params *ListByocTrunkParams) (chan VoiceV1ByocTrunk, chan error) { if params == nil { params = &ListByocTrunkParams{} } @@ -258,19 +289,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.PageByocTrunkWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamByocTrunk(response, params, recordChannel, errorChannel) + go c.streamByocTrunk(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) streamByocTrunk(ctx context.Context, response *ListByocTrunkResponse, params *ListByocTrunkParams, recordChannel chan VoiceV1ByocTrunk, errorChannel chan error) { curRecord := 1 for response != nil { @@ -285,7 +316,7 @@ func (c *ApiService) streamByocTrunk(response *ListByocTrunkResponse, params *Li } } - record, err := client.GetNext(c.baseURL, response, c.getNextListByocTrunkResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListByocTrunkResponse) if err != nil { errorChannel <- err break @@ -300,11 +331,11 @@ func (c *ApiService) streamByocTrunk(response *ListByocTrunkResponse, params *Li close(errorChannel) } -func (c *ApiService) getNextListByocTrunkResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListByocTrunkResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -385,6 +416,11 @@ func (params *UpdateByocTrunkParams) SetFromDomainSid(FromDomainSid string) *Upd // func (c *ApiService) UpdateByocTrunk(Sid string, params *UpdateByocTrunkParams) (*VoiceV1ByocTrunk, error) { + return c.UpdateByocTrunkWithCtx(context.TODO(), Sid, params) +} + +// +func (c *ApiService) UpdateByocTrunkWithCtx(ctx context.Context, Sid string, params *UpdateByocTrunkParams) (*VoiceV1ByocTrunk, error) { path := "/v1/ByocTrunks/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -422,7 +458,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.Post(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 24eda12dd..60f65bc0a 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" @@ -36,6 +37,11 @@ func (params *CreateConnectionPolicyParams) SetFriendlyName(FriendlyName string) // func (c *ApiService) CreateConnectionPolicy(params *CreateConnectionPolicyParams) (*VoiceV1ConnectionPolicy, error) { + return c.CreateConnectionPolicyWithCtx(context.TODO(), params) +} + +// +func (c *ApiService) CreateConnectionPolicyWithCtx(ctx context.Context, params *CreateConnectionPolicyParams) (*VoiceV1ConnectionPolicy, error) { path := "/v1/ConnectionPolicies" data := url.Values{} @@ -45,7 +51,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -62,13 +68,18 @@ func (c *ApiService) CreateConnectionPolicy(params *CreateConnectionPolicyParams // func (c *ApiService) DeleteConnectionPolicy(Sid string) error { + return c.DeleteConnectionPolicyWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) DeleteConnectionPolicyWithCtx(ctx context.Context, Sid string) error { path := "/v1/ConnectionPolicies/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -80,13 +91,18 @@ func (c *ApiService) DeleteConnectionPolicy(Sid string) error { // func (c *ApiService) FetchConnectionPolicy(Sid string) (*VoiceV1ConnectionPolicy, error) { + return c.FetchConnectionPolicyWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) FetchConnectionPolicyWithCtx(ctx context.Context, Sid string) (*VoiceV1ConnectionPolicy, error) { path := "/v1/ConnectionPolicies/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -120,6 +136,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.PageConnectionPolicyWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of ConnectionPolicy records from the API. Request is executed immediately. +func (c *ApiService) PageConnectionPolicyWithCtx(ctx context.Context, params *ListConnectionPolicyParams, pageToken, pageNumber string) (*ListConnectionPolicyResponse, error) { path := "/v1/ConnectionPolicies" data := url.Values{} @@ -136,7 +157,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -153,7 +174,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.ListConnectionPolicyWithCtx(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) ListConnectionPolicyWithCtx(ctx context.Context, params *ListConnectionPolicyParams) ([]VoiceV1ConnectionPolicy, error) { + response, errors := c.StreamConnectionPolicyWithCtx(ctx, params) records := make([]VoiceV1ConnectionPolicy, 0) for record := range response { @@ -169,6 +195,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.StreamConnectionPolicyWithCtx(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) StreamConnectionPolicyWithCtx(ctx context.Context, params *ListConnectionPolicyParams) (chan VoiceV1ConnectionPolicy, chan error) { if params == nil { params = &ListConnectionPolicyParams{} } @@ -177,19 +208,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.PageConnectionPolicyWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamConnectionPolicy(response, params, recordChannel, errorChannel) + go c.streamConnectionPolicy(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) streamConnectionPolicy(ctx context.Context, response *ListConnectionPolicyResponse, params *ListConnectionPolicyParams, recordChannel chan VoiceV1ConnectionPolicy, errorChannel chan error) { curRecord := 1 for response != nil { @@ -204,7 +235,7 @@ func (c *ApiService) streamConnectionPolicy(response *ListConnectionPolicyRespon } } - record, err := client.GetNext(c.baseURL, response, c.getNextListConnectionPolicyResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListConnectionPolicyResponse) if err != nil { errorChannel <- err break @@ -219,11 +250,11 @@ func (c *ApiService) streamConnectionPolicy(response *ListConnectionPolicyRespon close(errorChannel) } -func (c *ApiService) getNextListConnectionPolicyResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListConnectionPolicyResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -250,6 +281,11 @@ func (params *UpdateConnectionPolicyParams) SetFriendlyName(FriendlyName string) // func (c *ApiService) UpdateConnectionPolicy(Sid string, params *UpdateConnectionPolicyParams) (*VoiceV1ConnectionPolicy, error) { + return c.UpdateConnectionPolicyWithCtx(context.TODO(), Sid, params) +} + +// +func (c *ApiService) UpdateConnectionPolicyWithCtx(ctx context.Context, Sid string, params *UpdateConnectionPolicyParams) (*VoiceV1ConnectionPolicy, error) { path := "/v1/ConnectionPolicies/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -260,7 +296,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.Post(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 015b0c972..7974d8a8f 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" @@ -60,6 +61,11 @@ func (params *CreateConnectionPolicyTargetParams) SetEnabled(Enabled bool) *Crea // func (c *ApiService) CreateConnectionPolicyTarget(ConnectionPolicySid string, params *CreateConnectionPolicyTargetParams) (*VoiceV1ConnectionPolicyTarget, error) { + return c.CreateConnectionPolicyTargetWithCtx(context.TODO(), ConnectionPolicySid, params) +} + +// +func (c *ApiService) CreateConnectionPolicyTargetWithCtx(ctx context.Context, ConnectionPolicySid string, params *CreateConnectionPolicyTargetParams) (*VoiceV1ConnectionPolicyTarget, error) { path := "/v1/ConnectionPolicies/{ConnectionPolicySid}/Targets" path = strings.Replace(path, "{"+"ConnectionPolicySid"+"}", ConnectionPolicySid, -1) @@ -82,7 +88,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -99,6 +105,11 @@ func (c *ApiService) CreateConnectionPolicyTarget(ConnectionPolicySid string, pa // func (c *ApiService) DeleteConnectionPolicyTarget(ConnectionPolicySid string, Sid string) error { + return c.DeleteConnectionPolicyTargetWithCtx(context.TODO(), ConnectionPolicySid, Sid) +} + +// +func (c *ApiService) DeleteConnectionPolicyTargetWithCtx(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) @@ -106,7 +117,7 @@ func (c *ApiService) DeleteConnectionPolicyTarget(ConnectionPolicySid string, Si data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -118,6 +129,11 @@ func (c *ApiService) DeleteConnectionPolicyTarget(ConnectionPolicySid string, Si // func (c *ApiService) FetchConnectionPolicyTarget(ConnectionPolicySid string, Sid string) (*VoiceV1ConnectionPolicyTarget, error) { + return c.FetchConnectionPolicyTargetWithCtx(context.TODO(), ConnectionPolicySid, Sid) +} + +// +func (c *ApiService) FetchConnectionPolicyTargetWithCtx(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) @@ -125,7 +141,7 @@ func (c *ApiService) FetchConnectionPolicyTarget(ConnectionPolicySid string, Sid data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -159,6 +175,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.PageConnectionPolicyTargetWithCtx(context.TODO(), ConnectionPolicySid, params, pageToken, pageNumber) +} + +// Retrieve a single page of ConnectionPolicyTarget records from the API. Request is executed immediately. +func (c *ApiService) PageConnectionPolicyTargetWithCtx(ctx context.Context, ConnectionPolicySid string, params *ListConnectionPolicyTargetParams, pageToken, pageNumber string) (*ListConnectionPolicyTargetResponse, error) { path := "/v1/ConnectionPolicies/{ConnectionPolicySid}/Targets" path = strings.Replace(path, "{"+"ConnectionPolicySid"+"}", ConnectionPolicySid, -1) @@ -177,7 +198,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -194,7 +215,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.ListConnectionPolicyTargetWithCtx(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) ListConnectionPolicyTargetWithCtx(ctx context.Context, ConnectionPolicySid string, params *ListConnectionPolicyTargetParams) ([]VoiceV1ConnectionPolicyTarget, error) { + response, errors := c.StreamConnectionPolicyTargetWithCtx(ctx, ConnectionPolicySid, params) records := make([]VoiceV1ConnectionPolicyTarget, 0) for record := range response { @@ -210,6 +236,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.StreamConnectionPolicyTargetWithCtx(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) StreamConnectionPolicyTargetWithCtx(ctx context.Context, ConnectionPolicySid string, params *ListConnectionPolicyTargetParams) (chan VoiceV1ConnectionPolicyTarget, chan error) { if params == nil { params = &ListConnectionPolicyTargetParams{} } @@ -218,19 +249,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.PageConnectionPolicyTargetWithCtx(ctx, ConnectionPolicySid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamConnectionPolicyTarget(response, params, recordChannel, errorChannel) + go c.streamConnectionPolicyTarget(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) streamConnectionPolicyTarget(ctx context.Context, response *ListConnectionPolicyTargetResponse, params *ListConnectionPolicyTargetParams, recordChannel chan VoiceV1ConnectionPolicyTarget, errorChannel chan error) { curRecord := 1 for response != nil { @@ -245,7 +276,7 @@ func (c *ApiService) streamConnectionPolicyTarget(response *ListConnectionPolicy } } - record, err := client.GetNext(c.baseURL, response, c.getNextListConnectionPolicyTargetResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListConnectionPolicyTargetResponse) if err != nil { errorChannel <- err break @@ -260,11 +291,11 @@ func (c *ApiService) streamConnectionPolicyTarget(response *ListConnectionPolicy close(errorChannel) } -func (c *ApiService) getNextListConnectionPolicyTargetResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListConnectionPolicyTargetResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -315,6 +346,11 @@ func (params *UpdateConnectionPolicyTargetParams) SetEnabled(Enabled bool) *Upda // func (c *ApiService) UpdateConnectionPolicyTarget(ConnectionPolicySid string, Sid string, params *UpdateConnectionPolicyTargetParams) (*VoiceV1ConnectionPolicyTarget, error) { + return c.UpdateConnectionPolicyTargetWithCtx(context.TODO(), ConnectionPolicySid, Sid, params) +} + +// +func (c *ApiService) UpdateConnectionPolicyTargetWithCtx(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) @@ -338,7 +374,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.Post(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 7c8a3ddc8..2523d6bac 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,11 @@ 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.CreateDialingPermissionsCountryBulkUpdateWithCtx(context.TODO(), params) +} + +// 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) CreateDialingPermissionsCountryBulkUpdateWithCtx(ctx context.Context, params *CreateDialingPermissionsCountryBulkUpdateParams) (*VoiceV1DialingPermissionsCountryBulkUpdate, error) { path := "/v1/DialingPermissions/BulkCountryUpdates" data := url.Values{} @@ -41,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.Post(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 90e73b526..d1fd531a6 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,13 +26,18 @@ import ( // Retrieve voice dialing country permissions identified by the given ISO country code func (c *ApiService) FetchDialingPermissionsCountry(IsoCode string) (*VoiceV1DialingPermissionsCountryInstance, error) { + return c.FetchDialingPermissionsCountryWithCtx(context.TODO(), IsoCode) +} + +// Retrieve voice dialing country permissions identified by the given ISO country code +func (c *ApiService) FetchDialingPermissionsCountryWithCtx(ctx context.Context, IsoCode string) (*VoiceV1DialingPermissionsCountryInstance, error) { path := "/v1/DialingPermissions/Countries/{IsoCode}" path = strings.Replace(path, "{"+"IsoCode"+"}", IsoCode, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -101,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.PageDialingPermissionsCountryWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of DialingPermissionsCountry records from the API. Request is executed immediately. +func (c *ApiService) PageDialingPermissionsCountryWithCtx(ctx context.Context, params *ListDialingPermissionsCountryParams, pageToken, pageNumber string) (*ListDialingPermissionsCountryResponse, error) { path := "/v1/DialingPermissions/Countries" data := url.Values{} @@ -135,7 +146,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -152,7 +163,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.ListDialingPermissionsCountryWithCtx(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) ListDialingPermissionsCountryWithCtx(ctx context.Context, params *ListDialingPermissionsCountryParams) ([]VoiceV1DialingPermissionsCountry, error) { + response, errors := c.StreamDialingPermissionsCountryWithCtx(ctx, params) records := make([]VoiceV1DialingPermissionsCountry, 0) for record := range response { @@ -168,6 +184,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.StreamDialingPermissionsCountryWithCtx(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) StreamDialingPermissionsCountryWithCtx(ctx context.Context, params *ListDialingPermissionsCountryParams) (chan VoiceV1DialingPermissionsCountry, chan error) { if params == nil { params = &ListDialingPermissionsCountryParams{} } @@ -176,19 +197,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.PageDialingPermissionsCountryWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamDialingPermissionsCountry(response, params, recordChannel, errorChannel) + go c.streamDialingPermissionsCountry(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) streamDialingPermissionsCountry(ctx context.Context, response *ListDialingPermissionsCountryResponse, params *ListDialingPermissionsCountryParams, recordChannel chan VoiceV1DialingPermissionsCountry, errorChannel chan error) { curRecord := 1 for response != nil { @@ -203,7 +224,7 @@ func (c *ApiService) streamDialingPermissionsCountry(response *ListDialingPermis } } - record, err := client.GetNext(c.baseURL, response, c.getNextListDialingPermissionsCountryResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListDialingPermissionsCountryResponse) if err != nil { errorChannel <- err break @@ -218,11 +239,11 @@ func (c *ApiService) streamDialingPermissionsCountry(response *ListDialingPermis close(errorChannel) } -func (c *ApiService) getNextListDialingPermissionsCountryResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListDialingPermissionsCountryResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 db256ce6d..ae19c51a4 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.PageDialingPermissionsHrsPrefixesWithCtx(context.TODO(), IsoCode, params, pageToken, pageNumber) +} + +// Retrieve a single page of DialingPermissionsHrsPrefixes records from the API. Request is executed immediately. +func (c *ApiService) PageDialingPermissionsHrsPrefixesWithCtx(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) @@ -60,7 +66,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -77,7 +83,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.ListDialingPermissionsHrsPrefixesWithCtx(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) ListDialingPermissionsHrsPrefixesWithCtx(ctx context.Context, IsoCode string, params *ListDialingPermissionsHrsPrefixesParams) ([]VoiceV1DialingPermissionsHrsPrefixes, error) { + response, errors := c.StreamDialingPermissionsHrsPrefixesWithCtx(ctx, IsoCode, params) records := make([]VoiceV1DialingPermissionsHrsPrefixes, 0) for record := range response { @@ -93,6 +104,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.StreamDialingPermissionsHrsPrefixesWithCtx(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) StreamDialingPermissionsHrsPrefixesWithCtx(ctx context.Context, IsoCode string, params *ListDialingPermissionsHrsPrefixesParams) (chan VoiceV1DialingPermissionsHrsPrefixes, chan error) { if params == nil { params = &ListDialingPermissionsHrsPrefixesParams{} } @@ -101,19 +117,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.PageDialingPermissionsHrsPrefixesWithCtx(ctx, IsoCode, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamDialingPermissionsHrsPrefixes(response, params, recordChannel, errorChannel) + go c.streamDialingPermissionsHrsPrefixes(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) streamDialingPermissionsHrsPrefixes(ctx context.Context, response *ListDialingPermissionsHrsPrefixesResponse, params *ListDialingPermissionsHrsPrefixesParams, recordChannel chan VoiceV1DialingPermissionsHrsPrefixes, errorChannel chan error) { curRecord := 1 for response != nil { @@ -128,7 +144,7 @@ func (c *ApiService) streamDialingPermissionsHrsPrefixes(response *ListDialingPe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListDialingPermissionsHrsPrefixesResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListDialingPermissionsHrsPrefixesResponse) if err != nil { errorChannel <- err break @@ -143,11 +159,11 @@ func (c *ApiService) streamDialingPermissionsHrsPrefixes(response *ListDialingPe close(errorChannel) } -func (c *ApiService) getNextListDialingPermissionsHrsPrefixesResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListDialingPermissionsHrsPrefixesResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 93ed82dde..3f1297fc7 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" @@ -48,6 +49,11 @@ func (params *CreateIpRecordParams) SetCidrPrefixLength(CidrPrefixLength int) *C // func (c *ApiService) CreateIpRecord(params *CreateIpRecordParams) (*VoiceV1IpRecord, error) { + return c.CreateIpRecordWithCtx(context.TODO(), params) +} + +// +func (c *ApiService) CreateIpRecordWithCtx(ctx context.Context, params *CreateIpRecordParams) (*VoiceV1IpRecord, error) { path := "/v1/IpRecords" data := url.Values{} @@ -63,7 +69,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -80,13 +86,18 @@ func (c *ApiService) CreateIpRecord(params *CreateIpRecordParams) (*VoiceV1IpRec // func (c *ApiService) DeleteIpRecord(Sid string) error { + return c.DeleteIpRecordWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) DeleteIpRecordWithCtx(ctx context.Context, Sid string) error { path := "/v1/IpRecords/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -98,13 +109,18 @@ func (c *ApiService) DeleteIpRecord(Sid string) error { // func (c *ApiService) FetchIpRecord(Sid string) (*VoiceV1IpRecord, error) { + return c.FetchIpRecordWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) FetchIpRecordWithCtx(ctx context.Context, Sid string) (*VoiceV1IpRecord, error) { path := "/v1/IpRecords/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -138,6 +154,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.PageIpRecordWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of IpRecord records from the API. Request is executed immediately. +func (c *ApiService) PageIpRecordWithCtx(ctx context.Context, params *ListIpRecordParams, pageToken, pageNumber string) (*ListIpRecordResponse, error) { path := "/v1/IpRecords" data := url.Values{} @@ -154,7 +175,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -171,7 +192,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.ListIpRecordWithCtx(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) ListIpRecordWithCtx(ctx context.Context, params *ListIpRecordParams) ([]VoiceV1IpRecord, error) { + response, errors := c.StreamIpRecordWithCtx(ctx, params) records := make([]VoiceV1IpRecord, 0) for record := range response { @@ -187,6 +213,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.StreamIpRecordWithCtx(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) StreamIpRecordWithCtx(ctx context.Context, params *ListIpRecordParams) (chan VoiceV1IpRecord, chan error) { if params == nil { params = &ListIpRecordParams{} } @@ -195,19 +226,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.PageIpRecordWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamIpRecord(response, params, recordChannel, errorChannel) + go c.streamIpRecord(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) streamIpRecord(ctx context.Context, response *ListIpRecordResponse, params *ListIpRecordParams, recordChannel chan VoiceV1IpRecord, errorChannel chan error) { curRecord := 1 for response != nil { @@ -222,7 +253,7 @@ func (c *ApiService) streamIpRecord(response *ListIpRecordResponse, params *List } } - record, err := client.GetNext(c.baseURL, response, c.getNextListIpRecordResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListIpRecordResponse) if err != nil { errorChannel <- err break @@ -237,11 +268,11 @@ func (c *ApiService) streamIpRecord(response *ListIpRecordResponse, params *List close(errorChannel) } -func (c *ApiService) getNextListIpRecordResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListIpRecordResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -268,6 +299,11 @@ func (params *UpdateIpRecordParams) SetFriendlyName(FriendlyName string) *Update // func (c *ApiService) UpdateIpRecord(Sid string, params *UpdateIpRecordParams) (*VoiceV1IpRecord, error) { + return c.UpdateIpRecordWithCtx(context.TODO(), Sid, params) +} + +// +func (c *ApiService) UpdateIpRecordWithCtx(ctx context.Context, Sid string, params *UpdateIpRecordParams) (*VoiceV1IpRecord, error) { path := "/v1/IpRecords/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -278,7 +314,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.Post(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 2906226fc..1c4759bfa 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,12 +23,17 @@ import ( // Retrieve voice dialing permissions inheritance for the sub-account func (c *ApiService) FetchDialingPermissionsSettings() (*VoiceV1DialingPermissionsSettings, error) { + return c.FetchDialingPermissionsSettingsWithCtx(context.TODO()) +} + +// Retrieve voice dialing permissions inheritance for the sub-account +func (c *ApiService) FetchDialingPermissionsSettingsWithCtx(ctx context.Context) (*VoiceV1DialingPermissionsSettings, error) { path := "/v1/Settings" data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -55,6 +61,11 @@ func (params *UpdateDialingPermissionsSettingsParams) SetDialingPermissionsInher // Update voice dialing permissions inheritance for the sub-account func (c *ApiService) UpdateDialingPermissionsSettings(params *UpdateDialingPermissionsSettingsParams) (*VoiceV1DialingPermissionsSettings, error) { + return c.UpdateDialingPermissionsSettingsWithCtx(context.TODO(), params) +} + +// Update voice dialing permissions inheritance for the sub-account +func (c *ApiService) UpdateDialingPermissionsSettingsWithCtx(ctx context.Context, params *UpdateDialingPermissionsSettingsParams) (*VoiceV1DialingPermissionsSettings, error) { path := "/v1/Settings" data := url.Values{} @@ -64,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.Post(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 083da2e12..ffb1e03ff 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" @@ -42,6 +43,11 @@ func (params *CreateSourceIpMappingParams) SetSipDomainSid(SipDomainSid string) // func (c *ApiService) CreateSourceIpMapping(params *CreateSourceIpMappingParams) (*VoiceV1SourceIpMapping, error) { + return c.CreateSourceIpMappingWithCtx(context.TODO(), params) +} + +// +func (c *ApiService) CreateSourceIpMappingWithCtx(ctx context.Context, params *CreateSourceIpMappingParams) (*VoiceV1SourceIpMapping, error) { path := "/v1/SourceIpMappings" data := url.Values{} @@ -54,7 +60,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -71,13 +77,18 @@ func (c *ApiService) CreateSourceIpMapping(params *CreateSourceIpMappingParams) // func (c *ApiService) DeleteSourceIpMapping(Sid string) error { + return c.DeleteSourceIpMappingWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) DeleteSourceIpMappingWithCtx(ctx context.Context, Sid string) error { path := "/v1/SourceIpMappings/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -89,13 +100,18 @@ func (c *ApiService) DeleteSourceIpMapping(Sid string) error { // func (c *ApiService) FetchSourceIpMapping(Sid string) (*VoiceV1SourceIpMapping, error) { + return c.FetchSourceIpMappingWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) FetchSourceIpMappingWithCtx(ctx context.Context, Sid string) (*VoiceV1SourceIpMapping, error) { path := "/v1/SourceIpMappings/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -129,6 +145,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.PageSourceIpMappingWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of SourceIpMapping records from the API. Request is executed immediately. +func (c *ApiService) PageSourceIpMappingWithCtx(ctx context.Context, params *ListSourceIpMappingParams, pageToken, pageNumber string) (*ListSourceIpMappingResponse, error) { path := "/v1/SourceIpMappings" data := url.Values{} @@ -145,7 +166,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -162,7 +183,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.ListSourceIpMappingWithCtx(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) ListSourceIpMappingWithCtx(ctx context.Context, params *ListSourceIpMappingParams) ([]VoiceV1SourceIpMapping, error) { + response, errors := c.StreamSourceIpMappingWithCtx(ctx, params) records := make([]VoiceV1SourceIpMapping, 0) for record := range response { @@ -178,6 +204,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.StreamSourceIpMappingWithCtx(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) StreamSourceIpMappingWithCtx(ctx context.Context, params *ListSourceIpMappingParams) (chan VoiceV1SourceIpMapping, chan error) { if params == nil { params = &ListSourceIpMappingParams{} } @@ -186,19 +217,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.PageSourceIpMappingWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSourceIpMapping(response, params, recordChannel, errorChannel) + go c.streamSourceIpMapping(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) streamSourceIpMapping(ctx context.Context, response *ListSourceIpMappingResponse, params *ListSourceIpMappingParams, recordChannel chan VoiceV1SourceIpMapping, errorChannel chan error) { curRecord := 1 for response != nil { @@ -213,7 +244,7 @@ func (c *ApiService) streamSourceIpMapping(response *ListSourceIpMappingResponse } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSourceIpMappingResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListSourceIpMappingResponse) if err != nil { errorChannel <- err break @@ -228,11 +259,11 @@ func (c *ApiService) streamSourceIpMapping(response *ListSourceIpMappingResponse close(errorChannel) } -func (c *ApiService) getNextListSourceIpMappingResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSourceIpMappingResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -259,6 +290,11 @@ func (params *UpdateSourceIpMappingParams) SetSipDomainSid(SipDomainSid string) // func (c *ApiService) UpdateSourceIpMapping(Sid string, params *UpdateSourceIpMappingParams) (*VoiceV1SourceIpMapping, error) { + return c.UpdateSourceIpMappingWithCtx(context.TODO(), Sid, params) +} + +// +func (c *ApiService) UpdateSourceIpMappingWithCtx(ctx context.Context, Sid string, params *UpdateSourceIpMappingParams) (*VoiceV1SourceIpMapping, error) { path := "/v1/SourceIpMappings/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -269,7 +305,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.Post(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 6c75acb40..0c9c8f928 100644 --- a/rest/wireless/v1/api_service.go +++ b/rest/wireless/v1/api_service.go @@ -20,10 +20,14 @@ import ( type ApiService struct { baseURL string - requestHandler *twilio.RequestHandler + requestHandler *twilio.RequestHandlerWithCtx } func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { + return NewApiServiceWithCtx(twilio.UpgradeRequestHandler(requestHandler)) +} + +func NewApiServiceWithCtx(requestHandler *twilio.RequestHandlerWithCtx) *ApiService { return &ApiService{ requestHandler: requestHandler, baseURL: "https://wireless.twilio.com", @@ -33,3 +37,7 @@ func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { func NewApiServiceWithClient(client twilio.BaseClient) *ApiService { return NewApiService(twilio.NewRequestHandler(client)) } + +func NewApiServiceWithClientWithCtx(client twilio.BaseClientWithCtx) *ApiService { + return NewApiServiceWithCtx(twilio.NewRequestHandlerWithCtx(client)) +} diff --git a/rest/wireless/v1/commands.go b/rest/wireless/v1/commands.go index 8a3bd9cfb..237dc8b60 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,11 @@ func (params *CreateCommandParams) SetDeliveryReceiptRequested(DeliveryReceiptRe // Send a Command to a Sim. func (c *ApiService) CreateCommand(params *CreateCommandParams) (*WirelessV1Command, error) { + return c.CreateCommandWithCtx(context.TODO(), params) +} + +// Send a Command to a Sim. +func (c *ApiService) CreateCommandWithCtx(ctx context.Context, params *CreateCommandParams) (*WirelessV1Command, error) { path := "/v1/Commands" data := url.Values{} @@ -99,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.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -116,13 +122,18 @@ func (c *ApiService) CreateCommand(params *CreateCommandParams) (*WirelessV1Comm // Delete a Command instance from your account. func (c *ApiService) DeleteCommand(Sid string) error { + return c.DeleteCommandWithCtx(context.TODO(), Sid) +} + +// Delete a Command instance from your account. +func (c *ApiService) DeleteCommandWithCtx(ctx context.Context, Sid string) error { path := "/v1/Commands/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -134,13 +145,18 @@ func (c *ApiService) DeleteCommand(Sid string) error { // Fetch a Command instance from your account. func (c *ApiService) FetchCommand(Sid string) (*WirelessV1Command, error) { + return c.FetchCommandWithCtx(context.TODO(), Sid) +} + +// Fetch a Command instance from your account. +func (c *ApiService) FetchCommandWithCtx(ctx context.Context, Sid string) (*WirelessV1Command, error) { path := "/v1/Commands/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -198,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.PageCommandWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Command records from the API. Request is executed immediately. +func (c *ApiService) PageCommandWithCtx(ctx context.Context, params *ListCommandParams, pageToken, pageNumber string) (*ListCommandResponse, error) { path := "/v1/Commands" data := url.Values{} @@ -226,7 +247,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -243,7 +264,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.ListCommandWithCtx(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) ListCommandWithCtx(ctx context.Context, params *ListCommandParams) ([]WirelessV1Command, error) { + response, errors := c.StreamCommandWithCtx(ctx, params) records := make([]WirelessV1Command, 0) for record := range response { @@ -259,6 +285,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.StreamCommandWithCtx(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) StreamCommandWithCtx(ctx context.Context, params *ListCommandParams) (chan WirelessV1Command, chan error) { if params == nil { params = &ListCommandParams{} } @@ -267,19 +298,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.PageCommandWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamCommand(response, params, recordChannel, errorChannel) + go c.streamCommand(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) streamCommand(ctx context.Context, response *ListCommandResponse, params *ListCommandParams, recordChannel chan WirelessV1Command, errorChannel chan error) { curRecord := 1 for response != nil { @@ -294,7 +325,7 @@ func (c *ApiService) streamCommand(response *ListCommandResponse, params *ListCo } } - record, err := client.GetNext(c.baseURL, response, c.getNextListCommandResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListCommandResponse) if err != nil { errorChannel <- err break @@ -309,11 +340,11 @@ func (c *ApiService) streamCommand(response *ListCommandResponse, params *ListCo close(errorChannel) } -func (c *ApiService) getNextListCommandResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListCommandResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 16f05faf4..a1d27e167 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" @@ -96,6 +97,11 @@ func (params *CreateRatePlanParams) SetInternationalRoamingDataLimit(Internation // func (c *ApiService) CreateRatePlan(params *CreateRatePlanParams) (*WirelessV1RatePlan, error) { + return c.CreateRatePlanWithCtx(context.TODO(), params) +} + +// +func (c *ApiService) CreateRatePlanWithCtx(ctx context.Context, params *CreateRatePlanParams) (*WirelessV1RatePlan, error) { path := "/v1/RatePlans" data := url.Values{} @@ -137,7 +143,7 @@ func (c *ApiService) CreateRatePlan(params *CreateRatePlanParams) (*WirelessV1Ra data.Set("InternationalRoamingDataLimit", fmt.Sprint(*params.InternationalRoamingDataLimit)) } - resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Post(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -154,13 +160,18 @@ func (c *ApiService) CreateRatePlan(params *CreateRatePlanParams) (*WirelessV1Ra // func (c *ApiService) DeleteRatePlan(Sid string) error { + return c.DeleteRatePlanWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) DeleteRatePlanWithCtx(ctx context.Context, Sid string) error { path := "/v1/RatePlans/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -172,13 +183,18 @@ func (c *ApiService) DeleteRatePlan(Sid string) error { // func (c *ApiService) FetchRatePlan(Sid string) (*WirelessV1RatePlan, error) { + return c.FetchRatePlanWithCtx(context.TODO(), Sid) +} + +// +func (c *ApiService) FetchRatePlanWithCtx(ctx context.Context, Sid string) (*WirelessV1RatePlan, error) { path := "/v1/RatePlans/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -212,6 +228,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.PageRatePlanWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of RatePlan records from the API. Request is executed immediately. +func (c *ApiService) PageRatePlanWithCtx(ctx context.Context, params *ListRatePlanParams, pageToken, pageNumber string) (*ListRatePlanResponse, error) { path := "/v1/RatePlans" data := url.Values{} @@ -228,7 +249,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -245,7 +266,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.ListRatePlanWithCtx(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) ListRatePlanWithCtx(ctx context.Context, params *ListRatePlanParams) ([]WirelessV1RatePlan, error) { + response, errors := c.StreamRatePlanWithCtx(ctx, params) records := make([]WirelessV1RatePlan, 0) for record := range response { @@ -261,6 +287,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.StreamRatePlanWithCtx(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) StreamRatePlanWithCtx(ctx context.Context, params *ListRatePlanParams) (chan WirelessV1RatePlan, chan error) { if params == nil { params = &ListRatePlanParams{} } @@ -269,19 +300,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.PageRatePlanWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamRatePlan(response, params, recordChannel, errorChannel) + go c.streamRatePlan(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) streamRatePlan(ctx context.Context, response *ListRatePlanResponse, params *ListRatePlanParams, recordChannel chan WirelessV1RatePlan, errorChannel chan error) { curRecord := 1 for response != nil { @@ -296,7 +327,7 @@ func (c *ApiService) streamRatePlan(response *ListRatePlanResponse, params *List } } - record, err := client.GetNext(c.baseURL, response, c.getNextListRatePlanResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListRatePlanResponse) if err != nil { errorChannel <- err break @@ -311,11 +342,11 @@ func (c *ApiService) streamRatePlan(response *ListRatePlanResponse, params *List close(errorChannel) } -func (c *ApiService) getNextListRatePlanResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListRatePlanResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -348,6 +379,11 @@ func (params *UpdateRatePlanParams) SetFriendlyName(FriendlyName string) *Update // func (c *ApiService) UpdateRatePlan(Sid string, params *UpdateRatePlanParams) (*WirelessV1RatePlan, error) { + return c.UpdateRatePlanWithCtx(context.TODO(), Sid, params) +} + +// +func (c *ApiService) UpdateRatePlanWithCtx(ctx context.Context, Sid string, params *UpdateRatePlanParams) (*WirelessV1RatePlan, error) { path := "/v1/RatePlans/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -361,7 +397,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.Post(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 28d88fd5a..e575104ce 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,13 +26,18 @@ import ( // Delete a Sim resource on your Account. func (c *ApiService) DeleteSim(Sid string) error { + return c.DeleteSimWithCtx(context.TODO(), Sid) +} + +// Delete a Sim resource on your Account. +func (c *ApiService) DeleteSimWithCtx(ctx context.Context, Sid string) error { path := "/v1/Sims/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Delete(ctx, c.baseURL+path, data, headers) if err != nil { return err } @@ -43,13 +49,18 @@ func (c *ApiService) DeleteSim(Sid string) error { // Fetch a Sim resource on your Account. func (c *ApiService) FetchSim(Sid string) (*WirelessV1Sim, error) { + return c.FetchSimWithCtx(context.TODO(), Sid) +} + +// Fetch a Sim resource on your Account. +func (c *ApiService) FetchSimWithCtx(ctx context.Context, Sid string) (*WirelessV1Sim, error) { path := "/v1/Sims/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) data := url.Values{} headers := make(map[string]interface{}) - resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + resp, err := c.requestHandler.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -113,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.PageSimWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of Sim records from the API. Request is executed immediately. +func (c *ApiService) PageSimWithCtx(ctx context.Context, params *ListSimParams, pageToken, pageNumber string) (*ListSimResponse, error) { path := "/v1/Sims" data := url.Values{} @@ -144,7 +160,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -161,7 +177,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.ListSimWithCtx(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) ListSimWithCtx(ctx context.Context, params *ListSimParams) ([]WirelessV1Sim, error) { + response, errors := c.StreamSimWithCtx(ctx, params) records := make([]WirelessV1Sim, 0) for record := range response { @@ -177,6 +198,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.StreamSimWithCtx(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) StreamSimWithCtx(ctx context.Context, params *ListSimParams) (chan WirelessV1Sim, chan error) { if params == nil { params = &ListSimParams{} } @@ -185,19 +211,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.PageSimWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamSim(response, params, recordChannel, errorChannel) + go c.streamSim(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) streamSim(ctx context.Context, response *ListSimResponse, params *ListSimParams, recordChannel chan WirelessV1Sim, errorChannel chan error) { curRecord := 1 for response != nil { @@ -212,7 +238,7 @@ func (c *ApiService) streamSim(response *ListSimResponse, params *ListSimParams, } } - record, err := client.GetNext(c.baseURL, response, c.getNextListSimResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListSimResponse) if err != nil { errorChannel <- err break @@ -227,11 +253,11 @@ func (c *ApiService) streamSim(response *ListSimResponse, params *ListSimParams, close(errorChannel) } -func (c *ApiService) getNextListSimResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListSimResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err } @@ -360,6 +386,11 @@ 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.UpdateSimWithCtx(context.TODO(), Sid, params) +} + +// Updates the given properties of a Sim resource on your Account. +func (c *ApiService) UpdateSimWithCtx(ctx context.Context, Sid string, params *UpdateSimParams) (*WirelessV1Sim, error) { path := "/v1/Sims/{Sid}" path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) @@ -421,7 +452,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.Post(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 e54aa72f1..21abed8d1 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.PageDataSessionWithCtx(context.TODO(), SimSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of DataSession records from the API. Request is executed immediately. +func (c *ApiService) PageDataSessionWithCtx(ctx context.Context, SimSid string, params *ListDataSessionParams, pageToken, pageNumber string) (*ListDataSessionResponse, error) { path := "/v1/Sims/{SimSid}/DataSessions" path = strings.Replace(path, "{"+"SimSid"+"}", SimSid, -1) @@ -60,7 +66,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -77,7 +83,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.ListDataSessionWithCtx(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) ListDataSessionWithCtx(ctx context.Context, SimSid string, params *ListDataSessionParams) ([]WirelessV1DataSession, error) { + response, errors := c.StreamDataSessionWithCtx(ctx, SimSid, params) records := make([]WirelessV1DataSession, 0) for record := range response { @@ -93,6 +104,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.StreamDataSessionWithCtx(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) StreamDataSessionWithCtx(ctx context.Context, SimSid string, params *ListDataSessionParams) (chan WirelessV1DataSession, chan error) { if params == nil { params = &ListDataSessionParams{} } @@ -101,19 +117,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.PageDataSessionWithCtx(ctx, SimSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamDataSession(response, params, recordChannel, errorChannel) + go c.streamDataSession(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) streamDataSession(ctx context.Context, response *ListDataSessionResponse, params *ListDataSessionParams, recordChannel chan WirelessV1DataSession, errorChannel chan error) { curRecord := 1 for response != nil { @@ -128,7 +144,7 @@ func (c *ApiService) streamDataSession(response *ListDataSessionResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListDataSessionResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListDataSessionResponse) if err != nil { errorChannel <- err break @@ -143,11 +159,11 @@ func (c *ApiService) streamDataSession(response *ListDataSessionResponse, params close(errorChannel) } -func (c *ApiService) getNextListDataSessionResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListDataSessionResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 db9896288..f7c09c2a6 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.PageUsageRecordWithCtx(context.TODO(), SimSid, params, pageToken, pageNumber) +} + +// Retrieve a single page of UsageRecord records from the API. Request is executed immediately. +func (c *ApiService) PageUsageRecordWithCtx(ctx context.Context, SimSid string, params *ListUsageRecordParams, pageToken, pageNumber string) (*ListUsageRecordResponse, error) { path := "/v1/Sims/{SimSid}/UsageRecords" path = strings.Replace(path, "{"+"SimSid"+"}", SimSid, -1) @@ -88,7 +94,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -105,7 +111,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.ListUsageRecordWithCtx(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) ListUsageRecordWithCtx(ctx context.Context, SimSid string, params *ListUsageRecordParams) ([]WirelessV1UsageRecord, error) { + response, errors := c.StreamUsageRecordWithCtx(ctx, SimSid, params) records := make([]WirelessV1UsageRecord, 0) for record := range response { @@ -121,6 +132,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.StreamUsageRecordWithCtx(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) StreamUsageRecordWithCtx(ctx context.Context, SimSid string, params *ListUsageRecordParams) (chan WirelessV1UsageRecord, chan error) { if params == nil { params = &ListUsageRecordParams{} } @@ -129,19 +145,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.PageUsageRecordWithCtx(ctx, SimSid, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamUsageRecord(response, params, recordChannel, errorChannel) + go c.streamUsageRecord(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) streamUsageRecord(ctx context.Context, response *ListUsageRecordResponse, params *ListUsageRecordParams, recordChannel chan WirelessV1UsageRecord, errorChannel chan error) { curRecord := 1 for response != nil { @@ -156,7 +172,7 @@ func (c *ApiService) streamUsageRecord(response *ListUsageRecordResponse, params } } - record, err := client.GetNext(c.baseURL, response, c.getNextListUsageRecordResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListUsageRecordResponse) if err != nil { errorChannel <- err break @@ -171,11 +187,11 @@ func (c *ApiService) streamUsageRecord(response *ListUsageRecordResponse, params close(errorChannel) } -func (c *ApiService) getNextListUsageRecordResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListUsageRecordResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(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 4f22007f3..04d2c1334 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.PageAccountUsageRecordWithCtx(context.TODO(), params, pageToken, pageNumber) +} + +// Retrieve a single page of AccountUsageRecord records from the API. Request is executed immediately. +func (c *ApiService) PageAccountUsageRecordWithCtx(ctx context.Context, params *ListAccountUsageRecordParams, pageToken, pageNumber string) (*ListAccountUsageRecordResponse, error) { path := "/v1/UsageRecords" data := url.Values{} @@ -85,7 +91,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.Get(ctx, c.baseURL+path, data, headers) if err != nil { return nil, err } @@ -102,7 +108,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.ListAccountUsageRecordWithCtx(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) ListAccountUsageRecordWithCtx(ctx context.Context, params *ListAccountUsageRecordParams) ([]WirelessV1AccountUsageRecord, error) { + response, errors := c.StreamAccountUsageRecordWithCtx(ctx, params) records := make([]WirelessV1AccountUsageRecord, 0) for record := range response { @@ -118,6 +129,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.StreamAccountUsageRecordWithCtx(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) StreamAccountUsageRecordWithCtx(ctx context.Context, params *ListAccountUsageRecordParams) (chan WirelessV1AccountUsageRecord, chan error) { if params == nil { params = &ListAccountUsageRecordParams{} } @@ -126,19 +142,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.PageAccountUsageRecordWithCtx(ctx, params, "", "") if err != nil { errorChannel <- err close(recordChannel) close(errorChannel) } else { - go c.streamAccountUsageRecord(response, params, recordChannel, errorChannel) + go c.streamAccountUsageRecord(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) streamAccountUsageRecord(ctx context.Context, response *ListAccountUsageRecordResponse, params *ListAccountUsageRecordParams, recordChannel chan WirelessV1AccountUsageRecord, errorChannel chan error) { curRecord := 1 for response != nil { @@ -153,7 +169,7 @@ func (c *ApiService) streamAccountUsageRecord(response *ListAccountUsageRecordRe } } - record, err := client.GetNext(c.baseURL, response, c.getNextListAccountUsageRecordResponse) + record, err := client.GetNextWithCtx(ctx, c.baseURL, response, c.getNextListAccountUsageRecordResponse) if err != nil { errorChannel <- err break @@ -168,11 +184,11 @@ func (c *ApiService) streamAccountUsageRecord(response *ListAccountUsageRecordRe close(errorChannel) } -func (c *ApiService) getNextListAccountUsageRecordResponse(nextPageUrl string) (interface{}, error) { +func (c *ApiService) getNextListAccountUsageRecordResponse(ctx context.Context, nextPageUrl string) (interface{}, error) { if nextPageUrl == "" { return nil, nil } - resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) + resp, err := c.requestHandler.Get(ctx, nextPageUrl, nil, nil) if err != nil { return nil, err }