MCPcopy Create free account
hub / github.com/algolia/cli / NewClient

Function NewClient

api/dashboard/client.go:33–74  ·  view source on GitHub ↗

NewClient creates a new dashboard client with the given OAuth client ID. Respects ALGOLIA_DASHBOARD_URL, ALGOLIA_API_URL, and ALGOLIA_OAUTH_SCOPE environment variables, falling back to the compiled-in defaults (set via ldflags).

(clientID string)

Source from the content-addressed store, hash-verified

31// Respects ALGOLIA_DASHBOARD_URL, ALGOLIA_API_URL, and ALGOLIA_OAUTH_SCOPE
32// environment variables, falling back to the compiled-in defaults (set via ldflags).
33func NewClient(clientID string) *Client {
34 dashboardURL := DefaultDashboardURL
35 if v := os.Getenv("ALGOLIA_DASHBOARD_URL"); v != "" {
36 dashboardURL = strings.TrimRight(v, "/")
37 }
38 if dashboardURL == "" {
39 fmt.Fprintln(
40 os.Stderr,
41 "fatal: ALGOLIA_DASHBOARD_URL is not set and no default was compiled in",
42 )
43 os.Exit(1)
44 }
45
46 apiURL := DefaultAPIURL
47 if v := os.Getenv("ALGOLIA_API_URL"); v != "" {
48 apiURL = strings.TrimRight(v, "/")
49 }
50 if apiURL == "" {
51 fmt.Fprintln(os.Stderr, "fatal: ALGOLIA_API_URL is not set and no default was compiled in")
52 os.Exit(1)
53 }
54
55 oauthScope := DefaultOAuthScope
56 if v := os.Getenv("ALGOLIA_OAUTH_SCOPE"); v != "" {
57 oauthScope = v
58 }
59 if oauthScope == "" {
60 fmt.Fprintln(
61 os.Stderr,
62 "fatal: ALGOLIA_OAUTH_SCOPE is not set and no default was compiled in",
63 )
64 os.Exit(1)
65 }
66
67 return &Client{
68 DashboardURL: dashboardURL,
69 APIURL: apiURL,
70 OAuthScope: oauthScope,
71 ClientID: clientID,
72 client: http.DefaultClient,
73 }
74}
75
76// NewClientWithHTTPClient creates a new dashboard client with a custom HTTP client.
77// Used primarily in tests; callers must set DashboardURL and APIURL explicitly.

Callers 14

NewOpenCmdFunction · 0.92
NewGetCmdFunction · 0.92
NewSignupCmdFunction · 0.92
NewLoginCmdFunction · 0.92
NewLogoutCmdFunction · 0.92
NewCrawlerCmdFunction · 0.92
NewDowngradeCmdFunction · 0.92
NewUpdateCmdFunction · 0.92
NewListCmdFunction · 0.92
NewSelectCmdFunction · 0.92
RunFunction · 0.92
NewCreateCmdFunction · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected