Skip to content

feat: Adding support for query parameters in all rest calls #217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: 2.0.0-rc
Choose a base branch
from
Open
  •  
  •  
  •  
63 changes: 63 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,68 @@
twilio-go changelog
====================
[2023-12-07] Version 2.0.0-rc.1
-------------------------------
**Library - Feature**
- [PR #213](https://github.com/twilio/twilio-go/pull/213): Support JSON payload in HTTP requests. Thanks to [@AsabuHere](https://github.com/AsabuHere)!

**Accounts**
- Updated Safelist metadata to correct the docs.
- Add Global SafeList API changes

**Api**
- Updated service base url for connect apps and authorized connect apps APIs **(breaking change)**
- Update documentation to reflect RiskCheck GA
- Added optional parameter `CallToken` for create participant api

**Events**
- Marked as GA

**Flex**
- Adding `provisioning_status` for Email Manager
- Adding `offline_config` to Flex Configuration

**Insights**
- decommission voice-qualitystats-endpoint role

**Intelligence**
- Add text-generation operator (for example conversation summary) results to existing OperatorResults collection.
- Deleted `redacted` parameter from fetching transcript in v2 **(breaking change)**

**Lookups**
- Add new `phone_number_quality_score` package to the lookup response
- Remove `disposable_phone_number_risk` package **(breaking change)**

**Messaging**
- Add tollfree edit_allowed and edit_reason fields
- Update Phone Number, Short Code, Alpha Sender, US A2P and Channel Sender documentation
- Add DELETE support to Tollfree Verification resource
- Update US App To Person documentation with current `message_samples` requirements

**Serverless**
- Add node18 as a valid Build runtime

**Taskrouter**
- Add container attribute to task_queue_bulk_real_time_statistics endpoint
- Remove beta_feature check on task_queue_bulk_real_time_statistics endpoint
- Add `virtual_start_time` property to tasks
- Updating `task_queue_data` format from `map` to `array` in the response of bulk get endpoint of TaskQueue Real Time Statistics API **(breaking change)**

**Trusthub**
- Add additional optional fields in compliance_tollfree_inquiry.json
- Rename did to tollfree_phone_number in compliance_tollfree_inquiry.json
- Add new optional field notification_email to compliance_tollfree_inquiry.json

**Verify**
- Remove `Tags` from Public Docs **(breaking change)**
- Add `VerifyEventSubscriptionEnabled` parameter to service create and update endpoints.
- Add `Tags` optional parameter on Verification creation.
- Update Verify TOTP maturity to GA.


[2023-11-22] Version 2.0.0-rc.0
---------------------------
- Release Candidate preparation

[2023-10-05] Version 1.14.1
---------------------------
**Library - Chore**
Expand Down
7 changes: 7 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

_All `MAJOR` version bumps will have upgrade notes posted here._

## [2023-11-22] 1.x.x to 2.x.x-rc.x
### Overview

#### Twilio Go Helper Library’s major version 2.0.0-rc.x is now available. We ensured that you can upgrade to Go helper Library 2.0.0-rc.x version without any breaking changes

Support for JSON payloads has been added in the request body

[2022-10-05] 0.26.x to 1.x.x
-----------------------------
### NEW FEATURE - Added Support for Twiml Building
Expand Down
2 changes: 1 addition & 1 deletion client/base_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ type BaseClient interface {
AccountSid() string
SetTimeout(timeout time.Duration)
SendRequest(method string, rawURL string, data url.Values,
headers map[string]interface{}) (*http.Response, error)
headers map[string]interface{}, queryParams url.Values, body ...byte) (*http.Response, error)
}
64 changes: 43 additions & 21 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package client

