1// Copyright 2020 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 5// Code generated file. DO NOT EDIT. 6 7// Package webfonts provides access to the Web Fonts Developer API. 8// 9// For product documentation, see: https://developers.google.com/fonts/docs/developer_api 10// 11// Creating a client 12// 13// Usage example: 14// 15// import "google.golang.org/api/webfonts/v1" 16// ... 17// ctx := context.Background() 18// webfontsService, err := webfonts.NewService(ctx) 19// 20// In this example, Google Application Default Credentials are used for authentication. 21// 22// For information on how to create and obtain Application Default Credentials, see https://developers.google.com/identity/protocols/application-default-credentials. 23// 24// Other authentication options 25// 26// To use an API key for authentication (note: some APIs do not support API keys), use option.WithAPIKey: 27// 28// webfontsService, err := webfonts.NewService(ctx, option.WithAPIKey("AIza...")) 29// 30// To use an OAuth token (e.g., a user token obtained via a three-legged OAuth flow), use option.WithTokenSource: 31// 32// config := &oauth2.Config{...} 33// // ... 34// token, err := config.Exchange(ctx, ...) 35// webfontsService, err := webfonts.NewService(ctx, option.WithTokenSource(config.TokenSource(ctx, token))) 36// 37// See https://godoc.org/google.golang.org/api/option/ for details on options. 38package webfonts // import "google.golang.org/api/webfonts/v1" 39 40import ( 41 "bytes" 42 "context" 43 "encoding/json" 44 "errors" 45 "fmt" 46 "io" 47 "net/http" 48 "net/url" 49 "strconv" 50 "strings" 51 52 googleapi "google.golang.org/api/googleapi" 53 gensupport "google.golang.org/api/internal/gensupport" 54 option "google.golang.org/api/option" 55 internaloption "google.golang.org/api/option/internaloption" 56 htransport "google.golang.org/api/transport/http" 57) 58 59// Always reference these packages, just in case the auto-generated code 60// below doesn't. 61var _ = bytes.NewBuffer 62var _ = strconv.Itoa 63var _ = fmt.Sprintf 64var _ = json.NewDecoder 65var _ = io.Copy 66var _ = url.Parse 67var _ = gensupport.MarshalJSON 68var _ = googleapi.Version 69var _ = errors.New 70var _ = strings.Replace 71var _ = context.Canceled 72var _ = internaloption.WithDefaultEndpoint 73 74const apiId = "webfonts:v1" 75const apiName = "webfonts" 76const apiVersion = "v1" 77const basePath = "https://webfonts.googleapis.com/" 78const mtlsBasePath = "https://webfonts.mtls.googleapis.com/" 79 80// NewService creates a new Service. 81func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, error) { 82 opts = append(opts, internaloption.WithDefaultEndpoint(basePath)) 83 opts = append(opts, internaloption.WithDefaultMTLSEndpoint(mtlsBasePath)) 84 client, endpoint, err := htransport.NewClient(ctx, opts...) 85 if err != nil { 86 return nil, err 87 } 88 s, err := New(client) 89 if err != nil { 90 return nil, err 91 } 92 if endpoint != "" { 93 s.BasePath = endpoint 94 } 95 return s, nil 96} 97 98// New creates a new Service. It uses the provided http.Client for requests. 99// 100// Deprecated: please use NewService instead. 101// To provide a custom HTTP client, use option.WithHTTPClient. 102// If you are using google.golang.org/api/googleapis/transport.APIKey, use option.WithAPIKey with NewService instead. 103func New(client *http.Client) (*Service, error) { 104 if client == nil { 105 return nil, errors.New("client is nil") 106 } 107 s := &Service{client: client, BasePath: basePath} 108 s.Webfonts = NewWebfontsService(s) 109 return s, nil 110} 111 112type Service struct { 113 client *http.Client 114 BasePath string // API endpoint base URL 115 UserAgent string // optional additional User-Agent fragment 116 117 Webfonts *WebfontsService 118} 119 120func (s *Service) userAgent() string { 121 if s.UserAgent == "" { 122 return googleapi.UserAgent 123 } 124 return googleapi.UserAgent + " " + s.UserAgent 125} 126 127func NewWebfontsService(s *Service) *WebfontsService { 128 rs := &WebfontsService{s: s} 129 return rs 130} 131 132type WebfontsService struct { 133 s *Service 134} 135 136// Webfont: Metadata describing a family of fonts. 137type Webfont struct { 138 // Category: The category of the font. 139 Category string `json:"category,omitempty"` 140 141 // Family: The name of the font. 142 Family string `json:"family,omitempty"` 143 144 // Files: The font files (with all supported scripts) for each one of 145 // the available variants, as a key : value map. 146 Files map[string]string `json:"files,omitempty"` 147 148 // Kind: This kind represents a webfont object in the webfonts service. 149 Kind string `json:"kind,omitempty"` 150 151 // LastModified: The date (format "yyyy-MM-dd") the font was modified 152 // for the last time. 153 LastModified string `json:"lastModified,omitempty"` 154 155 // Subsets: The scripts supported by the font. 156 Subsets []string `json:"subsets,omitempty"` 157 158 // Variants: The available variants for the font. 159 Variants []string `json:"variants,omitempty"` 160 161 // Version: The font version. 162 Version string `json:"version,omitempty"` 163 164 // ForceSendFields is a list of field names (e.g. "Category") to 165 // unconditionally include in API requests. By default, fields with 166 // empty values are omitted from API requests. However, any non-pointer, 167 // non-interface field appearing in ForceSendFields will be sent to the 168 // server regardless of whether the field is empty or not. This may be 169 // used to include empty fields in Patch requests. 170 ForceSendFields []string `json:"-"` 171 172 // NullFields is a list of field names (e.g. "Category") to include in 173 // API 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 181func (s *Webfont) MarshalJSON() ([]byte, error) { 182 type NoMethod Webfont 183 raw := NoMethod(*s) 184 return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields) 185} 186 187// WebfontList: Response containing the list of fonts currently served 188// by the Google Fonts API. 189type WebfontList struct { 190 // Items: The list of fonts currently served by the Google Fonts API. 191 Items []*Webfont `json:"items,omitempty"` 192 193 // Kind: This kind represents a list of webfont objects in the webfonts 194 // service. 195 Kind string `json:"kind,omitempty"` 196 197 // ServerResponse contains the HTTP response code and headers from the 198 // server. 199 googleapi.ServerResponse `json:"-"` 200 201 // ForceSendFields is a list of field names (e.g. "Items") to 202 // unconditionally include in API requests. By default, fields with 203 // empty values are omitted from API requests. However, any non-pointer, 204 // non-interface field appearing in ForceSendFields will be sent to the 205 // server regardless of whether the field is empty or not. This may be 206 // used to include empty fields in Patch requests. 207 ForceSendFields []string `json:"-"` 208 209 // NullFields is a list of field names (e.g. "Items") to include in API 210 // requests with the JSON null value. By default, fields with empty 211 // values are omitted from API requests. However, any field with an 212 // empty value appearing in NullFields will be sent to the server as 213 // null. It is an error if a field in this list has a non-empty value. 214 // This may be used to include null fields in Patch requests. 215 NullFields []string `json:"-"` 216} 217 218func (s *WebfontList) MarshalJSON() ([]byte, error) { 219 type NoMethod WebfontList 220 raw := NoMethod(*s) 221 return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields) 222} 223 224// method id "webfonts.webfonts.list": 225 226type WebfontsListCall struct { 227 s *Service 228 urlParams_ gensupport.URLParams 229 ifNoneMatch_ string 230 ctx_ context.Context 231 header_ http.Header 232} 233 234// List: Retrieves the list of fonts currently served by the Google 235// Fonts Developer API. 236func (r *WebfontsService) List() *WebfontsListCall { 237 c := &WebfontsListCall{s: r.s, urlParams_: make(gensupport.URLParams)} 238 return c 239} 240 241// Sort sets the optional parameter "sort": Enables sorting of the list. 242// 243// Possible values: 244// "SORT_UNDEFINED" - No sorting specified, use the default sorting 245// method. 246// "ALPHA" - Sort alphabetically 247// "DATE" - Sort by date added 248// "POPULARITY" - Sort by popularity 249// "STYLE" - Sort by number of styles 250// "TRENDING" - Sort by trending 251func (c *WebfontsListCall) Sort(sort string) *WebfontsListCall { 252 c.urlParams_.Set("sort", sort) 253 return c 254} 255 256// Fields allows partial responses to be retrieved. See 257// https://developers.google.com/gdata/docs/2.0/basics#PartialResponse 258// for more information. 259func (c *WebfontsListCall) Fields(s ...googleapi.Field) *WebfontsListCall { 260 c.urlParams_.Set("fields", googleapi.CombineFields(s)) 261 return c 262} 263 264// IfNoneMatch sets the optional parameter which makes the operation 265// fail if the object's ETag matches the given value. This is useful for 266// getting updates only after the object has changed since the last 267// request. Use googleapi.IsNotModified to check whether the response 268// error from Do is the result of In-None-Match. 269func (c *WebfontsListCall) IfNoneMatch(entityTag string) *WebfontsListCall { 270 c.ifNoneMatch_ = entityTag 271 return c 272} 273 274// Context sets the context to be used in this call's Do method. Any 275// pending HTTP request will be aborted if the provided context is 276// canceled. 277func (c *WebfontsListCall) Context(ctx context.Context) *WebfontsListCall { 278 c.ctx_ = ctx 279 return c 280} 281 282// Header returns an http.Header that can be modified by the caller to 283// add HTTP headers to the request. 284func (c *WebfontsListCall) Header() http.Header { 285 if c.header_ == nil { 286 c.header_ = make(http.Header) 287 } 288 return c.header_ 289} 290 291func (c *WebfontsListCall) doRequest(alt string) (*http.Response, error) { 292 reqHeaders := make(http.Header) 293 reqHeaders.Set("x-goog-api-client", "gl-go/"+gensupport.GoVersion()+" gdcl/20201009") 294 for k, v := range c.header_ { 295 reqHeaders[k] = v 296 } 297 reqHeaders.Set("User-Agent", c.s.userAgent()) 298 if c.ifNoneMatch_ != "" { 299 reqHeaders.Set("If-None-Match", c.ifNoneMatch_) 300 } 301 var body io.Reader = nil 302 c.urlParams_.Set("alt", alt) 303 c.urlParams_.Set("prettyPrint", "false") 304 urls := googleapi.ResolveRelative(c.s.BasePath, "v1/webfonts") 305 urls += "?" + c.urlParams_.Encode() 306 req, err := http.NewRequest("GET", urls, body) 307 if err != nil { 308 return nil, err 309 } 310 req.Header = reqHeaders 311 return gensupport.SendRequest(c.ctx_, c.s.client, req) 312} 313 314// Do executes the "webfonts.webfonts.list" call. 315// Exactly one of *WebfontList or error will be non-nil. Any non-2xx 316// status code is an error. Response headers are in either 317// *WebfontList.ServerResponse.Header or (if a response was returned at 318// all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified 319// to check whether the returned error was because 320// http.StatusNotModified was returned. 321func (c *WebfontsListCall) Do(opts ...googleapi.CallOption) (*WebfontList, error) { 322 gensupport.SetOptions(c.urlParams_, opts...) 323 res, err := c.doRequest("json") 324 if res != nil && res.StatusCode == http.StatusNotModified { 325 if res.Body != nil { 326 res.Body.Close() 327 } 328 return nil, &googleapi.Error{ 329 Code: res.StatusCode, 330 Header: res.Header, 331 } 332 } 333 if err != nil { 334 return nil, err 335 } 336 defer googleapi.CloseBody(res) 337 if err := googleapi.CheckResponse(res); err != nil { 338 return nil, err 339 } 340 ret := &WebfontList{ 341 ServerResponse: googleapi.ServerResponse{ 342 Header: res.Header, 343 HTTPStatusCode: res.StatusCode, 344 }, 345 } 346 target := &ret 347 if err := gensupport.DecodeResponse(target, res); err != nil { 348 return nil, err 349 } 350 return ret, nil 351 // { 352 // "description": "Retrieves the list of fonts currently served by the Google Fonts Developer API.", 353 // "flatPath": "v1/webfonts", 354 // "httpMethod": "GET", 355 // "id": "webfonts.webfonts.list", 356 // "parameterOrder": [], 357 // "parameters": { 358 // "sort": { 359 // "description": "Enables sorting of the list.", 360 // "enum": [ 361 // "SORT_UNDEFINED", 362 // "ALPHA", 363 // "DATE", 364 // "POPULARITY", 365 // "STYLE", 366 // "TRENDING" 367 // ], 368 // "enumDescriptions": [ 369 // "No sorting specified, use the default sorting method.", 370 // "Sort alphabetically", 371 // "Sort by date added", 372 // "Sort by popularity", 373 // "Sort by number of styles", 374 // "Sort by trending" 375 // ], 376 // "location": "query", 377 // "type": "string" 378 // } 379 // }, 380 // "path": "v1/webfonts", 381 // "response": { 382 // "$ref": "WebfontList" 383 // } 384 // } 385 386} 387