Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

318 lignes
9.6 KiB

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