1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 package kgsearch
52
53 import (
54 "bytes"
55 "context"
56 "encoding/json"
57 "errors"
58 "fmt"
59 "io"
60 "net/http"
61 "net/url"
62 "strconv"
63 "strings"
64
65 googleapi "google.golang.org/api/googleapi"
66 internal "google.golang.org/api/internal"
67 gensupport "google.golang.org/api/internal/gensupport"
68 option "google.golang.org/api/option"
69 internaloption "google.golang.org/api/option/internaloption"
70 htransport "google.golang.org/api/transport/http"
71 )
72
73
74
75 var _ = bytes.NewBuffer
76 var _ = strconv.Itoa
77 var _ = fmt.Sprintf
78 var _ = json.NewDecoder
79 var _ = io.Copy
80 var _ = url.Parse
81 var _ = gensupport.MarshalJSON
82 var _ = googleapi.Version
83 var _ = errors.New
84 var _ = strings.Replace
85 var _ = context.Canceled
86 var _ = internaloption.WithDefaultEndpoint
87 var _ = internal.Version
88
89 const apiId = "kgsearch:v1"
90 const apiName = "kgsearch"
91 const apiVersion = "v1"
92 const basePath = "https://kgsearch.googleapis.com/"
93 const basePathTemplate = "https://kgsearch.UNIVERSE_DOMAIN/"
94 const mtlsBasePath = "https://kgsearch.mtls.googleapis.com/"
95
96
97 func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, error) {
98 opts = append(opts, internaloption.WithDefaultEndpoint(basePath))
99 opts = append(opts, internaloption.WithDefaultEndpointTemplate(basePathTemplate))
100 opts = append(opts, internaloption.WithDefaultMTLSEndpoint(mtlsBasePath))
101 opts = append(opts, internaloption.EnableNewAuthLibrary())
102 client, endpoint, err := htransport.NewClient(ctx, opts...)
103 if err != nil {
104 return nil, err
105 }
106 s, err := New(client)
107 if err != nil {
108 return nil, err
109 }
110 if endpoint != "" {
111 s.BasePath = endpoint
112 }
113 return s, nil
114 }
115
116
117
118
119
120
121 func New(client *http.Client) (*Service, error) {
122 if client == nil {
123 return nil, errors.New("client is nil")
124 }
125 s := &Service{client: client, BasePath: basePath}
126 s.Entities = NewEntitiesService(s)
127 return s, nil
128 }
129
130 type Service struct {
131 client *http.Client
132 BasePath string
133 UserAgent string
134
135 Entities *EntitiesService
136 }
137
138 func (s *Service) userAgent() string {
139 if s.UserAgent == "" {
140 return googleapi.UserAgent
141 }
142 return googleapi.UserAgent + " " + s.UserAgent
143 }
144
145 func NewEntitiesService(s *Service) *EntitiesService {
146 rs := &EntitiesService{s: s}
147 return rs
148 }
149
150 type EntitiesService struct {
151 s *Service
152 }
153
154
155
156 type SearchResponse struct {
157
158 ItemListElement []interface{} `json:"itemListElement,omitempty"`
159
160
161 googleapi.ServerResponse `json:"-"`
162
163
164
165
166
167 ForceSendFields []string `json:"-"`
168
169
170
171
172 NullFields []string `json:"-"`
173 }
174
175 func (s *SearchResponse) MarshalJSON() ([]byte, error) {
176 type NoMethod SearchResponse
177 return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields)
178 }
179
180 type EntitiesSearchCall struct {
181 s *Service
182 urlParams_ gensupport.URLParams
183 ifNoneMatch_ string
184 ctx_ context.Context
185 header_ http.Header
186 }
187
188
189
190
191 func (r *EntitiesService) Search() *EntitiesSearchCall {
192 c := &EntitiesSearchCall{s: r.s, urlParams_: make(gensupport.URLParams)}
193 return c
194 }
195
196
197
198
199 func (c *EntitiesSearchCall) Ids(ids ...string) *EntitiesSearchCall {
200 c.urlParams_.SetMulti("ids", append([]string{}, ids...))
201 return c
202 }
203
204
205
206 func (c *EntitiesSearchCall) Indent(indent bool) *EntitiesSearchCall {
207 c.urlParams_.Set("indent", fmt.Sprint(indent))
208 return c
209 }
210
211
212
213 func (c *EntitiesSearchCall) Languages(languages ...string) *EntitiesSearchCall {
214 c.urlParams_.SetMulti("languages", append([]string{}, languages...))
215 return c
216 }
217
218
219
220 func (c *EntitiesSearchCall) Limit(limit int64) *EntitiesSearchCall {
221 c.urlParams_.Set("limit", fmt.Sprint(limit))
222 return c
223 }
224
225
226
227 func (c *EntitiesSearchCall) Prefix(prefix bool) *EntitiesSearchCall {
228 c.urlParams_.Set("prefix", fmt.Sprint(prefix))
229 return c
230 }
231
232
233
234 func (c *EntitiesSearchCall) Query(query string) *EntitiesSearchCall {
235 c.urlParams_.Set("query", query)
236 return c
237 }
238
239
240
241
242
243 func (c *EntitiesSearchCall) Types(types ...string) *EntitiesSearchCall {
244 c.urlParams_.SetMulti("types", append([]string{}, types...))
245 return c
246 }
247
248
249
250
251 func (c *EntitiesSearchCall) Fields(s ...googleapi.Field) *EntitiesSearchCall {
252 c.urlParams_.Set("fields", googleapi.CombineFields(s))
253 return c
254 }
255
256
257
258
259 func (c *EntitiesSearchCall) IfNoneMatch(entityTag string) *EntitiesSearchCall {
260 c.ifNoneMatch_ = entityTag
261 return c
262 }
263
264
265 func (c *EntitiesSearchCall) Context(ctx context.Context) *EntitiesSearchCall {
266 c.ctx_ = ctx
267 return c
268 }
269
270
271
272 func (c *EntitiesSearchCall) Header() http.Header {
273 if c.header_ == nil {
274 c.header_ = make(http.Header)
275 }
276 return c.header_
277 }
278
279 func (c *EntitiesSearchCall) doRequest(alt string) (*http.Response, error) {
280 reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "", c.header_)
281 if c.ifNoneMatch_ != "" {
282 reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
283 }
284 var body io.Reader = nil
285 c.urlParams_.Set("alt", alt)
286 c.urlParams_.Set("prettyPrint", "false")
287 urls := googleapi.ResolveRelative(c.s.BasePath, "v1/entities:search")
288 urls += "?" + c.urlParams_.Encode()
289 req, err := http.NewRequest("GET", urls, body)
290 if err != nil {
291 return nil, err
292 }
293 req.Header = reqHeaders
294 return gensupport.SendRequest(c.ctx_, c.s.client, req)
295 }
296
297
298
299
300
301
302 func (c *EntitiesSearchCall) Do(opts ...googleapi.CallOption) (*SearchResponse, error) {
303 gensupport.SetOptions(c.urlParams_, opts...)
304 res, err := c.doRequest("json")
305 if res != nil && res.StatusCode == http.StatusNotModified {
306 if res.Body != nil {
307 res.Body.Close()
308 }
309 return nil, gensupport.WrapError(&googleapi.Error{
310 Code: res.StatusCode,
311 Header: res.Header,
312 })
313 }
314 if err != nil {
315 return nil, err
316 }
317 defer googleapi.CloseBody(res)
318 if err := googleapi.CheckResponse(res); err != nil {
319 return nil, gensupport.WrapError(err)
320 }
321 ret := &SearchResponse{
322 ServerResponse: googleapi.ServerResponse{
323 Header: res.Header,
324 HTTPStatusCode: res.StatusCode,
325 },
326 }
327 target := &ret
328 if err := gensupport.DecodeResponse(target, res); err != nil {
329 return nil, err
330 }
331 return ret, nil
332 }
333
View as plain text