Skip to content
This repository has been archived by the owner on Nov 5, 2022. It is now read-only.

Commit

Permalink
update exports
Browse files Browse the repository at this point in the history
  • Loading branch information
Fallenstedt committed Nov 25, 2021
1 parent 4ad157e commit 6b7c9ba
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion stream_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type (

// newStreamResponseBodyReader returns an instance of streamResponseBodyReader
// for the given Twitter stream response body.
func newStreamResponseBodyReader() *streamResponseBodyReader {
func newStreamResponseBodyReader() IStreamResponseBodyReader {
return &streamResponseBodyReader{}
}

Expand Down
14 changes: 7 additions & 7 deletions token_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (
)

type (
//ITokenGenerator is the interface that tokenGenerator implements.
//ITokenGenerator is the interface that TokenGenerator implements.
ITokenGenerator interface {
RequestBearerToken() (*RequestBearerTokenResponse, error)
SetApiKeyAndSecret(apiKey, apiSecret string) ITokenGenerator
}
tokenGenerator struct {
TokenGenerator struct {
httpClient httpclient.IHttpClient
apiKey string
apiSecret string
Expand All @@ -24,18 +24,18 @@ type (
)

func newTokenGenerator(httpClient httpclient.IHttpClient) ITokenGenerator {
return &tokenGenerator{httpClient: httpClient}
return &TokenGenerator{httpClient: httpClient}
}

// SetApiKeyAndSecret sets the apiKey and apiSecret fields for the tokenGenerator instance.
func (a *tokenGenerator) SetApiKeyAndSecret(apiKey, apiSecret string) ITokenGenerator {
// SetApiKeyAndSecret sets the apiKey and apiSecret fields for the TokenGenerator instance.
func (a *TokenGenerator) SetApiKeyAndSecret(apiKey, apiSecret string) ITokenGenerator {
a.apiKey = apiKey
a.apiSecret = apiSecret
return a
}

// RequestBearerToken requests a bearer token from twitter using the apiKey and apiSecret.
func (a *tokenGenerator) RequestBearerToken() (*RequestBearerTokenResponse, error) {
func (a *TokenGenerator) RequestBearerToken() (*RequestBearerTokenResponse, error) {

resp, err := a.httpClient.NewHttpRequest(&httpclient.RequestOpts{
Headers: []struct {
Expand All @@ -62,7 +62,7 @@ func (a *tokenGenerator) RequestBearerToken() (*RequestBearerTokenResponse, erro
}


func (a *tokenGenerator) base64EncodeKeys() string {
func (a *TokenGenerator) base64EncodeKeys() string {
// See Step 1 of encoding consumer key and secret twitter application-only requests here
// https://developer.twitter.com/en/docs/authentication/oauth-2-0/application-only
return base64.StdEncoding.EncodeToString([]byte(a.apiKey + ":" + a.apiSecret))
Expand Down
8 changes: 4 additions & 4 deletions token_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ func TestSetApiKeyAndSecret(t *testing.T) {
var tests = []struct {
apiKey string
apiSecret string
result tokenGenerator
result TokenGenerator
}{
{"foo", "bar", tokenGenerator{apiKey: "foo", apiSecret: "bar"}},
{"", "", tokenGenerator{apiKey: "", apiSecret: ""}},
{"foo", "bar", TokenGenerator{apiKey: "foo", apiSecret: "bar"}},
{"", "", TokenGenerator{apiKey: "", apiSecret: ""}},
}

for i, tt := range tests {
testName := fmt.Sprintf("(%d) %s %s", i, tt.apiKey, tt.apiSecret)
t.Run(testName, func(t *testing.T) {
result := &tokenGenerator{httpClient: httpclient.NewHttpClientMock("")}
result := &TokenGenerator{httpClient: httpclient.NewHttpClientMock("")}
result.SetApiKeyAndSecret(tt.apiKey, tt.apiSecret)

if result.apiKey != tt.result.apiKey {
Expand Down
2 changes: 1 addition & 1 deletion twitterstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type TwitterApi struct {
}


// NewTokenGenerator creates a tokenGenerator which can request a Bearer token using a twitter api key and secret.
// NewTokenGenerator creates a TokenGenerator which can request a Bearer token using a twitter api key and secret.
func NewTokenGenerator() ITokenGenerator {
client := httpclient.NewHttpClient("")
tokenGenerator := newTokenGenerator(client)
Expand Down

0 comments on commit 6b7c9ba

Please sign in to comment.