1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 package webfonts
52
53 import (
54 "bytes"
55 "context"
56 "encoding/json"
57 "errors"
58 "fmt"
59 "io"
60 "net/http"
61 "net/url"
62 "strconv"
63 "strings"
64
65 googleapi "google.golang.org/api/googleapi"
66 internal "google.golang.org/api/internal"
67 gensupport "google.golang.org/api/internal/gensupport"
68 option "google.golang.org/api/option"
69 internaloption "google.golang.org/api/option/internaloption"
70 htransport "google.golang.org/api/transport/http"
71 )
72
73
74
75 var _ = bytes.NewBuffer
76 var _ = strconv.Itoa
77 var _ = fmt.Sprintf
78 var _ = json.NewDecoder
79 var _ = io.Copy
80 var _ = url.Parse
81 var _ = gensupport.MarshalJSON
82 var _ = googleapi.Version
83 var _ = errors.New
84 var _ = strings.Replace
85 var _ = context.Canceled
86 var _ = internaloption.WithDefaultEndpoint
87 var _ = internal.Version
88
89 const apiId = "webfonts:v1"
90 const apiName = "webfonts"
91 const apiVersion = "v1"
92 const basePath = "https://webfonts.googleapis.com/"
93 const basePathTemplate = "https://webfonts.UNIVERSE_DOMAIN/"
94 const mtlsBasePath = "https://webfonts.mtls.googleapis.com/"
95
96
97 func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, error) {
98 opts = append(opts, internaloption.WithDefaultEndpoint(basePath))
99 opts = append(opts, internaloption.WithDefaultEndpointTemplate(basePathTemplate))
100 opts = append(opts, internaloption.WithDefaultMTLSEndpoint(mtlsBasePath))
101 opts = append(opts, internaloption.EnableNewAuthLibrary())
102 client, endpoint, err := htransport.NewClient(ctx, opts...)
103 if err != nil {
104 return nil, err
105 }
106 s, err := New(client)
107 if err != nil {
108 return nil, err
109 }
110 if endpoint != "" {
111 s.BasePath = endpoint
112 }
113 return s, nil
114 }
115
116
117
118
119
120
121 func New(client *http.Client) (*Service, error) {
122 if client == nil {
123 return nil, errors.New("client is nil")
124 }
125 s := &Service{client: client, BasePath: basePath}
126 s.Webfonts = NewWebfontsService(s)
127 return s, nil
128 }
129
130 type Service struct {
131 client *http.Client
132 BasePath string
133 UserAgent string
134
135 Webfonts *WebfontsService
136 }
137
138 func (s *Service) userAgent() string {
139 if s.UserAgent == "" {
140 return googleapi.UserAgent
141 }
142 return googleapi.UserAgent + " " + s.UserAgent
143 }
144
145 func NewWebfontsService(s *Service) *WebfontsService {
146 rs := &WebfontsService{s: s}
147 return rs
148 }
149
150 type WebfontsService struct {
151 s *Service
152 }
153
154
155 type Axis struct {
156
157 End float64 `json:"end,omitempty"`
158
159 Start float64 `json:"start,omitempty"`
160
161 Tag string `json:"tag,omitempty"`
162
163
164
165
166
167 ForceSendFields []string `json:"-"`
168
169
170
171
172 NullFields []string `json:"-"`
173 }
174
175 func (s *Axis) MarshalJSON() ([]byte, error) {
176 type NoMethod Axis
177 return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields)
178 }
179
180 func (s *Axis) UnmarshalJSON(data []byte) error {
181 type NoMethod Axis
182 var s1 struct {
183 End gensupport.JSONFloat64 `json:"end"`
184 Start gensupport.JSONFloat64 `json:"start"`
185 *NoMethod
186 }
187 s1.NoMethod = (*NoMethod)(s)
188 if err := json.Unmarshal(data, &s1); err != nil {
189 return err
190 }
191 s.End = float64(s1.End)
192 s.Start = float64(s1.Start)
193 return nil
194 }
195
196
197 type Webfont struct {
198
199 Axes []*Axis `json:"axes,omitempty"`
200
201 Category string `json:"category,omitempty"`
202
203 ColorCapabilities []string `json:"colorCapabilities,omitempty"`
204
205 Family string `json:"family,omitempty"`
206
207
208 Files map[string]string `json:"files,omitempty"`
209
210 Kind string `json:"kind,omitempty"`
211
212
213 LastModified string `json:"lastModified,omitempty"`
214
215
216 Menu string `json:"menu,omitempty"`
217
218 Subsets []string `json:"subsets,omitempty"`
219
220 Variants []string `json:"variants,omitempty"`
221
222 Version string `json:"version,omitempty"`
223
224
225
226
227
228 ForceSendFields []string `json:"-"`
229
230
231
232
233 NullFields []string `json:"-"`
234 }
235
236 func (s *Webfont) MarshalJSON() ([]byte, error) {
237 type NoMethod Webfont
238 return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields)
239 }
240
241
242
243 type WebfontList struct {
244
245 Items []*Webfont `json:"items,omitempty"`
246
247
248 Kind string `json:"kind,omitempty"`
249
250
251 googleapi.ServerResponse `json:"-"`
252
253
254
255
256
257 ForceSendFields []string `json:"-"`
258
259
260
261
262 NullFields []string `json:"-"`
263 }
264
265 func (s *WebfontList) MarshalJSON() ([]byte, error) {
266 type NoMethod WebfontList
267 return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields)
268 }
269
270 type WebfontsListCall struct {
271 s *Service
272 urlParams_ gensupport.URLParams
273 ifNoneMatch_ string
274 ctx_ context.Context
275 header_ http.Header
276 }
277
278
279
280 func (r *WebfontsService) List() *WebfontsListCall {
281 c := &WebfontsListCall{s: r.s, urlParams_: make(gensupport.URLParams)}
282 return c
283 }
284
285
286
287
288
289
290
291
292
293
294
295 func (c *WebfontsListCall) Capability(capability ...string) *WebfontsListCall {
296 c.urlParams_.SetMulti("capability", append([]string{}, capability...))
297 return c
298 }
299
300
301
302 func (c *WebfontsListCall) Family(family ...string) *WebfontsListCall {
303 c.urlParams_.SetMulti("family", append([]string{}, family...))
304 return c
305 }
306
307
308
309
310
311
312
313
314
315
316
317 func (c *WebfontsListCall) Sort(sort string) *WebfontsListCall {
318 c.urlParams_.Set("sort", sort)
319 return c
320 }
321
322
323
324 func (c *WebfontsListCall) Subset(subset string) *WebfontsListCall {
325 c.urlParams_.Set("subset", subset)
326 return c
327 }
328
329
330
331
332 func (c *WebfontsListCall) Fields(s ...googleapi.Field) *WebfontsListCall {
333 c.urlParams_.Set("fields", googleapi.CombineFields(s))
334 return c
335 }
336
337
338
339
340 func (c *WebfontsListCall) IfNoneMatch(entityTag string) *WebfontsListCall {
341 c.ifNoneMatch_ = entityTag
342 return c
343 }
344
345
346 func (c *WebfontsListCall) Context(ctx context.Context) *WebfontsListCall {
347 c.ctx_ = ctx
348 return c
349 }
350
351
352
353 func (c *WebfontsListCall) Header() http.Header {
354 if c.header_ == nil {
355 c.header_ = make(http.Header)
356 }
357 return c.header_
358 }
359
360 func (c *WebfontsListCall) doRequest(alt string) (*http.Response, error) {
361 reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "", c.header_)
362 if c.ifNoneMatch_ != "" {
363 reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
364 }
365 var body io.Reader = nil
366 c.urlParams_.Set("alt", alt)
367 c.urlParams_.Set("prettyPrint", "false")
368 urls := googleapi.ResolveRelative(c.s.BasePath, "v1/webfonts")
369 urls += "?" + c.urlParams_.Encode()
370 req, err := http.NewRequest("GET", urls, body)
371 if err != nil {
372 return nil, err
373 }
374 req.Header = reqHeaders
375 return gensupport.SendRequest(c.ctx_, c.s.client, req)
376 }
377
378
379
380
381
382
383 func (c *WebfontsListCall) Do(opts ...googleapi.CallOption) (*WebfontList, error) {
384 gensupport.SetOptions(c.urlParams_, opts...)
385 res, err := c.doRequest("json")
386 if res != nil && res.StatusCode == http.StatusNotModified {
387 if res.Body != nil {
388 res.Body.Close()
389 }
390 return nil, gensupport.WrapError(&googleapi.Error{
391 Code: res.StatusCode,
392 Header: res.Header,
393 })
394 }
395 if err != nil {
396 return nil, err
397 }
398 defer googleapi.CloseBody(res)
399 if err := googleapi.CheckResponse(res); err != nil {
400 return nil, gensupport.WrapError(err)
401 }
402 ret := &WebfontList{
403 ServerResponse: googleapi.ServerResponse{
404 Header: res.Header,
405 HTTPStatusCode: res.StatusCode,
406 },
407 }
408 target := &ret
409 if err := gensupport.DecodeResponse(target, res); err != nil {
410 return nil, err
411 }
412 return ret, nil
413 }
414
View as plain text