Skip to content

Commit

Permalink
feat(api): manual updates updated (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed Sep 26, 2024
1 parent 67dc5f9 commit fa7e2ad
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 6
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/find-ai%2Ffind-ai-eb213564d2ef98cf3d73c3688212227fdbb3974a8422b15d14c5b20bfdf8d22b.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/find-ai%2Ffind-ai-bf9b5b8a950e0a79b0bf1911bf01feb5a3575113be8f5d24f7b487351f3470c5.yml
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@ import (
"context"

"github.com/Find-AI/find-ai-go"
"github.com/Find-AI/find-ai-go/option"
)

func main() {
client := findai.NewClient()
client := findai.NewClient(
option.WithAPIKey("My API Key"), // defaults to os.LookupEnv("FIND_AI_API_KEY")
)
searchGetResponses, err := client.Searches.Get(context.TODO(), "id")
if err != nil {
panic(err.Error())
Expand Down
10 changes: 7 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package findai
import (
"context"
"net/http"
"os"

"github.com/Find-AI/find-ai-go/internal/requestconfig"
"github.com/Find-AI/find-ai-go/option"
Expand All @@ -21,11 +22,14 @@ type Client struct {
}

// NewClient generates a new client with the default option read from the
// environment (). The option passed in as arguments are applied after these
// default arguments, and all option will be passed down to the services and
// requests that this client makes.
// environment (FIND_AI_API_KEY). The option passed in as arguments are applied
// after these default arguments, and all option will be passed down to the
// services and requests that this client makes.
func NewClient(opts ...option.RequestOption) (r *Client) {
defaults := []option.RequestOption{option.WithEnvironmentProduction()}
if o, ok := os.LookupEnv("FIND_AI_API_KEY"); ok {
defaults = append(defaults, option.WithAPIKey(o))
}
opts = append(defaults, opts...)

r = &Client{Options: opts}
Expand Down
2 changes: 2 additions & 0 deletions companyenrichmentenrich_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func TestCompanyEnrichmentEnrichNewWithOptionalParams(t *testing.T) {
}
client := findai.NewClient(
option.WithBaseURL(baseURL),
option.WithAPIKey("My API Key"),
)
_, err := client.CompanyEnrichment.Enrich.New(context.TODO(), findai.CompanyEnrichmentEnrichNewParams{
Domain: findai.F("domain"),
Expand All @@ -46,6 +47,7 @@ func TestCompanyEnrichmentEnrichGet(t *testing.T) {
}
client := findai.NewClient(
option.WithBaseURL(baseURL),
option.WithAPIKey("My API Key"),
)
_, err := client.CompanyEnrichment.Enrich.Get(context.TODO(), "token")
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions internal/requestconfig/requestconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ type RequestConfig struct {
BaseURL *url.URL
HTTPClient *http.Client
Middlewares []middleware
APIKey string
// If ResponseBodyInto not nil, then we will attempt to deserialize into
// ResponseBodyInto. If Destination is a []byte, then it will return the body as
// is.
Expand Down Expand Up @@ -480,6 +481,7 @@ func (cfg *RequestConfig) Clone(ctx context.Context) *RequestConfig {
BaseURL: cfg.BaseURL,
HTTPClient: cfg.HTTPClient,
Middlewares: cfg.Middlewares,
APIKey: cfg.APIKey,
}

return new
Expand Down
8 changes: 8 additions & 0 deletions option/requestoption.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,11 @@ func WithRequestTimeout(dur time.Duration) RequestOption {
func WithEnvironmentProduction() RequestOption {
return WithBaseURL("https://usefind.ai/found/")
}

// WithAPIKey returns a RequestOption that sets the client setting "api_key".
func WithAPIKey(value string) RequestOption {
return func(r *requestconfig.RequestConfig) error {
r.APIKey = value
return r.Apply(WithHeader("Authorization", r.APIKey))
}
}
2 changes: 2 additions & 0 deletions peopleenrichmentenrich_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func TestPeopleEnrichmentEnrichNewWithOptionalParams(t *testing.T) {
}
client := findai.NewClient(
option.WithBaseURL(baseURL),
option.WithAPIKey("My API Key"),
)
_, err := client.PeopleEnrichment.Enrich.New(context.TODO(), findai.PeopleEnrichmentEnrichNewParams{
Email: findai.F("email"),
Expand All @@ -46,6 +47,7 @@ func TestPeopleEnrichmentEnrichGet(t *testing.T) {
}
client := findai.NewClient(
option.WithBaseURL(baseURL),
option.WithAPIKey("My API Key"),
)
_, err := client.PeopleEnrichment.Enrich.Get(context.TODO(), "token")
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func TestSearchNewWithOptionalParams(t *testing.T) {
}
client := findai.NewClient(
option.WithBaseURL(baseURL),
option.WithAPIKey("My API Key"),
)
_, err := client.Searches.New(context.TODO(), findai.SearchNewParams{
MaxMatches: findai.F(0.000000),
Expand All @@ -49,6 +50,7 @@ func TestSearchGet(t *testing.T) {
}
client := findai.NewClient(
option.WithBaseURL(baseURL),
option.WithAPIKey("My API Key"),
)
_, err := client.Searches.Get(context.TODO(), "id")
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions usage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func TestUsage(t *testing.T) {
}
client := findai.NewClient(
option.WithBaseURL(baseURL),
option.WithAPIKey("My API Key"),
)
_, err := client.Searches.Get(context.TODO(), "id")
if err != nil {
Expand Down

0 comments on commit fa7e2ad

Please sign in to comment.