You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

372 line
11 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 webfonts provides access to the Google Fonts Developer API.
  6. //
  7. // For product documentation, see: https://developers.google.com/fonts/docs/developer_api
  8. //
  9. // Creating a client
  10. //
  11. // Usage example:
  12. //
  13. // import "google.golang.org/api/webfonts/v1"
  14. // ...
  15. // ctx := context.Background()
  16. // webfontsService, err := webfonts.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. // webfontsService, err := webfonts.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. // webfontsService, err := webfonts.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 webfonts // import "google.golang.org/api/webfonts/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 = "webfonts:v1"
  67. const apiName = "webfonts"
  68. const apiVersion = "v1"
  69. const basePath = "https://www.googleapis.com/webfonts/v1/"
  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.Webfonts = NewWebfontsService(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. Webfonts *WebfontsService
  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 NewWebfontsService(s *Service) *WebfontsService {
  111. rs := &WebfontsService{s: s}
  112. return rs
  113. }
  114. type WebfontsService struct {
  115. s *Service
  116. }
  117. type Webfont struct {
  118. // Category: The category of the font.
  119. Category string `json:"category,omitempty"`
  120. // Family: The name of the font.
  121. Family string `json:"family,omitempty"`
  122. // Files: The font files (with all supported scripts) for each one of
  123. // the available variants, as a key : value map.
  124. Files map[string]string `json:"files,omitempty"`
  125. // Kind: This kind represents a webfont object in the webfonts service.
  126. Kind string `json:"kind,omitempty"`
  127. // LastModified: The date (format "yyyy-MM-dd") the font was modified
  128. // for the last time.
  129. LastModified string `json:"lastModified,omitempty"`
  130. // Subsets: The scripts supported by the font.
  131. Subsets []string `json:"subsets,omitempty"`
  132. // Variants: The available variants for the font.
  133. Variants []string `json:"variants,omitempty"`
  134. // Version: The font version.
  135. Version string `json:"version,omitempty"`
  136. // ForceSendFields is a list of field names (e.g. "Category") to
  137. // unconditionally include in API requests. By default, fields with
  138. // empty values are omitted from API requests. However, any non-pointer,
  139. // non-interface field appearing in ForceSendFields will be sent to the
  140. // server regardless of whether the field is empty or not. This may be
  141. // used to include empty fields in Patch requests.
  142. ForceSendFields []string `json:"-"`
  143. // NullFields is a list of field names (e.g. "Category") to include in
  144. // API requests with the JSON null value. By default, fields with empty
  145. // values are omitted from API requests. However, any field with an
  146. // empty value appearing in NullFields will be sent to the server as
  147. // null. It is an error if a field in this list has a non-empty value.
  148. // This may be used to include null fields in Patch requests.
  149. NullFields []string `json:"-"`
  150. }
  151. func (s *Webfont) MarshalJSON() ([]byte, error) {
  152. type NoMethod Webfont
  153. raw := NoMethod(*s)
  154. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  155. }
  156. type WebfontList struct {
  157. // Items: The list of fonts currently served by the Google Fonts API.
  158. Items []*Webfont `json:"items,omitempty"`
  159. // Kind: This kind represents a list of webfont objects in the webfonts
  160. // service.
  161. Kind string `json:"kind,omitempty"`
  162. // ServerResponse contains the HTTP response code and headers from the
  163. // server.
  164. googleapi.ServerResponse `json:"-"`
  165. // ForceSendFields is a list of field names (e.g. "Items") to
  166. // unconditionally include in API requests. By default, fields with
  167. // empty values are omitted from API requests. However, any non-pointer,
  168. // non-interface field appearing in ForceSendFields will be sent to the
  169. // server regardless of whether the field is empty or not. This may be
  170. // used to include empty fields in Patch requests.
  171. ForceSendFields []string `json:"-"`
  172. // NullFields is a list of field names (e.g. "Items") to include in API
  173. // requests with the JSON null value. By default, fields with empty
  174. // values are omitted from API requests. However, any field with an
  175. // empty value appearing in NullFields will be sent to the server as
  176. // null. It is an error if a field in this list has a non-empty value.
  177. // This may be used to include null fields in Patch requests.
  178. NullFields []string `json:"-"`
  179. }
  180. func (s *WebfontList) MarshalJSON() ([]byte, error) {
  181. type NoMethod WebfontList
  182. raw := NoMethod(*s)
  183. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  184. }
  185. // method id "webfonts.webfonts.list":
  186. type WebfontsListCall struct {
  187. s *Service
  188. urlParams_ gensupport.URLParams
  189. ifNoneMatch_ string
  190. ctx_ context.Context
  191. header_ http.Header
  192. }
  193. // List: Retrieves the list of fonts currently served by the Google
  194. // Fonts Developer API
  195. func (r *WebfontsService) List() *WebfontsListCall {
  196. c := &WebfontsListCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  197. return c
  198. }
  199. // Sort sets the optional parameter "sort": Enables sorting of the list
  200. //
  201. // Possible values:
  202. // "alpha" - Sort alphabetically
  203. // "date" - Sort by date added
  204. // "popularity" - Sort by popularity
  205. // "style" - Sort by number of styles
  206. // "trending" - Sort by trending
  207. func (c *WebfontsListCall) Sort(sort string) *WebfontsListCall {
  208. c.urlParams_.Set("sort", sort)
  209. return c
  210. }
  211. // Fields allows partial responses to be retrieved. See
  212. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  213. // for more information.
  214. func (c *WebfontsListCall) Fields(s ...googleapi.Field) *WebfontsListCall {
  215. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  216. return c
  217. }
  218. // IfNoneMatch sets the optional parameter which makes the operation
  219. // fail if the object's ETag matches the given value. This is useful for
  220. // getting updates only after the object has changed since the last
  221. // request. Use googleapi.IsNotModified to check whether the response
  222. // error from Do is the result of In-None-Match.
  223. func (c *WebfontsListCall) IfNoneMatch(entityTag string) *WebfontsListCall {
  224. c.ifNoneMatch_ = entityTag
  225. return c
  226. }
  227. // Context sets the context to be used in this call's Do method. Any
  228. // pending HTTP request will be aborted if the provided context is
  229. // canceled.
  230. func (c *WebfontsListCall) Context(ctx context.Context) *WebfontsListCall {
  231. c.ctx_ = ctx
  232. return c
  233. }
  234. // Header returns an http.Header that can be modified by the caller to
  235. // add HTTP headers to the request.
  236. func (c *WebfontsListCall) Header() http.Header {
  237. if c.header_ == nil {
  238. c.header_ = make(http.Header)
  239. }
  240. return c.header_
  241. }
  242. func (c *WebfontsListCall) doRequest(alt string) (*http.Response, error) {
  243. reqHeaders := make(http.Header)
  244. for k, v := range c.header_ {
  245. reqHeaders[k] = v
  246. }
  247. reqHeaders.Set("User-Agent", c.s.userAgent())
  248. if c.ifNoneMatch_ != "" {
  249. reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
  250. }
  251. var body io.Reader = nil
  252. c.urlParams_.Set("alt", alt)
  253. c.urlParams_.Set("prettyPrint", "false")
  254. urls := googleapi.ResolveRelative(c.s.BasePath, "webfonts")
  255. urls += "?" + c.urlParams_.Encode()
  256. req, err := http.NewRequest("GET", urls, body)
  257. if err != nil {
  258. return nil, err
  259. }
  260. req.Header = reqHeaders
  261. return gensupport.SendRequest(c.ctx_, c.s.client, req)
  262. }
  263. // Do executes the "webfonts.webfonts.list" call.
  264. // Exactly one of *WebfontList or error will be non-nil. Any non-2xx
  265. // status code is an error. Response headers are in either
  266. // *WebfontList.ServerResponse.Header or (if a response was returned at
  267. // all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified
  268. // to check whether the returned error was because
  269. // http.StatusNotModified was returned.
  270. func (c *WebfontsListCall) Do(opts ...googleapi.CallOption) (*WebfontList, error) {
  271. gensupport.SetOptions(c.urlParams_, opts...)
  272. res, err := c.doRequest("json")
  273. if res != nil && res.StatusCode == http.StatusNotModified {
  274. if res.Body != nil {
  275. res.Body.Close()
  276. }
  277. return nil, &googleapi.Error{
  278. Code: res.StatusCode,
  279. Header: res.Header,
  280. }
  281. }
  282. if err != nil {
  283. return nil, err
  284. }
  285. defer googleapi.CloseBody(res)
  286. if err := googleapi.CheckResponse(res); err != nil {
  287. return nil, err
  288. }
  289. ret := &WebfontList{
  290. ServerResponse: googleapi.ServerResponse{
  291. Header: res.Header,
  292. HTTPStatusCode: res.StatusCode,
  293. },
  294. }
  295. target := &ret
  296. if err := gensupport.DecodeResponse(target, res); err != nil {
  297. return nil, err
  298. }
  299. return ret, nil
  300. // {
  301. // "description": "Retrieves the list of fonts currently served by the Google Fonts Developer API",
  302. // "httpMethod": "GET",
  303. // "id": "webfonts.webfonts.list",
  304. // "parameters": {
  305. // "sort": {
  306. // "description": "Enables sorting of the list",
  307. // "enum": [
  308. // "alpha",
  309. // "date",
  310. // "popularity",
  311. // "style",
  312. // "trending"
  313. // ],
  314. // "enumDescriptions": [
  315. // "Sort alphabetically",
  316. // "Sort by date added",
  317. // "Sort by popularity",
  318. // "Sort by number of styles",
  319. // "Sort by trending"
  320. // ],
  321. // "location": "query",
  322. // "type": "string"
  323. // }
  324. // },
  325. // "path": "webfonts",
  326. // "response": {
  327. // "$ref": "WebfontList"
  328. // }
  329. // }
  330. }