Skip to content

Commit

Permalink
Merge pull request #77 from Weimw/add-dg-header
Browse files Browse the repository at this point in the history
change to User-Agent header
  • Loading branch information
SandraRodgers authored Aug 22, 2023
2 parents 82dda92 + 677b9e3 commit 7c935e1
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 30 deletions.
4 changes: 2 additions & 2 deletions deepgram/billing.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (dg *Client) ListBalances(projectId string) (BalanceList, error) {
"Host": []string{dg.Host},
"Content-Type": []string{"application/json"},
"Authorization": []string{"token " + dg.ApiKey},
"X-DG-Agent": []string{dgAgent},
"User-Agent": []string{dgAgent},
}

var result BalanceList
Expand Down Expand Up @@ -69,7 +69,7 @@ func (dg *Client) GetBalance(projectId string, balanceId string) (Balance, error
"Host": []string{dg.Host},
"Content-Type": []string{"application/json"},
"Authorization": []string{"token " + dg.ApiKey},
"X-DG-Agent": []string{dgAgent},
"User-Agent": []string{dgAgent},
}

var result Balance
Expand Down
13 changes: 12 additions & 1 deletion deepgram/deepgram.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ package deepgram
import (
"encoding/json"
"net/http"
"runtime"
"strings"
)

var sdkVersion string = "0.10.0"
var dgAgent string = "deepgram-go-sdk/v" + sdkVersion

var dgAgent string = "@deepgram/sdk/" + sdkVersion + " go/" + goVersion()

type Client struct {
ApiKey string
Expand Down Expand Up @@ -44,3 +47,11 @@ func GetJson(resp *http.Response, target interface{}) error {

return json.NewDecoder(resp.Body).Decode(target)
}

func goVersion() string {
version := runtime.Version()
if strings.HasPrefix(version, "go") {
return version[2:]
}
return version
}
6 changes: 3 additions & 3 deletions deepgram/invitations.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (dg *Client) ListInvitations(projectId string) (InvitationList, error) {
"Host": []string{dg.Host},
"Content-Type": []string{"application/json"},
"Authorization": []string{"token " + dg.ApiKey},
"X-DG-Agent": []string{dgAgent},
"User-Agent": []string{dgAgent},
}

var result InvitationList
Expand Down Expand Up @@ -60,7 +60,7 @@ func (dg *Client) SendInvitation(projectId string, options InvitationOptions) (M
"Host": []string{dg.Host},
"Content-Type": []string{"application/json"},
"Authorization": []string{"token " + dg.ApiKey},
"X-DG-Agent": []string{dgAgent},
"User-Agent": []string{dgAgent},
}

var result Message
Expand Down Expand Up @@ -95,7 +95,7 @@ func (dg *Client) DeleteInvitation(projectId string, email string) (Message, err
"Host": []string{dg.Host},
"Content-Type": []string{"application/json"},
"Authorization": []string{"token " + dg.ApiKey},
"X-DG-Agent": []string{dgAgent},
"User-Agent": []string{dgAgent},
}

var result Message
Expand Down
8 changes: 4 additions & 4 deletions deepgram/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (dg *Client) ListKeys(projectId string) (KeyResponse, error) {
"Host": []string{dg.Host},
"Content-Type": []string{"application/json"},
"Authorization": []string{"token " + dg.ApiKey},
"X-DG-Agent": []string{dgAgent},
"User-Agent": []string{dgAgent},
}

var result KeyResponse
Expand Down Expand Up @@ -91,7 +91,7 @@ func (dg *Client) GetKey(projectId string, keyId string) (KeyResponseObj, error)
"Host": []string{dg.Host},
"Content-Type": []string{"application/json"},
"Authorization": []string{"token " + dg.ApiKey},
"X-DG-Agent": []string{dgAgent},
"User-Agent": []string{dgAgent},
}