import (
"bytes"
"encoding/json"
"fmt"
"net/http"
Expand Down Expand Up @@ -56,10 +57,20 @@ func (c *Client) SetTimeout(timeout time.Duration) {
c.HTTPClient.Timeout = timeout
}

func extractContentTypeHeader(headers map[string]interface{}) (cType string) {
headerType, ok := headers["Content-Type"]
if !ok {
return urlEncodedContentType
}
return headerType.(string)
}

const (
keepZeros = true
delimiter = '.'
escapee = '\\'
urlEncodedContentType = "application/x-www-form-urlencoded"
jsonContentType = "application/json"
keepZeros = true
delimiter = '.'
escapee = '\\'
)

func (c *Client) doWithErr(req *http.Request) (*http.Response, error) {
Expand Down Expand Up @@ -89,32 +100,48 @@ func (c *Client) doWithErr(req *http.Request) (*http.Response, error) {

// SendRequest verifies, constructs, and authorizes an HTTP request.
func (c *Client) SendRequest(method string, rawURL string, data url.Values,
headers map[string]interface{}) (*http.Response, error) {
headers map[string]interface{}, queryParams url.Values, body ...byte) (*http.Response, error) {

contentType := extractContentTypeHeader(headers)

u, err := url.Parse(rawURL)
if err != nil {
return nil, err
}

valueReader := &strings.Reader{}
goVersion := runtime.Version()
var req *http.Request

if method == http.MethodGet {
if data != nil {
v, _ := form.EncodeToStringWith(data, delimiter, escapee, keepZeros)
regex := regexp.MustCompile(`\.\d+`)
s := regex.ReplaceAllString(v, "")
if queryParams != nil {
v, _ := form.EncodeToStringWith(queryParams, delimiter, escapee, keepZeros)
regex := regexp.MustCompile(`\.\d+`)
s := regex.ReplaceAllString(v, "")
u.RawQuery = s
}

u.RawQuery = s
//data is already processed and information will be added to u(the url) in the
//previous step. Now body will solely contain json payload
if contentType == jsonContentType {
req, err = http.NewRequest(method, u.String(), bytes.NewBuffer(body))
if err != nil {
return nil, err
}
} else {
//Here the HTTP POST methods which is not having json content type are processed
//All the values will be added in data and encoded (all body, query, path parameters)
if method == http.MethodPost {
valueReader = strings.NewReader(data.Encode())
}
req, err = http.NewRequest(method, u.String(), valueReader)
if err != nil {
return nil, err
}
}

if method == http.MethodPost {
valueReader = strings.NewReader(data.Encode())
}

req, err := http.NewRequest(method, u.String(), valueReader)
if err != nil {
return nil, err
if contentType == urlEncodedContentType {
req.Header.Add("Content-Type", urlEncodedContentType)
}

req.SetBasicAuth(c.basicAuth())
Expand All @@ -128,14 +155,9 @@ func (c *Client) SendRequest(method string, rawURL string, data url.Values,

req.Header.Add("User-Agent", userAgent)

if method == http.MethodPost {
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
}

for k, v := range headers {
req.Header.Add(k, fmt.Sprint(v))
}

return c.doWithErr(req)
}

Expand Down
2 changes: 1 addition & 1 deletion client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func TestClient_SetAccountSid(t *testing.T) {
func TestClient_DefaultUserAgentHeaders(t *testing.T) {
headerServer := httptest.NewServer(http.HandlerFunc(
func(writer http.ResponseWriter, request *http.Request) {
assert.Regexp(t, regexp.MustCompile(`^twilio-go/[0-9.]+\s\(\w+\s\w+\)\sgo/\S+$`), request.Header.Get("User-Agent"))
assert.Regexp(t, regexp.MustCompile(`^twilio-go/[0-9.]+(-rc.[0-9])*\s\(\w+\s\w+\)\sgo/\S+$`), request.Header.Get("User-Agent"))
}))

resp, _ := testClient.SendRequest("GET", headerServer.URL, nil, nil)
Expand Down
17 changes: 8 additions & 9 deletions client/request_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ func NewRequestHandler(client BaseClient) *RequestHandler {
}

func (c *RequestHandler) sendRequest(method string, rawURL string, data url.Values,
headers map[string]interface{}) (*http.Response, error) {
headers map[string]interface{}, queryParams url.Values, body ...byte) (*http.Response, error) {
parsedURL, err := c.BuildUrl(rawURL)
if err != nil {
return nil, err
}

return c.Client.SendRequest(method, parsedURL, data, headers)
return c.Client.SendRequest(method, parsedURL, data, headers, queryParams, body...)
}

// BuildUrl builds the target host string taking into account region and edge configurations.
Expand Down Expand Up @@ -83,14 +82,14 @@ func (c *RequestHandler) BuildUrl(rawURL string) (string, error) {
return u.String(), nil
}

func (c *RequestHandler) Post(path string, bodyData url.Values, headers map[string]interface{}) (*http.Response, error) {
return c.sendRequest(http.MethodPost, path, bodyData, headers)
func (c *RequestHandler) Post(path string, bodyData url.Values, headers map[string]interface{}, queryParams url.Values, body ...byte) (*http.Response, error) {
return c.sendRequest(http.MethodPost, path, bodyData, headers, queryParams, body...)
}

func (c *RequestHandler) Get(path string, queryData url.Values, headers map[string]interface{}) (*http.Response, error) {
return c.sendRequest(http.MethodGet, path, queryData, headers)
func (c *RequestHandler) Get(path string, queryData url.Values, headers map[string]interface{}, queryParams url.Values) (*http.Response, error) {
return c.sendRequest(http.MethodGet, path, queryData, headers, queryParams)
}

func (c *RequestHandler) Delete(path string, nothing url.Values, headers map[string]interface{}) (*http.Response, error) {
return c.sendRequest(http.MethodDelete, path, nil, headers)
func (c *RequestHandler) Delete(path string, nothing url.Values, headers map[string]interface{}, queryParams url.Values) (*http.Response, error) {
return c.sendRequest(http.MethodDelete, path, nil, headers, queryParams)
}
2 changes: 1 addition & 1 deletion client/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
package client

// LibraryVersion specifies the current version of twilio-go.
const LibraryVersion = "1.14.1"
const LibraryVersion = "2.0.0-rc.1"
6 changes: 5 additions & 1 deletion rest/accounts/v1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This is the public Twilio REST API.
## Overview
This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project from the OpenAPI specs located at [twilio/twilio-oai](https://github.com/twilio/twilio-oai/tree/main/spec). By using the [OpenAPI-spec](https://www.openapis.org/) from a remote server, you can easily generate an API client.

- API version: 1.50.1
- API version: 1.0.0
- Package version: 1.0.0
- Build package: com.twilio.oai.TwilioGoGenerator
For more information, please visit [https://support.twilio.com](https://support.twilio.com)
Expand Down Expand Up @@ -44,6 +44,9 @@ Class | Method | HTTP request | Description
*CredentialsPublicKeysApi* | [**FetchCredentialPublicKey**](docs/CredentialsPublicKeysApi.md#fetchcredentialpublickey) | **Get** /v1/Credentials/PublicKeys/{Sid} |
*CredentialsPublicKeysApi* | [**ListCredentialPublicKey**](docs/CredentialsPublicKeysApi.md#listcredentialpublickey) | **Get** /v1/Credentials/PublicKeys |
*CredentialsPublicKeysApi* | [**UpdateCredentialPublicKey**](docs/CredentialsPublicKeysApi.md#updatecredentialpublickey) | **Post** /v1/Credentials/PublicKeys/{Sid} |
*SafeListNumbersApi* | [**CreateSafelist**](docs/SafeListNumbersApi.md#createsafelist) | **Post** /v1/SafeList/Numbers |
*SafeListNumbersApi* | [**DeleteSafelist**](docs/SafeListNumbersApi.md#deletesafelist) | **Delete** /v1/SafeList/Numbers |
*SafeListNumbersApi* | [**FetchSafelist**](docs/SafeListNumbersApi.md#fetchsafelist) | **Get** /v1/SafeList/Numbers |


## Documentation For Models
Expand All @@ -54,6 +57,7 @@ Class | Method | HTTP request | Description
- [AccountsV1AuthTokenPromotion](docs/AccountsV1AuthTokenPromotion.md)
- [AccountsV1CredentialAws](docs/AccountsV1CredentialAws.md)
- [AccountsV1CredentialPublicKey](docs/AccountsV1CredentialPublicKey.md)
- [AccountsV1Safelist](docs/AccountsV1Safelist.md)
- [ListCredentialAwsResponseMeta](docs/ListCredentialAwsResponseMeta.md)


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ApiV2010Safelist
# AccountsV1Safelist

## Properties

Expand Down
2 changes: 1 addition & 1 deletion rest/accounts/v1/docs/ListCredentialAwsResponseMeta.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**FirstPageUrl** | **string** | |[optional]
**Key** | **string** | |[optional]
**NextPageUrl** | Pointer to **string** | |
**Page** | **int** | |[optional]
**PageSize** | **int** | |[optional]
**PreviousPageUrl** | Pointer to **string** | |
**Url** | **string** | |[optional]
**Key** | **string** | |[optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# SafeListNumbersApi

All URIs are relative to *https://api.twilio.com*
All URIs are relative to *https://accounts.twilio.com*

Method | HTTP request | Description
------------- | ------------- | -------------
[**CreateSafelist**](SafeListNumbersApi.md#CreateSafelist) | **Post** /2010-04-01/SafeList/Numbers.json |
[**DeleteSafelist**](SafeListNumbersApi.md#DeleteSafelist) | **Delete** /2010-04-01/SafeList/Numbers.json |
[**FetchSafelist**](SafeListNumbersApi.md#FetchSafelist) | **Get** /2010-04-01/SafeList/Numbers.json |
[**CreateSafelist**](SafeListNumbersApi.md#CreateSafelist) | **Post** /v1/SafeList/Numbers |
[**DeleteSafelist**](SafeListNumbersApi.md#DeleteSafelist) | **Delete** /v1/SafeList/Numbers |
[**FetchSafelist**](SafeListNumbersApi.md#FetchSafelist) | **Get** /v1/SafeList/Numbers |



## CreateSafelist

> ApiV2010Safelist CreateSafelist(ctx, optional)
> AccountsV1Safelist CreateSafelist(ctx, optional)



Expand All @@ -33,7 +33,7 @@ Name | Type | Description

### Return type

[**ApiV2010Safelist**](ApiV2010Safelist.md)
[**AccountsV1Safelist**](AccountsV1Safelist.md)

### Authorization

Expand Down Expand Up @@ -90,7 +90,7 @@ Name | Type | Description

## FetchSafelist

> ApiV2010Safelist FetchSafelist(ctx, optional)
> AccountsV1Safelist FetchSafelist(ctx, optional)



Expand All @@ -111,7 +111,7 @@ Name | Type | Description

### Return type

[**ApiV2010Safelist**](ApiV2010Safelist.md)
[**AccountsV1Safelist**](AccountsV1Safelist.md)

### Authorization

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
* | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
*
* Twilio - Api
* Twilio - Accounts
* This is the public Twilio REST API.
*
* NOTE: This class is auto generated by OpenAPI Generator.
Expand All @@ -14,8 +14,8 @@

package openapi

// ApiV2010Safelist struct for ApiV2010Safelist
type ApiV2010Safelist struct {
// AccountsV1Safelist struct for AccountsV1Safelist
type AccountsV1Safelist struct {
// The unique string that we created to identify the SafeList resource.
Sid *string `json:"sid,omitempty"`
// The phone number in SafeList.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ package openapi
// ListCredentialAwsResponseMeta struct for ListCredentialAwsResponseMeta
type ListCredentialAwsResponseMeta struct {
FirstPageUrl string `json:"first_page_url,omitempty"`
Key string `json:"key,omitempty"`
NextPageUrl *string `json:"next_page_url,omitempty"`
Page int `json:"page,omitempty"`
PageSize int `json:"page_size,omitempty"`
PreviousPageUrl *string `json:"previous_page_url,omitempty"`
Url string `json:"url,omitempty"`
Key string `json:"key,omitempty"`
}
Loading