Skip to content
This repository was archived by the owner on Mar 20, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions application.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ type ApplicationResponseCollection struct {

// List your Applications
func (client *ApplicationClient) GetApplications(opts GetApplicationsOpts) (ApplicationResponseCollection, ApplicationErrorResponse, error) {
return client.GetApplicationsContext(context.Background(), opts)
}

// List your Applications
func (client *ApplicationClient) GetApplicationsContext(ctx context.Context, opts GetApplicationsOpts) (ApplicationResponseCollection, ApplicationErrorResponse, error) {
// create the client
applicationClient := application.NewAPIClient(client.Config)

Expand All @@ -74,7 +79,7 @@ func (client *ApplicationClient) GetApplications(opts GetApplicationsOpts) (Appl
AppOpts.PageSize = optional.NewInt32(opts.PageSize)
}

ctx := context.WithValue(context.Background(), application.ContextBasicAuth, application.BasicAuth{
ctx = context.WithValue(ctx, application.ContextBasicAuth, application.BasicAuth{
UserName: client.apiKey,
Password: client.apiSecret,
})
Expand Down Expand Up @@ -112,10 +117,15 @@ func (client *ApplicationClient) GetApplications(opts GetApplicationsOpts) (Appl

// GetApplication returns one application, by app ID
func (client *ApplicationClient) GetApplication(app_id string) (ApplicationResponse, ApplicationErrorResponse, error) {
return client.GetApplicationContext(context.Background(), app_id)
}

// GetApplicationContext returns one application, by app ID
func (client *ApplicationClient) GetApplicationContext(ctx context.Context, app_id string) (ApplicationResponse, ApplicationErrorResponse, error) {
// create the client
applicationClient := application.NewAPIClient(client.Config)

ctx := context.WithValue(context.Background(), application.ContextBasicAuth, application.BasicAuth{
ctx = context.WithValue(ctx, application.ContextBasicAuth, application.BasicAuth{
UserName: client.apiKey,
Password: client.apiSecret,
})
Expand Down Expand Up @@ -201,6 +211,11 @@ type CreateApplicationRequestOpts struct {

// CreateApplication creates a new application
func (client *ApplicationClient) CreateApplication(name string, opts CreateApplicationOpts) (ApplicationResponse, ApplicationErrorResponse, error) {
return client.CreateApplicationContext(context.Background(), name, opts)
}

// CreateApplicationContext creates a new application
func (client *ApplicationClient) CreateApplicationContext(ctx context.Context, name string, opts CreateApplicationOpts) (ApplicationResponse, ApplicationErrorResponse, error) {
// create the client
applicationClient := application.NewAPIClient(client.Config)

Expand All @@ -215,7 +230,7 @@ func (client *ApplicationClient) CreateApplication(name string, opts CreateAppli

createOpts := application.CreateApplicationOpts{Opts: optional.NewInterface(AppOpts)}

ctx := context.WithValue(context.Background(), application.ContextBasicAuth, application.BasicAuth{
ctx = context.WithValue(ctx, application.ContextBasicAuth, application.BasicAuth{
UserName: client.apiKey,
Password: client.apiSecret,
})
Expand All @@ -240,10 +255,15 @@ func (client *ApplicationClient) CreateApplication(name string, opts CreateAppli

// Delete application deletes an application
func (client *ApplicationClient) DeleteApplication(app_id string) (bool, ApplicationErrorResponse, error) {
return client.DeleteApplicationContext(context.Background(), app_id)
}

// DeleteContext application deletes an application
func (client *ApplicationClient) DeleteApplicationContext(ctx context.Context, app_id string) (bool, ApplicationErrorResponse, error) {
// create the client
applicationClient := application.NewAPIClient(client.Config)

ctx := context.WithValue(context.Background(), application.ContextBasicAuth, application.BasicAuth{
ctx = context.WithValue(ctx, application.ContextBasicAuth, application.BasicAuth{
UserName: client.apiKey,
Password: client.apiSecret,
})
Expand Down Expand Up @@ -282,6 +302,11 @@ type UpdateApplicationRequestOpts struct {

// UpdateApplication updates an existing application
func (client *ApplicationClient) UpdateApplication(id string, name string, opts UpdateApplicationOpts) (ApplicationResponse, ApplicationErrorResponse, error) {
return client.UpdateApplicationContext(context.Background(), id, name, opts)
}

// UpdateApplicationContext updates an existing application
func (client *ApplicationClient) UpdateApplicationContext(ctx context.Context, id string, name string, opts UpdateApplicationOpts) (ApplicationResponse, ApplicationErrorResponse, error) {
// create the client
applicationClient := application.NewAPIClient(client.Config)

Expand All @@ -296,7 +321,7 @@ func (client *ApplicationClient) UpdateApplication(id string, name string, opts

updateOpts := application.UpdateApplicationOpts{Opts: optional.NewInterface(AppOpts)}

ctx := context.WithValue(context.Background(), application.ContextBasicAuth, application.BasicAuth{
ctx = context.WithValue(ctx, application.ContextBasicAuth, application.BasicAuth{
UserName: client.apiKey,
Password: client.apiSecret,
})
Expand Down
35 changes: 30 additions & 5 deletions number.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ type NumberCollection struct {

// List shows the numbers you already own, filters and pagination are available
func (client *NumbersClient) List(opts NumbersOpts) (NumberCollection, NumbersErrorResponse, error) {
return client.ListContext(context.Background(), opts)
}

// ListContext shows the numbers you already own, filters and pagination are available
func (client *NumbersClient) ListContext(ctx context.Context, opts NumbersOpts) (NumberCollection, NumbersErrorResponse, error) {

numbersClient := number.NewAPIClient(client.Config)

Expand Down Expand Up @@ -112,7 +117,7 @@ func (client *NumbersClient) List(opts NumbersOpts) (NumberCollection, NumbersEr
}

// we need context for the API key
ctx := context.WithValue(context.Background(), number.ContextAPIKey, number.APIKey{
ctx = context.WithValue(ctx, number.ContextAPIKey, number.APIKey{
Key: client.apiKey,
})

Expand Down Expand Up @@ -168,11 +173,16 @@ type NumberAvailable struct {

// Search lets you find a great phone number to use in your application
func (client *NumbersClient) Search(country string, opts NumberSearchOpts) (NumberSearch, NumbersErrorResponse, error) {
return client.SearchContext(context.Background(), country, opts)
}

// SearchContext lets you find a great phone number to use in your application
func (client *NumbersClient) SearchContext(ctx context.Context, country string, opts NumberSearchOpts) (NumberSearch, NumbersErrorResponse, error) {

numbersClient := number.NewAPIClient(client.Config)

// we need context for the API key
ctx := context.WithValue(context.Background(), number.ContextAPIKey, number.APIKey{
ctx = context.WithValue(ctx, number.ContextAPIKey, number.APIKey{
Key: client.apiKey,
})

Expand Down Expand Up @@ -227,11 +237,16 @@ type NumberBuyOpts struct {

// Buy the best phone number to use in your app
func (client *NumbersClient) Buy(country string, msisdn string, opts NumberBuyOpts) (NumbersResponse, NumbersErrorResponse, error) {
return client.BuyContext(context.Background(), country, msisdn, opts)
}

// BuyContext the best phone number to use in your app
func (client *NumbersClient) BuyContext(ctx context.Context, country string, msisdn string, opts NumberBuyOpts) (NumbersResponse, NumbersErrorResponse, error) {

numbersClient := number.NewAPIClient(client.Config)

// we need context for the API key
ctx := context.WithValue(context.Background(), number.ContextAPIKey, number.APIKey{
ctx = context.WithValue(ctx, number.ContextAPIKey, number.APIKey{
Key: client.apiKey,
})

Expand Down Expand Up @@ -272,10 +287,15 @@ type NumberCancelOpts struct {

// Cancel a number already in your account
func (client *NumbersClient) Cancel(country string, msisdn string, opts NumberCancelOpts) (NumbersResponse, NumbersErrorResponse, error) {
return client.CancelContext(context.Background(), country, msisdn, opts)
}

// CancelContext a number already in your account
func (client *NumbersClient) CancelContext(ctx context.Context, country string, msisdn string, opts NumberCancelOpts) (NumbersResponse, NumbersErrorResponse, error) {
numbersClient := number.NewAPIClient(client.Config)

// we need context for the API key
ctx := context.WithValue(context.Background(), number.ContextAPIKey, number.APIKey{
ctx = context.WithValue(ctx, number.ContextAPIKey, number.APIKey{
Key: client.apiKey,
})

Expand Down Expand Up @@ -322,10 +342,15 @@ type NumberUpdateOpts struct {

// Update the configuration for your number
func (client *NumbersClient) Update(country string, msisdn string, opts NumberUpdateOpts) (NumbersResponse, NumbersErrorResponse, error) {
return client.UpdateContext(context.Background(), country, msisdn, opts)
}

// UpdateContext the configuration for your number
func (client *NumbersClient) UpdateContext(ctx context.Context, country string, msisdn string, opts NumberUpdateOpts) (NumbersResponse, NumbersErrorResponse, error) {
numbersClient := number.NewAPIClient(client.Config)

// we need context for the API key
ctx := context.WithValue(context.Background(), number.ContextAPIKey, number.APIKey{
ctx = context.WithValue(ctx, number.ContextAPIKey, number.APIKey{
Key: client.apiKey,
})

Expand Down
18 changes: 15 additions & 3 deletions numberinsight.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ type NiResponseJsonBasic struct {

// Basic does a basic-level lookup for data about a number
func (client *NumberInsightClient) Basic(number string, opts NiOpts) (NiResponseJsonBasic, NiErrorResponse, error) {
return client.BasicContext(context.Background(), number, opts)
}

// BasicContext does a basic-level lookup for data about a number
func (client *NumberInsightClient) BasicContext(ctx context.Context, number string, opts NiOpts) (NiResponseJsonBasic, NiErrorResponse, error) {
// create the client
numberinsightClient := numberinsight.NewAPIClient(client.Config)

Expand All @@ -59,7 +64,6 @@ func (client *NumberInsightClient) Basic(number string, opts NiOpts) (NiResponse
}

// we need context for the API key
ctx := context.Background()
ctx = context.WithValue(ctx, numberinsight.ContextAPIKey, numberinsight.APIKey{Key: client.apiKey})
ctx = context.WithValue(ctx, numberinsight.ContextAPISecret, numberinsight.APIKey{Key: client.apiSecret})

Expand Down Expand Up @@ -107,13 +111,17 @@ type NiResponseJsonStandard struct {

// Standard does a Standard-level lookup for data about a number
func (client *NumberInsightClient) Standard(number string, opts NiOpts) (NiResponseJsonStandard, NiErrorResponse, error) {
return client.StandardContext(context.Background(), number, opts)
}

// StandardContext does a Standard-level lookup for data about a number
func (client *NumberInsightClient) StandardContext(ctx context.Context, number string, opts NiOpts) (NiResponseJsonStandard, NiErrorResponse, error) {
// create the client
numberinsightClient := numberinsight.NewAPIClient(client.Config)

niOpts := numberinsight.GetNumberInsightStandardOpts{}

// we need context for the API key
ctx := context.Background()
ctx = context.WithValue(ctx, numberinsight.ContextAPIKey, numberinsight.APIKey{Key: client.apiKey})
ctx = context.WithValue(ctx, numberinsight.ContextAPISecret, numberinsight.APIKey{Key: client.apiSecret})

Expand Down Expand Up @@ -146,13 +154,17 @@ type NiResponseAsync struct {

// AdvancedAsync requests a callback with advanced-level information about a number
func (client *NumberInsightClient) AdvancedAsync(number string, callback string, opts NiOpts) (NiResponseAsync, NiErrorResponse, error) {
return client.AdvancedAsyncContext(context.Background(), number, callback, opts)
}

// AdvancedAsyncContext requests a callback with advanced-level information about a number
func (client *NumberInsightClient) AdvancedAsyncContext(ctx context.Context, number string, callback string, opts NiOpts) (NiResponseAsync, NiErrorResponse, error) {
// create the client
numberinsightClient := numberinsight.NewAPIClient(client.Config)

niOpts := numberinsight.GetNumberInsightAsyncOpts{}

// we need context for the API key
ctx := context.Background()
ctx = context.WithValue(ctx, numberinsight.ContextAPIKey, numberinsight.APIKey{Key: client.apiKey})
ctx = context.WithValue(ctx, numberinsight.ContextAPISecret, numberinsight.APIKey{Key: client.apiSecret})

Expand Down
9 changes: 7 additions & 2 deletions sms.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ type SmsError struct {
// some restrictions on what you can send from, to be safe try using a Vonage
// number associated with your account
func (client *SMSClient) Send(from string, to string, text string, opts SMSOpts) (Sms, SmsErrorResponse, error) {
return client.SendContext(context.Background(), from, to, text, opts)
}

// SendContext an SMS. Give some text to send and the number to send to - there are
// some restrictions on what you can send from, to be safe try using a Vonage
// number associated with your account
func (client *SMSClient) SendContext(ctx context.Context, from string, to string, text string, opts SMSOpts) (Sms, SmsErrorResponse, error) {

smsClient := sms.NewAPIClient(client.Config)

Expand All @@ -81,8 +88,6 @@ func (client *SMSClient) Send(from string, to string, text string, opts SMSOpts)
smsOpts.StatusReportReq = optional.NewBool(opts.StatusReportReq)
}

ctx := context.Background()

// now send the SMS
result, resp, err := smsClient.DefaultApi.SendAnSms(ctx, "json", client.apiKey, from, to, &smsOpts)

Expand Down
36 changes: 30 additions & 6 deletions verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ type VerifyErrorResponse struct {

// Request a number is verified for ownership
func (client *VerifyClient) Request(number string, brand string, opts VerifyOpts) (VerifyRequestResponse, VerifyErrorResponse, error) {
return client.RequestContext(context.Background(), number, brand, opts)
}

// RequestContext a number is verified for ownership
func (client *VerifyClient) RequestContext(ctx context.Context, number string, brand string, opts VerifyOpts) (VerifyRequestResponse, VerifyErrorResponse, error) {
// create the client
verifyClient := verify.NewAPIClient(client.Config)

Expand All @@ -75,7 +80,6 @@ func (client *VerifyClient) Request(number string, brand string, opts VerifyOpts
verifyOpts.SenderId = optional.NewString(opts.SenderID)
}

ctx := context.Background()
result, resp, err := verifyClient.DefaultApi.VerifyRequest(ctx, "json", client.apiKey, client.apiSecret, number, brand, &verifyOpts)

// catch HTTP errors
Expand Down Expand Up @@ -107,12 +111,16 @@ type VerifyCheckResponse struct {

// Check the user-supplied code for this request ID
func (client *VerifyClient) Check(requestID string, code string) (VerifyCheckResponse, VerifyErrorResponse, error) {
return client.CheckContext(context.Background(), requestID, code)
}

// CheckContext the user-supplied code for this request ID
func (client *VerifyClient) CheckContext(ctx context.Context, requestID string, code string) (VerifyCheckResponse, VerifyErrorResponse, error) {
// create the client
verifyClient := verify.NewAPIClient(client.Config)

// set up and then parse the options
verifyOpts := verify.VerifyCheckOpts{}
ctx := context.Background()
result, resp, err := verifyClient.DefaultApi.VerifyCheck(ctx, "json", client.apiKey, client.apiSecret, requestID, code, &verifyOpts)

// catch HTTP errors
Expand Down Expand Up @@ -153,13 +161,17 @@ type VerifySearchResponse struct {

// Search for an earlier request by id
func (client *VerifyClient) Search(requestID string) (VerifySearchResponse, VerifyErrorResponse, error) {
return client.SearchContext(context.Background(), requestID)
}

// SearchContext for an earlier request by id
func (client *VerifyClient) SearchContext(ctx context.Context, requestID string) (VerifySearchResponse, VerifyErrorResponse, error) {
// create the client
verifyClient := verify.NewAPIClient(client.Config)

// set up and then parse the options
verifyOpts := verify.VerifySearchOpts{}
verifyOpts.RequestId = optional.NewString(requestID)
ctx := context.Background()
result, resp, err := verifyClient.DefaultApi.VerifySearch(ctx, "json", client.apiKey, client.apiSecret, &verifyOpts)

// catch HTTP errors
Expand Down Expand Up @@ -188,10 +200,14 @@ type VerifyControlResponse struct {

// Cancel an in-progress request (check API docs for when this is possible)
func (client *VerifyClient) Cancel(requestID string) (VerifyControlResponse, VerifyErrorResponse, error) {
return client.CancelContext(context.Background(), requestID)
}

// CancelContext an in-progress request (check API docs for when this is possible)
func (client *VerifyClient) CancelContext(ctx context.Context, requestID string) (VerifyControlResponse, VerifyErrorResponse, error) {
// create the client
verifyClient := verify.NewAPIClient(client.Config)

ctx := context.Background()
result, resp, err := verifyClient.DefaultApi.VerifyControl(ctx, "json", client.apiKey, client.apiSecret, requestID, "cancel")

// catch HTTP errors
Expand All @@ -215,10 +231,14 @@ func (client *VerifyClient) Cancel(requestID string) (VerifyControlResponse, Ver

// TriggerNextEvent moves on to the next event in the workflow
func (client *VerifyClient) TriggerNextEvent(requestID string) (VerifyControlResponse, VerifyErrorResponse, error) {
return client.TriggerNextEventContext(context.Background(), requestID)
}

// TriggerNextEventContext moves on to the next event in the workflow
func (client *VerifyClient) TriggerNextEventContext(ctx context.Context, requestID string) (VerifyControlResponse, VerifyErrorResponse, error) {
// create the client
verifyClient := verify.NewAPIClient(client.Config)

ctx := context.Background()
result, resp, err := verifyClient.DefaultApi.VerifyControl(ctx, "json", client.apiKey, client.apiSecret, requestID, "trigger_next_event")

// catch HTTP errors
Expand Down Expand Up @@ -252,6 +272,11 @@ type VerifyPsd2Opts struct {

// Psd2 requests a user confirm a payment with amount and payee
func (client *VerifyClient) Psd2(number string, payee string, amount float64, opts VerifyPsd2Opts) (VerifyRequestResponse, VerifyErrorResponse, error) {
return client.Psd2Context(context.Background(), number, payee, amount, opts)
}

// Psd2Context requests a user confirm a payment with amount and payee
func (client *VerifyClient) Psd2Context(ctx context.Context, number string, payee string, amount float64, opts VerifyPsd2Opts) (VerifyRequestResponse, VerifyErrorResponse, error) {
// create the client
verifyClient := verify.NewAPIClient(client.Config)

Expand All @@ -270,7 +295,6 @@ func (client *VerifyClient) Psd2(number string, payee string, amount float64, op
verifyOpts.WorkflowId = optional.NewInt32(opts.WorkflowID)
}

ctx := context.Background()
result, resp, err := verifyClient.DefaultApi.VerifyRequestWithPSD2(ctx, "json", client.apiKey, client.apiSecret, number, payee, float32(amount), &verifyOpts)

// catch HTTP errors
Expand Down
Loading