Skip to content

Commit a4ebbf1

Browse files
author
stlc-bot
committed
feat(people): publish people search in the API specification (#2094)
Stainless-Generated-From: f926e2e509baf334f272aa099fc4de6fb8f0f389
1 parent 170ffef commit a4ebbf1

4 files changed

Lines changed: 147 additions & 1 deletion

File tree

‎.stats.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
configured_endpoints: 39
1+
configured_endpoints: 40

‎pkg/cmd/cmd.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ func init() {
181181
Suggest: true,
182182
Commands: []*cli.Command{
183183
&peopleEnrich,
184+
&peopleSearch,
184185
},
185186
},
186187
{

‎pkg/cmd/person.go‎

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,55 @@ var peopleEnrich = requestflag.WithInnerFlags(cli.Command{
145145
},
146146
})
147147

148+
var peopleSearch = requestflag.WithInnerFlags(cli.Command{
149+
Name: "search",
150+
Usage: "Find people with a natural-language query.",
151+
Suggest: true,
152+
Flags: []cli.Flag{
153+
&requestflag.Flag[string]{
154+
Name: "query",
155+
Usage: "Describe the people to find.",
156+
Required: true,
157+
BodyPath: "query",
158+
},
159+
&requestflag.Flag[string]{
160+
Name: "cursor",
161+
Usage: "Use next_cursor with the same query and filters to fetch the next page.",
162+
BodyPath: "cursor",
163+
},
164+
&requestflag.Flag[map[string]any]{
165+
Name: "filters",
166+
Usage: "Additional constraints every result must match.",
167+
BodyPath: "filters",
168+
},
169+
&requestflag.Flag[[]string]{
170+
Name: "tag",
171+
Usage: "Labels for filtering usage in the dashboard.",
172+
BodyPath: "tags",
173+
},
174+
},
175+
Action: handlePeopleSearch,
176+
HideHelpCommand: true,
177+
}, map[string][]requestflag.HasOuterFlag{
178+
"filters": {
179+
&requestflag.InnerFlag[[]string]{
180+
Name: "filters.countries",
181+
Usage: "Countries people live in as two-letter codes, such as US or GB.",
182+
InnerField: "countries",
183+
},
184+
&requestflag.InnerFlag[int64]{
185+
Name: "filters.years-of-experience-max",
186+
Usage: "Maximum years of professional experience.",
187+
InnerField: "years_of_experience_max",
188+
},
189+
&requestflag.InnerFlag[int64]{
190+
Name: "filters.years-of-experience-min",
191+
Usage: "Minimum years of professional experience.",
192+
InnerField: "years_of_experience_min",
193+
},
194+
},
195+
})
196+
148197
func handlePeopleEnrich(ctx context.Context, cmd *cli.Command) error {
149198
client := contextdev.NewClient(getDefaultRequestOptions(cmd)...)
150199
unusedArgs := cmd.Args().Slice()
@@ -185,3 +234,44 @@ func handlePeopleEnrich(ctx context.Context, cmd *cli.Command) error {
185234
Transform: transform,
186235
})
187236
}
237+
238+
func handlePeopleSearch(ctx context.Context, cmd *cli.Command) error {
239+
client := contextdev.NewClient(getDefaultRequestOptions(cmd)...)
240+
unusedArgs := cmd.Args().Slice()
241+
242+
if len(unusedArgs) > 0 {
243+
return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs)
244+
}
245+
246+
options, err := flagOptions(
247+
cmd,
248+
apiquery.NestedQueryFormatBrackets,
249+
apiquery.ArrayQueryFormatComma,
250+
ApplicationJSON,
251+
false,
252+
)
253+
if err != nil {
254+
return err
255+
}
256+
257+
params := contextdev.PersonSearchParams{}
258+
259+
var res []byte
260+
options = append(options, option.WithResponseBodyInto(&res))
261+
_, err = client.People.Search(ctx, params, options...)
262+
if err != nil {
263+
return err
264+
}
265+
266+
obj := gjson.ParseBytes(res)
267+
format := cmd.Root().String("format")
268+
explicitFormat := cmd.Root().IsSet("format")
269+
transform := cmd.Root().String("transform")
270+
return ShowJSON(obj, ShowJSONOpts{
271+
ExplicitFormat: explicitFormat,
272+
Format: format,
273+
RawOutput: cmd.Root().Bool("raw-output"),
274+
Title: "people search",
275+
Transform: transform,
276+
})
277+
}

‎pkg/cmd/person_test.go‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,58 @@ func TestPeopleEnrich(t *testing.T) {
9696
)
9797
})
9898
}
99+
100+
func TestPeopleSearch(t *testing.T) {
101+
t.Skip("Mock server tests are disabled")
102+
t.Run("regular flags", func(t *testing.T) {
103+
mocktest.TestRunMockTestWithFlags(
104+
t,
105+
"--api-key", "string",
106+
"people", "search",
107+
"--query", "VPs of sales at solar companies in California",
108+
"--cursor", "cursor",
109+
"--filters", "{countries: [SE], years_of_experience_max: 0, years_of_experience_min: 0}",
110+
"--tag", "production",
111+
"--tag", "team-alpha",
112+
)
113+
})
114+
115+
t.Run("inner flags", func(t *testing.T) {
116+
// Check that inner flags have been set up correctly
117+
requestflag.CheckInnerFlags(peopleSearch)
118+
119+
// Alternative argument passing style using inner flags
120+
mocktest.TestRunMockTestWithFlags(
121+
t,
122+
"--api-key", "string",
123+
"people", "search",
124+
"--query", "VPs of sales at solar companies in California",
125+
"--cursor", "cursor",
126+
"--filters.countries", "[SE]",
127+
"--filters.years-of-experience-max", "0",
128+
"--filters.years-of-experience-min", "0",
129+
"--tag", "production",
130+
"--tag", "team-alpha",
131+
)
132+
})
133+
134+
t.Run("piping data", func(t *testing.T) {
135+
// Test piping YAML data over stdin
136+
pipeData := []byte("" +
137+
"query: VPs of sales at solar companies in California\n" +
138+
"cursor: cursor\n" +
139+
"filters:\n" +
140+
" countries:\n" +
141+
" - SE\n" +
142+
" years_of_experience_max: 0\n" +
143+
" years_of_experience_min: 0\n" +
144+
"tags:\n" +
145+
" - production\n" +
146+
" - team-alpha\n")
147+
mocktest.TestRunMockTestWithPipeAndFlags(
148+
t, pipeData,
149+
"--api-key", "string",
150+
"people", "search",
151+
)
152+
})
153+
}

0 commit comments

Comments
 (0)