var result KeyResponseObj
Expand Down Expand Up @@ -145,7 +145,7 @@ func (dg *Client) CreateKey(projectId string, comment string, scopes []string, o
"Host": []string{dg.Host},
"Content-Type": []string{"application/json"},
"Authorization": []string{"token " + dg.ApiKey},
"X-DG-Agent": []string{dgAgent},
"User-Agent": []string{dgAgent},
}

var result Key
Expand Down Expand Up @@ -182,7 +182,7 @@ func (dg *Client) DeleteKey(projectId string, keyId string) (Message, error) {
"Host": []string{dg.Host},
"Content-Type": []string{"application/json"},
"Authorization": []string{"token " + dg.ApiKey},
"X-DG-Agent": []string{dgAgent},
"User-Agent": []string{dgAgent},
}
var result Message
res, err := client.Do(req)
Expand Down
10 changes: 5 additions & 5 deletions deepgram/members.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (dg *Client) ListMembers(projectId string) (MemberList, error) {
"Host": []string{dg.Host},
"Content-Type": []string{"application/json"},
"Authorization": []string{"token " + dg.ApiKey},
"X-DG-Agent": []string{dgAgent},
"User-Agent": []string{dgAgent},
}

var result MemberList
Expand Down Expand Up @@ -75,7 +75,7 @@ func (dg *Client) RemoveMember(projectId string, memberId string) (Message, erro
"Host": []string{dg.Host},
"Content-Type": []string{"application/json"},
"Authorization": []string{"token " + dg.ApiKey},
"X-DG-Agent": []string{dgAgent},
"User-Agent": []string{dgAgent},
}

var result Message
Expand Down Expand Up @@ -111,7 +111,7 @@ func (dg *Client) GetMemberScopes(projectId string, memberId string) (ScopeList,
"Host": []string{dg.Host},
"Content-Type": []string{"application/json"},
"Authorization": []string{"token " + dg.ApiKey},
"X-DG-Agent": []string{dgAgent},
"User-Agent": []string{dgAgent},
}

var result ScopeList
Expand Down Expand Up @@ -152,7 +152,7 @@ func (dg *Client) UpdateMemberScopes(projectId string, memberId string, scope st
"Host": []string{dg.Host},
"Content-Type": []string{"application/json"},
"Authorization": []string{"token " + dg.ApiKey},
"X-DG-Agent": []string{dgAgent},
"User-Agent": []string{dgAgent},
}

var result Message
Expand Down Expand Up @@ -189,7 +189,7 @@ func (dg *Client) LeaveProject(projectId string) (Message, error) {
"Host": []string{dg.Host},
"Content-Type": []string{"application/json"},
"Authorization": []string{"token " + dg.ApiKey},
"X-DG-Agent": []string{dgAgent},
"User-Agent": []string{dgAgent},
}

var result Message
Expand Down
12 changes: 6 additions & 6 deletions deepgram/prerecorded.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ type PreRecordedTranscriptionOptions struct {
Utterances bool `json:"utterances" url:"utterances,omitempty" `
Utt_split float64 `json:"utt_split" url:"utt_split,omitempty" `
Version string `json:"version" url:"version,omitempty" `
FillerWords string `json:"filler_words" url:"filler_words,omitempty" `
FillerWords string `json:"filler_words" url:"filler_words,omitempty" `
}

type PreRecordedResponse struct {
Request_id string `json:"request_id,omitempty"`
Metadata Metadata `json:"metadata"`
Results Results `json:"results"`
Request_id string `json:"request_id,omitempty"`
Metadata Metadata `json:"metadata"`
Results Results `json:"results"`
}

