webfonts-gen.go 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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. }
  98. func (s *Webfont) MarshalJSON() ([]byte, error) {
  99. type noMethod Webfont
  100. raw := noMethod(*s)
  101. return gensupport.MarshalJSON(raw, s.ForceSendFields)
  102. }
  103. type WebfontList struct {
  104. // Items: The list of fonts currently served by the Google Fonts API.
  105. Items []*Webfont `json:"items,omitempty"`
  106. // Kind: This kind represents a list of webfont objects in the webfonts
  107. // service.
  108. Kind string `json:"kind,omitempty"`
  109. // ServerResponse contains the HTTP response code and headers from the
  110. // server.
  111. googleapi.ServerResponse `json:"-"`
  112. // ForceSendFields is a list of field names (e.g. "Items") to
  113. // unconditionally include in API requests. By default, fields with
  114. // empty values are omitted from API requests. However, any non-pointer,
  115. // non-interface field appearing in ForceSendFields will be sent to the
  116. // server regardless of whether the field is empty or not. This may be
  117. // used to include empty fields in Patch requests.
  118. ForceSendFields []string `json:"-"`
  119. }
  120. func (s *WebfontList) MarshalJSON() ([]byte, error) {
  121. type noMethod WebfontList
  122. raw := noMethod(*s)
  123. return gensupport.MarshalJSON(raw, s.ForceSendFields)
  124. }
  125. // method id "webfonts.webfonts.list":
  126. type WebfontsListCall struct {
  127. s *Service
  128. urlParams_ gensupport.URLParams
  129. ifNoneMatch_ string
  130. ctx_ context.Context
  131. }
  132. // List: Retrieves the list of fonts currently served by the Google
  133. // Fonts Developer API
  134. func (r *WebfontsService) List() *WebfontsListCall {
  135. c := &WebfontsListCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  136. return c
  137. }
  138. // Sort sets the optional parameter "sort": Enables sorting of the list
  139. //
  140. // Possible values:
  141. // "alpha" - Sort alphabetically
  142. // "date" - Sort by date added
  143. // "popularity" - Sort by popularity
  144. // "style" - Sort by number of styles
  145. // "trending" - Sort by trending
  146. func (c *WebfontsListCall) Sort(sort string) *WebfontsListCall {
  147. c.urlParams_.Set("sort", sort)
  148. return c
  149. }
  150. // Fields allows partial responses to be retrieved. See
  151. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  152. // for more information.
  153. func (c *WebfontsListCall) Fields(s ...googleapi.Field) *WebfontsListCall {
  154. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  155. return c
  156. }
  157. // IfNoneMatch sets the optional parameter which makes the operation
  158. // fail if the object's ETag matches the given value. This is useful for
  159. // getting updates only after the object has changed since the last
  160. // request. Use googleapi.IsNotModified to check whether the response
  161. // error from Do is the result of In-None-Match.
  162. func (c *WebfontsListCall) IfNoneMatch(entityTag string) *WebfontsListCall {
  163. c.ifNoneMatch_ = entityTag
  164. return c
  165. }
  166. // Context sets the context to be used in this call's Do method. Any
  167. // pending HTTP request will be aborted if the provided context is
  168. // canceled.
  169. func (c *WebfontsListCall) Context(ctx context.Context) *WebfontsListCall {
  170. c.ctx_ = ctx
  171. return c
  172. }
  173. func (c *WebfontsListCall) doRequest(alt string) (*http.Response, error) {
  174. var body io.Reader = nil
  175. c.urlParams_.Set("alt", alt)
  176. urls := googleapi.ResolveRelative(c.s.BasePath, "webfonts")
  177. urls += "?" + c.urlParams_.Encode()
  178. req, _ := http.NewRequest("GET", urls, body)
  179. googleapi.SetOpaque(req.URL)
  180. req.Header.Set("User-Agent", c.s.userAgent())
  181. if c.ifNoneMatch_ != "" {
  182. req.Header.Set("If-None-Match", c.ifNoneMatch_)
  183. }
  184. if c.ctx_ != nil {
  185. return ctxhttp.Do(c.ctx_, c.s.client, req)
  186. }
  187. return c.s.client.Do(req)
  188. }
  189. // Do executes the "webfonts.webfonts.list" call.
  190. // Exactly one of *WebfontList or error will be non-nil. Any non-2xx
  191. // status code is an error. Response headers are in either
  192. // *WebfontList.ServerResponse.Header or (if a response was returned at
  193. // all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified
  194. // to check whether the returned error was because
  195. // http.StatusNotModified was returned.
  196. func (c *WebfontsListCall) Do(opts ...googleapi.CallOption) (*WebfontList, error) {
  197. gensupport.SetOptions(c.urlParams_, opts...)
  198. res, err := c.doRequest("json")
  199. if res != nil && res.StatusCode == http.StatusNotModified {
  200. if res.Body != nil {
  201. res.Body.Close()
  202. }
  203. return nil, &googleapi.Error{
  204. Code: res.StatusCode,
  205. Header: res.Header,
  206. }
  207. }
  208. if err != nil {
  209. return nil, err
  210. }
  211. defer googleapi.CloseBody(res)
  212. if err := googleapi.CheckResponse(res); err != nil {
  213. return nil, err
  214. }
  215. ret := &WebfontList{
  216. ServerResponse: googleapi.ServerResponse{
  217. Header: res.Header,
  218. HTTPStatusCode: res.StatusCode,
  219. },
  220. }
  221. if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
  222. return nil, err
  223. }
  224. return ret, nil
  225. // {
  226. // "description": "Retrieves the list of fonts currently served by the Google Fonts Developer API",
  227. // "httpMethod": "GET",
  228. // "id": "webfonts.webfonts.list",
  229. // "parameters": {
  230. // "sort": {
  231. // "description": "Enables sorting of the list",
  232. // "enum": [
  233. // "alpha",
  234. // "date",
  235. // "popularity",
  236. // "style",
  237. // "trending"
  238. // ],
  239. // "enumDescriptions": [
  240. // "Sort alphabetically",
  241. // "Sort by date added",
  242. // "Sort by popularity",
  243. // "Sort by number of styles",
  244. // "Sort by trending"
  245. // ],
  246. // "location": "query",
  247. // "type": "string"
  248. // }
  249. // },
  250. // "path": "webfonts",
  251. // "response": {
  252. // "$ref": "WebfontList"
  253. // }
  254. // }
  255. }