Skip to content

Commit

Permalink
feat: options for local client
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelrubbioli committed Nov 6, 2024
1 parent 598dda4 commit f98f1e2
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions inter.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type inter struct {
ClientSecret string
ContaCorrente string
BaseURL string
DisableTLS bool

client *http.Client
Oauth *oauth.OAuth
Expand All @@ -40,6 +41,13 @@ func WithSandboxEnv() Option {
}
}

func WithLocalEnv(url string) Option {
return func(i *inter) {
i.BaseURL = url
i.DisableTLS = true
}
}

// New creates a new Inter instance with the provided key file path, certificate file path, client id and client secret
func New(keyFilePath, certFilePath, clientID, clientSecret string, accountNumber *string, options ...Option) (Inter, error) {
i := &inter{
Expand All @@ -52,14 +60,18 @@ func New(keyFilePath, certFilePath, clientID, clientSecret string, accountNumber
option(i)
}

c, err := NewClient(certFilePath, keyFilePath, accountNumber)
if err != nil {
return nil, err
}
var err error
if !i.DisableTLS {
i.client, err = NewClient(certFilePath, keyFilePath, accountNumber)
if err != nil {
return nil, err
}

i.client = c
} else {
i.client = http.DefaultClient
}

o := oauth.NewOAuth(c, clientID, clientSecret, i.BaseURL)
o := oauth.NewOAuth(i.client, clientID, clientSecret, i.BaseURL)
i.Oauth = o

return i, nil
Expand Down

0 comments on commit f98f1e2

Please sign in to comment.