type Metadata struct {
Expand Down Expand Up @@ -203,7 +203,7 @@ func (dg *Client) PreRecordedFromStream(source ReadStreamSource, options PreReco
"Host": []string{dg.Host},
"Content-Type": []string{source.Mimetype},
"Authorization": []string{"token " + dg.ApiKey},
"X-DG-Agent": []string{dgAgent},
"User-Agent": []string{dgAgent},
}

res, err := client.Do(req)
Expand Down Expand Up @@ -246,7 +246,7 @@ func (dg *Client) PreRecordedFromURL(source UrlSource, options PreRecordedTransc
"Host": []string{dg.Host},
"Content-Type": []string{"application/json"},
"Authorization": []string{"token " + dg.ApiKey},
"X-DG-Agent": []string{dgAgent},
"User-Agent": []string{dgAgent},
}

var result PreRecordedResponse
Expand Down
8 changes: 4 additions & 4 deletions deepgram/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (dg *Client) ListProjects() (ProjectResponse, error) {
"Host": []string{dg.Host},
"Content-Type": []string{"application/json"},
"Authorization": []string{"token " + dg.ApiKey},
"X-DG-Agent": []string{dgAgent},
"User-Agent": []string{dgAgent},
}

var result ProjectResponse
Expand Down Expand Up @@ -75,7 +75,7 @@ func (dg *Client) GetProject(projectId string) (Project, error) {
"Host": []string{dg.Host},
"Content-Type": []string{"application/json"},
"Authorization": []string{"token " + dg.ApiKey},
"X-DG-Agent": []string{dgAgent},
"User-Agent": []string{dgAgent},
}

var result Project
Expand Down Expand Up @@ -116,7 +116,7 @@ func (dg *Client) UpdateProject(projectId string, options ProjectUpdateOptions)
"Host": []string{dg.Host},
"Content-Type": []string{"application/json"},
"Authorization": []string{"token " + dg.ApiKey},
"X-DG-Agent": []string{dgAgent},
"User-Agent": []string{dgAgent},
}

var result Message
Expand Down Expand Up @@ -153,7 +153,7 @@ func (dg *Client) DeleteProject(projectId string) (Message, error) {
"Host": []string{dg.Host},
"Content-Type": []string{"application/json"},
"Authorization": []string{"token " + dg.ApiKey},
"X-DG-Agent": []string{dgAgent},
"User-Agent": []string{dgAgent},
}

var result Message
Expand Down
2 changes: 1 addition & 1 deletion deepgram/transcriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (dg *Client) LiveTranscription(options LiveTranscriptionOptions) (*websocke
header := http.Header{
"Host": []string{dg.Host},
"Authorization": []string{"token " + dg.ApiKey},
"X-DG-Agent": []string{dgAgent},
"User-Agent": []string{dgAgent},
}

c, resp, err := websocket.DefaultDialer.Dial(u.String(), header)
Expand Down
8 changes: 4 additions & 4 deletions deepgram/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (dg *Client) ListRequests(projectId string, options UsageRequestListOptions
"Host": []string{dg.Host},
"Content-Type": []string{"application/json"},
"Authorization": []string{"token " + dg.ApiKey},
"X-DG-Agent": []string{dgAgent},
"User-Agent": []string{dgAgent},
}

var result UsageRequestList
Expand Down Expand Up @@ -134,7 +134,7 @@ func (dg *Client) GetRequest(projectId string, requestId string) (UsageRequest,
"Host": []string{dg.Host},
"Content-Type": []string{"application/json"},
"Authorization": []string{"token " + dg.ApiKey},
"X-DG-Agent": []string{dgAgent},
"User-Agent": []string{dgAgent},
}

var result UsageRequest
Expand Down Expand Up @@ -171,7 +171,7 @@ func (dg *Client) GetFields(projectId string, options UsageRequestListOptions) (
"Host": []string{dg.Host},
"Content-Type": []string{"application/json"},
"Authorization": []string{"token " + dg.ApiKey},
"X-DG-Agent": []string{dgAgent},
"User-Agent": []string{dgAgent},
}

var result interface{}
Expand Down Expand Up @@ -208,7 +208,7 @@ func (dg *Client) GetUsage(projectId string, options UsageOptions) (UsageSummary
"Host": []string{dg.Host},
"Content-Type": []string{"application/json"},
"Authorization": []string{"token " + dg.ApiKey},
"X-DG-Agent": []string{dgAgent},
"User-Agent": []string{dgAgent},
}

var result UsageSummary
Expand Down

0 comments on commit 7c935e1

Please sign in to comment.