Skip to content

Commit 6a9b2f5

Browse files
feat(api): manual updates
1 parent 7e6e3b7 commit 6a9b2f5

4 files changed

Lines changed: 244 additions & 3 deletions

File tree

‎.stats.yml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 40
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-4f279e7b1f0a52f5c917d4256e17188dfe330ddf7495146e2b1611e812605fdc.yml
1+
configured_endpoints: 41
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-5dbe631ce516ca688273053ddcb58870561bd6dc76fa75df354c954d7af65a3c.yml
33
openapi_spec_hash: 53a74c4cccbdec8590db38183840a446
4-
config_hash: 920678668dd2da6f8966fbf1b8fde4e2
4+
config_hash: 0fb0ceca5946298c416cec0cca5260c7

‎pkg/cmd/cmd.go‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,14 @@ func init() {
187187
&peopleEnrich,
188188
},
189189
},
190+
{
191+
Name: "news",
192+
Category: "API RESOURCE",
193+
Suggest: true,
194+
Commands: []*cli.Command{
195+
&newsSearch,
196+
},
197+
},
190198
{
191199
Name: "@manpages",
192200
Usage: "Generate documentation for 'man'",

‎pkg/cmd/news.go‎

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
package cmd
4+
5+
import (
6+
"context"
7+
"fmt"
8+
9+
"github.com/context-dot-dev/context-dev-cli/internal/apiquery"
10+
"github.com/context-dot-dev/context-dev-cli/internal/requestflag"
11+
"github.com/context-dot-dev/context-go-sdk/v2"
12+
"github.com/context-dot-dev/context-go-sdk/v2/option"
13+
"github.com/tidwall/gjson"
14+
"github.com/urfave/cli/v3"
15+
)
16+
17+
var newsSearch = requestflag.WithInnerFlags(cli.Command{
18+
Name: "search",
19+
Usage: "Searches live and historical company news for one company, identified in\nsearchBy by name, domain, ticker (optionally disambiguated by exchange), or\nISIN. Results can be filtered by publisher domain, publisher country, article\nlanguage, article type, and published-at date, and include stable story IDs,\nsource metadata, verified entity relevance, and cursor pagination.",
20+
Suggest: true,
21+
Flags: []cli.Flag{
22+
&requestflag.Flag[map[string]any]{
23+
Name: "search-by",
24+
Usage: "What to search for.",
25+
Required: true,
26+
BodyPath: "searchBy",
27+
},
28+
&requestflag.Flag[*string]{
29+
Name: "cursor",
30+
Usage: "Opaque next_cursor from the previous response, or null for the first page.",
31+
BodyPath: "cursor",
32+
},
33+
&requestflag.Flag[map[string]any]{
34+
Name: "filter-by",
35+
Usage: "Optional result filters.",
36+
Default: map[string]any{},
37+
BodyPath: "filterBy",
38+
},
39+
&requestflag.Flag[int64]{
40+
Name: "limit",
41+
Usage: "Maximum results to return. Defaults to 10.",
42+
Default: 10,
43+
BodyPath: "limit",
44+
},
45+
&requestflag.Flag[map[string]any]{
46+
Name: "sort-by",
47+
Usage: "Result ordering. Defaults to newest.",
48+
Default: map[string]any{"type": "newest"},
49+
BodyPath: "sortBy",
50+
},
51+
&requestflag.Flag[[]string]{
52+
Name: "tag",
53+
Usage: "Optional tags for tracking usage. Up to 20 tags, each 1 to 50 characters.",
54+
BodyPath: "tags",
55+
},
56+
},
57+
Action: handleNewsSearch,
58+
HideHelpCommand: true,
59+
}, map[string][]requestflag.HasOuterFlag{
60+
"search-by": {
61+
&requestflag.InnerFlag[map[string]any]{
62+
Name: "search-by.entity",
63+
Usage: "The company to search news for, identified by name, domain, ticker, or ISIN.",
64+
InnerField: "entity",
65+
},
66+
&requestflag.InnerFlag[string]{
67+
Name: "search-by.type",
68+
Usage: "How to search. Only entity search is supported.",
69+
InnerField: "type",
70+
},
71+
},
72+
"filter-by": {
73+
&requestflag.InnerFlag[[]string]{
74+
Name: "filter-by.article-language",
75+
Usage: "Article languages to include. Up to 3.",
76+
InnerField: "articleLanguage",
77+
},
78+
&requestflag.InnerFlag[[]string]{
79+
Name: "filter-by.article-type",
80+
Usage: "Article types to include. Up to 3.",
81+
InnerField: "articleType",
82+
},
83+
&requestflag.InnerFlag[map[string]any]{
84+
Name: "filter-by.date",
85+
Usage: "Published-at window in epoch milliseconds.",
86+
InnerField: "date",
87+
},
88+
&requestflag.InnerFlag[[]string]{
89+
Name: "filter-by.source-country",
90+
Usage: "Publisher countries to include, as lowercase ISO 3166-1 alpha-2 codes. Up to 3.",
91+
InnerField: "sourceCountry",
92+
},
93+
&requestflag.InnerFlag[[]string]{
94+
Name: "filter-by.source-domain",
95+
Usage: "Publisher domains to include. Up to 3.",
96+
InnerField: "sourceDomain",
97+
},
98+
},
99+
"sort-by": {
100+
&requestflag.InnerFlag[string]{
101+
Name: "sort-by.type",
102+
Usage: "Result ordering.",
103+
InnerField: "type",
104+
},
105+
},
106+
})
107+
108+
func handleNewsSearch(ctx context.Context, cmd *cli.Command) error {
109+
client := contextdev.NewClient(getDefaultRequestOptions(cmd)...)
110+
unusedArgs := cmd.Args().Slice()
111+
112+
if len(unusedArgs) > 0 {
113+
return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs)
114+
}
115+
116+
options, err := flagOptions(
117+
cmd,
118+
apiquery.NestedQueryFormatBrackets,
119+
apiquery.ArrayQueryFormatComma,
120+
ApplicationJSON,
121+
false,
122+
)
123+
if err != nil {
124+
return err
125+
}
126+
127+
params := contextdev.NewsSearchParams{}
128+
129+
var res []byte
130+
options = append(options, option.WithResponseBodyInto(&res))
131+
_, err = client.News.Search(ctx, params, options...)
132+
if err != nil {
133+
return err
134+
}
135+
136+
obj := gjson.ParseBytes(res)
137+
format := cmd.Root().String("format")
138+
explicitFormat := cmd.Root().IsSet("format")
139+
transform := cmd.Root().String("transform")
140+
return ShowJSON(obj, ShowJSONOpts{
141+
ExplicitFormat: explicitFormat,
142+
Format: format,
143+
RawOutput: cmd.Root().Bool("raw-output"),
144+
Title: "news search",
145+
Transform: transform,
146+
})
147+
}

