Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 

337 строки
11 KiB

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