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)
10package webfonts // import "google.golang.org/api/webfonts/v1"
11
12import (
13	"bytes"
14	"encoding/json"
15	"errors"
16	"fmt"
17	context "golang.org/x/net/context"
18	ctxhttp "golang.org/x/net/context/ctxhttp"
19	gensupport "google.golang.org/api/gensupport"
20	googleapi "google.golang.org/api/googleapi"
21	"io"
22	"net/http"
23	"net/url"
24	"strconv"
25	"strings"
26)
27
28// Always reference these packages, just in case the auto-generated code
29// below doesn't.
30var _ = bytes.NewBuffer
31var _ = strconv.Itoa
32var _ = fmt.Sprintf
33var _ = json.NewDecoder
34var _ = io.Copy
35var _ = url.Parse
36var _ = gensupport.MarshalJSON
37var _ = googleapi.Version
38var _ = errors.New
39var _ = strings.Replace
40var _ = context.Canceled
41var _ = ctxhttp.Do
42
43const apiId = "webfonts:v1"
44const apiName = "webfonts"
45const apiVersion = "v1"
46const basePath = "https://www.googleapis.com/webfonts/v1/"
47
48func New(client *http.Client) (*Service, error) {
49	if client == nil {
50		return nil, errors.New("client is nil")
51	}
52	s := &Service{client: client, BasePath: basePath}
53	s.Webfonts = NewWebfontsService(s)
54	return s, nil
55}
56
57type Service struct {
58	client    *http.Client
59	BasePath  string // API endpoint base URL
60	UserAgent string // optional additional User-Agent fragment
61
62	Webfonts *WebfontsService
63}
64
65func (s *Service) userAgent() string {
66	if s.UserAgent == "" {
67		return googleapi.UserAgent
68	}
69	return googleapi.UserAgent + " " + s.UserAgent
70}
71
72func NewWebfontsService(s *Service) *WebfontsService {
73	rs := &WebfontsService{s: s}
74	return rs
75}
76
77type WebfontsService struct {
78	s *Service
79}
80
81type Webfont struct {
82	// Category: The category of the font.
83	Category string `json:"category,omitempty"`
84
85	// Family: The name of the font.
86	Family string `json:"family,omitempty"`
87
88	// Files: The font files (with all supported scripts) for each one of
89	// the available variants, as a key : value map.
90	Files map[string]string `json:"files,omitempty"`
91
92	// Kind: This kind represents a webfont object in the webfonts service.
93	Kind string `json:"kind,omitempty"`
94
95	// LastModified: The date (format "yyyy-MM-dd") the font was modified
96	// for the last time.
97	LastModified string `json:"lastModified,omitempty"`
98
99	// Subsets: The scripts supported by the font.
100	Subsets []string `json:"subsets,omitempty"`
101
102	// Variants: The available variants for the font.
103	Variants []string `json:"variants,omitempty"`
104
105	// Version: The font version.
106	Version string `json:"version,omitempty"`
107
108	// ForceSendFields is a list of field names (e.g. "Category") to
109	// unconditionally include in API requests. By default, fields with
110	// empty values are omitted from API requests. However, any non-pointer,
111	// non-interface field appearing in ForceSendFields will be sent to the
112	// server regardless of whether the field is empty or not. This may be
113	// used to include empty fields in Patch requests.
114	ForceSendFields []string `json:"-"`
115}
116
117func (s *Webfont) MarshalJSON() ([]byte, error) {
118	type noMethod Webfont
119	raw := noMethod(*s)
120	return gensupport.MarshalJSON(raw, s.ForceSendFields)
121}
122
123type WebfontList struct {
124	// Items: The list of fonts currently served by the Google Fonts API.
125	Items []*Webfont `json:"items,omitempty"`
126
127	// Kind: This kind represents a list of webfont objects in the webfonts
128	// service.
129	Kind string `json:"kind,omitempty"`
130
131	// ServerResponse contains the HTTP response code and headers from the
132	// server.
133	googleapi.ServerResponse `json:"-"`
134
135	// ForceSendFields is a list of field names (e.g. "Items") to
136	// unconditionally include in API requests. By default, fields with
137	// empty values are omitted from API requests. However, any non-pointer,
138	// non-interface field appearing in ForceSendFields will be sent to the
139	// server regardless of whether the field is empty or not. This may be
140	// used to include empty fields in Patch requests.
141	ForceSendFields []string `json:"-"`
142}
143
144func (s *WebfontList) MarshalJSON() ([]byte, error) {
145	type noMethod WebfontList
146	raw := noMethod(*s)
147	return gensupport.MarshalJSON(raw, s.ForceSendFields)
148}
149
150// method id "webfonts.webfonts.list":
151
152type WebfontsListCall struct {
153	s            *Service
154	urlParams_   gensupport.URLParams
155	ifNoneMatch_ string
156	ctx_         context.Context
157}
158
159// List: Retrieves the list of fonts currently served by the Google
160// Fonts Developer API
161func (r *WebfontsService) List() *WebfontsListCall {
162	c := &WebfontsListCall{s: r.s, urlParams_: make(gensupport.URLParams)}
163	return c
164}
165
166// Sort sets the optional parameter "sort": Enables sorting of the list
167//
168// Possible values:
169//   "alpha" - Sort alphabetically
170//   "date" - Sort by date added
171//   "popularity" - Sort by popularity
172//   "style" - Sort by number of styles
173//   "trending" - Sort by trending
174func (c *WebfontsListCall) Sort(sort string) *WebfontsListCall {
175	c.urlParams_.Set("sort", sort)
176	return c
177}
178
179// Fields allows partial responses to be retrieved. See
180// https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
181// for more information.
182func (c *WebfontsListCall) Fields(s ...googleapi.Field) *WebfontsListCall {
183	c.urlParams_.Set("fields", googleapi.CombineFields(s))
184	return c
185}
186
187// IfNoneMatch sets the optional parameter which makes the operation
188// fail if the object's ETag matches the given value. This is useful for
189// getting updates only after the object has changed since the last
190// request. Use googleapi.IsNotModified to check whether the response
191// error from Do is the result of In-None-Match.
192func (c *WebfontsListCall) IfNoneMatch(entityTag string) *WebfontsListCall {
193	c.ifNoneMatch_ = entityTag
194	return c
195}
196
197// Context sets the context to be used in this call's Do method. Any
198// pending HTTP request will be aborted if the provided context is
199// canceled.
200func (c *WebfontsListCall) Context(ctx context.Context) *WebfontsListCall {
201	c.ctx_ = ctx
202	return c
203}
204
205func (c *WebfontsListCall) doRequest(alt string) (*http.Response, error) {
206	var body io.Reader = nil
207	c.urlParams_.Set("alt", alt)
208	urls := googleapi.ResolveRelative(c.s.BasePath, "webfonts")
209	urls += "?" + c.urlParams_.Encode()
210	req, _ := http.NewRequest("GET", urls, body)
211	googleapi.SetOpaque(req.URL)
212	req.Header.Set("User-Agent", c.s.userAgent())
213	if c.ifNoneMatch_ != "" {
214		req.Header.Set("If-None-Match", c.ifNoneMatch_)
215	}
216	if c.ctx_ != nil {
217		return ctxhttp.Do(c.ctx_, c.s.client, req)
218	}
219	return c.s.client.Do(req)
220}
221
222// Do executes the "webfonts.webfonts.list" call.
223// Exactly one of *WebfontList or error will be non-nil. Any non-2xx
224// status code is an error. Response headers are in either
225// *WebfontList.ServerResponse.Header or (if a response was returned at
226// all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified
227// to check whether the returned error was because
228// http.StatusNotModified was returned.
229func (c *WebfontsListCall) Do(opts ...googleapi.CallOption) (*WebfontList, error) {
230	gensupport.SetOptions(c.urlParams_, opts...)
231	res, err := c.doRequest("json")
232	if res != nil && res.StatusCode == http.StatusNotModified {
233		if res.Body != nil {
234			res.Body.Close()
235		}
236		return nil, &googleapi.Error{
237			Code:   res.StatusCode,
238			Header: res.Header,
239		}
240	}
241	if err != nil {
242		return nil, err
243	}
244	defer googleapi.CloseBody(res)
245	if err := googleapi.CheckResponse(res); err != nil {
246		return nil, err
247	}
248	ret := &WebfontList{
249		ServerResponse: googleapi.ServerResponse{
250			Header:         res.Header,
251			HTTPStatusCode: res.StatusCode,
252		},
253	}
254	if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
255		return nil, err
256	}
257	return ret, nil
258	// {
259	//   "description": "Retrieves the list of fonts currently served by the Google Fonts Developer API",
260	//   "httpMethod": "GET",
261	//   "id": "webfonts.webfonts.list",
262	//   "parameters": {
263	//     "sort": {
264	//       "description": "Enables sorting of the list",
265	//       "enum": [
266	//         "alpha",
267	//         "date",
268	//         "popularity",
269	//         "style",
270	//         "trending"
271	//       ],
272	//       "enumDescriptions": [
273	//         "Sort alphabetically",
274	//         "Sort by date added",
275	//         "Sort by popularity",
276	//         "Sort by number of styles",
277	//         "Sort by trending"
278	//       ],
279	//       "location": "query",
280	//       "type": "string"
281	//     }
282	//   },
283	//   "path": "webfonts",
284	//   "response": {
285	//     "$ref": "WebfontList"
286	//   }
287	// }
288
289}
290