‎pkg/cmd/news_test.go‎

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
package cmd
4+
5+
import (
6+
"testing"
7+
8+
"github.com/context-dot-dev/context-dev-cli/internal/mocktest"
9+
"github.com/context-dot-dev/context-dev-cli/internal/requestflag"
10+
)
11+
12+
func TestNewsSearch(t *testing.T) {
13+
t.Skip("Mock server tests are disabled")
14+
t.Run("regular flags", func(t *testing.T) {
15+
mocktest.TestRunMockTestWithFlags(
16+
t,
17+
"--api-key", "string",
18+
"news", "search",
19+
"--search-by", "{entity: {name: xx, type: name}, type: entity}",
20+
"--cursor", "cursor",
21+
"--filter-by", "{articleLanguage: [ar], articleType: [editorial], date: {from: 0, to: 0}, sourceCountry: [ae], sourceDomain: [x]}",
22+
"--limit", "1",
23+
"--sort-by", "{type: relevance}",
24+
"--tag", "production",
25+
"--tag", "team-alpha",
26+
)
27+
})
28+
29+
t.Run("inner flags", func(t *testing.T) {
30+
// Check that inner flags have been set up correctly
31+
requestflag.CheckInnerFlags(newsSearch)
32+
33+
// Alternative argument passing style using inner flags
34+
mocktest.TestRunMockTestWithFlags(
35+
t,
36+
"--api-key", "string",
37+
"news", "search",
38+
"--search-by.entity", "{name: xx, type: name}",
39+
"--search-by.type", "entity",
40+
"--cursor", "cursor",
41+
"--filter-by.article-language", "[ar]",
42+
"--filter-by.article-type", "[editorial]",
43+
"--filter-by.date", "{from: 0, to: 0}",
44+
"--filter-by.source-country", "[ae]",
45+
"--filter-by.source-domain", "[x]",
46+
"--limit", "1",
47+
"--sort-by.type", "relevance",
48+
"--tag", "production",
49+
"--tag", "team-alpha",
50+
)
51+
})
52+
53+
t.Run("piping data", func(t *testing.T) {
54+
// Test piping YAML data over stdin
55+
pipeData := []byte("" +
56+
"searchBy:\n" +
57+
" entity:\n" +
58+
" name: xx\n" +
59+
" type: name\n" +
60+
" type: entity\n" +
61+
"cursor: cursor\n" +
62+
"filterBy:\n" +
63+
" articleLanguage:\n" +
64+
" - ar\n" +
65+
" articleType:\n" +
66+
" - editorial\n" +
67+
" date:\n" +
68+
" from: 0\n" +
69+
" to: 0\n" +
70+
" sourceCountry:\n" +
71+
" - ae\n" +
72+
" sourceDomain:\n" +
73+
" - x\n" +
74+
"limit: 1\n" +
75+
"sortBy:\n" +
76+
" type: relevance\n" +
77+
"tags:\n" +
78+
" - production\n" +
79+
" - team-alpha\n")
80+
mocktest.TestRunMockTestWithPipeAndFlags(
81+
t, pipeData,
82+
"--api-key", "string",
83+
"news", "search",
84+
)
85+
})
86+
}

0 commit comments

Comments
 (0)