Skip to content
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

chore: add user-agent header on all requests #60

Merged
merged 2 commits into from
Apr 13, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
language: go
go:
- "1.14"
- "1.15"
- "1.16"
- master
install:
- make install
script:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test:

goimports:
go get golang.org/x/tools/cmd/goimports
goimports -w twilio
goimports -w .

govet: goimports
go vet ./...
Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# twilio-go

[![Build Status](https://travis-ci.com/twilio/twilio-go.png?branch=main)](https://travis-ci.com/twilio/twilio-go)
[![PkgGoDev](https://pkg.go.dev/badge/github.com/twilio/twilio-go)](https://pkg.go.dev/github.com/twilio/twilio-go)
[![Release](https://img.shields.io/github/release/twilio/twilio-go.svg)](https://github.com/twilio/twilio-go/releases/latest)
[![Learn OSS Contribution in TwilioQuest](https://img.shields.io/static/v1?label=TwilioQuest&message=Learn%20to%20contribute%21&color=F22F46&labelColor=1f243c&style=flat-square&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAMAAAD04JH5AAAASFBMVEUAAAAZGRkcHBwjIyMoKCgAAABgYGBoaGiAgICMjIyzs7PJycnMzMzNzc3UoBfd3d3m5ubqrhfrMEDu7u739/f4vSb/3AD///9tbdyEAAAABXRSTlMAAAAAAMJrBrEAAAKoSURBVHgB7ZrRcuI6EESdyxXGYoNFvMD//+l2bSszRgyUYpFAsXOeiJGmj4NkuWx1Qeh+Ekl9DgEXOBwOx+Px5xyQhDykfgq4wG63MxxaR4ddIkg6Ul3g84vCIcjPBA5gmUMeXESrlukuoK33+33uID8TWeLAdOWsKpJYzwVMB7bOzYSGOciyUlXSn0/ABXTosJ1M1SbypZ4O4MbZuIDMU02PMbauhhHMHXbmebmALIiEbbbbbUrpF1gwE9kFfRNAJaP+FQEXCCTGyJ4ngDrjOFo3jEL5JdqjF/pueR4cCeCGgAtwmuRS6gDwaRiGvu+DMFwSBLTE3+jF8JyuV1okPZ+AC4hDFhCHyHQjdjPHUKFDlHSJkHQXMB3KpSwXNGJPcwwTdZiXlRN0gSp0zpWxNtM0beYE0nRH6QIbO7rawwXaBYz0j78gxjokDuv12gVeUuBD0MDi0OQCLvDaAho4juP1Q/jkAncXqIcCfd+7gAu4QLMACCLxpRsSuQh0igu0C9Svhi7weAGZg50L3IE3cai4IfkNZAC8dfdhsUD3CgKBVC9JE5ABAFzg4QL/taYPAAWrHdYcgfLaIgAXWJ7OV38n1LEF8tt2TH29E+QAoDoO5Ve/LtCQDmKM9kPbvCEBApK+IXzbcSJ0cIGF6e8gpcRhUDogWZ8JnaWjPXc/fNnBBUKRngiHgTUSivSzDRDgHZQOLvBQgf8rRt+VdBUUhwkU6VpJ+xcOwQUqZr+mR0kvBUgv6cB4+37hQAkXqE8PwGisGhJtN4xAHMzrsgvI7rccXqSvKh6jltGlrOHA3Xk1At3LC4QiPdX9/0ndHpGVvTjR4bZA1ypAKgVcwE5vx74ulwIugDt8e/X7JgfkucBMIAr26ndnB4UCLnDOqvteQsHlgX9N4A+c4cW3DXSPbwAAAABJRU5ErkJggg==)](https://twil.io/learn-open-source)

## Documentation
Expand All @@ -11,7 +13,6 @@ The documentation for the Twilio API can be found [here][apidocs].

This library supports the following Go implementations:

* 1.14
* 1.15
* 1.16

Expand Down Expand Up @@ -219,6 +220,3 @@ If you need help installing or using the library, please check the [Twilio Suppo
All the code [here](twilio/rest) was generated by [twilio-oai-generator](https://github.com/twilio/twilio-oai-generator) by leveraging [openapi-generator](https://github.com/OpenAPITools/openapi-generator) and [twilio-oai](https://github.com/twilio/twilio-oai). If you find an issue with the generation or the openapi specs, please go ahead and open an issue or a PR against the relevant repositories.

[apidocs]: https://www.twilio.com/docs/api
[twiml]: https://www.twilio.com/docs/api/twiml
[libdocs]: https://twilio.github.io/twilio-go

10 changes: 10 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import (
"net/http"
"net/url"
"regexp"
"runtime"
"strconv"
"strings"
"time"

"github.com/pkg/errors"
"github.com/twilio/twilio-go/config"
twilioError "github.com/twilio/twilio-go/framework/error"
)

Expand Down Expand Up @@ -87,6 +89,7 @@ func (c Client) SendRequest(method string, rawURL string, queryParams interface{
}

valueReader := &strings.Reader{}
goVersion := runtime.Version()

if queryParams != nil {
v, _ := EncodeToStringWith(queryParams, delimiter, escapee, keepZeros)
Expand All @@ -107,6 +110,13 @@ func (c Client) SendRequest(method string, rawURL string, queryParams interface{

req.SetBasicAuth(c.basicAuth())

// go1.16 -> v1.16
shwetha-manvinkurke marked this conversation as resolved.
Show resolved Hide resolved
goVersion = strings.Replace(goVersion, "go", "v", -1)

// E.g. "User-Agent": "twilio-go/1.0.0 (Go v1.16)"
userAgent := fmt.Sprint("twilio-go/", config.LibraryVersion, " (Go ", goVersion, ")")
req.Header.Add("User-Agent", userAgent)

if method == http.MethodPost {
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
}
Expand Down
7 changes: 4 additions & 3 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package client_test

import (
"encoding/json"
"github.com/stretchr/testify/assert"
twilio "github.com/twilio/twilio-go/client"
"github.com/twilio/twilio-go/framework/error"
"net/http"
"net/http/httptest"
"testing"
"time"

"github.com/stretchr/testify/assert"
twilio "github.com/twilio/twilio-go/client"
"github.com/twilio/twilio-go/framework/error"
)

func NewClient(accountSid string, authToken string) *twilio.Client {
Expand Down
5 changes: 5 additions & 0 deletions config/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Package config for config files.
package config

// LibraryVersion specifies the current version of twilio-go.
const LibraryVersion = "0.5.0"
5 changes: 3 additions & 2 deletions framework/error/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package error_test

import (
"encoding/json"
assert "github.com/stretchr/testify/require"
"github.com/twilio/twilio-go/framework/error"
"strings"
"testing"

assert "github.com/stretchr/testify/require"
"github.com/twilio/twilio-go/framework/error"
)

const errorCode = 20001
Expand Down