...

Source file src/google.golang.org/api/webfonts/v1/webfonts-gen.go

Documentation: google.golang.org/api/webfonts/v1

     1  // Copyright 2024 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  // # Library status
    12  //
    13  // These client libraries are officially supported by Google. However, this
    14  // library is considered complete and is in maintenance mode. This means
    15  // that we will address critical bugs and security issues but will not add
    16  // any new features.
    17  //
    18  // When possible, we recommend using our newer
    19  // [Cloud Client Libraries for Go](https://pkg.go.dev/cloud.google.com/go)
    20  // that are still actively being worked and iterated on.
    21  //
    22  // # Creating a client
    23  //
    24  // Usage example:
    25  //
    26  //	import "google.golang.org/api/webfonts/v1"
    27  //	...
    28  //	ctx := context.Background()
    29  //	webfontsService, err := webfonts.NewService(ctx)
    30  //
    31  // In this example, Google Application Default Credentials are used for
    32  // authentication. For information on how to create and obtain Application
    33  // Default Credentials, see https://developers.google.com/identity/protocols/application-default-credentials.
    34  //
    35  // # Other authentication options
    36  //
    37  // To use an API key for authentication (note: some APIs do not support API
    38  // keys), use [google.golang.org/api/option.WithAPIKey]:
    39  //
    40  //	webfontsService, err := webfonts.NewService(ctx, option.WithAPIKey("AIza..."))
    41  //
    42  // To use an OAuth token (e.g., a user token obtained via a three-legged OAuth
    43  // flow, use [google.golang.org/api/option.WithTokenSource]:
    44  //
    45  //	config := &oauth2.Config{...}
    46  //	// ...
    47  //	token, err := config.Exchange(ctx, ...)
    48  //	webfontsService, err := webfonts.NewService(ctx, option.WithTokenSource(config.TokenSource(ctx, token)))
    49  //
    50  // See [google.golang.org/api/option.ClientOption] for details on options.
    51  package webfonts // import "google.golang.org/api/webfonts/v1"
    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  // Always reference these packages, just in case the auto-generated code
    74  // below doesn't.
    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  // NewService creates a new Service.
    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  // New creates a new Service. It uses the provided http.Client for requests.
   117  //
   118  // Deprecated: please use NewService instead.
   119  // To provide a custom HTTP client, use option.WithHTTPClient.
   120  // If you are using google.golang.org/api/googleapis/transport.APIKey, use option.WithAPIKey with NewService instead.
   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 // API endpoint base URL
   133  	UserAgent string // optional additional User-Agent fragment
   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  // Axis: Metadata for a variable font axis.
   155  type Axis struct {
   156  	// End: maximum value
   157  	End float64 `json:"end,omitempty"`
   158  	// Start: minimum value
   159  	Start float64 `json:"start,omitempty"`
   160  	// Tag: tag name.
   161  	Tag string `json:"tag,omitempty"`
   162  	// ForceSendFields is a list of field names (e.g. "End") to unconditionally
   163  	// include in API requests. By default, fields with empty or default values are
   164  	// omitted from API requests. See
   165  	// https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
   166  	// details.
   167  	ForceSendFields []string `json:"-"`
   168  	// NullFields is a list of field names (e.g. "End") to include in API requests
   169  	// with the JSON null value. By default, fields with empty values are omitted
   170  	// from API requests. See
   171  	// https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
   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  // Webfont: Metadata describing a family of fonts.
   197  type Webfont struct {
   198  	// Axes: Axis for variable fonts.
   199  	Axes []*Axis `json:"axes,omitempty"`
   200  	// Category: The category of the font.
   201  	Category string `json:"category,omitempty"`
   202  	// ColorCapabilities: The color format(s) available for this family.
   203  	ColorCapabilities []string `json:"colorCapabilities,omitempty"`
   204  	// Family: The name of the font.
   205  	Family string `json:"family,omitempty"`
   206  	// Files: The font files (with all supported scripts) for each one of the
   207  	// available variants, as a key : value map.
   208  	Files map[string]string `json:"files,omitempty"`
   209  	// Kind: This kind represents a webfont object in the webfonts service.
   210  	Kind string `json:"kind,omitempty"`
   211  	// LastModified: The date (format "yyyy-MM-dd") the font was modified for the
   212  	// last time.
   213  	LastModified string `json:"lastModified,omitempty"`
   214  	// Menu: Font URL for menu subset, a subset of the font that is enough to
   215  	// display the font name
   216  	Menu string `json:"menu,omitempty"`
   217  	// Subsets: The scripts supported by the font.
   218  	Subsets []string `json:"subsets,omitempty"`
   219  	// Variants: The available variants for the font.
   220  	Variants []string `json:"variants,omitempty"`
   221  	// Version: The font version.
   222  	Version string `json:"version,omitempty"`
   223  	// ForceSendFields is a list of field names (e.g. "Axes") to unconditionally
   224  	// include in API requests. By default, fields with empty or default values are
   225  	// omitted from API requests. See
   226  	// https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
   227  	// details.
   228  	ForceSendFields []string `json:"-"`
   229  	// NullFields is a list of field names (e.g. "Axes") to include in API requests
   230  	// with the JSON null value. By default, fields with empty values are omitted
   231  	// from API requests. See
   232  	// https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
   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  // WebfontList: Response containing the list of fonts currently served by the
   242  // Google Fonts API.
   243  type WebfontList struct {
   244  	// Items: The list of fonts currently served by the Google Fonts API.
   245  	Items []*Webfont `json:"items,omitempty"`
   246  	// Kind: This kind represents a list of webfont objects in the webfonts
   247  	// service.
   248  	Kind string `json:"kind,omitempty"`
   249  
   250  	// ServerResponse contains the HTTP response code and headers from the server.
   251  	googleapi.ServerResponse `json:"-"`
   252  	// ForceSendFields is a list of field names (e.g. "Items") to unconditionally
   253  	// include in API requests. By default, fields with empty or default values are
   254  	// omitted from API requests. See
   255  	// https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
   256  	// details.
   257  	ForceSendFields []string `json:"-"`
   258  	// NullFields is a list of field names (e.g. "Items") to include in API
   259  	// requests with the JSON null value. By default, fields with empty values are
   260  	// omitted from API requests. See
   261  	// https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
   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  // List: Retrieves the list of fonts currently served by the Google Fonts
   279  // Developer API.
   280  func (r *WebfontsService) List() *WebfontsListCall {
   281  	c := &WebfontsListCall{s: r.s, urlParams_: make(gensupport.URLParams)}
   282  	return c
   283  }
   284  
   285  // Capability sets the optional parameter "capability": Controls the font urls
   286  // in `Webfont.files`, by default, static ttf fonts are sent.
   287  //
   288  // Possible values:
   289  //
   290  //	"CAPABILITY_UNSPECIFIED" - Default means static ttf fonts.
   291  //	"WOFF2" - Use WOFF2(Compressed)instead of ttf.
   292  //	"VF" - Prefer variable font files instead of static fonts instantiated at
   293  //
   294  // standard weights.
   295  func (c *WebfontsListCall) Capability(capability ...string) *WebfontsListCall {
   296  	c.urlParams_.SetMulti("capability", append([]string{}, capability...))
   297  	return c
   298  }
   299  
   300  // Family sets the optional parameter "family": Filters by Webfont.family,
   301  // using literal match. If not set, returns all families
   302  func (c *WebfontsListCall) Family(family ...string) *WebfontsListCall {
   303  	c.urlParams_.SetMulti("family", append([]string{}, family...))
   304  	return c
   305  }
   306  
   307  // Sort sets the optional parameter "sort": Enables sorting of the list.
   308  //
   309  // Possible values:
   310  //
   311  //	"SORT_UNDEFINED" - No sorting specified, use the default sorting method.
   312  //	"ALPHA" - Sort alphabetically
   313  //	"DATE" - Sort by date added
   314  //	"POPULARITY" - Sort by popularity
   315  //	"STYLE" - Sort by number of styles
   316  //	"TRENDING" - Sort by trending
   317  func (c *WebfontsListCall) Sort(sort string) *WebfontsListCall {
   318  	c.urlParams_.Set("sort", sort)
   319  	return c
   320  }
   321  
   322  // Subset sets the optional parameter "subset": Filters by Webfont.subset, if
   323  // subset is found in Webfont.subsets. If not set, returns all families.
   324  func (c *WebfontsListCall) Subset(subset string) *WebfontsListCall {
   325  	c.urlParams_.Set("subset", subset)
   326  	return c
   327  }
   328  
   329  // Fields allows partial responses to be retrieved. See
   330  // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse for more
   331  // details.
   332  func (c *WebfontsListCall) Fields(s ...googleapi.Field) *WebfontsListCall {
   333  	c.urlParams_.Set("fields", googleapi.CombineFields(s))
   334  	return c
   335  }
   336  
   337  // IfNoneMatch sets an optional parameter which makes the operation fail if the
   338  // object's ETag matches the given value. This is useful for getting updates
   339  // only after the object has changed since the last request.
   340  func (c *WebfontsListCall) IfNoneMatch(entityTag string) *WebfontsListCall {
   341  	c.ifNoneMatch_ = entityTag
   342  	return c
   343  }
   344  
   345  // Context sets the context to be used in this call's Do method.
   346  func (c *WebfontsListCall) Context(ctx context.Context) *WebfontsListCall {
   347  	c.ctx_ = ctx
   348  	return c
   349  }
   350  
   351  // Header returns a http.Header that can be modified by the caller to add
   352  // headers to the request.
   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  // Do executes the "webfonts.webfonts.list" call.
   379  // Any non-2xx status code is an error. Response headers are in either
   380  // *WebfontList.ServerResponse.Header or (if a response was returned at all) in
   381  // error.(*googleapi.Error).Header. Use googleapi.IsNotModified to check
   382  // whether the returned error was because http.StatusNotModified was returned.
   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