Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 

391 rader
12 KiB

  1. // Copyright 2019 Google LLC.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // Code generated file. DO NOT EDIT.
  5. // Package kgsearch provides access to the Knowledge Graph Search API.
  6. //
  7. // For product documentation, see: https://developers.google.com/knowledge-graph/
  8. //
  9. // Creating a client
  10. //
  11. // Usage example:
  12. //
  13. // import "google.golang.org/api/kgsearch/v1"
  14. // ...
  15. // ctx := context.Background()
  16. // kgsearchService, err := kgsearch.NewService(ctx)
  17. //
  18. // In this example, Google Application Default Credentials are used for authentication.
  19. //
  20. // For information on how to create and obtain Application Default Credentials, see https://developers.google.com/identity/protocols/application-default-credentials.
  21. //
  22. // Other authentication options
  23. //
  24. // To use an API key for authentication (note: some APIs do not support API keys), use option.WithAPIKey:
  25. //
  26. // kgsearchService, err := kgsearch.NewService(ctx, option.WithAPIKey("AIza..."))
  27. //
  28. // To use an OAuth token (e.g., a user token obtained via a three-legged OAuth flow), use option.WithTokenSource:
  29. //
  30. // config := &oauth2.Config{...}
  31. // // ...
  32. // token, err := config.Exchange(ctx, ...)
  33. // kgsearchService, err := kgsearch.NewService(ctx, option.WithTokenSource(config.TokenSource(ctx, token)))
  34. //
  35. // See https://godoc.org/google.golang.org/api/option/ for details on options.
  36. package kgsearch // import "google.golang.org/api/kgsearch/v1"
  37. import (
  38. "bytes"
  39. "context"
  40. "encoding/json"
  41. "errors"
  42. "fmt"
  43. "io"
  44. "net/http"
  45. "net/url"
  46. "strconv"
  47. "strings"
  48. gensupport "google.golang.org/api/gensupport"
  49. googleapi "google.golang.org/api/googleapi"
  50. option "google.golang.org/api/option"
  51. htransport "google.golang.org/api/transport/http"
  52. )
  53. // Always reference these packages, just in case the auto-generated code
  54. // below doesn't.
  55. var _ = bytes.NewBuffer
  56. var _ = strconv.Itoa
  57. var _ = fmt.Sprintf
  58. var _ = json.NewDecoder
  59. var _ = io.Copy
  60. var _ = url.Parse
  61. var _ = gensupport.MarshalJSON
  62. var _ = googleapi.Version
  63. var _ = errors.New
  64. var _ = strings.Replace
  65. var _ = context.Canceled
  66. const apiId = "kgsearch:v1"
  67. const apiName = "kgsearch"
  68. const apiVersion = "v1"
  69. const basePath = "https://kgsearch.googleapis.com/"
  70. // NewService creates a new Service.
  71. func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, error) {
  72. client, endpoint, err := htransport.NewClient(ctx, opts...)
  73. if err != nil {
  74. return nil, err
  75. }
  76. s, err := New(client)
  77. if err != nil {
  78. return nil, err
  79. }
  80. if endpoint != "" {
  81. s.BasePath = endpoint
  82. }
  83. return s, nil
  84. }
  85. // New creates a new Service. It uses the provided http.Client for requests.
  86. //
  87. // Deprecated: please use NewService instead.
  88. // To provide a custom HTTP client, use option.WithHTTPClient.
  89. // If you are using google.golang.org/api/googleapis/transport.APIKey, use option.WithAPIKey with NewService instead.
  90. func New(client *http.Client) (*Service, error) {
  91. if client == nil {
  92. return nil, errors.New("client is nil")
  93. }
  94. s := &Service{client: client, BasePath: basePath}
  95. s.Entities = NewEntitiesService(s)
  96. return s, nil
  97. }
  98. type Service struct {
  99. client *http.Client
  100. BasePath string // API endpoint base URL
  101. UserAgent string // optional additional User-Agent fragment
  102. Entities *EntitiesService
  103. }
  104. func (s *Service) userAgent() string {
  105. if s.UserAgent == "" {
  106. return googleapi.UserAgent
  107. }
  108. return googleapi.UserAgent + " " + s.UserAgent
  109. }
  110. func NewEntitiesService(s *Service) *EntitiesService {
  111. rs := &EntitiesService{s: s}
  112. return rs
  113. }
  114. type EntitiesService struct {
  115. s *Service
  116. }
  117. // SearchResponse: Response message includes the context and a list of
  118. // matching results
  119. // which contain the detail of associated entities.
  120. type SearchResponse struct {
  121. // ItemListElement: The item list of search results.
  122. ItemListElement []interface{} `json:"itemListElement,omitempty"`
  123. // ServerResponse contains the HTTP response code and headers from the
  124. // server.
  125. googleapi.ServerResponse `json:"-"`
  126. // ForceSendFields is a list of field names (e.g. "ItemListElement") to
  127. // unconditionally include in API requests. By default, fields with
  128. // empty values are omitted from API requests. However, any non-pointer,
  129. // non-interface field appearing in ForceSendFields will be sent to the
  130. // server regardless of whether the field is empty or not. This may be
  131. // used to include empty fields in Patch requests.
  132. ForceSendFields []string `json:"-"`
  133. // NullFields is a list of field names (e.g. "ItemListElement") to
  134. // include in API requests with the JSON null value. By default, fields
  135. // with empty values are omitted from API requests. However, any field
  136. // with an empty value appearing in NullFields will be sent to the
  137. // server as null. It is an error if a field in this list has a
  138. // non-empty value. This may be used to include null fields in Patch
  139. // requests.
  140. NullFields []string `json:"-"`
  141. }
  142. func (s *SearchResponse) MarshalJSON() ([]byte, error) {
  143. type NoMethod SearchResponse
  144. raw := NoMethod(*s)
  145. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  146. }
  147. // method id "kgsearch.entities.search":
  148. type EntitiesSearchCall struct {
  149. s *Service
  150. urlParams_ gensupport.URLParams
  151. ifNoneMatch_ string
  152. ctx_ context.Context
  153. header_ http.Header
  154. }
  155. // Search: Searches Knowledge Graph for entities that match the
  156. // constraints.
  157. // A list of matched entities will be returned in response, which will
  158. // be in
  159. // JSON-LD format and compatible with http://schema.org
  160. func (r *EntitiesService) Search() *EntitiesSearchCall {
  161. c := &EntitiesSearchCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  162. return c
  163. }
  164. // Ids sets the optional parameter "ids": The list of entity id to be
  165. // used for search instead of query string.
  166. // To specify multiple ids in the HTTP request, repeat the parameter in
  167. // the
  168. // URL as in ...?ids=A&ids=B
  169. func (c *EntitiesSearchCall) Ids(ids ...string) *EntitiesSearchCall {
  170. c.urlParams_.SetMulti("ids", append([]string{}, ids...))
  171. return c
  172. }
  173. // Indent sets the optional parameter "indent": Enables indenting of
  174. // json results.
  175. func (c *EntitiesSearchCall) Indent(indent bool) *EntitiesSearchCall {
  176. c.urlParams_.Set("indent", fmt.Sprint(indent))
  177. return c
  178. }
  179. // Languages sets the optional parameter "languages": The list of
  180. // language codes (defined in ISO 693) to run the query with,
  181. // e.g. 'en'.
  182. func (c *EntitiesSearchCall) Languages(languages ...string) *EntitiesSearchCall {
  183. c.urlParams_.SetMulti("languages", append([]string{}, languages...))
  184. return c
  185. }
  186. // Limit sets the optional parameter "limit": Limits the number of
  187. // entities to be returned.
  188. func (c *EntitiesSearchCall) Limit(limit int64) *EntitiesSearchCall {
  189. c.urlParams_.Set("limit", fmt.Sprint(limit))
  190. return c
  191. }
  192. // Prefix sets the optional parameter "prefix": Enables prefix match
  193. // against names and aliases of entities
  194. func (c *EntitiesSearchCall) Prefix(prefix bool) *EntitiesSearchCall {
  195. c.urlParams_.Set("prefix", fmt.Sprint(prefix))
  196. return c
  197. }
  198. // Query sets the optional parameter "query": The literal query string
  199. // for search.
  200. func (c *EntitiesSearchCall) Query(query string) *EntitiesSearchCall {
  201. c.urlParams_.Set("query", query)
  202. return c
  203. }
  204. // Types sets the optional parameter "types": Restricts returned
  205. // entities with these types, e.g. Person
  206. // (as defined in http://schema.org/Person). If multiple types are
  207. // specified,
  208. // returned entities will contain one or more of these types.
  209. func (c *EntitiesSearchCall) Types(types ...string) *EntitiesSearchCall {
  210. c.urlParams_.SetMulti("types", append([]string{}, types...))
  211. return c
  212. }
  213. // Fields allows partial responses to be retrieved. See
  214. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  215. // for more information.
  216. func (c *EntitiesSearchCall) Fields(s ...googleapi.Field) *EntitiesSearchCall {
  217. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  218. return c
  219. }
  220. // IfNoneMatch sets the optional parameter which makes the operation
  221. // fail if the object's ETag matches the given value. This is useful for
  222. // getting updates only after the object has changed since the last
  223. // request. Use googleapi.IsNotModified to check whether the response
  224. // error from Do is the result of In-None-Match.
  225. func (c *EntitiesSearchCall) IfNoneMatch(entityTag string) *EntitiesSearchCall {
  226. c.ifNoneMatch_ = entityTag
  227. return c
  228. }
  229. // Context sets the context to be used in this call's Do method. Any
  230. // pending HTTP request will be aborted if the provided context is
  231. // canceled.
  232. func (c *EntitiesSearchCall) Context(ctx context.Context) *EntitiesSearchCall {
  233. c.ctx_ = ctx
  234. return c
  235. }
  236. // Header returns an http.Header that can be modified by the caller to
  237. // add HTTP headers to the request.
  238. func (c *EntitiesSearchCall) Header() http.Header {
  239. if c.header_ == nil {
  240. c.header_ = make(http.Header)
  241. }
  242. return c.header_
  243. }
  244. func (c *EntitiesSearchCall) doRequest(alt string) (*http.Response, error) {
  245. reqHeaders := make(http.Header)
  246. for k, v := range c.header_ {
  247. reqHeaders[k] = v
  248. }
  249. reqHeaders.Set("User-Agent", c.s.userAgent())
  250. if c.ifNoneMatch_ != "" {
  251. reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
  252. }
  253. var body io.Reader = nil
  254. c.urlParams_.Set("alt", alt)
  255. c.urlParams_.Set("prettyPrint", "false")
  256. urls := googleapi.ResolveRelative(c.s.BasePath, "v1/entities:search")
  257. urls += "?" + c.urlParams_.Encode()
  258. req, err := http.NewRequest("GET", urls, body)
  259. if err != nil {
  260. return nil, err
  261. }
  262. req.Header = reqHeaders
  263. return gensupport.SendRequest(c.ctx_, c.s.client, req)
  264. }
  265. // Do executes the "kgsearch.entities.search" call.
  266. // Exactly one of *SearchResponse or error will be non-nil. Any non-2xx
  267. // status code is an error. Response headers are in either
  268. // *SearchResponse.ServerResponse.Header or (if a response was returned
  269. // at all) in error.(*googleapi.Error).Header. Use
  270. // googleapi.IsNotModified to check whether the returned error was
  271. // because http.StatusNotModified was returned.
  272. func (c *EntitiesSearchCall) Do(opts ...googleapi.CallOption) (*SearchResponse, error) {
  273. gensupport.SetOptions(c.urlParams_, opts...)
  274. res, err := c.doRequest("json")
  275. if res != nil && res.StatusCode == http.StatusNotModified {
  276. if res.Body != nil {
  277. res.Body.Close()
  278. }
  279. return nil, &googleapi.Error{
  280. Code: res.StatusCode,
  281. Header: res.Header,
  282. }
  283. }
  284. if err != nil {
  285. return nil, err
  286. }
  287. defer googleapi.CloseBody(res)
  288. if err := googleapi.CheckResponse(res); err != nil {
  289. return nil, err
  290. }
  291. ret := &SearchResponse{
  292. ServerResponse: googleapi.ServerResponse{
  293. Header: res.Header,
  294. HTTPStatusCode: res.StatusCode,
  295. },
  296. }
  297. target := &ret
  298. if err := gensupport.DecodeResponse(target, res); err != nil {
  299. return nil, err
  300. }
  301. return ret, nil
  302. // {
  303. // "description": "Searches Knowledge Graph for entities that match the constraints.\nA list of matched entities will be returned in response, which will be in\nJSON-LD format and compatible with http://schema.org",
  304. // "flatPath": "v1/entities:search",
  305. // "httpMethod": "GET",
  306. // "id": "kgsearch.entities.search",
  307. // "parameterOrder": [],
  308. // "parameters": {
  309. // "ids": {
  310. // "description": "The list of entity id to be used for search instead of query string.\nTo specify multiple ids in the HTTP request, repeat the parameter in the\nURL as in ...?ids=A\u0026ids=B",
  311. // "location": "query",
  312. // "repeated": true,
  313. // "type": "string"
  314. // },
  315. // "indent": {
  316. // "description": "Enables indenting of json results.",
  317. // "location": "query",
  318. // "type": "boolean"
  319. // },
  320. // "languages": {
  321. // "description": "The list of language codes (defined in ISO 693) to run the query with,\ne.g. 'en'.",
  322. // "location": "query",
  323. // "repeated": true,
  324. // "type": "string"
  325. // },
  326. // "limit": {
  327. // "description": "Limits the number of entities to be returned.",
  328. // "format": "int32",
  329. // "location": "query",
  330. // "type": "integer"
  331. // },
  332. // "prefix": {
  333. // "description": "Enables prefix match against names and aliases of entities",
  334. // "location": "query",
  335. // "type": "boolean"
  336. // },
  337. // "query": {
  338. // "description": "The literal query string for search.",
  339. // "location": "query",
  340. // "type": "string"
  341. // },
  342. // "types": {
  343. // "description": "Restricts returned entities with these types, e.g. Person\n(as defined in http://schema.org/Person). If multiple types are specified,\nreturned entities will contain one or more of these types.",
  344. // "location": "query",
  345. // "repeated": true,
  346. // "type": "string"
  347. // }
  348. // },
  349. // "path": "v1/entities:search",
  350. // "response": {
  351. // "$ref": "SearchResponse"
  352. // }
  353. // }
  354. }